mirror of
				https://github.com/espressif/esp-idf.git
				synced 2025-10-31 04:59:55 +00:00 
			
		
		
		
	feat(temperature_sensor): Add temperature sensor calibration support
This commit is contained in:
		| @@ -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 | ||||
|  */ | ||||
| @@ -107,7 +107,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 | ||||
|     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; | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 C.S.M
					C.S.M