aboutsummaryrefslogtreecommitdiffstats
path: root/tmk_core/protocol/usb_descriptor.c
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/protocol/usb_descriptor.c')
-rw-r--r--tmk_core/protocol/usb_descriptor.c111
1 files changed, 110 insertions, 1 deletions
diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c
index bcca24586..f5d32445d 100644
--- a/tmk_core/protocol/usb_descriptor.c
+++ b/tmk_core/protocol/usb_descriptor.c
@@ -279,6 +279,63 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = {
};
#endif
+#ifdef JOYSTICK_ENABLE
+# if JOYSTICK_AXES_COUNT == 0 && JOYSTICK_BUTTON_COUNT == 0
+# error Need at least one axis or button for joystick
+# endif
+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
+ HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
+# if JOYSTICK_AXES_COUNT >= 1
+ HID_RI_USAGE(8, 0x30), // X
+# endif
+# if JOYSTICK_AXES_COUNT >= 2
+ HID_RI_USAGE(8, 0x31), // Y
+# endif
+# if JOYSTICK_AXES_COUNT >= 3
+ HID_RI_USAGE(8, 0x32), // Z
+# endif
+# if JOYSTICK_AXES_COUNT >= 4
+ HID_RI_USAGE(8, 0x33), // Rx
+# endif
+# if JOYSTICK_AXES_COUNT >= 5
+ HID_RI_USAGE(8, 0x34), // Ry
+# endif
+# if JOYSTICK_AXES_COUNT >= 6
+ HID_RI_USAGE(8, 0x35), // Rz
+# endif
+# if JOYSTICK_AXES_COUNT >= 1
+ HID_RI_LOGICAL_MINIMUM(8, -127),
+ HID_RI_LOGICAL_MAXIMUM(8, 127),
+ HID_RI_REPORT_COUNT(8, JOYSTICK_AXES_COUNT),
+ HID_RI_REPORT_SIZE(8, 0x08),
+ HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
+# endif
+
+# if JOYSTICK_BUTTON_COUNT >= 1
+ 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
*/
@@ -288,7 +345,7 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = {
.Type = DTYPE_Device
},
.USBSpecification = VERSION_BCD(1, 1, 0),
-
+
#if VIRTSER_ENABLE
.Class = USB_CSCP_IADDeviceClass,
.SubClass = USB_CSCP_IADDeviceSubclass,
@@ -813,6 +870,46 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
.PollingIntervalMS = 0x05
},
#endif
+
+ /*
+ * Joystick
+ */
+#ifdef JOYSTICK_ENABLE
+ .Joystick_Interface = {
+ .Header = {
+ .Size = sizeof(USB_Descriptor_Interface_t),
+ .Type = DTYPE_Interface
+ },
+ .InterfaceNumber = JOYSTICK_INTERFACE,
+ .AlternateSetting = 0x00,
+ .TotalEndpoints = 1,
+ .Class = HID_CSCP_HIDClass,
+ .SubClass = HID_CSCP_NonBootSubclass,
+ .Protocol = HID_CSCP_NonBootProtocol,
+ .InterfaceStrIndex = NO_DESCRIPTOR
+ },
+ .Joystick_HID = {
+ .Header = {
+ .Size = sizeof(USB_HID_Descriptor_HID_t),
+ .Type = HID_DTYPE_HID
+ },
+ .HIDSpec = VERSION_BCD(1, 1, 1),
+ .CountryCode = 0x00,
+ .TotalReportDescriptors = 1,
+ .HIDReportType = HID_DTYPE_Report,
+ .HIDReportLength = sizeof(JoystickReport)
+ },
+ .Joystick_INEndpoint = {
+ .Header = {
+ .Size = sizeof(USB_Descriptor_Endpoint_t),
+ .Type = DTYPE_Endpoint
+ },
+ .EndpointAddress = (ENDPOINT_DIR_IN | JOYSTICK_IN_EPNUM),
+ .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
+ .EndpointSize = JOYSTICK_EPSIZE,
+ .PollingIntervalMS = USB_POLLING_INTERVAL_MS
+ }
+#endif
};
/*
@@ -945,6 +1042,12 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
break;
#endif
+#ifdef JOYSTICK_ENABLE
+ case JOYSTICK_INTERFACE:
+ Address = &ConfigurationDescriptor.Joystick_HID;
+ Size = sizeof(USB_HID_Descriptor_HID_t);
+ break;
+#endif
}
break;
@@ -989,6 +1092,12 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
break;
#endif
+#ifdef JOYSTICK_ENABLE
+ case JOYSTICK_INTERFACE:
+ Address = &JoystickReport;
+ Size = sizeof(JoystickReport);
+ break;
+#endif
}
break;