Added support for the Nintendo GameCube adapter, tested on Steam Link hardware

This commit is contained in:
Sam Lantinga 2019-12-30 09:44:32 -08:00
parent 9340cfa9a1
commit a9482a1d60
3 changed files with 32 additions and 15 deletions

View File

@ -535,9 +535,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
struct PLATFORM_hid_device_info *raw_dev;
#endif /* HAVE_PLATFORM_BACKEND */
struct hid_device_info *devs = NULL, *last = NULL, *new_dev;
#ifdef SDL_LIBUSB_DYNAMIC
SDL_bool bFound;
#endif
if (SDL_hidapi_wasinit == SDL_FALSE) {
hid_init();
@ -557,6 +555,10 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
bFound = SDL_FALSE;
#if HAVE_PLATFORM_BACKEND
for (raw_dev = raw_devs; raw_dev; raw_dev = raw_dev->next) {
if (raw_dev->vendor_id == 0x057e && raw_dev->product_id == 0x0337) {
/* The GameCube adapter is handled by the USB HIDAPI driver */
continue;
}
if (usb_dev->vendor_id == raw_dev->vendor_id &&
usb_dev->product_id == raw_dev->product_id &&
(raw_dev->interface_number < 0 || usb_dev->interface_number == raw_dev->interface_number)) {
@ -585,16 +587,28 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
#if HAVE_PLATFORM_BACKEND
if (udev_ctx) {
for (raw_dev = raw_devs; raw_dev; raw_dev = raw_dev->next) {
new_dev = (struct hid_device_info*) SDL_malloc(sizeof(struct hid_device_info));
PLATFORM_CopyHIDDeviceInfo(raw_dev, new_dev);
new_dev->next = NULL;
if (last != NULL) {
last->next = new_dev;
} else {
devs = new_dev;
bFound = SDL_FALSE;
for (new_dev = devs; new_dev; new_dev = new_dev->next) {
if (raw_dev->vendor_id == new_dev->vendor_id &&
raw_dev->product_id == new_dev->product_id &&
raw_dev->interface_number == new_dev->interface_number) {
bFound = SDL_TRUE;
break;
}
}
if (!bFound) {
new_dev = (struct hid_device_info*) SDL_malloc(sizeof(struct hid_device_info));
PLATFORM_CopyHIDDeviceInfo(raw_dev, new_dev);
new_dev->next = NULL;
if (last != NULL) {
last->next = new_dev;
} else {
devs = new_dev;
}
last = new_dev;
}
last = new_dev;
}
PLATFORM_hid_free_enumeration(raw_devs);
}

View File

@ -98,6 +98,9 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
goto error;
}
/* Wait for the adapter to initialize */
SDL_Delay(10);
/* Add all the applicable joysticks */
while ((size = hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
if (size < 37 || packet[0] != 0x21) {

View File

@ -734,11 +734,11 @@ HIDAPI_AddDevice(struct hid_device_info *info)
SDL_HIDAPI_devices = device;
}
#ifdef DEBUG_HIDAPI
SDL_Log("Added HIDAPI device '%s' VID 0x%.4x, PID 0x%.4x, version %d, interface %d, usage page 0x%.4x, usage 0x%.4x, driver = %s\n", device->name, device->vendor_id, device->product_id, device->version, device->interface_number, device->usage_page, device->usage, device->driver ? device->driver->hint : "NONE");
#endif
HIDAPI_SetupDeviceDriver(device);
#ifdef DEBUG_HIDAPI
SDL_Log("Added HIDAPI device '%s' VID 0x%.4x, PID 0x%.4x, version %d, interface %d, usage page 0x%.4x, usage 0x%.4x, path = %s, driver = %s\n", device->name, device->vendor_id, device->product_id, device->version, device->interface_number, device->usage_page, device->usage, device->path, device->driver ? device->driver->hint : "NONE");
#endif
}