|
|
ChaosDMX
Open-Source DMX-Interface
|
Thread-safe configuration component utilizing NVS for ESP32. Implements the private storage structures, mutex protection mechanisms, and input validation logic defined in config.h. More...
#include "config.h"#include "freertos/FreeRTOS.h"#include "freertos/semphr.h"#include "led.h"#include "logger.h"#include "nvs.h"#include <stdio.h>#include <string.h>Go to the source code of this file.
Data Structures | |
| struct | app_wifi_creds_t |
| WIFI credentials structure for both Station and Access Point modes. More... | |
| struct | __attribute__ |
| Internal configuration storage layout. Mirrors the private runtime configuration context state in RAM. More... | |
Macros | |
| #define | LOG_TAG "CONFIG" |
| "CONFIG" log tag for this file | |
| #define | NVS_NAMESPACE "app_config" |
| NVS storage namespace for configuration data. | |
| #define | NVS_BLOB_KEY "config_blob" |
| Key under which the entire config blob is stored in NVS. | |
| #define | APP_CONFIG_MAGIC 0x43444D58 |
| #define | APP_CONFIG_VERSION 4 |
| #define | LOCK() |
| Locks the configuration mutex for exclusive access. | |
| #define | UNLOCK() |
| Unlocks the configuration mutex after access. | |
Functions | |
| static void | load_factory_defaults (void) |
| Restores all configuration fields to their factory-defined values in RAM. | |
| esp_err_t | config_init (void) |
| Initializes the configuration component. | |
| esp_err_t | config_reset_defaults (void) |
| Resets all configuration settings back to factory defaults. | |
| esp_err_t | config_save (void) |
| Flushes all staged RAM changes permanently to the non-volatile storage. | |
| config_connection_t | config_get_connection (void) |
| Gets the current network connection type. | |
| bool | config_set_connection (config_connection_t conn) |
| Sets the network connection type in RAM. | |
| config_ip_method_t | config_get_ip_method (void) |
| Gets the current IP allocation method. | |
| bool | config_set_ip_method (config_ip_method_t method) |
| Sets the IP assignment method in RAM. | |
| uint8_t | config_get_led_brightness (void) |
| Gets the current status LED brightness level. | |
| bool | config_set_led_brightness (uint8_t brightness) |
| Sets the status LED brightness level in RAM. | |
| uint16_t | config_get_dmx_universe (uint8_t port_index) |
| Gets the configured DMX universe for a specific port. | |
| bool | config_set_dmx_universe (uint8_t port_index, uint16_t universe) |
| Sets the DMX universe for a specific port in RAM. | |
| config_direction_t | config_get_dmx_direction (uint8_t port_index) |
| Gets the data direction for a specific port. | |
| bool | config_set_dmx_direction (uint8_t port_index, config_direction_t direction) |
| Sets the data direction for a specific port in RAM. | |
| void | config_get_wifi_sta_config (wifi_config_t *dest) |
| Gets the Wi-Fi Station mode configuration. | |
| bool | config_set_wifi_sta_config (const wifi_config_t *src) |
| Sets the Wi-Fi Station mode configuration in RAM. | |
| void | config_get_wifi_ap_config (wifi_config_t *dest) |
| Gets the Wi-Fi Access Point mode configuration. | |
| bool | config_set_wifi_ap_config (const wifi_config_t *src) |
| Sets the Wi-Fi Access Point mode configuration in RAM. | |
| config_button_action_t | config_get_button_action (app_button_event_t event) |
| Retrieves the action assigned to a specific button event. | |
| bool | config_set_button_action (app_button_event_t event, config_button_action_t action) |
| Assigns a new action to a specific button event in RAM. | |
Variables | |
| static config_storage_t | s_config |
| Private runtime memory footprint of the active configuration. | |
| static SemaphoreHandle_t | s_config_mutex = NULL |
| Mutex guard ensuring thread-safe operations on the shared configuration context. | |
| static bool | s_is_initialized = false |
| Tracks if the configuration component has been successfully initialized. | |
| static bool | s_is_dirty = false |
| Set to true if any RAM values diverge from the persisted flash storage state. | |
Thread-safe configuration component utilizing NVS for ESP32. Implements the private storage structures, mutex protection mechanisms, and input validation logic defined in config.h.
Definition in file config.c.
| #define APP_CONFIG_MAGIC 0x43444D58 |
ASCII for 'CDMX'
Definition at line 28 of file config.c.
Referenced by config_init(), and load_factory_defaults().
| #define APP_CONFIG_VERSION 4 |
Incremented when struct layout changes
Definition at line 29 of file config.c.
Referenced by config_init(), and load_factory_defaults().
| #define LOCK | ( | ) |
Locks the configuration mutex for exclusive access.
Definition at line 86 of file config.c.
Referenced by config_get_button_action(), config_get_connection(), config_get_dmx_direction(), config_get_dmx_universe(), config_get_ip_method(), config_get_led_brightness(), config_get_wifi_ap_config(), config_get_wifi_sta_config(), config_reset_defaults(), config_save(), config_set_button_action(), config_set_connection(), config_set_dmx_direction(), config_set_dmx_universe(), config_set_ip_method(), config_set_led_brightness(), config_set_wifi_ap_config(), and config_set_wifi_sta_config().
| #define NVS_BLOB_KEY "config_blob" |
Key under which the entire config blob is stored in NVS.
Definition at line 24 of file config.c.
Referenced by config_init(), and config_save().
| #define NVS_NAMESPACE "app_config" |
NVS storage namespace for configuration data.
Definition at line 23 of file config.c.
Referenced by config_init(), and config_save().
| #define UNLOCK | ( | ) |
Unlocks the configuration mutex after access.
Definition at line 90 of file config.c.
Referenced by config_get_button_action(), config_get_connection(), config_get_dmx_direction(), config_get_dmx_universe(), config_get_ip_method(), config_get_led_brightness(), config_get_wifi_ap_config(), config_get_wifi_sta_config(), config_reset_defaults(), config_save(), config_set_button_action(), config_set_connection(), config_set_dmx_direction(), config_set_dmx_universe(), config_set_ip_method(), config_set_led_brightness(), config_set_wifi_ap_config(), and config_set_wifi_sta_config().
| config_button_action_t config_get_button_action | ( | app_button_event_t | event | ) |
Retrieves the action assigned to a specific button event.
| [in] | event | The button event to query. |
Definition at line 447 of file config.c.
References APP_BUTTON_ACTION_NONE, APP_BUTTON_EVENT_DOUBLE_CLICK, APP_BUTTON_EVENT_MULTIPLE_CLICK, APP_BUTTON_EVENT_SINGLE_CLICK, LOCK, s_config, s_is_initialized, and UNLOCK.
Referenced by iot_button_double_click_cb(), iot_button_multiple_click_cb(), and iot_button_single_click_cb().
| config_connection_t config_get_connection | ( | void | ) |
Gets the current network connection type.
Definition at line 243 of file config.c.
References APP_CONFIG_DEFAULT_CONNECTION, LOCK, s_config, s_is_initialized, and UNLOCK.
| config_direction_t config_get_dmx_direction | ( | uint8_t | port_index | ) |
Gets the data direction for a specific port.
| [in] | port_index | Index of the port (0 to APP_CONFIG_DMX_PORT_COUNT - 1). |
Definition at line 342 of file config.c.
References APP_CONFIG_DEFAULT_DMX_DIR, APP_CONFIG_DMX_PORT_COUNT, LOCK, s_config, s_is_initialized, and UNLOCK.
| uint16_t config_get_dmx_universe | ( | uint8_t | port_index | ) |
Gets the configured DMX universe for a specific port.
| [in] | port_index | Index of the port (0 to APP_CONFIG_DMX_PORT_COUNT - 1). |
Definition at line 318 of file config.c.
References APP_CONFIG_DMX_PORT_COUNT, APP_CONFIG_INVALID_UNIVERSE, LOCK, s_config, s_is_initialized, and UNLOCK.
| config_ip_method_t config_get_ip_method | ( | void | ) |
Gets the current IP allocation method.
Definition at line 267 of file config.c.
References APP_CONFIG_DEFAULT_IP_METHOD, LOCK, s_config, s_is_initialized, and UNLOCK.
| uint8_t config_get_led_brightness | ( | void | ) |
Gets the current status LED brightness level.
Definition at line 290 of file config.c.
References APP_CONFIG_DEFAULT_LED_BRIGHTNESS, LOCK, s_config, s_is_initialized, and UNLOCK.
Referenced by app_main(), and execute_button_action().
| void config_get_wifi_ap_config | ( | wifi_config_t * | dest | ) |
| void config_get_wifi_sta_config | ( | wifi_config_t * | dest | ) |
| esp_err_t config_init | ( | void | ) |
Initializes the configuration component.
Sets up internal mutexes and loads the persisted configuration blob from NVS.
Definition at line 136 of file config.c.
References APP_CONFIG_MAGIC, APP_CONFIG_VERSION, load_factory_defaults(), LOGE, LOGI, LOGW, NVS_BLOB_KEY, NVS_NAMESPACE, s_config, s_config_mutex, s_is_dirty, and s_is_initialized.
Referenced by app_main().
| esp_err_t config_reset_defaults | ( | void | ) |
Resets all configuration settings back to factory defaults.
Definition at line 194 of file config.c.
References load_factory_defaults(), LOCK, LOGI, s_is_initialized, and UNLOCK.
Referenced by app_main().
| esp_err_t config_save | ( | void | ) |
Flushes all staged RAM changes permanently to the non-volatile storage.
Definition at line 204 of file config.c.
References LOCK, LOGE, LOGI, NVS_BLOB_KEY, NVS_NAMESPACE, s_config, s_is_dirty, s_is_initialized, and UNLOCK.
Referenced by app_main(), and execute_button_action().
| bool config_set_button_action | ( | app_button_event_t | event, |
| config_button_action_t | action ) |
Assigns a new action to a specific button event in RAM.
| [in] | event | The button event to modify. |
| [in] | action | The config_button_action_t to assign. |
Definition at line 477 of file config.c.
References APP_BUTTON_ACTION_MAX, APP_BUTTON_EVENT_DOUBLE_CLICK, APP_BUTTON_EVENT_MULTIPLE_CLICK, APP_BUTTON_EVENT_SINGLE_CLICK, LOCK, s_config, s_is_dirty, s_is_initialized, and UNLOCK.
| bool config_set_connection | ( | config_connection_t | conn | ) |
Sets the network connection type in RAM.
| [in] | conn | New connection mode to apply. |
Definition at line 252 of file config.c.
References APP_CONFIG_CONN_ETHERNET, LOCK, LOGI, s_config, s_is_dirty, s_is_initialized, and UNLOCK.
| bool config_set_dmx_direction | ( | uint8_t | port_index, |
| config_direction_t | direction ) |
Sets the data direction for a specific port in RAM.
| [in] | port_index | Index of the port (0 to APP_CONFIG_DMX_PORT_COUNT - 1). |
| [in] | direction | New direction (Input/Output). |
Definition at line 351 of file config.c.
References APP_CONFIG_DIR_INPUT, APP_CONFIG_DMX_PORT_COUNT, LOCK, s_config, s_is_dirty, s_is_initialized, and UNLOCK.
| bool config_set_dmx_universe | ( | uint8_t | port_index, |
| uint16_t | universe ) |
Sets the DMX universe for a specific port in RAM.
| [in] | port_index | Index of the port (0 to APP_CONFIG_DMX_PORT_COUNT - 1). |
| [in] | universe | DMX Universe number (typically 0 - 32768). |
Definition at line 327 of file config.c.
References APP_CONFIG_DMX_PORT_COUNT, APP_CONFIG_INVALID_UNIVERSE, LOCK, s_config, s_is_dirty, s_is_initialized, and UNLOCK.
| bool config_set_ip_method | ( | config_ip_method_t | method | ) |
Sets the IP assignment method in RAM.
| [in] | method | New IP allocation method to apply. |
Definition at line 276 of file config.c.
References APP_CONFIG_IP_DHCP, LOCK, s_config, s_is_dirty, s_is_initialized, and UNLOCK.
| bool config_set_led_brightness | ( | uint8_t | brightness | ) |
Sets the status LED brightness level in RAM.
| [in] | brightness | Desired brightness (0 - 255). |
Definition at line 299 of file config.c.
References led_set_brightness(), LOCK, LOGI, s_config, s_is_dirty, s_is_initialized, and UNLOCK.
Referenced by execute_button_action().
| bool config_set_wifi_ap_config | ( | const wifi_config_t * | src | ) |
Sets the Wi-Fi Access Point mode configuration in RAM.
| [in] | src | Pointer to a wifi_config_t struct containing the new config. |
Definition at line 415 of file config.c.
References LOCK, LOGE, s_config, s_is_dirty, s_is_initialized, and UNLOCK.
| bool config_set_wifi_sta_config | ( | const wifi_config_t * | src | ) |
Sets the Wi-Fi Station mode configuration in RAM.
| [in] | src | Pointer to a wifi_config_t struct containing the new config. |
Definition at line 379 of file config.c.
References LOCK, LOGE, s_config, s_is_dirty, s_is_initialized, and UNLOCK.
|
static |
Restores all configuration fields to their factory-defined values in RAM.
Sets the magic number, version, and all functional parameters (Wi-Fi, DMX, LED). Marks the configuration as dirty to trigger a save on next config_save() call.
Definition at line 102 of file config.c.
References APP_CONFIG_DEFAULT_AP_PASSWORD, APP_CONFIG_DEFAULT_AP_SSID_PREFIX, APP_CONFIG_DEFAULT_CONNECTION, APP_CONFIG_DEFAULT_DMX_DIR, APP_CONFIG_DEFAULT_DOUBLE_CLICK_ACT, APP_CONFIG_DEFAULT_IP_METHOD, APP_CONFIG_DEFAULT_LED_BRIGHTNESS, APP_CONFIG_DEFAULT_MULTI_CLICK_ACT, APP_CONFIG_DEFAULT_SINGLE_CLICK_ACT, APP_CONFIG_DEFAULT_STA_PASSWORD, APP_CONFIG_DEFAULT_STA_SSID, APP_CONFIG_DEFAULT_START_UNIVERSE, APP_CONFIG_DMX_PORT_COUNT, APP_CONFIG_MAGIC, APP_CONFIG_VERSION, s_config, and s_is_dirty.
Referenced by config_init(), and config_reset_defaults().
|
static |
Private runtime memory footprint of the active configuration.
Definition at line 65 of file config.c.
Referenced by config_get_button_action(), config_get_connection(), config_get_dmx_direction(), config_get_dmx_universe(), config_get_ip_method(), config_get_led_brightness(), config_get_wifi_ap_config(), config_get_wifi_sta_config(), config_init(), config_save(), config_set_button_action(), config_set_connection(), config_set_dmx_direction(), config_set_dmx_universe(), config_set_ip_method(), config_set_led_brightness(), config_set_wifi_ap_config(), config_set_wifi_sta_config(), and load_factory_defaults().
|
static |
Mutex guard ensuring thread-safe operations on the shared configuration context.
Definition at line 71 of file config.c.
Referenced by config_init().
|
static |
Set to true if any RAM values diverge from the persisted flash storage state.
Definition at line 83 of file config.c.
Referenced by config_init(), config_save(), config_set_button_action(), config_set_connection(), config_set_dmx_direction(), config_set_dmx_universe(), config_set_ip_method(), config_set_led_brightness(), config_set_wifi_ap_config(), config_set_wifi_sta_config(), and load_factory_defaults().
|
static |
Tracks if the configuration component has been successfully initialized.
Definition at line 77 of file config.c.
Referenced by config_get_button_action(), config_get_connection(), config_get_dmx_direction(), config_get_dmx_universe(), config_get_ip_method(), config_get_led_brightness(), config_get_wifi_ap_config(), config_get_wifi_sta_config(), config_init(), config_reset_defaults(), config_save(), config_set_button_action(), config_set_connection(), config_set_dmx_direction(), config_set_dmx_universe(), config_set_ip_method(), config_set_led_brightness(), config_set_wifi_ap_config(), and config_set_wifi_sta_config().