USBHIDKeyboard: Fix 200ms delay for every key #7218
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Change
Arduino-esp32 2.0.4 was released with a version of TinyUSB hid_device.h that uses uint16_t for the last argument:
But USBHID implements this callback with
uint8_t
:The result is that when
USBHIDKeyboard
sends a report to the host, it times out, waiting 100 ms for the callback to be called (which never occurs because the function signature does not match). It does this once for pressing the key and once for releasing the key, so 100 ms * 2 = 200 ms.The latest version of hid_device.h reverts the last argument to
uint8_t
:But these commits suggest that the last argument will eventually be changed to
uint16_t
:hathach/tinyusb@556b5d5
hathach/tinyusb@b495d6f
To prevent this from becoming broken again, in preparation for the change to
uint16_t
, makeUSBHID
resilient to any type for the last argument fortud_hid_report_complete_cb()
by using some C++ template metaprogramming,adapted from https://stackoverflow.com/questions/22632236/how-is-possible-to-deduce-function-argument-type-in-c.
Tests scenarios
I have tested my Pull Request on Arduino-esp32 core v2.0.4 with ESP32-S2 Board with this scenario.