more teardown on deep sleep (Mirror #2060)
This commit is contained in:
@@ -64,6 +64,14 @@ void HalPowerManager::setPowerSaving(bool enabled) {
|
|||||||
void HalPowerManager::startDeepSleep(HalGPIO& gpio, bool keepClockAlive) const {
|
void HalPowerManager::startDeepSleep(HalGPIO& gpio, bool keepClockAlive) const {
|
||||||
LOG_DBG("PWR", "startDeepSleep: isPressed=%d, rawPin=%d, keepClock=%d", gpio.isPressed(HalGPIO::BTN_POWER),
|
LOG_DBG("PWR", "startDeepSleep: isPressed=%d, rawPin=%d, keepClock=%d", gpio.isPressed(HalGPIO::BTN_POWER),
|
||||||
digitalRead(InputManager::POWER_BUTTON_PIN) == LOW, keepClockAlive);
|
digitalRead(InputManager::POWER_BUTTON_PIN) == LOW, keepClockAlive);
|
||||||
|
|
||||||
|
#ifdef ENABLE_SERIAL_LOG
|
||||||
|
// Tear down HWCDC so the host sees a clean disconnect and the peripheral
|
||||||
|
// doesn't hold power domains that interfere with USB-powered GPIO wake.
|
||||||
|
// logSerial is the raw HWCDC reference; Serial is the MySerialImpl proxy
|
||||||
|
// (which doesn't expose end()).
|
||||||
|
logSerial.end();
|
||||||
|
#endif
|
||||||
// Perform all hardware preparation immediately (while the button may still be held)
|
// Perform all hardware preparation immediately (while the button may still be held)
|
||||||
// so the user gets instant visual feedback (display already off). Only block for
|
// so the user gets instant visual feedback (display already off). Only block for
|
||||||
// button release at the very end, right before entering sleep.
|
// button release at the very end, right before entering sleep.
|
||||||
@@ -96,7 +104,6 @@ void HalPowerManager::startDeepSleep(HalGPIO& gpio, bool keepClockAlive) const {
|
|||||||
// regardless of the wakeup source configuration.
|
// regardless of the wakeup source configuration.
|
||||||
// When keepClockAlive is true, this is the actual wakeup mechanism since the MCU stays powered.
|
// When keepClockAlive is true, this is the actual wakeup mechanism since the MCU stays powered.
|
||||||
esp_deep_sleep_enable_gpio_wakeup(1ULL << InputManager::POWER_BUTTON_PIN, ESP_GPIO_WAKEUP_GPIO_LOW);
|
esp_deep_sleep_enable_gpio_wakeup(1ULL << InputManager::POWER_BUTTON_PIN, ESP_GPIO_WAKEUP_GPIO_LOW);
|
||||||
LOG_DBG("PWR", "startDeepSleep: entering deep sleep now");
|
|
||||||
// Enter Deep Sleep
|
// Enter Deep Sleep
|
||||||
esp_deep_sleep_start();
|
esp_deep_sleep_start();
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-1
@@ -14,6 +14,7 @@
|
|||||||
#include <I18n.h>
|
#include <I18n.h>
|
||||||
#include <Logging.h>
|
#include <Logging.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
#include <WiFi.h>
|
||||||
#include <builtinFonts/all.h>
|
#include <builtinFonts/all.h>
|
||||||
#include <esp_ota_ops.h>
|
#include <esp_ota_ops.h>
|
||||||
|
|
||||||
@@ -165,7 +166,12 @@ void enterDeepSleep() {
|
|||||||
APP_STATE.readerActivityLoadCount = 0;
|
APP_STATE.readerActivityLoadCount = 0;
|
||||||
}
|
}
|
||||||
APP_STATE.saveToFile();
|
APP_STATE.saveToFile();
|
||||||
|
// Tear down WiFi so the modem power domain isn't held alive across deep sleep.
|
||||||
|
// Wake from deep sleep is effectively a chip reset, so no state needs to survive.
|
||||||
|
if (WiFi.getMode() != WIFI_MODE_NULL) {
|
||||||
|
WiFi.disconnect(true);
|
||||||
|
WiFi.mode(WIFI_OFF);
|
||||||
|
}
|
||||||
activityManager.goToSleep();
|
activityManager.goToSleep();
|
||||||
halTiltSensor.deepSleep();
|
halTiltSensor.deepSleep();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user