From 3cfd8d6906e7821fd932670f97ea2b578bf11159 Mon Sep 17 00:00:00 2001 From: laokaiyao Date: Mon, 8 Dec 2025 14:46:21 +0800 Subject: [PATCH] feat(tsens): graduate temperature sensor hal component --- components/esp_driver_tsens/CMakeLists.txt | 1 + .../esp_driver_tsens/src/temperature_sensor.c | 2 +- .../src/temperature_sensor_private.h | 2 +- .../main/test_temperature_phy.cpp | 2 +- components/esp_hal_ana_conv/CMakeLists.txt | 7 ++++ components/esp_hal_ana_conv/README.md | 33 +++++++++++++++++-- .../include/hal/temperature_sensor_ll.h | 20 +++++------ .../esp32c2/temperature_sensor_periph.c | 4 +-- .../include/hal/temperature_sensor_ll.h | 20 +++++------ .../esp32c3/temperature_sensor_periph.c | 4 +-- .../include/hal/temperature_sensor_ll.h | 20 +++++------ .../esp32c5/temperature_sensor_periph.c | 4 +-- .../include/hal/temperature_sensor_ll.h | 20 +++++------ .../esp32c6/temperature_sensor_periph.c | 4 +-- .../include/hal/temperature_sensor_ll.h | 20 +++++------ .../esp32c61/temperature_sensor_periph.c | 4 +-- .../include/hal/temperature_sensor_ll.h | 20 +++++------ .../esp32h2/temperature_sensor_periph.c | 4 +-- .../include/hal/temperature_sensor_ll.h | 2 +- .../esp32p4/temperature_sensor_periph.c | 4 +-- .../include/hal/temperature_sensor_ll.h | 2 +- .../esp32s2}/temperature_sensor_periph.c | 4 +-- .../include/hal/temperature_sensor_ll.h | 2 +- .../esp32s3}/temperature_sensor_periph.c | 4 +-- .../include/hal/temperature_sensor_hal.h | 0 .../include/hal}/temperature_sensor_periph.h | 4 +-- .../include/hal/temperature_sensor_types.h | 0 .../temperature_sensor_hal.c | 2 +- components/esp_hw_support/CMakeLists.txt | 2 +- components/esp_hw_support/linker.lf | 4 +++ components/esp_phy/CMakeLists.txt | 3 +- components/esp_pm/linker.lf | 4 +++ components/hal/CMakeLists.txt | 4 --- components/soc/CMakeLists.txt | 4 --- docs/doxygen/Doxyfile | 2 +- 35 files changed, 138 insertions(+), 100 deletions(-) rename components/{hal => esp_hal_ana_conv}/esp32c2/include/hal/temperature_sensor_ll.h (93%) rename components/{soc => esp_hal_ana_conv}/esp32c2/temperature_sensor_periph.c (82%) rename components/{hal => esp_hal_ana_conv}/esp32c3/include/hal/temperature_sensor_ll.h (94%) rename components/{soc => esp_hal_ana_conv}/esp32c3/temperature_sensor_periph.c (82%) rename components/{hal => esp_hal_ana_conv}/esp32c5/include/hal/temperature_sensor_ll.h (96%) rename components/{soc => esp_hal_ana_conv}/esp32c5/temperature_sensor_periph.c (95%) rename components/{hal => esp_hal_ana_conv}/esp32c6/include/hal/temperature_sensor_ll.h (96%) rename components/{soc => esp_hal_ana_conv}/esp32c6/temperature_sensor_periph.c (95%) rename components/{hal => esp_hal_ana_conv}/esp32c61/include/hal/temperature_sensor_ll.h (96%) rename components/{soc => esp_hal_ana_conv}/esp32c61/temperature_sensor_periph.c (95%) rename components/{hal => esp_hal_ana_conv}/esp32h2/include/hal/temperature_sensor_ll.h (96%) rename components/{soc => esp_hal_ana_conv}/esp32h2/temperature_sensor_periph.c (95%) rename components/{hal => esp_hal_ana_conv}/esp32p4/include/hal/temperature_sensor_ll.h (98%) rename components/{soc => esp_hal_ana_conv}/esp32p4/temperature_sensor_periph.c (82%) rename components/{hal => esp_hal_ana_conv}/esp32s2/include/hal/temperature_sensor_ll.h (98%) rename components/{soc/esp32s3 => esp_hal_ana_conv/esp32s2}/temperature_sensor_periph.c (82%) rename components/{hal => esp_hal_ana_conv}/esp32s3/include/hal/temperature_sensor_ll.h (98%) rename components/{soc/esp32s2 => esp_hal_ana_conv/esp32s3}/temperature_sensor_periph.c (82%) rename components/{hal => esp_hal_ana_conv}/include/hal/temperature_sensor_hal.h (100%) rename components/{soc/include/soc => esp_hal_ana_conv/include/hal}/temperature_sensor_periph.h (87%) rename components/{hal => esp_hal_ana_conv}/include/hal/temperature_sensor_types.h (100%) rename components/{hal => esp_hal_ana_conv}/temperature_sensor_hal.c (98%) diff --git a/components/esp_driver_tsens/CMakeLists.txt b/components/esp_driver_tsens/CMakeLists.txt index be0e65609f..30b2f8429f 100644 --- a/components/esp_driver_tsens/CMakeLists.txt +++ b/components/esp_driver_tsens/CMakeLists.txt @@ -10,5 +10,6 @@ endif() idf_component_register(SRCS ${srcs} INCLUDE_DIRS ${public_include} + REQUIRES esp_hal_ana_conv PRIV_REQUIRES ${priv_req} ) diff --git a/components/esp_driver_tsens/src/temperature_sensor.c b/components/esp_driver_tsens/src/temperature_sensor.c index d40db9b671..6e16a2b2f6 100644 --- a/components/esp_driver_tsens/src/temperature_sensor.c +++ b/components/esp_driver_tsens/src/temperature_sensor.c @@ -25,7 +25,7 @@ #include "esp_private/periph_ctrl.h" #include "temperature_sensor_private.h" #include "hal/temperature_sensor_ll.h" -#include "soc/temperature_sensor_periph.h" +#include "hal/temperature_sensor_periph.h" #include "hal/temperature_sensor_hal.h" #include "esp_memory_utils.h" #include "esp_private/sar_periph_ctrl.h" diff --git a/components/esp_driver_tsens/src/temperature_sensor_private.h b/components/esp_driver_tsens/src/temperature_sensor_private.h index 28b84be5f8..ef1a499111 100644 --- a/components/esp_driver_tsens/src/temperature_sensor_private.h +++ b/components/esp_driver_tsens/src/temperature_sensor_private.h @@ -7,7 +7,7 @@ #pragma once #include -#include "soc/temperature_sensor_periph.h" +#include "hal/temperature_sensor_periph.h" #include "hal/temperature_sensor_types.h" #include "driver/temperature_sensor.h" #include "esp_intr_alloc.h" diff --git a/components/esp_driver_tsens/test_apps/temperature_sensor/main/test_temperature_phy.cpp b/components/esp_driver_tsens/test_apps/temperature_sensor/main/test_temperature_phy.cpp index a130ac0605..51953e9387 100644 --- a/components/esp_driver_tsens/test_apps/temperature_sensor/main/test_temperature_phy.cpp +++ b/components/esp_driver_tsens/test_apps/temperature_sensor/main/test_temperature_phy.cpp @@ -16,7 +16,7 @@ #include "nvs_flash.h" #include "freertos/task.h" #include "freertos/event_groups.h" -#include "soc/temperature_sensor_periph.h" +#include "hal/temperature_sensor_periph.h" #include "unity.h" #include "unity_test_utils.h" #include "driver/temperature_sensor.h" diff --git a/components/esp_hal_ana_conv/CMakeLists.txt b/components/esp_hal_ana_conv/CMakeLists.txt index e5886231de..26b0c8d2b3 100644 --- a/components/esp_hal_ana_conv/CMakeLists.txt +++ b/components/esp_hal_ana_conv/CMakeLists.txt @@ -15,6 +15,7 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${target}/include") list(APPEND includes "${target}/include") endif() +# ADC related source files if(CONFIG_SOC_ADC_SUPPORTED) list(APPEND srcs "${target}/adc_periph.c" "adc_hal_common.c" "adc_oneshot_hal.c") if(CONFIG_SOC_ADC_DMA_SUPPORTED) @@ -22,10 +23,16 @@ if(CONFIG_SOC_ADC_SUPPORTED) endif() endif() +# DAC related source files if(CONFIG_SOC_DAC_SUPPORTED) list(APPEND srcs "${target}/dac_periph.c") endif() +# Temperature sensor related source files +if(CONFIG_SOC_TEMP_SENSOR_SUPPORTED) + list(APPEND srcs "temperature_sensor_hal.c" "${target}/temperature_sensor_periph.c") +endif() + idf_component_register(SRCS ${srcs} INCLUDE_DIRS ${includes} REQUIRES ${requires}) diff --git a/components/esp_hal_ana_conv/README.md b/components/esp_hal_ana_conv/README.md index bf4671a307..2dfbb23604 100644 --- a/components/esp_hal_ana_conv/README.md +++ b/components/esp_hal_ana_conv/README.md @@ -5,7 +5,7 @@ ## Overview -The `esp_hal_ana_conv` component provides a **Hardware Abstraction Layer** for analog conversion related peripherals across all ESP-IDF supported targets. This HAL currently supports Analog-to-Digital Converter (ADC), Digital-to-Analog Converter (DAC) and other analog conversion related peripherals. The HAL enables analog signal acquisition, generation, and monitoring capabilities. +The `esp_hal_ana_conv` component provides a **Hardware Abstraction Layer** for analog conversion related peripherals across all ESP-IDF supported targets. This HAL currently supports Analog-to-Digital Converter (ADC), Digital-to-Analog Converter (DAC), Temperature Sensor and other analog conversion related peripherals. The HAL enables analog signal acquisition, generation, monitoring, and temperature measurement capabilities. ## Architecture @@ -34,6 +34,12 @@ This HAL supports various DAC controller types depending on the ESP chip: - **RTC Controller**: Direct voltage output control - **DMA Controller**: High-speed data output via I2S or SPI DMA +### Temperature Sensor Controllers + +This HAL supports temperature sensor functionality depending on the ESP chip: + +- **Temperature Sensor**: On-chip temperature monitoring with automatic range management + ## ADC Features ### Work Modes @@ -88,9 +94,32 @@ This HAL supports various DAC controller types depending on the ESP chip: - **ADC-DAC Synchronization**: Synchronized operation with ADC RTC controller - **Power Management**: Independent power control per channel +## Temperature Sensor Features + +### Measurement Capabilities + +- **Temperature Range**: Typically -40°C to 125°C (chip-dependent) +- **Automatic Range Management**: Five configurable temperature ranges with optimized accuracy for each range +- **Raw Value Reading**: Direct access to raw temperature sensor values +- **Degree Conversion**: Automatic conversion from raw values to temperature in degrees Celsius + +### Range Management + +- **Multi-Range Support**: Five temperature ranges with different offset and error characteristics +- **Dynamic Range Switching**: Automatic range adjustment based on measured temperature for optimal accuracy +- **Range Tracking**: HAL layer maintains range state to minimize unnecessary range switches + +### Advanced Features + +- **Sleep Retention**: Register context retention during sleep modes (chip-dependent) +- **Clock Source Selection**: Flexible clock source configuration (XTAL, FOSC, etc., chip-dependent) +- **ETM Support**: Event Task Matrix integration for temperature monitoring events and tasks +- **Wake-up Functionality**: Temperature-based wake-up from sleep modes +- **Power Control**: Independent power and clock gating control + ## Usage -The HAL functions primarily serve ESP-IDF peripheral drivers such as `esp_adc` and `esp_driver_dac`. +The HAL functions primarily serve ESP-IDF peripheral drivers such as `esp_adc`, `esp_driver_dac`, and `esp_driver_tsens`. Advanced developers can use these interfaces directly when implementing custom drivers, with the understanding that API stability is not guaranteed. diff --git a/components/hal/esp32c2/include/hal/temperature_sensor_ll.h b/components/esp_hal_ana_conv/esp32c2/include/hal/temperature_sensor_ll.h similarity index 93% rename from components/hal/esp32c2/include/hal/temperature_sensor_ll.h rename to components/esp_hal_ana_conv/esp32c2/include/hal/temperature_sensor_ll.h index 53ed7819ca..6e75c62456 100644 --- a/components/hal/esp32c2/include/hal/temperature_sensor_ll.h +++ b/components/esp_hal_ana_conv/esp32c2/include/hal/temperature_sensor_ll.h @@ -86,15 +86,15 @@ static inline void temperature_sensor_ll_clk_sel(temperature_sensor_clk_src_t cl { uint8_t clk_sel = 0; switch (clk_src) { - case TEMPERATURE_SENSOR_CLK_SRC_XTAL: - clk_sel = 1; - break; - case TEMPERATURE_SENSOR_CLK_SRC_RC_FAST: - clk_sel = 0; - break; - default: - HAL_ASSERT(false); - break; + case TEMPERATURE_SENSOR_CLK_SRC_XTAL: + clk_sel = 1; + break; + case TEMPERATURE_SENSOR_CLK_SRC_RC_FAST: + clk_sel = 0; + break; + default: + HAL_ASSERT(false); + break; } APB_SARADC.saradc_apb_tsens_ctrl2.saradc_tsens_clk_sel = clk_sel; } @@ -166,7 +166,7 @@ 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 - int tsens_cal = ((cal_temp & BIT(8)) != 0)? -(uint8_t)cal_temp: (uint8_t)cal_temp; + int tsens_cal = ((cal_temp & BIT(8)) != 0) ? -(uint8_t)cal_temp : (uint8_t)cal_temp; return tsens_cal; } diff --git a/components/soc/esp32c2/temperature_sensor_periph.c b/components/esp_hal_ana_conv/esp32c2/temperature_sensor_periph.c similarity index 82% rename from components/soc/esp32c2/temperature_sensor_periph.c rename to components/esp_hal_ana_conv/esp32c2/temperature_sensor_periph.c index d495564a39..ab5d9783a5 100644 --- a/components/soc/esp32c2/temperature_sensor_periph.c +++ b/components/esp_hal_ana_conv/esp32c2/temperature_sensor_periph.c @@ -1,10 +1,10 @@ /* * SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/temperature_sensor_periph.h" +#include "hal/temperature_sensor_periph.h" const temperature_sensor_attribute_t temperature_sensor_attributes[TEMPERATURE_SENSOR_ATTR_RANGE_NUM] = { /*Offset reg_val min max error */ diff --git a/components/hal/esp32c3/include/hal/temperature_sensor_ll.h b/components/esp_hal_ana_conv/esp32c3/include/hal/temperature_sensor_ll.h similarity index 94% rename from components/hal/esp32c3/include/hal/temperature_sensor_ll.h rename to components/esp_hal_ana_conv/esp32c3/include/hal/temperature_sensor_ll.h index 081f89e218..e498dded92 100644 --- a/components/hal/esp32c3/include/hal/temperature_sensor_ll.h +++ b/components/esp_hal_ana_conv/esp32c3/include/hal/temperature_sensor_ll.h @@ -86,15 +86,15 @@ static inline void temperature_sensor_ll_clk_sel(temperature_sensor_clk_src_t cl { uint8_t clk_sel = 0; switch (clk_src) { - case TEMPERATURE_SENSOR_CLK_SRC_XTAL: - clk_sel = 1; - break; - case TEMPERATURE_SENSOR_CLK_SRC_RC_FAST: - clk_sel = 0; - break; - default: - HAL_ASSERT(false); - break; + case TEMPERATURE_SENSOR_CLK_SRC_XTAL: + clk_sel = 1; + break; + case TEMPERATURE_SENSOR_CLK_SRC_RC_FAST: + clk_sel = 0; + break; + default: + HAL_ASSERT(false); + break; } APB_SARADC.apb_tsens_ctrl2.tsens_clk_sel = clk_sel; } @@ -168,7 +168,7 @@ static inline int temperature_sensor_ll_load_calib_param(void) } uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temp_calib; // 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; + int tsens_cal = ((cal_temp & BIT(8)) != 0) ? -(uint8_t)cal_temp : (uint8_t)cal_temp; return tsens_cal; } diff --git a/components/soc/esp32c3/temperature_sensor_periph.c b/components/esp_hal_ana_conv/esp32c3/temperature_sensor_periph.c similarity index 82% rename from components/soc/esp32c3/temperature_sensor_periph.c rename to components/esp_hal_ana_conv/esp32c3/temperature_sensor_periph.c index d495564a39..ab5d9783a5 100644 --- a/components/soc/esp32c3/temperature_sensor_periph.c +++ b/components/esp_hal_ana_conv/esp32c3/temperature_sensor_periph.c @@ -1,10 +1,10 @@ /* * SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/temperature_sensor_periph.h" +#include "hal/temperature_sensor_periph.h" const temperature_sensor_attribute_t temperature_sensor_attributes[TEMPERATURE_SENSOR_ATTR_RANGE_NUM] = { /*Offset reg_val min max error */ diff --git a/components/hal/esp32c5/include/hal/temperature_sensor_ll.h b/components/esp_hal_ana_conv/esp32c5/include/hal/temperature_sensor_ll.h similarity index 96% rename from components/hal/esp32c5/include/hal/temperature_sensor_ll.h rename to components/esp_hal_ana_conv/esp32c5/include/hal/temperature_sensor_ll.h index 7e204535b8..6e4945ddb9 100644 --- a/components/hal/esp32c5/include/hal/temperature_sensor_ll.h +++ b/components/esp_hal_ana_conv/esp32c5/include/hal/temperature_sensor_ll.h @@ -100,15 +100,15 @@ static inline void temperature_sensor_ll_clk_sel(temperature_sensor_clk_src_t cl { uint8_t clk_sel = 0; switch (clk_src) { - case TEMPERATURE_SENSOR_CLK_SRC_XTAL: - clk_sel = 1; - break; - case TEMPERATURE_SENSOR_CLK_SRC_RC_FAST: - clk_sel = 0; - break; - default: - HAL_ASSERT(false); - break; + case TEMPERATURE_SENSOR_CLK_SRC_XTAL: + clk_sel = 1; + break; + case TEMPERATURE_SENSOR_CLK_SRC_RC_FAST: + clk_sel = 0; + break; + default: + HAL_ASSERT(false); + break; } PCR.tsens_clk_conf.tsens_clk_sel = clk_sel; } @@ -280,7 +280,7 @@ static inline int temperature_sensor_ll_load_calib_param(void) { uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temperature_sensor; // 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; + int tsens_cal = ((cal_temp & BIT(8)) != 0) ? -(uint8_t)cal_temp : (uint8_t)cal_temp; return tsens_cal; } diff --git a/components/soc/esp32c5/temperature_sensor_periph.c b/components/esp_hal_ana_conv/esp32c5/temperature_sensor_periph.c similarity index 95% rename from components/soc/esp32c5/temperature_sensor_periph.c rename to components/esp_hal_ana_conv/esp32c5/temperature_sensor_periph.c index 7124a337e8..2d359634fe 100644 --- a/components/soc/esp32c5/temperature_sensor_periph.c +++ b/components/esp_hal_ana_conv/esp32c5/temperature_sensor_periph.c @@ -1,12 +1,12 @@ /* * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #include #include "soc/regdma.h" -#include "soc/temperature_sensor_periph.h" +#include "hal/temperature_sensor_periph.h" #include "soc/apb_saradc_reg.h" const temperature_sensor_attribute_t temperature_sensor_attributes[TEMPERATURE_SENSOR_ATTR_RANGE_NUM] = { diff --git a/components/hal/esp32c6/include/hal/temperature_sensor_ll.h b/components/esp_hal_ana_conv/esp32c6/include/hal/temperature_sensor_ll.h similarity index 96% rename from components/hal/esp32c6/include/hal/temperature_sensor_ll.h rename to components/esp_hal_ana_conv/esp32c6/include/hal/temperature_sensor_ll.h index e9633274d1..a074ae08b1 100644 --- a/components/hal/esp32c6/include/hal/temperature_sensor_ll.h +++ b/components/esp_hal_ana_conv/esp32c6/include/hal/temperature_sensor_ll.h @@ -100,15 +100,15 @@ static inline void temperature_sensor_ll_clk_sel(temperature_sensor_clk_src_t cl { uint8_t clk_sel = 0; switch (clk_src) { - case TEMPERATURE_SENSOR_CLK_SRC_XTAL: - clk_sel = 1; - break; - case TEMPERATURE_SENSOR_CLK_SRC_RC_FAST: - clk_sel = 0; - break; - default: - HAL_ASSERT(false); - break; + case TEMPERATURE_SENSOR_CLK_SRC_XTAL: + clk_sel = 1; + break; + case TEMPERATURE_SENSOR_CLK_SRC_RC_FAST: + clk_sel = 0; + break; + default: + HAL_ASSERT(false); + break; } PCR.tsens_clk_conf.tsens_clk_sel = clk_sel; } @@ -280,7 +280,7 @@ static inline int temperature_sensor_ll_load_calib_param(void) { uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temp_calib; // 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; + int tsens_cal = ((cal_temp & BIT(8)) != 0) ? -(uint8_t)cal_temp : (uint8_t)cal_temp; return tsens_cal; } diff --git a/components/soc/esp32c6/temperature_sensor_periph.c b/components/esp_hal_ana_conv/esp32c6/temperature_sensor_periph.c similarity index 95% rename from components/soc/esp32c6/temperature_sensor_periph.c rename to components/esp_hal_ana_conv/esp32c6/temperature_sensor_periph.c index 3804f37146..1f4af3135a 100644 --- a/components/soc/esp32c6/temperature_sensor_periph.c +++ b/components/esp_hal_ana_conv/esp32c6/temperature_sensor_periph.c @@ -1,12 +1,12 @@ /* * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #include #include "soc/regdma.h" -#include "soc/temperature_sensor_periph.h" +#include "hal/temperature_sensor_periph.h" #include "soc/apb_saradc_reg.h" const temperature_sensor_attribute_t temperature_sensor_attributes[TEMPERATURE_SENSOR_ATTR_RANGE_NUM] = { diff --git a/components/hal/esp32c61/include/hal/temperature_sensor_ll.h b/components/esp_hal_ana_conv/esp32c61/include/hal/temperature_sensor_ll.h similarity index 96% rename from components/hal/esp32c61/include/hal/temperature_sensor_ll.h rename to components/esp_hal_ana_conv/esp32c61/include/hal/temperature_sensor_ll.h index db7f4f9a22..e0ec747fef 100644 --- a/components/hal/esp32c61/include/hal/temperature_sensor_ll.h +++ b/components/esp_hal_ana_conv/esp32c61/include/hal/temperature_sensor_ll.h @@ -100,15 +100,15 @@ static inline void temperature_sensor_ll_clk_sel(temperature_sensor_clk_src_t cl { uint8_t clk_sel = 0; switch (clk_src) { - case TEMPERATURE_SENSOR_CLK_SRC_XTAL: - clk_sel = 1; - break; - case TEMPERATURE_SENSOR_CLK_SRC_RC_FAST: - clk_sel = 0; - break; - default: - HAL_ASSERT(false); - break; + case TEMPERATURE_SENSOR_CLK_SRC_XTAL: + clk_sel = 1; + break; + case TEMPERATURE_SENSOR_CLK_SRC_RC_FAST: + clk_sel = 0; + break; + default: + HAL_ASSERT(false); + break; } PCR.tsens_clk_conf.tsens_clk_sel = clk_sel; } @@ -280,7 +280,7 @@ static inline int temperature_sensor_ll_load_calib_param(void) { uint32_t cal_temp = EFUSE0.rd_sys_part1_data4.temperature_sensor; // 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; + int tsens_cal = ((cal_temp & BIT(8)) != 0) ? -(uint8_t)cal_temp : (uint8_t)cal_temp; return tsens_cal; } diff --git a/components/soc/esp32c61/temperature_sensor_periph.c b/components/esp_hal_ana_conv/esp32c61/temperature_sensor_periph.c similarity index 95% rename from components/soc/esp32c61/temperature_sensor_periph.c rename to components/esp_hal_ana_conv/esp32c61/temperature_sensor_periph.c index 58aeb8e8da..3e0e2d70d7 100644 --- a/components/soc/esp32c61/temperature_sensor_periph.c +++ b/components/esp_hal_ana_conv/esp32c61/temperature_sensor_periph.c @@ -1,12 +1,12 @@ /* * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #include #include "soc/regdma.h" -#include "soc/temperature_sensor_periph.h" +#include "hal/temperature_sensor_periph.h" #include "soc/apb_saradc_reg.h" const temperature_sensor_attribute_t temperature_sensor_attributes[TEMPERATURE_SENSOR_ATTR_RANGE_NUM] = { diff --git a/components/hal/esp32h2/include/hal/temperature_sensor_ll.h b/components/esp_hal_ana_conv/esp32h2/include/hal/temperature_sensor_ll.h similarity index 96% rename from components/hal/esp32h2/include/hal/temperature_sensor_ll.h rename to components/esp_hal_ana_conv/esp32h2/include/hal/temperature_sensor_ll.h index af55ad1c2e..30f2fabb82 100644 --- a/components/hal/esp32h2/include/hal/temperature_sensor_ll.h +++ b/components/esp_hal_ana_conv/esp32h2/include/hal/temperature_sensor_ll.h @@ -99,15 +99,15 @@ static inline void temperature_sensor_ll_clk_sel(temperature_sensor_clk_src_t cl { uint8_t clk_sel = 0; switch (clk_src) { - case TEMPERATURE_SENSOR_CLK_SRC_XTAL: - clk_sel = 1; - break; - case TEMPERATURE_SENSOR_CLK_SRC_RC_FAST: - clk_sel = 0; - break; - default: - HAL_ASSERT(false); - break; + case TEMPERATURE_SENSOR_CLK_SRC_XTAL: + clk_sel = 1; + break; + case TEMPERATURE_SENSOR_CLK_SRC_RC_FAST: + clk_sel = 0; + break; + default: + HAL_ASSERT(false); + break; } PCR.tsens_clk_conf.tsens_clk_sel = clk_sel; } @@ -279,7 +279,7 @@ static inline int temperature_sensor_ll_load_calib_param(void) { uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temp_calib; // 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; + int tsens_cal = ((cal_temp & BIT(8)) != 0) ? -(uint8_t)cal_temp : (uint8_t)cal_temp; return tsens_cal; } diff --git a/components/soc/esp32h2/temperature_sensor_periph.c b/components/esp_hal_ana_conv/esp32h2/temperature_sensor_periph.c similarity index 95% rename from components/soc/esp32h2/temperature_sensor_periph.c rename to components/esp_hal_ana_conv/esp32h2/temperature_sensor_periph.c index 7718883a23..2819b947d9 100644 --- a/components/soc/esp32h2/temperature_sensor_periph.c +++ b/components/esp_hal_ana_conv/esp32h2/temperature_sensor_periph.c @@ -1,12 +1,12 @@ /* * SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #include #include "soc/regdma.h" -#include "soc/temperature_sensor_periph.h" +#include "hal/temperature_sensor_periph.h" #include "soc/apb_saradc_reg.h" const temperature_sensor_attribute_t temperature_sensor_attributes[TEMPERATURE_SENSOR_ATTR_RANGE_NUM] = { diff --git a/components/hal/esp32p4/include/hal/temperature_sensor_ll.h b/components/esp_hal_ana_conv/esp32p4/include/hal/temperature_sensor_ll.h similarity index 98% rename from components/hal/esp32p4/include/hal/temperature_sensor_ll.h rename to components/esp_hal_ana_conv/esp32p4/include/hal/temperature_sensor_ll.h index 7061d75f5f..1a72bb2897 100644 --- a/components/hal/esp32p4/include/hal/temperature_sensor_ll.h +++ b/components/esp_hal_ana_conv/esp32p4/include/hal/temperature_sensor_ll.h @@ -273,7 +273,7 @@ static inline int temperature_sensor_ll_load_calib_param(void) #ifdef EFUSE_TEMPERATURE_SENSOR uint32_t cal_temp = EFUSE.rd_sys_part2_data3.temperature_sensor; // 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; + int tsens_cal = ((cal_temp & BIT(8)) != 0) ? -(uint8_t)cal_temp : (uint8_t)cal_temp; return tsens_cal; #else return 0; diff --git a/components/soc/esp32p4/temperature_sensor_periph.c b/components/esp_hal_ana_conv/esp32p4/temperature_sensor_periph.c similarity index 82% rename from components/soc/esp32p4/temperature_sensor_periph.c rename to components/esp_hal_ana_conv/esp32p4/temperature_sensor_periph.c index ba9c49647d..2889475ae3 100644 --- a/components/soc/esp32p4/temperature_sensor_periph.c +++ b/components/esp_hal_ana_conv/esp32p4/temperature_sensor_periph.c @@ -1,10 +1,10 @@ /* * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/temperature_sensor_periph.h" +#include "hal/temperature_sensor_periph.h" const temperature_sensor_attribute_t temperature_sensor_attributes[TEMPERATURE_SENSOR_ATTR_RANGE_NUM] = { /*Offset reg_val min max error */ diff --git a/components/hal/esp32s2/include/hal/temperature_sensor_ll.h b/components/esp_hal_ana_conv/esp32s2/include/hal/temperature_sensor_ll.h similarity index 98% rename from components/hal/esp32s2/include/hal/temperature_sensor_ll.h rename to components/esp_hal_ana_conv/esp32s2/include/hal/temperature_sensor_ll.h index 355bc3623a..76beef5144 100644 --- a/components/hal/esp32s2/include/hal/temperature_sensor_ll.h +++ b/components/esp_hal_ana_conv/esp32s2/include/hal/temperature_sensor_ll.h @@ -157,7 +157,7 @@ static inline int temperature_sensor_ll_load_calib_param(void) } uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temp_calib; // 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; + int tsens_cal = ((cal_temp & BIT(8)) != 0) ? -(uint8_t)cal_temp : (uint8_t)cal_temp; return tsens_cal; } diff --git a/components/soc/esp32s3/temperature_sensor_periph.c b/components/esp_hal_ana_conv/esp32s2/temperature_sensor_periph.c similarity index 82% rename from components/soc/esp32s3/temperature_sensor_periph.c rename to components/esp_hal_ana_conv/esp32s2/temperature_sensor_periph.c index d495564a39..ab5d9783a5 100644 --- a/components/soc/esp32s3/temperature_sensor_periph.c +++ b/components/esp_hal_ana_conv/esp32s2/temperature_sensor_periph.c @@ -1,10 +1,10 @@ /* * SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/temperature_sensor_periph.h" +#include "hal/temperature_sensor_periph.h" const temperature_sensor_attribute_t temperature_sensor_attributes[TEMPERATURE_SENSOR_ATTR_RANGE_NUM] = { /*Offset reg_val min max error */ diff --git a/components/hal/esp32s3/include/hal/temperature_sensor_ll.h b/components/esp_hal_ana_conv/esp32s3/include/hal/temperature_sensor_ll.h similarity index 98% rename from components/hal/esp32s3/include/hal/temperature_sensor_ll.h rename to components/esp_hal_ana_conv/esp32s3/include/hal/temperature_sensor_ll.h index c6be40a443..23a0e116b1 100644 --- a/components/hal/esp32s3/include/hal/temperature_sensor_ll.h +++ b/components/esp_hal_ana_conv/esp32s3/include/hal/temperature_sensor_ll.h @@ -157,7 +157,7 @@ static inline int temperature_sensor_ll_load_calib_param(void) } uint32_t cal_temp = EFUSE.rd_sys_part1_data4.temp_calib; // 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; + int tsens_cal = ((cal_temp & BIT(8)) != 0) ? -(uint8_t)cal_temp : (uint8_t)cal_temp; return tsens_cal; } diff --git a/components/soc/esp32s2/temperature_sensor_periph.c b/components/esp_hal_ana_conv/esp32s3/temperature_sensor_periph.c similarity index 82% rename from components/soc/esp32s2/temperature_sensor_periph.c rename to components/esp_hal_ana_conv/esp32s3/temperature_sensor_periph.c index d495564a39..ab5d9783a5 100644 --- a/components/soc/esp32s2/temperature_sensor_periph.c +++ b/components/esp_hal_ana_conv/esp32s3/temperature_sensor_periph.c @@ -1,10 +1,10 @@ /* * SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/temperature_sensor_periph.h" +#include "hal/temperature_sensor_periph.h" const temperature_sensor_attribute_t temperature_sensor_attributes[TEMPERATURE_SENSOR_ATTR_RANGE_NUM] = { /*Offset reg_val min max error */ diff --git a/components/hal/include/hal/temperature_sensor_hal.h b/components/esp_hal_ana_conv/include/hal/temperature_sensor_hal.h similarity index 100% rename from components/hal/include/hal/temperature_sensor_hal.h rename to components/esp_hal_ana_conv/include/hal/temperature_sensor_hal.h diff --git a/components/soc/include/soc/temperature_sensor_periph.h b/components/esp_hal_ana_conv/include/hal/temperature_sensor_periph.h similarity index 87% rename from components/soc/include/soc/temperature_sensor_periph.h rename to components/esp_hal_ana_conv/include/hal/temperature_sensor_periph.h index c466734cfc..b3765388fa 100644 --- a/components/soc/include/soc/temperature_sensor_periph.h +++ b/components/esp_hal_ana_conv/include/hal/temperature_sensor_periph.h @@ -1,7 +1,7 @@ /* - * SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD * - * SPDX-License-Identifier: Apache-2.0 OR MIT + * SPDX-License-Identifier: Apache-2.0 */ #pragma once diff --git a/components/hal/include/hal/temperature_sensor_types.h b/components/esp_hal_ana_conv/include/hal/temperature_sensor_types.h similarity index 100% rename from components/hal/include/hal/temperature_sensor_types.h rename to components/esp_hal_ana_conv/include/hal/temperature_sensor_types.h diff --git a/components/hal/temperature_sensor_hal.c b/components/esp_hal_ana_conv/temperature_sensor_hal.c similarity index 98% rename from components/hal/temperature_sensor_hal.c rename to components/esp_hal_ana_conv/temperature_sensor_hal.c index 0a0659ecfd..8855e82d73 100644 --- a/components/hal/temperature_sensor_hal.c +++ b/components/esp_hal_ana_conv/temperature_sensor_hal.c @@ -6,7 +6,7 @@ #include "hal/temperature_sensor_hal.h" #include "hal/temperature_sensor_ll.h" -#include "soc/temperature_sensor_periph.h" +#include "hal/temperature_sensor_periph.h" #include "hal/log.h" #include "esp_rom_sys.h" diff --git a/components/esp_hw_support/CMakeLists.txt b/components/esp_hw_support/CMakeLists.txt index bff4639928..99d765aa35 100644 --- a/components/esp_hw_support/CMakeLists.txt +++ b/components/esp_hw_support/CMakeLists.txt @@ -74,11 +74,11 @@ if(NOT non_os_build) list(APPEND priv_requires esp_driver_gpio # for GPIO and RTC (by sleep_gpio and sleep_modes) esp_timer esp_hal_touch_sens # for touch sensor wakeup (introduced in sleep_modes.c) + esp_hal_i2s # required by `sleep_system_peripheral.c` esp_pm) list(APPEND priv_requires esp_mm esp_hal_mspi - esp_hal_i2s # required by `sleep_system_peripheral.c` ) if(CONFIG_IDF_TARGET_ESP32 OR CONFIG_IDF_TARGET_ESP32S2) diff --git a/components/esp_hw_support/linker.lf b/components/esp_hw_support/linker.lf index 6fb67bbb74..24f393515b 100644 --- a/components/esp_hw_support/linker.lf +++ b/components/esp_hw_support/linker.lf @@ -96,5 +96,9 @@ archive: libsoc.a entries: if PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND: gpio_periph: GPIO_HOLD_MASK (noflash) + +[mapping:hal_tsens_pm] +archive: libesp_hal_ana_conv.a +entries: if PM_SLP_IRAM_OPT = y && SOC_TEMP_SENSOR_SUPPORTED = y: temperature_sensor_periph:temperature_sensor_attributes (noflash) diff --git a/components/esp_phy/CMakeLists.txt b/components/esp_phy/CMakeLists.txt index 1cbf65bdf9..b566f006e8 100644 --- a/components/esp_phy/CMakeLists.txt +++ b/components/esp_phy/CMakeLists.txt @@ -55,7 +55,8 @@ endif() idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "include" "${idf_target}/include" - PRIV_REQUIRES nvs_flash esp_driver_gpio efuse esp_timer esp_wifi esptool_py + # 'esp_hal_ana_conv' is required by 'phy_common.c' for the temperature sensor hal + PRIV_REQUIRES nvs_flash esp_driver_gpio esp_hal_ana_conv efuse esp_timer esp_wifi esptool_py LDFRAGMENTS "${ldfragments}" EMBED_FILES ${embed_files} ) diff --git a/components/esp_pm/linker.lf b/components/esp_pm/linker.lf index 07237e3d96..2403e9b93d 100644 --- a/components/esp_pm/linker.lf +++ b/components/esp_pm/linker.lf @@ -89,6 +89,10 @@ entries: rtc_cntl_hal:rtc_cntl_hal_enable_cpu_retention (noflash) if PM_SLP_IRAM_OPT = y && PM_RESTORE_CACHE_TAGMEM_AFTER_LIGHT_SLEEP = y: rtc_cntl_hal:rtc_cntl_hal_enable_tagmem_retention (noflash) + +[mapping:esp_hal_ana_conv_pm] +archive: libesp_hal_ana_conv.a +entries: if SOC_TEMP_SENSOR_SUPPORTED = y: if PM_SLP_IRAM_OPT = y: temperature_sensor_hal:temperature_sensor_hal_get_raw_value (noflash) diff --git a/components/hal/CMakeLists.txt b/components/hal/CMakeLists.txt index 31926a9c2e..ae34060196 100644 --- a/components/hal/CMakeLists.txt +++ b/components/hal/CMakeLists.txt @@ -166,10 +166,6 @@ elseif(NOT BOOTLOADER_BUILD) list(APPEND srcs "ds_hal.c") endif() - if(CONFIG_SOC_TEMP_SENSOR_SUPPORTED) - list(APPEND srcs "temperature_sensor_hal.c") - endif() - if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${target}/rtc_cntl_hal.c") list(APPEND srcs "${target}/rtc_cntl_hal.c") endif() diff --git a/components/soc/CMakeLists.txt b/components/soc/CMakeLists.txt index 4065577425..ec18dad057 100644 --- a/components/soc/CMakeLists.txt +++ b/components/soc/CMakeLists.txt @@ -76,10 +76,6 @@ if(CONFIG_SOC_I3C_MASTER_SUPPORTED) list(APPEND srcs "${target_folder}/i3c_master_periph.c") endif() -if(CONFIG_SOC_TEMP_SENSOR_SUPPORTED) - list(APPEND srcs "${target_folder}/temperature_sensor_periph.c") -endif() - if(CONFIG_SOC_MPI_SUPPORTED) list(APPEND srcs "${target_folder}/mpi_periph.c") endif() diff --git a/docs/doxygen/Doxyfile b/docs/doxygen/Doxyfile index 3cd69920ed..9618b2f9ab 100644 --- a/docs/doxygen/Doxyfile +++ b/docs/doxygen/Doxyfile @@ -165,6 +165,7 @@ INPUT = \ $(PROJECT_PATH)/components/esp_event/include/esp_event.h \ $(PROJECT_PATH)/components/esp_hal_ana_conv/include/hal/adc_types.h \ $(PROJECT_PATH)/components/esp_hal_ana_conv/include/hal/dac_types.h \ + $(PROJECT_PATH)/components/esp_hal_ana_conv/include/hal/temperature_sensor_types.h \ $(PROJECT_PATH)/components/esp_hal_gpio/include/hal/gpio_types.h \ $(PROJECT_PATH)/components/esp_hal_gpio/include/hal/rtc_io_types.h \ $(PROJECT_PATH)/components/esp_hal_gpio/include/hal/sdm_types.h \ @@ -268,7 +269,6 @@ INPUT = \ $(PROJECT_PATH)/components/hal/include/hal/ledc_types.h \ $(PROJECT_PATH)/components/hal/include/hal/mcpwm_types.h \ $(PROJECT_PATH)/components/hal/include/hal/sdio_slave_types.h \ - $(PROJECT_PATH)/components/hal/include/hal/temperature_sensor_types.h \ $(PROJECT_PATH)/components/hal/include/hal/uart_types.h \ $(PROJECT_PATH)/components/hal/include/hal/efuse_hal.h \ $(PROJECT_PATH)/components/hal/include/hal/eth_types.h \