-
Notifications
You must be signed in to change notification settings - Fork 17
Demo of boot protocol working #50
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,11 @@ bool BootKeyboard_::setup(USBSetup& setup) { | |
if (request == HID_GET_PROTOCOL) { | ||
// TODO improve | ||
#ifdef __AVR__ | ||
// This is where the `protocol` variable is used to set...something, but I don't | ||
// know what. With the change that I've made to use `boot_protocol_` instead, this | ||
// would always be set to `HID_REPORT_PROTOCOL`, even when sending boot protocol | ||
// reports (successfully). It doesn't seem correct, but it works on macOS and Linux | ||
// (or at least, my old Ubuntu machine). | ||
UEDATX = protocol; | ||
#endif | ||
#ifdef ARDUINO_ARCH_SAM | ||
|
@@ -237,15 +242,29 @@ uint8_t BootKeyboard_::getLeds() { | |
} | ||
|
||
uint8_t BootKeyboard_::getProtocol() { | ||
return protocol; | ||
if (boot_protocol_) { | ||
return HID_BOOT_PROTOCOL; | ||
} else { | ||
return HID_REPORT_PROTOCOL; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This reports the protocol based on the new |
||
} | ||
|
||
void BootKeyboard_::setProtocol(uint8_t protocol) { | ||
this->protocol = protocol; | ||
if (protocol == HID_BOOT_PROTOCOL) { | ||
boot_protocol_ = true; | ||
} else { | ||
boot_protocol_ = false; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of setting the BootKeyboard_::BootKeyboard_(void) : PluggableUSBModule(1, 1, epType), protocol(HID_REPORT_PROTOCOL), idle(1), leds(0) { |
||
} | ||
|
||
int BootKeyboard_::sendReport() { | ||
if (memcmp(&last_report_, &report_, sizeof(report_))) { | ||
Serial.print(F("sending boot report: ")); | ||
for (byte i{0}; i < 8; ++i) { | ||
Serial.print(F(" ")); | ||
Serial.print(report_.bytes[i], HEX); | ||
} | ||
Serial.println(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Serial debug output showing the details of any report sent in boot protocol mode. |
||
// if the two reports are different, send a report | ||
int returnCode = USB_Send(pluggedEndpoint | TRANSFER_RELEASE, &report_, sizeof(report_)); | ||
HIDReportObserver::observeReport(HID_REPORTID_KEYBOARD, &report_, sizeof(report_), returnCode); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,7 @@ class BootKeyboard_ : public PluggableUSBModule { | |
|
||
EPTYPE_DESCRIPTOR_SIZE epType[1]; | ||
uint8_t protocol; | ||
bool boot_protocol_{false}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This adds a state variable whose only purpose is to track changes requested by Kaleidoscope, and to feed them back to Kaleidoscope via |
||
uint8_t idle; | ||
|
||
uint8_t leds; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,12 @@ void Keyboard_::end() { | |
} | ||
|
||
int Keyboard_::sendReportUnchecked() { | ||
Serial.print(F("sending nkro report:")); | ||
for (byte i{0}; i < 29; ++i) { | ||
Serial.print(F(" ")); | ||
Serial.print(report_.allkeys[i], HEX); | ||
} | ||
Serial.println(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is all just debug output, making it clear when the keyboard is in report protocol mode. |
||
return HID().SendReport(HID_REPORTID_NKRO_KEYBOARD, | ||
&last_report_, sizeof(last_report_)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an optimization for AVR to queue a single byte for transmission on the control pipe. In this particular case, it is the single byte response to the
HID_GET_PROTOCOL
request.