From eb82748d506a2156793bfa2830b0cd105434f4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=82=E3=81=8F?= Date: Fri, 30 Apr 2021 07:47:02 +0300 Subject: [PATCH] Drivers: skip initialization if bq27220 is unresponsive (#435) --- lib/drivers/bq27220.c | 7 +++++-- lib/drivers/bq27220.h | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/drivers/bq27220.c b/lib/drivers/bq27220.c index ab242e4c..e7fcb35f 100644 --- a/lib/drivers/bq27220.c +++ b/lib/drivers/bq27220.c @@ -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() { diff --git a/lib/drivers/bq27220.h b/lib/drivers/bq27220.h index 7e50942d..a4606f4f 100644 --- a/lib/drivers/bq27220.h +++ b/lib/drivers/bq27220.h @@ -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();