SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
gauge/ti/GaugeBQ27220.hpp
Go to the documentation of this file.
1
29#pragma once
30
31#include "../../SensorBuildOpt.h"
32#if !SENSORLIB_EXCLUDE_GAUGE_BQ27220
33
35#include "../GaugeBase.hpp"
36
37// BQ27220 Unique device address
38static constexpr uint8_t BQ27220_SLAVE_ADDRESS = (0x55);
39
40// *INDENT-OFF*
42private:
43 bool isConfigUpdateMode;
44 bool isBtpThresholdExceeded;
45 bool isCapacityAccumulationThrottled;
46 bool isInitializationComplete;
47 bool isDischargeCycleCompliant;
48 bool isBatteryVoltageBelowEdv2;
49 uint8_t securityAccessLevel;
50 bool isCalibrationModeEnabled;
51public:
52 FuelGaugeOperationStatus(uint16_t value) {
53 // parse CFGUPDATE bit
54 isConfigUpdateMode = (value & 0x0400) != 0;
55 // parse BTPINT bit
56 isBtpThresholdExceeded = (value & 0x80) != 0;
57 // parse SMTH bit
58 isCapacityAccumulationThrottled = (value & 0x40) != 0;
59 // parse INITCOMP bit
60 isInitializationComplete = (value & 0x20) != 0;
61 // parse VDQ bit
62 isDischargeCycleCompliant = (value & 0x10) != 0;
63 // parse EDV2 bit
64 isBatteryVoltageBelowEdv2 = (value & 0x08) != 0;
65 // parse SEC bit
66 securityAccessLevel = (value >> 1) & 0x03;
67 // parse CALMD bit
68 isCalibrationModeEnabled = (value & 0x01) != 0;
69 }
70
71 // Gets whether the fuel gauge is in configuration update mode
72 bool getIsConfigUpdateMode() const {
73 return isConfigUpdateMode;
74 }
75
76 // Get whether the BTP threshold has been exceeded
78 return isBtpThresholdExceeded;
79 }
80
81 // Gets whether the remaining capacity accumulation is throttled
83 return isCapacityAccumulationThrottled;
84 }
85
86 // Get whether the fuel gauge initialization is completed
88 return isInitializationComplete;
89 }
90
91 // Get whether the current discharge cycle complies with FCC update requirements
93 return isDischargeCycleCompliant;
94 }
95
96 // Get whether the battery voltage is lower than the EDV2 threshold
98 return isBatteryVoltageBelowEdv2;
99 }
100
101 // Get the current security access level
102 uint8_t getSecurityAccessLevel() const {
103 return securityAccessLevel;
104 }
105
106 // Gets whether calibration mode is enabled
108 return isCalibrationModeEnabled;
109 }
110};
111
113protected:
114 struct {
115 //* Full discharge detected. This flag is set and cleared based on the SOC
116 //* Flag Config B option selected.
118 //* OCV measurement update is complete. True when set
120 //* Status bit indicating that an OCV read failed due to current.
121 //* This bit can only be set if a battery is present after receiving an OCV_CMD(). True when set
123 //* The device operates in SLEEP mode when set.
124 //* This bit will be temporarily cleared during AD measurements in SLEEP mode.
126 //* Over-temperature is detected during charging. If Operation Config B [INT_OT] bit = 1,
127 //* the SOC_INT pin toggles once when the [OTC] bit is set.
129 //* Over-temperature detected during discharge condition. True when set. If Operation Config B [INT_OT] bit = 1,
130 //* the SOC_INT pin toggles once when the [OTD] bit is set.
132 //* Full charge detected. This flag is set and cleared based on the SOC Flag Config A and SOC Flag Config B options selected.
134 //* Charge Inhibit: If set, indicates that charging should not begin because the Temperature() is outside the range
135 //* [Charge Inhibit Temp Low, Charge Inhibit Temp High]. True when set
137 //* Termination of charging alarm. This flag is set and cleared based on the selected SOC Flag Config A option.
139 //* A good OCV measurement was made. True when set
141 //* Detects inserted battery. True when set.
143 //* Battery presence detected. True when set.
145 //* Termination discharge alarm. This flag is set and cleared according to the selected SOC Flag Config A option.
147 //* System shutdown bit indicating that the system should be shut down. True when set. If set, the SOC_INT pin toggles once.
149 //* When set, the device is in DISCHARGE mode; when cleared, the device is in CHARGING or RELAXATION mode.
152public:
158 BatteryStatus(uint16_t bitmaps){
159 uint8_t hsb = (bitmaps >> 8) & 0xFF;
160 uint8_t lsb = bitmaps & 0xFF;
161 status.fullDischargeDetected = (hsb & sensorlib::_bv(7)) != 0;
162 status.ocvMeasurementUpdateComplete = (hsb & sensorlib::_bv(6)) != 0;
163 status.ocvReadFailedDueToCurrent = (hsb & sensorlib::_bv(5)) != 0;
164 status.inSleepMode = (hsb & sensorlib::_bv(4)) != 0;
165 status.overTemperatureDuringCharging = (hsb & sensorlib::_bv(3)) != 0;
166 status.overTemperatureDuringDischarge = (hsb & sensorlib::_bv(2)) != 0;
167 status.fullChargeDetected = (hsb & sensorlib::_bv(1)) != 0;
168 status.chargeInhibited = (hsb & sensorlib::_bv(0)) != 0;
169
170 // status.RSVD = (lsb & (1 << 7))!= 0;
171 status.chargingTerminationAlarm = (lsb & sensorlib::_bv(6)) != 0;
172 status.goodOcvMeasurement = (lsb & sensorlib::_bv(5)) != 0;
173 status.batteryInserted = (lsb & sensorlib::_bv(4)) != 0;
174 status.batteryPresent = (lsb & sensorlib::_bv(3)) != 0;
175 status.dischargeTerminationAlarm = (lsb & sensorlib::_bv(2)) != 0;
176 status.systemShutdownRequired = (lsb & sensorlib::_bv(1)) != 0;
177 status.inDischargeMode = (lsb & sensorlib::_bv(0)) != 0;
178 };
179
186 return status.fullDischargeDetected;
187 }
188
194 return status.ocvMeasurementUpdateComplete;
195 }
196
203 return status.ocvReadFailedDueToCurrent;
204 }
205
211 bool isInSleepMode() const {
212 return status.inSleepMode;
213 }
214
221 return status.overTemperatureDuringCharging;
222 }
223
230 return status.overTemperatureDuringDischarge;
231 }
232
238 bool isFullChargeDetected() const {
239 return status.fullChargeDetected;
240 }
241
247 bool isChargeInhibited() const {
248 return status.chargeInhibited;
249 }
250
257 return status.chargingTerminationAlarm;
258 }
259
264 bool isGoodOcvMeasurement() const {
265 return status.goodOcvMeasurement;
266 }
267
272 bool isBatteryInserted() const {
273 return status.batteryInserted;
274 }
275
280 bool isBatteryPresent() const {
281 return status.batteryPresent;
282 }
283
290 return status.dischargeTerminationAlarm;
291 }
292
299 return status.systemShutdownRequired;
300 }
301
307 bool isInDischargeMode() const {
308 return status.inDischargeMode;
309 }
310};
311
313private:
314 //* OperationConfig *//
315 uint16_t rawA;
316 // High - byte bits
317 bool temps; // When set to 1, select an external thermistor for Temperature().
318 bool reserved1; // Reserved. Do not use.
319 bool batg_pol; // BATT_GD pin polarity. Low level is 0, high level is 1.
320 bool batg_en; // Enable BATT_GD function.
321 bool reserved2; // Reserved.
322 bool sleep; // If the working conditions allow, the fuel gauge can enter the SLEEP state. Set to true when set.
323 bool slpwakechg; // When Current > Sleep Current but not enough to trigger an event, accumulate the estimated charge from the sleep - wake state. Set to true when enabled.
324 bool wrtemp; // Write temperature. The temperature should be written by the host and used for fuel gauge monitoring. When not using an external thermistor and not using the internal temperature sensor, set it to false.
325
326 // Low - byte bits
327 bool bienable; // When enabled, the fuel gauge can detect battery insertion. If disabled, the fuel gauge will rely on the host to use the BAT_INSERT or BAT_REMOVE command to set and clear the BatteryStatus(BATTPRES) bit. Set to true when set.
328 bool reserved3; // Reserved. Do not use.
329 bool bl_pup_en; // Battery insertion pin pull - up enable.
330 int pfc_cfg; // Pin Function Code (PFC) mode selection: PFC 0, 1, 2, or 3, selected by 00, 01, 10, or 11 respectively.
331 bool wake_en; // Wake - up enable.
332 int wk_th1; // Wake - up threshold 1.
333 int wk_th0; // Wake - up threshold 0.
334
335 //* OperationConfigB *//
336 uint16_t rawB;
337 // High - byte bits
338 // Reserved.
339 // Reserved.
340 // Reserved.
341 // Reserved.
342 bool defaultSeal; // Sealed during POR. 0 = No seal after POR (default setting), 1 = Seal after POR.
343 bool nonRemovable; // Non - removable.
344 // Reserved.
345 // Reserved.
346
347 // Low - byte bits
348 bool intBrem; // When the battery is removed and [BIEnable] = 1, GPIOUT pulses for 1ms. Enable when set.
349 bool intBatL; // Enable GPIOUT pin toggling when TDA is set.
350 bool intState; // Enable SOC_INT function to pulse the GPIOUT pin when the current direction changes.
351 bool intOcv; // Enable SOC_INT function to generate pulses based on the OCV command.
352 // Reserved.
353 bool intOt; // Enable SOC_INT function to generate pulses based on over - temperature conditions and combined with BatteryStatus()[OTC or OTD].
354 bool intPol; // GPIOUT pin polarity control. Low level is 0, high level is 1.
355 bool intFocv; // If this bit is set, GPIOUT will pulse during the first measurement.
356
357public:
363 OperationConfig(uint32_t registerValue) {
364
365 //* OperationConfig A *//
366 rawA = (registerValue >> 16);
367 // Parse high - byte bits
368 temps = (rawA >> 7) & 1;
369 reserved1 = (rawA >> 6) & 1;
370 batg_pol = (rawA >> 5) & 1;
371 batg_en = (rawA >> 4) & 1;
372 reserved2 = (rawA >> 3) & 1;
373 sleep = (rawA >> 2) & 1;
374 slpwakechg = (rawA >> 1) & 1;
375 wrtemp = rawA & 1;
376
377 // Parse low - byte bits
378 bienable = (rawA >> 15) & 1;
379 reserved3 = (rawA >> 14) & 1;
380 bl_pup_en = (rawA >> 13) & 1;
381 pfc_cfg = (rawA >> 11) & 3;
382 wake_en = (rawA >> 10) & 1;
383 wk_th1 = (rawA >> 9) & 1;
384 wk_th0 = (rawA >> 8) & 1;
385
386 //* OperationConfig B *//
387 rawB = (registerValue & 0xFFFF);
388
389 // Parse high - byte bits
390 defaultSeal = (rawB >> 3) & 1;
391 nonRemovable = (rawB >> 2) & 1;
392
393 // Parse low - byte bits
394 intBrem = (rawB >> 15) & 1;
395 intBatL = (rawB >> 14) & 1;
396 intState = (rawB >> 13) & 1;
397 intOcv = (rawB >> 12) & 1;
398 intOt = (rawB >> 10) & 1;
399 intPol = (rawB >> 9) & 1;
400 intFocv = (rawB >> 8) & 1;
401 }
402
407 uint16_t getConfigA() const {
408 return rawA;
409 }
410
415 uint16_t getConfigB() const {
416 return rawB;
417 }
418
423 bool isTempsSet() const {
424 return temps;
425 }
426
431 bool isBatgPolHigh() const {
432 return batg_pol;
433 }
434
439 bool isBatgEnEnabled() const {
440 return batg_en;
441 }
442
447 bool canEnterSleep() const {
448 return sleep;
449 }
450
455 bool isSlpwakechgEnabled() const {
456 return slpwakechg;
457 }
458
463 bool isWrtempEnabled() const {
464 return wrtemp;
465 }
466
471 bool isBienableEnabled() const {
472 return bienable;
473 }
474
479 bool isBlPupEnEnabled() const {
480 return bl_pup_en;
481 }
482
487 int getPfcCfg() const {
488 return pfc_cfg;
489 }
490
495 bool isWakeEnEnabled() const {
496 return wake_en;
497 }
498
503 int getWkTh1() const {
504 return wk_th1;
505 }
506
511 int getWkTh0() const {
512 return wk_th0;
513 }
514
515 //* OperationConfig B *//
516
521 bool isDefaultSealEnabled() const {
522 return defaultSeal;
523 }
524
529 bool isNonRemovableSet() const {
530 return nonRemovable;
531 }
532
537 bool isIntBremEnabled() const {
538 return intBrem;
539 }
540
545 bool isIntBatLEnabled() const {
546 return intBatL;
547 }
548
553 bool isIntStateEnabled() const {
554 return intState;
555 }
556
561 bool isIntOcvEnabled() const {
562 return intOcv;
563 }
564
569 bool isIntOtEnabled() const {
570 return intOt;
571 }
572
577 bool isIntPolHigh() const {
578 return intPol;
579 }
580
585 bool isIntFocvEnabled() const {
586 return intFocv;
587 }
588};
589// *INDENT-ON*
590
592{
593private:
594 typedef struct {
595 uint16_t AtRate; // mA - REG02 - 03
596 uint16_t AtRateTimeToEmpty; // Minute - REG04 - 05
597 uint16_t Temperature; // 0.1*K - REG06 - 07
598 uint16_t Voltage; // mV - REG08 - 09
599 uint16_t BatteryStatus; // bitmaps - REG0A - 0B
600 int16_t Current; // mA - REG0C - 0D
601
602 uint16_t RESERVE1; // Rse - REG0E - 0F
603
604 uint16_t RemainingCapacity; // mAh - REG10 - 11
605 uint16_t FullChargeCapacity; // mAh - REG12 - 13
606
607 uint16_t RESERVE2; // Resv - REG14 - 15
608
609 uint16_t TimeToEmpty; // Minute - REG16 - 17
610 uint16_t TimeToFull; // Minute - REG18 - 19
611 int16_t StandbyCurrent; // mA - REG1A - 1B
612 uint16_t StandbyTimeToEmpty; // Minute - REG1C - 1D
613 int16_t MaxLoadCurrent; // mA - REG1E - 1F
614 uint16_t MaxLoadTimeToEmpty; // Minute - REG20 - 21
615 uint16_t RawCoulombCount; // Count - REG22 - 23
616 int16_t AveragePower; // mW - REG24 - 25
617
618 uint16_t RESERVE3; // Resv - REG26 - 27
619
620 uint16_t InternalTemperature; // 0.1*K - REG28 - 29
621 uint16_t CycleCount; // Count - REG2A - 2B
622 uint16_t StateOfCharge; // % - REG2C - 2D
623 uint16_t StateOfHealth; // % - REG2E - 2F
624 uint16_t ChargingVoltage; // mV - REG30 - 31 - 65535 request max voltage
625 uint16_t ChargingCurrent; // mA - REG32 - 33 - 65535 request max current
626 uint16_t BTPDischargeSet; // Control - REG34 - 35
627 uint16_t BTPChargeSet; // Control - REG36 - 37
628
629 uint16_t OperationStatus; // Status - REG3A - 3B
630 uint16_t DesignCapacity; // mAh - REG3C - 3D
631 } BatteryData;
632
633public:
634
640
641 GaugeBQ27220() : accessKey(0xFFFFFFFF) {}
642
643 ~GaugeBQ27220() = default;
644
645#if defined(ARDUINO)
646 bool begin(TwoWire &wire, int sda = -1, int scl = -1)
647 {
648 return I2CDeviceWithHal::begin(wire, BQ27220_SLAVE_ADDRESS, sda, scl);
649 }
650
651#elif defined(ESP_PLATFORM)
652
653#if defined(SENSORLIB_USE_I2C_LEGACY)
654 bool begin(i2c_port_t port_num, int sda = -1, int scl = -1)
655 {
656 return I2CDeviceWithHal::begin(port_num, BQ27220_SLAVE_ADDRESS, sda, scl);
657 }
658#else
659 bool begin(i2c_master_bus_handle_t handle)
660 {
661 return I2CDeviceWithHal::begin(handle, BQ27220_SLAVE_ADDRESS);
662 }
663#endif //ESP_PLATFORM
664#endif //ARDUINO
665
668 {
669 return I2CDeviceWithHal::begin(callback, hal_callback, BQ27220_SLAVE_ADDRESS);
670 }
671
672
679 bool refresh() override
680 {
681 uint8_t buffer[REGISTER_COUNT];
682 if (readRegBuff(START_REGISTER, buffer, REGISTER_COUNT) < 0) {
683 return false;
684 }
685 uint8_t *ptr = (uint8_t *)&data;
686 for (int i = 0; i < REGISTER_COUNT; i += 2) {
687 uint16_t value = (buffer[i + 1] << 8) | buffer[i];
688 *(uint16_t *)ptr = value;
689 ptr += 2;
690 }
691
692 if (readRegBuff(0x3A, buffer, 4) < 0) {
693 return false;
694 }
695 data.OperationStatus = (buffer[1] << 8) | buffer[0];
696 data.DesignCapacity = (buffer[3] << 8) | buffer[2];
697 return true;
698 }
699
700 // *INDENT-OFF*
707 uint16_t getAtRate() const { return data.AtRate; }
708
715 uint16_t getAtRateTimeToEmpty() const { return data.AtRateTimeToEmpty; }
716
723 float getTemperature() override { return (data.Temperature * 0.1f) - 273.15f; }
724
731 uint16_t getVoltage() override { return data.Voltage; }
732
739 BatteryStatus getBatteryStatus() const { return BatteryStatus(data.BatteryStatus); }
740
747 float getCurrent() override { return data.Current; }
748
753 bool isCharging() override { return data.Current > 0; }
754
759 bool isDischarging() override { return data.Current < 0; }
760
766 uint16_t getRemainingCapacity() const { return data.RemainingCapacity; }
767
773 uint16_t getFullChargeCapacity() const { return data.FullChargeCapacity; }
774
781 uint16_t getTimeToEmpty() override { return data.TimeToEmpty; }
782
789 uint16_t getTimeToFull() override { return data.TimeToFull; }
790
796 int16_t getStandbyCurrent() const { return data.StandbyCurrent; }
797
803 uint16_t getStandbyTimeToEmpty() const { return data.StandbyTimeToEmpty; }
804
810 int16_t getMaxLoadCurrent() const { return data.MaxLoadCurrent; }
811
817 uint16_t getMaxLoadTimeToEmpty() const { return data.MaxLoadTimeToEmpty; }
818
824 uint16_t getRawCoulombCount() const { return data.RawCoulombCount; }
825
833 int16_t getAveragePower() const { return data.AveragePower; }
834
841 float getInternalTemperature() const { return (data.InternalTemperature * 0.1f) - 273.15f; }
842
849 uint16_t getCycleCount() const { return data.CycleCount; }
850
857 uint16_t getStateOfCharge() override { return data.StateOfCharge; }
858
865 uint16_t getStateOfHealth() const { return data.StateOfHealth; }
866
874 uint16_t getRequestChargingVoltage() const { return data.ChargingVoltage; }
875
883 uint16_t getRequestChargingCurrent() const { return data.ChargingCurrent; }
884
891 uint16_t getBTPDischargeSet() const { return data.BTPDischargeSet; }
892
899 uint16_t getBTPChargeSet() const { return data.BTPChargeSet; }
900
908
916 uint16_t getDesignCapacity() const { return data.DesignCapacity; }
917
918 // *INDENT-ON*
919
932 bool setNewCapacity(uint16_t newDesignCapacity, uint16_t newFullChargeCapacity)
933 {
934 return performConfigUpdate<bool>([this, newDesignCapacity, newFullChargeCapacity]() {
935 // Set the design capacity
936 if (!setCapacity(newDesignCapacity, sensorlib::_lowByte(BQ27220_ROM_DESIGN_CAPACITY),
938 SENSORLIB_LOG_E("Failed to set design capacity!");
939 return false;
940 }
941 hal->delay(10);
942
943 // Set full charge capacity
944 if (!setCapacity(newFullChargeCapacity, sensorlib::_lowByte(BQ27220_ROM_FULL_CHARGE_CAPACITY),
946 SENSORLIB_LOG_E("Failed to set full charge capacity!");
947 return false;
948 }
949 hal->delay(10);
950
951 return true;
952 });
953 }
954
965 {
966 return performConfigUpdate<OperationConfig>([this]() {
968 hal->delay(10);
970 hal->delay(10);
971 uint8_t buffer[4];
972 readRegBuff(0x40, buffer, 4);
973 uint16_t bitmapsA = (buffer[0] << 8) | buffer[1];
974 uint16_t bitmapsB = (buffer[2] << 8) | buffer[3];
975 OperationConfig value((bitmapsA << 16) | bitmapsB);
976 return value;
977 });
978 }
979
984 uint16_t getChipID() override
985 {
986 uint8_t buffer[2] = {0};
987 if (sendSubCommand(BQ27220_SUB_CMD_DEVICE_NUMBER, true) < 0) {
988 return 0;
989 }
990 if (this->getMACData(buffer, arraySize(buffer)) < 0) {
991 return -1;
992 }
993 return static_cast<uint16_t>((buffer[1] << 8) | buffer[0]);
994 }
995
1006 {
1007 uint8_t buffer[2];
1008 constexpr uint8_t value = 0x00;
1010 if (this->getMACData(buffer, arraySize(buffer)) < 0) {
1011 return -1;
1012 }
1013 return static_cast<uint16_t>((buffer[1] << 8) | buffer[0]);
1014 }
1015
1016
1026 {
1027 uint8_t buffer[4];
1028 if (sendSubCommand(BQ27220_SUB_CMD_FW_VERSION, true) < 0) {
1029 return -1;
1030 }
1031 if (this->getMACData(buffer, arraySize(buffer)) < 0) {
1032 return -1;
1033 }
1034 return (buffer[3] << 24) | (buffer[2] << 16) | (buffer[1] << 8) | buffer[0];
1035 }
1036
1041 void reset() override
1042 {
1043 sendSubCommand(BQ27220_SUB_CMD_RESET);
1044 }
1045
1052 void setAccessKey(uint32_t key)
1053 {
1054 accessKey = key;
1055 }
1056
1057private:
1058 FuelGaugeOperationStatus getOperationStatusNow()
1059 {
1061 }
1062
1063 // This read-write block will return the result data for the currently active subcommand.
1064 int getMACData(uint8_t *buffer, uint8_t request_len)
1065 {
1066 const uint8_t max_size = BQ27220_REG_MAC_BUFFER_END - BQ27220_REG_MAC_BUFFER_START + 1;
1067 if (request_len > max_size) {
1068 return -1;
1069 }
1070 if (!buffer) {
1071 return -1;
1072 }
1073 uint8_t reg = BQ27220_REG_MAC_BUFFER_START;
1074 return writeThenRead(&reg, 1, buffer, request_len);
1075 }
1076
1077 // This read and write function returns the checksum of the current subcommand and data block.
1078 // Writing to this register provides the checksum required to execute a subcommand that requires data.
1079 uint16_t getMACDataSum()
1080 {
1081 uint8_t sum = 0x00;
1082 if (readRegBuff(BQ27220_REG_MAC_DATA_SUM, &sum, 1) < 0) {
1083 return 0;
1084 }
1085 return sum;
1086 }
1087
1088 // This read and write function returns the number of MACData()
1089 // bytes contained in MACDataSum() as part of the response.
1090 uint16_t getMACDataLen()
1091 {
1092 uint8_t length = 0x00;
1093 if (readRegBuff(BQ27220_REG_MAC_DATA_LEN, &length, 1) < 0) {
1094 return 0;
1095 }
1096 return length;
1097 }
1098
1099 // Subcommands
1100 int sendSubCommand(uint16_t subCmd, bool waitConfirm = false)
1101 {
1102 uint8_t buffer[3];
1103 buffer[0] = 0x00;
1104 buffer[1] = sensorlib::_lowByte(subCmd);
1105 buffer[2] = sensorlib::_highByte(subCmd);
1106 if (writeBuff(buffer, arraySize(buffer)) < 0) {
1107 return -1;
1108 }
1109 if (!waitConfirm) {
1110 hal->delay(10);
1111 return 0;
1112 }
1113 constexpr uint8_t statusReg = 0x00;
1114 int waitCount = 20;
1115 hal->delay(10);
1116 while (waitCount--) {
1117 writeThenRead(&statusReg, 1, buffer, 2);
1118 uint16_t *value = reinterpret_cast<uint16_t *>(buffer);
1119 if (*value == 0xFFA5) {
1120 return 0;
1121 }
1122 hal->delay(100);
1123 }
1124 SENSORLIB_LOG_E("Subcommand failed!");
1125 return -1;
1126 }
1127
1128 // Unlock Safe Mode
1129 int unsealDevice()
1130 {
1131 uint8_t cmd1[] = {0x00, 0x14, 0x04};
1132 if (writeBuff(cmd1, arraySize(cmd1)) < 0) {
1133 return -1;
1134 }
1135 hal->delay(10);
1136 uint8_t cmd2[] = {0x00, 0x72, 0x36};
1137 if (writeBuff(cmd2, arraySize(cmd2)) < 0) {
1138 return -1;
1139 }
1140 hal->delay(10);
1141 return 0;
1142 }
1143
1144 // Full access key, 0xFFFFFFFF if not set
1145 int unsealFullAccess()
1146 {
1147 uint8_t buffer[3];
1148 buffer[0] = 0x00;
1149 buffer[1] = sensorlib::_lowByte((accessKey >> 24));
1150 buffer[2] = sensorlib::_lowByte((accessKey >> 16));
1151 if (writeBuff(buffer, arraySize(buffer)) < 0) {
1152 return -1;
1153 }
1154 hal->delay(10);
1155 buffer[1] = sensorlib::_lowByte((accessKey >> 8));
1156 buffer[2] = sensorlib::_lowByte((accessKey));
1157 if (writeBuff(buffer, arraySize(buffer)) < 0) {
1158 return -1;
1159 }
1160 hal->delay(10);
1161 return 0;
1162 }
1163
1164 int exitSealMode()
1165 {
1166 return sendSubCommand(BQ27220_SUB_CMD_SEALED);
1167 }
1168
1169 template<typename ResultType, typename Func>
1170 ResultType performConfigUpdate(Func specificOperation)
1171 {
1172 bool isSealed = false;
1173
1174 // Check access settings
1175 FuelGaugeOperationStatus status = getOperationStatusNow();
1176 uint8_t currAccesslevel = status.getSecurityAccessLevel();
1177 if (currAccesslevel == SEALED_ACCESS) {
1178 isSealed = true;
1179 unsealDevice();
1180 }
1181 if (currAccesslevel != FULL_ACCESS) {
1182 unsealFullAccess();
1183 }
1184
1185 // Send ENTER_CFG_UPDATE command (0x0090)
1186 sendSubCommand(BQ27220_SUB_CMD_ENTER_CFG_UPDATE);
1187
1188 // Confirm CFUPDATE mode by polling the OperationStatus() register until Bit 2 is set.
1189 bool isConfigUpdate = false;
1190 uint32_t timeout = hal->millis() + 1500UL;
1191 while (timeout > hal->millis()) {
1192 status = getOperationStatusNow();
1193 if (status.getIsConfigUpdateMode()) {
1194 isConfigUpdate = true;
1195 break;
1196 }
1197 hal->delay(100);
1198 }
1199 if (!isConfigUpdate) {
1200 SENSORLIB_LOG_E("The update mode has timed out. It may also be that the access key for full permissions is invalid!");
1201 if (std::is_same<ResultType, bool>::value) {
1202 return false;
1203 } else if (std::is_same<ResultType, OperationConfig>::value) {
1204 return { 0x00 };
1205 }
1206 }
1207
1208 ResultType result = specificOperation();
1209
1210 // Exit CFUPDATE mode by sending the EXIT_CFG_UPDATE_REINIT (0x0091) or EXIT_CFG_UPDATE (0x0092) command
1212 hal->delay(10);
1213
1214 // Confirm that CFUPDATE mode has been exited by polling the OperationStatus() register until bit 2 is cleared
1215 timeout = hal->millis() + 3000UL;
1216 while (timeout > hal->millis()) {
1217 status = getOperationStatusNow();
1218 if (!status.getIsConfigUpdateMode()) {
1219 timeout = hal->millis() + 1000;
1220 break;
1221 }
1222 hal->delay(100);
1223 }
1224 if (hal->millis() > timeout) {
1225 SENSORLIB_LOG_E("Timed out waiting to exit update mode.");
1226 if (std::is_same<ResultType, bool>::value) {
1227 return false;
1228 } else if (std::is_same<ResultType, OperationConfig>::value) {
1229 return { 0x00 };
1230 }
1231 }
1232
1233 // If the device was previously in SEALED state, return to SEALED mode by sending the Control(0x0030) subcommand
1234 if (isSealed) {
1235 SENSORLIB_LOG_D("Restore Safe Mode!");
1236 exitSealMode();
1237 }
1238
1239 return result;
1240 }
1241
1242
1243 bool setCapacity(uint16_t newCapacity, uint8_t msbAccessValue, uint8_t lsbAccessValue)
1244 {
1245 constexpr uint8_t fixedDataLength = 0x06;
1246
1247 // Write to access the MSB of Capacity
1248 writeReg(BQ27220_REG_ROM_START, msbAccessValue);
1249 hal->delay(10);
1250
1251 // Write to access the LSB of Capacity
1252 writeReg(BQ27220_REG_ROM_START + 1, lsbAccessValue);
1253 hal->delay(10);
1254
1255 // Write two Capacity bytes starting from 0x40
1256 uint8_t newCapacityMsb = sensorlib::_highByte(newCapacity);
1257 uint8_t newCapacityLsb = sensorlib::_lowByte(newCapacity);
1258 uint8_t capacityRaw[] = {newCapacityMsb, newCapacityLsb};
1260
1261 // Calculate new checksum
1262 uint8_t newChksum = 0xFF - ((msbAccessValue + lsbAccessValue + newCapacityMsb + newCapacityLsb) & 0xFF);
1263
1264 // Write new checksum (0x60)
1266
1267 // Write the block length
1268 writeReg(BQ27220_REG_MAC_DATA_LEN, fixedDataLength);
1269
1270 return true;
1271 }
1272
1273 int getHalfWord(uint8_t reg)
1274 {
1275 uint8_t buffer[2] = {0};
1276 if (writeThenRead(&reg, 1, buffer, arraySize(buffer)) < 0) {
1277 SENSORLIB_LOG_E("Read register %" PRIu32 " failed!", reg);
1278 return UINT16_MAX;
1279 }
1280 return (buffer[1] << 8) | buffer[0];
1281 }
1282
1283 bool initImpl(uint8_t param) override
1284 {
1285 int chipID = getChipID();
1286 if (chipID != BQ27220_CHIP_ID) {
1287 SENSORLIB_LOG_E("Chip id not match : %" PRIu32, chipID);
1288 return false;
1289 }
1290
1291 int sw = getFirmwareVersion();
1292 if (sw < 0) {
1293 SENSORLIB_LOG_E("Software version error!");
1294 } else {
1295 SENSORLIB_LOG_D("Software version 0x%" PRIu32, sw);
1296 }
1297 hal->delay(100);
1298 int hw = getHardwareVersion();
1299 if (hw < 0) {
1300 SENSORLIB_LOG_E("Hardware version error!");
1301 } else {
1302 SENSORLIB_LOG_D("Hardware version 0x%" PRIu32, hw);
1303 }
1304
1305 return true;
1306 }
1307
1308protected:
1309 uint32_t accessKey;
1310 BatteryData data;
1311 const uint8_t START_REGISTER = 0x02;
1312 const uint8_t REGISTER_COUNT = 54;
1313
1314 //* Sub command
1315 static constexpr uint16_t BQ27220_SUB_CMD_CTRL_STATUS = (0x0000);
1316 static constexpr uint16_t BQ27220_SUB_CMD_DEVICE_NUMBER = (0x0001);
1317 static constexpr uint16_t BQ27220_SUB_CMD_FW_VERSION = (0x0002);
1318 static constexpr uint16_t BQ27220_SUB_CMD_HW_VERSION = (0x0003);
1319 static constexpr uint16_t BQ27220_SUB_CMD_BOARD_OFFSET = (0x0009);
1320 static constexpr uint16_t BQ27220_SUB_CMD_CC_OFFSET = (0x000A);
1321 static constexpr uint16_t BQ27220_SUB_CMD_CC_OFFSET_SAVE = (0x000B);
1322 static constexpr uint16_t BQ27220_SUB_CMD_OCV_CMD = (0x000C);
1323 static constexpr uint16_t BQ27220_SUB_CMD_BAT_INSERT = (0x000D);
1324 static constexpr uint16_t BQ27220_SUB_CMD_BAT_REMOVE = (0x000E);
1325 static constexpr uint16_t BQ27220_SUB_CMD_SET_SNOOZE = (0x0013);
1326 static constexpr uint16_t BQ27220_SUB_CMD_CLEAR_SNOOZE = (0x0014);
1327 static constexpr uint16_t BQ27220_SUB_CMD_SET_PROFILE_1 = (0x0015);
1328 static constexpr uint16_t BQ27220_SUB_CMD_SET_PROFILE_2 = (0x0016);
1329 static constexpr uint16_t BQ27220_SUB_CMD_SET_PROFILE_3 = (0x0017);
1330 static constexpr uint16_t BQ27220_SUB_CMD_SET_PROFILE_4 = (0x0018);
1331 static constexpr uint16_t BQ27220_SUB_CMD_SET_PROFILE_5 = (0x0019);
1332 static constexpr uint16_t BQ27220_SUB_CMD_SET_PROFILE_6 = (0x001A);
1333 static constexpr uint16_t BQ27220_SUB_CMD_CAL_TOGGLE = (0x002D);
1334 static constexpr uint16_t BQ27220_SUB_CMD_SEALED = (0x0030);
1335 static constexpr uint16_t BQ27220_SUB_CMD_RESET = (0x0041);
1336 static constexpr uint16_t BQ27220_SUB_CMD_EXIT_CAL = (0x0080);
1337 static constexpr uint16_t BQ27220_SUB_CMD_ENTER_CAL = (0x0081);
1338 static constexpr uint16_t BQ27220_SUB_CMD_ENTER_CFG_UPDATE = (0x0090);
1339 static constexpr uint16_t BQ27220_SUB_CMD_EXIT_CFG_UPDATE_REINIT = (0x0091);
1340 static constexpr uint16_t BQ27220_SUB_CMD_EXIT_CFG_UPDATE = (0x0092);
1341 static constexpr uint16_t BQ27220_SUB_CMD_RETURN_TO_ROM = (0x0F00);
1342
1343 //* Standard commands
1344 static constexpr uint8_t BQ27220_REG_STA_AT_RATE = (0x02);
1345 static constexpr uint8_t BQ27220_REG_STA_AT_RATE_TIME_TO_EMPTY = (0x04);
1346 static constexpr uint8_t BQ27220_REG_STA_NTC_TEMP = (0x06);
1347 static constexpr uint8_t BQ27220_REG_STA_BAT_VOLTAGE = (0x08);
1348 static constexpr uint8_t BQ27220_REG_STA_BAT_STATUS = (0x0A);
1349 static constexpr uint8_t BQ27220_REG_STA_CURRENT = (0x0C);
1350 static constexpr uint8_t BQ27220_REG_STA_REMAINING_CAPACITY = (0x10);
1351 static constexpr uint8_t BQ27220_REG_STA_FULL_CHARGE_CAPACITY = (0x12);
1352 static constexpr uint8_t BQ27220_REG_STA_TIME_TO_EMPTY = (0x16);
1353 static constexpr uint8_t BQ27220_REG_STA_TIME_TO_FULL = (0x18);
1354 static constexpr uint8_t BQ27220_REG_STA_STANDBY_CURRENT = (0x1A);
1355 static constexpr uint8_t BQ27220_REG_STA_STANDBY_TIME_TO_EMPTY = (0x1C);
1356 static constexpr uint8_t BQ27220_REG_STA_MAX_LOAD_CURRENT = (0x1E);
1357 static constexpr uint8_t BQ27220_REG_STA_MAX_LOAD_TO_EMPTY = (0x20);
1358 static constexpr uint8_t BQ27220_REG_STA_COULOMB_COUNT = (0x22);
1359 static constexpr uint8_t BQ27220_REG_STA_AVG_POWER = (0x24);
1360 static constexpr uint8_t BQ27220_REG_STA_INTER_TEMP = (0x28);
1361 static constexpr uint8_t BQ27220_REG_STA_CYCLE_COUNT = (0x2A);
1362 static constexpr uint8_t BQ27220_REG_STA_STATE_OF_CHARGE = (0x2C);
1363 static constexpr uint8_t BQ27220_REG_STA_STATE_OF_HEALTH = (0x2E);
1364 static constexpr uint8_t BQ27220_REG_STA_CHARGING_VOLTAGE = (0x30);
1365 static constexpr uint8_t BQ27220_REG_STA_CHARGING_CURRENT = (0x32);
1366 static constexpr uint8_t BQ27220_REG_STA_BTP_DISC_SET = (0x34);
1367 static constexpr uint8_t BQ27220_REG_STA_BTP_CHARGE_SET = (0x36);
1368 static constexpr uint8_t BQ27220_REG_STA_OPERATION_STATUS = (0x3A);
1369 static constexpr uint8_t BQ27220_REG_STA_DESIGN_CAPACITY = (0x3C);
1370 static constexpr uint8_t BQ27220_REG_STA_DESIGN_CAPACITY_MSB = (0x3E);
1371 static constexpr uint8_t BQ27220_REG_STA_DESIGN_CAPACITY_LSB = (0x3F);
1372 static constexpr uint8_t BQ27220_REG_MAC_BUFFER_START = (0x40);
1373 static constexpr uint8_t BQ27220_REG_MAC_BUFFER_END = (0x5F);
1374 static constexpr uint8_t BQ27220_REG_MAC_DATA_SUM = (0x60);
1375 static constexpr uint8_t BQ27220_REG_MAC_DATA_LEN = (0x61);
1376 static constexpr uint8_t BQ27220_REG_ANALOG_COUNT = (0x79);
1377 static constexpr uint8_t BQ27220_REG_RAW_CURRENT = (0x7A);
1378 static constexpr uint8_t BQ27220_REG_RAW_VOLTAGE = (0x7C);
1379 static constexpr uint8_t BQ27220_REG_ROM_START = (0x3E);
1380
1381 static constexpr uint16_t BQ27220_CHIP_ID = (0x0220);
1382
1383 static constexpr uint16_t BQ27220_ROM_FULL_CHARGE_CAPACITY = (0x929D);
1384 static constexpr uint16_t BQ27220_ROM_DESIGN_CAPACITY = (0x929F);
1385 static constexpr uint16_t BQ27220_ROM_OPERATION_CONFIG_A = (0x9206);
1386 static constexpr uint16_t BQ27220_ROM_OPERATION_CONFIG_B = (0x9208);
1387};
1388
1389
1390#endif
@license MIT License
constexpr size_t arraySize(const T(&arr)[N])
Returns the number of elements in a C‑style array at compile time.
#define SENSORLIB_LOG_E(...)
#define SENSORLIB_LOG_D(...)
bool isInSleepMode() const
Check if the device is in sleep mode.
bool isBatteryPresent() const
Check if a battery is present.
bool isChargeInhibited() const
Check if charging is inhibited.
struct BatteryStatus::@0 status
bool isInDischargeMode() const
Check if the device is in discharge mode.
bool isOverTemperatureDuringCharging() const
Check if over-temperature is detected during charging.
bool isDischargeTerminationAlarm() const
Check if the discharge termination alarm is triggered.
bool isFullChargeDetected() const
Check if full charge is detected.
bool isSystemShutdownRequired() const
Check if system shutdown is required.
bool isGoodOcvMeasurement() const
Check if a good OCV measurement was made.
bool isOcvReadFailedDueToCurrent() const
Check if the OCV read failed due to current.
bool isChargingTerminationAlarm() const
Check if the charging termination alarm is triggered.
bool isOverTemperatureDuringDischarge() const
Check if over-temperature is detected during discharge.
BatteryStatus(uint16_t bitmaps)
Constructor for BatteryStatus class.
bool isFullDischargeDetected() const
Check if full discharge is detected.
bool isOcvMeasurementUpdateComplete() const
Check if the OCV measurement update is complete.
bool isBatteryInserted() const
Check if a battery is inserted.
std::unique_ptr< SensorHal > hal
bool isDischarging() override
Check if battery is discharging.
static constexpr uint16_t BQ27220_SUB_CMD_HW_VERSION
static constexpr uint8_t BQ27220_REG_MAC_DATA_SUM
int getHardwareVersion()
Get the hardware version of the device.
static constexpr uint16_t BQ27220_SUB_CMD_BOARD_OFFSET
static constexpr uint8_t BQ27220_REG_STA_CHARGING_VOLTAGE
uint16_t getMaxLoadTimeToEmpty() const
Get the estimated time until the battery is empty at maximum load current discharge rate.
static constexpr uint8_t BQ27220_REG_STA_AVG_POWER
void reset() override
Reset the device.
static constexpr uint8_t BQ27220_REG_STA_STANDBY_TIME_TO_EMPTY
uint16_t getTimeToFull() override
Get the estimated time until the battery is fully charged.
uint16_t getChipID() override
Retrieve the unique identifier of the chip.
uint16_t getBTPDischargeSet() const
Get the BTP discharge set value.
uint16_t getStandbyTimeToEmpty() const
Get the estimated time until the battery is empty at standby discharge rate.
uint16_t getAtRateTimeToEmpty() const
Get the AtRateTimeToEmpty value.
static constexpr uint16_t BQ27220_SUB_CMD_SET_PROFILE_6
static constexpr uint16_t BQ27220_SUB_CMD_DEVICE_NUMBER
static constexpr uint8_t BQ27220_REG_STA_STANDBY_CURRENT
static constexpr uint16_t BQ27220_SUB_CMD_CTRL_STATUS
uint16_t getFullChargeCapacity() const
Get the full charge capacity of the battery.
uint16_t getStateOfHealth() const
Get the state of health value.
static constexpr uint16_t BQ27220_SUB_CMD_SET_PROFILE_5
uint16_t getStateOfCharge() override
Get the state of charge value.
static constexpr uint16_t BQ27220_SUB_CMD_FW_VERSION
static constexpr uint8_t BQ27220_REG_STA_NTC_TEMP
static constexpr uint8_t BQ27220_REG_STA_STATE_OF_HEALTH
static constexpr uint8_t BQ27220_REG_STA_BTP_DISC_SET
uint16_t getRawCoulombCount() const
Get the raw coulomb count value.
static constexpr uint16_t BQ27220_CHIP_ID
OperationConfig getOperationConfig()
Retrieve the operation configuration of the device.
static constexpr uint8_t BQ27220_REG_STA_BTP_CHARGE_SET
static constexpr uint16_t BQ27220_SUB_CMD_BAT_REMOVE
int16_t getAveragePower() const
Get the average power value.
static constexpr uint16_t BQ27220_SUB_CMD_SET_PROFILE_1
BatteryStatus getBatteryStatus() const
Get the battery status.
static constexpr uint16_t BQ27220_SUB_CMD_SEALED
uint16_t getRemainingCapacity() const
Get the remaining battery capacity.
static constexpr uint16_t BQ27220_SUB_CMD_CC_OFFSET
static constexpr uint8_t BQ27220_REG_ANALOG_COUNT
static constexpr uint8_t BQ27220_REG_STA_INTER_TEMP
uint16_t getCycleCount() const
Get the cycle count value.
static constexpr uint8_t BQ27220_REG_STA_BAT_VOLTAGE
static constexpr uint8_t BQ27220_REG_STA_AT_RATE
static constexpr uint8_t BQ27220_REG_STA_DESIGN_CAPACITY_LSB
uint16_t getRequestChargingCurrent() const
Get the requested charging current value.
static constexpr uint8_t BQ27220_REG_RAW_VOLTAGE
static constexpr uint16_t BQ27220_SUB_CMD_EXIT_CFG_UPDATE_REINIT
static constexpr uint8_t BQ27220_REG_STA_CYCLE_COUNT
static constexpr uint8_t BQ27220_REG_STA_DESIGN_CAPACITY_MSB
static constexpr uint16_t BQ27220_SUB_CMD_BAT_INSERT
bool refresh() override
Refresh the battery data by reading from the registers.
bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_callback)
static constexpr uint16_t BQ27220_SUB_CMD_RESET
static constexpr uint16_t BQ27220_SUB_CMD_CAL_TOGGLE
~GaugeBQ27220()=default
static constexpr uint8_t BQ27220_REG_MAC_BUFFER_END
static constexpr uint8_t BQ27220_REG_STA_COULOMB_COUNT
static constexpr uint8_t BQ27220_REG_STA_TIME_TO_EMPTY
int getFirmwareVersion()
Get the firmware version of the device.
static constexpr uint16_t BQ27220_SUB_CMD_SET_SNOOZE
static constexpr uint8_t BQ27220_REG_STA_FULL_CHARGE_CAPACITY
float getTemperature() override
Get the temperature value.
static constexpr uint8_t BQ27220_REG_MAC_BUFFER_START
static constexpr uint8_t BQ27220_REG_STA_MAX_LOAD_TO_EMPTY
static constexpr uint8_t BQ27220_REG_STA_REMAINING_CAPACITY
static constexpr uint16_t BQ27220_SUB_CMD_CLEAR_SNOOZE
static constexpr uint16_t BQ27220_SUB_CMD_RETURN_TO_ROM
uint16_t getAtRate() const
Get the AtRate value.
const uint8_t REGISTER_COUNT
static constexpr uint16_t BQ27220_SUB_CMD_EXIT_CAL
uint16_t getDesignCapacity() const
Get the design capacity value.
FuelGaugeOperationStatus getOperationStatus() const
Get the operation status.
static constexpr uint16_t BQ27220_SUB_CMD_ENTER_CAL
void setAccessKey(uint32_t key)
Set the access key for the device.
static constexpr uint16_t BQ27220_ROM_OPERATION_CONFIG_A
static constexpr uint16_t BQ27220_SUB_CMD_SET_PROFILE_2
uint16_t getRequestChargingVoltage() const
Get the requested charging voltage value.
static constexpr uint16_t BQ27220_SUB_CMD_OCV_CMD
static constexpr uint8_t BQ27220_REG_STA_DESIGN_CAPACITY
float getCurrent() override
Get the instantaneous current value.
float getInternalTemperature() const
Get the internal temperature value.
static constexpr uint16_t BQ27220_SUB_CMD_CC_OFFSET_SAVE
static constexpr uint8_t BQ27220_REG_STA_AT_RATE_TIME_TO_EMPTY
static constexpr uint8_t BQ27220_REG_STA_BAT_STATUS
static constexpr uint16_t BQ27220_SUB_CMD_EXIT_CFG_UPDATE
static constexpr uint16_t BQ27220_ROM_DESIGN_CAPACITY
static constexpr uint16_t BQ27220_SUB_CMD_ENTER_CFG_UPDATE
static constexpr uint8_t BQ27220_REG_STA_CHARGING_CURRENT
static constexpr uint8_t BQ27220_REG_ROM_START
int16_t getMaxLoadCurrent() const
Get the maximum load current value.
static constexpr uint8_t BQ27220_REG_RAW_CURRENT
static constexpr uint16_t BQ27220_SUB_CMD_SET_PROFILE_4
static constexpr uint16_t BQ27220_ROM_OPERATION_CONFIG_B
uint16_t getVoltage() override
Get the battery voltage value.
static constexpr uint8_t BQ27220_REG_STA_OPERATION_STATUS
static constexpr uint8_t BQ27220_REG_STA_STATE_OF_CHARGE
uint16_t getTimeToEmpty() override
Get the estimated time until the battery is empty.
bool setNewCapacity(uint16_t newDesignCapacity, uint16_t newFullChargeCapacity)
Set the new design capacity and full charge capacity of the battery.
static constexpr uint16_t BQ27220_SUB_CMD_SET_PROFILE_3
uint16_t getBTPChargeSet() const
Get the BTP charge set value.
static constexpr uint8_t BQ27220_REG_STA_MAX_LOAD_CURRENT
bool isCharging() override
Check if battery is charging.
static constexpr uint8_t BQ27220_REG_STA_TIME_TO_FULL
const uint8_t START_REGISTER
static constexpr uint8_t BQ27220_REG_MAC_DATA_LEN
static constexpr uint16_t BQ27220_ROM_FULL_CHARGE_CAPACITY
static constexpr uint8_t BQ27220_REG_STA_CURRENT
int16_t getStandbyCurrent() const
Get the standby current value.
Base class for battery gauge implementations.
Definition GaugeBase.hpp:40
bool begin(SensorCommCustom::CustomCallback cb, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialize the sensor using custom callback interface.
bool isNonRemovableSet() const
Check if the non - removable option is set.
bool isIntBremEnabled() const
Check if the INT_BREM function is enabled.
bool isIntStateEnabled() const
Check if the INT_STATE function is enabled.
bool isTempsSet() const
Check if the external thermistor is selected for temperature measurement.
uint16_t getConfigB() const
Get the value in configuration register B.
bool canEnterSleep() const
Check if the fuel gauge can enter the SLEEP state.
bool isWakeEnEnabled() const
Check if the wake - up function is enabled.
bool isDefaultSealEnabled() const
Check if the default seal option is enabled (sealed after POR).
bool isIntBatLEnabled() const
Check if the INT_BATL function is enabled.
bool isWrtempEnabled() const
Check if the write temperature function is enabled.
int getPfcCfg() const
Get the Pin Function Code (PFC) mode.
bool isBlPupEnEnabled() const
Check if the battery insertion pin pull - up is enabled.
bool isIntFocvEnabled() const
Check if the INT_FOCV function is enabled.
OperationConfig(uint32_t registerValue)
Constructor for OperationConfig class.
uint16_t getConfigA() const
Get the value in configuration register A.
bool isIntPolHigh() const
Check if the INT_POL function is enabled (high - level polarity).
bool isBienableEnabled() const
Check if battery insertion detection is enabled.
int getWkTh0() const
Get the Wake - up threshold 0 value.
bool isBatgPolHigh() const
Check the BATT_GD pin polarity.
bool isBatgEnEnabled() const
Check if the BATT_GD function is enabled.
bool isIntOtEnabled() const
Check if the INT_OT function is enabled.
int getWkTh1() const
Get the Wake - up threshold 1 value.
bool isIntOcvEnabled() const
Check if the INT_OCV function is enabled.
bool isSlpwakechgEnabled() const
Check if the slpwakechg function is enabled.
uint32_t(*)(Operation op, void *param1, void *param2) CustomHalCallback
bool(*)(uint8_t addr, uint8_t reg, uint8_t *buf, size_t len, bool writeReg, bool isWrite) CustomCallback
int writeBuff(uint8_t *buf, size_t len)
int writeRegBuff(uint8_t reg, uint8_t *buf, size_t len)
int writeReg(uint8_t reg, uint8_t val)
int writeThenRead(const uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len)
int readRegBuff(uint8_t reg, uint8_t *buf, size_t len) const
uint32_t hal_callback(SensorCommCustomHal::Operation op, void *param1, void *param2)
constexpr uint32_t _bv(uint8_t b)
Definition SensorLib.h:62
constexpr uint8_t _lowByte(uint16_t w)
Definition SensorLib.h:69
constexpr uint8_t _highByte(uint16_t w)
Definition SensorLib.h:73
uint8_t i