|
|
|
@ -3,6 +3,31 @@ |
|
|
|
|
|
|
|
TBeamBoard board; |
|
|
|
|
|
|
|
// Using PMU AXP2102
|
|
|
|
#define PMU_WIRE_PORT Wire |
|
|
|
|
|
|
|
bool pmuIntFlag = false; |
|
|
|
|
|
|
|
void TBeamBoard::printPMU() |
|
|
|
{ |
|
|
|
Serial.print("isCharging:"); Serial.println(PMU->isCharging() ? "YES" : "NO"); |
|
|
|
Serial.print("isDischarge:"); Serial.println(PMU->isDischarge() ? "YES" : "NO"); |
|
|
|
Serial.print("isVbusIn:"); Serial.println(PMU->isVbusIn() ? "YES" : "NO"); |
|
|
|
Serial.print("getBattVoltage:"); Serial.print(PMU->getBattVoltage()); Serial.println("mV"); |
|
|
|
Serial.print("getVbusVoltage:"); Serial.print(PMU->getVbusVoltage()); Serial.println("mV"); |
|
|
|
Serial.print("getSystemVoltage:"); Serial.print(PMU->getSystemVoltage()); Serial.println("mV"); |
|
|
|
|
|
|
|
// The battery percentage may be inaccurate at first use, the PMU will automatically
|
|
|
|
// learn the battery curve and will automatically calibrate the battery percentage
|
|
|
|
// after a charge and discharge cycle
|
|
|
|
if (PMU->isBatteryConnect()) { |
|
|
|
Serial.print("getBatteryPercent:"); Serial.print(PMU->getBatteryPercent()); Serial.println("%"); |
|
|
|
} |
|
|
|
|
|
|
|
Serial.println(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if defined(P_LORA_SCLK) |
|
|
|
static SPIClass spi; |
|
|
|
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_0, P_LORA_RESET, P_LORA_DIO_1, spi); |
|
|
|
@ -15,10 +40,168 @@ WRAPPER_CLASS radio_driver(radio, board); |
|
|
|
ESP32RTCClock fallback_clock; |
|
|
|
AutoDiscoverRTCClock rtc_clock(fallback_clock); |
|
|
|
|
|
|
|
static void setPMUIntFlag(){ |
|
|
|
pmuIntFlag = true; |
|
|
|
} |
|
|
|
|
|
|
|
#ifndef LORA_CR |
|
|
|
#define LORA_CR 5 |
|
|
|
#endif |
|
|
|
|
|
|
|
bool TBeamBoard::power_init() |
|
|
|
{ |
|
|
|
if (!PMU) |
|
|
|
{ |
|
|
|
PMU = new XPowersAXP2101(PMU_WIRE_PORT); |
|
|
|
if (!PMU->init()) |
|
|
|
{ |
|
|
|
Serial.println("Warning: Failed to find AXP2101 power management"); |
|
|
|
delete PMU; |
|
|
|
PMU = NULL; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Serial.println("AXP2101 PMU init succeeded, using AXP2101 PMU"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!PMU) |
|
|
|
{ |
|
|
|
PMU = new XPowersAXP192(PMU_WIRE_PORT); |
|
|
|
if (!PMU->init()) |
|
|
|
{ |
|
|
|
Serial.println("Warning: Failed to find AXP192 power management"); |
|
|
|
delete PMU; |
|
|
|
PMU = NULL; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Serial.println("AXP192 PMU init succeeded, using AXP192 PMU"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!PMU) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
Serial.printf("PMU ID:0x%x\n", PMU->getChipID()); |
|
|
|
printPMU(); |
|
|
|
if (PMU->getChipModel() == XPOWERS_AXP192) |
|
|
|
{ |
|
|
|
|
|
|
|
// lora radio power channel
|
|
|
|
PMU->setPowerChannelVoltage(XPOWERS_LDO2, 3300); |
|
|
|
PMU->enablePowerOutput(XPOWERS_LDO2); |
|
|
|
|
|
|
|
// oled module power channel,
|
|
|
|
// disable it will cause abnormal communication between boot and AXP power supply,
|
|
|
|
// do not turn it off
|
|
|
|
PMU->setPowerChannelVoltage(XPOWERS_DCDC1, 3300); |
|
|
|
// enable oled power
|
|
|
|
PMU->enablePowerOutput(XPOWERS_DCDC1); |
|
|
|
|
|
|
|
// gnss module power channel
|
|
|
|
PMU->setPowerChannelVoltage(XPOWERS_LDO3, 3300); |
|
|
|
// power->enablePowerOutput(XPOWERS_LDO3);
|
|
|
|
|
|
|
|
// protected oled power source
|
|
|
|
PMU->setProtectedChannel(XPOWERS_DCDC1); |
|
|
|
// protected esp32 power source
|
|
|
|
PMU->setProtectedChannel(XPOWERS_DCDC3); |
|
|
|
|
|
|
|
// disable not use channel
|
|
|
|
PMU->disablePowerOutput(XPOWERS_DCDC2); |
|
|
|
|
|
|
|
// disable all axp chip interrupt
|
|
|
|
PMU->disableIRQ(XPOWERS_AXP192_ALL_IRQ); |
|
|
|
|
|
|
|
//
|
|
|
|
/* Set the constant current charging current of AXP192
|
|
|
|
opt: |
|
|
|
XPOWERS_AXP192_CHG_CUR_100MA, |
|
|
|
XPOWERS_AXP192_CHG_CUR_190MA, |
|
|
|
XPOWERS_AXP192_CHG_CUR_280MA, |
|
|
|
XPOWERS_AXP192_CHG_CUR_360MA, |
|
|
|
XPOWERS_AXP192_CHG_CUR_450MA, |
|
|
|
XPOWERS_AXP192_CHG_CUR_550MA, |
|
|
|
XPOWERS_AXP192_CHG_CUR_630MA, |
|
|
|
XPOWERS_AXP192_CHG_CUR_700MA, |
|
|
|
XPOWERS_AXP192_CHG_CUR_780MA, |
|
|
|
XPOWERS_AXP192_CHG_CUR_880MA, |
|
|
|
XPOWERS_AXP192_CHG_CUR_960MA, |
|
|
|
XPOWERS_AXP192_CHG_CUR_1000MA, |
|
|
|
XPOWERS_AXP192_CHG_CUR_1080MA, |
|
|
|
XPOWERS_AXP192_CHG_CUR_1160MA, |
|
|
|
XPOWERS_AXP192_CHG_CUR_1240MA, |
|
|
|
XPOWERS_AXP192_CHG_CUR_1320MA, |
|
|
|
*/ |
|
|
|
PMU->setChargerConstantCurr(XPOWERS_AXP192_CHG_CUR_550MA); |
|
|
|
} |
|
|
|
else if (PMU->getChipModel() == XPOWERS_AXP2101) |
|
|
|
{ |
|
|
|
// gnss module power channel
|
|
|
|
PMU->setPowerChannelVoltage(XPOWERS_ALDO4, 3300); |
|
|
|
PMU->enablePowerOutput(XPOWERS_ALDO4); |
|
|
|
|
|
|
|
// lora radio power channel
|
|
|
|
PMU->setPowerChannelVoltage(XPOWERS_ALDO3, 3300); |
|
|
|
PMU->enablePowerOutput(XPOWERS_ALDO3); |
|
|
|
|
|
|
|
// m.2 interface
|
|
|
|
PMU->setPowerChannelVoltage(XPOWERS_DCDC3, 3300); |
|
|
|
PMU->enablePowerOutput(XPOWERS_DCDC3); |
|
|
|
|
|
|
|
// power->setPowerChannelVoltage(XPOWERS_DCDC4, 3300);
|
|
|
|
// power->enablePowerOutput(XPOWERS_DCDC4);
|
|
|
|
|
|
|
|
// not use channel
|
|
|
|
PMU->disablePowerOutput(XPOWERS_DCDC2); // not elicited
|
|
|
|
PMU->disablePowerOutput(XPOWERS_DCDC5); // not elicited
|
|
|
|
PMU->disablePowerOutput(XPOWERS_DLDO1); // Invalid power channel, it does not exist
|
|
|
|
PMU->disablePowerOutput(XPOWERS_DLDO2); // Invalid power channel, it does not exist
|
|
|
|
PMU->disablePowerOutput(XPOWERS_VBACKUP); |
|
|
|
|
|
|
|
// disable all axp chip interrupt
|
|
|
|
PMU->disableIRQ(XPOWERS_AXP2101_ALL_IRQ); |
|
|
|
|
|
|
|
/* Set the constant current charging current of AXP2101
|
|
|
|
opt: |
|
|
|
XPOWERS_AXP2101_CHG_CUR_100MA, |
|
|
|
XPOWERS_AXP2101_CHG_CUR_125MA, |
|
|
|
XPOWERS_AXP2101_CHG_CUR_150MA, |
|
|
|
XPOWERS_AXP2101_CHG_CUR_175MA, |
|
|
|
XPOWERS_AXP2101_CHG_CUR_200MA, |
|
|
|
XPOWERS_AXP2101_CHG_CUR_300MA, |
|
|
|
XPOWERS_AXP2101_CHG_CUR_400MA, |
|
|
|
XPOWERS_AXP2101_CHG_CUR_500MA, |
|
|
|
XPOWERS_AXP2101_CHG_CUR_600MA, |
|
|
|
XPOWERS_AXP2101_CHG_CUR_700MA, |
|
|
|
XPOWERS_AXP2101_CHG_CUR_800MA, |
|
|
|
XPOWERS_AXP2101_CHG_CUR_900MA, |
|
|
|
XPOWERS_AXP2101_CHG_CUR_1000MA, |
|
|
|
*/ |
|
|
|
PMU->setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_500MA); |
|
|
|
|
|
|
|
// Set up PMU interrupts
|
|
|
|
Serial.println("Setting up PMU interrupts"); |
|
|
|
pinMode(PIN_PMU_IRQ, INPUT_PULLUP); |
|
|
|
attachInterrupt(PIN_PMU_IRQ, setPMUIntFlag, FALLING); |
|
|
|
|
|
|
|
// Reset and re-enable PMU interrupts
|
|
|
|
Serial.println("Re-enable interrupts"); |
|
|
|
PMU->disableIRQ(XPOWERS_AXP2101_ALL_IRQ); |
|
|
|
PMU->clearIrqStatus(); |
|
|
|
PMU->enableIRQ( |
|
|
|
XPOWERS_AXP2101_BAT_INSERT_IRQ | XPOWERS_AXP2101_BAT_REMOVE_IRQ | // Battery interrupts
|
|
|
|
XPOWERS_AXP2101_VBUS_INSERT_IRQ | XPOWERS_AXP2101_VBUS_REMOVE_IRQ | // VBUS interrupts
|
|
|
|
XPOWERS_AXP2101_PKEY_SHORT_IRQ | XPOWERS_AXP2101_PKEY_LONG_IRQ | // Power Key interrupts
|
|
|
|
XPOWERS_AXP2101_BAT_CHG_DONE_IRQ | XPOWERS_AXP2101_BAT_CHG_START_IRQ // Charging interrupts
|
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
bool radio_init() { |
|
|
|
fallback_clock.begin(); |
|
|
|
rtc_clock.begin(Wire); |
|
|
|
@ -33,7 +216,9 @@ bool radio_init() { |
|
|
|
return false; // fail
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
radio.setCRC(1); |
|
|
|
|
|
|
|
|
|
|
|
return true; // success
|
|
|
|
} |
|
|
|
|