Skip to content

Commit

Permalink
Added support for the Nintendo GameCube adapter, tested on Steam Link…
Browse files Browse the repository at this point in the history
… hardware
  • Loading branch information
slouken committed Dec 30, 2019
1 parent 9340cfa commit a9482a1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
36 changes: 25 additions & 11 deletions src/hidapi/SDL_hidapi.c
Expand Up @@ -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();
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions src/joystick/hidapi/SDL_hidapi_gamecube.c
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/joystick/hidapi/SDL_hidapijoystick.c
Expand Up @@ -734,11 +734,11 @@ HIDAPI_AddDevice(struct hid_device_info *info)
SDL_HIDAPI_devices = device;
}

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, 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");
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

HIDAPI_SetupDeviceDriver(device);
}


Expand Down

0 comments on commit a9482a1

Please sign in to comment.