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

[feature] add support for USB programmable buttons usage #12950

Merged
merged 1 commit into from
Sep 15, 2021

Conversation

t-8ch
Copy link
Contributor

@t-8ch t-8ch commented May 19, 2021

Description

This adds the possibility to send "Programmable Button" events.
These are defined in the USB "Consumer Page" as
"The user defines the function of these buttons to control software
applications or GUI objects."

This allows QMK to emit events that can be handled by bespoke software
on the host without having to worry about other software trying to
handle them.

Open points:

  • This is only implements for the VUSB backend, other backends will crash
  • This creates a whole new USB report, as all the existing infrastructure is set up to work with 16bit records
    • This nicely fits with the fact that USB also allows 2**16 of these programmable buttons
  • The interface should probably provide macros create programmable buttons with arbitrary IDs instead of having to hardcode macros for all of them
  • Depending on the amount of programmable buttons that should be supported this will need better integration into the internal QMK keycode table
  • Operating system support is limited
    • I have a patch for Linux that will add support, which I will publish (and link here)
    • Other operating systems should be tested, too
  • All open points from the checklist below, this is meant as a basis for discussion

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

@github-actions github-actions bot added the core label May 19, 2021
@t-8ch
Copy link
Contributor Author

t-8ch commented May 19, 2021

Copy link
Contributor

@sigprof sigprof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any existing software that supports these usage codes, or maybe even some hardware that actually send these keycodes?

Did you test how would Windows behave when seeing a device with such HID descriptor?

tmk_core/common/keycode.h Outdated Show resolved Hide resolved
tmk_core/protocol/vusb/vusb.c Outdated Show resolved Hide resolved
tmk_core/protocol/vusb/vusb.c Outdated Show resolved Hide resolved
tmk_core/protocol/vusb/vusb.c Outdated Show resolved Hide resolved
tmk_core/protocol/vusb/vusb.c Outdated Show resolved Hide resolved
tmk_core/protocol/vusb/vusb.c Outdated Show resolved Hide resolved
@t-8ch
Copy link
Contributor Author

t-8ch commented May 19, 2021

Is there any existing software that supports these usage codes, or maybe even some hardware that actually send these keycodes?

I have no real hardware. For the implementation in Linux I first implemented a uhid program which implements a HID device in userspace. After that I implemented the support in QMK and tested it with the Linux implementation.

tmk_core/common/keycode.h Outdated Show resolved Hide resolved
tmk_core/protocol/vusb/vusb.c Outdated Show resolved Hide resolved
tmk_core/common/report.h Outdated Show resolved Hide resolved
tmk_core/protocol/vusb/vusb.c Outdated Show resolved Hide resolved
@t-8ch
Copy link
Contributor Author

t-8ch commented May 21, 2021

Maybe it would be better have these buttons only in the quantum keymap?

@t-8ch
Copy link
Contributor Author

t-8ch commented May 21, 2021

@sigprof Thanks for your reviews!
I converted the whole feature to use the quantum keycode table and support 32 keys now.

quantum/programmable_button.c Show resolved Hide resolved
quantum/quantum_keycodes.h Outdated Show resolved Hide resolved
quantum/quantum_keycodes.h Outdated Show resolved Hide resolved
@t-8ch t-8ch force-pushed the programmable-buttons branch from 0f91383 to 1aff3b8 Compare May 22, 2021 08:22
@github-actions github-actions bot added CI cli qmk cli command documentation keyboard keymap python translation via Adds via keymap and/or updates keyboard for via support labels May 22, 2021
@t-8ch t-8ch changed the base branch from master to develop May 22, 2021 08:23
@github-actions github-actions bot removed cli qmk cli command python keymap translation CI keyboard via Adds via keymap and/or updates keyboard for via support labels May 22, 2021
@t-8ch t-8ch force-pushed the programmable-buttons branch from ff878b6 to de8613f Compare May 30, 2021 06:41
@t-8ch t-8ch changed the title [feature] [DO NOT MERGE YET] add support for USB programmable buttons usage [feature] add support for USB programmable buttons usage May 30, 2021
@t-8ch t-8ch marked this pull request as ready for review May 30, 2021 07:10
@t-8ch
Copy link
Contributor Author

t-8ch commented Jun 24, 2021

FYI the host side implementation for Linux has been accepted and is scheduled to end up in Linux 5.14:
https://git.kernel.org/pub/scm/linux/kernel/git/hid/hid.git/commit/?h=for-5.14/core&id=bcfa8d14570d85c998a9b706b074ab151b286edf

These are defined in the USB "Consumer Page" as
"The user defines the function of these buttons to control software
applications orGUI objects."

This allows QMK to emit events that can be handled by bespoke software
on the host without having to worry about other software trying to
handle them.

On Linux this is handled natively from version 5.14 onwards by the
vanilla HID layer, emitting KEY_MACRO# events.
@t-8ch t-8ch force-pushed the programmable-buttons branch from c0291f7 to a29a3bf Compare September 11, 2021 07:52
@t-8ch
Copy link
Contributor Author

t-8ch commented Sep 15, 2021

FYI I tested the latest rebase and it still works.

@drashna drashna merged commit 8398859 into qmk:develop Sep 15, 2021
@drashna
Copy link
Member

drashna commented Sep 15, 2021

Thanks!

@t-8ch
Copy link
Contributor Author

t-8ch commented Sep 15, 2021

Thank you all :-)

@drashna
Copy link
Member

drashna commented Sep 15, 2021

well, fun... this is breaking a bunch of boards:
https://qmk.tzarc.io/

Compiling: tmk_core/common/avr/printf.c                                                             [OK]
Compiling: tmk_core/protocol/lufa/lufa.c                                                           tmk_core/protocol/lufa/lufa.c: In function ‘send_report’:
tmk_core/protocol/lufa/lufa.c:769:29: error: ‘SHARED_IN_EPNUM’ undeclared (first use in this function)                                                      
     Endpoint_SelectEndpoint(SHARED_IN_EPNUM);
                             ^                                                                                                                                  
tmk_core/protocol/lufa/lufa.c:769:29: note: each undeclared identifier is reported only once for each function it appears in                                    
tmk_core/protocol/lufa/lufa.c: At top level:                                                                                                                    
tmk_core/protocol/lufa/lufa.c:764:13: error: ‘send_report’ defined but not used [-Werror=unused-function]                                                   
 static void send_report(void *report, size_t size) {
             ^                                                                                                                                                  
cc1: all warnings being treated as errors
 [ERRORS]
 | 
 | 
 | 
make[1]: *** [tmk_core/rules.mk:443: .build/obj_0xc7_61key_via/lufa.o] Error 1

@t-8ch
Copy link
Contributor Author

t-8ch commented Sep 15, 2021

@drashna Want me to prepare a fix or are you working on it already?

@drashna
Copy link
Member

drashna commented Sep 15, 2021

@drashna Want me to prepare a fix or are you working on it already?

I haven't taken a look at where the issue is exactly, so please do!

t-8ch added a commit to t-8ch/qmk_firmware that referenced this pull request Sep 15, 2021
@t-8ch
Copy link
Contributor Author

t-8ch commented Sep 15, 2021

@drashna #14454
Sorry for that...

@t-8ch t-8ch deleted the programmable-buttons branch September 15, 2021 20:21
@drashna
Copy link
Member

drashna commented Sep 15, 2021

no worries! That's part of why we have the develop branch

ptrxyz pushed a commit to ptrxyz/qmk_firmware that referenced this pull request Apr 9, 2022
ptrxyz pushed a commit to ptrxyz/qmk_firmware that referenced this pull request Apr 9, 2022
coquizen pushed a commit to coquizen/qmk_firmware that referenced this pull request Jun 3, 2022
BorisTestov pushed a commit to BorisTestov/qmk_firmware that referenced this pull request May 23, 2024
BorisTestov pushed a commit to BorisTestov/qmk_firmware that referenced this pull request May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants