Creating firmware to emulate the Nintendo Switch Pro Controller

Talk about anything concerning the source code.
aterial
Posts: 13
Joined: Fri Sep 22, 2017 7:01 am

Re: Creating firmware to emulate the Nintendo Switch Pro Controller

Post by aterial » Fri Oct 13, 2017 3:31 am

Alright, i figured out the transport fail error. Guess lufa or the avr usb stack doesnt like there being an IN endpoint and an OUT endpoint on the same address, so i just swapped the OUT address to 0x02. The firmware can now read incoming requests from the switch, and react accordingly.
The only problem now is that the switch doesn't want to detect the firmware as a controller, so it seems i'm still missing something.
http://www38.zippyshare.com/v/PjZ1M3gX/file.html
Filter for this dump is (usb.addr contains "1.87.")
The communication LOOKS okay, the firmware is reading the input data just fine, and replying to it correctly, so im kinda stumped here. I'm taking a break for now and trying again tomorrow.

aterial
Posts: 13
Joined: Fri Sep 22, 2017 7:01 am

Re: Creating firmware to emulate the Nintendo Switch Pro Controller

Post by aterial » Tue Oct 31, 2017 6:51 am

Alright I got it working. The switch correctly detects the firmware as an official Switch Pro Controller. The only things left to do now are figure out how to encode the thumbstick/gyro/accel data into a format the switch expects. I'm not that good at figuring out how bitshifting/bitmasks work (which apparently are crucial as thumbstick data is encoded by shifting and masking certain bits), so i'm struggling quite a bit here. If you'd like to help me figure out exactly how to encode this thumbstick/gyro/accel data I would greatly appreciate it.

User avatar
Matlo
Posts: 4451
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Creating firmware to emulate the Nintendo Switch Pro Controller

Post by Matlo » Tue Oct 31, 2017 9:46 pm

I can help, the only thing I need is a capture (or multiple captures) with comments on which control is being changed at which time.
GIMX creator Donate Shop

aterial
Posts: 13
Joined: Fri Sep 22, 2017 7:01 am

Re: Creating firmware to emulate the Nintendo Switch Pro Controller

Post by aterial » Wed Nov 01, 2017 1:04 am

Looks like someone else figured out how to properly decode the stick/gyro data to somewhat-usable values.
https://github.com/dekuNukem/Nintendo_S ... stick-data
I'll try and implement this on a test program i have and see if the switch accepts the values i send to it.

User avatar
Matlo
Posts: 4451
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Creating firmware to emulate the Nintendo Switch Pro Controller

Post by Matlo » Wed Nov 01, 2017 11:25 am

Stick coordinates are packed on 3 bytes. Try something like this:

Code: Select all

uint16_t stick_x = clamp(0, axis[index_x] + 0x7FF, 0xFFF);
uint16_t stick_y = clamp(0, axis[index_y] + 0x7FF, 0xFFF);

coords[0] = stick_x & 0xFF;
coords[1] = ((stick_x >> 8) & 0x0F) | ((stick_y & 0x0F) << 4);
coords[2] = stick_y >> 4;
GIMX creator Donate Shop

aterial
Posts: 13
Joined: Fri Sep 22, 2017 7:01 am

Re: Creating firmware to emulate the Nintendo Switch Pro Controller

Post by aterial » Wed Nov 01, 2017 11:55 pm

Thanks for that! The switch is now correctly detecting the joysticks using the formula you gave me! I'll try and mess with the gyroscope values now and see what I can come up with.

Edit:
Early celebrations wew. Left stick is properly detected, right stick seems to trigger certain buttons. Seems like i messed up somewhere, gonna try and dump communications and see where i went wrong
Edit edit:
disregard me i slightly messed up a memcpy on a serial routine

The current goal now is to get sensible gyroscope values. I'll see what I can do about that.

aterial
Posts: 13
Joined: Fri Sep 22, 2017 7:01 am

Re: Creating firmware to emulate the Nintendo Switch Pro Controller

Post by aterial » Mon Nov 06, 2017 5:13 am

well, its done. updates at the expected maximum rate of 120 updates per second, with full gyroscope/accelerometer support. rumble info is not sent over serial to the hosting application since i personally dont feel thats necessary, but it can be added by parsing specific packets. i made a simple c# program that acts as a mini-gimx to test with, since the current firmware uses my own protocol. i even tested it out in splatoon 2 to check out how well it controls and, other than small issues with the proper Z value to use (which i'm currently attempting to fix), it works quite well!
i'll go ahead and start cleaning up/commenting my code and i'll send it over to you to implement with gimx as you see fit!

User avatar
Matlo
Posts: 4451
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Creating firmware to emulate the Nintendo Switch Pro Controller

Post by Matlo » Tue Nov 07, 2017 9:10 pm

Congrats for your achievement and please share your work :)
GIMX creator Donate Shop

aterial
Posts: 13
Joined: Fri Sep 22, 2017 7:01 am

Re: Creating firmware to emulate the Nintendo Switch Pro Controller

Post by aterial » Mon Nov 13, 2017 1:35 am

Sorry for the delays, here ya go!
If you have any questions about the serial protocol, lemme know but it should be fairly self-explanatory.

Post Reply