Created
April 4, 2022 17:28
-
-
Save weirddan455/0c01897414c2ac7eab774b0fc46a9655 to your computer and use it in GitHub Desktop.
Xbox One Controller Bluetooth Patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c | |
index 071fd093a5f4..a4ba824395b0 100644 | |
--- a/drivers/hid/hid-microsoft.c | |
+++ b/drivers/hid/hid-microsoft.c | |
@@ -27,6 +27,7 @@ | |
#define MS_DUPLICATE_USAGES BIT(5) | |
#define MS_SURFACE_DIAL BIT(6) | |
#define MS_QUIRK_FF BIT(7) | |
+#define MS_QUIRK_XBOX BIT(8) | |
struct ms_data { | |
unsigned long quirks; | |
@@ -179,6 +180,34 @@ static int ms_surface_dial_quirk(struct hid_input *hi, struct hid_field *field, | |
return 0; | |
} | |
+static int ms_xbox_quirk(struct hid_input *hi, struct hid_usage *usage, | |
+ unsigned long **bit, int *max) | |
+{ | |
+ if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) { | |
+ switch (usage->hid & HID_USAGE) { | |
+ case 0x223: | |
+ ms_map_key_clear(BTN_MODE); | |
+ return 1; | |
+ case 0x224: | |
+ ms_map_key_clear(BTN_SELECT); | |
+ return 1; | |
+ } | |
+ } | |
+ | |
+ if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) { | |
+ int code = ((usage->hid - 1) & HID_USAGE) + BTN_GAMEPAD; | |
+ switch (code) { | |
+ case BTN_C: | |
+ case BTN_Z: | |
+ case BTN_TL2: | |
+ case BTN_TR2: | |
+ return -1; | |
+ } | |
+ } | |
+ | |
+ return 0; | |
+} | |
+ | |
static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |
struct hid_field *field, struct hid_usage *usage, | |
unsigned long **bit, int *max) | |
@@ -203,6 +232,12 @@ static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |
return ret; | |
} | |
+ if (quirks & MS_QUIRK_XBOX) { | |
+ int ret = ms_xbox_quirk(hi, usage, bit, max); | |
+ if (ret) | |
+ return ret; | |
+ } | |
+ | |
return 0; | |
} | |
@@ -447,7 +482,7 @@ static const struct hid_device_id ms_devices[] = { | |
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, 0x091B), | |
.driver_data = MS_SURFACE_DIAL }, | |
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_XBOX_ONE_S_CONTROLLER), | |
- .driver_data = MS_QUIRK_FF }, | |
+ .driver_data = MS_QUIRK_FF | MS_QUIRK_XBOX }, | |
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_8BITDO_SN30_PRO_PLUS), | |
.driver_data = MS_QUIRK_FF }, | |
{ } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment