From 07804e1efae224d8a2dfd8e62770d39b15059f4e Mon Sep 17 00:00:00 2001 From: m1nl Date: Tue, 24 Jun 2025 09:23:37 +0200 Subject: [PATCH] move feature flags --- src/PowerFSM.cpp | 4 ++-- src/PowerFSM.h | 5 +---- src/platform/esp32/architecture.h | 10 ++++++++++ src/sleep.cpp | 20 ++++++++++---------- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index 4f2108177..df2e088cd 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -102,7 +102,7 @@ static void lsEnter() static void lsIdle() { if (!doPreflightSleep()) { -#ifdef DYNAMIC_LIGHT_SLEEP +#ifdef HAS_DYNAMIC_LIGHT_SLEEP powerFSM.trigger(EVENT_WAKE_TIMER); #endif return; @@ -329,7 +329,7 @@ void PowerFSM_setup() powerFSM.add_transition(&stateLS, &stateDARK, EVENT_WEB_REQUEST, NULL, "Web request"); powerFSM.add_transition(&stateDARK, &stateDARK, EVENT_WEB_REQUEST, NULL, "Web request"); -#ifdef DYNAMIC_LIGHT_SLEEP +#ifdef HAS_DYNAMIC_LIGHT_SLEEP // it's better to exit dynamic light sleep when packet is received to ensure routing is properly handled powerFSM.add_transition(&stateLS, &stateDARK, EVENT_RADIO_INTERRUPT, NULL, "Radio interrupt"); powerFSM.add_transition(&stateDARK, &stateDARK, EVENT_RADIO_INTERRUPT, NULL, "Radio interrupt"); diff --git a/src/PowerFSM.h b/src/PowerFSM.h index 6eea31a9d..e79bc07ed 100644 --- a/src/PowerFSM.h +++ b/src/PowerFSM.h @@ -24,14 +24,11 @@ #define EVENT_RADIO_INTERRUPT 18 #define EVENT_WEB_REQUEST 19 -#ifdef ARCH_ESP32 -#ifdef CONFIG_FREERTOS_USE_TICKLESS_IDLE -#define DYNAMIC_LIGHT_SLEEP +#ifdef HAS_DYNAMIC_LIGHT_SLEEP #define WAKE_TIME_MS 500 #else #define WAKE_TIME_MS (Default::getConfiguredOrDefaultMs(config.power.min_wake_secs, default_min_wake_secs)) #endif -#endif #if MESHTASTIC_EXCLUDE_POWER_FSM class FakeFsm diff --git a/src/platform/esp32/architecture.h b/src/platform/esp32/architecture.h index baefbc4eb..caf2585db 100644 --- a/src/platform/esp32/architecture.h +++ b/src/platform/esp32/architecture.h @@ -211,3 +211,13 @@ #endif #define SERIAL0_RX_GPIO 3 // Always GPIO3 on ESP32 // FIXME: may be different on ESP32-S3, etc. + +// Setup flag, which indicates if our device supports power management +#ifdef CONFIG_PM_ENABLE +#define HAS_ESP32_PM_SUPPORT +#endif + +// Setup flag, which indicates if our device supports dynamic light sleep +#if defined(HAS_ESP32_PM_SUPPORT) && defined(CONFIG_FREERTOS_USE_TICKLESS_IDLE) +#define HAS_DYNAMIC_LIGHT_SLEEP +#endif diff --git a/src/sleep.cpp b/src/sleep.cpp index 04b1e0d00..ace271f46 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -18,7 +18,7 @@ #include "target_specific.h" #ifdef ARCH_ESP32 -#ifdef CONFIG_PM_ENABLE +#ifdef HAS_ESP32_PM_SUPPORT #include "esp32/pm.h" #include "esp_pm.h" #endif @@ -54,7 +54,7 @@ Observable notifyLightSleep; /// Called to tell observers that light sleep has just ended, and why it ended Observable notifyLightSleepEnd; -#ifdef CONFIG_PM_ENABLE +#ifdef HAS_ESP32_PM_SUPPORT esp_pm_lock_handle_t pmHandle; #endif @@ -84,7 +84,7 @@ void setCPUFast(bool on) #if defined(ARCH_ESP32) && !HAS_TFT #ifdef HAS_WIFI if (isWifiAvailable()) { -#if !defined(CONFIG_IDF_TARGET_ESP32C3) && defined(WIFI_MAX_PERFORMANCE) +#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(WIFI_MAX_PERFORMANCE) LOG_DEBUG("Set CPU to 240MHz because WiFi is in use"); setCpuFrequencyMhz(240); return; @@ -342,7 +342,7 @@ void doLightSleep(uint32_t sleepMsec) return; // nothing to do } -#ifdef CONFIG_PM_ENABLE +#ifdef HAS_ESP32_PM_SUPPORT res = esp_pm_lock_acquire(pmHandle); assert(res == ESP_OK); #endif @@ -360,7 +360,7 @@ void doLightSleep(uint32_t sleepMsec) if (!pmLockAcquired) { console->flush(); -#ifndef CONFIG_FREERTOS_USE_TICKLESS_IDLE +#ifndef HAS_DYNAMIC_LIGHT_SLEEP esp_light_sleep_start(); #endif @@ -371,7 +371,7 @@ void doLightSleep(uint32_t sleepMsec) enableLoraInterrupt(); enableButtonInterrupt(); -#ifndef CONFIG_FREERTOS_USE_TICKLESS_IDLE +#ifndef HAS_DYNAMIC_LIGHT_SLEEP res = esp_sleep_enable_timer_wakeup(sleepMsec * 1000LL); assert(res == ESP_OK); #endif @@ -414,13 +414,13 @@ void doLightSleep(uint32_t sleepMsec) console->flush(); -#ifdef CONFIG_PM_ENABLE +#ifdef HAS_ESP32_PM_SUPPORT res = esp_pm_lock_release(pmHandle); assert(res == ESP_OK); #endif pmLockAcquired = false; -#ifndef CONFIG_FREERTOS_USE_TICKLESS_IDLE +#ifndef HAS_DYNAMIC_LIGHT_SLEEP esp_light_sleep_start(); #endif @@ -432,7 +432,7 @@ void initLightSleep() { esp_err_t res; -#ifdef CONFIG_PM_ENABLE +#ifdef HAS_ESP32_PM_SUPPORT res = esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "meshtastic", &pmHandle); assert(res == ESP_OK); @@ -442,7 +442,7 @@ void initLightSleep() esp_pm_config_esp32_t pm_config; pm_config.max_freq_mhz = 80; pm_config.min_freq_mhz = 20; -#ifdef CONFIG_FREERTOS_USE_TICKLESS_IDLE +#ifdef HAS_DYNAMIC_LIGHT_SLEEP pm_config.light_sleep_enable = true; #else pm_config.light_sleep_enable = false;