How do I use a USB game pad in FreeBSD?

I have a Logitech Dual Action USB game pad plugged into my computer. I dual boot Funtoo Linux 1.2 and FreeBSD 12-STABLE. The game pad works fine under Linux with no additional configuration. Under FreeBSD, however, I'm having problems. I run Plasma 5. The kcm module for input/joystick doesn't load in system settings. No program which uses game pads recognizes that a game pad is available. However, I have webcamd configured and running at startup through /etc/rc.conf, and it created /dev/input/js0 with ownership webcamd:webcamd. So the device node exists. My user is in the webcamd group. And I installed and ran jstest-gtk which correctly identifies the game pad as Logitech Dual Action and responds correctly to all buttons presses and movements of the game pad and joysticks. My guess is that maybe the X server is failing to recognize the device or load the xf86-input-joystick and/or xf86-input-evdev drivers because, when I checked /var/log/Xorg.0.log, I didn't see any mention of joystick or evdev, although it did mention the mouse and keyboard drivers being loaded.

So does anyone have any idea what's going on and how to fix this?
 
xf86-input-joystick

That driver is supposed to map gamepad/joystick to keyboard and pointer controls. That might be enough for a simple gamepad without analog sticks, but nothing more than that — there are only 2 mouse axes.

No program which uses game pads recognizes that a game pad is available. However, I have webcamd configured and running at startup through /etc/rc.conf, and it created /dev/input/js0 with ownership webcamd:webcamd. So the device node exists.

Note that /dev/input/js0 means the old Linux joystick API, evdev device nodes are named differently. Other than that, you should recompile sdl2 (the most popular input library by far) with evdev support or harass convince either port maintainer or upstream devs into patching it accordingly.
 
SDL2's port doesn't have an option for compiling with evdev support, but it does have options for HID and UDEV. I enabled HID support and recompiled it. I then tested with PCSXR. It did recognize one USB controller that I had just plugged in immediately. I then disabled webcamd and rebooted, and after the reboot PCSXR also recognized as an HID device the other USB controller which had previously been claimed by webcamd.

I'll also try compiling SDL2 with UDEV support enabled and see how that fares. I don't know how many programs still use /dev/input/js0, but if any do they won't be able to work without webcamd creating the device node. I wonder if webcamd can be enabled without blocking the USB controller from also being available as an HID device.

I also learned of this Xorg-server / evdev related bug which may be responsible for Plasma 5 not recognizing the device and perhaps also some software: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=222609
 
https://svnweb.freebsd.org/ports?view=revision&revision=487369
Add devd rule for a Logitech gamepad.

Interesting… The individual gamepad drivers (media_tree/drivers/input/joystick/ directory) are disabled by default and there is no option to build them in the webcamd port, so it's really surprising to see that webcamd actually picks Logitech controller. Some generic HID driver maybe?

Judging by this PR, there is now some evdev controller support, albeit it's thoroughly half-assed. (SDL 1? Really? Of all f*ing things…)
 
Yeah. I've been trying to get an idea of what the underlying issues are. This open bug might also be relevant: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=196678 But as you mentioned earlier, part of the problem may be the default options in some of the ports (like SDL2). It's puzzling when things work without any effort under Linux and then work only with lots of tinkering, if at all, under FreeBSD, and then I have to figure out if it's a configuration issue or a lack of hardware support.
 

As I said earlier, X11 doesn't have any joystick/gamepad concept. As far as X11 is concerned you are a happy owner of a little keyboard & mouse device.

It's puzzling when things work without any effort under Linux and then work only with lots of tinkering, if at all, under FreeBSD

Well, Linux has 2 native joystick input APIs and FreeBSD has none*. It is as simple as that. (No, expecting every application to directly parse HID descriptors doesn't cut it, especially since not every gamepad is a HID device in the first place.)

* emphasis on native; we can compile Linux input drivers with webcamd and we can recompile (most) applications to actually use those evdev devices nodes, but upstream developers would need to be aware of that possibility to actually consider enabling evdev on FreeBSD by default.
 
Apparently the sdl20 port's UDEV option is in fact the option to enable evdev support. Despite enabling that option and recompiling sdl20, SDL2 applications don't recognize the game pad under FreeBSD. I even tried setting the environment variable SDL_JOYSTICK_DEVICE=/dev/input/event5 (and to /dev/input/js0 just to try) to try to force its use. So something isn't working as intended.

Oh, and it turns out that with FreeBSD 12, evdev support is enabled by default. I'd read that it was disabled (the discussion I read was prior to 12-RELEASE) by default but could be enabled. But when I went to modify the GENERIC kernel config and recompile my kernel, I found that evdev support was already enabled in the GENERIC configuration. I am running 12-STABLE. I checked, and it is not enabled by default in 12-RELEASE. So presumably it will be enabled by default with 12.1-RELEASE.
 
Apparently the sdl20 port's UDEV option is in fact the option to enable evdev support.

I don't think it does that.

Oh, and it turns out that with FreeBSD 12, evdev support is enabled by default.

Kernel evdev support is mostly concerned with exposing FreeBSD mouse and keyboard drivers through evdev. There is also a uinput implementation. Webcamd doesn't care about either of those things — it creates device nodes through CUSE and then handles ioctls in userspace.
 
Back
Top