feat(temperature_sensor): Add temperature sensor support on esp32p4

This commit is contained in:
Cao Sen Miao
2023-12-22 11:26:53 +08:00
parent 227c5d2cb7
commit 439bc719fe
24 changed files with 424 additions and 37 deletions

View File

@@ -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.