diff --git a/components/esp_driver_tsens/src/temperature_sensor.c b/components/esp_driver_tsens/src/temperature_sensor.c index 5353b21c59..c2a6f5b4b2 100644 --- a/components/esp_driver_tsens/src/temperature_sensor.c +++ b/components/esp_driver_tsens/src/temperature_sensor.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -22,7 +22,6 @@ #include "clk_ctrl_os.h" #include "freertos/FreeRTOS.h" #include "driver/temperature_sensor.h" -#include "esp_efuse_rtc_calib.h" #include "esp_private/periph_ctrl.h" #include "temperature_sensor_private.h" #include "hal/temperature_sensor_ll.h" @@ -36,7 +35,7 @@ static const char *TAG = "temperature_sensor"; -static float s_deltaT = NAN; // unused number +static int s_deltaT = INT_MIN; // unused number #if SOC_TEMPERATURE_SENSOR_INTR_SUPPORT static int8_t s_temperature_regval_2_celsius(temperature_sensor_handle_t tsens, uint8_t regval); @@ -274,19 +273,20 @@ esp_err_t temperature_sensor_disable(temperature_sensor_handle_t tsens) static esp_err_t read_delta_t_from_efuse(void) { - if (temperature_sensor_ll_calib_get_tsens_val(&s_deltaT) != true) { - ESP_LOGW(TAG, "Calibration failed"); + s_deltaT = temperature_sensor_ll_load_calib_param(); + if (s_deltaT == 0) { + ESP_LOGW(TAG, "No calibration param in eFuse"); } - ESP_LOGD(TAG, "s_deltaT = %f", s_deltaT); + ESP_LOGD(TAG, "s_deltaT = %d", s_deltaT); return ESP_OK; } static float parse_temp_sensor_raw_value(int16_t tsens_raw) { - if (isnan(s_deltaT)) { //suggests that the value is not initialized + if (s_deltaT == INT_MIN) { //suggests that the value is not initialized read_delta_t_from_efuse(); } - float result = tsens_raw - s_deltaT / 10.0; + float result = tsens_raw - (float)s_deltaT / 10.0; return result; } diff --git a/components/hal/esp32c2/include/hal/temperature_sensor_ll.h b/components/hal/esp32c2/include/hal/temperature_sensor_ll.h index a9e77ae80d..003c1fbafc 100644 --- a/components/hal/esp32c2/include/hal/temperature_sensor_ll.h +++ b/components/hal/esp32c2/include/hal/temperature_sensor_ll.h @@ -155,18 +155,15 @@ static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div) /** * @brief Retrieve and calculate the temperature sensor calibration value. * - * @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored. - * The output is a signed floating-point value based on the efuse data. - * - * @return returns true to indicate successful retrieval. false for calibration failed. + * @return Temperature calibration value. */ -static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal) +static inline int temperature_sensor_ll_load_calib_param(void) { uint32_t cal_temp = 0; cal_temp = EFUSE.rd_blk2_data2.temp_calib; // 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 true; + int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; + return tsens_cal; } #ifdef __cplusplus diff --git a/components/hal/esp32c3/include/hal/temperature_sensor_ll.h b/components/hal/esp32c3/include/hal/temperature_sensor_ll.h index 2d14d04b1d..ea14092a46 100644 --- a/components/hal/esp32c3/include/hal/temperature_sensor_ll.h +++ b/components/hal/esp32c3/include/hal/temperature_sensor_ll.h @@ -155,22 +155,17 @@ static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div) /** * @brief Retrieve and calculate the temperature sensor calibration value. * - * @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored. - * The output is a signed floating-point value based on the efuse data. - * - * @return returns true to indicate successful retrieval. false for calibration failed. + * @return Temperature calibration value. */ -static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal) +static inline int temperature_sensor_ll_load_calib_param(void) { - uint32_t version = efuse_ll_get_blk_version_major(); - if (version == 0) { - *tsens_cal = 0.0; - return ESP_ERR_NOT_SUPPORTED; + if (efuse_ll_get_blk_version_major() == 0) { + return 0; } - uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temp_calib; - *tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; - return ESP_OK; + // BIT(8) stands for sign: 1: negative, 0: positive + int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; + return tsens_cal; } #ifdef __cplusplus diff --git a/components/hal/esp32c5/include/hal/temperature_sensor_ll.h b/components/hal/esp32c5/include/hal/temperature_sensor_ll.h index 20fa2afcb8..85035b7c84 100644 --- a/components/hal/esp32c5/include/hal/temperature_sensor_ll.h +++ b/components/hal/esp32c5/include/hal/temperature_sensor_ll.h @@ -270,16 +270,14 @@ static inline void temperature_sensor_ll_set_sample_rate(uint16_t rate) /** * @brief Retrieve and calculate the temperature sensor calibration value. * - * @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored. - * The output is a signed floating-point value based on the efuse data. - * - * @return returns true to indicate successful retrieval. false for calibration failed. + * @return Temperature calibration value. */ -static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal) +static inline int temperature_sensor_ll_load_calib_param(void) { uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temperature_sensor; - *tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; - return true; + // BIT(8) stands for sign: 1: negative, 0: positive + int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; + return tsens_cal; } #ifdef __cplusplus diff --git a/components/hal/esp32c6/include/hal/temperature_sensor_ll.h b/components/hal/esp32c6/include/hal/temperature_sensor_ll.h index 3c9b61ca29..54803190e3 100644 --- a/components/hal/esp32c6/include/hal/temperature_sensor_ll.h +++ b/components/hal/esp32c6/include/hal/temperature_sensor_ll.h @@ -270,16 +270,14 @@ static inline void temperature_sensor_ll_set_sample_rate(uint16_t rate) /** * @brief Retrieve and calculate the temperature sensor calibration value. * - * @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored. - * The output is a signed floating-point value based on the efuse data. - * - * @return returns true to indicate successful retrieval. false for calibration failed. + * @return Temperature calibration value. */ -static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal) +static inline int temperature_sensor_ll_load_calib_param(void) { uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temp_calib; - *tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; - return true; + // BIT(8) stands for sign: 1: negative, 0: positive + int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; + return tsens_cal; } #ifdef __cplusplus diff --git a/components/hal/esp32c61/include/hal/temperature_sensor_ll.h b/components/hal/esp32c61/include/hal/temperature_sensor_ll.h index 42a03f7bc6..16aed27916 100644 --- a/components/hal/esp32c61/include/hal/temperature_sensor_ll.h +++ b/components/hal/esp32c61/include/hal/temperature_sensor_ll.h @@ -270,16 +270,14 @@ static inline void temperature_sensor_ll_set_sample_rate(uint16_t rate) /** * @brief Retrieve and calculate the temperature sensor calibration value. * - * @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored. - * The output is a signed floating-point value based on the efuse data. - * - * @return returns true to indicate successful retrieval. false for calibration failed. + * @return Temperature calibration value. */ -static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal) +static inline int temperature_sensor_ll_load_calib_param(void) { uint32_t cal_temp = EFUSE0.rd_sys_part1_data4.temperature_sensor; - *tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; - return true; + // BIT(8) stands for sign: 1: negative, 0: positive + int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; + return tsens_cal; } #ifdef __cplusplus diff --git a/components/hal/esp32h2/include/hal/temperature_sensor_ll.h b/components/hal/esp32h2/include/hal/temperature_sensor_ll.h index 644d4c4342..50f3f11d78 100644 --- a/components/hal/esp32h2/include/hal/temperature_sensor_ll.h +++ b/components/hal/esp32h2/include/hal/temperature_sensor_ll.h @@ -269,16 +269,14 @@ static inline void temperature_sensor_ll_set_sample_rate(uint16_t rate) /** * @brief Retrieve and calculate the temperature sensor calibration value. * - * @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored. - * The output is a signed floating-point value based on the efuse data. - * - * @return returns true to indicate successful retrieval. false for calibration failed. + * @return Temperature calibration value. */ -static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal) +static inline int temperature_sensor_ll_load_calib_param(void) { uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temp_calib; - *tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; - return true; + // BIT(8) stands for sign: 1: negative, 0: positive + int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; + return tsens_cal; } #ifdef __cplusplus diff --git a/components/hal/esp32p4/include/hal/temperature_sensor_ll.h b/components/hal/esp32p4/include/hal/temperature_sensor_ll.h index 1045dfd173..7db8114b99 100644 --- a/components/hal/esp32p4/include/hal/temperature_sensor_ll.h +++ b/components/hal/esp32p4/include/hal/temperature_sensor_ll.h @@ -262,16 +262,14 @@ static inline void temperature_sensor_ll_set_sample_rate(uint16_t rate) /** * @brief Retrieve and calculate the temperature sensor calibration value. * - * @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored. - * The output is a signed floating-point value based on the efuse data. - * - * @return returns true to indicate successful retrieval. false for calibration failed. + * @return Temperature calibration value. */ -static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal) +static inline int temperature_sensor_ll_load_calib_param(void) { uint32_t cal_temp = EFUSE.rd_sys_part2_data3.temperature_sensor; - *tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; - return true; + // BIT(8) stands for sign: 1: negative, 0: positive + int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; + return tsens_cal; } #ifdef __cplusplus diff --git a/components/hal/esp32s2/include/hal/temperature_sensor_ll.h b/components/hal/esp32s2/include/hal/temperature_sensor_ll.h index cb01bdcb93..8395ff5ec1 100644 --- a/components/hal/esp32s2/include/hal/temperature_sensor_ll.h +++ b/components/hal/esp32s2/include/hal/temperature_sensor_ll.h @@ -144,22 +144,17 @@ static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div) /** * @brief Retrieve and calculate the temperature sensor calibration value. * - * @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored. - * The output is a signed floating-point value based on the efuse data. - * - * @return returns true to indicate successful retrieval. false for calibration failed. + * @return Temperature calibration value. */ -static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal) +static inline int temperature_sensor_ll_load_calib_param(void) { - uint32_t version = efuse_ll_get_blk_version_major(); - if (version == 0) { - *tsens_cal = 0.0; - return false; + if (efuse_ll_get_blk_version_major() == 0) { + return 0; } - uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temp_calib; - *tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; - return true; + // BIT(8) stands for sign: 1: negative, 0: positive + int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; + return tsens_cal; } #ifdef __cplusplus diff --git a/components/hal/esp32s3/include/hal/temperature_sensor_ll.h b/components/hal/esp32s3/include/hal/temperature_sensor_ll.h index 28951b6a5a..88834ee041 100644 --- a/components/hal/esp32s3/include/hal/temperature_sensor_ll.h +++ b/components/hal/esp32s3/include/hal/temperature_sensor_ll.h @@ -144,22 +144,17 @@ static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div) /** * @brief Retrieve and calculate the temperature sensor calibration value. * - * @param[out] tsens_cal Pointer to a float where the calculated calibration value will be stored. - * The output is a signed floating-point value based on the efuse data. - * - * @return returns true to indicate successful retrieval. false for calibration failed. + * @return Temperature calibration value. */ -static inline bool temperature_sensor_ll_calib_get_tsens_val(float* tsens_cal) +static inline int temperature_sensor_ll_load_calib_param(void) { - uint32_t version = efuse_ll_get_blk_version_major(); - if (version == 0) { - *tsens_cal = 0.0; - return false; + if (efuse_ll_get_blk_version_major() == 0) { + return 0; } - uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temp_calib; - *tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; - return true; + // BIT(8) stands for sign: 1: negative, 0: positive + int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; + return tsens_cal; } #ifdef __cplusplus diff --git a/components/soc/esp32c61/register/soc/efuse_struct.h b/components/soc/esp32c61/register/soc/efuse_struct.h index 2994dd8836..1a0a4226d6 100644 --- a/components/soc/esp32c61/register/soc/efuse_struct.h +++ b/components/soc/esp32c61/register/soc/efuse_struct.h @@ -4536,7 +4536,6 @@ typedef struct { } efuse_dev_t; extern efuse_dev_t EFUSE0; -extern efuse_dev_t EFUSE1; #ifndef __cplusplus _Static_assert(sizeof(efuse_dev_t) == 0x70c, "Invalid size of efuse_dev_t structure"); diff --git a/docs/en/migration-guides/release-6.x/6.0/peripherals.rst b/docs/en/migration-guides/release-6.x/6.0/peripherals.rst index c1b84a2592..876fd4884b 100644 --- a/docs/en/migration-guides/release-6.x/6.0/peripherals.rst +++ b/docs/en/migration-guides/release-6.x/6.0/peripherals.rst @@ -91,7 +91,7 @@ SDMMC .. only:: SOC_TEMP_SENSOR_SUPPORTED - Legacy Temperature Senor Driver is Removed - ------------------------------------------ + Legacy Temperature Sensor Driver is Removed + ------------------------------------------- The legacy temperature sensor driver ``driver/temp_sensor.h`` is deprecated since version 5.0 (see :ref:`deprecate_tsens_legacy_driver`). Starting from version 6.0, the legacy driver is completely removed. The new driver is placed in the :component:`esp_driver_tsens`, and the header file path is ``driver/temperature_sensor.h``.