RetroArch icon indicating copy to clipboard operation
RetroArch copied to clipboard

[SDL][Joypad] Support for SDL2 HIDAPI drivers

Open lucasmr opened this issue 3 years ago • 3 comments

Speaking on the Linux side: Linux gamepad specification If you have a non-standard controller with many axes or triggers (DS2, DS3, DS4, any controller with triggers or pressure-sensitive buttons), the drivers might simply not support them to conform to this spec. For example, Sony dropped pressure sensitivity in their hid-sony driver in this commit. Currently, the SDL GameController API follows the evdev implementation, so different controllers with more axes will never get properly configured. The axes are not even reported on evdev because the drivers won't support them all. What could be done:

  • Convince the maintainers to improve the gamepad specification and update every Linux driver to report all axes.
  • Talk to the gamepad directly via HIDAPI (hidraw or libusb backends). Every userspace application would need their own drivers. Some emulators do this.
  • Use an external library that does this.

Luckily, SDL2 has been implementing lots of HIDAPI drivers:

/* This is the full set of HIDAPI drivers available */                          
#define SDL_JOYSTICK_HIDAPI_GAMECUBE                                            
#define SDL_JOYSTICK_HIDAPI_LUNA                                                
#define SDL_JOYSTICK_HIDAPI_PS3                                                 
#define SDL_JOYSTICK_HIDAPI_PS4                                                 
#define SDL_JOYSTICK_HIDAPI_PS5                                                 
#define SDL_JOYSTICK_HIDAPI_STADIA                                              
#define SDL_JOYSTICK_HIDAPI_SWITCH                                              
#define SDL_JOYSTICK_HIDAPI_WII                                                 
#define SDL_JOYSTICK_HIDAPI_XBOX360                                             
#define SDL_JOYSTICK_HIDAPI_XBOXONE                                             
#define SDL_JOYSTICK_HIDAPI_SHIELD

By using SDL2, you can finally get all functionality from these controllers. However, you cannot use the GameController API and should fallback to the Joystick API, so some code changes are required. SDL_GameController SDL_Joystick

Relevant issues: #11721 #6920

lucasmr avatar Sep 16 '22 23:09 lucasmr

For reference, here's a DualShock 3 controller with every pressure-sensitive button working via SDL2 HIDAPI driver and sdl2-jstest: image Digital buttons (15): ×, ○, □, △, Select, PS, Start, L3, R3, L1, R1, ↑, ↓, ←, → Analog axes (16): Left Analog X, Left Analog Y, Right Analog X, Right Analog Y, L2, R2, ×, ○, □, △, L1, R1, ↑, ↓, ←, →,

lucasmr avatar Sep 16 '22 23:09 lucasmr

https://bugzilla.kernel.org/show_bug.cgi?id=195643

soredake avatar Sep 18 '22 07:09 soredake

Looks like SDL has finally support for pressure-sensitive buttons on Linux, MacOS and Windows: https://github.com/libsdl-org/SDL/issues/5148.

Maybe now it will be easier to put it into RetroArch.

eVenent avatar Aug 26 '24 09:08 eVenent