Add some explanations about PMU and prevent null pointer judgment

This commit is contained in:
lewishe 2022-09-08 10:45:12 +08:00
parent 35c77ef99c
commit 7d0e16d1b6
3 changed files with 24 additions and 24 deletions

View File

@ -391,6 +391,12 @@ bool Power::axpChipInit()
} }
if (!PMU) { 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; return false;
} }
@ -427,16 +433,6 @@ bool Power::axpChipInit()
//disable all axp chip interrupt //disable all axp chip interrupt
PMU->disableIRQ(XPOWERS_AXP192_ALL_IRQ); 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){ if(config.power.charge_current == Config_PowerConfig_ChargeCurrent_MAUnset){
config.power.charge_current = Config_PowerConfig_ChargeCurrent_MA450; config.power.charge_current = Config_PowerConfig_ChargeCurrent_MA450;

View File

@ -3,7 +3,7 @@
#include <Wire.h> #include <Wire.h>
#include "mesh/generated/telemetry.pb.h" #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 #ifndef XPOWERS_AXP192_AXP2101_ADDRESS
#define XPOWERS_AXP192_AXP2101_ADDRESS 0x34 #define XPOWERS_AXP192_AXP2101_ADDRESS 0x34
#endif #endif

View File

@ -79,7 +79,7 @@ void setLed(bool ledOn)
#endif #endif
#ifdef HAS_PMU #ifdef HAS_PMU
if (pmu_found) { if (pmu_found && PMU) {
// blink the axp led // blink the axp led
PMU->setChargingLedMode(ledOn ? XPOWERS_CHG_LED_ON : XPOWERS_CHG_LED_OFF); 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); DEBUG_MSG("Setting GPS power=%d\n", on);
#ifdef HAS_PMU #ifdef HAS_PMU
if (pmu_found){ if (pmu_found && PMU){
#ifdef LILYGO_TBEAM_S3_CORE uint8_t model = PMU->getChipModel();
on ? PMU->enablePowerOutput(XPOWERS_ALDO4) : PMU->disablePowerOutput(XPOWERS_ALDO4); if(model == XPOWERS_AXP2101){
#else // t-beam-s3-core GNSS power channel
on ? PMU->enablePowerOutput(XPOWERS_LDO3) : PMU->disablePowerOutput(XPOWERS_LDO3); on ? PMU->enablePowerOutput(XPOWERS_ALDO4) : PMU->disablePowerOutput(XPOWERS_ALDO4);
#endif /*LILYGO_TBEAM_S3_CORE*/ }else if(model == XPOWERS_AXP192){
// t-beam GNSS power channel
on ? PMU->enablePowerOutput(XPOWERS_LDO3) : PMU->disablePowerOutput(XPOWERS_LDO3);
}
} }
#endif #endif
} }
@ -191,7 +194,7 @@ void doDeepSleep(uint64_t msecToWake)
#endif #endif
#ifdef HAS_PMU #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. // 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 // 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 // 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 // in its sequencer (true?) so the average power draw should be much lower even if we were listinging for packets
// all the time. // all the time.
#ifdef LILYGO_TBEAM_S3_CORE uint8_t model = PMU->getChipModel();
PMU->disablePowerOutput(XPOWERS_ALDO3); // lora radio power channel if(model == XPOWERS_AXP2101){
#else PMU->disablePowerOutput(XPOWERS_ALDO3); // lora radio power channel
PMU->disablePowerOutput(XPOWERS_LDO2); // lora radio power channel }else if(model == XPOWERS_AXP192){
#endif /*LILYGO_TBEAM_S3_CORE*/ PMU->disablePowerOutput(XPOWERS_LDO2); // lora radio power channel
}
} }
#endif #endif