Merge branch 'feat/esp32s3_support_gpio_deepsleep_wakeup_v4.3' into 'release/v4.3'

example/deep_sleep: add example of EXT0 and using internal pullups (v4.3)

See merge request espressif/esp-idf!18120
This commit is contained in:
Michael (XIAO Xufeng) 2022-10-20 01:32:23 +08:00
commit 19ebbf6f14
2 changed files with 54 additions and 1 deletions

View File

@ -19,8 +19,17 @@ menu "Example Configuration"
the window defined by the initial temperature and a threshold
around it.
config EXAMPLE_EXT0_WAKEUP
bool "Enable wakeup from GPIO (ext0)"
default y
depends on !IDF_TARGET_ESP32C3
help
This option enables wake up from deep sleep from GPIO3. They should be connected to LOW to avoid
floating pins. When triggering a wake up, connect one or both of the pins to HIGH. Note that floating
pins may trigger a wake up.
config EXAMPLE_EXT1_WAKEUP
bool "Enable wakeup from GPIO"
bool "Enable wakeup from GPIO (ext1)"
default y
depends on !IDF_TARGET_ESP32C3
help
@ -28,6 +37,21 @@ menu "Example Configuration"
floating pins. When triggering a wake up, connect one or both of the pins to HIGH. Note that floating
pins may trigger a wake up.
config EXAMPLE_EXT1_USE_INTERNAL_PULLUPS
bool "Use internal pull-up/downs for EXT1 wakeup source"
default n
depends on EXAMPLE_EXT1_WAKEUP
help
When using EXT1 wakeup source without external pull-up/downs, you may want to make use of the internal
ones.
However, the RTC IO reside in the RTC Periph power domain. Enable this option to force that power domain
ON during deep sleep. Note that this will increase some power comsumption, so it's still suggested to use
external ones instead.
EXT0 wakeup source resides in the same power domain as RTCIO (RTC Periph), so internal pull-up/downs are
always available. There's no need to explicitly force it on for EXT0.
config EXAMPLE_GPIO_WAKEUP
bool "Enable wakeup from GPIO"
default y

View File

@ -103,6 +103,12 @@ void app_main(void)
int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000;
switch (esp_sleep_get_wakeup_cause()) {
#if CONFIG_EXAMPLE_EXT0_WAKEUP
case ESP_SLEEP_WAKEUP_EXT0: {
printf("Wake up from ext0\n");
break;
}
#endif // CONFIG_EXAMPLE_EXT0_WAKEUP
#ifdef CONFIG_EXAMPLE_EXT1_WAKEUP
case ESP_SLEEP_WAKEUP_EXT1: {
uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status();
@ -174,6 +180,18 @@ void app_main(void)
printf("Enabling timer wakeup, %ds\n", wakeup_time_sec);
esp_sleep_enable_timer_wakeup(wakeup_time_sec * 1000000);
#if CONFIG_EXAMPLE_EXT0_WAKEUP
const int ext_wakeup_pin_0 = 3;
printf("Enabling EXT0 wakeup on pin GPIO%d\n", ext_wakeup_pin_0);
esp_sleep_enable_ext0_wakeup(ext_wakeup_pin_0, 1);
// Configure pullup/downs via RTCIO to tie wakeup pins to inactive level during deepsleep.
// EXT0 resides in the same power domain (RTC_PERIPH) as the RTC IO pullup/downs.
// No need to keep that power domain explicitly, unlike EXT1.
rtc_gpio_pullup_dis(ext_wakeup_pin_0);
rtc_gpio_pulldown_en(ext_wakeup_pin_0);
#endif // CONFIG_EXAMPLE_EXT0_WAKEUP
#ifdef CONFIG_EXAMPLE_EXT1_WAKEUP
const int ext_wakeup_pin_1 = 2;
const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1;
@ -182,6 +200,17 @@ void app_main(void)
printf("Enabling EXT1 wakeup on pins GPIO%d, GPIO%d\n", ext_wakeup_pin_1, ext_wakeup_pin_2);
esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask | ext_wakeup_pin_2_mask, ESP_EXT1_WAKEUP_ANY_HIGH);
/* If there are no external pull-up/downs, tie wakeup pins to inactive level with internal pull-up/downs via RTC IO
* during deepsleep. However, RTC IO relies on the RTC_PERIPH power domain. Keeping this power domain on will
* increase some power comsumption. */
# if CONFIG_EXAMPLE_EXT1_USE_INTERNAL_PULLUPS
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
rtc_gpio_pullup_dis(ext_wakeup_pin_1);
rtc_gpio_pulldown_en(ext_wakeup_pin_1);
rtc_gpio_pullup_dis(ext_wakeup_pin_2);
rtc_gpio_pulldown_en(ext_wakeup_pin_2);
# endif //CONFIG_EXAMPLE_EXT1_USE_INTERNAL_PULLUPS
#endif // CONFIG_EXAMPLE_EXT1_WAKEUP
#ifdef CONFIG_EXAMPLE_GPIO_WAKEUP