Skip to content

[Power] Recover battery gauge after VGM flashing#1041

Closed
squazaryu wants to merge 1 commit into
DarkFlippers:devfrom
squazaryu:fix/961-vgm-gauge-recovery
Closed

[Power] Recover battery gauge after VGM flashing#1041
squazaryu wants to merge 1 commit into
DarkFlippers:devfrom
squazaryu:fix/961-vgm-gauge-recovery

Conversation

@squazaryu

Copy link
Copy Markdown

Summary

Fixes #961.

Flashing official firmware to the Video Game Module can leave the BQ27220 fuel gauge with INITCOMP=0. Battery telemetry remains readable, but furi_hal_power_gauge_is_ok() correctly reports the gauge as unavailable, so Desktop shows - until Flipper is rebooted.

Changes

  • refresh the battery viewport when gauge_is_ok changes;
  • arm a one-shot gauge recovery after the last application exits;
  • run recovery only when no app is active and the gauge is unhealthy;
  • verify I2C communication and BATTPRES before recovery;
  • reuse the existing boot-time bq27220_init() path only when INITCOMP=0.

The recovery does not run for a healthy gauge or on an I2C read failure. No public API symbols were added or changed.

Root-cause evidence

Immediately after reproducing the issue, before reboot:

  • Desktop battery indicator: -;
  • gauge.initcomp: 0;
  • gauge.battpres: 1;
  • SOC: 100;
  • voltage: approximately 4.15 V;
  • temperature: 30 C.

A reboot restored INITCOMP=1, matching the boot-time BQ27220 initialization behavior.

Verification

  • ./fbt -j4 firmware_all
  • API check: 88.0 unchanged
  • hardware: Flipper Zero with Video Game Module
  • flashed official VGM firmware using Video Game Module Tool
  • exited the tool without rebooting Flipper
  • battery indicator recovered to 100%
  • info power_debug confirmed gauge.initcomp: 1, gauge.battpres: 1, and valid telemetry

Risk

The existing BQ27220 initialization can briefly delay the power service, but the new path is one-shot, application-exit gated, and only entered for the confirmed BATTPRES=1 && INITCOMP=0 state.

@squazaryu
squazaryu requested a review from xMasterX as a code owner July 16, 2026 09:40
@github-actions github-actions Bot added the area/system Related to the system subsystem label Jul 16, 2026
@squazaryu
squazaryu marked this pull request as draft July 16, 2026 10:02
@squazaryu

Copy link
Copy Markdown
Author

Hardware follow-up found one side effect that needs more investigation before review: recovery from INITCOMP=0 uses the existing full bq27220_init() path, which issues RESET and triggers a fresh OCV-based SOC estimate. In a 99% pre-flash test the displayed SOC returned as 100%. The percentage formula is unchanged, but I am moving this PR back to draft while checking whether the VGM flashing path can avoid disturbing the gauge or whether a narrower recovery can preserve gauge state.

@squazaryu

Copy link
Copy Markdown
Author

Hardware follow-up completed with an additional lower-SOC check:\n\n- Before flashing the official VGM firmware: 98%\n- After leaving Video Game Module Tool: the runtime recovery completed without reboot\n- Desktop battery value after recovery: 98%\n- The previous 99% -> 100% observation was therefore not a forced/default 100% value; it was consistent with a one-point OCV re-estimation at the upper rounding boundary.\n- The user-visible regression remains fixed: the battery percentage returns automatically instead of staying as a dash until a Flipper reboot.\n\nThe recovery uses the same existing BQ27220 initialization path that a reboot would invoke, but now performs it only after the app queue is empty. Marking the PR ready again with this hardware result documented.

@squazaryu
squazaryu marked this pull request as ready for review July 16, 2026 10:26
@squazaryu

Copy link
Copy Markdown
Author

Correction after another hardware run:\n\n- Before flashing the official VGM firmware: 97%\n- After leaving Video Game Module Tool and automatic gauge recovery: 100%\n\nThis disproves the earlier tentative conclusion from the 98% -> 98% run. The current recovery is not acceptable: a full BQ27220 reset can lose the accumulated SOC state and replace it with an OCV estimate that differs by several percentage points.\n\nThe PR is being returned to draft. The fix must prevent the VGM flashing path from disturbing the gauge, or otherwise preserve valid gauge state without issuing a full reset.

@squazaryu

Copy link
Copy Markdown
Author

Deferring this approach after additional hardware testing. A battery-only VGM flash can clear INITCOMP, but the proposed full BQ27220 recovery loses accumulated SOC and can re-estimate 97% as 100%, so it is not safe to merge. USB-powered VGM flashing preserves INITCOMP, and opening/closing the tool without flashing is harmless. The complete telemetry matrix, workaround, candidate VGM Tool power-path fix, and acceptance criteria are archived in squazaryu/tumoflip#131. Tumoflip 089-038 will exclude all commits from this recovery experiment.

@squazaryu squazaryu closed this Jul 16, 2026
@Oskal79

Oskal79 commented Jul 16, 2026

Copy link
Copy Markdown

AI-Slop issue, stop using Claude for everything... Try to use keyboard for making comments at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/system Related to the system subsystem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VGM

2 participants