diff options
| author | Ryan <fauxpark@gmail.com> | 2024-11-10 09:10:10 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-09 14:10:10 -0800 |
| commit | a3cfb1dab7679a774d8aa09f7b609f3302dad73d (patch) | |
| tree | 315e8c7a35ae390b56f84def0d37b867bfa428c7 /tmk_core/protocol | |
| parent | 69093f6de9b551bd84ff0a8eabcccca73026d55e (diff) | |
Joystick: add support for 8-way hat switch (#24515)
Diffstat (limited to 'tmk_core/protocol')
| -rw-r--r-- | tmk_core/protocol/host.c | 4 | ||||
| -rw-r--r-- | tmk_core/protocol/report.h | 5 | ||||
| -rw-r--r-- | tmk_core/protocol/usb_descriptor.c | 17 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/vusb.c | 17 |
4 files changed, 43 insertions, 0 deletions
diff --git a/tmk_core/protocol/host.c b/tmk_core/protocol/host.c index 732fbdc37d..df805c827c 100644 --- a/tmk_core/protocol/host.c +++ b/tmk_core/protocol/host.c | |||
| @@ -193,6 +193,10 @@ void host_joystick_send(joystick_t *joystick) { | |||
| 193 | }, | 193 | }, |
| 194 | # endif | 194 | # endif |
| 195 | 195 | ||
| 196 | # ifdef JOYSTICK_HAS_HAT | ||
| 197 | .hat = joystick->hat, | ||
| 198 | # endif | ||
| 199 | |||
| 196 | # if JOYSTICK_BUTTON_COUNT > 0 | 200 | # if JOYSTICK_BUTTON_COUNT > 0 |
| 197 | .buttons = | 201 | .buttons = |
| 198 | { | 202 | { |
diff --git a/tmk_core/protocol/report.h b/tmk_core/protocol/report.h index 37c8ea48f1..d854f51d5c 100644 --- a/tmk_core/protocol/report.h +++ b/tmk_core/protocol/report.h | |||
| @@ -246,6 +246,11 @@ typedef struct { | |||
| 246 | joystick_axis_t axes[JOYSTICK_AXIS_COUNT]; | 246 | joystick_axis_t axes[JOYSTICK_AXIS_COUNT]; |
| 247 | #endif | 247 | #endif |
| 248 | 248 | ||
| 249 | #ifdef JOYSTICK_HAS_HAT | ||
| 250 | int8_t hat : 4; | ||
| 251 | uint8_t reserved : 4; | ||
| 252 | #endif | ||
| 253 | |||
| 249 | #if JOYSTICK_BUTTON_COUNT > 0 | 254 | #if JOYSTICK_BUTTON_COUNT > 0 |
| 250 | uint8_t buttons[(JOYSTICK_BUTTON_COUNT - 1) / 8 + 1]; | 255 | uint8_t buttons[(JOYSTICK_BUTTON_COUNT - 1) / 8 + 1]; |
| 251 | #endif | 256 | #endif |
diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c index e7d12a07d9..c7fb660b65 100644 --- a/tmk_core/protocol/usb_descriptor.c +++ b/tmk_core/protocol/usb_descriptor.c | |||
| @@ -247,6 +247,23 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = { | |||
| 247 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), | 247 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), |
| 248 | # endif | 248 | # endif |
| 249 | 249 | ||
| 250 | # ifdef JOYSTICK_HAS_HAT | ||
| 251 | // Hat Switch (4 bits) | ||
| 252 | HID_RI_USAGE(8, 0x39), // Hat Switch | ||
| 253 | HID_RI_LOGICAL_MINIMUM(8, 0x00), | ||
| 254 | HID_RI_LOGICAL_MAXIMUM(8, 0x07), | ||
| 255 | HID_RI_PHYSICAL_MINIMUM(8, 0), | ||
| 256 | HID_RI_PHYSICAL_MAXIMUM(16, 315), | ||
| 257 | HID_RI_UNIT(8, 0x14), // Degree, English Rotation | ||
| 258 | HID_RI_REPORT_COUNT(8, 1), | ||
| 259 | HID_RI_REPORT_SIZE(8, 4), | ||
| 260 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NULLSTATE), | ||
| 261 | // Padding (4 bits) | ||
| 262 | HID_RI_REPORT_COUNT(8, 0x04), | ||
| 263 | HID_RI_REPORT_SIZE(8, 0x01), | ||
| 264 | HID_RI_INPUT(8, HID_IOF_CONSTANT), | ||
| 265 | # endif | ||
| 266 | |||
| 250 | # if JOYSTICK_BUTTON_COUNT > 0 | 267 | # if JOYSTICK_BUTTON_COUNT > 0 |
| 251 | HID_RI_USAGE_PAGE(8, 0x09), // Button | 268 | HID_RI_USAGE_PAGE(8, 0x09), // Button |
| 252 | HID_RI_USAGE_MINIMUM(8, 0x01), | 269 | HID_RI_USAGE_MINIMUM(8, 0x01), |
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index 2a29fe65d9..fdbfcc17dc 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c | |||
| @@ -621,6 +621,23 @@ const PROGMEM uchar shared_hid_report[] = { | |||
| 621 | 0x81, 0x02, // Input (Data, Variable, Absolute) | 621 | 0x81, 0x02, // Input (Data, Variable, Absolute) |
| 622 | # endif | 622 | # endif |
| 623 | 623 | ||
| 624 | # ifdef JOYSTICK_HAS_HAT | ||
| 625 | // Hat Switch (4 bits) | ||
| 626 | 0x09, 0x39, // Usage (Hat Switch) | ||
| 627 | 0x15, 0x00, // Logical Minimum (0) | ||
| 628 | 0x25, 0x07, // Logical Maximum (7) | ||
| 629 | 0x35, 0x00, // Physical Minimum (0) | ||
| 630 | 0x46, 0x3B, 0x01, // Physical Maximum (315) | ||
| 631 | 0x65, 0x14, // Unit (Degree, English Rotation) | ||
| 632 | 0x95, 0x01, // Report Count (1) | ||
| 633 | 0x75, 0x04, // Report Size (4) | ||
| 634 | 0x81, 0x42, // Input (Data, Variable, Absolute, Null State) | ||
| 635 | // Padding (4 bits) | ||
| 636 | 0x95, 0x04, // Report Count (4) | ||
| 637 | 0x75, 0x01, // Report Size (1) | ||
| 638 | 0x81, 0x01, // Input (Constant) | ||
| 639 | # endif | ||
| 640 | |||
| 624 | # if JOYSTICK_BUTTON_COUNT > 0 | 641 | # if JOYSTICK_BUTTON_COUNT > 0 |
| 625 | 0x05, 0x09, // Usage Page (Button) | 642 | 0x05, 0x09, // Usage Page (Button) |
| 626 | 0x19, 0x01, // Usage Minimum (Button 1) | 643 | 0x19, 0x01, // Usage Minimum (Button 1) |
