HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
EspTypes_PIO.h
Go to the documentation of this file.
1
14#pragma once
15
16#include "BasePio.h" // For hf_pio_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 PIO/RMT TYPE MAPPINGS
23//==============================================================================
24
25// Direct ESP-IDF type usage - no unnecessary aliases
26// These types are used internally by EspPio implementation
27
28//==============================================================================
29// ESP32 PIO/RMT CONSTANTS
30//==============================================================================
31
32// ESP32 Variant-Specific RMT Channel Allocation
33// Based on ESP-IDF v5.5 specifications for different ESP32 models
34
35#if defined(CONFIG_IDF_TARGET_ESP32)
36// ESP32: 8 channels, each configurable as TX or RX
37static constexpr uint8_t HF_RMT_MAX_CHANNELS = 8;
38static constexpr uint8_t HF_RMT_MAX_TX_CHANNELS = 8; // All channels can be TX
39static constexpr uint8_t HF_RMT_MAX_RX_CHANNELS = 8; // All channels can be RX
40static constexpr uint8_t HF_RMT_TX_CHANNEL_START = 0; // TX channels: 0-7
41static constexpr uint8_t HF_RMT_RX_CHANNEL_START = 0; // RX channels: 0-7
42
43#elif defined(CONFIG_IDF_TARGET_ESP32S2)
44// ESP32-S2: 4 channels, each configurable as TX or RX
45static constexpr uint8_t HF_RMT_MAX_CHANNELS = 4;
46static constexpr uint8_t HF_RMT_MAX_TX_CHANNELS = 4; // All channels can be TX
47static constexpr uint8_t HF_RMT_MAX_RX_CHANNELS = 4; // All channels can be RX
48static constexpr uint8_t HF_RMT_TX_CHANNEL_START = 0; // TX channels: 0-3
49static constexpr uint8_t HF_RMT_RX_CHANNEL_START = 0; // RX channels: 0-3
50
51#elif defined(CONFIG_IDF_TARGET_ESP32S3)
52// ESP32-S3: 8 channels, hardcoded TX/RX allocation
53static constexpr uint8_t HF_RMT_MAX_CHANNELS = 8;
54static constexpr uint8_t HF_RMT_MAX_TX_CHANNELS = 4; // Channels 0-3 are hardcoded for TX
55static constexpr uint8_t HF_RMT_MAX_RX_CHANNELS = 4; // Channels 4-7 are hardcoded for RX
56static constexpr uint8_t HF_RMT_TX_CHANNEL_START = 0; // TX channels: 0-3
57static constexpr uint8_t HF_RMT_RX_CHANNEL_START = 4; // RX channels: 4-7
58
59#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) || \
60 defined(CONFIG_IDF_TARGET_ESP32H2)
61// ESP32-C3/C6/H2: 4 channels, hardcoded TX/RX allocation
62static constexpr uint8_t HF_RMT_MAX_CHANNELS = 4;
63static constexpr uint8_t HF_RMT_MAX_TX_CHANNELS = 2; // Channels 0-1 are hardcoded for TX
64static constexpr uint8_t HF_RMT_MAX_RX_CHANNELS = 2; // Channels 2-3 are hardcoded for RX
65static constexpr uint8_t HF_RMT_TX_CHANNEL_START = 0; // TX channels: 0-1
66static constexpr uint8_t HF_RMT_RX_CHANNEL_START = 2; // RX channels: 2-3
67
68#else
69// Default fallback for unknown ESP32 variants
70static constexpr uint8_t HF_RMT_MAX_CHANNELS = 4;
71static constexpr uint8_t HF_RMT_MAX_TX_CHANNELS = 2;
72static constexpr uint8_t HF_RMT_MAX_RX_CHANNELS = 2;
73static constexpr uint8_t HF_RMT_TX_CHANNEL_START = 0;
74static constexpr uint8_t HF_RMT_RX_CHANNEL_START = 2;
75#endif
76
77// Common RMT constants for all ESP32 variants
78static constexpr size_t HF_RMT_MIN_MEM_BLOCK_SYMBOLS = 48;
79static constexpr size_t HF_RMT_MAX_MEM_BLOCK_SYMBOLS = 1024;
80static constexpr size_t HF_RMT_DEFAULT_MEM_BLOCK_SYMBOLS = 64;
81static constexpr uint32_t HF_RMT_MAX_RESOLUTION_HZ = 80000000; // 80 MHz max
82static constexpr uint32_t HF_RMT_MIN_RESOLUTION_HZ = 1000; // 1 kHz min
83static constexpr uint32_t HF_RMT_DEFAULT_RESOLUTION_HZ = 1000000; // 1 MHz default
84static constexpr uint8_t HF_RMT_MAX_QUEUE_DEPTH = 32;
85static constexpr uint8_t HF_RMT_MAX_INTERRUPT_PRIORITY = 7;
86
87//==============================================================================
88// ESP32 PIO/RMT ENUMS
89//==============================================================================
90
100
108
109//==============================================================================
110// ESP32 PIO/RMT CONFIGURATION STRUCTURES
111//==============================================================================
112
117 uint32_t loop_count;
119 bool with_dma;
120 uint32_t queue_depth;
122 bool allow_pd;
123
125 : loop_count(0), invert_signal(false), with_dma(false), queue_depth(4), intr_priority(0),
126 allow_pd(false) {}
127};
128
143
156
157//==============================================================================
158// ESP32 PIO/RMT VALIDATION MACROS
159//==============================================================================
160
164#define HF_RMT_IS_VALID_CHANNEL(ch) ((ch) < HF_RMT_MAX_CHANNELS)
165
166// ESP32 variant-specific TX channel validation
167#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2)
168// ESP32/ESP32-S2: Any channel can be TX or RX
169#define HF_RMT_IS_VALID_TX_CHANNEL(ch) ((ch) < HF_RMT_MAX_CHANNELS)
170#define HF_RMT_IS_VALID_RX_CHANNEL(ch) ((ch) < HF_RMT_MAX_CHANNELS)
171#elif defined(CONFIG_IDF_TARGET_ESP32S3)
172// ESP32-S3: Channels 0-3 for TX, 4-7 for RX
173#define HF_RMT_IS_VALID_TX_CHANNEL(ch) ((ch) >= 0 && (ch) < 4)
174#define HF_RMT_IS_VALID_RX_CHANNEL(ch) ((ch) >= 4 && (ch) < 8)
175#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) || \
176 defined(CONFIG_IDF_TARGET_ESP32H2)
177// ESP32-C3/C6/H2: Channels 0-1 for TX, 2-3 for RX
178#define HF_RMT_IS_VALID_TX_CHANNEL(ch) ((ch) >= 0 && (ch) < 2)
179#define HF_RMT_IS_VALID_RX_CHANNEL(ch) ((ch) >= 2 && (ch) < 4)
180#else
181// Default fallback
182#define HF_RMT_IS_VALID_TX_CHANNEL(ch) ((ch) >= 0 && (ch) < 2)
183#define HF_RMT_IS_VALID_RX_CHANNEL(ch) ((ch) >= 2 && (ch) < 4)
184#endif
185
186#define HF_RMT_IS_VALID_RESOLUTION(res) \
187 ((res) >= HF_RMT_MIN_RESOLUTION_HZ && (res) <= HF_RMT_MAX_RESOLUTION_HZ)
188#define HF_RMT_IS_VALID_MEM_BLOCK_SIZE(size) \
189 ((size) >= HF_RMT_MIN_MEM_BLOCK_SYMBOLS && (size) <= HF_RMT_MAX_MEM_BLOCK_SYMBOLS)
190#define HF_RMT_IS_VALID_QUEUE_DEPTH(depth) ((depth) >= 1 && (depth) <= HF_RMT_MAX_QUEUE_DEPTH)
191#define HF_RMT_IS_VALID_INTR_PRIORITY(prio) ((prio) <= HF_RMT_MAX_INTERRUPT_PRIORITY)
192
198inline constexpr int8_t HfRmtGetTxChannel(uint8_t index) noexcept {
199 if (index >= HF_RMT_MAX_TX_CHANNELS) {
200 return -1;
201 }
202 return static_cast<int8_t>(HF_RMT_TX_CHANNEL_START + index);
203}
204
210inline constexpr int8_t HfRmtGetRxChannel(uint8_t index) noexcept {
211 if (index >= HF_RMT_MAX_RX_CHANNELS) {
212 return -1;
213 }
214 return static_cast<int8_t>(HF_RMT_RX_CHANNEL_START + index);
215}
216
223inline constexpr bool HfRmtIsChannelValidForDirection(uint8_t channel_id,
224 hf_pio_direction_t direction) noexcept {
225 if (!HF_RMT_IS_VALID_CHANNEL(channel_id)) {
226 return false;
227 }
228
229 switch (direction) {
231 return HF_RMT_IS_VALID_TX_CHANNEL(channel_id);
233 return HF_RMT_IS_VALID_RX_CHANNEL(channel_id);
235 // Bidirectional requires both TX and RX capability
236 return HF_RMT_IS_VALID_TX_CHANNEL(channel_id) && HF_RMT_IS_VALID_RX_CHANNEL(channel_id);
237 default:
238 return false;
239 }
240}
241
246inline constexpr const char* HfRmtGetVariantName() noexcept {
247#if defined(CONFIG_IDF_TARGET_ESP32)
248 return "ESP32";
249#elif defined(CONFIG_IDF_TARGET_ESP32S2)
250 return "ESP32-S2";
251#elif defined(CONFIG_IDF_TARGET_ESP32S3)
252 return "ESP32-S3";
253#elif defined(CONFIG_IDF_TARGET_ESP32C3)
254 return "ESP32-C3";
255#elif defined(CONFIG_IDF_TARGET_ESP32C6)
256 return "ESP32-C6";
257#elif defined(CONFIG_IDF_TARGET_ESP32H2)
258 return "ESP32-H2";
259#else
260 return "Unknown ESP32";
261#endif
262}
263
264//==============================================================================
265// END OF ESPPIO TYPES - MINIMAL AND ESSENTIAL ONLY
266//==============================================================================
Abstract base class for Programmable IO Channel implementations in the HardFOC system.
hf_pio_direction_t
PIO channel direction.
Definition BasePio.h:113
@ Receive
Receive mode (input)
@ Transmit
Transmit mode (output)
@ Bidirectional
Bidirectional mode (if supported)
ESP32 base type definitions for hardware abstraction.
static constexpr size_t HF_RMT_MIN_MEM_BLOCK_SYMBOLS
Definition EspTypes_PIO.h:78
constexpr const char * HfRmtGetVariantName() noexcept
Get ESP32 variant name for debugging.
Definition EspTypes_PIO.h:246
hf_rmt_clock_source_t
ESP32 RMT clock source selection.
Definition EspTypes_PIO.h:94
@ HF_RMT_CLK_SRC_DEFAULT
Default clock source (APB)
@ HF_RMT_CLK_SRC_RC_FAST
RC fast clock (~8MHz)
@ HF_RMT_CLK_SRC_APB
APB clock (80MHz)
@ HF_RMT_CLK_SRC_XTAL
Crystal clock (40MHz)
#define HF_RMT_IS_VALID_RX_CHANNEL(ch)
Definition EspTypes_PIO.h:183
static constexpr size_t HF_RMT_MAX_MEM_BLOCK_SYMBOLS
Definition EspTypes_PIO.h:79
static constexpr uint8_t HF_RMT_MAX_QUEUE_DEPTH
Definition EspTypes_PIO.h:84
constexpr int8_t HfRmtGetRxChannel(uint8_t index) noexcept
Get the recommended RX channel for the current ESP32 variant.
Definition EspTypes_PIO.h:210
constexpr bool HfRmtIsChannelValidForDirection(uint8_t channel_id, hf_pio_direction_t direction) noexcept
Validate channel for specific direction on current ESP32 variant.
Definition EspTypes_PIO.h:223
static constexpr uint8_t HF_RMT_TX_CHANNEL_START
Definition EspTypes_PIO.h:73
#define HF_RMT_IS_VALID_TX_CHANNEL(ch)
Definition EspTypes_PIO.h:182
static constexpr uint32_t HF_RMT_MIN_RESOLUTION_HZ
Definition EspTypes_PIO.h:82
static constexpr uint8_t HF_RMT_MAX_RX_CHANNELS
Definition EspTypes_PIO.h:72
static constexpr size_t HF_RMT_DEFAULT_MEM_BLOCK_SYMBOLS
Definition EspTypes_PIO.h:80
static constexpr uint8_t HF_RMT_MAX_TX_CHANNELS
Definition EspTypes_PIO.h:71
static constexpr uint8_t HF_RMT_MAX_INTERRUPT_PRIORITY
Definition EspTypes_PIO.h:85
static constexpr uint8_t HF_RMT_RX_CHANNEL_START
Definition EspTypes_PIO.h:74
hf_rmt_channel_direction_t
ESP32 RMT channel direction.
Definition EspTypes_PIO.h:104
@ HF_RMT_CHANNEL_DIRECTION_TX
Transmit direction.
@ HF_RMT_CHANNEL_DIRECTION_RX
Receive direction.
#define HF_RMT_IS_VALID_CHANNEL(ch)
RMT validation macros for ESP32 variants.
Definition EspTypes_PIO.h:164
constexpr int8_t HfRmtGetTxChannel(uint8_t index) noexcept
Get the recommended TX channel for the current ESP32 variant.
Definition EspTypes_PIO.h:198
static constexpr uint32_t HF_RMT_MAX_RESOLUTION_HZ
Definition EspTypes_PIO.h:81
static constexpr uint32_t HF_RMT_DEFAULT_RESOLUTION_HZ
Definition EspTypes_PIO.h:83
static constexpr uint8_t HF_RMT_MAX_CHANNELS
Definition EspTypes_PIO.h:70
Platform-agnostic hardware type definitions for the HardFOC system.
Centralized MCU platform selection and configuration header.
ESP32 RMT carrier configuration for IR protocols.
Definition EspTypes_PIO.h:147
uint8_t polarity_active_low
Carrier polarity (0=high, 1=low)
Definition EspTypes_PIO.h:150
bool always_on
Always on carrier mode.
Definition EspTypes_PIO.h:151
hf_rmt_carrier_config_t() noexcept
Definition EspTypes_PIO.h:153
float duty_cycle
Duty cycle (0.0 to 1.0)
Definition EspTypes_PIO.h:149
uint32_t frequency_hz
Carrier frequency in Hz.
Definition EspTypes_PIO.h:148
ESP32 RMT reception configuration.
Definition EspTypes_PIO.h:132
hf_rmt_receive_config_t() noexcept
Definition EspTypes_PIO.h:139
bool allow_pd
Allow power down in sleep modes.
Definition EspTypes_PIO.h:137
bool with_dma
Enable DMA mode for large transfers.
Definition EspTypes_PIO.h:135
uint8_t intr_priority
Interrupt priority (0-7)
Definition EspTypes_PIO.h:136
uint32_t signal_range_min_ns
Minimum signal range in nanoseconds.
Definition EspTypes_PIO.h:133
uint32_t signal_range_max_ns
Maximum signal range in nanoseconds.
Definition EspTypes_PIO.h:134
ESP32 RMT transmission configuration.
Definition EspTypes_PIO.h:116
hf_rmt_transmit_config_t() noexcept
Definition EspTypes_PIO.h:124
uint32_t queue_depth
TX queue depth (1-32)
Definition EspTypes_PIO.h:120
bool with_dma
Enable DMA mode for large transfers.
Definition EspTypes_PIO.h:119
bool allow_pd
Allow power down in sleep modes.
Definition EspTypes_PIO.h:122
bool invert_signal
Invert output signal.
Definition EspTypes_PIO.h:118
uint32_t loop_count
Loop count (0 = no loop)
Definition EspTypes_PIO.h:117
uint8_t intr_priority
Interrupt priority (0-7)
Definition EspTypes_PIO.h:121