SDL: Implemented SDL_GameControllerGetFirmwareVersion() for HIDAPI PS5 controllers

From 9202df0472fd8f3e5596cb99a4fa3cd68f45669d Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 9 Jun 2022 18:11:34 -0700
Subject: [PATCH] Implemented SDL_GameControllerGetFirmwareVersion() for HIDAPI
 PS5 controllers

---
 src/joystick/hidapi/SDL_hidapi_ps5.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/joystick/hidapi/SDL_hidapi_ps5.c b/src/joystick/hidapi/SDL_hidapi_ps5.c
index 2549c2afd5d..3f1b62cc4c4 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps5.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps5.c
@@ -59,6 +59,7 @@ typedef enum
 {
     k_EPS5FeatureReportIdCalibration = 0x05,
     k_EPS5FeatureReportIdSerialNumber = 0x09,
+    k_EPS5FeatureReportIdFirmwareInfo = 0x20,
 } EPS5FeatureReportId;
 
 typedef struct
@@ -601,6 +602,13 @@ HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
                 data[6], data[5], data[4], data[3], data[2], data[1]);
             joystick->serial = SDL_strdup(serial);
         }
+
+        /* Read the firmware version
+           This will also enable enhanced reports over Bluetooth
+        */
+        if (ReadFeatureReport(device->dev, k_EPS5FeatureReportIdFirmwareInfo, data, USB_PACKET_LENGTH) >= 46) {
+            joystick->firmware_version = (Uint16)data[44] | ((Uint16)data[45] << 8);
+        }
     }
 
     if (!joystick->serial && device->serial && SDL_strlen(device->serial) == 12) {