forked from SonixQMK/qmk_firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Defer sending keyboard report to host until after matrix loop
This change defers calling "host_keyboard_send(keyboard_report)" until after the matrix loop. This enables the ability to send multiple key changes in a single report, which also means that multiple key changes can be detected in a single polling cycle. This essentially allows us report more information in the same amount of time at no additional cost. Before this change, only one key change (a press, or release) could be sent at a time. This is because "host_keyboard_send(..)" was created as a blocking method so that data cannot be changed mid-transmission to host, and this method was formerly called immediately after any change was made to the keyboard report. Calling this method at this point meant that the remainder of the polling interval would be used to send the report to host. The impact of this can be very significant in gaming scenarios, when multiple keypresses need to be triggered simultaneously. See issue qmk#4904 for more details. I tested the change manually on a Fox Leaf 60 and a Romac, and compared directly against the same firmware without the change. I've confirmed in manual testing that this allows multiple simultaneous keypresses, while not seeming to introduce any new issues. Exact changes include: - In "send_keyboard_report(..)" method, flag the last report's state as dirty instead of immediately sending report to host - Create a new "send_keyboard_report_immediate(..)" method which is called after the matrix loop, which checks if the last report sent to host is dirty and sends an updated report if so, then sets it to clean Gate deferred keyboard reports feature behind an optional define Create a define to enable the experimental "deferred keyboard reports" feature (the feature is off by default). - I manually tested a Fox Leaf 60 firmware with the define on and firmware with the define off. - All unit tests pass when feature define is not specified. - 9 unit tests fail when feature define is specified, keeping it in experimental status. Refactor "defer send keyboard report" feature to support macros This refactor makes the "defer send keyboard report" feature compatible with macros. Rather than modify the functionality of all "send_keyboard_report(..)" calls - the method now sends the keyboard report immediately like before. A new function called "send_keyboard_report_deferred(..)" handles the deferred support if the define is set, and I've replaced former calls to "send_keyboard_report(..)" with the new "send_keyboard_report_deferred(..)" function along the code path for handling keys through the matrix scan (this will not affect other calls, such as how macros are handled). When the feature define is included, it is now passing all but 5 unit tests. Adapt for tapped and subsequent shifted key events Tapped key events by default work only on **key release** by sending a key press event and a subsequent key release event to the host. Now with deferring the send event after the complete matrix scan these events are merged and erase each other becoming effectively a nop. The idea is to buffer the unregister event of the key release for all tapped keys (normal keys are not buffered) and send these in a separate keyboard report just after the key press events have been send. Unregister events/key codes are stored in the unregister_keycodes struct by unregister_code_buffered() which is called for all tapped key codes and send after a complete scan is completed by send_keyboard_report_buffered_unregister_keys(). Subsequent shifted key codes like pressing KC_EQL and KC_PLUS (KC_LSHIFT + KC_EQL) while holding the former need an additional key release event of KC_EQL before sending the combination again. This release event isn't defeered anymore but send as a report immediatly. All failing unit-tests have been fixed or rather adapted for this feature. As it turns out most of the failing key press cases expect one report per key event so they are false negatives. DEFER_KEYBOARD_REPORT_ENABLE was renamed to REGISTER_MULTIPLE_KEYEVENTS_ENABLE because it rather states a implementation detail but doesn't communicate purpose very well in my opinion.
- Loading branch information
1 parent
3a410c6
commit e4690de
Showing
10 changed files
with
824 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.