Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/include/zmk/usb_hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ int zmk_usb_hid_send_consumer_report(void);
int zmk_usb_hid_send_mouse_report(void);
#endif // IS_ENABLED(CONFIG_ZMK_MOUSE)
void zmk_usb_hid_set_protocol(uint8_t protocol);
#include <stdbool.h>
/* True when the host (or the 2.4G dongle's host) selected HID boot protocol. */
bool zmk_usb_hid_is_boot_protocol(void);
17 changes: 17 additions & 0 deletions app/src/endpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,23 @@ int transport_send(struct zmk_hid_keyboard_report *report, uint8_t len) {
static int send_keyboard_report(void) {
extern struct zmk_adapative_nkro adapative_nkro;
int ret = 0;
if (zmk_usb_hid_is_boot_protocol()) {
/* The host only understands 8-byte boot reports without report IDs, so it must not
* get the report-ID-prefixed 6KRO report or the NKRO bitmap report. */
bool changed = kb_changed();
changed |= nkro_changed();
if (!changed) {
return 0;
}
if (current_instance.transport == ZMK_TRANSPORT_USB) {
return zmk_usb_hid_send_keyboard_report();
}
/* Over 2.4G the 6KRO body is already in boot layout; only drop the NKRO report. */
struct zmk_hid_keyboard_report *report = zmk_hid_get_keyboard_report();
report->report_id = ZMK_HID_REPORT_ID_KEYBOARD;
report->body._reserved = 0;
return transport_send(report, CONFIG_ZMK_HID_KEYBOARD_REPORT_SIZE + 3);
}
if (kb_changed()) {
struct zmk_hid_keyboard_report *report = zmk_hid_get_keyboard_report();
report->report_id = ZMK_HID_REPORT_ID_KEYBOARD;
Expand Down
3 changes: 2 additions & 1 deletion app/src/hid_keychron.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ zmk_hid_boot_report_t *zmk_hid_get_boot_report(void) {
return boot_report_rollover(keyboard_report.body.modifiers);
}
boot_report.modifiers = keyboard_report.body.modifiers;
if (!zmk_nkro_enable) {
/* With adaptive NKRO keyboard_report always holds the 6-key array, NKRO or not. */
if (IS_ENABLED(CONFIG_ADAPATIVE_NKRO) || !zmk_nkro_enable) {
#if CONFIG_ZMK_HID_KEYBOARD_REPORT_SIZE != HID_BOOT_KEY_LEN
// Form a boot report from a report of different size.
int out = 0;
Expand Down
16 changes: 14 additions & 2 deletions app/src/usb_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,21 @@ static void set_proto_cb(const struct device *dev, uint8_t protocol) {
void zmk_usb_hid_set_protocol(uint8_t protocol) { hid_protocol = protocol; }
#endif /* IS_ENABLED(CONFIG_ZMK_USB_BOOT) */

bool zmk_usb_hid_is_boot_protocol(void) {
#if IS_ENABLED(CONFIG_ZMK_USB_BOOT)
return hid_protocol == HID_PROTOCOL_BOOT;
#else
return false;
#endif
}

uint8_t *get_keyboard_report(size_t *len) {
#if IS_ENABLED(CONFIG_ZMK_USB_BOOT)
if (hid_protocol != HID_PROTOCOL_REPORT) {
zmk_hid_boot_report_t *boot_report = zmk_hid_get_boot_report();
*len = sizeof(*boot_report);
/* A boot keyboard report is exactly 8 bytes (modifiers, reserved, 6 keys). The
* report body type is larger than that because its key array is sized for NKRO. */
*len = 2 + HID_BOOT_KEY_LEN;
return (uint8_t *)boot_report;
}
#endif
Expand Down Expand Up @@ -207,7 +217,9 @@ int zmk_usb_hid_send_report(const uint8_t *report, size_t len) {
int err = 0;
// LOG_HEXDUMP_ERR(report,len,"usb");
// cut reserve byte in nkro report;
if (report[0] == ZMK_HID_REPORT_ID_KEYBOARD_NKRO) {
/* Boot protocol reports have no report ID: byte 0 is the modifier mask, and
* 0x04 there means Left Alt, not the NKRO report ID. */
if (!zmk_usb_hid_is_boot_protocol() && report[0] == ZMK_HID_REPORT_ID_KEYBOARD_NKRO) {
uint8_t buffer[(ZMK_HID_KEYBOARD_NKRO_MAX_USAGE + 1) / 8 + 2];
buffer[0] = report[0];
buffer[1] = report[1];
Expand Down