From ad8862fa19bcd6e0d7643213adaf52a37c4bddfd Mon Sep 17 00:00:00 2001 From: Armando Date: Wed, 20 Jul 2022 15:01:31 +0800 Subject: [PATCH] adc: fix esp32s2 continuous mode converted bytes issue When working in continuous mode, hardware will continuously trigger ADC to do conversions. On esp32s2, 2 bytes will be generated per conversion. Prior to this commit, driver assumes 4 bytes per conversion (on s2). This commit fixed this issue. --- components/driver/adc.c | 2 +- components/hal/adc_hal.c | 2 +- components/hal/include/hal/adc_hal.h | 3 --- components/soc/esp32/include/soc/soc_caps.h | 2 ++ components/soc/esp32c3/include/soc/soc_caps.h | 2 ++ components/soc/esp32h2/include/soc/soc_caps.h | 2 ++ components/soc/esp32s2/include/soc/soc_caps.h | 2 ++ components/soc/esp32s3/include/soc/soc_caps.h | 2 ++ 8 files changed, 12 insertions(+), 5 deletions(-) diff --git a/components/driver/adc.c b/components/driver/adc.c index d16bdc7e1f..b28b9d919a 100644 --- a/components/driver/adc.c +++ b/components/driver/adc.c @@ -280,7 +280,7 @@ esp_err_t adc_digi_initialize(const adc_digi_init_config_t *init_config) #endif .desc_max_num = INTERNAL_BUF_NUM, .dma_chan = dma_chan, - .eof_num = init_config->conv_num_each_intr / ADC_HAL_DATA_LEN_PER_CONV + .eof_num = init_config->conv_num_each_intr / SOC_ADC_DIGI_DATA_BYTES_PER_CONV }; adc_hal_context_config(&s_adc_digi_ctx->hal, &config); diff --git a/components/hal/adc_hal.c b/components/hal/adc_hal.c index 0994202714..42855524ca 100644 --- a/components/hal/adc_hal.c +++ b/components/hal/adc_hal.c @@ -350,7 +350,7 @@ void adc_hal_digi_start(adc_hal_context_t *hal, uint8_t *data_buf) //reset the current descriptor address hal->cur_desc_ptr = &hal->desc_dummy_head; - adc_hal_digi_dma_link_descriptors(hal->rx_desc, data_buf, hal->eof_num * ADC_HAL_DATA_LEN_PER_CONV, hal->desc_max_num); + adc_hal_digi_dma_link_descriptors(hal->rx_desc, data_buf, hal->eof_num * SOC_ADC_DIGI_DATA_BYTES_PER_CONV, hal->desc_max_num); //start DMA adc_dma_ll_rx_start(hal->dev, hal->dma_chan, (lldesc_t *)hal->rx_desc); diff --git a/components/hal/include/hal/adc_hal.h b/components/hal/include/hal/adc_hal.h index b8455e27ec..787e50246e 100644 --- a/components/hal/include/hal/adc_hal.h +++ b/components/hal/include/hal/adc_hal.h @@ -36,9 +36,6 @@ #define ADC_HAL_DMA_INTR_MASK BIT(9) #endif -//For ADC module, each conversion contains 4 bytes -#define ADC_HAL_DATA_LEN_PER_CONV 4 - typedef enum adc_hal_work_mode_t { ADC_HAL_ULP_MODE, ADC_HAL_SINGLE_READ_MODE, diff --git a/components/soc/esp32/include/soc/soc_caps.h b/components/soc/esp32/include/soc/soc_caps.h index 15ca029b3c..1225d9a1ea 100644 --- a/components/soc/esp32/include/soc/soc_caps.h +++ b/components/soc/esp32/include/soc/soc_caps.h @@ -90,6 +90,8 @@ #define SOC_ADC_PATT_LEN_MAX (16) //Two pattern table, each contains 16 items. Each item takes 1 byte. But only support ADC1 using DMA mode #define SOC_ADC_DIGI_MIN_BITWIDTH (9) #define SOC_ADC_DIGI_MAX_BITWIDTH (12) +#define SOC_ADC_DIGI_RESULT_BYTES (2) +#define SOC_ADC_DIGI_DATA_BYTES_PER_CONV (4) /*!< F_sample = F_digi_con / 2 / interval. F_digi_con = 5M for now. 30 <= interva <= 4095 */ #define SOC_ADC_SAMPLE_FREQ_THRES_HIGH (2*1000*1000) #define SOC_ADC_SAMPLE_FREQ_THRES_LOW (2000) diff --git a/components/soc/esp32c3/include/soc/soc_caps.h b/components/soc/esp32c3/include/soc/soc_caps.h index a564972a56..24a8ebe11b 100644 --- a/components/soc/esp32c3/include/soc/soc_caps.h +++ b/components/soc/esp32c3/include/soc/soc_caps.h @@ -55,6 +55,8 @@ #define SOC_ADC_DIGI_CONTROLLER_NUM (1U) #define SOC_ADC_PATT_LEN_MAX (8) /*!< One pattern table, each contains 8 items. Each item takes 1 byte */ #define SOC_ADC_DIGI_MAX_BITWIDTH (12) +#define SOC_ADC_DIGI_RESULT_BYTES (4) +#define SOC_ADC_DIGI_DATA_BYTES_PER_CONV (4) #define SOC_ADC_DIGI_FILTER_NUM (2) #define SOC_ADC_DIGI_MONITOR_NUM (2) /*!< F_sample = F_digi_con / 2 / interval. F_digi_con = 5M for now. 30 <= interva <= 4095 */ diff --git a/components/soc/esp32h2/include/soc/soc_caps.h b/components/soc/esp32h2/include/soc/soc_caps.h index 629834b868..94761eb81b 100644 --- a/components/soc/esp32h2/include/soc/soc_caps.h +++ b/components/soc/esp32h2/include/soc/soc_caps.h @@ -45,6 +45,8 @@ #define SOC_ADC_DIGI_CONTROLLER_NUM (1U) #define SOC_ADC_PATT_LEN_MAX (8) /*!< One pattern table, each contains 8 items. Each item takes 1 byte */ #define SOC_ADC_DIGI_MAX_BITWIDTH (12) +#define SOC_ADC_DIGI_RESULT_BYTES (4) +#define SOC_ADC_DIGI_DATA_BYTES_PER_CONV (4) #define SOC_ADC_DIGI_FILTER_NUM (2) #define SOC_ADC_DIGI_MONITOR_NUM (2) /*!< F_sample = F_digi_con / 2 / interval. F_digi_con = 5M for now. 30 <= interva <= 4095 */ diff --git a/components/soc/esp32s2/include/soc/soc_caps.h b/components/soc/esp32s2/include/soc/soc_caps.h index 8bb13f3936..c75571aae0 100644 --- a/components/soc/esp32s2/include/soc/soc_caps.h +++ b/components/soc/esp32s2/include/soc/soc_caps.h @@ -69,6 +69,8 @@ #define SOC_ADC_DIGI_CONTROLLER_NUM (2) #define SOC_ADC_PATT_LEN_MAX (32) /*!< Two pattern table, each contains 16 items. Each item takes 1 byte */ #define SOC_ADC_DIGI_MAX_BITWIDTH (12) +#define SOC_ADC_DIGI_RESULT_BYTES (2) +#define SOC_ADC_DIGI_DATA_BYTES_PER_CONV (2) /*!< F_sample = F_digi_con / 2 / interval. F_digi_con = 5M for now. 30 <= interva <= 4095 */ #define SOC_ADC_SAMPLE_FREQ_THRES_HIGH 83333 #define SOC_ADC_SAMPLE_FREQ_THRES_LOW 611 diff --git a/components/soc/esp32s3/include/soc/soc_caps.h b/components/soc/esp32s3/include/soc/soc_caps.h index 53d385e067..583ba949e9 100644 --- a/components/soc/esp32s3/include/soc/soc_caps.h +++ b/components/soc/esp32s3/include/soc/soc_caps.h @@ -57,6 +57,8 @@ #define SOC_ADC_DIGI_CONTROLLER_NUM (2) #define SOC_ADC_PATT_LEN_MAX (24) //Two pattern table, each contains 12 items. Each item takes 1 byte #define SOC_ADC_DIGI_MAX_BITWIDTH (12) +#define SOC_ADC_DIGI_RESULT_BYTES (4) +#define SOC_ADC_DIGI_DATA_BYTES_PER_CONV (4) /*!< F_sample = F_digi_con / 2 / interval. F_digi_con = 5M for now. 30 <= interva <= 4095 */ #define SOC_ADC_SAMPLE_FREQ_THRES_HIGH 83333 #define SOC_ADC_SAMPLE_FREQ_THRES_LOW 611