SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
SY6970Core.hpp
Go to the documentation of this file.
1
41#pragma once
42
43#include "../../../platform/comm/I2CDeviceWithHal.hpp"
44
45namespace SY6970Faults
46{
47constexpr uint8_t WATCHDOG_TIMEOUT = 0x80;
48constexpr uint8_t BOOST_FAULT = 0x40;
49constexpr uint8_t CHARGE_FAULT_MASK = 0x30; // Bits 5-4
50constexpr uint8_t CHARGE_FAULT_NORMAL = 0x00;
51constexpr uint8_t CHARGE_FAULT_INPUT = 0x10; // Bit 4: BUS OVP or VBAT<BUS<3.8V
52constexpr uint8_t CHARGE_FAULT_THERMAL = 0x20; // Bit 5: Thermal shutdown
53constexpr uint8_t CHARGE_FAULT_TIMER = 0x30; // Bits 5+4: Safety timer expiration
54constexpr uint8_t BATTERY_FAULT = 0x08;
55constexpr uint8_t NTC_FAULT_MASK = 0x07; // Bits 2-0
56
57inline bool isWatchdogTimeout(uint8_t fault)
58{
59 return (fault & WATCHDOG_TIMEOUT) != 0;
60}
61inline bool isBoostFault(uint8_t fault)
62{
63 return (fault & BOOST_FAULT) != 0;
64}
65inline bool isChargeFault(uint8_t fault)
66{
67 return (fault & CHARGE_FAULT_MASK) != 0;
68}
69inline uint8_t getChargeFaultType(uint8_t fault)
70{
71 return fault & CHARGE_FAULT_MASK;
72}
73inline bool isChargeInputFault(uint8_t fault)
74{
75 return (fault & CHARGE_FAULT_MASK) == CHARGE_FAULT_INPUT;
76}
77inline bool isChargeThermalFault(uint8_t fault)
78{
79 return (fault & CHARGE_FAULT_MASK) == CHARGE_FAULT_THERMAL;
80}
81inline bool isChargeTimerFault(uint8_t fault)
82{
83 return (fault & CHARGE_FAULT_MASK) == CHARGE_FAULT_TIMER;
84}
85inline bool isBatteryFault(uint8_t fault)
86{
87 return (fault & BATTERY_FAULT) != 0;
88}
89inline uint8_t getNtcFault(uint8_t fault)
90{
91 return fault & NTC_FAULT_MASK;
92}
93}
94
96{
97public:
98 SY6970Core() = default;
99
100 ~SY6970Core() = default;
101
108 void end();
109
121 bool isValid() const;
122
131 uint8_t getDeviceRevision() const;
132
140 void reset();
141
152 bool isVbusPresent();
153
170 uint8_t getBusStatus();
171
183 uint8_t getChargeStatus();
184
193 bool isPowerGood();
194
205 bool isCharging();
206
215 bool isChargeDone();
216
225 bool isOtg();
226
243 bool getFaultStatus(uint8_t &fault);
244
245private:
246 bool initImpl(uint8_t param) override;
247};
uint8_t getBusStatus()
Get USB port type status.
~SY6970Core()=default
bool isOtg()
Check if in OTG (boost) mode.
void reset()
Reset device to default state.
void end()
Deinitialize and release resources.
bool isChargeDone()
Check if charging is complete.
bool isCharging()
Check if actively charging.
uint8_t getChargeStatus()
Get charging status.
uint8_t getDeviceRevision() const
Get device revision.
bool isVbusPresent()
Check if VBUS (USB power) is present.
SY6970Core()=default
bool isPowerGood()
Check if power is good.
bool isValid() const
Check if device is valid/present.
bool getFaultStatus(uint8_t &fault)
Get fault status.
bool isChargeThermalFault(uint8_t fault)
constexpr uint8_t CHARGE_FAULT_NORMAL
bool isChargeFault(uint8_t fault)
constexpr uint8_t CHARGE_FAULT_INPUT
constexpr uint8_t CHARGE_FAULT_MASK
uint8_t getNtcFault(uint8_t fault)
uint8_t getChargeFaultType(uint8_t fault)
constexpr uint8_t BATTERY_FAULT
constexpr uint8_t CHARGE_FAULT_THERMAL
bool isBoostFault(uint8_t fault)
constexpr uint8_t CHARGE_FAULT_TIMER
bool isBatteryFault(uint8_t fault)
bool isWatchdogTimeout(uint8_t fault)
bool isChargeTimerFault(uint8_t fault)
constexpr uint8_t WATCHDOG_TIMEOUT
bool isChargeInputFault(uint8_t fault)
constexpr uint8_t BOOST_FAULT
constexpr uint8_t NTC_FAULT_MASK