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 »

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 »

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: 5768
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Creating firmware to emulate the Nintendo Switch Pro Controller

Post by Matlo »

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
aterial
Posts: 13
Joined: Fri Sep 22, 2017 7:01 am

Re: Creating firmware to emulate the Nintendo Switch Pro Controller

Post by aterial »

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: 5768
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Creating firmware to emulate the Nintendo Switch Pro Controller

Post by Matlo »

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
aterial
Posts: 13
Joined: Fri Sep 22, 2017 7:01 am

Re: Creating firmware to emulate the Nintendo Switch Pro Controller

Post by aterial »

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 »

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: 5768
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Creating firmware to emulate the Nintendo Switch Pro Controller

Post by Matlo »

Congrats for your achievement and please share your work :)
GIMX creator
aterial
Posts: 13
Joined: Fri Sep 22, 2017 7:01 am

Re: Creating firmware to emulate the Nintendo Switch Pro Controller

Post by aterial »

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.
conzar
Posts: 2
Joined: Sun Jun 24, 2018 10:46 pm

Re: Creating firmware to emulate the Nintendo Switch Pro Controller

Post by conzar »

I am in the process of building a GIMX and would like to use GIMX with my nintendo switch. How do I integrate the switch into GIMX?
https://github.com/AterialDawn/Nintendo ... R-Firmware
Post Reply