27#include <esp_adc/adc_continuous.h>
28#include <esp_adc/adc_oneshot.h>
270 SOC_ADC_DIGI_DATA_BYTES_PER_CONV;
282 uint32_t enabled_channels)
noexcept {
294 uint32_t max_store_frames)
noexcept {
295 return CalcFrameSize(samples_per_frame, enabled_channels) * max_store_frames;
306 uint32_t max_store_frames)
noexcept {
307 if (enabled_channels == 0 || samples_per_frame == 0 || max_store_frames == 0) {
311 uint32_t frame_size =
CalcFrameSize(samples_per_frame, enabled_channels);
312 uint32_t pool_size =
CalcBufferPoolSize(samples_per_frame, enabled_channels, max_store_frames);
316 (pool_size <= 32768) &&
355 return (gpio_pin >= 0 && gpio_pin <= 6) ?
static_cast<hf_channel_id_t>(gpio_pin)
Abstract base class for ADC implementations in the HardFOC system.
constexpr uint32_t HF_ESP32_ADC_DATA_BYTES_PER_CONV
Example of ISR-safe ADC callback implementation.
Definition EspTypes_ADC.h:269
hf_adc_filter_coeff_t
ADC filter coefficient enumeration.
Definition EspTypes_ADC.h:74
@ COEFF_16
Coefficient 16.
@ COEFF_64
Coefficient 64.
bool(*)(const hf_adc_continuous_data_t *data, void *user_data) hf_adc_continuous_callback_t
ADC continuous mode data callback function.
Definition EspTypes_ADC.h:218
constexpr bool IsValidContinuousConfig(uint32_t samples_per_frame, uint32_t enabled_channels, uint32_t max_store_frames) noexcept
Validate continuous mode configuration parameters.
Definition EspTypes_ADC.h:305
constexpr uint32_t GetMaxInputVoltage(hf_adc_atten_t atten) noexcept
Get maximum input voltage for given attenuation.
Definition EspTypes_ADC.h:378
hf_adc_mode_t
ADC operating modes supported by ESP32.
Definition EspTypes_ADC.h:41
@ CONTINUOUS
Continuous mode with DMA for high-speed sampling.
@ ONESHOT
One-shot mode for single conversions.
constexpr hf_pin_num_t AdcChannelToGpio(hf_channel_id_t channel_id) noexcept
Convert ADC channel to GPIO pin for ESP32.
Definition EspTypes_ADC.h:366
hf_adc_bitwidth_t
ADC resolution/bit width settings for ESP32 Values must match ESP-IDF adc_bitwidth_t enum.
Definition EspTypes_ADC.h:62
@ WIDTH_11BIT
11-bit resolution (0-2047)
@ WIDTH_10BIT
10-bit resolution (0-1023)
@ WIDTH_DEFAULT
Default width (12-bit for ESP32)
@ WIDTH_9BIT
9-bit resolution (0-511)
@ WIDTH_13BIT
13-bit resolution (0-8191)
@ WIDTH_12BIT
12-bit resolution (0-4095) - Default for ESP32
constexpr hf_channel_id_t GpioToAdcChannel(hf_pin_num_t gpio_pin) noexcept
Convert GPIO pin to ADC channel for ESP32.
Definition EspTypes_ADC.h:351
constexpr uint32_t HF_ESP32_ADC_DEFAULT_FRAME_SIZE
Default frame size.
Definition EspTypes_ADC.h:273
constexpr uint32_t HF_ESP32_ADC_MIN_FRAME_SIZE
Minimum frame size.
Definition EspTypes_ADC.h:271
constexpr uint32_t CalcBufferPoolSize(uint32_t samples_per_frame, uint32_t enabled_channels, uint32_t max_store_frames) noexcept
Calculate total buffer pool size based on frames and enabled channels.
Definition EspTypes_ADC.h:293
constexpr uint32_t GetFrameResultCount(uint32_t frame_size) noexcept
Calculate number of conversion results that fit in a frame.
Definition EspTypes_ADC.h:336
hf_adc_atten_t
ADC attenuation levels for ESP32 These control the input voltage range that can be measured Values mu...
Definition EspTypes_ADC.h:51
@ ATTEN_DB_12
12dB attenuation - Input range: 0V to ~3.3V
@ ATTEN_DB_2_5
2.5dB attenuation - Input range: 0V to ~1.32V
@ ATTEN_DB_6
6dB attenuation - Input range: 0V to ~1.98V
@ ATTEN_DB_0
No attenuation (0dB) - Input range: 0V to ~0.95V.
constexpr bool IsValidFrameSize(uint32_t frame_size) noexcept
Validate that frame size is properly aligned.
Definition EspTypes_ADC.h:325
constexpr uint32_t HF_ESP32_ADC_MAX_FRAME_SIZE
Maximum frame size.
Definition EspTypes_ADC.h:272
constexpr uint32_t CalcFrameSize(uint32_t samples_per_frame, uint32_t enabled_channels) noexcept
Calculate frame size in bytes based on samples per frame and enabled channels.
Definition EspTypes_ADC.h:281
hf_adc_monitor_event_type_t
ADC monitor event type enumeration.
Definition EspTypes_ADC.h:85
@ HIGH_THRESH
High threshold exceeded.
@ LOW_THRESH
Below low threshold.
constexpr uint32_t GetMaxRawValue(hf_adc_bitwidth_t bitwidth) noexcept
Get maximum raw value for given bit width.
Definition EspTypes_ADC.h:398
void(*)(const hf_adc_monitor_event_t *event, void *user_data) hf_adc_monitor_callback_t
ADC threshold monitor callback function.
Definition EspTypes_ADC.h:234
ESP32 base type definitions for hardware abstraction.
Platform-agnostic hardware type definitions for the HardFOC system.
constexpr hf_pin_num_t HF_INVALID_PIN
Invalid pin constant for unassigned or invalid pins.
Definition HardwareTypes.h:104
hf_i32_t hf_pin_num_t
Platform-agnostic GPIO pin number type.
Definition HardwareTypes.h:99
hf_u32_t hf_channel_id_t
Platform-agnostic channel identifier type.
Definition HardwareTypes.h:163
constexpr hf_channel_id_t HF_INVALID_CHANNEL
Invalid channel constant for unassigned or invalid channels.
Definition HardwareTypes.h:168
Centralized MCU platform selection and configuration header.
ADC calibration configuration structure.
Definition EspTypes_ADC.h:149
hf_adc_calibration_config_t()
Definition EspTypes_ADC.h:154
uint32_t calibration_interval_ms
Calibration interval in milliseconds.
Definition EspTypes_ADC.h:152
bool enable_calibration
Enable calibration flag.
Definition EspTypes_ADC.h:150
bool auto_calibration
Auto calibration flag.
Definition EspTypes_ADC.h:151
ADC channel configuration structure.
Definition EspTypes_ADC.h:93
hf_adc_channel_config_t()
Definition EspTypes_ADC.h:99
hf_channel_id_t channel_id
Channel ID.
Definition EspTypes_ADC.h:94
hf_adc_atten_t attenuation
Attenuation level.
Definition EspTypes_ADC.h:95
hf_adc_bitwidth_t bitwidth
Bit width.
Definition EspTypes_ADC.h:96
bool enabled
Channel enabled flag.
Definition EspTypes_ADC.h:97
ADC continuous mode configuration structure.
Definition EspTypes_ADC.h:110
uint32_t max_store_frames
Maximum number of frames to store in buffer pool (1-8 recommended)
Definition EspTypes_ADC.h:114
uint32_t sample_freq_hz
Sampling frequency in Hz.
Definition EspTypes_ADC.h:111
uint32_t samples_per_frame
Number of samples per frame per enabled channel (64-1024 recommended)
Definition EspTypes_ADC.h:113
bool flush_pool
Flush pool flag.
Definition EspTypes_ADC.h:115
hf_adc_continuous_config_t()
Definition EspTypes_ADC.h:117
ADC continuous data structure.
Definition EspTypes_ADC.h:176
uint64_t timestamp_us
Timestamp in microseconds.
Definition EspTypes_ADC.h:180
hf_adc_continuous_data_t()
Definition EspTypes_ADC.h:182
uint8_t * buffer
Data buffer.
Definition EspTypes_ADC.h:177
uint32_t size
Data size in bytes.
Definition EspTypes_ADC.h:178
uint32_t conversion_count
Number of conversions.
Definition EspTypes_ADC.h:179
ADC filter configuration structure.
Definition EspTypes_ADC.h:124
hf_adc_filter_config_t()
Definition EspTypes_ADC.h:129
uint8_t filter_id
Filter ID (0-1)
Definition EspTypes_ADC.h:125
hf_adc_filter_coeff_t coefficient
Filter coefficient.
Definition EspTypes_ADC.h:127
hf_channel_id_t channel_id
Channel ID to filter.
Definition EspTypes_ADC.h:126
ADC monitor configuration structure.
Definition EspTypes_ADC.h:136
hf_channel_id_t channel_id
Channel ID to monitor.
Definition EspTypes_ADC.h:138
uint32_t high_threshold
High threshold value (raw)
Definition EspTypes_ADC.h:139
uint8_t monitor_id
Monitor ID (0-1)
Definition EspTypes_ADC.h:137
uint32_t low_threshold
Low threshold value (raw)
Definition EspTypes_ADC.h:140
hf_adc_monitor_config_t()
Definition EspTypes_ADC.h:142
ADC monitor event structure.
Definition EspTypes_ADC.h:188
uint8_t monitor_id
Monitor ID.
Definition EspTypes_ADC.h:189
uint64_t timestamp_us
Timestamp in microseconds.
Definition EspTypes_ADC.h:193
uint32_t raw_value
Raw ADC value.
Definition EspTypes_ADC.h:191
hf_adc_monitor_event_t()
Definition EspTypes_ADC.h:195
hf_adc_monitor_event_type_t event_type
Event type.
Definition EspTypes_ADC.h:192
hf_channel_id_t channel_id
Channel ID.
Definition EspTypes_ADC.h:190
ADC unit configuration structure.
Definition EspTypes_ADC.h:161
hf_adc_calibration_config_t calibration_config
Calibration configuration.
Definition EspTypes_ADC.h:167
hf_adc_channel_config_t channel_configs[7]
Channel configurations (ESP32 has 7 channels)
Definition EspTypes_ADC.h:165
uint8_t unit_id
ADC unit ID.
Definition EspTypes_ADC.h:162
hf_adc_mode_t mode
Operating mode.
Definition EspTypes_ADC.h:163
hf_adc_bitwidth_t bit_width
ADC bit width.
Definition EspTypes_ADC.h:164
hf_adc_continuous_config_t continuous_config
Continuous mode configuration.
Definition EspTypes_ADC.h:166
hf_adc_unit_config_t()
Definition EspTypes_ADC.h:169