Compare commits
4 Commits
e81fc62645
...
dfad7cfb76
| Author | SHA1 | Date | |
|---|---|---|---|
|
dfad7cfb76
|
|||
|
5d78572481
|
|||
|
9e9fb15f86
|
|||
|
e7af663bc3
|
@@ -11,7 +11,7 @@ void analytics_init(void)
|
|||||||
.log_type = ESP_DIAG_LOG_TYPE_ERROR | ESP_DIAG_LOG_TYPE_EVENT | ESP_DIAG_LOG_TYPE_WARNING,
|
.log_type = ESP_DIAG_LOG_TYPE_ERROR | ESP_DIAG_LOG_TYPE_EVENT | ESP_DIAG_LOG_TYPE_WARNING,
|
||||||
.node_id = NULL,
|
.node_id = NULL,
|
||||||
.auth_key = insights_auth_key_start,
|
.auth_key = insights_auth_key_start,
|
||||||
.alloc_ext_ram = false,
|
.alloc_ext_ram = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
esp_insights_init(&config);
|
esp_insights_init(&config);
|
||||||
|
|||||||
@@ -59,5 +59,37 @@ class MenuItem;
|
|||||||
*/
|
*/
|
||||||
typedef std::function<void(MenuItem, ButtonType)> ButtonCallback;
|
typedef std::function<void(MenuItem, ButtonType)> ButtonCallback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def IMPLEMENT_GET_NAME
|
||||||
|
* @brief Macro to implement getName() method using __FILE__
|
||||||
|
* @details Extracts the class name from the source filename automatically.
|
||||||
|
* Use this macro in .cpp files to implement Widget::getName().
|
||||||
|
* @param ClassName The class name for the method scope (e.g., MainMenu)
|
||||||
|
*/
|
||||||
|
#define IMPLEMENT_GET_NAME(ClassName) \
|
||||||
|
const char *ClassName::getName() const \
|
||||||
|
{ \
|
||||||
|
static const char *cachedName = nullptr; \
|
||||||
|
if (!cachedName) \
|
||||||
|
{ \
|
||||||
|
const char *file = __FILE__; \
|
||||||
|
const char *lastSlash = file; \
|
||||||
|
for (const char *p = file; *p; ++p) \
|
||||||
|
{ \
|
||||||
|
if (*p == '/' || *p == '\\') \
|
||||||
|
lastSlash = p + 1; \
|
||||||
|
} \
|
||||||
|
static char buffer[64]; \
|
||||||
|
size_t i = 0; \
|
||||||
|
for (; lastSlash[i] && lastSlash[i] != '.' && i < sizeof(buffer) - 1; ++i) \
|
||||||
|
{ \
|
||||||
|
buffer[i] = lastSlash[i]; \
|
||||||
|
} \
|
||||||
|
buffer[i] = '\0'; \
|
||||||
|
cachedName = buffer; \
|
||||||
|
} \
|
||||||
|
return cachedName; \
|
||||||
|
}
|
||||||
|
|
||||||
// Include MenuItem.h after the typedef to avoid circular dependency
|
// Include MenuItem.h after the typedef to avoid circular dependency
|
||||||
#include "data/MenuItem.h"
|
#include "data/MenuItem.h"
|
||||||
@@ -150,6 +150,19 @@ class Widget
|
|||||||
*/
|
*/
|
||||||
virtual void OnButtonClicked(ButtonType button);
|
virtual void OnButtonClicked(ButtonType button);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the name of this widget for diagnostic purposes
|
||||||
|
* @return A string identifying the widget type
|
||||||
|
*
|
||||||
|
* @details This method returns a human-readable name for the widget which
|
||||||
|
* is used for logging and diagnostic events. Derived classes should
|
||||||
|
* override this method to return their specific screen/widget name.
|
||||||
|
*
|
||||||
|
* @note The base implementation returns "Widget". Override in derived classes
|
||||||
|
* to provide meaningful screen names for diagnostics.
|
||||||
|
*/
|
||||||
|
virtual const char *getName() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief Pointer to the u8g2 display context used for rendering operations
|
* @brief Pointer to the u8g2 display context used for rendering operations
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class ClockScreenSaver final : public Widget
|
|||||||
void Update(uint64_t dt) override;
|
void Update(uint64_t dt) override;
|
||||||
void Render() override;
|
void Render() override;
|
||||||
void OnButtonClicked(ButtonType button) override;
|
void OnButtonClicked(ButtonType button) override;
|
||||||
|
const char *getName() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr int MOVE_INTERVAL = 50; // milliseconds between movements
|
static constexpr int MOVE_INTERVAL = 50; // milliseconds between movements
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ class ExternalDevices final : public Menu
|
|||||||
public:
|
public:
|
||||||
explicit ExternalDevices(menu_options_t *options);
|
explicit ExternalDevices(menu_options_t *options);
|
||||||
|
|
||||||
|
const char *getName() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onButtonPressed(const MenuItem &menuItem, ButtonType button) override;
|
void onButtonPressed(const MenuItem &menuItem, ButtonType button) override;
|
||||||
menu_options_t *m_options;
|
menu_options_t *m_options;
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ class LightMenu final : public Menu
|
|||||||
*/
|
*/
|
||||||
explicit LightMenu(menu_options_t *options);
|
explicit LightMenu(menu_options_t *options);
|
||||||
|
|
||||||
|
const char *getName() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief Handles button press events specific to light control menu items
|
* @brief Handles button press events specific to light control menu items
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ class MainMenu final : public Menu
|
|||||||
*/
|
*/
|
||||||
explicit MainMenu(menu_options_t *options);
|
explicit MainMenu(menu_options_t *options);
|
||||||
|
|
||||||
|
const char *getName() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief Handles button press events specific to main menu items
|
* @brief Handles button press events specific to main menu items
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class ScreenSaver final : public Widget
|
|||||||
void Update(uint64_t dt) override;
|
void Update(uint64_t dt) override;
|
||||||
void Render() override;
|
void Render() override;
|
||||||
void OnButtonClicked(ButtonType button) override;
|
void OnButtonClicked(ButtonType button) override;
|
||||||
|
const char *getName() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -74,4 +74,6 @@ public:
|
|||||||
* @see Menu::Menu for base class construction details
|
* @see Menu::Menu for base class construction details
|
||||||
*/
|
*/
|
||||||
explicit SettingsMenu(menu_options_t *options);
|
explicit SettingsMenu(menu_options_t *options);
|
||||||
|
|
||||||
|
const char *getName() const override;
|
||||||
};
|
};
|
||||||
@@ -151,6 +151,8 @@ class SplashScreen final : public Widget
|
|||||||
*/
|
*/
|
||||||
void Render() override;
|
void Render() override;
|
||||||
|
|
||||||
|
const char *getName() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief Pointer to menu options configuration structure
|
* @brief Pointer to menu options configuration structure
|
||||||
|
|||||||
@@ -31,3 +31,8 @@ void Widget::Render()
|
|||||||
void Widget::OnButtonClicked(ButtonType button)
|
void Widget::OnButtonClicked(ButtonType button)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *Widget::getName() const
|
||||||
|
{
|
||||||
|
return "Widget";
|
||||||
|
}
|
||||||
|
|||||||
@@ -132,3 +132,5 @@ void ClockScreenSaver::OnButtonClicked(ButtonType button)
|
|||||||
m_options->popScreen();
|
m_options->popScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_GET_NAME(ClockScreenSaver)
|
||||||
|
|||||||
@@ -23,3 +23,5 @@ void ExternalDevices::onButtonPressed(const MenuItem &menuItem, const ButtonType
|
|||||||
ble_connect_to_device(menuItem.getId());
|
ble_connect_to_device(menuItem.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_GET_NAME(ExternalDevices)
|
||||||
|
|||||||
@@ -47,10 +47,10 @@ LightMenu::LightMenu(menu_options_t *options) : Menu(options), m_options(options
|
|||||||
variants.emplace_back("1");
|
variants.emplace_back("1");
|
||||||
variants.emplace_back("2");
|
variants.emplace_back("2");
|
||||||
variants.emplace_back("3");
|
variants.emplace_back("3");
|
||||||
int variant_value = 2;
|
int variant_value = 3;
|
||||||
if (m_options && m_options->persistenceManager)
|
if (m_options && m_options->persistenceManager)
|
||||||
{
|
{
|
||||||
variant_value = m_options->persistenceManager->GetValue(LightMenuOptions::LIGHT_VARIANT, variant_value);
|
variant_value = m_options->persistenceManager->GetValue(LightMenuOptions::LIGHT_VARIANT, variant_value) - 1;
|
||||||
}
|
}
|
||||||
addSelection(LightMenuItem::VARIANT, "Variante", variants, variant_value);
|
addSelection(LightMenuItem::VARIANT, "Variante", variants, variant_value);
|
||||||
}
|
}
|
||||||
@@ -123,3 +123,5 @@ void LightMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType butto
|
|||||||
m_options->pushScreen(widget);
|
m_options->pushScreen(widget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_GET_NAME(LightMenu)
|
||||||
|
|||||||
@@ -48,3 +48,5 @@ void MainMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType button
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_GET_NAME(MainMenu)
|
||||||
|
|||||||
@@ -327,3 +327,5 @@ void ScreenSaver::OnButtonClicked(ButtonType button)
|
|||||||
m_options->popScreen();
|
m_options->popScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_GET_NAME(ScreenSaver)
|
||||||
|
|||||||
@@ -9,3 +9,5 @@ SettingsMenu::SettingsMenu(menu_options_t *options) : Menu(options)
|
|||||||
{
|
{
|
||||||
addText(SettingsMenuItem::OTA_UPLOAD, "OTA Einspielen");
|
addText(SettingsMenuItem::OTA_UPLOAD, "OTA Einspielen");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_GET_NAME(SettingsMenu)
|
||||||
|
|||||||
@@ -28,3 +28,5 @@ void SplashScreen::Render()
|
|||||||
u8g2_SetFont(u8g2, u8g2_font_haxrcorp4089_tr);
|
u8g2_SetFont(u8g2, u8g2_font_haxrcorp4089_tr);
|
||||||
u8g2_DrawStr(u8g2, 35, 50, "Initialisierung...");
|
u8g2_DrawStr(u8g2, 35, 50, "Initialisierung...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_GET_NAME(SplashScreen)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "wifi_manager.h"
|
#include "wifi_manager.h"
|
||||||
#include <driver/i2c.h>
|
#include <driver/i2c.h>
|
||||||
#include <esp_diagnostics.h>
|
#include <esp_diagnostics.h>
|
||||||
|
#include <esp_insights.h>
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include <esp_task_wdt.h>
|
#include <esp_task_wdt.h>
|
||||||
#include <esp_timer.h>
|
#include <esp_timer.h>
|
||||||
@@ -62,6 +63,7 @@ void setScreen(const std::shared_ptr<Widget> &screen)
|
|||||||
{
|
{
|
||||||
if (screen != nullptr)
|
if (screen != nullptr)
|
||||||
{
|
{
|
||||||
|
ESP_DIAG_EVENT(TAG, "Screen set: %s", screen->getName());
|
||||||
m_widget = screen;
|
m_widget = screen;
|
||||||
m_history.clear();
|
m_history.clear();
|
||||||
m_history.emplace_back(m_widget);
|
m_history.emplace_back(m_widget);
|
||||||
@@ -77,6 +79,7 @@ void pushScreen(const std::shared_ptr<Widget> &screen)
|
|||||||
{
|
{
|
||||||
m_widget->onPause();
|
m_widget->onPause();
|
||||||
}
|
}
|
||||||
|
ESP_DIAG_EVENT(TAG, "Screen pushed: %s", screen->getName());
|
||||||
m_widget = screen;
|
m_widget = screen;
|
||||||
m_widget->onEnter();
|
m_widget->onEnter();
|
||||||
m_history.emplace_back(m_widget);
|
m_history.emplace_back(m_widget);
|
||||||
@@ -97,6 +100,7 @@ void popScreen()
|
|||||||
m_widget->onExit();
|
m_widget->onExit();
|
||||||
}
|
}
|
||||||
m_widget = m_history.back();
|
m_widget = m_history.back();
|
||||||
|
ESP_DIAG_EVENT(TAG, "Screen popped, now: %s", m_widget->getName());
|
||||||
m_widget->onResume();
|
m_widget->onResume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,12 @@
|
|||||||
static const char *TAG = "button_handling";
|
static const char *TAG = "button_handling";
|
||||||
|
|
||||||
const uint8_t gpios[] = {BUTTON_DOWN, BUTTON_UP, BUTTON_LEFT, BUTTON_RIGHT, BUTTON_SELECT, BUTTON_BACK};
|
const uint8_t gpios[] = {BUTTON_DOWN, BUTTON_UP, BUTTON_LEFT, BUTTON_RIGHT, BUTTON_SELECT, BUTTON_BACK};
|
||||||
|
static const char *button_names[] = {"DOWN", "UP", "LEFT", "RIGHT", "SELECT", "BACK"};
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t gpio;
|
uint8_t gpio;
|
||||||
|
uint8_t index;
|
||||||
} button_user_data_t;
|
} button_user_data_t;
|
||||||
|
|
||||||
static button_user_data_t button_data[6];
|
static button_user_data_t button_data[6];
|
||||||
@@ -35,8 +37,9 @@ static void button_event_cb(void *arg, void *usr_data)
|
|||||||
}
|
}
|
||||||
button_user_data_t *data = (button_user_data_t *)usr_data;
|
button_user_data_t *data = (button_user_data_t *)usr_data;
|
||||||
uint8_t gpio_num = data->gpio;
|
uint8_t gpio_num = data->gpio;
|
||||||
|
const char *button_name = button_names[data->index];
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Button pressed on GPIO %d", gpio_num);
|
ESP_DIAG_EVENT(TAG, "Button %s pressed (GPIO %d)", button_name, gpio_num);
|
||||||
|
|
||||||
if (xQueueSend(buttonQueue, &gpio_num, 0) != pdTRUE)
|
if (xQueueSend(buttonQueue, &gpio_num, 0) != pdTRUE)
|
||||||
{
|
{
|
||||||
@@ -60,6 +63,7 @@ static void init_button(uint8_t gpio, int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
button_data[index].gpio = gpio;
|
button_data[index].gpio = gpio;
|
||||||
|
button_data[index].index = index;
|
||||||
iot_button_register_cb(gpio_btn, BUTTON_SINGLE_CLICK, NULL, button_event_cb, &button_data[index]);
|
iot_button_register_cb(gpio_btn, BUTTON_SINGLE_CLICK, NULL, button_event_cb, &button_data[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,23 +15,39 @@ static const unsigned int I2C_TIMEOUT_MS = 1000;
|
|||||||
static spi_device_handle_t handle_spi; // SPI handle.
|
static spi_device_handle_t handle_spi; // SPI handle.
|
||||||
static i2c_cmd_handle_t handle_i2c; // I2C handle.
|
static i2c_cmd_handle_t handle_i2c; // I2C handle.
|
||||||
static u8g2_esp32_hal_t u8g2_esp32_hal; // HAL state data.
|
static u8g2_esp32_hal_t u8g2_esp32_hal; // HAL state data.
|
||||||
|
static bool i2c_transfer_failed = false; // Flag to track I2C transfer errors
|
||||||
|
|
||||||
#define HOST SPI2_HOST
|
#define HOST SPI2_HOST
|
||||||
|
|
||||||
#undef ESP_ERROR_CHECK
|
#undef ESP_ERROR_CHECK
|
||||||
#define ESP_ERROR_CHECK(x) \
|
#define ESP_ERROR_CHECK(x) \
|
||||||
do { \
|
do \
|
||||||
|
{ \
|
||||||
esp_err_t rc = (x); \
|
esp_err_t rc = (x); \
|
||||||
if (rc != ESP_OK) { \
|
if (rc != ESP_OK) \
|
||||||
|
{ \
|
||||||
ESP_LOGE("err", "esp_err_t = %d", rc); \
|
ESP_LOGE("err", "esp_err_t = %d", rc); \
|
||||||
assert(0 && #x); \
|
assert(0 && #x); \
|
||||||
} \
|
} \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
|
// Softer error handling for I2C operations that may fail temporarily
|
||||||
|
#define I2C_ERROR_CHECK(x) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
esp_err_t rc = (x); \
|
||||||
|
if (rc != ESP_OK) \
|
||||||
|
{ \
|
||||||
|
ESP_LOGW(TAG, "I2C error: %s = %d", #x, rc); \
|
||||||
|
i2c_transfer_failed = true; \
|
||||||
|
} \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialze the ESP32 HAL.
|
* Initialze the ESP32 HAL.
|
||||||
*/
|
*/
|
||||||
void u8g2_esp32_hal_init(u8g2_esp32_hal_t u8g2_esp32_hal_param) {
|
void u8g2_esp32_hal_init(u8g2_esp32_hal_t u8g2_esp32_hal_param)
|
||||||
|
{
|
||||||
u8g2_esp32_hal = u8g2_esp32_hal_param;
|
u8g2_esp32_hal = u8g2_esp32_hal_param;
|
||||||
} // u8g2_esp32_hal_init
|
} // u8g2_esp32_hal_init
|
||||||
|
|
||||||
@@ -39,15 +55,14 @@ void u8g2_esp32_hal_init(u8g2_esp32_hal_t u8g2_esp32_hal_param) {
|
|||||||
* HAL callback function as prescribed by the U8G2 library. This callback is
|
* HAL callback function as prescribed by the U8G2 library. This callback is
|
||||||
* invoked to handle SPI communications.
|
* invoked to handle SPI communications.
|
||||||
*/
|
*/
|
||||||
uint8_t u8g2_esp32_spi_byte_cb(u8x8_t* u8x8,
|
uint8_t u8g2_esp32_spi_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||||
uint8_t msg,
|
{
|
||||||
uint8_t arg_int,
|
ESP_LOGD(TAG, "spi_byte_cb: Received a msg: %d, arg_int: %d, arg_ptr: %p", msg, arg_int, arg_ptr);
|
||||||
void* arg_ptr) {
|
switch (msg)
|
||||||
ESP_LOGD(TAG, "spi_byte_cb: Received a msg: %d, arg_int: %d, arg_ptr: %p",
|
{
|
||||||
msg, arg_int, arg_ptr);
|
|
||||||
switch (msg) {
|
|
||||||
case U8X8_MSG_BYTE_SET_DC:
|
case U8X8_MSG_BYTE_SET_DC:
|
||||||
if (u8g2_esp32_hal.dc != U8G2_ESP32_HAL_UNDEFINED) {
|
if (u8g2_esp32_hal.dc != U8G2_ESP32_HAL_UNDEFINED)
|
||||||
|
{
|
||||||
gpio_set_level(u8g2_esp32_hal.dc, arg_int);
|
gpio_set_level(u8g2_esp32_hal.dc, arg_int);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -55,7 +70,8 @@ uint8_t u8g2_esp32_spi_byte_cb(u8x8_t* u8x8,
|
|||||||
case U8X8_MSG_BYTE_INIT: {
|
case U8X8_MSG_BYTE_INIT: {
|
||||||
if (u8g2_esp32_hal.bus.spi.clk == U8G2_ESP32_HAL_UNDEFINED ||
|
if (u8g2_esp32_hal.bus.spi.clk == U8G2_ESP32_HAL_UNDEFINED ||
|
||||||
u8g2_esp32_hal.bus.spi.mosi == U8G2_ESP32_HAL_UNDEFINED ||
|
u8g2_esp32_hal.bus.spi.mosi == U8G2_ESP32_HAL_UNDEFINED ||
|
||||||
u8g2_esp32_hal.bus.spi.cs == U8G2_ESP32_HAL_UNDEFINED) {
|
u8g2_esp32_hal.bus.spi.cs == U8G2_ESP32_HAL_UNDEFINED)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,16 +127,15 @@ uint8_t u8g2_esp32_spi_byte_cb(u8x8_t* u8x8,
|
|||||||
* HAL callback function as prescribed by the U8G2 library. This callback is
|
* HAL callback function as prescribed by the U8G2 library. This callback is
|
||||||
* invoked to handle I2C communications.
|
* invoked to handle I2C communications.
|
||||||
*/
|
*/
|
||||||
uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t* u8x8,
|
uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||||
uint8_t msg,
|
{
|
||||||
uint8_t arg_int,
|
ESP_LOGD(TAG, "i2c_cb: Received a msg: %d, arg_int: %d, arg_ptr: %p", msg, arg_int, arg_ptr);
|
||||||
void* arg_ptr) {
|
|
||||||
ESP_LOGD(TAG, "i2c_cb: Received a msg: %d, arg_int: %d, arg_ptr: %p", msg,
|
|
||||||
arg_int, arg_ptr);
|
|
||||||
|
|
||||||
switch (msg) {
|
switch (msg)
|
||||||
|
{
|
||||||
case U8X8_MSG_BYTE_SET_DC: {
|
case U8X8_MSG_BYTE_SET_DC: {
|
||||||
if (u8g2_esp32_hal.dc != U8G2_ESP32_HAL_UNDEFINED) {
|
if (u8g2_esp32_hal.dc != U8G2_ESP32_HAL_UNDEFINED)
|
||||||
|
{
|
||||||
gpio_set_level(u8g2_esp32_hal.dc, arg_int);
|
gpio_set_level(u8g2_esp32_hal.dc, arg_int);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -128,7 +143,8 @@ uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t* u8x8,
|
|||||||
|
|
||||||
case U8X8_MSG_BYTE_INIT: {
|
case U8X8_MSG_BYTE_INIT: {
|
||||||
if (u8g2_esp32_hal.bus.i2c.sda == U8G2_ESP32_HAL_UNDEFINED ||
|
if (u8g2_esp32_hal.bus.i2c.sda == U8G2_ESP32_HAL_UNDEFINED ||
|
||||||
u8g2_esp32_hal.bus.i2c.scl == U8G2_ESP32_HAL_UNDEFINED) {
|
u8g2_esp32_hal.bus.i2c.scl == U8G2_ESP32_HAL_UNDEFINED)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,19 +161,26 @@ uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t* u8x8,
|
|||||||
ESP_LOGI(TAG, "i2c_param_config %d", conf.mode);
|
ESP_LOGI(TAG, "i2c_param_config %d", conf.mode);
|
||||||
ESP_ERROR_CHECK(i2c_param_config(I2C_MASTER_NUM, &conf));
|
ESP_ERROR_CHECK(i2c_param_config(I2C_MASTER_NUM, &conf));
|
||||||
ESP_LOGI(TAG, "i2c_driver_install %d", I2C_MASTER_NUM);
|
ESP_LOGI(TAG, "i2c_driver_install %d", I2C_MASTER_NUM);
|
||||||
ESP_ERROR_CHECK(i2c_driver_install(I2C_MASTER_NUM, conf.mode,
|
ESP_ERROR_CHECK(
|
||||||
I2C_MASTER_RX_BUF_DISABLE,
|
i2c_driver_install(I2C_MASTER_NUM, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0));
|
||||||
I2C_MASTER_TX_BUF_DISABLE, 0));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case U8X8_MSG_BYTE_SEND: {
|
case U8X8_MSG_BYTE_SEND: {
|
||||||
|
if (i2c_transfer_failed)
|
||||||
|
{
|
||||||
|
break; // Skip sending if transfer already failed
|
||||||
|
}
|
||||||
uint8_t *data_ptr = (uint8_t *)arg_ptr;
|
uint8_t *data_ptr = (uint8_t *)arg_ptr;
|
||||||
ESP_LOG_BUFFER_HEXDUMP(TAG, data_ptr, arg_int, ESP_LOG_VERBOSE);
|
ESP_LOG_BUFFER_HEXDUMP(TAG, data_ptr, arg_int, ESP_LOG_VERBOSE);
|
||||||
|
|
||||||
while (arg_int > 0) {
|
while (arg_int > 0)
|
||||||
ESP_ERROR_CHECK(
|
{
|
||||||
i2c_master_write_byte(handle_i2c, *data_ptr, ACK_CHECK_EN));
|
I2C_ERROR_CHECK(i2c_master_write_byte(handle_i2c, *data_ptr, ACK_CHECK_EN));
|
||||||
|
if (i2c_transfer_failed)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
data_ptr++;
|
data_ptr++;
|
||||||
arg_int--;
|
arg_int--;
|
||||||
}
|
}
|
||||||
@@ -167,18 +190,20 @@ uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t* u8x8,
|
|||||||
case U8X8_MSG_BYTE_START_TRANSFER: {
|
case U8X8_MSG_BYTE_START_TRANSFER: {
|
||||||
uint8_t i2c_address = u8x8_GetI2CAddress(u8x8);
|
uint8_t i2c_address = u8x8_GetI2CAddress(u8x8);
|
||||||
handle_i2c = i2c_cmd_link_create();
|
handle_i2c = i2c_cmd_link_create();
|
||||||
|
i2c_transfer_failed = false; // Reset error flag at start of transfer
|
||||||
ESP_LOGD(TAG, "Start I2C transfer to %02X.", i2c_address >> 1);
|
ESP_LOGD(TAG, "Start I2C transfer to %02X.", i2c_address >> 1);
|
||||||
ESP_ERROR_CHECK(i2c_master_start(handle_i2c));
|
I2C_ERROR_CHECK(i2c_master_start(handle_i2c));
|
||||||
ESP_ERROR_CHECK(i2c_master_write_byte(
|
I2C_ERROR_CHECK(i2c_master_write_byte(handle_i2c, i2c_address | I2C_MASTER_WRITE, ACK_CHECK_EN));
|
||||||
handle_i2c, i2c_address | I2C_MASTER_WRITE, ACK_CHECK_EN));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case U8X8_MSG_BYTE_END_TRANSFER: {
|
case U8X8_MSG_BYTE_END_TRANSFER: {
|
||||||
ESP_LOGD(TAG, "End I2C transfer.");
|
ESP_LOGD(TAG, "End I2C transfer.");
|
||||||
ESP_ERROR_CHECK(i2c_master_stop(handle_i2c));
|
if (!i2c_transfer_failed)
|
||||||
ESP_ERROR_CHECK(i2c_master_cmd_begin(I2C_MASTER_NUM, handle_i2c,
|
{
|
||||||
pdMS_TO_TICKS(I2C_TIMEOUT_MS)));
|
I2C_ERROR_CHECK(i2c_master_stop(handle_i2c));
|
||||||
|
I2C_ERROR_CHECK(i2c_master_cmd_begin(I2C_MASTER_NUM, handle_i2c, pdMS_TO_TICKS(I2C_TIMEOUT_MS)));
|
||||||
|
}
|
||||||
i2c_cmd_link_delete(handle_i2c);
|
i2c_cmd_link_delete(handle_i2c);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -190,30 +215,31 @@ uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t* u8x8,
|
|||||||
* HAL callback function as prescribed by the U8G2 library. This callback is
|
* HAL callback function as prescribed by the U8G2 library. This callback is
|
||||||
* invoked to handle callbacks for GPIO and delay functions.
|
* invoked to handle callbacks for GPIO and delay functions.
|
||||||
*/
|
*/
|
||||||
uint8_t u8g2_esp32_gpio_and_delay_cb(u8x8_t* u8x8,
|
uint8_t u8g2_esp32_gpio_and_delay_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||||
uint8_t msg,
|
{
|
||||||
uint8_t arg_int,
|
ESP_LOGD(TAG, "gpio_and_delay_cb: Received a msg: %d, arg_int: %d, arg_ptr: %p", msg, arg_int, arg_ptr);
|
||||||
void* arg_ptr) {
|
|
||||||
ESP_LOGD(TAG,
|
|
||||||
"gpio_and_delay_cb: Received a msg: %d, arg_int: %d, arg_ptr: %p",
|
|
||||||
msg, arg_int, arg_ptr);
|
|
||||||
|
|
||||||
switch (msg) {
|
switch (msg)
|
||||||
|
{
|
||||||
// Initialize the GPIO and DELAY HAL functions. If the pins for DC and
|
// Initialize the GPIO and DELAY HAL functions. If the pins for DC and
|
||||||
// RESET have been specified then we define those pins as GPIO outputs.
|
// RESET have been specified then we define those pins as GPIO outputs.
|
||||||
case U8X8_MSG_GPIO_AND_DELAY_INIT: {
|
case U8X8_MSG_GPIO_AND_DELAY_INIT: {
|
||||||
uint64_t bitmask = 0;
|
uint64_t bitmask = 0;
|
||||||
if (u8g2_esp32_hal.dc != U8G2_ESP32_HAL_UNDEFINED) {
|
if (u8g2_esp32_hal.dc != U8G2_ESP32_HAL_UNDEFINED)
|
||||||
|
{
|
||||||
bitmask = bitmask | (1ull << u8g2_esp32_hal.dc);
|
bitmask = bitmask | (1ull << u8g2_esp32_hal.dc);
|
||||||
}
|
}
|
||||||
if (u8g2_esp32_hal.reset != U8G2_ESP32_HAL_UNDEFINED) {
|
if (u8g2_esp32_hal.reset != U8G2_ESP32_HAL_UNDEFINED)
|
||||||
|
{
|
||||||
bitmask = bitmask | (1ull << u8g2_esp32_hal.reset);
|
bitmask = bitmask | (1ull << u8g2_esp32_hal.reset);
|
||||||
}
|
}
|
||||||
if (u8g2_esp32_hal.bus.spi.cs != U8G2_ESP32_HAL_UNDEFINED) {
|
if (u8g2_esp32_hal.bus.spi.cs != U8G2_ESP32_HAL_UNDEFINED)
|
||||||
|
{
|
||||||
bitmask = bitmask | (1ull << u8g2_esp32_hal.bus.spi.cs);
|
bitmask = bitmask | (1ull << u8g2_esp32_hal.bus.spi.cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bitmask == 0) {
|
if (bitmask == 0)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
gpio_config_t gpioConfig;
|
gpio_config_t gpioConfig;
|
||||||
@@ -228,26 +254,30 @@ uint8_t u8g2_esp32_gpio_and_delay_cb(u8x8_t* u8x8,
|
|||||||
|
|
||||||
// Set the GPIO reset pin to the value passed in through arg_int.
|
// Set the GPIO reset pin to the value passed in through arg_int.
|
||||||
case U8X8_MSG_GPIO_RESET:
|
case U8X8_MSG_GPIO_RESET:
|
||||||
if (u8g2_esp32_hal.reset != U8G2_ESP32_HAL_UNDEFINED) {
|
if (u8g2_esp32_hal.reset != U8G2_ESP32_HAL_UNDEFINED)
|
||||||
|
{
|
||||||
gpio_set_level(u8g2_esp32_hal.reset, arg_int);
|
gpio_set_level(u8g2_esp32_hal.reset, arg_int);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// Set the GPIO client select pin to the value passed in through arg_int.
|
// Set the GPIO client select pin to the value passed in through arg_int.
|
||||||
case U8X8_MSG_GPIO_CS:
|
case U8X8_MSG_GPIO_CS:
|
||||||
if (u8g2_esp32_hal.bus.spi.cs != U8G2_ESP32_HAL_UNDEFINED) {
|
if (u8g2_esp32_hal.bus.spi.cs != U8G2_ESP32_HAL_UNDEFINED)
|
||||||
|
{
|
||||||
gpio_set_level(u8g2_esp32_hal.bus.spi.cs, arg_int);
|
gpio_set_level(u8g2_esp32_hal.bus.spi.cs, arg_int);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// Set the Software I²C pin to the value passed in through arg_int.
|
// Set the Software I²C pin to the value passed in through arg_int.
|
||||||
case U8X8_MSG_GPIO_I2C_CLOCK:
|
case U8X8_MSG_GPIO_I2C_CLOCK:
|
||||||
if (u8g2_esp32_hal.bus.i2c.scl != U8G2_ESP32_HAL_UNDEFINED) {
|
if (u8g2_esp32_hal.bus.i2c.scl != U8G2_ESP32_HAL_UNDEFINED)
|
||||||
|
{
|
||||||
gpio_set_level(u8g2_esp32_hal.bus.i2c.scl, arg_int);
|
gpio_set_level(u8g2_esp32_hal.bus.i2c.scl, arg_int);
|
||||||
// printf("%c",(arg_int==1?'C':'c'));
|
// printf("%c",(arg_int==1?'C':'c'));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// Set the Software I²C pin to the value passed in through arg_int.
|
// Set the Software I²C pin to the value passed in through arg_int.
|
||||||
case U8X8_MSG_GPIO_I2C_DATA:
|
case U8X8_MSG_GPIO_I2C_DATA:
|
||||||
if (u8g2_esp32_hal.bus.i2c.sda != U8G2_ESP32_HAL_UNDEFINED) {
|
if (u8g2_esp32_hal.bus.i2c.sda != U8G2_ESP32_HAL_UNDEFINED)
|
||||||
|
{
|
||||||
gpio_set_level(u8g2_esp32_hal.bus.i2c.sda, arg_int);
|
gpio_set_level(u8g2_esp32_hal.bus.i2c.sda, arg_int);
|
||||||
// printf("%c",(arg_int==1?'D':'d'));
|
// printf("%c",(arg_int==1?'D':'d'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
0.1.2
|
0.1.3
|
||||||
Reference in New Issue
Block a user