mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 04:34:43 +04:00
FuriHal, drivers: rework gauge initialization routine (#3912)
* FuriHal, drivers: rework gauge initialization, ensure that we can recover from any kind of internal/external issue * Make PVS happy * Format sources * bq27220: add gaps injection into write operations * Drivers: bq27220 cleanup and various fixes * Drivers: bq27220 verbose logging and full access routine fix * Drivers: better cfg mode exit handling in bq27220 driver * Drivers: rewrite bq27220 based on bqstudio+ev2400, experiments and guessing. Fixes all known issues. * PVS: hello license check * Drivers: minimize reset count in bq27220 init sequence * Drivers: bq27220 hide debug logging, reorganize routine to ensure predictable result and minimum amount of interaction with gauge, add documentation and notes. * Drivers: more reliable bq27220_full_access routine * Drivers: replace some warning with error in bq27220 * Drivers: move static asserts to headers in bq27220 * Fix PVS warnings * Drivers: simplify logic in bq27220 --------- Co-authored-by: hedger <hedger@users.noreply.github.com>
This commit is contained in:
@@ -73,18 +73,14 @@ void furi_hal_power_init(void) {
|
||||
// Find and init gauge
|
||||
size_t retry = 2;
|
||||
while(retry > 0) {
|
||||
furi_hal_power.gauge_ok = bq27220_init(&furi_hal_i2c_handle_power);
|
||||
if(furi_hal_power.gauge_ok) {
|
||||
furi_hal_power.gauge_ok = bq27220_apply_data_memory(
|
||||
&furi_hal_i2c_handle_power, furi_hal_power_gauge_data_memory);
|
||||
}
|
||||
furi_hal_power.gauge_ok =
|
||||
bq27220_init(&furi_hal_i2c_handle_power, furi_hal_power_gauge_data_memory);
|
||||
if(furi_hal_power.gauge_ok) {
|
||||
break;
|
||||
} else {
|
||||
// Normal startup time is 250ms
|
||||
// But if we try to access gauge at that stage it will become unresponsive
|
||||
// 2 seconds timeout needed to restart communication
|
||||
furi_delay_us(2020202);
|
||||
// Gauge need some time to think about it's behavior
|
||||
// We must wait, otherwise next init cycle will fail at unseal stage
|
||||
furi_delay_us(4000000);
|
||||
}
|
||||
retry--;
|
||||
}
|
||||
@@ -110,8 +106,8 @@ void furi_hal_power_init(void) {
|
||||
bool furi_hal_power_gauge_is_ok(void) {
|
||||
bool ret = true;
|
||||
|
||||
BatteryStatus battery_status;
|
||||
OperationStatus operation_status;
|
||||
Bq27220BatteryStatus battery_status;
|
||||
Bq27220OperationStatus operation_status;
|
||||
|
||||
furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
||||
|
||||
@@ -132,7 +128,7 @@ bool furi_hal_power_gauge_is_ok(void) {
|
||||
bool furi_hal_power_is_shutdown_requested(void) {
|
||||
bool ret = false;
|
||||
|
||||
BatteryStatus battery_status;
|
||||
Bq27220BatteryStatus battery_status;
|
||||
|
||||
furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
||||
|
||||
@@ -593,8 +589,8 @@ void furi_hal_power_debug_get(PropertyValueCallback out, void* context) {
|
||||
PropertyValueContext property_context = {
|
||||
.key = key, .value = value, .out = out, .sep = '.', .last = false, .context = context};
|
||||
|
||||
BatteryStatus battery_status;
|
||||
OperationStatus operation_status;
|
||||
Bq27220BatteryStatus battery_status;
|
||||
Bq27220OperationStatus operation_status;
|
||||
|
||||
furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user