forked from kofal.net/zmk
feat(usb): Add boot protocol support
* USB boot protocol support * Use a single definition of a boot report, used for regular reports in non-6KRO, and for rollover in all branches. * Handle gaps in the zmk report when producing a boot report in HKRO mode. For .example, if it was 8KRO, it would be possible to have the state 0 0 0 0 0 0 0 17 (by pressing 8 keys, and letting go of the first 7). Copying the first 6 bytes would not show up the single pressed key. * Disable usb status change and callback on SOF events: SOF events were introduced by the boot protocol changes, and required internally by Zephyr's idle support, but are unused within ZMK itself. Ignore them in the usb status callback. --------- Co-authored-by: Andrew Childs <lorne@cons.org.nz>
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
#include <zmk/event_manager.h>
|
||||
#include <zmk/events/usb_conn_state_changed.h>
|
||||
|
||||
#include <zmk/usb_hid.h>
|
||||
|
||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
|
||||
static enum usb_dc_status_code usb_status = USB_DC_UNKNOWN;
|
||||
@@ -35,6 +37,7 @@ enum zmk_usb_conn_state zmk_usb_get_conn_state() {
|
||||
case USB_DC_CONFIGURED:
|
||||
case USB_DC_RESUME:
|
||||
case USB_DC_CLEAR_HALT:
|
||||
case USB_DC_SOF:
|
||||
return ZMK_USB_CONN_HID;
|
||||
|
||||
case USB_DC_DISCONNECTED:
|
||||
@@ -47,6 +50,17 @@ enum zmk_usb_conn_state zmk_usb_get_conn_state() {
|
||||
}
|
||||
|
||||
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
|
||||
if (status == USB_DC_SOF) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_ZMK_USB_BOOT)
|
||||
if (status == USB_DC_RESET) {
|
||||
zmk_usb_hid_set_protocol(HID_PROTOCOL_REPORT);
|
||||
}
|
||||
#endif
|
||||
usb_status = status;
|
||||
k_work_submit(&usb_status_notifier_work);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user