From 1107c6d23d46fb3f44042a595f98446b0509e0b2 Mon Sep 17 00:00:00 2001 From: geeksville Date: Fri, 13 Mar 2020 22:42:43 -0700 Subject: [PATCH] Fix serious bug: button presses were not waking from light-sleep on TBEAM Root cause seems to be the axp192 interrupt, which on some boards fires during sleep. I'm not sure why, but we don't need this yet, so leaving masked during sleep. --- src/CustomRF95.cpp | 1 + src/main.cpp | 3 +++ src/sleep.cpp | 13 +++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/CustomRF95.cpp b/src/CustomRF95.cpp index 6172b715..9bce33f3 100644 --- a/src/CustomRF95.cpp +++ b/src/CustomRF95.cpp @@ -21,6 +21,7 @@ CustomRF95::CustomRF95(MemoryPool &_pool, PointerQueue & bool CustomRF95::canSleep() { // We allow initializing mode, because sometimes while testing we don't ever call init() to turn on the hardware + DEBUG_MSG("canSleep, mode=%d, isRx=%d, txEmpty=%d, txGood=%d\n", _mode, _isReceiving, txQueue.isEmpty(), _txGood); return (_mode == RHModeInitialising || _mode == RHModeIdle || _mode == RHModeRx) && !_isReceiving && txQueue.isEmpty(); } diff --git a/src/main.cpp b/src/main.cpp index c45a01fd..861f8cef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -341,6 +341,9 @@ void loop() // axpDebugOutput.loop(); loopBLE(); + // for debug printing + // service.radio.rf95.canSleep(); + #ifdef T_BEAM_V10 if (axp192_found) { diff --git a/src/sleep.cpp b/src/sleep.cpp index a9989f0d..b253d6e0 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -177,6 +177,10 @@ void doDeepSleep(uint64_t msecToWake) // Only GPIOs which are have RTC functionality can be used in this bit map: 0,2,4,12-15,25-27,32-39. uint64_t gpioMask = (1ULL << BUTTON_PIN); +#ifdef BUTTON_NEED_PULLUP + gpio_pullup_en((gpio_num_t) BUTTON_PIN); +#endif + // Not needed because both of the current boards have external pullups // FIXME change polarity in hw so we can wake on ANY_HIGH instead - that would allow us to use all three buttons (instead of just the first) // gpio_pullup_en((gpio_num_t)BUTTON_PIN); @@ -206,15 +210,20 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more r // We want RTC peripherals to stay on esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); +#ifdef BUTTON_NEED_PULLUP + gpio_pullup_en((gpio_num_t) BUTTON_PIN); +#endif + gpio_wakeup_enable((gpio_num_t)BUTTON_PIN, GPIO_INTR_LOW_LEVEL); // when user presses, this button goes low gpio_wakeup_enable((gpio_num_t)DIO0_GPIO, GPIO_INTR_HIGH_LEVEL); // RF95 interrupt, active high #ifdef PMU_IRQ - gpio_wakeup_enable((gpio_num_t)PMU_IRQ, GPIO_INTR_HIGH_LEVEL); // pmu irq + // FIXME, disable wake due to PMU because it seems to fire all the time? + // gpio_wakeup_enable((gpio_num_t)PMU_IRQ, GPIO_INTR_HIGH_LEVEL); // pmu irq #endif assert(esp_sleep_enable_gpio_wakeup() == ESP_OK); assert(esp_sleep_enable_timer_wakeup(sleepUsec) == ESP_OK); assert(esp_light_sleep_start() == ESP_OK); - //DEBUG_MSG("Exit light sleep\n"); + //DEBUG_MSG("Exit light sleep b=%d, rf95=%d, pmu=%d\n", digitalRead(BUTTON_PIN), digitalRead(DIO0_GPIO), digitalRead(PMU_IRQ)); return esp_sleep_get_wakeup_cause(); }