Skip to content

Commit 18eeaea

Browse files
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
1 parent a53eb52 commit 18eeaea

File tree

13 files changed

+906
-2
lines changed

13 files changed

+906
-2
lines changed

VisualC-GDK/SDL/SDL.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@
723723
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_ps5.c" />
724724
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_rumble.c" />
725725
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_shield.c" />
726+
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_sinput.c" />
726727
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_stadia.c" />
727728
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_steam.c" />
728729
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_steam_hori.c" />

VisualC-GDK/SDL/SDL.vcxproj.filters

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_ps5.c" />
7575
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_rumble.c" />
7676
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_shield.c" />
77+
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_sinput.c" />
7778
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_stadia.c" />
7879
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_steam.c" />
7980
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_steam_hori.c" />

VisualC/SDL/SDL.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@
613613
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_ps5.c" />
614614
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_rumble.c" />
615615
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_shield.c" />
616+
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_sinput.c" />
616617
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_stadia.c" />
617618
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_steam.c" />
618619
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_steam_hori.c" />
@@ -774,4 +775,4 @@
774775
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
775776
<ImportGroup Label="ExtensionTargets">
776777
</ImportGroup>
777-
</Project>
778+
</Project>

VisualC/SDL/SDL.vcxproj.filters

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,9 @@
12151215
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_shield.c">
12161216
<Filter>joystick\hidapi</Filter>
12171217
</ClCompile>
1218+
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_sinput.c">
1219+
<Filter>joystick\hidapi</Filter>
1220+
</ClCompile>
12181221
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_stadia.c">
12191222
<Filter>joystick\hidapi</Filter>
12201223
</ClCompile>
@@ -1615,4 +1618,4 @@
16151618
<ItemGroup>
16161619
<ResourceCompile Include="..\..\src\core\windows\version.rc" />
16171620
</ItemGroup>
1618-
</Project>
1621+
</Project>

Xcode/SDL/SDL.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
89E580242D03606400DAF6D3 /* SDL_hidapihaptic_lg4ff.c in Sources */ = {isa = PBXBuildFile; fileRef = 89E580212D03606400DAF6D3 /* SDL_hidapihaptic_lg4ff.c */; };
7777
89E580252D03606400DAF6D3 /* SDL_hidapihaptic_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 89E580202D03606400DAF6D3 /* SDL_hidapihaptic_c.h */; };
7878
9846B07C287A9020000C35C8 /* SDL_hidapi_shield.c in Sources */ = {isa = PBXBuildFile; fileRef = 9846B07B287A9020000C35C8 /* SDL_hidapi_shield.c */; };
79+
02D6A1C228A84B8F00A7F002 /* SDL_hidapi_sinput.c in Sources */ = {isa = PBXBuildFile; fileRef = 02D6A1C128A84B8F00A7F001 /* SDL_hidapi_sinput.c */; };
7980
A1626A3E2617006A003F1973 /* SDL_triangle.c in Sources */ = {isa = PBXBuildFile; fileRef = A1626A3D2617006A003F1973 /* SDL_triangle.c */; };
8081
A1626A522617008D003F1973 /* SDL_triangle.h in Headers */ = {isa = PBXBuildFile; fileRef = A1626A512617008C003F1973 /* SDL_triangle.h */; };
8182
A1BB8B6327F6CF330057CFA8 /* SDL_list.c in Sources */ = {isa = PBXBuildFile; fileRef = A1BB8B6127F6CF320057CFA8 /* SDL_list.c */; };
@@ -620,6 +621,7 @@
620621
89E580202D03606400DAF6D3 /* SDL_hidapihaptic_c.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDL_hidapihaptic_c.h; sourceTree = "<group>"; };
621622
89E580212D03606400DAF6D3 /* SDL_hidapihaptic_lg4ff.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = SDL_hidapihaptic_lg4ff.c; sourceTree = "<group>"; };
622623
9846B07B287A9020000C35C8 /* SDL_hidapi_shield.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_shield.c; sourceTree = "<group>"; };
624+
02D6A1C128A84B8F00A7F001 /* SDL_hidapi_sinput.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_sinput.c; sourceTree = "<group>"; };
623625
A1626A3D2617006A003F1973 /* SDL_triangle.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_triangle.c; sourceTree = "<group>"; };
624626
A1626A512617008C003F1973 /* SDL_triangle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_triangle.h; sourceTree = "<group>"; };
625627
A1BB8B6127F6CF320057CFA8 /* SDL_list.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_list.c; sourceTree = "<group>"; };
@@ -1943,6 +1945,7 @@
19431945
A75FDBC323EA380300529352 /* SDL_hidapi_rumble.h */,
19441946
A75FDBC423EA380300529352 /* SDL_hidapi_rumble.c */,
19451947
9846B07B287A9020000C35C8 /* SDL_hidapi_shield.c */,
1948+
02D6A1C128A84B8F00A7F001 /* SDL_hidapi_sinput.c */,
19461949
F3984CCF25BCC92800374F43 /* SDL_hidapi_stadia.c */,
19471950
A75FDAAC23E2795C00529352 /* SDL_hidapi_steam.c */,
19481951
F3FD042D2C9B755700824C4C /* SDL_hidapi_steam_hori.c */,
@@ -2877,6 +2880,7 @@
28772880
A7D8B62F23E2514300DCD162 /* SDL_sysfilesystem.m in Sources */,
28782881
A7D8B41C23E2514300DCD162 /* SDL_systls.c in Sources */,
28792882
9846B07C287A9020000C35C8 /* SDL_hidapi_shield.c in Sources */,
2883+
02D6A1C228A84B8F00A7F002 /* SDL_hidapi_sinput.c in Sources */,
28802884
F31013C72C24E98200FBE946 /* SDL_keymap.c in Sources */,
28812885
F3A9AE992C8A13C100AAC390 /* SDL_render_gpu.c in Sources */,
28822886
A7D8BBD923E2574800DCD162 /* SDL_uikitmessagebox.m in Sources */,

include/SDL3/SDL_hints.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,18 @@ extern "C" {
17461746
*/
17471747
#define SDL_HINT_JOYSTICK_HIDAPI_8BITDO "SDL_JOYSTICK_HIDAPI_8BITDO"
17481748

1749+
/**
1750+
* A variable controlling whether the HIDAPI driver for SInput controllers
1751+
* should be used. More info - https://github.com/HandHeldLegend/SInput-HID
1752+
*
1753+
* This variable can be set to the following values:
1754+
*
1755+
* "0" - HIDAPI driver is not used. "1" - HIDAPI driver is used.
1756+
*
1757+
* The default is the value of SDL_HINT_JOYSTICK_HIDAPI
1758+
*/
1759+
#define SDL_HINT_JOYSTICK_HIDAPI_SINPUT "SDL_JOYSTICK_HIDAPI_SINPUT"
1760+
17491761
/**
17501762
* A variable controlling whether the HIDAPI driver for Flydigi controllers
17511763
* should be used.

src/joystick/SDL_gamepad.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,54 @@ static GamepadMapping_t *SDL_CreateMappingForHIDAPIGamepad(SDL_GUID guid)
798798
product == USB_PRODUCT_8BITDO_SF30_PRO_BT)) {
799799
// This controller has no guide button
800800
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));
801+
} else if (SDL_IsJoystickSInputController(vendor, product)) {
802+
Uint8 face_style = (guid.data[15] & 0xF0) >> 4;
803+
Uint8 u_id = guid.data[15] & 0x0F;
804+
805+
switch (product) {
806+
case USB_PRODUCT_HANDHELDLEGEND_PROGCC:
807+
// ProGCC Mapping
808+
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));
809+
break;
810+
811+
case USB_PRODUCT_HANDHELDLEGEND_GCULTIMATE:
812+
// GC Ultimate Map
813+
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));
814+
break;
815+
816+
case USB_PRODUCT_HANDHELDLEGEND_SINPUT_GENERIC:
817+
if (u_id != 1) {
818+
return NULL;
819+
}
820+
821+
// SuperGamepad+ Map
822+
if (u_id == 1) {
823+
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));
824+
}
825+
826+
// Apply face style
827+
switch (face_style) {
828+
default:
829+
case 1:
830+
SDL_strlcat(mapping_string, "face:abxy,", sizeof(mapping_string));
831+
break;
832+
case 2:
833+
SDL_strlcat(mapping_string, "face:axby,", sizeof(mapping_string));
834+
break;
835+
case 3:
836+
SDL_strlcat(mapping_string, "face:bayx,", sizeof(mapping_string));
837+
break;
838+
case 4:
839+
SDL_strlcat(mapping_string, "face:sony,", sizeof(mapping_string));
840+
break;
841+
}
842+
break;
843+
844+
default:
845+
case USB_PRODUCT_BONJIRICHANNEL_FIREBIRD:
846+
// Unmapped devices
847+
return NULL;
848+
}
801849
} else {
802850
// All other gamepads have the standard set of 19 buttons and 6 axes
803851
if (SDL_IsJoystickGameCube(vendor, product)) {
@@ -1235,6 +1283,7 @@ static bool SDL_PrivateParseGamepadElement(SDL_Gamepad *gamepad, const char *szG
12351283
if (SDL_strstr(gamepad->mapping->mapping, ",hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1") != NULL) {
12361284
baxy_mapping = true;
12371285
}
1286+
12381287
// FIXME: We fix these up when loading the mapping, does this ever get hit?
12391288
//SDL_assert(!axby_mapping && !baxy_mapping);
12401289

src/joystick/SDL_joystick.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,6 +3202,17 @@ bool SDL_IsJoystickHoriSteamController(Uint16 vendor_id, Uint16 product_id)
32023202
return vendor_id == USB_VENDOR_HORI && (product_id == USB_PRODUCT_HORI_STEAM_CONTROLLER || product_id == USB_PRODUCT_HORI_STEAM_CONTROLLER_BT);
32033203
}
32043204

3205+
bool SDL_IsJoystickSInputController(Uint16 vendor_id, Uint16 product_id)
3206+
{
3207+
bool vendor_match = (vendor_id == USB_VENDOR_RASPBERRYPI);
3208+
bool product_match =
3209+
(product_id == USB_PRODUCT_HANDHELDLEGEND_SINPUT_GENERIC) |
3210+
(product_id == USB_PRODUCT_HANDHELDLEGEND_PROGCC) |
3211+
(product_id == USB_PRODUCT_HANDHELDLEGEND_GCULTIMATE) |
3212+
(product_id == USB_PRODUCT_BONJIRICHANNEL_FIREBIRD);
3213+
return (vendor_match && product_match);
3214+
}
3215+
32053216
bool SDL_IsJoystickFlydigiController(Uint16 vendor_id, Uint16 product_id)
32063217
{
32073218
return vendor_id == USB_VENDOR_FLYDIGI && product_id == USB_PRODUCT_FLYDIGI_GAMEPAD;

src/joystick/SDL_joystick_c.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ extern bool SDL_IsJoystickSteamController(Uint16 vendor_id, Uint16 product_id);
135135
// Function to return whether a joystick is a HORI Steam controller
136136
extern bool SDL_IsJoystickHoriSteamController(Uint16 vendor_id, Uint16 product_id);
137137

138+
// Function to return whether a joystick is an SInput (Open Format) controller
139+
extern bool SDL_IsJoystickSInputController(Uint16 vendor_id, Uint16 product_id);
140+
138141
// Function to return whether a joystick is a Flydigi controller
139142
extern bool SDL_IsJoystickFlydigiController(Uint16 vendor_id, Uint16 product_id);
140143

0 commit comments

Comments
 (0)