mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-05 19:08:12 +00:00
add 8BitDo Controller (#12964)
add SN30 Pro, SF30 Pro, Pro 2. Supported versions: Pro 2 v3.06 above SF30 Pro/SN30 Pro v2.05 above
This commit is contained in:
@@ -3177,7 +3177,20 @@ bool SDL_IsJoystickHoriSteamController(Uint16 vendor_id, Uint16 product_id)
|
|||||||
|
|
||||||
bool SDL_IsJoystick8BitDoController(Uint16 vendor_id, Uint16 product_id)
|
bool SDL_IsJoystick8BitDoController(Uint16 vendor_id, Uint16 product_id)
|
||||||
{
|
{
|
||||||
return vendor_id == USB_VENDOR_8BITDO && (product_id == USB_PRODUCT_8BITDO_ULTIMATE2_WIRELESS);
|
if (vendor_id == USB_VENDOR_8BITDO) {
|
||||||
|
switch (product_id) {
|
||||||
|
case USB_PRODUCT_8BITDO_ULTIMATE2_WIRELESS:
|
||||||
|
case USB_PRODUCT_8BITDO_SN30_PRO:
|
||||||
|
case USB_PRODUCT_8BITDO_SN30_PRO_BT:
|
||||||
|
case USB_PRODUCT_8BITDO_SF30_PRO:
|
||||||
|
case USB_PRODUCT_8BITDO_PRO_2:
|
||||||
|
case USB_PRODUCT_8BITDO_PRO_2_BT:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SDL_IsJoystickSteamDeck(Uint16 vendor_id, Uint16 product_id)
|
bool SDL_IsJoystickSteamDeck(Uint16 vendor_id, Uint16 product_id)
|
||||||
|
@@ -42,6 +42,11 @@ enum
|
|||||||
SDL_GAMEPAD_NUM_8BITDO_BUTTONS,
|
SDL_GAMEPAD_NUM_8BITDO_BUTTONS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define SDL_8BITDO_FEATURE_REPORTID_ENABLE_SDL_REPORTID 0x06
|
||||||
|
#define SDL_8BITDO_REPORTID_SDL_REPORTID 0x04
|
||||||
|
#define SDL_8BITDO_REPORTID_NOT_SUPPORTED_SDL_REPORTID 0x03
|
||||||
|
#define SDL_8BITDO_BT_REPORTID_SDL_REPORTID 0x01
|
||||||
|
|
||||||
#define ABITDO_ACCEL_SCALE 4096.f
|
#define ABITDO_ACCEL_SCALE 4096.f
|
||||||
#define SENSOR_INTERVAL_NS 8000000ULL
|
#define SENSOR_INTERVAL_NS 8000000ULL
|
||||||
|
|
||||||
@@ -112,6 +117,13 @@ static bool HIDAPI_Driver8BitDo_IsEnabled(void)
|
|||||||
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_8BITDO, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
|
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_8BITDO, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report, size_t length)
|
||||||
|
{
|
||||||
|
SDL_memset(report, 0, length);
|
||||||
|
report[0] = report_id;
|
||||||
|
return SDL_hid_get_feature_report(dev, report, length);
|
||||||
|
}
|
||||||
|
|
||||||
static bool HIDAPI_Driver8BitDo_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GamepadType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
|
static bool HIDAPI_Driver8BitDo_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GamepadType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
|
||||||
{
|
{
|
||||||
return SDL_IsJoystick8BitDoController(vendor_id, product_id);
|
return SDL_IsJoystick8BitDoController(vendor_id, product_id);
|
||||||
@@ -135,6 +147,19 @@ static bool HIDAPI_Driver8BitDo_InitDevice(SDL_HIDAPI_Device *device)
|
|||||||
ctx->rumble_supported = true;
|
ctx->rumble_supported = true;
|
||||||
ctx->powerstate_supported = true;
|
ctx->powerstate_supported = true;
|
||||||
}
|
}
|
||||||
|
} else if (device->product_id == USB_PRODUCT_8BITDO_SN30_PRO || device->product_id == USB_PRODUCT_8BITDO_SN30_PRO_BT ||
|
||||||
|
device->product_id == USB_PRODUCT_8BITDO_SF30_PRO || device->product_id == USB_PRODUCT_8BITDO_PRO_2 ||
|
||||||
|
device->product_id == USB_PRODUCT_8BITDO_PRO_2_BT) {
|
||||||
|
Uint8 data[USB_PACKET_LENGTH];
|
||||||
|
int size = ReadFeatureReport(device->dev, SDL_8BITDO_FEATURE_REPORTID_ENABLE_SDL_REPORTID, data, sizeof(data));
|
||||||
|
if (size > 0) {
|
||||||
|
ctx->sensors_supported = true;
|
||||||
|
ctx->rumble_supported = true;
|
||||||
|
ctx->powerstate_supported = true;
|
||||||
|
} else {
|
||||||
|
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
|
||||||
|
"HIDAPI_Driver8BitDo_InitDevice(): Couldn't read feature report 0x06");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return HIDAPI_JoystickConnected(device, NULL);
|
return HIDAPI_JoystickConnected(device, NULL);
|
||||||
@@ -236,7 +261,8 @@ static void HIDAPI_Driver8BitDo_HandleStatePacket(SDL_Joystick *joystick, SDL_Dr
|
|||||||
{
|
{
|
||||||
Sint16 axis;
|
Sint16 axis;
|
||||||
Uint64 timestamp = SDL_GetTicksNS();
|
Uint64 timestamp = SDL_GetTicksNS();
|
||||||
if (data[0] != 0x03 && data[0] != 0x01) {
|
if (data[0] != SDL_8BITDO_REPORTID_SDL_REPORTID && data[0] != SDL_8BITDO_REPORTID_NOT_SUPPORTED_SDL_REPORTID &&
|
||||||
|
data[0] != SDL_8BITDO_BT_REPORTID_SDL_REPORTID) {
|
||||||
// We don't know how to handle this report
|
// We don't know how to handle this report
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -60,6 +60,11 @@
|
|||||||
#define USB_VENDOR_ZEROPLUS 0x0c12
|
#define USB_VENDOR_ZEROPLUS 0x0c12
|
||||||
|
|
||||||
#define USB_PRODUCT_8BITDO_ULTIMATE2_WIRELESS 0x6012
|
#define USB_PRODUCT_8BITDO_ULTIMATE2_WIRELESS 0x6012
|
||||||
|
#define USB_PRODUCT_8BITDO_SN30_PRO 0x6001 // B + START
|
||||||
|
#define USB_PRODUCT_8BITDO_SN30_PRO_BT 0x6101 // B + START
|
||||||
|
#define USB_PRODUCT_8BITDO_SF30_PRO 0x6000 // B + START
|
||||||
|
#define USB_PRODUCT_8BITDO_PRO_2 0x6003 // mode switch to D
|
||||||
|
#define USB_PRODUCT_8BITDO_PRO_2_BT 0x6006 // mode switch to D
|
||||||
#define USB_PRODUCT_AMAZON_LUNA_CONTROLLER 0x0419
|
#define USB_PRODUCT_AMAZON_LUNA_CONTROLLER 0x0419
|
||||||
#define USB_PRODUCT_ASTRO_C40_XBOX360 0x0024
|
#define USB_PRODUCT_ASTRO_C40_XBOX360 0x0024
|
||||||
#define USB_PRODUCT_BACKBONE_ONE_IOS 0x0103
|
#define USB_PRODUCT_BACKBONE_ONE_IOS 0x0103
|
||||||
|
Reference in New Issue
Block a user