Skip to content

Commit e18c6bd

Browse files
authored
8BitDo (#12661)
Added HIDAPI support for the 8BitDo Ultimate 2 Wireless Controller running firmware v1.03 or newer over Bluetooth.
1 parent 6b1d6bf commit e18c6bd

File tree

13 files changed

+465
-1
lines changed

13 files changed

+465
-1
lines changed

VisualC-GDK/SDL/SDL.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@
712712
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
713713
<ClCompile Include="..\..\src\joystick\gdk\SDL_gameinputjoystick.c" />
714714
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapijoystick.c" />
715+
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_8bitdo.c" />
715716
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_combined.c" />
716717
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_gamecube.c" />
717718
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_luna.c" />

VisualC-GDK/SDL/SDL.vcxproj.filters

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
6464
<ClCompile Include="..\..\src\joystick\gdk\SDL_gameinputjoystick.c" />
6565
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapijoystick.c" />
66+
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_8bitdo.c" />
6667
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_combined.c" />
6768
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_gamecube.c" />
6869
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_luna.c" />

VisualC/SDL/SDL.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@
582582
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
583583
<ClCompile Include="..\..\src\joystick\gdk\SDL_gameinputjoystick.c" />
584584
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapijoystick.c" />
585+
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_8bitdo.c" />
585586
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_combined.c" />
586587
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_gamecube.c" />
587588
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_luna.c" />

VisualC/SDL/SDL.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,9 @@
11871187
<ClCompile Include="..\..\src\joystick\gdk\SDL_gameinputjoystick.c">
11881188
<Filter>joystick\gdk</Filter>
11891189
</ClCompile>
1190+
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_8bitdo.c">
1191+
<Filter>joystick\hidapi</Filter>
1192+
</ClCompile>
11901193
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_combined.c">
11911194
<Filter>joystick\hidapi</Filter>
11921195
</ClCompile>

Xcode/SDL/SDL.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@
388388
F32DDAD42AB795A30041EAA5 /* SDL_audioresample.c in Sources */ = {isa = PBXBuildFile; fileRef = F32DDACE2AB795A30041EAA5 /* SDL_audioresample.c */; };
389389
F338A1182D1B37D8007CDFDF /* SDL_tray.m in Sources */ = {isa = PBXBuildFile; fileRef = F338A1172D1B37D8007CDFDF /* SDL_tray.m */; };
390390
F338A11A2D1B37E4007CDFDF /* SDL_tray.c in Sources */ = {isa = PBXBuildFile; fileRef = F338A1192D1B37E4007CDFDF /* SDL_tray.c */; };
391+
F3395BA82D9A5971007246C8 /* SDL_hidapi_8bitdo.c in Sources */ = {isa = PBXBuildFile; fileRef = F3395BA72D9A5971007246C8 /* SDL_hidapi_8bitdo.c */; };
391392
F34400342D40217A003F26D7 /* LICENSE.txt in Resources */ = {isa = PBXBuildFile; fileRef = F373DA182D388A1E002158FA /* LICENSE.txt */; };
392393
F34400362D40217A003F26D7 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = F373DA192D388A1E002158FA /* README.md */; };
393394
F344003D2D4022E1003F26D7 /* INSTALL.md in Resources */ = {isa = PBXBuildFile; fileRef = F344003C2D4022E1003F26D7 /* INSTALL.md */; };
@@ -946,6 +947,7 @@
946947
F32DDACE2AB795A30041EAA5 /* SDL_audioresample.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_audioresample.c; sourceTree = "<group>"; };
947948
F338A1172D1B37D8007CDFDF /* SDL_tray.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDL_tray.m; sourceTree = "<group>"; };
948949
F338A1192D1B37E4007CDFDF /* SDL_tray.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = SDL_tray.c; sourceTree = "<group>"; };
950+
F3395BA72D9A5971007246C8 /* SDL_hidapi_8bitdo.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_8bitdo.c; sourceTree = "<group>"; };
949951
F344003C2D4022E1003F26D7 /* INSTALL.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = INSTALL.md; sourceTree = "<group>"; };
950952
F362B9152B3349E200D30B94 /* controller_list.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = controller_list.h; sourceTree = "<group>"; };
951953
F362B9162B3349E200D30B94 /* SDL_gamepad_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_gamepad_c.h; sourceTree = "<group>"; };
@@ -1923,9 +1925,10 @@
19231925
A7D8A7BE23E2513E00DCD162 /* hidapi */ = {
19241926
isa = PBXGroup;
19251927
children = (
1926-
89E5801D2D03602200DAF6D3 /* SDL_hidapi_lg4ff.c */,
1928+
F3395BA72D9A5971007246C8 /* SDL_hidapi_8bitdo.c */,
19271929
F32305FE28939F6400E66D30 /* SDL_hidapi_combined.c */,
19281930
A7D8A7C923E2513E00DCD162 /* SDL_hidapi_gamecube.c */,
1931+
89E5801D2D03602200DAF6D3 /* SDL_hidapi_lg4ff.c */,
19291932
F3F07D59269640160074468B /* SDL_hidapi_luna.c */,
19301933
F3FD042C2C9B755700824C4C /* SDL_hidapi_nintendo.h */,
19311934
F388C95428B5F6F600661ECF /* SDL_hidapi_ps3.c */,
@@ -3075,6 +3078,7 @@
30753078
000028F8113A53F4333E0000 /* SDL_main_callbacks.c in Sources */,
30763079
000098E9DAA43EF6FF7F0000 /* SDL_camera.c in Sources */,
30773080
F310138E2C1F2CB700FBE946 /* SDL_random.c in Sources */,
3081+
F3395BA82D9A5971007246C8 /* SDL_hidapi_8bitdo.c in Sources */,
30783082
00001B2471F503DD3C1B0000 /* SDL_camera_dummy.c in Sources */,
30793083
00002B20A48E055EB0350000 /* SDL_camera_coremedia.m in Sources */,
30803084
000080903BC03006F24E0000 /* SDL_filesystem.c in Sources */,

include/SDL3/SDL_hints.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,19 @@ extern "C" {
17341734
*/
17351735
#define SDL_HINT_JOYSTICK_HIDAPI_LG4FF "SDL_JOYSTICK_HIDAPI_LG4FF"
17361736

1737+
/**
1738+
* A variable controlling whether the HIDAPI driver for 8BitDo
1739+
* controllers should be used.
1740+
*
1741+
* This variable can be set to the following values:
1742+
*
1743+
* "0" - HIDAPI driver is not used.
1744+
* "1" - HIDAPI driver is used.
1745+
*
1746+
* The default is the value of SDL_HINT_JOYSTICK_HIDAPI
1747+
*/
1748+
#define SDL_HINT_JOYSTICK_HIDAPI_8BITDO "SDL_JOYSTICK_HIDAPI_8BITDO"
1749+
17371750
/**
17381751
* A variable controlling whether the HIDAPI driver for Nintendo Switch
17391752
* controllers should be used.

src/joystick/SDL_gamepad.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,8 @@ static GamepadMapping_t *SDL_CreateMappingForHIDAPIGamepad(SDL_GUID guid)
814814
} else if (SDL_IsJoystickHoriSteamController(vendor, product)) {
815815
/* The Wireless HORIPad for Steam has QAM, Steam, Capsense L/R Sticks, 2 rear buttons, and 2 misc buttons */
816816
SDL_strlcat(mapping_string, "paddle1:b13,paddle2:b12,paddle3:b15,paddle4:b14,misc2:b11,misc3:b16,misc4:b17", sizeof(mapping_string));
817+
} else if (SDL_IsJoystick8BitDoController(vendor, product)) {
818+
SDL_strlcat(mapping_string, "paddle1:b12,paddle2:b11,paddle3:b14,paddle4:b13", sizeof(mapping_string));
817819
} else {
818820
switch (SDL_GetGamepadTypeFromGUID(guid, NULL)) {
819821
case SDL_GAMEPAD_TYPE_PS4:

src/joystick/SDL_joystick.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,6 +3029,11 @@ bool SDL_IsJoystickHoriSteamController(Uint16 vendor_id, Uint16 product_id)
30293029
return vendor_id == USB_VENDOR_HORI && (product_id == USB_PRODUCT_HORI_STEAM_CONTROLLER || product_id == USB_PRODUCT_HORI_STEAM_CONTROLLER_BT);
30303030
}
30313031

3032+
bool SDL_IsJoystick8BitDoController(Uint16 vendor_id, Uint16 product_id)
3033+
{
3034+
return vendor_id == USB_VENDOR_8BITDO && (product_id == USB_PRODUCT_8BITDO_ULTIMATE2_WIRELESS);
3035+
}
3036+
30323037
bool SDL_IsJoystickSteamDeck(Uint16 vendor_id, Uint16 product_id)
30333038
{
30343039
EControllerType eType = GuessControllerType(vendor_id, product_id);

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 a 8BitDo controller
139+
extern bool SDL_IsJoystick8BitDoController(Uint16 vendor_id, Uint16 product_id);
140+
138141
// Function to return whether a joystick is a Steam Deck
139142
extern bool SDL_IsJoystickSteamDeck(Uint16 vendor_id, Uint16 product_id);
140143

0 commit comments

Comments
 (0)