Initial HIDAPI driver support for the PS3 controller
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 738f550..6f28235 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -706,6 +706,17 @@ extern "C" {
#define SDL_HINT_JOYSTICK_HIDAPI_SHIELD "SDL_JOYSTICK_HIDAPI_SHIELD"
/**
+ * \brief A variable controlling whether the HIDAPI driver for PS3 controllers should be used.
+ *
+ * This variable can be set to the following values:
+ * "0" - HIDAPI driver is not used
+ * "1" - HIDAPI driver is used
+ *
+ * The default is the value of SDL_HINT_JOYSTICK_HIDAPI
+ */
+#define SDL_HINT_JOYSTICK_HIDAPI_PS3 "SDL_JOYSTICK_HIDAPI_PS3"
+
+/**
* \brief A variable controlling whether the HIDAPI driver for PS4 controllers should be used.
*
* This variable can be set to the following values:
diff --git a/src/hidapi/libusb/hid.c b/src/hidapi/libusb/hid.c
index dbcd4fa..c740be5 100644
--- a/src/hidapi/libusb/hid.c
+++ b/src/hidapi/libusb/hid.c
@@ -173,6 +173,10 @@ struct hid_device_ {
int transfer_loop_finished;
struct libusb_transfer *transfer;
+ /* Quirks */
+ int skip_output_report_id;
+ int no_output_reports_on_intr_ep;
+
/* List of received input reports. */
struct input_report *input_reports;
};
@@ -1144,6 +1148,19 @@ static void init_xboxone(libusb_device_handle *device_handle, unsigned short idV
}
}
+static void calculate_device_quirks(hid_device *dev, unsigned short idVendor, unsigned short idProduct)
+{
+ static const int VENDOR_SONY = 0x054c;
+ static const int PRODUCT_PS3_CONTROLLER = 0x0268;
+ static const int PRODUCT_NAVIGATION_CONTROLLER = 0x042f;
+
+ if (idVendor == VENDOR_SONY &&
+ (idProduct == PRODUCT_PS3_CONTROLLER || idProduct == PRODUCT_NAVIGATION_CONTROLLER)) {
+ dev->skip_output_report_id = 1;
+ dev->no_output_reports_on_intr_ep = 1;
+ }
+}
+
hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
{
hid_device *dev = NULL;
@@ -1269,6 +1286,8 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
}
}
+ calculate_device_quirks(dev, desc.idVendor, desc.idProduct);
+
dev->thread = SDL_CreateThread(read_thread, NULL, dev);
/* Wait here for the read thread to be initialized. */
@@ -1301,11 +1320,11 @@ int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t
{
int res;
- if (dev->output_endpoint <= 0) {
+ if (dev->output_endpoint <= 0 || dev->no_output_reports_on_intr_ep) {
int report_number = data[0];
int skipped_report_id = 0;
- if (report_number == 0x0) {
+ if (report_number == 0x0 || dev->skip_output_report_id) {
data++;
length--;
skipped_report_id = 1;
diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index a7baee6..3506871 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -52,6 +52,9 @@ static SDL_HIDAPI_DeviceDriver *SDL_HIDAPI_drivers[] = {
#ifdef SDL_JOYSTICK_HIDAPI_SHIELD
&SDL_HIDAPI_DriverShield,
#endif
+#ifdef SDL_JOYSTICK_HIDAPI_PS3
+ &SDL_HIDAPI_DriverPS3,
+#endif
#ifdef SDL_JOYSTICK_HIDAPI_PS4
&SDL_HIDAPI_DriverPS4,
#endif
diff --git a/src/joystick/hidapi/SDL_hidapijoystick_c.h b/src/joystick/hidapi/SDL_hidapijoystick_c.h
index 3975e0b..fbf21ac 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick_c.h
+++ b/src/joystick/hidapi/SDL_hidapijoystick_c.h
@@ -34,6 +34,7 @@
/* This is the full set of HIDAPI drivers available */
#define SDL_JOYSTICK_HIDAPI_GAMECUBE
#define SDL_JOYSTICK_HIDAPI_LUNA
+#define SDL_JOYSTICK_HIDAPI_PS3
#define SDL_JOYSTICK_HIDAPI_PS4
#define SDL_JOYSTICK_HIDAPI_PS5
#define SDL_JOYSTICK_HIDAPI_STADIA
@@ -125,6 +126,7 @@ extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverJoyCons;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverLuna;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverNintendoClassic;
+extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS5;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverShield;
diff --git a/src/joystick/usb_ids.h b/src/joystick/usb_ids.h
index a22a286..f1cd185 100644
--- a/src/joystick/usb_ids.h
+++ b/src/joystick/usb_ids.h
@@ -57,6 +57,7 @@
#define USB_PRODUCT_RAZER_PANTHERA 0x0401
#define USB_PRODUCT_RAZER_PANTHERA_EVO 0x1008
#define USB_PRODUCT_RAZER_ATROX 0x0a00
+#define USB_PRODUCT_SONY_DS3 0x0268
#define USB_PRODUCT_SONY_DS4 0x05c4
#define USB_PRODUCT_SONY_DS4_DONGLE 0x0ba0
#define USB_PRODUCT_SONY_DS4_SLIM 0x09cc