From 10f3b29d6b44a937b1e06e2277e159e6b274b4b4 Mon Sep 17 00:00:00 2001 From: P-R-O-C-H-Y <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 14 Feb 2022 13:33:48 +0100 Subject: [PATCH 1/2] ADC esp32s2 attenuation fix for DAC pins --- cores/esp32/esp32-hal-adc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cores/esp32/esp32-hal-adc.c b/cores/esp32/esp32-hal-adc.c index 674554fcce9..3c7dbeb3595 100644 --- a/cores/esp32/esp32-hal-adc.c +++ b/cores/esp32/esp32-hal-adc.c @@ -27,6 +27,7 @@ #include "soc/rtc_io_reg.h" #include "esp32/rom/ets_sys.h" #include "esp_intr_alloc.h" +#include "soc/dac_channel.h" #define DEFAULT_VREF 1100 static esp_adc_cal_characteristics_t *__analogCharacteristics[2] = {NULL, NULL}; static uint16_t __analogVRef = 0; @@ -35,6 +36,7 @@ static uint8_t __analogVRefPin = 0; #include "esp32s2/rom/ets_sys.h" #include "soc/sens_reg.h" #include "soc/rtc_io_reg.h" +#include "soc/dac_channel.h" #elif CONFIG_IDF_TARGET_ESP32C3 #include "esp32c3/rom/ets_sys.h" #else @@ -142,9 +144,9 @@ bool __adcAttachPin(uint8_t pin){ #endif } #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 - else if(pin == 25){ + else if(pin == DAC_CHANNEL_1_GPIO_NUM){ CLEAR_PERI_REG_MASK(RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_XPD_DAC | RTC_IO_PDAC1_DAC_XPD_FORCE);//stop dac1 - } else if(pin == 26){ + } else if(pin == DAC_CHANNEL_2_GPIO_NUM){ CLEAR_PERI_REG_MASK(RTC_IO_PAD_DAC2_REG, RTC_IO_PDAC2_XPD_DAC | RTC_IO_PDAC2_DAC_XPD_FORCE);//stop dac2 } #endif From cd08cb3b23e003d8a9773bd12ba68812d47673a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Procha=CC=81zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Wed, 16 Feb 2022 13:34:08 +0100 Subject: [PATCH 2/2] Use soc define instead config target --- cores/esp32/esp32-hal-adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-adc.c b/cores/esp32/esp32-hal-adc.c index 3c7dbeb3595..0598be61df7 100644 --- a/cores/esp32/esp32-hal-adc.c +++ b/cores/esp32/esp32-hal-adc.c @@ -143,7 +143,7 @@ bool __adcAttachPin(uint8_t pin){ } #endif } -#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 +#if SOC_DAC_SUPPORTED else if(pin == DAC_CHANNEL_1_GPIO_NUM){ CLEAR_PERI_REG_MASK(RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_XPD_DAC | RTC_IO_PDAC1_DAC_XPD_FORCE);//stop dac1 } else if(pin == DAC_CHANNEL_2_GPIO_NUM){