Skip to content

Commit 8899c36

Browse files
authored
feat(wakeup): Use Macro for GPIO_NUM
Changed the example to use a #define for the RTC IO Pin (GPIO) used in the example.
1 parent cd26220 commit 8899c36

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Diff for: libraries/ESP32/examples/DeepSleep/ExternalWakeUp/ExternalWakeUp.ino

+7-6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex
2626
#define USE_EXT0_WAKEUP 1 // 1 = EXT0 wakeup, 0 = EXT1 wakeup
27+
#define WAKEUP_GPIO GPIO_NUM_33 // Only RTC GPIO are allowed - this is a ESP32 example
2728
RTC_DATA_ATTR int bootCount = 0;
2829

2930
/*
@@ -67,24 +68,24 @@ void setup() {
6768
RTC peripherals to be turned on.
6869
*/
6970
#if USE_EXT0_WAKEUP
70-
esp_sleep_enable_ext0_wakeup(GPIO_NUM_33, 1); //1 = High, 0 = Low
71+
esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1); //1 = High, 0 = Low
7172
// Configure pullup/downs via RTCIO to tie wakeup pins to inactive level during deepsleep.
7273
// EXT0 resides in the same power domain (RTC_PERIPH) as the RTC IO pullup/downs.
7374
// No need to keep that power domain explicitly, unlike EXT1.
74-
rtc_gpio_pullup_dis(GPIO_NUM_33);
75-
rtc_gpio_pulldown_en(GPIO_NUM_33);
75+
rtc_gpio_pullup_dis(WAKEUP_GPIO);
76+
rtc_gpio_pulldown_en(WAKEUP_GPIO);
7677

7778
#else // EXT1 WAKEUP
7879
//If you were to use ext1, you would use it like
79-
esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(GPIO_NUM_33), ESP_EXT1_WAKEUP_ANY_HIGH);
80+
esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH);
8081
/*
8182
If there are no external pull-up/downs, tie wakeup pins to inactive level with internal pull-up/downs via RTC IO
8283
during deepsleep. However, RTC IO relies on the RTC_PERIPH power domain. Keeping this power domain on will
8384
increase some power comsumption. However, if we turn off the RTC_PERIPH domain or if certain chips lack the RTC_PERIPH
8485
domain, we will use the HOLD feature to maintain the pull-up and pull-down on the pins during sleep.
8586
*/
86-
rtc_gpio_pulldown_en(GPIO_NUM_33); // GPIO33 is tie to GND in order to wake up in HIGH
87-
rtc_gpio_pullup_dis(GPIO_NUM_33); // Disable PULL_UP in order to allow it to wakeup on HIGH
87+
rtc_gpio_pulldown_en(WAKEUP_GPIO); // GPIO33 is tie to GND in order to wake up in HIGH
88+
rtc_gpio_pullup_dis(WAKEUP_GPIO); // Disable PULL_UP in order to allow it to wakeup on HIGH
8889
#endif
8990
//Go to sleep now
9091
Serial.println("Going to sleep now");

0 commit comments

Comments
 (0)