|
MeshX 0.4
This repository provides an implementation for Bluetooth Low Energy (BLE) Mesh network nodes. The project allows you to create BLE mesh nodes that can communicate with each other, enabling the development of smart home solutions or other IoT-based applications.
|
MeshX GPIO KV Engine Serialization Format. More...
#include <stdint.h>#include <stdbool.h>#include <stddef.h>#include <stdio.h>#include "interface/utils/meshx_fal_interface.h"#include "meshx_gpio_types.h"Go to the source code of this file.
Data Structures | |
| struct | meshx_gpio_config_header_kv_t |
| Header for serialized GPIO configuration stored in KV Engine. More... | |
| struct | meshx_gpio_pin_config_kv_t |
| Serialized GPIO pin configuration for KV Engine storage. More... | |
| struct | meshx_gpio_pwm_config_kv_t |
| Serialized PWM configuration for KV Engine storage. More... | |
| struct | meshx_gpio_intr_config_kv_t |
| Serialized interrupt configuration for KV Engine storage. More... | |
| struct | meshx_gpio_pin_state_kv_t |
| Serialized GPIO pin state for KV Engine storage. More... | |
Macros | |
| #define | MESHX_GPIO_CONFIG_VERSION_CURRENT 1 |
| Current GPIO configuration serialization format version. | |
| #define | MESHX_GPIO_CONFIG_VERSION_MIN 1 |
| Minimum supported version (for backward compatibility). | |
| #define | MESHX_GPIO_CONFIG_VERSION_MAX 1 |
| Maximum supported version (for forward compatibility). | |
| #define | MESHX_GPIO_KV_PRODUCT_NAME_MAX_LEN 16 |
| Maximum length for product name in key prefix. | |
| #define | MESHX_GPIO_KV_KEY_MAX_LEN 32 |
| Maximum total key length (KV Engine limit is 32). | |
| #define | MESHX_GPIO_KV_KEY_CONFIG "config" |
| Key suffix for main GPIO configuration. | |
| #define | MESHX_GPIO_KV_KEY_STATE "state" |
| Key suffix for GPIO pin state. | |
| #define | MESHX_GPIO_KV_KEY_PWM "pwm" |
| Key suffix for PWM configuration. | |
| #define | MESHX_GPIO_KV_KEY_INTR "intr" |
| Key suffix for interrupt configuration. | |
| #define | MESHX_GPIO_CONFIG_HEADER_SIZE sizeof(meshx_gpio_config_header_kv_t) |
| Size of configuration header. | |
| #define | MESHX_GPIO_PIN_CONFIG_SIZE sizeof(meshx_gpio_pin_config_kv_t) |
| Size of basic pin configuration. | |
| #define | MESHX_GPIO_PWM_CONFIG_SIZE sizeof(meshx_gpio_pwm_config_kv_t) |
| Size of PWM configuration extension. | |
| #define | MESHX_GPIO_INTR_CONFIG_SIZE sizeof(meshx_gpio_intr_config_kv_t) |
| Size of interrupt configuration extension. | |
| #define | MESHX_GPIO_PIN_STATE_SIZE sizeof(meshx_gpio_pin_state_kv_t) |
| Size of pin state record. | |
| #define | MESHX_GPIO_PIN_MAX_SIZE |
| Maximum size per pin (including extensions). | |
| #define | MESHX_GPIO_CONFIG_TOTAL_SIZE(pin_count) |
| Calculate total config size for given pin count. | |
| #define | MESHX_GPIO_CONFIG_FLAG_HAS_PWM (1 << 0) |
| Flag: Configuration has PWM extensions. | |
| #define | MESHX_GPIO_CONFIG_FLAG_HAS_INTR (1 << 1) |
| Flag: Configuration has interrupt extensions. | |
| #define | MESHX_GPIO_CONFIG_FLAG_MIGRATED (1 << 2) |
| Flag: Configuration is migrated from older version. | |
| #define | MESHX_GPIO_CONFIG_FLAG_READ_ONLY (1 << 3) |
| Flag: Configuration is in read-only mode. | |
| #define | MESHX_GPIO_CONFIG_TYPE_NONE 0 |
| No extended configuration. | |
| #define | MESHX_GPIO_CONFIG_TYPE_PWM 1 |
| PWM configuration follows. | |
| #define | MESHX_GPIO_CONFIG_TYPE_INTR 2 |
| Interrupt configuration follows. | |
Functions | |
| static uint8_t | meshx_gpio_kv_make_config_key (const char *product_name, char *buf, uint8_t buf_len) |
| Construct KV Engine key for GPIO configuration. | |
| static uint8_t | meshx_gpio_kv_make_state_key (const char *product_name, uint8_t logical_pin, char *buf, uint8_t buf_len) |
| Construct KV Engine key for GPIO pin state. | |
| static uint8_t | meshx_gpio_kv_make_pwm_key (const char *product_name, uint8_t logical_pin, char *buf, uint8_t buf_len) |
| Construct KV Engine key for PWM configuration. | |
| static uint8_t | meshx_gpio_kv_make_intr_key (const char *product_name, uint8_t logical_pin, char *buf, uint8_t buf_len) |
| Construct KV Engine key for interrupt configuration. | |
| static uint16_t | meshx_gpio_kv_calc_crc16 (const uint8_t *data, uint32_t len) |
| Calculate CRC16 compatible with KV Engine. | |
| static bool | meshx_gpio_kv_verify_crc16 (const uint8_t *data, uint32_t len) |
| Verify CRC16 of serialized GPIO configuration. | |
| static void | meshx_gpio_kv_init_header (meshx_gpio_config_header_kv_t *header, uint8_t pin_count) |
| Initialize a GPIO configuration header. | |
| static void | meshx_gpio_kv_finalize_crc16 (uint8_t *data, uint32_t len) |
| Calculate and set CRC16 for serialized configuration. | |
| static void | meshx_gpio_kv_serialize_pin (const meshx_gpio_pin_config_t *src, meshx_gpio_pin_config_kv_t *dst) |
| Convert runtime pin config to serialized format. | |
| static void | meshx_gpio_kv_deserialize_pin (const meshx_gpio_pin_config_kv_t *src, meshx_gpio_pin_config_t *dst) |
| Convert serialized pin config to runtime format. | |
| static void | meshx_gpio_kv_serialize_pwm (const meshx_gpio_pin_config_t *src, meshx_gpio_pwm_config_kv_t *dst) |
| Serialize PWM configuration. | |
| static void | meshx_gpio_kv_deserialize_pwm (const meshx_gpio_pwm_config_kv_t *src, meshx_gpio_pin_config_t *dst) |
| Deserialize PWM configuration. | |
| static void | meshx_gpio_kv_serialize_intr (const meshx_gpio_pin_config_t *src, meshx_gpio_intr_config_kv_t *dst) |
| Serialize interrupt configuration. | |
| static void | meshx_gpio_kv_deserialize_intr (const meshx_gpio_intr_config_kv_t *src, meshx_gpio_pin_config_t *dst) |
| Deserialize interrupt configuration. | |
| static bool | meshx_gpio_kv_is_version_supported (uint8_t version) |
| Check if a configuration version is supported. | |
| static bool | meshx_gpio_kv_needs_migration (uint8_t from_version, uint8_t to_version) |
| Get migration requirement between versions. | |
| meshx_err_t | meshx_gpio_kv_init (const meshx_fal_partition_t *kv_partition, const char *product_name) |
| Initialize GPIO KV Engine persistence. | |
| meshx_err_t | meshx_gpio_save_config_to_kv (const meshx_gpio_pin_config_t *configs, uint8_t pin_count) |
| Save GPIO configuration to KV Engine. | |
| meshx_err_t | meshx_gpio_load_config_from_kv (meshx_gpio_pin_config_t *configs, uint8_t max_pins, uint8_t *out_pin_count) |
| Load GPIO configuration from KV Engine. | |
| meshx_err_t | meshx_gpio_config_exists_in_kv (bool *exists) |
| Check if GPIO configuration exists in KV Engine. | |
| meshx_err_t | meshx_gpio_save_pin_state_to_kv (uint8_t logical_pin, const meshx_gpio_pin_state_t *state) |
| Save current pin state to KV Engine. | |
| meshx_err_t | meshx_gpio_load_pin_state_from_kv (uint8_t logical_pin, meshx_gpio_pin_state_t *state) |
| Load pin state from KV Engine. | |
| meshx_err_t | meshx_gpio_export_config (const meshx_gpio_pin_config_t *configs, uint8_t pin_count, uint8_t *buf, uint16_t buf_len, uint16_t *out_size) |
| Export GPIO configuration to serialized format. | |
| meshx_err_t | meshx_gpio_import_config (const uint8_t *buf, uint16_t buf_len, meshx_gpio_pin_config_t *configs, uint8_t max_pins, uint8_t *out_pin_count) |
| Import GPIO configuration from serialized format. | |
| meshx_err_t | meshx_gpio_clear_config_in_kv (void) |
| Clear GPIO configuration from KV Engine. | |
| meshx_err_t | meshx_gpio_kv_deinit (void) |
| Deinitialize GPIO KV Engine persistence. | |
| bool | meshx_gpio_kv_is_initialized (void) |
| Check if GPIO KV persistence is initialized. | |
MeshX GPIO KV Engine Serialization Format.
This file defines the binary serialization structures for GPIO configuration persistence using the MeshX KV Engine. The format is designed for:
| #define MESHX_GPIO_CONFIG_FLAG_HAS_INTR (1 << 1) |
Flag: Configuration has interrupt extensions.
| #define MESHX_GPIO_CONFIG_FLAG_HAS_PWM (1 << 0) |
Flag: Configuration has PWM extensions.
| #define MESHX_GPIO_CONFIG_FLAG_MIGRATED (1 << 2) |
Flag: Configuration is migrated from older version.
| #define MESHX_GPIO_CONFIG_FLAG_READ_ONLY (1 << 3) |
Flag: Configuration is in read-only mode.
| #define MESHX_GPIO_CONFIG_HEADER_SIZE sizeof(meshx_gpio_config_header_kv_t) |
Size of configuration header.
| #define MESHX_GPIO_CONFIG_TOTAL_SIZE | ( | pin_count | ) |
Calculate total config size for given pin count.
| #define MESHX_GPIO_CONFIG_TYPE_INTR 2 |
Interrupt configuration follows.
| #define MESHX_GPIO_CONFIG_TYPE_NONE 0 |
No extended configuration.
| #define MESHX_GPIO_CONFIG_TYPE_PWM 1 |
PWM configuration follows.
| #define MESHX_GPIO_CONFIG_VERSION_CURRENT 1 |
Current GPIO configuration serialization format version.
| #define MESHX_GPIO_CONFIG_VERSION_MAX 1 |
Maximum supported version (for forward compatibility).
| #define MESHX_GPIO_CONFIG_VERSION_MIN 1 |
Minimum supported version (for backward compatibility).
| #define MESHX_GPIO_INTR_CONFIG_SIZE sizeof(meshx_gpio_intr_config_kv_t) |
Size of interrupt configuration extension.
| #define MESHX_GPIO_KV_KEY_CONFIG "config" |
Key suffix for main GPIO configuration.
| #define MESHX_GPIO_KV_KEY_INTR "intr" |
Key suffix for interrupt configuration.
| #define MESHX_GPIO_KV_KEY_MAX_LEN 32 |
Maximum total key length (KV Engine limit is 32).
| #define MESHX_GPIO_KV_KEY_PWM "pwm" |
Key suffix for PWM configuration.
| #define MESHX_GPIO_KV_KEY_STATE "state" |
Key suffix for GPIO pin state.
| #define MESHX_GPIO_KV_PRODUCT_NAME_MAX_LEN 16 |
Maximum length for product name in key prefix.
| #define MESHX_GPIO_PIN_CONFIG_SIZE sizeof(meshx_gpio_pin_config_kv_t) |
Size of basic pin configuration.
| #define MESHX_GPIO_PIN_MAX_SIZE |
Maximum size per pin (including extensions).
| #define MESHX_GPIO_PIN_STATE_SIZE sizeof(meshx_gpio_pin_state_kv_t) |
Size of pin state record.
| #define MESHX_GPIO_PWM_CONFIG_SIZE sizeof(meshx_gpio_pwm_config_kv_t) |
Size of PWM configuration extension.
| meshx_err_t meshx_gpio_clear_config_in_kv | ( | void | ) |
Clear GPIO configuration from KV Engine.
Removes the stored GPIO configuration, forcing fallback to defaults on next load.
| meshx_err_t meshx_gpio_config_exists_in_kv | ( | bool * | exists | ) |
Check if GPIO configuration exists in KV Engine.
| [out] | exists | true if configuration exists, false otherwise |
| meshx_err_t meshx_gpio_export_config | ( | const meshx_gpio_pin_config_t * | configs, |
| uint8_t | pin_count, | ||
| uint8_t * | buf, | ||
| uint16_t | buf_len, | ||
| uint16_t * | out_size ) |
Export GPIO configuration to serialized format.
Exports the configuration in binary format for transfer to another device.
| configs | Array of pin configurations | |
| pin_count | Number of pins | |
| [out] | buf | Output buffer |
| buf_len | Buffer length | |
| [out] | out_size | Actual exported size |
| meshx_err_t meshx_gpio_import_config | ( | const uint8_t * | buf, |
| uint16_t | buf_len, | ||
| meshx_gpio_pin_config_t * | configs, | ||
| uint8_t | max_pins, | ||
| uint8_t * | out_pin_count ) |
Import GPIO configuration from serialized format.
Imports configuration from binary format received from another device.
| buf | Input buffer | |
| buf_len | Buffer length | |
| [out] | configs | Array to store imported configurations |
| max_pins | Maximum pins that can be stored | |
| [out] | out_pin_count | Actual number of pins imported |
|
inlinestatic |
Calculate CRC16 compatible with KV Engine.
Uses the same CRC-16 algorithm as meshx_kv_engine.c (Modbus CRC-16 with polynomial 0xA001). This ensures the GPIO subsystem can independently verify data integrity.
| data | Pointer to data buffer |
| len | Length of data in bytes |
| meshx_err_t meshx_gpio_kv_deinit | ( | void | ) |
Deinitialize GPIO KV Engine persistence.
Cleans up KV persistence resources. Does not affect the underlying KV Engine partition.
|
inlinestatic |
Deserialize interrupt configuration.
| src | Source serialized configuration |
| dst | Destination runtime configuration |
|
inlinestatic |
Convert serialized pin config to runtime format.
| src | Source serialized configuration |
| dst | Destination runtime configuration |
|
inlinestatic |
Deserialize PWM configuration.
| src | Source serialized configuration |
| dst | Destination runtime configuration |
|
inlinestatic |
Calculate and set CRC16 for serialized configuration.
| data | Pointer to serialized data buffer (including header) |
| len | Total length of data |
| meshx_err_t meshx_gpio_kv_init | ( | const meshx_fal_partition_t * | kv_partition, |
| const char * | product_name ) |
Initialize GPIO KV Engine persistence.
This function initializes the KV Engine for GPIO configuration storage. It must be called before any other GPIO KV functions.
| kv_partition | Pointer to the flash partition to use for KV storage |
| product_name | Product name for key prefix (max 16 chars) |
|
inlinestatic |
Initialize a GPIO configuration header.
| header | Pointer to header to initialize |
| pin_count | Number of pins in configuration |
| bool meshx_gpio_kv_is_initialized | ( | void | ) |
Check if GPIO KV persistence is initialized.
|
inlinestatic |
Check if a configuration version is supported.
| version | Version number to check |
|
inlinestatic |
Construct KV Engine key for GPIO configuration.
| product_name | Product name (max 16 chars) |
| buf | Buffer to store the key |
| buf_len | Buffer length |
|
inlinestatic |
Construct KV Engine key for interrupt configuration.
| product_name | Product name (max 16 chars) |
| logical_pin | Logical pin number |
| buf | Buffer to store the key |
| buf_len | Buffer length |
|
inlinestatic |
Construct KV Engine key for PWM configuration.
| product_name | Product name (max 16 chars) |
| logical_pin | Logical pin number |
| buf | Buffer to store the key |
| buf_len | Buffer length |
|
inlinestatic |
Construct KV Engine key for GPIO pin state.
| product_name | Product name (max 16 chars) |
| logical_pin | Logical pin number |
| buf | Buffer to store the key |
| buf_len | Buffer length |
|
inlinestatic |
Get migration requirement between versions.
| from_version | Source version |
| to_version | Target version |
|
inlinestatic |
|
inlinestatic |
Convert runtime pin config to serialized format.
| src | Source runtime configuration |
| dst | Destination serialized configuration |
|
inlinestatic |
Serialize PWM configuration.
| src | Source runtime PWM configuration |
| dst | Destination serialized configuration |
|
inlinestatic |
Verify CRC16 of serialized GPIO configuration.
| data | Pointer to serialized data (including header) |
| len | Total length of data |
| meshx_err_t meshx_gpio_load_config_from_kv | ( | meshx_gpio_pin_config_t * | configs, |
| uint8_t | max_pins, | ||
| uint8_t * | out_pin_count ) |
Load GPIO configuration from KV Engine.
This function loads and deserializes GPIO configuration from KV Engine. If the configuration is not found or corrupted, returns MESHX_NOT_FOUND to allow fallback to compiled defaults.
| configs | Array to store loaded pin configurations | |
| max_pins | Maximum pins that can be stored | |
| [out] | out_pin_count | Actual number of pins loaded |
| meshx_err_t meshx_gpio_load_pin_state_from_kv | ( | uint8_t | logical_pin, |
| meshx_gpio_pin_state_t * | state ) |
Load pin state from KV Engine.
Loads previously persisted runtime state of a GPIO pin.
| logical_pin | Logical pin number | |
| [out] | state | Pointer to store loaded pin state |
| meshx_err_t meshx_gpio_save_config_to_kv | ( | const meshx_gpio_pin_config_t * | configs, |
| uint8_t | pin_count ) |
Save GPIO configuration to KV Engine.
This function serializes and saves the GPIO configuration to KV Engine with versioning and CRC validation.
| configs | Array of pin configurations to save |
| pin_count | Number of pins in configuration |
| meshx_err_t meshx_gpio_save_pin_state_to_kv | ( | uint8_t | logical_pin, |
| const meshx_gpio_pin_state_t * | state ) |
Save current pin state to KV Engine.
Persists the runtime state of a GPIO pin across reboots.
| logical_pin | Logical pin number |
| state | Pointer to pin state to save |