Skip to content

Commit 359d40c

Browse files
committed
hidapi/libusb: added quirks for the Sony PS3 controller
Signed-off-by: Sam Lantinga <slouken@libsdl.org>
1 parent 249b513 commit 359d40c

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/hidapi/libusb/hid.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ struct hid_device_ {
179179
int transfer_loop_finished;
180180
struct libusb_transfer *transfer;
181181

182+
/* Quirks */
183+
int skip_output_report_id;
184+
int no_output_reports_on_intr_ep;
185+
182186
/* List of received input reports. */
183187
struct input_report *input_reports;
184188

@@ -1329,6 +1333,19 @@ static void init_xboxone(libusb_device_handle *device_handle, unsigned short idV
13291333
}
13301334
}
13311335

1336+
static void calculate_device_quirks(hid_device *dev, unsigned short idVendor, unsigned short idProduct)
1337+
{
1338+
static const int VENDOR_SONY = 0x054c;
1339+
static const int PRODUCT_PS3_CONTROLLER = 0x0268;
1340+
static const int PRODUCT_NAVIGATION_CONTROLLER = 0x042f;
1341+
1342+
if (idVendor == VENDOR_SONY &&
1343+
(idProduct == PRODUCT_PS3_CONTROLLER || idProduct == PRODUCT_NAVIGATION_CONTROLLER)) {
1344+
dev->skip_output_report_id = 1;
1345+
dev->no_output_reports_on_intr_ep = 1;
1346+
}
1347+
}
1348+
13321349
static int hidapi_initialize_device(hid_device *dev, int config_number, const struct libusb_interface_descriptor *intf_desc, const struct libusb_config_descriptor *conf_desc)
13331350
{
13341351
int i =0;
@@ -1426,6 +1443,8 @@ static int hidapi_initialize_device(hid_device *dev, int config_number, const st
14261443
}
14271444
}
14281445

1446+
calculate_device_quirks(dev, desc.idVendor, desc.idProduct);
1447+
14291448
pthread_create(&dev->thread, NULL, read_thread, dev);
14301449

14311450
/* Wait here for the read thread to be initialized. */
@@ -1591,14 +1610,14 @@ int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t
15911610

15921611
report_number = data[0];
15931612

1594-
if (report_number == 0x0) {
1613+
if (report_number == 0x0 || dev->skip_output_report_id) {
15951614
data++;
15961615
length--;
15971616
skipped_report_id = 1;
15981617
}
15991618

16001619

1601-
if (dev->output_endpoint <= 0) {
1620+
if (dev->output_endpoint <= 0 || dev->no_output_reports_on_intr_ep) {
16021621
/* No interrupt out endpoint. Use the Control Endpoint */
16031622
res = libusb_control_transfer(dev->device_handle,
16041623
LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE|LIBUSB_ENDPOINT_OUT,

0 commit comments

Comments
 (0)