summaryrefslogtreecommitdiffstats
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.c190
1 files changed, 99 insertions, 91 deletions
diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c
index 21795cef60..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[] = {
@@ -181,39 +250,37 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM DigitizerReport[] = {
const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
# define SHARED_REPORT_STARTED
# endif
- HID_RI_USAGE_PAGE(8, 0x0D), // Digitizers
- HID_RI_USAGE(8, 0x01), // Digitizer
- HID_RI_COLLECTION(8, 0x01), // Application
+ HID_RI_USAGE_PAGE(8, 0x0D), // Digitizers
+ HID_RI_USAGE(8, 0x01), // Digitizer
+ HID_RI_COLLECTION(8, 0x01), // Application
# ifdef DIGITIZER_SHARED_EP
HID_RI_REPORT_ID(8, REPORT_ID_DIGITIZER),
# endif
- HID_RI_USAGE(8, 0x20), // Stylus
- HID_RI_COLLECTION(8, 0x00), // Physical
- // Tip Switch (1 bit)
- HID_RI_USAGE(8, 0x42), // Tip Switch
+ HID_RI_USAGE(8, 0x20), // Stylus
+ HID_RI_COLLECTION(8, 0x00), // Physical
+ // In Range, Tip Switch & Barrel Switch (3 bits)
+ HID_RI_USAGE(8, 0x32), // In Range
+ HID_RI_USAGE(8, 0x42), // Tip Switch
+ HID_RI_USAGE(8, 0x44), // Barrel Switch
HID_RI_LOGICAL_MINIMUM(8, 0x00),
HID_RI_LOGICAL_MAXIMUM(8, 0x01),
+ HID_RI_REPORT_COUNT(8, 0x03),
HID_RI_REPORT_SIZE(8, 0x01),
- HID_RI_REPORT_COUNT(8, 0x01),
- HID_RI_INPUT(8, HID_IOF_VARIABLE),
- // In Range (1 bit)
- HID_RI_USAGE(8, 0x32), // In Range
- HID_RI_INPUT(8, HID_IOF_VARIABLE),
- // Padding (6 bits)
- HID_RI_REPORT_COUNT(8, 0x06),
- HID_RI_INPUT(8, HID_IOF_CONSTANT | HID_IOF_VARIABLE),
+ HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
+ // Padding (5 bits)
+ HID_RI_REPORT_COUNT(8, 0x05),
+ HID_RI_INPUT(8, HID_IOF_CONSTANT),
// X/Y Position (4 bytes)
- HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
+ HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
+ HID_RI_USAGE(8, 0x30), // X
+ HID_RI_USAGE(8, 0x31), // Y
HID_RI_LOGICAL_MAXIMUM(16, 0x7FFF),
+ HID_RI_REPORT_COUNT(8, 0x02),
HID_RI_REPORT_SIZE(8, 0x10),
- HID_RI_REPORT_COUNT(8, 0x01),
- HID_RI_UNIT(8, 0x33), // Inch, English Linear
- HID_RI_UNIT_EXPONENT(8, 0x0E), // -2
- HID_RI_USAGE(8, 0x30), // X
- HID_RI_INPUT(8, HID_IOF_VARIABLE),
- HID_RI_USAGE(8, 0x31), // Y
- HID_RI_INPUT(8, HID_IOF_VARIABLE),
+ HID_RI_UNIT(8, 0x33), // Inch, English Linear
+ HID_RI_UNIT_EXPONENT(8, 0x0E), // -2
+ HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
HID_RI_END_COLLECTION(0),
HID_RI_END_COLLECTION(0),
# ifndef DIGITIZER_SHARED_EP
@@ -362,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
*/
@@ -960,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),
@@ -1046,7 +1054,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
*/
const USB_Descriptor_String_t PROGMEM LanguageString = {
.Header = {
- .Size = USB_STRING_LEN(1),
+ .Size = 4,
.Type = DTYPE_String
},
.UnicodeString = {LANGUAGE_ID_ENG}
@@ -1054,24 +1062,24 @@ const USB_Descriptor_String_t PROGMEM LanguageString = {
const USB_Descriptor_String_t PROGMEM ManufacturerString = {
.Header = {
- .Size = USB_STRING_LEN(sizeof(STR(MANUFACTURER)) - 1), // Subtract 1 for null terminator
+ .Size = sizeof(USBSTR(MANUFACTURER)),
.Type = DTYPE_String
},
- .UnicodeString = LSTR(MANUFACTURER)
+ .UnicodeString = USBSTR(MANUFACTURER)
};
const USB_Descriptor_String_t PROGMEM ProductString = {
.Header = {
- .Size = USB_STRING_LEN(sizeof(STR(PRODUCT)) - 1), // Subtract 1 for null terminator
+ .Size = sizeof(USBSTR(PRODUCT)),
.Type = DTYPE_String
},
- .UnicodeString = LSTR(PRODUCT)
+ .UnicodeString = USBSTR(PRODUCT)
};
#if defined(SERIAL_NUMBER)
const USB_Descriptor_String_t PROGMEM SerialNumberString = {
.Header = {
- .Size = USB_STRING_LEN(sizeof(SERIAL_NUMBER) - 1), // Subtract 1 for null terminator
+ .Size = sizeof(USBSTR(SERIAL_NUMBER)),
.Type = DTYPE_String
},
.UnicodeString = USBSTR(SERIAL_NUMBER)
@@ -1171,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);
@@ -1228,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);