diff options
| author | Thomas Weißschuh <thomas@t-8ch.de> | 2021-09-15 17:40:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-15 08:40:22 -0700 |
| commit | 83988597f4d916a37b2b0987f393ceaa007532eb (patch) | |
| tree | ba5d07ccf743cb27bee77b4d6cd2128035ce365e /tmk_core | |
| parent | 1a68feb842ebcc6a7d1aef7cd7f83865cc18fab1 (diff) | |
| download | qmk_firmware-83988597f4d916a37b2b0987f393ceaa007532eb.tar.gz qmk_firmware-83988597f4d916a37b2b0987f393ceaa007532eb.zip | |
Add Support for USB programmable buttons (#12950)
Diffstat (limited to 'tmk_core')
| -rw-r--r-- | tmk_core/common/chibios/suspend.c | 4 | ||||
| -rw-r--r-- | tmk_core/common/host.c | 15 | ||||
| -rw-r--r-- | tmk_core/common/host.h | 2 | ||||
| -rw-r--r-- | tmk_core/common/host_driver.h | 1 | ||||
| -rw-r--r-- | tmk_core/common/report.h | 6 | ||||
| -rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 33 | ||||
| -rw-r--r-- | tmk_core/protocol/usb_descriptor.c | 19 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/vusb.c | 36 |
8 files changed, 103 insertions, 13 deletions
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c index 991fe6e08..9310a9992 100644 --- a/tmk_core/common/chibios/suspend.c +++ b/tmk_core/common/chibios/suspend.c | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "action.h" | 7 | #include "action.h" |
| 8 | #include "action_util.h" | 8 | #include "action_util.h" |
| 9 | #include "mousekey.h" | 9 | #include "mousekey.h" |
| 10 | #include "programmable_button.h" | ||
| 10 | #include "host.h" | 11 | #include "host.h" |
| 11 | #include "suspend.h" | 12 | #include "suspend.h" |
| 12 | #include "led.h" | 13 | #include "led.h" |
| @@ -79,6 +80,9 @@ void suspend_wakeup_init(void) { | |||
| 79 | #ifdef MOUSEKEY_ENABLE | 80 | #ifdef MOUSEKEY_ENABLE |
| 80 | mousekey_clear(); | 81 | mousekey_clear(); |
| 81 | #endif /* MOUSEKEY_ENABLE */ | 82 | #endif /* MOUSEKEY_ENABLE */ |
| 83 | #ifdef PROGRAMMABLE_BUTTON_ENABLE | ||
| 84 | programmable_button_clear(); | ||
| 85 | #endif /* PROGRAMMABLE_BUTTON_ENABLE */ | ||
| 82 | #ifdef EXTRAKEY_ENABLE | 86 | #ifdef EXTRAKEY_ENABLE |
| 83 | host_system_send(0); | 87 | host_system_send(0); |
| 84 | host_consumer_send(0); | 88 | host_consumer_send(0); |
diff --git a/tmk_core/common/host.c b/tmk_core/common/host.c index f0c396b18..56d4bb084 100644 --- a/tmk_core/common/host.c +++ b/tmk_core/common/host.c | |||
| @@ -30,8 +30,9 @@ extern keymap_config_t keymap_config; | |||
| 30 | #endif | 30 | #endif |
| 31 | 31 | ||
| 32 | static host_driver_t *driver; | 32 | static host_driver_t *driver; |
| 33 | static uint16_t last_system_report = 0; | 33 | static uint16_t last_system_report = 0; |
| 34 | static uint16_t last_consumer_report = 0; | 34 | static uint16_t last_consumer_report = 0; |
| 35 | static uint32_t last_programmable_button_report = 0; | ||
| 35 | 36 | ||
| 36 | void host_set_driver(host_driver_t *d) { driver = d; } | 37 | void host_set_driver(host_driver_t *d) { driver = d; } |
| 37 | 38 | ||
| @@ -122,6 +123,16 @@ void host_digitizer_send(digitizer_t *digitizer) { | |||
| 122 | 123 | ||
| 123 | __attribute__((weak)) void send_digitizer(report_digitizer_t *report) {} | 124 | __attribute__((weak)) void send_digitizer(report_digitizer_t *report) {} |
| 124 | 125 | ||
| 126 | void host_programmable_button_send(uint32_t report) { | ||
| 127 | if (report == last_programmable_button_report) return; | ||
| 128 | last_programmable_button_report = report; | ||
| 129 | |||
| 130 | if (!driver) return; | ||
| 131 | (*driver->send_programmable_button)(report); | ||
| 132 | } | ||
| 133 | |||
| 125 | uint16_t host_last_system_report(void) { return last_system_report; } | 134 | uint16_t host_last_system_report(void) { return last_system_report; } |
| 126 | 135 | ||
| 127 | uint16_t host_last_consumer_report(void) { return last_consumer_report; } | 136 | uint16_t host_last_consumer_report(void) { return last_consumer_report; } |
| 137 | |||
| 138 | uint32_t host_last_programmable_button_report(void) { return last_programmable_button_report; } | ||
diff --git a/tmk_core/common/host.h b/tmk_core/common/host.h index 2cffef6e1..6b15f0d0c 100644 --- a/tmk_core/common/host.h +++ b/tmk_core/common/host.h | |||
| @@ -47,9 +47,11 @@ void host_keyboard_send(report_keyboard_t *report); | |||
| 47 | void host_mouse_send(report_mouse_t *report); | 47 | void host_mouse_send(report_mouse_t *report); |
| 48 | void host_system_send(uint16_t data); | 48 | void host_system_send(uint16_t data); |
| 49 | void host_consumer_send(uint16_t data); | 49 | void host_consumer_send(uint16_t data); |
| 50 | void host_programmable_button_send(uint32_t data); | ||
| 50 | 51 | ||
| 51 | uint16_t host_last_system_report(void); | 52 | uint16_t host_last_system_report(void); |
| 52 | uint16_t host_last_consumer_report(void); | 53 | uint16_t host_last_consumer_report(void); |
| 54 | uint32_t host_last_programmable_button_report(void); | ||
| 53 | 55 | ||
| 54 | #ifdef __cplusplus | 56 | #ifdef __cplusplus |
| 55 | } | 57 | } |
diff --git a/tmk_core/common/host_driver.h b/tmk_core/common/host_driver.h index 2aebca043..affd0dcb3 100644 --- a/tmk_core/common/host_driver.h +++ b/tmk_core/common/host_driver.h | |||
| @@ -29,6 +29,7 @@ typedef struct { | |||
| 29 | void (*send_mouse)(report_mouse_t *); | 29 | void (*send_mouse)(report_mouse_t *); |
| 30 | void (*send_system)(uint16_t); | 30 | void (*send_system)(uint16_t); |
| 31 | void (*send_consumer)(uint16_t); | 31 | void (*send_consumer)(uint16_t); |
| 32 | void (*send_programmable_button)(uint32_t); | ||
| 32 | } host_driver_t; | 33 | } host_driver_t; |
| 33 | 34 | ||
| 34 | void send_digitizer(report_digitizer_t *report); \ No newline at end of file | 35 | void send_digitizer(report_digitizer_t *report); \ No newline at end of file |
diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h index f2223e806..1adc892f3 100644 --- a/tmk_core/common/report.h +++ b/tmk_core/common/report.h | |||
| @@ -29,6 +29,7 @@ enum hid_report_ids { | |||
| 29 | REPORT_ID_MOUSE, | 29 | REPORT_ID_MOUSE, |
| 30 | REPORT_ID_SYSTEM, | 30 | REPORT_ID_SYSTEM, |
| 31 | REPORT_ID_CONSUMER, | 31 | REPORT_ID_CONSUMER, |
| 32 | REPORT_ID_PROGRAMMABLE_BUTTON, | ||
| 32 | REPORT_ID_NKRO, | 33 | REPORT_ID_NKRO, |
| 33 | REPORT_ID_JOYSTICK, | 34 | REPORT_ID_JOYSTICK, |
| 34 | REPORT_ID_DIGITIZER | 35 | REPORT_ID_DIGITIZER |
| @@ -196,6 +197,11 @@ typedef struct { | |||
| 196 | } __attribute__((packed)) report_extra_t; | 197 | } __attribute__((packed)) report_extra_t; |
| 197 | 198 | ||
| 198 | typedef struct { | 199 | typedef struct { |
| 200 | uint8_t report_id; | ||
| 201 | uint32_t usage; | ||
| 202 | } __attribute__((packed)) report_programmable_button_t; | ||
| 203 | |||
| 204 | typedef struct { | ||
| 199 | #ifdef MOUSE_SHARED_EP | 205 | #ifdef MOUSE_SHARED_EP |
| 200 | uint8_t report_id; | 206 | uint8_t report_id; |
| 201 | #endif | 207 | #endif |
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 5b56e8a03..cb3aa693b 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c | |||
| @@ -142,7 +142,8 @@ static void send_keyboard(report_keyboard_t *report); | |||
| 142 | static void send_mouse(report_mouse_t *report); | 142 | static void send_mouse(report_mouse_t *report); |
| 143 | static void send_system(uint16_t data); | 143 | static void send_system(uint16_t data); |
| 144 | static void send_consumer(uint16_t data); | 144 | static void send_consumer(uint16_t data); |
| 145 | host_driver_t lufa_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer}; | 145 | static void send_programmable_button(uint32_t data); |
| 146 | host_driver_t lufa_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer, send_programmable_button}; | ||
| 146 | 147 | ||
| 147 | #ifdef VIRTSER_ENABLE | 148 | #ifdef VIRTSER_ENABLE |
| 148 | // clang-format off | 149 | // clang-format off |
| @@ -760,27 +761,31 @@ static void send_mouse(report_mouse_t *report) { | |||
| 760 | #endif | 761 | #endif |
| 761 | } | 762 | } |
| 762 | 763 | ||
| 763 | /** \brief Send Extra | 764 | static void send_report(void *report, size_t size) { |
| 764 | * | ||
| 765 | * FIXME: Needs doc | ||
| 766 | */ | ||
| 767 | #ifdef EXTRAKEY_ENABLE | ||
| 768 | static void send_extra(uint8_t report_id, uint16_t data) { | ||
| 769 | uint8_t timeout = 255; | 765 | uint8_t timeout = 255; |
| 770 | 766 | ||
| 771 | if (USB_DeviceState != DEVICE_STATE_Configured) return; | 767 | if (USB_DeviceState != DEVICE_STATE_Configured) return; |
| 772 | 768 | ||
| 773 | static report_extra_t r; | ||
| 774 | r = (report_extra_t){.report_id = report_id, .usage = data}; | ||
| 775 | Endpoint_SelectEndpoint(SHARED_IN_EPNUM); | 769 | Endpoint_SelectEndpoint(SHARED_IN_EPNUM); |
| 776 | 770 | ||
| 777 | /* Check if write ready for a polling interval around 10ms */ | 771 | /* Check if write ready for a polling interval around 10ms */ |
| 778 | while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); | 772 | while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); |
| 779 | if (!Endpoint_IsReadWriteAllowed()) return; | 773 | if (!Endpoint_IsReadWriteAllowed()) return; |
| 780 | 774 | ||
| 781 | Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); | 775 | Endpoint_Write_Stream_LE(report, size, NULL); |
| 782 | Endpoint_ClearIN(); | 776 | Endpoint_ClearIN(); |
| 783 | } | 777 | } |
| 778 | |||
| 779 | /** \brief Send Extra | ||
| 780 | * | ||
| 781 | * FIXME: Needs doc | ||
| 782 | */ | ||
| 783 | #ifdef EXTRAKEY_ENABLE | ||
| 784 | static void send_extra(uint8_t report_id, uint16_t data) { | ||
| 785 | static report_extra_t r; | ||
| 786 | r = (report_extra_t){.report_id = report_id, .usage = data}; | ||
| 787 | send_report(&r, sizeof(r)); | ||
| 788 | } | ||
| 784 | #endif | 789 | #endif |
| 785 | 790 | ||
| 786 | /** \brief Send System | 791 | /** \brief Send System |
| @@ -822,6 +827,14 @@ static void send_consumer(uint16_t data) { | |||
| 822 | #endif | 827 | #endif |
| 823 | } | 828 | } |
| 824 | 829 | ||
| 830 | static void send_programmable_button(uint32_t data) { | ||
| 831 | #ifdef PROGRAMMABLE_BUTTON_ENABLE | ||
| 832 | static report_programmable_button_t r; | ||
| 833 | r = (report_programmable_button_t){.report_id = REPORT_ID_PROGRAMMABLE_BUTTON, .usage = data}; | ||
| 834 | send_report(&r, sizeof(r)); | ||
| 835 | #endif | ||
| 836 | } | ||
| 837 | |||
| 825 | /******************************************************************************* | 838 | /******************************************************************************* |
| 826 | * sendchar | 839 | * sendchar |
| 827 | ******************************************************************************/ | 840 | ******************************************************************************/ |
diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c index 099964ae5..f720eea8d 100644 --- a/tmk_core/protocol/usb_descriptor.c +++ b/tmk_core/protocol/usb_descriptor.c | |||
| @@ -237,6 +237,25 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = { | |||
| 237 | HID_RI_END_COLLECTION(0), | 237 | HID_RI_END_COLLECTION(0), |
| 238 | #endif | 238 | #endif |
| 239 | 239 | ||
| 240 | #ifdef PROGRAMMABLE_BUTTON_ENABLE | ||
| 241 | HID_RI_USAGE_PAGE(8, 0x0C), // Consumer | ||
| 242 | HID_RI_USAGE(8, 0x01), // Consumer Control | ||
| 243 | HID_RI_COLLECTION(8, 0x01), // Application | ||
| 244 | HID_RI_REPORT_ID(8, REPORT_ID_PROGRAMMABLE_BUTTON), | ||
| 245 | HID_RI_USAGE(8, 0x09), // Programmable Buttons | ||
| 246 | HID_RI_COLLECTION(8, 0x04), // Named Array | ||
| 247 | HID_RI_USAGE_PAGE(8, 0x09), // Button | ||
| 248 | HID_RI_USAGE_MINIMUM(8, 0x01), // Button 1 | ||
| 249 | HID_RI_USAGE_MAXIMUM(8, 0x20), // Button 32 | ||
| 250 | HID_RI_LOGICAL_MINIMUM(8, 0x01), | ||
| 251 | HID_RI_LOGICAL_MAXIMUM(8, 0x01), | ||
| 252 | HID_RI_REPORT_COUNT(8, 32), | ||
| 253 | HID_RI_REPORT_SIZE(8, 1), | ||
| 254 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), | ||
| 255 | HID_RI_END_COLLECTION(0), | ||
| 256 | HID_RI_END_COLLECTION(0), | ||
| 257 | #endif | ||
| 258 | |||
| 240 | #ifdef NKRO_ENABLE | 259 | #ifdef NKRO_ENABLE |
| 241 | HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop | 260 | HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop |
| 242 | HID_RI_USAGE(8, 0x06), // Keyboard | 261 | HID_RI_USAGE(8, 0x06), // Keyboard |
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index 485b20c90..e4db5d065 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c | |||
| @@ -226,8 +226,9 @@ static void send_keyboard(report_keyboard_t *report); | |||
| 226 | static void send_mouse(report_mouse_t *report); | 226 | static void send_mouse(report_mouse_t *report); |
| 227 | static void send_system(uint16_t data); | 227 | static void send_system(uint16_t data); |
| 228 | static void send_consumer(uint16_t data); | 228 | static void send_consumer(uint16_t data); |
| 229 | static void send_programmable_button(uint32_t data); | ||
| 229 | 230 | ||
| 230 | static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer}; | 231 | static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer, send_programmable_button}; |
| 231 | 232 | ||
| 232 | host_driver_t *vusb_driver(void) { return &driver; } | 233 | host_driver_t *vusb_driver(void) { return &driver; } |
| 233 | 234 | ||
| @@ -296,6 +297,19 @@ void send_digitizer(report_digitizer_t *report) { | |||
| 296 | #ifdef DIGITIZER_ENABLE | 297 | #ifdef DIGITIZER_ENABLE |
| 297 | if (usbInterruptIsReadyShared()) { | 298 | if (usbInterruptIsReadyShared()) { |
| 298 | usbSetInterruptShared((void *)report, sizeof(report_digitizer_t)); | 299 | usbSetInterruptShared((void *)report, sizeof(report_digitizer_t)); |
| 300 | #endif | ||
| 301 | } | ||
| 302 | |||
| 303 | static void send_programmable_button(uint32_t data) { | ||
| 304 | #ifdef PROGRAMMABLE_BUTTON_ENABLE | ||
| 305 | static report_programmable_button_t report = { | ||
| 306 | .report_id = REPORT_ID_PROGRAMMABLE_BUTTON, | ||
| 307 | }; | ||
| 308 | |||
| 309 | report.usage = data; | ||
| 310 | |||
| 311 | if (usbInterruptIsReadyShared()) { | ||
| 312 | usbSetInterruptShared((void *)&report, sizeof(report)); | ||
| 299 | } | 313 | } |
| 300 | #endif | 314 | #endif |
| 301 | } | 315 | } |
| @@ -558,6 +572,26 @@ const PROGMEM uchar shared_hid_report[] = { | |||
| 558 | 0xC0 // End Collection | 572 | 0xC0 // End Collection |
| 559 | #endif | 573 | #endif |
| 560 | 574 | ||
| 575 | #ifdef PROGRAMMABLE_BUTTON_ENABLE | ||
| 576 | // Programmable buttons report descriptor | ||
| 577 | 0x05, 0x0C, // Usage Page (Consumer) | ||
| 578 | 0x09, 0x01, // Usage (Consumer Control) | ||
| 579 | 0xA1, 0x01, // Collection (Application) | ||
| 580 | 0x85, REPORT_ID_PROGRAMMABLE_BUTTON, // Report ID | ||
| 581 | 0x09, 0x03, // Usage (Programmable Buttons) | ||
| 582 | 0xA1, 0x04, // Collection (Named Array) | ||
| 583 | 0x05, 0x09, // Usage Page (Button) | ||
| 584 | 0x19, 0x01, // Usage Minimum (Button 1) | ||
| 585 | 0x29, 0x20, // Usage Maximum (Button 32) | ||
| 586 | 0x15, 0x00, // Logical Minimum (0) | ||
| 587 | 0x25, 0x01, // Logical Maximum (1) | ||
| 588 | 0x95, 0x20, // Report Count (32) | ||
| 589 | 0x75, 0x01, // Report Size (1) | ||
| 590 | 0x81, 0x02, // Input (Data, Variable, Absolute) | ||
| 591 | 0xC0, // End Collection | ||
| 592 | 0xC0 // End Collection | ||
| 593 | #endif | ||
| 594 | |||
| 561 | #ifdef SHARED_EP_ENABLE | 595 | #ifdef SHARED_EP_ENABLE |
| 562 | }; | 596 | }; |
| 563 | #endif | 597 | #endif |
