aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/protocol
diff options
context:
space:
mode:
authorThomas Weißschuh <thomas@t-8ch.de>2021-09-15 17:40:22 +0200
committerGitHub <noreply@github.com>2021-09-15 08:40:22 -0700
commit83988597f4d916a37b2b0987f393ceaa007532eb (patch)
treeba5d07ccf743cb27bee77b4d6cd2128035ce365e /tmk_core/protocol
parent1a68feb842ebcc6a7d1aef7cd7f83865cc18fab1 (diff)
downloadqmk_firmware-83988597f4d916a37b2b0987f393ceaa007532eb.tar.gz
qmk_firmware-83988597f4d916a37b2b0987f393ceaa007532eb.zip
Add Support for USB programmable buttons (#12950)
Diffstat (limited to 'tmk_core/protocol')
-rw-r--r--tmk_core/protocol/lufa/lufa.c33
-rw-r--r--tmk_core/protocol/usb_descriptor.c19
-rw-r--r--tmk_core/protocol/vusb/vusb.c36
3 files changed, 77 insertions, 11 deletions
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);
142static void send_mouse(report_mouse_t *report); 142static void send_mouse(report_mouse_t *report);
143static void send_system(uint16_t data); 143static void send_system(uint16_t data);
144static void send_consumer(uint16_t data); 144static void send_consumer(uint16_t data);
145host_driver_t lufa_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer}; 145static void send_programmable_button(uint32_t data);
146host_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 764static void send_report(void *report, size_t size) {
764 *
765 * FIXME: Needs doc
766 */
767#ifdef EXTRAKEY_ENABLE
768static 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
784static 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
830static 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);
226static void send_mouse(report_mouse_t *report); 226static void send_mouse(report_mouse_t *report);
227static void send_system(uint16_t data); 227static void send_system(uint16_t data);
228static void send_consumer(uint16_t data); 228static void send_consumer(uint16_t data);
229static void send_programmable_button(uint32_t data);
229 230
230static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer}; 231static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer, send_programmable_button};
231 232
232host_driver_t *vusb_driver(void) { return &driver; } 233host_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
303static 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