1- From 2b3ffaf974a82c25bc20e0335de7b9bc2e2ad5c7 Mon Sep 17 00:00:00 2001
2- From: Li Bo <libo @espressif.com>
3- Date: Mon, 7 Nov 2022 14:32:54 +0800
1+ From 9696f0479565203ec3638cff3f2f38e0dfbcba4b Mon Sep 17 00:00:00 2001
2+ From: yanke <yanke2 @espressif.com>
3+ Date: Wed, 18 Sep 2024 16:36:27 +0800
44Subject: [PATCH] fix(adc): support esp32s3 adc range above 3100mv
55
66---
7- components/driver/adc.c | 11 ++++-
8- .../efuse/esp32s3/esp_efuse_rtc_calib.c | 44 ++++++++++++++++++-
7+ components/driver/adc.c | 9 ++++
8+ .../efuse/esp32s3/esp_efuse_rtc_calib.c | 45 ++++++++++++++++++-
99 .../esp32s3/include/esp_efuse_rtc_calib.h | 9 ++++
10- components/esp_adc_cal/esp_adc_cal_common.c | 44 +++++++++++++++++++
11- 4 files changed, 105 insertions(+), 3 deletions (-)
10+ components/esp_adc_cal/esp_adc_cal_common.c | 44 ++++++++++++++++++
11+ 4 files changed, 106 insertions(+), 1 deletion (-)
1212
1313diff --git a/components/driver/adc.c b/components/driver/adc.c
14- index b28b9d919a..b9faac93d5 100644
14+ index 756ec9f26c..4743dae082 100644
1515--- a/components/driver/adc.c
1616+++ b/components/driver/adc.c
17- @@ -844 ,11 +844,16 @@ static uint16_t s_adc_cali_param[SOC_ADC_PERIPH_NUM][ADC_ATTEN_MAX] = {};
18- //This function shouldn 't be called inside critical section or ISR
17+ @@ -866 ,11 +866,17 @@ static uint16_t s_adc_cali_param[SOC_ADC_PERIPH_NUM][ADC_ATTEN_MAX] = {};
18+ //This function shoudn 't be called inside critical section or ISR
1919 uint32_t adc_get_calibration_offset(adc_ll_num_t adc_n, adc_channel_t channel, adc_atten_t atten)
2020 {
2121+ #ifdef CONFIG_ENABLE_ADC_USER_CODE_OFFSET
@@ -25,40 +25,39 @@ index b28b9d919a..b9faac93d5 100644
2525 ESP_LOGV(ADC_TAG, "Use calibrated val ADC%d atten=%d: %04X", adc_n, atten, s_adc_cali_param[adc_n][atten]);
2626 return (uint32_t)s_adc_cali_param[adc_n][atten];
2727 }
28- -
28+
2929+ #ifdef CONFIG_ENABLE_ADC_USER_CODE_OFFSET
3030+ }
3131+ #endif
3232 // check if we can fetch the values from eFuse.
3333 int version = esp_efuse_rtc_calib_get_ver();
34-
35- @@ -866,7 +871,9 @@ uint32_t adc_get_calibration_offset(adc_ll_num_t adc_n, adc_channel_t channel, a
36- ADC_EXIT_CRITICAL();
37- adc_power_release();
34+
35+ @@ -889,6 +895,9 @@ uint32_t adc_get_calibration_offset(adc_ll_num_t adc_n, adc_channel_t channel, a
36+ sar_periph_ctrl_adc_oneshot_power_release();
3837 }
39- -
38+
4039+ #ifdef CONFIG_ENABLE_ADC_USER_CODE_OFFSET
4140+ esp_efuse_rtc_calib_clear_init_code_offset_flag(adc_n, atten);
4241+ #endif
4342 s_adc_cali_param[adc_n][atten] = init_code;
4443 ESP_LOGV(ADC_TAG, "Calib(V%d) ADC%d atten=%d: %04X", version, adc_n, atten, init_code);
45-
44+
4645diff --git a/components/efuse/esp32s3/esp_efuse_rtc_calib.c b/components/efuse/esp32s3/esp_efuse_rtc_calib.c
47- index ec5f76814c..99c9aff483 100644
46+ index 7fdcdc46b9..8966976ff6 100644
4847--- a/components/efuse/esp32s3/esp_efuse_rtc_calib.c
4948+++ b/components/efuse/esp32s3/esp_efuse_rtc_calib.c
5049@@ -9,6 +9,7 @@
5150 #include "esp_log.h"
5251 #include "esp_efuse.h"
5352 #include "esp_efuse_table.h"
5453+ #include "esp_efuse_rtc_calib.h"
55-
56- //Don't introduce new dependency of ADC, keep these macro same as ADC related definitions
54+
55+ //Don't introduce new dependency of ADC, keep these macro same as ADC related definations
5756 #define ADC_ATTEN_MAX 4
5857@@ -30,6 +31,44 @@ int esp_efuse_rtc_calib_get_ver(void)
5958 return cali_version_v1;
6059 }
61-
60+
6261+ #ifdef CONFIG_ENABLE_ADC_USER_CODE_OFFSET
6362+ static uint32_t adc_icode_offset[ADC_NUM_MAX][4] = {0};
6463+ static bool adc_icode_offset_flag[ADC_NUM_MAX][4] = {0};
@@ -100,18 +99,18 @@ index ec5f76814c..99c9aff483 100644
10099 uint32_t esp_efuse_rtc_calib_get_init_code(int version, uint32_t adc_unit, int atten)
101100 {
102101 assert(version == 1);
103- @@ -61,8 +100,11 @@ uint32_t esp_efuse_rtc_calib_get_init_code(int version, uint32_t adc_unit, int a
104- adc_icode[2] = adc_icode_diff[2] + adc_icode[1];
102+ @@ -62,7 +101,11 @@ uint32_t esp_efuse_rtc_calib_get_init_code(int version, uint32_t adc_unit, int a
105103 adc_icode[3] = adc_icode_diff[3] + adc_icode[2];
106104 }
107- -
105+
106+ - return adc_icode[atten];
108107+ #ifdef CONFIG_ENABLE_ADC_USER_CODE_OFFSET
109108+ return adc_icode[atten] + adc_icode_offset[adc_unit][atten];
110109+ #else
111- return adc_icode[atten];
110+ + return adc_icode[atten];
112111+ #endif
113112 }
114-
113+
115114 esp_err_t esp_efuse_rtc_calib_get_cal_voltage(int version, uint32_t adc_unit, int atten, uint32_t *out_digi, uint32_t *out_vol_mv)
116115diff --git a/components/efuse/esp32s3/include/esp_efuse_rtc_calib.h b/components/efuse/esp32s3/include/esp_efuse_rtc_calib.h
117116index e2f5b54329..9d215ac057 100644
@@ -120,7 +119,7 @@ index e2f5b54329..9d215ac057 100644
120119@@ -54,6 +54,15 @@ esp_err_t esp_efuse_rtc_calib_get_cal_voltage(int version, uint32_t adc_unit, in
121120 */
122121 float esp_efuse_rtc_calib_get_cal_temp(int version);
123-
122+
124123+ #define CONFIG_ENABLE_ADC_USER_CODE_OFFSET 1
125124+
126125+ #ifdef CONFIG_ENABLE_ADC_USER_CODE_OFFSET
@@ -134,7 +133,7 @@ index e2f5b54329..9d215ac057 100644
134133 }
135134 #endif
136135diff --git a/components/esp_adc_cal/esp_adc_cal_common.c b/components/esp_adc_cal/esp_adc_cal_common.c
137- index 09878cc015..9a5af2432e 100644
136+ index 09878cc015..7910359718 100644
138137--- a/components/esp_adc_cal/esp_adc_cal_common.c
139138+++ b/components/esp_adc_cal/esp_adc_cal_common.c
140139@@ -12,6 +12,7 @@
@@ -144,7 +143,7 @@ index 09878cc015..9a5af2432e 100644
144143+ #include "esp_efuse_rtc_calib.h"
145144 #include "esp_adc_cal.h"
146145 #include "esp_adc_cal_internal.h"
147-
146+
148147@@ -33,11 +34,54 @@ esp_err_t esp_adc_cal_get_voltage(adc_channel_t channel,
149148 } else {
150149 ESP_RETURN_ON_FALSE(channel < SOC_ADC_CHANNEL_NUM(1), ESP_ERR_INVALID_ARG, TAG, "Invalid channel");
@@ -154,7 +153,7 @@ index 09878cc015..9a5af2432e 100644
154153+ return ret;
155154+ }
156155 }
157-
156+
158157 if (ret == ESP_OK) {
159158 *voltage = esp_adc_cal_raw_to_voltage((uint32_t)adc_reading, chars);
160159 }
@@ -165,7 +164,7 @@ index 09878cc015..9a5af2432e 100644
165164+ #else //using float type
166165+ typedef const float ADC_CAL_TYPE;
167166+ #endif
168- + if(chars->atten == ADC_ATTEN_DB_11 ) {
167+ + if(chars->atten == ADC_ATTEN_DB_12 ) {
169168+ if (*voltage > 2900) {
170169+ /* add initcode offset */
171170+ ESP_LOGV(TAG, "first is %u", *voltage);
@@ -199,6 +198,7 @@ index 09878cc015..9a5af2432e 100644
199198+
200199 return ret;
201200 }
202-
203- - -
201+
202+ - -
2042032.34.1
204+
0 commit comments