mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-13 19:58:45 +08:00
Implement SInput Device Support (#13343)
This implements a new SDL HID driver for a format developed by Hand Held Legend for their gamepad devices called SInput Devices that are supported by this change with well-defined mappings GC Ultimate ( https://gcultimate.com ) ProGCC ( https://handheldlegend.com/products/progcc-kit-wireless-wired-bundle ) The SInput format is documented here: https://github.com/HandHeldLegend/SInput-HID
This commit is contained in:
@@ -723,6 +723,7 @@
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_ps5.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_rumble.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_shield.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_sinput.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_stadia.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_steam.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_steam_hori.c" />
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_ps5.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_rumble.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_shield.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_sinput.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_stadia.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_steam.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_steam_hori.c" />
|
||||
|
||||
@@ -613,6 +613,7 @@
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_ps5.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_rumble.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_shield.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_sinput.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_stadia.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_steam.c" />
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_steam_hori.c" />
|
||||
@@ -774,4 +775,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -1215,6 +1215,9 @@
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_shield.c">
|
||||
<Filter>joystick\hidapi</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_sinput.c">
|
||||
<Filter>joystick\hidapi</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_stadia.c">
|
||||
<Filter>joystick\hidapi</Filter>
|
||||
</ClCompile>
|
||||
@@ -1615,4 +1618,4 @@
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="..\..\src\core\windows\version.rc" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -76,6 +76,7 @@
|
||||
89E580242D03606400DAF6D3 /* SDL_hidapihaptic_lg4ff.c in Sources */ = {isa = PBXBuildFile; fileRef = 89E580212D03606400DAF6D3 /* SDL_hidapihaptic_lg4ff.c */; };
|
||||
89E580252D03606400DAF6D3 /* SDL_hidapihaptic_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 89E580202D03606400DAF6D3 /* SDL_hidapihaptic_c.h */; };
|
||||
9846B07C287A9020000C35C8 /* SDL_hidapi_shield.c in Sources */ = {isa = PBXBuildFile; fileRef = 9846B07B287A9020000C35C8 /* SDL_hidapi_shield.c */; };
|
||||
02D6A1C228A84B8F00A7F002 /* SDL_hidapi_sinput.c in Sources */ = {isa = PBXBuildFile; fileRef = 02D6A1C128A84B8F00A7F001 /* SDL_hidapi_sinput.c */; };
|
||||
A1626A3E2617006A003F1973 /* SDL_triangle.c in Sources */ = {isa = PBXBuildFile; fileRef = A1626A3D2617006A003F1973 /* SDL_triangle.c */; };
|
||||
A1626A522617008D003F1973 /* SDL_triangle.h in Headers */ = {isa = PBXBuildFile; fileRef = A1626A512617008C003F1973 /* SDL_triangle.h */; };
|
||||
A1BB8B6327F6CF330057CFA8 /* SDL_list.c in Sources */ = {isa = PBXBuildFile; fileRef = A1BB8B6127F6CF320057CFA8 /* SDL_list.c */; };
|
||||
@@ -620,6 +621,7 @@
|
||||
89E580202D03606400DAF6D3 /* SDL_hidapihaptic_c.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDL_hidapihaptic_c.h; sourceTree = "<group>"; };
|
||||
89E580212D03606400DAF6D3 /* SDL_hidapihaptic_lg4ff.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = SDL_hidapihaptic_lg4ff.c; sourceTree = "<group>"; };
|
||||
9846B07B287A9020000C35C8 /* SDL_hidapi_shield.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_shield.c; sourceTree = "<group>"; };
|
||||
02D6A1C128A84B8F00A7F001 /* SDL_hidapi_sinput.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_sinput.c; sourceTree = "<group>"; };
|
||||
A1626A3D2617006A003F1973 /* SDL_triangle.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_triangle.c; sourceTree = "<group>"; };
|
||||
A1626A512617008C003F1973 /* SDL_triangle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_triangle.h; sourceTree = "<group>"; };
|
||||
A1BB8B6127F6CF320057CFA8 /* SDL_list.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_list.c; sourceTree = "<group>"; };
|
||||
@@ -1943,6 +1945,7 @@
|
||||
A75FDBC323EA380300529352 /* SDL_hidapi_rumble.h */,
|
||||
A75FDBC423EA380300529352 /* SDL_hidapi_rumble.c */,
|
||||
9846B07B287A9020000C35C8 /* SDL_hidapi_shield.c */,
|
||||
02D6A1C128A84B8F00A7F001 /* SDL_hidapi_sinput.c */,
|
||||
F3984CCF25BCC92800374F43 /* SDL_hidapi_stadia.c */,
|
||||
A75FDAAC23E2795C00529352 /* SDL_hidapi_steam.c */,
|
||||
F3FD042D2C9B755700824C4C /* SDL_hidapi_steam_hori.c */,
|
||||
@@ -2877,6 +2880,7 @@
|
||||
A7D8B62F23E2514300DCD162 /* SDL_sysfilesystem.m in Sources */,
|
||||
A7D8B41C23E2514300DCD162 /* SDL_systls.c in Sources */,
|
||||
9846B07C287A9020000C35C8 /* SDL_hidapi_shield.c in Sources */,
|
||||
02D6A1C228A84B8F00A7F002 /* SDL_hidapi_sinput.c in Sources */,
|
||||
F31013C72C24E98200FBE946 /* SDL_keymap.c in Sources */,
|
||||
F3A9AE992C8A13C100AAC390 /* SDL_render_gpu.c in Sources */,
|
||||
A7D8BBD923E2574800DCD162 /* SDL_uikitmessagebox.m in Sources */,
|
||||
|
||||
@@ -1746,6 +1746,18 @@ extern "C" {
|
||||
*/
|
||||
#define SDL_HINT_JOYSTICK_HIDAPI_8BITDO "SDL_JOYSTICK_HIDAPI_8BITDO"
|
||||
|
||||
/**
|
||||
* A variable controlling whether the HIDAPI driver for SInput controllers
|
||||
* should be used. More info - https://github.com/HandHeldLegend/SInput-HID
|
||||
*
|
||||
* This variable can be set to the following values:
|
||||
*
|
||||
* "0" - HIDAPI driver is not used. "1" - HIDAPI driver is used.
|
||||
*
|
||||
* The default is the value of SDL_HINT_JOYSTICK_HIDAPI
|
||||
*/
|
||||
#define SDL_HINT_JOYSTICK_HIDAPI_SINPUT "SDL_JOYSTICK_HIDAPI_SINPUT"
|
||||
|
||||
/**
|
||||
* A variable controlling whether the HIDAPI driver for Flydigi controllers
|
||||
* should be used.
|
||||
|
||||
@@ -798,6 +798,54 @@ static GamepadMapping_t *SDL_CreateMappingForHIDAPIGamepad(SDL_GUID guid)
|
||||
product == USB_PRODUCT_8BITDO_SF30_PRO_BT)) {
|
||||
// This controller has no guide button
|
||||
SDL_strlcat(mapping_string, "a:b1,b:b0,back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,", sizeof(mapping_string));
|
||||
} else if (SDL_IsJoystickSInputController(vendor, product)) {
|
||||
Uint8 face_style = (guid.data[15] & 0xF0) >> 4;
|
||||
Uint8 u_id = guid.data[15] & 0x0F;
|
||||
|
||||
switch (product) {
|
||||
case USB_PRODUCT_HANDHELDLEGEND_PROGCC:
|
||||
// ProGCC Mapping
|
||||
SDL_strlcat(mapping_string, "a:b1,b:b0,back:b15,dpdown:b5,dpleft:b6,dpright:b7,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b8,lefttrigger:b12,leftx:a0,lefty:a1,misc1:b17,rightshoulder:b11,rightstick:b9,righttrigger:b13,rightx:a2,righty:a3,start:b14,x:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,", sizeof(mapping_string));
|
||||
break;
|
||||
|
||||
case USB_PRODUCT_HANDHELDLEGEND_GCULTIMATE:
|
||||
// GC Ultimate Map
|
||||
SDL_strlcat(mapping_string, "a:b0,b:b2,back:b15,dpdown:b5,dpleft:b6,dpright:b7,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b8,lefttrigger:a4,leftx:a0,lefty:a1,misc1:b17,misc3:b18,paddle1:b13,paddle2:b12,rightshoulder:b11,rightstick:b9,righttrigger:a5,rightx:a2,righty:a3,start:b14,x:b1,y:b3,hint:!SDL_GAMECONTROLLER_USE_GAMECUBE_LABELS:=1,", sizeof(mapping_string));
|
||||
break;
|
||||
|
||||
case USB_PRODUCT_HANDHELDLEGEND_SINPUT_GENERIC:
|
||||
if (u_id != 1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// SuperGamepad+ Map
|
||||
if (u_id == 1) {
|
||||
SDL_strlcat(mapping_string, "a:b1,b:b0,back:b11,dpdown:b5,dpleft:b6,dpright:b7,dpup:b4,leftshoulder:b8,rightshoulder:b9,start:b10,x:b3,y:b2,", sizeof(mapping_string));
|
||||
}
|
||||
|
||||
// Apply face style
|
||||
switch (face_style) {
|
||||
default:
|
||||
case 1:
|
||||
SDL_strlcat(mapping_string, "face:abxy,", sizeof(mapping_string));
|
||||
break;
|
||||
case 2:
|
||||
SDL_strlcat(mapping_string, "face:axby,", sizeof(mapping_string));
|
||||
break;
|
||||
case 3:
|
||||
SDL_strlcat(mapping_string, "face:bayx,", sizeof(mapping_string));
|
||||
break;
|
||||
case 4:
|
||||
SDL_strlcat(mapping_string, "face:sony,", sizeof(mapping_string));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
case USB_PRODUCT_BONJIRICHANNEL_FIREBIRD:
|
||||
// Unmapped devices
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
// All other gamepads have the standard set of 19 buttons and 6 axes
|
||||
if (SDL_IsJoystickGameCube(vendor, product)) {
|
||||
@@ -1235,6 +1283,7 @@ static bool SDL_PrivateParseGamepadElement(SDL_Gamepad *gamepad, const char *szG
|
||||
if (SDL_strstr(gamepad->mapping->mapping, ",hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1") != NULL) {
|
||||
baxy_mapping = true;
|
||||
}
|
||||
|
||||
// FIXME: We fix these up when loading the mapping, does this ever get hit?
|
||||
//SDL_assert(!axby_mapping && !baxy_mapping);
|
||||
|
||||
|
||||
@@ -3202,6 +3202,17 @@ bool SDL_IsJoystickHoriSteamController(Uint16 vendor_id, Uint16 product_id)
|
||||
return vendor_id == USB_VENDOR_HORI && (product_id == USB_PRODUCT_HORI_STEAM_CONTROLLER || product_id == USB_PRODUCT_HORI_STEAM_CONTROLLER_BT);
|
||||
}
|
||||
|
||||
bool SDL_IsJoystickSInputController(Uint16 vendor_id, Uint16 product_id)
|
||||
{
|
||||
bool vendor_match = (vendor_id == USB_VENDOR_RASPBERRYPI);
|
||||
bool product_match =
|
||||
(product_id == USB_PRODUCT_HANDHELDLEGEND_SINPUT_GENERIC) |
|
||||
(product_id == USB_PRODUCT_HANDHELDLEGEND_PROGCC) |
|
||||
(product_id == USB_PRODUCT_HANDHELDLEGEND_GCULTIMATE) |
|
||||
(product_id == USB_PRODUCT_BONJIRICHANNEL_FIREBIRD);
|
||||
return (vendor_match && product_match);
|
||||
}
|
||||
|
||||
bool SDL_IsJoystickFlydigiController(Uint16 vendor_id, Uint16 product_id)
|
||||
{
|
||||
return vendor_id == USB_VENDOR_FLYDIGI && product_id == USB_PRODUCT_FLYDIGI_GAMEPAD;
|
||||
|
||||
@@ -135,6 +135,9 @@ extern bool SDL_IsJoystickSteamController(Uint16 vendor_id, Uint16 product_id);
|
||||
// Function to return whether a joystick is a HORI Steam controller
|
||||
extern bool SDL_IsJoystickHoriSteamController(Uint16 vendor_id, Uint16 product_id);
|
||||
|
||||
// Function to return whether a joystick is an SInput (Open Format) controller
|
||||
extern bool SDL_IsJoystickSInputController(Uint16 vendor_id, Uint16 product_id);
|
||||
|
||||
// Function to return whether a joystick is a Flydigi controller
|
||||
extern bool SDL_IsJoystickFlydigiController(Uint16 vendor_id, Uint16 product_id);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -97,6 +97,9 @@ static SDL_HIDAPI_DeviceDriver *SDL_HIDAPI_drivers[] = {
|
||||
#ifdef SDL_JOYSTICK_HIDAPI_FLYDIGI
|
||||
&SDL_HIDAPI_DriverFlydigi,
|
||||
#endif
|
||||
#ifdef SDL_JOYSTICK_HIDAPI_SINPUT
|
||||
&SDL_HIDAPI_DriverSInput,
|
||||
#endif
|
||||
};
|
||||
static int SDL_HIDAPI_numdrivers = 0;
|
||||
static SDL_AtomicInt SDL_HIDAPI_updating_devices;
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#define SDL_JOYSTICK_HIDAPI_8BITDO
|
||||
#define SDL_JOYSTICK_HIDAPI_FLYDIGI
|
||||
#define SDL_JOYSTICK_HIDAPI_GIP
|
||||
#define SDL_JOYSTICK_HIDAPI_SINPUT
|
||||
|
||||
// Joystick capability definitions
|
||||
#define SDL_JOYSTICK_CAP_MONO_LED 0x00000001
|
||||
@@ -165,6 +166,7 @@ extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamHori;
|
||||
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverLg4ff;
|
||||
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_Driver8BitDo;
|
||||
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverFlydigi;
|
||||
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSInput;
|
||||
|
||||
// Return true if a HID device is present and supported as a joystick of the given type
|
||||
extern bool HIDAPI_IsDeviceTypePresent(SDL_GamepadType type);
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
#define USB_VENDOR_SWITCH 0x2563
|
||||
#define USB_VENDOR_VALVE 0x28de
|
||||
#define USB_VENDOR_ZEROPLUS 0x0c12
|
||||
#define USB_VENDOR_RASPBERRYPI 0x2e8a // Commercial hardware from various companies are registered under this VID
|
||||
|
||||
#define USB_PRODUCT_8BITDO_SF30_PRO 0x6000 // B + START
|
||||
#define USB_PRODUCT_8BITDO_SF30_PRO_BT 0x6100 // B + START
|
||||
@@ -161,6 +162,10 @@
|
||||
#define USB_PRODUCT_XBOX_SERIES_X_BLE 0x0b13
|
||||
#define USB_PRODUCT_XBOX_ONE_XBOXGIP_CONTROLLER 0x02ff // XBOXGIP driver software PID
|
||||
#define USB_PRODUCT_STEAM_VIRTUAL_GAMEPAD 0x11ff
|
||||
#define USB_PRODUCT_HANDHELDLEGEND_SINPUT_GENERIC 0x10c6
|
||||
#define USB_PRODUCT_HANDHELDLEGEND_PROGCC 0x10df
|
||||
#define USB_PRODUCT_HANDHELDLEGEND_GCULTIMATE 0x10dd
|
||||
#define USB_PRODUCT_BONJIRICHANNEL_FIREBIRD 0x10e0
|
||||
|
||||
// USB usage pages
|
||||
#define USB_USAGEPAGE_GENERIC_DESKTOP 0x0001
|
||||
|
||||
Reference in New Issue
Block a user