diff options
author | angweekiat <[email protected]> | 2024-10-15 07:15:45 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2024-10-14 19:15:45 -0400 |
commit | 0adb80c02b846e9fae9b53ff71df3b1071c05573 (patch) | |
tree | 3eef0ebab44be9096186ce7bd528a2115d1836b2 /app/src | |
parent | 6cbf25f04a275cb68cddae4846d46fb66824f349 (diff) | |
download | zmk-0adb80c02b846e9fae9b53ff71df3b1071c05573.tar.gz zmk-0adb80c02b846e9fae9b53ff71df3b1071c05573.zip |
fix(usb): detect USB power mode to fallback to BLE
* Add tracking to see if we ever hit a configured status before
suspend, so we can properly track "is connected" even when
connected to a suspended/asleep host.
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/usb.c | 10 |
1 files changed, 10 insertions, 0 deletions
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); }; |