Initial HIDAPI driver support for the PS3 controller

This commit is contained in:
Sam Lantinga 2022-08-23 22:45:37 -07:00
parent 50c5d23f7d
commit b6f96b69aa
5 changed files with 38 additions and 2 deletions

View File

@ -705,6 +705,17 @@ extern "C" {
*/ */
#define SDL_HINT_JOYSTICK_HIDAPI_SHIELD "SDL_JOYSTICK_HIDAPI_SHIELD" #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. * \brief A variable controlling whether the HIDAPI driver for PS4 controllers should be used.
* *

View File

@ -173,6 +173,10 @@ struct hid_device_ {
int transfer_loop_finished; int transfer_loop_finished;
struct libusb_transfer *transfer; struct libusb_transfer *transfer;
/* Quirks */
int skip_output_report_id;
int no_output_reports_on_intr_ep;
/* List of received input reports. */ /* List of received input reports. */
struct input_report *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 * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
{ {
hid_device *dev = NULL; 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); dev->thread = SDL_CreateThread(read_thread, NULL, dev);
/* Wait here for the read thread to be initialized. */ /* 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; 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 report_number = data[0];
int skipped_report_id = 0; int skipped_report_id = 0;
if (report_number == 0x0) { if (report_number == 0x0 || dev->skip_output_report_id) {
data++; data++;
length--; length--;
skipped_report_id = 1; skipped_report_id = 1;

View File

@ -52,6 +52,9 @@ static SDL_HIDAPI_DeviceDriver *SDL_HIDAPI_drivers[] = {
#ifdef SDL_JOYSTICK_HIDAPI_SHIELD #ifdef SDL_JOYSTICK_HIDAPI_SHIELD
&SDL_HIDAPI_DriverShield, &SDL_HIDAPI_DriverShield,
#endif #endif
#ifdef SDL_JOYSTICK_HIDAPI_PS3
&SDL_HIDAPI_DriverPS3,
#endif
#ifdef SDL_JOYSTICK_HIDAPI_PS4 #ifdef SDL_JOYSTICK_HIDAPI_PS4
&SDL_HIDAPI_DriverPS4, &SDL_HIDAPI_DriverPS4,
#endif #endif

View File

@ -34,6 +34,7 @@
/* This is the full set of HIDAPI drivers available */ /* This is the full set of HIDAPI drivers available */
#define SDL_JOYSTICK_HIDAPI_GAMECUBE #define SDL_JOYSTICK_HIDAPI_GAMECUBE
#define SDL_JOYSTICK_HIDAPI_LUNA #define SDL_JOYSTICK_HIDAPI_LUNA
#define SDL_JOYSTICK_HIDAPI_PS3
#define SDL_JOYSTICK_HIDAPI_PS4 #define SDL_JOYSTICK_HIDAPI_PS4
#define SDL_JOYSTICK_HIDAPI_PS5 #define SDL_JOYSTICK_HIDAPI_PS5
#define SDL_JOYSTICK_HIDAPI_STADIA #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_DriverJoyCons;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverLuna; extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverLuna;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverNintendoClassic; 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_DriverPS4;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS5; extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS5;
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverShield; extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverShield;

View File

@ -57,6 +57,7 @@
#define USB_PRODUCT_RAZER_PANTHERA 0x0401 #define USB_PRODUCT_RAZER_PANTHERA 0x0401
#define USB_PRODUCT_RAZER_PANTHERA_EVO 0x1008 #define USB_PRODUCT_RAZER_PANTHERA_EVO 0x1008
#define USB_PRODUCT_RAZER_ATROX 0x0a00 #define USB_PRODUCT_RAZER_ATROX 0x0a00
#define USB_PRODUCT_SONY_DS3 0x0268
#define USB_PRODUCT_SONY_DS4 0x05c4 #define USB_PRODUCT_SONY_DS4 0x05c4
#define USB_PRODUCT_SONY_DS4_DONGLE 0x0ba0 #define USB_PRODUCT_SONY_DS4_DONGLE 0x0ba0
#define USB_PRODUCT_SONY_DS4_SLIM 0x09cc #define USB_PRODUCT_SONY_DS4_SLIM 0x09cc