diff --git a/src/Power.cpp b/src/Power.cpp index 03f8e92a6..2073bd660 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -391,6 +391,12 @@ bool Power::axpChipInit() } if (!PMU) { + /* + * In XPowersLib, if the XPowersAXPxxx object is released, Wire.end() will be called at the same time. + * In order not to affect other devices, if the initialization of the PMU fails, Wire needs to be re-initialized once, + * if there are multiple devices sharing the bus. + * * */ + Wire.begin(I2C_SDA, I2C_SCL); return false; } @@ -427,16 +433,6 @@ bool Power::axpChipInit() //disable all axp chip interrupt PMU->disableIRQ(XPOWERS_AXP192_ALL_IRQ); - /* - PMU->enableIRQ(XPOWERS_AXP192_VBUS_REMOVE_IRQ | - XPOWERS_AXP192_VBUS_INSERT_IRQ | - XPOWERS_AXP192_BAT_CHG_DONE_IRQ | - XPOWERS_AXP192_BAT_CHG_START_IRQ | - XPOWERS_AXP192_BAT_REMOVE_IRQ | - XPOWERS_AXP192_BAT_INSERT_IRQ | - XPOWERS_AXP192_PKEY_SHORT_IRQ - ); - */ if(config.power.charge_current == Config_PowerConfig_ChargeCurrent_MAUnset){ config.power.charge_current = Config_PowerConfig_ChargeCurrent_MA450; diff --git a/src/detect/i2cScan.h b/src/detect/i2cScan.h index 09b31bd67..f5f8effc9 100644 --- a/src/detect/i2cScan.h +++ b/src/detect/i2cScan.h @@ -3,7 +3,7 @@ #include #include "mesh/generated/telemetry.pb.h" - +// AXP192 and AXP2101 have the same device address, we just need to identify it in Power.cpp #ifndef XPOWERS_AXP192_AXP2101_ADDRESS #define XPOWERS_AXP192_AXP2101_ADDRESS 0x34 #endif diff --git a/src/sleep.cpp b/src/sleep.cpp index 27135dd8e..58f686cea 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -79,7 +79,7 @@ void setLed(bool ledOn) #endif #ifdef HAS_PMU - if (pmu_found) { + if (pmu_found && PMU) { // blink the axp led PMU->setChargingLedMode(ledOn ? XPOWERS_CHG_LED_ON : XPOWERS_CHG_LED_OFF); } @@ -91,12 +91,15 @@ void setGPSPower(bool on) DEBUG_MSG("Setting GPS power=%d\n", on); #ifdef HAS_PMU - if (pmu_found){ -#ifdef LILYGO_TBEAM_S3_CORE - on ? PMU->enablePowerOutput(XPOWERS_ALDO4) : PMU->disablePowerOutput(XPOWERS_ALDO4); -#else - on ? PMU->enablePowerOutput(XPOWERS_LDO3) : PMU->disablePowerOutput(XPOWERS_LDO3); -#endif /*LILYGO_TBEAM_S3_CORE*/ + if (pmu_found && PMU){ + uint8_t model = PMU->getChipModel(); + if(model == XPOWERS_AXP2101){ + // t-beam-s3-core GNSS power channel + on ? PMU->enablePowerOutput(XPOWERS_ALDO4) : PMU->disablePowerOutput(XPOWERS_ALDO4); + }else if(model == XPOWERS_AXP192){ + // t-beam GNSS power channel + on ? PMU->enablePowerOutput(XPOWERS_LDO3) : PMU->disablePowerOutput(XPOWERS_LDO3); + } } #endif } @@ -191,7 +194,7 @@ void doDeepSleep(uint64_t msecToWake) #endif #ifdef HAS_PMU - if (pmu_found) { + if (pmu_found && PMU) { // 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 // wake. We currently use deep sleep only for 'we want our device to actually be off - because our battery is @@ -203,11 +206,12 @@ void doDeepSleep(uint64_t msecToWake) // in its sequencer (true?) so the average power draw should be much lower even if we were listinging for packets // all the time. -#ifdef LILYGO_TBEAM_S3_CORE - PMU->disablePowerOutput(XPOWERS_ALDO3); // lora radio power channel -#else - PMU->disablePowerOutput(XPOWERS_LDO2); // lora radio power channel -#endif /*LILYGO_TBEAM_S3_CORE*/ + uint8_t model = PMU->getChipModel(); + if(model == XPOWERS_AXP2101){ + PMU->disablePowerOutput(XPOWERS_ALDO3); // lora radio power channel + }else if(model == XPOWERS_AXP192){ + PMU->disablePowerOutput(XPOWERS_LDO2); // lora radio power channel + } } #endif