flipperzero-firmware
flipperzero-firmware copied to clipboard
power: Also ask charger if charge done
What's new
- Also check
bq25896'sCHRG_STATto see if charging is complete- More accurately reflects charging status
- Simplifies local custom firmware builds that reduce the battery charging voltage
- Keep
bq27220fuel gauge check to show as charged at 100%- Ensures Flipper shows as charged as soon as it's plugged in if already 100%
- No changes made to charging procedure
| Criteria | Rank | Reason |
|---|---|---|
| Impact | ★☆☆ 1/3 | More accurate status, groundwork for locally reducing charging voltage |
| Risk | ★☆☆ 1/3 | Charging might be shown as complete before it's done |
| Intrusiveness | ★★☆ 2/3 | Modifies driver, power HAL, and power interface, might interfere with other pull requests |
Verification
Standard charging behavior
- Flash firmware to Flipper
- Drain Flipper battery below 100%, then connect to charger
- Ensure that Flipper shows as charging (red LED)
- Charge until full (100%)
- Ensure that Flipper shows as full (green LED)
- Unplug Flipper from charger
- Wait until Flipper shows as disconnected (green LED turns off)
- Reconnect Flipper to charger while at 100%
- Ensure that Flipper shows as full (green LED) as soon as power is detected
Modified charging behavior
This provides a way to test the "charging done" status from the bq25896 without relying on the fuel gauge. Whether or not an actual UI to implement charge limiting will be added is under discussion in issue #1158.
- Modify
lib/drivers/bq25896.cto add a hard-coded charge limit for testing- Only for testing, not part of this pull request
@@ -56,6 +56,12 @@ void bq25896_init(FuriHalI2cBusHandle* handle) {
furi_hal_i2c_write_reg_8(
handle, BQ25896_ADDRESS, 0x02, *(uint8_t*)&bq25896_regs.r02, BQ25896_I2C_TIMEOUT);
+ // FIXME: Hard-coded hack to test, move this to an actual function later
+ // WARNING: Do NOT go above 0x17 (23 decimal) - that will overcharge the battery!
+ bq25896_regs.r06.VREG = 0x00; // Charge Voltage Limit: 3840 mV (offset: +3840mV)
+ furi_hal_i2c_write_reg_8(
+ handle, BQ25896_ADDRESS, 0x06, *(uint8_t*)&bq25896_regs.r06, BQ25896_I2C_TIMEOUT);
+
bq25896_regs.r07.WATCHDOG = WatchdogDisable;
furi_hal_i2c_write_reg_8(
handle, BQ25896_ADDRESS, 0x07, *(uint8_t*)&bq25896_regs.r07, BQ25896_I2C_TIMEOUT);
- Flash firmware to Flipper
- Drain Flipper battery below 3.8v (possibly near 70%), then connect to charger
- Ensure that Flipper shows as charging (red LED)
- Charge until Flipper shows as full (green LED)
- Unplug Flipper from charger
- Wait until Flipper shows as disconnected (green LED turns off)
- Ensure that Flipper eventually shows as full (green LED)
- May take up to 1 minute for
bq25896to determine that charging is already done
- May take up to 1 minute for
Code review extras
I'm unsure about adding #include "bq25896_reg.h" to lib/drivers/bq25896.h. It's needed to specify a return type of ChrgStat to bq25896_get_charge_status(), which avoids duplicating code, but that is pulling in another header file at the header level.
If there's a better way to handle this, let me know.
Checklist (For Reviewer)
- [ ] PR has description of feature/bug or link to Confluence/Jira task
- [ ] Description contains actions to verify feature/bugfix
- [ ] I've built this code, uploaded it to the device and verified feature/bugfix
There are cases when charging will be suppressed. This changes need verification, I'll be able to test it on weekend.
So it's scheduled for next release
Let me know if there's anything I could do to make this easier to review. No rush implied though; I realize the Flipper team's got much bigger matters to tackle.
I've been running this atop dev plus local changes to actually limit the charge (this PR does not limit charging) and it's been working well. I'll keep rebasing as I update, though if the pushes cause issues I can stop.
I have updated this with the latest changes to introduce the public Flipper API. This pull request adds the following to the API:
Function,+,furi_hal_power_is_charging_done,_Bool,
When combined with my work-in-progress support for charge limiting, two other functions get added.
EDIT: I noticed the force-push to the dev branch and I've rebased this.
@skotopes Thank you for picking this up!
I'll refrain from doing further rebases atop dev since you've assigned this to yourself.