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

@@ -39,6 +39,15 @@ static inline __attribute__((always_inline)) void regi2c_ctrl_ll_bbpll_calibrati
REG_SET_BIT(I2C_MST_ANA_CONF0_REG, I2C_MST_BBPLL_STOP_FORCE_LOW);
}
/**
* @brief Enable I2C_SAR
*/
static inline void regi2c_ctrl_ll_i2c_saradc_enable(void)
{
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, ANA_I2C_SAR_FORCE_PD);
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_I2C_SAR_FORCE_PU);
}
#ifdef __cplusplus
}
#endif

View File

@@ -32,25 +32,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.
*
@@ -93,14 +74,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 range)
{
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, ANA_I2C_SAR_FORCE_PD);
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_I2C_SAR_FORCE_PU);
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC, range);
}