Using raphnet-tech adapters with RetroPie
IntroductionThe RetroPie project is a great alternative to using a full PC for your retro-gaming and emulation needs. The low cost, low power consumption and small form factor of the Raspberry Pi make it a perfect fit for the living room, just as your beloved consoles.
RetroPie is Linux based, so all raphnet-tech USB adapters are natively supported. But as I learned about small complications in getting multi-controller adapters to work, I created this page to help.
Adapters that simply work out of the boxGood news, most of our products are supported without doing anything special. For instance:
- NES controller to USB adapter
- SNES controller to USB adapter (single player version)
- Genesis/SMS/Atari controller to USB adapter
- Sega saturn controller to USB adapter
- ... And other single-player circuit kits and adapters.
Multiplayer adapters : Issue with initial values (pointing north-west)
The symtomsConstant scrolling in the game menus, undesired scrolling when switch back to the EmulationStation menu.
The issue explainedUnder Linux, the initial values of USB HID joysticks are not initialized properly. The way things currently are, even though the current values are requested from the adapter when it is first connected, the answer is ignored. This results in an inital axis postion pointing North-West.
When there are several controllers or adapters connected, or if you are using one of our multi controller adapters, this has consequences. Imagine you navigate the EmulationStation menu using the first controller. Then you start a game that supports two players. You have used the first joystick, so the incorrect inital values have long been replaced. But the second joystick you have not yet touched is still pointing in the upper left direction, so the game sees a non-centred player 2 joypad. If the game main menu is controllable by both players, you get a continuously moving cursor until you press a button on the second Joystick. That's an easy workaroud.
But if you have a four controller adapter with only ports 1 and 2 wired, how will you press buttons on joysticks 3 and 4 if their non-centered initial positions are causing unwanted operations? Well you can't, and that's a problem!
Solution : Patching the kernelI wrote 3 patches which together solve the issue:
- usbhid_iostart.diff : Makes sure the answer to the initial GET_REPORTs are not dropped due to a lock being held.
- usbhid_start_before_connect.diff : Makes sure initial events resulting of the above patch occur after the input layer is connected (otherwise the events are lost and the problem remains)
- jsdev_initial_value.diff : Make sure jsdev generates initial events that are representative of the current state. Not strictly required since EmulationStation seems to be using evdev, but just in case.
# Getting the kernel source $ git clone ... # (see the raspberrypi.org page mentionned above) # Downloading the patches $ wget www.raphnet-tech.com/support/retropie/usbhid_iostart.diff $ wget www.raphnet-tech.com/support/retropie/usbhid_start_before_connect.diff $ wget www.raphnet-tech.com/support/retropie/jsdev_initial_value.diff # Applying the patches $ cd linux $ patch -p1 < ../usbhid_iostart.diff $ patch -p1 < ../usbhid_start_before_connect.diff $ patch -p1 < ../jsdev_initial_value.diff
Follow the instructions from the aforementionned page to compile and install the kernel, reboot and enjoy!
Multiplayer adapters and pre-4.2 kernels (old)
Note: This section does not apply to RetroPie 3.8 SD card images, thanks to the use of a 4.4 series kernel.The way multi-player adapters and boards are implemented make them appear as one single controllers in Linux. For instance, the adapters based on the 4nes4snes board (eg: Four SNES to USB) used to register as a joystick with 4 pairs of axes, and 32 buttons (8 per controller). But at some point, this became 2 axis (a mix of all controllers) but still 32 buttons.
This is verifiable by running the jstest program:
pi@retropie:~ $ jstest /dev/input/js0 Driver version is 2.1.0. Joystick (raphnet.net 4nes4snes) has 2 axes (X, Y) and 32 buttons (...)
To fix this problem, I wrote a kernel patch to make the adapters appear as a set of independant controllers in march 2015 and it was included in the Linux kernel starting at version 4.2.0. With this patch, things are cleaner than ever. But as 2016-05-02, the kernel included in the RetroPie SD images is still one of the 4.1 series... So besides waiting, what can one do? Of course geting the kernel sources, applying the patch, compiling and installing it! But there is an easier way.
You can add the following to the kernel command-line, and it will have the same effect as the patch.
You may not feel comfortable editing the file using the command line as after all, it can make you SD image unbootable if you are not careful. So I made this this simple script which is safer:usbhid.quirks=0x289b:0x0002:0x40,0x289b:0x0003:0x40,0x1781:0x0a9d:0x40
Upload the script to the Pi, ssh into the pi. Make sure the script is executable by using chmod on it, then run it once.
Now reboot, and your multiplayer adapter now appears as multiple controllers! Enjoy!pi@retropie:~ $ sudo chmod +x addRaphnetQuirks.sh pi@retropie:~ $ sudo ./addRaphnetQuirks.sh Raphnet-tech cmdline.txt updater script for USB HID quirks, v0.1 www.raphnet-tech.com/support/retropie/ Successfully updated /boot/cmdline.txt