-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Switch 2 Controller Support #13327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch 2 Controller Support #13327
Conversation
Well, my preferred name would be just Nohzockt or Noah, no email or something special. I feel honoured that you ask me. Thanks a lot. |
Done! I also cleaned up the button reading and made a working gamepad mapping, once the left/right stick are working this is ready to review. |
Quick question. I was able to generate an SDL3.dll file with your WIP stub, would an SDL2.dll be able to be generated as well or this still a work in progress? I am wondering how these can be built for executables like emulators or steam API. |
I have some devices I can test in addition to the GC controller so I might want to add those to this PR if possible. I can create a branch off of your branch, or add them after this is merged. |
Whatever works! I can add commits to this PR if Sam doesn't get to it first. |
int size; | ||
while ((size = SDL_hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) { | ||
if (size > 14) { | ||
Uint64 timestamp = SDL_GetTicksNS(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block should be refactored out into a separate function to handle devices with varying capabilities and report formats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe all NS2 devices report the same layout (passing 0 for unsupported axes like the GCN triggers) but @endrift can confirm this.
040524d
to
01f8dea
Compare
Does this support Bluetooth? What changes would need to be made for rumble and gyro support? |
I haven't looked over the code yet, but I tested the controller and discovered a few things that might want improvements:
|
Unfortunately no, the only interface that's exposed as-is is the first interrupt endpoint |
Hi, I've been following the development of this for a bit since I got a GC NS2 controller, I saw on the open issue that there's some work to be done for the sticks and triggers, I wonder if there's any way I could help? I'm not super familiar with the code here, but I'd be happy to contribute. I currently have a mac if that helps |
Unfortunately the current holdup is mostly about internal design issues. The calibration stuff can be fairly easily solved once that's resolved based on information provided both in this thread and on other sites in the meantime. |
I've started looking into how to plumb through the necessary pointers and I'm not really making much progress. Short of really hacky smuggling of pointers and type punning, I'm not sure any even halfway-decent way to architect this. The SDL_hidapi abstraction layer doesn't provide a way of determining the backend so you can safely cast the device pointer, afaict, but maybe I'm overlooking how the ifdefs are used. I would appreciate it if someone who's more familiar with the codebase could "bless" a way to get the libusb_device pointer out of a SDL_HIDAPI_Device. The alternative, however, is adding "side channels" to SDL_HIDAPI_Devices that you can look up and communicate with. While most game controllers only have one channel to worry about, we will need to deal with side channels once we get to bluetooth too. |
My plan was likely going to be to do all the bulk interactions on init and add the calibration data as a pointer property to the hid_device; this assumes that all the work could fit in init_ns2 though... I'm just skipping rumble for now, that's a whole other issue that might become obsoleted if we ever figure out BLE support. |
I have a Nintendo Switch 2 Pro controller now, and a plan to plumb the secondary device through. I'll take a swing at this when I have time, hopefully sometime this week. |
After that's plumbed through, adding calibration should be enough for an initial merge. Rumble will have to wait a bit, as will bluetooth, but those can come later I think |
I checked out your branch and built with libusb support, but I'm not seeing any packets come in, after successful initialization. I'm running on Windows, hopefully that doesn't matter. Any ideas? |
Only thing I can think of is it needing the WinUSB fuss like the GameCube adapter did, but I haven't seen anyone else use it - @endrift have you tried this on Windows by chance? |
Ah, the problem was that the interface wasn't claimed. I'll add a commit to the PR to fix that. |
Okay, the libusb bulk endpoint is now available to the driver. Party on! |
#include "SDL_libusb.h" | ||
|
||
#ifdef HAVE_LIBUSB | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#ifdef SDL_LIBUSB_DYNAMIC | |
SDL_ELF_NOTE_DLOPEN( | |
"libusb", | |
"Support for joysticks through libusb", | |
SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, | |
SDL_LIBUSB_DYNAMIC | |
); | |
#endif | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That won't compile yet, this PR is based on older SDL3 main. We'll have to add that after it's merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's also why I didn't regenerate the dynapi files, because I don't want to cause conflicts there.
Okay, I think this is ready for iteration in main, so I'll go ahead and merge it. Thanks everyone who contributed! |
hey, is it a case where we had to have connected the controllers to a Switch 2 system already for it to work on PC via SDL? or are we all good out of the box? |
They'll work out of the box. Note that SDL needs to be built with libusb support and have access to low level USB devices which isn't usually the case. We'll have to figure out messaging around that. |
does steam do that with the version of SDL in their client? sorry for being a total newbie/outsider/etc asking all this LOL |
Steam does not build SDL with libusb enabled, since that normally requires root permissions and you should not run Steam as root. We'll figure out the right path forward once this driver matures and is ready for prime time. |
I'm pretty frustrated you just went ahead and merged this without additional feedback. It wasn't ready and now I'm gonna have to fix it on main instead in a PR. |
Sorry, I didn't realize you were actively working on this, feel free to submit a PR when you're ready. |
Fixes #13178.
Device init and polling works, but I haven't translated the packets yet since
the public code doesn't line up with the automatic mappingsand I'm intentionally avoiding doing any further reverse engineering myself. Happy to add patches to get this PR working though!udev rule for Linux:
CC @Nohzockt: If you have a preferred name/email for
Co-authored-by
I'll apply it to the patch that implements the init/polling work.