Skip to content

Commit

Permalink
Merge branch 'fix/fix_adc_range_extend_apply_tag' into 'master'
Browse files Browse the repository at this point in the history
fix: adc range extend apply tag

See merge request ae_group/esp-iot-solution!1080
  • Loading branch information
leeebo committed Sep 19, 2024
2 parents 7ee98cd + f27a924 commit e1ee3d1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ repos:
.*_pb2.py|
.*.pb-c.h|
.*.pb-c.c|
.*.yuv
.*.yuv|
.*.patch
)$
- id: end-of-file-fixer
exclude: *whitespace_excludes
Expand Down
2 changes: 2 additions & 0 deletions codespell-ignore-list
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ ser
TE
uncompressible
wHeigh
shoudn't
definations
66 changes: 33 additions & 33 deletions docs/_static/esp32s3_adc_range_to_3100.patch
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
From 2b3ffaf974a82c25bc20e0335de7b9bc2e2ad5c7 Mon Sep 17 00:00:00 2001
From: Li Bo <libo@espressif.com>
Date: Mon, 7 Nov 2022 14:32:54 +0800
From 9696f0479565203ec3638cff3f2f38e0dfbcba4b Mon Sep 17 00:00:00 2001
From: yanke <yanke2@espressif.com>
Date: Wed, 18 Sep 2024 16:36:27 +0800
Subject: [PATCH] fix(adc): support esp32s3 adc range above 3100mv

---
components/driver/adc.c | 11 ++++-
.../efuse/esp32s3/esp_efuse_rtc_calib.c | 44 ++++++++++++++++++-
components/driver/adc.c | 9 ++++
.../efuse/esp32s3/esp_efuse_rtc_calib.c | 45 ++++++++++++++++++-
.../esp32s3/include/esp_efuse_rtc_calib.h | 9 ++++
components/esp_adc_cal/esp_adc_cal_common.c | 44 +++++++++++++++++++
4 files changed, 105 insertions(+), 3 deletions(-)
components/esp_adc_cal/esp_adc_cal_common.c | 44 ++++++++++++++++++
4 files changed, 106 insertions(+), 1 deletion(-)

diff --git a/components/driver/adc.c b/components/driver/adc.c
index b28b9d919a..b9faac93d5 100644
index 756ec9f26c..4743dae082 100644
--- a/components/driver/adc.c
+++ b/components/driver/adc.c
@@ -844,11 +844,16 @@ static uint16_t s_adc_cali_param[SOC_ADC_PERIPH_NUM][ADC_ATTEN_MAX] = {};
//This function shouldn't be called inside critical section or ISR
@@ -866,11 +866,17 @@ static uint16_t s_adc_cali_param[SOC_ADC_PERIPH_NUM][ADC_ATTEN_MAX] = {};
//This function shoudn't be called inside critical section or ISR
uint32_t adc_get_calibration_offset(adc_ll_num_t adc_n, adc_channel_t channel, adc_atten_t atten)
{
+#ifdef CONFIG_ENABLE_ADC_USER_CODE_OFFSET
Expand All @@ -25,40 +25,39 @@ index b28b9d919a..b9faac93d5 100644
ESP_LOGV(ADC_TAG, "Use calibrated val ADC%d atten=%d: %04X", adc_n, atten, s_adc_cali_param[adc_n][atten]);
return (uint32_t)s_adc_cali_param[adc_n][atten];
}
-
+#ifdef CONFIG_ENABLE_ADC_USER_CODE_OFFSET
+ }
+#endif
// check if we can fetch the values from eFuse.
int version = esp_efuse_rtc_calib_get_ver();

@@ -866,7 +871,9 @@ uint32_t adc_get_calibration_offset(adc_ll_num_t adc_n, adc_channel_t channel, a
ADC_EXIT_CRITICAL();
adc_power_release();

@@ -889,6 +895,9 @@ uint32_t adc_get_calibration_offset(adc_ll_num_t adc_n, adc_channel_t channel, a
sar_periph_ctrl_adc_oneshot_power_release();
}
-
+#ifdef CONFIG_ENABLE_ADC_USER_CODE_OFFSET
+ esp_efuse_rtc_calib_clear_init_code_offset_flag(adc_n, atten);
+#endif
s_adc_cali_param[adc_n][atten] = init_code;
ESP_LOGV(ADC_TAG, "Calib(V%d) ADC%d atten=%d: %04X", version, adc_n, atten, init_code);

diff --git a/components/efuse/esp32s3/esp_efuse_rtc_calib.c b/components/efuse/esp32s3/esp_efuse_rtc_calib.c
index ec5f76814c..99c9aff483 100644
index 7fdcdc46b9..8966976ff6 100644
--- a/components/efuse/esp32s3/esp_efuse_rtc_calib.c
+++ b/components/efuse/esp32s3/esp_efuse_rtc_calib.c
@@ -9,6 +9,7 @@
#include "esp_log.h"
#include "esp_efuse.h"
#include "esp_efuse_table.h"
+#include "esp_efuse_rtc_calib.h"

//Don't introduce new dependency of ADC, keep these macro same as ADC related definitions
//Don't introduce new dependency of ADC, keep these macro same as ADC related definations
#define ADC_ATTEN_MAX 4
@@ -30,6 +31,44 @@ int esp_efuse_rtc_calib_get_ver(void)
return cali_version_v1;
}

+#ifdef CONFIG_ENABLE_ADC_USER_CODE_OFFSET
+static uint32_t adc_icode_offset[ADC_NUM_MAX][4] = {0};
+static bool adc_icode_offset_flag[ADC_NUM_MAX][4] = {0};
Expand Down Expand Up @@ -100,18 +99,18 @@ index ec5f76814c..99c9aff483 100644
uint32_t esp_efuse_rtc_calib_get_init_code(int version, uint32_t adc_unit, int atten)
{
assert(version == 1);
@@ -61,8 +100,11 @@ uint32_t esp_efuse_rtc_calib_get_init_code(int version, uint32_t adc_unit, int a
adc_icode[2] = adc_icode_diff[2] + adc_icode[1];
@@ -62,7 +101,11 @@ uint32_t esp_efuse_rtc_calib_get_init_code(int version, uint32_t adc_unit, int a
adc_icode[3] = adc_icode_diff[3] + adc_icode[2];
}
-

- return adc_icode[atten];
+#ifdef CONFIG_ENABLE_ADC_USER_CODE_OFFSET
+ return adc_icode[atten] + adc_icode_offset[adc_unit][atten];
+#else
return adc_icode[atten];
+ return adc_icode[atten];
+#endif
}

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)
diff --git a/components/efuse/esp32s3/include/esp_efuse_rtc_calib.h b/components/efuse/esp32s3/include/esp_efuse_rtc_calib.h
index e2f5b54329..9d215ac057 100644
Expand All @@ -120,7 +119,7 @@ index e2f5b54329..9d215ac057 100644
@@ -54,6 +54,15 @@ esp_err_t esp_efuse_rtc_calib_get_cal_voltage(int version, uint32_t adc_unit, in
*/
float esp_efuse_rtc_calib_get_cal_temp(int version);

+#define CONFIG_ENABLE_ADC_USER_CODE_OFFSET 1
+
+#ifdef CONFIG_ENABLE_ADC_USER_CODE_OFFSET
Expand All @@ -134,7 +133,7 @@ index e2f5b54329..9d215ac057 100644
}
#endif
diff --git a/components/esp_adc_cal/esp_adc_cal_common.c b/components/esp_adc_cal/esp_adc_cal_common.c
index 09878cc015..9a5af2432e 100644
index 09878cc015..7910359718 100644
--- a/components/esp_adc_cal/esp_adc_cal_common.c
+++ b/components/esp_adc_cal/esp_adc_cal_common.c
@@ -12,6 +12,7 @@
Expand All @@ -144,7 +143,7 @@ index 09878cc015..9a5af2432e 100644
+#include "esp_efuse_rtc_calib.h"
#include "esp_adc_cal.h"
#include "esp_adc_cal_internal.h"

@@ -33,11 +34,54 @@ esp_err_t esp_adc_cal_get_voltage(adc_channel_t channel,
} else {
ESP_RETURN_ON_FALSE(channel < SOC_ADC_CHANNEL_NUM(1), ESP_ERR_INVALID_ARG, TAG, "Invalid channel");
Expand All @@ -154,7 +153,7 @@ index 09878cc015..9a5af2432e 100644
+ return ret;
+ }
}

if (ret == ESP_OK) {
*voltage = esp_adc_cal_raw_to_voltage((uint32_t)adc_reading, chars);
}
Expand All @@ -165,7 +164,7 @@ index 09878cc015..9a5af2432e 100644
+#else //using float type
+ typedef const float ADC_CAL_TYPE;
+#endif
+ if(chars->atten == ADC_ATTEN_DB_11) {
+ if(chars->atten == ADC_ATTEN_DB_12) {
+ if (*voltage > 2900) {
+ /* add initcode offset */
+ ESP_LOGV(TAG, "first is %u", *voltage);
Expand Down Expand Up @@ -199,6 +198,7 @@ index 09878cc015..9a5af2432e 100644
+
return ret;
}

--
--
2.34.1

4 changes: 2 additions & 2 deletions docs/en/others/adc_range.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Overall, during each ADC measurement, there will be 1-2 times ADC reading. For m
Patch Use Guide
-------------------

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

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

Expand Down
4 changes: 2 additions & 2 deletions docs/zh_CN/others/adc_range.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ ESP32-S3 可通过配置寄存器调整 ADC 的偏置电压,再结合高电压
Patch 使用方法
-------------------

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

1. 确认 ESP-IDF 已经 ``checkout`` 到 ``release/v4.4`` 分支
1. 确认 ESP-IDF 已经 ``checkout`` 到 ``v4.4.8``
2. 下载 :download:`esp32s3_adc_range_to_3100.patch <../../_static/esp32s3_adc_range_to_3100.patch>` 文件
3. 使用指令 ``git am --signoff < esp32s3_adc_range_to_3100.patch`` 将 Patch 应用到 IDF 中
4. 请注意, 该方案仅对 ``esp_adc_cal_get_voltage`` 接口有效,用户可直接调用该接口获取扩展后的读数
Expand Down
1 change: 1 addition & 0 deletions tools/ci/astyle-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ not_formatted_permanent:
- "components/gui/lvgl_gui/"
- "components/usb/usb_stream/test_apps/main/wave_1ch_16bits.c"
- "components/utilities/xz/"
- "docs/_static/esp32s3_adc_range_to_3100.patch"
- "docs/doxygen-known-warnings.txt"
- "docs/sphinx-known-warnings.txt"
- "examples/hmi/lvgl_coffee/"
Expand Down

0 comments on commit e1ee3d1

Please sign in to comment.