Microsoft manufactures good hardware but sometimes it is difficult to configure it under Linux. In this case, it is about the XboxOne gamepad. According to some websites , the Linux kernel has support for Xbox One from version 4.5. Currently, Gentoo has a stable kernel of version 4.4.39. To keep the stable kernel and enjoy our gamepad, we will compile the module independently and load it.
We download the latest version of the Xpad driver code and compile the module.
We make a copy of the previous module, download the module, and reload it.
rmmod xpad
modprobe xpad
The SDL libraries have some very useful tools. We download the source code and compile them.
wget –no-check-certificate https://libsdl.org/release/SDL2-2.0.5.tar.gz
tar xvzf SDL2-2.0.5.tar.gz
cd SDL2-2.0.5/test
./configure
gcc -o testjoystick testjoystick.c -g -O2 -D_REENTRANT -I/usr/include/SDL2 -DHAVE_OPENGL -g -lSDL2_test -lSDL2
gcc -o controllermap controllermap.c -g -O2 -D_REENTRANT -I/usr/include/SDL2 -DHAVE_OPENGL -g -lSDL2_test -lSDL2
We check the gamepad ID and firmware version.
INFO: There are 1 joysticks attached
INFO: Joystick 0: Microsoft X-Box One pad (Firmware 2015)
INFO: axes: 6
INFO: balls: 0
INFO: hats: 1
INFO: buttons: 11
INFO: instance id: 0
INFO: guid: 030000005e040000dd02000003020000
We launch an assistant that will allow us to obtain the button mapping of our gamepad.
INFO: There are 1 joysticks attached
INFO: Joystick 0: Microsoft X-Box One pad (Firmware 2015)
INFO: axes: 6
INFO: balls: 0
INFO: hats: 1
INFO: buttons: 11
INFO: instance id: 0
INFO: guid: 030000005e040000dd02000003020000
INFO: Watching joystick 0: (Microsoft X-Box One pad (Firmware 2015))
INFO: Joystick has 6 axes, 1 hats, 0 balls, and 11 buttons
INFO:
====================================================================================
Press the buttons on your controller when indicated
(Your controller may look different than the picture)
If you want to correct a mistake, press backspace or the back button on your device
To skip a button, press SPACE or click/touch the screen
To exit, press ESC
====================================================================================
INFO: Mapping:
030000005e040000dd02000003020000,Microsoft X-Box One pad (Firmware 2015),platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,
Now we just need to export the environment variable SDL_GAMECONTROLLERCONFIG with the mapping and launch the desired application, in my case Steam. To make it more convenient, we will export the variable through the bash profile.
export SDL_GAMECONTROLLERCONFIG="030000005e040000dd02000003020000,Microsoft X-Box One pad (Firmware 2015),platform:Linux,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,"
We exit the shell and re-enter, and now we can enjoy our gamepad on Linux :)
As for the wireless mode, there are many hopes that it will work in the near future.