Update XPowersLib

This commit is contained in:
lewishe 2023-05-23 14:04:49 +08:00
commit c37a356774
28 changed files with 2965 additions and 137 deletions

View file

@ -0,0 +1,31 @@
name: PlatformIO CI
on: [push,pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
example: [examples/AXP192_Example/AXP192_Example.ino,examples/AXP202_Example/AXP202_Example.ino,examples/AXP2101_Charge_Example/AXP2101_Charge_Example.ino,examples/AXP2101_Example/AXP2101_Example.ino,examples/AXP2101_InterruptExample/AXP2101_InterruptExample.ino,examples/AXP2101_Voltage_Example/AXP2101_Voltage_Example.ino,examples/XPowersLibInterface_Example/XPowersLibInterface_Example.ino]
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install PlatformIO Core
run: pip install --upgrade platformio
- name: Run PlatformIO
run: pio ci --lib="." --board=esp32dev --board=esp32-c3-devkitm-1
env:
PLATFORMIO_BUILD_FLAGS: -D XPOWERS_NO_ERROR
PLATFORMIO_CI_SRC: ${{ matrix.example }}

View file

@ -2,12 +2,12 @@ menu "XPowersLib Configuration"
choice PMU_Type
prompt "XPowers chip type"
default XPOWERS_CHIP_AXP2102 if IDF_TARGET_ESP32
default XPOWERS_CHIP_AXP2101 if IDF_TARGET_ESP32
default XPOWERS_CHIP_AXP192
help
Defines the default peripheral for xpowers example
config XPOWERS_CHIP_AXP2102
config XPOWERS_CHIP_AXP2101
bool "Xpowers AXP2101"
config XPOWERS_CHIP_AXP192
bool "Xpowers AXP192"

View file

@ -551,7 +551,7 @@ class AXP2101(I2CInterface):
return bool(super().getRegisterBit(_AXP2101_STATUS2, 3) == 0)
def getChargerStatus(self) -> None:
return super().readRegister(_AXP2101_THE_REGU_THRES_SET)[0] & 0x07
return super().readRegister(_AXP2101_STATUS2)[0] & 0x07
# Data Buffer
def writeDataBuffer(self, data: list, size: int) -> None:
@ -612,7 +612,7 @@ class AXP2101(I2CInterface):
super().setRegisterBit(_AXP2101_BATFET_CTRL, 0)
def disableBatfetDieOverTempDetect(self) -> None:
super().setRegisterBit(_AXP2101_BATFET_CTRL, 0)
super().clrRegisterBit(_AXP2101_BATFET_CTRL, 0)
# @param opt: 0:115 , 1:125 , 2:135
def setDieOverTempLevel1(self, opt: int) -> None:
@ -629,7 +629,7 @@ class AXP2101(I2CInterface):
super().setRegisterBit(_AXP2101_DIE_TEMP_CTRL, 0)
def disableDieOverTempDetect(self) -> None:
super().setRegisterBit(_AXP2101_DIE_TEMP_CTRL, 0)
super().clrRegisterBit(_AXP2101_DIE_TEMP_CTRL, 0)
# Linear Charger Vsys voltage dpm
def setLinearChargerVsysDpm(self, opt: int) -> None:
@ -1944,9 +1944,21 @@ class AXP2101(I2CInterface):
def getBatteryParameter(self) -> int:
return super().readRegister(_AXP2101_BAT_PARAME)[0]
def fuelGaugeControl(self, writeROM: bool, enable: bool) -> int:
if writeROM:
super().clrRegisterBit(_AXP2101_FUEL_GAUGE_CTRL, 4)
else:
super().setRegisterBit(_AXP2101_FUEL_GAUGE_CTRL, 4)
if enable:
super().setRegisterBit(_AXP2101_FUEL_GAUGE_CTRL, 0)
else:
super().clrRegisterBit(_AXP2101_FUEL_GAUGE_CTRL, 0)
# Interrupt status/control functions
# @brief Get the interrupt controller mask value.
# @retval Mask value corresponds to _axp2101_irq_t ,
def getIrqStatus(self) -> int:
self.statusRegister = super().readRegister(_AXP2101_INTSTS1, 3)
return (self.statusRegister[0] << 16) | (self.statusRegister[1] << 8) | (self.statusRegister[2])

View file

@ -32,31 +32,30 @@ if there is any loss,please bear it by yourself
✨ Through esp32,esp32s3 verification,other platforms have not been tested. Due to the many functions of the chip,it cannot be verified one by one.
✨ At present, other XPowers models except AXP2101 have been discontinued and are not supported for the time being
# Chip Resource List
| CHIP | AXP192 | AXP2101 | Remarks |
| ---------- | ----------------- | -------------------------------------- | ---------------- |
| DC1 | 0.7V-3.5V /1.2A | 1.5-3.4V /2A | |
| DC2 | 0.7-2.275V /1.6A | 0.5-1.2V,1.22-1.54V /2A | |
| DC3 | 0.7-3.5V /0.7A | 0.5-1.2V,1.22-1.54V,1.6-3.4V /2A | |
| DC4 | x | 0.5-1.2V,1.22-1.84V /1.5A | |
| DC5 | x | 1.2V,1.4-3.7V /1A | |
| LDO1(VRTC) | 3.3V /30mA | 1.8V /30mA | |
| LDO2 | 1.8V-3.3V /200mA | x | |
| LDO3 | 1.8-3.3V /200mA | x | |
| LDO4 | X | x | |
| LDO5/IO0 | 1.8-3.3V /50mA | x | |
| ALDO1 | x | 0.5-3.5V /300mA | |
| ALDO2 | x | 0.5-3.5V /300mA | |
| ALDO3 | x | 0.5-3.5V /300mA | |
| ALDO4 | x | 0.5-3.5V /300mA | |
| BLDO1 | x | 0.5-3.5V /300mA | |
| BLDO2 | x | 0.5-3.5V /300mA | |
| DLDO1 | x | 0.5-3.3V/ 0.5-1.4V /300mA | |
| DLDO1 | x | 0.5-3.3V/ 0.5-1.4V /300mA | |
| CPUSLDO | x | 0.5-1.4V /30mA | Dependent on DC4 |
| CHIP | AXP192 | AXP202 | AXP2101 | Remarks |
| ---------- | ----------------- | ----------------- | -------------------------------------- | ---------------- |
| DC1 | 0.7V-3.5V /1.2A | X | 1.5-3.4V /2A | |
| DC2 | 0.7-2.275V /1.6A | 0.7-2.275V /1.6A | 0.5-1.2V,1.22-1.54V /2A | |
| DC3 | 0.7-3.5V /0.7A | 0.7-3.5V /1.2A | 0.5-1.2V,1.22-1.54V,1.6-3.4V /2A | |
| DC4 | x | x | 0.5-1.2V,1.22-1.84V /1.5A | |
| DC5 | x | x | 1.2V,1.4-3.7V /1A | |
| LDO1(VRTC) | 3.3V /30mA | 3.3V /30mA | 1.8V /30mA | |
| LDO2 | 1.8V-3.3V /200mA | 1.8V-3.3V /200mA | x | |
| LDO3 | 1.8-3.3V /200mA | 0.7-3.5V /200mA | x | |
| LDO4 | X | 1.8V-3.3V /200mA | x | |
| LDO5/IO0 | 1.8-3.3V /50mA | 1.8-3.3V /50mA | x | |
| ALDO1 | x | x | 0.5-3.5V /300mA | |
| ALDO2 | x | x | 0.5-3.5V /300mA | |
| ALDO3 | x | x | 0.5-3.5V /300mA | |
| ALDO4 | x | x | 0.5-3.5V /300mA | |
| BLDO1 | x | x | 0.5-3.5V /300mA | |
| BLDO2 | x | x | 0.5-3.5V /300mA | |
| DLDO1 | x | x | 0.5-3.3V/ 0.5-1.4V /300mA | |
| DLDO1 | x | x | 0.5-3.3V/ 0.5-1.4V /300mA | |
| CPUSLDO | x | x | 0.5-1.4V /30mA | Dependent on DC4 |
# AXP2101 Notes:

Binary file not shown.

Binary file not shown.

View file

@ -28,7 +28,9 @@ Please do not run the example without knowing the external load voltage of the P
it may burn your external load, please check the voltage setting before running the example,
if there is any loss, please bear it by yourself
*/
#ifndef XPOWERS_NO_ERROR
#error "Running this example is known to not damage the device! Please go and uncomment this!"
#endif
// Defined using AXP192
#define XPOWERS_CHIP_AXP192

View file

@ -0,0 +1,403 @@
/*
MIT License
Copyright (c) 2022 lewis he
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*
! WARN:
Please do not run the example without knowing the external load voltage of the PMU,
it may burn your external load, please check the voltage setting before running the example,
if there is any loss, please bear it by yourself
*/
#ifndef XPOWERS_NO_ERROR
#error "Running this example is known to not damage the device! Please go and uncomment this!"
#endif
#define XPOWERS_CHIP_AXP202
#include <Wire.h>
#include <Arduino.h>
#include "XPowersLib.h"
#ifndef CONFIG_PMU_SDA
#define CONFIG_PMU_SDA 21
#endif
#ifndef CONFIG_PMU_SCL
#define CONFIG_PMU_SCL 22
#endif
#ifndef CONFIG_PMU_IRQ
#define CONFIG_PMU_IRQ 35
#endif
bool pmu_flag = 0;
XPowersPMU PMU;
const uint8_t i2c_sda = CONFIG_PMU_SDA;
const uint8_t i2c_scl = CONFIG_PMU_SCL;
const uint8_t pmu_irq_pin = CONFIG_PMU_IRQ;
void setFlag(void)
{
pmu_flag = true;
}
void setup()
{
Serial.begin(115200);
bool result = PMU.begin(Wire, AXP202_SLAVE_ADDRESS, i2c_sda, i2c_scl);
if (result == false) {
Serial.println("PMU is not online..."); while (1)delay(50);
}
Serial.printf("getID:0x%x\n", PMU.getChipID());
// Set the minimum system operating voltage inside the PMU,
// below this value will shut down the PMU
// Range: 2600~3300mV
PMU.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);
// Turn off USB input current limit
PMU.setVbusCurrentLimit(XPOWERS_AXP202_VBUS_CUR_LIM_OFF);
// DC2 700~3500 mV, IMAX=1.6A;
PMU.setDC2Voltage(700);
// DC3 700~3500 mV,IMAX=0.7A;
PMU.setDC3Voltage(3300);
//LDO2 1800~3300 mV, 100mV/step, IMAX=200mA
PMU.setLDO2Voltage(1800);
//LDO3 700~2275 mV, 100mV/step, IMAX=200mA
PMU.setLDO3Voltage(1800);
/* LDO4 Range:
1250, 1300, 1400, 1500, 1600, 1700, 1800, 1900,
2000, 2500, 2700, 2800, 3000, 3100, 3200, 3300
*/
PMU.setLDO4Voltage(3300);
//LDOio 1800~3300 mV, 100mV/step, IMAX=50mA
PMU.setLDOioVoltage(3300);
// Enable power output channel
PMU.enableDC2();
// PMU.enableDC3();
PMU.enableLDO2();
PMU.enableLDO3();
PMU.enableLDO4();
PMU.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.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.println("==========================================================================");
// Set the time of pressing the button to turn off
PMU.setPowerKeyPressOffTime(XPOWERS_AXP202_POWEROFF_4S);
uint8_t opt = PMU.getPowerKeyPressOffTime();
Serial.print("PowerKeyPressOffTime:");
switch (opt) {
case XPOWERS_AXP202_POWEROFF_4S: Serial.println("4 Second");
break;
case XPOWERS_AXP202_POWEROFF_65: Serial.println("6 Second");
break;
case XPOWERS_AXP202_POWEROFF_8S: Serial.println("8 Second");
break;
case XPOWERS_AXP202_POWEROFF_10S: Serial.println("10 Second");
break;
default:
break;
}
// Set the button power-on press time
PMU.setPowerKeyPressOnTime(XPOWERS_POWERON_128MS);
opt = PMU.getPowerKeyPressOnTime();
Serial.print("PowerKeyPressOnTime:");
switch (opt) {
case XPOWERS_POWERON_128MS: Serial.println("128 Ms");
break;
case XPOWERS_POWERON_512MS: Serial.println("512 Ms");
break;
case XPOWERS_POWERON_1S: Serial.println("1 Second");
break;
case XPOWERS_POWERON_2S: Serial.println("2 Second");
break;
default:
break;
}
Serial.println("===========================================================================");
// 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();
// PMU.enableTemperatureMeasure();
// PMU.disableTemperatureMeasure();
// Enable internal ADC detection
PMU.enableBattDetection();
PMU.enableVbusVoltageMeasure();
PMU.enableBattVoltageMeasure();
PMU.enableSystemVoltageMeasure();
/*
The default setting is CHGLED is automatically controlled by the PMU.
- 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_OFF);
pinMode(pmu_irq_pin, INPUT);
attachInterrupt(pmu_irq_pin, setFlag, FALLING);
// Disable all interrupts
PMU.disableIRQ(XPOWERS_AXP202_ALL_IRQ);
// Clear all interrupt flags
PMU.clearIrqStatus();
// Enable the required interrupt function
PMU.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
XPOWERS_AXP202_BAT_CHG_DONE_IRQ | XPOWERS_AXP202_BAT_CHG_START_IRQ | //CHARGE
// XPOWERS_AXP202_PKEY_NEGATIVE_IRQ | XPOWERS_AXP202_PKEY_POSITIVE_IRQ | //POWER KEY
XPOWERS_AXP202_TIMER_TIMEOUT_IRQ //Timer
);
// Set constant current charge current limit
PMU.setChargerConstantCurr(XPOWERS_AXP202_CHG_CUR_280MA);
// Set stop charging termination current
PMU.setChargerTerminationCurr(XPOWERS_AXP202_CHG_ITERM_LESS_10_PERCENT);
// Set charge cut-off voltage
PMU.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);
memset(data, 0, XPOWERS_AXP202_DATA_BUFFER_SIZE);
Serial.print("Read pmu data buffer :");
PMU.readDataBuffer(data, XPOWERS_AXP202_DATA_BUFFER_SIZE);
for (int i = 0; i < XPOWERS_AXP202_DATA_BUFFER_SIZE; ++i) {
Serial.print(data[i]);
Serial.print(",");
}
Serial.println();
// Set the timing after one minute, the isWdtExpireIrq will be triggered in the loop interrupt function
PMU.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.println();
}
void enterPmuSleep(void)
{
// Set sleep flag
PMU.enableSleep();
PMU.disableDC2();
PMU.disableLDO2();
PMU.disableLDO3();
// Finally, turn off the power of the control chip
PMU.disableDC3();
}
void loop()
{
if (pmu_flag) {
pmu_flag = false;
// Get PMU Interrupt Status Register
uint32_t status = PMU.getIrqStatus();
Serial.print("STATUS => HEX:");
Serial.print(status, HEX);
Serial.print(" BIN:");
Serial.println(status, BIN);
if (PMU.isAcinOverVoltageIrq()) {
Serial.println("isAcinOverVoltageIrq");
}
if (PMU.isAcinInserIrq()) {
Serial.println("isAcinInserIrq");
}
if (PMU.isAcinRemoveIrq()) {
Serial.println("isAcinRemoveIrq");
}
if (PMU.isVbusOverVoltageIrq()) {
Serial.println("isVbusOverVoltageIrq");
}
if (PMU.isVbusInsertIrq()) {
Serial.println("isVbusInsertIrq");
}
if (PMU.isVbusRemoveIrq()) {
Serial.println("isVbusRemoveIrq");
}
if (PMU.isVbusLowVholdIrq()) {
Serial.println("isVbusLowVholdIrq");
}
if (PMU.isBatInsertIrq()) {
Serial.println("isBatInsertIrq");
}
if (PMU.isBatRemoveIrq()) {
Serial.println("isBatRemoveIrq");
}
if (PMU.isBattEnterActivateIrq()) {
Serial.println("isBattEnterActivateIrq");
}
if (PMU.isBattExitActivateIrq()) {
Serial.println("isBattExitActivateIrq");
}
if (PMU.isBatChagerStartIrq()) {
Serial.println("isBatChagerStartIrq");
}
if (PMU.isBatChagerDoneIrq()) {
Serial.println("isBatChagerDoneIrq");
}
if (PMU.isBattTempHighIrq()) {
Serial.println("isBattTempHighIrq");
}
if (PMU.isBattTempLowIrq()) {
Serial.println("isBattTempLowIrq");
}
if (PMU.isChipOverTemperatureIrq()) {
Serial.println("isChipOverTemperatureIrq");
}
if (PMU.isChargingCurrentLessIrq()) {
Serial.println("isChargingCurrentLessIrq");
}
if (PMU.isDC1VoltageLessIrq()) {
Serial.println("isDC1VoltageLessIrq");
}
if (PMU.isDC2VoltageLessIrq()) {
Serial.println("isDC2VoltageLessIrq");
}
if (PMU.isDC3VoltageLessIrq()) {
Serial.println("isDC3VoltageLessIrq");
}
if (PMU.isPekeyShortPressIrq()) {
Serial.println("isPekeyShortPress");
// enterPmuSleep();
//CHG LED mode test
uint8_t m = PMU.getChargingLedMode();
Serial.print("getChargingLedMode:");
Serial.println(m++);
m %= XPOWERS_CHG_LED_CTRL_CHG;
Serial.printf("setChargingLedMode:%u", m);
PMU.setChargingLedMode(m);
}
if (PMU.isPekeyLongPressIrq()) {
Serial.println("isPekeyLongPress");
}
if (PMU.isNOEPowerOnIrq()) {
Serial.println("isNOEPowerOnIrq");
}
if (PMU.isNOEPowerDownIrq()) {
Serial.println("isNOEPowerDownIrq");
}
if (PMU.isVbusEffectiveIrq()) {
Serial.println("isVbusEffectiveIrq");
}
if (PMU.isVbusInvalidIrq()) {
Serial.println("isVbusInvalidIrq");
}
if (PMU.isVbusSessionIrq()) {
Serial.println("isVbusSessionIrq");
}
if (PMU.isVbusSessionEndIrq()) {
Serial.println("isVbusSessionEndIrq");
}
if (PMU.isLowVoltageLevel2Irq()) {
Serial.println("isLowVoltageLevel2Irq");
}
if (PMU.isWdtExpireIrq()) {
Serial.println("isWdtExpire");
printPMU();
// Clear the timer state and continue to the next timer
PMU.clearTimerFlag();
}
if (PMU.isGpio2EdgeTriggerIrq()) {
Serial.println("isGpio2EdgeTriggerIrq");
}
if (PMU.isGpio1EdgeTriggerIrq()) {
Serial.println("isGpio1EdgeTriggerIrq");
}
if (PMU.isGpio0EdgeTriggerIrq()) {
Serial.println("isGpio0EdgeTriggerIrq");
}
// Clear PMU Interrupt Status Register
PMU.clearIrqStatus();
}
delay(10);
}

View file

@ -0,0 +1,326 @@
/*
MIT License
Copyright (c) 2022 lewis he
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*
! WARN:
Please do not run the example without knowing the external load voltage of the PMU,
it may burn your external load, please check the voltage setting before running the example,
if there is any loss, please bear it by yourself
*/
#ifndef XPOWERS_NO_ERROR
#error "Running this example is known to not damage the device! Please go and uncomment this!"
#endif
// Defined using AXP2102
#define XPOWERS_CHIP_AXP2101
#include <Wire.h>
#include <Arduino.h>
#include "XPowersLib.h"
#ifndef CONFIG_PMU_SDA
#define CONFIG_PMU_SDA 21
#endif
#ifndef CONFIG_PMU_SCL
#define CONFIG_PMU_SCL 22
#endif
#ifndef CONFIG_PMU_IRQ
#define CONFIG_PMU_IRQ 35
#endif
bool pmu_flag = 0;
XPowersPMU PMU;
const uint8_t i2c_sda = CONFIG_PMU_SDA;
const uint8_t i2c_scl = CONFIG_PMU_SCL;
const uint8_t pmu_irq_pin = CONFIG_PMU_IRQ;
void setFlag(void)
{
pmu_flag = true;
}
void setup()
{
Serial.begin(115200);
bool result = PMU.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl);
if (result == false) {
Serial.println("PMU is not online..."); while (1)delay(50);
}
Serial.printf("getID:0x%x\n", PMU.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);
// 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);
// Get the VSYS shutdown voltage
uint16_t vol = PMU.getSysPowerDownVoltage();
Serial.printf("-> getSysPowerDownVoltage:%u\n", vol);
// Set VSY off voltage as 2600mV , Adjustment range 2600mV ~ 3300mV
PMU.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();
// PMU.enableTemperatureMeasure();
// Enable internal ADC detection
PMU.enableBattDetection();
PMU.enableVbusVoltageMeasure();
PMU.enableBattVoltageMeasure();
PMU.enableSystemVoltageMeasure();
/*
The default setting is CHGLED is automatically controlled by the PMU.
- 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_CTRL_CHG);
// Force add pull-up
pinMode(pmu_irq_pin, INPUT_PULLUP);
attachInterrupt(pmu_irq_pin, setFlag, FALLING);
// Disable all interrupts
PMU.disableIRQ(XPOWERS_AXP2101_ALL_IRQ);
// Clear all interrupt flags
PMU.clearIrqStatus();
// Enable the required interrupt function
PMU.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
XPOWERS_AXP2101_WARNING_LEVEL1_IRQ | XPOWERS_AXP2101_WARNING_LEVEL2_IRQ //Low battery warning
// XPOWERS_AXP2101_PKEY_NEGATIVE_IRQ | XPOWERS_AXP2101_PKEY_POSITIVE_IRQ | //POWER KEY
);
// Set the precharge charging current
PMU.setPrechargeCurr(XPOWERS_AXP2101_PRECHARGE_200MA);
// Set stop charging termination current
PMU.setChargerTerminationCurr(XPOWERS_AXP2101_CHG_ITERM_25MA);
// Set constant current charge current limit
if (!PMU.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();
Serial.print("Setting Charge Target Current : ");
Serial.println(currTable[val]);
// Set charge cut-off voltage
PMU.setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V2);
const uint16_t tableVoltage[] = {
0, 4000, 4100, 4200, 4350, 4400, 255
};
val = PMU.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);
// Set the power level to be lower than 5% and turn off the power supply
PMU.setLowBatShutdownThreshold(5);
/*
Turn on the learning battery curve,
And write the learned battery curve into the ROM
*/
PMU.fuelGaugeControl(true, true);
Serial.println();
delay(5000);
}
void printPMU()
{
Serial.println("---------------------------------------------------------------------------------------------------------");
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();
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");
// 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");
uint8_t charge_status = PMU.getChargerStatus();
if (charge_status == XPOWERS_AXP2101_CHG_TRI_STATE) {
Serial.println("tri_charge");
} else if (charge_status == XPOWERS_AXP2101_CHG_PRE_STATE) {
Serial.println("pre_charge");
} else if (charge_status == XPOWERS_AXP2101_CHG_CC_STATE) {
Serial.println("constant charge(CC)");
} else if (charge_status == XPOWERS_AXP2101_CHG_CV_STATE) {
Serial.println("constant voltage(CV)");
} else if (charge_status == XPOWERS_AXP2101_CHG_DONE_STATE) {
Serial.println("charge done");
} else if (charge_status == XPOWERS_AXP2101_CHG_STOP_STATE) {
Serial.println("not chargin");
}
Serial.println();
}
uint32_t printTime = 0;
void loop()
{
if (millis() > printTime) {
printTime = millis() + 2000;
printPMU();
}
if (pmu_flag) {
pmu_flag = false;
// Get PMU Interrupt Status Register
uint32_t status = PMU.getIrqStatus();
Serial.print("STATUS => HEX:");
Serial.print(status, HEX);
Serial.print(" BIN:");
Serial.println(status, BIN);
if (PMU.isDropWarningLevel2Irq()) {
Serial.println("isDropWarningLevel2");
}
if (PMU.isDropWarningLevel1Irq()) {
Serial.println(" >>>> isDropWarningLevel1 <<<<");
PMU.shutdown();
}
if (PMU.isGaugeWdtTimeoutIrq()) {
Serial.println("isWdtTimeout");
}
if (PMU.isBatChargerOverTemperatureIrq()) {
Serial.println("isBatChargeOverTemperature");
}
if (PMU.isBatWorkOverTemperatureIrq()) {
Serial.println("isBatWorkOverTemperature");
}
if (PMU.isBatWorkUnderTemperatureIrq()) {
Serial.println("isBatWorkUnderTemperature");
}
if (PMU.isVbusInsertIrq()) {
Serial.println("isVbusInsert");
uint8_t val = PMU.getVbusCurrentLimit();
Serial.print("Get Vbus Current Limit = "); Serial.println(val);
}
if (PMU.isVbusRemoveIrq()) {
Serial.println("isVbusRemove");
uint8_t val = PMU.getVbusCurrentLimit();
Serial.print("Get Vbus Current Limit = "); Serial.println(val);
}
if (PMU.isBatInsertIrq()) {
Serial.println("isBatInsert");
}
if (PMU.isBatRemoveIrq()) {
Serial.println("isBatRemove");
}
if (PMU.isPekeyShortPressIrq()) {
Serial.println("isPekeyShortPress");
}
if (PMU.isPekeyLongPressIrq()) {
Serial.println("isPekeyLongPress");
}
if (PMU.isPekeyNegativeIrq()) {
Serial.println("isPekeyNegative");
}
if (PMU.isPekeyPositiveIrq()) {
Serial.println("isPekeyPositive");
}
if (PMU.isWdtExpireIrq()) {
Serial.println("isWdtExpire");
}
if (PMU.isLdoOverCurrentIrq()) {
Serial.println("isLdoOverCurrentIrq");
}
if (PMU.isBatfetOverCurrentIrq()) {
Serial.println("isBatfetOverCurrentIrq");
}
if (PMU.isBatChagerDoneIrq()) {
Serial.println("isBatChagerDone");
}
if (PMU.isBatChagerStartIrq()) {
Serial.println("isBatChagerStart");
}
if (PMU.isBatDieOverTemperatureIrq()) {
Serial.println("isBatDieOverTemperature");
}
if (PMU.isChagerOverTimeoutIrq()) {
Serial.println("isChagerOverTimeout");
}
if (PMU.isBatOverVoltageIrq()) {
Serial.println("isBatOverVoltage");
}
// Clear PMU Interrupt Status Register
PMU.clearIrqStatus();
}
delay(10);
}

View file

@ -28,10 +28,11 @@ Please do not run the example without knowing the external load voltage of the P
it may burn your external load, please check the voltage setting before running the example,
if there is any loss, please bear it by yourself
*/
#ifndef XPOWERS_NO_ERROR
#error "Running this example is known to not damage the device! Please go and uncomment this!"
#endif
// Defined using AXP2102
#define XPOWERS_CHIP_AXP2102
#define XPOWERS_CHIP_AXP2101
#include <Wire.h>
#include <Arduino.h>

View file

@ -28,10 +28,11 @@ Please do not run the example without knowing the external load voltage of the P
it may burn your external load, please check the voltage setting before running the example,
if there is any loss, please bear it by yourself
*/
#ifndef XPOWERS_NO_ERROR
#error "Running this example is known to not damage the device! Please go and uncomment this!"
#endif
// Defined using AXP2102
#define XPOWERS_CHIP_AXP2102
#define XPOWERS_CHIP_AXP2101
#include <Wire.h>
#include <Arduino.h>

View file

@ -29,10 +29,11 @@ Please do not run the example without knowing the external load voltage of the P
it may burn your external load, please check the voltage setting before running the example,
if there is any loss, please bear it by yourself
*/
#ifndef XPOWERS_NO_ERROR
#error "Running this example is known to not damage the device! Please go and uncomment this!"
#endif
// Defined using AXP2102
#define XPOWERS_CHIP_AXP2102
#define XPOWERS_CHIP_AXP2101
#include <Wire.h>
#include <Arduino.h>

View file

@ -2,12 +2,12 @@ menu "XPowersLib Configuration"
choice PMU_Type
prompt "XPowers chip type"
default XPOWERS_CHIP_AXP2102 if IDF_TARGET_ESP32
default XPOWERS_CHIP_AXP2101 if IDF_TARGET_ESP32
default XPOWERS_CHIP_AXP192
help
Defines the default peripheral for xpowers example
config XPOWERS_CHIP_AXP2102
config XPOWERS_CHIP_AXP2101
bool "Xpowers AXP2101"
config XPOWERS_CHIP_AXP192
bool "Xpowers AXP192"

View file

@ -17,8 +17,9 @@ Please do not run the example without knowing the external load voltage of the P
it may burn your external load, please check the voltage setting before running the example,
if there is any loss, please bear it by yourself
*/
// #error "Running this example is known to not damage the device! Please go and uncomment this!"
#ifndef XPOWERS_NO_ERROR
#error "Running this example is known to not damage the device! Please go and uncomment this!"
#endif
static const char *TAG = "mian";

View file

@ -4,9 +4,9 @@
#include "esp_log.h"
#include "esp_err.h"
#ifdef CONFIG_XPOWERS_CHIP_AXP2102
#ifdef CONFIG_XPOWERS_CHIP_AXP2101
#define XPOWERS_CHIP_AXP2102
#define XPOWERS_CHIP_AXP2101
#include "XPowersLib.h"
static const char *TAG = "AXP2101";

View file

@ -28,13 +28,13 @@ Please do not run the example without knowing the external load voltage of the P
it may burn your external load, please check the voltage setting before running the example,
if there is any loss, please bear it by yourself
*/
#ifndef XPOWERS_NO_ERROR
#error "Running this example is known to not damage the device! Please go and uncomment this!"
#endif
#include <Arduino.h>
#include <Wire.h>
#include "XPowersLibInterface.hpp"
#include "XPowersLib.h"
@ -92,6 +92,18 @@ void setup()
}
}
if (!PMU) {
PMU = new XPowersAXP202(Wire, i2c_sda, i2c_scl);
if (!PMU->init()) {
Serial.printf("Warning: Failed to find AXP202 power management\n");
delete PMU;
PMU = NULL;
} else {
Serial.printf("AXP202 PMU init succeeded, using AXP202 PMU\n");
}
}
if (!PMU) {
Serial.println("PMU not detected, please check.."); while (1)delay(50);
}
@ -154,7 +166,47 @@ void setup()
}
// The following AXP202 power supply voltage setting is based on esp32 T-Watch
else if (PMU->getChipModel() == XPOWERS_AXP202) {
PMU->disablePowerOutput(XPOWERS_DCDC2); //not elicited
//Display backlight
PMU->setPowerChannelVoltage(XPOWERS_LDO2, 3300);
PMU->enablePowerOutput(XPOWERS_LDO2);
// Shiled Vdd
PMU->setPowerChannelVoltage(XPOWERS_LDO3, 3300);
PMU->enablePowerOutput(XPOWERS_LDO3);
// S7xG GNSS Vdd
PMU->setPowerChannelVoltage(XPOWERS_LDO4, 1800);
PMU->enablePowerOutput(XPOWERS_LDO4);
//
/* Set the constant current charging current of AXP202
opt:
XPOWERS_AXP202_CHG_CUR_100MA,
XPOWERS_AXP202_CHG_CUR_190MA,
XPOWERS_AXP202_CHG_CUR_280MA,
XPOWERS_AXP202_CHG_CUR_360MA,
XPOWERS_AXP202_CHG_CUR_450MA,
XPOWERS_AXP202_CHG_CUR_550MA,
XPOWERS_AXP202_CHG_CUR_630MA,
XPOWERS_AXP202_CHG_CUR_700MA,
XPOWERS_AXP202_CHG_CUR_780MA,
XPOWERS_AXP202_CHG_CUR_880MA,
XPOWERS_AXP202_CHG_CUR_960MA,
XPOWERS_AXP202_CHG_CUR_1000MA,
XPOWERS_AXP202_CHG_CUR_1080MA,
XPOWERS_AXP202_CHG_CUR_1160MA,
XPOWERS_AXP202_CHG_CUR_1240MA,
XPOWERS_AXP202_CHG_CUR_1320MA,
*/
PMU->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) {
@ -222,6 +274,12 @@ void setup()
if (PMU->isChannelAvailable(XPOWERS_LDO3)) {
Serial.printf("LDO3 : %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_LDO3) ? "+" : "-", PMU->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 (PMU->isChannelAvailable(XPOWERS_LDO5)) {
Serial.printf("LDO5 : %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_LDO5) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_LDO5));
}
if (PMU->isChannelAvailable(XPOWERS_ALDO1)) {
Serial.printf("ALDO1: %s Voltage:%u mV \n", PMU->isPowerChannelEnable(XPOWERS_ALDO1) ? "+" : "-", PMU->getPowerChannelVoltage(XPOWERS_ALDO1));
}
@ -321,6 +379,9 @@ void setup()
PMU->clearIrqStatus();
/*
// call specific interrupt request
uint64_t pmuIrqMask = 0;
if (PMU->getChipModel() == XPOWERS_AXP192) {
@ -329,26 +390,28 @@ void setup()
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) {
pmuIrqMask = 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
}
// Enable the required interrupt function
PMU->enableIRQ(pmuIrqMask);
*/
// Call the interrupt request through the interface class
PMU->disableInterrupt(XPOWERS_ALL_INT);
PMU->enableInterrupt(XPOWERS_USB_INSERT_INT |
XPOWERS_USB_REMOVE_INT |
XPOWERS_BATTERY_INSERT_INT |
XPOWERS_BATTERY_REMOVE_INT |
XPOWERS_PWR_BTN_CLICK_INT |
XPOWERS_CHARGE_START_INT |
XPOWERS_CHARGE_DONE_INT);
}
void printPMU()

View file

@ -508,7 +508,7 @@ XPOWERS_TIMER_TIMEOUT_IRQ LITERAL1
XPOWERS_ALL_IRQ LITERAL1
XPOWERS_CHIP_AXP192 LITERAL1
XPOWERS_CHIP_AXP202 LITERAL1
XPOWERS_CHIP_AXP2102 LITERAL1
XPOWERS_CHIP_AXP2101 LITERAL1
# AXP2102

View file

@ -1,6 +1,6 @@
{
"name": "XPowersLib",
"version": "0.1.5",
"version": "0.1.6",
"description": "Arduino,CircuitPython,Micropython library for x-powers power management series",
"keywords": "AXP192 AXP202 AXP2101 x-powers",
"authors": [

View file

@ -1,5 +1,5 @@
name=XPowersLib
version=0.1.5
version=0.1.6
author=Lewis He
maintainer=Lewis He <lewishe@outlook.com>
sentence=Arduino,CircuitPython,Micropython library for x-powers power management series

View file

@ -9,8 +9,17 @@
; https://docs.platformio.org/page/projectconf.html
[platformio]
src_dir = examples/AXP2101_Example
src_dir = /examples/AXP192_Example
; src_dir = /examples/AXP202_Example
; src_dir = /examples/AXP2101_Charge_Example
; src_dir = /examples/AXP2101_Example
; src_dir = /examples/AXP2101_InterruptExample
; src_dir = /examples/AXP2101_Voltage_Example
; src_dir = /examples/XPowersLibInterface_Example
default_envs=esp32s3
; default_envs=esp32dev
[env]
lib_extra_dirs = .
@ -18,13 +27,17 @@ lib_extra_dirs = .
upload_speed = 921600
monitor_speed = 115200
monitor_port = COM169
upload_port = COM169
monitor_port = COM150
upload_port = COM150
build_flags =
; -DCONFIG_PMU_SDA=42
; -DCONFIG_PMU_SCL=41
; -DCONFIG_PMU_IRQ=40
; -UARDUINO_USB_CDC_ON_BOOT
; -DARDUINO_USB_CDC_ON_BOOT=1
; build_flags =
; -DCONFIG_PMU_SDA=15
; -DCONFIG_PMU_SCL=7
; -DCONFIG_PMU_IRQ=6
[env:esp32dev]
platform = espressif32

View file

@ -51,7 +51,7 @@
#define XPOWERS_AXP202_VBUS_DET_SRP (0x8B)
#define XPOWERS_AXP202_HOTOVER_CTL (0x8F)
#define XPOWERS_AXP202_DATA_BUFFER_SIZE (12)
#define XPOWERS_AXP202_GPIO0_CTL (0x90)
#define XPOWERS_AXP202_GPIO0_VOL (0x91)
#define XPOWERS_AXP202_GPIO1_CTL (0x92)
@ -147,5 +147,46 @@
#define XPOWERS_AXP202_APS_VOLTAGE_STEP (1.4F)
#define XPOWERS_AXP202_TS_PIN_OUT_STEP (0.8F)
#define XPOWERS_AXP202_LDO2_VOL_MIN (1800u)
#define XPOWERS_AXP202_LDO2_VOL_MAX (3300u)
#define XPOWERS_AXP202_LDO2_VOL_STEPS (100u)
#define XPOWERS_AXP202_LDO2_VOL_BIT_MASK (4u)
#define XPOWERS_AXP202_LDO3_VOL_MIN (1800u)
#define XPOWERS_AXP202_LDO3_VOL_MAX (3300u)
#define XPOWERS_AXP202_LDO3_VOL_STEPS (100u)
#define XPOWERS_AXP202_DC2_VOL_STEPS (25u)
#define XPOWERS_AXP202_DC2_VOL_MIN (700u)
#define XPOWERS_AXP202_DC2_VOL_MAX (3500u)
#define XPOWERS_AXP202_DC3_VOL_STEPS (25u)
#define XPOWERS_AXP202_DC3_VOL_MIN (700u)
#define XPOWERS_AXP202_DC3_VOL_MAX (3500u)
#define XPOWERS_AXP202_LDOIO_VOL_STEPS (100)
#define XPOWERS_AXP202_LDOIO_VOL_MIN (1800)
#define XPOWERS_AXP202_LDOIO_VOL_MAX (3300)
#define XPOWERS_AXP202_SYS_VOL_STEPS (100)
#define XPOWERS_AXP202_VOFF_VOL_MIN (2600)
#define XPOWERS_AXP202_VOFF_VOL_MAX (3300)
#define XPOWERS_AXP202_CHG_EXT_CURR_MIN (300)
#define XPOWERS_AXP202_CHG_EXT_CURR_MAX (1000)
#define XPOWERS_AXP202_CHG_EXT_CURR_STEP (100)
#define XPOWERS_AXP202_INERNAL_TEMP_OFFSET (144.7)

View file

@ -36,46 +36,20 @@
#include "REG/AXP192Constants.h"
#include "XPowersLibInterface.hpp"
typedef enum {
MONITOR_TS_PIN = _BV(0),
MONITOR_APS_VOLTAGE = _BV(1),
MONITOR_USB_CURRENT = _BV(2),
MONITOR_USB_VOLTAGE = _BV(3),
MONITOR_AC_CURRENT = _BV(4),
MONITOR_AC_VOLTAGE = _BV(5),
MONITOR_BAT_CURRENT = _BV(6),
MONITOR_BAT_VOLTAGE = _BV(7),
MONITOR_ADC_IO3 = _BV(8),
MONITOR_ADC_IO2 = _BV(9),
MONITOR_ADC_IO1 = _BV(10),
MONITOR_ADC_IO0 = _BV(11),
MONITOR_TEMPERATURE = _BV(16),
} axp192_adc_func_t;
typedef enum {
XPOWERS_AXP192_BOOT_TIME_128MS,
XPOWERS_AXP192_BOOT_TIME_512MS,
XPOWERS_AXP192_BOOT_TIME_1S,
XPOWERS_AXP192_BOOT_TIME_2S,
} axp192_boot_time_t;
} xpowers_axp192_boot_time_t;
typedef enum {
PMU_GPIO0,
PMU_GPIO1,
PMU_GPIO2,
PMU_GPIO3,
PMU_GPIO4,
PMU_GPIO5,
PMU_TS_PIN
} xpowers_num_t;
typedef enum {
XPOWERS_AXP192_CHG_ITERM_LESS_10_PERCENT,
XPOWERS_AXP192_CHG_ITERM_LESS_15_PERCENT,
} xpowers_chg_iterm_t;
} xpowers_axp192_chg_iterm_t;
typedef enum {
@ -83,14 +57,14 @@ typedef enum {
XPOWERS_AXP192_PRECHG_TIMEOUT_40MIN,
XPOWERS_AXP192_PRECHG_TIMEOUT_50MIN,
XPOWERS_AXP192_PRECHG_TIMEOUT_60MIN,
} xpoers_prechg_to_t;
} xpoers_axp192_prechg_to_t;
typedef enum {
XPOWERS_AXP192_POWEROFF_4S,
XPOWERS_AXP192_POWEROFF_65,
XPOWERS_AXP192_POWEROFF_8S,
XPOWERS_AXP192_POWEROFF_10S,
} xpowers_pekey_poweroff_arg_t;
} xpowers_axp192_pekey_poweroff_arg_t;
typedef enum {
@ -98,18 +72,7 @@ typedef enum {
XPOWERS_AXP192_LONGPRESS_1500MS,
XPOWERS_AXP192_LONGPRESS_2000MS,
XPOWERS_AXP192_LONGPRESS_2500MS,
} xpowers_pekey_long_press_t;
typedef enum {
XPOWERS_AXP192_CHG_LED_DISABLE,
XPOWERS_AXP192_CHG_LED_FRE_1HZ,
XPOWERS_AXP192_CHG_LED_FRE_4HZ,
XPOWERS_AXP192_CHG_LED_LEVEL_LOW,
XPOWERS_AXP192_CHG_LED_CTRL_CHG, // The charging indicator is controlled by the charger
} xpowers_chgled_t;
} xpowers_axp192_pekey_long_press_t;
typedef enum {
XPOWERS_AXP192_VBUS_VOL_LIM_4V,
@ -122,17 +85,12 @@ typedef enum {
XPOWERS_AXP192_VBUS_VOL_LIM_4V7,
} xpowers_axp192_vbus_vol_limit_t;
typedef enum {
XPOWERS_AXP192_CHG_CONS_TIMEOUT_7H,
XPOWERS_AXP192_CHG_CONS_TIMEOUT_8H,
XPOWERS_AXP192_CHG_CONS_TIMEOUT_9H,
XPOWERS_AXP192_CHG_CONS_TIMEOUT_10H,
} xpowers_chg_cons_to_t;
} xpowers_axp192_chg_cons_to_t;
typedef enum {
@ -140,24 +98,57 @@ typedef enum {
XPOWERS_AXP192_BACKUP_BAT_VOL_3V,
XPOWERS_AXP192_BACKUP_BAT_VOL_3V0, //!NEED FIX,DATASHEET ERROR!
XPOWERS_AXP192_BACKUP_BAT_VOL_2V5,
} xpowers_backup_batt_vol_t;
} xpowers_axp192_backup_batt_vol_t;
typedef enum {
XPOWERS_AXP192_BACKUP_BAT_CUR_50UA,
XPOWERS_AXP192_BACKUP_BAT_CUR_100UA,
XPOWERS_AXP192_BACKUP_BAT_CUR_200UA,
XPOWERS_AXP192_BACKUP_BAT_CUR_400UA,
} xpowers_backup_batt_curr_t;
} xpowers_axp192_backup_batt_curr_t;
typedef struct {
uint8_t mode;
} xpowers_gpio_t;
} xpowers_axp192_gpio_t;
class XPowersAXP192 :
public XPowersCommon<XPowersAXP192>, public XPowersLibInterface
{
friend class XPowersCommon<XPowersAXP192>;
typedef enum {
PMU_GPIO0,
PMU_GPIO1,
PMU_GPIO2,
PMU_GPIO3,
PMU_GPIO4,
PMU_GPIO5,
PMU_TS_PIN
} xpowers_axp192_num_t;
typedef enum {
MONITOR_TS_PIN = _BV(0),
MONITOR_APS_VOLTAGE = _BV(1),
MONITOR_USB_CURRENT = _BV(2),
MONITOR_USB_VOLTAGE = _BV(3),
MONITOR_AC_CURRENT = _BV(4),
MONITOR_AC_VOLTAGE = _BV(5),
MONITOR_BAT_CURRENT = _BV(6),
MONITOR_BAT_VOLTAGE = _BV(7),
MONITOR_ADC_IO3 = _BV(8),
MONITOR_ADC_IO2 = _BV(9),
MONITOR_ADC_IO1 = _BV(10),
MONITOR_ADC_IO0 = _BV(11),
MONITOR_TEMPERATURE = _BV(16),
} axp192_adc_func_t;
typedef struct {
uint8_t mode;
} xpowers_gpio_t;
public:
@ -187,6 +178,17 @@ public:
deinit();
}
#if defined(ARDUINO)
bool init(TwoWire &w, int sda = SDA, int scl = SCL, uint8_t addr = AXP192_SLAVE_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
return begin();
}
#endif
bool init()
{
return begin();
@ -422,7 +424,7 @@ public:
return val;
}
void setChargerTerminationCurr(xpowers_chg_iterm_t opt)
void setChargerTerminationCurr(xpowers_axp192_chg_iterm_t opt)
{
switch (opt) {
case XPOWERS_AXP192_CHG_ITERM_LESS_10_PERCENT:
@ -441,7 +443,7 @@ public:
return getRegisterBit(XPOWERS_AXP192_CHARGE1, 4);
}
bool setPrechargeTimeout(xpoers_prechg_to_t opt)
bool setPrechargeTimeout(xpoers_axp192_prechg_to_t opt)
{
int val = readRegister(XPOWERS_AXP192_CHARGE2);
if (val == -1)return false;
@ -481,7 +483,7 @@ public:
}
// Timeout setting in constant current mode
bool setChargerConstantTimeout(xpowers_chg_cons_to_t opt)
bool setChargerConstantTimeout(xpowers_axp192_chg_cons_to_t opt)
{
int val = readRegister(XPOWERS_AXP192_CHARGE2);
if (val == -1)return false;
@ -505,7 +507,7 @@ public:
return getRegisterBit(XPOWERS_AXP192_BACKUP_CHG, 7);
}
bool setBackupBattChargerVoltage(xpowers_backup_batt_vol_t opt)
bool setBackupBattChargerVoltage(xpowers_axp192_backup_batt_vol_t opt)
{
int val = readRegister(XPOWERS_AXP192_BACKUP_CHG);
if (val == -1)return false;
@ -513,7 +515,7 @@ public:
return 0 == writeRegister(XPOWERS_AXP192_BACKUP_CHG, val | (opt << 5));
}
bool setBackupBattChargerCurr(xpowers_backup_batt_curr_t opt)
bool setBackupBattChargerCurr(xpowers_axp192_backup_batt_curr_t opt)
{
int val = readRegister(XPOWERS_AXP192_BACKUP_CHG);
if (val == -1)return false;
@ -1836,7 +1838,7 @@ public:
}
void setPowerKeyLongPressOnTime(xpowers_pekey_long_press_t opt)
void setPowerKeyLongPressOnTime(xpowers_axp192_pekey_long_press_t opt)
{
int val = readRegister(XPOWERS_AXP192_POK_SET);
if (val == -1)return;
@ -2067,6 +2069,7 @@ protected:
return "AXP192";
}
private:
const uint16_t chargeTargetVol[4] = {4100, 4150, 4200, 4360};
uint8_t statusRegister[5];

File diff suppressed because it is too large Load diff

View file

@ -231,6 +231,17 @@ public:
deinit();
}
#if defined(ARDUINO)
bool init(TwoWire &w, int sda = SDA, int scl = SCL, uint8_t addr = AXP2101_SLAVE_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
return begin();
}
#endif
bool init()
{
return begin();
@ -246,8 +257,8 @@ public:
*/
uint16_t status()
{
uint8_t status1 = readRegister(XPOWERS_AXP2101_STATUS1);
uint8_t status2 = readRegister(XPOWERS_AXP2101_STATUS2);
uint16_t status1 = readRegister(XPOWERS_AXP2101_STATUS1) & 0x1F;
uint16_t status2 = readRegister(XPOWERS_AXP2101_STATUS2) & 0x1F;;
return (status1 << 8) | (status2);
}
@ -314,7 +325,7 @@ public:
xpowers_chg_status_t getChargerStatus(void)
{
int val = readRegister(XPOWERS_AXP2101_THE_REGU_THRES_SET);
int val = readRegister(XPOWERS_AXP2101_STATUS2);
if (val == -1)return XPOWERS_AXP2101_CHG_STOP_STATE;
val &= 0x07;
return (xpowers_chg_status_t)val;
@ -424,7 +435,7 @@ public:
void disableBatfetDieOverTempDetect(void)
{
setRegisterBit(XPOWERS_AXP2101_BATFET_CTRL, 0);
clrRegisterBit(XPOWERS_AXP2101_BATFET_CTRL, 0);
}
/**
@ -450,7 +461,7 @@ public:
void disableDieOverTempDetect(void)
{
setRegisterBit(XPOWERS_AXP2101_DIE_TEMP_CTRL, 0);
clrRegisterBit(XPOWERS_AXP2101_DIE_TEMP_CTRL, 0);
}
// Linear Charger Vsys voltage dpm
@ -653,10 +664,13 @@ public:
}
/**
* @brief Low battery warning threshold 5-20%, 1% per step
* @brief Low battery warning threshold 5-20%, 1% per step
* @param opt: 5 ~ 20
* @retval None
*/
void setLowBatWarnThreshold(uint8_t opt)
{
if (opt < 5 || opt > 20)return;
int val = readRegister(XPOWERS_AXP2101_LOW_BAT_WARN_SET);
if (val == -1)return;
val &= 0x0F;
@ -669,11 +683,13 @@ public:
}
/**
* @brief Low battery shutdown threshold 0-15%, 1% per step
* @brief Low battery shutdown threshold 5-20%, 1% per step
* @param opt: 5 ~ 20
* @retval None
*/
void setLowBatShutdownThreshold(uint8_t opt)
{
if (opt < 5 || opt > 20)return;
int val = readRegister(XPOWERS_AXP2101_LOW_BAT_WARN_SET);
if (val == -1)return;
val &= 0xF0;
@ -973,8 +989,8 @@ public:
{
int val = readRegister(XPOWERS_AXP2101_SLEEP_WAKEUP_CTRL);
if (val == -1)return;
enable ? (val | opt) : (val & (~opt));
writeRegister(XPOWERS_AXP2101_SLEEP_WAKEUP_CTRL, val | opt);
enable ? (val |= opt) : (val &= (~opt));
writeRegister(XPOWERS_AXP2101_SLEEP_WAKEUP_CTRL, val);
}
bool enableWakeup(void)
@ -2402,7 +2418,9 @@ public:
*/
uint8_t getChargerConstantCurr(void)
{
return (readRegister(XPOWERS_AXP2101_ICC_CHG_SET) & 0x1F);
int val = readRegister(XPOWERS_AXP2101_ICC_CHG_SET);
if (val == -1)return 0;
return val & 0x1F;
}
/**
@ -2489,6 +2507,20 @@ public:
return readRegister(XPOWERS_AXP2101_BAT_PARAME);
}
void fuelGaugeControl(bool writeROM, bool enable)
{
if (writeROM) {
clrRegisterBit(XPOWERS_AXP2101_FUEL_GAUGE_CTRL, 4);
} else {
setRegisterBit(XPOWERS_AXP2101_FUEL_GAUGE_CTRL, 4);
}
if (enable) {
setRegisterBit(XPOWERS_AXP2101_FUEL_GAUGE_CTRL, 0);
} else {
clrRegisterBit(XPOWERS_AXP2101_FUEL_GAUGE_CTRL, 0);
}
}
/*
* Interrupt status/control functions
*/
@ -2985,6 +3017,7 @@ protected:
{
if (getChipID() == XPOWERS_AXP2101_CHIP_ID) {
setChipModel(XPOWERS_AXP2101);
disableTSPinMeasure(); //Disable NTC temperature detection by default
return true;
}
return false;

View file

@ -15,15 +15,14 @@
#include "XPowersAXP192.tpp"
typedef XPowersAXP192 XPowersPMU;
#elif defined(XPOWERS_CHIP_AXP202)
// #include "XPowersAXP202.tpp"
// typedef XPowersAXP202 XPowersPMU;
#error "Not currently supported!"
#elif defined(XPOWERS_CHIP_AXP2102)
#include "XPowersAXP202.tpp"
typedef XPowersAXP202 XPowersPMU;
#elif defined(XPOWERS_CHIP_AXP2101)
#include "XPowersAXP2101.tpp"
typedef XPowersAXP2101 XPowersPMU;
#else
#include "XPowersAXP192.tpp"
// #include "XPowersAXP202.tpp"
#include "XPowersAXP202.tpp"
#include "XPowersAXP2101.tpp"
#endif

View file

@ -106,3 +106,68 @@ uint16_t XPowersLibInterface::getVbusVoltage()
{
return 0;
}
static uint64_t inline check_params(uint32_t opt, uint32_t params, uint64_t mask)
{
return ((opt & params) == params) ? mask : 0;
}
bool XPowersLibInterface::enableInterrupt(uint32_t option)
{
return setInterruptMask(option, true);
}
bool XPowersLibInterface::disableInterrupt(uint32_t option)
{
return setInterruptMask(option, false);
}
bool XPowersLibInterface::setInterruptMask(uint32_t option, bool enable)
{
uint64_t params = 0;
switch (__chipModel) {
case XPOWERS_AXP173:
break;
case XPOWERS_AXP192:
params |= check_params(option, XPOWERS_USB_INSERT_INT, XPOWERS_AXP192_VBUS_INSERT_IRQ);
params |= check_params(option, XPOWERS_USB_REMOVE_INT, XPOWERS_AXP192_VBUS_REMOVE_IRQ);
params |= check_params(option, XPOWERS_BATTERY_INSERT_INT, XPOWERS_AXP192_BAT_INSERT_IRQ);
params |= check_params(option, XPOWERS_BATTERY_REMOVE_INT, XPOWERS_AXP192_BAT_REMOVE_IRQ);
params |= check_params(option, XPOWERS_CHARGE_START_INT, XPOWERS_AXP192_BAT_CHG_START_IRQ);
params |= check_params(option, XPOWERS_CHARGE_DONE_INT, XPOWERS_AXP192_BAT_CHG_DONE_IRQ);
params |= check_params(option, XPOWERS_PWR_BTN_CLICK_INT, XPOWERS_AXP192_PKEY_SHORT_IRQ);
params |= check_params(option, XPOWERS_PWR_BTN_LONGPRESSED_INT, XPOWERS_AXP192_PKEY_LONG_IRQ);
params |= check_params(option, XPOWERS_ALL_INT, XPOWERS_AXP192_ALL_IRQ);
return enable ? enableIRQ(params) : disableIRQ(params);
break;
case XPOWERS_AXP202:
params |= check_params(option, XPOWERS_USB_INSERT_INT, XPOWERS_AXP202_VBUS_INSERT_IRQ);
params |= check_params(option, XPOWERS_USB_REMOVE_INT, XPOWERS_AXP202_VBUS_REMOVE_IRQ);
params |= check_params(option, XPOWERS_BATTERY_INSERT_INT, XPOWERS_AXP202_BAT_INSERT_IRQ);
params |= check_params(option, XPOWERS_BATTERY_REMOVE_INT, XPOWERS_AXP202_BAT_REMOVE_IRQ);
params |= check_params(option, XPOWERS_CHARGE_START_INT, XPOWERS_AXP202_BAT_CHG_START_IRQ);
params |= check_params(option, XPOWERS_CHARGE_DONE_INT, XPOWERS_AXP202_BAT_CHG_DONE_IRQ);
params |= check_params(option, XPOWERS_PWR_BTN_CLICK_INT, XPOWERS_AXP202_PKEY_SHORT_IRQ);
params |= check_params(option, XPOWERS_PWR_BTN_LONGPRESSED_INT, XPOWERS_AXP202_PKEY_LONG_IRQ);
params |= check_params(option, XPOWERS_ALL_INT, XPOWERS_AXP202_ALL_IRQ);
return enable ? enableIRQ(params) : disableIRQ(params);
break;
case XPOWERS_AXP216:
break;
case XPOWERS_AXP2101:
params |= check_params(option, XPOWERS_USB_INSERT_INT, XPOWERS_AXP2101_VBUS_INSERT_IRQ);
params |= check_params(option, XPOWERS_USB_REMOVE_INT, XPOWERS_AXP2101_VBUS_REMOVE_IRQ);
params |= check_params(option, XPOWERS_BATTERY_INSERT_INT, XPOWERS_AXP2101_BAT_INSERT_IRQ);
params |= check_params(option, XPOWERS_BATTERY_REMOVE_INT, XPOWERS_AXP2101_BAT_REMOVE_IRQ);
params |= check_params(option, XPOWERS_CHARGE_START_INT, XPOWERS_AXP2101_BAT_CHG_START_IRQ);
params |= check_params(option, XPOWERS_CHARGE_DONE_INT, XPOWERS_AXP2101_BAT_CHG_DONE_IRQ);
params |= check_params(option, XPOWERS_PWR_BTN_CLICK_INT, XPOWERS_AXP2101_PKEY_SHORT_IRQ);
params |= check_params(option, XPOWERS_PWR_BTN_LONGPRESSED_INT, XPOWERS_AXP2101_PKEY_LONG_IRQ);
params |= check_params(option, XPOWERS_ALL_INT, XPOWERS_AXP2101_ALL_IRQ);
return enable ? enableIRQ(params) : disableIRQ(params);
break;
default:
break;
}
return false;
}

View file

@ -439,10 +439,34 @@ public:
* @brief Disable PMU interrupt control mask .
* @param opt: View the related chip type xpowers_axpxxx_irq_t enumeration
* parameters in "XPowersParams.hpp"
* @retval
* @retval true valid false invalid
*/
virtual bool disableIRQ(uint64_t opt) = 0;
/**
* @brief .
* @param opt: View the related chip type xpowers_interrupt_enum_t enumeration
* parameters in "XPowersParams.hpp"
* @retval true valid false invalid
*/
bool enableInterrupt(uint32_t opt);
/**
* @brief .
* @param opt: View the related chip type xpowers_interrupt_enum_t enumeration
* parameters in "XPowersParams.hpp"
* @retval true valid false invalid
*/
bool disableInterrupt(uint32_t opt);
/**
* @brief .
* @param opt: View the related chip type xpowers_interrupt_enum_t enumeration
* parameters in "XPowersParams.hpp"
* @retval true valid false invalid
*/
bool setInterruptMask(uint32_t option, bool enable);
/**
* @brief Interrupt response when PMU PEKEY is short pressed
* @retval true valid false invalid

View file

@ -114,6 +114,17 @@ typedef enum __xpowers_axp192_chg_vol {
XPOWERS_AXP192_CHG_VOL_MAX,
} xpowers_axp192_chg_vol_t;
/**
* @brief axp202 charge target voltage parameters.
*/
typedef enum __xpowers_axp202_chg_vol {
XPOWERS_AXP202_CHG_VOL_4V1,
XPOWERS_AXP202_CHG_VOL_4V15,
XPOWERS_AXP202_CHG_VOL_4V2,
XPOWERS_AXP202_CHG_VOL_4V36,
XPOWERS_AXP202_CHG_VOL_MAX,
} xpowers_axp202_chg_vol_t;
/**
* @brief axp192 charge currnet voltage parameters.
*/
@ -136,7 +147,27 @@ typedef enum __xpowers_axp192_chg_curr {
XPOWERS_AXP192_CHG_CUR_1320MA,
} xpowers_axp192_chg_curr_t;
/**
* @brief axp202 charge currnet voltage parameters.
*/
typedef enum __xpowers_axp202_chg_curr {
XPOWERS_AXP202_CHG_CUR_100MA,
XPOWERS_AXP202_CHG_CUR_190MA,
XPOWERS_AXP202_CHG_CUR_280MA,
XPOWERS_AXP202_CHG_CUR_360MA,
XPOWERS_AXP202_CHG_CUR_450MA,
XPOWERS_AXP202_CHG_CUR_550MA,
XPOWERS_AXP202_CHG_CUR_630MA,
XPOWERS_AXP202_CHG_CUR_700MA,
XPOWERS_AXP202_CHG_CUR_780MA,
XPOWERS_AXP202_CHG_CUR_880MA,
XPOWERS_AXP202_CHG_CUR_960MA,
XPOWERS_AXP202_CHG_CUR_1000MA,
XPOWERS_AXP202_CHG_CUR_1080MA,
XPOWERS_AXP202_CHG_CUR_1160MA,
XPOWERS_AXP202_CHG_CUR_1240MA,
XPOWERS_AXP202_CHG_CUR_1320MA,
} xpowers_axp202_chg_curr_t;
/**
@ -161,6 +192,35 @@ typedef enum {
} xpowers_axp192_vbus_cur_limit_t;
/**
* @brief axp202 vbus currnet limit parameters.
*/
typedef enum {
XPOWERS_AXP202_VBUS_CUR_LIM_900MA,
XPOWERS_AXP202_VBUS_CUR_LIM_500MA,
XPOWERS_AXP202_VBUS_CUR_LIM_100MA,
XPOWERS_AXP202_VBUS_CUR_LIM_OFF,
} xpowers_axp202_vbus_cur_limit_t;
/**
* @brief XPowersLibInterface interrupt control mask parameters.
* Common interrupt interfaces
* @Example: enableInterrupt(XPOWERS_USB_INSERT_INT|XPOWERS_USB_REMOVE_INT);
* disableInterrupt(XPOWERS_CHARGE_START_INT|XPOWERS_PWR_BTN_CLICK_INT);
*/
typedef enum __xpowers_interrupt_enum {
XPOWERS_USB_INSERT_INT = _BV(0),
XPOWERS_USB_REMOVE_INT = _BV(1),
XPOWERS_BATTERY_INSERT_INT = _BV(2),
XPOWERS_BATTERY_REMOVE_INT = _BV(3),
XPOWERS_CHARGE_START_INT = _BV(4),
XPOWERS_CHARGE_DONE_INT = _BV(5),
XPOWERS_PWR_BTN_CLICK_INT = _BV(6),
XPOWERS_PWR_BTN_LONGPRESSED_INT = _BV(7),
XPOWERS_ALL_INT = _BV(8),
} xpowers_interrupt_enum_t;
/**
* @brief axp192 interrupt control mask parameters.
*/
@ -257,8 +317,61 @@ typedef enum __xpowers_axp2101_irq {
} xpowers_axp2101_irq_t;
/**
* @brief axp202 interrupt control mask parameters.
*/
typedef enum __xpowers_axp202_irq {
//! IRQ1 REG 40H
XPOWERS_AXP202_VBUS_VHOLD_LOW_IRQ = _BV(1), //VBUS is available, but lower than V HOLD, IRQ enable
XPOWERS_AXP202_VBUS_REMOVE_IRQ = _BV(2), //VBUS removed, IRQ enable
XPOWERS_AXP202_VBUS_INSERT_IRQ = _BV(3), //VBUS connected, IRQ enable
XPOWERS_AXP202_VBUS_OVER_VOL_IRQ = _BV(4), //VBUS over-voltage, IRQ enable
XPOWERS_AXP202_ACIN_REMOVED_IRQ = _BV(5), //ACIN removed, IRQ enable
XPOWERS_AXP202_ACIN_CONNECT_IRQ = _BV(6), //ACIN connected, IRQ enable
XPOWERS_AXP202_ACIN_OVER_VOL_IRQ = _BV(7), //ACIN over-voltage, IRQ enable
//! IRQ2 REG 41H
XPOWERS_AXP202_BATT_LOW_TEMP_IRQ = _BV(8), //Battery low-temperature, IRQ enable
XPOWERS_AXP202_BATT_OVER_TEMP_IRQ = _BV(9), //Battery over-temperature, IRQ enable
XPOWERS_AXP202_BAT_CHG_DONE_IRQ = _BV(10), //Charge finished, IRQ enable
XPOWERS_AXP202_BAT_CHG_START_IRQ = _BV(11), //Be charging, IRQ enable
XPOWERS_AXP202_BATT_EXIT_ACTIVATE_IRQ = _BV(12), //Exit battery activate mode, IRQ enable
XPOWERS_AXP202_BATT_ACTIVATE_IRQ = _BV(13), //Battery activate mode, IRQ enable
XPOWERS_AXP202_BAT_REMOVE_IRQ = _BV(14), //Battery removed, IRQ enable
XPOWERS_AXP202_BAT_INSERT_IRQ = _BV(15), //Battery connected, IRQ enable
//! IRQ3 REG 42H
XPOWERS_AXP202_PKEY_LONG_IRQ = _BV(16), //PEK long press, IRQ enable
XPOWERS_AXP202_PKEY_SHORT_IRQ = _BV(17), //PEK short press, IRQ enable
XPOWERS_AXP202_LDO3_LOW_VOL_IRQ = _BV(18), //LDO3output voltage is lower than the set value, IRQ enable
XPOWERS_AXP202_DC3_LOW_VOL_IRQ = _BV(19), //DC-DC3output voltage is lower than the set value, IRQ enable
XPOWERS_AXP202_DC2_LOW_VOL_IRQ = _BV(20), //DC-DC2 output voltage is lower than the set value, IRQ enable
//**Reserved and unchangeable BIT 5
XPOWERS_AXP202_CHARGE_LOW_CUR_IRQ = _BV(22), //Charge current is lower than the set current, IRQ enable
XPOWERS_AXP202_CHIP_TEMP_HIGH_IRQ = _BV(23), //AXP202 internal over-temperature, IRQ enable
//! IRQ4 REG 43H
XPOWERS_AXP202_APS_LOW_VOL_LEVEL2_IRQ = _BV(24), //APS low-voltage, IRQ enableLEVEL2
XPOWERS_APX202_APS_LOW_VOL_LEVEL1_IRQ = _BV(25), //APS low-voltage, IRQ enableLEVEL1
XPOWERS_AXP202_VBUS_SESSION_END_IRQ = _BV(26), //VBUS Session End IRQ enable
XPOWERS_AXP202_VBUS_SESSION_AB_IRQ = _BV(27), //VBUS Session A/B IRQ enable
XPOWERS_AXP202_VBUS_INVALID_IRQ = _BV(28), //VBUS invalid, IRQ enable
XPOWERS_AXP202_VBUS_VAILD_IRQ = _BV(29), //VBUS valid, IRQ enable
XPOWERS_AXP202_NOE_OFF_IRQ = _BV(30), //N_OE shutdown, IRQ enable
XPOWERS_AXP202_NOE_ON_IRQ = _BV(31), //N_OE startup, IRQ enable
//! IRQ5 REG 44H
XPOWERS_AXP202_GPIO0_EDGE_TRIGGER_IRQ = _BV(32), //GPIO0 input edge trigger, IRQ enable
XPOWERS_AXP202_GPIO1_EDGE_TRIGGER_IRQ = _BV(33), //GPIO1input edge trigger or ADC input, IRQ enable
XPOWERS_AXP202_GPIO2_EDGE_TRIGGER_IRQ = _BV(34), //GPIO2input edge trigger, IRQ enable
XPOWERS_AXP202_GPIO3_EDGE_TRIGGER_IRQ = _BV(35), //GPIO3 input edge trigger, IRQ enable
//**Reserved and unchangeable BIT 4
XPOWERS_AXP202_PKEY_NEGATIVE_IRQ = _BV(37), //PEK press falling edge, IRQ enable
XPOWERS_AXP202_PKEY_POSITIVE_IRQ = _BV(38), //PEK press rising edge, IRQ enable
XPOWERS_AXP202_TIMER_TIMEOUT_IRQ = _BV(39), //Timer timeout, IRQ enable
XPOWERS_AXP202_ALL_IRQ = (0xFFFFFFFFFFULL)
} xpowers_axp202_irq_t;