From 3c0817340a722149d30b5fa4e0583987085b46a8 Mon Sep 17 00:00:00 2001 From: Manuel Verch Date: Mon, 3 Apr 2023 19:45:12 +0200 Subject: [PATCH] Fixed blank screen button issue and SX126x wakeup --- src/PowerFSM.cpp | 24 +++++++++--------------- src/sleep.cpp | 5 ++++- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index 1c3441769..66dfdc9fd 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -93,24 +93,18 @@ static void lsIdle() powerFSM.trigger(EVENT_SERIAL_CONNECTED); break; + case ESP_SLEEP_WAKEUP_GPIO: + // GPIO of BUTTON_PIN (if available) triggered the wakeup + powerFSM.trigger(EVENT_PRESS); + break; + default: - // We woke for some other reason (button press, device interrupt) + // We woke for some other reason (device interrupt) // uint64_t status = esp_sleep_get_ext1_wakeup_status(); LOG_INFO("wakeCause2 %d\n", wakeCause2); - -#ifdef BUTTON_PIN - bool pressed = !digitalRead(BUTTON_PIN); -#else - bool pressed = false; -#endif - if (pressed) // If we woke because of press, instead generate a PRESS event. - { - powerFSM.trigger(EVENT_PRESS); - } else { - // Otherwise let the NB state handle the IRQ (and that state will handle stuff like IRQs etc) - // we lie and say "wake timer" because the interrupt will be handled by the regular IRQ code - powerFSM.trigger(EVENT_WAKE_TIMER); - } + // Let the NB state handle the IRQ (and that state will handle stuff like IRQs etc) + // we lie and say "wake timer" because the interrupt will be handled by the regular IRQ code + powerFSM.trigger(EVENT_WAKE_TIMER); break; } } else { diff --git a/src/sleep.cpp b/src/sleep.cpp index 8b6346038..e3f042a27 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -301,7 +301,10 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more r // assert(esp_sleep_enable_uart_wakeup(0) == ESP_OK); #endif #ifdef BUTTON_PIN - gpio_wakeup_enable((gpio_num_t)BUTTON_PIN, GPIO_INTR_LOW_LEVEL); // when user presses, this button goes low + esp_sleep_enable_ext0_wakeup((gpio_num_t)BUTTON_PIN, LOW); // when user presses, this button goes low +#endif +#if defined(LORA_DIO1) && (LORA_DIO1 != RADIOLIB_NC) + gpio_wakeup_enable((gpio_num_t)LORA_DIO1, GPIO_INTR_HIGH_LEVEL); // SX126x/SX128x interrupt, active high #endif #ifdef RF95_IRQ gpio_wakeup_enable((gpio_num_t)RF95_IRQ, GPIO_INTR_HIGH_LEVEL); // RF95 interrupt, active high