From bbede6988770838e325dec268a341c64034b2ee3 Mon Sep 17 00:00:00 2001 From: pawndev Date: Fri, 3 Apr 2026 00:06:28 +0200 Subject: [PATCH] feat(rocknix/rgds): native keymapping in grout --- app/setup.go | 3 ++ cfw/rocknix/input_mappings.go | 51 ++++++++++++++++++++++++++++ cfw/rocknix/input_mappings/rgds.json | 25 ++++++++++++++ scripts/ROCKNIX/Grout.sh | 2 +- 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 cfw/rocknix/input_mappings.go create mode 100644 cfw/rocknix/input_mappings/rgds.json diff --git a/app/setup.go b/app/setup.go index 2e99382..6f07c4b 100644 --- a/app/setup.go +++ b/app/setup.go @@ -8,6 +8,7 @@ import ( "grout/cfw/minui" "grout/cfw/muos" "grout/cfw/onion" + "grout/cfw/rocknix" "grout/cfw/spruce" "grout/internal" "grout/internal/environment" @@ -87,6 +88,8 @@ func setupInputMapping(currentCFW cfw.CFW) { mappingBytes, mappingErr = minui.GetInputMappingBytes() case cfw.Spruce: mappingBytes, mappingErr = spruce.GetInputMappingBytes() + case cfw.ROCKNIX: + mappingBytes, mappingErr = rocknix.GetInputMappingBytes() } if mappingBytes != nil && mappingErr == nil { diff --git a/cfw/rocknix/input_mappings.go b/cfw/rocknix/input_mappings.go new file mode 100644 index 0000000..935268b --- /dev/null +++ b/cfw/rocknix/input_mappings.go @@ -0,0 +1,51 @@ +package rocknix + +import ( + "embed" + "fmt" + "os" + "path/filepath" + "strings" +) + +//go:embed input_mappings/*.json +var embeddedInputMappings embed.FS + +type Device string + +const ( + DeviceAnbernicRGDS Device = "rgds" + DeviceGeneric Device = "generic" +) + +func DetectDevice() Device { + compatible, err := os.ReadFile("/sys/firmware/devicetree/base/compatible") + if err == nil && strings.Contains(string(compatible), "anbernic,rg-ds") { + return DeviceAnbernicRGDS + } + + return DeviceGeneric +} + +func GetInputMappingBytes() ([]byte, error) { + device := DetectDevice() + + var filename string + switch device { + case DeviceAnbernicRGDS: + filename = "input_mappings/rgds.json" + default: + return nil, nil + } + + overridePath := filepath.Join("overrides", "cfw", "rocknix", filename) + data, err := os.ReadFile(overridePath) + if err != nil { + data, err = embeddedInputMappings.ReadFile(filename) + if err != nil { + return nil, fmt.Errorf("failed to read embedded input mapping %s: %w", filename, err) + } + } + + return data, nil +} diff --git a/cfw/rocknix/input_mappings/rgds.json b/cfw/rocknix/input_mappings/rgds.json new file mode 100644 index 0000000..3418457 --- /dev/null +++ b/cfw/rocknix/input_mappings/rgds.json @@ -0,0 +1,25 @@ +{ + "keyboard_map": {}, + "controller_button_map": { + "0": 6, + "1": 5, + "10": 11, + "11": 1, + "12": 2, + "13": 3, + "14": 4, + "2": 7, + "3": 8, + "4": 14, + "5": 15, + "6": 13, + "9": 9 + }, + "controller_hat_map": {}, + "joystick_axis_map": {}, + "joystick_button_map": { + "6": 10, + "7": 12 + }, + "joystick_hat_map": {} +} \ No newline at end of file diff --git a/scripts/ROCKNIX/Grout.sh b/scripts/ROCKNIX/Grout.sh index c48aff8..cdc6955 100644 --- a/scripts/ROCKNIX/Grout.sh +++ b/scripts/ROCKNIX/Grout.sh @@ -11,7 +11,7 @@ fi export CFW=ROCKNIX export LD_LIBRARY_PATH="$CUR_DIR/Grout/lib:$LD_LIBRARY_PATH" -export FLIP_FACE_BUTTONS=1 +#export FLIP_FACE_BUTTONS=1 ./grout