fix(battery): prevent bus fault when battery does not exist
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.
This commit is contained in:
parent
7652fbeb6b
commit
6bf4870704
1 changed files with 3 additions and 1 deletions
|
@ -87,7 +87,9 @@ static void zmk_battery_timer(struct k_timer *timer) {
|
||||||
K_TIMER_DEFINE(battery_timer, zmk_battery_timer, NULL);
|
K_TIMER_DEFINE(battery_timer, zmk_battery_timer, NULL);
|
||||||
|
|
||||||
static void zmk_battery_start_reporting() {
|
static void zmk_battery_start_reporting() {
|
||||||
|
if (device_is_ready(battery)) {
|
||||||
k_timer_start(&battery_timer, K_NO_WAIT, K_SECONDS(CONFIG_ZMK_BATTERY_REPORT_INTERVAL));
|
k_timer_start(&battery_timer, K_NO_WAIT, K_SECONDS(CONFIG_ZMK_BATTERY_REPORT_INTERVAL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int zmk_battery_init(const struct device *_arg) {
|
static int zmk_battery_init(const struct device *_arg) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue