From f2df3eba9dce72d95f01ebf0ec1169f9eb33cace Mon Sep 17 00:00:00 2001 From: Tom Harkness Date: Sat, 3 Oct 2026 16:43:48 +1000 Subject: [PATCH] Move bwm_battery_info_t into pm3_cmd.h (shared wire-protocol header) bwm_charger.h is an armsrc-only header included after pm3_cmd.h in appmain.c, so a struct embedding bwm_battery_info_t by value (e.g. a future PM5 status command) couldn't see the type at the point it's needed. bwm_ble_status_t and bwm_autooff_status_t already live in pm3_cmd.h for the same reason - this just brings bwm_battery_info_t in line with them. bwm_charger.c/.h keep their function declarations unchanged; only the struct's home moves. Co-Authored-By: Claude Sonnet 5 --- armsrc/bwm_charger.h | 27 ++++++--------------------- include/pm3_cmd.h | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/armsrc/bwm_charger.h b/armsrc/bwm_charger.h index c0c22d641..171f0a0a4 100644 --- a/armsrc/bwm_charger.h +++ b/armsrc/bwm_charger.h @@ -28,6 +28,7 @@ #define __BWM_CHARGER_H #include "common.h" +#include "pm3_cmd.h" // bwm_battery_info_t // Reference design capacity for the fitted cell (VXE 502540, 500 mAh / 3.7 V). // Used as the default target for `hw bwm setcap` and as the fall-back divisor for @@ -51,27 +52,11 @@ void bwm_detect_and_init(void); // detected by bwm_detect_and_init(). void bwm_print_battery_status(void); -// Compact battery telemetry for CMD_PM5_BWM_GET_BATTERY - a machine-readable -// subset of what bwm_print_battery_status() prints (same underlying reads, -// so the two can't drift on the numbers they share). All fields zeroed if -// bwm_present is false or gauge_ok is false. -typedef struct { - bool bwm_present; - bool gauge_ok; - uint16_t soc_pct; - uint16_t voltage_mv; - int16_t current_ma; // +charge / -discharge - uint16_t remaining_mah; - uint16_t full_charge_mah; - uint16_t design_cap_mah; - int16_t temp_c10; // tenths of a degree C - uint8_t charger_fault; // 0 = none, else AW32001E REG09 bits masked 0x3F - uint8_t charge_status; // 0=not charging,1=pre-charge,2=charging,3=done - uint8_t health_pct; -} PACKED bwm_battery_info_t; - -// Returns false (all fields zeroed) if no BWM was detected. A false gauge_ok -// with bwm_present true means the charger ACKed but the fuel gauge didn't. +// Fills in bwm_battery_info_t (pm3_cmd.h) for CMD_PM5_BWM_GET_BATTERY - same +// underlying reads as bwm_print_battery_status(), so the two can't drift on +// the numbers they share. Returns false (all fields zeroed) if no BWM was +// detected. A false gauge_ok with bwm_present true means the charger ACKed +// but the fuel gauge didn't. bool bwm_read_battery_info(bwm_battery_info_t *out); // One-time BQ27427 Design Capacity provisioning (CMD_PM5_BWM_SET_CAP / diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 1b2892391..d60f8204e 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -987,6 +987,23 @@ typedef struct { uint8_t bonded_count; uint8_t bonded[BWM_BLE_BONDED_MAX][7]; // addr[6] + type, first bonded_count valid } PACKED bwm_ble_status_t; +// Compact battery telemetry shared by `hw status`'s underlying data source and +// any client (e.g. the Flipper Zero FAP) wanting raw numbers instead of free-text +// Dbprintf lines. All fields zeroed if bwm_present is false or gauge_ok is false. +typedef struct { + bool bwm_present; + bool gauge_ok; + uint16_t soc_pct; + uint16_t voltage_mv; + int16_t current_ma; // +charge / -discharge + uint16_t remaining_mah; + uint16_t full_charge_mah; + uint16_t design_cap_mah; + int16_t temp_c10; // tenths of a degree C + uint8_t charger_fault; // 0 = none, else AW32001E REG09 bits masked 0x3F + uint8_t charge_status; // 0=not charging,1=pre-charge,2=charging,3=done + uint8_t health_pct; +} PACKED bwm_battery_info_t; // PM5, read compact BWM battery telemetry (bwm_battery_info_t). Used by `hw status`'s // underlying data source and by clients (e.g. the Flipper Zero FAP) that want the raw // numbers instead of hw status's free-text Dbprintf lines.