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);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* @file Common.h
|
* @file Common.h
|
||||||
* @brief Common definitions and types for the INSA component
|
* @brief Common definitions and types for the INSA component
|
||||||
* @details This header file contains shared enumerations, type definitions, and
|
* @details This header file contains shared enumerations, type definitions, and
|
||||||
* callback function types used throughout the INSA component system.
|
* callback function types used throughout the INSA component system.
|
||||||
* It provides the foundation for button handling and event management.
|
* It provides the foundation for button handling and event management.
|
||||||
* @author System Control Team
|
* @author System Control Team
|
||||||
@@ -16,19 +16,19 @@
|
|||||||
* @enum ButtonType
|
* @enum ButtonType
|
||||||
* @brief Enumeration defining the different types of buttons available in the system
|
* @brief Enumeration defining the different types of buttons available in the system
|
||||||
* @details This enumeration represents all possible button types that can be handled
|
* @details This enumeration represents all possible button types that can be handled
|
||||||
* by the system's input management. NONE represents no button pressed or
|
* by the system's input management. NONE represents no button pressed or
|
||||||
* an invalid button state, while the other values correspond to specific
|
* an invalid button state, while the other values correspond to specific
|
||||||
* directional and action buttons.
|
* directional and action buttons.
|
||||||
*/
|
*/
|
||||||
enum class ButtonType
|
enum class ButtonType
|
||||||
{
|
{
|
||||||
NONE, ///< No button pressed or invalid button state
|
NONE, ///< No button pressed or invalid button state
|
||||||
UP, ///< Up directional button for navigation
|
UP, ///< Up directional button for navigation
|
||||||
DOWN, ///< Down directional button for navigation
|
DOWN, ///< Down directional button for navigation
|
||||||
LEFT, ///< Left directional button for navigation
|
LEFT, ///< Left directional button for navigation
|
||||||
RIGHT, ///< Right directional button for navigation
|
RIGHT, ///< Right directional button for navigation
|
||||||
SELECT, ///< Select/confirm button for accepting choices
|
SELECT, ///< Select/confirm button for accepting choices
|
||||||
BACK ///< Back/cancel button for returning to previous state
|
BACK ///< Back/cancel button for returning to previous state
|
||||||
};
|
};
|
||||||
|
|
||||||
// Forward declaration of MenuItem to avoid circular dependency
|
// Forward declaration of MenuItem to avoid circular dependency
|
||||||
@@ -40,13 +40,13 @@ class MenuItem;
|
|||||||
* @details This function type is used to define callback functions that handle
|
* @details This function type is used to define callback functions that handle
|
||||||
* button press events. The callback receives information about which
|
* button press events. The callback receives information about which
|
||||||
* button was pressed and any additional context data.
|
* button was pressed and any additional context data.
|
||||||
*
|
*
|
||||||
* @param MenuItem menu item for the specific action
|
* @param MenuItem menu item for the specific action
|
||||||
* @param ButtonType The type of button that was pressed
|
* @param ButtonType The type of button that was pressed
|
||||||
*
|
*
|
||||||
* @note The first parameter can be used to distinguish between multiple instances
|
* @note The first parameter can be used to distinguish between multiple instances
|
||||||
* of the same button type or to pass additional event-specific data.
|
* of the same button type or to pass additional event-specific data.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* @code
|
* @code
|
||||||
* ButtonCallback myCallback = [](const MenuItem& item, ButtonType type) {
|
* ButtonCallback myCallback = [](const MenuItem& item, ButtonType type) {
|
||||||
@@ -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:
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -20,40 +20,40 @@
|
|||||||
* interface for the application. It allows users to configure various aspects
|
* interface for the application. It allows users to configure various aspects
|
||||||
* of the system including display preferences, system behavior, network
|
* of the system including display preferences, system behavior, network
|
||||||
* settings, and other configurable parameters.
|
* settings, and other configurable parameters.
|
||||||
*
|
*
|
||||||
* The SettingsMenu class extends the base Menu functionality by:
|
* The SettingsMenu class extends the base Menu functionality by:
|
||||||
* - Providing settings-specific menu items (toggles, selections, number inputs)
|
* - Providing settings-specific menu items (toggles, selections, number inputs)
|
||||||
* - Managing configuration persistence and validation
|
* - Managing configuration persistence and validation
|
||||||
* - Organizing settings into logical categories and sections
|
* - Organizing settings into logical categories and sections
|
||||||
* - Implementing real-time preview of setting changes where applicable
|
* - Implementing real-time preview of setting changes where applicable
|
||||||
*
|
*
|
||||||
* Typical settings categories include:
|
* Typical settings categories include:
|
||||||
* - Display settings (brightness, contrast, theme)
|
* - Display settings (brightness, contrast, theme)
|
||||||
* - System preferences (timeouts, auto-save, etc.)
|
* - System preferences (timeouts, auto-save, etc.)
|
||||||
* - Network configuration (if applicable)
|
* - Network configuration (if applicable)
|
||||||
* - User interface preferences
|
* - User interface preferences
|
||||||
* - Hardware-specific parameters
|
* - Hardware-specific parameters
|
||||||
*
|
*
|
||||||
* @note This class is marked as final and cannot be inherited from.
|
* @note This class is marked as final and cannot be inherited from.
|
||||||
* @note Settings changes are typically applied immediately or after confirmation,
|
* @note Settings changes are typically applied immediately or after confirmation,
|
||||||
* depending on the specific setting type and system requirements.
|
* depending on the specific setting type and system requirements.
|
||||||
*
|
*
|
||||||
* @see Menu for base menu functionality
|
* @see Menu for base menu functionality
|
||||||
* @see menu_options_t for configuration structure
|
* @see menu_options_t for configuration structure
|
||||||
* @see MainMenu for navigation back to main interface
|
* @see MainMenu for navigation back to main interface
|
||||||
*/
|
*/
|
||||||
class SettingsMenu final : public Menu
|
class SettingsMenu final : public Menu
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Constructs the settings menu with the specified configuration
|
* @brief Constructs the settings menu with the specified configuration
|
||||||
* @param options Pointer to menu options configuration structure
|
* @param options Pointer to menu options configuration structure
|
||||||
*
|
*
|
||||||
* @pre options must not be nullptr and must remain valid for the menu's lifetime
|
* @pre options must not be nullptr and must remain valid for the menu's lifetime
|
||||||
* @pre options->u8g2 must be initialized and ready for graphics operations
|
* @pre options->u8g2 must be initialized and ready for graphics operations
|
||||||
* @pre All callback functions in options must be properly configured
|
* @pre All callback functions in options must be properly configured
|
||||||
* @post SettingsMenu is initialized with all available configuration options and ready for use
|
* @post SettingsMenu is initialized with all available configuration options and ready for use
|
||||||
*
|
*
|
||||||
* @details The constructor initializes the settings menu by creating all the
|
* @details The constructor initializes the settings menu by creating all the
|
||||||
* configuration menu items based on the current system state and
|
* configuration menu items based on the current system state and
|
||||||
* available options. This includes:
|
* available options. This includes:
|
||||||
@@ -61,17 +61,19 @@ public:
|
|||||||
* - Creating appropriate menu items (toggles, selections, number inputs)
|
* - Creating appropriate menu items (toggles, selections, number inputs)
|
||||||
* - Setting up validation ranges and allowed values
|
* - Setting up validation ranges and allowed values
|
||||||
* - Organizing items in a logical, user-friendly order
|
* - Organizing items in a logical, user-friendly order
|
||||||
*
|
*
|
||||||
* The menu automatically detects which settings are available based on
|
* The menu automatically detects which settings are available based on
|
||||||
* hardware capabilities and system configuration, ensuring only relevant
|
* hardware capabilities and system configuration, ensuring only relevant
|
||||||
* options are presented to the user.
|
* options are presented to the user.
|
||||||
*
|
*
|
||||||
* @note The menu does not take ownership of the options structure and assumes
|
* @note The menu does not take ownership of the options structure and assumes
|
||||||
* it remains valid throughout the menu's lifetime.
|
* it remains valid throughout the menu's lifetime.
|
||||||
* @note Setting values are loaded from persistent storage during construction
|
* @note Setting values are loaded from persistent storage during construction
|
||||||
* and changes are typically saved automatically or on confirmation.
|
* and changes are typically saved automatically or on confirmation.
|
||||||
*
|
*
|
||||||
* @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)
|
||||||
|
|||||||
@@ -326,4 +326,6 @@ void ScreenSaver::OnButtonClicked(ButtonType button)
|
|||||||
{
|
{
|
||||||
m_options->popScreen();
|
m_options->popScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_GET_NAME(ScreenSaver)
|
||||||
|
|||||||
@@ -8,4 +8,6 @@ constexpr uint8_t OTA_UPLOAD = 0;
|
|||||||
SettingsMenu::SettingsMenu(menu_options_t *options) : Menu(options)
|
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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,254 +9,284 @@
|
|||||||
|
|
||||||
#include "u8g2_esp32_hal.h"
|
#include "u8g2_esp32_hal.h"
|
||||||
|
|
||||||
static const char* TAG = "u8g2_hal";
|
static const char *TAG = "u8g2_hal";
|
||||||
static const unsigned int I2C_TIMEOUT_MS = 1000;
|
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); \
|
{ \
|
||||||
if (rc != ESP_OK) { \
|
esp_err_t rc = (x); \
|
||||||
ESP_LOGE("err", "esp_err_t = %d", rc); \
|
if (rc != ESP_OK) \
|
||||||
assert(0 && #x); \
|
{ \
|
||||||
} \
|
ESP_LOGE("err", "esp_err_t = %d", rc); \
|
||||||
} while (0);
|
assert(0 && #x); \
|
||||||
|
} \
|
||||||
|
} 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_init
|
u8g2_esp32_hal = u8g2_esp32_hal_param;
|
||||||
|
} // u8g2_esp32_hal_init
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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;
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
spi_bus_config_t bus_config;
|
||||||
|
memset(&bus_config, 0, sizeof(spi_bus_config_t));
|
||||||
|
bus_config.sclk_io_num = u8g2_esp32_hal.bus.spi.clk; // CLK
|
||||||
|
bus_config.mosi_io_num = u8g2_esp32_hal.bus.spi.mosi; // MOSI
|
||||||
|
bus_config.miso_io_num = GPIO_NUM_NC; // MISO
|
||||||
|
bus_config.quadwp_io_num = GPIO_NUM_NC; // Not used
|
||||||
|
bus_config.quadhd_io_num = GPIO_NUM_NC; // Not used
|
||||||
|
// ESP_LOGI(TAG, "... Initializing bus.");
|
||||||
|
ESP_ERROR_CHECK(spi_bus_initialize(HOST, &bus_config, 1));
|
||||||
|
|
||||||
|
spi_device_interface_config_t dev_config;
|
||||||
|
dev_config.address_bits = 0;
|
||||||
|
dev_config.command_bits = 0;
|
||||||
|
dev_config.dummy_bits = 0;
|
||||||
|
dev_config.mode = 0;
|
||||||
|
dev_config.duty_cycle_pos = 0;
|
||||||
|
dev_config.cs_ena_posttrans = 0;
|
||||||
|
dev_config.cs_ena_pretrans = 0;
|
||||||
|
dev_config.clock_speed_hz = 10000;
|
||||||
|
dev_config.spics_io_num = u8g2_esp32_hal.bus.spi.cs;
|
||||||
|
dev_config.flags = 0;
|
||||||
|
dev_config.queue_size = 200;
|
||||||
|
dev_config.pre_cb = NULL;
|
||||||
|
dev_config.post_cb = NULL;
|
||||||
|
// ESP_LOGI(TAG, "... Adding device bus.");
|
||||||
|
ESP_ERROR_CHECK(spi_bus_add_device(HOST, &dev_config, &handle_spi));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
spi_bus_config_t bus_config;
|
|
||||||
memset(&bus_config, 0, sizeof(spi_bus_config_t));
|
|
||||||
bus_config.sclk_io_num = u8g2_esp32_hal.bus.spi.clk; // CLK
|
|
||||||
bus_config.mosi_io_num = u8g2_esp32_hal.bus.spi.mosi; // MOSI
|
|
||||||
bus_config.miso_io_num = GPIO_NUM_NC; // MISO
|
|
||||||
bus_config.quadwp_io_num = GPIO_NUM_NC; // Not used
|
|
||||||
bus_config.quadhd_io_num = GPIO_NUM_NC; // Not used
|
|
||||||
// ESP_LOGI(TAG, "... Initializing bus.");
|
|
||||||
ESP_ERROR_CHECK(spi_bus_initialize(HOST, &bus_config, 1));
|
|
||||||
|
|
||||||
spi_device_interface_config_t dev_config;
|
|
||||||
dev_config.address_bits = 0;
|
|
||||||
dev_config.command_bits = 0;
|
|
||||||
dev_config.dummy_bits = 0;
|
|
||||||
dev_config.mode = 0;
|
|
||||||
dev_config.duty_cycle_pos = 0;
|
|
||||||
dev_config.cs_ena_posttrans = 0;
|
|
||||||
dev_config.cs_ena_pretrans = 0;
|
|
||||||
dev_config.clock_speed_hz = 10000;
|
|
||||||
dev_config.spics_io_num = u8g2_esp32_hal.bus.spi.cs;
|
|
||||||
dev_config.flags = 0;
|
|
||||||
dev_config.queue_size = 200;
|
|
||||||
dev_config.pre_cb = NULL;
|
|
||||||
dev_config.post_cb = NULL;
|
|
||||||
// ESP_LOGI(TAG, "... Adding device bus.");
|
|
||||||
ESP_ERROR_CHECK(spi_bus_add_device(HOST, &dev_config, &handle_spi));
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case U8X8_MSG_BYTE_SEND: {
|
case U8X8_MSG_BYTE_SEND: {
|
||||||
spi_transaction_t trans_desc;
|
spi_transaction_t trans_desc;
|
||||||
trans_desc.addr = 0;
|
trans_desc.addr = 0;
|
||||||
trans_desc.cmd = 0;
|
trans_desc.cmd = 0;
|
||||||
trans_desc.flags = 0;
|
trans_desc.flags = 0;
|
||||||
trans_desc.length = 8 * arg_int; // Number of bits NOT number of bytes.
|
trans_desc.length = 8 * arg_int; // Number of bits NOT number of bytes.
|
||||||
trans_desc.rxlength = 0;
|
trans_desc.rxlength = 0;
|
||||||
trans_desc.tx_buffer = arg_ptr;
|
trans_desc.tx_buffer = arg_ptr;
|
||||||
trans_desc.rx_buffer = NULL;
|
trans_desc.rx_buffer = NULL;
|
||||||
|
|
||||||
// ESP_LOGI(TAG, "... Transmitting %d bytes.", arg_int);
|
// ESP_LOGI(TAG, "... Transmitting %d bytes.", arg_int);
|
||||||
ESP_ERROR_CHECK(spi_device_transmit(handle_spi, &trans_desc));
|
ESP_ERROR_CHECK(spi_device_transmit(handle_spi, &trans_desc));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
} // u8g2_esp32_spi_byte_cb
|
} // u8g2_esp32_spi_byte_cb
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
i2c_config_t conf = {0};
|
i2c_config_t conf = {0};
|
||||||
conf.mode = I2C_MODE_MASTER;
|
conf.mode = I2C_MODE_MASTER;
|
||||||
ESP_LOGI(TAG, "sda_io_num %d", u8g2_esp32_hal.bus.i2c.sda);
|
ESP_LOGI(TAG, "sda_io_num %d", u8g2_esp32_hal.bus.i2c.sda);
|
||||||
conf.sda_io_num = u8g2_esp32_hal.bus.i2c.sda;
|
conf.sda_io_num = u8g2_esp32_hal.bus.i2c.sda;
|
||||||
conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
|
conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
|
||||||
ESP_LOGI(TAG, "scl_io_num %d", u8g2_esp32_hal.bus.i2c.scl);
|
ESP_LOGI(TAG, "scl_io_num %d", u8g2_esp32_hal.bus.i2c.scl);
|
||||||
conf.scl_io_num = u8g2_esp32_hal.bus.i2c.scl;
|
conf.scl_io_num = u8g2_esp32_hal.bus.i2c.scl;
|
||||||
conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
|
conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
|
||||||
ESP_LOGI(TAG, "clk_speed %d", I2C_MASTER_FREQ_HZ);
|
ESP_LOGI(TAG, "clk_speed %d", I2C_MASTER_FREQ_HZ);
|
||||||
conf.master.clk_speed = I2C_MASTER_FREQ_HZ;
|
conf.master.clk_speed = I2C_MASTER_FREQ_HZ;
|
||||||
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: {
|
||||||
uint8_t* data_ptr = (uint8_t*)arg_ptr;
|
if (i2c_transfer_failed)
|
||||||
ESP_LOG_BUFFER_HEXDUMP(TAG, data_ptr, arg_int, ESP_LOG_VERBOSE);
|
{
|
||||||
|
break; // Skip sending if transfer already failed
|
||||||
|
}
|
||||||
|
uint8_t *data_ptr = (uint8_t *)arg_ptr;
|
||||||
|
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));
|
||||||
data_ptr++;
|
if (i2c_transfer_failed)
|
||||||
arg_int--;
|
{
|
||||||
}
|
break;
|
||||||
break;
|
}
|
||||||
|
data_ptr++;
|
||||||
|
arg_int--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
ESP_LOGD(TAG, "Start I2C transfer to %02X.", i2c_address >> 1);
|
i2c_transfer_failed = false; // Reset error flag at start of transfer
|
||||||
ESP_ERROR_CHECK(i2c_master_start(handle_i2c));
|
ESP_LOGD(TAG, "Start I2C transfer to %02X.", i2c_address >> 1);
|
||||||
ESP_ERROR_CHECK(i2c_master_write_byte(
|
I2C_ERROR_CHECK(i2c_master_start(handle_i2c));
|
||||||
handle_i2c, i2c_address | I2C_MASTER_WRITE, ACK_CHECK_EN));
|
I2C_ERROR_CHECK(i2c_master_write_byte(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_cmd_link_delete(handle_i2c);
|
I2C_ERROR_CHECK(i2c_master_cmd_begin(I2C_MASTER_NUM, handle_i2c, pdMS_TO_TICKS(I2C_TIMEOUT_MS)));
|
||||||
break;
|
}
|
||||||
|
i2c_cmd_link_delete(handle_i2c);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
} // u8g2_esp32_i2c_byte_cb
|
} // u8g2_esp32_i2c_byte_cb
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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
|
{
|
||||||
// RESET have been specified then we define those pins as GPIO outputs.
|
// 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.
|
||||||
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) {
|
}
|
||||||
bitmask = bitmask | (1ull << u8g2_esp32_hal.reset);
|
if (u8g2_esp32_hal.reset != U8G2_ESP32_HAL_UNDEFINED)
|
||||||
}
|
{
|
||||||
if (u8g2_esp32_hal.bus.spi.cs != U8G2_ESP32_HAL_UNDEFINED) {
|
bitmask = bitmask | (1ull << u8g2_esp32_hal.reset);
|
||||||
bitmask = bitmask | (1ull << u8g2_esp32_hal.bus.spi.cs);
|
}
|
||||||
}
|
if (u8g2_esp32_hal.bus.spi.cs != U8G2_ESP32_HAL_UNDEFINED)
|
||||||
|
{
|
||||||
|
bitmask = bitmask | (1ull << u8g2_esp32_hal.bus.spi.cs);
|
||||||
|
}
|
||||||
|
|
||||||
if (bitmask == 0) {
|
if (bitmask == 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
gpio_config_t gpioConfig;
|
||||||
|
gpioConfig.pin_bit_mask = bitmask;
|
||||||
|
gpioConfig.mode = GPIO_MODE_OUTPUT;
|
||||||
|
gpioConfig.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||||
|
gpioConfig.pull_down_en = GPIO_PULLDOWN_ENABLE;
|
||||||
|
gpioConfig.intr_type = GPIO_INTR_DISABLE;
|
||||||
|
gpio_config(&gpioConfig);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
gpio_config_t gpioConfig;
|
|
||||||
gpioConfig.pin_bit_mask = bitmask;
|
|
||||||
gpioConfig.mode = GPIO_MODE_OUTPUT;
|
|
||||||
gpioConfig.pull_up_en = GPIO_PULLUP_DISABLE;
|
|
||||||
gpioConfig.pull_down_en = GPIO_PULLDOWN_ENABLE;
|
|
||||||
gpioConfig.intr_type = GPIO_INTR_DISABLE;
|
|
||||||
gpio_config(&gpioConfig);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
}
|
||||||
// Set the GPIO client select pin to the value passed in through arg_int.
|
break;
|
||||||
|
// 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;
|
}
|
||||||
// Set the Software I²C pin to the value passed in through arg_int.
|
break;
|
||||||
|
// 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);
|
{
|
||||||
// printf("%c",(arg_int==1?'C':'c'));
|
gpio_set_level(u8g2_esp32_hal.bus.i2c.scl, arg_int);
|
||||||
}
|
// printf("%c",(arg_int==1?'C':'c'));
|
||||||
break;
|
}
|
||||||
// Set the Software I²C pin to the value passed in through arg_int.
|
break;
|
||||||
|
// 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);
|
{
|
||||||
// printf("%c",(arg_int==1?'D':'d'));
|
gpio_set_level(u8g2_esp32_hal.bus.i2c.sda, arg_int);
|
||||||
}
|
// printf("%c",(arg_int==1?'D':'d'));
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// Delay for the number of milliseconds passed in through arg_int.
|
// Delay for the number of milliseconds passed in through arg_int.
|
||||||
case U8X8_MSG_DELAY_MILLI:
|
case U8X8_MSG_DELAY_MILLI:
|
||||||
vTaskDelay(arg_int / portTICK_PERIOD_MS);
|
vTaskDelay(arg_int / portTICK_PERIOD_MS);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
} // u8g2_esp32_gpio_and_delay_cb
|
} // u8g2_esp32_gpio_and_delay_cb
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
0.1.2
|
0.1.3
|
||||||
Reference in New Issue
Block a user