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
This commit is contained in:
あく 2022-04-19 02:09:11 +03:00 committed by GitHub
parent 703844dd69
commit 1623134a82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 89 additions and 32 deletions

View file

@ -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

View file

@ -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

View file

@ -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
}
}

View file

@ -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);

26
applications/power/power_service/power.c Executable file → Normal file
View file

@ -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) {

View file

@ -29,6 +29,8 @@ typedef struct {
} PowerEvent;
typedef struct {
bool gauge_is_ok;
float current_charger;
float current_gauge;

View file

@ -1,3 +1,3 @@
#pragma once
#define PROTOBUF_MAJOR_VERSION 0
#define PROTOBUF_MINOR_VERSION 5
#define PROTOBUF_MINOR_VERSION 6

View file

@ -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,

View file

@ -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.

View file

@ -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;