31#include "../../../SensorBuildOpt.h"
32#if !SENSORLIB_EXCLUDE_PMIC_AXP2101
54 if (mA > 200) mA = 200;
55 uint8_t code = mA / 25;
57 if (regVal < 0)
return false;
58 regVal = (regVal & 0xF0) | code;
65 if (val < 0)
return 0;
66 return (val & 0x0F) * 25;
72 if (mA > 1000) mA = 1000;
76 code = (mA - 200) / 100 + 8;
79 if (regVal < 0)
return false;
80 regVal = (regVal & 0xE0) | code;
87 if (val < 0)
return 0;
88 uint8_t code = val & 0x1F;
92 return 200 + (code - 8) * 100;
97 if (mA > 200) mA = 200;
98 uint8_t code = mA / 25;
100 if (regVal < 0)
return false;
101 regVal = (regVal & 0xF0) | code;
108 if (val < 0)
return 0;
109 return (val & 0x0F) * 25;
116 case 5000: code = 0;
break;
117 case 4000: code = 1;
break;
118 case 4100: code = 2;
break;
119 case 4200: code = 3;
break;
120 case 4350: code = 4;
break;
121 case 4400: code = 5;
break;
122 default:
return false;
125 if (regVal < 0)
return false;
126 regVal = (regVal & 0xF8) | code;
133 if (val < 0)
return 0;
134 switch (val & 0x07) {
150 if (status1 < 0 || status2 < 0) {
153 status.online =
true;
154 status.vbusPresent = (status1 >> 5) & 0x01;
155 status.batteryPresent = (status1 >> 3) & 0x01;
156 uint8_t chargePhase = status2 & 0x07;
157 switch (chargePhase) {
172 status.chargeDone = (chargePhase == 4);
173 status.charging = (chargePhase >= 1 && chargePhase <= 3);
174 status.fault = (status1 & 0x01) != 0;
197 if (val < 0)
return false;
198 return (val >> 4) & 0x01;
220 if (millivolt < 2600 || millivolt > 3300 || (millivolt % 100))
223 if (val < 0)
return false;
225 val |= (millivolt - 2600) / 100;
232 if (val < 0)
return 0;
233 return ((val & 0x07) * 100) + 2600;
257 if (opt > 3) opt = 3;
267 if (opt > 3) opt = 3;
290 if (val < 0)
return 0;
317 return (val < 0) ? 0 :
static_cast<uint8_t
>(val);
328 return (val < 0) ? 0 :
static_cast<uint8_t
>(val);
339 return (val < 0) ? 0 :
static_cast<uint8_t
>(val);
350 return (val < 0) ? 0 :
static_cast<uint8_t
>(val);
363 return (val < 0) ? 0 :
static_cast<uint8_t
>(val);
374 return (val < 0) ? 0 :
static_cast<uint8_t
>(val);
403 if (levels > 2)
return false;
405 if (val < 0)
return false;
407 val |= (levels << 2);
414 if (val < 0)
return 0;
415 return (val >> 2) & 0x03;
420 if (levels > 2)
return false;
422 if (val < 0)
return false;
431 if (val < 0)
return 0;
441 if (reg < 0)
return false;
450 if (val < 0)
return 0;
458 if (reg < 0)
return false;
460 reg |= ((val & 0x0F) << 4);
467 if (val < 0)
return 0;
468 return (val >> 4) & 0x0F;
Status getStatus() override
Get the current charger status.
void disableButtonBatteryCharge()
Disable button/coin-cell battery charging (REG 0x18, bit 2).
bool isCharging() override
Check if the charger is actively charging.
uint8_t getChargeHighTempFaultThreshold()
Get charge high-temperature fault threshold (REG 55, VHTF_CHG).
bool isBatteryDetectionEnabled()
Check if battery detection is enabled (REG 0x68, bit 0).
void disableBatteryDetection()
Disable battery detection (REG 0x68, bit 0).
bool setLowTempHysteresis(uint8_t val)
Set low-temperature hysteresis (REG 52, HYSL2H).
void enableBatteryDetection()
Enable battery detection (REG 0x68, bit 0).
bool setChargeLowTempFaultThreshold(uint8_t val)
Set charge low-temperature fault threshold (REG 54, VLTF_CHG).
bool setJeitaCoolVoltageDrop(uint8_t levels)
Set cool-zone voltage drop levels in JEITA.
AXP2101Charger(AXP2101Core &core)
Construct AXP2101Charger with a reference to the AXP2101Core.
uint16_t getPreChargeCurrent() override
Get the configured precharge current (REG 0x61, bits 3:0).
bool setJeitaCoolThreshold(uint8_t val)
Set JEITA cool temperature threshold T2 (REG 5B low nibble).
bool setWorkLowTempFaultThreshold(uint8_t val)
Set work low-temperature fault threshold (REG 56, VLTF_WORK).
uint8_t getJeitaWarmVoltageDrop()
Get warm-zone voltage drop levels in JEITA (REG 0x59).
uint8_t getJeitaWarmThreshold()
Get JEITA warm temperature threshold T3 (REG 5B high nibble).
void enableButtonBatteryCharge()
Enable button/coin-cell battery charging (REG 0x18, bit 2).
uint8_t getThermalRegulationThreshold()
Get the thermal regulation threshold (REG 0x65, bits 1:0).
bool setJeitaWarmVoltageDrop(uint8_t levels)
Set warm-zone voltage drop levels in JEITA.
uint8_t getLowTempHysteresis()
Get low-temperature hysteresis (REG 52, HYSL2H).
bool setFastChargeCurrent(uint16_t mA) override
Set the fast-charge current limit (REG 0x62, bits 4:0).
bool setJeitaCoolCurrentReduction(bool reduce)
Set cool-zone current reduction in JEITA.
bool setPreChargeCurrent(uint16_t mA) override
Set the precharge current limit (REG 0x61, bits 3:0).
void setChargeDoneSafetyTimer(uint8_t opt)
Set the charge-done safety timer (REG 0x67, bits 6:4).
uint8_t getWorkLowTempFaultThreshold()
Get work low-temperature fault threshold (REG 56, VLTF_WORK).
bool enableJeita(bool enable)
Enable or disable JEITA temperature standard.
bool setChargeVoltage(uint16_t mV) override
Set the charge voltage target (REG 0x64, bits 2:0).
bool setHighTempHysteresis(uint8_t val)
Set high-temperature hysteresis (REG 53, HYSH2L).
uint8_t getHighTempHysteresis()
Get high-temperature hysteresis (REG 53, HYSH2L).
bool isJeitaEnabled()
Check if JEITA temperature standard is enabled.
void enableChargeTermination()
Enable charge termination detection (REG 0x63, bit 4).
bool getJeitaCoolCurrentReduction()
Get cool-zone current reduction setting in JEITA (REG 0x59).
uint16_t getButtonBatteryChargeVoltage()
Get the configured button battery charge voltage (REG 0x6A, bits 2:0).
uint8_t getJeitaCoolThreshold()
Get JEITA cool temperature threshold T2 (REG 5B low nibble).
uint8_t getJeitaCoolVoltageDrop()
Get cool-zone voltage drop levels in JEITA (REG 0x59).
bool enableCharging(bool enable) override
Enable or disable battery charging.
uint16_t getChargeVoltage() override
Get the configured charge voltage target (REG 0x64, bits 2:0).
void disableChargeTermination()
Disable charge termination detection (REG 0x63, bit 4).
uint16_t getFastChargeCurrent() override
Get the configured fast-charge current (REG 0x62, bits 4:0).
bool setChargeHighTempFaultThreshold(uint8_t val)
Set charge high-temperature fault threshold (REG 55, VHTF_CHG).
bool isButtonBatteryChargeEnabled()
Check if button battery charging is enabled (REG 0x18, bit 2).
bool setWorkHighTempFaultThreshold(uint8_t val)
Set work high-temperature fault threshold (REG 57, VHTF_WORK).
uint8_t getChargeLowTempFaultThreshold()
Get charge low-temperature fault threshold (REG 54, VLTF_CHG).
bool setJeitaWarmThreshold(uint8_t val)
Set JEITA warm temperature threshold T3 (REG 5B high nibble).
bool setButtonBatteryChargeVoltage(uint16_t millivolt)
Set the button battery charge voltage (REG 0x6A, bits 2:0).
bool getJeitaWarmCurrentReduction()
Get warm-zone current reduction setting in JEITA (REG 0x59).
void setPreChargeSafetyTimer(uint8_t opt)
Set the precharge safety timer (REG 0x67, bits 2:0).
uint8_t getWorkHighTempFaultThreshold()
Get work high-temperature fault threshold (REG 57, VHTF_WORK).
bool setJeitaWarmCurrentReduction(bool reduce)
Set warm-zone current reduction in JEITA.
uint16_t getTerminationCurrent() override
Get the configured termination current (REG 0x63, bits 3:0).
bool setTerminationCurrent(uint16_t mA) override
Set the charge termination current (REG 0x63, bits 3:0).
void setThermalRegulationThreshold(uint8_t opt)
Set the thermal regulation threshold (REG 0x65, bits 1:0).
bool isChargeTerminationEnabled()
Check if charge termination detection is enabled (REG 0x63, bit 4).
Core I2C communication layer for the AXP2101 PMIC.
bool enableModule(Module module, bool enable)
Enable or disable an internal functional module.
@ CELL_CHARGE
Cell battery charger (REG 0x18 bit 1)
@ NO_CHARGING
Not charging, battery idle or disconnected.
@ PRE_CHARGE
Pre-charge phase (low current for weak battery)
@ TERMINATION
Charging terminated (battery full)
@ FAST_CHARGE
Fast charge phase (constant current)
bool clrRegBit(uint8_t reg, uint8_t bit)
bool getRegBit(uint8_t reg, uint8_t bit)
int readReg(uint8_t reg) const
int writeReg(uint8_t reg, uint8_t val)
bool setRegBit(uint8_t reg, uint8_t bit)
Charger status structure.
bool charging
Charging state (coarse: true if in precharge/fastcharge)
static constexpr uint8_t STATUS2
static constexpr uint8_t STATUS1
static constexpr uint8_t BAT_DETECT_CTRL
static constexpr uint8_t CV_CHG_VOLTAGE
static constexpr uint8_t ITERM_CTRL
static constexpr uint8_t ICC_SETTING
static constexpr uint8_t BTN_BAT_CHG_VOL
static constexpr uint8_t CHG_TIMER_CFG
static constexpr uint8_t THERMAL_REG_THRESH
static constexpr uint8_t IPRECHG_SET
static constexpr uint8_t MODULE_EN
static constexpr uint8_t SET2
static constexpr uint8_t SET0
static constexpr uint8_t EN_CTRL
static constexpr uint8_t VLTF_CHG
static constexpr uint8_t VHTF_CHG
static constexpr uint8_t VLTF_WORK
static constexpr uint8_t VHTF_WORK
static constexpr uint8_t HYSH2L
static constexpr uint8_t HYSL2H