Skip to content

Commit

Permalink
Rename the example variable names #23
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Jul 8, 2024
1 parent d0751fb commit 14ff5da
Show file tree
Hide file tree
Showing 13 changed files with 978 additions and 978 deletions.
208 changes: 104 additions & 104 deletions examples/AXP192_Example/AXP192_Example.ino

Large diffs are not rendered by default.

202 changes: 101 additions & 101 deletions examples/AXP202_Example/AXP202_Example.ino

Large diffs are not rendered by default.

64 changes: 32 additions & 32 deletions examples/AXP2101_ADC_Example/AXP2101_ADC_Example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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
);

Expand All @@ -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();
Expand All @@ -130,27 +130,27 @@ 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 {
adcOff(); Serial.println("Disable ADC\n\n\n");
}
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) {
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]);
}

Expand All @@ -82,47 +82,47 @@ 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) {
delay(5000);
}
}

// 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.
Expand All @@ -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();
}
Expand All @@ -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();
Expand All @@ -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);
Expand Down
Loading

0 comments on commit 14ff5da

Please sign in to comment.