diff --git a/app/Kconfig b/app/Kconfig index 9902046d..438bc3f0 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -323,6 +323,23 @@ config ZMK_EXT_POWER bool "Enable support to control external power output" default y +choice ZMK_BATTERY_FETCH + prompt "Battery sensor fetch mode" + +config ZMK_BATTERY_FETCH_INDIVIDUAL_CHANNELS + bool "Use sensor_sample_fetch_chan()" + help + Use sensor_sample_fetch_chan() to fetch the individual battery sensor + channels instead of fetching all channels. + +config ZMK_BATTERY_FETCH_ALL + bool "Use sensor_sample_fetch()" + help + Use sensor_sample_fetch() to fetch all battery sensor channels. Use this + if your battery sensor driver requires fetching SENSOR_CHAN_ALL. + +endchoice + #Power Management endmenu diff --git a/app/src/battery.c b/app/src/battery.c index 3f662241..37bf78d0 100644 --- a/app/src/battery.c +++ b/app/src/battery.c @@ -34,7 +34,13 @@ static const struct device *battery; static int zmk_battery_update(const struct device *battery) { struct sensor_value state_of_charge; +#if defined(CONFIG_ZMK_BATTERY_FETCH_ALL) + int rc = sensor_sample_fetch(battery); +#elif defined(CONFIG_ZMK_BATTERY_FETCH_INDIVIDUAL_CHANNELS) int rc = sensor_sample_fetch_chan(battery, SENSOR_CHAN_GAUGE_STATE_OF_CHARGE); +#else +#error "No value selected for ZMK_BATTERY_FETCH" +#endif if (rc != 0) { LOG_DBG("Failed to fetch battery values: %d", rc);