Loading...
Searching...
No Matches
bq27220.h File Reference

Quite problematic chip with quite bad documentation. More...

#include <stdint.h>
#include <stdbool.h>
#include <furi_hal_i2c.h>

Go to the source code of this file.

Data Structures

struct  Bq27220ControlStatus
 
struct  Bq27220BatteryStatus
 
struct  Bq27220OperationStatus
 
struct  Bq27220GaugingStatus
 

Macros

#define BQ27220_ERROR   0x0
 
#define BQ27220_SUCCESS   0x1
 

Typedefs

typedef struct BQ27220DMData BQ27220DMData
 

Enumerations

enum  Bq27220OperationStatusSec { Bq27220OperationStatusSecSealed = 0b11 , Bq27220OperationStatusSecUnsealed = 0b10 , Bq27220OperationStatusSecFull = 0b01 }
 

Functions

bool bq27220_init (FuriHalI2cBusHandle *handle, const BQ27220DMData *data_memory)
 Initialize Driver.
 
bool bq27220_reset (FuriHalI2cBusHandle *handle)
 Reset gauge.
 
bool bq27220_seal (FuriHalI2cBusHandle *handle)
 Seal gauge access.
 
bool bq27220_unseal (FuriHalI2cBusHandle *handle)
 Unseal gauge access.
 
bool bq27220_full_access (FuriHalI2cBusHandle *handle)
 Get full access.
 
uint16_t bq27220_get_voltage (FuriHalI2cBusHandle *handle)
 Get battery voltage.
 
int16_t bq27220_get_current (FuriHalI2cBusHandle *handle)
 Get current.
 
bool bq27220_get_control_status (FuriHalI2cBusHandle *handle, Bq27220ControlStatus *control_status)
 Get control status.
 
bool bq27220_get_battery_status (FuriHalI2cBusHandle *handle, Bq27220BatteryStatus *battery_status)
 Get battery status.
 
bool bq27220_get_operation_status (FuriHalI2cBusHandle *handle, Bq27220OperationStatus *operation_status)
 Get operation status.
 
bool bq27220_get_gauging_status (FuriHalI2cBusHandle *handle, Bq27220GaugingStatus *gauging_status)
 Get gauging status.
 
uint16_t bq27220_get_temperature (FuriHalI2cBusHandle *handle)
 Get temperature.
 
uint16_t bq27220_get_full_charge_capacity (FuriHalI2cBusHandle *handle)
 Get compensated full charge capacity.
 
uint16_t bq27220_get_design_capacity (FuriHalI2cBusHandle *handle)
 Get design capacity.
 
uint16_t bq27220_get_remaining_capacity (FuriHalI2cBusHandle *handle)
 Get remaining capacity.
 
uint16_t bq27220_get_state_of_charge (FuriHalI2cBusHandle *handle)
 Get predicted remaining battery capacity.
 
uint16_t bq27220_get_state_of_health (FuriHalI2cBusHandle *handle)
 Get ratio of full charge capacity over design capacity.
 

Detailed Description

Quite problematic chip with quite bad documentation.

Couple things to keep in mind:

  • Datasheet and technical reference manual are full of bullshit
  • bqstudio is ignoring them
  • bqstudio i2c exchange tracing gives some ideas on timings that works, but there is a catch
  • bqstudio timings contradicts to gm.fs file specification
  • it's impossible to reproduce all situations in bqstudio
  • experiments with blackbox can not cover all edge cases
  • final timings are kinda blend between all of those sources
  • device behavior differs depending on i2c clock speed
  • The Hero Himmel would not have used this gauge in the first place

Couple advises if you'll need to modify this driver:

  • Reset and wait for INITCOMP if something is not right.
  • Do not do partial config update, it takes unpredictable amount of time to apply.
  • Don't forget to reset chip before writing new config.
  • If something fails at config update stage, wait for 4 seconds before doing next cycle.
  • If you can program and lock chip at factory stage - do it. It will save you a lot of time.
  • Keep sealed or strange things may happen.
  • There is a condition when it may stuck at INITCOMP state, just "press reset button".

Function Documentation

◆ bq27220_full_access()

bool bq27220_full_access ( FuriHalI2cBusHandle * handle)

Get full access.

Warning
must be done in unsealed state
Parameters
handleThe I2C Bus handle
Returns
true on success, false otherwise

◆ bq27220_get_battery_status()

bool bq27220_get_battery_status ( FuriHalI2cBusHandle * handle,
Bq27220BatteryStatus * battery_status )

Get battery status.

Parameters
handleThe handle
battery_statusThe battery status
Returns
true on success, false otherwise

◆ bq27220_get_control_status()

bool bq27220_get_control_status ( FuriHalI2cBusHandle * handle,
Bq27220ControlStatus * control_status )

Get control status.

Parameters
handleThe handle
control_statusThe control status
Returns
true on success, false otherwise

◆ bq27220_get_current()

int16_t bq27220_get_current ( FuriHalI2cBusHandle * handle)

Get current.

Parameters
handleThe I2C Bus handle
Returns
current in mA or BQ27220_ERROR

◆ bq27220_get_design_capacity()

uint16_t bq27220_get_design_capacity ( FuriHalI2cBusHandle * handle)

Get design capacity.

Parameters
handleThe I2C Bus handle
Returns
design capacity in mAh or BQ27220_ERROR

◆ bq27220_get_full_charge_capacity()

uint16_t bq27220_get_full_charge_capacity ( FuriHalI2cBusHandle * handle)

Get compensated full charge capacity.

Parameters
handleThe I2C Bus handle
Returns
full charge capacity in mAh or BQ27220_ERROR

◆ bq27220_get_gauging_status()

bool bq27220_get_gauging_status ( FuriHalI2cBusHandle * handle,
Bq27220GaugingStatus * gauging_status )

Get gauging status.

Parameters
handleThe handle
gauging_statusThe gauging status
Returns
true on success, false otherwise

◆ bq27220_get_operation_status()

bool bq27220_get_operation_status ( FuriHalI2cBusHandle * handle,
Bq27220OperationStatus * operation_status )

Get operation status.

Parameters
handleThe handle
operation_statusThe operation status
Returns
true on success, false otherwise

◆ bq27220_get_remaining_capacity()

uint16_t bq27220_get_remaining_capacity ( FuriHalI2cBusHandle * handle)

Get remaining capacity.

Parameters
handleThe I2C Bus handle
Returns
remaining capacity in mAh or BQ27220_ERROR

◆ bq27220_get_state_of_charge()

uint16_t bq27220_get_state_of_charge ( FuriHalI2cBusHandle * handle)

Get predicted remaining battery capacity.

Parameters
handleThe I2C Bus handle
Returns
state of charge in percents or BQ27220_ERROR

◆ bq27220_get_state_of_health()

uint16_t bq27220_get_state_of_health ( FuriHalI2cBusHandle * handle)

Get ratio of full charge capacity over design capacity.

Parameters
handleThe I2C Bus handle
Returns
state of health in percents or BQ27220_ERROR

◆ bq27220_get_temperature()

uint16_t bq27220_get_temperature ( FuriHalI2cBusHandle * handle)

Get temperature.

Parameters
handleThe I2C Bus handle
Returns
temperature in units of 0.1°K

◆ bq27220_get_voltage()

uint16_t bq27220_get_voltage ( FuriHalI2cBusHandle * handle)

Get battery voltage.

Parameters
handleThe I2C Bus handle
Returns
voltage in mV or BQ27220_ERROR

◆ bq27220_init()

bool bq27220_init ( FuriHalI2cBusHandle * handle,
const BQ27220DMData * data_memory )

Initialize Driver.

This routine performs a lot of things under the hood:

  • Verifies that gauge is present on i2c bus and got correct ID(0220)
  • Unseals gauge
  • Checks various internal statuses
  • Checks that current profile is 0
  • Checks configuration again provided data_memory
  • Reset gauge if something on previous stages was fishy
  • Updates configuration if needed
  • Sealing gauge to prevent configuration and state from accidental damage
Parameters
handleThe I2C Bus handle
[in]data_memoryThe data memory to be uploaded into gauge
Returns
true on success, false otherwise

◆ bq27220_reset()

bool bq27220_reset ( FuriHalI2cBusHandle * handle)

Reset gauge.

Parameters
handleThe I2C Bus handle
Returns
true on success, false otherwise

◆ bq27220_seal()

bool bq27220_seal ( FuriHalI2cBusHandle * handle)

Seal gauge access.

Parameters
handleThe I2C Bus handle
Returns
true on success, false otherwise

◆ bq27220_unseal()

bool bq27220_unseal ( FuriHalI2cBusHandle * handle)

Unseal gauge access.

Parameters
handleThe I2C Bus handle
Returns
true on success, false otherwise