temperature_sensor: Add temperature sensor support for ESP32-C2

This commit is contained in:
Cao Sen Miao
2022-06-14 14:50:35 +08:00
parent 7d68098089
commit 3a820462ac
38 changed files with 388 additions and 113 deletions

View File

@@ -35,6 +35,7 @@ static inline void regi2c_ctrl_ll_i2c_bbpll_enable(void)
*/
static inline void regi2c_ctrl_ll_i2c_saradc_enable(void)
{
SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_PU);
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, I2C_SAR_M);
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_SAR_CFG2_M);
}

View File

@@ -30,25 +30,6 @@ extern "C" {
#define TEMPERATURE_SENSOR_LL_DAC_FACTOR (27.88)
#define TEMPERATURE_SENSOR_LL_OFFSET_FACTOR (20.52)
#define TEMPERATURE_SENSOR_LL_RANGE_NUM (5)
typedef struct {
int offset;
int reg_val;
int range_min;
int range_max;
int error_max;
} temp_sensor_ll_attribute_t;
static const temp_sensor_ll_attribute_t temp_sensor_ll_attributes[TEMPERATURE_SENSOR_LL_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},
};
/**
* @brief Enable the temperature sensor power.
*
@@ -79,15 +60,12 @@ static inline void temperature_sensor_ll_clk_sel(temperature_sensor_clk_src_t cl
}
/**
* @brief Set the hardware range, you can refer to the table ``temp_sensor_ll_attributes``
* @brief Set the hardware range, you can refer to the table ``temperature_sensor_attributes``
*
* @param tsens_dac ``reg_val`` in table ``temp_sensor_ll_attributes``
* @param tsens_dac ``reg_val`` in table ``temperature_sensor_attributes``
*/
static inline void temperature_sensor_ll_set_range(uint32_t tsens_dac)
{
SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_PU);
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, I2C_SAR_M);
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_SAR_CFG2_M);
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC, tsens_dac);
}