32#include "../../PmicChargerBase.hpp"
33#include "../../../platform/SensorCommWrapper.hpp"
35template<
typename Regs>
102 if (mA < Regs::chg::CHG_CUR_MIN) mA = Regs::chg::CHG_CUR_MIN;
103 if (mA > Regs::chg::CHG_CUR_MAX) mA = Regs::chg::CHG_CUR_MAX;
104 uint8_t code = (mA - Regs::chg::CHG_CUR_MIN) / Regs::chg::CHG_CUR_STEP;
106 if (regVal < 0)
return false;
107 regVal = (regVal & 0xF0) | code;
108 return _core.
writeReg(Regs::chg::CHARGE1,
static_cast<uint8_t
>(regVal)) >= 0;
118 if (val < 0)
return 0;
119 uint8_t code = val & 0x0F;
120 return code * Regs::chg::CHG_CUR_STEP + Regs::chg::CHG_CUR_MIN;
135 bool set = (mA >= 150);
136 return _core.
updateBits(Regs::chg::CHARGE1, 0x10, set ? 0x10 : 0x00) >= 0;
146 if (val < 0)
return 0;
147 return (val & 0x10) ? 150 : 0;
168 }
else if (mV <= 4150) {
170 }
else if (mV <= 4200) {
185 if (val < 0)
return 0;
186 uint8_t code = (val >> 5) & 0x03;
209 if (s0 < 0 || s1 < 0) {
212 status.online =
true;
213 status.vbusPresent = (s0 >> 5) & 0x01;
214 status.batteryPresent = (s1 >> 5) & 0x01;
215 status.charging = (s1 >> 6) & 0x01;
216 status.chargeDone =
false;
217 status.fault = (s1 >> 7) & 0x01;
218 if (status.charging) {
bool setFastChargeCurrent(uint16_t mA) override
Set fast charge (constant-current) current.
bool setChargeVoltage(uint16_t mV) override
Set the charge target voltage (CV).
uint16_t getChargeVoltage() override
Get the charge target voltage (CV).
SensorCommWrapper & _core
uint16_t getPreChargeCurrent() override
Get pre-charge current (not supported by AXP1xx).
bool setTerminationCurrent(uint16_t mA) override
Set the termination current threshold.
uint16_t getTerminationCurrent() override
Get the termination current threshold.
uint16_t getFastChargeCurrent() override
Get the fast charge (constant-current) current.
bool isCharging() override
Check whether the battery is currently charging.
bool setPreChargeCurrent(uint16_t mA) override
Set pre-charge current (not supported by AXP1xx).
bool enableCharging(bool enable) override
Enable or disable battery charging.
Status getStatus() override
Get the charger status.
AXP1xxCharger(SensorCommWrapper &core)
Construct charger control interface.
PMIC charger capability interface.
@ NO_CHARGING
Not charging, battery idle or disconnected.
@ FAST_CHARGE
Fast charge phase (constant current)
bool clrRegBit(uint8_t reg, uint8_t bit)
int readReg(uint8_t reg) const
int writeReg(uint8_t reg, uint8_t val)
int updateBits(uint8_t reg, uint8_t mask, uint8_t value_shifted)
bool setRegBit(uint8_t reg, uint8_t bit)
Charger status structure.
bool charging
Charging state (coarse: true if in precharge/fastcharge)