Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hid) Basic support for generic desktop usage page #2473

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

angweekiat
Copy link
Contributor

@angweekiat angweekiat commented Sep 10, 2024

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 #1535 where the mute button was mentioned, I initially extended the work to additionally include up to 32 keys in total:

  • System Dock (0xA0) to System Microphone Mute (0xA9),
  • System Display Invert (0xB0) to System 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 evtest to verify that system events are coming in)

@angweekiat angweekiat requested a review from a team as a code owner September 10, 2024 11:02
@petejohanson
Copy link
Contributor

@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.

@urob
Copy link
Contributor

urob commented Nov 23, 2024

Finally got around testing this - Works great on my end! Thanks for implementing this & hope to see it upstream soon :)

@urob
Copy link
Contributor

urob commented Nov 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants