From 9c4b822ab13d55765c1da379045a4112ea0e42d7 Mon Sep 17 00:00:00 2001 From: "C.S.M" Date: Mon, 4 Nov 2024 18:09:24 +0800 Subject: [PATCH] feat(temperature_sensor): Add temperature sensor calibration support --- components/efuse/esp32c2/esp_efuse_rtc_calib.c | 17 ++++++++++++++--- components/efuse/esp32c6/esp_efuse_rtc_calib.c | 17 ++++++++++++++--- components/efuse/esp32h2/esp_efuse_rtc_calib.c | 17 ++++++++++++++--- components/efuse/esp32p4/esp_efuse_rtc_calib.c | 3 +-- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/components/efuse/esp32c2/esp_efuse_rtc_calib.c b/components/efuse/esp32c2/esp_efuse_rtc_calib.c index 79d91b2319..673d0e1deb 100644 --- a/components/efuse/esp32c2/esp_efuse_rtc_calib.c +++ b/components/efuse/esp32c2/esp_efuse_rtc_calib.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -111,7 +111,18 @@ esp_err_t esp_efuse_rtc_calib_get_cal_voltage(int version, uint32_t adc_unit, in esp_err_t esp_efuse_rtc_calib_get_tsens_val(float* tsens_cal) { - // Currently calibration is not supported on ESP32-C2, IDF-5236 - *tsens_cal = 0.0; + const esp_efuse_desc_t** cal_temp_efuse; + cal_temp_efuse = ESP_EFUSE_TEMP_CALIB; + int cal_temp_size = esp_efuse_get_field_size(cal_temp_efuse); + assert(cal_temp_size == 9); + + uint32_t cal_temp = 0; + esp_err_t err = esp_efuse_read_field_blob(cal_temp_efuse, &cal_temp, cal_temp_size); + if (err != ESP_OK) { + *tsens_cal = 0.0; + return err; + } + // BIT(8) stands for sign: 1: negative, 0: positive + *tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; return ESP_OK; } diff --git a/components/efuse/esp32c6/esp_efuse_rtc_calib.c b/components/efuse/esp32c6/esp_efuse_rtc_calib.c index 5477b095a4..0f4defa9e1 100644 --- a/components/efuse/esp32c6/esp_efuse_rtc_calib.c +++ b/components/efuse/esp32c6/esp_efuse_rtc_calib.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -132,7 +132,18 @@ esp_err_t esp_efuse_rtc_calib_get_cal_voltage(int version, uint32_t adc_unit, in esp_err_t esp_efuse_rtc_calib_get_tsens_val(float* tsens_cal) { - // Currently calibration is not supported on ESP32-C6, IDF-5236 - *tsens_cal = 0; + const esp_efuse_desc_t** cal_temp_efuse; + cal_temp_efuse = ESP_EFUSE_TEMP_CALIB; + int cal_temp_size = esp_efuse_get_field_size(cal_temp_efuse); + assert(cal_temp_size == 9); + + uint32_t cal_temp = 0; + esp_err_t err = esp_efuse_read_field_blob(cal_temp_efuse, &cal_temp, cal_temp_size); + if (err != ESP_OK) { + *tsens_cal = 0.0; + return err; + } + // BIT(8) stands for sign: 1: negative, 0: positive + *tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; return ESP_OK; } diff --git a/components/efuse/esp32h2/esp_efuse_rtc_calib.c b/components/efuse/esp32h2/esp_efuse_rtc_calib.c index 2ff20ea3a3..26f4426175 100644 --- a/components/efuse/esp32h2/esp_efuse_rtc_calib.c +++ b/components/efuse/esp32h2/esp_efuse_rtc_calib.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -124,7 +124,18 @@ esp_err_t esp_efuse_rtc_calib_get_cal_voltage(int version, uint32_t adc_unit, in esp_err_t esp_efuse_rtc_calib_get_tsens_val(float* tsens_cal) { - // Currently calibration is not supported on ESP32-H2, IDF-5236 - *tsens_cal = 0; + const esp_efuse_desc_t** cal_temp_efuse; + cal_temp_efuse = ESP_EFUSE_TEMP_CALIB; + int cal_temp_size = esp_efuse_get_field_size(cal_temp_efuse); + assert(cal_temp_size == 9); + + uint32_t cal_temp = 0; + esp_err_t err = esp_efuse_read_field_blob(cal_temp_efuse, &cal_temp, cal_temp_size); + if (err != ESP_OK) { + *tsens_cal = 0.0; + return err; + } + // BIT(8) stands for sign: 1: negative, 0: positive + *tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; return ESP_OK; } diff --git a/components/efuse/esp32p4/esp_efuse_rtc_calib.c b/components/efuse/esp32p4/esp_efuse_rtc_calib.c index 47ac9117d7..8ae810bbc7 100644 --- a/components/efuse/esp32p4/esp_efuse_rtc_calib.c +++ b/components/efuse/esp32p4/esp_efuse_rtc_calib.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -35,7 +35,6 @@ esp_err_t esp_efuse_rtc_calib_get_cal_voltage(int version, int atten, uint32_t* esp_err_t esp_efuse_rtc_calib_get_tsens_val(float* tsens_cal) { - //TODO: IDF-7482 *tsens_cal = 0; return ESP_ERR_NOT_SUPPORTED; }