diff options
-rw-r--r-- | app/include/zmk/usb.h | 4 | ||||
-rw-r--r-- | app/src/usb.c | 10 |
2 files changed, 11 insertions, 3 deletions
diff --git a/app/include/zmk/usb.h b/app/include/zmk/usb.h index 540cdd9c7e..a5e5089f88 100644 --- a/app/include/zmk/usb.h +++ b/app/include/zmk/usb.h @@ -24,6 +24,4 @@ enum zmk_usb_conn_state zmk_usb_get_conn_state(void); static inline bool zmk_usb_is_powered(void) { return zmk_usb_get_conn_state() != ZMK_USB_CONN_NONE; } -static inline bool zmk_usb_is_hid_ready(void) { - return zmk_usb_get_conn_state() == ZMK_USB_CONN_HID; -} +bool zmk_usb_is_hid_ready(void); diff --git a/app/src/usb.c b/app/src/usb.c index cd78761834..cf76341eee 100644 --- a/app/src/usb.c +++ b/app/src/usb.c @@ -20,6 +20,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); static enum usb_dc_status_code usb_status = USB_DC_UNKNOWN; +static bool is_configured; static void raise_usb_status_changed_event(struct k_work *_work) { raise_zmk_usb_conn_state_changed( @@ -49,6 +50,10 @@ enum zmk_usb_conn_state zmk_usb_get_conn_state(void) { } } +bool zmk_usb_is_hid_ready(void) { + return zmk_usb_get_conn_state() == ZMK_USB_CONN_HID && is_configured; +} + void usb_status_cb(enum usb_dc_status_code status, const uint8_t *params) { // Start-of-frame events are too frequent and noisy to notify, and they're // not used within ZMK @@ -62,6 +67,11 @@ void usb_status_cb(enum usb_dc_status_code status, const uint8_t *params) { } #endif usb_status = status; + if (zmk_usb_get_conn_state() == ZMK_USB_CONN_HID) { + is_configured |= usb_status == USB_DC_CONFIGURED; + } else { + is_configured = false; + } k_work_submit(&usb_status_notifier_work); }; |