From 14ff5da3ab7c73ce4f699bd62c7b153e89e7ba2e Mon Sep 17 00:00:00 2001 From: lewisxhe Date: Mon, 8 Jul 2024 20:48:11 +0800 Subject: [PATCH] Rename the example variable names https://github.com/lewisxhe/XPowersLib/issues/23 --- examples/AXP192_Example/AXP192_Example.ino | 208 ++++++------- examples/AXP202_Example/AXP202_Example.ino | 202 ++++++------ .../AXP2101_ADC_Example.ino | 64 ++-- .../AXP2101_Charge_Current_Setting.ino | 46 +-- .../AXP2101_Charge_Example.ino | 130 ++++---- examples/AXP2101_Example/AXP2101_Example.ino | 290 +++++++++--------- .../AXP2101_InterruptExample.ino | 78 ++--- .../AXP2101_LowBatteryWarningExample.ino | 110 +++---- .../AXP2101_Sleep_Example.ino | 66 ++-- .../AXP2101_Voltage_Example.ino | 172 +++++------ examples/ESP_IDF_Example/main/port_axp192.cpp | 172 +++++------ .../ESP_IDF_Example/main/port_axp2101.cpp | 180 +++++------ .../XPowersLibInterface_Example.ino | 238 +++++++------- 13 files changed, 978 insertions(+), 978 deletions(-) diff --git a/examples/AXP192_Example/AXP192_Example.ino b/examples/AXP192_Example/AXP192_Example.ino index 63fa2a2..4855299 100644 --- a/examples/AXP192_Example/AXP192_Example.ino +++ b/examples/AXP192_Example/AXP192_Example.ino @@ -52,7 +52,7 @@ if there is any loss, please bear it by yourself #endif bool pmu_flag = 0; -XPowersPMU PMU; +XPowersPMU power; const uint8_t i2c_sda = CONFIG_PMU_SDA; const uint8_t i2c_scl = CONFIG_PMU_SCL; @@ -68,71 +68,71 @@ void setup() { Serial.begin(115200); - bool result = PMU.begin(Wire, AXP192_SLAVE_ADDRESS, i2c_sda, i2c_scl); + bool result = power.begin(Wire, AXP192_SLAVE_ADDRESS, i2c_sda, i2c_scl); if (result == false) { - Serial.println("PMU is not online..."); while (1)delay(50); + Serial.println("power is not online..."); while (1)delay(50); } - Serial.printf("getID:0x%x\n", PMU.getChipID()); + Serial.printf("getID:0x%x\n", power.getChipID()); // Set the minimum system operating voltage inside the PMU, // below this value will shut down the PMU // Range: 2600~3300mV - PMU.setSysPowerDownVoltage(2700); + power.setSysPowerDownVoltage(2700); // Set the minimum common working voltage of the PMU VBUS input, // below this value will turn off the PMU - PMU.setVbusVoltageLimit(XPOWERS_AXP192_VBUS_VOL_LIM_4V5); + power.setVbusVoltageLimit(XPOWERS_AXP192_VBUS_VOL_LIM_4V5); // Turn off USB input current limit - PMU.setVbusCurrentLimit(XPOWERS_AXP192_VBUS_CUR_LIM_OFF); + power.setVbusCurrentLimit(XPOWERS_AXP192_VBUS_CUR_LIM_OFF); // DC1 700~3500mV, IMAX=1.2A - PMU.setDC1Voltage(3300); - Serial.printf("DC1 :%s Voltage:%u mV \n", PMU.isEnableDC1() ? "+" : "-", PMU.getDC1Voltage()); + power.setDC1Voltage(3300); + Serial.printf("DC1 :%s Voltage:%u mV \n", power.isEnableDC1() ? "+" : "-", power.getDC1Voltage()); // DC2 700~2750 mV, IMAX=1.6A; - PMU.setDC2Voltage(700); - Serial.printf("DC2 :%s Voltage:%u mV \n", PMU.isEnableDC2() ? "+" : "-", PMU.getDC2Voltage()); + power.setDC2Voltage(700); + Serial.printf("DC2 :%s Voltage:%u mV \n", power.isEnableDC2() ? "+" : "-", power.getDC2Voltage()); // DC3 700~3500 mV,IMAX=0.7A; - PMU.setDC3Voltage(3300); - Serial.printf("DC3 :%s Voltage:%u mV \n", PMU.isEnableDC3() ? "+" : "-", PMU.getDC3Voltage()); + power.setDC3Voltage(3300); + Serial.printf("DC3 :%s Voltage:%u mV \n", power.isEnableDC3() ? "+" : "-", power.getDC3Voltage()); //LDO2 1800~3300 mV, 100mV/step, IMAX=200mA - PMU.setLDO2Voltage(1800); + power.setLDO2Voltage(1800); //LDO3 1800~3300 mV, 100mV/step, IMAX=200mA - PMU.setLDO3Voltage(1800); + power.setLDO3Voltage(1800); //LDOio 1800~3300 mV, 100mV/step, IMAX=50mA - PMU.setLDOioVoltage(3300); + power.setLDOioVoltage(3300); - // Enable power output channel - // PMU.enableDC1(); - PMU.enableDC2(); - PMU.enableDC3(); - PMU.enableLDO2(); - PMU.enableLDO3(); - PMU.enableLDOio(); + // Enable PMU output channel + // power.enableDC1(); + power.enableDC2(); + power.enableDC3(); + power.enableLDO2(); + power.enableLDO3(); + power.enableLDOio(); Serial.println("DCDC======================================================================="); - Serial.printf("DC1 :%s Voltage:%u mV \n", PMU.isEnableDC1() ? "ENABLE" : "DISABLE", PMU.getDC1Voltage()); - Serial.printf("DC2 :%s Voltage:%u mV \n", PMU.isEnableDC2() ? "ENABLE" : "DISABLE", PMU.getDC2Voltage()); - Serial.printf("DC3 :%s Voltage:%u mV \n", PMU.isEnableDC3() ? "ENABLE" : "DISABLE", PMU.getDC3Voltage()); + Serial.printf("DC1 :%s Voltage:%u mV \n", power.isEnableDC1() ? "ENABLE" : "DISABLE", power.getDC1Voltage()); + Serial.printf("DC2 :%s Voltage:%u mV \n", power.isEnableDC2() ? "ENABLE" : "DISABLE", power.getDC2Voltage()); + Serial.printf("DC3 :%s Voltage:%u mV \n", power.isEnableDC3() ? "ENABLE" : "DISABLE", power.getDC3Voltage()); Serial.println("LDO======================================================================="); - Serial.printf("LDO2: %s Voltage:%u mV\n", PMU.isEnableLDO2() ? "ENABLE" : "DISABLE", PMU.getLDO2Voltage()); - Serial.printf("LDO3: %s Voltage:%u mV\n", PMU.isEnableLDO3() ? "ENABLE" : "DISABLE", PMU.getLDO3Voltage()); - Serial.printf("LDOio: %s Voltage:%u mV\n", PMU.isEnableLDOio() ? "ENABLE" : "DISABLE", PMU.getLDOioVoltage()); + Serial.printf("LDO2: %s Voltage:%u mV\n", power.isEnableLDO2() ? "ENABLE" : "DISABLE", power.getLDO2Voltage()); + Serial.printf("LDO3: %s Voltage:%u mV\n", power.isEnableLDO3() ? "ENABLE" : "DISABLE", power.getLDO3Voltage()); + Serial.printf("LDOio: %s Voltage:%u mV\n", power.isEnableLDOio() ? "ENABLE" : "DISABLE", power.getLDOioVoltage()); Serial.println("=========================================================================="); // Set the time of pressing the button to turn off - PMU.setPowerKeyPressOffTime(XPOWERS_AXP192_POWEROFF_4S); - uint8_t opt = PMU.getPowerKeyPressOffTime(); + power.setPowerKeyPressOffTime(XPOWERS_AXP192_POWEROFF_4S); + uint8_t opt = power.getPowerKeyPressOffTime(); Serial.print("PowerKeyPressOffTime:"); switch (opt) { case XPOWERS_AXP192_POWEROFF_4S: Serial.println("4 Second"); @@ -147,8 +147,8 @@ void setup() break; } // Set the button power-on press time - PMU.setPowerKeyPressOnTime(XPOWERS_POWERON_128MS); - opt = PMU.getPowerKeyPressOnTime(); + power.setPowerKeyPressOnTime(XPOWERS_POWERON_128MS); + opt = power.getPowerKeyPressOnTime(); Serial.print("PowerKeyPressOnTime:"); switch (opt) { case XPOWERS_POWERON_128MS: Serial.println("128 Ms"); @@ -167,16 +167,16 @@ void setup() // It is necessary to disable the detection function of the TS pin on the board // without the battery temperature detection function, otherwise it will cause abnormal charging - PMU.disableTSPinMeasure(); + power.disableTSPinMeasure(); - // PMU.enableTemperatureMeasure(); - // PMU.disableTemperatureMeasure(); + // power.enableTemperatureMeasure(); + // power.disableTemperatureMeasure(); // Enable internal ADC detection - PMU.enableBattDetection(); - PMU.enableVbusVoltageMeasure(); - PMU.enableBattVoltageMeasure(); - PMU.enableSystemVoltageMeasure(); + power.enableBattDetection(); + power.enableVbusVoltageMeasure(); + power.enableBattVoltageMeasure(); + power.enableSystemVoltageMeasure(); /* The default setting is CHGLED is automatically controlled by the PMU. @@ -186,18 +186,18 @@ void setup() - XPOWERS_CHG_LED_ON, - XPOWERS_CHG_LED_CTRL_CHG, * */ - PMU.setChargingLedMode(XPOWERS_CHG_LED_OFF); + power.setChargingLedMode(XPOWERS_CHG_LED_OFF); pinMode(pmu_irq_pin, INPUT); attachInterrupt(pmu_irq_pin, setFlag, FALLING); // Disable all interrupts - PMU.disableIRQ(XPOWERS_AXP192_ALL_IRQ); + power.disableIRQ(XPOWERS_AXP192_ALL_IRQ); // Clear all interrupt flags - PMU.clearIrqStatus(); + power.clearIrqStatus(); // Enable the required interrupt function - PMU.enableIRQ( + power.enableIRQ( XPOWERS_AXP192_BAT_INSERT_IRQ | XPOWERS_AXP192_BAT_REMOVE_IRQ | //BATTERY XPOWERS_AXP192_VBUS_INSERT_IRQ | XPOWERS_AXP192_VBUS_REMOVE_IRQ | //VBUS XPOWERS_AXP192_PKEY_SHORT_IRQ | XPOWERS_AXP192_PKEY_LONG_IRQ | //POWER KEY @@ -207,21 +207,21 @@ void setup() ); // Set constant current charge current limit - PMU.setChargerConstantCurr(XPOWERS_AXP192_CHG_CUR_280MA); + power.setChargerConstantCurr(XPOWERS_AXP192_CHG_CUR_280MA); // Set stop charging termination current - PMU.setChargerTerminationCurr(XPOWERS_AXP192_CHG_ITERM_LESS_10_PERCENT); + power.setChargerTerminationCurr(XPOWERS_AXP192_CHG_ITERM_LESS_10_PERCENT); // Set charge cut-off voltage - PMU.setChargeTargetVoltage(XPOWERS_AXP192_CHG_VOL_4V2); + power.setChargeTargetVoltage(XPOWERS_AXP192_CHG_VOL_4V2); // Cache writes and reads, as long as the PMU remains powered, the data will always be stored inside the PMU Serial.println("Write pmu data buffer ."); uint8_t data[XPOWERS_AXP192_DATA_BUFFER_SIZE] = {1, 2, 3, 4, 5, 6}; - PMU.writeDataBuffer(data, XPOWERS_AXP192_DATA_BUFFER_SIZE); + power.writeDataBuffer(data, XPOWERS_AXP192_DATA_BUFFER_SIZE); memset(data, 0, XPOWERS_AXP192_DATA_BUFFER_SIZE); Serial.print("Read pmu data buffer :"); - PMU.readDataBuffer(data, XPOWERS_AXP192_DATA_BUFFER_SIZE); + power.readDataBuffer(data, XPOWERS_AXP192_DATA_BUFFER_SIZE); for (int i = 0; i < XPOWERS_AXP192_DATA_BUFFER_SIZE; ++i) { Serial.print(data[i]); Serial.print(","); @@ -229,21 +229,21 @@ void setup() Serial.println(); // Set the timing after one minute, the isWdtExpireIrq will be triggered in the loop interrupt function - PMU.setTimerout(1); + power.setTimerout(1); } void 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"); - Serial.print("getTemperature:"); Serial.print(PMU.getTemperature()); Serial.println("*C"); - - if (PMU.isBatteryConnect()) { - Serial.print("getBatteryPercent:"); Serial.print(PMU.getBatteryPercent()); Serial.println("%"); + Serial.print("isCharging:"); Serial.println(power.isCharging() ? "YES" : "NO"); + Serial.print("isDischarge:"); Serial.println(power.isDischarge() ? "YES" : "NO"); + Serial.print("isVbusIn:"); Serial.println(power.isVbusIn() ? "YES" : "NO"); + Serial.print("getBattVoltage:"); Serial.print(power.getBattVoltage()); Serial.println("mV"); + Serial.print("getVbusVoltage:"); Serial.print(power.getVbusVoltage()); Serial.println("mV"); + Serial.print("getSystemVoltage:"); Serial.print(power.getSystemVoltage()); Serial.println("mV"); + Serial.print("getTemperature:"); Serial.print(power.getTemperature()); Serial.println("*C"); + + if (power.isBatteryConnect()) { + Serial.print("getBatteryPercent:"); Serial.print(power.getBatteryPercent()); Serial.println("%"); } Serial.println(); @@ -254,16 +254,16 @@ void printPMU() void enterPmuSleep(void) { // Set sleep flag - PMU.enableSleep(); + power.enableSleep(); - PMU.disableDC2(); - PMU.disableDC3(); + power.disableDC2(); + power.disableDC3(); - PMU.disableLDO2(); - PMU.disableLDO3(); + power.disableLDO2(); + power.disableLDO3(); // Finally, turn off the power of the control chip - PMU.disableDC1(); + power.disableDC1(); } void loop() @@ -273,129 +273,129 @@ void loop() pmu_flag = false; // Get PMU Interrupt Status Register - uint32_t status = PMU.getIrqStatus(); + uint32_t status = power.getIrqStatus(); Serial.print("STATUS => HEX:"); Serial.print(status, HEX); Serial.print(" BIN:"); Serial.println(status, BIN); - if (PMU.isAcinOverVoltageIrq()) { + if (power.isAcinOverVoltageIrq()) { Serial.println("isAcinOverVoltageIrq"); } - if (PMU.isAcinInserIrq()) { + if (power.isAcinInserIrq()) { Serial.println("isAcinInserIrq"); } - if (PMU.isAcinRemoveIrq()) { + if (power.isAcinRemoveIrq()) { Serial.println("isAcinRemoveIrq"); } - if (PMU.isVbusOverVoltageIrq()) { + if (power.isVbusOverVoltageIrq()) { Serial.println("isVbusOverVoltageIrq"); } - if (PMU.isVbusInsertIrq()) { + if (power.isVbusInsertIrq()) { Serial.println("isVbusInsertIrq"); } - if (PMU.isVbusRemoveIrq()) { + if (power.isVbusRemoveIrq()) { Serial.println("isVbusRemoveIrq"); } - if (PMU.isVbusLowVholdIrq()) { + if (power.isVbusLowVholdIrq()) { Serial.println("isVbusLowVholdIrq"); } - if (PMU.isBatInsertIrq()) { + if (power.isBatInsertIrq()) { Serial.println("isBatInsertIrq"); } - if (PMU.isBatRemoveIrq()) { + if (power.isBatRemoveIrq()) { Serial.println("isBatRemoveIrq"); } - if (PMU.isBattEnterActivateIrq()) { + if (power.isBattEnterActivateIrq()) { Serial.println("isBattEnterActivateIrq"); } - if (PMU.isBattExitActivateIrq()) { + if (power.isBattExitActivateIrq()) { Serial.println("isBattExitActivateIrq"); } - if (PMU.isBatChagerStartIrq()) { + if (power.isBatChagerStartIrq()) { Serial.println("isBatChagerStartIrq"); } - if (PMU.isBatChagerDoneIrq()) { + if (power.isBatChagerDoneIrq()) { Serial.println("isBatChagerDoneIrq"); } - if (PMU.isBattTempHighIrq()) { + if (power.isBattTempHighIrq()) { Serial.println("isBattTempHighIrq"); } - if (PMU.isBattTempLowIrq()) { + if (power.isBattTempLowIrq()) { Serial.println("isBattTempLowIrq"); } - if (PMU.isChipOverTemperatureIrq()) { + if (power.isChipOverTemperatureIrq()) { Serial.println("isChipOverTemperatureIrq"); } - if (PMU.isChargingCurrentLessIrq()) { + if (power.isChargingCurrentLessIrq()) { Serial.println("isChargingCurrentLessIrq"); } - if (PMU.isDC1VoltageLessIrq()) { + if (power.isDC1VoltageLessIrq()) { Serial.println("isDC1VoltageLessIrq"); } - if (PMU.isDC2VoltageLessIrq()) { + if (power.isDC2VoltageLessIrq()) { Serial.println("isDC2VoltageLessIrq"); } - if (PMU.isDC3VoltageLessIrq()) { + if (power.isDC3VoltageLessIrq()) { Serial.println("isDC3VoltageLessIrq"); } - if (PMU.isPekeyShortPressIrq()) { + if (power.isPekeyShortPressIrq()) { Serial.println("isPekeyShortPress"); // enterPmuSleep(); //CHG LED mode test - uint8_t m = PMU.getChargingLedMode(); + uint8_t m = power.getChargingLedMode(); Serial.print("getChargingLedMode:"); Serial.println(m++); m %= XPOWERS_CHG_LED_CTRL_CHG; Serial.printf("setChargingLedMode:%u", m); - PMU.setChargingLedMode(m); + power.setChargingLedMode(m); } - if (PMU.isPekeyLongPressIrq()) { + if (power.isPekeyLongPressIrq()) { Serial.println("isPekeyLongPress"); } - if (PMU.isNOEPowerOnIrq()) { + if (power.isNOEPowerOnIrq()) { Serial.println("isNOEPowerOnIrq"); } - if (PMU.isNOEPowerDownIrq()) { + if (power.isNOEPowerDownIrq()) { Serial.println("isNOEPowerDownIrq"); } - if (PMU.isVbusEffectiveIrq()) { + if (power.isVbusEffectiveIrq()) { Serial.println("isVbusEffectiveIrq"); } - if (PMU.isVbusInvalidIrq()) { + if (power.isVbusInvalidIrq()) { Serial.println("isVbusInvalidIrq"); } - if (PMU.isVbusSessionIrq()) { + if (power.isVbusSessionIrq()) { Serial.println("isVbusSessionIrq"); } - if (PMU.isVbusSessionEndIrq()) { + if (power.isVbusSessionEndIrq()) { Serial.println("isVbusSessionEndIrq"); } - if (PMU.isLowVoltageLevel2Irq()) { + if (power.isLowVoltageLevel2Irq()) { Serial.println("isLowVoltageLevel2Irq"); } - if (PMU.isWdtExpireIrq()) { + if (power.isWdtExpireIrq()) { Serial.println("isWdtExpire"); printPMU(); // Clear the timer state and continue to the next timer - PMU.clearTimerFlag(); + power.clearTimerFlag(); } - if (PMU.isGpio2EdgeTriggerIrq()) { + if (power.isGpio2EdgeTriggerIrq()) { Serial.println("isGpio2EdgeTriggerIrq"); } - if (PMU.isGpio1EdgeTriggerIrq()) { + if (power.isGpio1EdgeTriggerIrq()) { Serial.println("isGpio1EdgeTriggerIrq"); } - if (PMU.isGpio0EdgeTriggerIrq()) { + if (power.isGpio0EdgeTriggerIrq()) { Serial.println("isGpio0EdgeTriggerIrq"); } // Clear PMU Interrupt Status Register - PMU.clearIrqStatus(); + power.clearIrqStatus(); } delay(10); diff --git a/examples/AXP202_Example/AXP202_Example.ino b/examples/AXP202_Example/AXP202_Example.ino index 74f4b21..3f8a3eb 100644 --- a/examples/AXP202_Example/AXP202_Example.ino +++ b/examples/AXP202_Example/AXP202_Example.ino @@ -51,7 +51,7 @@ if there is any loss, please bear it by yourself #endif bool pmu_flag = 0; -XPowersPMU PMU; +XPowersPMU power; const uint8_t i2c_sda = CONFIG_PMU_SDA; const uint8_t i2c_scl = CONFIG_PMU_SCL; @@ -67,73 +67,73 @@ void setup() { Serial.begin(115200); - bool result = PMU.begin(Wire, AXP202_SLAVE_ADDRESS, i2c_sda, i2c_scl); + bool result = power.begin(Wire, AXP202_SLAVE_ADDRESS, i2c_sda, i2c_scl); if (result == false) { - Serial.println("PMU is not online..."); while (1)delay(50); + Serial.println("power is not online..."); while (1)delay(50); } - Serial.printf("getID:0x%x\n", PMU.getChipID()); + Serial.printf("getID:0x%x\n", power.getChipID()); // Set the minimum system operating voltage inside the PMU, // below this value will shut down the PMU // Range: 2600~3300mV - PMU.setSysPowerDownVoltage(2700); + power.setSysPowerDownVoltage(2700); // Set the minimum common working voltage of the PMU VBUS input, // below this value will turn off the PMU - PMU.setVbusVoltageLimit(XPOWERS_AXP202_VBUS_VOL_LIM_4V5); + power.setVbusVoltageLimit(XPOWERS_AXP202_VBUS_VOL_LIM_4V5); // Turn off USB input current limit - PMU.setVbusCurrentLimit(XPOWERS_AXP202_VBUS_CUR_LIM_OFF); + power.setVbusCurrentLimit(XPOWERS_AXP202_VBUS_CUR_LIM_OFF); // DC2 700~3500 mV, IMAX=1.6A; - PMU.setDC2Voltage(700); + power.setDC2Voltage(700); // DC3 700~3500 mV,IMAX=0.7A; - PMU.setDC3Voltage(3300); + power.setDC3Voltage(3300); //LDO2 1800~3300 mV, 100mV/step, IMAX=200mA - PMU.setLDO2Voltage(1800); + power.setLDO2Voltage(1800); //LDO3 700~2275 mV, 100mV/step, IMAX=200mA - PMU.setLDO3Voltage(1800); + power.setLDO3Voltage(1800); /* LDO4 Range: 1250, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2500, 2700, 2800, 3000, 3100, 3200, 3300 */ - PMU.setLDO4Voltage(3300); + power.setLDO4Voltage(3300); //LDOio 1800~3300 mV, 100mV/step, IMAX=50mA - PMU.setLDOioVoltage(3300); + power.setLDOioVoltage(3300); // Enable power output channel - PMU.enableDC2(); + power.enableDC2(); - // PMU.enableDC3(); + // power.enableDC3(); - PMU.enableLDO2(); - PMU.enableLDO3(); - PMU.enableLDO4(); - PMU.enableLDOio(); + power.enableLDO2(); + power.enableLDO3(); + power.enableLDO4(); + power.enableLDOio(); Serial.println("DCDC======================================================================="); - Serial.printf("DC2 :%s Voltage:%u mV \n", PMU.isEnableDC2() ? "ENABLE" : "DISABLE", PMU.getDC2Voltage()); - Serial.printf("DC3 :%s Voltage:%u mV \n", PMU.isEnableDC3() ? "ENABLE" : "DISABLE", PMU.getDC3Voltage()); + Serial.printf("DC2 :%s Voltage:%u mV \n", power.isEnableDC2() ? "ENABLE" : "DISABLE", power.getDC2Voltage()); + Serial.printf("DC3 :%s Voltage:%u mV \n", power.isEnableDC3() ? "ENABLE" : "DISABLE", power.getDC3Voltage()); Serial.println("LDO======================================================================="); - Serial.printf("LDO2: %s Voltage:%u mV\n", PMU.isEnableLDO2() ? "ENABLE" : "DISABLE", PMU.getLDO2Voltage()); - Serial.printf("LDO3: %s Voltage:%u mV\n", PMU.isEnableLDO3() ? "ENABLE" : "DISABLE", PMU.getLDO3Voltage()); - Serial.printf("LDO4: %s Voltage:%u mV\n", PMU.isEnableLDO4() ? "ENABLE" : "DISABLE", PMU.getLDO4Voltage()); - Serial.printf("LDOio: %s Voltage:%u mV\n", PMU.isEnableLDOio() ? "ENABLE" : "DISABLE", PMU.getLDOioVoltage()); + Serial.printf("LDO2: %s Voltage:%u mV\n", power.isEnableLDO2() ? "ENABLE" : "DISABLE", power.getLDO2Voltage()); + Serial.printf("LDO3: %s Voltage:%u mV\n", power.isEnableLDO3() ? "ENABLE" : "DISABLE", power.getLDO3Voltage()); + Serial.printf("LDO4: %s Voltage:%u mV\n", power.isEnableLDO4() ? "ENABLE" : "DISABLE", power.getLDO4Voltage()); + Serial.printf("LDOio: %s Voltage:%u mV\n", power.isEnableLDOio() ? "ENABLE" : "DISABLE", power.getLDOioVoltage()); Serial.println("=========================================================================="); // Set the time of pressing the button to turn off - PMU.setPowerKeyPressOffTime(XPOWERS_AXP202_POWEROFF_4S); - uint8_t opt = PMU.getPowerKeyPressOffTime(); + power.setPowerKeyPressOffTime(XPOWERS_AXP202_POWEROFF_4S); + uint8_t opt = power.getPowerKeyPressOffTime(); Serial.print("PowerKeyPressOffTime:"); switch (opt) { case XPOWERS_AXP202_POWEROFF_4S: Serial.println("4 Second"); @@ -148,8 +148,8 @@ void setup() break; } // Set the button power-on press time - PMU.setPowerKeyPressOnTime(XPOWERS_POWERON_128MS); - opt = PMU.getPowerKeyPressOnTime(); + power.setPowerKeyPressOnTime(XPOWERS_POWERON_128MS); + opt = power.getPowerKeyPressOnTime(); Serial.print("PowerKeyPressOnTime:"); switch (opt) { case XPOWERS_POWERON_128MS: Serial.println("128 Ms"); @@ -168,16 +168,16 @@ void setup() // It is necessary to disable the detection function of the TS pin on the board // without the battery temperature detection function, otherwise it will cause abnormal charging - PMU.disableTSPinMeasure(); + power.disableTSPinMeasure(); - // PMU.enableTemperatureMeasure(); - // PMU.disableTemperatureMeasure(); + // power.enableTemperatureMeasure(); + // power.disableTemperatureMeasure(); // Enable internal ADC detection - PMU.enableBattDetection(); - PMU.enableVbusVoltageMeasure(); - PMU.enableBattVoltageMeasure(); - PMU.enableSystemVoltageMeasure(); + power.enableBattDetection(); + power.enableVbusVoltageMeasure(); + power.enableBattVoltageMeasure(); + power.enableSystemVoltageMeasure(); /* The default setting is CHGLED is automatically controlled by the PMU. @@ -187,18 +187,18 @@ void setup() - XPOWERS_CHG_LED_ON, - XPOWERS_CHG_LED_CTRL_CHG, * */ - PMU.setChargingLedMode(XPOWERS_CHG_LED_OFF); + power.setChargingLedMode(XPOWERS_CHG_LED_OFF); pinMode(pmu_irq_pin, INPUT); attachInterrupt(pmu_irq_pin, setFlag, FALLING); // Disable all interrupts - PMU.disableIRQ(XPOWERS_AXP202_ALL_IRQ); + power.disableIRQ(XPOWERS_AXP202_ALL_IRQ); // Clear all interrupt flags - PMU.clearIrqStatus(); + power.clearIrqStatus(); // Enable the required interrupt function - PMU.enableIRQ( + power.enableIRQ( XPOWERS_AXP202_BAT_INSERT_IRQ | XPOWERS_AXP202_BAT_REMOVE_IRQ | //BATTERY XPOWERS_AXP202_VBUS_INSERT_IRQ | XPOWERS_AXP202_VBUS_REMOVE_IRQ | //VBUS XPOWERS_AXP202_PKEY_SHORT_IRQ | XPOWERS_AXP202_PKEY_LONG_IRQ | //POWER KEY @@ -208,21 +208,21 @@ void setup() ); // Set constant current charge current limit - PMU.setChargerConstantCurr(XPOWERS_AXP202_CHG_CUR_280MA); + power.setChargerConstantCurr(XPOWERS_AXP202_CHG_CUR_280MA); // Set stop charging termination current - PMU.setChargerTerminationCurr(XPOWERS_AXP202_CHG_ITERM_LESS_10_PERCENT); + power.setChargerTerminationCurr(XPOWERS_AXP202_CHG_ITERM_LESS_10_PERCENT); // Set charge cut-off voltage - PMU.setChargeTargetVoltage(XPOWERS_AXP202_CHG_VOL_4V2); + power.setChargeTargetVoltage(XPOWERS_AXP202_CHG_VOL_4V2); // Cache writes and reads, as long as the PMU remains powered, the data will always be stored inside the PMU Serial.println("Write pmu data buffer ."); uint8_t data[XPOWERS_AXP202_DATA_BUFFER_SIZE] = {1, 2, 3, 4, 5, 6}; - PMU.writeDataBuffer(data, XPOWERS_AXP202_DATA_BUFFER_SIZE); + power.writeDataBuffer(data, XPOWERS_AXP202_DATA_BUFFER_SIZE); memset(data, 0, XPOWERS_AXP202_DATA_BUFFER_SIZE); Serial.print("Read pmu data buffer :"); - PMU.readDataBuffer(data, XPOWERS_AXP202_DATA_BUFFER_SIZE); + power.readDataBuffer(data, XPOWERS_AXP202_DATA_BUFFER_SIZE); for (int i = 0; i < XPOWERS_AXP202_DATA_BUFFER_SIZE; ++i) { Serial.print(data[i]); Serial.print(","); @@ -230,21 +230,21 @@ void setup() Serial.println(); // Set the timing after one minute, the isWdtExpireIrq will be triggered in the loop interrupt function - PMU.setTimerout(1); + power.setTimerout(1); } void 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"); - Serial.print("getTemperature:"); Serial.print(PMU.getTemperature()); Serial.println("*C"); - - if (PMU.isBatteryConnect()) { - Serial.print("getBatteryPercent:"); Serial.print(PMU.getBatteryPercent()); Serial.println("%"); + Serial.print("isCharging:"); Serial.println(power.isCharging() ? "YES" : "NO"); + Serial.print("isDischarge:"); Serial.println(power.isDischarge() ? "YES" : "NO"); + Serial.print("isVbusIn:"); Serial.println(power.isVbusIn() ? "YES" : "NO"); + Serial.print("getBattVoltage:"); Serial.print(power.getBattVoltage()); Serial.println("mV"); + Serial.print("getVbusVoltage:"); Serial.print(power.getVbusVoltage()); Serial.println("mV"); + Serial.print("getSystemVoltage:"); Serial.print(power.getSystemVoltage()); Serial.println("mV"); + Serial.print("getTemperature:"); Serial.print(power.getTemperature()); Serial.println("*C"); + + if (power.isBatteryConnect()) { + Serial.print("getBatteryPercent:"); Serial.print(power.getBatteryPercent()); Serial.println("%"); } Serial.println(); @@ -255,15 +255,15 @@ void printPMU() void enterPmuSleep(void) { // Set sleep flag - PMU.enableSleep(); + power.enableSleep(); - PMU.disableDC2(); + power.disableDC2(); - PMU.disableLDO2(); - PMU.disableLDO3(); + power.disableLDO2(); + power.disableLDO3(); // Finally, turn off the power of the control chip - PMU.disableDC3(); + power.disableDC3(); } void loop() @@ -272,130 +272,130 @@ void loop() pmu_flag = false; - // Get PMU Interrupt Status Register - uint32_t status = PMU.getIrqStatus(); + // Get power Interrupt Status Register + uint32_t status = power.getIrqStatus(); Serial.print("STATUS => HEX:"); Serial.print(status, HEX); Serial.print(" BIN:"); Serial.println(status, BIN); - if (PMU.isAcinOverVoltageIrq()) { + if (power.isAcinOverVoltageIrq()) { Serial.println("isAcinOverVoltageIrq"); } - if (PMU.isAcinInserIrq()) { + if (power.isAcinInserIrq()) { Serial.println("isAcinInserIrq"); } - if (PMU.isAcinRemoveIrq()) { + if (power.isAcinRemoveIrq()) { Serial.println("isAcinRemoveIrq"); } - if (PMU.isVbusOverVoltageIrq()) { + if (power.isVbusOverVoltageIrq()) { Serial.println("isVbusOverVoltageIrq"); } - if (PMU.isVbusInsertIrq()) { + if (power.isVbusInsertIrq()) { Serial.println("isVbusInsertIrq"); } - if (PMU.isVbusRemoveIrq()) { + if (power.isVbusRemoveIrq()) { Serial.println("isVbusRemoveIrq"); } - if (PMU.isVbusLowVholdIrq()) { + if (power.isVbusLowVholdIrq()) { Serial.println("isVbusLowVholdIrq"); } - if (PMU.isBatInsertIrq()) { + if (power.isBatInsertIrq()) { Serial.println("isBatInsertIrq"); } - if (PMU.isBatRemoveIrq()) { + if (power.isBatRemoveIrq()) { Serial.println("isBatRemoveIrq"); } - if (PMU.isBattEnterActivateIrq()) { + if (power.isBattEnterActivateIrq()) { Serial.println("isBattEnterActivateIrq"); } - if (PMU.isBattExitActivateIrq()) { + if (power.isBattExitActivateIrq()) { Serial.println("isBattExitActivateIrq"); } - if (PMU.isBatChagerStartIrq()) { + if (power.isBatChagerStartIrq()) { Serial.println("isBatChagerStartIrq"); } - if (PMU.isBatChagerDoneIrq()) { + if (power.isBatChagerDoneIrq()) { Serial.println("isBatChagerDoneIrq"); } - if (PMU.isBattTempHighIrq()) { + if (power.isBattTempHighIrq()) { Serial.println("isBattTempHighIrq"); } - if (PMU.isBattTempLowIrq()) { + if (power.isBattTempLowIrq()) { Serial.println("isBattTempLowIrq"); } - if (PMU.isChipOverTemperatureIrq()) { + if (power.isChipOverTemperatureIrq()) { Serial.println("isChipOverTemperatureIrq"); } - if (PMU.isChargingCurrentLessIrq()) { + if (power.isChargingCurrentLessIrq()) { Serial.println("isChargingCurrentLessIrq"); } - if (PMU.isDC1VoltageLessIrq()) { + if (power.isDC1VoltageLessIrq()) { Serial.println("isDC1VoltageLessIrq"); } - if (PMU.isDC2VoltageLessIrq()) { + if (power.isDC2VoltageLessIrq()) { Serial.println("isDC2VoltageLessIrq"); } - if (PMU.isDC3VoltageLessIrq()) { + if (power.isDC3VoltageLessIrq()) { Serial.println("isDC3VoltageLessIrq"); } - if (PMU.isPekeyShortPressIrq()) { + if (power.isPekeyShortPressIrq()) { Serial.println("isPekeyShortPress"); // enterPmuSleep(); //CHG LED mode test - uint8_t m = PMU.getChargingLedMode(); + uint8_t m = power.getChargingLedMode(); Serial.print("getChargingLedMode:"); Serial.println(m++); m %= XPOWERS_CHG_LED_CTRL_CHG; Serial.printf("setChargingLedMode:%u", m); - PMU.setChargingLedMode(m); + power.setChargingLedMode(m); } - if (PMU.isPekeyLongPressIrq()) { + if (power.isPekeyLongPressIrq()) { Serial.println("isPekeyLongPress"); } - if (PMU.isNOEPowerOnIrq()) { + if (power.isNOEPowerOnIrq()) { Serial.println("isNOEPowerOnIrq"); } - if (PMU.isNOEPowerDownIrq()) { + if (power.isNOEPowerDownIrq()) { Serial.println("isNOEPowerDownIrq"); } - if (PMU.isVbusEffectiveIrq()) { + if (power.isVbusEffectiveIrq()) { Serial.println("isVbusEffectiveIrq"); } - if (PMU.isVbusInvalidIrq()) { + if (power.isVbusInvalidIrq()) { Serial.println("isVbusInvalidIrq"); } - if (PMU.isVbusSessionIrq()) { + if (power.isVbusSessionIrq()) { Serial.println("isVbusSessionIrq"); } - if (PMU.isVbusSessionEndIrq()) { + if (power.isVbusSessionEndIrq()) { Serial.println("isVbusSessionEndIrq"); } - if (PMU.isLowVoltageLevel2Irq()) { + if (power.isLowVoltageLevel2Irq()) { Serial.println("isLowVoltageLevel2Irq"); } - if (PMU.isWdtExpireIrq()) { + if (power.isWdtExpireIrq()) { Serial.println("isWdtExpire"); printPMU(); // Clear the timer state and continue to the next timer - PMU.clearTimerFlag(); + power.clearTimerFlag(); } - if (PMU.isGpio2EdgeTriggerIrq()) { + if (power.isGpio2EdgeTriggerIrq()) { Serial.println("isGpio2EdgeTriggerIrq"); } - if (PMU.isGpio1EdgeTriggerIrq()) { + if (power.isGpio1EdgeTriggerIrq()) { Serial.println("isGpio1EdgeTriggerIrq"); } - if (PMU.isGpio0EdgeTriggerIrq()) { + if (power.isGpio0EdgeTriggerIrq()) { Serial.println("isGpio0EdgeTriggerIrq"); } - // Clear PMU Interrupt Status Register - PMU.clearIrqStatus(); + // Clear power Interrupt Status Register + power.clearIrqStatus(); } delay(10); diff --git a/examples/AXP2101_ADC_Example/AXP2101_ADC_Example.ino b/examples/AXP2101_ADC_Example/AXP2101_ADC_Example.ino index 0ace684..348da1f 100644 --- a/examples/AXP2101_ADC_Example/AXP2101_ADC_Example.ino +++ b/examples/AXP2101_ADC_Example/AXP2101_ADC_Example.ino @@ -50,7 +50,7 @@ if there is any loss, please bear it by yourself #define CONFIG_PMU_IRQ 6 #endif -XPowersPMU PMU; +XPowersPMU power; const uint8_t i2c_sda = CONFIG_PMU_SDA; const uint8_t i2c_scl = CONFIG_PMU_SCL; @@ -66,29 +66,29 @@ void setFlag(void) void adcOn() { - PMU.enableTemperatureMeasure(); + power.enableTemperatureMeasure(); // Enable internal ADC detection - PMU.enableBattDetection(); - PMU.enableVbusVoltageMeasure(); - PMU.enableBattVoltageMeasure(); - PMU.enableSystemVoltageMeasure(); + power.enableBattDetection(); + power.enableVbusVoltageMeasure(); + power.enableBattVoltageMeasure(); + power.enableSystemVoltageMeasure(); } void adcOff() { - PMU.disableTemperatureMeasure(); + power.disableTemperatureMeasure(); // Enable internal ADC detection - PMU.disableBattDetection(); - PMU.disableVbusVoltageMeasure(); - PMU.disableBattVoltageMeasure(); - PMU.disableSystemVoltageMeasure(); + power.disableBattDetection(); + power.disableVbusVoltageMeasure(); + power.disableBattVoltageMeasure(); + power.disableSystemVoltageMeasure(); } void setup() { Serial.begin(115200); - bool result = PMU.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl); + bool result = power.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl); if (result == false) { Serial.println("PMU is not online..."); while (1)delay(50); @@ -98,11 +98,11 @@ void setup() pinMode(pmu_irq_pin, INPUT_PULLUP); attachInterrupt(pmu_irq_pin, setFlag, FALLING); - PMU.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); + power.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); // Clear all interrupt flags - PMU.clearIrqStatus(); + power.clearIrqStatus(); // Enable the required interrupt function - PMU.enableIRQ( + power.enableIRQ( XPOWERS_AXP2101_PKEY_SHORT_IRQ //POWER KEY ); @@ -114,7 +114,7 @@ void setup() - XPOWERS_CHG_LED_ON, - XPOWERS_CHG_LED_CTRL_CHG, * */ - PMU.setChargingLedMode(XPOWERS_CHG_LED_ON); + power.setChargingLedMode(XPOWERS_CHG_LED_ON); //Default turn on adc adcOn(); @@ -130,8 +130,8 @@ void loop() if (pmu_flag) { pmu_flag = false; // Get PMU Interrupt Status Register - uint32_t status = PMU.getIrqStatus(); - if (PMU.isPekeyShortPressIrq()) { + uint32_t status = power.getIrqStatus(); + if (power.isPekeyShortPressIrq()) { if (adc_switch) { adcOn(); Serial.println("Enable ADC\n\n\n"); } else { @@ -139,18 +139,18 @@ void loop() } adc_switch = !adc_switch; } - // Clear PMU Interrupt Status Register - PMU.clearIrqStatus(); + // Clear power Interrupt Status Register + power.clearIrqStatus(); } - Serial.print("PMU Temperature:"); Serial.print(PMU.getTemperature()); Serial.println("*C"); - Serial.print("isCharging:"); Serial.println(PMU.isCharging() ? "YES" : "NO"); - Serial.print("isDischarge:"); Serial.println(PMU.isDischarge() ? "YES" : "NO"); - Serial.print("isStandby:"); Serial.println(PMU.isStandby() ? "YES" : "NO"); - Serial.print("isVbusIn:"); Serial.println(PMU.isVbusIn() ? "YES" : "NO"); - Serial.print("isVbusGood:"); Serial.println(PMU.isVbusGood() ? "YES" : "NO"); + Serial.print("power Temperature:"); Serial.print(power.getTemperature()); Serial.println("*C"); + Serial.print("isCharging:"); Serial.println(power.isCharging() ? "YES" : "NO"); + Serial.print("isDischarge:"); Serial.println(power.isDischarge() ? "YES" : "NO"); + Serial.print("isStandby:"); Serial.println(power.isStandby() ? "YES" : "NO"); + Serial.print("isVbusIn:"); Serial.println(power.isVbusIn() ? "YES" : "NO"); + Serial.print("isVbusGood:"); Serial.println(power.isVbusGood() ? "YES" : "NO"); Serial.print("getChargerStatus:"); - uint8_t charge_status = PMU.getChargerStatus(); + uint8_t charge_status = power.getChargerStatus(); if (charge_status == XPOWERS_AXP2101_CHG_TRI_STATE) { Serial.println("tri_charge"); } else if (charge_status == XPOWERS_AXP2101_CHG_PRE_STATE) { @@ -166,15 +166,15 @@ void loop() } // After the ADC detection is turned off, the register will return to the last reading. The PMU will not refresh the data register - 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"); + Serial.print("getBattVoltage:"); Serial.print(power.getBattVoltage()); Serial.println("mV"); + Serial.print("getVbusVoltage:"); Serial.print(power.getVbusVoltage()); Serial.println("mV"); + Serial.print("getSystemVoltage:"); Serial.print(power.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("%"); + if (power.isBatteryConnect()) { + Serial.print("getBatteryPercent:"); Serial.print(power.getBatteryPercent()); Serial.println("%"); } // Serial.println(); diff --git a/examples/AXP2101_Charge_Current_Setting/AXP2101_Charge_Current_Setting.ino b/examples/AXP2101_Charge_Current_Setting/AXP2101_Charge_Current_Setting.ino index dd54d17..0dfb783 100644 --- a/examples/AXP2101_Charge_Current_Setting/AXP2101_Charge_Current_Setting.ino +++ b/examples/AXP2101_Charge_Current_Setting/AXP2101_Charge_Current_Setting.ino @@ -50,7 +50,7 @@ if there is any loss, please bear it by yourself #define CONFIG_PMU_IRQ 35 #endif -XPowersPMU PMU; +XPowersPMU power; bool pmu_flag = false; uint8_t curIndex = 4; @@ -66,7 +66,7 @@ void printChargerConstantCurr() const uint16_t currTable[] = { 0, 0, 0, 0, 100, 125, 150, 175, 200, 300, 400, 500, 600, 700, 800, 900, 1000 }; - uint8_t val = PMU.getChargerConstantCurr(); + uint8_t val = power.getChargerConstantCurr(); Serial.printf("Setting Charge Target Current - VAL:%u CURRENT:%u\n", val, currTable[val]); } @@ -82,7 +82,7 @@ void setup() Serial.println(); - bool res = PMU.begin(Wire, AXP2101_SLAVE_ADDRESS, CONFIG_PMU_SDA, CONFIG_PMU_SCL); + bool res = power.begin(Wire, AXP2101_SLAVE_ADDRESS, CONFIG_PMU_SDA, CONFIG_PMU_SCL); if (!res) { Serial.println("Failed to initialize power....."); while (1) { @@ -90,39 +90,39 @@ void setup() } } - // Set PMU interrupt + // Set power interrupt pinMode(CONFIG_PMU_IRQ, INPUT); attachInterrupt(CONFIG_PMU_IRQ, setFlag, FALLING); // Disable all interrupts - PMU.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); + power.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); // Enable the required interrupt function - PMU.enableIRQ( + power.enableIRQ( XPOWERS_AXP2101_BAT_INSERT_IRQ | XPOWERS_AXP2101_BAT_REMOVE_IRQ | //BATTERY XPOWERS_AXP2101_VBUS_INSERT_IRQ | XPOWERS_AXP2101_VBUS_REMOVE_IRQ | //VBUS XPOWERS_AXP2101_PKEY_SHORT_IRQ | XPOWERS_AXP2101_PKEY_LONG_IRQ | //POWER KEY XPOWERS_AXP2101_BAT_CHG_DONE_IRQ | XPOWERS_AXP2101_BAT_CHG_START_IRQ //CHARGE ); // Clear all interrupt flags - PMU.clearIrqStatus(); + power.clearIrqStatus(); // Set the minimum common working voltage of the PMU VBUS input, - // below this value will turn off the PMU - PMU.setVbusVoltageLimit(XPOWERS_AXP2101_VBUS_VOL_LIM_4V36); + // below this value will turn off the power + power.setVbusVoltageLimit(XPOWERS_AXP2101_VBUS_VOL_LIM_4V36); // Set the maximum current of the PMU VBUS input, // higher than this value will turn off the PMU - PMU.setVbusCurrentLimit(XPOWERS_AXP2101_VBUS_CUR_LIM_1500MA); + power.setVbusCurrentLimit(XPOWERS_AXP2101_VBUS_CUR_LIM_1500MA); // Set VSY off voltage as 2600mV , Adjustment range 2600mV ~ 3300mV - PMU.setSysPowerDownVoltage(2600); + power.setSysPowerDownVoltage(2600); // Set the precharge charging current - PMU.setPrechargeCurr(XPOWERS_AXP2101_PRECHARGE_50MA); + power.setPrechargeCurr(XPOWERS_AXP2101_PRECHARGE_50MA); // Set constant current charge current limit - PMU.setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_200MA); + power.setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_200MA); // Set stop charging termination current - PMU.setChargerTerminationCurr(XPOWERS_AXP2101_CHG_ITERM_25MA); + power.setChargerTerminationCurr(XPOWERS_AXP2101_CHG_ITERM_25MA); // Set charge cut-off voltage - PMU.setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V1); + power.setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V1); /* The default setting is CHGLED is automatically controlled by the PMU. @@ -132,11 +132,11 @@ void setup() - XPOWERS_CHG_LED_ON, - XPOWERS_CHG_LED_CTRL_CHG, * */ - PMU.setChargingLedMode(XPOWERS_CHG_LED_OFF); + power.setChargingLedMode(XPOWERS_CHG_LED_OFF); // Set cell battery voltage to 3.3V - PMU.setButtonBatteryChargeVoltage(3300); + power.setButtonBatteryChargeVoltage(3300); // Enable cell battery charge function - PMU.enableButtonBatteryCharge(); + power.enableButtonBatteryCharge(); // Print default setting current printChargerConstantCurr(); } @@ -146,12 +146,12 @@ void loop() if (pmu_flag) { pmu_flag = false; // Get PMU Interrupt Status Register - uint32_t status = PMU.getIrqStatus(); - if (PMU.isPekeyShortPressIrq()) { + uint32_t status = power.getIrqStatus(); + if (power.isPekeyShortPressIrq()) { // Set constant current charge current limit // For setting a current greater than 500mA, the VBUS power supply must be sufficient. If the input is lower than 5V, the charging current will be below 500mA. - if (!PMU.setChargerConstantCurr(curIndex)) { + if (!power.setChargerConstantCurr(curIndex)) { Serial.println("Setting Charger Constant Current Failed!"); } printChargerConstantCurr(); @@ -163,10 +163,10 @@ void loop() } // Toggle CHG led - PMU.setChargingLedMode(PMU.getChargingLedMode() != XPOWERS_CHG_LED_OFF ? XPOWERS_CHG_LED_OFF : XPOWERS_CHG_LED_ON); + power.setChargingLedMode(power.getChargingLedMode() != XPOWERS_CHG_LED_OFF ? XPOWERS_CHG_LED_OFF : XPOWERS_CHG_LED_ON); } // Clear PMU Interrupt Status Register - PMU.clearIrqStatus(); + power.clearIrqStatus(); } delay(200); diff --git a/examples/AXP2101_Charge_Example/AXP2101_Charge_Example.ino b/examples/AXP2101_Charge_Example/AXP2101_Charge_Example.ino index 79b65c5..3d4c5aa 100644 --- a/examples/AXP2101_Charge_Example/AXP2101_Charge_Example.ino +++ b/examples/AXP2101_Charge_Example/AXP2101_Charge_Example.ino @@ -51,7 +51,7 @@ if there is any loss, please bear it by yourself #endif bool pmu_flag = 0; -XPowersPMU PMU; +XPowersPMU power; const uint8_t i2c_sda = CONFIG_PMU_SDA; const uint8_t i2c_scl = CONFIG_PMU_SCL; @@ -67,41 +67,41 @@ void setup() { Serial.begin(115200); - bool result = PMU.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl); + bool result = power.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl); if (result == false) { - Serial.println("PMU is not online..."); while (1)delay(50); + Serial.println("power is not online..."); while (1)delay(50); } - Serial.printf("getID:0x%x\n", PMU.getChipID()); + Serial.printf("getID:0x%x\n", power.getChipID()); // Set the minimum common working voltage of the PMU VBUS input, // below this value will turn off the PMU - PMU.setVbusVoltageLimit(XPOWERS_AXP2101_VBUS_VOL_LIM_4V36); + power.setVbusVoltageLimit(XPOWERS_AXP2101_VBUS_VOL_LIM_4V36); // Set the maximum current of the PMU VBUS input, // higher than this value will turn off the PMU - PMU.setVbusCurrentLimit(XPOWERS_AXP2101_VBUS_CUR_LIM_1500MA); + power.setVbusCurrentLimit(XPOWERS_AXP2101_VBUS_CUR_LIM_1500MA); // Get the VSYS shutdown voltage - uint16_t vol = PMU.getSysPowerDownVoltage(); + uint16_t vol = power.getSysPowerDownVoltage(); Serial.printf("-> getSysPowerDownVoltage:%u\n", vol); // Set VSY off voltage as 2600mV , Adjustment range 2600mV ~ 3300mV - PMU.setSysPowerDownVoltage(2600); + power.setSysPowerDownVoltage(2600); // It is necessary to disable the detection function of the TS pin on the board // without the battery temperature detection function, otherwise it will cause abnormal charging - PMU.disableTSPinMeasure(); + power.disableTSPinMeasure(); - // PMU.enableTemperatureMeasure(); + // power.enableTemperatureMeasure(); // Enable internal ADC detection - PMU.enableBattDetection(); - PMU.enableVbusVoltageMeasure(); - PMU.enableBattVoltageMeasure(); - PMU.enableSystemVoltageMeasure(); + power.enableBattDetection(); + power.enableVbusVoltageMeasure(); + power.enableBattVoltageMeasure(); + power.enableSystemVoltageMeasure(); /* The default setting is CHGLED is automatically controlled by the PMU. @@ -111,7 +111,7 @@ void setup() - XPOWERS_CHG_LED_ON, - XPOWERS_CHG_LED_CTRL_CHG, * */ - PMU.setChargingLedMode(XPOWERS_CHG_LED_CTRL_CHG); + power.setChargingLedMode(XPOWERS_CHG_LED_CTRL_CHG); // Force add pull-up @@ -120,11 +120,11 @@ void setup() // Disable all interrupts - PMU.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); + power.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); // Clear all interrupt flags - PMU.clearIrqStatus(); + power.clearIrqStatus(); // Enable the required interrupt function - PMU.enableIRQ( + power.enableIRQ( XPOWERS_AXP2101_BAT_INSERT_IRQ | XPOWERS_AXP2101_BAT_REMOVE_IRQ | //BATTERY XPOWERS_AXP2101_VBUS_INSERT_IRQ | XPOWERS_AXP2101_VBUS_REMOVE_IRQ | //VBUS XPOWERS_AXP2101_PKEY_SHORT_IRQ | XPOWERS_AXP2101_PKEY_LONG_IRQ | //POWER KEY @@ -134,47 +134,47 @@ void setup() ); // Set the precharge charging current - PMU.setPrechargeCurr(XPOWERS_AXP2101_PRECHARGE_200MA); + power.setPrechargeCurr(XPOWERS_AXP2101_PRECHARGE_200MA); // Set stop charging termination current - PMU.setChargerTerminationCurr(XPOWERS_AXP2101_CHG_ITERM_25MA); + power.setChargerTerminationCurr(XPOWERS_AXP2101_CHG_ITERM_25MA); // Set constant current charge current limit - if (!PMU.setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_1000MA)) { + if (!power.setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_1000MA)) { Serial.println("Setting Charger Constant Current Failed!"); } const uint16_t currTable[] = { 0, 0, 0, 0, 100, 125, 150, 175, 200, 300, 400, 500, 600, 700, 800, 900, 1000 }; - uint8_t val = PMU.getChargerConstantCurr(); + uint8_t val = power.getChargerConstantCurr(); Serial.print("Setting Charge Target Current : "); Serial.println(currTable[val]); // Set charge cut-off voltage - PMU.setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V2); + power.setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V2); const uint16_t tableVoltage[] = { 0, 4000, 4100, 4200, 4350, 4400, 255 }; - val = PMU.getChargeTargetVoltage(); + val = power.getChargeTargetVoltage(); Serial.print("Setting Charge Target Voltage : "); Serial.println(tableVoltage[val]); // Set the power level to be lower than 15% and send an interrupt to the host` - PMU.setLowBatWarnThreshold(10); + power.setLowBatWarnThreshold(10); // Set the power level to be lower than 5% and turn off the power supply - PMU.setLowBatShutdownThreshold(5); + power.setLowBatShutdownThreshold(5); /* Turn on the learning battery curve, And write the learned battery curve into the ROM */ - PMU.fuelGaugeControl(true, true); + power.fuelGaugeControl(true, true); Serial.println(); @@ -187,24 +187,24 @@ void printPMU() Serial.println("Satus1 Satus2 CHARG DISC STBY VBUSIN VGOOD VBAT VBUS VSYS Percentage CHG_STATUS"); Serial.println("(Bin) (Bin) (bool) (bool) (bool) (bool) (bool) (mV) (mV) (mV) (%) (str) "); Serial.println("---------------------------------------------------------------------------------------------------------"); - uint16_t statusVal = PMU.status(); + uint16_t statusVal = power.status(); Serial.print("0b"); Serial.print(statusVal >> 8, BIN); Serial.print("\t"); Serial.print("0b"); Serial.print(statusVal & 0xFF, BIN); Serial.print("\t"); - Serial.print(PMU.isCharging() ? "YES" : "NO "); Serial.print("\t"); - Serial.print(PMU.isDischarge() ? "YES" : "NO "); Serial.print("\t"); - Serial.print(PMU.isStandby() ? "YES" : "NO "); Serial.print("\t"); - Serial.print(PMU.isVbusIn() ? "YES" : "NO "); Serial.print("\t"); - Serial.print(PMU.isVbusGood() ? "YES" : "NO "); Serial.print("\t"); - Serial.print(PMU.getBattVoltage()); Serial.print("\t"); - Serial.print(PMU.getVbusVoltage()); Serial.print("\t"); - Serial.print(PMU.getSystemVoltage()); Serial.print("\t"); + Serial.print(power.isCharging() ? "YES" : "NO "); Serial.print("\t"); + Serial.print(power.isDischarge() ? "YES" : "NO "); Serial.print("\t"); + Serial.print(power.isStandby() ? "YES" : "NO "); Serial.print("\t"); + Serial.print(power.isVbusIn() ? "YES" : "NO "); Serial.print("\t"); + Serial.print(power.isVbusGood() ? "YES" : "NO "); Serial.print("\t"); + Serial.print(power.getBattVoltage()); Serial.print("\t"); + Serial.print(power.getVbusVoltage()); Serial.print("\t"); + Serial.print(power.getSystemVoltage()); Serial.print("\t"); // 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 - Serial.print(PMU.getBatteryPercent()); Serial.print("\t"); + Serial.print(power.getBatteryPercent()); Serial.print("\t"); - uint8_t charge_status = PMU.getChargerStatus(); + uint8_t charge_status = power.getChargerStatus(); if (charge_status == XPOWERS_AXP2101_CHG_TRI_STATE) { Serial.println("tri_charge"); } else if (charge_status == XPOWERS_AXP2101_CHG_PRE_STATE) { @@ -237,88 +237,88 @@ void loop() pmu_flag = false; // Get PMU Interrupt Status Register - uint32_t status = PMU.getIrqStatus(); + uint32_t status = power.getIrqStatus(); Serial.print("STATUS => HEX:"); Serial.print(status, HEX); Serial.print(" BIN:"); Serial.println(status, BIN); - if (PMU.isDropWarningLevel2Irq()) { + if (power.isDropWarningLevel2Irq()) { Serial.println("isDropWarningLevel2"); } - if (PMU.isDropWarningLevel1Irq()) { + if (power.isDropWarningLevel1Irq()) { Serial.println(" >>>> isDropWarningLevel1 <<<<"); - PMU.shutdown(); + power.shutdown(); } - if (PMU.isGaugeWdtTimeoutIrq()) { + if (power.isGaugeWdtTimeoutIrq()) { Serial.println("isWdtTimeout"); } - if (PMU.isBatChargerOverTemperatureIrq()) { + if (power.isBatChargerOverTemperatureIrq()) { Serial.println("isBatChargeOverTemperature"); } - if (PMU.isBatWorkOverTemperatureIrq()) { + if (power.isBatWorkOverTemperatureIrq()) { Serial.println("isBatWorkOverTemperature"); } - if (PMU.isBatWorkUnderTemperatureIrq()) { + if (power.isBatWorkUnderTemperatureIrq()) { Serial.println("isBatWorkUnderTemperature"); } - if (PMU.isVbusInsertIrq()) { + if (power.isVbusInsertIrq()) { Serial.println("isVbusInsert"); - uint8_t val = PMU.getVbusCurrentLimit(); + uint8_t val = power.getVbusCurrentLimit(); Serial.print("Get Vbus Current Limit = "); Serial.println(val); } - if (PMU.isVbusRemoveIrq()) { + if (power.isVbusRemoveIrq()) { Serial.println("isVbusRemove"); - uint8_t val = PMU.getVbusCurrentLimit(); + uint8_t val = power.getVbusCurrentLimit(); Serial.print("Get Vbus Current Limit = "); Serial.println(val); } - if (PMU.isBatInsertIrq()) { + if (power.isBatInsertIrq()) { Serial.println("isBatInsert"); } - if (PMU.isBatRemoveIrq()) { + if (power.isBatRemoveIrq()) { Serial.println("isBatRemove"); } - if (PMU.isPekeyShortPressIrq()) { + if (power.isPekeyShortPressIrq()) { Serial.println("isPekeyShortPress"); } - if (PMU.isPekeyLongPressIrq()) { + if (power.isPekeyLongPressIrq()) { Serial.println("isPekeyLongPress"); } - if (PMU.isPekeyNegativeIrq()) { + if (power.isPekeyNegativeIrq()) { Serial.println("isPekeyNegative"); } - if (PMU.isPekeyPositiveIrq()) { + if (power.isPekeyPositiveIrq()) { Serial.println("isPekeyPositive"); } - if (PMU.isWdtExpireIrq()) { + if (power.isWdtExpireIrq()) { Serial.println("isWdtExpire"); } - if (PMU.isLdoOverCurrentIrq()) { + if (power.isLdoOverCurrentIrq()) { Serial.println("isLdoOverCurrentIrq"); } - if (PMU.isBatfetOverCurrentIrq()) { + if (power.isBatfetOverCurrentIrq()) { Serial.println("isBatfetOverCurrentIrq"); } - if (PMU.isBatChagerDoneIrq()) { + if (power.isBatChagerDoneIrq()) { Serial.println("isBatChagerDone"); } - if (PMU.isBatChagerStartIrq()) { + if (power.isBatChagerStartIrq()) { Serial.println("isBatChagerStart"); } - if (PMU.isBatDieOverTemperatureIrq()) { + if (power.isBatDieOverTemperatureIrq()) { Serial.println("isBatDieOverTemperature"); } - if (PMU.isChagerOverTimeoutIrq()) { + if (power.isChagerOverTimeoutIrq()) { Serial.println("isChagerOverTimeout"); } - if (PMU.isBatOverVoltageIrq()) { + if (power.isBatOverVoltageIrq()) { Serial.println("isBatOverVoltage"); } // Clear PMU Interrupt Status Register - PMU.clearIrqStatus(); + power.clearIrqStatus(); } delay(10); diff --git a/examples/AXP2101_Example/AXP2101_Example.ino b/examples/AXP2101_Example/AXP2101_Example.ino index 61c0d40..cb29fb2 100644 --- a/examples/AXP2101_Example/AXP2101_Example.ino +++ b/examples/AXP2101_Example/AXP2101_Example.ino @@ -51,7 +51,7 @@ if there is any loss, please bear it by yourself #endif bool pmu_flag = 0; -XPowersPMU PMU; +XPowersPMU power; const uint8_t i2c_sda = CONFIG_PMU_SDA; const uint8_t i2c_scl = CONFIG_PMU_SCL; @@ -67,141 +67,141 @@ void setup() { Serial.begin(115200); - bool result = PMU.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl); + bool result = power.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl); if (result == false) { - Serial.println("PMU is not online..."); while (1)delay(50); + Serial.println("power is not online..."); while (1)delay(50); } - Serial.printf("getID:0x%x\n", PMU.getChipID()); + Serial.printf("getID:0x%x\n", power.getChipID()); // Set the minimum common working voltage of the PMU VBUS input, // below this value will turn off the PMU - PMU.setVbusVoltageLimit(XPOWERS_AXP2101_VBUS_VOL_LIM_4V36); + power.setVbusVoltageLimit(XPOWERS_AXP2101_VBUS_VOL_LIM_4V36); // Set the maximum current of the PMU VBUS input, // higher than this value will turn off the PMU - PMU.setVbusCurrentLimit(XPOWERS_AXP2101_VBUS_CUR_LIM_1500MA); + power.setVbusCurrentLimit(XPOWERS_AXP2101_VBUS_CUR_LIM_1500MA); // Get the VSYS shutdown voltage - uint16_t vol = PMU.getSysPowerDownVoltage(); + uint16_t vol = power.getSysPowerDownVoltage(); Serial.printf("-> getSysPowerDownVoltage:%u\n", vol); // Set VSY off voltage as 2600mV , Adjustment range 2600mV ~ 3300mV - PMU.setSysPowerDownVoltage(2600); + power.setSysPowerDownVoltage(2600); - vol = PMU.getSysPowerDownVoltage(); + vol = power.getSysPowerDownVoltage(); Serial.printf("-> getSysPowerDownVoltage:%u\n", vol); // DC1 IMAX=2A // 1500~3400mV,100mV/step,20steps - PMU.setDC1Voltage(3300); - Serial.printf("DC1 : %s Voltage:%u mV \n", PMU.isEnableDC1() ? "+" : "-", PMU.getDC1Voltage()); + power.setDC1Voltage(3300); + Serial.printf("DC1 : %s Voltage:%u mV \n", power.isEnableDC1() ? "+" : "-", power.getDC1Voltage()); // DC2 IMAX=2A // 500~1200mV 10mV/step,71steps // 1220~1540mV 20mV/step,17steps - PMU.setDC2Voltage(1000); - Serial.printf("DC2 : %s Voltage:%u mV \n", PMU.isEnableDC2() ? "+" : "-", PMU.getDC2Voltage()); + power.setDC2Voltage(1000); + Serial.printf("DC2 : %s Voltage:%u mV \n", power.isEnableDC2() ? "+" : "-", power.getDC2Voltage()); // DC3 IMAX = 2A // 500~1200mV,10mV/step,71steps // 1220~1540mV,20mV/step,17steps // 1600~3400mV,100mV/step,19steps - PMU.setDC3Voltage(3300); - Serial.printf("DC3 : %s Voltage:%u mV \n", PMU.isEnableDC3() ? "+" : "-", PMU.getDC3Voltage()); + power.setDC3Voltage(3300); + Serial.printf("DC3 : %s Voltage:%u mV \n", power.isEnableDC3() ? "+" : "-", power.getDC3Voltage()); // DCDC4 IMAX=1.5A // 500~1200mV,10mV/step,71steps // 1220~1840mV,20mV/step,32steps - PMU.setDC4Voltage(1000); - Serial.printf("DC4 : %s Voltage:%u mV \n", PMU.isEnableDC4() ? "+" : "-", PMU.getDC4Voltage()); + power.setDC4Voltage(1000); + Serial.printf("DC4 : %s Voltage:%u mV \n", power.isEnableDC4() ? "+" : "-", power.getDC4Voltage()); // DC5 IMAX=2A // 1200mV // 1400~3700mV,100mV/step,24steps - PMU.setDC5Voltage(3300); - Serial.printf("DC5 : %s Voltage:%u mV \n", PMU.isEnableDC5() ? "+" : "-", PMU.getDC5Voltage()); + power.setDC5Voltage(3300); + Serial.printf("DC5 : %s Voltage:%u mV \n", power.isEnableDC5() ? "+" : "-", power.getDC5Voltage()); //ALDO1 IMAX=300mA //500~3500mV, 100mV/step,31steps - PMU.setALDO1Voltage(3300); + power.setALDO1Voltage(3300); //ALDO2 IMAX=300mA //500~3500mV, 100mV/step,31steps - PMU.setALDO2Voltage(3300); + power.setALDO2Voltage(3300); //ALDO3 IMAX=300mA //500~3500mV, 100mV/step,31steps - PMU.setALDO3Voltage(3300); + power.setALDO3Voltage(3300); //ALDO4 IMAX=300mA //500~3500mV, 100mV/step,31steps - PMU.setALDO4Voltage(3300); + power.setALDO4Voltage(3300); //BLDO1 IMAX=300mA //500~3500mV, 100mV/step,31steps - PMU.setBLDO1Voltage(3300); + power.setBLDO1Voltage(3300); //BLDO2 IMAX=300mA //500~3500mV, 100mV/step,31steps - PMU.setBLDO2Voltage(3300); + power.setBLDO2Voltage(3300); //CPUSLDO IMAX=30mA //500~1400mV,50mV/step,19steps - PMU.setCPUSLDOVoltage(1000); + power.setCPUSLDOVoltage(1000); //DLDO1 IMAX=300mA //500~3400mV, 100mV/step,29steps - PMU.setDLDO1Voltage(3300); + power.setDLDO1Voltage(3300); //DLDO2 IMAX=300mA //500~1400mV, 50mV/step,2steps - PMU.setDLDO2Voltage(3300); + power.setDLDO2Voltage(3300); - // PMU.enableDC1(); - PMU.enableDC2(); - PMU.enableDC3(); - PMU.enableDC4(); - PMU.enableDC5(); - PMU.enableALDO1(); - PMU.enableALDO2(); - PMU.enableALDO3(); - PMU.enableALDO4(); - PMU.enableBLDO1(); - PMU.enableBLDO2(); - PMU.enableCPUSLDO(); - PMU.enableDLDO1(); - PMU.enableDLDO2(); + // power.enableDC1(); + power.enableDC2(); + power.enableDC3(); + power.enableDC4(); + power.enableDC5(); + power.enableALDO1(); + power.enableALDO2(); + power.enableALDO3(); + power.enableALDO4(); + power.enableBLDO1(); + power.enableBLDO2(); + power.enableCPUSLDO(); + power.enableDLDO1(); + power.enableDLDO2(); Serial.println("DCDC======================================================================="); - Serial.printf("DC1 : %s Voltage:%u mV \n", PMU.isEnableDC1() ? "+" : "-", PMU.getDC1Voltage()); - Serial.printf("DC2 : %s Voltage:%u mV \n", PMU.isEnableDC2() ? "+" : "-", PMU.getDC2Voltage()); - Serial.printf("DC3 : %s Voltage:%u mV \n", PMU.isEnableDC3() ? "+" : "-", PMU.getDC3Voltage()); - Serial.printf("DC4 : %s Voltage:%u mV \n", PMU.isEnableDC4() ? "+" : "-", PMU.getDC4Voltage()); - Serial.printf("DC5 : %s Voltage:%u mV \n", PMU.isEnableDC5() ? "+" : "-", PMU.getDC5Voltage()); + Serial.printf("DC1 : %s Voltage:%u mV \n", power.isEnableDC1() ? "+" : "-", power.getDC1Voltage()); + Serial.printf("DC2 : %s Voltage:%u mV \n", power.isEnableDC2() ? "+" : "-", power.getDC2Voltage()); + Serial.printf("DC3 : %s Voltage:%u mV \n", power.isEnableDC3() ? "+" : "-", power.getDC3Voltage()); + Serial.printf("DC4 : %s Voltage:%u mV \n", power.isEnableDC4() ? "+" : "-", power.getDC4Voltage()); + Serial.printf("DC5 : %s Voltage:%u mV \n", power.isEnableDC5() ? "+" : "-", power.getDC5Voltage()); Serial.println("ALDO======================================================================="); - Serial.printf("ALDO1: %s Voltage:%u mV\n", PMU.isEnableALDO1() ? "+" : "-", PMU.getALDO1Voltage()); - Serial.printf("ALDO2: %s Voltage:%u mV\n", PMU.isEnableALDO2() ? "+" : "-", PMU.getALDO2Voltage()); - Serial.printf("ALDO3: %s Voltage:%u mV\n", PMU.isEnableALDO3() ? "+" : "-", PMU.getALDO3Voltage()); - Serial.printf("ALDO4: %s Voltage:%u mV\n", PMU.isEnableALDO4() ? "+" : "-", PMU.getALDO4Voltage()); + Serial.printf("ALDO1: %s Voltage:%u mV\n", power.isEnableALDO1() ? "+" : "-", power.getALDO1Voltage()); + Serial.printf("ALDO2: %s Voltage:%u mV\n", power.isEnableALDO2() ? "+" : "-", power.getALDO2Voltage()); + Serial.printf("ALDO3: %s Voltage:%u mV\n", power.isEnableALDO3() ? "+" : "-", power.getALDO3Voltage()); + Serial.printf("ALDO4: %s Voltage:%u mV\n", power.isEnableALDO4() ? "+" : "-", power.getALDO4Voltage()); Serial.println("BLDO======================================================================="); - Serial.printf("BLDO1: %s Voltage:%u mV\n", PMU.isEnableBLDO1() ? "+" : "-", PMU.getBLDO1Voltage()); - Serial.printf("BLDO2: %s Voltage:%u mV\n", PMU.isEnableBLDO2() ? "+" : "-", PMU.getBLDO2Voltage()); + Serial.printf("BLDO1: %s Voltage:%u mV\n", power.isEnableBLDO1() ? "+" : "-", power.getBLDO1Voltage()); + Serial.printf("BLDO2: %s Voltage:%u mV\n", power.isEnableBLDO2() ? "+" : "-", power.getBLDO2Voltage()); Serial.println("CPUSLDO===================================================================="); - Serial.printf("CPUSLDO: %s Voltage:%u mV\n", PMU.isEnableCPUSLDO() ? "+" : "-", PMU.getCPUSLDOVoltage()); + Serial.printf("CPUSLDO: %s Voltage:%u mV\n", power.isEnableCPUSLDO() ? "+" : "-", power.getCPUSLDOVoltage()); Serial.println("DLDO======================================================================="); - Serial.printf("DLDO1: %s Voltage:%u mV\n", PMU.isEnableDLDO1() ? "+" : "-", PMU.getDLDO1Voltage()); - Serial.printf("DLDO2: %s Voltage:%u mV\n", PMU.isEnableDLDO2() ? "+" : "-", PMU.getDLDO2Voltage()); + Serial.printf("DLDO1: %s Voltage:%u mV\n", power.isEnableDLDO1() ? "+" : "-", power.getDLDO1Voltage()); + Serial.printf("DLDO2: %s Voltage:%u mV\n", power.isEnableDLDO2() ? "+" : "-", power.getDLDO2Voltage()); Serial.println("==========================================================================="); // Set the time of pressing the button to turn off - PMU.setPowerKeyPressOffTime(XPOWERS_POWEROFF_4S); - uint8_t opt = PMU.getPowerKeyPressOffTime(); + power.setPowerKeyPressOffTime(XPOWERS_POWEROFF_4S); + uint8_t opt = power.getPowerKeyPressOffTime(); Serial.print("PowerKeyPressOffTime:"); switch (opt) { case XPOWERS_POWEROFF_4S: Serial.println("4 Second"); @@ -216,8 +216,8 @@ void setup() break; } // Set the button power-on press time - PMU.setPowerKeyPressOnTime(XPOWERS_POWERON_128MS); - opt = PMU.getPowerKeyPressOnTime(); + power.setPowerKeyPressOnTime(XPOWERS_POWERON_128MS); + opt = power.getPowerKeyPressOnTime(); Serial.print("PowerKeyPressOnTime:"); switch (opt) { case XPOWERS_POWERON_128MS: Serial.println("128 Ms"); @@ -237,48 +237,48 @@ void setup() bool en; // DCDC 120%(130%) high voltage turn off PMIC function - en = PMU.getDCHighVoltagePowerDowmEn(); + en = power.getDCHighVoltagePowerDowmEn(); Serial.print("getDCHighVoltagePowerDowmEn:"); Serial.println(en ? "ENABLE" : "DISABLE"); // DCDC1 85% low voltage turn off PMIC function - en = PMU.getDC1LowVoltagePowerDowmEn(); + en = power.getDC1LowVoltagePowerDowmEn(); Serial.print("getDC1LowVoltagePowerDowmEn:"); Serial.println(en ? "ENABLE" : "DISABLE"); // DCDC2 85% low voltage turn off PMIC function - en = PMU.getDC2LowVoltagePowerDowmEn(); + en = power.getDC2LowVoltagePowerDowmEn(); Serial.print("getDC2LowVoltagePowerDowmEn:"); Serial.println(en ? "ENABLE" : "DISABLE"); // DCDC3 85% low voltage turn off PMIC function - en = PMU.getDC3LowVoltagePowerDowmEn(); + en = power.getDC3LowVoltagePowerDowmEn(); Serial.print("getDC3LowVoltagePowerDowmEn:"); Serial.println(en ? "ENABLE" : "DISABLE"); // DCDC4 85% low voltage turn off PMIC function - en = PMU.getDC4LowVoltagePowerDowmEn(); + en = power.getDC4LowVoltagePowerDowmEn(); Serial.print("getDC4LowVoltagePowerDowmEn:"); Serial.println(en ? "ENABLE" : "DISABLE"); // DCDC5 85% low voltage turn off PMIC function - en = PMU.getDC5LowVoltagePowerDowmEn(); + en = power.getDC5LowVoltagePowerDowmEn(); Serial.print("getDC5LowVoltagePowerDowmEn:"); Serial.println(en ? "ENABLE" : "DISABLE"); - // PMU.setDCHighVoltagePowerDowm(true); - // PMU.setDC1LowVoltagePowerDowm(true); - // PMU.setDC2LowVoltagePowerDowm(true); - // PMU.setDC3LowVoltagePowerDowm(true); - // PMU.setDC4LowVoltagePowerDowm(true); - // PMU.setDC5LowVoltagePowerDowm(true); + // power.setDCHighVoltagePowerDowm(true); + // power.setDC1LowVoltagePowerDowm(true); + // power.setDC2LowVoltagePowerDowm(true); + // power.setDC3LowVoltagePowerDowm(true); + // power.setDC4LowVoltagePowerDowm(true); + // power.setDC5LowVoltagePowerDowm(true); // It is necessary to disable the detection function of the TS pin on the board // without the battery temperature detection function, otherwise it will cause abnormal charging - PMU.disableTSPinMeasure(); + power.disableTSPinMeasure(); - // PMU.enableTemperatureMeasure(); + // power.enableTemperatureMeasure(); // Enable internal ADC detection - PMU.enableBattDetection(); - PMU.enableVbusVoltageMeasure(); - PMU.enableBattVoltageMeasure(); - PMU.enableSystemVoltageMeasure(); + power.enableBattDetection(); + power.enableVbusVoltageMeasure(); + power.enableBattVoltageMeasure(); + power.enableSystemVoltageMeasure(); /* @@ -289,7 +289,7 @@ void setup() - XPOWERS_CHG_LED_ON, - XPOWERS_CHG_LED_CTRL_CHG, * */ - PMU.setChargingLedMode(XPOWERS_CHG_LED_OFF); + power.setChargingLedMode(XPOWERS_CHG_LED_OFF); // Force add pull-up @@ -298,11 +298,11 @@ void setup() // Disable all interrupts - PMU.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); + power.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); // Clear all interrupt flags - PMU.clearIrqStatus(); + power.clearIrqStatus(); // Enable the required interrupt function - PMU.enableIRQ( + power.enableIRQ( XPOWERS_AXP2101_BAT_INSERT_IRQ | XPOWERS_AXP2101_BAT_REMOVE_IRQ | //BATTERY XPOWERS_AXP2101_VBUS_INSERT_IRQ | XPOWERS_AXP2101_VBUS_REMOVE_IRQ | //VBUS XPOWERS_AXP2101_PKEY_SHORT_IRQ | XPOWERS_AXP2101_PKEY_LONG_IRQ | //POWER KEY @@ -311,41 +311,41 @@ void setup() ); // Set the precharge charging current - PMU.setPrechargeCurr(XPOWERS_AXP2101_PRECHARGE_50MA); + power.setPrechargeCurr(XPOWERS_AXP2101_PRECHARGE_50MA); // Set constant current charge current limit - PMU.setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_200MA); + power.setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_200MA); // Set stop charging termination current - PMU.setChargerTerminationCurr(XPOWERS_AXP2101_CHG_ITERM_25MA); + power.setChargerTerminationCurr(XPOWERS_AXP2101_CHG_ITERM_25MA); // Set charge cut-off voltage - PMU.setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V1); + power.setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V1); // Set the watchdog trigger event type - PMU.setWatchdogConfig(XPOWERS_AXP2101_WDT_IRQ_TO_PIN); + power.setWatchdogConfig(XPOWERS_AXP2101_WDT_IRQ_TO_PIN); // Set watchdog timeout - PMU.setWatchdogTimeout(XPOWERS_AXP2101_WDT_TIMEOUT_4S); + power.setWatchdogTimeout(XPOWERS_AXP2101_WDT_TIMEOUT_4S); // Enable watchdog to trigger interrupt event - PMU.enableWatchdog(); + power.enableWatchdog(); - // PMU.disableWatchdog(); + // power.disableWatchdog(); // Enable Button Battery charge - PMU.enableButtonBatteryCharge(); + power.enableButtonBatteryCharge(); // Set Button Battery charge voltage - PMU.setButtonBatteryChargeVoltage(3300); + power.setButtonBatteryChargeVoltage(3300); } void printPMU() { - Serial.print("isCharging:"); Serial.println(PMU.isCharging() ? "YES" : "NO"); - Serial.print("isDischarge:"); Serial.println(PMU.isDischarge() ? "YES" : "NO"); - Serial.print("isStandby:"); Serial.println(PMU.isStandby() ? "YES" : "NO"); - Serial.print("isVbusIn:"); Serial.println(PMU.isVbusIn() ? "YES" : "NO"); - Serial.print("isVbusGood:"); Serial.println(PMU.isVbusGood() ? "YES" : "NO"); + Serial.print("isCharging:"); Serial.println(power.isCharging() ? "YES" : "NO"); + Serial.print("isDischarge:"); Serial.println(power.isDischarge() ? "YES" : "NO"); + Serial.print("isStandby:"); Serial.println(power.isStandby() ? "YES" : "NO"); + Serial.print("isVbusIn:"); Serial.println(power.isVbusIn() ? "YES" : "NO"); + Serial.print("isVbusGood:"); Serial.println(power.isVbusGood() ? "YES" : "NO"); Serial.print("getChargerStatus:"); - uint8_t charge_status = PMU.getChargerStatus(); + uint8_t charge_status = power.getChargerStatus(); if (charge_status == XPOWERS_AXP2101_CHG_TRI_STATE) { Serial.println("tri_charge"); } else if (charge_status == XPOWERS_AXP2101_CHG_PRE_STATE) { @@ -360,15 +360,15 @@ void printPMU() Serial.println("not chargin"); } - 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"); + Serial.print("getBattVoltage:"); Serial.print(power.getBattVoltage()); Serial.println("mV"); + Serial.print("getVbusVoltage:"); Serial.print(power.getVbusVoltage()); Serial.println("mV"); + Serial.print("getSystemVoltage:"); Serial.print(power.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("%"); + if (power.isBatteryConnect()) { + Serial.print("getBatteryPercent:"); Serial.print(power.getBatteryPercent()); Serial.println("%"); } Serial.println(); @@ -379,30 +379,30 @@ void printPMU() void enterPmuSleep(void) { // Set the wake-up source to PWRKEY - PMU.wakeupControl(XPOWERS_AXP2101_WAKEUP_IRQ_PIN_TO_LOW, true); + power.wakeupControl(XPOWERS_AXP2101_WAKEUP_IRQ_PIN_TO_LOW, true); // Set sleep flag - PMU.enableSleep(); + power.enableSleep(); - PMU.disableDC2(); - PMU.disableDC3(); - PMU.disableDC4(); - PMU.disableDC5(); + power.disableDC2(); + power.disableDC3(); + power.disableDC4(); + power.disableDC5(); - PMU.disableALDO1(); - PMU.disableALDO2(); - PMU.disableALDO3(); - PMU.disableALDO4(); + power.disableALDO1(); + power.disableALDO2(); + power.disableALDO3(); + power.disableALDO4(); - PMU.disableBLDO1(); - PMU.disableBLDO2(); + power.disableBLDO1(); + power.disableBLDO2(); - PMU.disableCPUSLDO(); - PMU.disableDLDO1(); - PMU.disableDLDO2(); + power.disableCPUSLDO(); + power.disableDLDO1(); + power.disableDLDO2(); // Finally, turn off the power of the control chip - PMU.disableDC1(); + power.disableDC1(); } void loop() @@ -413,50 +413,50 @@ void loop() pmu_flag = false; // Get PMU Interrupt Status Register - uint32_t status = PMU.getIrqStatus(); + uint32_t status = power.getIrqStatus(); Serial.print("STATUS => HEX:"); Serial.print(status, HEX); Serial.print(" BIN:"); Serial.println(status, BIN); - if (PMU.isDropWarningLevel2Irq()) { + if (power.isDropWarningLevel2Irq()) { Serial.println("isDropWarningLevel2"); } - if (PMU.isDropWarningLevel1Irq()) { + if (power.isDropWarningLevel1Irq()) { Serial.println("isDropWarningLevel1"); } - if (PMU.isGaugeWdtTimeoutIrq()) { + if (power.isGaugeWdtTimeoutIrq()) { Serial.println("isWdtTimeout"); } - if (PMU.isBatChargerOverTemperatureIrq()) { + if (power.isBatChargerOverTemperatureIrq()) { Serial.println("isBatChargeOverTemperature"); } - if (PMU.isBatWorkOverTemperatureIrq()) { + if (power.isBatWorkOverTemperatureIrq()) { Serial.println("isBatWorkOverTemperature"); } - if (PMU.isBatWorkUnderTemperatureIrq()) { + if (power.isBatWorkUnderTemperatureIrq()) { Serial.println("isBatWorkUnderTemperature"); } - if (PMU.isVbusInsertIrq()) { + if (power.isVbusInsertIrq()) { Serial.println("isVbusInsert"); } - if (PMU.isVbusRemoveIrq()) { + if (power.isVbusRemoveIrq()) { Serial.println("isVbusRemove"); } - if (PMU.isBatInsertIrq()) { + if (power.isBatInsertIrq()) { Serial.println("isBatInsert"); } - if (PMU.isBatRemoveIrq()) { + if (power.isBatRemoveIrq()) { Serial.println("isBatRemove"); } - if (PMU.isPekeyShortPressIrq()) { + if (power.isPekeyShortPressIrq()) { Serial.println("isPekeyShortPress"); // enterPmuSleep(); Serial.print("Read pmu data buffer ."); uint8_t data[4] = {0}; - PMU.readDataBuffer(data, XPOWERS_AXP2101_DATA_BUFFER_SIZE); + power.readDataBuffer(data, XPOWERS_AXP2101_DATA_BUFFER_SIZE); for (int i = 0; i < 4; ++i) { Serial.print(data[i]); Serial.print(","); @@ -464,47 +464,47 @@ void loop() Serial.println(); } - if (PMU.isPekeyLongPressIrq()) { + if (power.isPekeyLongPressIrq()) { Serial.println("isPekeyLongPress"); Serial.println("write pmu data buffer ."); uint8_t data[4] = {1, 2, 3, 4}; - PMU.writeDataBuffer(data, XPOWERS_AXP2101_DATA_BUFFER_SIZE); + power.writeDataBuffer(data, XPOWERS_AXP2101_DATA_BUFFER_SIZE); } - if (PMU.isPekeyNegativeIrq()) { + if (power.isPekeyNegativeIrq()) { Serial.println("isPekeyNegative"); } - if (PMU.isPekeyPositiveIrq()) { + if (power.isPekeyPositiveIrq()) { Serial.println("isPekeyPositive"); } - if (PMU.isWdtExpireIrq()) { + if (power.isWdtExpireIrq()) { Serial.println("isWdtExpire"); printPMU(); } - if (PMU.isLdoOverCurrentIrq()) { + if (power.isLdoOverCurrentIrq()) { Serial.println("isLdoOverCurrentIrq"); } - if (PMU.isBatfetOverCurrentIrq()) { + if (power.isBatfetOverCurrentIrq()) { Serial.println("isBatfetOverCurrentIrq"); } - if (PMU.isBatChagerDoneIrq()) { + if (power.isBatChagerDoneIrq()) { Serial.println("isBatChagerDone"); } - if (PMU.isBatChagerStartIrq()) { + if (power.isBatChagerStartIrq()) { Serial.println("isBatChagerStart"); } - if (PMU.isBatDieOverTemperatureIrq()) { + if (power.isBatDieOverTemperatureIrq()) { Serial.println("isBatDieOverTemperature"); } - if (PMU.isChagerOverTimeoutIrq()) { + if (power.isChagerOverTimeoutIrq()) { Serial.println("isChagerOverTimeout"); } - if (PMU.isBatOverVoltageIrq()) { + if (power.isBatOverVoltageIrq()) { Serial.println("isBatOverVoltage"); } // Clear PMU Interrupt Status Register - PMU.clearIrqStatus(); + power.clearIrqStatus(); } delay(10); diff --git a/examples/AXP2101_InterruptExample/AXP2101_InterruptExample.ino b/examples/AXP2101_InterruptExample/AXP2101_InterruptExample.ino index a7456c4..98ba7da 100644 --- a/examples/AXP2101_InterruptExample/AXP2101_InterruptExample.ino +++ b/examples/AXP2101_InterruptExample/AXP2101_InterruptExample.ino @@ -51,7 +51,7 @@ if there is any loss, please bear it by yourself #endif bool pmu_flag = 0; -XPowersPMU PMU; +XPowersPMU power; const uint8_t i2c_sda = CONFIG_PMU_SDA; @@ -67,13 +67,13 @@ void setup() { Serial.begin(115200); - bool result = PMU.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl); + bool result = power.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl); if (result == false) { - Serial.println("PMU is not online..."); while (1)delay(50); + Serial.println("power is not online..."); while (1)delay(50); } - Serial.printf("getID:0x%x\n", PMU.getChipID()); + Serial.printf("getID:0x%x\n", power.getChipID()); // Force add pull-up pinMode(pmu_irq_pin, INPUT_PULLUP); @@ -81,16 +81,16 @@ void setup() // Disable all interrupts - PMU.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); + power.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); // Print interrupt register - PMU.printIntRegister(&Serial); + power.printIntRegister(&Serial); // Clear all interrupt flags - PMU.clearIrqStatus(); + power.clearIrqStatus(); // Enable the required interrupt function - // PMU.enableIRQ( + // power.enableIRQ( // XPOWERS_AXP2101_BAT_INSERT_IRQ | XPOWERS_AXP2101_BAT_REMOVE_IRQ | //BATTERY // XPOWERS_AXP2101_VBUS_INSERT_IRQ | XPOWERS_AXP2101_VBUS_REMOVE_IRQ | //VBUS // XPOWERS_AXP2101_PKEY_SHORT_IRQ | XPOWERS_AXP2101_PKEY_LONG_IRQ | //POWER KEY @@ -98,17 +98,17 @@ void setup() // // XPOWERS_AXP2101_PKEY_NEGATIVE_IRQ | XPOWERS_AXP2101_PKEY_POSITIVE_IRQ | //POWER KEY // ); - PMU.enableIRQ(XPOWERS_AXP2101_BAT_NOR_UNDER_TEMP_IRQ); + power.enableIRQ(XPOWERS_AXP2101_BAT_NOR_UNDER_TEMP_IRQ); // Print AXP2101 interrupt control register - PMU.printIntRegister(&Serial); + power.printIntRegister(&Serial); - PMU.enableIRQ(XPOWERS_AXP2101_PKEY_SHORT_IRQ | XPOWERS_AXP2101_PKEY_NEGATIVE_IRQ); + power.enableIRQ(XPOWERS_AXP2101_PKEY_SHORT_IRQ | XPOWERS_AXP2101_PKEY_NEGATIVE_IRQ); // Print AXP2101 interrupt control register - PMU.printIntRegister(&Serial); + power.printIntRegister(&Serial); - PMU.enableIRQ(XPOWERS_AXP2101_BAT_OVER_VOL_IRQ); + power.enableIRQ(XPOWERS_AXP2101_BAT_OVER_VOL_IRQ); // Print AXP2101 interrupt control register - PMU.printIntRegister(&Serial); + power.printIntRegister(&Serial); // delay(30000); } @@ -121,84 +121,84 @@ void loop() pmu_flag = false; // Get PMU Interrupt Status Register - uint32_t status = PMU.getIrqStatus(); + uint32_t status = power.getIrqStatus(); Serial.print("STATUS => HEX:"); Serial.print(status, HEX); Serial.print(" BIN:"); Serial.println(status, BIN); - if (PMU.isDropWarningLevel2Irq()) { + if (power.isDropWarningLevel2Irq()) { Serial.println("isDropWarningLevel2"); } - if (PMU.isDropWarningLevel1Irq()) { + if (power.isDropWarningLevel1Irq()) { Serial.println("isDropWarningLevel1"); } - if (PMU.isGaugeWdtTimeoutIrq()) { + if (power.isGaugeWdtTimeoutIrq()) { Serial.println("isWdtTimeout"); } - if (PMU.isBatChargerOverTemperatureIrq()) { + if (power.isBatChargerOverTemperatureIrq()) { Serial.println("isBatChargeOverTemperature"); } - if (PMU.isBatWorkOverTemperatureIrq()) { + if (power.isBatWorkOverTemperatureIrq()) { Serial.println("isBatWorkOverTemperature"); } - if (PMU.isBatWorkUnderTemperatureIrq()) { + if (power.isBatWorkUnderTemperatureIrq()) { Serial.println("isBatWorkUnderTemperature"); } - if (PMU.isVbusInsertIrq()) { + if (power.isVbusInsertIrq()) { Serial.println("isVbusInsert"); } - if (PMU.isVbusRemoveIrq()) { + if (power.isVbusRemoveIrq()) { Serial.println("isVbusRemove"); } - if (PMU.isBatInsertIrq()) { + if (power.isBatInsertIrq()) { Serial.println("isBatInsert"); } - if (PMU.isBatRemoveIrq()) { + if (power.isBatRemoveIrq()) { Serial.println("isBatRemove"); } - if (PMU.isPekeyShortPressIrq()) { + if (power.isPekeyShortPressIrq()) { Serial.println("isPekeyShortPress"); } - if (PMU.isPekeyLongPressIrq()) { + if (power.isPekeyLongPressIrq()) { Serial.println("isPekeyLongPress"); } - if (PMU.isPekeyNegativeIrq()) { + if (power.isPekeyNegativeIrq()) { Serial.println("isPekeyNegative"); } - if (PMU.isPekeyPositiveIrq()) { + if (power.isPekeyPositiveIrq()) { Serial.println("isPekeyPositive"); } - if (PMU.isWdtExpireIrq()) { + if (power.isWdtExpireIrq()) { Serial.println("isWdtExpire"); } - if (PMU.isLdoOverCurrentIrq()) { + if (power.isLdoOverCurrentIrq()) { Serial.println("isLdoOverCurrentIrq"); } - if (PMU.isBatfetOverCurrentIrq()) { + if (power.isBatfetOverCurrentIrq()) { Serial.println("isBatfetOverCurrentIrq"); } - if (PMU.isBatChagerDoneIrq()) { + if (power.isBatChagerDoneIrq()) { Serial.println("isBatChagerDone"); } - if (PMU.isBatChagerStartIrq()) { + if (power.isBatChagerStartIrq()) { Serial.println("isBatChagerStart"); } - if (PMU.isBatDieOverTemperatureIrq()) { + if (power.isBatDieOverTemperatureIrq()) { Serial.println("isBatDieOverTemperature"); } - if (PMU.isChagerOverTimeoutIrq()) { + if (power.isChagerOverTimeoutIrq()) { Serial.println("isChagerOverTimeout"); } - if (PMU.isBatOverVoltageIrq()) { + if (power.isBatOverVoltageIrq()) { Serial.println("isBatOverVoltage"); } // Clear PMU Interrupt Status Register - PMU.clearIrqStatus(); + power.clearIrqStatus(); // Print AXP2101 interrupt control register - PMU.printIntRegister(&Serial); + power.printIntRegister(&Serial); } delay(10); diff --git a/examples/AXP2101_LowBatteryWarningExample/AXP2101_LowBatteryWarningExample.ino b/examples/AXP2101_LowBatteryWarningExample/AXP2101_LowBatteryWarningExample.ino index 77f3d72..8d318bf 100644 --- a/examples/AXP2101_LowBatteryWarningExample/AXP2101_LowBatteryWarningExample.ino +++ b/examples/AXP2101_LowBatteryWarningExample/AXP2101_LowBatteryWarningExample.ino @@ -51,7 +51,7 @@ if there is any loss, please bear it by yourself #endif bool pmu_flag = 0; -XPowersPMU PMU; +XPowersPMU power; const uint8_t i2c_sda = CONFIG_PMU_SDA; const uint8_t i2c_scl = CONFIG_PMU_SCL; @@ -68,63 +68,63 @@ void setup() { Serial.begin(115200); - bool result = PMU.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl); + bool result = power.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl); if (result == false) { - Serial.println("PMU is not online..."); while (1)delay(50); + Serial.println("power is not online..."); while (1)delay(50); } - Serial.printf("getID:0x%x\n", PMU.getChipID()); + Serial.printf("getID:0x%x\n", power.getChipID()); // Set the minimum common working voltage of the PMU VBUS input, // below this value will turn off the PMU - PMU.setVbusVoltageLimit(XPOWERS_AXP2101_VBUS_VOL_LIM_4V36); + power.setVbusVoltageLimit(XPOWERS_AXP2101_VBUS_VOL_LIM_4V36); // Set the maximum current of the PMU VBUS input, // higher than this value will turn off the PMU - PMU.setVbusCurrentLimit(XPOWERS_AXP2101_VBUS_CUR_LIM_1500MA); + power.setVbusCurrentLimit(XPOWERS_AXP2101_VBUS_CUR_LIM_1500MA); // Get the VSYS shutdown voltage - uint16_t vol = PMU.getSysPowerDownVoltage(); + uint16_t vol = power.getSysPowerDownVoltage(); Serial.printf("-> getSysPowerDownVoltage:%u\n", vol); - // Set VSY off voltage as 2600mV , Adjustment range 2600mV ~ 3300mV - PMU.setSysPowerDownVoltage(2600); + // Set VSYS off voltage as 2600mV , Adjustment range 2600mV ~ 3300mV + power.setSysPowerDownVoltage(2600); - vol = PMU.getSysPowerDownVoltage(); + vol = power.getSysPowerDownVoltage(); Serial.printf("-> getSysPowerDownVoltage:%u\n", vol); Serial.println("DCDC======================================================================="); - Serial.printf("DC1 : %s Voltage:%u mV \n", PMU.isEnableDC1() ? "+" : "-", PMU.getDC1Voltage()); - Serial.printf("DC2 : %s Voltage:%u mV \n", PMU.isEnableDC2() ? "+" : "-", PMU.getDC2Voltage()); - Serial.printf("DC3 : %s Voltage:%u mV \n", PMU.isEnableDC3() ? "+" : "-", PMU.getDC3Voltage()); - Serial.printf("DC4 : %s Voltage:%u mV \n", PMU.isEnableDC4() ? "+" : "-", PMU.getDC4Voltage()); - Serial.printf("DC5 : %s Voltage:%u mV \n", PMU.isEnableDC5() ? "+" : "-", PMU.getDC5Voltage()); + Serial.printf("DC1 : %s Voltage:%u mV \n", power.isEnableDC1() ? "+" : "-", power.getDC1Voltage()); + Serial.printf("DC2 : %s Voltage:%u mV \n", power.isEnableDC2() ? "+" : "-", power.getDC2Voltage()); + Serial.printf("DC3 : %s Voltage:%u mV \n", power.isEnableDC3() ? "+" : "-", power.getDC3Voltage()); + Serial.printf("DC4 : %s Voltage:%u mV \n", power.isEnableDC4() ? "+" : "-", power.getDC4Voltage()); + Serial.printf("DC5 : %s Voltage:%u mV \n", power.isEnableDC5() ? "+" : "-", power.getDC5Voltage()); Serial.println("ALDO======================================================================="); - Serial.printf("ALDO1: %s Voltage:%u mV\n", PMU.isEnableALDO1() ? "+" : "-", PMU.getALDO1Voltage()); - Serial.printf("ALDO2: %s Voltage:%u mV\n", PMU.isEnableALDO2() ? "+" : "-", PMU.getALDO2Voltage()); - Serial.printf("ALDO3: %s Voltage:%u mV\n", PMU.isEnableALDO3() ? "+" : "-", PMU.getALDO3Voltage()); - Serial.printf("ALDO4: %s Voltage:%u mV\n", PMU.isEnableALDO4() ? "+" : "-", PMU.getALDO4Voltage()); + Serial.printf("ALDO1: %s Voltage:%u mV\n", power.isEnableALDO1() ? "+" : "-", power.getALDO1Voltage()); + Serial.printf("ALDO2: %s Voltage:%u mV\n", power.isEnableALDO2() ? "+" : "-", power.getALDO2Voltage()); + Serial.printf("ALDO3: %s Voltage:%u mV\n", power.isEnableALDO3() ? "+" : "-", power.getALDO3Voltage()); + Serial.printf("ALDO4: %s Voltage:%u mV\n", power.isEnableALDO4() ? "+" : "-", power.getALDO4Voltage()); Serial.println("BLDO======================================================================="); - Serial.printf("BLDO1: %s Voltage:%u mV\n", PMU.isEnableBLDO1() ? "+" : "-", PMU.getBLDO1Voltage()); - Serial.printf("BLDO2: %s Voltage:%u mV\n", PMU.isEnableBLDO2() ? "+" : "-", PMU.getBLDO2Voltage()); + Serial.printf("BLDO1: %s Voltage:%u mV\n", power.isEnableBLDO1() ? "+" : "-", power.getBLDO1Voltage()); + Serial.printf("BLDO2: %s Voltage:%u mV\n", power.isEnableBLDO2() ? "+" : "-", power.getBLDO2Voltage()); Serial.println("CPUSLDO===================================================================="); - Serial.printf("CPUSLDO: %s Voltage:%u mV\n", PMU.isEnableCPUSLDO() ? "+" : "-", PMU.getCPUSLDOVoltage()); + Serial.printf("CPUSLDO: %s Voltage:%u mV\n", power.isEnableCPUSLDO() ? "+" : "-", power.getCPUSLDOVoltage()); Serial.println("DLDO======================================================================="); - Serial.printf("DLDO1: %s Voltage:%u mV\n", PMU.isEnableDLDO1() ? "+" : "-", PMU.getDLDO1Voltage()); - Serial.printf("DLDO2: %s Voltage:%u mV\n", PMU.isEnableDLDO2() ? "+" : "-", PMU.getDLDO2Voltage()); + Serial.printf("DLDO1: %s Voltage:%u mV\n", power.isEnableDLDO1() ? "+" : "-", power.getDLDO1Voltage()); + Serial.printf("DLDO2: %s Voltage:%u mV\n", power.isEnableDLDO2() ? "+" : "-", power.getDLDO2Voltage()); Serial.println("==========================================================================="); // Enable internal ADC detection - PMU.enableBattDetection(); - PMU.enableVbusVoltageMeasure(); - PMU.enableBattVoltageMeasure(); - PMU.enableSystemVoltageMeasure(); - PMU.enableTemperatureMeasure(); + power.enableBattDetection(); + power.enableVbusVoltageMeasure(); + power.enableBattVoltageMeasure(); + power.enableSystemVoltageMeasure(); + power.enableTemperatureMeasure(); /* @@ -135,7 +135,7 @@ void setup() - XPOWERS_CHG_LED_ON, - XPOWERS_CHG_LED_CTRL_CHG, * */ - PMU.setChargingLedMode(XPOWERS_CHG_LED_CTRL_CHG); + power.setChargingLedMode(XPOWERS_CHG_LED_CTRL_CHG); // Force add pull-up @@ -144,11 +144,11 @@ void setup() // Disable all interrupts - PMU.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); + power.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); // Clear all interrupt flags - PMU.clearIrqStatus(); + power.clearIrqStatus(); // Enable the required interrupt function - PMU.enableIRQ( + power.enableIRQ( XPOWERS_AXP2101_BAT_INSERT_IRQ | XPOWERS_AXP2101_BAT_REMOVE_IRQ | //BATTERY XPOWERS_AXP2101_VBUS_INSERT_IRQ | XPOWERS_AXP2101_VBUS_REMOVE_IRQ | //VBUS XPOWERS_AXP2101_PKEY_SHORT_IRQ | XPOWERS_AXP2101_PKEY_LONG_IRQ | //POWER KEY @@ -158,7 +158,7 @@ void setup() // Get the default low pressure warning percentage setting - uint8_t low_warn_per = PMU.getLowBatWarnThreshold(); + uint8_t low_warn_per = power.getLowBatWarnThreshold(); Serial.printf("Default low battery warning threshold is %d percentage\n", low_warn_per); // @@ -169,14 +169,14 @@ void setup() // 10% ~= 3.55V // 5% ~= 3.5V // 1% ~= 3.4V - PMU.setLowBatWarnThreshold(5); // Set to trigger interrupt when reaching 5% + power.setLowBatWarnThreshold(5); // Set to trigger interrupt when reaching 5% // Get the low voltage warning percentage setting - low_warn_per = PMU.getLowBatWarnThreshold(); + low_warn_per = power.getLowBatWarnThreshold(); Serial.printf("Set low battery warning threshold is %d percentage\n", low_warn_per); // Get the default low voltage shutdown percentage setting - uint8_t low_shutdown_per = PMU.getLowBatShutdownThreshold(); + uint8_t low_shutdown_per = power.getLowBatShutdownThreshold(); Serial.printf("Default low battery shutdown threshold is %d percentage\n", low_shutdown_per); // setLowBatShutdownThreshold Range: 0% ~ 15% @@ -185,10 +185,10 @@ void setup() // 10% ~= 3.55V // 5% ~= 3.5V // 1% ~= 3.4V - PMU.setLowBatShutdownThreshold(1); // Set to trigger interrupt when reaching 1% + power.setLowBatShutdownThreshold(1); // Set to trigger interrupt when reaching 1% // Get the low voltage shutdown percentage setting - low_shutdown_per = PMU.getLowBatShutdownThreshold(); + low_shutdown_per = power.getLowBatShutdownThreshold(); Serial.printf("Set low battery shutdown threshold is %d percentage\n", low_shutdown_per); @@ -215,15 +215,15 @@ void loop() interval = millis() + 3000; - 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"); + Serial.print("getBattVoltage:"); Serial.print(power.getBattVoltage()); Serial.println("mV"); + Serial.print("getVbusVoltage:"); Serial.print(power.getVbusVoltage()); Serial.println("mV"); + Serial.print("getSystemVoltage:"); Serial.print(power.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("%"); + if (power.isBatteryConnect()) { + Serial.print("getBatteryPercent:"); Serial.print(power.getBatteryPercent()); Serial.println("%"); } Serial.println(); } @@ -233,7 +233,7 @@ void loop() pmu_flag = false; // Get PMU Interrupt Status Register - uint32_t status = PMU.getIrqStatus(); + uint32_t status = power.getIrqStatus(); Serial.print("STATUS => HEX:"); Serial.print(status, HEX); Serial.print(" BIN:"); @@ -241,41 +241,41 @@ void loop() // When the set low-voltage battery percentage warning threshold is reached, // set the threshold through getLowBatWarnThreshold( 5% ~ 20% ) - if (PMU.isDropWarningLevel2Irq()) { + if (power.isDropWarningLevel2Irq()) { Serial.println("The voltage percentage has reached the low voltage warning threshold!!!"); } // When the set low-voltage battery percentage shutdown threshold is reached // set the threshold through setLowBatShutdownThreshold() - if (PMU.isDropWarningLevel1Irq()) { + if (power.isDropWarningLevel1Irq()) { int i = 4; while (i--) { Serial.printf("The voltage percentage has reached the low voltage shutdown threshold and will shut down in %d seconds.\n", i); } // Turn off all power supplies, leaving only the RTC power supply. The RTC power supply cannot be turned off. - PMU.shutdown(); + power.shutdown(); } - if (PMU.isVbusInsertIrq()) { + if (power.isVbusInsertIrq()) { Serial.println("isVbusInsert"); } - if (PMU.isVbusRemoveIrq()) { + if (power.isVbusRemoveIrq()) { Serial.println("isVbusRemove"); } - if (PMU.isBatInsertIrq()) { + if (power.isBatInsertIrq()) { Serial.println("isBatInsert"); } - if (PMU.isBatRemoveIrq()) { + if (power.isBatRemoveIrq()) { Serial.println("isBatRemove"); } - if (PMU.isPekeyShortPressIrq()) { + if (power.isPekeyShortPressIrq()) { Serial.println("isPekeyShortPress"); } - if (PMU.isPekeyLongPressIrq()) { + if (power.isPekeyLongPressIrq()) { Serial.println("isPekeyLongPress"); } // Clear PMU Interrupt Status Register - PMU.clearIrqStatus(); + power.clearIrqStatus(); } delay(10); diff --git a/examples/AXP2101_Sleep_Example/AXP2101_Sleep_Example.ino b/examples/AXP2101_Sleep_Example/AXP2101_Sleep_Example.ino index 38a4a99..c23d7c4 100644 --- a/examples/AXP2101_Sleep_Example/AXP2101_Sleep_Example.ino +++ b/examples/AXP2101_Sleep_Example/AXP2101_Sleep_Example.ino @@ -56,7 +56,7 @@ if there is any loss, please bear it by yourself #define CONFIG_PMU_IRQ 6 #endif -XPowersPMU PMU; +XPowersPMU power; const uint8_t i2c_sda = CONFIG_PMU_SDA; const uint8_t i2c_scl = CONFIG_PMU_SCL; @@ -74,7 +74,7 @@ void setup() { Serial.begin(115200); - bool result = PMU.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl); + bool result = power.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl); if (result == false) { Serial.println("PMU is not online..."); while (1)delay(50); @@ -85,19 +85,19 @@ void setup() attachInterrupt(pmu_irq_pin, setFlag, FALLING); // Close other IRQs - PMU.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); + power.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); // Clear all interrupt flags - PMU.clearIrqStatus(); + power.clearIrqStatus(); // Enable the required interrupt function - PMU.enableIRQ( + power.enableIRQ( XPOWERS_AXP2101_PKEY_SHORT_IRQ //POWER KEY ); // Turn on the charging indicator light as a power-on indicator - PMU.setChargingLedMode(XPOWERS_CHG_LED_ON); + power.setChargingLedMode(XPOWERS_CHG_LED_ON); // Enable chip temperature detection - PMU.enableTemperatureMeasure(); + power.enableTemperatureMeasure(); } @@ -107,47 +107,47 @@ void loop() if (pmu_flag) { pmu_flag = false; // Get PMU Interrupt Status Register - uint32_t status = PMU.getIrqStatus(); - if (PMU.isPekeyShortPressIrq()) { + uint32_t status = power.getIrqStatus(); + if (power.isPekeyShortPressIrq()) { // Turn off the charging indicator to save power - PMU.setChargingLedMode(XPOWERS_CHG_LED_OFF); + power.setChargingLedMode(XPOWERS_CHG_LED_OFF); // Turn off ADC data monitoring to save power - PMU.disableTemperatureMeasure(); + power.disableTemperatureMeasure(); // Enable internal ADC detection - PMU.disableBattDetection(); - PMU.disableVbusVoltageMeasure(); - PMU.disableBattVoltageMeasure(); - PMU.disableSystemVoltageMeasure(); + power.disableBattDetection(); + power.disableVbusVoltageMeasure(); + power.disableBattVoltageMeasure(); + power.disableSystemVoltageMeasure(); // Enable PMU sleep - PMU.enableSleep(); + power.enableSleep(); // Reserve the MCU chip power supply, LilyGo AXP2101 usually uses DC as ESP power supply - // PMU.enableDC1(); + // power.enableDC1(); // Turn off the power output of other channels - PMU.disableDC2(); - PMU.disableDC3(); - PMU.disableDC4(); - PMU.disableDC5(); - PMU.disableALDO1(); - PMU.disableALDO2(); - PMU.disableALDO3(); - PMU.disableALDO4(); - PMU.disableBLDO1(); - PMU.disableBLDO2(); - PMU.disableCPUSLDO(); - PMU.disableDLDO1(); - PMU.disableDLDO2(); + power.disableDC2(); + power.disableDC3(); + power.disableDC4(); + power.disableDC5(); + power.disableALDO1(); + power.disableALDO2(); + power.disableALDO3(); + power.disableALDO4(); + power.disableBLDO1(); + power.disableBLDO2(); + power.disableCPUSLDO(); + power.disableDLDO1(); + power.disableDLDO2(); // Clear PMU Interrupt Status Register - PMU.clearIrqStatus(); + power.clearIrqStatus(); // Send IRQ wakeup command - PMU.enableWakeup(); + power.enableWakeup(); #if !CONFIG_IDF_TARGET_ESP32S3 Serial.println("Please implement the MCU sleep method"); @@ -164,7 +164,7 @@ void loop() } // When not sleeping, print PMU temperature - Serial.print("PMU Temperature:"); Serial.print(PMU.getTemperature()); Serial.println("*C"); + Serial.print("power Temperature:"); Serial.print(power.getTemperature()); Serial.println("*C"); delay(1000); } diff --git a/examples/AXP2101_Voltage_Example/AXP2101_Voltage_Example.ino b/examples/AXP2101_Voltage_Example/AXP2101_Voltage_Example.ino index 4f0248a..0367b2b 100644 --- a/examples/AXP2101_Voltage_Example/AXP2101_Voltage_Example.ino +++ b/examples/AXP2101_Voltage_Example/AXP2101_Voltage_Example.ino @@ -39,7 +39,7 @@ if there is any loss, please bear it by yourself #include #include "XPowersLib.h" -XPowersPMU PMU; +XPowersPMU power; #ifndef CONFIG_PMU_SDA #define CONFIG_PMU_SDA 21 @@ -65,38 +65,38 @@ void setup() { Serial.begin(115200); - bool result = PMU.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl); + bool result = power.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl); if (result == false) { - Serial.println("PMU is not online..."); while (1)delay(50); + Serial.println("power is not online..."); while (1)delay(50); } Serial.println("AXP2101 Power Output Test."); - PMU.disableDC2(); - PMU.disableDC3(); - PMU.disableDC4(); - PMU.disableDC5(); - PMU.disableALDO1(); - PMU.disableALDO2(); - PMU.disableALDO3(); - PMU.disableALDO4(); - PMU.disableBLDO1(); - PMU.disableBLDO2(); - PMU.disableCPUSLDO(); - PMU.disableDLDO1(); - PMU.disableDLDO2(); + power.disableDC2(); + power.disableDC3(); + power.disableDC4(); + power.disableDC5(); + power.disableALDO1(); + power.disableALDO2(); + power.disableALDO3(); + power.disableALDO4(); + power.disableBLDO1(); + power.disableBLDO2(); + power.disableCPUSLDO(); + power.disableDLDO1(); + power.disableDLDO2(); // DC1 IMAX=2A // 1500~3400mV,100mV/step,20steps vol = 1500; for (int i = 0; i < 20; ++i) { - PMU.setDC1Voltage(vol); + power.setDC1Voltage(vol); vol += 100; - Serial.printf("DC1 :%s Voltage:%u mV \n", PMU.isEnableDC1() ? "ENABLE" : "DISABLE", PMU.getDC1Voltage()); + Serial.printf("DC1 :%s Voltage:%u mV \n", power.isEnableDC1() ? "ENABLE" : "DISABLE", power.getDC1Voltage()); } @@ -104,10 +104,10 @@ void setup() // 500~1200mV 10mV/step,71steps vol = 500; for (int i = 0; i < 71; ++i) { - PMU.setDC2Voltage(vol); + power.setDC2Voltage(vol); delay(1); - targetVol = PMU.getDC2Voltage(); - Serial.printf("[%d]DC2 :%s Voltage:%u mV \n", i, PMU.isEnableDC2() ? "ENABLE" : "DISABLE", targetVol ); + targetVol = power.getDC2Voltage(); + Serial.printf("[%d]DC2 :%s Voltage:%u mV \n", i, power.isEnableDC2() ? "ENABLE" : "DISABLE", targetVol ); if (targetVol != vol)Serial.println(">>> FAILED!"); vol += 10; } @@ -116,10 +116,10 @@ void setup() // 1220~1540mV 20mV/step,17steps vol = 1220; for (int i = 0; i < 17; ++i) { - PMU.setDC2Voltage(vol); + power.setDC2Voltage(vol); delay(1); - targetVol = PMU.getDC2Voltage(); - Serial.printf("[%u]DC2 :%s Voltage:%u mV \n", i, PMU.isEnableDC2() ? "ENABLE" : "DISABLE", targetVol ); + targetVol = power.getDC2Voltage(); + Serial.printf("[%u]DC2 :%s Voltage:%u mV \n", i, power.isEnableDC2() ? "ENABLE" : "DISABLE", targetVol ); if (targetVol != vol)Serial.println(">>> FAILED!"); vol += 20; } @@ -128,10 +128,10 @@ void setup() // 500~1200mV,10mV/step,71steps vol = 500; for (int i = 0; i < 71; ++i) { - PMU.setDC3Voltage(vol); + power.setDC3Voltage(vol); delay(1); - targetVol = PMU.getDC3Voltage(); - Serial.printf("[%u]DC3 :%s Voltage:%u mV \n", i, PMU.isEnableDC3() ? "ENABLE" : "DISABLE", targetVol ); + targetVol = power.getDC3Voltage(); + Serial.printf("[%u]DC3 :%s Voltage:%u mV \n", i, power.isEnableDC3() ? "ENABLE" : "DISABLE", targetVol ); if (targetVol != vol)Serial.println(">>> FAILED!"); vol += 10; } @@ -140,10 +140,10 @@ void setup() // 1220~1540mV,20mV/step,17steps vol = 1220; for (int i = 0; i < 17; ++i) { - PMU.setDC3Voltage(vol); + power.setDC3Voltage(vol); delay(1); - targetVol = PMU.getDC3Voltage(); - Serial.printf("[%u]DC3 :%s Voltage:%u mV \n", i, PMU.isEnableDC3() ? "ENABLE" : "DISABLE", targetVol ); + targetVol = power.getDC3Voltage(); + Serial.printf("[%u]DC3 :%s Voltage:%u mV \n", i, power.isEnableDC3() ? "ENABLE" : "DISABLE", targetVol ); if (targetVol != vol)Serial.println(">>> FAILED!"); vol += 20; } @@ -153,10 +153,10 @@ void setup() // 1600~3400mV,100mV/step,19steps vol = 1600; for (int i = 0; i < 19; ++i) { - PMU.setDC3Voltage(vol); + power.setDC3Voltage(vol); delay(1); - targetVol = PMU.getDC3Voltage(); - Serial.printf("[%u]DC3 :%s Voltage:%u mV \n", i, PMU.isEnableDC3() ? "ENABLE" : "DISABLE", targetVol ); + targetVol = power.getDC3Voltage(); + Serial.printf("[%u]DC3 :%s Voltage:%u mV \n", i, power.isEnableDC3() ? "ENABLE" : "DISABLE", targetVol ); if (targetVol != vol)Serial.println(">>> FAILED!"); vol += 100; } @@ -166,10 +166,10 @@ void setup() // 500~1200mV,10mV/step,71steps vol = 500; for (int i = 0; i < 71; ++i) { - PMU.setDC4Voltage(vol); + power.setDC4Voltage(vol); delay(1); - targetVol = PMU.getDC4Voltage(); - Serial.printf("[%u]DC4 :%s Voltage:%u mV \n", i, PMU.isEnableDC4() ? "ENABLE" : "DISABLE", targetVol ); + targetVol = power.getDC4Voltage(); + Serial.printf("[%u]DC4 :%s Voltage:%u mV \n", i, power.isEnableDC4() ? "ENABLE" : "DISABLE", targetVol ); if (targetVol != vol)Serial.println(">>> FAILED!"); vol += 10; } @@ -178,29 +178,29 @@ void setup() // 1220~1840mV,20mV/step,32steps vol = 1220; for (int i = 0; i < 32; ++i) { - PMU.setDC4Voltage(vol); + power.setDC4Voltage(vol); delay(1); - targetVol = PMU.getDC4Voltage(); - Serial.printf("[%u]DC4 :%s Voltage:%u mV \n", i, PMU.isEnableDC4() ? "ENABLE" : "DISABLE", targetVol ); + targetVol = power.getDC4Voltage(); + Serial.printf("[%u]DC4 :%s Voltage:%u mV \n", i, power.isEnableDC4() ? "ENABLE" : "DISABLE", targetVol ); if (targetVol != vol)Serial.println(">>> FAILED!"); vol += 20; } // DC5 IMAX=2A // 1200mV - PMU.setDC5Voltage(1200); - targetVol = PMU.getDC5Voltage(); - Serial.printf("[0]DC5 :%s Voltage:%u mV \n", PMU.isEnableDC5() ? "ENABLE" : "DISABLE", targetVol ); + power.setDC5Voltage(1200); + targetVol = power.getDC5Voltage(); + Serial.printf("[0]DC5 :%s Voltage:%u mV \n", power.isEnableDC5() ? "ENABLE" : "DISABLE", targetVol ); // DC5 IMAX=2A // 1400~3700mV,100mV/step,24steps vol = 1400; for (int i = 0; i < 24; ++i) { - PMU.setDC5Voltage(vol); + power.setDC5Voltage(vol); delay(1); - targetVol = PMU.getDC5Voltage(); - Serial.printf("[%u]DC5 :%s Voltage:%u mV \n", i, PMU.isEnableDC5() ? "ENABLE" : "DISABLE", targetVol ); + targetVol = power.getDC5Voltage(); + Serial.printf("[%u]DC5 :%s Voltage:%u mV \n", i, power.isEnableDC5() ? "ENABLE" : "DISABLE", targetVol ); if (targetVol != vol)Serial.println(">>> FAILED!"); vol += 100; } @@ -211,10 +211,10 @@ void setup() //500~3500mV, 100mV/step,31steps vol = 500; for (int i = 0; i < 31; ++i) { - PMU.setALDO1Voltage(vol); + power.setALDO1Voltage(vol); delay(1); - targetVol = PMU.getALDO1Voltage(); - Serial.printf("[%u]ALDO1 :%s Voltage:%u mV \n", i, PMU.isEnableALDO1() ? "ENABLE" : "DISABLE", targetVol ); + targetVol = power.getALDO1Voltage(); + Serial.printf("[%u]ALDO1 :%s Voltage:%u mV \n", i, power.isEnableALDO1() ? "ENABLE" : "DISABLE", targetVol ); if (targetVol != vol)Serial.println(">>> FAILED!"); vol += 100; } @@ -223,10 +223,10 @@ void setup() //500~3500mV, 100mV/step,31steps vol = 500; for (int i = 0; i < 31; ++i) { - PMU.setALDO2Voltage(vol); + power.setALDO2Voltage(vol); delay(1); - targetVol = PMU.getALDO2Voltage(); - Serial.printf("[%u]ALDO2 :%s Voltage:%u mV \n", i, PMU.isEnableALDO2() ? "ENABLE" : "DISABLE", targetVol ); + targetVol = power.getALDO2Voltage(); + Serial.printf("[%u]ALDO2 :%s Voltage:%u mV \n", i, power.isEnableALDO2() ? "ENABLE" : "DISABLE", targetVol ); if (targetVol != vol)Serial.println(">>> FAILED!"); vol += 100; } @@ -235,10 +235,10 @@ void setup() //500~3500mV, 100mV/step,31steps vol = 500; for (int i = 0; i < 31; ++i) { - PMU.setALDO3Voltage(vol); + power.setALDO3Voltage(vol); delay(1); - targetVol = PMU.getALDO3Voltage(); - Serial.printf("[%u]ALDO3 :%s Voltage:%u mV \n", i, PMU.isEnableALDO3() ? "ENABLE" : "DISABLE", targetVol ); + targetVol = power.getALDO3Voltage(); + Serial.printf("[%u]ALDO3 :%s Voltage:%u mV \n", i, power.isEnableALDO3() ? "ENABLE" : "DISABLE", targetVol ); if (targetVol != vol)Serial.println(">>> FAILED!"); vol += 100; } @@ -247,10 +247,10 @@ void setup() //500~3500mV, 100mV/step,31steps vol = 500; for (int i = 0; i < 31; ++i) { - PMU.setALDO4Voltage(vol); + power.setALDO4Voltage(vol); delay(1); - targetVol = PMU.getALDO4Voltage(); - Serial.printf("[%u]ALDO4 :%s Voltage:%u mV \n", i, PMU.isEnableALDO4() ? "ENABLE" : "DISABLE", targetVol ); + targetVol = power.getALDO4Voltage(); + Serial.printf("[%u]ALDO4 :%s Voltage:%u mV \n", i, power.isEnableALDO4() ? "ENABLE" : "DISABLE", targetVol ); if (targetVol != vol)Serial.println(">>> FAILED!"); vol += 100; } @@ -259,10 +259,10 @@ void setup() //500~3500mV, 100mV/step,31steps vol = 500; for (int i = 0; i < 31; ++i) { - PMU.setBLDO1Voltage(vol); + power.setBLDO1Voltage(vol); delay(1); - targetVol = PMU.getBLDO1Voltage(); - Serial.printf("[%u]BLDO1 :%s Voltage:%u mV \n", i, PMU.isEnableBLDO1() ? "ENABLE" : "DISABLE", targetVol ); + targetVol = power.getBLDO1Voltage(); + Serial.printf("[%u]BLDO1 :%s Voltage:%u mV \n", i, power.isEnableBLDO1() ? "ENABLE" : "DISABLE", targetVol ); if (targetVol != vol)Serial.println(">>> FAILED!"); vol += 100; } @@ -271,10 +271,10 @@ void setup() //500~3500mV, 100mV/step,31steps vol = 500; for (int i = 0; i < 31; ++i) { - PMU.setBLDO2Voltage(vol); + power.setBLDO2Voltage(vol); delay(1); - targetVol = PMU.getBLDO2Voltage(); - Serial.printf("[%u]BLDO2 :%s Voltage:%u mV \n", i, PMU.isEnableBLDO2() ? "ENABLE" : "DISABLE", targetVol ); + targetVol = power.getBLDO2Voltage(); + Serial.printf("[%u]BLDO2 :%s Voltage:%u mV \n", i, power.isEnableBLDO2() ? "ENABLE" : "DISABLE", targetVol ); if (targetVol != vol)Serial.println(">>> FAILED!"); vol += 100; } @@ -284,10 +284,10 @@ void setup() //500~1400mV,50mV/step,19steps vol = 500; for (int i = 0; i < 19; ++i) { - PMU.setCPUSLDOVoltage(vol); + power.setCPUSLDOVoltage(vol); delay(1); - targetVol = PMU.getCPUSLDOVoltage(); - Serial.printf("[%u]CPUSLDO :%s Voltage:%u mV \n", i, PMU.isEnableCPUSLDO() ? "ENABLE" : "DISABLE", targetVol ); + targetVol = power.getCPUSLDOVoltage(); + Serial.printf("[%u]CPUSLDO :%s Voltage:%u mV \n", i, power.isEnableCPUSLDO() ? "ENABLE" : "DISABLE", targetVol ); if (targetVol != vol)Serial.println(">>> FAILED!"); vol += 50; } @@ -296,10 +296,10 @@ void setup() //500~3400mV, 100mV/step,29steps vol = 500; for (int i = 0; i < 29; ++i) { - PMU.setDLDO1Voltage(vol); + power.setDLDO1Voltage(vol); delay(1); - targetVol = PMU.getDLDO1Voltage(); - Serial.printf("[%u]DLDO1 :%s Voltage:%u mV \n", i, PMU.isEnableDLDO1() ? "ENABLE" : "DISABLE", targetVol ); + targetVol = power.getDLDO1Voltage(); + Serial.printf("[%u]DLDO1 :%s Voltage:%u mV \n", i, power.isEnableDLDO1() ? "ENABLE" : "DISABLE", targetVol ); if (targetVol != vol)Serial.println(">>> FAILED!"); vol += 100; } @@ -308,10 +308,10 @@ void setup() //500~1400mV, 50mV/step,2steps vol = 500; for (int i = 0; i < 29; ++i) { - PMU.setDLDO2Voltage(vol); + power.setDLDO2Voltage(vol); delay(1); - targetVol = PMU.getDLDO2Voltage(); - Serial.printf("[%u]DLDO2 :%s Voltage:%u mV \n", i, PMU.isEnableDLDO2() ? "ENABLE" : "DISABLE", targetVol ); + targetVol = power.getDLDO2Voltage(); + Serial.printf("[%u]DLDO2 :%s Voltage:%u mV \n", i, power.isEnableDLDO2() ? "ENABLE" : "DISABLE", targetVol ); if (targetVol != vol)Serial.println(">>> FAILED!"); vol += 100; } @@ -324,25 +324,25 @@ void setup() if there is any loss, please bear it by yourself */ - // PMU.enableDC1(); - // PMU.enableDC2(); - // PMU.enableDC3(); - // PMU.enableDC4(); - // PMU.enableDC5(); + // power.enableDC1(); + // power.enableDC2(); + // power.enableDC3(); + // power.enableDC4(); + // power.enableDC5(); - // PMU.enableALDO1(); - // PMU.enableALDO2(); - // PMU.enableALDO3(); - // PMU.enableALDO4(); + // power.enableALDO1(); + // power.enableALDO2(); + // power.enableALDO3(); + // power.enableALDO4(); - // PMU.enableBLDO1(); - // PMU.enableBLDO2(); + // power.enableBLDO1(); + // power.enableBLDO2(); - // PMU.enableCPUSLDO(); + // power.enableCPUSLDO(); - // PMU.enableDLDO1(); - // PMU.enableDLDO2(); + // power.enableDLDO1(); + // power.enableDLDO2(); } diff --git a/examples/ESP_IDF_Example/main/port_axp192.cpp b/examples/ESP_IDF_Example/main/port_axp192.cpp index 4ab06b2..bc92886 100644 --- a/examples/ESP_IDF_Example/main/port_axp192.cpp +++ b/examples/ESP_IDF_Example/main/port_axp192.cpp @@ -10,7 +10,7 @@ #include "XPowersLib.h" static const char *TAG = "AXP192"; -XPowersPMU PMU; +XPowersPMU power; extern int pmu_register_read(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint8_t len); extern int pmu_register_write_byte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint8_t len); @@ -21,7 +21,7 @@ esp_err_t pmu_init() //* Implemented using read and write callback methods, applicable to other platforms #if CONFIG_I2C_COMMUNICATION_METHOD_CALLBACK_RW ESP_LOGI(TAG, "Implemented using read and write callback methods"); - if (PMU.begin(AXP192_SLAVE_ADDRESS, pmu_register_read, pmu_register_write_byte)) { + if (power.begin(AXP192_SLAVE_ADDRESS, pmu_register_read, pmu_register_write_byte)) { ESP_LOGI(TAG, "Init PMU SUCCESS!"); } else { ESP_LOGE(TAG, "Init PMU FAILED!"); @@ -38,7 +38,7 @@ esp_err_t pmu_init() // * which is useful when the bus shares multiple devices. extern i2c_master_bus_handle_t bus_handle; - if (PMU.begin(bus_handle, AXP192_SLAVE_ADDRESS)) { + if (power.begin(bus_handle, AXP192_SLAVE_ADDRESS)) { ESP_LOGI(TAG, "Init PMU SUCCESS!"); } else { ESP_LOGE(TAG, "Init PMU FAILED!"); @@ -48,7 +48,7 @@ esp_err_t pmu_init() ESP_LOGI(TAG, "Implemented using built-in read and write methods (Use lower version < 5.0 API)"); - if (PMU.begin((i2c_port_t)CONFIG_I2C_MASTER_PORT_NUM, AXP192_SLAVE_ADDRESS, CONFIG_PMU_I2C_SDA, CONFIG_PMU_I2C_SCL)) { + if (power.begin((i2c_port_t)CONFIG_I2C_MASTER_PORT_NUM, AXP192_SLAVE_ADDRESS, CONFIG_PMU_I2C_SDA, CONFIG_PMU_I2C_SCL)) { ESP_LOGI(TAG, "Init PMU SUCCESS!"); } else { ESP_LOGE(TAG, "Init PMU FAILED!"); @@ -57,64 +57,64 @@ esp_err_t pmu_init() #endif //ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0) #endif //CONFIG_I2C_COMMUNICATION_METHOD_BUILTIN_RW - ESP_LOGI(TAG, "getID:0x%x", PMU.getChipID()); + ESP_LOGI(TAG, "getID:0x%x", power.getChipID()); // Set the minimum system operating voltage inside the PMU, // below this value will shut down the PMU // Range: 2600~3300mV - PMU.setSysPowerDownVoltage(2700); + power.setSysPowerDownVoltage(2700); // Set the minimum common working voltage of the PMU VBUS input, // below this value will turn off the PMU - PMU.setVbusVoltageLimit(XPOWERS_AXP192_VBUS_VOL_LIM_4V5); + power.setVbusVoltageLimit(XPOWERS_AXP192_VBUS_VOL_LIM_4V5); // Turn off USB input current limit - PMU.setVbusCurrentLimit(XPOWERS_AXP192_VBUS_CUR_LIM_OFF); + power.setVbusCurrentLimit(XPOWERS_AXP192_VBUS_CUR_LIM_OFF); // DC1 700~3500mV, IMAX=1.2A - PMU.setDC1Voltage(3300); - ESP_LOGI(TAG, "DC1 :%s Voltage:%u mV ", PMU.isEnableDC1() ? "ENABLE" : "DISABLE", PMU.getDC1Voltage()); + power.setDC1Voltage(3300); + ESP_LOGI(TAG, "DC1 :%s Voltage:%u mV ", power.isEnableDC1() ? "ENABLE" : "DISABLE", power.getDC1Voltage()); // DC2 700~2750mV, IMAX=1.6A; - PMU.setDC2Voltage(700); - ESP_LOGI(TAG, "DC2 :%s Voltage:%u mV ", PMU.isEnableDC2() ? "ENABLE" : "DISABLE", PMU.getDC2Voltage()); + power.setDC2Voltage(700); + ESP_LOGI(TAG, "DC2 :%s Voltage:%u mV ", power.isEnableDC2() ? "ENABLE" : "DISABLE", power.getDC2Voltage()); // DC3 700~3500mV,IMAX=0.7A; - PMU.setDC3Voltage(3300); - ESP_LOGI(TAG, "DC3 :%s Voltage:%u mV ", PMU.isEnableDC3() ? "ENABLE" : "DISABLE", PMU.getDC3Voltage()); + power.setDC3Voltage(3300); + ESP_LOGI(TAG, "DC3 :%s Voltage:%u mV ", power.isEnableDC3() ? "ENABLE" : "DISABLE", power.getDC3Voltage()); //LDO2 1800~3300V, 100mV/step, IMAX=200mA - PMU.setLDO2Voltage(1800); + power.setLDO2Voltage(1800); //LDO3 1800~3300V, 100mV/step, IMAX=200mA - PMU.setLDO3Voltage(1800); + power.setLDO3Voltage(1800); //LDOio 1800~3300V, 100mV/step, IMAX=50mA - PMU.setLDOioVoltage(3300); + power.setLDOioVoltage(3300); // Enable power output channel - // PMU.enableDC1(); - PMU.enableDC2(); - PMU.enableDC3(); - PMU.enableLDO2(); - PMU.enableLDO3(); - PMU.enableLDOio(); + // power.enableDC1(); + power.enableDC2(); + power.enableDC3(); + power.enableLDO2(); + power.enableLDO3(); + power.enableLDOio(); ESP_LOGI(TAG, "DCDC=======================================================================\n"); - ESP_LOGI(TAG, "DC1 :%s Voltage:%u mV \n", PMU.isEnableDC1() ? "ENABLE" : "DISABLE", PMU.getDC1Voltage()); - ESP_LOGI(TAG, "DC2 :%s Voltage:%u mV \n", PMU.isEnableDC2() ? "ENABLE" : "DISABLE", PMU.getDC2Voltage()); - ESP_LOGI(TAG, "DC3 :%s Voltage:%u mV \n", PMU.isEnableDC3() ? "ENABLE" : "DISABLE", PMU.getDC3Voltage()); + ESP_LOGI(TAG, "DC1 :%s Voltage:%u mV \n", power.isEnableDC1() ? "ENABLE" : "DISABLE", power.getDC1Voltage()); + ESP_LOGI(TAG, "DC2 :%s Voltage:%u mV \n", power.isEnableDC2() ? "ENABLE" : "DISABLE", power.getDC2Voltage()); + ESP_LOGI(TAG, "DC3 :%s Voltage:%u mV \n", power.isEnableDC3() ? "ENABLE" : "DISABLE", power.getDC3Voltage()); ESP_LOGI(TAG, "LDO=======================================================================\n"); - ESP_LOGI(TAG, "LDO2: %s Voltage:%u mV\n", PMU.isEnableLDO2() ? "ENABLE" : "DISABLE", PMU.getLDO2Voltage()); - ESP_LOGI(TAG, "LDO3: %s Voltage:%u mV\n", PMU.isEnableLDO3() ? "ENABLE" : "DISABLE", PMU.getLDO3Voltage()); - ESP_LOGI(TAG, "LDOio: %s Voltage:%u mV\n", PMU.isEnableLDOio() ? "ENABLE" : "DISABLE", PMU.getLDOioVoltage()); + ESP_LOGI(TAG, "LDO2: %s Voltage:%u mV\n", power.isEnableLDO2() ? "ENABLE" : "DISABLE", power.getLDO2Voltage()); + ESP_LOGI(TAG, "LDO3: %s Voltage:%u mV\n", power.isEnableLDO3() ? "ENABLE" : "DISABLE", power.getLDO3Voltage()); + ESP_LOGI(TAG, "LDOio: %s Voltage:%u mV\n", power.isEnableLDOio() ? "ENABLE" : "DISABLE", power.getLDOioVoltage()); ESP_LOGI(TAG, "==========================================================================\n"); // Set the time of pressing the button to turn off - PMU.setPowerKeyPressOffTime(XPOWERS_POWEROFF_4S); - uint8_t opt = PMU.getPowerKeyPressOffTime(); + power.setPowerKeyPressOffTime(XPOWERS_POWEROFF_4S); + uint8_t opt = power.getPowerKeyPressOffTime(); ESP_LOGI(TAG, "PowerKeyPressOffTime:"); switch (opt) { case XPOWERS_POWEROFF_4S: ESP_LOGI(TAG, "4 Second"); @@ -129,8 +129,8 @@ esp_err_t pmu_init() break; } // Set the button power-on press time - PMU.setPowerKeyPressOnTime(XPOWERS_POWERON_128MS); - opt = PMU.getPowerKeyPressOnTime(); + power.setPowerKeyPressOnTime(XPOWERS_POWERON_128MS); + opt = power.getPowerKeyPressOnTime(); ESP_LOGI(TAG, "PowerKeyPressOnTime:"); switch (opt) { case XPOWERS_POWERON_128MS: ESP_LOGI(TAG, "128 Ms"); @@ -149,16 +149,16 @@ esp_err_t pmu_init() // It is necessary to disable the detection function of the TS pin on the board // without the battery temperature detection function, otherwise it will cause abnormal charging - PMU.disableTSPinMeasure(); + power.disableTSPinMeasure(); - // PMU.enableTemperatureMeasure(); - // PMU.disableTemperatureMeasure(); + // power.enableTemperatureMeasure(); + // power.disableTemperatureMeasure(); // Enable internal ADC detection - PMU.enableBattDetection(); - PMU.enableVbusVoltageMeasure(); - PMU.enableBattVoltageMeasure(); - PMU.enableSystemVoltageMeasure(); + power.enableBattDetection(); + power.enableVbusVoltageMeasure(); + power.enableBattVoltageMeasure(); + power.enableSystemVoltageMeasure(); /* The default setting is CHGLED is automatically controlled by the PMU. @@ -168,14 +168,14 @@ esp_err_t pmu_init() - XPOWERS_CHG_LED_ON, - XPOWERS_CHG_LED_CTRL_CHG, * */ - PMU.setChargingLedMode(XPOWERS_CHG_LED_OFF); + power.setChargingLedMode(XPOWERS_CHG_LED_OFF); // Disable all interrupts - PMU.disableIRQ(XPOWERS_AXP192_ALL_IRQ); + power.disableIRQ(XPOWERS_AXP192_ALL_IRQ); // Clear all interrupt flags - PMU.clearIrqStatus(); + power.clearIrqStatus(); // Enable the required interrupt function - PMU.enableIRQ( + power.enableIRQ( XPOWERS_AXP192_BAT_INSERT_IRQ | XPOWERS_AXP192_BAT_REMOVE_IRQ | //BATTERY XPOWERS_AXP192_VBUS_INSERT_IRQ | XPOWERS_AXP192_VBUS_REMOVE_IRQ | //VBUS XPOWERS_AXP192_PKEY_SHORT_IRQ | XPOWERS_AXP192_PKEY_LONG_IRQ | //POWER KEY @@ -185,25 +185,25 @@ esp_err_t pmu_init() ); // Set constant current charge current limit - PMU.setChargerConstantCurr(XPOWERS_AXP192_CHG_CUR_280MA); + power.setChargerConstantCurr(XPOWERS_AXP192_CHG_CUR_280MA); // Set stop charging termination current - PMU.setChargerTerminationCurr(XPOWERS_AXP192_CHG_ITERM_LESS_10_PERCENT); + power.setChargerTerminationCurr(XPOWERS_AXP192_CHG_ITERM_LESS_10_PERCENT); // Set charge cut-off voltage - PMU.setChargeTargetVoltage(XPOWERS_AXP192_CHG_VOL_4V2); + power.setChargeTargetVoltage(XPOWERS_AXP192_CHG_VOL_4V2); // Cache writes and reads, as long as the PMU remains powered, the data will always be stored inside the PMU ESP_LOGI(TAG, "Write pmu data buffer ."); uint8_t data[XPOWERS_AXP192_DATA_BUFFER_SIZE] = {1, 2, 3, 4, 5, 6}; - PMU.writeDataBuffer(data, XPOWERS_AXP192_DATA_BUFFER_SIZE); + power.writeDataBuffer(data, XPOWERS_AXP192_DATA_BUFFER_SIZE); memset(data, 0, XPOWERS_AXP192_DATA_BUFFER_SIZE); ESP_LOGI(TAG, "Read pmu data buffer :"); - PMU.readDataBuffer(data, XPOWERS_AXP192_DATA_BUFFER_SIZE); + power.readDataBuffer(data, XPOWERS_AXP192_DATA_BUFFER_SIZE); ESP_LOG_BUFFER_HEX(TAG, data, XPOWERS_AXP192_DATA_BUFFER_SIZE); // Set the timing after one minute, the isWdtExpireIrq will be triggered in the loop interrupt function - PMU.setTimerout(1); + power.setTimerout(1); return ESP_OK; } @@ -212,113 +212,113 @@ esp_err_t pmu_init() void pmu_isr_handler() { // Get PMU Interrupt Status Register - PMU.getIrqStatus(); + power.getIrqStatus(); - if (PMU.isAcinOverVoltageIrq()) { + if (power.isAcinOverVoltageIrq()) { ESP_LOGI(TAG, "isAcinOverVoltageIrq"); } - if (PMU.isAcinInserIrq()) { + if (power.isAcinInserIrq()) { ESP_LOGI(TAG, "isAcinInserIrq"); } - if (PMU.isAcinRemoveIrq()) { + if (power.isAcinRemoveIrq()) { ESP_LOGI(TAG, "isAcinRemoveIrq"); } - if (PMU.isVbusOverVoltageIrq()) { + if (power.isVbusOverVoltageIrq()) { ESP_LOGI(TAG, "isVbusOverVoltageIrq"); } - if (PMU.isVbusInsertIrq()) { + if (power.isVbusInsertIrq()) { ESP_LOGI(TAG, "isVbusInsertIrq"); } - if (PMU.isVbusRemoveIrq()) { + if (power.isVbusRemoveIrq()) { ESP_LOGI(TAG, "isVbusRemoveIrq"); } - if (PMU.isVbusLowVholdIrq()) { + if (power.isVbusLowVholdIrq()) { ESP_LOGI(TAG, "isVbusLowVholdIrq"); } - if (PMU.isBatInsertIrq()) { + if (power.isBatInsertIrq()) { ESP_LOGI(TAG, "isBatInsertIrq"); } - if (PMU.isBatRemoveIrq()) { + if (power.isBatRemoveIrq()) { ESP_LOGI(TAG, "isBatRemoveIrq"); } - if (PMU.isBattEnterActivateIrq()) { + if (power.isBattEnterActivateIrq()) { ESP_LOGI(TAG, "isBattEnterActivateIrq"); } - if (PMU.isBattExitActivateIrq()) { + if (power.isBattExitActivateIrq()) { ESP_LOGI(TAG, "isBattExitActivateIrq"); } - if (PMU.isBatChagerStartIrq()) { + if (power.isBatChagerStartIrq()) { ESP_LOGI(TAG, "isBatChagerStartIrq"); } - if (PMU.isBatChagerDoneIrq()) { + if (power.isBatChagerDoneIrq()) { ESP_LOGI(TAG, "isBatChagerDoneIrq"); } - if (PMU.isBattTempHighIrq()) { + if (power.isBattTempHighIrq()) { ESP_LOGI(TAG, "isBattTempHighIrq"); } - if (PMU.isBattTempLowIrq()) { + if (power.isBattTempLowIrq()) { ESP_LOGI(TAG, "isBattTempLowIrq"); } - if (PMU.isChipOverTemperatureIrq()) { + if (power.isChipOverTemperatureIrq()) { ESP_LOGI(TAG, "isChipOverTemperatureIrq"); } - if (PMU.isChargingCurrentLessIrq()) { + if (power.isChargingCurrentLessIrq()) { ESP_LOGI(TAG, "isChargingCurrentLessIrq"); } - if (PMU.isDC1VoltageLessIrq()) { + if (power.isDC1VoltageLessIrq()) { ESP_LOGI(TAG, "isDC1VoltageLessIrq"); } - if (PMU.isDC2VoltageLessIrq()) { + if (power.isDC2VoltageLessIrq()) { ESP_LOGI(TAG, "isDC2VoltageLessIrq"); } - if (PMU.isDC3VoltageLessIrq()) { + if (power.isDC3VoltageLessIrq()) { ESP_LOGI(TAG, "isDC3VoltageLessIrq"); } - if (PMU.isPekeyShortPressIrq()) { + if (power.isPekeyShortPressIrq()) { ESP_LOGI(TAG, "isPekeyShortPress"); // enterPmuSleep(); } - if (PMU.isPekeyLongPressIrq()) { + if (power.isPekeyLongPressIrq()) { ESP_LOGI(TAG, "isPekeyLongPress"); } - if (PMU.isNOEPowerOnIrq()) { + if (power.isNOEPowerOnIrq()) { ESP_LOGI(TAG, "isNOEPowerOnIrq"); } - if (PMU.isNOEPowerDownIrq()) { + if (power.isNOEPowerDownIrq()) { ESP_LOGI(TAG, "isNOEPowerDownIrq"); } - if (PMU.isVbusEffectiveIrq()) { + if (power.isVbusEffectiveIrq()) { ESP_LOGI(TAG, "isVbusEffectiveIrq"); } - if (PMU.isVbusInvalidIrq()) { + if (power.isVbusInvalidIrq()) { ESP_LOGI(TAG, "isVbusInvalidIrq"); } - if (PMU.isVbusSessionIrq()) { + if (power.isVbusSessionIrq()) { ESP_LOGI(TAG, "isVbusSessionIrq"); } - if (PMU.isVbusSessionEndIrq()) { + if (power.isVbusSessionEndIrq()) { ESP_LOGI(TAG, "isVbusSessionEndIrq"); } - if (PMU.isLowVoltageLevel2Irq()) { + if (power.isLowVoltageLevel2Irq()) { ESP_LOGI(TAG, "isLowVoltageLevel2Irq"); } - if (PMU.isWdtExpireIrq()) { + if (power.isWdtExpireIrq()) { ESP_LOGI(TAG, "isWdtExpire"); // Clear the timer state and continue to the next timer - PMU.clearTimerFlag(); + power.clearTimerFlag(); } - if (PMU.isGpio2EdgeTriggerIrq()) { + if (power.isGpio2EdgeTriggerIrq()) { ESP_LOGI(TAG, "isGpio2EdgeTriggerIrq"); } - if (PMU.isGpio1EdgeTriggerIrq()) { + if (power.isGpio1EdgeTriggerIrq()) { ESP_LOGI(TAG, "isGpio1EdgeTriggerIrq"); } - if (PMU.isGpio0EdgeTriggerIrq()) { + if (power.isGpio0EdgeTriggerIrq()) { ESP_LOGI(TAG, "isGpio0EdgeTriggerIrq"); } // Clear PMU Interrupt Status Register - PMU.clearIrqStatus(); + power.clearIrqStatus(); } #endif /*CONFIG_XPOWERS_AXP192_CHIP_AXP192*/ diff --git a/examples/ESP_IDF_Example/main/port_axp2101.cpp b/examples/ESP_IDF_Example/main/port_axp2101.cpp index fd80268..1f84c8b 100644 --- a/examples/ESP_IDF_Example/main/port_axp2101.cpp +++ b/examples/ESP_IDF_Example/main/port_axp2101.cpp @@ -10,7 +10,7 @@ #include "XPowersLib.h" static const char *TAG = "AXP2101"; -static XPowersPMU PMU; +static XPowersPMU power; extern int pmu_register_read(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint8_t len); extern int pmu_register_write_byte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint8_t len); @@ -21,7 +21,7 @@ esp_err_t pmu_init() //* Implemented using read and write callback methods, applicable to other platforms #if CONFIG_I2C_COMMUNICATION_METHOD_CALLBACK_RW ESP_LOGI(TAG, "Implemented using read and write callback methods"); - if (PMU.begin(AXP2101_SLAVE_ADDRESS, pmu_register_read, pmu_register_write_byte)) { + if (power.begin(AXP2101_SLAVE_ADDRESS, pmu_register_read, pmu_register_write_byte)) { ESP_LOGI(TAG, "Init PMU SUCCESS!"); } else { ESP_LOGE(TAG, "Init PMU FAILED!"); @@ -39,7 +39,7 @@ esp_err_t pmu_init() // * which is useful when the bus shares multiple devices. extern i2c_master_bus_handle_t bus_handle; - if (PMU.begin(bus_handle, AXP2101_SLAVE_ADDRESS)) { + if (power.begin(bus_handle, AXP2101_SLAVE_ADDRESS)) { ESP_LOGI(TAG, "Init PMU SUCCESS!"); } else { ESP_LOGE(TAG, "Init PMU FAILED!"); @@ -49,7 +49,7 @@ esp_err_t pmu_init() ESP_LOGI(TAG, "Implemented using built-in read and write methods (Use lower version < 5.0 API)"); - if (PMU.begin((i2c_port_t)CONFIG_I2C_MASTER_PORT_NUM, AXP2101_SLAVE_ADDRESS, CONFIG_PMU_I2C_SDA, CONFIG_PMU_I2C_SCL)) { + if (power.begin((i2c_port_t)CONFIG_I2C_MASTER_PORT_NUM, AXP2101_SLAVE_ADDRESS, CONFIG_PMU_I2C_SDA, CONFIG_PMU_I2C_SCL)) { ESP_LOGI(TAG, "Init PMU SUCCESS!"); } else { ESP_LOGE(TAG, "Init PMU FAILED!"); @@ -59,94 +59,94 @@ esp_err_t pmu_init() #endif //CONFIG_I2C_COMMUNICATION_METHOD_BUILTIN_RW //Turn off not use power channel - PMU.disableDC2(); - PMU.disableDC3(); - PMU.disableDC4(); - PMU.disableDC5(); + power.disableDC2(); + power.disableDC3(); + power.disableDC4(); + power.disableDC5(); - PMU.disableALDO1(); - PMU.disableALDO2(); - PMU.disableALDO3(); - PMU.disableALDO4(); - PMU.disableBLDO1(); - PMU.disableBLDO2(); + power.disableALDO1(); + power.disableALDO2(); + power.disableALDO3(); + power.disableALDO4(); + power.disableBLDO1(); + power.disableBLDO2(); - PMU.disableCPUSLDO(); - PMU.disableDLDO1(); - PMU.disableDLDO2(); + power.disableCPUSLDO(); + power.disableDLDO1(); + power.disableDLDO2(); //ESP32s3 Core VDD - PMU.setDC3Voltage(3300); - PMU.enableDC3(); + power.setDC3Voltage(3300); + power.enableDC3(); //Extern 3.3V VDD - PMU.setDC1Voltage(3300); - PMU.enableDC1(); + power.setDC1Voltage(3300); + power.enableDC1(); // CAM DVDD 1500~1800 - PMU.setALDO1Voltage(1800); - // PMU.setALDO1Voltage(1500); - PMU.enableALDO1(); + power.setALDO1Voltage(1800); + // power.setALDO1Voltage(1500); + power.enableALDO1(); // CAM DVDD 2500~2800 - PMU.setALDO2Voltage(2800); - PMU.enableALDO2(); + power.setALDO2Voltage(2800); + power.enableALDO2(); // CAM AVDD 2800~3000 - PMU.setALDO4Voltage(3000); - PMU.enableALDO4(); + power.setALDO4Voltage(3000); + power.enableALDO4(); // PIR VDD 3300 - PMU.setALDO3Voltage(3300); - PMU.enableALDO3(); + power.setALDO3Voltage(3300); + power.enableALDO3(); // OLED VDD 3300 - PMU.setBLDO1Voltage(3300); - PMU.enableBLDO1(); + power.setBLDO1Voltage(3300); + power.enableBLDO1(); // MIC VDD 33000 - PMU.setBLDO2Voltage(3300); - PMU.enableBLDO2(); + power.setBLDO2Voltage(3300); + power.enableBLDO2(); ESP_LOGI(TAG, "DCDC=======================================================================\n"); - ESP_LOGI(TAG, "DC1 : %s Voltage:%u mV \n", PMU.isEnableDC1() ? "+" : "-", PMU.getDC1Voltage()); - ESP_LOGI(TAG, "DC2 : %s Voltage:%u mV \n", PMU.isEnableDC2() ? "+" : "-", PMU.getDC2Voltage()); - ESP_LOGI(TAG, "DC3 : %s Voltage:%u mV \n", PMU.isEnableDC3() ? "+" : "-", PMU.getDC3Voltage()); - ESP_LOGI(TAG, "DC4 : %s Voltage:%u mV \n", PMU.isEnableDC4() ? "+" : "-", PMU.getDC4Voltage()); - ESP_LOGI(TAG, "DC5 : %s Voltage:%u mV \n", PMU.isEnableDC5() ? "+" : "-", PMU.getDC5Voltage()); + ESP_LOGI(TAG, "DC1 : %s Voltage:%u mV \n", power.isEnableDC1() ? "+" : "-", power.getDC1Voltage()); + ESP_LOGI(TAG, "DC2 : %s Voltage:%u mV \n", power.isEnableDC2() ? "+" : "-", power.getDC2Voltage()); + ESP_LOGI(TAG, "DC3 : %s Voltage:%u mV \n", power.isEnableDC3() ? "+" : "-", power.getDC3Voltage()); + ESP_LOGI(TAG, "DC4 : %s Voltage:%u mV \n", power.isEnableDC4() ? "+" : "-", power.getDC4Voltage()); + ESP_LOGI(TAG, "DC5 : %s Voltage:%u mV \n", power.isEnableDC5() ? "+" : "-", power.getDC5Voltage()); ESP_LOGI(TAG, "ALDO=======================================================================\n"); - ESP_LOGI(TAG, "ALDO1: %s Voltage:%u mV\n", PMU.isEnableALDO1() ? "+" : "-", PMU.getALDO1Voltage()); - ESP_LOGI(TAG, "ALDO2: %s Voltage:%u mV\n", PMU.isEnableALDO2() ? "+" : "-", PMU.getALDO2Voltage()); - ESP_LOGI(TAG, "ALDO3: %s Voltage:%u mV\n", PMU.isEnableALDO3() ? "+" : "-", PMU.getALDO3Voltage()); - ESP_LOGI(TAG, "ALDO4: %s Voltage:%u mV\n", PMU.isEnableALDO4() ? "+" : "-", PMU.getALDO4Voltage()); + ESP_LOGI(TAG, "ALDO1: %s Voltage:%u mV\n", power.isEnableALDO1() ? "+" : "-", power.getALDO1Voltage()); + ESP_LOGI(TAG, "ALDO2: %s Voltage:%u mV\n", power.isEnableALDO2() ? "+" : "-", power.getALDO2Voltage()); + ESP_LOGI(TAG, "ALDO3: %s Voltage:%u mV\n", power.isEnableALDO3() ? "+" : "-", power.getALDO3Voltage()); + ESP_LOGI(TAG, "ALDO4: %s Voltage:%u mV\n", power.isEnableALDO4() ? "+" : "-", power.getALDO4Voltage()); ESP_LOGI(TAG, "BLDO=======================================================================\n"); - ESP_LOGI(TAG, "BLDO1: %s Voltage:%u mV\n", PMU.isEnableBLDO1() ? "+" : "-", PMU.getBLDO1Voltage()); - ESP_LOGI(TAG, "BLDO2: %s Voltage:%u mV\n", PMU.isEnableBLDO2() ? "+" : "-", PMU.getBLDO2Voltage()); + ESP_LOGI(TAG, "BLDO1: %s Voltage:%u mV\n", power.isEnableBLDO1() ? "+" : "-", power.getBLDO1Voltage()); + ESP_LOGI(TAG, "BLDO2: %s Voltage:%u mV\n", power.isEnableBLDO2() ? "+" : "-", power.getBLDO2Voltage()); ESP_LOGI(TAG, "CPUSLDO====================================================================\n"); - ESP_LOGI(TAG, "CPUSLDO: %s Voltage:%u mV\n", PMU.isEnableCPUSLDO() ? "+" : "-", PMU.getCPUSLDOVoltage()); + ESP_LOGI(TAG, "CPUSLDO: %s Voltage:%u mV\n", power.isEnableCPUSLDO() ? "+" : "-", power.getCPUSLDOVoltage()); ESP_LOGI(TAG, "DLDO=======================================================================\n"); - ESP_LOGI(TAG, "DLDO1: %s Voltage:%u mV\n", PMU.isEnableDLDO1() ? "+" : "-", PMU.getDLDO1Voltage()); - ESP_LOGI(TAG, "DLDO2: %s Voltage:%u mV\n", PMU.isEnableDLDO2() ? "+" : "-", PMU.getDLDO2Voltage()); + ESP_LOGI(TAG, "DLDO1: %s Voltage:%u mV\n", power.isEnableDLDO1() ? "+" : "-", power.getDLDO1Voltage()); + ESP_LOGI(TAG, "DLDO2: %s Voltage:%u mV\n", power.isEnableDLDO2() ? "+" : "-", power.getDLDO2Voltage()); ESP_LOGI(TAG, "===========================================================================\n"); - PMU.clearIrqStatus(); + power.clearIrqStatus(); - PMU.enableVbusVoltageMeasure(); - PMU.enableBattVoltageMeasure(); - PMU.enableSystemVoltageMeasure(); - PMU.enableTemperatureMeasure(); + power.enableVbusVoltageMeasure(); + power.enableBattVoltageMeasure(); + power.enableSystemVoltageMeasure(); + power.enableTemperatureMeasure(); // It is necessary to disable the detection function of the TS pin on the board // without the battery temperature detection function, otherwise it will cause abnormal charging - PMU.disableTSPinMeasure(); + power.disableTSPinMeasure(); // Disable all interrupts - PMU.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); + power.disableIRQ(XPOWERS_AXP2101_ALL_IRQ); // Clear all interrupt flags - PMU.clearIrqStatus(); + power.clearIrqStatus(); // Enable the required interrupt function - PMU.enableIRQ( + power.enableIRQ( XPOWERS_AXP2101_BAT_INSERT_IRQ | XPOWERS_AXP2101_BAT_REMOVE_IRQ | //BATTERY XPOWERS_AXP2101_VBUS_INSERT_IRQ | XPOWERS_AXP2101_VBUS_REMOVE_IRQ | //VBUS XPOWERS_AXP2101_PKEY_SHORT_IRQ | XPOWERS_AXP2101_PKEY_LONG_IRQ | //POWER KEY @@ -155,31 +155,31 @@ esp_err_t pmu_init() ); /* - The default setting is CHGLED is automatically controlled by the PMU. + The default setting is CHGLED is automatically controlled by the power. - XPOWERS_CHG_LED_OFF, - XPOWERS_CHG_LED_BLINK_1HZ, - XPOWERS_CHG_LED_BLINK_4HZ, - XPOWERS_CHG_LED_ON, - XPOWERS_CHG_LED_CTRL_CHG, * */ - PMU.setChargingLedMode(XPOWERS_CHG_LED_BLINK_1HZ); + power.setChargingLedMode(XPOWERS_CHG_LED_BLINK_1HZ); // Set the precharge charging current - PMU.setPrechargeCurr(XPOWERS_AXP2101_PRECHARGE_50MA); + power.setPrechargeCurr(XPOWERS_AXP2101_PRECHARGE_50MA); // Set constant current charge current limit - PMU.setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_200MA); + power.setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_200MA); // Set stop charging termination current - PMU.setChargerTerminationCurr(XPOWERS_AXP2101_CHG_ITERM_25MA); + power.setChargerTerminationCurr(XPOWERS_AXP2101_CHG_ITERM_25MA); // Set charge cut-off voltage - PMU.setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V1); + power.setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V1); // Set the watchdog trigger event type - // PMU.setWatchdogConfig(XPOWERS_AXP2101_WDT_IRQ_TO_PIN); + // power.setWatchdogConfig(XPOWERS_AXP2101_WDT_IRQ_TO_PIN); // Set watchdog timeout - PMU.setWatchdogTimeout(XPOWERS_AXP2101_WDT_TIMEOUT_4S); + power.setWatchdogTimeout(XPOWERS_AXP2101_WDT_TIMEOUT_4S); // Enable watchdog to trigger interrupt event - PMU.enableWatchdog(); + power.enableWatchdog(); return ESP_OK; } @@ -187,76 +187,76 @@ esp_err_t pmu_init() void pmu_isr_handler() { // Get PMU Interrupt Status Register - PMU.getIrqStatus(); + power.getIrqStatus(); - if (PMU.isDropWarningLevel2Irq()) { + if (power.isDropWarningLevel2Irq()) { ESP_LOGI(TAG, "isDropWarningLevel2"); } - if (PMU.isDropWarningLevel1Irq()) { + if (power.isDropWarningLevel1Irq()) { ESP_LOGI(TAG, "isDropWarningLevel1"); } - if (PMU.isGaugeWdtTimeoutIrq()) { + if (power.isGaugeWdtTimeoutIrq()) { ESP_LOGI(TAG, "isWdtTimeout"); } - if (PMU.isBatChargerOverTemperatureIrq()) { + if (power.isBatChargerOverTemperatureIrq()) { ESP_LOGI(TAG, "isBatChargeOverTemperature"); } - if (PMU.isBatWorkOverTemperatureIrq()) { + if (power.isBatWorkOverTemperatureIrq()) { ESP_LOGI(TAG, "isBatWorkOverTemperature"); } - if (PMU.isBatWorkUnderTemperatureIrq()) { + if (power.isBatWorkUnderTemperatureIrq()) { ESP_LOGI(TAG, "isBatWorkUnderTemperature"); } - if (PMU.isVbusInsertIrq()) { + if (power.isVbusInsertIrq()) { ESP_LOGI(TAG, "isVbusInsert"); } - if (PMU.isVbusRemoveIrq()) { + if (power.isVbusRemoveIrq()) { ESP_LOGI(TAG, "isVbusRemove"); } - if (PMU.isBatInsertIrq()) { + if (power.isBatInsertIrq()) { ESP_LOGI(TAG, "isBatInsert"); } - if (PMU.isBatRemoveIrq()) { + if (power.isBatRemoveIrq()) { ESP_LOGI(TAG, "isBatRemove"); } - if (PMU.isPekeyShortPressIrq()) { + if (power.isPekeyShortPressIrq()) { ESP_LOGI(TAG, "isPekeyShortPress"); } - if (PMU.isPekeyLongPressIrq()) { + if (power.isPekeyLongPressIrq()) { ESP_LOGI(TAG, "isPekeyLongPress"); } - if (PMU.isPekeyNegativeIrq()) { + if (power.isPekeyNegativeIrq()) { ESP_LOGI(TAG, "isPekeyNegative"); } - if (PMU.isPekeyPositiveIrq()) { + if (power.isPekeyPositiveIrq()) { ESP_LOGI(TAG, "isPekeyPositive"); } - if (PMU.isWdtExpireIrq()) { + if (power.isWdtExpireIrq()) { ESP_LOGI(TAG, "isWdtExpire"); } - if (PMU.isLdoOverCurrentIrq()) { + if (power.isLdoOverCurrentIrq()) { ESP_LOGI(TAG, "isLdoOverCurrentIrq"); } - if (PMU.isBatfetOverCurrentIrq()) { + if (power.isBatfetOverCurrentIrq()) { ESP_LOGI(TAG, "isBatfetOverCurrentIrq"); } - if (PMU.isBatChagerDoneIrq()) { + if (power.isBatChagerDoneIrq()) { ESP_LOGI(TAG, "isBatChagerDone"); } - if (PMU.isBatChagerStartIrq()) { + if (power.isBatChagerStartIrq()) { ESP_LOGI(TAG, "isBatChagerStart"); } - if (PMU.isBatDieOverTemperatureIrq()) { + if (power.isBatDieOverTemperatureIrq()) { ESP_LOGI(TAG, "isBatDieOverTemperature"); } - if (PMU.isChagerOverTimeoutIrq()) { + if (power.isChagerOverTimeoutIrq()) { ESP_LOGI(TAG, "isChagerOverTimeout"); } - if (PMU.isBatOverVoltageIrq()) { + if (power.isBatOverVoltageIrq()) { ESP_LOGI(TAG, "isBatOverVoltage"); } // Clear PMU Interrupt Status Register - PMU.clearIrqStatus(); + power.clearIrqStatus(); } #endif /*CONFIG_XPOWERS_AXP2101_CHIP_AXP2102*/ diff --git a/examples/XPowersLibInterface_Example/XPowersLibInterface_Example.ino b/examples/XPowersLibInterface_Example/XPowersLibInterface_Example.ino index 1c89c45..86dd453 100644 --- a/examples/XPowersLibInterface_Example/XPowersLibInterface_Example.ino +++ b/examples/XPowersLibInterface_Example/XPowersLibInterface_Example.ino @@ -51,7 +51,7 @@ if there is any loss, please bear it by yourself #endif // Use the XPowersLibInterface standard to use the xpowers API -XPowersLibInterface *PMU = NULL; +XPowersLibInterface *power = NULL; bool pmu_flag = 0; @@ -70,76 +70,76 @@ void setup() Serial.begin(115200); - if (!PMU) { - PMU = new XPowersAXP2101(Wire, i2c_sda, i2c_scl); - if (!PMU->init()) { + if (!power) { + power = new XPowersAXP2101(Wire, i2c_sda, i2c_scl); + if (!power->init()) { Serial.printf("Warning: Failed to find AXP2101 power management\n"); - delete PMU; - PMU = NULL; + delete power; + power = NULL; } else { Serial.printf("AXP2101 PMU init succeeded, using AXP2101 PMU\n"); } } - if (!PMU) { - PMU = new XPowersAXP192(Wire, i2c_sda, i2c_scl); - if (!PMU->init()) { + if (!power) { + power = new XPowersAXP192(Wire, i2c_sda, i2c_scl); + if (!power->init()) { Serial.printf("Warning: Failed to find AXP192 power management\n"); - delete PMU; - PMU = NULL; + delete power; + power = NULL; } else { Serial.printf("AXP192 PMU init succeeded, using AXP192 PMU\n"); } } - if (!PMU) { - PMU = new XPowersAXP202(Wire, i2c_sda, i2c_scl); - if (!PMU->init()) { + if (!power) { + power = new XPowersAXP202(Wire, i2c_sda, i2c_scl); + if (!power->init()) { Serial.printf("Warning: Failed to find AXP202 power management\n"); - delete PMU; - PMU = NULL; + delete power; + power = NULL; } else { Serial.printf("AXP202 PMU init succeeded, using AXP202 PMU\n"); } } - if (!PMU) { + if (!power) { Serial.println("PMU not detected, please check.."); while (1)delay(50); } //The following AXP192 power supply setting voltage is based on esp32 T-beam - if (PMU->getChipModel() == XPOWERS_AXP192) { + if (power->getChipModel() == XPOWERS_AXP192) { // lora radio power channel - PMU->setPowerChannelVoltage(XPOWERS_LDO2, 3300); - PMU->enablePowerOutput(XPOWERS_LDO2); + power->setPowerChannelVoltage(XPOWERS_LDO2, 3300); + power->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); + power->setPowerChannelVoltage(XPOWERS_DCDC1, 3300); // enable oled power - PMU->enablePowerOutput(XPOWERS_DCDC1); + power->enablePowerOutput(XPOWERS_DCDC1); // gnss module power channel - PMU->setPowerChannelVoltage(XPOWERS_LDO3, 3300); - // PMU->enablePowerOutput(XPOWERS_LDO3); + power->setPowerChannelVoltage(XPOWERS_LDO3, 3300); + // power->enablePowerOutput(XPOWERS_LDO3); //protected oled power source - PMU->setProtectedChannel(XPOWERS_DCDC1); + power->setProtectedChannel(XPOWERS_DCDC1); //protected esp32 power source - PMU->setProtectedChannel(XPOWERS_DCDC3); + power->setProtectedChannel(XPOWERS_DCDC3); //disable not use channel - PMU->disablePowerOutput(XPOWERS_DCDC2); + power->disablePowerOutput(XPOWERS_DCDC2); //disable all axp chip interrupt - PMU->disableIRQ(XPOWERS_AXP192_ALL_IRQ); + power->disableIRQ(XPOWERS_AXP192_ALL_IRQ); // @@ -162,26 +162,26 @@ void setup() XPOWERS_AXP192_CHG_CUR_1240MA, XPOWERS_AXP192_CHG_CUR_1320MA, */ - PMU->setChargerConstantCurr(XPOWERS_AXP192_CHG_CUR_550MA); + power->setChargerConstantCurr(XPOWERS_AXP192_CHG_CUR_550MA); } // The following AXP202 power supply voltage setting is based on esp32 T-Watch - else if (PMU->getChipModel() == XPOWERS_AXP202) { + else if (power->getChipModel() == XPOWERS_AXP202) { - PMU->disablePowerOutput(XPOWERS_DCDC2); //not elicited + power->disablePowerOutput(XPOWERS_DCDC2); //not elicited //Display backlight - PMU->setPowerChannelVoltage(XPOWERS_LDO2, 3300); - PMU->enablePowerOutput(XPOWERS_LDO2); + power->setPowerChannelVoltage(XPOWERS_LDO2, 3300); + power->enablePowerOutput(XPOWERS_LDO2); // Shiled Vdd - PMU->setPowerChannelVoltage(XPOWERS_LDO3, 3300); - PMU->enablePowerOutput(XPOWERS_LDO3); + power->setPowerChannelVoltage(XPOWERS_LDO3, 3300); + power->enablePowerOutput(XPOWERS_LDO3); // S7xG GNSS Vdd - PMU->setPowerChannelVoltage(XPOWERS_LDO4, 1800); - PMU->enablePowerOutput(XPOWERS_LDO4); + power->setPowerChannelVoltage(XPOWERS_LDO4, 1800); + power->enablePowerOutput(XPOWERS_LDO4); // @@ -204,36 +204,36 @@ void setup() XPOWERS_AXP202_CHG_CUR_1240MA, XPOWERS_AXP202_CHG_CUR_1320MA, */ - PMU->setChargerConstantCurr(XPOWERS_AXP202_CHG_CUR_550MA); + power->setChargerConstantCurr(XPOWERS_AXP202_CHG_CUR_550MA); } // The following AXP192 power supply voltage setting is based on esp32s3 T-beam - else if (PMU->getChipModel() == XPOWERS_AXP2101) { + else if (power->getChipModel() == XPOWERS_AXP2101) { // gnss module power channel - PMU->setPowerChannelVoltage(XPOWERS_ALDO4, 3300); - PMU->enablePowerOutput(XPOWERS_ALDO4); + power->setPowerChannelVoltage(XPOWERS_ALDO4, 3300); + power->enablePowerOutput(XPOWERS_ALDO4); // lora radio power channel - PMU->setPowerChannelVoltage(XPOWERS_ALDO3, 3300); - PMU->enablePowerOutput(XPOWERS_ALDO3); + power->setPowerChannelVoltage(XPOWERS_ALDO3, 3300); + power->enablePowerOutput(XPOWERS_ALDO3); // m.2 interface - PMU->setPowerChannelVoltage(XPOWERS_DCDC3, 3300); - PMU->enablePowerOutput(XPOWERS_DCDC3); + power->setPowerChannelVoltage(XPOWERS_DCDC3, 3300); + power->enablePowerOutput(XPOWERS_DCDC3); - // PMU->setPowerChannelVoltage(XPOWERS_DCDC4, 3300); - // PMU->enablePowerOutput(XPOWERS_DCDC4); + // 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); + power->disablePowerOutput(XPOWERS_DCDC2); //not elicited + power->disablePowerOutput(XPOWERS_DCDC5); //not elicited + power->disablePowerOutput(XPOWERS_DLDO1); //Invalid power channel, it does not exist + power->disablePowerOutput(XPOWERS_DLDO2); //Invalid power channel, it does not exist + power->disablePowerOutput(XPOWERS_VBACKUP); //disable all axp chip interrupt - PMU->disableIRQ(XPOWERS_AXP2101_ALL_IRQ); + power->disableIRQ(XPOWERS_AXP2101_ALL_IRQ); /* Set the constant current charging current of AXP2101 opt: @@ -251,72 +251,72 @@ void setup() XPOWERS_AXP2101_CHG_CUR_900MA, XPOWERS_AXP2101_CHG_CUR_1000MA, */ - PMU->setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_500MA); + power->setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_500MA); } Serial.println("=======================================================================\n"); - if (PMU->isChannelAvailable(XPOWERS_DCDC1)) { - Serial.printf("DC1 : %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_DCDC1) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_DCDC1)); + if (power->isChannelAvailable(XPOWERS_DCDC1)) { + Serial.printf("DC1 : %s Voltage:%u mV \n", power->isPowerChannelEnable(XPOWERS_DCDC1) ? "+" : "-", power->getPowerChannelVoltage(XPOWERS_DCDC1)); } - if (PMU->isChannelAvailable(XPOWERS_DCDC2)) { - Serial.printf("DC2 : %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_DCDC2) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_DCDC2)); + if (power->isChannelAvailable(XPOWERS_DCDC2)) { + Serial.printf("DC2 : %s Voltage:%u mV \n", power->isPowerChannelEnable(XPOWERS_DCDC2) ? "+" : "-", power->getPowerChannelVoltage(XPOWERS_DCDC2)); } - if (PMU->isChannelAvailable(XPOWERS_DCDC3)) { - Serial.printf("DC3 : %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_DCDC3) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_DCDC3)); + if (power->isChannelAvailable(XPOWERS_DCDC3)) { + Serial.printf("DC3 : %s Voltage:%u mV \n", power->isPowerChannelEnable(XPOWERS_DCDC3) ? "+" : "-", power->getPowerChannelVoltage(XPOWERS_DCDC3)); } - if (PMU->isChannelAvailable(XPOWERS_DCDC4)) { - Serial.printf("DC4 : %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_DCDC4) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_DCDC4)); + if (power->isChannelAvailable(XPOWERS_DCDC4)) { + Serial.printf("DC4 : %s Voltage:%u mV \n", power->isPowerChannelEnable(XPOWERS_DCDC4) ? "+" : "-", power->getPowerChannelVoltage(XPOWERS_DCDC4)); } - if (PMU->isChannelAvailable(XPOWERS_LDO2)) { - Serial.printf("LDO2 : %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_LDO2) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_LDO2)); + if (power->isChannelAvailable(XPOWERS_LDO2)) { + Serial.printf("LDO2 : %s Voltage:%u mV \n", power->isPowerChannelEnable(XPOWERS_LDO2) ? "+" : "-", power->getPowerChannelVoltage(XPOWERS_LDO2)); } - if (PMU->isChannelAvailable(XPOWERS_LDO3)) { - Serial.printf("LDO3 : %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_LDO3) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_LDO3)); + if (power->isChannelAvailable(XPOWERS_LDO3)) { + Serial.printf("LDO3 : %s Voltage:%u mV \n", power->isPowerChannelEnable(XPOWERS_LDO3) ? "+" : "-", power->getPowerChannelVoltage(XPOWERS_LDO3)); } - if (PMU->isChannelAvailable(XPOWERS_LDO4)) { - Serial.printf("LDO4 : %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_LDO4) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_LDO4)); + if (power->isChannelAvailable(XPOWERS_LDO4)) { + Serial.printf("LDO4 : %s Voltage:%u mV \n", power->isPowerChannelEnable(XPOWERS_LDO4) ? "+" : "-", power->getPowerChannelVoltage(XPOWERS_LDO4)); } - if (PMU->isChannelAvailable(XPOWERS_LDO5)) { - Serial.printf("LDO5 : %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_LDO5) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_LDO5)); + if (power->isChannelAvailable(XPOWERS_LDO5)) { + Serial.printf("LDO5 : %s Voltage:%u mV \n", power->isPowerChannelEnable(XPOWERS_LDO5) ? "+" : "-", power->getPowerChannelVoltage(XPOWERS_LDO5)); } - if (PMU->isChannelAvailable(XPOWERS_ALDO1)) { - Serial.printf("ALDO1: %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_ALDO1) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_ALDO1)); + if (power->isChannelAvailable(XPOWERS_ALDO1)) { + Serial.printf("ALDO1: %s Voltage:%u mV \n", power->isPowerChannelEnable(XPOWERS_ALDO1) ? "+" : "-", power->getPowerChannelVoltage(XPOWERS_ALDO1)); } - if (PMU->isChannelAvailable(XPOWERS_ALDO2)) { - Serial.printf("ALDO2: %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_ALDO2) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_ALDO2)); + if (power->isChannelAvailable(XPOWERS_ALDO2)) { + Serial.printf("ALDO2: %s Voltage:%u mV \n", power->isPowerChannelEnable(XPOWERS_ALDO2) ? "+" : "-", power->getPowerChannelVoltage(XPOWERS_ALDO2)); } - if (PMU->isChannelAvailable(XPOWERS_ALDO3)) { - Serial.printf("ALDO3: %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_ALDO3) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_ALDO3)); + if (power->isChannelAvailable(XPOWERS_ALDO3)) { + Serial.printf("ALDO3: %s Voltage:%u mV \n", power->isPowerChannelEnable(XPOWERS_ALDO3) ? "+" : "-", power->getPowerChannelVoltage(XPOWERS_ALDO3)); } - if (PMU->isChannelAvailable(XPOWERS_ALDO4)) { - Serial.printf("ALDO4: %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_ALDO4) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_ALDO4)); + if (power->isChannelAvailable(XPOWERS_ALDO4)) { + Serial.printf("ALDO4: %s Voltage:%u mV \n", power->isPowerChannelEnable(XPOWERS_ALDO4) ? "+" : "-", power->getPowerChannelVoltage(XPOWERS_ALDO4)); } - if (PMU->isChannelAvailable(XPOWERS_BLDO1)) { - Serial.printf("BLDO1: %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_BLDO1) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_BLDO1)); + if (power->isChannelAvailable(XPOWERS_BLDO1)) { + Serial.printf("BLDO1: %s Voltage:%u mV \n", power->isPowerChannelEnable(XPOWERS_BLDO1) ? "+" : "-", power->getPowerChannelVoltage(XPOWERS_BLDO1)); } - if (PMU->isChannelAvailable(XPOWERS_BLDO2)) { - Serial.printf("BLDO2: %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_BLDO2) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_BLDO2)); + if (power->isChannelAvailable(XPOWERS_BLDO2)) { + Serial.printf("BLDO2: %s Voltage:%u mV \n", power->isPowerChannelEnable(XPOWERS_BLDO2) ? "+" : "-", power->getPowerChannelVoltage(XPOWERS_BLDO2)); } Serial.println("=======================================================================\n"); //Set up the charging voltage, AXP2101/AXP192 4.2V gear is the same // XPOWERS_AXP192_CHG_VOL_4V2 = XPOWERS_AXP2101_CHG_VOL_4V2 - PMU->setChargeTargetVoltage(XPOWERS_AXP192_CHG_VOL_4V2); + power->setChargeTargetVoltage(XPOWERS_AXP192_CHG_VOL_4V2); // Set VSY off voltage as 2600mV , Adjustment range 2600mV ~ 3300mV - PMU->setSysPowerDownVoltage(2600); + power->setSysPowerDownVoltage(2600); // Get the VSYS shutdown voltage - uint16_t vol = PMU->getSysPowerDownVoltage(); + uint16_t vol = power->getSysPowerDownVoltage(); Serial.printf("-> getSysPowerDownVoltage:%u\n", vol); // Set the time of pressing the button to turn off - PMU->setPowerKeyPressOffTime(XPOWERS_POWEROFF_4S); - uint8_t opt = PMU->getPowerKeyPressOffTime(); + power->setPowerKeyPressOffTime(XPOWERS_POWEROFF_4S); + uint8_t opt = power->getPowerKeyPressOffTime(); Serial.print("PowerKeyPressOffTime:"); switch (opt) { case XPOWERS_POWEROFF_4S: Serial.println("4 Second"); @@ -332,8 +332,8 @@ void setup() } // Set the button power-on press time - PMU->setPowerKeyPressOnTime(XPOWERS_POWERON_128MS); - opt = PMU->getPowerKeyPressOnTime(); + power->setPowerKeyPressOnTime(XPOWERS_POWERON_128MS); + opt = power->getPowerKeyPressOnTime(); Serial.print("PowerKeyPressOnTime:"); switch (opt) { case XPOWERS_POWERON_128MS: Serial.println("128 Ms"); @@ -352,13 +352,13 @@ void setup() // It is necessary to disable the detection function of the TS pin on the board // without the battery temperature detection function, otherwise it will cause abnormal charging - PMU->disableTSPinMeasure(); + power->disableTSPinMeasure(); // Enable internal ADC detection - PMU->enableBattDetection(); - PMU->enableVbusVoltageMeasure(); - PMU->enableBattVoltageMeasure(); - PMU->enableSystemVoltageMeasure(); + power->enableBattDetection(); + power->enableVbusVoltageMeasure(); + power->enableBattVoltageMeasure(); + power->enableSystemVoltageMeasure(); /* @@ -369,14 +369,14 @@ void setup() - XPOWERS_CHG_LED_ON, - XPOWERS_CHG_LED_CTRL_CHG, * */ - PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF); + power->setChargingLedMode(XPOWERS_CHG_LED_OFF); pinMode(pmu_irq_pin, INPUT); attachInterrupt(pmu_irq_pin, setFlag, FALLING); // Clear all interrupt flags - PMU->clearIrqStatus(); + power->clearIrqStatus(); /* @@ -384,13 +384,13 @@ void setup() uint64_t pmuIrqMask = 0; - if (PMU->getChipModel() == XPOWERS_AXP192) { + if (power->getChipModel() == XPOWERS_AXP192) { pmuIrqMask = XPOWERS_AXP192_VBUS_INSERT_IRQ | XPOWERS_AXP192_VBUS_REMOVE_IRQ | //BATTERY XPOWERS_AXP192_BAT_INSERT_IRQ | XPOWERS_AXP192_BAT_REMOVE_IRQ | //VBUS XPOWERS_AXP192_PKEY_SHORT_IRQ | XPOWERS_AXP192_PKEY_LONG_IRQ | //POWER KEY XPOWERS_AXP192_BAT_CHG_START_IRQ | XPOWERS_AXP192_BAT_CHG_DONE_IRQ ; //CHARGE - } else if (PMU->getChipModel() == XPOWERS_AXP2101) { + } else if (power->getChipModel() == XPOWERS_AXP2101) { pmuIrqMask = XPOWERS_AXP2101_BAT_INSERT_IRQ | XPOWERS_AXP2101_BAT_REMOVE_IRQ | //BATTERY XPOWERS_AXP2101_VBUS_INSERT_IRQ | XPOWERS_AXP2101_VBUS_REMOVE_IRQ | //VBUS @@ -398,14 +398,14 @@ void setup() XPOWERS_AXP2101_BAT_CHG_DONE_IRQ | XPOWERS_AXP2101_BAT_CHG_START_IRQ; //CHARGE } // Enable the required interrupt function - PMU->enableIRQ(pmuIrqMask); + power->enableIRQ(pmuIrqMask); */ // Call the interrupt request through the interface class - PMU->disableInterrupt(XPOWERS_ALL_INT); + power->disableInterrupt(XPOWERS_ALL_INT); - PMU->enableInterrupt(XPOWERS_USB_INSERT_INT | + power->enableInterrupt(XPOWERS_USB_INSERT_INT | XPOWERS_USB_REMOVE_INT | XPOWERS_BATTERY_INSERT_INT | XPOWERS_BATTERY_REMOVE_INT | @@ -416,18 +416,18 @@ void setup() void 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"); + Serial.print("isCharging:"); Serial.println(power->isCharging() ? "YES" : "NO"); + Serial.print("isDischarge:"); Serial.println(power->isDischarge() ? "YES" : "NO"); + Serial.print("isVbusIn:"); Serial.println(power->isVbusIn() ? "YES" : "NO"); + Serial.print("getBattVoltage:"); Serial.print(power->getBattVoltage()); Serial.println("mV"); + Serial.print("getVbusVoltage:"); Serial.print(power->getVbusVoltage()); Serial.println("mV"); + Serial.print("getSystemVoltage:"); Serial.print(power->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("%"); + if (power->isBatteryConnect()) { + Serial.print("getBatteryPercent:"); Serial.print(power->getBatteryPercent()); Serial.println("%"); } Serial.println(); @@ -443,38 +443,38 @@ void loop() pmu_flag = false; // Get PMU Interrupt Status Register - uint32_t status = PMU->getIrqStatus(); + uint32_t status = power->getIrqStatus(); Serial.print("STATUS => HEX:"); Serial.print(status, HEX); Serial.print(" BIN:"); Serial.println(status, BIN); - if (PMU->isVbusInsertIrq()) { + if (power->isVbusInsertIrq()) { Serial.println("isVbusInsert"); } - if (PMU->isVbusRemoveIrq()) { + if (power->isVbusRemoveIrq()) { Serial.println("isVbusRemove"); } - if (PMU->isBatInsertIrq()) { + if (power->isBatInsertIrq()) { Serial.println("isBatInsert"); } - if (PMU->isBatRemoveIrq()) { + if (power->isBatRemoveIrq()) { Serial.println("isBatRemove"); } - if (PMU->isPekeyShortPressIrq()) { + if (power->isPekeyShortPressIrq()) { Serial.println("isPekeyShortPress"); } - if (PMU->isPekeyLongPressIrq()) { + if (power->isPekeyLongPressIrq()) { Serial.println("isPekeyLongPress"); } - if (PMU->isBatChagerDoneIrq()) { + if (power->isBatChagerDoneIrq()) { Serial.println("isBatChagerDone"); } - if (PMU->isBatChagerStartIrq()) { + if (power->isBatChagerStartIrq()) { Serial.println("isBatChagerStart"); } // Clear PMU Interrupt Status Register - PMU->clearIrqStatus(); + power->clearIrqStatus(); } delay(10);