arduino-libraries / Keyboard

GNU Lesser General Public License v3.0
225 stars 158 forks source link

[Feature Request] Support for boot protocol #42

Open bitboy85 opened 3 years ago

bitboy85 commented 3 years ago

By now the library does not support boot protocol for keyboard which makes it impossible to use it on certain devices like KVM switches or in older pc bios.

This request might require additional changes in the used hid or usb libraries

T-vK commented 3 years ago

Is this actually a thing? Do you have a link? Maybe this is related to the fact that some keyboards have the ability to fall back to PS/2 through the USB connector? https://en.wikipedia.org/wiki/PS/2_port#Conversion_between_PS/2_and_USB

bitboy85 commented 3 years ago

As asked i add a few links as reference. HID-Project from NicoHood supports boot protocol, but its not working in all cases https://github.com/NicoHood/HID/issues/34 https://github.com/NicoHood/HID/issues/225

https://deskthority.net/wiki/USB

USB specs https://usb.org/sites/default/files/hid1_11.pdf mainly page 59. boot protocol also needs 2 additional functions to let the host know about "boot mode"

There are also a few questions in the forum about this topic.

In short: the current keyboard lib is not working in some cases. It is a software issue as i found out that a teensy with the same chip as an arduino micro, is always working, like a real keyboard.

T-vK commented 3 years ago

Very interesting, thanks for the links. I wasn't aware that the teeny has the same chip as the Arduino Micro. I wonder if it would be possible to flash the Teensy firmware onto the Micro in order to get it to work.

T-vK commented 3 years ago

Seems like "boot mode" is simply a difference in the HID device descriptor.

https://github.com/NicoHood/HID/blob/64b89df10c6ceb4fac492bcf66434edf95059dd8/src/SingleReport/BootKeyboard.cpp vs https://github.com/arduino-libraries/Keyboard/blob/716d28617ccd5df3d9d0fb2c121bb1f1eeeb8d6c/src/Keyboard.cpp

The difficulty would be to dynmically detect which one to use.

bitboy85 commented 3 years ago

Teensy is proprietary and has its own bootloader. So i guess its not possible.

The USB document above talks about 2 additional functions a "boot" device needs to have so "boot mode" could be enabled. It is also possible that a fully compliant keyboard needs to have both descriptors/endpoints, the boot one, and the standard HID one.

T-vK commented 3 years ago

The Teensy bootloader being proprietary would mean that it would be extremely difficult to make changes to it, but it should be hard possible to dump the bootloader from an existing one or find someone on the Internet who has done it and flash it onto an Arduino Micro. Although the Arduino Micro might not expose all the pins you may want/need to the PCB and I suppose the bootloader could theoretically be able to somehow detect if it's running an an Adruino Micro PCB and refuse to work.

Looking a bit deeper into the document it seems like you'd also have to make changes to the interface descriptor, not just the report descriptor: image

Unfortunately I haven't messed with USB on that level before.