SDL icon indicating copy to clipboard operation
SDL copied to clipboard

[hidapi] Whitelisting for libusb-only devices

Open flibitijibibo opened this issue 3 years ago • 2 comments

We've had support for Nintendo's official GameCube adapter for a while...

https://github.com/libsdl-org/SDL/blob/main/src/joystick/hidapi/SDL_hidapi_gamecube.c

... but the big problem that's always kept it locked away is that it requires libusb. This is because while it looks like a HID, it doesn't act like one: You have to manually initialize it with a magic number, then it suddenly starts acting like a real input device. This means the normal paths are out of the question (with the exception of writing support into the kernel, which is way out of my league and I don't know anyone else that wants to do it), and since libusb is too aggressive to enable by default most developers ship without it.

But from what I recall, it only takes exclusive control once you open the device, not during enumeration (unless you go out of your way to enable a flag that detaches drivers during enumeration). On top of that, the way we enumerate in SDL is by getting the libusb devices first, then the platform implementation next. So I wonder if, for platforms with non-libusb backends, we could make a whitelist for devices that require libusb and then ignore the rest of what the backend finds, with the expectation that the platform API will pick those up the Proper Way(TM).

Odds are this would just be for WUP-028, but I wonder if there are other devices out there like this? In any case, this seems like the best way to achieve the ultimate goal for SteamOS controller support provided the idea actually works.

CC: @slouken

flibitijibibo avatar Aug 05 '22 08:08 flibitijibibo

Yeah, that sounds like a good idea to me.

slouken avatar Aug 05 '22 17:08 slouken

Going to try and write this either tonight or tomorrow - FNA's been shipping with libusb support for a while so we have more than enough test data on our end to work with here.

flibitijibibo avatar Aug 05 '22 19:08 flibitijibibo