From 1623134a8287c04e90e1030062ea1acd55bde59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=82=E3=81=8F?= Date: Tue, 19 Apr 2022 02:09:11 +0300 Subject: [PATCH] Build system improvements and bug fixes (#1129) * Assets: recompile * Makefile: add debug_other to main makefile * Github: stop compilation if compiled assets not in sync with assets sources * Assets: recompile * Makefile: correct debug_other rule. Bt: prevent on system start hook from waiting for bt service * Power, FuriHal: gauge self check report * Loader: move on system start hook call to the beginning --- .github/workflows/build.yml | 1 + Makefile | 4 +++ applications/bt/bt_cli.c | 7 +++-- applications/loader/loader.c | 11 +++---- applications/power/power_service/power.c | 26 +++++++++++----- applications/power/power_service/power.h | 2 ++ assets/compiled/protobuf_version.h | 2 +- firmware/targets/f7/furi_hal/furi_hal_power.c | 31 +++++++++++++++++-- .../targets/furi_hal_include/furi_hal_power.h | 14 +++++++-- lib/drivers/bq27220.h | 23 ++++++++------ 10 files changed, 89 insertions(+), 32 deletions(-) mode change 100755 => 100644 applications/power/power_service/power.c diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 308aa942..f158efbb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -78,6 +78,7 @@ jobs: set -e make -C assets clean make -C assets + git diff --quiet || ( echo "Assets recompilation required."; exit 255 ) - name: 'Build the firmware in docker' uses: ./.github/actions/docker diff --git a/Makefile b/Makefile index 02008033..06486f85 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,10 @@ flash: firmware_flash debug: @$(MAKE) -C firmware -j$(NPROCS) debug +.PHONY: debug_other +debug_other: + @$(MAKE) -C firmware -j$(NPROCS) debug_other + .PHONY: blackmagic blackmagic: @$(MAKE) -C firmware -j$(NPROCS) blackmagic diff --git a/applications/bt/bt_cli.c b/applications/bt/bt_cli.c index 2469e74e..4c68e597 100644 --- a/applications/bt/bt_cli.c +++ b/applications/bt/bt_cli.c @@ -189,6 +189,8 @@ static void bt_cli_print_usage() { } static void bt_cli(Cli* cli, string_t args, void* context) { + furi_record_open("bt"); + string_t cmd; string_init(cmd); BtSettings bt_settings; @@ -235,16 +237,15 @@ static void bt_cli(Cli* cli, string_t args, void* context) { } string_clear(cmd); + furi_record_close("bt"); } void bt_on_system_start() { #ifdef SRV_CLI Cli* cli = furi_record_open("cli"); - furi_record_open("bt"); cli_add_command(cli, "bt", CliCommandFlagDefault, bt_cli, NULL); - furi_record_close("bt"); furi_record_close("cli"); #else UNUSED(bt_cli); #endif -} \ No newline at end of file +} diff --git a/applications/loader/loader.c b/applications/loader/loader.c index dafe255a..f9c69ca6 100644 --- a/applications/loader/loader.c +++ b/applications/loader/loader.c @@ -455,18 +455,17 @@ void loader_update_menu() { } int32_t loader_srv(void* p) { - FURI_LOG_I(TAG, "Starting"); + FURI_LOG_I(TAG, "Executing system start hooks"); + for(size_t i = 0; i < FLIPPER_ON_SYSTEM_START_COUNT; i++) { + FLIPPER_ON_SYSTEM_START[i](); + } + FURI_LOG_I(TAG, "Starting"); loader_instance = loader_alloc(); loader_build_menu(); loader_build_submenu(); - // Call on start hooks - for(size_t i = 0; i < FLIPPER_ON_SYSTEM_START_COUNT; i++) { - FLIPPER_ON_SYSTEM_START[i](); - } - FURI_LOG_I(TAG, "Started"); furi_record_create("loader", loader_instance); diff --git a/applications/power/power_service/power.c b/applications/power/power_service/power.c old mode 100755 new mode 100644 index 8c2ecd17..5f7eeb84 --- a/applications/power/power_service/power.c +++ b/applications/power/power_service/power.c @@ -12,14 +12,19 @@ void power_draw_battery_callback(Canvas* canvas, void* context) { furi_assert(context); Power* power = context; canvas_draw_icon(canvas, 0, 1, &I_Battery_26x8); - canvas_draw_box(canvas, 2, 3, (power->info.charge + 4) / 5, 4); - if(power->state == PowerStateCharging) { - canvas_set_bitmap_mode(canvas, 1); - canvas_set_color(canvas, ColorWhite); - canvas_draw_icon(canvas, 8, 0, &I_Charging_lightning_mask_9x10); - canvas_set_color(canvas, ColorBlack); - canvas_draw_icon(canvas, 8, 0, &I_Charging_lightning_9x10); - canvas_set_bitmap_mode(canvas, 0); + + if(power->info.gauge_is_ok) { + canvas_draw_box(canvas, 2, 3, (power->info.charge + 4) / 5, 4); + if(power->state == PowerStateCharging) { + canvas_set_bitmap_mode(canvas, 1); + canvas_set_color(canvas, ColorWhite); + canvas_draw_icon(canvas, 8, 0, &I_Charging_lightning_mask_9x10); + canvas_set_color(canvas, ColorBlack); + canvas_draw_icon(canvas, 8, 0, &I_Charging_lightning_9x10); + canvas_set_bitmap_mode(canvas, 0); + } + } else { + canvas_draw_box(canvas, 8, 4, 8, 2); } } @@ -119,6 +124,7 @@ static void power_check_charging_state(Power* power) { static bool power_update_info(Power* power) { PowerInfo info; + info.gauge_is_ok = furi_hal_power_gauge_is_ok(); info.charge = furi_hal_power_get_pct(); info.health = furi_hal_power_get_bat_health_pct(); info.capacity_remaining = furi_hal_power_get_battery_remaining_capacity(); @@ -140,6 +146,10 @@ static bool power_update_info(Power* power) { } static void power_check_low_battery(Power* power) { + if(!power->info.gauge_is_ok) { + return; + } + // Check battery charge and vbus voltage if((power->info.charge == 0) && (power->info.voltage_vbus < 4.0f) && power->show_low_bat_level_message) { diff --git a/applications/power/power_service/power.h b/applications/power/power_service/power.h index 92cca6f7..c32c31b3 100644 --- a/applications/power/power_service/power.h +++ b/applications/power/power_service/power.h @@ -29,6 +29,8 @@ typedef struct { } PowerEvent; typedef struct { + bool gauge_is_ok; + float current_charger; float current_gauge; diff --git a/assets/compiled/protobuf_version.h b/assets/compiled/protobuf_version.h index 53e0b73b..0459d120 100644 --- a/assets/compiled/protobuf_version.h +++ b/assets/compiled/protobuf_version.h @@ -1,3 +1,3 @@ #pragma once #define PROTOBUF_MAJOR_VERSION 0 -#define PROTOBUF_MINOR_VERSION 5 +#define PROTOBUF_MINOR_VERSION 6 diff --git a/firmware/targets/f7/furi_hal/furi_hal_power.c b/firmware/targets/f7/furi_hal/furi_hal_power.c index e5060536..2b78c7f0 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_power.c +++ b/firmware/targets/f7/furi_hal/furi_hal_power.c @@ -21,6 +21,9 @@ typedef struct { volatile uint8_t insomnia; volatile uint8_t deep_insomnia; volatile uint8_t suppress_charge; + + uint8_t gauge_initialized; + uint8_t charger_initialized; } FuriHalPower; static volatile FuriHalPower furi_hal_power = { @@ -84,6 +87,29 @@ void furi_hal_power_init() { FURI_LOG_I(TAG, "Init OK"); } +bool furi_hal_power_gauge_is_ok() { + bool ret = true; + + BatteryStatus battery_status; + OperationStatus operation_status; + + furi_hal_i2c_acquire(&furi_hal_i2c_handle_power); + + if(bq27220_get_battery_status(&furi_hal_i2c_handle_power, &battery_status) == BQ27220_ERROR || + bq27220_get_operation_status(&furi_hal_i2c_handle_power, &operation_status) == + BQ27220_ERROR) { + ret = false; + } else { + ret &= battery_status.BATTPRES; + ret &= operation_status.INITCOMP; + ret &= (cedv.design_cap == bq27220_get_design_capacity(&furi_hal_i2c_handle_power)); + } + + furi_hal_i2c_release(&furi_hal_i2c_handle_power); + + return ret; +} + uint16_t furi_hal_power_insomnia_level() { return furi_hal_power.insomnia; } @@ -315,10 +341,9 @@ void furi_hal_power_dump_state() { } else { // Operation status register printf( - "bq27220: CALMD: %d, SEC0: %d, SEC1: %d, EDV2: %d, VDQ: %d, INITCOMP: %d, SMTH: %d, BTPINT: %d, CFGUPDATE: %d\r\n", + "bq27220: CALMD: %d, SEC: %d, EDV2: %d, VDQ: %d, INITCOMP: %d, SMTH: %d, BTPINT: %d, CFGUPDATE: %d\r\n", operation_status.CALMD, - operation_status.SEC0, - operation_status.SEC1, + operation_status.SEC, operation_status.EDV2, operation_status.VDQ, operation_status.INITCOMP, diff --git a/firmware/targets/furi_hal_include/furi_hal_power.h b/firmware/targets/furi_hal_include/furi_hal_power.h index c55e3804..717f6570 100644 --- a/firmware/targets/furi_hal_include/furi_hal_power.h +++ b/firmware/targets/furi_hal_include/furi_hal_power.h @@ -19,10 +19,20 @@ typedef enum { FuriHalPowerICFuelGauge, } FuriHalPowerIC; -/** Initialize drivers - */ +/** Initialize drivers */ void furi_hal_power_init(); +/** Check if gauge is ok + * + * Verifies that: + * - gauge is alive + * - correct profile loaded + * - self diagnostic status is good + * + * @return true if gauge is ok + */ +bool furi_hal_power_gauge_is_ok(); + /** Get current insomnia level * * @return insomnia level: 0 - no insomnia, >0 - insomnia, bearer count. diff --git a/lib/drivers/bq27220.h b/lib/drivers/bq27220.h index 71773cb5..c822301a 100644 --- a/lib/drivers/bq27220.h +++ b/lib/drivers/bq27220.h @@ -28,22 +28,25 @@ typedef struct { bool FD : 1; // Full-discharge is detected } BatteryStatus; +_Static_assert(sizeof(BatteryStatus) == 2, "Incorrect structure size"); + typedef struct { // Low byte, Low bit first - bool CALMD : 1; - bool SEC0 : 1; - bool SEC1 : 1; - bool EDV2 : 1; - bool VDQ : 1; - bool INITCOMP : 1; - bool SMTH : 1; - bool BTPINT : 1; + bool CALMD : 1; /**< Calibration mode enabled */ + uint8_t SEC : 2; /**< Current security access */ + bool EDV2 : 1; /**< EDV2 threshold exceeded */ + bool VDQ : 1; /**< Indicates if Current discharge cycle is NOT qualified or qualified for an FCC updated */ + bool INITCOMP : 1; /**< gauge initialization is complete */ + bool SMTH : 1; /**< RemainingCapacity is scaled by smooth engine */ + bool BTPINT : 1; /**< BTP threshold has been crossed */ // High byte, Low bit first uint8_t RSVD1 : 2; - bool CFGUPDATE : 1; + bool CFGUPDATE : 1; /**< Gauge is in CONFIG UPDATE mode */ uint8_t RSVD0 : 5; } OperationStatus; +_Static_assert(sizeof(OperationStatus) == 2, "Incorrect structure size"); + typedef struct { // Low byte, Low bit first bool CCT : 1; @@ -62,6 +65,8 @@ typedef struct { uint8_t RSVD3 : 3; } GaugingConfig; +_Static_assert(sizeof(GaugingConfig) == 2, "Incorrect structure size"); + typedef struct { union { GaugingConfig gauge_conf;