From 1d9754404163b9bed92d79da92d6019053f91127 Mon Sep 17 00:00:00 2001 From: todd-herbert Date: Mon, 15 Apr 2024 23:50:42 +1200 Subject: [PATCH] Wireless Paper: Fix BLE after Lightsleep (#3629) * NimBLE deinit for deep-sleep only * Optionally disable blink during light-sleep * Advised to revert "blink disable" This reverts commit 66347ce19bb7e6ade64827a01b0ba834bff1e361. --- src/nimble/NimbleBluetooth.cpp | 8 ++++---- src/nimble/NimbleBluetooth.h | 1 + src/sleep.cpp | 6 ++++++ variants/heltec_wireless_paper/variant.h | 3 +++ variants/heltec_wireless_paper_v1/variant.h | 3 +++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/nimble/NimbleBluetooth.cpp b/src/nimble/NimbleBluetooth.cpp index 0b91bf44f..092aef470 100644 --- a/src/nimble/NimbleBluetooth.cpp +++ b/src/nimble/NimbleBluetooth.cpp @@ -112,12 +112,12 @@ void NimbleBluetooth::shutdown() NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising(); pAdvertising->reset(); pAdvertising->stop(); +} -#if defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_WIRELESS_PAPER_V1_0) - // Saving of ~1mA - // Probably applicable to other ESP32 boards - unverified +// Extra power-saving on some devices +void NimbleBluetooth::deinit() +{ NimBLEDevice::deinit(); -#endif } bool NimbleBluetooth::isActive() diff --git a/src/nimble/NimbleBluetooth.h b/src/nimble/NimbleBluetooth.h index df2d3e45a..d1e347830 100644 --- a/src/nimble/NimbleBluetooth.h +++ b/src/nimble/NimbleBluetooth.h @@ -6,6 +6,7 @@ class NimbleBluetooth : BluetoothApi public: void setup(); void shutdown(); + void deinit(); void clearBonds(); bool isActive(); bool isConnected(); diff --git a/src/sleep.cpp b/src/sleep.cpp index 6abe535d7..860a676df 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -206,6 +206,12 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false) // not using wifi yet, but once we are this is needed to shutoff the radio hw // esp_wifi_stop(); waitEnterSleep(skipPreflight); + +#ifdef NIMBLE_DEINIT_FOR_DEEPSLEEP + // Extra power saving on some devices + nimbleBluetooth->deinit(); +#endif + #ifdef ARCH_ESP32 if (shouldLoraWake(msecToWake)) { notifySleep.notifyObservers(NULL); diff --git a/variants/heltec_wireless_paper/variant.h b/variants/heltec_wireless_paper/variant.h index 29b8bbbd1..466925a2e 100644 --- a/variants/heltec_wireless_paper/variant.h +++ b/variants/heltec_wireless_paper/variant.h @@ -55,3 +55,6 @@ #define SX126X_DIO2_AS_RF_SWITCH #define SX126X_DIO3_TCXO_VOLTAGE 1.8 + +// Power management +#define NIMBLE_DEINIT_FOR_DEEPSLEEP // Required to reach manufacturers claim of 18uA diff --git a/variants/heltec_wireless_paper_v1/variant.h b/variants/heltec_wireless_paper_v1/variant.h index 29b8bbbd1..466925a2e 100644 --- a/variants/heltec_wireless_paper_v1/variant.h +++ b/variants/heltec_wireless_paper_v1/variant.h @@ -55,3 +55,6 @@ #define SX126X_DIO2_AS_RF_SWITCH #define SX126X_DIO3_TCXO_VOLTAGE 1.8 + +// Power management +#define NIMBLE_DEINIT_FOR_DEEPSLEEP // Required to reach manufacturers claim of 18uA