libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.82k stars 1.82k forks source link

SDL doesn't interpret Xbox Elite Series 2 input correctly via Bluetooth #8907

Closed TacoDog311 closed 1 month ago

TacoDog311 commented 9 months ago

Xbox Elite Series 2 input is read correctly via USB cord but not bluetooth. When connected via Bluetooth, sdl2-jstest reports 122 buttons, and only one paddle (top right) seems to work with SDL programs.

Oddly, jstest with root permissions seems to correctly identify all buttons over bluetooth.

This udev rule is being used to mark the controller as a joystick, which is only necessary for the Bluetooth connection.

SUBSYSTEM=="input", ATTRS{id/product}=="0b22", ATTRS{id/vendor}=="045e", MODE="0666", ENV{ID_INPUT_JOYSTICK}="1"

USB cord:

> ./sdl2-jstest -l
Found 1 joystick(s)

Joystick Name:     'Xbox One Elite 2 Controller'
Joystick GUID:     03005d085e040000000b000011050000
Joystick Number:    0
Number of Axes:     6
Number of Buttons: 15
Number of Hats:     1
Number of Balls:    0
GameControllerConfig:
  Name:    'Xbox One Elite 2 Controller'
  Mapping: '03005d085e040000000b000011050000,Xbox One Elite 2 Controller,a:b0,b:b1,x:b2,y:b3,back:b6,guide:b8,start:b7,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,paddle1:b11,paddle2:b13,paddle3:b12,paddle4:b14,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,crc:085d,platform:Linux'

Bluetooth:

> ./sdl2-jstest -l
Found 1 joystick(s)

Joystick Name:     'Xbox One Elite 2 Controller'
Joystick GUID:     05005d085e040000220b000017050000
Joystick Number:    0
Number of Axes:     6
Number of Buttons: 122
Number of Hats:     1
Number of Balls:    0
GameControllerConfig:
  Name:    'Xbox One Elite 2 Controller'
  Mapping: '05005d085e040000220b000017050000,Xbox One Elite 2 Controller,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,paddle1:b15,paddle2:b17,paddle3:b16,paddle4:b18,crc:085d,platform:Linux,'

Bluetooth with sudo:

> sudo ./sdl2-jstest -l
Found 1 joystick(s)

Joystick Name:     'Xbox One Elite 2 Controller'
Joystick GUID:     03005d085e040000000b000011056800
Joystick Number:    0
Number of Axes:     6
Number of Buttons: 19
Number of Hats:     0
Number of Balls:    0
GameControllerConfig:
  Name:    'Xbox One Elite 2 Controller'
  Mapping: '03005d085e040000000b000011056800,*,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,paddle1:b15,paddle2:b17,paddle3:b16,paddle4:b18,crc:085d,platform:Linux'
slouken commented 9 months ago

What kernel driver do you have for the Xbox controller?

TacoDog311 commented 9 months ago

No additional drivers installed, just what's in the Linux Kernel:

Linux 6.7.0-arch3-1 #1 SMP PREEMPT_DYNAMIC Sat, 13 Jan 2024 14:37:14 +0000 x86_64 GNU/Linux
slouken commented 9 months ago

What does it say in dmesg when you connect your controller?

TacoDog311 commented 9 months ago

USB:

[62187.349397] usb 1-4: new full-speed USB device number 30 using xhci_hcd
[62187.491177] usb 1-4: New USB device found, idVendor=045e, idProduct=0b00, bcdDevice= 5.11
[62187.491181] usb 1-4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[62187.491183] usb 1-4: Product: Controller
[62187.491184] usb 1-4: Manufacturer: Microsoft
[62187.491185] usb 1-4: SerialNumber: 30324D4930303736333233333430
[62187.494126] input: Microsoft X-Box One Elite 2 pad as /devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4:1.0/input/input104
[62198.941815] usb 1-4: USB disconnect, device number 30

Bluetooth:

[62199.976435] input: Xbox Wireless Controller as /devices/virtual/misc/uhid/0005:045E:0B22.003E/input/input105
[62199.976888] microsoft 0005:045E:0B22.003E: input,hidraw1: BLUETOOTH HID v5.17 Gamepad [Xbox Wireless Controller] on 20:16:b9:b7:ab:6e
slouken commented 9 months ago

uhid means there’s a user space driver picking up the Bluetooth controller. Do you know which one that is?

TacoDog311 commented 9 months ago

I think the driver is called hid_microsoft.

Does this info help?

dmsg:

5448.514466] input: Xbox Wireless Controller as /devices/virtual/misc/uhid/0005:045E:0B22.0042/input/input109
[65448.514862] microsoft 0005:045E:0B22.0042: input,hidraw1: BLUETOOTH HID v5.17 Gamepad [Xbox Wireless Controller] on 20:16:b9:b7:ab:6e
> ls -l /sys/class/input/input109/device/driver       
lrwxrwxrwx 1 root root 0 Jan 23 09:28 /sys/class/input/input109/device/driver -> ../../../../../bus/hid/drivers/microsoft

> ls -l /sys/class/input/input109/device/driver/module
lrwxrwxrwx 1 root root 0 Jan 23 09:07 /sys/class/input/input109/device/driver/module -> ../../../../module/hid_microsoft
> modinfo hid_microsoft
filename:       /lib/modules/6.7.0-arch3-1/kernel/drivers/hid/hid-microsoft.ko.zst
license:        GPL
srcversion:     87BDA7A5262AA831EC7A9E4
alias:          hid:b0005g*v0000045Ep000002E0
alias:          hid:b0005g*v0000045Ep00000B22
alias:          hid:b0005g*v0000045Ep00000B05
alias:          hid:b0005g*v0000045Ep00000B13
alias:          hid:b0005g*v0000045Ep00000B20
alias:          hid:b0005g*v0000045Ep000002FD
alias:          hid:b0005g*v0000045Ep0000091B
alias:          hid:b0005g*v0000045Ep00000701
alias:          hid:b0003g*v0000045Ep000000E3
alias:          hid:b0003g*v0000045Ep000007DA
alias:          hid:b0003g*v0000045Ep0000076C
alias:          hid:b0003g*v0000045Ep0000009D
alias:          hid:b0003g*v0000045Ep00000732
alias:          hid:b0003g*v0000045Ep00000750
alias:          hid:b0003g*v0000045Ep000000B4
alias:          hid:b0003g*v0000045Ep00000730
alias:          hid:b0003g*v0000045Ep00000713
alias:          hid:b0003g*v0000045Ep000000F9
alias:          hid:b0003g*v0000045Ep0000071D
alias:          hid:b0003g*v0000045Ep000000DC
alias:          hid:b0003g*v0000045Ep000000DB
alias:          hid:b0003g*v0000045Ep00000048
alias:          hid:b0003g*v0000045Ep0000003B
depends:        ff-memless
retpoline:      Y
intree:         Y
name:           hid_microsoft
vermagic:       6.7.0-arch3-1 SMP preempt mod_unload 
sig_id:         PKCS#7
signer:         Build time autogenerated kernel key
sig_key:        74:AD:6D:EF:C7:AA:E6:D8:28:90:49:4D:D6:B5:90:3D:31:F0:1A:2F
sig_hashalgo:   sha512
signature:      30:66:02:31:00:85:CD:24:3E:C9:00:77:5D:43:33:99:2F:0B:7B:6E:
                BB:C6:0C:09:53:17:28:C2:E5:AE:55:5C:EE:22:AE:C9:2F:6E:F9:00:
                11:19:AC:3D:CF:72:88:4B:86:B1:16:26:F2:02:31:00:A7:ED:9D:66:
                26:A7:07:F2:CA:5D:50:28:BE:EC:01:A3:29:1C:CE:A7:A0:B5:2A:AA:
                85:6E:50:C3:A7:07:F2:6E:FF:56:8B:22:C1:78:07:D8:A3:FA:D3:EB:
                46:B6:F9:20
slouken commented 9 months ago

No, that's not a user mode driver. You might find it by running ps aux and looking at the process list for anything that looks drivery or xboxery.

TacoDog311 commented 9 months ago

I did a full reboot, connected the controller. Seeing the same behavior, but I can't find anything suspicious in "ps aux"

https://pastebin.com/iY4HfZi6

slouken commented 9 months ago

I don't see anything obvious, but from a little google searching, it looks like maybe you're using https://atar-axis.github.io/xpadneo/?

TacoDog311 commented 9 months ago

At one time I did have that installed through the package manager. But I have since removed it. Just to double check I tried the xpadneo uninstall script, and it doesn't find it.

 sudo ./uninstall.sh
* unloading current driver module
modprobe: FATAL: Module hid_xpadneo not found.
* looking for registered instances
found 0 registered instance(s) on your system

I noticed that when connected by USB the driver connected to the /sys/class/input/inputXX/device/driver appears to be xpad as opposed to hid_microsoft.

slouken commented 9 months ago

What happens if you just use controllermap in the test directory to create a new mapping?

TacoDog311 commented 9 months ago

controllermap also finds 122 buttons. Paddle1 (top right hand) records as button 121. The other three paddles do not register when clicked.

INFO: There are 1 joysticks attached
INFO: Joystick 0: Xbox One Elite 2 Controller
INFO:        axes: 6
INFO:       balls: 0
INFO:        hats: 1
INFO:     buttons: 122
INFO: instance id: 0
INFO:        guid: 05005d085e040000220b000017050000
INFO:     VID/PID: 0x045e/0x0b22
INFO: Watching joystick 0: (Xbox One Elite 2 Controller)
INFO: Joystick has 6 axes, 1 hats, 0 balls, and 122 buttons
INFO: 
05005d085e040000220b000017050000,Xbox One Elite 2 Controller,platform:Linux,b:b1,x:b3,y:b4,back:b10,guide:b12,start:b11,leftstick:b13,rightstick:b14,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,paddle1:b121,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a5,righttrigger:a4,
slouken commented 9 months ago

Hmm, aside from the paddles, everything there looks like I would expect. This doesn't look like an SDL bug, this is happening in the driver for the Xbox controller, whatever that is.