mirror of https://github.com/zmkfirmware/zmk.git
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.
This commit is contained in:
parent
6cbf25f04a
commit
0adb80c02b
|
|
@ -24,6 +24,4 @@ enum zmk_usb_conn_state zmk_usb_get_conn_state(void);
|
||||||
static inline bool zmk_usb_is_powered(void) {
|
static inline bool zmk_usb_is_powered(void) {
|
||||||
return zmk_usb_get_conn_state() != ZMK_USB_CONN_NONE;
|
return zmk_usb_get_conn_state() != ZMK_USB_CONN_NONE;
|
||||||
}
|
}
|
||||||
static inline bool zmk_usb_is_hid_ready(void) {
|
bool zmk_usb_is_hid_ready(void);
|
||||||
return zmk_usb_get_conn_state() == ZMK_USB_CONN_HID;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||||
|
|
||||||
static enum usb_dc_status_code usb_status = USB_DC_UNKNOWN;
|
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) {
|
static void raise_usb_status_changed_event(struct k_work *_work) {
|
||||||
raise_zmk_usb_conn_state_changed(
|
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) {
|
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
|
// Start-of-frame events are too frequent and noisy to notify, and they're
|
||||||
// not used within ZMK
|
// not used within ZMK
|
||||||
|
|
@ -62,6 +67,11 @@ void usb_status_cb(enum usb_dc_status_code status, const uint8_t *params) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
usb_status = status;
|
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);
|
k_work_submit(&usb_status_notifier_work);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue