From 6c2ed82c28cdee0c7259f5da24005385f2af567a Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Thu, 14 Mar 2019 10:54:26 -0500 Subject: [PATCH] Demo of boot protocol working This adds serial debugging output showing when a boot protocol HID report is sent (and when an NKRO protocol report is sent, too), and the contents of that report. It also changes the variable used to decide which type of report to send to the host, without changing the `getDescriptor()` and `setup()` methods, which still do whatever they do with the `protocol` variable, and `UEDATX`. I don't understand why this works, but it seems to allow proper switching between boot protocol and report protocol on macOS & Linux (the two machines I have access to). --- src/BootKeyboard/BootKeyboard.cpp | 18 ++++++++++++++++-- src/BootKeyboard/BootKeyboard.h | 1 + src/MultiReport/Keyboard.cpp | 6 ++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/BootKeyboard/BootKeyboard.cpp b/src/BootKeyboard/BootKeyboard.cpp index 105b4a9f..4e0b1a07 100644 --- a/src/BootKeyboard/BootKeyboard.cpp +++ b/src/BootKeyboard/BootKeyboard.cpp @@ -196,15 +196,29 @@ uint8_t BootKeyboard_::getLeds(void) { } uint8_t BootKeyboard_::getProtocol(void) { - return protocol; + if (boot_protocol_) { + return HID_BOOT_PROTOCOL; + } else { + return HID_REPORT_PROTOCOL; + } } void BootKeyboard_::setProtocol(uint8_t protocol) { - this->protocol = protocol; + if (protocol == HID_BOOT_PROTOCOL) { + boot_protocol_ = true; + } else { + boot_protocol_ = false; + } } int BootKeyboard_::sendReport(void) { if (memcmp(&_lastKeyReport, &_keyReport, sizeof(_keyReport))) { + Serial.print(F("sending boot report: ")); + for (byte i{0}; i < 8; ++i) { + Serial.print(F(" ")); + Serial.print(int(_keyReport.bytes[i])); + } + Serial.println(); // if the two reports are different, send a report int returnCode = USB_Send(pluggedEndpoint | TRANSFER_RELEASE, &_keyReport, sizeof(_keyReport)); memcpy(&_lastKeyReport, &_keyReport, sizeof(_keyReport)); diff --git a/src/BootKeyboard/BootKeyboard.h b/src/BootKeyboard/BootKeyboard.h index 7f2ef54e..087050d2 100644 --- a/src/BootKeyboard/BootKeyboard.h +++ b/src/BootKeyboard/BootKeyboard.h @@ -78,6 +78,7 @@ class BootKeyboard_ : public PluggableUSBModule { uint8_t epType[1]; uint8_t protocol; + bool boot_protocol_{false}; uint8_t idle; uint8_t leds; diff --git a/src/MultiReport/Keyboard.cpp b/src/MultiReport/Keyboard.cpp index 7d496242..cc0c506d 100644 --- a/src/MultiReport/Keyboard.cpp +++ b/src/MultiReport/Keyboard.cpp @@ -98,6 +98,12 @@ void Keyboard_::end(void) { } int Keyboard_::sendReportUnchecked(void) { + Serial.print(F("sending nkro report:")); + for (byte i{0}; i < 29; ++i) { + Serial.print(F(" ")); + Serial.print(int(keyReport.allkeys[i])); + } + Serial.println(); return HID().SendReport(HID_REPORTID_NKRO_KEYBOARD, &keyReport, sizeof(keyReport)); }