refactor(Monitoring): abstract platform-specific ADC code and add ESP32-S2 support

- Move calibration functions to platform-specific files
- Add ADC_SAMPLER_SUPPORTED macro for unified platform detection
- Add ESP32-S2 support (UNTESTED)
- Remove explicit #if defined() macros from common code
This commit is contained in:
m-RNA
2026-01-10 23:50:03 +08:00
parent c6584af3b5
commit 01053752d9
6 changed files with 159 additions and 54 deletions

View File

@@ -9,14 +9,30 @@
# +-----------------------+
# | ESP-IDF ADC HAL | ← Espressif official driver
# +-----------------------+
#
# Supported platforms (must support ESP-CAM):
# - ESP32: Tested
# - ESP32-S3: Tested
# - ESP32-S2: UNTESTED - Based on datasheet
set(
requires
Helpers
)
# List of supported ADC platforms (aligned with ESP_CAMERA_SUPPORTED)
set(ADC_SUPPORTED_TARGETS "esp32" "esp32s3" "esp32s2")
# Check if current target supports ADC
list(FIND ADC_SUPPORTED_TARGETS "$ENV{IDF_TARGET}" ADC_TARGET_INDEX)
if (NOT ADC_TARGET_INDEX EQUAL -1)
set(ADC_SAMPLER_SUPPORTED TRUE)
else()
set(ADC_SAMPLER_SUPPORTED FALSE)
endif()
# Platform-specific dependencies
if ("$ENV{IDF_TARGET}" STREQUAL "esp32s3" OR "$ENV{IDF_TARGET}" STREQUAL "esp32")
if (ADC_SAMPLER_SUPPORTED)
list(APPEND requires
driver
esp_adc
@@ -32,22 +48,20 @@ set(
)
# BSP Layer: ADC sampler implementation
if ("$ENV{IDF_TARGET}" STREQUAL "esp32s3" OR "$ENV{IDF_TARGET}" STREQUAL "esp32")
# Common ADC implementation
list(APPEND source_files
"Monitoring/AdcSampler.cpp"
if (ADC_SAMPLER_SUPPORTED)
# Common ADC implementation
list(APPEND source_files
"Monitoring/AdcSampler.cpp"
)
# Platform-specific GPIO-to-channel mapping
if ("$ENV{IDF_TARGET}" STREQUAL "esp32s3")
list(APPEND source_files
"Monitoring/AdcSampler_esp32s3.cpp"
)
elseif ("$ENV{IDF_TARGET}" STREQUAL "esp32")
list(APPEND source_files
"Monitoring/AdcSampler_esp32.cpp"
)
endif()
# Platform-specific GPIO-to-channel mapping and calibration
if ("$ENV{IDF_TARGET}" STREQUAL "esp32s3")
list(APPEND source_files "Monitoring/AdcSampler_esp32s3.cpp")
elseif ("$ENV{IDF_TARGET}" STREQUAL "esp32s2")
list(APPEND source_files "Monitoring/AdcSampler_esp32s2.cpp")
elseif ("$ENV{IDF_TARGET}" STREQUAL "esp32")
list(APPEND source_files "Monitoring/AdcSampler_esp32.cpp")
endif()
endif()