diff --git a/src/resources/adc_esp32.cc b/src/resources/adc_esp32.cc index 60f9c7ca7..c0971400b 100644 --- a/src/resources/adc_esp32.cc +++ b/src/resources/adc_esp32.cc @@ -35,6 +35,8 @@ namespace toit { #if CONFIG_IDF_TARGET_ESP32 +#define ADC_CLK_SRC_DEFAULT ADC_RTC_CLK_SRC_DEFAULT + static int get_adc1_channel(int pin) { switch (pin) { case 36: return ADC_CHANNEL_0; @@ -67,6 +69,8 @@ static int get_adc2_channel(int pin) { #elif CONFIG_IDF_TARGET_ESP32C3 +#define ADC_CLK_SRC_DEFAULT ADC_DIGI_CLK_SRC_DEFAULT + static int get_adc1_channel(int pin) { switch (pin) { case 0: return ADC_CHANNEL_0; @@ -87,6 +91,8 @@ static int get_adc2_channel(int pin) { #elif CONFIG_IDF_TARGET_ESP32C6 +#define ADC_CLK_SRC_DEFAULT ADC_DIGI_CLK_SRC_DEFAULT + static int get_adc1_channel(int pin) { switch (pin) { case 0: return ADC_CHANNEL_0; @@ -107,6 +113,9 @@ static int get_adc2_channel(int pin) { #elif CONFIG_IDF_TARGET_ESP32S2 +#define ADC_CLK_SRC_DEFAULT ADC_RTC_CLK_SRC_DEFAULT +#define ADC_HAS_NO_DEFAULT_VREF 1 + static int get_adc1_channel(int pin) { switch (pin) { case 1: return ADC_CHANNEL_0; @@ -141,6 +150,8 @@ static int get_adc2_channel(int pin) { #elif CONFIG_IDF_TARGET_ESP32S3 +#define ADC_CLK_SRC_DEFAULT ADC_RTC_CLK_SRC_DEFAULT + static int get_adc1_channel(int pin) { switch (pin) { case 1: return ADC_CHANNEL_0; @@ -228,7 +239,7 @@ static esp_err_t adc_use(adc_oneshot_unit_handle_t* unit_handle) { ASSERT(*unit_handle == null); adc_oneshot_unit_init_cfg_t init_config = { .unit_id = unit_id, - .clk_src = ADC_RTC_CLK_SRC_DEFAULT, + .clk_src = ADC_CLK_SRC_DEFAULT, .ulp_mode = ADC_ULP_MODE_DISABLE, }; @@ -274,8 +285,10 @@ static esp_err_t calibration_init(adc_unit_t unit, .unit_id = unit, .atten = atten, .bitwidth = ADC_BITWIDTH_DEFAULT, +#ifndef ADC_HAS_NO_DEFAULT_VREF // If the chip wasn't calibrated just use the default vref. .default_vref = 1100, +#endif }; err = adc_cali_create_scheme_line_fitting(&cali_config, handle); #else