Skip to content

Commit f27a924

Browse files
committed
fix: adc range extend apply tag
1 parent 7ee98cd commit f27a924

File tree

6 files changed

+42
-38
lines changed

6 files changed

+42
-38
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ repos:
3535
.*_pb2.py|
3636
.*.pb-c.h|
3737
.*.pb-c.c|
38-
.*.yuv
38+
.*.yuv|
39+
.*.patch
3940
)$
4041
- id: end-of-file-fixer
4142
exclude: *whitespace_excludes

codespell-ignore-list

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ ser
1616
TE
1717
uncompressible
1818
wHeigh
19+
shoudn't
20+
definations

docs/_static/esp32s3_adc_range_to_3100.patch

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
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
44
Subject: [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

1313
diff --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+
4645
diff --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)
116115
diff --git a/components/efuse/esp32s3/include/esp_efuse_rtc_calib.h b/components/efuse/esp32s3/include/esp_efuse_rtc_calib.h
117116
index 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
136135
diff --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+
--
204203
2.34.1
204+

docs/en/others/adc_range.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Overall, during each ADC measurement, there will be 1-2 times ADC reading. For m
2020
Patch Use Guide
2121
-------------------
2222

23-
At present, the patch file is developed based on ESP-IDF ``release/v4.4`` branch:
23+
At present, the patch file is developed based on ESP-IDF ``v4.4.8``:
2424

25-
1. Please make sure ESP-IDF has been ``checked out`` to the ``release/v4.4`` branch
25+
1. Please make sure ESP-IDF has been ``checked out`` to the ``v4.4.8``
2626
2. Please download file :download:`esp32s3_adc_range_to_3100.patch <../../_static/esp32s3_adc_range_to_3100.patch>` to anywhere you want
2727
3. Using command ``git am --signoff < esp32s3_adc_range_to_3100.patch`` to apply the patch to ESP-IDF
2828

docs/zh_CN/others/adc_range.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ ESP32-S3 可通过配置寄存器调整 ADC 的偏置电压,再结合高电压
2020
Patch 使用方法
2121
-------------------
2222

23-
当前 Patch 基于 ESP-IDF ``release/v4.4`` 分支开发
23+
当前 Patch 基于 ESP-IDF ``v4.4.8`` 开发
2424

25-
1. 确认 ESP-IDF 已经 ``checkout`` 到 ``release/v4.4`` 分支
25+
1. 确认 ESP-IDF 已经 ``checkout`` 到 ``v4.4.8``
2626
2. 下载 :download:`esp32s3_adc_range_to_3100.patch <../../_static/esp32s3_adc_range_to_3100.patch>` 文件
2727
3. 使用指令 ``git am --signoff < esp32s3_adc_range_to_3100.patch`` 将 Patch 应用到 IDF 中
2828
4. 请注意, 该方案仅对 ``esp_adc_cal_get_voltage`` 接口有效,用户可直接调用该接口获取扩展后的读数

tools/ci/astyle-rules.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ not_formatted_permanent:
3737
- "components/gui/lvgl_gui/"
3838
- "components/usb/usb_stream/test_apps/main/wave_1ch_16bits.c"
3939
- "components/utilities/xz/"
40+
- "docs/_static/esp32s3_adc_range_to_3100.patch"
4041
- "docs/doxygen-known-warnings.txt"
4142
- "docs/sphinx-known-warnings.txt"
4243
- "examples/hmi/lvgl_coffee/"

0 commit comments

Comments
 (0)