33 * @brief BSP Layer - Common ADC sampling implementation
44 *
55 * This file contains platform-independent ADC sampling logic.
6- * Platform-specific GPIO-to-channel mapping is in separate files:
7- * - AdcSampler_esp32.cpp
8- * - AdcSampler_esp32s3.cpp
6+ * Platform-specific implementations are in separate files:
7+ * - AdcSampler_esp32.cpp (Tested)
8+ * - AdcSampler_esp32s3.cpp (Tested)
9+ * - AdcSampler_esp32s2.cpp (UNTESTED)
910 */
1011
1112#include " AdcSampler.hpp"
1213
13- #if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32)
14+ #if ADC_SAMPLER_SUPPORTED
1415#include < esp_log.h>
1516
1617static const char * TAG = " [AdcSampler]" ;
@@ -22,11 +23,7 @@ AdcSampler::~AdcSampler()
2223{
2324 if (cali_handle_)
2425 {
25- #if defined(CONFIG_IDF_TARGET_ESP32S3)
26- adc_cali_delete_scheme_curve_fitting (cali_handle_);
27- #elif defined(CONFIG_IDF_TARGET_ESP32)
28- adc_cali_delete_scheme_line_fitting (cali_handle_);
29- #endif
26+ delete_calibration (cali_handle_);
3027 cali_handle_ = nullptr ;
3128 }
3229}
@@ -66,29 +63,8 @@ bool AdcSampler::init(int gpio, adc_atten_t atten, adc_bitwidth_t bitwidth, size
6663 }
6764
6865 // Try calibration (requires eFuse data)
69- // ESP32-S3 uses curve-fitting, ESP32 uses line-fitting
70- esp_err_t cal_err = ESP_FAIL;
71-
72- #if defined(CONFIG_IDF_TARGET_ESP32S3)
73- // ESP32-S3 curve fitting calibration
74- adc_cali_curve_fitting_config_t cal_cfg = {
75- .unit_id = unit_,
76- .chan = channel_,
77- .atten = atten_,
78- .bitwidth = bitwidth_,
79- };
80- cal_err = adc_cali_create_scheme_curve_fitting (&cal_cfg, &cali_handle_);
81- #elif defined(CONFIG_IDF_TARGET_ESP32)
82- // ESP32 line-fitting calibration is per-unit, not per-channel
83- adc_cali_line_fitting_config_t cal_cfg = {
84- .unit_id = unit_,
85- .atten = atten_,
86- .bitwidth = bitwidth_,
87- };
88- cal_err = adc_cali_create_scheme_line_fitting (&cal_cfg, &cali_handle_);
89- #endif
90-
91- if (cal_err == ESP_OK)
66+ // Platform-specific: ESP32-S3/S2 use curve-fitting, ESP32 uses line-fitting
67+ if (create_calibration (&cali_handle_))
9268 {
9369 cali_inited_ = true ;
9470 ESP_LOGI (TAG, " ADC calibration initialized" );
@@ -193,4 +169,4 @@ bool AdcSampler::configure_channel(int gpio, adc_atten_t atten, adc_bitwidth_t b
193169 return true ;
194170}
195171
196- #endif // CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32
172+ #endif // ADC_SAMPLER_SUPPORTED
0 commit comments