GPIO based Joystick controller

Post Reply
User avatar
tobetter
Posts: 8434
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 490 times
Been thanked: 1332 times
Contact:

GPIO based Joystick controller

Post by tobetter »

I originally wrote a driver to support the parallel port on the GPIO headers, but...eventually I encountered a problem that I cannot have a hardware that has the parallel port for testing. Even the used dot-printer is expensive. :( So..I turned out to use the driver to support gpio-based joystick controllers and have three patches for this. These patches are based on the Hardkernel's 4.9 kernel and tested with RetroArena. Please note that these patches are not applied to any official emulator yet.
[1] https://github.com/tobetter/linux/commi ... 8dd276ece9
[2] https://github.com/tobetter/linux/commi ... 3aaeddcf62
[3] https://github.com/tobetter/linux/commi ... 3d4d885f1c
[4] https://github.com/tobetter/linux/commi ... e7dc7545d9
[5] https://github.com/tobetter/linux/commi ... 4e2d285753

After applying these patches, Linux kernel image must be updated as well as kernel modules. Also the device tree must be updated but this part would be very depends on the OS. Hardkernel's Linux kernel switched to support device tree overlay, so the patch [2] will work with it. Otherwise the patch [2] must be integrated to the original device tree file.

With the Hardkernel's Linux kernel tree to use the device tree overlay, config.ini should be modified like this in order to enable GPIOs to connect with the the switches.

Code: Select all

; Device Tree Overlay
overlay_resize=16384
overlay_profile=joysticks
overlays="spi0 i2c0 i2c1 uart0"

[overlay_custom]
overlays="i2c0 i2c1"

[overlay_hktft32]
overlays="hktft32"

[overlay_hktft35]
overlays="hktft35"

[overlay_joysticks]
overlays="gpio-joystick0 gpio-joystick1"
Also boot.init must be updated, so...add this to the end of the line of bootargs. This change will enable to the driver gamecon and map the GPIO pins to emulate the joystick controller.

Code: Select all

gamecon.map=0,10 gamecon.map2=1,10
Once everything is applied properly, two joystick will appear after rebooting. /dev/input/js0 and /dev/input/js1 are the devices for GPIO based joystick controllers.

Code: Select all

# ls -l /dev/input/
total 0
drwxr-xr-x  2 root root      80 Jan 28  2018 by-id
drwxr-xr-x  2 root root      80 Jan 28  2018 by-path
crw-rw----  1 root input 13, 64 Jan 28  2018 event0
crw-rw----  1 root input 13, 65 Jan 28  2018 event1
crw-rw----  1 root input 13, 66 Jan 28  2018 event2
crw-rw----+ 1 root input 13, 67 Nov  1 08:29 event3
crw-rw----+ 1 root input 13, 68 Nov  1 08:29 event4
crw-rw----+ 1 root input 13,  0 Nov  1 08:29 js0
crw-rw----+ 1 root input 13,  1 Nov  1 08:29 js1
crw-rw----  1 root input 13, 63 Jan 28  2018 mice
For GPIO pins wiring, we have very limited number pins to use for two joystick controllers. The controller is assumed to have 12 inputs, LEFT/RIGHT/UP/DOWN/A/B/X/Y/TL/TR. Here is the map how the switches can be wired to GPIO pin header and how it's different with the RPi. Disadantage of having two joysticks is that only one GPIO pinpad remans. :(
GPIO-based-joystick-pinmap.png
GPIO-based-joystick-pinmap.png (136.34 KiB) Viewed 1950 times
These users thanked the author tobetter for the post (total 4):
odroid (Mon Nov 02, 2020 9:34 am) • superpowter77 (Mon Nov 02, 2020 10:57 am) • shanti (Wed Nov 04, 2020 6:33 pm) • ponz (Tue Nov 17, 2020 4:10 am)

User avatar
tobetter
Posts: 8434
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 490 times
Been thanked: 1332 times
Contact:

Re: GPIO based Joystick controller

Post by tobetter »

Good new!!

EmuELEC 4.0 (test release) has been released about 7 hours ago and gratefully the patch to enable GPIO based joystick controller are merged. Thanks to @shanti for accepting the patch and release it with 4.0. Intresting thing is that EmuELEC has released the new version for ODROID-HC4 as well.
https://github.com/EmuELEC/EmuELEC-test ... /v4.0-test

I also upload the video how to set up the EmuELEC to enable GPIO based joystick which is boring... :D Please skip the video to here if you are familiar to set up EmuELEC and only to know what to change on EmuELEC image.


Thank you again, @shanti!!
These users thanked the author tobetter for the post (total 4):
ponz (Tue Nov 17, 2020 4:10 am) • lsc1117 (Tue Nov 17, 2020 12:23 pm) • odroid (Tue Nov 17, 2020 2:35 pm) • zach_morris (Sun Aug 29, 2021 8:17 am)

zach_morris
Posts: 3
Joined: Sun Aug 29, 2021 8:03 am
languages_spoken: english
Has thanked: 2 times
Been thanked: 2 times
Contact:

Re: GPIO based Joystick controller

Post by zach_morris »

Just wanted to say thanks for putting this together @tobetter, this is exactly what I was looking for for my project.
I've got this mini NES case 3D printed for an N2+, and put buttons in for power/reset and some extras on the side for various hot keys
Image
Image

I planned on using EmuElec and jslisten to map the buttons.

I did have a question though. I'm interested in also using the gpiopower option described here: https://wiki.odroid.com/odroid-n2/appli ... key_wakeup for powering on and off. For my setup, I don't need all the inputs (only 1 player for example and not even all the buttons).

Can this be combined in some way with the gpiopower option?

Thanks in advance!
These users thanked the author zach_morris for the post:
mctom (Mon Aug 30, 2021 4:07 pm)

shanti
Posts: 350
Joined: Fri Feb 15, 2019 3:12 am
languages_spoken: english, spanish
ODROIDs: Odroid N2
Has thanked: 103 times
Been thanked: 139 times
Contact:

Re: GPIO based Joystick controller

Post by shanti »

zach_morris wrote:
Mon Aug 30, 2021 9:12 am
I did have a question though. I'm interested in also using the gpiopower option described here: https://wiki.odroid.com/odroid-n2/appli ... key_wakeup for powering on and off. For my setup, I don't need all the inputs (only 1 player for example and not even all the buttons).

Can this be combined in some way with the gpiopower option?

Thanks in advance!
Check the config.ini that its on the root (EMUELEC) partition https://github.com/EmuELEC/EmuELEC/blob ... g.ini#L107 you can enable what GPIO pins are used there, select the ones that you have free and it should in theory work.
These users thanked the author shanti for the post (total 2):
odroid (Wed Sep 08, 2021 9:05 am) • zach_morris (Thu Sep 09, 2021 12:06 pm)

zach_morris
Posts: 3
Joined: Sun Aug 29, 2021 8:03 am
languages_spoken: english
Has thanked: 2 times
Been thanked: 2 times
Contact:

Re: GPIO based Joystick controller

Post by zach_morris »

Thanks @shanti and @tobetter. I've tried this with the latest EmuELEC. The power options (editing config.ini) work great!

I tried the gpio joystick, but I'm having trouble getting it to work. Following the instructions (only slightly modified) in the video, I edited by flash/boot.ini and added:

Code: Select all

setenv bootargs "${bootargs} gamecon.map=0,10 gamecon.map2=1,10"
Then I copied g12b_s922x_odroid_n2plus_joystick.dtb and replaced dtb.img on my Odroid N2+ in /flash (rather than edit the line in boot.ini).

Box boots up and runs normally, but I don't get any input from gpio as described. In troubleshooting, I see:
dmesg shows:

Code: Select all

[    0.000000@0] Booting Linux on physical CPU 0x0
[    0.000000@0] Linux version 4.9.113 (emuelec@emuelec-dev) (gcc version 8.3.0 (GCC) ) #1 SMP PREEMPT Fri Jun 18 01:52:55 CDT 2021
[    0.000000@0] Boot CPU: AArch64 Processor [410fd034]
[    0.000000@0] CoreELEC dt-id: g12b_s922x_odroid_n2plus
[    0.000000@0] Machine model: Hardkernel ODROID-N2Plus
...
0.000000@0] Kernel command line: BOOT_IMAGE=kernel.img boot=UUID=1806-0526 disk=UUID=8598802b-d370-4279-99ab-009dc4fbf19a console=ttyS0,115200 console=tty0 no_console_suspend     remotewakeup=0x23dc4db2 decode_type=0 remotewakeupmask=0xffffffff  gpiopower=492 # (pin 12 of J2 header)   hdmimode=1080p60hz logo=osd0,loaded,0x3d800000 vout=1080p60hz,enable frac_rate_policy=0 native_4k_gui=0  nosplash gamecon.map=0,10 gamecon.map2=1,10  systemd.show_status=auto
looking for js devices shows:

Code: Select all

ls /dev/input/js*
ls: /dev/input/js*: No such file or directory

ls -l /dev/input
total 0
drwxr-xr-x    2 root     root            60 Sep 11 14:26 by-id
drwxr-xr-x    2 root     root           100 Sep 11 14:26 by-path
crw-rw----    1 root     input      13,  64 Sep 11 14:26 event0
crw-rw----    1 root     input      13,  65 Sep 11 14:26 event1
crw-rw----    1 root     input      13,  66 Sep 11 14:26 event2
crw-rw----    1 root     input      13,  67 Sep 11 14:26 event3
crw-rw----    1 root     input      13,  63 Sep 11 14:26 mice
It seems like I'm missing something to get this enabled. Any other troubleshooting I can perform?

zach_morris
Posts: 3
Joined: Sun Aug 29, 2021 8:03 am
languages_spoken: english
Has thanked: 2 times
Been thanked: 2 times
Contact:

Re: GPIO based Joystick controller

Post by zach_morris »

Just an update on this. @shanti updated EmuELEC 4.3 so the drivers are working again (thanks @shanti).

In addition, in order to make this work for both the gpiopower command and the gpio controller, I modified your dts file and created a new one for just one player:

Code: Select all

#filename g12b_s922x_odroid_n2plus_1p_joystick, 1 player version of gpio joystick dts
#include "g12b_s922x_odroid_n2plus.dts"

/{
	parport0: parport@0 {
		compatible = "parport,odroid";
		status = "okay";

		data-gpios = <&gpio GPIOX_2 GPIO_ACTIVE_LOW>,
			<&gpio GPIOX_1 GPIO_ACTIVE_LOW>,
			<&gpio GPIOX_8 GPIO_ACTIVE_LOW>,
			<&gpio GPIOX_9 GPIO_ACTIVE_LOW>,
			<&gpio GPIOX_13 GPIO_ACTIVE_LOW>,
			<&gpio GPIOX_16 GPIO_ACTIVE_LOW>,
			<&gpio GPIOX_12 GPIO_ACTIVE_LOW>,
			<&gpio GPIOX_0 GPIO_ACTIVE_LOW>;

		status-gpios = <&gpio GPIOA_13 GPIO_ACTIVE_LOW>,
			<&gpio GPIOX_3 GPIO_ACTIVE_LOW>,
			<&gpio GPIOX_4 GPIO_ACTIVE_LOW>,
			<&gpio GPIOX_7 GPIO_ACTIVE_LOW>;
	};
};

&pinctrl_periphs {
	spdifout: spdifout {
		mux {/* GPIOA_11 */
			groups = "spdif_out_a11";
			function = "spdif_out";
		};
	};
};

Pinouts for the 1 player dtb are:

Code: Select all

Button A - GPIOX_2 - Pin 22
Button B - GPIOX_1 - Pin 18
Button Start - GPIOX_8 - Pin 19
Button Select - GPIOX_9 - Pin 21
Button X - GPIOX_13 - Pin 10
Button Y - GPIOX_16 - Pin 12
Button TL - GPIOX_12 - Pin 8
Button TR - GPIOX_0 - Pin 16
Button UP - GPIOA_13 - Pin 7
Button DOWN - GPIOX_3 - Pin 11
Button LEFT - GPIOX_4 - Pin 13
Button RIGHT - GPIOX_7 - Pin 15
After making that update, and choosing a gpiopower pin that didn't clash with the player 1 pins (I chose Power - GPIOX_5 - Pin 33 - #481 for example), both would then work.
These users thanked the author zach_morris for the post:
odroid (Mon Sep 27, 2021 9:18 am)

Post Reply

Return to “Games and Emulators”

Who is online

Users browsing this forum: No registered users and 0 guests