libretro / RetroArch

Cross-platform, sophisticated frontend for the libretro API. Licensed GPLv3.
http://www.libretro.com
GNU General Public License v3.0
10.09k stars 1.81k forks source link

[SDL][Joypad] Support for SDL2 HIDAPI drivers #14421

Open lucasmr opened 2 years ago

lucasmr commented 2 years ago

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:

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 commented 2 years ago

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, ↑, ↓, ←, →,

soredake commented 1 year ago

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

eVenent commented 3 weeks ago

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.