The release of FreeBSD 13.0 came loaded with news regarding the HID system, and several well-known gamepad drivers such as PS4 and Xbox were added.
In my case, I have several gamepads:
XBox One | 8BitDo Pro2 |
---|---|
Logitech RumblePad2 | iBuffalo |
---|---|
Some gamepads will work with the specific driver and others with the generic hgame , in my case all will work with hgame except for the Xbox One gamepad, which will use xb360gp and webcamd .
hgame -> Generic HID game controller (joystick/gamepad) driver
xb360gp -> XBox 360 gamepad driver
webcamd -> Daemon which provide access to USB webcam, USB DVB, USB radio, USB input, USB tablet and more devices
NOTE: All configuration has been done on a FreeBSD 13.1 system with the GENERIC kernel, both the XBoxOne and 8BitDo gamepads are wireless, the former via a USB adapter and the latter via Bluetooth, but I have not been able to get either of them to work wirelessly. Another detail is that the XBoxOne, 8bitDo, and Logitech controllers support vibration, but I have not been able to get any of them to work.
The setup instructions are as follows:
- Enable USB-HID and evdev rules
- Testing tools
- XBox One
- 8bitDo pro2
- Logitech RumblePad2
- iBUFFALO
- NES/SNES/GAMEBOY/GB-ADV
- NeoGeo
- N64
- PSX
- GAMECUBE/WII
- PSP
Enable USB-HID and evdev rules:
Enable USB-HID support in the FreeBSD loader:
hw.usb.usbhid.enable="1"
Load the corresponding module:
kldload usbhid
sysrc kld_list+=usbhid
Define some evdev rules so that our user can access the device:
[system=10]
add path 'usb/*' mode 0660 group operator
[localrules=10]
add path 'input' mode 0775 group wheel
add path 'input/*' mode 0660 group wheel
service devfs restart
NOTE: These rules are only necessary for 8BitDo, Logitech, and ibuffalo controllers, let’s say generic controllers.
Restart to apply the loader changes.
shutdown -r now
Testing tools:
Install some tools that will be useful to check if the gamepads are working correctly:
jstest-gtk will provide us with the names of the buttons and axes used in a simple way, antimicro also but in a more confusing way, but antimicro has a peculiarity and that is that it is capable of mapping controller buttons as if they were keyboard keys, so we can play with the controller even in games that do not support it.
XBox One:
This controller is my favorite without a doubt, it is comfortable, the materials are of very good quality and versatile since it works on any PC operating system and on the XBox itself, it is detected by FreeBSD in the following way:
dmesg | usbconfig |
---|---|
ugen0.9: |
ugen0.9: |
To make it work, we just need to load the cuse module:
sysrc kld_list+=cuse
And start webcamd, but first we will start it manually to make sure that nothing fails:
webcamd 12588 - - Attached to ugen0.9[0]
webcamd 12588 - - Creating /dev/input/event13
webcamd 12588 - - Creating /dev/input/js0
We check with jstest-gtk and antimicro that button presses are detected:
Now that we are sure it works correctly, we start it as a service. Webcamd is automatically called by evdev, passing it the port where the gamepad is connected, so it works dynamically wherever we connect the gamepad:
service webcamd start
8bitDo pro2:
This manufacturer is well known among retro-gamers and also makes a very good gamepad, but its ergonomics are not as good as the XboxOne gamepad. FreeBSD detects it as follows:
dmesg | usbconfig |
---|---|
ugen0.2: <8BitDo 8BitDo Pro 2> at usbus0 | ugen0.2: <8BitDo 8BitDo Pro 2> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (480mA) |
For this gamepad, it will be necessary to load the generic module:
sysrc kld_list+=hgame
NOTE: The only drawback of using the generic driver is that identifying the buttons will be a bit more complicated, as we can only use antimicro.
We check that the buttons are detected correctly:
Logitech RumblePad2:
As for the Logitech, it is a very old gamepad, but it still works like the first day. FreeBSD detects it as follows:
dmesg | usbconfig |
---|---|
ugen0.2: <Logitech Logitech RumblePad 2 USB> at usbus0 | ugen0.2: <Logitech Logitech RumblePad 2 USB> at usbus0, cfg=0 md=HOST spd=LOW (1.5Mbps) pwr=ON (500mA) |
This controller will also use the generic module. If we haven’t done it before, we load the module:
sysrc kld_list+=hgame
NOTE: The only drawback of using the generic driver is that identifying the buttons will be a bit more complicated since we can only use antimicro.
We check that the buttons are detected correctly:
iBUFFALO:
This controller is somewhat special as it simulates a SuperNintendo controller, great for playing old 2D games.
dmesg | usbconfig |
---|---|
ugen0.2: <vendor 0x0583 USB,2-axis 8-button gamepad> at usbus0 | ugen0.2: <vendor 0x0583 USB,2-axis 8-button gamepad> at usbus0, cfg=0 md=HOST spd=LOW (1.5Mbps) pwr=ON (100mA) |
This controller will also use the generic module. If we haven’t done it before, we load the module:
sysrc kld_list+=hgame
NOTE: The only drawback of using the generic driver is that identifying the buttons will be a bit more complicated since we can only use antimicro.
We check that the buttons are detected correctly:
NES/SNES/GAMEBOY/GAMEBOY-ADV:
We install Mednafen:
We load the desired ROM:
We can see that it has detected the four controllers:
Initializing joysticks...
ID: 0xdadcfa337304f38c0004000c00010000 - Logitech RumblePad 2 USB Joystick
ID: 0x0ea06f86c7f338d00006000b00010000 - Xbox One Controller
ID: 0x4624938846ca11020002000800000000 - vendor 0x0583 USB,2-axis 8-button gamepad Joystick
ID: 0xd4b85105fa8dffeb0004000f00010000 - 8BitDo Pro 2 Gamepad
To map the buttons, we just have to press:
ALT+SHIFT+1
Here we can see how I play without problems the magnificent Super Mario Land 2 with my iBUFFALO:
The basic functionalities of Mednafen are:
0-9 -> Select save slot
F5 -> Save
F7 -> Load
NeoGeo:
To play NeoGeo we will have to download the BIOS and the version of the game according to this BIOS, if we don’t do this MAME will not load the game, in these links you can find everything you need:
https://archive.org/download/MAME216RomsOnlyMerged
https://archive.org/download/MAME216RomsOnlyMerged/mslug.zip
https://archive.org/download/MAME216RomsOnlyMerged/neogeo.zip
We install MAME and a graphical frontend:
We start the frontend and configure the controller once inside the game:
This time I used the 8BitDo:
N64
We install Mupen:
The easiest way to configure Mupen is through mupen64plus-qt:
We load the desired ROM:
Mupen by default detects the Logitech controller perfectly and the iBuffalo partially, while the Xbox and 8BitDo are completely ignored:
Input: 4 SDL joysticks were found.
Input: N64 Controller #1: Using auto-config with SDL joystick 0 ('Logitech RumblePad 2 USB Joystick')
Input Error: No auto-config found for joystick named 'Xbox One Controller' in InputAutoConfig.ini
Input: N64 Controller #2: Using auto-config with SDL joystick 2 ('vendor 0x0583 USB,2-axis 8-button gamepad Joystick')
Input Error: No auto-config found for joystick named '8BitDo Pro 2 Gamepad' in InputAutoConfig.ini
Input: 2 controller(s) found, 2 plugged in and usable in the emulator
To make these controllers work, we will have to find out the button mapping and generate the configuration files for each of them, the method is a bit trial and error until we get it right:
[Xbox One Controller]
plugged = True
plugin = 2
mouse = False
AnalogDeadzone = 4096,4096
AnalogPeak = 32768,32768
DPad R = axis(6+)
DPad L = axis(6-)
DPad D = axis(7+)
DPad U = axis(7-)
Start = button(7)
Z Trig = axis(2+)
B Button = button(2)
A Button = button(0)
C Button R = axis(3+)
C Button L = axis(3-)
C Button D = axis(4+)
C Button U = axis(4-)
R Trig = button(5)
L Trig = button(5)
Mempak switch =
Rumblepak switch =
X Axis = axis(0-,0+)
Y Axis = axis(1-,1+)
[8BitDo Pro 2 Gamepad]
plugged = True
plugin = 2
mouse = False
AnalogDeadzone = 4096,4096
AnalogPeak = 32768,32768
DPad R = axis(4+)
DPad L = axis(4-)
DPad D = axis(5+)
DPad U = axis(5-)
Start = button(11)
Z Trig = button(8)
B Button = button(4)
A Button = button(1)
C Button R = axis(2+)
C Button L = axis(2-)
C Button D = axis(3+)
C Button U = axis(3-)
R Trig = button(7)
L Trig = button(6)
Mempak switch =
Rumblepak switch =
X Axis = axis(0-,0+)
Y Axis = axis(1-,1+)
Now if we start Mupen again, all 4 controllers are available:
Input: 4 SDL joysticks were found.
Input: N64 Controller #1: Using auto-config with SDL joystick 0 ('Logitech RumblePad 2 USB Joystick')
Input: N64 Controller #2: Using auto-config with SDL joystick 1 ('Xbox One Controller')
Input: N64 Controller #3: Using auto-config with SDL joystick 2 ('vendor 0x0583 USB,2-axis 8-button gamepad Joystick')
Input: N64 Controller #4: Using auto-config with SDL joystick 3 ('8BitDo Pro 2 Gamepad')
Input: 4 controller(s) found, 4 plugged in and usable in the emulator
NOTE: Mupen gets confused when there are many controllers connected, so I have left only the Xbox and 8BitDo ones.
You can see me playing MarioKart64, one of the best games in history, with the Xbox controller:
NOTE: I recorded it in window mode because for some reason neither OBS nor ffmpeg allow recording Mupen64 in fullscreen.
PSX
We install the PSX emulator:
The controllers will be recognized automatically and we can configure the buttons from the emulator itself. In this case, I am using the 8BitDo controller:
GAMECUBE/WII
We install the Dolphin emulator:
The controllers will be recognized automatically and we can configure the buttons from the emulator itself. In this case, I am using the Xbox controller:
NOTE: Recording the video penalizes quite a bit, the emulator runs smoothly but the recorded video seems to work a bit worse. Also, recording pulseaudio audio is complicated in FreeBSD. Of course, the emulator did output audio during the game without any problems.
In Wii, emulation works perfectly, but many games require movements of the original controllers that cannot be comfortably emulated with a traditional gamepad.
PSP
We install the emulator:
In this case, I am using the Xbox controller because the 8BitDo digital pad is not recognized for some reason, the Logitech is not detected, and the iBuffalo is not the most suitable for playing PSP: