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:
Chris Andreae
2023-11-14 03:04:04 +09:00
committed by GitHub
parent b80c0be0ce
commit 91aa3378f3
7 changed files with 229 additions and 15 deletions

View File

@@ -116,12 +116,24 @@ static const uint8_t zmk_hid_report_desc[] = {
HID_END_COLLECTION,
};
// struct zmk_hid_boot_report
// {
// uint8_t modifiers;
// uint8_t _unused;
// uint8_t keys[6];
// } __packed;
#if IS_ENABLED(CONFIG_ZMK_USB_BOOT)
#define HID_ERROR_ROLLOVER 0x1
#define HID_BOOT_KEY_LEN 6
#if IS_ENABLED(CONFIG_ZMK_HID_REPORT_TYPE_HKRO) && \
CONFIG_ZMK_HID_KEYBOARD_REPORT_SIZE == HID_BOOT_KEY_LEN
typedef struct zmk_hid_keyboard_report_body zmk_hid_boot_report_t;
#else
struct zmk_hid_boot_report {
zmk_mod_flags_t modifiers;
uint8_t _reserved;
uint8_t keys[HID_BOOT_KEY_LEN];
} __packed;
typedef struct zmk_hid_boot_report zmk_hid_boot_report_t;
#endif
#endif
struct zmk_hid_keyboard_report_body {
zmk_mod_flags_t modifiers;
@@ -179,3 +191,7 @@ bool zmk_hid_is_pressed(uint32_t usage);
struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report();
struct zmk_hid_consumer_report *zmk_hid_get_consumer_report();
#if IS_ENABLED(CONFIG_ZMK_USB_BOOT)
zmk_hid_boot_report_t *zmk_hid_get_boot_report();
#endif

View File

@@ -6,4 +6,8 @@
#pragma once
int zmk_usb_hid_send_report(const uint8_t *report, size_t len);
#include <stdint.h>
int zmk_usb_hid_send_keyboard_report();
int zmk_usb_hid_send_consumer_report();
void zmk_usb_hid_set_protocol(uint8_t protocol);