Skip to content

feat(battery)!: Switch to fuel gauge API#50

Draft
joelspadin wants to merge 82 commits intopetejohanson:core/move-to-zephyr-4-1from
joelspadin:zephyr-4-1-fuel-gauge
Draft

feat(battery)!: Switch to fuel gauge API#50
joelspadin wants to merge 82 commits intopetejohanson:core/move-to-zephyr-4-1from
joelspadin:zephyr-4-1-fuel-gauge

Conversation

@joelspadin
Copy link
Copy Markdown

Not well tested yet.

This switches ZMK's battery reporting to use the fuel gauge API instead of the sensor API. Existing battery sensor drivers have been rewritten as fuel gauge drivers.

/*
* For more information, see:
* http://docs.zephyrproject.org/latest/devices/dts/flash_partitions.html
* http: //docs.zephyrproject.org/latest/devices/dts/flash_partitions.html
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NCS extension seems to have some interesting ideas about how things should be formatted...

@joelspadin joelspadin force-pushed the zephyr-4-1-fuel-gauge branch 2 times, most recently from 24afe3a to e8b0488 Compare September 1, 2025 19:47
@petejohanson petejohanson force-pushed the core/move-to-zephyr-4-1 branch 13 times, most recently from 551b4f8 to 3f59fba Compare September 6, 2025 20:43
@petejohanson petejohanson force-pushed the core/move-to-zephyr-4-1 branch 10 times, most recently from 4331755 to 4701950 Compare October 6, 2025 18:30
@petejohanson petejohanson force-pushed the core/move-to-zephyr-4-1 branch 4 times, most recently from c67bc03 to d209263 Compare October 13, 2025 22:20
nmunnich and others added 16 commits November 5, 2025 11:39
Add a dediceated page to outline steps to set up bootloader integration
using the boot retention mechanism in newer Zephyr versions.
Install Zephyr deps using the newer `west packages pip --install`.

Signed-off-by: Peter Johanson <peter@peterjohanson.com>
Add necessary DTS/Kconfig settings to upstream RP2040 boards so they can
use the ZMK bootloader functionality using the boot mode retention
infrastructure.
Update all links to the Zephyr docs to the 4.1.0 versions to match our
Zephyr version in use.
Some optional modules, like libmetal, which is used on nRF5340,
specfically require CMake v3, so add a note in the native toolchain
setup about this.
Translate INPUT_BTN_TOUCH input codes into button 0 press/release for
HID layer.
Properl check return code from queue-ing messages, and fix up some type
warnings in our logging calls.
We use a fair amount of stack even without BLE or RP2040, so default to
2048 by default everywhere, and constrained platforms can lowes this if
they really need.
Use the correct Device Information Service Kconfig symbols for our model
number and manufacturer.
Newer Zephyr supports "board extensions" to formally do what we've added
in ourselves via some hacks, so move all our board overlay/config file
overides for upstream Zephyr boards into that correct structure.
Upstream xiao_ble uses different naming convention for the partition
labels, so add an additional label for the SD range, so the existing
nrf52840-nosd snippet will still work with the board.
@petejohanson petejohanson force-pushed the core/move-to-zephyr-4-1 branch from 17d5ff9 to 0e20958 Compare November 5, 2025 18:39
petejohanson and others added 3 commits November 5, 2025 22:42
The nano CBPRINTF implementation lacks some padded formatting needed to
ensure consistent formatting of BLE addresses, which we use to store
keys as strings in a few places, so use the complete CBPRINTF by default
now.
ZMK now uses the fuel gauge API instead of the sensor API for reading
battery state of charge. The zmk,battery-nrf-vddh and zmk,maxim-max17048
drivers have been rewritten to use the fuel gauge API.

There is also a new zmk,fuel-gauge-sensor driver which can be used to
wrap any Zephyr driver that uses the old sensor API, as well as a new
zmk,fuel-gauge-voltage driver which estimates state of charge by reading
from a battery voltage sensor.

This is a breaking change if your board uses "voltage-divider" or
"zmk,battery-voltage-divider" as the zmk,battery chosen node. To
integrate this change:

 1. Replace 'compatible = "zmk,battery-voltage-divider"' with
    'compatible = "voltage-divider"'.

 2. Add a new "zmk,fuel-gauge-voltage" node with the "voltage-divider"
    node as its "sensor" property. If the voltage divider node is
    labeled "vbatt", then it would look like this:

    vbatt_gauge: vbatt_gauge {
        compatible = "zmk,fuel-gauge-voltage";
        sensor = <&vbatt>;
    };

 3. Change the "zmk,battery" property in the "chosen" node to use the
    new "zmk,fuel-gauge-voltage" node.

    chosen {
        zmk,battery = &vbatt_gauge;
    };

This is also a breaking change if your board uses a "maxim,max17055",
"maxim,max17262", or "ti,bq274xx" fuel gauge or a custom driver that
uses the sensor API. To integrate this change, you can wrap it with a
"zmk,fuel-gauge-sensor" node:

    chosen {
        zmk,battery = &fuel_gauge;
    };

    fuel_gauge: fuel_gauge {
        compatible = "zmk,fuel-gauge-sensor";
        sensor = <&fuel_gauge_sensor>;
    };

    fuel_gauge_sensor: bq274xx@55 {
        compatible = "ti,bq274xx";
        ...
    };
This removes the deprecated code that searches for a device labeled
"BATTERY" to use as the battery state of charge sensor. Battery
reporting now requires using the zmk,battery chosen node.

To integrate this change with a custom board, search for any node with
a "label" property set to "BATTERY":

    vbatt {
        label = "BATTERY";
        ...
    };

If you find one, remove the "label" property. Add a node label if it is
missing one:

    vbatt: vbatt {
        ...
    };

Then, find the "chosen" node and set the "zmk,battery" property to
reference the node:

    chosen {
        ...
        zmk,battery = &vbatt;
        ...
    };
@joelspadin joelspadin force-pushed the zephyr-4-1-fuel-gauge branch from e8b0488 to 7961847 Compare November 16, 2025 17:02
@petejohanson petejohanson force-pushed the core/move-to-zephyr-4-1 branch 3 times, most recently from 569eda2 to 4e65661 Compare November 20, 2025 06:56
@petejohanson petejohanson force-pushed the core/move-to-zephyr-4-1 branch 6 times, most recently from cdb6558 to 1313b43 Compare December 9, 2025 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants