From cd262205d008fbcc6066aad23eaeb4a927d288a4 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 19 Jun 2024 11:12:42 -0300 Subject: [PATCH 1/4] fix(example): EXT0 and EXT1 wakeup Fixes the Deep Sleep wakup example to run with IDF5.1. The API has changed and a adjustment was necessary. --- .../ExternalWakeUp/ExternalWakeUp.ino | 86 +++++++++++-------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino b/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino index fb4228031f6..26ec1cf2ccc 100644 --- a/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino +++ b/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino @@ -1,33 +1,34 @@ /* -Deep Sleep with External Wake Up -===================================== -This code displays how to use deep sleep with -an external trigger as a wake up source and how -to store data in RTC memory to use it over reboots - -This code is under Public Domain License. - -Hardware Connections -====================== -Push Button to GPIO 33 pulled down with a 10K Ohm -resistor - -NOTE: -====== -Only RTC IO can be used as a source for external wake -source. They are pins: 0,2,4,12-15,25-27,32-39. - -Author: -Pranav Cherukupalli + Deep Sleep with External Wake Up + ===================================== + This code displays how to use deep sleep with + an external trigger as a wake up source and how + to store data in RTC memory to use it over reboots + + This code is under Public Domain License. + + Hardware Connections + ====================== + Push Button to GPIO 33 pulled down with a 10K Ohm + resistor + + NOTE: + ====== + Only RTC IO can be used as a source for external wake + source. They are pins: 0,2,4,12-15,25-27,32-39. + + Author: + Pranav Cherukupalli */ +#include "driver/rtc_io.h" -#define BUTTON_PIN_BITMASK 0x200000000 // 2^33 in hex - +#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex +#define USE_EXT0_WAKEUP 1 // 1 = EXT0 wakeup, 0 = EXT1 wakeup RTC_DATA_ATTR int bootCount = 0; /* -Method to print the reason by which ESP32 -has been awaken from sleep + Method to print the reason by which ESP32 + has been awaken from sleep */ void print_wakeup_reason() { esp_sleep_wakeup_cause_t wakeup_reason; @@ -56,20 +57,35 @@ void setup() { print_wakeup_reason(); /* - First we configure the wake up source - We set our ESP32 to wake up for an external trigger. - There are two types for ESP32, ext0 and ext1 . - ext0 uses RTC_IO to wakeup thus requires RTC peripherals - to be on while ext1 uses RTC Controller so does not need - peripherals to be powered on. - Note that using internal pullups/pulldowns also requires - RTC peripherals to be turned on. + First we configure the wake up source + We set our ESP32 to wake up for an external trigger. + There are two types for ESP32, ext0 and ext1 . + ext0 uses RTC_IO to wakeup thus requires RTC peripherals + to be on while ext1 uses RTC Controller so does not need + peripherals to be powered on. + Note that using internal pullups/pulldowns also requires + RTC peripherals to be turned on. */ +#if USE_EXT0_WAKEUP esp_sleep_enable_ext0_wakeup(GPIO_NUM_33, 1); //1 = High, 0 = Low - + // 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(GPIO_NUM_33); + rtc_gpio_pulldown_en(GPIO_NUM_33); + +#else // EXT1 WAKEUP //If you were to use ext1, you would use it like - //esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK,ESP_EXT1_WAKEUP_ANY_HIGH); - + esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(GPIO_NUM_33), 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. However, if we turn off the RTC_PERIPH domain or if certain chips lack the RTC_PERIPH + domain, we will use the HOLD feature to maintain the pull-up and pull-down on the pins during sleep. + */ + rtc_gpio_pulldown_en(GPIO_NUM_33); // GPIO33 is tie to GND in order to wake up in HIGH + rtc_gpio_pullup_dis(GPIO_NUM_33); // Disable PULL_UP in order to allow it to wakeup on HIGH +#endif //Go to sleep now Serial.println("Going to sleep now"); esp_deep_sleep_start(); From 8899c369be7ec1cc7bfce4fc4d00422671def0f4 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 19 Jun 2024 11:16:12 -0300 Subject: [PATCH 2/4] feat(wakeup): Use Macro for GPIO_NUM Changed the example to use a #define for the RTC IO Pin (GPIO) used in the example. --- .../DeepSleep/ExternalWakeUp/ExternalWakeUp.ino | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino b/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino index 26ec1cf2ccc..642536f90d5 100644 --- a/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino +++ b/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino @@ -24,6 +24,7 @@ #define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex #define USE_EXT0_WAKEUP 1 // 1 = EXT0 wakeup, 0 = EXT1 wakeup +#define WAKEUP_GPIO GPIO_NUM_33 // Only RTC GPIO are allowed - this is a ESP32 example RTC_DATA_ATTR int bootCount = 0; /* @@ -67,24 +68,24 @@ void setup() { RTC peripherals to be turned on. */ #if USE_EXT0_WAKEUP - esp_sleep_enable_ext0_wakeup(GPIO_NUM_33, 1); //1 = High, 0 = Low + esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1); //1 = High, 0 = Low // 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(GPIO_NUM_33); - rtc_gpio_pulldown_en(GPIO_NUM_33); + rtc_gpio_pullup_dis(WAKEUP_GPIO); + rtc_gpio_pulldown_en(WAKEUP_GPIO); #else // EXT1 WAKEUP //If you were to use ext1, you would use it like - esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(GPIO_NUM_33), ESP_EXT1_WAKEUP_ANY_HIGH); + esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), 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. However, if we turn off the RTC_PERIPH domain or if certain chips lack the RTC_PERIPH domain, we will use the HOLD feature to maintain the pull-up and pull-down on the pins during sleep. */ - rtc_gpio_pulldown_en(GPIO_NUM_33); // GPIO33 is tie to GND in order to wake up in HIGH - rtc_gpio_pullup_dis(GPIO_NUM_33); // Disable PULL_UP in order to allow it to wakeup on HIGH + rtc_gpio_pulldown_en(WAKEUP_GPIO); // GPIO33 is tie to GND in order to wake up in HIGH + rtc_gpio_pullup_dis(WAKEUP_GPIO); // Disable PULL_UP in order to allow it to wakeup on HIGH #endif //Go to sleep now Serial.println("Going to sleep now"); From d1a8bf69996b79386db218c6c85858782675d4c8 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 19 Jun 2024 11:22:20 -0300 Subject: [PATCH 3/4] fix(typo): typo and commentaries Fixes the commentary to the correct IDF terms. --- .../ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino b/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino index 642536f90d5..ef2111eeab9 100644 --- a/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino +++ b/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino @@ -24,7 +24,7 @@ #define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex #define USE_EXT0_WAKEUP 1 // 1 = EXT0 wakeup, 0 = EXT1 wakeup -#define WAKEUP_GPIO GPIO_NUM_33 // Only RTC GPIO are allowed - this is a ESP32 example +#define WAKEUP_GPIO GPIO_NUM_33 // Only RTC IO are allowed - ESP32 Pin example RTC_DATA_ATTR int bootCount = 0; /* From d367d390011e50eebce224ea4988653464eae120 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Wed, 19 Jun 2024 14:33:09 +0000 Subject: [PATCH 4/4] ci(pre-commit): Apply automatic fixes --- .../examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino b/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino index ef2111eeab9..dc247e387c7 100644 --- a/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino +++ b/libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino @@ -23,8 +23,8 @@ #include "driver/rtc_io.h" #define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex -#define USE_EXT0_WAKEUP 1 // 1 = EXT0 wakeup, 0 = EXT1 wakeup -#define WAKEUP_GPIO GPIO_NUM_33 // Only RTC IO are allowed - ESP32 Pin example +#define USE_EXT0_WAKEUP 1 // 1 = EXT0 wakeup, 0 = EXT1 wakeup +#define WAKEUP_GPIO GPIO_NUM_33 // Only RTC IO are allowed - ESP32 Pin example RTC_DATA_ATTR int bootCount = 0; /* @@ -74,8 +74,8 @@ void setup() { // No need to keep that power domain explicitly, unlike EXT1. rtc_gpio_pullup_dis(WAKEUP_GPIO); rtc_gpio_pulldown_en(WAKEUP_GPIO); - -#else // EXT1 WAKEUP + +#else // EXT1 WAKEUP //If you were to use ext1, you would use it like esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH); /*