mirror of
https://github.com/espressif/esp-idf.git
synced 2024-09-20 00:36:01 -04:00
Merge branch 'feat/temperature_p4' into 'master'
feat(temperature_sensor): Add temperature sensor support on esp32p4 Closes IDF-7482 and IDF-7485 See merge request espressif/esp-idf!28075
This commit is contained in:
commit
eef9c4053c
@ -1,2 +1,2 @@
|
||||
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | -------- | -------- | -------- | -------- | -------- | -------- |
|
||||
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
|
||||
|
@ -304,7 +304,7 @@ esp_err_t temperature_sensor_register_callbacks(temperature_sensor_handle_t tsen
|
||||
|
||||
// lazy install interrupt service.
|
||||
if (!tsens->temp_sensor_isr_handle) {
|
||||
ret = esp_intr_alloc_intrstatus(ETS_APB_ADC_INTR_SOURCE, isr_flags,
|
||||
ret = esp_intr_alloc_intrstatus(ETS_TEMPERATURE_SENSOR_INTR_SOURCE, isr_flags,
|
||||
(uint32_t)temperature_sensor_ll_get_intr_status(),
|
||||
TEMPERATURE_SENSOR_LL_INTR_MASK, temperature_sensor_isr, tsens, &tsens->temp_sensor_isr_handle);
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | -------- | -------- | -------- | -------- | -------- | -------- |
|
||||
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
|
||||
|
@ -26,6 +26,12 @@ static const char *TAG_TSENS = "temperature_sensor";
|
||||
|
||||
#define INT_NOT_USED 999999
|
||||
|
||||
#if !SOC_RCC_IS_INDEPENDENT
|
||||
#define TSENS_RCC_ATOMIC() PERIPH_RCC_ATOMIC()
|
||||
#else
|
||||
#define TSENS_RCC_ATOMIC()
|
||||
#endif
|
||||
|
||||
static int s_record_min = INT_NOT_USED;
|
||||
static int s_record_max = INT_NOT_USED;
|
||||
static int s_temperature_sensor_power_cnt;
|
||||
@ -37,10 +43,11 @@ void temperature_sensor_power_acquire(void)
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
s_temperature_sensor_power_cnt++;
|
||||
if (s_temperature_sensor_power_cnt == 1) {
|
||||
periph_module_enable(PERIPH_TEMPSENSOR_MODULE);
|
||||
periph_module_reset(PERIPH_TEMPSENSOR_MODULE);
|
||||
regi2c_saradc_enable();
|
||||
temperature_sensor_ll_clk_enable(true);
|
||||
TSENS_RCC_ATOMIC() {
|
||||
temperature_sensor_ll_bus_clk_enable(true);
|
||||
temperature_sensor_ll_reset_module();
|
||||
}
|
||||
temperature_sensor_ll_enable(true);
|
||||
}
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
@ -56,10 +63,11 @@ void temperature_sensor_power_release(void)
|
||||
ESP_LOGE(TAG_TSENS, "%s called, but s_temperature_sensor_power_cnt == 0", __func__);
|
||||
abort();
|
||||
} else if (s_temperature_sensor_power_cnt == 0) {
|
||||
temperature_sensor_ll_clk_enable(false);
|
||||
temperature_sensor_ll_enable(false);
|
||||
TSENS_RCC_ATOMIC() {
|
||||
temperature_sensor_ll_bus_clk_enable(false);
|
||||
}
|
||||
regi2c_saradc_disable();
|
||||
periph_module_disable(PERIPH_TEMPSENSOR_MODULE);
|
||||
}
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "soc/apb_saradc_struct.h"
|
||||
#include "soc/soc.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "soc/system_struct.h"
|
||||
#include "hal/temperature_sensor_types.h"
|
||||
#include "hal/assert.h"
|
||||
#include "hal/misc.h"
|
||||
@ -48,11 +49,28 @@ static inline void temperature_sensor_ll_enable(bool enable)
|
||||
/**
|
||||
* @brief Enable the clock
|
||||
*/
|
||||
static inline void temperature_sensor_ll_clk_enable(bool enable)
|
||||
static inline void temperature_sensor_ll_bus_clk_enable(bool enable)
|
||||
{
|
||||
// No need to enable the temperature clock on esp32c2
|
||||
SYSTEM.perip_clk_en1.tsens_clk_en = enable;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define temperature_sensor_ll_bus_clk_enable(...) do {(void)__DECLARE_RCC_ATOMIC_ENV; temperature_sensor_ll_bus_clk_enable(__VA_ARGS__);} while(0)
|
||||
|
||||
/**
|
||||
* @brief Reset the Temperature sensor module
|
||||
*/
|
||||
static inline void temperature_sensor_ll_reset_module(void)
|
||||
{
|
||||
SYSTEM.perip_rst_en1.tsens_rst = 1;
|
||||
SYSTEM.perip_rst_en1.tsens_rst = 0;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define temperature_sensor_ll_reset_module(...) do {(void)__DECLARE_RCC_ATOMIC_ENV; temperature_sensor_ll_reset_module(__VA_ARGS__);} while(0)
|
||||
|
||||
/**
|
||||
* @brief Select the clock source for temperature sensor. On ESP32-C2, temperautre sensor
|
||||
* can use XTAL or FOSC. To make it convenience, suggest using XTAL all the time.
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "soc/apb_saradc_struct.h"
|
||||
#include "soc/soc.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "soc/system_struct.h"
|
||||
#include "hal/temperature_sensor_types.h"
|
||||
#include "hal/assert.h"
|
||||
#include "hal/misc.h"
|
||||
@ -48,11 +49,28 @@ static inline void temperature_sensor_ll_enable(bool enable)
|
||||
/**
|
||||
* @brief Enable the clock
|
||||
*/
|
||||
static inline void temperature_sensor_ll_clk_enable(bool enable)
|
||||
static inline void temperature_sensor_ll_bus_clk_enable(bool enable)
|
||||
{
|
||||
// No need to enable the temperature clock on esp32c3
|
||||
SYSTEM.perip_clk_en1.reg_tsens_clk_en = enable;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define temperature_sensor_ll_bus_clk_enable(...) do {(void)__DECLARE_RCC_ATOMIC_ENV; temperature_sensor_ll_bus_clk_enable(__VA_ARGS__);} while(0)
|
||||
|
||||
/**
|
||||
* @brief Reset the Temperature sensor module
|
||||
*/
|
||||
static inline void temperature_sensor_ll_reset_module(void)
|
||||
{
|
||||
SYSTEM.perip_rst_en1.reg_tsens_rst = 1;
|
||||
SYSTEM.perip_rst_en1.reg_tsens_rst = 0;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define temperature_sensor_ll_reset_module(...) do {(void)__DECLARE_RCC_ATOMIC_ENV; temperature_sensor_ll_reset_module(__VA_ARGS__);} while(0)
|
||||
|
||||
/**
|
||||
* @brief Select the clock source for temperature sensor. On ESP32-C3, temperautre sensor
|
||||
* can use XTAL or FOSC. To make it convenience, suggest using XTAL all the time.
|
||||
|
@ -20,9 +20,11 @@
|
||||
#include "soc/regi2c_saradc.h"
|
||||
#include "soc/apb_saradc_struct.h"
|
||||
#include "soc/apb_saradc_reg.h"
|
||||
#include "soc/pcr_struct.h"
|
||||
#include "soc/soc.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "soc/pcr_struct.h"
|
||||
#include "soc/interrupts.h"
|
||||
#include "hal/temperature_sensor_types.h"
|
||||
#include "hal/assert.h"
|
||||
#include "hal/misc.h"
|
||||
@ -57,9 +59,18 @@ static inline void temperature_sensor_ll_enable(bool enable)
|
||||
/**
|
||||
* @brief Enable the clock
|
||||
*/
|
||||
static inline void temperature_sensor_ll_clk_enable(bool enable)
|
||||
static inline void temperature_sensor_ll_bus_clk_enable(bool enable)
|
||||
{
|
||||
// clock enable duplicated with periph enable, no need to enable it again.
|
||||
PCR.tsens_clk_conf.tsens_clk_en = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset the Temperature sensor module
|
||||
*/
|
||||
static inline void temperature_sensor_ll_reset_module(void)
|
||||
{
|
||||
PCR.tsens_clk_conf.tsens_rst_en = 1;
|
||||
PCR.tsens_clk_conf.tsens_rst_en = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -150,7 +161,7 @@ static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div)
|
||||
*
|
||||
* @param mode 0: Absolute value mode. 1: Difference mode.
|
||||
*/
|
||||
static inline void temperature_sensor_ll_wakeup_mode(uint8_t mode)
|
||||
static inline void temperature_sensor_ll_wakeup_mode(temperature_sensor_ll_wakeup_mode_t mode)
|
||||
{
|
||||
APB_SARADC.tsens_wake.saradc_wakeup_mode = mode;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "soc/soc.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "soc/pcr_struct.h"
|
||||
#include "soc/interrupts.h"
|
||||
#include "hal/temperature_sensor_types.h"
|
||||
#include "hal/assert.h"
|
||||
#include "hal/misc.h"
|
||||
@ -57,9 +58,18 @@ static inline void temperature_sensor_ll_enable(bool enable)
|
||||
/**
|
||||
* @brief Enable the clock
|
||||
*/
|
||||
static inline void temperature_sensor_ll_clk_enable(bool enable)
|
||||
static inline void temperature_sensor_ll_bus_clk_enable(bool enable)
|
||||
{
|
||||
// clock enable duplicated with periph enable, no need to enable it again.
|
||||
PCR.tsens_clk_conf.tsens_clk_en = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset the Temperature sensor module
|
||||
*/
|
||||
static inline void temperature_sensor_ll_reset_module(void)
|
||||
{
|
||||
PCR.tsens_clk_conf.tsens_rst_en = 1;
|
||||
PCR.tsens_clk_conf.tsens_rst_en = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -150,7 +160,7 @@ static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div)
|
||||
*
|
||||
* @param mode 0: Absolute value mode. 1: Difference mode.
|
||||
*/
|
||||
static inline void temperature_sensor_ll_wakeup_mode(uint8_t mode)
|
||||
static inline void temperature_sensor_ll_wakeup_mode(temperature_sensor_ll_wakeup_mode_t mode)
|
||||
{
|
||||
APB_SARADC.tsens_wake.saradc_wakeup_mode = mode;
|
||||
}
|
||||
|
251
components/hal/esp32p4/include/hal/temperature_sensor_ll.h
Normal file
251
components/hal/esp32p4/include/hal/temperature_sensor_ll.h
Normal file
@ -0,0 +1,251 @@
|
||||
/*
|
||||
* 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 <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include "hal/regi2c_ctrl.h"
|
||||
#include "soc/regi2c_saradc.h"
|
||||
#include "soc/tsens_struct.h"
|
||||
#include "soc/lpperi_struct.h"
|
||||
#include "soc/tsens_reg.h"
|
||||
#include "soc/soc.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "soc/interrupts.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)
|
||||
#define TEMPERATURE_SENSOR_LL_MEASURE_MAX (125)
|
||||
#define TEMPERATURE_SENSOR_LL_MEASURE_MIN (-40)
|
||||
|
||||
#define TEMPERATURE_SENSOR_LL_INTR_MASK TSENS_COCPU_TSENS_WAKE_INT_ST
|
||||
|
||||
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)
|
||||
{
|
||||
LP_TSENS.ctrl.power_up = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the clock
|
||||
*/
|
||||
static inline void temperature_sensor_ll_bus_clk_enable(bool enable)
|
||||
{
|
||||
LPPERI.clk_en.ck_en_lp_tsens = enable;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define temperature_sensor_ll_bus_clk_enable(...) do {(void)__DECLARE_RCC_ATOMIC_ENV; temperature_sensor_ll_bus_clk_enable(__VA_ARGS__);} while(0)
|
||||
|
||||
/**
|
||||
* @brief Reset the Temperature sensor module
|
||||
*/
|
||||
static inline void temperature_sensor_ll_reset_module(void)
|
||||
{
|
||||
LPPERI.reset_en.rst_en_lp_tsens = 1;
|
||||
LPPERI.reset_en.rst_en_lp_tsens = 0;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define temperature_sensor_ll_reset_module(...) do {(void)__DECLARE_RCC_ATOMIC_ENV; temperature_sensor_ll_reset_module(__VA_ARGS__);} while(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 LP_PLL can be used as clock source on P4.
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
__attribute__((always_inline))
|
||||
static inline uint32_t temperature_sensor_ll_get_raw_value(void)
|
||||
{
|
||||
return HAL_FORCE_READ_U32_REG_FIELD(LP_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
|
||||
*/
|
||||
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 HAL_FORCE_READ_U32_REG_FIELD(LP_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(LP_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)
|
||||
{
|
||||
LP_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 LP_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)
|
||||
{
|
||||
LP_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(LP_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(LP_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)
|
||||
{
|
||||
LP_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)
|
||||
{
|
||||
LP_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 &LP_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)
|
||||
{
|
||||
LP_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(LP_TSENS.sample_rate, sample_rate, rate);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -48,11 +48,28 @@ static inline void temperature_sensor_ll_enable(bool enable)
|
||||
/**
|
||||
* @brief Enable the clock
|
||||
*/
|
||||
static inline void temperature_sensor_ll_clk_enable(bool enable)
|
||||
static inline void temperature_sensor_ll_bus_clk_enable(bool enable)
|
||||
{
|
||||
SENS.sar_tctrl2.tsens_clkgate_en = enable;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define temperature_sensor_ll_bus_clk_enable(...) do {(void)__DECLARE_RCC_ATOMIC_ENV; temperature_sensor_ll_bus_clk_enable(__VA_ARGS__);} while(0)
|
||||
|
||||
/**
|
||||
* @brief Enable the clock
|
||||
*/
|
||||
static inline void temperature_sensor_ll_reset_module(void)
|
||||
{
|
||||
SENS.sar_tctrl2.tsens_reset = 1;
|
||||
SENS.sar_tctrl2.tsens_reset = 0;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define temperature_sensor_ll_reset_module(...) do {(void)__DECLARE_RCC_ATOMIC_ENV; temperature_sensor_ll_reset_module(__VA_ARGS__);} while(0)
|
||||
|
||||
/**
|
||||
* @brief Choose the clock. No need to choose the clock source on ESP32-S2. ESP32-S2
|
||||
* can use RTC clock.
|
||||
|
@ -48,11 +48,28 @@ static inline void temperature_sensor_ll_enable(bool enable)
|
||||
/**
|
||||
* @brief Enable the clock
|
||||
*/
|
||||
static inline void temperature_sensor_ll_clk_enable(bool enable)
|
||||
static inline void temperature_sensor_ll_bus_clk_enable(bool enable)
|
||||
{
|
||||
SENS.sar_peri_clk_gate_conf.tsens_clk_en = enable;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define temperature_sensor_ll_bus_clk_enable(...) do {(void)__DECLARE_RCC_ATOMIC_ENV; temperature_sensor_ll_bus_clk_enable(__VA_ARGS__);} while(0)
|
||||
|
||||
/**
|
||||
* @brief Enable the clock
|
||||
*/
|
||||
static inline void temperature_sensor_ll_reset_module(void)
|
||||
{
|
||||
SENS.sar_peri_reset_conf.tsens_reset = 1;
|
||||
SENS.sar_peri_reset_conf.tsens_reset = 0;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define temperature_sensor_ll_reset_module(...) do {(void)__DECLARE_RCC_ATOMIC_ENV; temperature_sensor_ll_reset_module(__VA_ARGS__);} while(0)
|
||||
|
||||
/**
|
||||
* @brief Choose the clock. No need to choose the clock source on ESP32-S3. ESP32-S3
|
||||
* can use RTC clock.
|
||||
|
@ -79,7 +79,8 @@ typedef enum {
|
||||
ETS_SYSTIMER_TARGET1_EDGE_INTR_SOURCE = ETS_SYSTIMER_TARGET1_INTR_SOURCE, /**< use ETS_SYSTIMER_TARGET1_INTR_SOURCE */
|
||||
ETS_SYSTIMER_TARGET2_EDGE_INTR_SOURCE = ETS_SYSTIMER_TARGET2_INTR_SOURCE, /**< use ETS_SYSTIMER_TARGET2_INTR_SOURCE */
|
||||
ETS_APB_ADC_INTR_SOURCE = 60, /**< interrupt of APB ADC, LEVEL*/
|
||||
ETS_MCPWM0_INTR_SOURCE, /**< interrupt of MCPWM0, LEVEL*/
|
||||
ETS_TEMPERATURE_SENSOR_INTR_SOURCE = ETS_APB_ADC_INTR_SOURCE,
|
||||
ETS_MCPWM0_INTR_SOURCE = 61, /**< interrupt of MCPWM0, LEVEL*/
|
||||
ETS_PCNT_INTR_SOURCE,
|
||||
ETS_PARL_IO_INTR_SOURCE,
|
||||
ETS_SLC0_INTR_SOURCE,
|
||||
|
@ -67,7 +67,8 @@ typedef enum {
|
||||
ETS_SYSTIMER_TARGET1_EDGE_INTR_SOURCE = ETS_SYSTIMER_TARGET1_INTR_SOURCE, /**< use ETS_SYSTIMER_TARGET1_INTR_SOURCE */
|
||||
ETS_SYSTIMER_TARGET2_EDGE_INTR_SOURCE = ETS_SYSTIMER_TARGET2_INTR_SOURCE, /**< use ETS_SYSTIMER_TARGET2_INTR_SOURCE */
|
||||
ETS_APB_ADC_INTR_SOURCE = 48, /**< interrupt of APB ADC, LEVEL*/
|
||||
ETS_MCPWM0_INTR_SOURCE,
|
||||
ETS_TEMPERATURE_SENSOR_INTR_SOURCE = ETS_APB_ADC_INTR_SOURCE,
|
||||
ETS_MCPWM0_INTR_SOURCE = 49,
|
||||
ETS_PCNT_INTR_SOURCE,
|
||||
ETS_PARL_IO_TX_INTR_SOURCE,
|
||||
ETS_PARL_IO_RX_INTR_SOURCE,
|
||||
|
@ -55,6 +55,10 @@ config SOC_ASYNC_MEMCPY_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TEMP_SENSOR_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_SUPPORTS_SECURE_DL_MODE
|
||||
bool
|
||||
default y
|
||||
@ -1331,11 +1335,11 @@ config SOC_PERIPH_CLK_CTRL_SHARED
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TEMPERATURE_SENSOR_SUPPORT_FAST_RC
|
||||
config SOC_TEMPERATURE_SENSOR_LP_PLL_SUPPORT
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TEMPERATURE_SENSOR_SUPPORT_XTAL
|
||||
config SOC_TEMPERATURE_SENSOR_INTR_SUPPORT
|
||||
bool
|
||||
default y
|
||||
|
||||
|
@ -636,6 +636,21 @@ typedef enum {
|
||||
SDMMC_CLK_SRC_PLL200M = SOC_MOD_CLK_PLL_F200M, /*!< Select PLL_200M as the source clock */
|
||||
} soc_periph_sdmmc_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_PLL}
|
||||
|
||||
/**
|
||||
* @brief Type of Temp Sensor clock source
|
||||
*/
|
||||
typedef enum {
|
||||
TEMPERATURE_SENSOR_CLK_SRC_LP_PLL = SOC_MOD_CLK_LP_PLL, /*!< Select LP_PLL as the source clock */
|
||||
TEMPERATURE_SENSOR_CLK_SRC_DEFAULT = SOC_MOD_CLK_LP_PLL, /*!< Select LP_PLL as the default choice */
|
||||
} soc_periph_temperature_sensor_clk_src_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -31,7 +31,8 @@ typedef enum {
|
||||
ETS_LP_SPI_INTR_SOURCE,
|
||||
ETS_LP_TOUCH_INTR_SOURCE,
|
||||
ETS_LP_TSENS_INTR_SOURCE,
|
||||
ETS_LP_UART_INTR_SOURCE,
|
||||
ETS_TEMPERATURE_SENSOR_INTR_SOURCE = ETS_LP_TSENS_INTR_SOURCE,
|
||||
ETS_LP_UART_INTR_SOURCE = 16,
|
||||
ETS_LP_EFUSE_INTR_SOURCE,
|
||||
ETS_LP_SW_INTR_SOURCE,
|
||||
ETS_LP_SYSREG_INTR_SOURCE,
|
||||
|
@ -15,7 +15,8 @@
|
||||
#define I2C_MST_BBPLL_CAL_DONE (BIT(24))
|
||||
|
||||
|
||||
#define ANA_CONFIG_REG 0x600AF81C
|
||||
|
||||
#define ANA_CONFIG_REG 0x5012401C
|
||||
#define ANA_CONFIG_S (8)
|
||||
#define ANA_CONFIG_M (0x3FF)
|
||||
|
||||
@ -23,7 +24,7 @@
|
||||
#define ANA_I2C_BBPLL_M BIT(17) /* Clear to enable BBPLL */
|
||||
|
||||
|
||||
#define ANA_CONFIG2_REG 0x600AF820
|
||||
#define ANA_CONFIG2_REG 0x50124020
|
||||
#define ANA_CONFIG2_M BIT(18)
|
||||
|
||||
#define ANA_I2C_SAR_FORCE_PU BIT(16)
|
||||
|
@ -14,3 +14,10 @@
|
||||
* bus. These definitions are used via macros defined in regi2c_ctrl.h, by
|
||||
* function in adc_ll.h.
|
||||
*/
|
||||
|
||||
#define I2C_SAR_ADC 0X69
|
||||
#define I2C_SAR_ADC_HOSTID 0
|
||||
|
||||
#define I2C_SARADC_TSENS_DAC 0x6
|
||||
#define I2C_SARADC_TSENS_DAC_MSB 3
|
||||
#define I2C_SARADC_TSENS_DAC_LSB 0
|
||||
|
@ -36,7 +36,7 @@
|
||||
#define SOC_ASYNC_MEMCPY_SUPPORTED 1
|
||||
// disable usb serial jtag for esp32p4, current image does not support
|
||||
// #define SOC_USB_SERIAL_JTAG_SUPPORTED 1 //TODO: IDF-7496
|
||||
// #define SOC_TEMP_SENSOR_SUPPORTED 1 //TODO: IDF-7482
|
||||
#define SOC_TEMP_SENSOR_SUPPORTED 1
|
||||
#define SOC_SUPPORTS_SECURE_DL_MODE 1
|
||||
#define SOC_ULP_SUPPORTED 1
|
||||
#define SOC_LP_CORE_SUPPORTED 1
|
||||
@ -574,8 +574,8 @@
|
||||
#define SOC_PERIPH_CLK_CTRL_SHARED (1) /*!< Peripheral clock control (e.g. set clock source) is shared between various peripherals */
|
||||
|
||||
/*-------------------------- Temperature Sensor CAPS -------------------------------------*/
|
||||
#define SOC_TEMPERATURE_SENSOR_SUPPORT_FAST_RC (1)
|
||||
#define SOC_TEMPERATURE_SENSOR_SUPPORT_XTAL (1)
|
||||
#define SOC_TEMPERATURE_SENSOR_LP_PLL_SUPPORT (1)
|
||||
#define SOC_TEMPERATURE_SENSOR_INTR_SUPPORT (1)
|
||||
|
||||
/*-------------------------- Memory CAPS --------------------------*/
|
||||
#define SOC_MEM_TCM_SUPPORTED (1)
|
||||
|
@ -222,6 +222,7 @@ typedef struct {
|
||||
volatile tsens_sample_rate_reg_t sample_rate;
|
||||
} tsens_dev_t;
|
||||
|
||||
extern tsens_dev_t LP_TSENS;
|
||||
|
||||
#ifndef __cplusplus
|
||||
_Static_assert(sizeof(tsens_dev_t) == 0x2c, "Invalid size of tsens_dev_t structure");
|
||||
|
@ -85,6 +85,7 @@ PROVIDE ( AHB_DMA = 0x50085000 );
|
||||
PROVIDE ( AXI_DMA = 0x5008a000 );
|
||||
PROVIDE ( LCD_CAM = 0x500dc000 );
|
||||
PROVIDE ( LP_IOMUX = 0x5012B000 );
|
||||
PROVIDE ( LP_TSENS = 0x5012f000 );
|
||||
|
||||
PROVIDE ( MIPI_CSI_BRIDGE = 0x5009F800 );
|
||||
PROVIDE ( MIPI_CSI_HOST = 0x5009F000 );
|
||||
|
@ -7,5 +7,10 @@
|
||||
#include "soc/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},
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | -------- | -------- | -------- | -------- | -------- | -------- |
|
||||
| Supported Targets | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
|
||||
|
||||
# Temperature Sensor Example
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
| Supported Targets | ESP32-C6 | ESP32-H2 |
|
||||
| ----------------- | -------- | -------- |
|
||||
| Supported Targets | ESP32-C6 | ESP32-H2 | ESP32-P4 |
|
||||
| ----------------- | -------- | -------- | -------- |
|
||||
|
||||
# Temperature Sensor Interrupt Example
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user