Flipper Zero Firmware
Loading...
Searching...
No Matches
bq27220.h
1#pragma once
2
3#include <stdint.h>
4#include <stdbool.h>
5#include <furi_hal_i2c.h>
6
7#define BQ27220_ERROR 0x0
8#define BQ27220_SUCCESS 0x1
9
10typedef struct {
11 // Low byte, Low bit first
12 bool DSG : 1; // The device is in DISCHARGE
13 bool SYSDWN : 1; // System down bit indicating the system should shut down
14 bool TDA : 1; // Terminate Discharge Alarm
15 bool BATTPRES : 1; // Battery Present detected
16 bool AUTH_GD : 1; // Detect inserted battery
17 bool OCVGD : 1; // Good OCV measurement taken
18 bool TCA : 1; // Terminate Charge Alarm
19 bool RSVD : 1; // Reserved
20 // High byte, Low bit first
21 bool CHGINH : 1; // Charge inhibit
22 bool FC : 1; // Full-charged is detected
23 bool OTD : 1; // Overtemperature in discharge condition is detected
24 bool OTC : 1; // Overtemperature in charge condition is detected
25 bool SLEEP : 1; // Device is operating in SLEEP mode when set
26 bool OCVFAIL : 1; // Status bit indicating that the OCV reading failed due to current
27 bool OCVCOMP : 1; // An OCV measurement update is complete
28 bool FD : 1; // Full-discharge is detected
30
31_Static_assert(sizeof(BatteryStatus) == 2, "Incorrect structure size");
32
33typedef struct {
34 // Low byte, Low bit first
35 bool CALMD : 1;
36 uint8_t SEC : 2;
37 bool EDV2 : 1;
38 bool VDQ : 1;
39 bool INITCOMP : 1;
40 bool SMTH : 1;
41 bool BTPINT : 1;
42 // High byte, Low bit first
43 uint8_t RSVD1 : 2;
44 bool CFGUPDATE : 1;
45 uint8_t RSVD0 : 5;
47
48_Static_assert(sizeof(OperationStatus) == 2, "Incorrect structure size");
49
50typedef struct BQ27220DMData BQ27220DMData;
51
55bool bq27220_init(FuriHalI2cBusHandle* handle);
56
60bool bq27220_apply_data_memory(FuriHalI2cBusHandle* handle, const BQ27220DMData* data_memory);
61
63uint16_t bq27220_get_voltage(FuriHalI2cBusHandle* handle);
64
66int16_t bq27220_get_current(FuriHalI2cBusHandle* handle);
67
69bool bq27220_get_battery_status(FuriHalI2cBusHandle* handle, BatteryStatus* battery_status);
70
72bool bq27220_get_operation_status(FuriHalI2cBusHandle* handle, OperationStatus* operation_status);
73
75uint16_t bq27220_get_temperature(FuriHalI2cBusHandle* handle);
76
78uint16_t bq27220_get_full_charge_capacity(FuriHalI2cBusHandle* handle);
79
81uint16_t bq27220_get_design_capacity(FuriHalI2cBusHandle* handle);
82
84uint16_t bq27220_get_remaining_capacity(FuriHalI2cBusHandle* handle);
85
87uint16_t bq27220_get_state_of_charge(FuriHalI2cBusHandle* handle);
88
90uint16_t bq27220_get_state_of_health(FuriHalI2cBusHandle* handle);
91
92void bq27220_change_design_capacity(FuriHalI2cBusHandle* handle, uint16_t capacity);
I2C HAL API.
Definition bq27220_data_memory.h:54
Definition bq27220.h:10
FuriHal i2c handle.
Definition furi_hal_i2c_types.h:44
Definition bq27220.h:33
bool BTPINT
BTP threshold has been crossed.
Definition bq27220.h:41
bool CFGUPDATE
Gauge is in CONFIG UPDATE mode.
Definition bq27220.h:44
bool SMTH
RemainingCapacity is scaled by smooth engine.
Definition bq27220.h:40
bool CALMD
Calibration mode enabled.
Definition bq27220.h:35
bool INITCOMP
gauge initialization is complete
Definition bq27220.h:39
uint8_t SEC
Current security access.
Definition bq27220.h:36
bool EDV2
EDV2 threshold exceeded.
Definition bq27220.h:37
bool VDQ
Indicates if Current discharge cycle is NOT qualified or qualified for an FCC updated.
Definition bq27220.h:38