feature(temperature_sensor): Add temperature sensor threshold interrupt reason

This commit is contained in:
Cao Sen Miao 2023-11-14 18:23:33 +08:00
parent bb95f9bcc6
commit 343f03c3a7
4 changed files with 33 additions and 0 deletions

View File

@ -97,11 +97,20 @@ esp_err_t temperature_sensor_get_celsius(temperature_sensor_handle_t tsens, floa
#if SOC_TEMPERATURE_SENSOR_INTR_SUPPORT
/**
* @brief Enum for temperature sensor interrupt condition.
*/
typedef enum {
TEMPERATURE_VAL_HIGHER_THAN_HIGH_THRESHOLD = 0, /*!< temperature sensor value is higher than high threshold*/
TEMPERATURE_VAL_LOWER_THAN_LOW_THRESHOLD = 1, /*!< temperature sensor value is lower than low threshold*/
} temperature_val_intr_condition_t;
/**
* @brief Temperature sensor event data
*/
typedef struct {
int celsius_value; /**< Celsius value in interrupt callback. */
temperature_val_intr_condition_t intr_condition; /*!< Can be used to judge temperature sensor interrupts in which reason*/
} temperature_sensor_threshold_event_data_t;
/**

View File

@ -76,8 +76,10 @@ static void IRAM_ATTR temperature_sensor_isr(void *arg)
temperature_sensor_ll_clear_intr();
bool cbs_yield = false;
temperature_sensor_handle_t tsens = (temperature_sensor_handle_t) arg;
temperature_val_intr_condition_t intr_condition = (temperature_sensor_ll_get_wakeup_reason() == 1 ? TEMPERATURE_VAL_HIGHER_THAN_HIGH_THRESHOLD: TEMPERATURE_VAL_LOWER_THAN_LOW_THRESHOLD);
temperature_sensor_threshold_event_data_t data = {
.celsius_value = s_temperature_regval_2_celsius(tsens, temperature_sensor_ll_get_raw_value()),
.intr_condition = intr_condition,
};
if (tsens->threshold_cbs) {
if (tsens->threshold_cbs(tsens, &data, tsens->cb_user_arg)) {

View File

@ -155,6 +155,17 @@ static inline void temperature_sensor_ll_wakeup_mode(uint8_t mode)
APB_SARADC.tsens_wake.saradc_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 APB_SARADC.tsens_wake.saradc_wakeup_over_upper_th;
}
/**
* @brief Configure whether to enable temperature sensor wake up
*

View File

@ -155,6 +155,17 @@ static inline void temperature_sensor_ll_wakeup_mode(uint8_t mode)
APB_SARADC.tsens_wake.saradc_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 APB_SARADC.tsens_wake.saradc_wakeup_over_upper_th;
}
/**
* @brief Configure whether to enable temperature sensor wake up
*