Drivers: skip initialization if bq27220 is unresponsive (#435)

This commit is contained in:
あく 2021-04-30 07:47:02 +03:00 committed by GitHub
parent 724b738048
commit eb82748d50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View file

@ -64,10 +64,12 @@ bool bq27220_set_parameter_u16(uint16_t address, uint16_t value) {
return ret;
}
void bq27220_init(const ParamCEDV* cedv) {
bool bq27220_init(const ParamCEDV* cedv) {
uint32_t timeout = 100;
OperationStatus status = {};
bq27220_control(Control_ENTER_CFG_UPDATE);
if(!bq27220_control(Control_ENTER_CFG_UPDATE)) {
return false;
};
while((status.CFGUPDATE != 1) && (timeout-- > 0)) {
bq27220_get_operation_status(&status);
}
@ -111,6 +113,7 @@ void bq27220_init(const ParamCEDV* cedv) {
delay_us(15000);
bq27220_control(Control_EXIT_CFG_UPDATE);
return true;
}
uint16_t bq27220_get_voltage() {

View file

@ -66,8 +66,10 @@ typedef struct {
uint16_t DOD100;
} ParamCEDV;
/** Initialize Driver */
void bq27220_init(const ParamCEDV* cedv);
/** Initialize Driver
* @return true on success, false otherwise
*/
bool bq27220_init(const ParamCEDV* cedv);
/** Get battery voltage in mV or error */
uint16_t bq27220_get_voltage();