Skip to content

Instantly share code, notes, and snippets.

@PeterCxy

PeterCxy/README.md

Last active Sep 24, 2020
Embed
What would you like to do?
Device Tree Overlay for GamePi43 (Raspberry Pi Retro Game Console Case)

This device tree overlay removes the need for the userspace daemon retrogame to process button press on GamePi43, reducing input latency and removes a point of failure (I don't really trust that daemon from Adafruit to be error-free).

To compile the dts, install dtc and then run

dtc -I dts -O dtb -o gamepi43.dtbo gamepi43.dts

To install the overlay, copy the resulting gamepi43.dtbo to /boot/overlays/, and then add

dtoverlay=gamepi43

to /boot/config.txt.

Remember to delete the retrogame daemon that is included with the official "driver" of GamePi43 (/usr/local/bin/retrogame, also remember to delete all instances of retrogame in /etc/rc.local).

In addition, to make the buttons work with RetroArch emulators, put the following content to /etc/udev/rules.d/10-gamepi.rules

SUBSYSTEM=="input", ATTRS{name}=="GamePi43 GPIO Keypad", ENV{ID_INPUT_KEYBOARD}="1"
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
fragment@0 {
target = <&gpio>;
__overlay__ {
gamepi43_pins: gamepi43_pins {
brcm,pins = <4 17 27 22 10 9 25 24 15 18 14 23 2>;
brcm,function = <0>; // 0: input
brcm,pull = <2>; // 2: up 1: down
};
};
};
fragment@1 {
target-path = "/";
__overlay__ {
keypad: gamepi43_keys {
// Load pin config first
pinctrl-names = "default";
pinctrl-0 = <&gamepi43_pins>;
// Use gpio-keys driver
compatible = "gpio-keys";
label = "GamePi43 GPIO Keypad";
autorepeat;
button-UP {
label = "GamePi43 UP";
linux,code = <103>; // 103 = UP
gpios = <&gpio 4 1>; // 1 = Active-Low
};
button-DOWN {
label = "GamePi43 DOWN";
linux,code = <108>;
gpios = <&gpio 17 1>;
};
button-LEFT {
label = "GamePi43 LEFT";
linux,code = <105>;
gpios = <&gpio 27 1>;
};
button-RIGHT {
label = "GamePi43 RIGHT";
linux,code = <106>;
gpios = <&gpio 22 1>;
};
button-A {
label = "GamePi43 A";
linux,code = <44>;
gpios = <&gpio 25 1>;
};
button-B {
label = "GamePi43 B";
linux,code = <45>;
gpios = <&gpio 24 1>;
};
button-X {
label = "GamePi43 X";
linux,code = <31>;
gpios = <&gpio 15 1>;
};
button-Y {
label = "GamePi43 Y";
linux,code = <50>;
gpios = <&gpio 18 1>;
};
button-L1 {
label = "GamePi43 Shoulder LEFT 1";
linux,code = <19>;
gpios = <&gpio 14 1>;
};
button-R1 {
label = "GamePi43 Shoulder RIGHT 1";
linux,code = <16>;
gpios = <&gpio 23 1>;
};
button-START {
label = "GamePi43 START";
linux,code = <28>;
gpios = <&gpio 10 1>;
};
button-SELECT {
label = "GamePi43 SELECT";
linux,code = <97>;
gpios = <&gpio 9 1>;
};
button-HOTKEY {
label = "GamePi43 HOTKEY";
linux,code = <1>;
gpios = <&gpio 2 1>;
};
};
};
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.