Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup battery code #2256

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

joelspadin
Copy link
Collaborator

Changed the zmk,battery-voltage-divider and zmk,battery-nrf-vddh drivers to support only SENSOR_CHAN_VOLTAGE, and changed the default battery fetch mode to ZMK_BATTERY_REPORTING_FETCH_MODE_LITHIUM_VOLTAGE. This allowed for removing the copy of lithium_ion_mv_to_pct() from the driver code, leaving only the version in battery.c.

Custom boards/shields that use a fuel gauge driver instead of a voltage sensor, will need the following added to their Kconfig.defconfig:

choice ZMK_BATTERY_REPORTING_FETCH_MODE
    default ZMK_BATTERY_REPORTING_FETCH_MODE_STATE_OF_CHARGE
endchoice

Alternatively, add the following to the _defconfig file:

ZMK_BATTERY_REPORTING_FETCH_MODE_STATE_OF_CHARGE=y

Also updated the battery docs to include missing options and recent changes to the battery code.

Changed the zmk,battery-voltage-divider and zmk,battery-nrf-vddh drivers
to support only SENSOR_CHAN_VOLTAGE, and changed the default battery
fetch mode to ZMK_BATTERY_REPORTING_FETCH_MODE_LITHIUM_VOLTAGE. This
allowed for removing the copy of lithium_ion_mv_to_pct() from the
driver code, leaving only the version in battery.c.

Custom boards/shields that use a fuel gauge driver instead of a voltage
sensor, will need the following added to their Kconfig.defconfig:

    choice ZMK_BATTERY_REPORTING_FETCH_MODE
        default ZMK_BATTERY_REPORTING_FETCH_MODE_STATE_OF_CHARGE
    endchoice

Alternatively, add the following to the _defconfig file:

    ZMK_BATTERY_REPORTING_FETCH_MODE_STATE_OF_CHARGE=y
Updated the battery configuration docs and added some missing Kconfig
options.
@joelspadin joelspadin requested a review from a team as a code owner April 6, 2024 03:11
@petejohanson petejohanson self-assigned this Apr 11, 2024
Copy link
Contributor

@petejohanson petejohanson left a comment

Choose a reason for hiding this comment

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

Code seems reasonable to me. I wonder if we should update any of our in tree boards to the Zephyr voltage divider driver as well, to allow us to really test that and give folks some examples to work from that are updated?

Estimate the battery level by reading the voltage of a Lithium battery.
zmk,battery chosen node should be a sensor driver that implements SENSOR_CHAN_VOLTAGE.

config ZMK_BATTERY_REPORTING_FETCH_MODE_STATE_OF_CHARGE
Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid breaking existing out of tree boards that use a fuel gauge, I wonder if it might be reasonable to default this choice selection if our max17048 driver is enabled? Seems pragmatic until we can get the few out of tree boards to update their setup, then we remove that temporary work around?

@petejohanson petejohanson added core Core functionality/behavior of ZMK sensors refactor labels Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core functionality/behavior of ZMK refactor sensors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants