SDL: Added support for the Razer Wolverine V2 controllers

From 4994654d4f2d5c96a0faa972ebbb6c653f939d56 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 20 Feb 2023 15:14:20 -0800
Subject: [PATCH] Added support for the Razer Wolverine V2 controllers

---
 src/joystick/SDL_joystick.c          | 6 ++++++
 src/joystick/controller_type.c       | 2 ++
 src/joystick/hidapi/SDL_hidapi_ps5.c | 6 ++++++
 src/joystick/usb_ids.h               | 6 ++++++
 4 files changed, 20 insertions(+)

diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 8dc5cbf4ab1d..df42684076a7 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -2195,6 +2195,12 @@ SDL_bool SDL_IsJoystickXboxSeriesX(Uint16 vendor_id, Uint16 product_id)
             return SDL_TRUE;
         }
     }
+    if (vendor_id == USB_VENDOR_RAZER) {
+        if (product_id == USB_PRODUCT_RAZER_WOLVERINE_V2 ||
+            product_id == USB_PRODUCT_RAZER_WOLVERINE_V2_CHROMA) {
+            return SDL_TRUE;
+        }
+    }
     if (vendor_id == USB_VENDOR_THRUSTMASTER) {
         if (product_id == USB_PRODUCT_THRUSTMASTER_ESWAPX_PRO) {
             return SDL_TRUE;
diff --git a/src/joystick/controller_type.c b/src/joystick/controller_type.c
index 0f9c93e85fa6..03836e806c53 100644
--- a/src/joystick/controller_type.c
+++ b/src/joystick/controller_type.c
@@ -155,6 +155,8 @@ static const ControllerDescription_t arrControllers[] = {
 	{ MAKE_CONTROLLER_ID( 0x054c, 0x0df2 ), k_eControllerType_PS5Controller, NULL },	// Sony DualSense Edge Controller
 	{ MAKE_CONTROLLER_ID( 0x0f0d, 0x0163 ), k_eControllerType_PS5Controller, NULL },	// HORI Fighting Commander OCTA
 	{ MAKE_CONTROLLER_ID( 0x0f0d, 0x0184 ), k_eControllerType_PS5Controller, NULL },	// Hori Fighting Stick α
+	{ MAKE_CONTROLLER_ID( 0x1532, 0x100b ), k_eControllerType_PS5Controller, NULL },	// Razer Wolverine V2 Pro (Wired)
+	{ MAKE_CONTROLLER_ID( 0x1532, 0x100c ), k_eControllerType_PS5Controller, NULL },	// Razer Wolverine V2 Pro (Wireless)
 
 	{ MAKE_CONTROLLER_ID( 0x0079, 0x0006 ), k_eControllerType_UnknownNonSteamController, NULL },	// DragonRise Generic USB PCB, sometimes configured as a PC Twin Shock Controller - looks like a DS3 but the face buttons are 1-4 instead of symbols
 
diff --git a/src/joystick/hidapi/SDL_hidapi_ps5.c b/src/joystick/hidapi/SDL_hidapi_ps5.c
index a8485e6e7d97..83f47328eb8e 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps5.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps5.c
@@ -474,6 +474,12 @@ static SDL_bool HIDAPI_DriverPS5_InitDevice(SDL_HIDAPI_Device *device)
         }
 
         ctx->use_alternate_report = SDL_TRUE;
+    } else if (device->vendor_id == USB_VENDOR_RAZER &&
+               (device->product_id == USB_PRODUCT_RAZER_WOLVERINE_V2_PRO_PS5_WIRED ||
+                device->product_id == USB_PRODUCT_RAZER_WOLVERINE_V2_PRO_PS5_WIRELESS)) {
+        /* The Razer Wolverine V2 Pro doesn't respond to the detection protocol, but has a touchpad and sensors, but no vibration */
+        ctx->sensors_supported = SDL_TRUE;
+        ctx->touchpad_supported = SDL_TRUE;
     }
     ctx->effects_supported = (ctx->lightbar_supported || ctx->vibration_supported || ctx->playerled_supported);
 
diff --git a/src/joystick/usb_ids.h b/src/joystick/usb_ids.h
index 72d79ecc3b05..306ea2f18a77 100644
--- a/src/joystick/usb_ids.h
+++ b/src/joystick/usb_ids.h
@@ -101,6 +101,12 @@
 #define USB_PRODUCT_RAZER_TOURNAMENT_EDITION_BLUETOOTH    0x100a
 #define USB_PRODUCT_RAZER_ULTIMATE_EDITION_USB            0x1004
 #define USB_PRODUCT_RAZER_ULTIMATE_EDITION_BLUETOOTH      0x1009
+#define USB_PRODUCT_RAZER_WOLVERINE_V2                    0x0a29
+#define USB_PRODUCT_RAZER_WOLVERINE_V2_CHROMA             0x0a2e
+#define USB_PRODUCT_RAZER_WOLVERINE_V2_PRO_PS5_WIRED      0x100b
+#define USB_PRODUCT_RAZER_WOLVERINE_V2_PRO_PS5_WIRELESS   0x100c
+#define USB_PRODUCT_RAZER_WOLVERINE_V2_PRO_XBOX_WIRED     0x1010
+#define USB_PRODUCT_RAZER_WOLVERINE_V2_PRO_XBOX_WIRELESS  0x1011
 #define USB_PRODUCT_SHANWAN_DS3                           0x0523
 #define USB_PRODUCT_SONY_DS3                              0x0268
 #define USB_PRODUCT_SONY_DS4                              0x05c4