Skip to content

Commit ea8db8e

Browse files
authored
snesdev: updates for the new version
New version needs WiringPi, but not the original version that got discontinued. There's an active fork of WiringPi which also provides `.deb` files, so check whether this new version is installed first before compiling locally a static version and using it. Other modifications: * modified the installation/build to use `$md_build` and handle the installation ourselves, instead of using the upstream `make` targets. This means the driver is copied to `/opt/retropie` (just like `xboxdrv`) instead of being located in `/usr/local`. * added a `systemd` unit file to start the driver and don't rely on the upstream `rc.d` service scripts.
1 parent 71e7fbb commit ea8db8e

File tree

2 files changed

+92
-11
lines changed

2 files changed

+92
-11
lines changed

scriptmodules/supplementary/snesdev.sh

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,77 @@ rp_module_section="driver"
1515
rp_module_repo="git https://github.com/MonsterJoysticks/SNESDev-RPi-Wiring-Pi.git master"
1616
rp_module_flags="noinstclean !all rpi"
1717

18+
# install the latest version of WiringPi
19+
function _wiringpi_snesdev() {
20+
pushd "$md_build"
21+
gitPullOrClone wiringpi https://github.com/WiringPi/WiringPi.git
22+
cd wiringpi
23+
applyPatch "$md_data/001-wiringpi-static.diff"
24+
make -C wiringPi libwiringPi.a
25+
popd
26+
}
27+
1828
function sources_snesdev() {
19-
gitPullOrClone "$md_inst"
29+
gitPullOrClone
2030
}
2131

2232
function build_snesdev() {
33+
local wiringpi_version
34+
wiringpi_version="$(dpkg-query -f='${Version} ${Status}' -W wiringpi 2>/dev/null | grep installed | cut -f1)"
35+
2336
cd "$md_inst"
24-
make -j1
25-
md_ret_require="$md_inst/src/SNESDev"
37+
if [[ -z "$wiringpi_version" ]] || compareVersions "$wiringpi_version" lt 3.14; then
38+
# when there's no WiringPi installed or there's an old version, build a static version and use it
39+
printMsgs console "Using locally built WiringPi library"
40+
_wiringpi_snesdev
41+
make LDFLAGS=" -L"$md_build/wiringpi/wiringPi"" CFLAGS="$CFLAGS -I"$md_build/wiringpi/wiringPi""
42+
else
43+
make
44+
fi
45+
md_ret_require="$md_build/src/SNESDev"
2646
}
2747

2848
function install_snesdev() {
29-
cd "$md_inst"
30-
make install
49+
md_ret_files=(
50+
"src/SNESDev"
51+
"README.md"
52+
"supplementary/snesdev.cfg"
53+
)
3154
}
3255

56+
function configure_snesdev() {
57+
if [[ "$md_mode" == "install" ]]; then
58+
install -m 0755 "$md_inst/snesdev.cfg" "/etc/snesdev.cfg"
59+
# remove old drivers and service
60+
[[ -f "/usr/local/bin/SNESDev" ]] && rm -f "/usr/local/bin/SNESDev"
61+
update-rc.d SNESDev remove
62+
rm -f /etc/init.d/SNESDev
63+
fi
64+
}
65+
66+
function _systemd_install_snesdev() {
67+
cat > /etc/systemd/system/snesdev.service << _EOF_
68+
[Unit]
69+
Description=Userspace SNES GPIO Driver
70+
71+
[Service]
72+
ExecStart=$md_inst/SNESDev
73+
74+
[Install]
75+
WantedBy=multi-user.target
76+
_EOF_
77+
78+
systemctl daemon-reload
79+
systemctl -q enable snesdev.service
80+
}
81+
82+
function _systemd_uninstall_snesdev() {
83+
if systemctl -q is-enabled snesdev.service 2>/dev/null; then
84+
systemctl stop snesdev.service
85+
systemctl -q disable snesdev.service
86+
fi
87+
[[ -f "/etc/systemd/system/snesdev.service" ]] && rm "/etc/systemd/system/snesdev.service"
88+
}
3389
# start SNESDev on boot and configure RetroArch input settings
3490
function enable_at_start_snesdev() {
3591
local mode="$1"
@@ -42,16 +98,19 @@ function enable_at_start_snesdev() {
4298
iniSet "button_enabled" "0"
4399
iniSet "gamepad1_enabled" "1"
44100
iniSet "gamepad2_enabled" "1"
101+
_systemd_install_snesdev
45102
;;
46103
2)
47104
iniSet "button_enabled" "1"
48105
iniSet "gamepad1_enabled" "0"
49106
iniSet "gamepad2_enabled" "0"
107+
_systemd_install_snesdev
50108
;;
51109
3)
52110
iniSet "button_enabled" "1"
53111
iniSet "gamepad1_enabled" "1"
54112
iniSet "gamepad2_enabled" "1"
113+
_systemd_install_snesdev
55114
;;
56115
*)
57116
echo "[enable_at_start_snesdev] I do not understand what is going on here."
@@ -71,8 +130,9 @@ function set_adapter_version_snesdev() {
71130
}
72131

73132
function remove_snesdev() {
74-
make -C "$md_inst" uninstallservice
75-
make -C "$md_inst" uninstall
133+
_systemd_uninstall_snesdev
134+
# remove old versions if found
135+
[[ -f "/usr/local/bin/SNESDev" ]] && rm -f "/usr/local/bin/SNESDev"
76136
}
77137

78138
function gui_snesdev() {
@@ -90,17 +150,14 @@ function gui_snesdev() {
90150
case "$choice" in
91151
1)
92152
enable_at_start_snesdev 3
93-
make -C "$md_inst" installservice
94153
printMsgs "dialog" "Enabled SNESDev on boot (polling pads and button)."
95154
;;
96155
2)
97156
enable_at_start_snesdev 1
98-
make -C "$md_inst" installservice
99157
printMsgs "dialog" "Enabled SNESDev on boot (polling only pads)."
100158
;;
101159
3)
102160
enable_at_start_snesdev 2
103-
make -C "$md_inst" installservice
104161
printMsgs "dialog" "Enabled SNESDev on boot (polling only button)."
105162
;;
106163
4)
@@ -112,7 +169,7 @@ function gui_snesdev() {
112169
printMsgs "dialog" "Switched to adapter version 2.X."
113170
;;
114171
D)
115-
make -C "$md_inst" uninstallservice
172+
_systemd_uninstall_snesdev
116173
printMsgs "dialog" "Disabled SNESDev on boot."
117174
;;
118175
esac
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
diff --git a/wiringPi/Makefile b/wiringPi/Makefile
2+
index 88fc48e..ee5dc9f 100644
3+
--- a/wiringPi/Makefile
4+
+++ b/wiringPi/Makefile
5+
@@ -78,6 +78,10 @@ $(DYNAMIC): $(OBJ)
6+
$Q echo "[Link (Dynamic)]"
7+
$Q $(CC) -shared -Wl,-soname,libwiringPi.so$(WIRINGPI_SONAME_SUFFIX) -o libwiringPi.so.$(VERSION) $(OBJ) $(LIBS)
8+
9+
+$(STATIC): $(OBJ)
10+
+ $Q echo "[Link (Static)]"
11+
+ $Q $(AR) -rcs $(STATIC) $(OBJ)
12+
+
13+
.c.o:
14+
$Q echo [Compile] $<
15+
$Q $(CC) -c $(CFLAGS) $< -o $@
16+
@@ -86,7 +90,7 @@ $(DYNAMIC): $(OBJ)
17+
.PHONY: clean
18+
clean:
19+
$Q echo "[Clean]"
20+
- $Q rm -f $(OBJ) $(OBJ_I2C) *~ core tags Makefile.bak libwiringPi.*
21+
+ $Q rm -f $(OBJ) $(OBJ_I2C) *~ core tags Makefile.bak libwiringPi.* $(STATIC)
22+
23+
.PHONY: tags
24+
tags: $(SRC)

0 commit comments

Comments
 (0)