Loading...
Searching...
No Matches
bq27220.h
Go to the documentation of this file.
1
29#pragma once
30
31#include <stdint.h>
32#include <stdbool.h>
33#include <furi_hal_i2c.h>
34
35#define BQ27220_ERROR 0x0
36#define BQ27220_SUCCESS 0x1
37
38typedef struct {
39 // Low byte, Low bit first
40 uint8_t BATT_ID : 3;
41 bool SNOOZE : 1;
42 bool BCA : 1;
43 bool CCA : 1;
44 uint8_t RSVD0 : 2;
45 // High byte, Low bit first
46 uint8_t RSVD1;
48
49_Static_assert(sizeof(Bq27220ControlStatus) == 2, "Incorrect Bq27220ControlStatus structure size");
50
51typedef struct {
52 // Low byte, Low bit first
53 bool DSG : 1;
54 bool SYSDWN : 1;
55 bool TDA : 1;
56 bool BATTPRES : 1;
57 bool AUTH_GD : 1;
58 bool OCVGD : 1;
59 bool TCA : 1;
60 bool RSVD : 1;
61 // High byte, Low bit first
62 bool CHGINH : 1;
63 bool FC : 1;
64 bool OTD : 1;
65 bool OTC : 1;
66 bool SLEEP : 1;
67 bool OCVFAIL : 1;
68 bool OCVCOMP : 1;
69 bool FD : 1;
71
72_Static_assert(sizeof(Bq27220BatteryStatus) == 2, "Incorrect Bq27220BatteryStatus structure size");
73
74typedef enum {
75 Bq27220OperationStatusSecSealed = 0b11,
76 Bq27220OperationStatusSecUnsealed = 0b10,
77 Bq27220OperationStatusSecFull = 0b01,
78} Bq27220OperationStatusSec;
79
80typedef struct {
81 // Low byte, Low bit first
82 bool CALMD : 1;
83 uint8_t SEC : 2;
84 bool EDV2 : 1;
85 bool VDQ : 1;
86 bool INITCOMP : 1;
87 bool SMTH : 1;
88 bool BTPINT : 1;
89 // High byte, Low bit first
90 uint8_t RSVD1 : 2;
91 bool CFGUPDATE : 1;
92 uint8_t RSVD0 : 5;
94
95_Static_assert(
96 sizeof(Bq27220OperationStatus) == 2,
97 "Incorrect Bq27220OperationStatus structure size");
98
99typedef struct {
100 // Low byte, Low bit first
101 bool FD : 1;
102 bool FC : 1;
103 bool TD : 1;
104 bool TC : 1;
105 bool RSVD0 : 1;
106 bool EDV : 1;
107 bool DSG : 1;
108 bool CF : 1;
109 // High byte, Low bit first
110 uint8_t RSVD1 : 2;
111 bool FCCX : 1;
112 uint8_t RSVD2 : 2;
113 bool EDV1 : 1;
114 bool EDV2 : 1;
115 bool VDQ : 1;
117
118_Static_assert(sizeof(Bq27220GaugingStatus) == 2, "Incorrect Bq27220GaugingStatus structure size");
119
120typedef struct BQ27220DMData BQ27220DMData;
121
139bool bq27220_init(FuriHalI2cBusHandle* handle, const BQ27220DMData* data_memory);
140
148
156
164
174
182
190
199
208
217 FuriHalI2cBusHandle* handle,
218 Bq27220OperationStatus* operation_status);
219
228
236
244
252
260
268
bool bq27220_get_control_status(FuriHalI2cBusHandle *handle, Bq27220ControlStatus *control_status)
Get control status.
Definition bq27220.c:529
bool bq27220_init(FuriHalI2cBusHandle *handle, const BQ27220DMData *data_memory)
Initialize Driver.
Definition bq27220.c:271
uint16_t bq27220_get_state_of_health(FuriHalI2cBusHandle *handle)
Get ratio of full charge capacity over design capacity.
Definition bq27220.c:575
bool bq27220_unseal(FuriHalI2cBusHandle *handle)
Unseal gauge access.
Definition bq27220.c:434
uint16_t bq27220_get_remaining_capacity(FuriHalI2cBusHandle *handle)
Get remaining capacity.
Definition bq27220.c:567
bool bq27220_full_access(FuriHalI2cBusHandle *handle)
Get full access.
Definition bq27220.c:468
bool bq27220_reset(FuriHalI2cBusHandle *handle)
Reset gauge.
Definition bq27220.c:368
uint16_t bq27220_get_voltage(FuriHalI2cBusHandle *handle)
Get battery voltage.
Definition bq27220.c:521
bool bq27220_seal(FuriHalI2cBusHandle *handle)
Seal gauge access.
Definition bq27220.c:399
uint16_t bq27220_get_temperature(FuriHalI2cBusHandle *handle)
Get temperature.
Definition bq27220.c:555
uint16_t bq27220_get_full_charge_capacity(FuriHalI2cBusHandle *handle)
Get compensated full charge capacity.
Definition bq27220.c:559
bool bq27220_get_battery_status(FuriHalI2cBusHandle *handle, Bq27220BatteryStatus *battery_status)
Get battery status.
Definition bq27220.c:533
uint16_t bq27220_get_state_of_charge(FuriHalI2cBusHandle *handle)
Get predicted remaining battery capacity.
Definition bq27220.c:571
bool bq27220_get_operation_status(FuriHalI2cBusHandle *handle, Bq27220OperationStatus *operation_status)
Get operation status.
Definition bq27220.c:537
bool bq27220_get_gauging_status(FuriHalI2cBusHandle *handle, Bq27220GaugingStatus *gauging_status)
Get gauging status.
Definition bq27220.c:543
int16_t bq27220_get_current(FuriHalI2cBusHandle *handle)
Get current.
Definition bq27220.c:525
uint16_t bq27220_get_design_capacity(FuriHalI2cBusHandle *handle)
Get design capacity.
Definition bq27220.c:563
I2C HAL API.
Definition bq27220_data_memory.h:54
Definition bq27220.h:51
bool TCA
Terminate Charge Alarm.
Definition bq27220.h:59
bool FD
Full-discharge is detected.
Definition bq27220.h:69
bool AUTH_GD
Detect inserted battery.
Definition bq27220.h:57
bool RSVD
Reserved.
Definition bq27220.h:60
bool SYSDWN
System down bit indicating the system should shut down.
Definition bq27220.h:54
bool OTD
Overtemperature in discharge condition is detected.
Definition bq27220.h:64
bool OTC
Overtemperature in charge condition is detected.
Definition bq27220.h:65
bool DSG
The device is in DISCHARGE.
Definition bq27220.h:53
bool OCVGD
Good OCV measurement taken.
Definition bq27220.h:58
bool TDA
Terminate Discharge Alarm.
Definition bq27220.h:55
bool SLEEP
Device is operating in SLEEP mode when set.
Definition bq27220.h:66
bool OCVCOMP
An OCV measurement update is complete.
Definition bq27220.h:68
bool CHGINH
Charge inhibit.
Definition bq27220.h:62
bool OCVFAIL
Status bit indicating that the OCV reading failed due to current.
Definition bq27220.h:67
bool BATTPRES
Battery Present detected.
Definition bq27220.h:56
bool FC
Full-charged is detected.
Definition bq27220.h:63
Definition bq27220.h:38
bool CCA
Coulomb Counter Calibration routine is active.
Definition bq27220.h:43
uint8_t BATT_ID
Battery Identification.
Definition bq27220.h:40
bool SNOOZE
SNOOZE mode is enabled.
Definition bq27220.h:41
uint8_t RSVD1
Reserved.
Definition bq27220.h:46
bool BCA
fuel gauge board calibration routine is active
Definition bq27220.h:42
uint8_t RSVD0
Reserved.
Definition bq27220.h:44
Definition bq27220.h:99
bool RSVD0
Reserved.
Definition bq27220.h:105
bool FD
Full Discharge.
Definition bq27220.h:101
bool EDV2
Cell voltage is above or below EDV2 threshold.
Definition bq27220.h:114
bool EDV1
Cell voltage is above or below EDV1 threshold.
Definition bq27220.h:113
bool TC
Terminate Charge.
Definition bq27220.h:104
bool TD
Terminate Discharge.
Definition bq27220.h:103
bool VDQ
Charge cycle FCC update qualification.
Definition bq27220.h:115
bool FCCX
fcc1hz clock going into CC: 0 = 1 Hz, 1 = 16 Hz
Definition bq27220.h:111
bool FC
Full Charge.
Definition bq27220.h:102
bool DSG
DISCHARGE or RELAXATION.
Definition bq27220.h:107
uint8_t RSVD2
Reserved.
Definition bq27220.h:112
bool EDV
Cell voltage is above or below EDV0 threshold.
Definition bq27220.h:106
uint8_t RSVD1
Reserved.
Definition bq27220.h:110
bool CF
Battery conditioning is needed.
Definition bq27220.h:108
Definition bq27220.h:80
uint8_t RSVD1
Reserved.
Definition bq27220.h:90
bool VDQ
Indicates if Current discharge cycle is NOT qualified or qualified for an FCC updated.
Definition bq27220.h:85
bool SMTH
RemainingCapacity is scaled by smooth engine.
Definition bq27220.h:87
bool CFGUPDATE
Gauge is in CONFIG UPDATE mode.
Definition bq27220.h:91
bool BTPINT
BTP threshold has been crossed.
Definition bq27220.h:88
bool CALMD
Calibration mode enabled.
Definition bq27220.h:82
bool INITCOMP
gauge initialization is complete
Definition bq27220.h:86
bool EDV2
EDV2 threshold exceeded.
Definition bq27220.h:84
uint8_t SEC
Current security access.
Definition bq27220.h:83
uint8_t RSVD0
Reserved.
Definition bq27220.h:92
FuriHal i2c handle.
Definition furi_hal_i2c_types.h:44