SDL: Added support for the 8BitDo Ultimate Wired Controller for Xbox

From be3a945a8b9ff12e78f4b0d4634d38cc89d4c418 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 20 Jul 2022 11:05:55 -0700
Subject: [PATCH] Added support for the 8BitDo Ultimate Wired Controller for
 Xbox

---
 .../app/src/main/java/org/libsdl/app/HIDDeviceManager.java   | 1 +
 src/hidapi/libusb/hid.c                                      | 1 +
 src/joystick/SDL_joystick.c                                  | 5 +++++
 src/joystick/controller_type.c                               | 1 +
 src/joystick/hidapi/SDL_hidapijoystick.c                     | 1 +
 src/joystick/usb_ids.h                                       | 2 ++
 6 files changed, 11 insertions(+)

diff --git a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java
index a50cfdafcea..cf3c9267fbd 100644
--- a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java
+++ b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java
@@ -278,6 +278,7 @@ private boolean isXboxOneController(UsbDevice usbDevice, UsbInterface usbInterfa
             0x1532, // Razer Wildcat
             0x20d6, // PowerA
             0x24c6, // PowerA
+            0x2dc8, /* 8BitDo */
             0x2e24, // Hyperkin
         };
 
diff --git a/src/hidapi/libusb/hid.c b/src/hidapi/libusb/hid.c
index 463060730b5..5a3b22a470a 100644
--- a/src/hidapi/libusb/hid.c
+++ b/src/hidapi/libusb/hid.c
@@ -664,6 +664,7 @@ static int is_xboxone(unsigned short vendor_id, const struct libusb_interface_de
 		0x1532, /* Razer Wildcat */
 		0x20d6, /* PowerA */
 		0x24c6, /* PowerA */
+		0x2dc8, /* 8BitDo */
 		0x2e24, /* Hyperkin */
 	};
 
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 6fc32f7de6f..f9d061f3082 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -2077,6 +2077,11 @@ SDL_IsJoystickXboxSeriesX(Uint16 vendor_id, Uint16 product_id)
             return SDL_TRUE;
         }
     }
+    if (vendor_id == USB_VENDOR_8BITDO) {
+        if (product_id == USB_PRODUCT_8BITDO_XBOX_CONTROLLER) {
+            return SDL_TRUE;
+        }
+    }
     return SDL_FALSE;
 }
 
diff --git a/src/joystick/controller_type.c b/src/joystick/controller_type.c
index 7f81bdb21d9..f10cd5560a2 100644
--- a/src/joystick/controller_type.c
+++ b/src/joystick/controller_type.c
@@ -406,6 +406,7 @@ static const ControllerDescription_t arrControllers[] = {
 	{ MAKE_CONTROLLER_ID( 0x24c6, 0x591a ), k_eControllerType_XBoxOneController, NULL },	// PowerA FUSION Pro Controller
 	{ MAKE_CONTROLLER_ID( 0x24c6, 0x592a ), k_eControllerType_XBoxOneController, NULL },	// BDA XB1 Spectra Pro
 	{ MAKE_CONTROLLER_ID( 0x24c6, 0x791a ), k_eControllerType_XBoxOneController, NULL },	// PowerA Fusion Fight Pad
+	{ MAKE_CONTROLLER_ID( 0x2dc8, 0x2002 ), k_eControllerType_XBoxOneController, NULL },	// 8BitDo Ultimate Wired Controller for Xbox
 	{ MAKE_CONTROLLER_ID( 0x2e24, 0x0652 ), k_eControllerType_XBoxOneController, NULL },	// Hyperkin Duke
 	{ MAKE_CONTROLLER_ID( 0x2e24, 0x1618 ), k_eControllerType_XBoxOneController, NULL },	// Hyperkin Duke
 	{ MAKE_CONTROLLER_ID( 0x2e24, 0x1688 ), k_eControllerType_XBoxOneController, NULL },	// Hyperkin X91
diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index 112397ab7f7..2e85580f39a 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -180,6 +180,7 @@ SDL_GetJoystickGameControllerProtocol(const char *name, Uint16 vendor, Uint16 pr
             0x1532, /* Razer */
             0x20d6, /* PowerA */
             0x24c6, /* PowerA */
+            0x2dc8, /* 8BitDo */
             0x2e24, /* Hyperkin */
         };
 
diff --git a/src/joystick/usb_ids.h b/src/joystick/usb_ids.h
index e93406d1744..ef7aa26bfa5 100644
--- a/src/joystick/usb_ids.h
+++ b/src/joystick/usb_ids.h
@@ -24,6 +24,7 @@
 
 /* Definitions of useful USB VID/PID values */
 
+#define USB_VENDOR_8BITDO       0x2dc8
 #define USB_VENDOR_AMAZON       0x1949
 #define USB_VENDOR_APPLE        0x05ac
 #define USB_VENDOR_GOOGLE       0x18d1
@@ -39,6 +40,7 @@
 #define USB_VENDOR_SONY         0x054c
 #define USB_VENDOR_VALVE        0x28de
 
+#define USB_PRODUCT_8BITDO_XBOX_CONTROLLER                  0x2002
 #define USB_PRODUCT_AMAZON_LUNA_CONTROLLER                  0x0419
 #define USB_PRODUCT_GOOGLE_STADIA_CONTROLLER                0x9400
 #define USB_PRODUCT_EVORETRO_GAMECUBE_ADAPTER               0x1846