SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
BQ25896Core.hpp
Go to the documentation of this file.
1
65#pragma once
66
67#include "../../../platform/comm/I2CDeviceWithHal.hpp"
68#include "BQ25896Regs.hpp"
69
71{
72constexpr uint8_t WATCHDOG_TIMEOUT = 0x80;
73constexpr uint8_t BOOST_FAULT = 0x40;
74constexpr uint8_t CHARGE_FAULT_MASK = 0x30;
75constexpr uint8_t CHARGE_FAULT_NORMAL = 0x00;
76constexpr uint8_t CHARGE_FAULT_INPUT = 0x10; // Bit 4: BUS OVP or VBAT<BUS<3.8V
77constexpr uint8_t CHARGE_FAULT_THERMAL = 0x20; // Bit 5: Thermal shutdown
78constexpr uint8_t CHARGE_FAULT_TIMER = 0x30; // Bits 5+4: Safety timer expiration
79constexpr uint8_t BATTERY_FAULT = 0x08;
80constexpr uint8_t NTC_FAULT_MASK = 0x07;
81
82inline bool isWatchdogTimeout(uint8_t fault)
83{
84 return (fault & WATCHDOG_TIMEOUT) != 0;
85}
86inline bool isBoostFault(uint8_t fault)
87{
88 return (fault & BOOST_FAULT) != 0;
89}
90inline bool isChargeFault(uint8_t fault)
91{
92 return (fault & CHARGE_FAULT_MASK) != 0;
93}
94inline uint8_t getChargeFaultType(uint8_t fault)
95{
96 return fault & CHARGE_FAULT_MASK;
97}
98inline bool isChargeInputFault(uint8_t fault)
99{
100 return (fault & CHARGE_FAULT_MASK) == CHARGE_FAULT_INPUT;
101}
102inline bool isChargeThermalFault(uint8_t fault)
103{
104 return (fault & CHARGE_FAULT_MASK) == CHARGE_FAULT_THERMAL;
105}
106inline bool isChargeTimerFault(uint8_t fault)
107{
108 return (fault & CHARGE_FAULT_MASK) == CHARGE_FAULT_TIMER;
109}
110inline bool isBatteryFault(uint8_t fault)
111{
112 return (fault & BATTERY_FAULT) != 0;
113}
114inline uint8_t getNtcFault(uint8_t fault)
115{
116 return fault & NTC_FAULT_MASK;
117}
118}
119
121{
122public:
123 BQ25896Core() = default;
124 ~BQ25896Core() = default;
125
132 void end();
133
145 bool isValid() const;
146
155 uint8_t getDeviceRevision() const;
156
164 uint8_t getDeviceConfig();
165
173 void reset();
174
186 bool isVbusPresent();
187
203 uint8_t getBusStatus();
204
216 uint8_t getChargeStatus();
217
226 bool isPowerGood();
227
238 bool isCharging();
239
248 bool isChargeDone();
249
258 bool isOtg();
259
271 bool isVsysInRegulation();
272
286 bool isVindpmActive();
287
300 bool isIindpmActive();
301
324 bool getFaultStatus(uint8_t &fault);
325
341
342
343private:
344 bool initImpl(uint8_t param) override;
345};
@license MIT License
void reset()
Reset device to default state.
bool isInputCurrentOptimizerOptimized()
Check if Input Current Optimizer has optimized.
uint8_t getChargeStatus()
Get charging status.
bool isOtg()
Check if in OTG (boost) mode.
~BQ25896Core()=default
BQ25896Core()=default
bool isPowerGood()
Check if power is good.
uint8_t getDeviceConfig()
Get device configuration/part number.
bool isVsysInRegulation()
Check if VSYS is in regulation.
uint8_t getDeviceRevision() const
Get device revision.
bool isVindpmActive()
Get fault status.
bool getFaultStatus(uint8_t &fault)
Get fault status.
uint8_t getBusStatus()
Get USB port type status.
bool isValid() const
Check if device is valid/present.
bool isVbusPresent()
Check if VBUS (USB power) is present.
bool isCharging()
Check if actively charging.
bool isIindpmActive()
Check if IINDPM is active (input current limiting)
void end()
Deinitialize and release resources.
bool isChargeDone()
Check if charging is complete.
constexpr uint8_t CHARGE_FAULT_TIMER
bool isChargeInputFault(uint8_t fault)
constexpr uint8_t CHARGE_FAULT_NORMAL
constexpr uint8_t BOOST_FAULT
bool isChargeTimerFault(uint8_t fault)
uint8_t getNtcFault(uint8_t fault)
bool isBatteryFault(uint8_t fault)
constexpr uint8_t CHARGE_FAULT_MASK
constexpr uint8_t BATTERY_FAULT
constexpr uint8_t WATCHDOG_TIMEOUT
bool isChargeThermalFault(uint8_t fault)
bool isBoostFault(uint8_t fault)
bool isWatchdogTimeout(uint8_t fault)
constexpr uint8_t NTC_FAULT_MASK
constexpr uint8_t CHARGE_FAULT_INPUT
bool isChargeFault(uint8_t fault)
constexpr uint8_t CHARGE_FAULT_THERMAL
uint8_t getChargeFaultType(uint8_t fault)