From dd47989f1c8db2ef9907267cf7460e8b0e5cab8a Mon Sep 17 00:00:00 2001
From: brooksytech <1673861+brooksytech@users.noreply.github.com>
Date: Mon, 5 Feb 2024 18:27:39 +0000
Subject: [PATCH] RK3399: Rename built in gamepad to rg552_joypad to avoid
conflicts
---
.../config/RK3399/GCPadNew.ini.south | 2 +-
.../config/RK3399/GCPadNew.ini.west | 2 +-
.../RK3399/WiiControllerProfiles/classic.ini | 2 +-
.../RK3399/WiiControllerProfiles/hremote.ini | 2 +-
.../RK3399/WiiControllerProfiles/nunchuck.ini | 2 +-
.../RK3399/WiiControllerProfiles/vremote.ini | 2 +-
.../RK3399/mappings/SDL_retrogame_joypad.cfg | 2 +-
.../config/RK3399/mupen64plus.cfg | 2 +-
.../config/RK3399/default.ini | 4 +-
.../config/RK3399/zlswap.ini | 4 +-
.../config/gamecontrollerdb.txt | 1 +
.../gamepads/rg552_joypad.cfg | 47 +++++++++++++++++++
.../devices/Anbernic RG552/050-game-configs | 16 +++++++
.../config/common/es_input.cfg | 27 +++++++++++
.../devices/RK3399/linux/linux.aarch64.conf | 2 +-
.../linux/patches/RK3399/000-rk3399-dts.patch | 6 +--
.../patches/RK3399/003-singleadc-joypad.patch | 36 +++++++-------
17 files changed, 125 insertions(+), 34 deletions(-)
create mode 100644 packages/emulators/tools/retroarch-joypads/gamepads/rg552_joypad.cfg
create mode 100644 packages/hardware/quirks/devices/Anbernic RG552/050-game-configs
diff --git a/packages/emulators/standalone/dolphin-sa/config/RK3399/GCPadNew.ini.south b/packages/emulators/standalone/dolphin-sa/config/RK3399/GCPadNew.ini.south
index 45a01985af..d771fe1717 100755
--- a/packages/emulators/standalone/dolphin-sa/config/RK3399/GCPadNew.ini.south
+++ b/packages/emulators/standalone/dolphin-sa/config/RK3399/GCPadNew.ini.south
@@ -1,5 +1,5 @@
[GCPad1]
-Device = evdev/0/retrogame_joypad
+Device = evdev/0/rg552_joypad
Buttons/A = Button 0
Buttons/B = Button 3
Buttons/Start = Button 8
diff --git a/packages/emulators/standalone/dolphin-sa/config/RK3399/GCPadNew.ini.west b/packages/emulators/standalone/dolphin-sa/config/RK3399/GCPadNew.ini.west
index e8eccb2e01..e5b9049819 100755
--- a/packages/emulators/standalone/dolphin-sa/config/RK3399/GCPadNew.ini.west
+++ b/packages/emulators/standalone/dolphin-sa/config/RK3399/GCPadNew.ini.west
@@ -1,5 +1,5 @@
[GCPad1]
-Device = evdev/0/retrogame_joypad
+Device = evdev/0/rg552_joypad
Buttons/A = Button 1
Buttons/B = Button 0
Buttons/Start = Button 8
diff --git a/packages/emulators/standalone/dolphin-sa/config/RK3399/WiiControllerProfiles/classic.ini b/packages/emulators/standalone/dolphin-sa/config/RK3399/WiiControllerProfiles/classic.ini
index 93256a3d65..06d6d919d4 100755
--- a/packages/emulators/standalone/dolphin-sa/config/RK3399/WiiControllerProfiles/classic.ini
+++ b/packages/emulators/standalone/dolphin-sa/config/RK3399/WiiControllerProfiles/classic.ini
@@ -1,5 +1,5 @@
[Wiimote1]
-Device = evdev/0/retrogame_joypad
+Device = evdev/0/rg552_joypad
Extension = Classic
Source = 1
Classic/Buttons/A = Button 1
diff --git a/packages/emulators/standalone/dolphin-sa/config/RK3399/WiiControllerProfiles/hremote.ini b/packages/emulators/standalone/dolphin-sa/config/RK3399/WiiControllerProfiles/hremote.ini
index 7f630e677f..93da6c32e6 100755
--- a/packages/emulators/standalone/dolphin-sa/config/RK3399/WiiControllerProfiles/hremote.ini
+++ b/packages/emulators/standalone/dolphin-sa/config/RK3399/WiiControllerProfiles/hremote.ini
@@ -1,5 +1,5 @@
[Wiimote1]
-Device = evdev/0/retrogame_joypad
+Device = evdev/0/rg552_joypad
Buttons/A = Button 0
Buttons/B = Button 1
Buttons/1 = Button 3
diff --git a/packages/emulators/standalone/dolphin-sa/config/RK3399/WiiControllerProfiles/nunchuck.ini b/packages/emulators/standalone/dolphin-sa/config/RK3399/WiiControllerProfiles/nunchuck.ini
index 1b40dbeaa5..8681b8e2b5 100755
--- a/packages/emulators/standalone/dolphin-sa/config/RK3399/WiiControllerProfiles/nunchuck.ini
+++ b/packages/emulators/standalone/dolphin-sa/config/RK3399/WiiControllerProfiles/nunchuck.ini
@@ -1,5 +1,5 @@
[Wiimote1]
-Device = evdev/0/retrogame_joypad
+Device = evdev/0/rg552_joypad
Extension = Nunchuk
Buttons/A = Button 0
Buttons/B = Button 1
diff --git a/packages/emulators/standalone/dolphin-sa/config/RK3399/WiiControllerProfiles/vremote.ini b/packages/emulators/standalone/dolphin-sa/config/RK3399/WiiControllerProfiles/vremote.ini
index fae3a89ab3..0a646cb8a4 100755
--- a/packages/emulators/standalone/dolphin-sa/config/RK3399/WiiControllerProfiles/vremote.ini
+++ b/packages/emulators/standalone/dolphin-sa/config/RK3399/WiiControllerProfiles/vremote.ini
@@ -1,5 +1,5 @@
[Wiimote1]
-Device = evdev/0/retrogame_joypad
+Device = evdev/0/rg552_joypad
Buttons/A = Button 0
Buttons/B = Button 1
Buttons/1 = Button 3
diff --git a/packages/emulators/standalone/flycast-sa/config/RK3399/mappings/SDL_retrogame_joypad.cfg b/packages/emulators/standalone/flycast-sa/config/RK3399/mappings/SDL_retrogame_joypad.cfg
index ef5bc58949..1471462970 100644
--- a/packages/emulators/standalone/flycast-sa/config/RK3399/mappings/SDL_retrogame_joypad.cfg
+++ b/packages/emulators/standalone/flycast-sa/config/RK3399/mappings/SDL_retrogame_joypad.cfg
@@ -26,7 +26,7 @@ bind9 = 9:btn_start
[emulator]
dead_zone = 10
-mapping_name = retrogame_joypad
+mapping_name = rg552_joypad
rumble_power = 100
version = 3
diff --git a/packages/emulators/standalone/mupen64plus-sa/mupen64plus-sa-core/config/RK3399/mupen64plus.cfg b/packages/emulators/standalone/mupen64plus-sa/mupen64plus-sa-core/config/RK3399/mupen64plus.cfg
index f8615ce4b7..c637c1119f 100644
--- a/packages/emulators/standalone/mupen64plus-sa/mupen64plus-sa-core/config/RK3399/mupen64plus.cfg
+++ b/packages/emulators/standalone/mupen64plus-sa/mupen64plus-sa-core/config/RK3399/mupen64plus.cfg
@@ -172,7 +172,7 @@ mode = 2
# Specifies which joystick is bound to this controller: -1=No joystick, 0 or more= SDL Joystick number
device = 0
# SDL joystick name (or Keyboard)
-name = "retrogame_joypad"
+name = "rg552_joypad"
# Specifies whether this controller is 'plugged in' to the simulated N64
plugged = True
# Specifies which type of expansion pak is in the controller: 1=None, 2=Mem pak, 4=Transfer pak, 5=Rumble pak
diff --git a/packages/emulators/standalone/mupen64plus-sa/mupen64plus-sa-input-sdl/config/RK3399/default.ini b/packages/emulators/standalone/mupen64plus-sa/mupen64plus-sa-input-sdl/config/RK3399/default.ini
index 8005fb6fcd..c062c8c8c4 100644
--- a/packages/emulators/standalone/mupen64plus-sa/mupen64plus-sa-input-sdl/config/RK3399/default.ini
+++ b/packages/emulators/standalone/mupen64plus-sa/mupen64plus-sa-input-sdl/config/RK3399/default.ini
@@ -1,5 +1,5 @@
; RG552 Gamepad - default.ini
-[retrogame_joypad]
+[rg552_joypad]
plugged = True
mouse = False
AnalogDeadzone = 0,0
@@ -22,4 +22,4 @@ Mempak switch =
Rumblepak switch =
# Analog axis configuration mappings
X Axis = axis(0-,0+)
-Y Axis = axis(1-,1+)
\ No newline at end of file
+Y Axis = axis(1-,1+)
diff --git a/packages/emulators/standalone/mupen64plus-sa/mupen64plus-sa-input-sdl/config/RK3399/zlswap.ini b/packages/emulators/standalone/mupen64plus-sa/mupen64plus-sa-input-sdl/config/RK3399/zlswap.ini
index 7606cad774..6735db0daa 100644
--- a/packages/emulators/standalone/mupen64plus-sa/mupen64plus-sa-input-sdl/config/RK3399/zlswap.ini
+++ b/packages/emulators/standalone/mupen64plus-sa/mupen64plus-sa-input-sdl/config/RK3399/zlswap.ini
@@ -1,5 +1,5 @@
; RG552 Gamepad - zlswap.ini
-[retrogame_joypad]
+[rg552_joypad]
plugged = True
mouse = False
AnalogDeadzone = 0,0
@@ -22,4 +22,4 @@ Mempak switch =
Rumblepak switch =
# Analog axis configuration mappings
X Axis = axis(0-,0+)
-Y Axis = axis(1-,1+)
\ No newline at end of file
+Y Axis = axis(1-,1+)
diff --git a/packages/emulators/tools/gamecontrollerdb/config/gamecontrollerdb.txt b/packages/emulators/tools/gamecontrollerdb/config/gamecontrollerdb.txt
index 1326d62949..3cfab694c9 100644
--- a/packages/emulators/tools/gamecontrollerdb/config/gamecontrollerdb.txt
+++ b/packages/emulators/tools/gamecontrollerdb/config/gamecontrollerdb.txt
@@ -9,3 +9,4 @@
19009321b0c300000002000010000000,XU10 Gamepad,platform:Linux,x:b3,a:b2,b:b1,y:b0,back:b8,guide:b16,start:b9,dpleft:b14,dpdown:b13,dpright:b15,dpup:b12,leftshoulder:b4,lefttrigger:b7,rightshoulder:b5,righttrigger:b6,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,
190014b3010000009178000000050000,r33s_joypad,platform:Linux,x:b2,a:b1,b:b0,y:b3,back:b8,start:b9,dpleft:b12,dpdown:b11,dpright:b13,dpup:b10,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,
1900e5914b4800007711000077010000,RGB20S Gamepad,platform:Linux,x:b2,a:b1,b:b0,y:b3,back:b12,start:b13,dpleft:b10,dpdown:b9,dpright:b11,dpup:b8,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b14,rightstick:b15,leftx:a0,lefty:a1,rightx:a2,righty:a3,
+1900e7444b4800000111000034020000,rg552_joypad,platform:Linux,x:b2,a:b1,b:b0,y:b3,back:b8,start:b9,dpleft:b15,dpdown:b14,dpright:b16,dpup:b13,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b11,rightstick:b12,leftx:a0,lefty:a1,rightx:a2,righty:a3,
diff --git a/packages/emulators/tools/retroarch-joypads/gamepads/rg552_joypad.cfg b/packages/emulators/tools/retroarch-joypads/gamepads/rg552_joypad.cfg
new file mode 100644
index 0000000000..5d15bc8847
--- /dev/null
+++ b/packages/emulators/tools/retroarch-joypads/gamepads/rg552_joypad.cfg
@@ -0,0 +1,47 @@
+input_driver = "udev"
+input_device = "rg552_joypad"
+input_device_display_name = "Anbernic RG552 Joypad"
+
+input_b_btn = "0"
+input_a_btn = "1"
+input_x_btn = "2"
+input_y_btn = "3"
+
+input_select_btn = "8"
+input_start_btn = "9"
+
+
+input_l_btn = "4"
+input_r_btn = "5"
+input_l2_btn = "6"
+input_r2_btn = "7"
+input_l3_btn = "11"
+input_r3_btn = "12"
+
+input_up_btn = "13"
+input_down_btn = "14"
+input_left_btn = "15"
+input_right_btn = "16"
+
+input_l_x_minus_axis = "-0"
+input_l_x_plus_axis = "+0"
+input_l_y_minus_axis = "-1"
+input_l_y_plus_axis = "+1"
+
+input_r_x_minus_axis = "-2"
+input_r_x_plus_axis = "+2"
+input_r_y_minus_axis = "-3"
+input_r_y_plus_axis = "+3"
+
+# Hotkeys
+input_enable_hotkey_btn = "8"
+input_exit_emulator_btn = "9"
+
+input_menu_toggle_btn = "2"
+input_fps_toggle_btn = "3"
+
+input_load_state_btn = "4"
+input_save_state_btn = "5"
+
+input_rewind_btn = "11"
+input_toggle_fast_forward_btn = "12"
diff --git a/packages/hardware/quirks/devices/Anbernic RG552/050-game-configs b/packages/hardware/quirks/devices/Anbernic RG552/050-game-configs
new file mode 100644
index 0000000000..ceb8eee2a1
--- /dev/null
+++ b/packages/hardware/quirks/devices/Anbernic RG552/050-game-configs
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2024-present JELOS (https://github.com/JustEnoughLinuxOS)
+
+. /etc/profile
+
+#Remap joypad name to rg552_joypad
+sed -i '/^mapping_name = retrogame_joypad/c\mapping_name = rg552_joypad' /storage/.config/flycast/mappings/SDL_retrogame_joypad.cfg
+sed -i '/retrogame_joypad/c\[rg552_joypad]' /storage/.config/mupen64plus/custominput.ini
+sed -i '/name = "retrogame_joypad"/c\name = "rg552_joypad"' /storage/.config/mupen64plus/mupen64plus.cfg
+
+#Fix ES input
+for config in "/storage/.config/emulationstation/es_input.cfg"; do
+ if ! grep -q rg552_joypad "$config"; then
+ cp -r /usr/config/emulationstation/es_input.cfg /storage/.config/emulationstation/es_input.cfg
+ fi
+done;
diff --git a/packages/ui/emulationstation/config/common/es_input.cfg b/packages/ui/emulationstation/config/common/es_input.cfg
index ee4003b29b..0e55098f0e 100644
--- a/packages/ui/emulationstation/config/common/es_input.cfg
+++ b/packages/ui/emulationstation/config/common/es_input.cfg
@@ -1419,4 +1419,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/projects/Rockchip/devices/RK3399/linux/linux.aarch64.conf b/projects/Rockchip/devices/RK3399/linux/linux.aarch64.conf
index 665f841a34..40061e087a 100644
--- a/projects/Rockchip/devices/RK3399/linux/linux.aarch64.conf
+++ b/projects/Rockchip/devices/RK3399/linux/linux.aarch64.conf
@@ -1857,7 +1857,7 @@ CONFIG_JOYSTICK_XPAD_LEDS=y
# CONFIG_JOYSTICK_PXRC is not set
# CONFIG_JOYSTICK_QWIIC is not set
# CONFIG_JOYSTICK_FSIA6B is not set
-CONFIG_JOYSTICK_SINGLEADCJOY=y
+CONFIG_JOYSTICK_RG552=y
# CONFIG_JOYSTICK_SENSEHAT is not set
# CONFIG_INPUT_TABLET is not set
CONFIG_INPUT_TOUCHSCREEN=y
diff --git a/projects/Rockchip/packages/linux/patches/RK3399/000-rk3399-dts.patch b/projects/Rockchip/packages/linux/patches/RK3399/000-rk3399-dts.patch
index 5693dabdbd..a756ffb499 100644
--- a/projects/Rockchip/packages/linux/patches/RK3399/000-rk3399-dts.patch
+++ b/projects/Rockchip/packages/linux/patches/RK3399/000-rk3399-dts.patch
@@ -91,16 +91,16 @@ diff -rupN linux.orig/arch/arm64/boot/dts/rockchip/rk3399-anbernic-rg552.dts lin
+ };
+
+ joypad: singleadc-joypad {
-+ compatible = "singleadc-joypad";
++ compatible = "rg552_joypad";
+
+ pwms = <&pwm3 0 200000000 0>;
+ pwm-names = "enable";
+ rumble-boost-weak = <0x0000>;
+ rumble-boost-strong = <0x0000>;
+
-+ joypad-name = "retrogame_joypad";
++ joypad-name = "rg552_joypad";
+ joypad-product = <0x1101>;
-+ joypad-revision = <0x0200>;
++ joypad-revision = <0x0234>;
+
+ status = "okay";
+
diff --git a/projects/Rockchip/packages/linux/patches/RK3399/003-singleadc-joypad.patch b/projects/Rockchip/packages/linux/patches/RK3399/003-singleadc-joypad.patch
index 3500bd7144..46be5b0287 100644
--- a/projects/Rockchip/packages/linux/patches/RK3399/003-singleadc-joypad.patch
+++ b/projects/Rockchip/packages/linux/patches/RK3399/003-singleadc-joypad.patch
@@ -451,9 +451,9 @@ diff -rupN linux.orig/drivers/input/joystick/Kconfig linux/drivers/input/joystic
To compile this driver as a module, choose M here: the
module will be called fsia6b.
-+config JOYSTICK_SINGLEADCJOY
-+ tristate "Single SARADC dual-joystick gamepad driver"
-+ select INPUT_POLLDEV
++config JOYSTICK_RG552
++ tristate "Anbernic RG552 gamepad driver"
++ select INPUT_POLLDEV
+ help
+ The 1-in 4-out SARADC joypad driver.
+
@@ -467,22 +467,22 @@ diff -rupN linux.orig/drivers/input/joystick/Makefile linux/drivers/input/joysti
obj-$(CONFIG_JOYSTICK_QWIIC) += qwiic-joystick.o
obj-$(CONFIG_JOYSTICK_SENSEHAT) += sensehat-joystick.o
obj-$(CONFIG_JOYSTICK_SIDEWINDER) += sidewinder.o
-+obj-$(CONFIG_JOYSTICK_SINGLEADCJOY) += singleadcjoy.o
++obj-$(CONFIG_JOYSTICK_RG552) += rg552_joypad.o
obj-$(CONFIG_JOYSTICK_SPACEBALL) += spaceball.o
obj-$(CONFIG_JOYSTICK_SPACEORB) += spaceorb.o
obj-$(CONFIG_JOYSTICK_STINGER) += stinger.o
-diff -rupN linux.orig/drivers/input/joystick/singleadcjoy.c linux/drivers/input/joystick/singleadcjoy.c
---- linux.orig/drivers/input/joystick/singleadcjoy.c 1970-01-01 00:00:00.000000000 +0000
-+++ linux/drivers/input/joystick/singleadcjoy.c 2024-01-08 18:43:54.081267482 +0000
+diff -rupN linux.orig/drivers/input/joystick/rg552_joypad.c linux/drivers/input/joystick/rg552_joypad.c
+--- linux.orig/drivers/input/joystick/rg552_joypad.c 1970-01-01 00:00:00.000000000 +0000
++++ linux/drivers/input/joystick/rg552_joypad.c 2024-01-08 18:43:54.081267482 +0000
@@ -0,0 +1,1448 @@
+/*----------------------------------------------------------------------------*/
+
+/*
-+ * Copyright (c) 2008-2021 Anbernic
++ * Copyright (c) 2008-2021 Anbernic
+ */
+
+/*
-+ * Single SARADC dual-joystick gamepad driver
++ * Anbernic RG552 gamepad driver
+ */
+
+/*----------------------------------------------------------------------------*/
@@ -504,7 +504,7 @@ diff -rupN linux.orig/drivers/input/joystick/singleadcjoy.c linux/drivers/input/
+#include
+
+/*----------------------------------------------------------------------------*/
-+#define DRV_NAME "retrogame_joypad"
++#define DRV_NAME "rg552_joypad"
+
+/*----------------------------------------------------------------------------*/
+#define ADC_MAX_VOLTAGE 1800
@@ -739,7 +739,7 @@ diff -rupN linux.orig/drivers/input/joystick/singleadcjoy.c linux/drivers/input/
+/*
+ * ATTRIBUTES:
+ *
-+ * /sys/devices/platform/retrogame_joypad/poll_interval [rw]
++ * /sys/devices/platform/rg552_joypad/poll_interval [rw]
+ */
+/*----------------------------------------------------------------------------*/
+static ssize_t joypad_store_poll_interval(struct device *dev,
@@ -777,7 +777,7 @@ diff -rupN linux.orig/drivers/input/joystick/singleadcjoy.c linux/drivers/input/
+/*
+ * ATTRIBUTES:
+ *
-+ * /sys/devices/platform/retrogame_joypad/adc_fuzz [r]
++ * /sys/devices/platform/rg552_joypad/adc_fuzz [r]
+ */
+/*----------------------------------------------------------------------------*/
+static ssize_t joypad_show_adc_fuzz(struct device *dev,
@@ -799,7 +799,7 @@ diff -rupN linux.orig/drivers/input/joystick/singleadcjoy.c linux/drivers/input/
+/*
+ * ATTRIBUTES:
+ *
-+ * /sys/devices/platform/retrogame_joypad/adc_flat [r]
++ * /sys/devices/platform/rg552_joypad/adc_flat [r]
+ */
+/*----------------------------------------------------------------------------*/
+static ssize_t joypad_show_adc_flat(struct device *dev,
@@ -821,7 +821,7 @@ diff -rupN linux.orig/drivers/input/joystick/singleadcjoy.c linux/drivers/input/
+/*
+ * ATTRIBUTES:
+ *
-+ * /sys/devices/platform/retrogame_joypad/enable [rw]
++ * /sys/devices/platform/rg552_joypad/enable [rw]
+ */
+/*----------------------------------------------------------------------------*/
+static ssize_t joypad_store_enable(struct device *dev,
@@ -859,7 +859,7 @@ diff -rupN linux.orig/drivers/input/joystick/singleadcjoy.c linux/drivers/input/
+/*
+ * ATTRIBUTES:
+ *
-+ * /sys/devices/platform/retrogame_joypad/adc_cal [rw]
++ * /sys/devices/platform/rg552_joypad/adc_cal [rw]
+ */
+/*----------------------------------------------------------------------------*/
+static ssize_t joypad_store_adc_cal(struct device *dev,
@@ -921,7 +921,7 @@ diff -rupN linux.orig/drivers/input/joystick/singleadcjoy.c linux/drivers/input/
+/*
+ * ATTRIBUTES:
+ *
-+ * /sys/devices/platform/retrogame_joypad/amux_debug [rw]
++ * /sys/devices/platform/rg552_joypad/amux_debug [rw]
+ *
+ * echo [debug channel] > amux_debug
+ * cat amux_debug : debug channel mux set & adc read
@@ -1108,7 +1108,7 @@ diff -rupN linux.orig/drivers/input/joystick/singleadcjoy.c linux/drivers/input/
+/*
+ * ATTRIBUTES:
+ *
-+ * /sys/devices/platform/singleadc-joypad/hdst [rw]
++ * /sys/devices/platform/rg552_joypad/hdst [rw]
+ */
+/*----------------------------------------------------------------------------*/
+static ssize_t joypad_store_hdst(struct device *dev,
@@ -1892,7 +1892,7 @@ diff -rupN linux.orig/drivers/input/joystick/singleadcjoy.c linux/drivers/input/
+
+/*----------------------------------------------------------------------------*/
+static const struct of_device_id joypad_of_match[] = {
-+ { .compatible = "singleadc-joypad", },
++ { .compatible = "rg552_joypad", },
+ {},
+};
+