Skip to content

Commit fbab3bc

Browse files
committed
Merge branch 'feat/temperature_sensor_bringup' into 'master'
feature(temperature_sensor): Add temperature sensor support on esp32c5 Closes IDF-8727 See merge request espressif/esp-idf!32665
2 parents 34813ec + 5d4275f commit fbab3bc

File tree

18 files changed

+331
-24
lines changed

18 files changed

+331
-24
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
2-
| ----------------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
1+
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
2+
| ----------------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |

components/driver/test_apps/legacy_rtc_temp_driver/pytest_legacy_temp_sensor_driver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
@pytest.mark.esp32c6
1212
@pytest.mark.esp32h2
1313
@pytest.mark.esp32p4
14+
@pytest.mark.esp32c5
1415
@pytest.mark.generic
1516
@pytest.mark.parametrize('config', [
1617
'release',

components/efuse/esp32c5/esp_efuse_rtc_calib.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ esp_err_t esp_efuse_rtc_calib_get_cal_voltage(int version, uint32_t adc_unit, in
4949

5050
esp_err_t esp_efuse_rtc_calib_get_tsens_val(float* tsens_cal)
5151
{
52-
// TODO: [ESP32C5] IDF-8727
53-
abort();
5452
// Currently calibration is not supported on ESP32-C5, IDF-5236
53+
// Allow no calibration
5554
*tsens_cal = 0;
5655
return ESP_OK;
5756
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
2-
| ----------------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
1+
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
2+
| ----------------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |

components/esp_driver_tsens/test_apps/temperature_sensor/pytest_temperature_sensor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
22
# SPDX-License-Identifier: CC0-1.0
3-
43
import pytest
54
from pytest_embedded import Dut
65
from pytest_embedded_idf.unity_tester import CaseTester
@@ -13,6 +12,7 @@
1312
@pytest.mark.esp32c6
1413
@pytest.mark.esp32h2
1514
@pytest.mark.esp32p4
15+
@pytest.mark.esp32c5
1616
@pytest.mark.generic
1717
@pytest.mark.parametrize('config', [
1818
'release',
@@ -24,6 +24,7 @@ def test_temperature_sensor_driver(dut: Dut) -> None:
2424
@pytest.mark.esp32c6
2525
@pytest.mark.esp32h2
2626
@pytest.mark.esp32p4
27+
@pytest.mark.esp32c5
2728
@pytest.mark.generic
2829
@pytest.mark.parametrize('config', [
2930
'iram_safe',
Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*******************************************************************************
8+
* NOTICE
9+
* The hal is not public api, don't use in application code.
10+
* See readme.md in component/hal/readme.md
11+
******************************************************************************/
12+
13+
// The LL for temperature sensor
14+
15+
#pragma once
16+
17+
#include <stdbool.h>
18+
#include <stdlib.h>
19+
#include "hal/regi2c_ctrl.h"
20+
#include "soc/regi2c_saradc.h"
21+
#include "soc/apb_saradc_struct.h"
22+
#include "soc/apb_saradc_reg.h"
23+
#include "soc/pcr_struct.h"
24+
#include "soc/soc.h"
25+
#include "soc/soc_caps.h"
26+
#include "soc/pcr_struct.h"
27+
#include "soc/interrupts.h"
28+
#include "soc/soc_etm_source.h"
29+
#include "hal/temperature_sensor_types.h"
30+
#include "hal/assert.h"
31+
#include "hal/misc.h"
32+
33+
#ifdef __cplusplus
34+
extern "C" {
35+
#endif
36+
37+
#define TEMPERATURE_SENSOR_LL_ADC_FACTOR (0.4386)
38+
#define TEMPERATURE_SENSOR_LL_DAC_FACTOR (27.88)
39+
#define TEMPERATURE_SENSOR_LL_OFFSET_FACTOR (20.52)
40+
#define TEMPERATURE_SENSOR_LL_MEASURE_MAX (125)
41+
#define TEMPERATURE_SENSOR_LL_MEASURE_MIN (-40)
42+
43+
#define TEMPERATURE_SENSOR_LL_INTR_MASK APB_SARADC_APB_SARADC_TSENS_INT_ST
44+
45+
#define TEMPERATURE_SENSOR_LL_ETM_EVENT_TABLE(event) \
46+
(uint32_t [TEMPERATURE_SENSOR_EVENT_MAX]){ \
47+
[TEMPERATURE_SENSOR_EVENT_OVER_LIMIT] = TMPSNSR_EVT_OVER_LIMIT, \
48+
}[event]
49+
50+
#define TEMPERATURE_SENSOR_LL_ETM_TASK_TABLE(task) \
51+
(uint32_t [TEMPERATURE_SENSOR_TASK_MAX]){ \
52+
[TEMPERATURE_SENSOR_TASK_START] = TMPSNSR_TASK_START_SAMPLE, \
53+
[TEMPERATURE_SENSOR_TASK_STOP] = TMPSNSR_TASK_STOP_SAMPLE, \
54+
}[task]
55+
56+
typedef enum {
57+
TEMPERATURE_SENSOR_LL_WAKE_ABSOLUTE = 0,
58+
TEMPERATURE_SENSOR_LL_WAKE_DELTA = 1,
59+
} temperature_sensor_ll_wakeup_mode_t;
60+
61+
/**
62+
* @brief Enable the temperature sensor power.
63+
*
64+
* @param enable true: enable the power.
65+
*/
66+
static inline void temperature_sensor_ll_enable(bool enable)
67+
{
68+
APB_SARADC.saradc_apb_tsens_ctrl.saradc_tsens_pu = enable;
69+
}
70+
71+
/**
72+
* @brief Enable the clock
73+
*/
74+
static inline void temperature_sensor_ll_bus_clk_enable(bool enable)
75+
{
76+
PCR.tsens_clk_conf.tsens_clk_en = enable;
77+
}
78+
79+
/**
80+
* @brief Reset the Temperature sensor module
81+
*/
82+
static inline void temperature_sensor_ll_reset_module(void)
83+
{
84+
PCR.tsens_clk_conf.tsens_rst_en = 1;
85+
PCR.tsens_clk_conf.tsens_rst_en = 0;
86+
}
87+
88+
/**
89+
* @brief Select the clock source for temperature sensor. On ESP32-C6, temperautre sensor
90+
* can use XTAL or FOSC. To make it convenience, suggest using XTAL all the time.
91+
*
92+
* @param clk_src refer to ``temperature_sensor_clk_src_t``
93+
*/
94+
static inline void temperature_sensor_ll_clk_sel(temperature_sensor_clk_src_t clk_src)
95+
{
96+
uint8_t clk_sel = 0;
97+
switch (clk_src) {
98+
case TEMPERATURE_SENSOR_CLK_SRC_XTAL:
99+
clk_sel = 1;
100+
break;
101+
case TEMPERATURE_SENSOR_CLK_SRC_RC_FAST:
102+
clk_sel = 0;
103+
break;
104+
default:
105+
HAL_ASSERT(false);
106+
break;
107+
}
108+
PCR.tsens_clk_conf.tsens_clk_sel = clk_sel;
109+
}
110+
111+
/**
112+
* @brief Set the hardware range, you can refer to the table ``temperature_sensor_attributes``
113+
*
114+
* @param tsens_dac ``reg_val`` in table ``temperature_sensor_attributes``
115+
*/
116+
static inline void temperature_sensor_ll_set_range(uint32_t range)
117+
{
118+
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC, range);
119+
}
120+
121+
/**
122+
* @brief Get the raw value of temperature sensor.
123+
*
124+
* @return uint32_t raw_value
125+
*/
126+
__attribute__((always_inline))
127+
static inline uint32_t temperature_sensor_ll_get_raw_value(void)
128+
{
129+
return HAL_FORCE_READ_U32_REG_FIELD(APB_SARADC.saradc_apb_tsens_ctrl, saradc_tsens_out);
130+
}
131+
132+
/**
133+
* @brief Get the offset value of temperature sensor.
134+
*
135+
* @note This function is only used in legacy driver
136+
*
137+
* @return uint32_t offset value
138+
*/
139+
static inline uint32_t temperature_sensor_ll_get_offset(void)
140+
{
141+
return REGI2C_READ_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC);
142+
}
143+
144+
/**
145+
* @brief Get the clock division factor value.
146+
*
147+
* @note This function is only used in legacy driver
148+
*
149+
* @return uint32_t clock division factor
150+
*/
151+
static inline uint32_t temperature_sensor_ll_get_clk_div(void)
152+
{
153+
return HAL_FORCE_READ_U32_REG_FIELD(APB_SARADC.saradc_apb_tsens_ctrl, saradc_tsens_clk_div);
154+
}
155+
156+
/**
157+
* @brief Set the clock division factor value, actually this has no impact on temperature sensor.
158+
* Suggest just keep it as default value 6.
159+
*
160+
* @note This function is only used in legacy driver
161+
*
162+
* @param clk_div clock division factor, range from 1-10
163+
*/
164+
static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div)
165+
{
166+
HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.saradc_apb_tsens_ctrl, saradc_tsens_clk_div, clk_div);
167+
}
168+
169+
/**
170+
* @brief Choose the wake-up mode for temperature sensor
171+
*
172+
* @note ESP32-C6 does not support difference mode.
173+
*
174+
* @param mode 0: Absolute value mode. 1: Difference mode.
175+
*/
176+
static inline void temperature_sensor_ll_wakeup_mode(temperature_sensor_ll_wakeup_mode_t mode)
177+
{
178+
APB_SARADC.tsens_wake.saradc_wakeup_mode = mode;
179+
}
180+
181+
/**
182+
* @brief Get temperature sensor interrupt/wakeup in which reason
183+
*
184+
* @return uint8_t 0: temperature value lower than low threshold 1: otherwise, higher than high threshold.
185+
*/
186+
__attribute__((always_inline))
187+
static inline uint8_t temperature_sensor_ll_get_wakeup_reason(void)
188+
{
189+
return APB_SARADC.tsens_wake.saradc_wakeup_over_upper_th;
190+
}
191+
192+
/**
193+
* @brief Configure whether to enable temperature sensor wake up
194+
*
195+
* @param en true: enable, false: disable.
196+
*/
197+
static inline void temperature_sensor_ll_wakeup_enable(bool en)
198+
{
199+
APB_SARADC.tsens_wake.saradc_wakeup_en = en;
200+
}
201+
202+
/**
203+
* @brief Configures the low threshold for temperature sensor to wakeup
204+
*
205+
* @param th_low low threshold value.
206+
*/
207+
static inline void temperature_sensor_ll_set_th_low_val(uint8_t th_low)
208+
{
209+
HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.tsens_wake, saradc_wakeup_th_low, th_low);
210+
}
211+
212+
/**
213+
* @brief Configures the high threshold for temperature sensor to wakeup
214+
*
215+
* @param th_high high threshold value.
216+
*/
217+
static inline void temperature_sensor_ll_set_th_high_val(uint8_t th_high)
218+
{
219+
HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.tsens_wake, saradc_wakeup_th_high, th_high);
220+
}
221+
222+
/**
223+
* @brief Enable temperature sensor interrupt
224+
*
225+
* @param enable true: enable. false: disable
226+
*/
227+
static inline void temperature_sensor_ll_enable_intr(bool enable)
228+
{
229+
APB_SARADC.saradc_int_ena.saradc_apb_saradc_tsens_int_ena = enable;
230+
}
231+
232+
/**
233+
* @brief Clear temperature sensor interrupt
234+
*/
235+
__attribute__((always_inline))
236+
static inline void temperature_sensor_ll_clear_intr(void)
237+
{
238+
APB_SARADC.saradc_int_clr.saradc_apb_saradc_tsens_int_clr = 1;
239+
}
240+
241+
/**
242+
* @brief Get temperature sensor interrupt status.
243+
*/
244+
static inline volatile void *temperature_sensor_ll_get_intr_status(void)
245+
{
246+
return &APB_SARADC.saradc_int_st;
247+
}
248+
249+
/**
250+
* @brief Configure whether to enable hardware sampling
251+
*
252+
* @param en true: enable, false: disable
253+
*/
254+
static inline void temperature_sensor_ll_sample_enable(bool en)
255+
{
256+
APB_SARADC.tsens_sample.saradc_tsens_sample_en = en;
257+
}
258+
259+
/**
260+
* @brief Configures the hardware sampling rate
261+
*
262+
* @param rate sampling rate
263+
*/
264+
static inline void temperature_sensor_ll_set_sample_rate(uint16_t rate)
265+
{
266+
HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.tsens_sample, saradc_tsens_sample_rate, rate);
267+
}
268+
269+
#ifdef __cplusplus
270+
}
271+
#endif

components/soc/esp32c5/include/soc/Kconfig.soc_caps.in

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ config SOC_USB_SERIAL_JTAG_SUPPORTED
5151
bool
5252
default y
5353

54+
config SOC_TEMP_SENSOR_SUPPORTED
55+
bool
56+
default y
57+
5458
config SOC_WIFI_SUPPORTED
5559
bool
5660
default y
@@ -315,6 +319,10 @@ config SOC_ADC_RTC_MAX_BITWIDTH
315319
int
316320
default 12
317321

322+
config SOC_ADC_TEMPERATURE_SHARE_INTR
323+
bool
324+
default y
325+
318326
config SOC_ADC_SHARED_POWER
319327
bool
320328
default y
@@ -1191,6 +1199,18 @@ config SOC_RCC_IS_INDEPENDENT
11911199
bool
11921200
default y
11931201

1202+
config SOC_TEMPERATURE_SENSOR_SUPPORT_FAST_RC
1203+
bool
1204+
default y
1205+
1206+
config SOC_TEMPERATURE_SENSOR_SUPPORT_XTAL
1207+
bool
1208+
default y
1209+
1210+
config SOC_TEMPERATURE_SENSOR_INTR_SUPPORT
1211+
bool
1212+
default y
1213+
11941214
config SOC_WIFI_HW_TSF
11951215
bool
11961216
default y

components/soc/esp32c5/include/soc/clk_tree_defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ typedef enum {
218218
/**
219219
* @brief Type of Temp Sensor clock source
220220
*/
221-
typedef enum { // TODO: [ESP32C5] IDF-8727 (inherit from C6)
221+
typedef enum {
222222
TEMPERATURE_SENSOR_CLK_SRC_XTAL = SOC_MOD_CLK_XTAL, /*!< Select XTAL as the source clock */
223223
TEMPERATURE_SENSOR_CLK_SRC_RC_FAST = SOC_MOD_CLK_RC_FAST, /*!< Select RC_FAST as the source clock */
224224
TEMPERATURE_SENSOR_CLK_SRC_DEFAULT = SOC_MOD_CLK_XTAL, /*!< Select XTAL as the default choice */

components/soc/esp32c5/include/soc/interrupts.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ typedef enum {
7777
ETS_SYSTIMER_TARGET0_INTR_SOURCE, /**< interrupt of system timer 0 */
7878
ETS_SYSTIMER_TARGET1_INTR_SOURCE, /**< interrupt of system timer 1 */
7979
ETS_SYSTIMER_TARGET2_INTR_SOURCE, /**< interrupt of system timer 2 */
80-
ETS_APB_ADC_INTR_SOURCE, /**< interrupt of APB ADC, LEVEL*/
81-
ETS_MCPWM0_INTR_SOURCE, /**< interrupt of MCPWM0, LEVEL*/
80+
ETS_APB_ADC_INTR_SOURCE = 62, /**< interrupt of APB ADC, LEVEL*/
81+
ETS_TEMPERATURE_SENSOR_INTR_SOURCE = ETS_APB_ADC_INTR_SOURCE,
82+
ETS_MCPWM0_INTR_SOURCE = 63, /**< interrupt of MCPWM0, LEVEL*/
8283
ETS_PCNT_INTR_SOURCE,
8384
ETS_PARL_IO_TX_INTR_SOURCE,
8485
ETS_PARL_IO_RX_INTR_SOURCE,

0 commit comments

Comments
 (0)