SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
AXP202ChargerEx.hpp
Go to the documentation of this file.
1
34#pragma once
35#include "AXP202Core.hpp"
36#include "AXP202Regs.hpp"
37
39{
40public:
41 explicit AXP202ChargerEx(AXP202Core &core) : _core(core) {}
42
43 // ---- Charge Temperature Thresholds ----
49 bool setChargeLowTempThreshold(uint8_t val)
50 {
51 return _core.writeReg(axp202_regs::chg::VLTF_CHGSET, val) >= 0;
52 }
53
55 {
57 return (val < 0) ? 0 : static_cast<uint8_t>(val);
58 }
59
66 {
67 return _core.writeReg(axp202_regs::chg::VHTF_CHGSET, val) >= 0;
68 }
69
71 {
73 return (val < 0) ? 0 : static_cast<uint8_t>(val);
74 }
75
76 // ---- Discharge Temperature Thresholds ----
83 {
84 return _core.writeReg(axp202_regs::chg::TLTF_DISCHGSET, val) >= 0;
85 }
86
88 {
90 return (val < 0) ? 0 : static_cast<uint8_t>(val);
91 }
92
99 {
100 return _core.writeReg(axp202_regs::chg::THTF_DISCHGSET, val) >= 0;
101 }
102
104 {
106 return (val < 0) ? 0 : static_cast<uint8_t>(val);
107 }
108
109 // ---- Backup Battery Charger (REG 35H) ----
110
116 bool enableBackupCharger(bool enable)
117 {
118 return enable ? _core.setRegBit(axp202_regs::chg::BACKUP_CHG, 7)
120 }
121
123 {
125 }
126
132 bool setBackupChargerVoltage(uint8_t opt)
133 {
134 if (opt > 3) return false;
135 return _core.updateBits(axp202_regs::chg::BACKUP_CHG, 0x60, opt << 5) >= 0;
136 }
137
139 {
140 int val = _core.readReg(axp202_regs::chg::BACKUP_CHG);
141 return (val < 0) ? 0 : static_cast<uint8_t>((val >> 5) & 0x03);
142 }
143
149 bool setBackupChargerCurrent(uint8_t opt)
150 {
151 if (opt > 3) return false;
152 return _core.updateBits(axp202_regs::chg::BACKUP_CHG, 0x03, opt) >= 0;
153 }
154
156 {
157 int val = _core.readReg(axp202_regs::chg::BACKUP_CHG);
158 return (val < 0) ? 0 : static_cast<uint8_t>(val & 0x03);
159 }
160
161 // ---- Charge Timeout (REG 34H) ----
162
168 bool setPrechargeTimeout(uint8_t opt)
169 {
170 if (opt > 3) return false;
171 return _core.updateBits(axp202_regs::chg::CHARGE2, 0xC0, opt << 6) >= 0;
172 }
173
175 {
176 int val = _core.readReg(axp202_regs::chg::CHARGE2);
177 return (val < 0) ? 0 : static_cast<uint8_t>((val >> 6) & 0x03);
178 }
179
186 {
187 if (opt > 3) return false;
188 return _core.updateBits(axp202_regs::chg::CHARGE2, 0x03, opt) >= 0;
189 }
190
192 {
193 int val = _core.readReg(axp202_regs::chg::CHARGE2);
194 return (val < 0) ? 0 : static_cast<uint8_t>(val & 0x03);
195 }
196
197 // NOTE: External channel charge functions removed - bits 2 and 4:3 of
198 // REG 34H are reserved. Using them corrupts CHGLED mode configuration.
199
200private:
201 AXP202Core &_core;
202};
@license MIT License
@license MIT License
bool enableBackupCharger(bool enable)
Enable backup battery charger (REG 35H bit 7)
AXP202ChargerEx(AXP202Core &core)
bool setChargeHighTempThreshold(uint8_t val)
Set charge high-temperature fault threshold (REG 39H)
bool setChargeLowTempThreshold(uint8_t val)
Set charge low-temperature fault threshold (REG 38H)
bool setDischargeLowTempThreshold(uint8_t val)
Set discharge low-temperature fault threshold (REG 3CH)
bool setBackupChargerVoltage(uint8_t opt)
Set backup battery charge voltage (REG 35H bits 6:5)
uint8_t getChargeHighTempThreshold()
bool setConstantCurrentTimeout(uint8_t opt)
Set constant-current charge timeout (REG 34H bits 1:0)
uint8_t getPrechargeTimeout()
uint8_t getConstantCurrentTimeout()
uint8_t getDischargeLowTempThreshold()
bool setBackupChargerCurrent(uint8_t opt)
Set backup battery charge current (REG 35H bits 1:0)
uint8_t getBackupChargerCurrent()
uint8_t getDischargeHighTempThreshold()
uint8_t getChargeLowTempThreshold()
bool setPrechargeTimeout(uint8_t opt)
Set precharge timeout (REG 34H bits 7:6)
uint8_t getBackupChargerVoltage()
bool setDischargeHighTempThreshold(uint8_t val)
Set discharge high-temperature fault threshold (REG 3DH)
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)
int updateBits(uint8_t reg, uint8_t mask, uint8_t value_shifted)
bool setRegBit(uint8_t reg, uint8_t bit)
static constexpr uint8_t BACKUP_CHG
static constexpr uint8_t VLTF_CHGSET
static constexpr uint8_t TLTF_DISCHGSET
static constexpr uint8_t VHTF_CHGSET
static constexpr uint8_t THTF_DISCHGSET
static constexpr uint8_t CHARGE2