From 35c77ef99c73e432900dc6656417c5b70ed84528 Mon Sep 17 00:00:00 2001 From: lewishe Date: Thu, 8 Sep 2022 10:36:53 +0800 Subject: [PATCH] Simplify HAS_PMU macro definition --- src/ButtonThread.h | 2 +- src/Power.cpp | 8 ++++---- src/detect/i2cScan.h | 2 +- src/main.cpp | 2 +- src/platform/esp32/architecture.h | 3 +++ src/shutdown.h | 2 +- src/sleep.cpp | 8 ++++---- 7 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/ButtonThread.h b/src/ButtonThread.h index e48487c7..af0a8e1e 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -128,7 +128,7 @@ class ButtonThread : public concurrency::OSThread #endif // If user button is held down for 5 seconds, shutdown the device. if ((millis() - longPressTime > 5 * 1000) && (longPressTime > 0)) { -#if defined(HAS_AXP192) || defined(HAS_AXP2101) +#ifdef HAS_PMU if (pmu_found == true) { setLed(false); power->shutdown(); diff --git a/src/Power.cpp b/src/Power.cpp index 53837128..03f8e92a 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -7,7 +7,7 @@ #include "utils.h" #include "buzz/buzz.h" -#if defined(HAS_AXP192) || defined(HAS_AXP2101) +#ifdef HAS_PMU #include "XPowersLibInterface.hpp" #include "XPowersAXP2101.tpp" #include "XPowersAXP192.tpp" @@ -235,7 +235,7 @@ void Power::shutdown() { -#if defined(HAS_AXP192) || defined(HAS_AXP2101) +#ifdef HAS_PMU DEBUG_MSG("Shutting down\n"); if(PMU){ PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); @@ -309,7 +309,7 @@ int32_t Power::runOnce() { readPowerStatus(); -#if defined(HAS_AXP192) || defined(HAS_AXP2101) +#ifdef HAS_PMU // WE no longer use the IRQ line to wake the CPU (due to false wakes from sleep), but we do poll // the IRQ status by reading the registers over I2C if(PMU){ @@ -366,7 +366,7 @@ int32_t Power::runOnce() bool Power::axpChipInit() { -#if defined(HAS_AXP192) || defined(HAS_AXP2101) +#ifdef HAS_PMU if (!PMU) { PMU = new XPowersAXP2101(Wire, I2C_SDA, I2C_SCL); diff --git a/src/detect/i2cScan.h b/src/detect/i2cScan.h index 4c1de7d7..09b31bd6 100644 --- a/src/detect/i2cScan.h +++ b/src/detect/i2cScan.h @@ -115,7 +115,7 @@ void scanI2Cdevice(void) screen_found = addr; DEBUG_MSG("st7567 display found\n"); } -#if defined(HAS_AXP192) || defined(HAS_AXP2101) +#ifdef HAS_PMU if (addr == XPOWERS_AXP192_AXP2101_ADDRESS) { pmu_found = true; DEBUG_MSG("axp192/axp2101 PMU found\n"); diff --git a/src/main.cpp b/src/main.cpp index 4b86bb5f..d57fb83f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -301,7 +301,7 @@ void setup() setupModules(); // Do this after service.init (because that clears error_code) -#if defined(HAS_AXP192) || defined(HAS_AXP2101) +#ifdef HAS_PMU if (!pmu_found) RECORD_CRITICALERROR(CriticalErrorCode_NoAXP192); // Record a hardware fault for missing hardware #endif diff --git a/src/platform/esp32/architecture.h b/src/platform/esp32/architecture.h index 8be6d02a..4d54e48f 100644 --- a/src/platform/esp32/architecture.h +++ b/src/platform/esp32/architecture.h @@ -34,6 +34,9 @@ #define HAS_RTC 1 #endif +#if defined(HAS_AXP192) || defined(HAS_AXP2101) +#define HAS_PMU +#endif // // set HW_VENDOR // diff --git a/src/shutdown.h b/src/shutdown.h index fdb68a94..f3733964 100644 --- a/src/shutdown.h +++ b/src/shutdown.h @@ -35,7 +35,7 @@ void powerCommandsCheck() if (shutdownAtMsec && millis() > shutdownAtMsec) { DEBUG_MSG("Shutting down from admin command\n"); -#if defined(HAS_AXP192) || defined(HAS_AXP2101) +#ifdef HAS_PMU if (pmu_found == true) { playShutdownMelody(); power->shutdown(); diff --git a/src/sleep.cpp b/src/sleep.cpp index 81fe46e2..27135dd8 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -19,7 +19,7 @@ esp_sleep_source_t wakeCause; // the reason we booted this time #endif -#if defined(HAS_AXP192) || defined(HAS_AXP2101) +#ifdef HAS_PMU #include "XPowersLibInterface.hpp" extern XPowersLibInterface *PMU; #endif @@ -78,7 +78,7 @@ void setLed(bool ledOn) digitalWrite(LED_PIN, ledOn ^ LED_INVERTED); #endif -#if defined(HAS_AXP192) || defined(HAS_AXP2101) +#ifdef HAS_PMU if (pmu_found) { // blink the axp led PMU->setChargingLedMode(ledOn ? XPOWERS_CHG_LED_ON : XPOWERS_CHG_LED_OFF); @@ -90,7 +90,7 @@ void setGPSPower(bool on) { DEBUG_MSG("Setting GPS power=%d\n", on); -#if defined(HAS_AXP192) || defined(HAS_AXP2101) +#ifdef HAS_PMU if (pmu_found){ #ifdef LILYGO_TBEAM_S3_CORE on ? PMU->enablePowerOutput(XPOWERS_ALDO4) : PMU->disablePowerOutput(XPOWERS_ALDO4); @@ -190,7 +190,7 @@ void doDeepSleep(uint64_t msecToWake) digitalWrite(VEXT_ENABLE, 1); // turn off the display power #endif -#if defined(HAS_AXP192) || defined(HAS_AXP2101) +#ifdef HAS_PMU if (pmu_found) { // Obsolete comment: from back when we we used to receive lora packets while CPU was in deep sleep. // We no longer do that, because our light-sleep current draws are low enough and it provides fast start/low cost