Multi-console gamepad driver for GPIO


244 posts   Page 1 of 10   1, 2, 3, 4, 5 ... 10
by marqs » Mon Aug 27, 2012 4:33 pm
Hi,

I've modified the good old gamecon driver to work with Raspberry Pi's GPIOs. It allows using up to 4 controllers of the following types without any extra hardware (minus wires):

-NES gamepads
-SNES gamepads and mouses
-PSX/PS2 gamepads, wheels and DDR controllers
-N64 gamepads
-Gamecube gamepads

The latest version of the driver and instructions can be downloaded here and soon also with RetroPie-script. I've tested the driver only with 1st party controllers and with no more than 2 simultaneous pads (50mA limit should be enough for 4, however), so I'm interested to hear how it works with different setups. All other feedback is also appreciated.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by petrockblog » Mon Aug 27, 2012 5:42 pm
Thanks for the update!
I have just uploaded your archive to the Github repository.
On my own installation, however, I get the error message
Code: Select all
ERROR: could not insert 'gamecon_gpio_rpi': Exec format error

when I try to run
Code: Select all
modprobe gamecon_gpio_rpi map=0,1,1,0

I assume that this is because of the recent firmware update.
Code: Select all
uname -a

gives for me "Linux raspberrypi 3.2.27+ #66 PREEMPT Fri Aug 24 23:52:42 BST 2012 armv6l GNU/Linux"

I assume that you have compiled the module for 3.1.9+? I could provide downloads for different firmwares on the Github repository ...

Nevertheless, thanks a lot for the hard work!
fun stuff for technics enthusiasts: www.petrockblock.com
Posts: 265
Joined: Wed Jul 04, 2012 6:12 am
Location: Germany
by toxibunny » Mon Aug 27, 2012 5:52 pm
Brilliant, thankyou :)
note: I may or may not know what I'm talking about...
Posts: 1174
Joined: Thu Aug 18, 2011 9:21 pm
by marqs » Mon Aug 27, 2012 6:18 pm
I assume that you have compiled the module for 3.1.9+? I could provide downloads for different firmwares on the Github repository ...

I'd better set this one to use dkms for better compatibility across different kernels, the compilation shouldn't take too much time even on Pi.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by petrockblog » Mon Aug 27, 2012 8:12 pm
marqs wrote:
I assume that you have compiled the module for 3.1.9+? I could provide downloads for different firmwares on the Github repository ...

I'd better set this one to use dkms for better compatibility across different kernels, the compilation shouldn't take too much time even on Pi.

Having an idea about what dkms is that sounds like a good idea - I have no idea how hard this is to implement, though.
fun stuff for technics enthusiasts: www.petrockblock.com
Posts: 265
Joined: Wed Jul 04, 2012 6:12 am
Location: Germany
by marqs » Thu Aug 30, 2012 5:07 pm
I've now generated a dkms deb, but the installation requires kernel headers which are unavailable for Rpi kernels installed by rpi-update. There are standard format kernels available (plus headers) in the raspbian repo, but they are not as recent and don't have the option to change CPU/GPU memory allocation.

For those using 3.2.27, I created a new zip with rebuilt module.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by petrockblog » Thu Aug 30, 2012 6:55 pm
marqs wrote:I've now generated a dkms deb, but the installation requires kernel headers which are unavailable for Rpi kernels installed by rpi-update. There are standard format kernels available (plus headers) in the raspbian repo, but they are not as recent and don't have the option to change CPU/GPU memory allocation.

For those using 3.2.27, I created a new zip with rebuilt module.


Code: Select all
uname -a
gives
Code: Select all
3.2.27+
for me. However, when I try to insert the module I get
Code: Select all
ERROR: could not insert 'gamecon_gpio_rpi': Exec format error

What would you look for in the first place to solve this problem?
fun stuff for technics enthusiasts: www.petrockblock.com
Posts: 265
Joined: Wed Jul 04, 2012 6:12 am
Location: Germany
by petrockblog » Thu Aug 30, 2012 7:14 pm
marqs wrote:I've now generated a dkms deb, but the installation requires kernel headers which are unavailable for Rpi kernels installed by rpi-update. There are standard format kernels available (plus headers) in the raspbian repo, but they are not as recent and don't have the option to change CPU/GPU memory allocation.


So, people that used rpi-update for a firmware update cannot use the .deb package, right?
fun stuff for technics enthusiasts: www.petrockblock.com
Posts: 265
Joined: Wed Jul 04, 2012 6:12 am
Location: Germany
by marqs » Thu Aug 30, 2012 7:35 pm
petrockblog wrote:
Code: Select all
ERROR: could not insert 'gamecon_gpio_rpi': Exec format error

What would you look for in the first place to solve this problem?

Did you run "depmod -a" after copying the file to the module path? If there is also an older version in /lib/modules/3.2.27+/... , loading may also fail. Try removing the module, run "depmod -a" and try to load it. It should report that module is not found. Then copy it again to the module path, run "depmod -a" and it should load ok now.

petrockblog wrote:
marqs wrote:I've now generated a dkms deb, but the installation requires kernel headers which are unavailable for Rpi kernels installed by rpi-update. There are standard format kernels available (plus headers) in the raspbian repo, but they are not as recent and don't have the option to change CPU/GPU memory allocation.


So, people that used rpi-update for a firmware update cannot use the .deb package, right?

Yeah, not until headers are made available for those kernels.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by marqs » Sun Sep 02, 2012 2:23 pm
It seems that the update to 3.2.27+ kernel on 29.8 has made the pre-built module incompatible ("module_layout" symbol has changed, as can be seen by studying commit changes). I've taken the 3.2.27+ module offline, since there's no point providing that if any kernel update (even on same version) may break the compatibility.

DKMS is the only option now, so I've been looking into generating the headers package for the kernels downloaded with rpi-update. I've now made a headers deb for 3.2.27+, which downloads the newest Module.symvers from github during postinst, and prepares the module build environment. This makes building DKMS modules possible for all 3.2.27+ updates. It is not the most optimal solution, but neither is updating the kernel with a script instead of apt. The actual header files are not dynamically downloaded like Module.symvers, but they are unlikely to get updated within 3.2.27+ branch, at least not the ones needed by gamecon. However, new kernel versions require new headers, which I'll have to provide.

So the build instructions for rpi-update -users are as follows: (run as root or with sudo)
Code: Select all
#update to the most recent version and reboot
rpi-update
reboot

#install dkms, download headers and gamecon
apt-get install dkms
wget http://www.niksula.hut.fi/~mhiienka/Rpi/linux-headers-rpi/linux-headers-3.2.27+_3.2.27+-1_armhf.deb
wget http://www.niksula.hut.fi/~mhiienka/Rpi/gamecon-gpio-rpi-dkms_0.5_all.deb

#install headers and gamecon (takes some time)
dpkg -i linux-headers-3.2.27+_3.2.27+-1_armhf.deb
dpkg -i gamecon-gpio-rpi-dkms_0.5_all.deb

After that, loading is done with modprobe as explained in /usr/share/doc/gamecon_gpio_rpi/README.gz

When rpi-update is used to update kernel next time, it is enough to run "dpkg-reconfigure linux-headers-3.2.27+" if still in 3.2.27+. Otherwise, matching headers should be grabbed from my site and installed.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by petrockblog » Sun Sep 02, 2012 8:26 pm
Thank you for your instructions! I have to adapt the RetroPie script in the next days then.
fun stuff for technics enthusiasts: www.petrockblock.com
Posts: 265
Joined: Wed Jul 04, 2012 6:12 am
Location: Germany
by petrockblog » Tue Sep 04, 2012 9:11 am
BTW: Did you get in contact with the Raspbian team and asked for including your driver into the official tree?
fun stuff for technics enthusiasts: www.petrockblock.com
Posts: 265
Joined: Wed Jul 04, 2012 6:12 am
Location: Germany
by petrockblog » Thu Sep 06, 2012 2:49 pm
petrockblog wrote:Thank you for your instructions! I have to adapt the RetroPie script in the next days then.

I have just updated the >RetroPie script< with your new module.
fun stuff for technics enthusiasts: www.petrockblock.com
Posts: 265
Joined: Wed Jul 04, 2012 6:12 am
Location: Germany
by marqs » Thu Sep 06, 2012 5:16 pm
petrockblog wrote:I have just updated the >RetroPie script< with your new module.
Thanks, that's great! One nice thing that could be added before module installation is a prompt to install newest firmware, since the automatically downloaded Module.symvers is always for the newest kernel.

petrockblog wrote:BTW: Did you get in contact with the Raspbian team and asked for including your driver into the official tree?
Not yet, but looking into the Raspbian branch, there doesn't seem to be any Rpi-specific drivers except the bcm2708 ones by Broadcom. Ideally the module would be for GPIO in general, and use normal gpio functions. That would work well with most controllers, but the timing is quite strict with N64 and GC pads, and any extra function calls (unless inline functions) makes reading those even harder.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by tooold » Tue Sep 11, 2012 11:50 pm
marqs wrote:It seems that the update to 3.2.27+ kernel on 29.8 has made the pre-built module incompatible ("module_layout" symbol has changed, as can be seen by studying commit changes). I've taken the 3.2.27+ module offline, since there's no point providing that if any kernel update (even on same version) may break the compatibility.

DKMS is the only option now, so I've been looking into generating the headers package for the kernels downloaded with rpi-update. I've now made a headers deb for 3.2.27+, which downloads the newest Module.symvers from github during postinst, and prepares the module build environment. This makes building DKMS modules possible for all 3.2.27+ updates. It is not the most optimal solution, but neither is updating the kernel with a script instead of apt. The actual header files are not dynamically downloaded like Module.symvers, but they are unlikely to get updated within 3.2.27+ branch, at least not the ones needed by gamecon. However, new kernel versions require new headers, which I'll have to provide.

So the build instructions for rpi-update -users are as follows: (run as root or with sudo)
Code: Select all
#update to the most recent version and reboot
rpi-update
reboot

#install dkms, download headers and gamecon
apt-get install dkms
wget http://www.niksula.hut.fi/~mhiienka/Rpi/linux-headers-rpi/linux-headers-3.2.27+_3.2.27+-1_armhf.deb
wget http://www.niksula.hut.fi/~mhiienka/Rpi/gamecon-gpio-rpi-dkms_0.5_all.deb

#install headers and gamecon (takes some time)
dpkg -i linux-headers-3.2.27+_3.2.27+-1_armhf.deb
dpkg -i gamecon-gpio-rpi-dkms_0.5_all.deb

After that, loading is done with modprobe as explained in /usr/share/doc/gamecon_gpio_rpi/README.gz

When rpi-update is used to update kernel next time, it is enough to run "dpkg-reconfigure linux-headers-3.2.27+" if still in 3.2.27+. Otherwise, matching headers should be grabbed from my site and installed.


Even with this method i do not get it to run.
Firmware: Linux raspberrypi 3.2.27+
Posts: 3
Joined: Tue Sep 11, 2012 11:47 pm
by marqs » Wed Sep 12, 2012 6:26 pm
tooold wrote:Even with this method i do not get it to run.
Firmware: Linux raspberrypi 3.2.27+
Does the building process go through without any errors, or is it modprobe which fails? In the latter case, could you please attach the output of "tail /var/log/kern.log" after modprobe.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by tooold » Wed Sep 12, 2012 7:31 pm
marqs wrote:Does the building process go through without any errors, or is it modprobe which fails? In the latter case, could you please attach the output of "tail /var/log/kern.log" after modprobe.


Everything works fine until i try to install
Code: Select all
dpkg -i linux-headers-3.2.27+_3.2.27+-1_armhf.deb

The following errors occurs:
Code: Select all
(Reading database ... 81998 files and directories currently installed.)
Preparing to replace linux-headers-3.2.27+ 3.2.27+-1 (using linux-headers-3.2.27+_3.2.27+-1_armhf.deb) ...
Unpacking replacement linux-headers-3.2.27+ ...
Removed /usr/src/linux-headers-3.2.27+
Setting up linux-headers-3.2.27+ (3.2.27+-1) ...
--2012-09-12 19:21:14--  https://github.com/raspberrypi/firmware/raw/master/extra/Module.symvers
Resolving github.com (github.com)... 207.97.227.239
Connecting to github.com (github.com)|207.97.227.239|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.github.com/raspberrypi/firmware/master/extra/Module.symvers [following]
--2012-09-12 19:21:19--  https://raw.github.com/raspberrypi/firmware/master/extra/Module.symvers
Resolving raw.github.com (raw.github.com)... 207.97.227.243
Connecting to raw.github.com (raw.github.com)|207.97.227.243|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 411903 (402K) [text/plain]
Saving to: `/usr/src/linux-headers-3.2.27+/Module.symvers'

100%[===================================================================================================================>] 411,903      290K/s   in 1.4s   

Last-modified header missing -- time-stamps turned off.
2012-09-12 19:21:27 (290 KB/s) - `/usr/src/linux-headers-3.2.27+/Module.symvers' saved [411903/411903]

make: Entering directory `/usr/src/linux-headers-3.2.27+'
make: *** No rule to make target `modules_prepare'.  Stop.
make: Leaving directory `/usr/src/linux-headers-3.2.27+'

------------------------------
Deleting module version: 0.5
completely from the DKMS tree.
------------------------------
Done.
Loading new gamecon_gpio_rpi-0.5 DKMS files...
First Installation: checking all kernels...
dpkg: warning: version '*-*' has bad syntax: version number does not start with digit
It is likely that 3.2.27+ belongs to a chroot's host
Building for architecture armv6l
Module build for the currently running kernel was skipped since the
kernel source for this kernel does not seem to be installed.
run-parts: executing /etc/kernel/header_postinst.d/dkms 3.2.27+
Error! echo
Your kernel headers for kernel 3.2.27+ cannot be found at
/lib/modules/3.2.27+/build or /lib/modules/3.2.27+/source.
Posts: 3
Joined: Tue Sep 11, 2012 11:47 pm
by marqs » Wed Sep 12, 2012 8:20 pm
It seems like the current cleanup routine causes the problem when installing over previous version of headers. Removing the headers before reinstalling should fix that:
Code: Select all
dpkg -r linux-headers-3.2.27+
dpkg -i linux-headers-3.2.27+_3.2.27+-1_armhf.deb
I'll rewrite the cleanup for the next headers package.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by tooold » Wed Sep 12, 2012 8:38 pm
marqs wrote:It seems like the current cleanup routine causes the problem when installing over previous version of headers. Removing the headers before reinstalling should fix that:
Code: Select all
dpkg -r linux-headers-3.2.27+
dpkg -i linux-headers-3.2.27+_3.2.27+-1_armhf.deb
I'll rewrite the cleanup for the next headers package.


Now the following happens:

Code: Select all
sudo dpkg -r linux-headers-3.2.27+

(Reading database ... 81998 files and directories currently installed.)
Removing linux-headers-3.2.27+ ...
Removed /usr/src/linux-headers-3.2.27+


then:

Code: Select all
sudo dpkg -i linux-headers-3.2.27+_3.2.27+-1_armhf.deb

Selecting previously unselected package linux-headers-3.2.27+.
(Reading database ... 72549 files and directories currently installed.)
Unpacking linux-headers-3.2.27+ (from linux-headers-3.2.27+_3.2.27+-1_armhf.deb) ...
Setting up linux-headers-3.2.27+ (3.2.27+-1) ...
--2012-09-12 20:25:11--  https://github.com/raspberrypi/firmware/raw/master/extra/Module.symvers
Resolving github.com (github.com)... 207.97.227.239
Connecting to github.com (github.com)|207.97.227.239|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.github.com/raspberrypi/firmware/master/extra/Module.symvers [following]
--2012-09-12 20:25:17--  https://raw.github.com/raspberrypi/firmware/master/extra/Module.symvers
Resolving raw.github.com (raw.github.com)... 207.97.227.243
Connecting to raw.github.com (raw.github.com)|207.97.227.243|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 411903 (402K) [text/plain]
Saving to: `/usr/src/linux-headers-3.2.27+/Module.symvers'

100%[===================================================================================================================>] 411,903      473K/s   in 0.9s   

Last-modified header missing -- time-stamps turned off.
2012-09-12 20:25:24 (473 KB/s) - `/usr/src/linux-headers-3.2.27+/Module.symvers' saved [411903/411903]

make: Entering directory `/usr/src/linux-headers-3.2.27+'
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf --silentoldconfig Kconfig
make: Leaving directory `/usr/src/linux-headers-3.2.27+'
make: Entering directory `/usr/src/linux-headers-3.2.27+'
  CHK     include/linux/version.h
  CHK     include/generated/utsrelease.h
  UPD     include/generated/utsrelease.h
make[1]: `include/generated/mach-types.h' is up to date.
  HOSTCC  scripts/genksyms/genksyms.o
  HOSTCC  scripts/genksyms/lex.lex.o
  HOSTCC  scripts/genksyms/parse.tab.o
  HOSTLD  scripts/genksyms/genksyms
  CC      scripts/mod/empty.o
  HOSTCC  scripts/mod/mk_elfconfig
  MKELF   scripts/mod/elfconfig.h
  HOSTCC  scripts/mod/file2alias.o
  HOSTCC  scripts/mod/modpost.o
  HOSTCC  scripts/mod/sumversion.o
  HOSTLD  scripts/mod/modpost
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/pnmtologo
  HOSTCC  scripts/conmakehash
  HOSTCC  scripts/bin2c
make: Leaving directory `/usr/src/linux-headers-3.2.27+'

------------------------------
Deleting module version: 0.5
completely from the DKMS tree.
------------------------------
Done.
Loading new gamecon_gpio_rpi-0.5 DKMS files...
First Installation: checking all kernels...
dpkg: warning: version '*-*' has bad syntax: version number does not start with digit
It is likely that 3.2.27+ belongs to a chroot's host
Building for architecture armv6l
Building initial module for 3.2.27+
Done.

gamecon_gpio_rpi:
Running module version sanity check.

Good news! Module version  for gamecon_gpio_rpi.ko
exactly matches what is already found in kernel 3.2.27+.
DKMS will not replace this module.
You may override by specifying --force.

depmod.....

DKMS: install completed.
run-parts: executing /etc/kernel/header_postinst.d/dkms 3.2.27+


and
Code: Select all
tail /var/log/kern.log

Sep 10 22:39:58 raspberrypi kernel: [   12.970596] Registering card ....
Sep 10 22:39:58 raspberrypi kernel: [   12.990211] bcm2835 ALSA CARD CREATED!
Sep 10 22:39:58 raspberrypi kernel: [   13.012862] ### BCM2835 ALSA driver init OK ###
Sep 10 22:39:58 raspberrypi kernel: [   13.352073] gamecon_gpio_rpi: disagrees about version of symbol module_layout
Sep 10 22:39:58 raspberrypi kernel: [   18.551086] mmc0: missed completion of cmd 18 DMA (512/512 [1]/[1]) - ignoring it
Sep 10 22:39:58 raspberrypi kernel: [   18.566679] mmc0: DMA IRQ 6 ignored - results were reset
Sep 10 22:39:58 raspberrypi kernel: [   22.912035] smsc95xx 1-1.1:1.0: eth0: link up, 100Mbps, full-duplex, lpa 0x4DE1
Sep 10 22:40:03 raspberrypi kernel: [   30.935235] Adding 102396k swap on /var/swap.  Priority:-1 extents:1 across:102396k SS
Sep 12 12:56:08 raspberrypi kernel: [  549.260694] gamecon_gpio_rpi: disagrees about version of symbol module_layout
Sep 12 19:13:08 raspberrypi kernel: [23168.914398] gamecon_gpio_rpi: disagrees about version of symbol module_layout
Posts: 3
Joined: Tue Sep 11, 2012 11:47 pm
by marqs » Wed Sep 12, 2012 9:19 pm
You seem to to have an old version of the module (from the zip?) in the module dir, which is not overwritten by dkms. Try to remove that before installing gamecon:
Code: Select all
find /lib/modules/3.2.27+ -name "gamecon*"
#remove the modules reported by find, then rebuild gamecon
depmod -a
dpkg-reconfigure gamecon-gpio-rpi-dkms
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by fotastisch » Sat Oct 06, 2012 9:35 am
Hey there!

I'm running into a problem since I've tried using the gamecon driver. When I try starting RetroPie, the dialog for the gamepad calibration comes up, but it doesn't work and my pi freezes. At first I thought I'd have made a mistake when I soldered together my adapter (and that still might be true ;) ), but then I tried it again without my adapter and it still froze. I can't skip the dialog, because the keyboard stops working as well. But I can log in via SSH and shut it down.

Has anyone had similar problems (or even better a solution :D )? On the other hand, I'd like to try again without the gamecon driver to see if everything else is still working. Is there a way to disable it?

Thanks for your help!
Posts: 31
Joined: Tue Aug 07, 2012 4:37 pm
by petrockblog » Sat Oct 06, 2012 9:46 am
fotastisch wrote:On the other hand, I'd like to try again without the gamecon driver to see if everything else is still working. Is there a way to disable it?

Thanks for your help!


You can disable the automatic loading of the driver by removing it from the file
Code: Select all
/etc/modules

e.g. with the editor nano:
Code: Select all
sudo nano /etc/modules
fun stuff for technics enthusiasts: www.petrockblock.com
Posts: 265
Joined: Wed Jul 04, 2012 6:12 am
Location: Germany
by marqs » Sat Oct 06, 2012 1:44 pm
fotastisch wrote:When I try starting RetroPie, the dialog for the gamepad calibration comes up, but it doesn't work and my pi freezes.


Which dialog do you mean? I recall doing calibration manually with retroarch-joyconfig.

Anyway, it would be a good idea not to load the driver during the RetroPie-installation (as it is fixed to snes pad -config), but instead pop a dialog which mentions the readme under /usr/share/doc and let the user do rest. Of course there could be a separate option for enabling the 2-player snes pad config, but it shouldn't be done as default.
Posts: 126
Joined: Sat Jun 09, 2012 11:34 am
by fotastisch » Sat Oct 06, 2012 4:31 pm
Hey!

Thanks, marqs, that worked. I was able to run emulationstation again, after removing the gamecon driver. So now I tried snesdev-rpi to connect my controllers, but it's still not working. I followed this tutorial by petrockblog:
https://github.com/petrockblog/SNESDev- ... /README.md
When I run SNESDev-RPi, I get some weird output printed on my screen and my keyboard is set to capital letters. And when I try emulationstation, it's somehow set to doom and I can't choose any SNES games.

So it seems that somehow my pi doesn't want me to connect controllers via the GPIOs. I'd be happy if someone had an idea how to make it work, preferable for the gamecon-driver, since I already soldered my connector to use the GPIOs 1 and 4. ;)

Cheers!
Posts: 31
Joined: Tue Aug 07, 2012 4:37 pm
by petrockblog » Sat Oct 06, 2012 4:52 pm
Hi!

You need to adapt the pin usage of SNESDev to your setup. To do so, you need to change the pin configuration in main.c (https://github.com/petrockblog/SNESDev- ... src/main.c, from line 145 on) and re-compile SNESDev with
Code: Select all
make clean
make

from the SNESDev-RPi directory. I will continue the work on SNESDev in a few days (when the revised version of the SNES-controller adapter board has arrived) and, hence, I have not adapted the sources to the pin usage of marqs module. You really just need to modify the lines 145 to 148 and the pin out shown at http://petrockblog.wordpress.com/2012/0 ... pberry-pi/ might help you.

I hope this helps!?
fun stuff for technics enthusiasts: www.petrockblock.com
Posts: 265
Joined: Wed Jul 04, 2012 6:12 am
Location: Germany