diff options
author | Ryan <fauxpark@gmail.com> | 2022-11-27 03:14:45 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-27 03:14:45 +1100 |
commit | 1e95f7be8f214c544bf99f415916a4a5f07a1e9b (patch) | |
tree | 99e7148ab4c464f40da8f0ee01e079843a26cf14 /tmk_core/protocol | |
parent | a5a20cc792540c0de61f064bd8dafcdc5815d4cc (diff) |
Joystick feature improvements (#19052)
Diffstat (limited to 'tmk_core/protocol')
-rw-r--r-- | tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c | 24 | ||||
-rw-r--r-- | tmk_core/protocol/chibios/usb_main.c | 4 | ||||
-rw-r--r-- | tmk_core/protocol/host.c | 15 | ||||
-rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 2 | ||||
-rw-r--r-- | tmk_core/protocol/report.h | 11 | ||||
-rw-r--r-- | tmk_core/protocol/usb_descriptor.c | 134 | ||||
-rw-r--r-- | tmk_core/protocol/usb_descriptor.h | 8 | ||||
-rw-r--r-- | tmk_core/protocol/usb_descriptor_common.h | 5 | ||||
-rw-r--r-- | tmk_core/protocol/vusb/vusb.c | 77 |
9 files changed, 185 insertions, 95 deletions
diff --git a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c index 5d681a8b71..bf190b1f18 100644 --- a/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c +++ b/tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c @@ -637,20 +637,20 @@ static uint8_t udi_hid_raw_report_recv[UDI_HID_RAW_REPORT_SIZE]; COMPILER_WORD_ALIGNED UDC_DESC_STORAGE udi_hid_raw_report_desc_t udi_hid_raw_report_desc = {{ - 0x06, RAW_USAGE_PAGE_LO, RAW_USAGE_PAGE_HI, // Usage Page (Vendor Defined) - 0x09, RAW_USAGE_ID, // Usage (Vendor Defined) - 0xA1, 0x01, // Collection (Application) - 0x75, 0x08, // Report Size (8) - 0x15, 0x00, // Logical Minimum (0) - 0x25, 0xFF, // Logical Maximum (255) + 0x06, HID_VALUE_16(RAW_USAGE_PAGE), // Usage Page (Vendor Defined) + 0x09, RAW_USAGE_ID, // Usage (Vendor Defined) + 0xA1, 0x01, // Collection (Application) + 0x75, 0x08, // Report Size (8) + 0x15, 0x00, // Logical Minimum (0) + 0x25, 0xFF, // Logical Maximum (255) // Data to host - 0x09, 0x62, // Usage (Vendor Defined) - 0x95, RAW_EPSIZE, // Report Count - 0x81, 0x02, // Input (Data, Variable, Absolute) + 0x09, 0x62, // Usage (Vendor Defined) + 0x95, RAW_EPSIZE, // Report Count + 0x81, 0x02, // Input (Data, Variable, Absolute) // Data from host - 0x09, 0x63, // Usage (Vendor Defined) - 0x95, RAW_EPSIZE, // Report Count - 0x91, 0x02, // Output (Data, Variable, Absolute) + 0x09, 0x63, // Usage (Vendor Defined) + 0x95, RAW_EPSIZE, // Report Count + 0x91, 0x02, // Output (Data, Variable, Absolute) 0xC0 // End Collection }}; diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index fb3d575846..62a11faff7 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -183,7 +183,7 @@ static const USBEndpointConfig shared_ep_config = { }; #endif -#ifdef JOYSTICK_ENABLE +#if defined(JOYSTICK_ENABLE) && !defined(JOYSTICK_SHARED_EP) /* joystick endpoint state structure */ static USBInEndpointState joystick_ep_state; @@ -507,7 +507,7 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) { #ifdef SHARED_EP_ENABLE usbInitEndpointI(usbp, SHARED_IN_EPNUM, &shared_ep_config); #endif -#ifdef JOYSTICK_ENABLE +#if defined(JOYSTICK_ENABLE) && !defined(JOYSTICK_SHARED_EP) usbInitEndpointI(usbp, JOYSTICK_IN_EPNUM, &joystick_ep_config); #endif #if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP) diff --git a/tmk_core/protocol/host.c b/tmk_core/protocol/host.c index 5fee872326..2c6654e9a6 100644 --- a/tmk_core/protocol/host.c +++ b/tmk_core/protocol/host.c @@ -164,24 +164,27 @@ void host_joystick_send(joystick_t *joystick) { if (!driver) return; report_joystick_t report = { -# if JOYSTICK_AXES_COUNT > 0 +# ifdef JOYSTICK_SHARED_EP + .report_id = REPORT_ID_JOYSTICK, +# endif +# if JOYSTICK_AXIS_COUNT > 0 .axes = { joystick->axes[0], -# if JOYSTICK_AXES_COUNT >= 2 +# if JOYSTICK_AXIS_COUNT >= 2 joystick->axes[1], # endif -# if JOYSTICK_AXES_COUNT >= 3 +# if JOYSTICK_AXIS_COUNT >= 3 joystick->axes[2], # endif -# if JOYSTICK_AXES_COUNT >= 4 +# if JOYSTICK_AXIS_COUNT >= 4 joystick->axes[3], # endif -# if JOYSTICK_AXES_COUNT >= 5 +# if JOYSTICK_AXIS_COUNT >= 5 joystick->axes[4], # endif -# if JOYSTICK_AXES_COUNT >= 6 +# if JOYSTICK_AXIS_COUNT >= 6 joystick->axes[5], # endif }, diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index af49ed5909..8f36e02b9a 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -404,7 +404,7 @@ void EVENT_USB_Device_ConfigurationChanged(void) { ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, CDC_EPSIZE, 1); #endif -#ifdef JOYSTICK_ENABLE +#if defined(JOYSTICK_ENABLE) && !defined(JOYSTICK_SHARED_EP) /* Setup joystick endpoint */ ConfigSuccess &= Endpoint_ConfigureEndpoint((JOYSTICK_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, 1); #endif diff --git a/tmk_core/protocol/report.h b/tmk_core/protocol/report.h index 543c44e33c..e4526e4ee6 100644 --- a/tmk_core/protocol/report.h +++ b/tmk_core/protocol/report.h @@ -235,11 +235,14 @@ typedef struct { } __attribute__((packed)) report_digitizer_t; typedef struct { -#if JOYSTICK_AXES_COUNT > 0 -# if JOYSTICK_AXES_RESOLUTION > 8 - int16_t axes[JOYSTICK_AXES_COUNT]; +#ifdef JOYSTICK_SHARED_EP + uint8_t report_id; +#endif +#if JOYSTICK_AXIS_COUNT > 0 +# if JOYSTICK_AXIS_RESOLUTION > 8 + int16_t axes[JOYSTICK_AXIS_COUNT]; # else - int8_t axes[JOYSTICK_AXES_COUNT]; + int8_t axes[JOYSTICK_AXIS_COUNT]; # endif #endif diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c index 3c170f1112..99c52952a0 100644 --- a/tmk_core/protocol/usb_descriptor.c +++ b/tmk_core/protocol/usb_descriptor.c @@ -174,6 +174,75 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = { # endif #endif +#ifdef JOYSTICK_ENABLE +# ifndef JOYSTICK_SHARED_EP +const USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] = { +# elif !defined(SHARED_REPORT_STARTED) +const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = { +# define SHARED_REPORT_STARTED +# endif + HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop + HID_RI_USAGE(8, 0x04), // Joystick + HID_RI_COLLECTION(8, 0x01), // Application +# ifdef JOYSTICK_SHARED_EP + HID_RI_REPORT_ID(8, REPORT_ID_JOYSTICK), +# endif + HID_RI_COLLECTION(8, 0x00), // Physical +# if JOYSTICK_AXIS_COUNT > 0 + HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop + HID_RI_USAGE(8, 0x30), // X +# if JOYSTICK_AXIS_COUNT > 1 + HID_RI_USAGE(8, 0x31), // Y +# endif +# if JOYSTICK_AXIS_COUNT > 2 + HID_RI_USAGE(8, 0x32), // Z +# endif +# if JOYSTICK_AXIS_COUNT > 3 + HID_RI_USAGE(8, 0x33), // Rx +# endif +# if JOYSTICK_AXIS_COUNT > 4 + HID_RI_USAGE(8, 0x34), // Ry +# endif +# if JOYSTICK_AXIS_COUNT > 5 + HID_RI_USAGE(8, 0x35), // Rz +# endif +# if JOYSTICK_AXIS_RESOLUTION == 8 + HID_RI_LOGICAL_MINIMUM(8, -JOYSTICK_MAX_VALUE), + HID_RI_LOGICAL_MAXIMUM(8, JOYSTICK_MAX_VALUE), + HID_RI_REPORT_COUNT(8, JOYSTICK_AXIS_COUNT), + HID_RI_REPORT_SIZE(8, 0x08), +# else + HID_RI_LOGICAL_MINIMUM(16, -JOYSTICK_MAX_VALUE), + HID_RI_LOGICAL_MAXIMUM(16, JOYSTICK_MAX_VALUE), + HID_RI_REPORT_COUNT(8, JOYSTICK_AXIS_COUNT), + HID_RI_REPORT_SIZE(8, 0x10), +# endif + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), +# endif + +# if JOYSTICK_BUTTON_COUNT > 0 + HID_RI_USAGE_PAGE(8, 0x09), // Button + HID_RI_USAGE_MINIMUM(8, 0x01), + HID_RI_USAGE_MAXIMUM(8, JOYSTICK_BUTTON_COUNT), + HID_RI_LOGICAL_MINIMUM(8, 0x00), + HID_RI_LOGICAL_MAXIMUM(8, 0x01), + HID_RI_REPORT_COUNT(8, JOYSTICK_BUTTON_COUNT), + HID_RI_REPORT_SIZE(8, 0x01), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), + +# if (JOYSTICK_BUTTON_COUNT % 8) != 0 + HID_RI_REPORT_COUNT(8, 8 - (JOYSTICK_BUTTON_COUNT % 8)), + HID_RI_REPORT_SIZE(8, 0x01), + HID_RI_INPUT(8, HID_IOF_CONSTANT), +# endif +# endif + HID_RI_END_COLLECTION(0), + HID_RI_END_COLLECTION(0), +# ifndef JOYSTICK_SHARED_EP +}; +# endif +#endif + #ifdef DIGITIZER_ENABLE # ifndef DIGITIZER_SHARED_EP const USB_Descriptor_HIDReport_Datatype_t PROGMEM DigitizerReport[] = { @@ -360,65 +429,6 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = { }; #endif -#ifdef JOYSTICK_ENABLE -const USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] = { - HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop - HID_RI_USAGE(8, 0x04), // Joystick - HID_RI_COLLECTION(8, 0x01), // Application - HID_RI_COLLECTION(8, 0x00), // Physical -# if JOYSTICK_AXES_COUNT > 0 - HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop - HID_RI_USAGE(8, 0x30), // X -# if JOYSTICK_AXES_COUNT > 1 - HID_RI_USAGE(8, 0x31), // Y -# endif -# if JOYSTICK_AXES_COUNT > 2 - HID_RI_USAGE(8, 0x32), // Z -# endif -# if JOYSTICK_AXES_COUNT > 3 - HID_RI_USAGE(8, 0x33), // Rx -# endif -# if JOYSTICK_AXES_COUNT > 4 - HID_RI_USAGE(8, 0x34), // Ry -# endif -# if JOYSTICK_AXES_COUNT > 5 - HID_RI_USAGE(8, 0x35), // Rz -# endif -# if JOYSTICK_AXES_RESOLUTION == 8 - HID_RI_LOGICAL_MINIMUM(8, -JOYSTICK_RESOLUTION), - HID_RI_LOGICAL_MAXIMUM(8, JOYSTICK_RESOLUTION), - HID_RI_REPORT_COUNT(8, JOYSTICK_AXES_COUNT), - HID_RI_REPORT_SIZE(8, 0x08), -# else - HID_RI_LOGICAL_MINIMUM(16, -JOYSTICK_RESOLUTION), - HID_RI_LOGICAL_MAXIMUM(16, JOYSTICK_RESOLUTION), - HID_RI_REPORT_COUNT(8, JOYSTICK_AXES_COUNT), - HID_RI_REPORT_SIZE(8, 0x10), -# endif - HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), -# endif - -# if JOYSTICK_BUTTON_COUNT > 0 - HID_RI_USAGE_PAGE(8, 0x09), // Button - HID_RI_USAGE_MINIMUM(8, 0x01), - HID_RI_USAGE_MAXIMUM(8, JOYSTICK_BUTTON_COUNT), - HID_RI_LOGICAL_MINIMUM(8, 0x00), - HID_RI_LOGICAL_MAXIMUM(8, 0x01), - HID_RI_REPORT_COUNT(8, JOYSTICK_BUTTON_COUNT), - HID_RI_REPORT_SIZE(8, 0x01), - HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), - -# if (JOYSTICK_BUTTON_COUNT % 8) != 0 - HID_RI_REPORT_COUNT(8, 8 - (JOYSTICK_BUTTON_COUNT % 8)), - HID_RI_REPORT_SIZE(8, 0x01), - HID_RI_INPUT(8, HID_IOF_CONSTANT), -# endif -# endif - HID_RI_END_COLLECTION(0), - HID_RI_END_COLLECTION(0) -}; -#endif - /* * Device descriptor */ @@ -958,10 +968,10 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { }, #endif +#if defined(JOYSTICK_ENABLE) && !defined(JOYSTICK_SHARED_EP) /* * Joystick */ -#ifdef JOYSTICK_ENABLE .Joystick_Interface = { .Header = { .Size = sizeof(USB_Descriptor_Interface_t), @@ -1169,7 +1179,7 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const break; #endif -#ifdef JOYSTICK_ENABLE +#if defined(JOYSTICK_ENABLE) && !defined(JOYSTICK_SHARED_EP) case JOYSTICK_INTERFACE: Address = &ConfigurationDescriptor.Joystick_HID; Size = sizeof(USB_HID_Descriptor_HID_t); @@ -1226,7 +1236,7 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const break; #endif -#ifdef JOYSTICK_ENABLE +#if defined(JOYSTICK_ENABLE) && !defined(JOYSTICK_SHARED_EP) case JOYSTICK_INTERFACE: Address = &JoystickReport; Size = sizeof(JoystickReport); diff --git a/tmk_core/protocol/usb_descriptor.h b/tmk_core/protocol/usb_descriptor.h index 6e842f6984..bc5e84e586 100644 --- a/tmk_core/protocol/usb_descriptor.h +++ b/tmk_core/protocol/usb_descriptor.h @@ -132,7 +132,7 @@ typedef struct { USB_Descriptor_Endpoint_t CDC_DataInEndpoint; #endif -#ifdef JOYSTICK_ENABLE +#if defined(JOYSTICK_ENABLE) && !defined(JOYSTICK_SHARED_EP) // Joystick HID Interface USB_Descriptor_Interface_t Joystick_Interface; USB_HID_Descriptor_HID_t Joystick_HID; @@ -187,7 +187,7 @@ enum usb_interfaces { CDI_INTERFACE, #endif -#if defined(JOYSTICK_ENABLE) +#if defined(JOYSTICK_ENABLE) && !defined(JOYSTICK_SHARED_EP) JOYSTICK_INTERFACE, #endif @@ -267,7 +267,11 @@ enum usb_endpoints { #endif #ifdef JOYSTICK_ENABLE +# if !defined(JOYSTICK_SHARED_EP) JOYSTICK_IN_EPNUM = NEXT_EPNUM, +# else +# define JOYSTICK_IN_EPNUM SHARED_IN_EPNUM +# endif #endif #ifdef DIGITIZER_ENABLE diff --git a/tmk_core/protocol/usb_descriptor_common.h b/tmk_core/protocol/usb_descriptor_common.h index ce0cf09763..909c230a99 100644 --- a/tmk_core/protocol/usb_descriptor_common.h +++ b/tmk_core/protocol/usb_descriptor_common.h @@ -20,6 +20,8 @@ #define USBCONCAT(a, b) a##b #define USBSTR(s) USBCONCAT(L, s) +#define HID_VALUE_16(v) ((uint8_t)(v & 0xFF)), ((uint8_t)(v >> 8)) + ///////////////////// // RAW Usage page and ID configuration @@ -30,6 +32,3 @@ #ifndef RAW_USAGE_ID # define RAW_USAGE_ID 0x61 #endif - -#define RAW_USAGE_PAGE_HI ((uint8_t)(RAW_USAGE_PAGE >> 8)) -#define RAW_USAGE_PAGE_LO ((uint8_t)(RAW_USAGE_PAGE & 0xFF)) diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index ac35043e2a..2d17761978 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -35,6 +35,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. # include "raw_hid.h" #endif +#ifdef JOYSTICK_ENABLE +# include "joystick.h" +#endif + #if defined(CONSOLE_ENABLE) # define RBUF_SIZE 128 # include "ring_buffer.h" @@ -275,6 +279,14 @@ static void send_extra(report_extra_t *report) { #endif } +void send_joystick(report_joystick_t *report) { +#ifdef JOYSTICK_ENABLE + if (usbInterruptIsReadyShared()) { + usbSetInterruptShared((void *)report, sizeof(report_joystick_t)); + } +#endif +} + void send_digitizer(report_digitizer_t *report) { #ifdef DIGITIZER_ENABLE if (usbInterruptIsReadyShared()) { @@ -526,6 +538,65 @@ const PROGMEM uchar shared_hid_report[] = { 0xC0, // End Collection #endif +#ifdef JOYSTICK_ENABLE + // Joystick report descriptor + 0x05, 0x01, // Usage Page (Generic Desktop) + 0x09, 0x04, // Usage (Joystick) + 0xA1, 0x01, // Collection (Application) + 0x85, REPORT_ID_JOYSTICK, // Report ID + 0xA1, 0x00, // Collection (Physical) +# if JOYSTICK_AXIS_COUNT > 0 + 0x05, 0x01, // Usage Page (Generic Desktop) + 0x09, 0x30, // Usage (X) +# if JOYSTICK_AXIS_COUNT > 1 + 0x09, 0x31, // Usage (Y) +# endif +# if JOYSTICK_AXIS_COUNT > 2 + 0x09, 0x32, // Usage (Z) +# endif +# if JOYSTICK_AXIS_COUNT > 3 + 0x09, 0x33, // Usage (Rx) +# endif +# if JOYSTICK_AXIS_COUNT > 4 + 0x09, 0x34, // Usage (Ry) +# endif +# if JOYSTICK_AXIS_COUNT > 5 + 0x09, 0x35, // Usage (Rz) +# endif +# if JOYSTICK_AXIS_RESOLUTION == 8 + 0x15, -JOYSTICK_MAX_VALUE, // Logical Minimum + 0x25, JOYSTICK_MAX_VALUE, // Logical Maximum + 0x95, JOYSTICK_AXIS_COUNT, // Report Count + 0x75, 0x08, // Report Size (8) +# else + 0x16, HID_VALUE_16(-JOYSTICK_MAX_VALUE), // Logical Minimum + 0x26, HID_VALUE_16(JOYSTICK_MAX_VALUE), // Logical Maximum + 0x95, JOYSTICK_AXIS_COUNT, // Report Count + 0x75, 0x10, // Report Size (16) +# endif + 0x81, 0x02, // Input (Data, Variable, Absolute) +# endif + +# if JOYSTICK_BUTTON_COUNT > 0 + 0x05, 0x09, // Usage Page (Button) + 0x19, 0x01, // Usage Minimum (Button 1) + 0x29, JOYSTICK_BUTTON_COUNT, // Usage Maximum + 0x15, 0x00, // Logical Minimum (0) + 0x25, 0x01, // Logical Maximum (1) + 0x95, JOYSTICK_BUTTON_COUNT, // Report Count + 0x75, 0x01, // Report Size (1) + 0x81, 0x02, // Input (Data, Variable, Absolute) + +# if (JOYSTICK_BUTTON_COUNT % 8) != 0 + 0x95, 8 - (JOYSTICK_BUTTON_COUNT % 8), // Report Count + 0x75, 0x01, // Report Size (1) + 0x81, 0x03, // Input (Constant) +# endif +# endif + 0xC0, // End Collection + 0xC0, // End Collection +#endif + #ifdef DIGITIZER_ENABLE // Digitizer report descriptor 0x05, 0x0D, // Usage Page (Digitizers) @@ -587,9 +658,9 @@ const PROGMEM uchar shared_hid_report[] = { #ifdef RAW_ENABLE const PROGMEM uchar raw_hid_report[] = { - 0x06, RAW_USAGE_PAGE_LO, RAW_USAGE_PAGE_HI, // Usage Page (Vendor Defined) - 0x09, RAW_USAGE_ID, // Usage (Vendor Defined) - 0xA1, 0x01, // Collection (Application) + 0x06, HID_VALUE_16(RAW_USAGE_PAGE), // Usage Page (Vendor Defined) + 0x09, RAW_USAGE_ID, // Usage (Vendor Defined) + 0xA1, 0x01, // Collection (Application) // Data to host 0x09, 0x62, // Usage (Vendor Defined) 0x15, 0x00, // Logical Minimum (0) |