mirror of
https://github.com/espressif/esp-idf.git
synced 2026-05-28 16:46:31 +03:00
feat(tsens): Add tsens support on esp32s31
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- | -------- |
|
||||
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 | ESP32-S31 |
|
||||
| ----------------- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- | -------- | --------- |
|
||||
|
||||
@@ -51,7 +51,7 @@ def test_temperature_sensor_driver_esp32c5_rev1(dut: Dut) -> None:
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@idf_parametrize('target', ['esp32c6', 'esp32h2', 'esp32p4', 'esp32c5', 'esp32c61'], indirect=['target'])
|
||||
@idf_parametrize('target', ['esp32c6', 'esp32h2', 'esp32p4', 'esp32c5', 'esp32c61', 'esp32s31'], indirect=['target'])
|
||||
def test_temperature_sensor_cbs(dut: Dut) -> None:
|
||||
dut.run_all_single_board_cases()
|
||||
|
||||
|
||||
@@ -0,0 +1,281 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 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 <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include "hal/regi2c_ctrl.h"
|
||||
#include "soc/regi2c_saradc.h"
|
||||
#include "soc/tsens_struct.h"
|
||||
#include "soc/tsens_reg.h"
|
||||
#include "soc/lp_peri_clkrst_struct.h"
|
||||
#include "soc/soc.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "soc/interrupts.h"
|
||||
#include "soc/soc_etm_source.h"
|
||||
#include "hal/temperature_sensor_types.h"
|
||||
#include "hal/assert.h"
|
||||
#include "hal/misc.h"
|
||||
#include "hal/efuse_ll.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)
|
||||
#define TEMPERATURE_SENSOR_LL_ADC_FACTOR_INT (4386)
|
||||
#define TEMPERATURE_SENSOR_LL_DAC_FACTOR_INT (278800)
|
||||
#define TEMPERATURE_SENSOR_LL_OFFSET_FACTOR_INT (205200)
|
||||
#define TEMPERATURE_SENSOR_LL_DENOMINATOR (10000)
|
||||
#define TEMPERATURE_SENSOR_LL_MEASURE_MAX (125)
|
||||
#define TEMPERATURE_SENSOR_LL_MEASURE_MIN (-40)
|
||||
|
||||
#define ETS_TEMPERATURE_SENSOR_INTR_SOURCE ETS_LP_TSENS_INTR_SOURCE
|
||||
|
||||
#define TEMPERATURE_SENSOR_LL_INTR_MASK TSENS_COCPU_TSENS_WAKE_INT_ST
|
||||
|
||||
#define TEMPERATURE_SENSOR_LL_ETM_EVENT_TABLE(event) \
|
||||
(uint32_t [TEMPERATURE_SENSOR_EVENT_MAX]){ \
|
||||
[TEMPERATURE_SENSOR_EVENT_OVER_LIMIT] = TMPSNSR_EVT_OVER_LIMIT, \
|
||||
}[event]
|
||||
|
||||
#define TEMPERATURE_SENSOR_LL_ETM_TASK_TABLE(task) \
|
||||
(uint32_t [TEMPERATURE_SENSOR_TASK_MAX]){ \
|
||||
[TEMPERATURE_SENSOR_TASK_START] = TMPSNSR_TASK_START_SAMPLE, \
|
||||
[TEMPERATURE_SENSOR_TASK_STOP] = TMPSNSR_TASK_STOP_SAMPLE, \
|
||||
}[task]
|
||||
|
||||
typedef enum {
|
||||
TEMPERATURE_SENSOR_LL_WAKE_ABSOLUTE = 0,
|
||||
TEMPERATURE_SENSOR_LL_WAKE_DELTA = 1,
|
||||
} temperature_sensor_ll_wakeup_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Enable the temperature sensor power.
|
||||
*
|
||||
* @param enable true: enable the power.
|
||||
*/
|
||||
static inline void temperature_sensor_ll_enable(bool enable)
|
||||
{
|
||||
TSENS.ctrl.power_up = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the clock
|
||||
*/
|
||||
static inline void temperature_sensor_ll_bus_clk_enable(bool enable)
|
||||
{
|
||||
LP_PERI_CLKRST.tsens_ctrl.lp_tsens_clk_en = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset the Temperature sensor module
|
||||
*/
|
||||
static inline void temperature_sensor_ll_reset_module(void)
|
||||
{
|
||||
LP_PERI_CLKRST.tsens_ctrl.lp_tsens_rst_en = 1;
|
||||
LP_PERI_CLKRST.tsens_ctrl.lp_tsens_rst_en = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Select the clock source for temperature sensor.
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
// Only use LP clock source on S31.
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the hardware range, you can refer to the table ``temperature_sensor_attributes``
|
||||
*
|
||||
* @param tsens_dac ``reg_val`` in table ``temperature_sensor_attributes``
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline void temperature_sensor_ll_set_range(uint32_t range)
|
||||
{
|
||||
REGI2C_WRITE_MASK(I2C_SARADC, I2C_SARADC_TSENS_DAC, range);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the raw value of temperature sensor.
|
||||
*
|
||||
* @return uint32_t raw_value
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline uint32_t temperature_sensor_ll_get_raw_value(void)
|
||||
{
|
||||
return HAL_FORCE_READ_U32_REG_FIELD(TSENS.ctrl, out);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the offset value of temperature sensor.
|
||||
*
|
||||
* @note This function is only used in legacy driver
|
||||
*
|
||||
* @return uint32_t offset value
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline uint32_t temperature_sensor_ll_get_offset(void)
|
||||
{
|
||||
return REGI2C_READ_MASK(I2C_SARADC, 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 HAL_FORCE_READ_U32_REG_FIELD(TSENS.ctrl, 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)
|
||||
{
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(TSENS.ctrl, clk_div, clk_div);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Choose the wake-up mode for temperature sensor
|
||||
*
|
||||
* @param mode 0: Absolute value mode. 1: Difference mode.
|
||||
*/
|
||||
static inline void temperature_sensor_ll_wakeup_mode(temperature_sensor_ll_wakeup_mode_t mode)
|
||||
{
|
||||
TSENS.wakeup_ctrl.wakeup_mode = mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get temperature sensor interrupt/wakeup in which reason
|
||||
*
|
||||
* @return uint8_t 0: temperature value lower than low threshold 1: otherwise, higher than high threshold.
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline uint8_t temperature_sensor_ll_get_wakeup_reason(void)
|
||||
{
|
||||
return TSENS.wakeup_ctrl.wakeup_over_upper_th;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
TSENS.wakeup_ctrl.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)
|
||||
{
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(TSENS.wakeup_ctrl, 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)
|
||||
{
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(TSENS.wakeup_ctrl, 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)
|
||||
{
|
||||
TSENS.int_ena.cocpu_tsens_wake_int_ena = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clear temperature sensor interrupt
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline void temperature_sensor_ll_clear_intr(void)
|
||||
{
|
||||
TSENS.int_clr.cocpu_tsens_wake_int_clr = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get temperature sensor interrupt status.
|
||||
*/
|
||||
static inline volatile void *temperature_sensor_ll_get_intr_status(void)
|
||||
{
|
||||
return &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)
|
||||
{
|
||||
TSENS.ctrl.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(TSENS.sample_rate, sample_rate, rate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Retrieve and calculate the temperature sensor calibration value.
|
||||
*
|
||||
* @return Temperature calibration value.
|
||||
*/
|
||||
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;
|
||||
return tsens_cal;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#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 */
|
||||
{-2, 5, 50, 125, 3},
|
||||
{-1, 7, 20, 100, 2},
|
||||
{ 0, 15, -10, 80, 1},
|
||||
{ 1, 11, -30, 50, 2},
|
||||
{ 2, 10, -40, 20, 3},
|
||||
};
|
||||
@@ -99,6 +99,10 @@ config SOC_USB_OTG_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TEMP_SENSOR_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_ULP_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
@@ -1534,3 +1538,19 @@ config SOC_I2S_PDM_MAX_RX_LINES
|
||||
config SOC_ASRC_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TEMPERATURE_SENSOR_INTR_SUPPORT
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TSENS_IS_INDEPENDENT_FROM_ADC
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TEMPERATURE_SENSOR_SUPPORT_ETM
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TEMPERATURE_SENSOR_SUPPORT_SLEEP_RETENTION
|
||||
bool
|
||||
default y
|
||||
|
||||
@@ -710,6 +710,21 @@ typedef enum {
|
||||
ADC_DIGI_CLK_SRC_DEFAULT = SOC_MOD_CLK_XTAL, /*!< Select XTAL as the default clock choice */
|
||||
} soc_periph_adc_digi_clk_src_t;
|
||||
|
||||
//////////////////////////////////////////////////Temp Sensor///////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* @brief Array initializer for all supported clock sources of Temperature Sensor
|
||||
*/
|
||||
#define SOC_TEMP_SENSOR_CLKS {SOC_MOD_CLK_LP_PERI}
|
||||
|
||||
/**
|
||||
* @brief Type of Temp Sensor clock source
|
||||
*/
|
||||
typedef enum {
|
||||
TEMPERATURE_SENSOR_CLK_SRC_LP_PERI = SOC_MOD_CLK_LP_PERI, /*!< Select LP_PERI as the source clock */
|
||||
TEMPERATURE_SENSOR_CLK_SRC_DEFAULT = SOC_MOD_CLK_LP_PERI, /*!< Select LP_PERI as the default choice */
|
||||
} soc_periph_temperature_sensor_clk_src_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
#define SOC_ASYNC_MEMCPY_SUPPORTED 1
|
||||
#define SOC_USB_OTG_SUPPORTED 1
|
||||
// #define SOC_USB_SERIAL_JTAG_SUPPORTED 1 // TODO: [ESP32S31] IDF-14788
|
||||
// #define SOC_TEMP_SENSOR_SUPPORTED 1 // TODO: [ESP32S31] IDF-14799
|
||||
#define SOC_TEMP_SENSOR_SUPPORTED 1
|
||||
// #define SOC_SUPPORTS_SECURE_DL_MODE 1 // TODO: [ESP32S31] IDF-14629
|
||||
#define SOC_ULP_SUPPORTED 1
|
||||
#define SOC_LP_CORE_SUPPORTED 1
|
||||
@@ -584,3 +584,10 @@
|
||||
|
||||
/*---------------------------------- ASRC CAPS ----------------------------------*/
|
||||
#define SOC_ASRC_SUPPORTED (1)
|
||||
|
||||
/*-------------------------- Temperature Sensor CAPS -------------------------------------*/
|
||||
#define SOC_TEMPERATURE_SENSOR_INTR_SUPPORT (1)
|
||||
#define SOC_TSENS_IS_INDEPENDENT_FROM_ADC (1) /*!< Temperature sensor is a separate module, not share regs with ADC */
|
||||
#define SOC_TEMPERATURE_SENSOR_SUPPORT_ETM (1)
|
||||
// temperature sensor on esp32s31 in under low power domain.
|
||||
#define SOC_TEMPERATURE_SENSOR_SUPPORT_SLEEP_RETENTION (1)
|
||||
|
||||
@@ -222,6 +222,7 @@ typedef struct {
|
||||
volatile tsens_sample_rate_reg_t sample_rate;
|
||||
} tsens_dev_t;
|
||||
|
||||
extern tsens_dev_t TSENS;
|
||||
|
||||
#ifndef __cplusplus
|
||||
_Static_assert(sizeof(tsens_dev_t) == 0x2c, "Invalid size of tsens_dev_t structure");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- | -------- |
|
||||
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 | ESP32-S31 |
|
||||
| ----------------- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- | -------- | --------- |
|
||||
|
||||
# Temperature Sensor Example
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
| Supported Targets | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H4 | ESP32-P4 |
|
||||
| ----------------- | -------- | -------- | --------- | -------- | -------- | -------- |
|
||||
| Supported Targets | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-H4 | ESP32-P4 | ESP32-S31 |
|
||||
| ----------------- | -------- | -------- | --------- | -------- | -------- | -------- | --------- |
|
||||
|
||||
# Temperature Sensor Interrupt Example
|
||||
|
||||
|
||||
@@ -11,6 +11,10 @@ tools/test_apps/phy/phy_multi_init_data_test:
|
||||
tools/test_apps/phy/phy_tsens:
|
||||
disable:
|
||||
- if: (SOC_WIFI_SUPPORTED != 1 or SOC_TEMP_SENSOR_SUPPORTED != 1) or SOC_LIGHT_SLEEP_SUPPORTED != 1
|
||||
disable_test:
|
||||
- if: IDF_TARGET in ["esp32s31"]
|
||||
temporary: true
|
||||
reason: lack of runner
|
||||
depends_components:
|
||||
- *common_components
|
||||
- hal
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | -------- | -------- | -------- | -------- | --------- | -------- | -------- |
|
||||
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-S2 | ESP32-S3 | ESP32-S31 |
|
||||
| ----------------- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | --------- |
|
||||
|
||||
Reference in New Issue
Block a user