|
|
@@ -45,6 +45,7 @@
|
|
|
/*
|
|
|
* HID report descriptors
|
|
|
*/
|
|
|
+#ifdef KEYBOARD_ENABLE
|
|
|
#ifdef KEYBOARD_SHARED_EP
|
|
|
const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
|
|
|
# define SHARED_REPORT_STARTED
|
|
|
@@ -95,6 +96,7 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = {
|
|
|
#ifndef KEYBOARD_SHARED_EP
|
|
|
};
|
|
|
#endif
|
|
|
+#endif
|
|
|
|
|
|
#ifdef MOUSE_ENABLE
|
|
|
# ifndef MOUSE_SHARED_EP
|
|
|
@@ -335,6 +337,64 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] = {
|
|
|
};
|
|
|
#endif
|
|
|
|
|
|
+#ifdef GAMEPAD_ENABLE
|
|
|
+const USB_Descriptor_HIDReport_Datatype_t PROGMEM GamepadReport[] = {
|
|
|
+ HID_RI_USAGE_PAGE(8,1), /* Generic Desktop */
|
|
|
+ HID_RI_USAGE(8,5), /* Joystick */
|
|
|
+ HID_RI_COLLECTION(8,1), /* Application */
|
|
|
+ // Buttons (2 bytes)
|
|
|
+ HID_RI_LOGICAL_MINIMUM(8,0),
|
|
|
+ HID_RI_LOGICAL_MAXIMUM(8,1),
|
|
|
+ HID_RI_PHYSICAL_MINIMUM(8,0),
|
|
|
+ HID_RI_PHYSICAL_MAXIMUM(8,1),
|
|
|
+ // The Switch will allow us to expand the original HORI descriptors to a full 16 buttons.
|
|
|
+ // The Switch will make use of 14 of those buttons.
|
|
|
+ HID_RI_REPORT_SIZE(8,1),
|
|
|
+ HID_RI_REPORT_COUNT(8,16),
|
|
|
+ HID_RI_USAGE_PAGE(8,9),
|
|
|
+ HID_RI_USAGE_MINIMUM(8,1),
|
|
|
+ HID_RI_USAGE_MAXIMUM(8,16),
|
|
|
+ HID_RI_INPUT(8,2),
|
|
|
+ // HAT Switch (1 nibble)
|
|
|
+ HID_RI_USAGE_PAGE(8,1),
|
|
|
+ HID_RI_LOGICAL_MAXIMUM(8,7),
|
|
|
+ HID_RI_PHYSICAL_MAXIMUM(16,315),
|
|
|
+ HID_RI_REPORT_SIZE(8,4),
|
|
|
+ HID_RI_REPORT_COUNT(8,1),
|
|
|
+ HID_RI_UNIT(8,20),
|
|
|
+ HID_RI_USAGE(8,57),
|
|
|
+ HID_RI_INPUT(8,66),
|
|
|
+ // There's an additional nibble here that's utilized as part of the Switch Pro Controller.
|
|
|
+ // I believe this -might- be separate U/D/L/R bits on the Switch Pro Controller, as they're utilized as four button descriptors on the Switch Pro Controller.
|
|
|
+ HID_RI_UNIT(8,0),
|
|
|
+ HID_RI_REPORT_COUNT(8,1),
|
|
|
+ HID_RI_INPUT(8,1),
|
|
|
+ // Joystick (4 bytes)
|
|
|
+ HID_RI_LOGICAL_MAXIMUM(16,255),
|
|
|
+ HID_RI_PHYSICAL_MAXIMUM(16,255),
|
|
|
+ HID_RI_USAGE(8,48),
|
|
|
+ HID_RI_USAGE(8,49),
|
|
|
+ HID_RI_USAGE(8,50),
|
|
|
+ HID_RI_USAGE(8,53),
|
|
|
+ HID_RI_REPORT_SIZE(8,8),
|
|
|
+ HID_RI_REPORT_COUNT(8,4),
|
|
|
+ HID_RI_INPUT(8,2),
|
|
|
+ // ??? Vendor Specific (1 byte)
|
|
|
+ // This byte requires additional investigation.
|
|
|
+ HID_RI_USAGE_PAGE(16,65280),
|
|
|
+ HID_RI_USAGE(8,32),
|
|
|
+ HID_RI_REPORT_COUNT(8,1),
|
|
|
+ HID_RI_INPUT(8,2),
|
|
|
+ // Output (8 bytes)
|
|
|
+ // Original observation of this suggests it to be a mirror of the inputs that we sent.
|
|
|
+ // The Switch requires us to have these descriptors available.
|
|
|
+ HID_RI_USAGE(16,9761),
|
|
|
+ HID_RI_REPORT_COUNT(8,8),
|
|
|
+ HID_RI_OUTPUT(8,2),
|
|
|
+ HID_RI_END_COLLECTION(0),
|
|
|
+};
|
|
|
+#endif
|
|
|
+
|
|
|
/*
|
|
|
* Device descriptor
|
|
|
*/
|
|
|
@@ -390,7 +450,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
|
|
|
.ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_REMOTEWAKEUP),
|
|
|
.MaxPowerConsumption = USB_CONFIG_POWER_MA(USB_MAX_POWER_CONSUMPTION)
|
|
|
},
|
|
|
-#ifndef KEYBOARD_SHARED_EP
|
|
|
+#if !defined(KEYBOARD_SHARED_EP) && defined(KEYBOARD_ENABLE)
|
|
|
/*
|
|
|
* Keyboard
|
|
|
*/
|
|
|
@@ -909,6 +969,56 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
|
|
|
.PollingIntervalMS = USB_POLLING_INTERVAL_MS
|
|
|
}
|
|
|
#endif
|
|
|
+
|
|
|
+#ifdef GAMEPAD_ENABLE
|
|
|
+ /*
|
|
|
+ * Gamepad
|
|
|
+ */
|
|
|
+ .Gamepad_Interface = {
|
|
|
+ .Header = {
|
|
|
+ .Size = sizeof(USB_Descriptor_Interface_t),
|
|
|
+ .Type = DTYPE_Interface
|
|
|
+ },
|
|
|
+ .InterfaceNumber = GAMEPAD_INTERFACE,
|
|
|
+ .AlternateSetting = 0x00,
|
|
|
+ .TotalEndpoints = 2,
|
|
|
+ .Class = HID_CSCP_HIDClass,
|
|
|
+ .SubClass = HID_CSCP_NonBootSubclass,
|
|
|
+ .Protocol = HID_CSCP_NonBootProtocol,
|
|
|
+ .InterfaceStrIndex = NO_DESCRIPTOR
|
|
|
+ },
|
|
|
+ .Gamepad_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(GamepadReport)
|
|
|
+ },
|
|
|
+ .Gamepad_INEndpoint = {
|
|
|
+ .Header = {
|
|
|
+ .Size = sizeof(USB_Descriptor_Endpoint_t),
|
|
|
+ .Type = DTYPE_Endpoint
|
|
|
+ },
|
|
|
+ .EndpointAddress = (ENDPOINT_DIR_IN | GAMEPAD_IN_EPNUM),
|
|
|
+ .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
|
|
+ .EndpointSize = GAMEPAD_EPSIZE,
|
|
|
+ .PollingIntervalMS = USB_POLLING_INTERVAL_MS
|
|
|
+ },
|
|
|
+ .Gamepad_OUTEndpoint = {
|
|
|
+ .Header = {
|
|
|
+ .Size = sizeof(USB_Descriptor_Endpoint_t),
|
|
|
+ .Type = DTYPE_Endpoint
|
|
|
+ },
|
|
|
+ .EndpointAddress = (ENDPOINT_DIR_OUT | GAMEPAD_OUT_EPNUM),
|
|
|
+ .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
|
|
+ .EndpointSize = GAMEPAD_EPSIZE,
|
|
|
+ .PollingIntervalMS = USB_POLLING_INTERVAL_MS
|
|
|
+ }
|
|
|
+#endif
|
|
|
};
|
|
|
|
|
|
/*
|
|
|
@@ -1003,7 +1113,7 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
|
|
|
break;
|
|
|
case HID_DTYPE_HID:
|
|
|
switch (wIndex) {
|
|
|
-#ifndef KEYBOARD_SHARED_EP
|
|
|
+#if !defined(KEYBOARD_SHARED_EP) && defined(KEYBOARD_ENABLE)
|
|
|
case KEYBOARD_INTERFACE:
|
|
|
Address = &ConfigurationDescriptor.Keyboard_HID;
|
|
|
Size = sizeof(USB_HID_Descriptor_HID_t);
|
|
|
@@ -1046,13 +1156,19 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
|
|
|
Address = &ConfigurationDescriptor.Joystick_HID;
|
|
|
Size = sizeof(USB_HID_Descriptor_HID_t);
|
|
|
break;
|
|
|
+#endif
|
|
|
+#ifdef GAMEPAD_ENABLE
|
|
|
+ case GAMEPAD_INTERFACE:
|
|
|
+ Address = &ConfigurationDescriptor.Gamepad_HID;
|
|
|
+ Size = sizeof(USB_HID_Descriptor_HID_t);
|
|
|
+ break;
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
case HID_DTYPE_Report:
|
|
|
switch (wIndex) {
|
|
|
-#ifndef KEYBOARD_SHARED_EP
|
|
|
+#if !defined(KEYBOARD_SHARED_EP) && defined(KEYBOARD_ENABLE)
|
|
|
case KEYBOARD_INTERFACE:
|
|
|
Address = &KeyboardReport;
|
|
|
Size = sizeof(KeyboardReport);
|
|
|
@@ -1096,6 +1212,12 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
|
|
|
Address = &JoystickReport;
|
|
|
Size = sizeof(JoystickReport);
|
|
|
break;
|
|
|
+#endif
|
|
|
+#ifdef GAMEPAD_ENABLE
|
|
|
+ case GAMEPAD_INTERFACE:
|
|
|
+ Address = &GamepadReport;
|
|
|
+ Size = sizeof(GamepadReport);
|
|
|
+ break;
|
|
|
#endif
|
|
|
}
|
|
|
|