aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorangweekiat <[email protected]>2024-10-15 07:15:45 +0800
committerGitHub <[email protected]>2024-10-14 19:15:45 -0400
commit0adb80c02b846e9fae9b53ff71df3b1071c05573 (patch)
tree3eef0ebab44be9096186ce7bd528a2115d1836b2
parent6cbf25f04a275cb68cddae4846d46fb66824f349 (diff)
downloadzmk-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.
-rw-r--r--app/include/zmk/usb.h4
-rw-r--r--app/src/usb.c10
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);
};