zmk icon indicating copy to clipboard operation
zmk copied to clipboard

feat(battery): decouple battery charging status from USB connection state

Open zhiayang opened this issue 2 years ago • 3 comments

reference/prior work: #1923

this should be the first phase in a set of PRs to decouple the status of battery charging from the device being connected to USB. the end goal is to allow non-USB-based charging to be reflected in ZMK, eg. via (as in #1923) a GPIO pin connected to a charge IC, or (in future) reading from a fuel gauge IC.

this first PR adds the zmk_battery_is_charging function, which for now simply falls back to detecting USB. It also updates places that were using USB as a proxy to use this new function instead.

the RGB and underglow config flags currently explicitly name USB (eg . CONFIG_ZMK_BACKLIGHT_AUTO_OFF_USB), so I've opted not to change them -- at least for now, and they still use USB detection.

The display widgets (corne-ish zen, nice_view, generic zmk display) have been updated to use zmk_battery_is_charging as well.

zhiayang avatar Feb 09 '24 01:02 zhiayang

tested on real hardware: default display widget (not niceview)

existing behaviour seems to work just fine, charging icon appears (immediately) when USB goes in, disappears (immediately) when USB goes out.

zhiayang avatar Feb 09 '24 02:02 zhiayang

I think it makes sense for RGB and backlighting to use USB power and not charging for their auto off triggers as otherwise the RGB and backlighting might randomly change state whilst the board is plugged in when the battery completes charging

ReFil avatar Feb 09 '24 08:02 ReFil

weirdge, it closed the pr. should be ready for review now.

for backlights and RGB stuff and their auto-off-unless-on-usb functionality, it might require a bit more changes (since they subscribe to the usb_conn event), and i'll put that in a separate PR. for now they still use usb detection.

zhiayang avatar Feb 23 '24 06:02 zhiayang