(I retrieved this documentation through zless /usr/share/doc/gamecon_gpio_rpi/README.gz and tried to make it a bit friendlier.)
Game controller driver for Raspberry Pi's GPIO v1.0
1. Intro
The driver is designed to be used with retro game controllers connected to Raspberry Pi's GPIO. Currently, up to 4 controllers of following types are supported:
-
NES gamepads
-
SNES gamepads
-
PSX/PS2 gamepads
-
N64 gamepads
-
Gamecube gamepads
The driver is based on
gamecon driver (see Documentation/input/joystick-parport.txt), but uses different pinout and parameters. No warranty - use at your own risk.
2. Required hardware
-Raspberry Pi and supported controllers
-Jumper wires between GPIO and pads
-Breadboard or splitter if multiple controllers are connected simultaneously
3. Connecting the controllers
Note that the GPIO input numbers do not match pin numbers.
GPIO pinout (all boards):
http://elinux.org/Rpi_Low-level_peripherals
Pins
P1-01 and
P1-06 are used as common power and ground for all controllers. Note that 3.3V is used for all controllers, even if SNES&NES pads nominally are operated at 5V. They should work fine with 3.3V so no level shifters are needed for data pins. The maximum current spec. (50mA) should be enough for 4 controllers. However, use a proper ac adapter with Pi to avoid any unwanted voltage drops.
Pins
P1-03,
05,
07,
26 (GPIO0, GPIO1, GPIO4 and GPIO7 on older Pi boards) are independent data pins, one per pad.
NOTE: P1-03 & P1-05 correspond to GPIO2 & GPIO3 in rev.2 board, which must taken into account when loading the module. This is explained in
section 4.
Pins
P1-19 &
P1-23 (GPIO10 & 11) are common signal pins for all NES/SNES pads.
Pins
P1-08,
P1-10 &
P1-12 (GPIO14, 15 & 18) are common signal pins for all PSX/PS2 pads.
Rpi pin |
| SNES controller pin | NES controller pin |
P1-01 (3.3V)
GPIO10
GPIO11
GPIOXX
P1-06 (GND) | ====
--->
--->
<---
==== | 1 (power)
2 (clock)
3 (latch)
4 (serial data)
7 (ground) | 1 (power)
5 (clock)
6 (latch)
7 (data)
4 (ground) |
GPIOXX is the independent data pin. See
section 4 on how to select the correct GPIO.
Rpi pin N64 controller pin
P1-01 (3.3V) ==== power
GPIOXX <--> data
P1-06 (GND) ==== ground
GPIOXX is the independent data pin. See
section 4 on how to select the correct GPIO.
Rpi pin Gamecube controller pin
P1-01 (3.3V) ==== 6 (power/3.43V)
GPIOXX <--> 3 (data)
P1-06 (GND) ==== 2&5 (gnd)
GPIOXX is the independent data pin. See
section 4 on how to select the correct GPIO.
Rpi pin PSX controller pin (numbered right to left)
P1-01 (3.3V) ====
5 (power/3.3V)
GPIO14 --->
2 (command)
GPIO15 --->
6 (select)
GPIO18 --->
7 (clock)
GPIOXX <---
1 (data)
P1-06 (GND) ====
4 (ground)
GPIOXX is the independent data pin. See section 4 below on how to select the correct GPIO.
Perform the following operations as
root (or with
sudo):
4.1 Configure pads
# modprobe gamecon_gpio_rpi map=<pad1/GPIO0>*,<pad2/GPIO1>*,<pad3/GPIO4>,<pad4/GPIO7>,<pad5/GPIO2>,<pad6/GPIO3>
where <pad...> is a number defining the pad type:
0 = no connection
1 = SNES pad
2 = NES pad
3 = Gamecube pad
6 = N64 pad
7 = PSX/PS2 pad
8 = PSX DDR controller
9 = SNES mouse
For example (on a rev.1 Raspberry Pi), if a SNES pad is connected to GPIO0 and a N64 pad to GPIO7, the command would be "modprobe gamecon_gpio_rpi map=1,0,0,6".
* NOTE: pad1 & pad2 are only used with rev.1 board, and pad5 and pad6 with rev.2. So if you have rev.2 board, pad1 and pad2 must be set as 0.
Connecting these two controllers on a more recent Pi requires something like map=0,0,1,6,0,0 (if you use GPIOs 4 and 7).
The final
pad index (used by the programs) is assigned sequentially for connected pads starting from 0. So in the previous example, snes pad would get index 0 and N64 pad index 1.
Use "
tail /var/log/kern.log" to verify that module loading was successful
4.2 Testing the pads
# apt-get install joystick
# jstest /dev/input/jsX
where
X corresponds to the
pad index (0-3)
4.3 Calibrating the axis of N64 analog pad
#
jscal -s 4,1,0,0,0,6972137,6972137,1,0,0,0,6547006,6468127,1,0,0,0,536854528,536854528,1,0,0,0,536854528,536854528 /dev/input/jsX
for each N64 controller
4.4 Setting access delay for psx pads
The access delay for PSX pads is set to 10us, which minimizes the performance penalty caused by the driver. However, in some rare cases it may not be enough to get stable input. If you have issues when reading psx pads, raise the delay with following extra modprobe parameter:
"
psx_delay=<delay>". <delay> is value in us, and can be set between 1-50.
5. More information
-
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=78&t=15787
-
https://github.com/petrockblog/RetroPie-Setup/wiki/Module-for-GPIO-interface-for-retro-game-controllers
The contents of this blog are free. You can however make an indirect donation buying a fun T-shirt. There are a few examples in this article :
100% of each donation goes to persons living below the poverty line. Thanks again and have a nice day.