Heyy I found a fix and haven’t seen anything about it so I figured I’d write up about it here. I’m working on something rather big i’m planning on releasing soon, more to come on that later… but along the way I figured something out for myself. Hopefully it helps others? Maybe a community OS solves this and I’m just living under a rock… Anyway!
Spent a while debugging why the ABXY face buttons don’t work in mGBA on Bookworm even though the D-pad is fine. Turns out SDL 2.26 (which Bookworm ships) quietly changed how joystick GUIDs work.
It now sticks a CRC16 into bytes 2-3 of the GUID. So the old mapping everyone’s been using (03000000af1e…) doesn’t match anymore.
The actual GUID on Bookworm is 030000fdaf1e00002400000010010000. You can verify yours by saving this as guid.py on the uConsole (over SSH):
import ctypes, ctypes.util
class GUID(ctypes.Structure):
_fields_ = [('data', ctypes.c_uint8 * 16)]
sdl = ctypes.CDLL(ctypes.util.find_library('SDL2'))
sdl.SDL_JoystickOpen.restype = ctypes.c_void_p
sdl.SDL_JoystickGetGUID.restype = GUID
sdl.SDL_JoystickGetGUID.argtypes = [ctypes.c_void_p]
sdl.SDL_JoystickGetGUIDString.argtypes = [GUID, ctypes.c_char_p, ctypes.c_int]
sdl.SDL_Init(0x200)
js = sdl.SDL_JoystickOpen(0)
buf = ctypes.create_string_buffer(33)
sdl.SDL_JoystickGetGUIDString(sdl.SDL_JoystickGetGUID(js), buf, 33)
print(buf.value.decode())
sdl.SDL_Quit()
Then run it from a local terminal on the uConsole (not SSH — SDL can’t see the joystick over SSH):
python3 guid.py
Also found that the A/B buttons were swapped in the old mapping. Here’s what actually works - put this in your .profile or .bashrc:
export SDL_GAMECONTROLLERCONFIG="030000fdaf1e00002400000010010000,ClockworkPI uConsole,platform:Linux,a:b1,b:b2,x:b3,y:b0,back:b8,start:b9,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,"
For mGBA specifically (0.10.1 from apt), the SDL env var alone isn’t enough becuase it needs explicit button bindings in ~/.config/mgba/config.ini:
[gba.input.SDLB]
keyA=1
keyB=2
keyStart=0
keySelect=3
[gba.input-profile.030000fdaf1e00002400000010010000]
keyA=1
keyB=2
keyStart=0
keySelect=3
The section names and key prefix are important and it took a while to figure that out. mGBA’s config format is not well documented for the SDL build.
A couple other things I learned along the way:
-
The D-pad sends keyboard arrow keys, not joystick events. That’s why it works out of the box.
-
ABXY fire as BTN_TRIGGER through BTN_TOP on evdev but don’t show up on /dev/input/js0 at all. this is probably written somewhere idk about.
-
There’s no uConsole entry in the upstream SDL_GameControllerDB yet
Have fun playing Pokemon hahaha
My system: CM4, Debian Bookworm, SDL 2.26.5, mGBA 0.10.1.