feat(battery)!: Switch to fuel gauge API#50
Draft
joelspadin wants to merge 82 commits intopetejohanson:core/move-to-zephyr-4-1from
Draft
feat(battery)!: Switch to fuel gauge API#50joelspadin wants to merge 82 commits intopetejohanson:core/move-to-zephyr-4-1from
joelspadin wants to merge 82 commits intopetejohanson:core/move-to-zephyr-4-1from
Conversation
joelspadin
commented
Sep 1, 2025
| /* | ||
| * For more information, see: | ||
| * http://docs.zephyrproject.org/latest/devices/dts/flash_partitions.html | ||
| * http: //docs.zephyrproject.org/latest/devices/dts/flash_partitions.html |
Author
There was a problem hiding this comment.
The NCS extension seems to have some interesting ideas about how things should be formatted...
24afe3a to
e8b0488
Compare
551b4f8 to
3f59fba
Compare
4331755 to
4701950
Compare
c67bc03 to
d209263
Compare
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.
17d5ff9 to
0e20958
Compare
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;
...
};
e8b0488 to
7961847
Compare
569eda2 to
4e65661
Compare
cdb6558 to
1313b43
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.