Merge branch 'bugfix/rtc_periph_ulp_touch_v4.4' into 'release/v4.4'

sleep_modes: allow using touch/ULP with RTC_PERIPH domain (including EXT0 wakeup source) (v4.4)

See merge request espressif/esp-idf!19768
This commit is contained in:
morris
2022-11-10 10:19:16 +08:00
2 changed files with 20 additions and 27 deletions

View File

@@ -106,10 +106,8 @@ esp_err_t esp_sleep_disable_wakeup_source(esp_sleep_source_t source);
#if SOC_ULP_SUPPORTED #if SOC_ULP_SUPPORTED
/** /**
* @brief Enable wakeup by ULP coprocessor * @brief Enable wakeup by ULP coprocessor
* @note In revisions 0 and 1 of the ESP32, ULP wakeup source * @note On ESP32, ULP wakeup source cannot be used when RTC_PERIPH power domain is forced,
* cannot be used when RTC_PERIPH power domain is forced * to be powered on (ESP_PD_OPTION_ON) or when ext0 wakeup source is used.
* to be powered on (ESP_PD_OPTION_ON) or when
* ext0 wakeup source is used.
* @return * @return
* - ESP_OK on success * - ESP_OK on success
* - ESP_ERR_NOT_SUPPORTED if additional current by touch (CONFIG_ESP32_RTC_EXT_CRYST_ADDIT_CURRENT) is enabled. * - ESP_ERR_NOT_SUPPORTED if additional current by touch (CONFIG_ESP32_RTC_EXT_CRYST_ADDIT_CURRENT) is enabled.
@@ -133,10 +131,8 @@ esp_err_t esp_sleep_enable_timer_wakeup(uint64_t time_in_us);
/** /**
* @brief Enable wakeup by touch sensor * @brief Enable wakeup by touch sensor
* *
* @note In revisions 0 and 1 of the ESP32, touch wakeup source * @note On ESP32, touch wakeup source can not be used when RTC_PERIPH power domain is forced
* can not be used when RTC_PERIPH power domain is forced * to be powered on (ESP_PD_OPTION_ON) or when ext0 wakeup source is used.
* to be powered on (ESP_PD_OPTION_ON) or when ext0 wakeup
* source is used.
* *
* @note The FSM mode of the touch button should be configured * @note The FSM mode of the touch button should be configured
* as the timer trigger mode. * as the timer trigger mode.
@@ -184,8 +180,7 @@ bool esp_sleep_is_valid_wakeup_gpio(gpio_num_t gpio_num);
* @note This function does not modify pin configuration. The pin is * @note This function does not modify pin configuration. The pin is
* configured in esp_sleep_start, immediately before entering sleep mode. * configured in esp_sleep_start, immediately before entering sleep mode.
* *
* @note In revisions 0 and 1 of the ESP32, ext0 wakeup source * @note On ESP32, ext0 wakeup source can not be used together with touch or ULP wakeup sources.
* can not be used together with touch or ULP wakeup sources.
* *
* @param gpio_num GPIO number used as wakeup source. Only GPIOs which are have RTC * @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. * functionality can be used: 0,2,4,12-15,25-27,32-39.
@@ -270,8 +265,7 @@ esp_err_t esp_deep_sleep_enable_gpio_wakeup(uint64_t gpio_pin_mask, esp_deepslee
* wakeup level, for each GPIO which is used for wakeup. * wakeup level, for each GPIO which is used for wakeup.
* Then call this function to enable wakeup feature. * Then call this function to enable wakeup feature.
* *
* @note In revisions 0 and 1 of the ESP32, GPIO wakeup source * @note On ESP32, GPIO wakeup source can not be used together with touch or ULP wakeup sources.
* can not be used together with touch or ULP wakeup sources.
* *
* @return * @return
* - ESP_OK on success * - ESP_OK on success

View File

@@ -953,6 +953,7 @@ static void touch_wakeup_prepare(void)
esp_err_t esp_sleep_enable_touchpad_wakeup(void) esp_err_t esp_sleep_enable_touchpad_wakeup(void)
{ {
#if CONFIG_IDF_TARGET_ESP32
#if ((defined CONFIG_ESP32_RTC_EXT_CRYST_ADDIT_CURRENT) || (defined CONFIG_ESP32_RTC_EXT_CRYST_ADDIT_CURRENT_V2)) #if ((defined CONFIG_ESP32_RTC_EXT_CRYST_ADDIT_CURRENT) || (defined CONFIG_ESP32_RTC_EXT_CRYST_ADDIT_CURRENT_V2))
ESP_LOGE(TAG, "Failed to enable wakeup when provide current to external 32kHz crystal"); ESP_LOGE(TAG, "Failed to enable wakeup when provide current to external 32kHz crystal");
return ESP_ERR_NOT_SUPPORTED; return ESP_ERR_NOT_SUPPORTED;
@@ -961,6 +962,8 @@ esp_err_t esp_sleep_enable_touchpad_wakeup(void)
ESP_LOGE(TAG, "Conflicting wake-up trigger: ext0"); ESP_LOGE(TAG, "Conflicting wake-up trigger: ext0");
return ESP_ERR_INVALID_STATE; return ESP_ERR_INVALID_STATE;
} }
#endif //CONFIG_IDF_TARGET_ESP32
s_config.wakeup_triggers |= RTC_TOUCH_TRIG_EN; s_config.wakeup_triggers |= RTC_TOUCH_TRIG_EN;
return ESP_OK; return ESP_OK;
} }
@@ -997,10 +1000,13 @@ esp_err_t esp_sleep_enable_ext0_wakeup(gpio_num_t gpio_num, int level)
if (!esp_sleep_is_valid_wakeup_gpio(gpio_num)) { if (!esp_sleep_is_valid_wakeup_gpio(gpio_num)) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
#if CONFIG_IDF_TARGET_ESP32
if (s_config.wakeup_triggers & (RTC_TOUCH_TRIG_EN | RTC_ULP_TRIG_EN)) { if (s_config.wakeup_triggers & (RTC_TOUCH_TRIG_EN | RTC_ULP_TRIG_EN)) {
ESP_LOGE(TAG, "Conflicting wake-up triggers: touch / ULP"); ESP_LOGE(TAG, "Conflicting wake-up triggers: touch / ULP");
return ESP_ERR_INVALID_STATE; return ESP_ERR_INVALID_STATE;
} }
#endif //CONFIG_IDF_TARGET_ESP32
s_config.ext0_rtc_gpio_num = rtc_io_number_get(gpio_num); s_config.ext0_rtc_gpio_num = rtc_io_number_get(gpio_num);
s_config.ext0_trigger_level = level; s_config.ext0_trigger_level = level;
s_config.wakeup_triggers |= RTC_EXT0_TRIG_EN; s_config.wakeup_triggers |= RTC_EXT0_TRIG_EN;
@@ -1300,29 +1306,22 @@ static uint32_t get_power_down_flags(void)
s_config.pd_options[ESP_PD_DOMAIN_RTC_FAST_MEM] = ESP_PD_OPTION_ON; s_config.pd_options[ESP_PD_DOMAIN_RTC_FAST_MEM] = ESP_PD_OPTION_ON;
#endif #endif
#if SOC_PM_SUPPORT_RTC_PERIPH_PD
// RTC_PERIPH is needed for EXT0 wakeup and GPIO wakeup. // RTC_PERIPH is needed for EXT0 wakeup and GPIO wakeup.
// If RTC_PERIPH is auto, and EXT0/GPIO aren't enabled, power down RTC_PERIPH. // If RTC_PERIPH is left auto (EXT0/GPIO aren't enabled), RTC_PERIPH will be powered off by default.
if (s_config.pd_options[ESP_PD_DOMAIN_RTC_PERIPH] == ESP_PD_OPTION_AUTO) { if (s_config.pd_options[ESP_PD_DOMAIN_RTC_PERIPH] == ESP_PD_OPTION_AUTO) {
#if SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP
uint32_t wakeup_source = RTC_TOUCH_TRIG_EN;
#if SOC_ULP_SUPPORTED
wakeup_source |= RTC_ULP_TRIG_EN;
#endif
if (s_config.wakeup_triggers & (RTC_EXT0_TRIG_EN | RTC_GPIO_TRIG_EN)) { if (s_config.wakeup_triggers & (RTC_EXT0_TRIG_EN | RTC_GPIO_TRIG_EN)) {
s_config.pd_options[ESP_PD_DOMAIN_RTC_PERIPH] = ESP_PD_OPTION_ON; s_config.pd_options[ESP_PD_DOMAIN_RTC_PERIPH] = ESP_PD_OPTION_ON;
} else if (s_config.wakeup_triggers & wakeup_source) { }
// In both rev. 0 and rev. 1 of ESP32, forcing power up of RTC_PERIPH #if CONFIG_IDF_TARGET_ESP32
else if (s_config.wakeup_triggers & (RTC_TOUCH_TRIG_EN | RTC_ULP_TRIG_EN)) {
// On ESP32, forcing power up of RTC_PERIPH
// prevents ULP timer and touch FSMs from working correctly. // prevents ULP timer and touch FSMs from working correctly.
s_config.pd_options[ESP_PD_DOMAIN_RTC_PERIPH] = ESP_PD_OPTION_OFF; s_config.pd_options[ESP_PD_DOMAIN_RTC_PERIPH] = ESP_PD_OPTION_OFF;
} }
#else #endif //CONFIG_IDF_TARGET_ESP32
if (s_config.wakeup_triggers & RTC_GPIO_TRIG_EN) {
s_config.pd_options[ESP_PD_DOMAIN_RTC_PERIPH] = ESP_PD_OPTION_ON;
} else {
s_config.pd_options[ESP_PD_DOMAIN_RTC_PERIPH] = ESP_PD_OPTION_OFF;
}
#endif // SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP
} }
#endif //SOC_PM_SUPPORT_RTC_PERIPH_PD
#if SOC_PM_SUPPORT_CPU_PD #if SOC_PM_SUPPORT_CPU_PD
if (!cpu_domain_pd_allowed()) { if (!cpu_domain_pd_allowed()) {