@@ -1307,6 +1307,66 @@ static void init_xboxone(libusb_device_handle *device_handle, unsigned short idV
1307
1307
}
1308
1308
}
1309
1309
1310
+ static bool switch2_find_bulk_out_endpoint (libusb_device_handle * handle , uint8_t * endpoint_out )
1311
+ {
1312
+ struct libusb_config_descriptor * config ;
1313
+ if (libusb_get_config_descriptor (libusb_get_device (handle ), 0 , & config ) != 0 ) {
1314
+ return false;
1315
+ }
1316
+
1317
+ for (int i = 0 ; i < config -> bNumInterfaces ; i ++ ) {
1318
+ const struct libusb_interface * iface = & config -> interface [i ];
1319
+ for (int j = 0 ; j < iface -> num_altsetting ; j ++ ) {
1320
+ const struct libusb_interface_descriptor * altsetting = & iface -> altsetting [j ];
1321
+ if (altsetting -> bInterfaceNumber == 1 ) {
1322
+ for (int k = 0 ; k < altsetting -> bNumEndpoints ; k ++ ) {
1323
+ const struct libusb_endpoint_descriptor * ep = & altsetting -> endpoint [k ];
1324
+ if ((ep -> bmAttributes & LIBUSB_TRANSFER_TYPE_MASK ) == LIBUSB_TRANSFER_TYPE_BULK && (ep -> bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK ) == LIBUSB_ENDPOINT_OUT ) {
1325
+ * endpoint_out = ep -> bEndpointAddress ;
1326
+ libusb_free_config_descriptor (config );
1327
+ return true;
1328
+ }
1329
+ }
1330
+ }
1331
+ }
1332
+ }
1333
+
1334
+ libusb_free_config_descriptor (config );
1335
+ return false;
1336
+ }
1337
+
1338
+ static void init_nsogcn (libusb_device_handle * device_handle )
1339
+ {
1340
+ const unsigned char DEFAULT_REPORT_DATA [] = {
1341
+ 0x03 , 0x91 , 0x00 , 0x0d , 0x00 , 0x08 ,
1342
+ 0x00 , 0x00 , 0x01 , 0x00 , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF
1343
+ };
1344
+ const unsigned char SET_LED_DATA [] = {
1345
+ 0x09 , 0x91 , 0x00 , 0x07 , 0x00 , 0x08 ,
1346
+ 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00
1347
+ };
1348
+
1349
+ uint8_t endpoint_out = 0 ;
1350
+ if (!switch2_find_bulk_out_endpoint (device_handle , & endpoint_out )) {
1351
+ return ;
1352
+ }
1353
+
1354
+ int transferred ;
1355
+ libusb_bulk_transfer (device_handle ,
1356
+ endpoint_out ,
1357
+ (unsigned char * )DEFAULT_REPORT_DATA ,
1358
+ sizeof (DEFAULT_REPORT_DATA ),
1359
+ & transferred ,
1360
+ 1000 );
1361
+
1362
+ libusb_bulk_transfer (device_handle ,
1363
+ endpoint_out ,
1364
+ (unsigned char * )SET_LED_DATA ,
1365
+ sizeof (SET_LED_DATA ),
1366
+ & transferred ,
1367
+ 1000 );
1368
+ }
1369
+
1310
1370
static void calculate_device_quirks (hid_device * dev , unsigned short idVendor , unsigned short idProduct )
1311
1371
{
1312
1372
static const int VENDOR_SONY = 0x054c ;
@@ -1368,6 +1428,11 @@ static int hidapi_initialize_device(hid_device *dev, const struct libusb_interfa
1368
1428
init_xboxone (dev -> device_handle , desc .idVendor , desc .idProduct , conf_desc );
1369
1429
}
1370
1430
1431
+ /* Initialize NSO GameCube controllers */
1432
+ if ((desc .idVendor == 0x057e ) && (desc .idProduct == 0x2073 )) {
1433
+ init_nsogcn (dev -> device_handle );
1434
+ }
1435
+
1371
1436
/* Store off the string descriptor indexes */
1372
1437
dev -> manufacturer_index = desc .iManufacturer ;
1373
1438
dev -> product_index = desc .iProduct ;
0 commit comments