From a83d5ada863689b931fa528585d672a4c7798c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 11 Mar 2023 22:40:33 +0100 Subject: [PATCH 1/6] - implement shutdown (deep sleep forever) on ESP32 - Clean up shutdown and delayed shutdown code conditionals. - clean up inputbroker includes --- src/Power.cpp | 20 ++++++++++++++++---- src/input/RotaryEncoderInterruptBase.h | 3 ++- src/input/UpDownInterruptBase.h | 2 +- src/input/kbI2cBase.h | 2 +- src/shutdown.h | 19 ++----------------- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index f84c7b71d..1f9aacd08 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -13,6 +13,10 @@ #include #endif +#ifndef DELAY_FOREVER +#define DELAY_FOREVER portMAX_DELAY +#endif + #ifdef HAS_PMU #include "XPowersAXP192.tpp" #include "XPowersAXP2101.tpp" @@ -256,16 +260,24 @@ void Power::shutdown() digitalWrite(PIN_EINK_EN, LOW); // power off backlight first #endif -#ifdef HAS_PMU LOG_INFO("Shutting down\n"); + +#ifdef HAS_PMU if (PMU) { PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); - PMU->shutdown(); } -#elif defined(ARCH_NRF52) - playBeep(); +#endif + +#if defined(ARCH_NRF52) || defined(ARCH_ESP32) +#ifdef PIN_LED1 ledOff(PIN_LED1); +#endif +#ifdef PIN_LED2 ledOff(PIN_LED2); +#endif +#ifdef PIN_LED3 + ledOff(PIN_LED2); +#endif doDeepSleep(DELAY_FOREVER); #endif } diff --git a/src/input/RotaryEncoderInterruptBase.h b/src/input/RotaryEncoderInterruptBase.h index 06f7a2354..bb77297a8 100644 --- a/src/input/RotaryEncoderInterruptBase.h +++ b/src/input/RotaryEncoderInterruptBase.h @@ -1,7 +1,8 @@ #pragma once #include "InputBroker.h" -#include "SinglePortModule.h" // TODO: what header file to include? +#include "concurrency/OSThread.h" +#include "mesh/generated/meshtastic/module_config.pb.h" enum RotaryEncoderInterruptBaseStateType { ROTARY_EVENT_OCCURRED, ROTARY_EVENT_CLEARED }; diff --git a/src/input/UpDownInterruptBase.h b/src/input/UpDownInterruptBase.h index ed7eee332..372478c22 100644 --- a/src/input/UpDownInterruptBase.h +++ b/src/input/UpDownInterruptBase.h @@ -1,7 +1,7 @@ #pragma once #include "InputBroker.h" -#include "SinglePortModule.h" // TODO: what header file to include? +#include "mesh/nodeDB.h" class UpDownInterruptBase : public Observable { diff --git a/src/input/kbI2cBase.h b/src/input/kbI2cBase.h index 29e8a19ed..e40fd5b33 100644 --- a/src/input/kbI2cBase.h +++ b/src/input/kbI2cBase.h @@ -1,7 +1,7 @@ #pragma once #include "InputBroker.h" -#include "SinglePortModule.h" // TODO: what header file to include? +#include "concurrency/OSThread.h" #include "Wire.h" class KbI2cBase : public Observable, public concurrency::OSThread diff --git a/src/shutdown.h b/src/shutdown.h index 1b0a0509a..b08478a1e 100644 --- a/src/shutdown.h +++ b/src/shutdown.h @@ -18,31 +18,16 @@ void powerCommandsCheck() #endif } -#if defined(ARCH_NRF52) || defined(HAS_PMU) +#if defined(ARCH_ESP32) || defined(ARCH_NRF52) if (shutdownAtMsec) { screen->startShutdownScreen(); - playBeep(); -#ifdef PIN_LED1 - ledOff(PIN_LED1); -#endif -#ifdef PIN_LED2 - ledOff(PIN_LED2); -#endif -#ifdef PIN_LED3 - ledOff(PIN_LED3); -#endif } #endif if (shutdownAtMsec && millis() > shutdownAtMsec) { LOG_INFO("Shutting down from admin command\n"); -#ifdef HAS_PMU - if (pmu_found == true) { - playShutdownMelody(); - power->shutdown(); - } -#elif defined(ARCH_NRF52) playShutdownMelody(); +#if defined(ARCH_NRF52) || defined(ARCH_ESP32) power->shutdown(); #else LOG_WARN("FIXME implement shutdown for this platform"); From 0d001423c8b7234820f25afa407360c8636b8576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 11 Mar 2023 22:48:08 +0100 Subject: [PATCH 2/6] woops --- src/Power.cpp | 2 +- src/input/RotaryEncoderInterruptBase.h | 2 +- src/input/UpDownInterruptBase.h | 2 +- src/input/kbI2cBase.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index 1f9aacd08..5c5c7bca9 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -14,7 +14,7 @@ #endif #ifndef DELAY_FOREVER -#define DELAY_FOREVER portMAX_DELAY +#define DELAY_FOREVER portMAX_DELAY #endif #ifdef HAS_PMU diff --git a/src/input/RotaryEncoderInterruptBase.h b/src/input/RotaryEncoderInterruptBase.h index bb77297a8..9bcf25a69 100644 --- a/src/input/RotaryEncoderInterruptBase.h +++ b/src/input/RotaryEncoderInterruptBase.h @@ -2,7 +2,7 @@ #include "InputBroker.h" #include "concurrency/OSThread.h" -#include "mesh/generated/meshtastic/module_config.pb.h" +#include "mesh/NodeDB.h" enum RotaryEncoderInterruptBaseStateType { ROTARY_EVENT_OCCURRED, ROTARY_EVENT_CLEARED }; diff --git a/src/input/UpDownInterruptBase.h b/src/input/UpDownInterruptBase.h index 372478c22..afa64d28d 100644 --- a/src/input/UpDownInterruptBase.h +++ b/src/input/UpDownInterruptBase.h @@ -1,7 +1,7 @@ #pragma once #include "InputBroker.h" -#include "mesh/nodeDB.h" +#include "mesh/NodeDB.h" class UpDownInterruptBase : public Observable { diff --git a/src/input/kbI2cBase.h b/src/input/kbI2cBase.h index e40fd5b33..a0a4dd608 100644 --- a/src/input/kbI2cBase.h +++ b/src/input/kbI2cBase.h @@ -1,8 +1,8 @@ #pragma once #include "InputBroker.h" -#include "concurrency/OSThread.h" #include "Wire.h" +#include "concurrency/OSThread.h" class KbI2cBase : public Observable, public concurrency::OSThread { From 210e3e09d56f2eea5df35a63ca3acc9fdec44b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 11 Mar 2023 23:10:02 +0100 Subject: [PATCH 3/6] enable deep sleep behaviour for ESP32 --- src/ButtonThread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ButtonThread.h b/src/ButtonThread.h index 5bb856027..172634895 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -133,7 +133,7 @@ class ButtonThread : public concurrency::OSThread setLed(false); power->shutdown(); } -#elif defined(ARCH_NRF52) +#elif defined(ARCH_NRF52) || defined(ARCH_ESP32) // Do actual shutdown when button released, otherwise the button release // may wake the board immediatedly. if ((!shutdown_on_long_stop) && (millis() > 30 * 1000)) { From 9b1d461567731575fec533a0a62987dab3cc78a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 11 Mar 2023 23:11:05 +0100 Subject: [PATCH 4/6] add NO_SCREEN shim --- src/graphics/Screen.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index 602211179..992a73285 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -25,6 +25,7 @@ class Screen void startBluetoothPinScreen(uint32_t pin) {} void stopBluetoothPinScreen() {} void startRebootScreen() {} + void startShutdownScreen() {} void startFirmwareUpdateScreen() {} }; } // namespace graphics From c288974b67840b6d2b6e66d40da5f12e2284dce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 11 Mar 2023 23:13:44 +0100 Subject: [PATCH 5/6] don't adjust brightness on long press any more --- src/ButtonThread.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/ButtonThread.h b/src/ButtonThread.h index 172634895..f35c53a46 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -123,9 +123,6 @@ class ButtonThread : public concurrency::OSThread static void userButtonPressedLong() { // LOG_DEBUG("Long press!\n"); -#ifdef ARCH_ESP32 - screen->adjustBrightness(); -#endif // If user button is held down for 5 seconds, shutdown the device. if ((millis() - longPressTime > 5 * 1000) && (longPressTime > 0)) { #ifdef HAS_PMU From 6d202158ba6c2c6607d770b46d5cbca28fb8bf79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sun, 12 Mar 2023 19:19:01 +0100 Subject: [PATCH 6/6] add (and fix) CPU Shutdown Flags --- src/platform/esp32/architecture.h | 3 +++ src/platform/nrf52/architecture.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/platform/esp32/architecture.h b/src/platform/esp32/architecture.h index 45ee7e6d4..da2d9d905 100644 --- a/src/platform/esp32/architecture.h +++ b/src/platform/esp32/architecture.h @@ -36,6 +36,9 @@ #ifndef HAS_RTC #define HAS_RTC 1 #endif +#ifndef HAS_CPU_SHUTDOWN +#define HAS_CPU_SHUTDOWN 1 +#endif #if defined(HAS_AXP192) || defined(HAS_AXP2101) #define HAS_PMU diff --git a/src/platform/nrf52/architecture.h b/src/platform/nrf52/architecture.h index f21635560..037e884cb 100644 --- a/src/platform/nrf52/architecture.h +++ b/src/platform/nrf52/architecture.h @@ -29,7 +29,7 @@ #ifndef HAS_RADIO #define HAS_RADIO 1 #endif -#ifdef HAS_CPU_SHUTDOWN +#ifndef HAS_CPU_SHUTDOWN #define HAS_CPU_SHUTDOWN 1 #endif