diff --git a/components/driver/test_apps/legacy_rtc_temp_driver/README.md b/components/driver/test_apps/legacy_rtc_temp_driver/README.md index 2a60590c79..d2553ff6db 100644 --- a/components/driver/test_apps/legacy_rtc_temp_driver/README.md +++ b/components/driver/test_apps/legacy_rtc_temp_driver/README.md @@ -1,2 +1,2 @@ -| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-S2 | ESP32-S3 | -| ----------------- | -------- | -------- | -------- | -------- | -------- | +| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 | +| ----------------- | -------- | -------- | -------- | -------- | -------- | -------- | diff --git a/components/driver/test_apps/legacy_rtc_temp_driver/pytest_legacy_temp_sensor_driver.py b/components/driver/test_apps/legacy_rtc_temp_driver/pytest_legacy_temp_sensor_driver.py index 98027b4c6d..04d23916ba 100644 --- a/components/driver/test_apps/legacy_rtc_temp_driver/pytest_legacy_temp_sensor_driver.py +++ b/components/driver/test_apps/legacy_rtc_temp_driver/pytest_legacy_temp_sensor_driver.py @@ -10,6 +10,7 @@ from pytest_embedded import Dut @pytest.mark.esp32s3 @pytest.mark.esp32c2 @pytest.mark.esp32c6 +@pytest.mark.esp32h2 @pytest.mark.generic @pytest.mark.parametrize('config', [ 'release', diff --git a/components/driver/test_apps/temperature_sensor/README.md b/components/driver/test_apps/temperature_sensor/README.md index 2a60590c79..d2553ff6db 100644 --- a/components/driver/test_apps/temperature_sensor/README.md +++ b/components/driver/test_apps/temperature_sensor/README.md @@ -1,2 +1,2 @@ -| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-S2 | ESP32-S3 | -| ----------------- | -------- | -------- | -------- | -------- | -------- | +| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 | +| ----------------- | -------- | -------- | -------- | -------- | -------- | -------- | diff --git a/components/driver/test_apps/temperature_sensor/pytest_temperature_sensor.py b/components/driver/test_apps/temperature_sensor/pytest_temperature_sensor.py index 317768e8ef..de1fe3c844 100644 --- a/components/driver/test_apps/temperature_sensor/pytest_temperature_sensor.py +++ b/components/driver/test_apps/temperature_sensor/pytest_temperature_sensor.py @@ -10,6 +10,7 @@ from pytest_embedded import Dut @pytest.mark.esp32s3 @pytest.mark.esp32c2 @pytest.mark.esp32c6 +@pytest.mark.esp32h2 @pytest.mark.generic @pytest.mark.parametrize('config', [ 'release', diff --git a/components/efuse/esp32h2/esp_efuse_rtc_calib.c b/components/efuse/esp32h2/esp_efuse_rtc_calib.c index 44826a0fea..5c41630475 100644 --- a/components/efuse/esp32h2/esp_efuse_rtc_calib.c +++ b/components/efuse/esp32h2/esp_efuse_rtc_calib.c @@ -1,5 +1,16 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ + +#include +#include "esp_efuse.h" +#include "esp_efuse_table.h" + +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; + return ESP_OK; +} diff --git a/components/hal/esp32c6/include/hal/temperature_sensor_ll.h b/components/hal/esp32c6/include/hal/temperature_sensor_ll.h index c57b56e47e..b245b2faca 100644 --- a/components/hal/esp32c6/include/hal/temperature_sensor_ll.h +++ b/components/hal/esp32c6/include/hal/temperature_sensor_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -24,6 +24,7 @@ #include "soc/pcr_struct.h" #include "hal/temperature_sensor_types.h" #include "hal/assert.h" +#include "hal/misc.h" #ifdef __cplusplus extern "C" { @@ -216,9 +217,9 @@ static inline void temperature_sensor_ll_sample_enable(bool en) * * @param rate sampling rate */ -static inline void temperature_sensor_ll_sample_rate(uint16_t rate) +static inline void temperature_sensor_ll_set_sample_rate(uint16_t rate) { - APB_SARADC.tsens_sample.saradc_tsens_sample_rate = rate; + HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.tsens_sample, saradc_tsens_sample_rate, rate); } #ifdef __cplusplus diff --git a/components/hal/esp32h2/include/hal/clk_gate_ll.h b/components/hal/esp32h2/include/hal/clk_gate_ll.h index 349bc4aa74..14737da172 100644 --- a/components/hal/esp32h2/include/hal/clk_gate_ll.h +++ b/components/hal/esp32h2/include/hal/clk_gate_ll.h @@ -67,6 +67,8 @@ static inline uint32_t periph_ll_get_clk_en_mask(periph_module_t periph) return PCR_HMAC_CLK_EN; case PERIPH_DS_MODULE: return PCR_DS_CLK_EN; + case PERIPH_TEMPSENSOR_MODULE: + return PCR_TSENS_CLK_EN; // case PERIPH_RNG_MODULE: // return PCR_WIFI_CLK_RNG_EN; // case PERIPH_WIFI_MODULE: @@ -128,6 +130,8 @@ static inline uint32_t periph_ll_get_rst_en_mask(periph_module_t periph, bool en return PCR_PWM_RST_EN; case PERIPH_ETM_MODULE: return PCR_ETM_RST_EN; + case PERIPH_TEMPSENSOR_MODULE: + return PCR_TSENS_RST_EN; case PERIPH_AES_MODULE: if (enable == true) { // Clear reset on digital signature, otherwise AES unit is held in reset also. @@ -232,6 +236,8 @@ static uint32_t periph_ll_get_clk_en_reg(periph_module_t periph) return PCR_HMAC_CONF_REG; case PERIPH_DS_MODULE: return PCR_DS_CONF_REG; + case PERIPH_TEMPSENSOR_MODULE: + return PCR_TSENS_CLK_CONF_REG; default: return 0; } @@ -289,6 +295,8 @@ static uint32_t periph_ll_get_rst_en_reg(periph_module_t periph) return PCR_HMAC_CONF_REG; case PERIPH_DS_MODULE: return PCR_DS_CONF_REG; + case PERIPH_TEMPSENSOR_MODULE: + return PCR_TSENS_CLK_CONF_REG; default: return 0; } diff --git a/components/hal/esp32h2/include/hal/temperature_sensor_ll.h b/components/hal/esp32h2/include/hal/temperature_sensor_ll.h new file mode 100644 index 0000000000..67188bca54 --- /dev/null +++ b/components/hal/esp32h2/include/hal/temperature_sensor_ll.h @@ -0,0 +1,227 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/******************************************************************************* + * NOTICE + * The hal is not public api, don't use in application code. + * See readme.md in component/hal/readme.md + ******************************************************************************/ + +// The LL for temperature sensor + +#pragma once + +#include +#include +#include "hal/regi2c_ctrl.h" +#include "soc/regi2c_saradc.h" +#include "soc/apb_saradc_struct.h" +#include "soc/soc.h" +#include "soc/soc_caps.h" +#include "soc/pcr_struct.h" +#include "hal/temperature_sensor_types.h" +#include "hal/assert.h" +#include "hal/misc.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define TEMPERATURE_SENSOR_LL_ADC_FACTOR (0.4386) +#define TEMPERATURE_SENSOR_LL_DAC_FACTOR (27.88) +#define TEMPERATURE_SENSOR_LL_OFFSET_FACTOR (20.52) + +/** + * @brief Enable the temperature sensor power. + * + * @param enable true: enable the power. + */ +static inline void temperature_sensor_ll_enable(bool enable) +{ + APB_SARADC.saradc_apb_tsens_ctrl.saradc_tsens_pu = enable; +} + +/** + * @brief Enable the clock + */ +static inline void temperature_sensor_ll_clk_enable(bool enable) +{ + // clock enable duplicated with periph enable, no need to enable it again. +} + +/** + * @brief Select the clock source for temperature sensor. On ESP32-C6, temperautre sensor + * can use XTAL or FOSC. To make it convenience, suggest using XTAL all the time. + * + * @param clk_src refer to ``temperature_sensor_clk_src_t`` + */ +static inline void temperature_sensor_ll_clk_sel(temperature_sensor_clk_src_t clk_src) +{ + 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; + } + PCR.tsens_clk_conf.tsens_clk_sel = clk_sel; +} + +/** + * @brief Set the hardware range, you can refer to the table ``temperature_sensor_attributes`` + * + * @param tsens_dac ``reg_val`` in table ``temperature_sensor_attributes`` + */ +static inline void temperature_sensor_ll_set_range(uint32_t range) +{ + REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC, range); +} + +/** + * @brief Get the raw value of temperature sensor. + * + * @return uint32_t raw_value + */ +static inline uint32_t temperature_sensor_ll_get_raw_value(void) +{ + return APB_SARADC.saradc_apb_tsens_ctrl.saradc_tsens_out; +} + +/** + * @brief Get the offset value of temperature sensor. + * + * @note This function is only used in legacy driver + * + * @return uint32_t offset value + */ +static inline uint32_t temperature_sensor_ll_get_offset(void) +{ + return REGI2C_READ_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC); +} + +/** + * @brief Get the clock division factor value. + * + * @note This function is only used in legacy driver + * + * @return uint32_t clock division factor + */ +static inline uint32_t temperature_sensor_ll_get_clk_div(void) +{ + return APB_SARADC.saradc_apb_tsens_ctrl.saradc_tsens_clk_div; +} + +/** + * @brief Set the clock division factor value, actually this has no impact on temperature sensor. + * Suggest just keep it as default value 6. + * + * @note This function is only used in legacy driver + * + * @param clk_div clock division factor, range from 1-10 + */ +static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div) +{ + APB_SARADC.saradc_apb_tsens_ctrl.saradc_tsens_clk_div = clk_div; +} + +/** + * @brief Choose the wake-up mode for temperature sensor + * + * @note ESP32-C6 does not support difference mode. + * + * @param mode 0: Absolute value mode. 1: Difference mode. + */ +static inline void temperature_sensor_ll_wakeup_mode(uint8_t mode) +{ + APB_SARADC.tsens_wake.saradc_wakeup_mode = mode; +} + +/** + * @brief Configure whether to enable temperature sensor wake up + * + * @param en true: enable, false: disable. + */ +static inline void temperature_sensor_ll_wakeup_enable(bool en) +{ + APB_SARADC.tsens_wake.saradc_wakeup_en = en; +} + +/** + * @brief Configures the low threshold for temperature sensor to wakeup + * + * @param th_low low threshold value. + */ +static inline void temperature_sensor_ll_set_th_low_val(uint8_t th_low) +{ + APB_SARADC.tsens_wake.saradc_wakeup_th_low = th_low; +} + +/** + * @brief Configures the high threshold for temperature sensor to wakeup + * + * @param th_high high threshold value. + */ +static inline void temperature_sensor_ll_set_th_high_val(uint8_t th_high) +{ + APB_SARADC.tsens_wake.saradc_wakeup_th_high = th_high; +} + +/** + * @brief Enable temperature sensor interrupt + * + * @param enable true: enable. false: disable + */ +static inline void temperature_sensor_ll_enable_intr(bool enable) +{ + APB_SARADC.saradc_int_ena.saradc_apb_saradc_tsens_int_ena = enable; +} + +/** + * @brief Clear temperature sensor interrupt + */ +static inline void temperature_sensor_ll_clear_intr(void) +{ + APB_SARADC.saradc_int_clr.saradc_apb_saradc_tsens_int_clr = 1; +} + +/** + * @brief Get temperature sensor interrupt status. + * + * @param[out] int_status interrupt status. + */ +static inline void temperature_sensor_ll_get_intr_status(uint8_t *int_status) +{ + *int_status = APB_SARADC.saradc_int_st.saradc_apb_saradc_tsens_int_st; +} + +/** + * @brief Configure whether to enable hardware sampling + * + * @param en true: enable, false: disable + */ +static inline void temperature_sensor_ll_sample_enable(bool en) +{ + APB_SARADC.tsens_sample.saradc_tsens_sample_en = en; +} + +/** + * @brief Configures the hardware sampling rate + * + * @param rate sampling rate + */ +static inline void temperature_sensor_ll_set_sample_rate(uint16_t rate) +{ + HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.tsens_sample, saradc_tsens_sample_rate, rate); +} + +#ifdef __cplusplus +} +#endif diff --git a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in index 1a26c84d32..72e2efad43 100644 --- a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in @@ -35,6 +35,10 @@ config SOC_USB_SERIAL_JTAG_SUPPORTED bool default y +config SOC_TEMP_SENSOR_SUPPORTED + bool + default y + config SOC_EFUSE_KEY_PURPOSE_FIELD bool default y diff --git a/components/soc/esp32h2/include/soc/periph_defs.h b/components/soc/esp32h2/include/soc/periph_defs.h index 4268055c0d..3b0c4e1794 100644 --- a/components/soc/esp32h2/include/soc/periph_defs.h +++ b/components/soc/esp32h2/include/soc/periph_defs.h @@ -42,6 +42,7 @@ typedef enum { PERIPH_ETM_MODULE, PERIPH_SYSTIMER_MODULE, PERIPH_SARADC_MODULE, + PERIPH_TEMPSENSOR_MODULE, PERIPH_MODULE_MAX } periph_module_t; diff --git a/components/soc/esp32h2/include/soc/soc_caps.h b/components/soc/esp32h2/include/soc/soc_caps.h index cfc57af1f7..ebcaca8fca 100644 --- a/components/soc/esp32h2/include/soc/soc_caps.h +++ b/components/soc/esp32h2/include/soc/soc_caps.h @@ -38,7 +38,7 @@ #define SOC_GPTIMER_SUPPORTED 1 #define SOC_IEEE802154_BLE_ONLY 1 #define SOC_USB_SERIAL_JTAG_SUPPORTED 1 -// #define SOC_TEMP_SENSOR_SUPPORTED 1 // TODO: IDF-6229 +#define SOC_TEMP_SENSOR_SUPPORTED 1 // #define SOC_SUPPORTS_SECURE_DL_MODE 1 // TODO: IDF-6281 //#define SOC_RISCV_COPROC_SUPPORTED 1 // TODO: IDF-6272 #define SOC_EFUSE_KEY_PURPOSE_FIELD 1 diff --git a/components/soc/esp32h2/ld/esp32h2.peripherals.ld b/components/soc/esp32h2/ld/esp32h2.peripherals.ld index 9eae994fe2..10839b12f9 100644 --- a/components/soc/esp32h2/ld/esp32h2.peripherals.ld +++ b/components/soc/esp32h2/ld/esp32h2.peripherals.ld @@ -20,7 +20,7 @@ PROVIDE ( TIMERG1 = 0x6000A000 ); PROVIDE ( SYSTIMER = 0x6000B000 ); PROVIDE ( TWAI0 = 0x6000C000 ); PROVIDE ( I2S0 = 0x6000D000 ); -PROVIDE ( APB_ADC = 0x6000E000 ); +PROVIDE ( APB_SARADC = 0x6000E000 ); PROVIDE ( USB_SERIAL_JTAG = 0x6000F000 ); PROVIDE ( INTMTX = 0x60010000 ); diff --git a/examples/peripherals/temp_sensor/README.md b/examples/peripherals/temp_sensor/README.md index f79aca7d32..560f858925 100644 --- a/examples/peripherals/temp_sensor/README.md +++ b/examples/peripherals/temp_sensor/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-S2 | ESP32-S3 | -| ----------------- | -------- | -------- | -------- | -------- | -------- | +| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 | +| ----------------- | -------- | -------- | -------- | -------- | -------- | -------- | # Temperature Sensor Example diff --git a/examples/peripherals/temp_sensor/pytest_temp_sensor_example.py b/examples/peripherals/temp_sensor/pytest_temp_sensor_example.py index 3bc5992169..631634749b 100644 --- a/examples/peripherals/temp_sensor/pytest_temp_sensor_example.py +++ b/examples/peripherals/temp_sensor/pytest_temp_sensor_example.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 import pytest @@ -10,6 +10,7 @@ from pytest_embedded.dut import Dut @pytest.mark.esp32s3 @pytest.mark.esp32c2 @pytest.mark.esp32c6 +@pytest.mark.esp32h2 @pytest.mark.generic def test_temp_sensor_example(dut: Dut) -> None: dut.expect_exact('Install temperature sensor')