Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Commit

Permalink
Demo of boot protocol working
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
gedankenexperimenter committed Mar 14, 2019
1 parent f9e03b1 commit 6c2ed82
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/BootKeyboard/BootKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions src/BootKeyboard/BootKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/MultiReport/Keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit 6c2ed82

Please sign in to comment.