wchill / SwitchInputEmulator

Nintendo Switch controller emulator that allows for serial input to control the Switch. Emulates a HORIPAD Wired Controller.
301 stars 39 forks source link

Arduino board is not recognized by Switch #10

Closed javmarina closed 5 years ago

javmarina commented 5 years ago

I have compiled the Joystick.hex and written a script in order to communicate via serial. Everything is wired correctly, as the Arduino UNO R3 receives the packets correctly. When synced, the board answers with 0x90 and if I connect it to the computer and go to https://html5gamepad.com/, it is shown as a gamepad and the button presses are correct. So the issue has to do with the Switch not recognizing it as a valid controller. Surprisingly, if I modify some parameters in the Descriptors.h file, it works. After a lot of trial and error, I have a working Descriptors.h. The modified version is inspired by the original from https://github.com/progmem/Switch-Fightstick. However, there are only a few differences between my modified version and the original file in this repository:

With these four changes, the Switch now recognizes the Arduino board. Note that I tried pressing L+R with the original file with no luck.

wchill commented 5 years ago

Hmm, something doesn't seem right here. The HORIPAD S descriptors are from an actual working controller, and in theory any USB HID compatible device should be recognized properly. I've been using those descriptors for months with no issues.

javmarina commented 5 years ago

I know it's strange. I may have done something wrong, but I followed the same steps for both descriptors. The board was synced and sending 0x80 ACKs.

wchill commented 5 years ago

A bit of a long shot, but do you have a setup that would allow you to MITM USB traffic between your Arduino and Switch? If so, I'd be interested in seeing what's going on.

javmarina commented 5 years ago

For now, I don't know how to analyze USB traffic. I will try it someday when I have spare time. I will also try modifying some of the parameters and install again the original firmware, just to check if I did something wrong. My plan is to start with the original code and then modify one of the parameters until it works again.

wchill commented 5 years ago

If you get a logic analyzer (I have a Saleae Logic Pro 16, but there are cheaper analyzers available) and a USB extension cable, I had some luck cutting into the cable and attaching my logic analyzer probes to the D+/D- wires. Since we are doing communication at USB 1.1 speeds, the sample rate requirement is not that high if you go this route.

javmarina commented 5 years ago

I just tried flashing the original firmware again and I got it working. My guess is that I didn't configure the system correctly. I tried connecting the cables in different order and it worked. Btw, do you know if those changes can affect something or are just "cosmetic"? I wonder if they make a real difference while playing.

wchill commented 5 years ago

@javmarina the USB related changes are technically just cosmetic; the descriptors I use are more "correct" since they're from a real product whereas the descriptors from the other project are modified, but there isn't really any difference in functionality.