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_io_bridge.h
Go to the documentation of this file.
1/**
2 * @file meshx_io_bridge.h
3 * @brief MeshX IO Bridge for C/C++ Boundary
4 *
5 * This file provides C interface for the C++ IO abstraction layer.
6 * It follows MeshX's C/C++ boundary patterns.
7 *
8 * @author MeshX Team
9 * @date 2024
10 */
11
12#ifndef __MESHX_IO_BRIDGE_H
13#define __MESHX_IO_BRIDGE_H
14
15#include "meshx_err.h"
16#include <stdint.h>
17#include <stdbool.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23/**
24 * @brief Opaque handle to IO instance
25 */
26typedef void* meshx_io_handle_t;
27
28/**
29 * @brief IO function types (C compatible)
30 */
43
44/**
45 * @brief IO configuration structure (C compatible)
46 */
47typedef struct {
48 uint8_t logical_pin;
49 uint8_t io_type;
50 const char* name;
51
52 union {
53 struct {
54 uint8_t mode;
55 uint8_t pull;
56 uint8_t drive;
59 } gpio;
60
61 struct {
62 uint32_t frequency;
63 uint8_t duty_cycle;
64 uint8_t resolution;
65 uint8_t channel;
66 } pwm;
67
68 struct {
69 uint16_t custom_id;
70 uint32_t custom_data;
71 } custom;
72 } config;
74
75/**
76 * @brief Create IO instance from configuration
77 *
78 * @param config IO configuration
79 * @return meshx_io_handle_t IO instance handle, NULL on failure
80 */
82
83/**
84 * @brief Destroy IO instance
85 *
86 * @param handle IO instance handle
87 */
89
90/**
91 * @brief Execute IO function
92 *
93 * @param handle IO instance handle
94 * @param function IO function to execute
95 * @param args Function arguments array
96 * @param arg_count Number of arguments
97 * @return meshx_err_t Error code
98 */
100 meshx_io_func_t function,
101 const uint32_t* args,
102 uint8_t arg_count);
103
104/**
105 * @brief Get logical pin number
106 *
107 * @param handle IO instance handle
108 * @return uint8_t Logical pin number
109 */
111
112/**
113 * @brief Get pin name
114 *
115 * @param handle IO instance handle
116 * @return const char* Pin name
117 */
118const char* meshx_io_get_name(meshx_io_handle_t handle);
119
120/**
121 * @brief Check if function is supported
122 *
123 * @param handle IO instance handle
124 * @param function IO function to check
125 * @return true if function is supported
126 * @return false if function is not supported
127 */
129 meshx_io_func_t function);
130
131/**
132 * @brief Set pin level (convenience function)
133 *
134 * @param handle IO instance handle
135 * @param level Pin level (0 = low, 1 = high)
136 * @return meshx_err_t Error code
137 */
139
140/**
141 * @brief Get pin level (convenience function)
142 *
143 * @param handle IO instance handle
144 * @param[out] level Pointer to store pin level
145 * @return meshx_err_t Error code
146 */
147meshx_err_t meshx_io_get_level(meshx_io_handle_t handle, uint8_t* level);
148
149/**
150 * @brief Toggle pin level (convenience function)
151 *
152 * @param handle IO instance handle
153 * @return meshx_err_t Error code
154 */
156
157/**
158 * @brief Initialize IO subsystem
159 *
160 * This function initializes the IO factory and registers all IO types.
161 *
162 * @return meshx_err_t Error code
163 */
165
166/**
167 * @brief Deinitialize IO subsystem
168 *
169 * @return meshx_err_t Error code
170 */
172
173#ifdef __cplusplus
174}
175#endif
176
177#endif /* __MESHX_IO_BRIDGE_H */
MeshX Error Codes.
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
meshx_io_handle_t meshx_io_create(const meshx_io_config_t *config)
Create IO instance from configuration.
Definition meshx_io_bridge.cpp:23
const char * meshx_io_get_name(meshx_io_handle_t handle)
Get pin name.
Definition meshx_io_bridge.cpp:87
bool meshx_io_is_function_supported(meshx_io_handle_t handle, meshx_io_func_t function)
Check if function is supported.
Definition meshx_io_bridge.cpp:94
meshx_err_t meshx_io_set_level(meshx_io_handle_t handle, uint8_t level)
Set pin level (convenience function).
Definition meshx_io_bridge.cpp:102
uint8_t meshx_io_get_logical_pin(meshx_io_handle_t handle)
Get logical pin number.
Definition meshx_io_bridge.cpp:80
meshx_err_t meshx_io_get_level(meshx_io_handle_t handle, uint8_t *level)
Get pin level (convenience function).
Definition meshx_io_bridge.cpp:110
void meshx_io_destroy(meshx_io_handle_t handle)
Destroy IO instance.
Definition meshx_io_bridge.cpp:56
meshx_err_t meshx_io_execute(meshx_io_handle_t handle, meshx_io_func_t function, const uint32_t *args, uint8_t arg_count)
Execute IO function.
Definition meshx_io_bridge.cpp:62
meshx_io_func_t
IO function types (C compatible).
Definition meshx_io_bridge.h:31
@ MESHX_IO_FUNC_SET_PWM_FREQUENCY
Definition meshx_io_bridge.h:36
@ MESHX_IO_FUNC_ENABLE_INTERRUPT
Definition meshx_io_bridge.h:39
@ MESHX_IO_FUNC_MAX
Definition meshx_io_bridge.h:41
@ MESHX_IO_FUNC_SET_LEVEL
Definition meshx_io_bridge.h:32
@ MESHX_IO_FUNC_UNREGISTER_INTERRUPT
Definition meshx_io_bridge.h:38
@ MESHX_IO_FUNC_CUSTOM
Definition meshx_io_bridge.h:40
@ MESHX_IO_FUNC_SET_PWM_DUTY
Definition meshx_io_bridge.h:35
@ MESHX_IO_FUNC_GET_LEVEL
Definition meshx_io_bridge.h:33
@ MESHX_IO_FUNC_REGISTER_INTERRUPT
Definition meshx_io_bridge.h:37
@ MESHX_IO_FUNC_TOGGLE
Definition meshx_io_bridge.h:34
meshx_err_t meshx_io_deinit(void)
Deinitialize IO subsystem.
Definition meshx_io_bridge.cpp:132
meshx_err_t meshx_io_init(void)
Initialize IO subsystem.
Definition meshx_io_bridge.cpp:126
meshx_err_t meshx_io_toggle(meshx_io_handle_t handle)
Toggle pin level (convenience function).
Definition meshx_io_bridge.cpp:118
void * meshx_io_handle_t
Opaque handle to IO instance.
Definition meshx_io_bridge.h:26
IO configuration structure (C compatible).
Definition meshx_io_bridge.h:47
uint8_t channel
Definition meshx_io_bridge.h:65
uint8_t io_type
Definition meshx_io_bridge.h:49
uint8_t mode
Definition meshx_io_bridge.h:54
uint8_t drive
Definition meshx_io_bridge.h:56
uint32_t custom_data
Definition meshx_io_bridge.h:70
uint16_t custom_id
Definition meshx_io_bridge.h:69
bool signal_inversion
Definition meshx_io_bridge.h:58
uint8_t resolution
Definition meshx_io_bridge.h:64
uint8_t duty_cycle
Definition meshx_io_bridge.h:63
const char * name
Definition meshx_io_bridge.h:50
uint8_t pull
Definition meshx_io_bridge.h:55
uint8_t initial_level
Definition meshx_io_bridge.h:57
uint8_t logical_pin
Definition meshx_io_bridge.h:48
uint32_t frequency
Definition meshx_io_bridge.h:62