samedi 19 mars 2016

RetroPie's gamecon driver - readme.gz

(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.

3.1 NES & SNES gamepads

 

Rpi pin
SNES controller pinNES 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.

3.2 N64 pads


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.

3.3 Gamecube pads


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.

3.4 PSX/PS2 pads



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.

4. Configuring the driver


 
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

9 commentaires:

  1. Hi! Do you have an idea of how to manually install the gamecon drivers from the .deb-packages and kernel headers here? http://www.niksula.hut.fi/~mhiienka/Rpi/

    When installing a PiTFT screen, it downgrades the kernel to 4.1.14 v7, which won't work with the updated Retropie, and you can't upgrade the kernel, or it breaks PiTFT support... The only workaround I can imagine is using the .deb and matching older 4.1.14 v7 headers there, but I don't know how to actually do that.

    RépondreSupprimer
  2. would be like connecting two joysticks snes.
    if you can help me I am grateful . ass rotroo@gmail.com

    RépondreSupprimer
  3. Hi there, I think that the pinout of the PSX/PS2 connnector is the other way around. Left pin is DATA instead of the right pin in your drawing. You probably mixed up the male connector (in your photograph) with the female connector. I just used the pinout of the following picture on an Arduino with succes. http://makezine.com/wp-content/uploads/2008/06/ps2_controller_pinout.jpg

    RépondreSupprimer
  4. I'm sorry but section 4 as referred to in "See section 4 on how to select the correct GPIO." is quite confusing, it still leaves me a bit uncertain of where I am supposed to connect my data and most of all how to configure it? It feels like this could be explained simpler, maybe I'll try to explain it to other people like me after I've figured this out.

    As I've understood it I can connect my data pin to any of the GPIO2,3,4 and 7. Then just define it by the order of the number where I put my 2 for a NES controller when I load the module? So when I load the module and have chosen GPIO4, it'd be" map=0,0,0,0,2,0"?

    I have a Raspberry Pi 3 by the way, which makes me wonder if I want to use GPIO07, am I supposed to wire it to board pin 26 instead of board pin 14?

    Thank you for your effort!

    RépondreSupprimer
    Réponses
    1. Greetings, happy new year and thanks for your comment, Torgny.

      GPIO4 pin is for the third pad so it's 0,0,2,0,0,0 whereas your config. would require you to plug the NES data to GPIO2 pin :)

      " # modprobe gamecon_gpio_rpi map=*,*,,,, " (chapter 4.1)

      And yes, pin 14 is a ground so pin 26 is correct for GPIO7 (cf. the big picture at the beginning of chapter 3)

      I wish you success in your tinkering :)
      Best regards and looking forward to hear back from you :)
      Nico

      Supprimer
    2. What a quick and polite reply! I have understood it now but I am currently struggling with a failing gamecon GPIO driver install that I have to figure out before moving on.

      Supprimer
    3. Ok, solved! It's all up and running! I did "modprobe gamecon_gpio_rpi map=0,0,2,0,0,0" but I still must say I would have found the order difficult to figure out without your help.

      Supprimer
    4. Ce commentaire a été supprimé par l'auteur.

      Supprimer
    5. I'm glad my article helped. I struggled a lot before figuring that stuff out. Linux is a pain in the neck and I'm too old to learn it just to play a few games :)
      Take care.

      Supprimer