Skip to content

Commit

Permalink
fix(battery): prevent bus fault when battery does not exist
Browse files Browse the repository at this point in the history
zmk_battery_start_reporting() may be called from battery_event_listener(), which
will result in a bus fault when attempting to read a battery that does not exist
such as on a dongle.
  • Loading branch information
xudongzheng authored and petejohanson committed Jan 9, 2024
1 parent 7652fbe commit 6bf4870
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/src/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ static void zmk_battery_timer(struct k_timer *timer) {
K_TIMER_DEFINE(battery_timer, zmk_battery_timer, NULL);

static void zmk_battery_start_reporting() {
k_timer_start(&battery_timer, K_NO_WAIT, K_SECONDS(CONFIG_ZMK_BATTERY_REPORT_INTERVAL));
if (device_is_ready(battery)) {
k_timer_start(&battery_timer, K_NO_WAIT, K_SECONDS(CONFIG_ZMK_BATTERY_REPORT_INTERVAL));
}
}

static int zmk_battery_init(const struct device *_arg) {
Expand Down

1 comment on commit 6bf4870

@ngpbach
Copy link

Choose a reason for hiding this comment

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

This commit is causing my board to intermittently freeze at start up.
I used this command to build my firmware:

west  build  -p -d build/left -b nice_nano_v2 -- -DZMK_CONFIG=../zmk-config/config -DSHIELD="corne_left nice_view_adapter nice_view"

After copying the firmware to the board, it either hang immediately on the automatic reboot, or would hang a couple seconds after a reset. Reboot to bootloader still work.
The board does has battery attached. But have tried disconnecting battery and it still hang.

After reverting this commit and build again, the firmware works perfectly.

Please sign in to comment.