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

@@ -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);
}