diff --git a/src/Power.cpp b/src/Power.cpp index 779e32ff5..d13fd6891 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -500,12 +500,7 @@ void Power::shutdown() { LOG_INFO("Shutting down\n"); -#ifdef HAS_PMU - if (pmu_found == true) { - PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); - PMU->shutdown(); - } -#elif defined(ARCH_NRF52) || defined(ARCH_ESP32) +#if defined(ARCH_NRF52) || defined(ARCH_ESP32) #ifdef PIN_LED1 ledOff(PIN_LED1); #endif diff --git a/src/nimble/NimbleBluetooth.cpp b/src/nimble/NimbleBluetooth.cpp index 0b91bf44f..42b296e45 100644 --- a/src/nimble/NimbleBluetooth.cpp +++ b/src/nimble/NimbleBluetooth.cpp @@ -113,8 +113,8 @@ void NimbleBluetooth::shutdown() pAdvertising->reset(); pAdvertising->stop(); -#if defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_WIRELESS_PAPER_V1_0) - // Saving of ~1mA +#if defined(ARCH_ESP32) + // Saving of ~1mA for esp32-s3 and 0.1mA for esp32 // Probably applicable to other ESP32 boards - unverified NimBLEDevice::deinit(); #endif diff --git a/src/sleep.cpp b/src/sleep.cpp index 5fbb733e6..7ed264183 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -245,6 +245,22 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false) digitalWrite(VEXT_ENABLE, 1); // turn off the display power #endif +#ifdef ARCH_ESP32 + if (shouldLoraWake(msecToWake)) { + enableLoraInterrupt(); + } +#ifdef BUTTON_PIN + // Avoid leakage through button pin + pinMode(BUTTON_PIN, INPUT); + gpio_hold_en((gpio_num_t)BUTTON_PIN); +#endif + + // LoRa CS (RADIO_NSS) needs to stay HIGH, even during deep sleep + pinMode(LORA_CS, OUTPUT); + digitalWrite(LORA_CS, HIGH); + gpio_hold_en((gpio_num_t)LORA_CS); +#endif + #ifdef HAS_PMU if (pmu_found && PMU) { // Obsolete comment: from back when we we used to receive lora packets while CPU was in deep sleep. @@ -257,6 +273,7 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false) // If we want to leave the radio receiving in would be 11.5mA current draw, but most of the time it is just waiting // in its sequencer (true?) so the average power draw should be much lower even if we were listinging for packets // all the time. + PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); uint8_t model = PMU->getChipModel(); if (model == XPOWERS_AXP2101) { @@ -271,25 +288,15 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false) // t-beam v1.1 radio power channel PMU->disablePowerOutput(XPOWERS_LDO2); // lora radio power channel } + if (msecToWake == portMAX_DELAY) { + LOG_INFO("PMU shutdown.\n"); + console->flush(); + PMU->shutdown(); + } } #endif -#ifdef ARCH_ESP32 - if (shouldLoraWake(msecToWake)) { - enableLoraInterrupt(); - } - -#if defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_WIRELESS_PAPER_V1_0) // Applicable to most ESP32 boards? - // Avoid leakage through button pin - pinMode(BUTTON_PIN, INPUT); - rtc_gpio_hold_en((gpio_num_t)BUTTON_PIN); - - // LoRa CS (RADIO_NSS) needs to stay HIGH, even during deep sleep - pinMode(LORA_CS, OUTPUT); - digitalWrite(LORA_CS, HIGH); - rtc_gpio_hold_en((gpio_num_t)LORA_CS); -#endif -#endif + console->flush(); cpuDeepSleep(msecToWake); }