feat(hid) Basic support for generic desktop usage page
Add basic support for "Generic Desktop" page, behind a ZMK_HID_GENERIC_DESKTOP_USAGES_BASIC KConfig, that works over USB and BLE, in particular for only 15 keys:
SYSTEM_POWER_DOWN |
SYSTEM_SLEEP |
SYSTEM_WAKE_UP |
SYSTEM_CONTEXT_MENU |
SYSTEM_MAIN_MENU |
SYSTEM_APP_MENU |
SYSTEM_MENU_HELP |
SYSTEM_MENU_EXIT |
SYSTEM_MENU_SELECT |
SYSTEM_MENU_RIGHT |
SYSTEM_MENU_LEFT |
SYSTEM_MENU_UP |
SYSTEM_MENU_DOWN |
SYSTEM_COLD_RESTART |
SYSTEM_WARM_RESTART |
See Section 4 of https://www.usb.org/sites/default/files/hut1_5.pdf for the full list of possible usages. Verified that system keys are intercepted by the host machine using evtest, even though the machine doesn't do anything in response to most buttons, outside of SYSTEM_POWER_DOWN and SYSTEM_SLEEP.
Note
Upon coming across https://github.com/zmkfirmware/zmk/issues/1535 where the mute button was mentioned, I initially extended the work to additionally include up to 32 keys in total:
System Dock (0xA0)toSystem Microphone Mute (0xA9),System Display Invert (0xB0)toSystem Display Swap Primary/Secondary (0xB6).
However, the linux machine that I'm testing on doesn't support the additional keys (uname -r -> 5.15.0-72-generic). If there's interest in these keys, and testing that it works, I'm happy to update the PR to include them. (I won't be able to test the keys myself)
Note 2
There's quite a bit of similar looking code between how the different keyboard, consumer, hid indicator, generic desktop pages are handled, across the relevant files. It may be possible to clean up some of the duplication if that's wanted, probably in a follow up PR.
Also, given that SYS_PWR and the other 2 system keys are already defined, maybe it's better if the config is set to true by default, or removed?
Test steps
- Flash central device with
ZMK_HID_GENERIC_DESKTOP_USAGES_BASICenabled, with key map that uses the system keys above - Re-pair the keyboard's Bluetooth connection, due to new attributes being added
- Try out the system keys! (Use
evtestto verify that system events are coming in)
@angweekiat It would definitely be nice to try to add the system microphone mute for testing on this PR.
On the duplication side of things, there's some great work on that in #2363 that will hopefully progress soon. Timing wise we'll see which is further first and merge/rebase/fixup as needed.
Finally got around testing this - Works great on my end! Thanks for implementing this & hope to see it upstream soon :)
Finally got around testing this - Works great on my end! Thanks for implementing this & hope to see it upstream soon :)
After some more usage I struggle to get this to work over ble. When connected via usb, everything works as expected. Via bluetooth, I get an EINVAL error from send_generic_desktop_report_callback and no key presses are registered on the host. No other relevant error messages appear in the logs.
I did repair the Bluetooth connection (going through a full cycle of BT_CLR, unpair & disable bluetooth on the host, re-pair).
[00:06:10.104,309] <dbg> zmk: on_keymap_binding_pressed: position 9 keycode 0x10082
[00:06:10.104,339] <dbg> zmk: hid_listener_keycode_pressed: usage_page 0x01 keycode 0x82 implicit_mods 0x00 explicit_mods 0x00
[00:06:10.104,370] <dbg> zmk: zmk_hid_implicit_modifiers_press: Modifiers set to 0x00
[00:06:10.104,370] <dbg> zmk: zmk_endpoints_send_report: usage page 0x01
[00:06:10.104,553] <dbg> zmk: send_generic_desktop_report_callback: Error notifying -22
...
[00:06:10.171,875] <dbg> zmk: on_keymap_binding_released: position 9 keycode 0x10082
[00:06:10.171,905] <dbg> zmk: hid_listener_keycode_released: usage_page 0x01 keycode 0x82 implicit_mods 0x00 explicit_mods 0x00
[00:06:10.171,905] <dbg> zmk: zmk_hid_implicit_modifiers_release: Modifiers set to 0x00
[00:06:10.171,936] <dbg> zmk: zmk_endpoints_send_report: usage page 0x01
[00:06:10.171,997] <dbg> zmk: send_generic_desktop_report_callback: Error notifying -22