diff --git a/components/driver/include/driver/touch_pad.h b/components/driver/include/driver/touch_pad.h index 643b07befe..6f0fd2d72a 100644 --- a/components/driver/include/driver/touch_pad.h +++ b/components/driver/include/driver/touch_pad.h @@ -550,6 +550,15 @@ esp_err_t touch_pad_filter_stop(); */ esp_err_t touch_pad_filter_delete(); +/** + * @brief Get the touch pad which caused wakeup from sleep + * @param pad_num pointer to touch pad which caused wakeup + * @return + * - ESP_OK Success + * - ESP_FAIL get status err + */ +esp_err_t touch_pad_get_wakeup_status(touch_pad_t *pad_num); + #ifdef __cplusplus } #endif diff --git a/components/driver/rtc_module.c b/components/driver/rtc_module.c index 333f50cc11..3a215fe216 100644 --- a/components/driver/rtc_module.c +++ b/components/driver/rtc_module.c @@ -1002,6 +1002,16 @@ esp_err_t touch_pad_filter_delete() return ESP_OK; } +esp_err_t touch_pad_get_wakeup_status(touch_pad_t *pad_num) +{ + uint32_t touch_mask = SENS.sar_touch_ctrl2.touch_meas_en; + if(touch_mask == 0) { + return ESP_FAIL; + } + *pad_num = touch_pad_num_wrap((touch_pad_t)(__builtin_ffs(touch_mask) - 1)); + return ESP_OK; +} + /*--------------------------------------------------------------- ADC Common ---------------------------------------------------------------*/ diff --git a/components/esp32/sleep_modes.c b/components/esp32/sleep_modes.c index 36730d291c..f4cefb98b6 100644 --- a/components/esp32/sleep_modes.c +++ b/components/esp32/sleep_modes.c @@ -441,9 +441,10 @@ touch_pad_t esp_sleep_get_touchpad_wakeup_status() if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_TOUCHPAD) { return TOUCH_PAD_MAX; } - uint32_t touch_mask = REG_GET_FIELD(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_MEAS_EN); - assert(touch_mask != 0 && "wakeup reason is RTC_TOUCH_TRIG_EN but SENS_TOUCH_MEAS_EN is zero"); - return (touch_pad_t) (__builtin_ffs(touch_mask) - 1); + touch_pad_t pad_num; + esp_err_t ret = touch_pad_get_wakeup_status(&pad_num); + assert(ret == ESP_OK && "wakeup reason is RTC_TOUCH_TRIG_EN but SENS_TOUCH_MEAS_EN is zero"); + return pad_num; } esp_err_t esp_sleep_enable_ext0_wakeup(gpio_num_t gpio_num, int level)