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.
Loading...
Searching...
No Matches
meshx_gpio_types.h
Go to the documentation of this file.
1/**
2 * @file meshx_gpio_types.h
3 * @brief MeshX GPIO Type Definitions
4 *
5 * This file defines data structures and types for GPIO configuration and state.
6 *
7 * @author MeshX Team
8 * @date 2024
9 */
10
11#ifndef __MESHX_GPIO_TYPES_H
12#define __MESHX_GPIO_TYPES_H
13
14#include <stdint.h>
15#include <stdbool.h>
16#include <stddef.h>
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22/**
23 * @brief GPIO Interrupt Trigger Types
24 *
25 * Forward declaration for use in meshx_gpio_pin_state_t.
26 * Full definition is in meshx_gpio.h
27 */
28typedef enum {
29 MESHX_GPIO_INTR_DISABLED = 0, /**< Interrupt disabled */
30 MESHX_GPIO_INTR_POSITIVE_EDGE, /**< Positive edge trigger */
31 MESHX_GPIO_INTR_NEGATIVE_EDGE, /**< Negative edge trigger */
32 MESHX_GPIO_INTR_ANY_EDGE, /**< Any edge trigger */
33 MESHX_GPIO_INTR_LOW_LEVEL, /**< Low level trigger */
34 MESHX_GPIO_INTR_HIGH_LEVEL, /**< High level trigger */
35 MESHX_GPIO_INTR_MAX /**< Maximum interrupt type */
37
38/**
39 * @brief GPIO Interrupt Callback Type (forward declaration)
40 *
41 * Full documentation is in meshx_gpio.h
42 */
43typedef void (*meshx_gpio_intr_cb_t)(uint8_t logical_pin, void *user_data);
44
45/**
46 * @brief GPIO Pin Configuration Structure
47 *
48 * This structure defines the configuration for a single GPIO pin.
49 * It is used both for compile-time configuration and runtime state.
50 */
51typedef struct {
52 uint8_t logical_pin; /**< Logical pin number (0-255) */
53 uint8_t physical_pin; /**< Physical pin number (BSP-specific) */
54 uint8_t mode; /**< Pin mode (meshx_gpio_mode_t) */
55 uint8_t pull; /**< Pull resistor setting (meshx_gpio_pull_t) */
56 uint8_t drive_strength; /**< Drive strength (meshx_gpio_drive_t) */
57 uint8_t initial_level; /**< Initial output level (0 or 1) */
58 bool signal_inversion; /**< Signal inversion (active-low) */
59
60 /** @brief Mode-specific configuration (union based on mode) */
61 union {
62 /** @brief Interrupt configuration (for input pins with interrupts) */
63 struct {
64 uint8_t trigger; /**< Interrupt trigger type (meshx_gpio_intr_type_t) */
65 uint8_t task_priority; /**< Interrupt task priority */
66 uint16_t task_stack_size; /**< Interrupt task stack size */
67 } interrupt;
68
69 /** @brief PWM configuration (for PWM output pins) */
70 struct {
71 uint32_t frequency; /**< PWM frequency in Hz */
72 uint8_t duty_cycle; /**< Initial duty cycle (0-100%) */
73 uint8_t resolution; /**< PWM resolution in bits */
74 uint8_t channel; /**< Hardware PWM channel */
75 } pwm;
76
77 /** @brief Custom function configuration */
78 struct {
79 uint16_t function_id; /**< Custom function ID */
80 uint32_t args[4]; /**< Custom function arguments */
81 uint8_t arg_count; /**< Number of arguments */
82 } custom;
83 } mode_config;
85
86/**
87 * @brief GPIO Pin State Structure
88 *
89 * This structure tracks the runtime state of a GPIO pin.
90 */
91typedef struct {
92 uint8_t current_level; /**< Current pin level (0 or 1) */
93 bool interrupt_registered; /**< Whether interrupt is registered */
94 meshx_gpio_intr_type_t intr_type; /**< Interrupt type (if registered) */
95 meshx_gpio_intr_cb_t intr_callback; /**< Interrupt callback function pointer */
96 void *intr_user_data; /**< Interrupt user data pointer */
97
98 /** @brief Mode-specific runtime state */
99 union {
100 /** @brief PWM runtime state */
101 struct {
102 bool started; /**< Whether PWM is started */
103 uint32_t frequency; /**< Current PWM frequency */
104 uint8_t duty_cycle; /**< Current PWM duty cycle */
105 } pwm;
106
107 /** @brief Custom function runtime state */
108 struct {
109 void *custom_data; /**< Custom function data pointer */
110 size_t data_size; /**< Custom data size */
111 } custom;
112 } mode_state;
114
115/**
116 * @brief GPIO Configuration Header
117 *
118 * This structure is used for serialized GPIO configuration storage
119 * in KV Engine with versioning and CRC validation.
120 */
121#pragma pack(push, 1)
122typedef struct {
123 uint8_t version; /**< Format version (1) */
124 uint8_t pin_count; /**< Number of configured pins */
125 uint16_t crc16; /**< CRC16 checksum (compatible with KV Engine) */
126 uint8_t reserved[3]; /**< Reserved for future use */
128
129/**
130 * @brief Serialized GPIO Pin Configuration
131 *
132 * Compact representation for KV Engine storage.
133 */
134typedef struct {
135 uint8_t logical_pin;
137 uint8_t mode;
138 uint8_t pull;
142 uint8_t reserved;
144
145/**
146 * @brief Serialized PWM Configuration
147 */
148typedef struct {
149 uint32_t frequency;
150 uint8_t duty_cycle;
151 uint8_t resolution;
152 uint8_t channel;
153 uint8_t reserved[1];
155
156/**
157 * @brief Serialized Interrupt Configuration
158 */
164#pragma pack(pop)
165
166/**
167 * @brief Hosted Mode State
168 */
169typedef enum {
170 MESHX_GPIO_MODE_NON_HOSTED = 0, /**< Non-hosted mode (direct GPIO access) */
171 MESHX_GPIO_MODE_HOSTED, /**< Hosted mode (UART transport) */
172 MESHX_GPIO_MODE_TRANSITIONING /**< Mode transition in progress */
174
175/**
176 * @brief Hosted Mode GPIO Event
177 *
178 * Structure for serializing GPIO events in hosted mode.
179 */
180typedef struct {
181 uint8_t event_type; /**< Event type (0 = level change, 1 = interrupt) */
182 uint8_t logical_pin; /**< Logical pin number */
183 uint8_t value; /**< Event value (level or interrupt type) */
184 uint32_t timestamp; /**< Event timestamp */
186
187#ifdef __cplusplus
188}
189#endif
190
191#endif /* __MESHX_GPIO_TYPES_H */
void(* meshx_gpio_intr_cb_t)(uint8_t logical_pin, void *user_data)
GPIO Interrupt Callback Function.
Definition meshx_gpio.h:80
meshx_gpio_intr_type_t
GPIO Interrupt Trigger Types.
Definition meshx_gpio_types.h:28
@ MESHX_GPIO_INTR_DISABLED
Definition meshx_gpio_types.h:29
@ MESHX_GPIO_INTR_MAX
Definition meshx_gpio_types.h:35
@ MESHX_GPIO_INTR_POSITIVE_EDGE
Definition meshx_gpio_types.h:30
@ MESHX_GPIO_INTR_NEGATIVE_EDGE
Definition meshx_gpio_types.h:31
@ MESHX_GPIO_INTR_ANY_EDGE
Definition meshx_gpio_types.h:32
@ MESHX_GPIO_INTR_LOW_LEVEL
Definition meshx_gpio_types.h:33
@ MESHX_GPIO_INTR_HIGH_LEVEL
Definition meshx_gpio_types.h:34
meshx_gpio_hosted_mode_t
Hosted Mode State.
Definition meshx_gpio_types.h:169
@ MESHX_GPIO_MODE_TRANSITIONING
Definition meshx_gpio_types.h:172
@ MESHX_GPIO_MODE_NON_HOSTED
Definition meshx_gpio_types.h:170
@ MESHX_GPIO_MODE_HOSTED
Definition meshx_gpio_types.h:171
void(* meshx_gpio_intr_cb_t)(uint8_t logical_pin, void *user_data)
GPIO Interrupt Callback Type (forward declaration).
Definition meshx_gpio_types.h:43
GPIO Configuration Header.
Definition meshx_gpio_types.h:122
uint8_t pin_count
Definition meshx_gpio_types.h:124
uint8_t version
Definition meshx_gpio_types.h:123
uint16_t crc16
Definition meshx_gpio_types.h:125
uint8_t reserved[3]
Definition meshx_gpio_types.h:126
Hosted Mode GPIO Event.
Definition meshx_gpio_types.h:180
uint8_t logical_pin
Definition meshx_gpio_types.h:182
uint32_t timestamp
Definition meshx_gpio_types.h:184
uint8_t event_type
Definition meshx_gpio_types.h:181
uint8_t value
Definition meshx_gpio_types.h:183
Serialized Interrupt Configuration.
Definition meshx_gpio_types.h:159
uint8_t task_priority
Definition meshx_gpio_types.h:161
uint8_t trigger_type
Definition meshx_gpio_types.h:160
uint16_t task_stack_size
Definition meshx_gpio_types.h:162
Serialized GPIO Pin Configuration.
Definition meshx_gpio_types.h:134
uint8_t initial_level
Definition meshx_gpio_types.h:140
uint8_t reserved
Definition meshx_gpio_types.h:142
uint8_t pull
Definition meshx_gpio_types.h:138
uint8_t signal_inversion
Definition meshx_gpio_types.h:141
uint8_t drive_strength
Definition meshx_gpio_types.h:139
uint8_t logical_pin
Definition meshx_gpio_types.h:135
uint8_t physical_pin
Definition meshx_gpio_types.h:136
uint8_t mode
Definition meshx_gpio_types.h:137
GPIO Pin Configuration Structure.
Definition meshx_gpio_types.h:51
uint8_t logical_pin
Definition meshx_gpio_types.h:52
uint8_t channel
Definition meshx_gpio_types.h:74
uint32_t args[4]
Definition meshx_gpio_types.h:80
uint8_t resolution
Definition meshx_gpio_types.h:73
uint32_t frequency
Definition meshx_gpio_types.h:71
uint8_t task_priority
Definition meshx_gpio_types.h:65
uint8_t mode
Definition meshx_gpio_types.h:54
uint8_t drive_strength
Definition meshx_gpio_types.h:56
uint8_t arg_count
Definition meshx_gpio_types.h:81
uint16_t task_stack_size
Definition meshx_gpio_types.h:66
uint16_t function_id
Definition meshx_gpio_types.h:79
uint8_t duty_cycle
Definition meshx_gpio_types.h:72
uint8_t initial_level
Definition meshx_gpio_types.h:57
uint8_t physical_pin
Definition meshx_gpio_types.h:53
uint8_t trigger
Definition meshx_gpio_types.h:64
bool signal_inversion
Definition meshx_gpio_types.h:58
uint8_t pull
Definition meshx_gpio_types.h:55
GPIO Pin State Structure.
Definition meshx_gpio_types.h:91
bool interrupt_registered
Definition meshx_gpio_types.h:93
void * intr_user_data
Definition meshx_gpio_types.h:96
uint32_t frequency
Definition meshx_gpio_types.h:103
size_t data_size
Definition meshx_gpio_types.h:110
void * custom_data
Definition meshx_gpio_types.h:109
meshx_gpio_intr_type_t intr_type
Definition meshx_gpio_types.h:94
uint8_t current_level
Definition meshx_gpio_types.h:92
bool started
Definition meshx_gpio_types.h:102
meshx_gpio_intr_cb_t intr_callback
Definition meshx_gpio_types.h:95
uint8_t duty_cycle
Definition meshx_gpio_types.h:104
Serialized PWM Configuration.
Definition meshx_gpio_types.h:148
uint8_t reserved[1]
Definition meshx_gpio_types.h:153
uint8_t resolution
Definition meshx_gpio_types.h:151
uint32_t frequency
Definition meshx_gpio_types.h:149
uint8_t channel
Definition meshx_gpio_types.h:152
uint8_t duty_cycle
Definition meshx_gpio_types.h:150