1. deal with conflicting wakeup triggers

2. modify deep_sleep.rst, add description of touch wakeup.
This commit is contained in:
Wangjialin 2017-01-24 15:53:59 +08:00 committed by Ivan Grokhotkov
parent cc13b0ea05
commit fb261c0bd5
3 changed files with 31 additions and 2 deletions

View file

@ -163,6 +163,10 @@ void system_deep_sleep(uint64_t) __attribute__((alias("esp_deep_sleep")));
esp_err_t esp_deep_sleep_enable_ulp_wakeup()
{
#ifdef CONFIG_ULP_COPROC_ENABLED
if(s_config.wakeup_triggers & RTC_TOUCH_TRIG_EN) {
ESP_LOGE(TAG, "Conflict wake-up triggers: touch");
return ESP_ERR_INVALID_STATE;
}
s_config.wakeup_triggers |= RTC_SAR_TRIG_EN;
return ESP_OK;
#else
@ -179,7 +183,11 @@ esp_err_t esp_deep_sleep_enable_timer_wakeup(uint64_t time_in_us)
esp_err_t esp_deep_sleep_enable_touchpad_wakeup()
{
s_config.wakeup_triggers |= TOUCH_TRIG_EN;
if (s_config.wakeup_triggers & (RTC_SAR_TRIG_EN | RTC_EXT_EVENT0_TRIG_EN)) {
ESP_LOGE(TAG, "Conflict wake-up triggers: ulp/ext0");
return ESP_ERR_INVALID_STATE;
}
s_config.wakeup_triggers |= RTC_TOUCH_TRIG_EN;
return ESP_OK;
}
@ -191,6 +199,10 @@ esp_err_t esp_deep_sleep_enable_ext0_wakeup(gpio_num_t gpio_num, int level)
if (!RTC_GPIO_IS_VALID_GPIO(gpio_num)) {
return ESP_ERR_INVALID_ARG;
}
if (s_config.wakeup_triggers & RTC_TOUCH_TRIG_EN) {
ESP_LOGE(TAG, "Conflict wake-up triggers: touch");
return ESP_ERR_INVALID_STATE;
}
s_config.ext0_rtc_gpio_num = rtc_gpio_desc[gpio_num].rtc_num;
s_config.ext0_trigger_level = level;
s_config.wakeup_triggers |= RTC_EXT_EVENT0_TRIG_EN;
@ -346,6 +358,9 @@ static uint32_t get_power_down_flags()
if (s_config.wakeup_triggers &
(RTC_SAR_TRIG_EN | RTC_EXT_EVENT0_TRIG_EN)) {
s_config.pd_options[ESP_PD_DOMAIN_RTC_PERIPH] = ESP_PD_OPTION_ON;
} else if (s_config.wakeup_triggers & RTC_TOUCH_TRIG_EN) {
// We have to set power down PERIPH so as to enable wake-up from touch sensor.
s_config.pd_options[ESP_PD_DOMAIN_RTC_PERIPH] = ESP_PD_OPTION_OFF;
}
}

View file

@ -53,9 +53,10 @@ typedef enum {
/**
* @brief Enable wakeup by ULP coprocessor
* @note ulp wakeup conflicts with touch wakeup.
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_STATE if ULP co-processor is not enabled.
* - ESP_ERR_INVALID_STATE if ULP co-processor is not enabled or if wakeup triggers conflict
*/
esp_err_t esp_deep_sleep_enable_ulp_wakeup();
@ -70,8 +71,10 @@ esp_err_t esp_deep_sleep_enable_timer_wakeup(uint64_t time_in_us);
/**
* @brief Enable wakeup by touch sensor
* @note Can not set touch wake-up if ulp or ext0 wake-up is enabled.
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_STATE if wakeup triggers conflict
*/
esp_err_t esp_deep_sleep_enable_touchpad_wakeup();
@ -87,6 +90,7 @@ esp_err_t esp_deep_sleep_enable_touchpad_wakeup();
* @note This function does not modify pin configuration. The pin is
* configured in esp_deep_sleep_start, immediately before
* entering deep sleep.
* @note This ext0 wakeup conflicts with touch wakeup.
*
* @param gpio_num GPIO number used as wakeup source. Only GPIOs which are have RTC
* functionality can be used: 0,2,4,12-15,25-27,32-39.
@ -95,6 +99,7 @@ esp_err_t esp_deep_sleep_enable_touchpad_wakeup();
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG if the selected GPIO is not an RTC GPIO,
* or the mode is invalid
* - ESP_ERR_INVALID_STATE if wakeup triggers conflict
*/
esp_err_t esp_deep_sleep_enable_ext0_wakeup(gpio_num_t gpio_num, int level);

View file

@ -26,6 +26,15 @@ The following function can be used to enable deep sleep wakeup using a timer.
.. doxygenfunction:: esp_deep_sleep_enable_timer_wakeup
Touch pad
^^^^^
RTC IO module contains logic to trigger wakeup when a touch sensor interrupt occurs. You need to configure the touch pad interrupt before the chip starts deep sleep.
Note that, for now, this wakeup requires RTC peripherals to be powered off during deep sleep.
.. doxygenfunction:: esp_deep_sleep_enable_touchpad_wakeup
External wakeup (ext0)
^^^^^^^^^^^^^^^^^^^^^^