HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
EspTypes_UART.h
Go to the documentation of this file.
1
14#pragma once
15
16#include "BaseUart.h" // For hf_uart_err_t
17#include "EspTypes_Base.h"
18#include "HardwareTypes.h" // For basic hardware types
19#include "McuSelect.h" // Central MCU platform selection (includes all ESP-IDF)
20
21//==============================================================================
22// ESP32 UART TYPE MAPPINGS
23//==============================================================================
24
25// Direct ESP-IDF type usage - no unnecessary aliases
26// These types are used internally by EspUart implementation
27
28//==============================================================================
29// ESP32 UART CONSTANTS
30//==============================================================================
31
32static constexpr hf_pin_num_t HF_UART_IO_UNUSED = 0xFFFFFFFF;
33static constexpr uint32_t HF_UART_BREAK_MIN_DURATION = 1;
34static constexpr uint32_t HF_UART_BREAK_MAX_DURATION = 1000;
35
36// ESP32 UART port limits
37#ifdef HF_MCU_ESP32C6
38static constexpr uint8_t HF_ESP32_UART_MAX_PORTS = 3; // ESP32-C6 has 3 UART ports
39#elif defined(HF_MCU_ESP32) || defined(HF_MCU_ESP32S2) || defined(HF_MCU_ESP32S3)
40static constexpr uint8_t HF_ESP32_UART_MAX_PORTS = 3; // ESP32 Classic/S2/S3 have 3 UART ports
41#elif defined(HF_MCU_ESP32C3) || defined(HF_MCU_ESP32C2) || defined(HF_MCU_ESP32H2)
42static constexpr uint8_t HF_ESP32_UART_MAX_PORTS = 2; // ESP32-C3/C2/H2 have 2 UART ports
43#else
44static constexpr uint8_t HF_ESP32_UART_MAX_PORTS = 3; // Default fallback
45#endif
46
47//==============================================================================
48// ESP32 UART ENUMS
49//==============================================================================
50
54enum class hf_uart_mode_t : uint8_t {
58};
59
69
73enum class hf_uart_parity_t : uint8_t {
77};
78
82enum class hf_uart_stop_bits_t : uint8_t {
86};
87
97
101enum class hf_uart_operating_mode_t : uint8_t {
105};
106
107//==============================================================================
108// ESP32 UART CONFIGURATION STRUCTURES
109//==============================================================================
110
144
163
179
195
213
221 uint8_t duty_cycle;
222
224 : enable_irda(false), invert_tx(false), invert_rx(false), duty_cycle(50) {}
225};
226
238
239//==============================================================================
240// ESP32 UART CALLBACK TYPES
241//==============================================================================
242
246enum class hf_uart_event_type_t : uint8_t {
247 HF_UART_DATA = 0,
248 HF_UART_FIFO_OVF = 1,
250 HF_UART_BREAK = 3,
255};
256
265
272using hf_uart_event_callback_t = bool (*)(const hf_uart_event_t* event, void* user_data);
273
280using hf_uart_break_callback_t = bool (*)(uint32_t break_duration, void* user_data);
281
282//==============================================================================
283// END OF ESPUART TYPES - MINIMAL AND ESSENTIAL ONLY
284//==============================================================================
285
286//==============================================================================
287// ESP32 UART PIN MAP DEFINITIONS
288//==============================================================================
289
290// ESP32-C6 UART Pin Mappings
291#ifdef HF_MCU_ESP32C6
292struct hf_uart_pin_map_esp32c6_t {
293 static constexpr hf_pin_num_t UART0_TX_PIN = 21; // GPIO21
294 static constexpr hf_pin_num_t UART0_RX_PIN = 20; // GPIO20
295 static constexpr hf_pin_num_t UART0_RTS_PIN = 19; // GPIO19
296 static constexpr hf_pin_num_t UART0_CTS_PIN = 18; // GPIO18
297
298 static constexpr hf_pin_num_t UART1_TX_PIN = 6; // GPIO6
299 static constexpr hf_pin_num_t UART1_RX_PIN = 7; // GPIO7
300 static constexpr hf_pin_num_t UART1_RTS_PIN = 8; // GPIO8
301 static constexpr hf_pin_num_t UART1_CTS_PIN = 9; // GPIO9
302
303 static constexpr hf_pin_num_t UART2_TX_PIN = 16; // GPIO16
304 static constexpr hf_pin_num_t UART2_RX_PIN = 17; // GPIO17
305 static constexpr hf_pin_num_t UART2_RTS_PIN = 14; // GPIO14
306 static constexpr hf_pin_num_t UART2_CTS_PIN = 15; // GPIO15
307};
308#endif
309
310// ESP32 Classic UART Pin Mappings
311#ifdef HF_MCU_ESP32
312struct hf_uart_pin_map_esp32_t {
313 static constexpr hf_pin_num_t UART0_TX_PIN = 1; // GPIO1 (UART0_TXD)
314 static constexpr hf_pin_num_t UART0_RX_PIN = 3; // GPIO3 (UART0_RXD)
315 static constexpr hf_pin_num_t UART0_RTS_PIN = 19; // GPIO19
316 static constexpr hf_pin_num_t UART0_CTS_PIN = 22; // GPIO22
317
318 static constexpr hf_pin_num_t UART1_TX_PIN = 10; // GPIO10
319 static constexpr hf_pin_num_t UART1_RX_PIN = 9; // GPIO9
320 static constexpr hf_pin_num_t UART1_RTS_PIN = 11; // GPIO11
321 static constexpr hf_pin_num_t UART1_CTS_PIN = 6; // GPIO6
322
323 static constexpr hf_pin_num_t UART2_TX_PIN = 17; // GPIO17
324 static constexpr hf_pin_num_t UART2_RX_PIN = 16; // GPIO16
325 static constexpr hf_pin_num_t UART2_RTS_PIN = 18; // GPIO18
326 static constexpr hf_pin_num_t UART2_CTS_PIN = 23; // GPIO23
327};
328#endif
329
330// ESP32-S2 UART Pin Mappings
331#ifdef HF_MCU_ESP32S2
332struct hf_uart_pin_map_esp32s2_t {
333 static constexpr hf_pin_num_t UART0_TX_PIN = 43; // GPIO43
334 static constexpr hf_pin_num_t UART0_RX_PIN = 44; // GPIO44
335 static constexpr hf_pin_num_t UART0_RTS_PIN = 45; // GPIO45
336 static constexpr hf_pin_num_t UART0_CTS_PIN = 46; // GPIO46
337
338 static constexpr hf_pin_num_t UART1_TX_PIN = 17; // GPIO17
339 static constexpr hf_pin_num_t UART1_RX_PIN = 18; // GPIO18
340 static constexpr hf_pin_num_t UART1_RTS_PIN = 19; // GPIO19
341 static constexpr hf_pin_num_t UART1_CTS_PIN = 20; // GPIO20
342
343 static constexpr hf_pin_num_t UART2_TX_PIN = 21; // GPIO21
344 static constexpr hf_pin_num_t UART2_RX_PIN = 22; // GPIO22
345 static constexpr hf_pin_num_t UART2_RTS_PIN = 23; // GPIO23
346 static constexpr hf_pin_num_t UART2_CTS_PIN = 24; // GPIO24
347};
348#endif
349
350// ESP32-S3 UART Pin Mappings
351#ifdef HF_MCU_ESP32S3
352struct hf_uart_pin_map_esp32s3_t {
353 static constexpr hf_pin_num_t UART0_TX_PIN = 43; // GPIO43
354 static constexpr hf_pin_num_t UART0_RX_PIN = 44; // GPIO44
355 static constexpr hf_pin_num_t UART0_RTS_PIN = 45; // GPIO45
356 static constexpr hf_pin_num_t UART0_CTS_PIN = 46; // GPIO46
357
358 static constexpr hf_pin_num_t UART1_TX_PIN = 17; // GPIO17
359 static constexpr hf_pin_num_t UART1_RX_PIN = 18; // GPIO18
360 static constexpr hf_pin_num_t UART1_RTS_PIN = 19; // GPIO19
361 static constexpr hf_pin_num_t UART1_CTS_PIN = 20; // GPIO20
362
363 static constexpr hf_pin_num_t UART2_TX_PIN = 21; // GPIO21
364 static constexpr hf_pin_num_t UART2_RX_PIN = 22; // GPIO22
365 static constexpr hf_pin_num_t UART2_RTS_PIN = 23; // GPIO23
366 static constexpr hf_pin_num_t UART2_CTS_PIN = 24; // GPIO24
367};
368#endif
369
370// ESP32-C3 UART Pin Mappings
371#ifdef HF_MCU_ESP32C3
372struct hf_uart_pin_map_esp32c3_t {
373 static constexpr hf_pin_num_t UART0_TX_PIN = 21; // GPIO21
374 static constexpr hf_pin_num_t UART0_RX_PIN = 20; // GPIO20
375 static constexpr hf_pin_num_t UART0_RTS_PIN = 19; // GPIO19
376 static constexpr hf_pin_num_t UART0_CTS_PIN = 18; // GPIO18
377
378 static constexpr hf_pin_num_t UART1_TX_PIN = 6; // GPIO6
379 static constexpr hf_pin_num_t UART1_RX_PIN = 7; // GPIO7
380 static constexpr hf_pin_num_t UART1_RTS_PIN = 8; // GPIO8
381 static constexpr hf_pin_num_t UART1_CTS_PIN = 9; // GPIO9
382};
383#endif
384
385// ESP32-C2 UART Pin Mappings
386#ifdef HF_MCU_ESP32C2
387struct hf_uart_pin_map_esp32c2_t {
388 static constexpr hf_pin_num_t UART0_TX_PIN = 21; // GPIO21
389 static constexpr hf_pin_num_t UART0_RX_PIN = 20; // GPIO20
390 static constexpr hf_pin_num_t UART0_RTS_PIN = 19; // GPIO19
391 static constexpr hf_pin_num_t UART0_CTS_PIN = 18; // GPIO18
392
393 static constexpr hf_pin_num_t UART1_TX_PIN = 6; // GPIO6
394 static constexpr hf_pin_num_t UART1_RX_PIN = 7; // GPIO7
395 static constexpr hf_pin_num_t UART1_RTS_PIN = 8; // GPIO8
396 static constexpr hf_pin_num_t UART1_CTS_PIN = 9; // GPIO9
397};
398#endif
399
400// ESP32-H2 UART Pin Mappings
401#ifdef HF_MCU_ESP32H2
402struct hf_uart_pin_map_esp32h2_t {
403 static constexpr hf_pin_num_t UART0_TX_PIN = 21; // GPIO21
404 static constexpr hf_pin_num_t UART0_RX_PIN = 20; // GPIO20
405 static constexpr hf_pin_num_t UART0_RTS_PIN = 19; // GPIO19
406 static constexpr hf_pin_num_t UART0_CTS_PIN = 18; // GPIO18
407
408 static constexpr hf_pin_num_t UART1_TX_PIN = 6; // GPIO6
409 static constexpr hf_pin_num_t UART1_RX_PIN = 7; // GPIO7
410 static constexpr hf_pin_num_t UART1_RTS_PIN = 8; // GPIO8
411 static constexpr hf_pin_num_t UART1_CTS_PIN = 9; // GPIO9
412};
413#endif
Abstract base class for UART driver implementations in the HardFOC system.
ESP32 base type definitions for hardware abstraction.
static constexpr uint32_t HF_UART_BREAK_MIN_DURATION
Minimum break duration (ms)
Definition EspTypes_UART.h:33
static constexpr hf_pin_num_t HF_UART_IO_UNUSED
Definition EspTypes_UART.h:32
hf_uart_stop_bits_t
ESP32 UART stop bits configuration.
Definition EspTypes_UART.h:82
@ HF_UART_STOP_BITS_1_5
1.5 stop bits
@ HF_UART_STOP_BITS_2
2 stop bits
@ HF_UART_STOP_BITS_1
1 stop bit
hf_uart_operating_mode_t
ESP32 UART operating mode.
Definition EspTypes_UART.h:101
@ HF_UART_MODE_POLLING
Polling mode.
@ HF_UART_MODE_INTERRUPT
Interrupt mode.
hf_uart_flow_ctrl_t
ESP32 UART flow control configuration.
Definition EspTypes_UART.h:91
@ HF_UART_HW_FLOWCTRL_DISABLE
No flow control.
@ HF_UART_HW_FLOWCTRL_RTS
RTS flow control.
@ HF_UART_HW_FLOWCTRL_CTS_RTS
CTS and RTS flow control.
@ HF_UART_HW_FLOWCTRL_CTS
CTS flow control.
static constexpr uint8_t HF_ESP32_UART_MAX_PORTS
Definition EspTypes_UART.h:44
hf_uart_parity_t
ESP32 UART parity configuration.
Definition EspTypes_UART.h:73
@ HF_UART_PARITY_ODD
Odd parity.
@ HF_UART_PARITY_EVEN
Even parity.
@ HF_UART_PARITY_DISABLE
No parity.
hf_uart_event_type_t
HardFOC UART event types (mapped from ESP-IDF events).
Definition EspTypes_UART.h:246
@ HF_UART_FRAME_ERR
Frame error.
@ HF_UART_PARITY_ERR
Parity error.
@ HF_UART_PATTERN_DET
Pattern detected.
@ HF_UART_BUFFER_FULL
Buffer full.
@ HF_UART_FIFO_OVF
FIFO overflow.
@ HF_UART_EVENT_MAX
Maximum event type.
@ HF_UART_DATA
Data received.
@ HF_UART_BREAK
Break detected.
hf_uart_data_bits_t
ESP32 UART data bits configuration.
Definition EspTypes_UART.h:63
@ HF_UART_DATA_7_BITS
7 data bits
@ HF_UART_DATA_6_BITS
6 data bits
@ HF_UART_DATA_8_BITS
8 data bits
@ HF_UART_DATA_5_BITS
5 data bits
static constexpr uint32_t HF_UART_BREAK_MAX_DURATION
Maximum break duration (ms)
Definition EspTypes_UART.h:34
bool(*)(uint32_t break_duration, void *user_data) hf_uart_break_callback_t
UART break detection callback function type.
Definition EspTypes_UART.h:280
hf_uart_mode_t
ESP32 UART operating modes.
Definition EspTypes_UART.h:54
@ HF_UART_MODE_IRDA
IrDA mode.
@ HF_UART_MODE_RS485
RS485 mode.
@ HF_UART_MODE_UART
Standard UART mode.
bool(*)(const hf_uart_event_t *event, void *user_data) hf_uart_event_callback_t
UART event callback function type.
Definition EspTypes_UART.h:272
Platform-agnostic hardware type definitions for the HardFOC system.
hf_time_t hf_timeout_ms_t
Timeout value in milliseconds.
Definition HardwareTypes.h:178
hf_u32_t hf_port_num_t
Platform-agnostic port/controller identifier type.
Definition HardwareTypes.h:120
hf_i32_t hf_pin_num_t
Platform-agnostic GPIO pin number type.
Definition HardwareTypes.h:99
hf_u32_t hf_baud_rate_t
Platform-agnostic baud rate type.
Definition HardwareTypes.h:153
Centralized MCU platform selection and configuration header.
ESP32 UART port configuration.
Definition EspTypes_UART.h:114
bool enable_pattern_detection
Enable pattern detection.
Definition EspTypes_UART.h:130
hf_baud_rate_t baud_rate
Baud rate in bits per second.
Definition EspTypes_UART.h:116
hf_pin_num_t cts_pin
CTS pin number (optional)
Definition EspTypes_UART.h:124
hf_uart_data_bits_t data_bits
Data bits (5-8)
Definition EspTypes_UART.h:117
hf_pin_num_t rts_pin
RTS pin number (optional)
Definition EspTypes_UART.h:123
hf_uart_parity_t parity
Parity configuration.
Definition EspTypes_UART.h:118
uint16_t tx_buffer_size
TX buffer size in bytes.
Definition EspTypes_UART.h:125
hf_pin_num_t tx_pin
TX pin number.
Definition EspTypes_UART.h:121
hf_uart_stop_bits_t stop_bits
Stop bits (1, 1.5, 2)
Definition EspTypes_UART.h:119
hf_timeout_ms_t timeout_ms
Default timeout for operations.
Definition EspTypes_UART.h:129
bool enable_wakeup
Enable UART wakeup from sleep.
Definition EspTypes_UART.h:131
hf_uart_flow_ctrl_t flow_control
Hardware flow control.
Definition EspTypes_UART.h:120
uint16_t rx_buffer_size
RX buffer size in bytes.
Definition EspTypes_UART.h:126
uint8_t event_queue_size
Event queue size for interrupt mode.
Definition EspTypes_UART.h:127
hf_uart_operating_mode_t operating_mode
Operating mode (polling/interrupt/DMA)
Definition EspTypes_UART.h:128
hf_pin_num_t rx_pin
RX pin number.
Definition EspTypes_UART.h:122
bool enable_loopback
Enable loopback mode for testing.
Definition EspTypes_UART.h:132
hf_uart_config_t() noexcept
Definition EspTypes_UART.h:134
hf_port_num_t port_number
UART port number (0, 1, 2)
Definition EspTypes_UART.h:115
HardFOC UART event structure.
Definition EspTypes_UART.h:260
uint8_t timeout_flag
Timeout flag.
Definition EspTypes_UART.h:263
size_t size
Data size (for data events)
Definition EspTypes_UART.h:262
hf_uart_event_type_t type
Event type.
Definition EspTypes_UART.h:261
ESP32 UART flow control configuration.
Definition EspTypes_UART.h:148
uint8_t xoff_char
XOFF character (default: 0x13)
Definition EspTypes_UART.h:152
uint16_t rx_flow_ctrl_thresh
RX flow control threshold (bytes)
Definition EspTypes_UART.h:153
uint8_t xon_char
XON character (default: 0x11)
Definition EspTypes_UART.h:151
bool enable_hw_flow_control
Enable hardware flow control (RTS/CTS)
Definition EspTypes_UART.h:149
bool auto_rts
Automatic RTS control.
Definition EspTypes_UART.h:155
bool enable_sw_flow_control
Enable software flow control (XON/XOFF)
Definition EspTypes_UART.h:150
uint16_t tx_flow_ctrl_thresh
TX flow control threshold (bytes)
Definition EspTypes_UART.h:154
bool auto_cts
Automatic CTS control.
Definition EspTypes_UART.h:156
hf_uart_flow_config_t() noexcept
Definition EspTypes_UART.h:158
ESP32 UART IrDA configuration.
Definition EspTypes_UART.h:217
uint8_t duty_cycle
IrDA duty cycle (0-100%)
Definition EspTypes_UART.h:221
bool enable_irda
Enable IrDA mode.
Definition EspTypes_UART.h:218
bool invert_tx
Invert TX signal for IrDA.
Definition EspTypes_UART.h:219
bool invert_rx
Invert RX signal for IrDA.
Definition EspTypes_UART.h:220
hf_uart_irda_config_t() noexcept
Definition EspTypes_UART.h:223
ESP32 UART pattern detection configuration.
Definition EspTypes_UART.h:183
uint16_t post_idle
Idle time after last pattern char (baud cycles)
Definition EspTypes_UART.h:188
uint16_t pre_idle
Idle time before first pattern char (baud cycles)
Definition EspTypes_UART.h:189
uint16_t char_timeout
Timeout between pattern characters (baud cycles)
Definition EspTypes_UART.h:187
bool enable_pattern_detection
Enable pattern detection feature.
Definition EspTypes_UART.h:184
hf_uart_pattern_config_t() noexcept
Definition EspTypes_UART.h:191
uint8_t pattern_char_num
Number of consecutive pattern characters.
Definition EspTypes_UART.h:186
char pattern_char
Character to detect (e.g., '+' for AT commands)
Definition EspTypes_UART.h:185
ESP32 UART power management configuration.
Definition EspTypes_UART.h:167
uint8_t wakeup_threshold
Wakeup threshold character count.
Definition EspTypes_UART.h:172
bool allow_pd_in_light_sleep
Allow power down in light sleep.
Definition EspTypes_UART.h:169
uint32_t wakeup_timeout_ms
Wakeup timeout in milliseconds.
Definition EspTypes_UART.h:173
hf_uart_power_config_t() noexcept
Definition EspTypes_UART.h:175
bool sleep_retention_enable
Enable sleep retention.
Definition EspTypes_UART.h:168
bool allow_pd_in_deep_sleep
Allow power down in deep sleep.
Definition EspTypes_UART.h:170
bool wakeup_enable
Enable UART wakeup capability.
Definition EspTypes_UART.h:171
ESP32 UART RS485 configuration.
Definition EspTypes_UART.h:199
hf_uart_mode_t mode
RS485 operating mode.
Definition EspTypes_UART.h:200
bool enable_echo_suppression
Suppress echo during transmission.
Definition EspTypes_UART.h:202
uint32_t rts_delay_ms
RTS delay in milliseconds.
Definition EspTypes_UART.h:204
hf_uart_rs485_config_t() noexcept
Definition EspTypes_UART.h:208
bool enable_collision_detect
Enable collision detection.
Definition EspTypes_UART.h:201
uint32_t rts_timeout_ms
RTS timeout in milliseconds.
Definition EspTypes_UART.h:205
bool auto_rts_control
Automatic RTS line control.
Definition EspTypes_UART.h:203
uint32_t collision_timeout_ms
Collision detection timeout.
Definition EspTypes_UART.h:206
ESP32 UART wakeup configuration.
Definition EspTypes_UART.h:230
uint8_t wakeup_threshold
Number of RX edges to trigger wakeup (3-1023)
Definition EspTypes_UART.h:232
bool use_ref_tick
Use REF_TICK as clock source during sleep.
Definition EspTypes_UART.h:233
bool enable_wakeup
Enable UART wakeup from light sleep.
Definition EspTypes_UART.h:231
hf_uart_wakeup_config_t() noexcept
Definition EspTypes_UART.h:235