initial commit

This commit is contained in:
2026-02-12 00:45:31 -08:00
commit 5f168f370b
3024 changed files with 804889 additions and 0 deletions

View File

@@ -0,0 +1,171 @@
/**
*
* @license MIT License
*
* Copyright (c) 2024 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.
*
* @file PowerDeliveryHUSB238.tpp
* @author Lewis He (lewishe@outlook.com)
* @date 2024-07-24
*
*/
#if defined(ARDUINO)
#include <Arduino.h>
#else
#include <math.h>
#endif /*ARDUINO*/
#include "XPowersCommon.tpp"
#include "REG/HUSB238Constants.h"
class PowerDeliveryHUSB238 :
public XPowersCommon<PowerDeliveryHUSB238>
{
friend class XPowersCommon<PowerDeliveryHUSB238>;
public:
enum PD_Status {
NO_RESPONSE,
SUCCESS,
INVALID_CMD,
NOT_SUPPORT,
TRANSACTION_FAIL
};
enum PD_Voltage {
PD_5V = 1,
PD_9V,
PD_12V,
PD_15V,
PD_18V,
PD_20V
};
#if defined(ARDUINO)
PowerDeliveryHUSB238(TwoWire &w, int sda = SDA, int scl = SCL, uint8_t addr = HUSB238_SLAVE_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
}
#endif
PowerDeliveryHUSB238(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback)
{
thisReadRegCallback = readRegCallback;
thisWriteRegCallback = writeRegCallback;
__addr = addr;
}
PowerDeliveryHUSB238()
{
#if defined(ARDUINO)
__wire = &Wire;
__sda = SDA;
__scl = SCL;
#endif
__addr = HUSB238_SLAVE_ADDRESS;
}
~PowerDeliveryHUSB238()
{
log_i("~PowerDeliveryHUSB238");
deinit();
}
#if defined(ARDUINO)
bool init(TwoWire &w, int sda = SDA, int scl = SCL, uint8_t addr = HUSB238_SLAVE_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
return begin();
}
#endif
void deinit()
{
end();
}
uint8_t getPdVoltage()
{
int val = readRegister(HUSB238_PD_STATUS0);
if (val == -1)return 0;
val &= 0xF0;
val >>= 4;
return pd_voltage_list[val];
}
float getPdCurrent()
{
int val = readRegister(HUSB238_PD_STATUS0);
if (val == -1)return 0;
val &= 0x0F;
return pd_current_list[val];
}
void setPdVoltage(PD_Voltage vol)
{
writeRegister(HUSB238_SRC_PDO, vol);
writeRegister(HUSB238_GO_COMMAND, 0x01);
}
void resetPdVoltage()
{
writeRegister(HUSB238_GO_COMMAND, 0x10);
}
bool attach()
{
return getRegisterBit(HUSB238_PD_STATUS1, 6);
}
PD_Status status()
{
int val = readRegister(HUSB238_PD_STATUS1);
if (val == -1)return NO_RESPONSE;
val >>= 3;
val &= 0x03;
return static_cast<PD_Status>(val);
}
private:
const uint8_t pd_voltage_list[7] = {0, 5, 9, 12, 15, 18, 20};
const float pd_current_list[16] = {
0.5, 0.7, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5,
2.75, 3, 3.25, 3.5, 4, 4.5, 5
};
bool initImpl()
{
return readRegister(HUSB238_PD_STATUS0) != -1;
}
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,995 @@
/**
*
* @license 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.
*
* @file PowersSY6970.tpp
* @author Lewis He (lewishe@outlook.com)
* @date 2023-07-20
*
*/
#if defined(ARDUINO)
#include <Arduino.h>
#else
#include <math.h>
#endif /*ARDUINO*/
#include "XPowersCommon.tpp"
#include "REG/GeneralPPMConstants.h"
#include "REG/SY6970Constants.h"
class PowersSY6970 :
public XPowersCommon<PowersSY6970>
{
friend class XPowersCommon<PowersSY6970>;
public:
enum BusStatus {
BUS_STATE_NOINPUT,
BUS_STATE_USB_SDP,
BUS_STATE_USB_CDP,
BUS_STATE_USB_DCP,
BUS_STATE_HVDCP,
BUS_STATE_ADAPTER,
BUS_STATE_NO_STANDARD_ADAPTER,
BUS_STATE_OTG
} ;
enum ChargeStatus {
CHARGE_STATE_NO_CHARGE,
CHARGE_STATE_PRE_CHARGE,
CHARGE_STATE_FAST_CHARGE,
CHARGE_STATE_DONE,
CHARGE_STATE_UNKOWN,
} ;
enum NTCStatus {
BUCK_NTC_NORMAL = 0,
BUCK_NTC_WARM = 2,
BUCK_NTC_COOL = 3,
BUCK_NTC_COLD = 5,
BUCK_NTC_HOT = 6,
};
enum BoostNTCStatus {
BOOST_NTC_NORMAL = 0,
BOOST_NTC_COLD = 5,
BOOST_NTC_HOT = 6,
};
enum Timeout {
TIMER_OUT_40SEC, //40 Second
TIMER_OUT_80SEC, //80 Second
TIMER_OUT_160SEC, //160 Second
} ;
enum MeasureMode {
ONE_SHORT,
CONTINUOUS,
};
enum BoostFreq {
BOOST_FREQ_1500KHZ,
BOOST_FREQ_500KHZ,
};
enum RequestRange {
REQUEST_9V,
REQUEST_12V,
};
enum FastChargeTimer {
FAST_CHARGE_TIMER_5H,
FAST_CHARGE_TIMER_8H,
FAST_CHARGE_TIMER_12H,
FAST_CHARGE_TIMER_20H,
};
enum BoostCurrentLimit {
BOOST_CUR_LIMIT_500MA,
BOOST_CUR_LIMIT_750MA,
BOOST_CUR_LIMIT_1200MA,
BOOST_CUR_LIMIT_1400MA,
BOOST_CUR_LIMIT_1650MA,
BOOST_CUR_LIMIT_1875MA,
BOOST_CUR_LIMIT_2150MA,
BOOST_CUR_LIMIT_2450MA,
} ;
#if defined(ARDUINO)
PowersSY6970(TwoWire &w, int sda = SDA, int scl = SCL, uint8_t addr = SY6970_SLAVE_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
}
#endif
PowersSY6970(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback)
{
thisReadRegCallback = readRegCallback;
thisWriteRegCallback = writeRegCallback;
__addr = addr;
}
PowersSY6970()
{
#if defined(ARDUINO)
__wire = &Wire;
__sda = SDA;
__scl = SCL;
#endif
__addr = SY6970_SLAVE_ADDRESS;
}
~PowersSY6970()
{
log_i("~PowersSY6970");
deinit();
}
#if defined(ARDUINO)
bool init(TwoWire &w, int sda = SDA, int scl = SCL, uint8_t addr = SY6970_SLAVE_ADDRESS)
{
__wire = &w;
__sda = sda;
__scl = scl;
__addr = addr;
__irq_mask = 0;
return begin();
}
#endif
const char *getChipName()
{
return getChipID() == SY6970_DEV_REV ? "SY6970" : "Unknown";
}
uint8_t getChipID()
{
int res = readRegister(POWERS_PPM_REG_14H);
return (res & 0x03);
}
void resetDefault()
{
setRegisterBit(POWERS_PPM_REG_14H, 7);
}
bool init()
{
return begin();
}
void deinit()
{
end();
}
///REG0B
bool isVbusIn()
{
return getBusStatus() != BUS_STATE_NOINPUT;
}
bool isOTG()
{
return getBusStatus() == BUS_STATE_OTG;
}
bool isCharging(void)
{
return chargeStatus() != CHARGE_STATE_NO_CHARGE;
}
bool isChargeDone()
{
return chargeStatus() == CHARGE_STATE_DONE;
}
bool isBatteryConnect(void) __attribute__((error("Not implemented")))
{
//TODO:
return false;
}
bool isPowerGood()
{
return getRegisterBit(POWERS_PPM_REG_0BH, 2);
}
bool isEnableCharge()
{
return getRegisterBit(POWERS_PPM_REG_03H, 4);
}
void disableCharge()
{
__user_disable_charge = true;
clrRegisterBit(POWERS_PPM_REG_03H, 4);
}
void enableCharge()
{
__user_disable_charge = false;
setRegisterBit(POWERS_PPM_REG_03H, 4);
}
bool isEnableOTG()
{
return getRegisterBit(POWERS_PPM_REG_03H, 5);
}
void disableOTG()
{
clrRegisterBit(POWERS_PPM_REG_03H, 5);
/*
* After turning on the OTG function, the charging function will
* be automatically disabled. If the user does not disable the charging
* function, the charging function will be automatically enabled after
* turning off the OTG output.
* */
if (!__user_disable_charge) {
setRegisterBit(POWERS_PPM_REG_03H, 4);
}
}
bool enableOTG()
{
if (isVbusIn())
return false;
return setRegisterBit(POWERS_PPM_REG_03H, 5);
}
void feedWatchdog()
{
setRegisterBit(POWERS_PPM_REG_03H, 6);
}
bool setSysPowerDownVoltage(uint16_t millivolt)
{
if (millivolt % POWERS_SY6970_SYS_VOL_STEPS) {
log_e("Mistake ! The steps is must %u mV", POWERS_SY6970_SYS_VOL_STEPS);
return false;
}
if (millivolt < POWERS_SY6970_SYS_VOFF_VOL_MIN) {
log_e("Mistake ! SYS minimum output voltage is %umV", POWERS_SY6970_SYS_VOFF_VOL_MIN);
return false;
} else if (millivolt > POWERS_SY6970_SYS_VOFF_VOL_MAX) {
log_e("Mistake ! SYS maximum output voltage is %umV", POWERS_SY6970_SYS_VOFF_VOL_MAX);
return false;
}
int val = readRegister(POWERS_PPM_REG_03H);
if (val == -1)return false;
val &= 0xF1;
val |= (millivolt - POWERS_SY6970_SYS_VOFF_VOL_MIN) / POWERS_SY6970_SYS_VOL_STEPS;
val <<= 1;
return 0 == writeRegister(POWERS_PPM_REG_03H, val);
}
uint16_t getSysPowerDownVoltage()
{
int val = readRegister(POWERS_PPM_REG_03H);
if (val == -1)return 0;
val &= 0x0E;
val >>= 1;
return (val * POWERS_SY6970_SYS_VOL_STEPS) + POWERS_SY6970_SYS_VOFF_VOL_MIN;
}
// Charging Termination Enable
void enableChargingTermination()
{
setRegisterBit(POWERS_PPM_REG_07H, 7);
}
// Charging Termination Enable
void disableChargingTermination()
{
clrRegisterBit(POWERS_PPM_REG_07H, 7);
}
// Charging Termination Enable
bool isEnableChargingTermination()
{
return getRegisterBit(POWERS_PPM_REG_07H, 7);
}
// disableStatPin
void disableStatLed()
{
setRegisterBit(POWERS_PPM_REG_07H, 6);
}
void enableStatLed()
{
clrRegisterBit(POWERS_PPM_REG_07H, 6);
}
bool isEnableStatLed()
{
return getRegisterBit(POWERS_PPM_REG_07H, 6) == false;
}
void disableWatchdog()
{
int regVal = readRegister(POWERS_PPM_REG_07H);
regVal &= 0xCF;
writeRegister(POWERS_PPM_REG_07H, regVal);
}
void enableWatchdog(enum Timeout val)
{
int regVal = readRegister(POWERS_PPM_REG_07H);
regVal &= 0xCF;
switch (val) {
case TIMER_OUT_40SEC:
writeRegister(POWERS_PPM_REG_07H, regVal | 0x10);
break;
case TIMER_OUT_80SEC:
writeRegister(POWERS_PPM_REG_07H, regVal | 0x20);
break;
case TIMER_OUT_160SEC:
writeRegister(POWERS_PPM_REG_07H, regVal | 0x30);
break;
default:
break;
}
}
void disableChargingSafetyTimer()
{
clrRegisterBit(POWERS_PPM_REG_07H, 3);
}
void enableChargingSafetyTimer()
{
setRegisterBit(POWERS_PPM_REG_07H, 3);
}
bool isEnableChargingSafetyTimer()
{
return getRegisterBit(POWERS_PPM_REG_07H, 3);
}
void setFastChargeTimer(FastChargeTimer timer)
{
int val;
switch (timer) {
case FAST_CHARGE_TIMER_5H:
case FAST_CHARGE_TIMER_8H:
case FAST_CHARGE_TIMER_12H:
case FAST_CHARGE_TIMER_20H:
val = readRegister(POWERS_PPM_REG_07H);
if (val == -1)
return;
val &= 0xF1;
val |= (timer << 1);
writeRegister(POWERS_PPM_REG_07H, val);
break;
default:
break;
}
}
FastChargeTimer getFastChargeTimer()
{
int val = readRegister(POWERS_PPM_REG_07H);
return static_cast<FastChargeTimer>((val & 0x0E) >> 1);
}
// Return Battery Load status
bool isEnableBatLoad()
{
return getRegisterBit(POWERS_PPM_REG_03H, 7);
}
// Battery Load (10mA) Disable
void disableBatLoad()
{
clrRegisterBit(POWERS_PPM_REG_03H, 7);
}
// Battery Load (10mA) Enable
void enableBatLoad()
{
setRegisterBit(POWERS_PPM_REG_03H, 7);
}
BusStatus getBusStatus()
{
int val = readRegister(POWERS_PPM_REG_0BH);
return (BusStatus)((val >> 5) & 0x07);
}
const char *getBusStatusString()
{
BusStatus status = getBusStatus();
switch (status) {
case BUS_STATE_NOINPUT:
return "No input";
case BUS_STATE_USB_SDP:
return "USB Host SDP";
case BUS_STATE_USB_CDP:
return "USB CDP";
case BUS_STATE_USB_DCP:
return "USB DCP";
case BUS_STATE_HVDCP:
return "HVDCP";
case BUS_STATE_ADAPTER:
case BUS_STATE_NO_STANDARD_ADAPTER:
return "Adapter";
case BUS_STATE_OTG:
return "OTG";
default:
return "Unknown";
}
}
ChargeStatus chargeStatus()
{
int val = readRegister(POWERS_PPM_REG_0BH);
if (val == -1)return CHARGE_STATE_UNKOWN;
return static_cast<ChargeStatus>((val >> 3) & 0x03);
}
const char *getChargeStatusString()
{
ChargeStatus status = chargeStatus();
switch (status) {
case CHARGE_STATE_NO_CHARGE:
return "Not Charging";
case CHARGE_STATE_PRE_CHARGE:
return "Pre-charge";
case CHARGE_STATE_FAST_CHARGE:
return "Fast Charging";
case CHARGE_STATE_DONE:
return "Charge Termination Done";
default:
return "Unknown";
}
}
uint8_t getNTCStatus()
{
return (__irq_mask & 0x07);
}
const char *getNTCStatusString()
{
uint8_t status = getNTCStatus();
if (isOTG()) {
// Boost mode
switch (status) {
case BOOST_NTC_NORMAL:
return "Boost mode NTC normal";
case BOOST_NTC_COLD:
return "Boost mode NTC cold";
case BOOST_NTC_HOT:
return "Boost mode NTC hot";
default:
break;
}
} else {
// Buck mode
switch (status) {
case BUCK_NTC_NORMAL:
return "Buck mode NTC normal";
case BUCK_NTC_WARM:
return "Buck mode NTC warm";
case BUCK_NTC_COOL:
case BUCK_NTC_COLD:
return "Buck mode NTC cold";
case BUCK_NTC_HOT:
return "Buck mode NTC hot";
default:
break;
}
}
return "Unknown";
}
bool enableADCMeasure() __attribute__((deprecated("The enableADCMeasure method will be replaced by enableMeasure in the future. Please update it to enableMeasure.")))
{
return enableMeasure();
}
bool enableMeasure(MeasureMode mode = CONTINUOUS)
{
int val = readRegister(POWERS_PPM_REG_02H);
switch (mode) {
case CONTINUOUS:
val |= _BV(6);
break;
case ONE_SHORT:
val &= (~_BV(6));
default:
break;
}
val |= _BV(7);
return writeRegister(POWERS_PPM_REG_02H, val) != -1;
}
bool disableADCMeasure()
{
int val = readRegister(POWERS_PPM_REG_02H);
if (val == -1) {
return false;
}
val &= (~_BV(7));
val &= (~_BV(6));
return writeRegister(POWERS_PPM_REG_02H, val) != 1;
}
bool setBoostFreq(BoostFreq freq)
{
switch (freq) {
case BOOST_FREQ_500KHZ:
return setRegisterBit(POWERS_PPM_REG_02H, 5);
case BOOST_FREQ_1500KHZ:
return clrRegisterBit(POWERS_PPM_REG_02H, 5);
default:
break;
}
return false;
}
BoostFreq getBoostFreq()
{
return getRegisterBit(POWERS_PPM_REG_02H, 5) ? BOOST_FREQ_500KHZ : BOOST_FREQ_1500KHZ;
}
void enableInputCurrentLimit()
{
setRegisterBit(POWERS_PPM_REG_02H, 4);
}
void disableInputCurrentLimit()
{
clrRegisterBit(POWERS_PPM_REG_02H, 4);
}
void enableHVDCP()
{
setRegisterBit(POWERS_PPM_REG_02H, 3);
}
void disableHVDCP()
{
clrRegisterBit(POWERS_PPM_REG_02H, 3);
}
bool isEnableHVDCP()
{
return getRegisterBit(POWERS_PPM_REG_02H, 3);
}
void setHighVoltageRequestedRange(RequestRange range)
{
switch (range) {
case REQUEST_9V:
clrRegisterBit(POWERS_PPM_REG_02H, 2);
break;
case REQUEST_12V:
setRegisterBit(POWERS_PPM_REG_02H, 2);
break;
default:
break;
}
}
RequestRange getHighVoltageRequestedRange()
{
return getRegisterBit(POWERS_PPM_REG_02H, 2) ? REQUEST_12V : REQUEST_9V;
}
// Enable Force DP/DM detection
void enableDetectionDPDM()
{
setRegisterBit(POWERS_PPM_REG_02H, 1);
}
// Disable Force DP/DM detection
void disableDetectionDPDM()
{
clrRegisterBit(POWERS_PPM_REG_02H, 1);
}
// Get Force DP/DM detection
bool isEnableDetectionDPDM()
{
return getRegisterBit(POWERS_PPM_REG_02H, 1);
}
// Enable DPDM detection when BUS is plugged-in.
void enableAutoDetectionDPDM()
{
setRegisterBit(POWERS_PPM_REG_02H, 0);
}
// Disable DPDM detection when BUS is plugged-in.
void disableAutoDetectionDPDM()
{
clrRegisterBit(POWERS_PPM_REG_02H, 0);
}
// Get DPDM detection when BUS is plugged-in.
bool isEnableAutoDetectionDPDM()
{
return getRegisterBit(POWERS_PPM_REG_02H, 0);
}
bool setInputCurrentLimit(uint16_t milliampere)
{
if (milliampere % POWERS_SY6970_IN_CURRENT_STEP) {
log_e("Mistake ! The steps is must %u mA", POWERS_SY6970_IN_CURRENT_STEP);
return false;
}
if (milliampere < POWERS_SY6970_IN_CURRENT_MIN) {
milliampere = POWERS_SY6970_IN_CURRENT_MIN;
}
if (milliampere > POWERS_SY6970_IN_CURRENT_MAX) {
milliampere = POWERS_SY6970_IN_CURRENT_MAX;
}
int val = readRegister(POWERS_PPM_REG_00H);
if (val == -1)
return false;
val &= 0xC0;
milliampere = ((milliampere - POWERS_SY6970_IN_CURRENT_MIN) / POWERS_SY6970_IN_CURRENT_STEP);
val |= milliampere;
return writeRegister(POWERS_PPM_REG_00H, val) != -1;
}
uint32_t getInputCurrentLimit()
{
int val = readRegister(POWERS_PPM_REG_00H);
if (val == -1)
return false;
val &= 0x3F;
return (val * POWERS_SY6970_IN_CURRENT_STEP) + POWERS_SY6970_IN_CURRENT_MIN;
}
// USB input path is disabled and can only be reset by disconnecting
// the power supply, otherwise the power cannot be turned on
void enterHizMode()
{
setRegisterBit(POWERS_PPM_REG_00H, 7);
}
void exitHizMode()
{
clrRegisterBit(POWERS_PPM_REG_00H, 7);
}
bool isHizMode()
{
return getRegisterBit(POWERS_PPM_REG_00H, 7);
}
void enableCurrentLimitPin()
{
setRegisterBit(POWERS_PPM_REG_00H, 6);
}
void disableCurrentLimitPin()
{
clrRegisterBit(POWERS_PPM_REG_00H, 6);
}
bool isEnableCurrentLimitPin()
{
return getRegisterBit(POWERS_PPM_REG_00H, 6);
}
uint16_t getVbusVoltage()
{
if (!isVbusIn()) {
return 0;
}
int val = readRegister(POWERS_PPM_REG_11H);
return (POWERS_SY6970_VBUS_MASK_VAL(val) * POWERS_SY6970_VBUS_VOL_STEP) + POWERS_SY6970_VBUS_BASE_VAL;
}
uint16_t getBattVoltage()
{
int val = readRegister(POWERS_PPM_REG_0EH);
val = POWERS_SY6970_VBAT_MASK_VAL(val);
if (val == 0)return 0;
return (val * POWERS_SY6970_VBAT_VOL_STEP) + POWERS_SY6970_VBAT_BASE_VAL;
}
uint16_t getSystemVoltage()
{
int val = readRegister(POWERS_PPM_REG_0FH);
return (POWERS_SY6970_VSYS_MASK_VAL(val) * POWERS_SY6970_VSYS_VOL_STEP) + POWERS_SY6970_VSYS_BASE_VAL;
}
float getNTCPercentage()
{
int val = readRegister(POWERS_PPM_REG_10H);
return (POWERS_SY6970_NTC_MASK_VAL(val) * POWERS_SY6970_NTC_VOL_STEP) + POWERS_SY6970_NTC_BASE_VAL;
}
uint16_t getChargeCurrent()
{
ChargeStatus status = chargeStatus();
if (status == CHARGE_STATE_NO_CHARGE) {
return 0;
}
//* If the charger is disconnected, the value in the register
//* will remain the last value and will not be updated to 0.
int val = readRegister(POWERS_PPM_REG_12H);
if (val == 0)return 0;
val = (val & 0x7F);
return (val * POWERS_SY6970_CHG_STEP_VAL) ;
}
// Range: 64mA ~ 1024 mA ,step:64mA
bool setPrechargeCurr(uint16_t milliampere)
{
if (milliampere % POWERS_SY6970_PRE_CHG_CUR_STEP) {
log_e("Mistake ! The steps is must %u mA", POWERS_SY6970_PRE_CHG_CUR_STEP);
return false;
}
if (milliampere < POWERS_SY6970_PRE_CHG_CURRENT_MIN) {
milliampere = POWERS_SY6970_PRE_CHG_CURRENT_MIN;
}
if (milliampere > POWERS_SY6970_PRE_CHG_CURRENT_MAX) {
milliampere = POWERS_SY6970_PRE_CHG_CURRENT_MAX;
}
int val = readRegister(POWERS_PPM_REG_05H);
val &= 0x0F;
milliampere = ((milliampere - POWERS_SY6970_PRE_CHG_CUR_BASE) / POWERS_SY6970_PRE_CHG_CUR_STEP);
val |= milliampere << 4;
return writeRegister(POWERS_PPM_REG_05H, val) != -1;
}
uint16_t getPrechargeCurr(void)
{
int val = readRegister(POWERS_PPM_REG_05H);
val &= 0xF0;
val >>= 4;
return POWERS_SY6970_PRE_CHG_CUR_STEP + (val * POWERS_SY6970_PRE_CHG_CUR_STEP);
}
uint16_t getChargerConstantCurr()
{
int val = readRegister(POWERS_PPM_REG_04H);
val &= 0x7F;
return val * POWERS_SY6970_FAST_CHG_CUR_STEP;
}
/**
* @brief setChargerConstantCurr
* @note
* @param milliampere: SY6970 Range:0~5056 mA / step:64mA
* @retval true : success false : failed
*/
bool setChargerConstantCurr(uint16_t milliampere)
{
if (milliampere % POWERS_SY6970_FAST_CHG_CUR_STEP) {
log_e("Mistake ! The steps is must %u mA", POWERS_SY6970_FAST_CHG_CUR_STEP);
return false;
}
if (milliampere > POWERS_SY6970_FAST_CHG_CURRENT_MAX) {
milliampere = POWERS_SY6970_FAST_CHG_CURRENT_MAX;
}
int val = readRegister(POWERS_PPM_REG_04H);
val &= 0x80;
val |= (milliampere / POWERS_SY6970_FAST_CHG_CUR_STEP);
return writeRegister(POWERS_PPM_REG_04H, val) != -1;
}
uint16_t getChargeTargetVoltage()
{
int val = readRegister(POWERS_PPM_REG_06H);
val = (val & 0xFC) >> 2;
if (val > 0x30) {
return POWERS_SY6970_FAST_CHG_VOL_MAX;
}
return val * POWERS_SY6970_CHG_VOL_STEP + POWERS_SY6970_CHG_VOL_BASE;
}
// Range:3840 ~ 4608mV ,step:16 mV
bool setChargeTargetVoltage(uint16_t millivolt)
{
if (millivolt % POWERS_SY6970_CHG_VOL_STEP) {
log_e("Mistake ! The steps is must %u mV", POWERS_SY6970_CHG_VOL_STEP);
return false;
}
if (millivolt < POWERS_SY6970_FAST_CHG_VOL_MIN) {
millivolt = POWERS_SY6970_FAST_CHG_VOL_MIN;
}
if (millivolt > POWERS_SY6970_FAST_CHG_VOL_MAX) {
millivolt = POWERS_SY6970_FAST_CHG_VOL_MAX;
}
int val = readRegister(POWERS_PPM_REG_06H);
val &= 0x03;
val |= (((millivolt - POWERS_SY6970_CHG_VOL_BASE) / POWERS_SY6970_CHG_VOL_STEP) << 2);
return writeRegister(POWERS_PPM_REG_06H, val) != -1;
}
// Turn off the battery power supply path. It can only be turned off when the
// battery is powered. It cannot be turned off when USB is connected.
// The device can only be powered on by pressing the PWR button or by connecting the power supply.
void shutdown()
{
disableBatterPowerPath();
}
// Close battery power path
void disableBatterPowerPath()
{
setRegisterBit(POWERS_PPM_REG_09H, 5); //Force BATFET Off : BATFET_DIS
}
// Enable battery power path
void enableBatterPowerPath()
{
clrRegisterBit(POWERS_PPM_REG_09H, 5); //Force BATFET Off : BATFET_DIS
}
// Boost Mode Voltage Regulation: 4550 mV ~ 5510 mV
bool setBoostVoltage(uint16_t millivolt)
{
if (millivolt % POWERS_SY6970_BOOTS_VOL_STEP) {
log_e("Mistake ! The steps is must %u mV", POWERS_SY6970_BOOTS_VOL_STEP);
return false;
}
if (millivolt < POWERS_SY6970_BOOST_VOL_MIN) {
millivolt = POWERS_SY6970_BOOST_VOL_MIN;
}
if (millivolt > POWERS_SY6970_BOOST_VOL_MAX) {
millivolt = POWERS_SY6970_BOOST_VOL_MAX;
}
int val = readRegister(POWERS_PPM_REG_0AH);
val &= 0xF0;
val |= (((millivolt - POWERS_SY6970_BOOTS_VOL_BASE) / POWERS_SY6970_BOOTS_VOL_STEP) << 4);
return writeRegister(POWERS_PPM_REG_0AH, val) != -1;
}
// Boost Current Limit: 500mA ~ 2450mA
bool setBoostCurrentLimit(BoostCurrentLimit milliampere)
{
if (milliampere > BOOST_CUR_LIMIT_2450MA) {
return false;
}
int val = readRegister(POWERS_PPM_REG_0AH);
val &= 0x03;
val |= milliampere;
return writeRegister(POWERS_PPM_REG_0AH, val) != -1;
}
uint8_t getFaultStatus(void)
{
int val = readRegister(POWERS_PPM_REG_0CH);
if (val == -1) {
return 0;
}
__irq_mask = val;
return __irq_mask;
}
void getReadOnlyRegisterValue()
{
#if defined(ARDUINO) && !defined(ARDUINO_ARCH_MBED) && !defined(ARDUINO_ARCH_ZEPHYR) //debug ..
static uint8_t last_val[8] = {0};
const uint8_t regis[] = {
POWERS_PPM_REG_0BH,
POWERS_PPM_REG_0CH,
// POWERS_PPM_REG_0EH, //BATTERY VOLTAGE
// POWERS_PPM_REG_0FH, //SYSTEM VOLTAGE
// POWERS_PPM_REG_10H, //NTC PERCENTAGE
// POWERS_PPM_REG_11H, //VBUS VOLTAGE
POWERS_PPM_REG_12H,
POWERS_PPM_REG_13H
};
Serial.println();
Serial.println("-------------------------");
for (uint32_t i = 0; i < sizeof(regis) / sizeof(regis[0]); ++i) {
int val = readRegister(regis[i]);
if (val == -1) {
continue;
}
if (last_val[i] != val) {
Serial.printf("\t---> REG%02X Prev:0x%02X ", regis[i], last_val[i]);
Serial.print(" BIN:"); Serial.print(last_val[i], BIN);
Serial.printf(" Curr: 0x%02X", val);
Serial.print(" BIN:"); Serial.println(val, BIN);
last_val[i] = val;
}
Serial.printf("\tREG%02XH:0x%X BIN:0b", regis[i], val);
Serial.println(val, BIN);
}
Serial.println("-------------------------");
#endif
}
bool isWatchdogFault()
{
return POWERS_SY6970_IRQ_WTD_FAULT(__irq_mask);
}
bool isBoostFault()
{
return POWERS_SY6970_IRQ_BOOST_FAULT(__irq_mask);
}
bool isChargeFault()
{
return POWERS_SY6970_IRQ_CHG_FAULT(__irq_mask);
}
bool isBatteryFault()
{
return POWERS_SY6970_IRQ_BAT_FAULT(__irq_mask);
}
bool isNTCFault()
{
return POWERS_SY6970_IRQ_NTC_FAULT(__irq_mask);
}
bool setVinDpmThreshold(uint16_t millivolt)
{
if (millivolt % POWERS_SY6970_VINDPM_VOL_STEPS) {
log_e("Mistake ! The steps is must %u mV", POWERS_SY6970_VINDPM_VOL_STEPS);
return false;
}
if (millivolt < POWERS_SY6970_VINDPM_VOL_MIN) {
millivolt = POWERS_SY6970_VINDPM_VOL_MIN;
}
if (millivolt > POWERS_SY6970_VINDPM_VOL_MAX) {
millivolt = POWERS_SY6970_VINDPM_VOL_MAX;
}
int val = readRegister(POWERS_PPM_REG_0DH);
val &= 0x80;
val |= (((millivolt - POWERS_SY6970_VINDPM_VOL_BASE) / POWERS_SY6970_VINDPM_VOL_STEPS));
return writeRegister(POWERS_PPM_REG_0DH, val) != -1;
}
private:
bool initImpl()
{
__user_disable_charge = false;
uint8_t rev = getChipID();
if (rev != SY6970_DEV_REV) {
return false;
}
// Set the minimum operating voltage. Below this voltage, the PMU will protect
// setSysPowerDownVoltage(3300);
//Default disable Watchdog
disableWatchdog();
return true;
}
bool __user_disable_charge;
uint32_t __irq_mask;
};

View File

@@ -0,0 +1,182 @@
#pragma once
#define AXP192_SLAVE_ADDRESS (0x34)
#define XPOWERS_AXP192_CHIP_ID (0x03)
#define XPOWERS_AXP192_STATUS (0x00)
#define XPOWERS_AXP192_MODE_CHGSTATUS (0x01)
#define XPOWERS_AXP192_OTG_STATUS (0x02)
#define XPOWERS_AXP192_IC_TYPE (0x03)
#define XPOWERS_AXP192_DATA_BUFFER1 (0x06)
#define XPOWERS_AXP192_DATA_BUFFER2 (0x07)
#define XPOWERS_AXP192_DATA_BUFFER3 (0x08)
#define XPOWERS_AXP192_DATA_BUFFER4 (0x09)
#define XPOWERS_AXP192_DATA_BUFFER5 (0x0A)
#define XPOWERS_AXP192_DATA_BUFFER6 (0x0B)
#define XPOWERS_AXP192_DATA_BUFFER_SIZE (6)
#define XPOWERS_AXP192_LDO23_DC123_EXT_CTL (0x12)
#define XPOWERS_AXP192_DC2OUT_VOL (0x23)
#define XPOWERS_AXP192_DC2_DVM (0x25)
#define XPOWERS_AXP192_DC3OUT_VOL (0x27)
#define XPOWERS_AXP192_LDO24OUT_VOL (0x28)
#define XPOWERS_AXP192_LDO3OUT_VOL (0x29)
#define XPOWERS_AXP192_IPS_SET (0x30)
#define XPOWERS_AXP192_VOFF_SET (0x31)
#define XPOWERS_AXP192_OFF_CTL (0x32)
#define XPOWERS_AXP192_CHARGE1 (0x33)
#define XPOWERS_AXP192_CHARGE2 (0x34)
#define XPOWERS_AXP192_BACKUP_CHG (0x35)
#define XPOWERS_AXP192_POK_SET (0x36)
#define XPOWERS_AXP192_DCDC_FREQSET (0x37)
#define XPOWERS_AXP192_VLTF_CHGSET (0x38)
#define XPOWERS_AXP192_VHTF_CHGSET (0x39)
#define XPOWERS_AXP192_APS_WARNING1 (0x3A)
#define XPOWERS_AXP192_APS_WARNING2 (0x3B)
#define XPOWERS_AXP192_TLTF_DISCHGSET (0x3C)
#define XPOWERS_AXP192_THTF_DISCHGSET (0x3D)
#define XPOWERS_AXP192_DCDC_MODESET (0x80)
#define XPOWERS_AXP192_ADC_EN1 (0x82)
#define XPOWERS_AXP192_ADC_EN2 (0x83)
#define XPOWERS_AXP192_ADC_SPEED (0x84)
#define XPOWERS_AXP192_ADC_INPUTRANGE (0x85)
#define XPOWERS_AXP192_ADC_IRQ_RETFSET (0x86)
#define XPOWERS_AXP192_ADC_IRQ_FETFSET (0x87)
#define XPOWERS_AXP192_TIMER_CTL (0x8A)
#define XPOWERS_AXP192_VBUS_DET_SRP (0x8B)
#define XPOWERS_AXP192_HOTOVER_CTL (0x8F)
#define XPOWERS_AXP192_PWM1_FREQ_SET (0x98)
#define XPOWERS_AXP192_PWM1_DUTY_SET1 (0x99)
#define XPOWERS_AXP192_PWM1_DUTY_SET2 (0x9A)
#define XPOWERS_AXP192_PWM2_FREQ_SET (0x9B)
#define XPOWERS_AXP192_PWM2_DUTY_SET1 (0x9C)
#define XPOWERS_AXP192_PWM2_DUTY_SET2 (0x9D)
// INTERRUPT REGISTER
#define XPOWERS_AXP192_INTEN1 (0x40)
#define XPOWERS_AXP192_INTEN2 (0x41)
#define XPOWERS_AXP192_INTEN3 (0x42)
#define XPOWERS_AXP192_INTEN4 (0x43)
#define XPOWERS_AXP192_INTEN5 (0x4A)
// INTERRUPT STATUS REGISTER
#define XPOWERS_AXP192_INTSTS1 (0x44)
#define XPOWERS_AXP192_INTSTS2 (0x45)
#define XPOWERS_AXP192_INTSTS3 (0x46)
#define XPOWERS_AXP192_INTSTS4 (0x47)
#define XPOWERS_AXP192_INTSTS5 (0x4D)
#define XPOWERS_AXP192_INTSTS_CNT (5)
#define XPOWERS_AXP192_DC1_VLOTAGE (0x26)
#define XPOWERS_AXP192_LDO23OUT_VOL (0x28)
#define XPOWERS_AXP192_GPIO0_CTL (0x90)
#define XPOWERS_AXP192_GPIO0_VOL (0x91)
#define XPOWERS_AXP192_GPIO1_CTL (0X92)
#define XPOWERS_AXP192_GPIO2_CTL (0x93)
#define XPOWERS_AXP192_GPIO012_SIGNAL (0x94)
#define XPOWERS_AXP192_GPIO34_CTL (0x95)
#define XPOWERS_AXP192_GPIO34_SIGNAL (0x96)
#define XPOWERS_AXP192_GPIO012_PULLDOWN (0x97)
#define XPOWERS_AXP192_GPIO5_CTL (0x9E)
#define XPOWERS_AXP192_GPIO0_VOL_ADC_H8 (0x64)
#define XPOWERS_AXP192_GPIO0_VOL_ADC_L4 (0x65)
#define XPOWERS_AXP192_GPIO1_VOL_ADC_H8 (0x66)
#define XPOWERS_AXP192_GPIO1_VOL_ADC_L4 (0x67)
#define XPOWERS_AXP192_GPIO2_VOL_ADC_H8 (0x68)
#define XPOWERS_AXP192_GPIO2_VOL_ADC_L4 (0x69)
#define XPOWERS_AXP192_GPIO3_VOL_ADC_H8 (0x6A)
#define XPOWERS_AXP192_GPIO3_VOL_ADC_L4 (0x6B)
#define XPOWERS_AXP192_GPIO0_STEP (0.5F)
#define XPOWERS_AXP192_GPIO1_STEP (0.5F)
#define XPOWERS_AXP192_TS_IN_H8 (0x62)
#define XPOWERS_AXP192_TS_IN_L4 (0x63)
#define XPOWERS_AXP192_BAT_AVERCHGCUR_H8 (0x7A)
#define XPOWERS_AXP192_BAT_AVERCHGCUR_L5 (0x7B)
#define XPOWERS_AXP192_ACIN_VOL_H8 (0x56)
#define XPOWERS_AXP192_ACIN_VOL_L4 (0x57)
#define XPOWERS_AXP192_ACIN_CUR_H8 (0x58)
#define XPOWERS_AXP192_ACIN_CUR_L4 (0x59)
#define XPOWERS_AXP192_VBUS_VOL_H8 (0x5A)
#define XPOWERS_AXP192_VBUS_VOL_L4 (0x5B)
#define XPOWERS_AXP192_VBUS_CUR_H8 (0x5C)
#define XPOWERS_AXP192_VBUS_CUR_L4 (0x5D)
#define XPOWERS_AXP192_BAT_AVERDISCHGCUR_H8 (0x7C)
#define XPOWERS_AXP192_BAT_AVERDISCHGCUR_L5 (0x7D)
#define XPOWERS_AXP192_APS_AVERVOL_H8 (0x7E)
#define XPOWERS_AXP192_APS_AVERVOL_L4 (0x7F)
#define XPOWERS_AXP192_BAT_AVERVOL_H8 (0x78)
#define XPOWERS_AXP192_BAT_AVERVOL_L4 (0x79)
#define XPOWERS_AXP192_BAT_CHGCOULOMB3 (0xB0)
#define XPOWERS_AXP192_BAT_CHGCOULOMB2 (0xB1)
#define XPOWERS_AXP192_BAT_CHGCOULOMB1 (0xB2)
#define XPOWERS_AXP192_BAT_CHGCOULOMB0 (0xB3)
#define XPOWERS_AXP192_BAT_DISCHGCOULOMB3 (0xB4)
#define XPOWERS_AXP192_BAT_DISCHGCOULOMB2 (0xB5)
#define XPOWERS_AXP192_BAT_DISCHGCOULOMB1 (0xB6)
#define XPOWERS_AXP192_BAT_DISCHGCOULOMB0 (0xB7)
#define XPOWERS_AXP192_COULOMB_CTL (0xB8)
#define XPOWERS_AXP192_BATT_VOLTAGE_STEP (1.1F)
#define XPOWERS_AXP192_BATT_DISCHARGE_CUR_STEP (0.5F)
#define XPOWERS_AXP192_BATT_CHARGE_CUR_STEP (0.5F)
#define XPOWERS_AXP192_ACIN_VOLTAGE_STEP (1.7F)
#define XPOWERS_AXP192_ACIN_CUR_STEP (0.625F)
#define XPOWERS_AXP192_VBUS_VOLTAGE_STEP (1.7F)
#define XPOWERS_AXP192_VBUS_CUR_STEP (0.375F)
#define XPOWERS_AXP192_APS_VOLTAGE_STEP (1.4F)
#define XPOWERS_AXP192_TS_PIN_OUT_STEP (0.8F)
#define XPOWERS_AXP192_LDO2_VOL_MIN (1800u)
#define XPOWERS_AXP192_LDO2_VOL_MAX (3300u)
#define XPOWERS_AXP192_LDO2_VOL_STEPS (100u)
#define XPOWERS_AXP192_LDO2_VOL_BIT_MASK (4u)
#define XPOWERS_AXP192_LDO3_VOL_MIN (1800u)
#define XPOWERS_AXP192_LDO3_VOL_MAX (3300u)
#define XPOWERS_AXP192_LDO3_VOL_STEPS (100u)
#define XPOWERS_AXP192_DC1_VOL_STEPS (25u)
#define XPOWERS_AXP192_DC1_VOL_MIN (700u)
#define XPOWERS_AXP192_DC1_VOL_MAX (3500u)
#define XPOWERS_AXP192_DC2_VOL_STEPS (25u)
#define XPOWERS_AXP192_DC2_VOL_MIN (700u)
#define XPOWERS_AXP192_DC2_VOL_MAX (3500u)
#define XPOWERS_AXP192_DC3_VOL_STEPS (25u)
#define XPOWERS_AXP192_DC3_VOL_MIN (700u)
#define XPOWERS_AXP192_DC3_VOL_MAX (3500u)
#define XPOWERS_AXP192_LDOIO_VOL_STEPS (100)
#define XPOWERS_AXP192_LDOIO_VOL_MIN (1800)
#define XPOWERS_AXP192_LDOIO_VOL_MAX (3300)
#define XPOWERS_AXP192_SYS_VOL_STEPS (100)
#define XPOWERS_AXP192_VOFF_VOL_MIN (2600)
#define XPOWERS_AXP192_VOFF_VOL_MAX (3300)
#define XPOWERS_AXP192_CHG_EXT_CURR_MIN (300)
#define XPOWERS_AXP192_CHG_EXT_CURR_MAX (1000)
#define XPOWERS_AXP192_CHG_EXT_CURR_STEP (100)
#define XPOWERS_AXP192_INTERNAL_TEMP_H8 (0x5E)
#define XPOWERS_AXP192_INTERNAL_TEMP_L4 (0x5F)
#define XPOWERS_AXP192_INTERNAL_TEMP_STEP (0.1F)
#define XPOWERS_AXP192_INTERNAL_TEMP_OFFSET (144.7)

View File

@@ -0,0 +1,192 @@
#pragma once
#define AXP202_SLAVE_ADDRESS (0x35)
#define XPOWERS_AXP202_CHIP_ID (0x41)
#define XPOWERS_AXP202_STATUS (0x00)
#define XPOWERS_AXP202_MODE_CHGSTATUS (0x01)
#define XPOWERS_AXP202_OTG_STATUS (0x02)
#define XPOWERS_AXP202_IC_TYPE (0x03)
#define XPOWERS_AXP202_DATA_BUFFER1 (0x04)
#define XPOWERS_AXP202_DATA_BUFFER2 (0x05)
#define XPOWERS_AXP202_DATA_BUFFER3 (0x06)
#define XPOWERS_AXP202_DATA_BUFFER4 (0x07)
#define XPOWERS_AXP202_DATA_BUFFER5 (0x08)
#define XPOWERS_AXP202_DATA_BUFFER6 (0x09)
#define XPOWERS_AXP202_DATA_BUFFER7 (0x0A)
#define XPOWERS_AXP202_DATA_BUFFER8 (0x0B)
#define XPOWERS_AXP202_DATA_BUFFER9 (0x0C)
#define XPOWERS_AXP202_DATA_BUFFERA (0x0D)
#define XPOWERS_AXP202_DATA_BUFFERB (0x0E)
#define XPOWERS_AXP202_DATA_BUFFERC (0x0F)
#define XPOWERS_AXP202_LDO234_DC23_CTL (0x12)
#define XPOWERS_AXP202_DC2OUT_VOL (0x23)
#define XPOWERS_AXP202_LDO3_DC2_DVM (0x25)
#define XPOWERS_AXP202_DC3OUT_VOL (0x27)
#define XPOWERS_AXP202_LDO24OUT_VOL (0x28)
#define XPOWERS_AXP202_LDO3OUT_VOL (0x29)
#define XPOWERS_AXP202_IPS_SET (0x30)
#define XPOWERS_AXP202_VOFF_SET (0x31)
#define XPOWERS_AXP202_OFF_CTL (0x32)
#define XPOWERS_AXP202_CHARGE1 (0x33)
#define XPOWERS_AXP202_CHARGE2 (0x34)
#define XPOWERS_AXP202_BACKUP_CHG (0x35)
#define XPOWERS_AXP202_POK_SET (0x36)
#define XPOWERS_AXP202_DCDC_FREQSET (0x37)
#define XPOWERS_AXP202_VLTF_CHGSET (0x38)
#define XPOWERS_AXP202_VHTF_CHGSET (0x39)
#define XPOWERS_AXP202_APS_WARNING1 (0x3A)
#define XPOWERS_AXP202_APS_WARNING2 (0x3B)
#define XPOWERS_AXP202_TLTF_DISCHGSET (0x3C)
#define XPOWERS_AXP202_THTF_DISCHGSET (0x3D)
#define XPOWERS_AXP202_DCDC_MODESET (0x80)
#define XPOWERS_AXP202_ADC_EN1 (0x82)
#define XPOWERS_AXP202_ADC_EN2 (0x83)
#define XPOWERS_AXP202_ADC_SPEED (0x84)
#define XPOWERS_AXP202_ADC_INPUTRANGE (0x85)
#define XPOWERS_AXP202_ADC_IRQ_RETFSET (0x86)
#define XPOWERS_AXP202_ADC_IRQ_FETFSET (0x87)
#define XPOWERS_AXP202_TIMER_CTL (0x8A)
#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)
#define XPOWERS_AXP202_GPIO2_CTL (0x93)
#define XPOWERS_AXP202_GPIO012_SIGNAL (0x94)
#define XPOWERS_AXP202_GPIO3_CTL (0x95)
// INTERRUPT REGISTER
#define XPOWERS_AXP202_INTEN1 (0x40)
#define XPOWERS_AXP202_INTEN2 (0x41)
#define XPOWERS_AXP202_INTEN3 (0x42)
#define XPOWERS_AXP202_INTEN4 (0x43)
#define XPOWERS_AXP202_INTEN5 (0x44)
//INTERRUPT STATUS REGISTER
#define XPOWERS_AXP202_INTSTS1 (0x48)
#define XPOWERS_AXP202_INTSTS2 (0x49)
#define XPOWERS_AXP202_INTSTS3 (0x4A)
#define XPOWERS_AXP202_INTSTS4 (0x4B)
#define XPOWERS_AXP202_INTSTS5 (0x4C)
#define XPOWERS_AXP202_INTSTS_CNT (5)
//AXP ADC DATA REGISTER
#define XPOWERS_AXP202_GPIO0_VOL_ADC_H8 (0x64)
#define XPOWERS_AXP202_GPIO0_VOL_ADC_L4 (0x65)
#define XPOWERS_AXP202_GPIO1_VOL_ADC_H8 (0x66)
#define XPOWERS_AXP202_GPIO1_VOL_ADC_L4 (0x67)
#define XPOWERS_AXP202_GPIO0_STEP (0.5F)
#define XPOWERS_AXP202_GPIO1_STEP (0.5F)
#define XPOWERS_AXP202_BAT_AVERVOL_H8 (0x78)
#define XPOWERS_AXP202_BAT_AVERVOL_L4 (0x79)
#define XPOWERS_AXP202_BAT_AVERCHGCUR_H8 (0x7A)
#define XPOWERS_AXP202_BAT_AVERCHGCUR_L4 (0x7B)
#define XPOWERS_AXP202_BAT_AVERCHGCUR_L5 (0x7B)
#define XPOWERS_AXP202_ACIN_VOL_H8 (0x56)
#define XPOWERS_AXP202_ACIN_VOL_L4 (0x57)
#define XPOWERS_AXP202_ACIN_CUR_H8 (0x58)
#define XPOWERS_AXP202_ACIN_CUR_L4 (0x59)
#define XPOWERS_AXP202_VBUS_VOL_H8 (0x5A)
#define XPOWERS_AXP202_VBUS_VOL_L4 (0x5B)
#define XPOWERS_AXP202_VBUS_CUR_H8 (0x5C)
#define XPOWERS_AXP202_VBUS_CUR_L4 (0x5D)
#define XPOWERS_AXP202_INTERNAL_TEMP_H8 (0x5E)
#define XPOWERS_AXP202_INTERNAL_TEMP_L4 (0x5F)
#define XPOWERS_AXP202_TS_IN_H8 (0x62)
#define XPOWERS_AXP202_TS_IN_L4 (0x63)
#define XPOWERS_AXP202_GPIO0_VOL_ADC_H8 (0x64)
#define XPOWERS_AXP202_GPIO0_VOL_ADC_L4 (0x65)
#define XPOWERS_AXP202_GPIO1_VOL_ADC_H8 (0x66)
#define XPOWERS_AXP202_GPIO1_VOL_ADC_L4 (0x67)
#define XPOWERS_AXP202_BAT_AVERDISCHGCUR_H8 (0x7C)
#define XPOWERS_AXP202_BAT_AVERDISCHGCUR_L5 (0x7D)
#define XPOWERS_AXP202_APS_AVERVOL_H8 (0x7E)
#define XPOWERS_AXP202_APS_AVERVOL_L4 (0x7F)
#define XPOWERS_AXP202_INT_BAT_CHGCUR_H8 (0xA0)
#define XPOWERS_AXP202_INT_BAT_CHGCUR_L4 (0xA1)
#define XPOWERS_AXP202_EXT_BAT_CHGCUR_H8 (0xA2)
#define XPOWERS_AXP202_EXT_BAT_CHGCUR_L4 (0xA3)
#define XPOWERS_AXP202_INT_BAT_DISCHGCUR_H8 (0xA4)
#define XPOWERS_AXP202_INT_BAT_DISCHGCUR_L4 (0xA5)
#define XPOWERS_AXP202_EXT_BAT_DISCHGCUR_H8 (0xA6)
#define XPOWERS_AXP202_EXT_BAT_DISCHGCUR_L4 (0xA7)
#define XPOWERS_AXP202_BAT_CHGCOULOMB3 (0xB0)
#define XPOWERS_AXP202_BAT_CHGCOULOMB2 (0xB1)
#define XPOWERS_AXP202_BAT_CHGCOULOMB1 (0xB2)
#define XPOWERS_AXP202_BAT_CHGCOULOMB0 (0xB3)
#define XPOWERS_AXP202_BAT_DISCHGCOULOMB3 (0xB4)
#define XPOWERS_AXP202_BAT_DISCHGCOULOMB2 (0xB5)
#define XPOWERS_AXP202_BAT_DISCHGCOULOMB1 (0xB6)
#define XPOWERS_AXP202_BAT_DISCHGCOULOMB0 (0xB7)
#define XPOWERS_AXP202_COULOMB_CTL (0xB8)
#define XPOWERS_AXP202_BATT_PERCENTAGE (0xB9)
#define XPOWERS_AXP202_BAT_POWERH8 (0x70)
#define XPOWERS_AXP202_BAT_POWERM8 (0x71)
#define XPOWERS_AXP202_BAT_POWERL8 (0x72)
#define XPOWERS_AXP202_BATT_VOLTAGE_STEP (1.1F)
#define XPOWERS_AXP202_BATT_DISCHARGE_CUR_STEP (0.5F)
#define XPOWERS_AXP202_BATT_CHARGE_CUR_STEP (0.5F)
#define XPOWERS_AXP202_ACIN_VOLTAGE_STEP (1.7F)
#define XPOWERS_AXP202_ACIN_CUR_STEP (0.625F)
#define XPOWERS_AXP202_VBUS_VOLTAGE_STEP (1.7F)
#define XPOWERS_AXP202_VBUS_CUR_STEP (0.375F)
#define XPOWERS_AXP202_INTERNAL_TEMP_STEP (0.1F)
#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 (700u)
#define XPOWERS_AXP202_LDO3_VOL_MAX (3500u)
#define XPOWERS_AXP202_LDO3_VOL_STEPS (25u)
#define XPOWERS_AXP202_DC2_VOL_STEPS (25u)
#define XPOWERS_AXP202_DC2_VOL_MIN (700u)
#define XPOWERS_AXP202_DC2_VOL_MAX (2275u)
#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_INTERNAL_TEMP_OFFSET (144.7)

View File

@@ -0,0 +1,242 @@
#pragma once
#define AXP2101_SLAVE_ADDRESS (0x34)
#define XPOWERS_AXP2101_CHIP_ID (0x4A)
#define XPOWERS_AXP2101_STATUS1 (0x00)
#define XPOWERS_AXP2101_STATUS2 (0x01)
#define XPOWERS_AXP2101_IC_TYPE (0x03)
#define XPOWERS_AXP2101_DATA_BUFFER1 (0x04)
#define XPOWERS_AXP2101_DATA_BUFFER2 (0x05)
#define XPOWERS_AXP2101_DATA_BUFFER3 (0x06)
#define XPOWERS_AXP2101_DATA_BUFFER4 (0x07)
#define XPOWERS_AXP2101_DATA_BUFFER_SIZE (4u)
#define XPOWERS_AXP2101_COMMON_CONFIG (0x10)
#define XPOWERS_AXP2101_BATFET_CTRL (0x12)
#define XPOWERS_AXP2101_DIE_TEMP_CTRL (0x13)
#define XPOWERS_AXP2101_MIN_SYS_VOL_CTRL (0x14)
#define XPOWERS_AXP2101_INPUT_VOL_LIMIT_CTRL (0x15)
#define XPOWERS_AXP2101_INPUT_CUR_LIMIT_CTRL (0x16)
#define XPOWERS_AXP2101_RESET_FUEL_GAUGE (0x17)
#define XPOWERS_AXP2101_CHARGE_GAUGE_WDT_CTRL (0x18)
#define XPOWERS_AXP2101_WDT_CTRL (0x19)
#define XPOWERS_AXP2101_LOW_BAT_WARN_SET (0x1A)
#define XPOWERS_AXP2101_PWRON_STATUS (0x20)
#define XPOWERS_AXP2101_PWROFF_STATUS (0x21)
#define XPOWERS_AXP2101_PWROFF_EN (0x22)
#define XPOWERS_AXP2101_DC_OVP_UVP_CTRL (0x23)
#define XPOWERS_AXP2101_VOFF_SET (0x24)
#define XPOWERS_AXP2101_PWROK_SEQU_CTRL (0x25)
#define XPOWERS_AXP2101_SLEEP_WAKEUP_CTRL (0x26)
#define XPOWERS_AXP2101_IRQ_OFF_ON_LEVEL_CTRL (0x27)
#define XPOWERS_AXP2101_FAST_PWRON_SET0 (0x28)
#define XPOWERS_AXP2101_FAST_PWRON_SET1 (0x29)
#define XPOWERS_AXP2101_FAST_PWRON_SET2 (0x2A)
#define XPOWERS_AXP2101_FAST_PWRON_CTRL (0x2B)
#define XPOWERS_AXP2101_ADC_CHANNEL_CTRL (0x30)
#define XPOWERS_AXP2101_ADC_DATA_RELUST0 (0x34)
#define XPOWERS_AXP2101_ADC_DATA_RELUST1 (0x35)
#define XPOWERS_AXP2101_ADC_DATA_RELUST2 (0x36)
#define XPOWERS_AXP2101_ADC_DATA_RELUST3 (0x37)
#define XPOWERS_AXP2101_ADC_DATA_RELUST4 (0x38)
#define XPOWERS_AXP2101_ADC_DATA_RELUST5 (0x39)
#define XPOWERS_AXP2101_ADC_DATA_RELUST6 (0x3A)
#define XPOWERS_AXP2101_ADC_DATA_RELUST7 (0x3B)
#define XPOWERS_AXP2101_ADC_DATA_RELUST8 (0x3C)
#define XPOWERS_AXP2101_ADC_DATA_RELUST9 (0x3D)
//XPOWERS INTERRUPT REGISTER
#define XPOWERS_AXP2101_INTEN1 (0x40)
#define XPOWERS_AXP2101_INTEN2 (0x41)
#define XPOWERS_AXP2101_INTEN3 (0x42)
//XPOWERS INTERRUPT STATUS REGISTER
#define XPOWERS_AXP2101_INTSTS1 (0x48)
#define XPOWERS_AXP2101_INTSTS2 (0x49)
#define XPOWERS_AXP2101_INTSTS3 (0x4A)
#define XPOWERS_AXP2101_INTSTS_CNT (3)
#define XPOWERS_AXP2101_TS_PIN_CTRL (0x50)
#define XPOWERS_AXP2101_TS_HYSL2H_SET (0x52)
#define XPOWERS_AXP2101_TS_LYSL2H_SET (0x53)
#define XPOWERS_AXP2101_VLTF_CHG_SET (0x54)
#define XPOWERS_AXP2101_VHLTF_CHG_SET (0x55)
#define XPOWERS_AXP2101_VLTF_WORK_SET (0x56)
#define XPOWERS_AXP2101_VHLTF_WORK_SET (0x57)
#define XPOWERS_AXP2101_JIETA_EN_CTRL (0x58)
#define XPOWERS_AXP2101_JIETA_SET0 (0x59)
#define XPOWERS_AXP2101_JIETA_SET1 (0x5A)
#define XPOWERS_AXP2101_JIETA_SET2 (0x5B)
#define XPOWERS_AXP2101_IPRECHG_SET (0x61)
#define XPOWERS_AXP2101_ICC_CHG_SET (0x62)
#define XPOWERS_AXP2101_ITERM_CHG_SET_CTRL (0x63)
#define XPOWERS_AXP2101_CV_CHG_VOL_SET (0x64)
#define XPOWERS_AXP2101_THE_REGU_THRES_SET (0x65)
#define XPOWERS_AXP2101_CHG_TIMEOUT_SET_CTRL (0x67)
#define XPOWERS_AXP2101_BAT_DET_CTRL (0x68)
#define XPOWERS_AXP2101_CHGLED_SET_CTRL (0x69)
#define XPOWERS_AXP2101_BTN_VOL_MIN (2600)
#define XPOWERS_AXP2101_BTN_VOL_MAX (3300)
#define XPOWERS_AXP2101_BTN_VOL_STEPS (100)
#define XPOWERS_AXP2101_BTN_BAT_CHG_VOL_SET (0x6A)
#define XPOWERS_AXP2101_DC_ONOFF_DVM_CTRL (0x80)
#define XPOWERS_AXP2101_DC_FORCE_PWM_CTRL (0x81)
#define XPOWERS_AXP2101_DC_VOL0_CTRL (0x82)
#define XPOWERS_AXP2101_DC_VOL1_CTRL (0x83)
#define XPOWERS_AXP2101_DC_VOL2_CTRL (0x84)
#define XPOWERS_AXP2101_DC_VOL3_CTRL (0x85)
#define XPOWERS_AXP2101_DC_VOL4_CTRL (0x86)
#define XPOWERS_AXP2101_LDO_ONOFF_CTRL0 (0x90)
#define XPOWERS_AXP2101_LDO_ONOFF_CTRL1 (0x91)
#define XPOWERS_AXP2101_LDO_VOL0_CTRL (0x92)
#define XPOWERS_AXP2101_LDO_VOL1_CTRL (0x93)
#define XPOWERS_AXP2101_LDO_VOL2_CTRL (0x94)
#define XPOWERS_AXP2101_LDO_VOL3_CTRL (0x95)
#define XPOWERS_AXP2101_LDO_VOL4_CTRL (0x96)
#define XPOWERS_AXP2101_LDO_VOL5_CTRL (0x97)
#define XPOWERS_AXP2101_LDO_VOL6_CTRL (0x98)
#define XPOWERS_AXP2101_LDO_VOL7_CTRL (0x99)
#define XPOWERS_AXP2101_LDO_VOL8_CTRL (0x9A)
#define XPOWERS_AXP2101_BAT_PARAMS (0xA1)
#define XPOWERS_AXP2101_FUEL_GAUGE_CTRL (0xA2)
#define XPOWERS_AXP2101_BAT_PERCENT_DATA (0xA4)
// DCDC 1~5
#define XPOWERS_AXP2101_DCDC1_VOL_MIN (1500)
#define XPOWERS_AXP2101_DCDC1_VOL_MAX (3400)
#define XPOWERS_AXP2101_DCDC1_VOL_STEPS (100u)
#define XPOWERS_AXP2101_DCDC2_VOL1_MIN (500u)
#define XPOWERS_AXP2101_DCDC2_VOL1_MAX (1200u)
#define XPOWERS_AXP2101_DCDC2_VOL2_MIN (1220u)
#define XPOWERS_AXP2101_DCDC2_VOL2_MAX (1540u)
#define XPOWERS_AXP2101_DCDC2_VOL_STEPS1 (10u)
#define XPOWERS_AXP2101_DCDC2_VOL_STEPS2 (20u)
#define XPOWERS_AXP2101_DCDC2_VOL_STEPS1_BASE (0u)
#define XPOWERS_AXP2101_DCDC2_VOL_STEPS2_BASE (71)
#define XPOWERS_AXP2101_DCDC3_VOL1_MIN (500u)
#define XPOWERS_AXP2101_DCDC3_VOL1_MAX (1200u)
#define XPOWERS_AXP2101_DCDC3_VOL2_MIN (1220u)
#define XPOWERS_AXP2101_DCDC3_VOL2_MAX (1540u)
#define XPOWERS_AXP2101_DCDC3_VOL3_MIN (1600u)
#define XPOWERS_AXP2101_DCDC3_VOL3_MAX (3400u)
#define XPOWERS_AXP2101_DCDC3_VOL_MIN (500)
#define XPOWERS_AXP2101_DCDC3_VOL_MAX (3400)
#define XPOWERS_AXP2101_DCDC3_VOL_STEPS1 (10u)
#define XPOWERS_AXP2101_DCDC3_VOL_STEPS2 (20u)
#define XPOWERS_AXP2101_DCDC3_VOL_STEPS3 (100u)
#define XPOWERS_AXP2101_DCDC3_VOL_STEPS1_BASE (0u)
#define XPOWERS_AXP2101_DCDC3_VOL_STEPS2_BASE (71)
#define XPOWERS_AXP2101_DCDC3_VOL_STEPS3_BASE (88)
#define XPOWERS_AXP2101_DCDC4_VOL1_MIN (500u)
#define XPOWERS_AXP2101_DCDC4_VOL1_MAX (1200u)
#define XPOWERS_AXP2101_DCDC4_VOL2_MIN (1220u)
#define XPOWERS_AXP2101_DCDC4_VOL2_MAX (1840u)
#define XPOWERS_AXP2101_DCDC4_VOL_STEPS1 (10u)
#define XPOWERS_AXP2101_DCDC4_VOL_STEPS2 (20u)
#define XPOWERS_AXP2101_DCDC4_VOL_STEPS1_BASE (0u)
#define XPOWERS_AXP2101_DCDC4_VOL_STEPS2_BASE (71)
#define XPOWERS_AXP2101_DCDC5_VOL_1200MV (1200)
#define XPOWERS_AXP2101_DCDC5_VOL_VAL (0x19)
#define XPOWERS_AXP2101_DCDC5_VOL_MIN (1400)
#define XPOWERS_AXP2101_DCDC5_VOL_MAX (3700)
#define XPOWERS_AXP2101_DCDC5_VOL_STEPS (100u)
#define XPOWERS_AXP2101_VSYS_VOL_THRESHOLD_MIN (2600)
#define XPOWERS_AXP2101_VSYS_VOL_THRESHOLD_MAX (3300)
#define XPOWERS_AXP2101_VSYS_VOL_THRESHOLD_STEPS (100)
// ALDO 1~4
#define XPOWERS_AXP2101_ALDO1_VOL_MIN (500)
#define XPOWERS_AXP2101_ALDO1_VOL_MAX (3500)
#define XPOWERS_AXP2101_ALDO1_VOL_STEPS (100u)
#define XPOWERS_AXP2101_ALDO2_VOL_MIN (500)
#define XPOWERS_AXP2101_ALDO2_VOL_MAX (3500)
#define XPOWERS_AXP2101_ALDO2_VOL_STEPS (100u)
#define XPOWERS_AXP2101_ALDO3_VOL_MIN (500)
#define XPOWERS_AXP2101_ALDO3_VOL_MAX (3500)
#define XPOWERS_AXP2101_ALDO3_VOL_STEPS (100u)
#define XPOWERS_AXP2101_ALDO4_VOL_MIN (500)
#define XPOWERS_AXP2101_ALDO4_VOL_MAX (3500)
#define XPOWERS_AXP2101_ALDO4_VOL_STEPS (100u)
// BLDO 1~2
#define XPOWERS_AXP2101_BLDO1_VOL_MIN (500)
#define XPOWERS_AXP2101_BLDO1_VOL_MAX (3500)
#define XPOWERS_AXP2101_BLDO1_VOL_STEPS (100u)
#define XPOWERS_AXP2101_BLDO2_VOL_MIN (500)
#define XPOWERS_AXP2101_BLDO2_VOL_MAX (3500)
#define XPOWERS_AXP2101_BLDO2_VOL_STEPS (100u)
// CPUSLDO
#define XPOWERS_AXP2101_CPUSLDO_VOL_MIN (500)
#define XPOWERS_AXP2101_CPUSLDO_VOL_MAX (1400)
#define XPOWERS_AXP2101_CPUSLDO_VOL_STEPS (50)
// DLDO 1~2
#define XPOWERS_AXP2101_DLDO1_VOL_MIN (500)
#define XPOWERS_AXP2101_DLDO1_VOL_MAX (3400)
#define XPOWERS_AXP2101_DLDO1_VOL_STEPS (100u)
#define XPOWERS_AXP2101_DLDO2_VOL_MIN (500)
#define XPOWERS_AXP2101_DLDO2_VOL_MAX (3400)
#define XPOWERS_AXP2101_DLDO2_VOL_STEPS (100u)
#define XPOWERS_AXP2101_CONVERSION(raw) (22.0 + (7274 - raw) / 20.0)

View File

@@ -0,0 +1,95 @@
#pragma once
#define AXP216_SLAVE_ADDRESS (0x34)
#define XPOWERS_AXP216_CHIP_ID (0x41)
//CONTROL REGISTER
#define XPOWERS_AXP216_STATUS (0x00)
#define XPOWERS_AXP216_MODE_CHGSTATUS (0x01)
#define XPOWERS_AXP216_DATA_BUFFER1 (0x04)
#define XPOWERS_AXP216_DATA_BUFFER2 (0x05)
#define XPOWERS_AXP216_DATA_BUFFER3 (0x06)
#define XPOWERS_AXP216_DATA_BUFFER4 (0x07)
#define XPOWERS_AXP216_DATA_BUFFER5 (0x08)
#define XPOWERS_AXP216_DATA_BUFFER6 (0x09)
#define XPOWERS_AXP216_DATA_BUFFER7 (0x0A)
#define XPOWERS_AXP216_DATA_BUFFER8 (0x0B)
#define XPOWERS_AXP216_DATA_BUFFER9 (0x0C)
#define XPOWERS_AXP216_DATA_BUFFERA (0x0D)
#define XPOWERS_AXP216_DATA_BUFFERB (0x0E)
#define XPOWERS_AXP216_DATA_BUFFERC (0x0F)
#define XPOWERS_AXP216_IC_TYPE (0x03)
#define XPOWERS_AXP216_DC12345_ALDO12_CTL (0x10)
#define XPOWERS_AXP216_LDO123_CTL (0x12)
#define XPOWERS_AXP216_OUTPUT_CTL (0x13)
#define XPOWERS_AXP216_ELDO1_VCTL (0x19)
#define XPOWERS_AXP216_ELDO2_VCTL (0x1A)
#define XPOWERS_AXP216_DCDC1_VCTL (0x21)
#define XPOWERS_AXP216_DCDC2_VCTL (0x22)
#define XPOWERS_AXP216_DCDC3_VCTL (0x23)
#define XPOWERS_AXP216_DCDC4_VCTL (0x24)
#define XPOWERS_AXP216_DCDC5_VCTL (0x25)
#define XPOWERS_AXP216_DCDC23_VOLX (0x27)
#define XPOWERS_AXP216_ALDO1_VCTL (0x28)
#define XPOWERS_AXP216_ALDO2_VCTL (0x29)
#define XPOWERS_AXP216_ALDO3_VCTL (0x2A)
#define XPOWERS_AXP216_VBUS_IPSOUT (0x30)
#define XPOWERS_AXP216_VOFF_SET (0x31)
#define XPOWERS_AXP216_OFF_CTL (0x32)
#define XPOWERS_AXP216_CHARGE1 (0x33)
#define XPOWERS_AXP216_CHARGE2 (0x34)
#define XPOWERS_AXP216_CHARGE3 (0x35)
#define XPOWERS_AXP216_PEK_SET (0x36)
#define XPOWERS_AXP216_OFFLEVEL (0x37)
#define XPOWERS_AXP216_VLTF_CHGSET (0x38)
#define XPOWERS_AXP216_VHTF_CHGSET (0x39)
#define XPOWERS_AXP216_DCDC_FREQ (0x3B)
#define XPOWERS_AXP216_TLTF_DISCHGSET (0x3C)
#define XPOWERS_AXP216_THTF_DISCHGSET (0x3D)
#define XPOWERS_AXP216_DCDC_MODESET (0x80)
#define XPOWERS_AXP216_ADC_CTL (0x82)
#define XPOWERS_AXP216_ADC_SPEED (0x84)
#define XPOWERS_AXP216_TS_ADC (0x85)
#define XPOWERS_AXP216_TIMER_CTL (0x8A)
#define XPOWERS_AXP216_HOTOVER_CTL (0x8F)
//GPIO REGISTER
#define XPOWERS_AXP216_GPIO1_CTL (0x92)
#define XPOWERS_AXP216_GPIO1_LDO_CTL (0x93)
#define XPOWERS_AXP216_GPIO01_STATUS (0x94)
#define XPOWERS_AXP216_GPIO1_PULLDOWN_CTL (0x97)
//XPOWERS INTERRUPT REGISTER
#define XPOWERS_AXP216_INTEN1 (0x40)
#define XPOWERS_AXP216_INTEN2 (0x41)
#define XPOWERS_AXP216_INTEN3 (0x42)
#define XPOWERS_AXP216_INTEN4 (0x43)
#define XPOWERS_AXP216_INTEN5 (0x44)
//XPOWERS INTERRUPT STATUS REGISTER
#define XPOWERS_AXP216_INTSTS1 (0x48)
#define XPOWERS_AXP216_INTSTS2 (0x49)
#define XPOWERS_AXP216_INTSTS3 (0x4A)
#define XPOWERS_AXP216_INTSTS4 (0x4B)
#define XPOWERS_AXP216_INTSTS5 (0x4C)
//XPOWERS ADC DATA REGISTER
#define XPOWERS_AXP216_INTERNAL_TEMP_H8 (0x56)
#define XPOWERS_AXP216_INTERNAL_TEMP_L4 (0x57)
#define XPOWERS_AXP216_TS_IN_H8 (0x58)
#define XPOWERS_AXP216_TS_IN_L4 (0x59)
#define XPOWERS_AXP216_BAT_VOLTAGE_H8 (0x78)
#define XPOWERS_AXP216_BAT_VOLTAGE_L4 (0x79)
#define XPOWERS_AXP216_BAT_CHGCURCUR_H8 (0x7A)
#define XPOWERS_AXP216_BAT_CHGCURCUR_L4 (0x7B)
#define XPOWERS_AXP216_BAT_DISCHGCUR_H8 (0x7C)
#define XPOWERS_AXP216_BAT_DISCHGCUR_L4 (0x7D)
#define XPOWERS_AXP216_FUEL_GAUGE_CTRL (0xB8)
#define XPOWERS_AXP216_FUEL_GAUGE_REULST (0xB9)
#define XPOWERS_AXP216_BAT_CAPACITY_0 (0xE0)
#define XPOWERS_AXP216_BAT_CAPACITY_1 (0xE1)
#define XPOWERS_AXP216_BAT_LOW_WARNING_CTRL (0xE6)

View File

@@ -0,0 +1,111 @@
/**
*
* @license 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.
*
* @file BQ25896Constants.h
* @author Lewis He (lewishe@outlook.com)
* @date 2023-07-20
*
*/
#pragma once
// https://www.ti.com/product/BQ25896
#define BQ25896_SLAVE_ADDRESS (0x6B)
#define BQ25896_DEV_REV (0x02)
#define POWERS_BQ25896_VBUS_MASK_VAL(val) (val & 0x7F)
#define POWERS_BQ25896_VBAT_MASK_VAL(val) (val & 0x7F)
#define POWERS_BQ25896_VSYS_MASK_VAL(val) (val & 0x7F)
#define POWERS_BQ25896_NTC_MASK_VAL(val) (val & 0x7F)
#define POWERS_BQ25896_VBUS_BASE_VAL (2600)
#define POWERS_BQ25896_VBAT_BASE_VAL (2304)
#define POWERS_BQ25896_VSYS_BASE_VAL (2304)
#define POWERS_BQ25896_NTC_BASE_VAL (21)
#define POWERS_BQ25896_VBUS_VOL_STEP (100)
#define POWERS_BQ25896_VBAT_VOL_STEP (20)
#define POWERS_BQ25896_VSYS_VOL_STEP (20)
#define POWERS_BQ25896_NTC_VOL_STEP (0.465)
#define POWERS_BQ25896_CHG_STEP_VAL (50)
#define POWERS_BQ25896_FAST_CHG_CUR_STEP (64)
#define POWERS_BQ25896_FAST_CHG_CURRENT_MIN (0)
#define POWERS_BQ25896_FAST_CHG_CURRENT_MAX (3008)
#define POWERS_BQ25896_PRE_CHG_CUR_BASE (64)
#define POWERS_BQ25896_PRE_CHG_CUR_STEP (64)
#define POWERS_BQ25896_PRE_CHG_CURRENT_MIN (64)
#define POWERS_BQ25896_PRE_CHG_CURRENT_MAX (1024)
#define POWERS_BQ25896_TERM_CHG_CUR_BASE (64)
#define POWERS_BQ25896_TERM_CHG_CUR_STEP (64)
#define POWERS_BQ25896_TERM_CHG_CURRENT_MIN (64)
#define POWERS_BQ25896_TERM_CHG_CURRENT_MAX (1024)
#define POWERS_BQ25896_CHG_VOL_BASE (3840)
#define POWERS_BQ25896_CHG_VOL_STEP (16)
#define POWERS_BQ25896_FAST_CHG_VOL_MIN (3840)
#define POWERS_BQ25896_FAST_CHG_VOL_MAX (4608)
#define POWERS_BQ25896_SYS_VOL_STEPS (100)
#define POWERS_BQ25896_SYS_VOFF_VOL_MIN (3000)
#define POWERS_BQ25896_SYS_VOFF_VOL_MAX (3700)
#define POWERS_BQ25896_IN_CURRENT_STEP (50)
#define POWERS_BQ25896_IN_CURRENT_MIN (100)
#define POWERS_BQ25896_IN_CURRENT_MAX (3250)
#define POWERS_BQ25896_IN_CURRENT_OPT_STEP (50)
#define POWERS_BQ25896_IN_CURRENT_OPT_MIN (100)
#define POWERS_BQ25896_IN_CURRENT_OPT_MAX (3250)
#define POWERS_BQ25896_IN_CURRENT_OFFSET_STEP (100)
#define POWERS_BQ25896_IN_CURRENT_OFFSET_MAX (3100)
#define POWERS_BQ25896_BOOTS_VOL_BASE (4550)
#define POWERS_BQ25896_BOOTS_VOL_STEP (64)
#define POWERS_BQ25896_BOOST_VOL_MIN (4550)
#define POWERS_BQ25896_BOOST_VOL_MAX (5510)
#define POWERS_BQ25896_IRQ_WTD_FAULT(x) (bool)(( x & 0xFF ) >> 7)
#define POWERS_BQ25896_IRQ_BOOST_FAULT(x) (bool)(( x & 0xFF ) >> 6)
#define POWERS_BQ25896_IRQ_CHG_FAULT(x) (( x >> 4 ) & 0x03)
#define POWERS_BQ25896_IRQ_BAT_FAULT(x) (bool)(( x & 0xFF ) >> 3)
#define POWERS_BQ25896_IRQ_NTC_FAULT(x) (bool)(( x & 0xFF ) & 0x03)
#define POWERS_BQ25896_VINDPM_VOL_BASE (4550)
#define POWERS_BQ25896_VINDPM_VOL_STEPS (100)
#define POWERS_BQ25896_VINDPM_VOL_MIN (3900)
#define POWERS_BQ25896_VINDPM_VOL_MAX (15300)
#define POWERS_BQ25896_BAT_COMP_STEPS (20)
#define POWERS_BQ25896_BAT_COMP_MAX (140)
#define POWERS_BQ25896_VCLAMP_STEPS (32)
#define POWERS_BQ25896_VCLAMP_MAX (224)

View File

@@ -0,0 +1,78 @@
/**
*
* @license MIT License
*
* Copyright (c) 2024 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.
*
* @file GeneralPPMConstants.h
* @author Lewis He (lewishe@outlook.com)
* @date 2024-10-29
*
*/
#pragma once
#define POWERS_PPM_REG_00H (0x00)
#define POWERS_PPM_REG_01H (0x01)
#define POWERS_PPM_REG_02H (0x02)
#define POWERS_PPM_REG_03H (0x03)
#define POWERS_PPM_REG_04H (0x04)
#define POWERS_PPM_REG_05H (0x05)
#define POWERS_PPM_REG_06H (0x06)
#define POWERS_PPM_REG_07H (0x07)
#define POWERS_PPM_REG_08H (0x08)
#define POWERS_PPM_REG_09H (0x09)
#define POWERS_PPM_REG_0AH (0x0A)
// Read only STATUS REG
#define POWERS_PPM_REG_0BH (0x0B)
// Read only CHARGE IRQ REG
#define POWERS_PPM_REG_0CH (0x0C)
// Absolute VINDPM Threshold
#define POWERS_PPM_REG_0DH (0x0D)
// Read only BATTERY VOLTAGE
#define POWERS_PPM_REG_0EH (0x0E)
// Read only SYSTEM VOLTAGE
#define POWERS_PPM_REG_0FH (0x0F)
// Read only NTC PERCENTAGE
#define POWERS_PPM_REG_10H (0x10)
// Read only VBUS VOLTAGE
#define POWERS_PPM_REG_11H (0x11)
// Read only CHARGE CURRENT
#define POWERS_PPM_REG_12H (0x12)
// Read only VINDPM/IINDPM STATUS/CURR LIMIT SETTING
#define POWERS_PPM_REG_13H (0x13)
// RESET REG
#define POWERS_PPM_REG_14H (0x14)

View File

@@ -0,0 +1,45 @@
/**
*
* @license 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.
*
* @file HUSB238Constants.h
* @author Lewis He (lewishe@outlook.com)
* @date 2024-07-24
*
*/
#pragma once
#define HUSB238_SLAVE_ADDRESS (0x8)
#define HUSB238_PD_STATUS0 (0x0)
#define HUSB238_PD_STATUS1 (0x1)
#define HUSB238_SRC_PDO_5V (0x2)
#define HUSB238_SRC_PDO_9V (0x3)
#define HUSB238_SRC_PDO_12V (0x4)
#define HUSB238_SRC_PDO_15V (0x5)
#define HUSB238_SRC_PDO_18V (0x6)
#define HUSB238_SRC_PDO_20V (0x7)
#define HUSB238_SRC_PDO (0x8)
#define HUSB238_GO_COMMAND (0x9)

View File

@@ -0,0 +1,88 @@
/**
*
* @license 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.
*
* @file SY6970Constants.h
* @author Lewis He (lewishe@outlook.com)
* @date 2023-07-20
*
*/
#pragma once
#define SY6970_SLAVE_ADDRESS (0x6A)
#define SY6970_DEV_REV (0x00)
#define POWERS_SY6970_VBUS_MASK_VAL(val) (val & 0x7F)
#define POWERS_SY6970_VBAT_MASK_VAL(val) (val & 0x7F)
#define POWERS_SY6970_VSYS_MASK_VAL(val) (val & 0x7F)
#define POWERS_SY6970_NTC_MASK_VAL(val) (val & 0x7F)
#define POWERS_SY6970_VBUS_BASE_VAL (2600)
#define POWERS_SY6970_VBAT_BASE_VAL (2304)
#define POWERS_SY6970_VSYS_BASE_VAL (2304)
#define POWERS_SY6970_NTC_BASE_VAL (21)
#define POWERS_SY6970_VBUS_VOL_STEP (100)
#define POWERS_SY6970_VBAT_VOL_STEP (20)
#define POWERS_SY6970_VSYS_VOL_STEP (20)
#define POWERS_SY6970_NTC_VOL_STEP (0.465)
#define POWERS_SY6970_CHG_STEP_VAL (50)
#define POWERS_SY6970_PRE_CHG_CUR_BASE (64)
#define POWERS_SY6970_FAST_CHG_CUR_STEP (64)
#define POWERS_SY6970_PRE_CHG_CUR_STEP (64)
#define POWERS_SY6970_FAST_CHG_CURRENT_MAX (5056)
#define POWERS_SY6970_PRE_CHG_CURRENT_MIN (64)
#define POWERS_SY6970_PRE_CHG_CURRENT_MAX (1024)
#define POWERS_SY6970_CHG_VOL_BASE (3840)
#define POWERS_SY6970_CHG_VOL_STEP (16)
#define POWERS_SY6970_FAST_CHG_VOL_MIN (3840)
#define POWERS_SY6970_FAST_CHG_VOL_MAX (4608)
#define POWERS_SY6970_SYS_VOL_STEPS (100)
#define POWERS_SY6970_SYS_VOFF_VOL_MIN (3000)
#define POWERS_SY6970_SYS_VOFF_VOL_MAX (3700)
#define POWERS_SY6970_IN_CURRENT_STEP (50)
#define POWERS_SY6970_IN_CURRENT_MIN (100)
#define POWERS_SY6970_IN_CURRENT_MAX (3250)
#define POWERS_SY6970_BOOTS_VOL_BASE (4550)
#define POWERS_SY6970_BOOTS_VOL_STEP (64)
#define POWERS_SY6970_BOOST_VOL_MIN (4550)
#define POWERS_SY6970_BOOST_VOL_MAX (5510)
#define POWERS_SY6970_IRQ_WTD_FAULT(x) (bool)(( x & 0xFF ) >> 7)
#define POWERS_SY6970_IRQ_BOOST_FAULT(x) (bool)(( x & 0xFF ) >> 6)
#define POWERS_SY6970_IRQ_CHG_FAULT(x) (bool)(( x & 0xFF ) >> 5)
#define POWERS_SY6970_IRQ_BAT_FAULT(x) (bool)(( x & 0xFF ) >> 4)
#define POWERS_SY6970_IRQ_NTC_FAULT(x) (bool)(( x & 0xFF ) & 0x03)
#define POWERS_SY6970_VINDPM_VOL_BASE (4550)
#define POWERS_SY6970_VINDPM_VOL_STEPS (100)
#define POWERS_SY6970_VINDPM_VOL_MIN (3900)
#define POWERS_SY6970_VINDPM_VOL_MAX (15300)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,520 @@
/**
*
* @license 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.
*
* @file XPowersCommon.h
* @author Lewis He (lewishe@outlook.com)
* @date 2022-05-07
*
*/
#pragma once
#include <stdint.h>
#if defined(ARDUINO)
#include <Wire.h>
#elif defined(ESP_PLATFORM)
#include <cstring>
#include "esp_log.h"
#include "esp_err.h"
#include "esp_idf_version.h"
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_XPOWERS_ESP_IDF_NEW_API)
#include "driver/i2c_master.h"
#else
#include "driver/i2c.h"
#define XPOWERSLIB_I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define XPOWERSLIB_I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define XPOWERSLIB_I2C_MASTER_TIMEOUT_MS 1000
#endif //ESP_IDF_VERSION
#endif //defined(ARDUINO)
#define XPOWERSLIB_I2C_MASTER_SPEED 400000
#ifdef _BV
#undef _BV
#endif
#define _BV(b) (1ULL << (uint64_t)(b))
#ifndef constrain
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
#endif
#define XPOWERS_ATTR_NOT_IMPLEMENTED __attribute__((error("Not implemented")))
#define IS_BIT_SET(val,mask) (((val)&(mask)) == (mask))
#if !defined(ARDUINO)
#ifdef linux
#include <stdio.h>
#include <string.h>
#include <errno.h>
#define log_e(__info, ...) printf("error :" __info,##__VA_ARGS__)
#define log_i(__info, ...) printf("info :" __info,##__VA_ARGS__)
#define log_d(__info, ...) printf("debug :" __info,##__VA_ARGS__)
#elif defined(ESP_PLATFORM)
#define log_e(__fmt, ...) ESP_LOGE("XPowers", __fmt, ##__VA_ARGS__);
#define log_i(__fmt, ...) ESP_LOGI("XPowers", __fmt, ##__VA_ARGS__);
#define log_d(__fmt, ...) ESP_LOGD("XPowers", __fmt, ##__VA_ARGS__);
#else
#define log_e(...)
#define log_i(...)
#define log_d(...)
#endif //linux
#define LOW 0x0
#define HIGH 0x1
//GPIO FUNCTIONS
#define INPUT 0x01
#define OUTPUT 0x03
#define PULLUP 0x04
#define INPUT_PULLUP 0x05
#define PULLDOWN 0x08
#define INPUT_PULLDOWN 0x09
#define RISING 0x01
#define FALLING 0x02
#endif //!defined(ARDUINO)
#if defined(ARDUINO_ARCH_MBED) || defined(ARDUINO_ARCH_ZEPHYR)
#define log_e(...)
#define log_i(...)
#define log_d(...)
#endif
#ifndef ESP32
#ifdef LOG_FILE_LINE_INFO
#undef LOG_FILE_LINE_INFO
#endif
#define LOG_FILE_LINE_INFO __FILE__, __LINE__
#ifndef log_e
#define log_e(fmt, ...) Serial.printf("[E][%s:%d] " fmt "\n", LOG_FILE_LINE_INFO, ##__VA_ARGS__)
#endif
#ifndef log_i
#define log_i(fmt, ...) Serial.printf("[I][%s:%d] " fmt "\n", LOG_FILE_LINE_INFO, ##__VA_ARGS__)
#endif
#ifndef log_d
#define log_d(fmt, ...) Serial.printf("[D][%s:%d] " fmt "\n", LOG_FILE_LINE_INFO, ##__VA_ARGS__)
#endif
#endif //ESP32
#if defined(NRF52840_XXAA) || defined(NRF52832_XXAA)
#ifndef SDA
#define SDA (0xFF)
#endif
#ifndef SCL
#define SCL (0xFF)
#endif
#endif
typedef int (*iic_fptr_t)(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint8_t len);
template <class chipType>
class XPowersCommon
{
public:
#if defined(ARDUINO)
bool begin(TwoWire &w, uint8_t addr, int sda, int scl)
{
if (__has_init)return thisChip().initImpl();
__has_init = true;
__sda = sda;
__scl = scl;
__wire = &w;
#if defined(NRF52840_XXAA) || defined(NRF52832_XXAA)
if (__sda != 0xFF && __scl != 0xFF) {
#if !defined(ARDUINO_ARCH_MBED) && !defined(ARDUINO_ARCH_ZEPHYR)
__wire->setPins(__sda, __scl);
#endif /* ARDUINO_ARCH_MBED || ZEPHYR */
}
__wire->begin();
#elif defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_STM32)
if (__sda != 0xFF && __scl != 0xFF) {
__wire->end();
__wire->setSDA(__sda);
__wire->setSCL(__scl);
}
__wire->begin();
#elif defined(ARDUINO_ARCH_ESP32)
__wire->begin(__sda, __scl);
#else
__wire->begin();
#endif
__addr = addr;
return thisChip().initImpl();
}
#elif defined(ESP_PLATFORM)
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_XPOWERS_ESP_IDF_NEW_API)
// * Using the new API of esp-idf 5.x, you need to pass the I2C BUS handle,
// * which is useful when the bus shares multiple devices.
bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr)
{
log_i("Using ESP-IDF Driver interface.");
if (i2c_dev_bus_handle == NULL) return false;
if (__has_init)return thisChip().initImpl();
thisReadRegCallback = NULL;
thisWriteRegCallback = NULL;
/*
i2c_master_bus_config_t i2c_bus_config;
memset(&i2c_bus_config, 0, sizeof(i2c_bus_config));
i2c_bus_config.clk_source = I2C_CLK_SRC_DEFAULT;
i2c_bus_config.i2c_port = port_num;
i2c_bus_config.scl_io_num = (gpio_num_t)__scl;
i2c_bus_config.sda_io_num = (gpio_num_t)__sda;
i2c_bus_config.glitch_ignore_cnt = 7;
i2c_new_master_bus(&i2c_bus_config, &bus_handle);
*/
bus_handle = i2c_dev_bus_handle;
i2c_device_config_t i2c_dev_conf = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = addr,
.scl_speed_hz = XPOWERSLIB_I2C_MASTER_SPEED,
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,3,0))
// New fields since esp-idf-v5.3-beta1
.scl_wait_us = 0,
.flags = {
. disable_ack_check = 0
}
#endif
};
if (ESP_OK != i2c_master_bus_add_device(bus_handle,
&i2c_dev_conf,
&__i2c_device)) {
return false;
}
__has_init = thisChip().initImpl();
if (!__has_init) {
// Initialization failed, delete device
i2c_master_bus_rm_device(__i2c_device);
}
return __has_init;
}
#else //ESP 4.X
bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl)
{
__i2c_num = port_num;
log_i("Using ESP-IDF Driver interface.");
if (__has_init)return thisChip().initImpl();
__sda = sda;
__scl = scl;
__addr = addr;
thisReadRegCallback = NULL;
thisWriteRegCallback = NULL;
i2c_config_t i2c_conf;
memset(&i2c_conf, 0, sizeof(i2c_conf));
i2c_conf.mode = I2C_MODE_MASTER;
i2c_conf.sda_io_num = sda;
i2c_conf.scl_io_num = scl;
i2c_conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
i2c_conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
i2c_conf.master.clk_speed = XPOWERSLIB_I2C_MASTER_SPEED;
/**
* @brief Without checking whether the initialization is successful,
* I2C may be initialized externally,
* so just make sure there is an initialization here.
*/
i2c_param_config(__i2c_num, &i2c_conf);
i2c_driver_install(__i2c_num,
i2c_conf.mode,
XPOWERSLIB_I2C_MASTER_RX_BUF_DISABLE,
XPOWERSLIB_I2C_MASTER_TX_BUF_DISABLE, 0);
__has_init = thisChip().initImpl();
return __has_init;
}
#endif //ESP 5.X
#endif //ESP_PLATFORM
bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback)
{
if (__has_init)return thisChip().initImpl();
__has_init = true;
thisReadRegCallback = readRegCallback;
thisWriteRegCallback = writeRegCallback;
__addr = addr;
return thisChip().initImpl();
}
int readRegister(uint8_t reg)
{
uint8_t val = 0;
return readRegister(reg, &val, 1) == -1 ? -1 : val;
}
int writeRegister(uint8_t reg, uint8_t val)
{
return writeRegister(reg, &val, 1);
}
int readRegister(uint8_t reg, uint8_t *buf, uint8_t length)
{
if (thisReadRegCallback) {
return thisReadRegCallback(__addr, reg, buf, length);
}
#if defined(ARDUINO)
if (__wire) {
__wire->beginTransmission(__addr);
__wire->write(reg);
if (__wire->endTransmission() != 0) {
return -1;
}
__wire->requestFrom(__addr, length);
return __wire->readBytes(buf, length) == length ? 0 : -1;
}
#elif defined(ESP_PLATFORM)
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_XPOWERS_ESP_IDF_NEW_API)
if (ESP_OK == i2c_master_transmit_receive(
__i2c_device,
(const uint8_t *)&reg,
1,
buf,
length,
-1)) {
return 0;
}
#else //ESP_IDF_VERSION
if (ESP_OK == i2c_master_write_read_device(__i2c_num,
__addr,
(uint8_t *)&reg,
1,
buf,
length,
XPOWERSLIB_I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS)) {
return 0;
}
#endif //ESP_IDF_VERSION
#endif //ESP_PLATFORM
return -1;
}
int writeRegister(uint8_t reg, uint8_t *buf, uint8_t length)
{
if (thisWriteRegCallback) {
return thisWriteRegCallback(__addr, reg, buf, length);
}
#if defined(ARDUINO)
if (__wire) {
__wire->beginTransmission(__addr);
__wire->write(reg);
__wire->write(buf, length);
return (__wire->endTransmission() == 0) ? 0 : -1;
}
return -1;
#elif defined(ESP_PLATFORM)
uint8_t *write_buffer = (uint8_t *)malloc(sizeof(uint8_t) * (length + 1));
if (!write_buffer) {
return -1;
}
write_buffer[0] = reg;
memcpy(write_buffer + 1, buf, length);
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_XPOWERS_ESP_IDF_NEW_API)
if (ESP_OK != i2c_master_transmit(
__i2c_device,
write_buffer,
length + 1,
-1)) {
free(write_buffer);
return -1;
}
#else //ESP_IDF_VERSION
if (ESP_OK != i2c_master_write_to_device(__i2c_num,
__addr,
write_buffer,
length + 1,
XPOWERSLIB_I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS)) {
free(write_buffer);
return -1;
}
#endif //ESP_IDF_VERSION
free(write_buffer);
return 0;
#endif //ESP_PLATFORM
}
bool inline clrRegisterBit(uint8_t registers, uint8_t bit)
{
int val = readRegister(registers);
if (val == -1) {
return false;
}
return writeRegister(registers, (val & (~_BV(bit)))) == 0;
}
bool inline setRegisterBit(uint8_t registers, uint8_t bit)
{
int val = readRegister(registers);
if (val == -1) {
return false;
}
return writeRegister(registers, (val | (_BV(bit)))) == 0;
}
bool inline getRegisterBit(uint8_t registers, uint8_t bit)
{
int val = readRegister(registers);
if (val == -1) {
return false;
}
return val & _BV(bit);
}
uint16_t inline readRegisterH8L4(uint8_t highReg, uint8_t lowReg)
{
int h8 = readRegister(highReg);
int l4 = readRegister(lowReg);
if (h8 == -1 || l4 == -1)return UINT16_MAX;
return (h8 << 4) | (l4 & 0x0F);
}
uint16_t inline readRegisterH8L5(uint8_t highReg, uint8_t lowReg)
{
int h8 = readRegister(highReg);
int l5 = readRegister(lowReg);
if (h8 == -1 || l5 == -1)return UINT16_MAX;
return (h8 << 5) | (l5 & 0x1F);
}
uint16_t inline readRegisterH6L8(uint8_t highReg, uint8_t lowReg)
{
int h6 = readRegister(highReg);
int l8 = readRegister(lowReg);
if (h6 == -1 || l8 == -1)return UINT16_MAX;
return ((h6 & 0x3F) << 8) | l8;
}
uint16_t inline readRegisterH5L8(uint8_t highReg, uint8_t lowReg)
{
int h5 = readRegister(highReg);
int l8 = readRegister(lowReg);
if (h5 == -1 || l8 == -1)return 0;
return ((h5 & 0x1F) << 8) | l8;
}
/*
* CRTP Helper
*/
protected:
bool begin()
{
#if defined(ARDUINO)
if (__has_init) return thisChip().initImpl();
__has_init = true;
if (__wire) {
log_i("SDA:%d SCL:%d", __sda, __scl);
#if defined(NRF52840_XXAA) || defined(NRF52832_XXAA)
if (__sda != 0xFF && __scl != 0xFF) {
#if !defined(ARDUINO_ARCH_MBED) && !defined(ARDUINO_ARCH_ZEPHYR)
__wire->setPins(__sda, __scl);
#endif /* ARDUINO_ARCH_MBED || ZEPHYR */
}
__wire->begin();
#elif defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_STM32)
if (__sda != 0xFF && __scl != 0xFF) {
__wire->end();
__wire->setSDA(__sda);
__wire->setSCL(__scl);
}
__wire->begin();
#elif defined(ARDUINO_ARCH_ESP32)
__wire->begin(__sda, __scl);
#else
__wire->begin();
#endif
}
#endif /*ARDUINO*/
return thisChip().initImpl();
}
void end()
{
#if defined(ARDUINO)
if (__wire) {
#if defined(ESP_IDF_VERSION)
#if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4,4,0)
__wire->end();
#endif /*ESP_IDF_VERSION*/
#endif /*ESP_IDF_VERSION*/
}
#endif /*ARDUINO*/
}
inline const chipType &thisChip() const
{
return static_cast<const chipType &>(*this);
}
inline chipType &thisChip()
{
return static_cast<chipType &>(*this);
}
protected:
bool __has_init = false;
#if defined(ARDUINO)
TwoWire *__wire = NULL;
#elif defined(ESP_PLATFORM)
i2c_port_t __i2c_num;
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_XPOWERS_ESP_IDF_NEW_API)
i2c_master_bus_handle_t bus_handle;
i2c_master_dev_handle_t __i2c_device;
#endif //ESP_IDF_VERSION
#endif //ESP_PLATFORM
int __sda = -1;
int __scl = -1;
uint8_t __addr = 0xFF;
iic_fptr_t thisReadRegCallback = NULL;
iic_fptr_t thisWriteRegCallback = NULL;
};

View File

@@ -0,0 +1,57 @@
/**
*
* @license MIT License
*
* Copyright (c) 2024 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.
*
* @file XPowersLib.h
* @author Lewis He (lewishe@outlook.com)
* @date 2024-10-30
*
*/
#pragma once
#if defined(XPOWERS_CHIP_AXP192)
#include "XPowersAXP192.tpp"
typedef XPowersAXP192 XPowersPMU;
#elif defined(XPOWERS_CHIP_AXP202)
#include "XPowersAXP202.tpp"
typedef XPowersAXP202 XPowersPMU;
#elif defined(XPOWERS_CHIP_AXP2101)
#include "XPowersAXP2101.tpp"
typedef XPowersAXP2101 XPowersPMU;
#elif defined(XPOWERS_CHIP_SY6970)
#include "PowersSY6970.tpp"
typedef PowersSY6970 XPowersPPM;
#elif defined(XPOWERS_CHIP_BQ25896)
#include "PowersBQ25896.tpp"
typedef PowersBQ25896 XPowersPPM;
#else
#include "XPowersAXP192.tpp"
#include "XPowersAXP202.tpp"
#include "XPowersAXP2101.tpp"
#include "PowersSY6970.tpp"
#endif
#include "PowerDeliveryHUSB238.hpp"
#include "XPowersLib_Version.h"

View File

@@ -0,0 +1,173 @@
/**
*
* @license 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.
*
* @file XPowersLibInterface.cpp
* @author Lewis He (lewishe@outlook.com)
* @date 2022-08-28
*
*/
#if defined(ARDUINO)
#include <Arduino.h>
#endif
#include "XPowersLibInterface.hpp"
bool XPowersLibInterface::isChannelAvailable(uint8_t channel)
{
if (__chipModel == XPOWERS_AXP192) {
switch (channel) {
case XPOWERS_DCDC1:
case XPOWERS_DCDC2:
case XPOWERS_DCDC3:
case XPOWERS_LDO2:
case XPOWERS_LDO3:
case XPOWERS_LDOIO:
return true;
default:
return false;
}
} else if (__chipModel == XPOWERS_AXP202) {
switch (channel) {
case XPOWERS_DCDC2:
case XPOWERS_DCDC3:
case XPOWERS_LDO2:
case XPOWERS_LDO3:
case XPOWERS_LDO4:
case XPOWERS_LDO5:
return true;
default:
return false;
}
} else if (__chipModel == XPOWERS_AXP2101) {
switch (channel) {
case XPOWERS_DCDC1:
case XPOWERS_DCDC2:
case XPOWERS_DCDC3:
case XPOWERS_DCDC4:
case XPOWERS_DCDC5:
case XPOWERS_ALDO1:
case XPOWERS_ALDO2:
case XPOWERS_ALDO3:
case XPOWERS_ALDO4:
case XPOWERS_BLDO1:
case XPOWERS_BLDO2:
case XPOWERS_VBACKUP:
case XPOWERS_CPULDO:
return true;
default:
// DLDO is not available, will also return false
return false;
}
}
return false;
}
void XPowersLibInterface::setProtectedChannel(uint8_t channel)
{
__protectedMask |= _BV(channel);
}
void XPowersLibInterface::setUnprotectChannel(uint8_t channel)
{
__protectedMask &= (~_BV(channel));
}
bool XPowersLibInterface::getProtectedChannel(uint8_t channel)
{
return __protectedMask & _BV(channel);
}
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

@@ -0,0 +1,670 @@
/**
*
* @license 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.
*
* @file XPowersLibInterface.hpp
* @author Lewis He (lewishe@outlook.com)
* @date 2022-08-28
*
*/
#pragma once
#include <stdint.h>
#include "XPowersParams.hpp"
/*
| CHIP | AXP173 | AXP192 | AXP202 | AXP2101 |
| ---------- | ----------------- | ----------------- | ----------------- | -------------------------------------- |
| DC1 | 0.7V-3.5V /1.2A | 0.7V-3.5V /1.2A | X | 1.5-3.4V /2A |
| DC2 | 0.7-2.275V/0.6A | 0.7-2.275V /1.6A | 0.7-2.275V /1.6A | 0.5-1.2V,1.22-1.54V /2A |
| DC3 | X | 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 | x | 0.5-1.2V,1.22-1.84V /1.5A |
| DC5 | X | x | x | 1.2V,1.4-3.7V /1A |
| LDO1(VRTC) | 3.3V /30mA | 3.3V /30mA | 3.3V /30mA | 1.8V /30mA |
| LDO2 | 1.8V-3.3V /200mA | 1.8V-3.3V /200mA | 1.8V-3.3V /200mA | x |
| LDO3 | 1.8V-3.3V /200mA | 1.8-3.3V /200mA | 0.7-3.5V /200mA | x |
| LDO4 | 0.7-3.5V /500mA | X | 1.8V-3.3V /200mA | x |
| LDO5/IO0 | X | 1.8-3.3V /50mA | 1.8-3.3V /50mA | x |
| ALDO1 | x | x | x | 0.5-3.5V /300mA |
| ALDO2 | x | x | x | 0.5-3.5V /300mA |
| ALDO3 | x | x | x | 0.5-3.5V /300mA |
| ALDO4 | x | x | x | 0.5-3.5V /300mA |
| BLDO1 | x | x | x | 0.5-3.5V /300mA |
| BLDO2 | x | x | x | 0.5-3.5V /300mA |
| DLDO1 | x | x | x | 0.5-3.3V/ 0.5-1.4V /300mA |
| DLDO1 | x | x | x | 0.5-3.3V/ 0.5-1.4V /300mA |
| CPUSLDO | x | x | x | 0.5-1.4V /30mA |
| | | | | |
*/
// @brief Each chip resource is different,please refer to the table above
typedef enum __XPowersPowerChannel {
XPOWERS_DCDC1,
XPOWERS_DCDC2,
XPOWERS_DCDC3,
XPOWERS_DCDC4,
XPOWERS_DCDC5,
XPOWERS_LDO1,
XPOWERS_LDO2,
XPOWERS_LDO3,
XPOWERS_LDO4,
XPOWERS_LDO5,
XPOWERS_LDOIO,
XPOWERS_ALDO1,
XPOWERS_ALDO2,
XPOWERS_ALDO3,
XPOWERS_ALDO4,
XPOWERS_BLDO1,
XPOWERS_BLDO2,
XPOWERS_DLDO1,
XPOWERS_DLDO2,
XPOWERS_VBACKUP,
XPOWERS_CPULDO,
} XPowersPowerChannel_t;
// @brief Chip type
typedef enum __XPowersChipModel {
XPOWERS_AXP173,
XPOWERS_AXP192,
XPOWERS_AXP202,
XPOWERS_AXP216,
XPOWERS_AXP2101,
XPOWERS_UNDEFINED,
} XPowersChipModel_t;
/**
* @brief Compatible with subclasses of the Meshtastic-devic project
*/
class HasBatteryLevel
{
public:
/**
* @brief Get battery percentage
* @retval 0~100% , -1 no battery is connected
*/
virtual int getBatteryPercent()
{
return -1;
}
/**
* @brief Get battery Voltage
* @retval Voltage unit: millivolt , 0 is no battery is connected
*/
virtual uint16_t getBattVoltage()
{
return 0;
}
/**
* @brief Query whether the current battery is connected
* @retval true to access,false to not access
*/
virtual bool isBatteryConnect()
{
return false;
}
/**
* @brief Query whether the current USB is connected
* @retval true to access,false to not access
*/
virtual bool isVbusIn()
{
return false;
}
/**
* @brief Query whether it is currently in charging state
* @retval true to charge,false to not charge
*/
virtual bool isCharging()
{
return false;
}
};
// @brief Power resource interface class
class XPowersLibInterface : public HasBatteryLevel
{
public:
XPowersLibInterface() : __chipModel(XPOWERS_UNDEFINED), __protectedMask(0) {};
virtual ~XPowersLibInterface() {}
/**
* @brief Calling the XPowersLibInterface interface class
* requires calling init for initialization
* @retval
*/
virtual bool init() = 0;
/**
* @brief When calling the XPowersLibInterface interface class,
* calling deinit releases the Wire handle
* @retval None
*/
virtual void deinit() = 0;
/**
* @brief Set the PMU sleep flag,
* need to manually close the power channel after setting
* @retval true success false failed
*/
virtual bool enableSleep() = 0;
/**
* @brief Set shutdown, calling shutdown will turn off all power channels,
* only VRTC belongs to normal power supply
* @retval None
*/
virtual void shutdown() = 0;
/**
* @brief Get PMU status register
* @note
* @retval register value
*/
virtual uint16_t status() = 0;
/**
* @brief Query chip ID
* @retval Chip ID
*/
virtual uint8_t getChipID() = 0;
//Status function
/**
* @brief Query whether it is currently in charging state
* @retval true to charge,false to not charge
*/
// virtual bool isCharging() = 0;
/**
* @brief Query whether the current USB is connected
* @retval true to access,false to not access
*/
// virtual bool isVbusIn() = 0;
/**
* @brief Query whether the current battery is connected
* @retval true to access,false to not access
*/
// virtual bool isBatteryConnect() = 0;
/**
* @brief Query whether the current is in the discharge state
* @retval true the battery is discharged,false is not discharged
*/
virtual bool isDischarge() = 0;
//Power Channel Control
/**
* @brief Turn on the power channel
* @param channel: Parameters See XPowersPowerChannel_t enumeration
* @retval true success false failed
*/
virtual bool enablePowerOutput(uint8_t channel) = 0;
/**
* @brief Turn off the power channel
* @param channel: Parameters See XPowersPowerChannel_t enumeration
* @retval true success false failed
*/
virtual bool disablePowerOutput(uint8_t channel) = 0;
/**
* @brief Get whether the power channel is enabled
* @param channel: Parameters See XPowersPowerChannel_t enumeration
* @retval true success false failed
*/
virtual bool isPowerChannelEnable(uint8_t channel) = 0;
/**
* @brief Get the set voltage of the power channel
* @param channel: Parameters See XPowersPowerChannel_t enumeration
* @retval true success false failed
*/
virtual uint16_t getPowerChannelVoltage(uint8_t channel) = 0;
/**
* @brief Set the output voltage of a channel power supply
* @param channel: Parameters See XPowersPowerChannel_t enumeration
* @retval true success false failed
*/
virtual bool setPowerChannelVoltage(uint8_t channel, uint16_t millivolt) = 0;
/**
* @brief Set a channel power protection,after setting this channel
* will not be able to be set and closed
* @param channel: Parameters See XPowersPowerChannel_t enumeration
*/
virtual void setProtectedChannel(uint8_t channel);
/**
* @brief Unprotect the channel, call this to unprotect the channel lock
* @param channel: Parameters See XPowersPowerChannel_t enumeration
*/
virtual void setUnprotectChannel(uint8_t channel);
/**
* * @brief Get whether a channel power supply has been protected
* @param channel: Parameters See XPowersPowerChannel_t enumeration
* @retval true is set,false is not set
*/
virtual bool getProtectedChannel(uint8_t channel);
/**
* @brief Query whether the PMU input parameter channel is valid
* @param channel: Parameters See XPowersPowerChannel_t enumeration
* @retval true valid false invalid
*/
virtual bool isChannelAvailable(uint8_t channel);
//battery
/**
* @brief Get battery Voltage
* @retval Voltage unit: millivolt , 0 is no battery is connected
*/
// virtual uint16_t getBattVoltage() = 0;
/**
* @brief Get battery percentage
* @retval 0~100% , -1 no battery is connected
*/
// virtual int getBatteryPercent(void);
// Vbus
/**
* @brief Get PMU VBUS/USB Voltage
* @retval Voltage unit: millivolt , 0 is no vbus is connected
*/
virtual uint16_t getVbusVoltage();
/**
* @brief Set VBUS Current Input Limit.
* @param opt: View the related chip type xpowers_axpxxx_vbus_cur_limit_t enumeration
* parameters in "XPowersParams.hpp"
* @retval true valid false invalid
*/
virtual bool setVbusCurrentLimit(uint8_t opt) = 0;
/**
* @brief Get VBUS Current Input Limit.
* @retval View the related chip type xpowers_axpxxx_vbus_cur_limit_t enumeration
* parameters in "XPowersParams.hpp"
*/
virtual uint8_t getVbusCurrentLimit(void) = 0;
/**
* @brief Set VBUS Voltage Input Limit.
* @param opt: View the related chip type xpowers_axpxxx_vbus_vol_limit_t enumeration
* parameters in "XPowersParams.hpp"
*
*/
virtual void setVbusVoltageLimit(uint8_t opt) = 0;
/**
* @brief Get VBUS Voltage Input Limit.
* @retval View the related chip type xpowers_axpxxx_vbus_vol_limit_t enumeration
* parameters in "XPowersParams.hpp"
*/
virtual uint8_t getVbusVoltageLimit(void) = 0;
// SYS
/**
* @brief Get PMU SYS main Voltage
* @retval Voltage unit: millivolt
*/
virtual uint16_t getSystemVoltage() = 0;
/**
* @brief Set PMU Low Voltage Shutdown Threshold
* @param millivolt: 2600mV ~ 3300mV
* @retval true valid false invalid
*/
virtual bool setSysPowerDownVoltage(uint16_t millivolt) = 0;
/**
* @brief Get PMU Low Voltage Shutdown Threshold
* @retval Voltage unit: millivolt
*/
virtual uint16_t getSysPowerDownVoltage() = 0;
/**
* @brief Set charge target voltage.
* @param opt: View the related chip type xpowers_axpxxx_chg_vol_t enumeration
* parameters in "XPowersParams.hpp"
* @retval true valid false invalid
*/
virtual bool setChargeTargetVoltage(uint8_t opt) = 0;
/**
* @brief Get charge target voltage.
* @retval View the related chip type xpowers_axpxxx_chg_vol_t enumeration
* parameters in "XPowersParams.hpp"
* parameters in "XPowersParams.hpp"
*/
virtual uint8_t getChargeTargetVoltage() = 0;
/**
* @brief Set charge current.
* @param opt: View the related chip type xpowers_axpxxx_chg_curr_t enumeration
* parameters in "XPowersParams.hpp"
* @retval true valid false invalid
*/
virtual bool setChargerConstantCurr(uint8_t opt) = 0;
/**
* @brief Get charge current.
* @retval View the related chip type xpowers_axpxxx_chg_curr_t enumeration
* parameters in "XPowersParams.hpp"
*/
virtual uint8_t getChargerConstantCurr() = 0;
//!PMU Interrupt control
/*
* Example of interrupt usage
* if (pmuInterrupt) {
* pmuInterrupt = false;
*
* Read interrupt status
* uint64_t mask = PMU->getIrqStatus();
* Serial.print("IRQ Mask:0b");
* Serial.println(mask,BIN);
*
* if (PMU->isPekeyShortPressIrq()) {
* Serial.println("isPekeyShortPressIrq");
* }
* if (PMU->isBatChargeStartIrq()) {
* Serial.println("isBatChargeStart");
* }
* ......
*
* After reading the interrupt status,you need to manually clear the status register
* PMU->clearIrqStatus();
* }
* * * */
/**
* @brief Get the interrupt controller mask value.
* @retval Mask value corresponds to xpowers_axpxxx_irq_t ,
*/
virtual uint64_t getIrqStatus() = 0;
/**
* @brief Clear interrupt controller state.
*/
virtual void clearIrqStatus() = 0;
/**
* @brief Enable PMU interrupt control mask .
* @param opt: View the related chip type xpowers_axpxxx_irq_t enumeration
* parameters in "XPowersParams.hpp"
* @retval true valid false invalid
*/
virtual bool enableIRQ(uint64_t opt) = 0;
/**
* @brief Disable PMU interrupt control mask .
* @param opt: View the related chip type xpowers_axpxxx_irq_t enumeration
* parameters in "XPowersParams.hpp"
* @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
*/
virtual bool isPekeyShortPressIrq() = 0;
/**
* @brief Interrupt response when PMU PEKEY is long pressed
* @retval true valid false invalid
*/
virtual bool isPekeyLongPressIrq() = 0;
/**
* @brief Interrupt response when PMU battery is connected
* @retval true valid false invalid
*/
virtual bool isBatInsertIrq() = 0;
/**
* @brief Interrupt response when PMU battery is removed
* @retval true valid false invalid
*/
virtual bool isBatRemoveIrq() = 0;
/**
* @brief Interrupt response when PMU USB is plugged in
* @retval true valid false invalid
*/
virtual bool isVbusInsertIrq() = 0;
/**
* @brief Interrupt response when PMU USB is removed
* @retval true valid false invalid
*/
virtual bool isVbusRemoveIrq() = 0;
/**
* @brief Interrupt response when PMU charging is complete
* @retval true valid false invalid
*/
virtual bool isBatChargeDoneIrq() = 0;
/**
* @brief Interrupt response when PMU charging starts
* @retval true valid false invalid
*/
virtual bool isBatChargeStartIrq() = 0;
//Data collection function
/**
* @brief Enable battery detection function,the default is on
* @retval true success false failed
*/
virtual bool enableBattDetection() = 0;
/**
* @brief Disable battery detection
* @retval true success false failed
*/
virtual bool disableBattDetection() = 0;
/**
* @brief Enable USB input voltage detection
* @retval true success false failed
*/
virtual bool enableVbusVoltageMeasure(void) = 0;
/**
* @brief Disable USB input voltage detection
* @retval true success false failed
*/
virtual bool disableVbusVoltageMeasure(void) = 0;
/**
* @brief Enable system voltage detection
* @retval true success false failed
*/
virtual bool enableSystemVoltageMeasure(void) = 0;
/**
* @brief Disable system voltage detection
* @retval true success false failed
*/
virtual bool disableSystemVoltageMeasure(void) = 0;
/**
* @brief Enable PMU internal temperature sensor detection
* @retval true success false failed
*/
virtual bool enableTemperatureMeasure(void) = 0;
/**
* @brief Disable PMU internal temperature sensor detection
* @retval true success false failed
*/
virtual bool disableTemperatureMeasure(void) = 0;
/**
* @brief Enable battery input voltage detection
* @retval true success false failed
*/
virtual bool enableBattVoltageMeasure(void) = 0;
/**
* @brief Disable battery input voltage detection
* @retval true success false failed
*/
virtual bool disableBattVoltageMeasure(void) = 0;
/**
* @brief Enable NTC thermistor detection (requires hardware support)
* @retval true success false failed
*/
virtual bool enableTSPinMeasure(void) = 0;
/**
* @brief Disable NTC thermistor detection (requires hardware support)
* @retval true success false failed
*/
virtual bool disableTSPinMeasure(void) = 0;
// Charge indicator function
/**
* @brief Set charging led mode
* @param opt: View the related chip type xpowers_chg_led_mode_t enumeration
* parameters in "XPowersParams.hpp"
*/
virtual void setChargingLedMode(uint8_t mode) = 0;
// PMU PEKEY settings
/**
* @brief Set PEKEY press power on time
* @param opt: View the related chip type xpowers_press_on_time_t enumeration
* parameters in "XPowersParams.hpp"
* @retval true success false failed
*/
virtual bool setPowerKeyPressOnTime(uint8_t opt) = 0;
/**
* @brief Get PEKEY press power on time
* @retval View the related chip type xpowers_press_on_time_t enumeration
* parameters in "XPowersParams.hpp"
*/
virtual uint8_t getPowerKeyPressOnTime() = 0;
/**
* @brief Set PEKEY press power off time
* @param opt: View the related chip type xpowers_press_off_time_t enumeration
* parameters in "XPowersParams.hpp"
* @retval true success false failed
*/
virtual bool setPowerKeyPressOffTime(uint8_t opt) = 0;
/**
* @brief Get PEKEY press power off time
* @retval View the related chip type xpowers_press_off_time_t enumeration
* parameters in "XPowersParams.hpp"
*/
virtual uint8_t getPowerKeyPressOffTime() = 0;
/**
* @brief Get the chip model
* @retval See XPowersChipModel_t enumeration
*/
uint8_t getChipModel()
{
return __chipModel;
}
protected:
void setChipModel(uint8_t m)
{
__chipModel = m;
}
uint8_t __chipModel;
uint32_t __protectedMask;
};

View File

@@ -0,0 +1,54 @@
/**
*
* @license MIT License
*
* Copyright (c) 2024 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.
*
* @file XPowersLib_Version.h
* @author Lewis He (lewishe@outlook.com)
* @date 2024-12-12
*
*/
#pragma once
/** Major version number (X.x.x) */
#define XPOWERSLIB_VERSION_MAJOR 0
/** Minor version number (x.X.x) */
#define XPOWERSLIB_VERSION_MINOR 3
/** Patch version number (x.x.X) */
#define XPOWERSLIB_VERSION_PATCH 3
/**
* Macro to convert XPowersLib version number into an integer
*
* To be used in comparisons, such as XPOWERSLIB_VERSION >= XPOWERSLIB_VERSION_VAL(2, 0, 0)
*/
#define XPOWERSLIB_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch))
/**
* Current XPowersLib version, as an integer
*
* To be used in comparisons, such as XPOWERSLIB_VERSION >= XPOWERSLIB_VERSION_VAL(2, 0, 0)
*/
#define XPOWERSLIB_VERSION XPOWERSLIB_VERSION_VAL(XPOWERSLIB_VERSION_MAJOR, \
XPOWERSLIB_VERSION_MINOR, \
XPOWERSLIB_VERSION_PATCH)

View File

@@ -0,0 +1,419 @@
/**
*
* @license 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.
*
* @file XPowersParams.hpp
* @author Lewis He (lewishe@outlook.com)
* @date 2022-08-28
*
*/
#pragma once
#ifdef _BV
#undef _BV
#endif
#define _BV(b) (1ULL << (uint64_t)(b))
//TODO:Unified interface functions and parameters
/**
* @brief PMU PEKEY Press off time parameters.
*/
typedef enum __xpowers_press_off_time {
XPOWERS_POWEROFF_4S,
XPOWERS_POWEROFF_6S,
XPOWERS_POWEROFF_8S,
XPOWERS_POWEROFF_10S,
} xpowers_press_off_time_t;
/**
* @brief PMU PEKEY Press on time parameters.
*/
typedef enum __xpowers_press_on_time {
XPOWERS_POWERON_128MS,
XPOWERS_POWERON_512MS,
XPOWERS_POWERON_1S,
XPOWERS_POWERON_2S,
} xpowers_press_on_time_t;
/**
* @brief Charging led mode parameters.
*/
typedef enum __xpowers_chg_led_mode {
XPOWERS_CHG_LED_OFF,
XPOWERS_CHG_LED_BLINK_1HZ,
XPOWERS_CHG_LED_BLINK_4HZ,
XPOWERS_CHG_LED_ON,
XPOWERS_CHG_LED_CTRL_CHG, // The charging indicator is controlled by the charger
} xpowers_chg_led_mode_t;
/**
* @brief axp2101 charge target voltage parameters.
*/
typedef enum __xpowers_axp2101_chg_vol {
XPOWERS_AXP2101_CHG_VOL_4V = 1,
XPOWERS_AXP2101_CHG_VOL_4V1,
XPOWERS_AXP2101_CHG_VOL_4V2,
XPOWERS_AXP2101_CHG_VOL_4V35,
XPOWERS_AXP2101_CHG_VOL_4V4,
XPOWERS_AXP2101_CHG_VOL_MAX
} xpowers_axp2101_chg_vol_t;
/**
* @brief axp2101 charge currnet voltage parameters.
*/
typedef enum __xpowers_axp2101_chg_curr {
XPOWERS_AXP2101_CHG_CUR_0MA,
XPOWERS_AXP2101_CHG_CUR_100MA = 4,
XPOWERS_AXP2101_CHG_CUR_125MA,
XPOWERS_AXP2101_CHG_CUR_150MA,
XPOWERS_AXP2101_CHG_CUR_175MA,
XPOWERS_AXP2101_CHG_CUR_200MA,
XPOWERS_AXP2101_CHG_CUR_300MA,
XPOWERS_AXP2101_CHG_CUR_400MA,
XPOWERS_AXP2101_CHG_CUR_500MA,
XPOWERS_AXP2101_CHG_CUR_600MA,
XPOWERS_AXP2101_CHG_CUR_700MA,
XPOWERS_AXP2101_CHG_CUR_800MA,
XPOWERS_AXP2101_CHG_CUR_900MA,
XPOWERS_AXP2101_CHG_CUR_1000MA,
} xpowers_axp2101_chg_curr_t;
/**
* @brief axp192 charge target voltage parameters.
*/
typedef enum __xpowers_axp192_chg_vol {
XPOWERS_AXP192_CHG_VOL_4V1,
XPOWERS_AXP192_CHG_VOL_4V15,
XPOWERS_AXP192_CHG_VOL_4V2,
XPOWERS_AXP192_CHG_VOL_4V36,
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.
*/
typedef enum __xpowers_axp192_chg_curr {
XPOWERS_AXP192_CHG_CUR_100MA,
XPOWERS_AXP192_CHG_CUR_190MA,
XPOWERS_AXP192_CHG_CUR_280MA,
XPOWERS_AXP192_CHG_CUR_360MA,
XPOWERS_AXP192_CHG_CUR_450MA,
XPOWERS_AXP192_CHG_CUR_550MA,
XPOWERS_AXP192_CHG_CUR_630MA,
XPOWERS_AXP192_CHG_CUR_700MA,
XPOWERS_AXP192_CHG_CUR_780MA,
XPOWERS_AXP192_CHG_CUR_880MA,
XPOWERS_AXP192_CHG_CUR_960MA,
XPOWERS_AXP192_CHG_CUR_1000MA,
XPOWERS_AXP192_CHG_CUR_1080MA,
XPOWERS_AXP192_CHG_CUR_1160MA,
XPOWERS_AXP192_CHG_CUR_1240MA,
XPOWERS_AXP192_CHG_CUR_1320MA,
} 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;
/**
* @brief axp2101 vbus currnet limit parameters.
*/
typedef enum {
XPOWERS_AXP2101_VBUS_CUR_LIM_100MA,
XPOWERS_AXP2101_VBUS_CUR_LIM_500MA,
XPOWERS_AXP2101_VBUS_CUR_LIM_900MA,
XPOWERS_AXP2101_VBUS_CUR_LIM_1000MA,
XPOWERS_AXP2101_VBUS_CUR_LIM_1500MA,
XPOWERS_AXP2101_VBUS_CUR_LIM_2000MA,
} xpowers_axp2101_vbus_cur_limit_t;
/**
* @brief axp192 vbus currnet limit parameters.
*/
typedef enum {
XPOWERS_AXP192_VBUS_CUR_LIM_500MA,
XPOWERS_AXP192_VBUS_CUR_LIM_100MA,
XPOWERS_AXP192_VBUS_CUR_LIM_OFF,
} 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;
typedef enum {
XPOWERS_AXP192_VBUS_VOL_LIM_4V,
XPOWERS_AXP192_VBUS_VOL_LIM_4V1,
XPOWERS_AXP192_VBUS_VOL_LIM_4V2,
XPOWERS_AXP192_VBUS_VOL_LIM_4V3,
XPOWERS_AXP192_VBUS_VOL_LIM_4V4,
XPOWERS_AXP192_VBUS_VOL_LIM_4V5,
XPOWERS_AXP192_VBUS_VOL_LIM_4V6,
XPOWERS_AXP192_VBUS_VOL_LIM_4V7,
} xpowers_axp192_vbus_vol_limit_t;
typedef enum {
XPOWERS_AXP202_VBUS_VOL_LIM_4V,
XPOWERS_AXP202_VBUS_VOL_LIM_4V1,
XPOWERS_AXP202_VBUS_VOL_LIM_4V2,
XPOWERS_AXP202_VBUS_VOL_LIM_4V3,
XPOWERS_AXP202_VBUS_VOL_LIM_4V4,
XPOWERS_AXP202_VBUS_VOL_LIM_4V5,
XPOWERS_AXP202_VBUS_VOL_LIM_4V6,
XPOWERS_AXP202_VBUS_VOL_LIM_4V7,
} xpowers_axp202_vbus_vol_limit_t;
typedef enum {
XPOWERS_AXP2101_VBUS_VOL_LIM_3V88,
XPOWERS_AXP2101_VBUS_VOL_LIM_3V96,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V04,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V12,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V20,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V28,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V36,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V44,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V52,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V60,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V68,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V76,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V84,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V92,
XPOWERS_AXP2101_VBUS_VOL_LIM_5V,
XPOWERS_AXP2101_VBUS_VOL_LIM_5V08,
} xpower_apx2101_vbus_vol_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.
*/
typedef enum __xpowers_axp192_irq {
//! IRQ1 REG 40H
XPOWERS_AXP192_VBUS_VHOLD_LOW_IRQ = _BV(1), //VBUS is available, but lower than V HOLD, IRQ enable
XPOWERS_AXP192_VBUS_REMOVE_IRQ = _BV(2), //VBUS removed, IRQ enable
XPOWERS_AXP192_VBUS_INSERT_IRQ = _BV(3), //VBUS connected, IRQ enable
XPOWERS_AXP192_VBUS_OVER_VOL_IRQ = _BV(4), //VBUS over-voltage, IRQ enable
XPOWERS_AXP192_ACIN_REMOVED_IRQ = _BV(5), //ACIN removed, IRQ enable
XPOWERS_AXP192_ACIN_CONNECT_IRQ = _BV(6), //ACIN connected, IRQ enable
XPOWERS_AXP192_ACIN_OVER_VOL_IRQ = _BV(7), //ACIN over-voltage, IRQ enable
//! IRQ2 REG 41H
XPOWERS_AXP192_BATT_LOW_TEMP_IRQ = _BV(8), //Battery low-temperature, IRQ enable
XPOWERS_AXP192_BATT_OVER_TEMP_IRQ = _BV(9), //Battery over-temperature, IRQ enable
XPOWERS_AXP192_BAT_CHG_DONE_IRQ = _BV(10), //Charge finished, IRQ enable
XPOWERS_AXP192_BAT_CHG_START_IRQ = _BV(11), //Be charging, IRQ enable
XPOWERS_AXP192_BATT_EXIT_ACTIVATE_IRQ = _BV(12), //Exit battery activate mode, IRQ enable
XPOWERS_AXP192_BATT_ACTIVATE_IRQ = _BV(13), //Battery activate mode, IRQ enable
XPOWERS_AXP192_BAT_REMOVE_IRQ = _BV(14), //Battery removed, IRQ enable
XPOWERS_AXP192_BAT_INSERT_IRQ = _BV(15), //Battery connected, IRQ enable
//! IRQ3 REG 42H
XPOWERS_AXP192_PKEY_LONG_IRQ = _BV(16), //PEK long press, IRQ enable
XPOWERS_AXP192_PKEY_SHORT_IRQ = _BV(17), //PEK short press, IRQ enable
//**Reserved and unchangeable BIT 2
XPOWERS_AXP192_DC3_LOW_VOL_IRQ = _BV(19), //DC-DC3output voltage is lower than the set value, IRQ enable
XPOWERS_AXP192_DC2_LOW_VOL_IRQ = _BV(20), //DC-DC2 output voltage is lower than the set value, IRQ enable
XPOWERS_AXP192_DC1_LOW_VOL_IRQ = _BV(21), //DC-DC1 output voltage is lower than the set value, IRQ enable
XPOWERS_AXP192_CHARGE_LOW_CUR_IRQ = _BV(22), //Charge current is lower than the set current, IRQ enable
XPOWERS_AXP192_CHIP_TEMP_HIGH_IRQ = _BV(23), //XPOWERS internal over-temperature, IRQ enable
//! IRQ4 REG 43H
XPOWERS_AXP192_APS_LOW_VOL_LEVEL_IRQ = _BV(24), //APS low-voltage, IRQ enable
//**Reserved and unchangeable BIT 1
XPOWERS_AXP192_VBUS_SESSION_END_IRQ = _BV(26), //VBUS Session End IRQ enable
XPOWERS_AXP192_VBUS_SESSION_AB_IRQ = _BV(27), //VBUS Session A/B IRQ enable
XPOWERS_AXP192_VBUS_INVALID_IRQ = _BV(28), //VBUS invalid, IRQ enable
XPOWERS_AXP192_VBUS_VAILD_IRQ = _BV(29), //VBUS valid, IRQ enable
XPOWERS_AXP192_NOE_OFF_IRQ = _BV(30), //N_OE shutdown, IRQ enable
XPOWERS_AXP192_NOE_ON_IRQ = _BV(31), //N_OE startup, IRQ enable
//! IRQ5 REG 4AH
XPOWERS_AXP192_GPIO0_EDGE_TRIGGER_IRQ = _BV(32), //GPIO0 input edge trigger, IRQ enable
XPOWERS_AXP192_GPIO1_EDGE_TRIGGER_IRQ = _BV(33), //GPIO1input edge trigger or ADC input, IRQ enable
XPOWERS_AXP192_GPIO2_EDGE_TRIGGER_IRQ = _BV(34), //GPIO2input edge trigger, IRQ enable
//**Reserved and unchangeable BIT 3
//**Reserved and unchangeable BIT 4
//**Reserved and unchangeable BIT 5
//**Reserved and unchangeable BIT 6
XPOWERS_AXP192_TIMER_TIMEOUT_IRQ = _BV(39), //Timer timeout, IRQ enable
XPOWERS_AXP192_ALL_IRQ = (0xFFFFFFFFFFULL)
} xpowers_axp192_irq_t;
/**
* @brief axp2101 interrupt control mask parameters.
*/
typedef enum __xpowers_axp2101_irq {
//! IRQ1 REG 40H
XPOWERS_AXP2101_BAT_NOR_UNDER_TEMP_IRQ = _BV(0), // Battery Under Temperature in Work
XPOWERS_AXP2101_BAT_NOR_OVER_TEMP_IRQ = _BV(1), // Battery Over Temperature in Work mode
XPOWERS_AXP2101_BAT_CHG_UNDER_TEMP_IRQ = _BV(2), // Battery Under Temperature in Charge mode IRQ(bcut_irq)
XPOWERS_AXP2101_BAT_CHG_OVER_TEMP_IRQ = _BV(3), // Battery Over Temperature in Charge mode IRQ(bcot_irq) enable
XPOWERS_AXP2101_GAUGE_NEW_SOC_IRQ = _BV(4), // Gauge New SOC IRQ(lowsoc_irq) enable (low state of charge)
XPOWERS_AXP2101_WDT_TIMEOUT_IRQ = _BV(5), // Gauge Watchdog Timeout IRQ(gwdt_irq) enable
XPOWERS_AXP2101_WARNING_LEVEL1_IRQ = _BV(6), // SOC drop to Warning Level1 IRQ(socwl1_irq) enable
XPOWERS_AXP2101_WARNING_LEVEL2_IRQ = _BV(7), // SOC drop to Warning Level2 IRQ(socwl2_irq) enable
//! IRQ2 REG 41H
XPOWERS_AXP2101_PKEY_POSITIVE_IRQ = _BV(8), // POWERON Positive Edge IRQ(ponpe_irq_en) enable
XPOWERS_AXP2101_PKEY_NEGATIVE_IRQ = _BV(9), // POWERON Negative Edge IRQ(ponne_irq_en) enable
XPOWERS_AXP2101_PKEY_LONG_IRQ = _BV(10), // POWERON Long PRESS IRQ(ponlp_irq) enable
XPOWERS_AXP2101_PKEY_SHORT_IRQ = _BV(11), // POWERON Short PRESS IRQ(ponsp_irq_en) enable
XPOWERS_AXP2101_BAT_REMOVE_IRQ = _BV(12), // Battery Remove IRQ(bremove_irq) enable
XPOWERS_AXP2101_BAT_INSERT_IRQ = _BV(13), // Battery Insert IRQ(binsert_irq) enabl
XPOWERS_AXP2101_VBUS_REMOVE_IRQ = _BV(14), // VBUS Remove IRQ(vremove_irq) enabl
XPOWERS_AXP2101_VBUS_INSERT_IRQ = _BV(15), // VBUS Insert IRQ(vinsert_irq) enable
//! IRQ3 REG 42H
XPOWERS_AXP2101_BAT_OVER_VOL_IRQ = _BV(16), // Battery Over Voltage Protection IRQ(bovp_irq) enable
XPOWERS_AXP2101_CHARGER_TIMER_IRQ = _BV(17), // Charger Safety Timer1/2 expire IRQ(chgte_irq) enable
XPOWERS_AXP2101_DIE_OVER_TEMP_IRQ = _BV(18), // DIE Over Temperature level1 IRQ(dotl1_irq) enable
XPOWERS_AXP2101_BAT_CHG_START_IRQ = _BV(19), // Charger start IRQ(chgst_irq) enable
XPOWERS_AXP2101_BAT_CHG_DONE_IRQ = _BV(20), // Battery charge done IRQ(chgdn_irq) enable
XPOWERS_AXP2101_BATFET_OVER_CURR_IRQ = _BV(21), // BATFET Over Current Protection IRQ(bocp_irq) enable
XPOWERS_AXP2101_LDO_OVER_CURR_IRQ = _BV(22), // LDO Over Current IRQ(ldooc_irq) enable
XPOWERS_AXP2101_WDT_EXPIRE_IRQ = _BV(23), // Watchdog Expire IRQ(wdexp_irq) enable
XPOWERS_AXP2101_ALL_IRQ = (0xFFFFFFFFUL)
} 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;