SDL: Added support for the STRIKEPAD PS4 Grip Add-on to the HIDAPI driver

From 618340bf990512247ed29a1beb38606e371d60e8 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 12 Dec 2022 10:54:29 -0800
Subject: [PATCH] Added support for the STRIKEPAD PS4 Grip Add-on to the HIDAPI
 driver

---
 src/joystick/hidapi/SDL_hidapi_ps4.c | 20 ++++++++++++--------
 src/joystick/usb_ids.h               |  1 +
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c
index 50feec2a9d20..facb6ff0c7cf 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps4.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps4.c
@@ -269,6 +269,10 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
         }
         device->is_bluetooth = SDL_FALSE;
         ctx->enhanced_mode = SDL_TRUE;
+    } else if (device->vendor_id == USB_VENDOR_SONY && device->product_id == USB_PRODUCT_SONY_DS4_STRIKEPAD) {
+        device->is_bluetooth = SDL_FALSE;
+        ctx->enhanced_mode = SDL_TRUE;
+
     } else if (device->vendor_id == USB_VENDOR_SONY) {
         /* This will fail if we're on Bluetooth */
         size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdSerialNumber, data, sizeof(data));
@@ -306,13 +310,7 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
 
     size = ReadFeatureReport(device->dev, k_ePS4FeatureReportIdCapabilities, data, sizeof data);
     /* Get the device capabilities */
-    if (device->vendor_id == USB_VENDOR_SONY) {
-        ctx->official_controller = SDL_TRUE;
-        ctx->sensors_supported = SDL_TRUE;
-        ctx->lightbar_supported = SDL_TRUE;
-        ctx->vibration_supported = SDL_TRUE;
-        ctx->touchpad_supported = SDL_TRUE;
-    } else if (size == 48 && data[2] == 0x27) {
+    if (size == 48 && data[2] == 0x27) {
         Uint8 capabilities = data[4];
         Uint8 device_type = data[5];
 
@@ -358,6 +356,12 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
             joystick_type = SDL_JOYSTICK_TYPE_UNKNOWN;
             break;
         }
+    } else if (device->vendor_id == USB_VENDOR_SONY) {
+        ctx->official_controller = SDL_TRUE;
+        ctx->sensors_supported = SDL_TRUE;
+        ctx->lightbar_supported = SDL_TRUE;
+        ctx->vibration_supported = SDL_TRUE;
+        ctx->touchpad_supported = SDL_TRUE;
     } else if (device->vendor_id == USB_VENDOR_RAZER) {
         /* The Razer Raiju doesn't respond to the detection protocol, but has a touchpad and vibration */
         ctx->vibration_supported = SDL_TRUE;
@@ -381,7 +385,7 @@ static SDL_bool HIDAPI_DriverPS4_InitDevice(SDL_HIDAPI_Device *device)
 
     device->joystick_type = joystick_type;
     device->type = SDL_CONTROLLER_TYPE_PS4;
-    if (device->vendor_id == USB_VENDOR_SONY) {
+    if (ctx->official_controller) {
         HIDAPI_SetDeviceName(device, "PS4 Controller");
     }
     HIDAPI_SetDeviceSerial(device, serial);
diff --git a/src/joystick/usb_ids.h b/src/joystick/usb_ids.h
index 4cf9d80a9e8d..2ae2f9606319 100644
--- a/src/joystick/usb_ids.h
+++ b/src/joystick/usb_ids.h
@@ -100,6 +100,7 @@
 #define USB_PRODUCT_SONY_DS4                              0x05c4
 #define USB_PRODUCT_SONY_DS4_DONGLE                       0x0ba0
 #define USB_PRODUCT_SONY_DS4_SLIM                         0x09cc
+#define USB_PRODUCT_SONY_DS4_STRIKEPAD                    0x05c5
 #define USB_PRODUCT_SONY_DS5                              0x0ce6
 #define USB_PRODUCT_SONY_DS5_EDGE                         0x0df2
 #define USB_PRODUCT_VICTRIX_FS_PRO_V2                     0x0207