Skip to content

Instantly share code, notes, and snippets.

@axyiee
Last active January 6, 2023 18:47
Show Gist options
  • Save axyiee/2e04f66a81e8260be18b788b2f60f211 to your computer and use it in GitHub Desktop.
Save axyiee/2e04f66a81e8260be18b788b2f60f211 to your computer and use it in GitHub Desktop.
Controller support on FreeBSD 13

Gamepads on FreeBSD

This tutorial will guide you through the process of setting up game controllers on a FreeBSD system.

Prerequisites

Before you start, you will need to install the devel/sdl2 port with make config and enable HIDAPI and UDEV. Then, run make install to install it system-wide.

You may also need to install the following packages, depending on your specific controller and needs:

  • x11-toolkits/qt5-gamepad for use with QT applications
  • multimedia/webcamd for certain controllers, such as the Xbox controller
  • x11-drivers/xf86-input-joystick x11-drivers/xf86-input-evdev for extended X11 support
  • devel/libgamepad devel/allegro for everything else

Also, you may need to enable some specific drivers according to your gamepad model - I'm going to go through it soon:

  • hgame(4) driver for generic HID game controllers
  • ps4dshock(4) driver for Sony's DualShock 4 controllers
  • x360gp(4) driver for Microsoft's Xbox 360 controllers

Enabling specific modules

To enable a module, you need to add the following to your /boot/loader.conf: <module>_load="YES". For example: hgame_load="YES".

Enabling USB HID support

To enable USB HID support, you will need to add the following lines to your /boot/loader.conf file:

usbhid_load="YES"
hw.usb.usbhid.enable=1

And run this command: sysrc kld_list+=usbhid && kldload usbhid

Enabling webcamd

To enable webcamd, you will need to add the following line to your /etc/rc.conf file:

webcamd_enable="YES"

Modern Sony controllers (DS4, DS5)

If you are using a DualShock or DualSense controller, you may need to follow a few extra steps. First, add the following sections to your /usr/local/etc/devd/sony.conf file:

# DualSense
notify 100 {
        match "system"          "USB";
        match "subsystem"       "INTERFACE";
        match "type"            "ATTACH";
        match "vendor" "0x054c";
        match "product" "0x0ce6";
        action "chgrp games /dev/$cdev; chmod 660 /dev/$cdev";
};

# DualShock 4
notify 100 {
        match "system"          "USB";
        match "subsystem"       "INTERFACE";
        match "type"            "ATTACH";
        match "vendor" "0x054c";
        match "product" "0x05c4";
        action "chgrp games /dev/$cdev; chmod 660 /dev/$cdev";
};

Then, add the following line to your /etc/devfs.rules file:

[system=10]
add path 'input*' mode 0660 group games
add path 'input'  mode 0775 group games

Finally, add the following line to your /etc/rc.conf file:

devfs_system_ruleset="system"

To ensure that you can access the device, make sure you are a member of the games group by running pw groupmod games -m <username>.

Testing Your Configuration

To test your configuration, you can use the wine control joy.cpl command or try running a QT application that uses gamepad input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment