Added support for the Nintendo GameCube adapter, tested on Steam Link hardware
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
diff --git a/src/hidapi/SDL_hidapi.c b/src/hidapi/SDL_hidapi.c
index c35c44f..f320c76 100644
--- a/src/hidapi/SDL_hidapi.c
+++ b/src/hidapi/SDL_hidapi.c
@@ -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);
}
diff --git a/src/joystick/hidapi/SDL_hidapi_gamecube.c b/src/joystick/hidapi/SDL_hidapi_gamecube.c
index 34648f9..197c2a3 100644
--- a/src/joystick/hidapi/SDL_hidapi_gamecube.c
+++ b/src/joystick/hidapi/SDL_hidapi_gamecube.c
@@ -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) {
diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index 3248769..b9277f9 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -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);
}