Installing
Documentation for xmorpheo v0.2.0
Requirements
- Linux 6.11 or newer with
CONFIG_HID_BPF, and the BPF filesystem mounted at/sys/fs/bpf. systemd mounts it at boot. - For building: Rust, clang, bpftool, and the libelf and zlib development
files. On Debian:
apt install clang llvm bpftool libelf-dev zlib1g-dev. The build reads the BTF of the running kernel from/sys/kernel/btf/vmlinux.
Install
Build as your user, then install as root:
make
sudo make install
make builds the binary and generates the other files to install, like
the udev rule, from their templates in dist/ into target/dist.
make generate does only the latter. It refuses to run as root, because that would leave files
owned by root in the source tree and in the home of root. sudo make install only copies, and asks to run make first if the build is
missing. Package
builds that run as root set ALLOW_ROOT_BUILD=1.
This installs:
| File | Purpose |
|---|---|
/usr/local/bin/xmorpheo | the tool |
/etc/udev/rules.d/60-xmorpheo.rules | attaches configured devices when they appear |
/usr/local/share/xmorpheo/examples/ | example configurations |
/usr/local/lib/xmorpheo/conf.d/ | empty, for configuration that comes with an installation |
/etc/xmorpheo/conf.d/ | empty, for your configuration |
No configuration is active after installing. PREFIX selects another
location. The build puts the installation paths into the generated files,
like the udev rule, so give the same PREFIX to make, make install,
and make uninstall:
make PREFIX=/opt/xmorpheo
sudo make PREFIX=/opt/xmorpheo install
make install stops if the build used another PREFIX, instead of
generating files as root. The udev rule goes to
/etc/udev/rules.d, because udev reads no rules below /usr/local or
/opt. Packages install nothing below /etc, see
PACKAGING.md.
The tool can also be built in a container, for example a distrobox, and
installed on the host: make in the container, sudo make install on the
host. The binary needs libelf.so.1, libz.so.1, and libzstd.so.1 on the
host.
Configure
The configuration is made of *.toml files in /etc/xmorpheo/conf.d
and the other drop-in directories, see CONFIG.md. To use an
example as it is, link it, so it follows updates:
sudo ln -s /usr/local/share/xmorpheo/examples/vkb-gladiator-evo.toml /etc/xmorpheo/conf.d/50-vkb.toml
To change it, copy it instead, or start from a template of your devices:
sudo cp /usr/local/share/xmorpheo/examples/vkb-gladiator-evo.toml /etc/xmorpheo/conf.d/50-vkb.toml
xmorpheo template 231d:0200 | sudo tee /etc/xmorpheo/conf.d/50-vkb.toml
Check which files are read, and the result, without loading anything:
xmorpheo config
xmorpheo attach --all --dry-run
Then let udev attach the configured devices, which also happens on every replug and reboot:
sudo udevadm control --reload
sudo udevadm trigger --action=bind --subsystem-match=hid
--action=bind, not add: the rule attaches when a driver binds to the
device, because only then the report descriptor has the fixups of the
driver. After changing the configuration, run
sudo xmorpheo attach --all --replace. It keeps the old programs if the
new configuration has an error.
Calibrate a device in its own tool first, for example VKBDevCfg for VKB
sticks, and check with evtest that a released stick rests in the middle
of its range. A curve shapes the response, but it cannot fix an off-center
rest position. See CLI.md.
Uninstall
sudo make uninstall
sudo udevadm control --reload
This detaches all programs and removes every installed file. Drop-in directories that still have configuration files stay, remove them by hand if you no longer need them. The evdev fuzz and flat stay 0 until the device is plugged in again.
Configuration
Documentation for xmorpheo v0.2.0
The configuration is TOML. Devices and axes that are not listed stay untouched. RECIPES.md has short configurations for common problems.
Files
Like systemd, xmorpheo reads *.toml drop-ins from these directories,
from the highest priority to the lowest:
/etc/xmorpheo/conf.d, for your configuration,/run/xmorpheo/conf.d, for configuration until the next reboot,<prefix>/lib/xmorpheo/conf.d, next to the installed tool, for example/usr/local/lib/xmorpheo/conf.d,/usr/lib/xmorpheo/conf.d, for packages.
Distributions that build with another SYSCONFDIR, like /usr/etc, use
that instead of /etc. xmorpheo config shows the directories of the
installed tool.
- A file replaces every file of the same name with a lower priority. So
/etc/xmorpheo/conf.d/50-vkb.tomloverrides a50-vkb.tomlof a package. - An empty file, or a symlink to
/dev/null, masks every file of the same name with a lower priority. - The remaining files are read in the order of their names, like
10-vkb.tomlbefore50-xbox.toml, and merged into one configuration. [constants]andtoleranceonly apply to the file they are in.- If two files have an entry for the same device, by
vendor,product,uniq, anddriver, the entry of the later file replaces the earlier one as a whole, with a warning.
xmorpheo config shows which files are active, overridden, or masked, and
their contents. xmorpheo list shows the file each configured device comes
from. -c reads a single file or a single directory instead.
Example
Expo curves for a pair of VKB Gladiator EVO sticks, from
examples/vkb-gladiator-evo.toml:
[constants]
k_stick = 0.6 # X/Y: slope 0.4 at the center
k_twist = 0.75 # Rz: slope 0.25 at the center
[[device]]
name = "VKB Gladiator EVO L"
vendor = 0x231d
product = 0x0201
[[device.axis]]
usage = "X"
curve = "(1 - k_stick) * x + k_stick * pow(x, 3)"
[[device.axis]]
usage = "Y"
curve = "(1 - k_stick) * x + k_stick * pow(x, 3)"
[[device.axis]]
usage = "Rz"
curve = "(1 - k_twist) * x + k_twist * pow(x, 3)"
The second stick follows with its own [[device]] entry.
Top Level
| Key | Default | Meaning |
|---|---|---|
tolerance | 0.5 | Fitting tolerance in steps of the field, for all axes. |
[constants] | none | Named numbers for all formulas. |
[[device]] | none | One entry per device. |
The tolerance bounds the error of the knot table: every output is within
tolerance + 0.5 steps of the exact formula. The default of half a step
is below what a sensor can resolve: the output already moves in whole
steps. 0 gives the exactly rounded curve and needs more knots,
which only makes sense for fields with few bits: a 16 bit field can need
more than the 1024 knots a curve may have. The error then names the knots
the curve needs, and a tolerance that fits.
Devices
| Key | Default | Meaning |
|---|---|---|
vendor | required | USB or Bluetooth vendor ID, like 0x231d. |
product | required | Product ID, like 0x0200. |
uniq | any | The unique ID of the device (HID_UNIQ, usually the serial number), to tell identical devices apart. |
driver | any | The HID driver that must be bound to the device, like hid-generic. |
name | none | A name for messages. |
evdev | none | "keep" leaves the evdev fuzz and flat as the driver set them. |
[device.fuzz] | 0 | The evdev fuzz by evdev axis, see below. |
[device.flat] | 0 | The evdev flat by evdev axis, see below. |
[[device.axis]] | none | One entry per axis to rewrite. |
xmorpheo list shows vendor, product, unique ID, and driver of the
connected devices. An entry without uniq or driver matches every
device with its vendor and product ID. An entry with driver wins over
one without, otherwise the first entry that matches a device wins.
A driver may replace the report descriptor of a device, so the same pedal
or stick can have another usage under another driver. driver limits an
entry to the driver its usages were written for. Under any other driver,
the entry does not apply.
evdev Fuzz and Flat
When attaching, xmorpheo sets the evdev fuzz and flat of every absolute axis of the device to 0. The kernel default fuzz smooths small movements and costs modern sensors resolution around the center, see CLI.md. The flat is only a deadzone hint for programs that read evdev, the kernel does not apply it. Games, SDL, and Proton apply their own deadzones.
Other values are set per evdev axis, by the names that evtest and
evdev-joystick show, in raw units of the evdev axis:
[device.flat]
ABS_X = 3072
ABS_Y = 3072
[device.fuzz]
ABS_Z = 4
These are evdev axes, not HID usages, because the driver decides which evdev axis a HID field becomes, and with which range. Unknown names and axes that the device does not have give a warning, not an error.
evdev = "keep" leaves fuzz and flat as the driver set them, for drivers
that choose them deliberately, like xpadneo. It cannot be combined with
[device.fuzz] or [device.flat].
Axes
| Key | Default | Meaning |
|---|---|---|
usage | required | The HID usage of the axis, see below. |
curve | required | The formula, see FORMULAS.md. |
kind | by usage | centered or unipolar. |
source.<name> | x = the axis | The axes the formula reads, see below. |
tolerance | top level | Fitting tolerance for this axis. |
Usages by name: X, Y, Z, Rx, Ry, Rz, Slider, Dial,
Wheel, Rudder, Throttle, Accelerator, Brake, Clutch, and
Steering. Any other usage works as page:id in hexadecimal, as xmorpheo descriptor prints it, for example 0001:0030 for X.
A centered axis rests in the middle, like a stick, and the formula sees
x in -1..1. A unipolar axis rests at one end, like a throttle or a
pedal, and the formula sees x in 0..1. Slider, Dial, Throttle,
Accelerator, Brake, and Clutch are unipolar by default, everything
else is centered. Set kind where a device uses a usage differently, for
example kind = "unipolar" for a throttle on Z.
Sources
By default, a formula reads its own axis as x. With source.<name>, it
reads other axes of the same report instead, as variables of the formula:
[[device.axis]]
usage = "Z" # the axis to write
kind = "centered"
source.l = { usage = "Z", kind = "unipolar" } # left trigger
source.r = { usage = "Rz", kind = "unipolar" } # right trigger
curve = "r - l"
[[device.axis]]
usage = "Rz"
kind = "unipolar"
curve = "0" # pinned at rest
- A source is a usage, like
source.y = "Y", which takes the kind of the usage, or a table{ usage = "...", kind = "..." }. The kind of a source never comes from the[[device.axis]]entry of the same usage: above, Z is a centered target, but a unipolar source. - With a source table, the formula only sees its variables, and
xonly if it is listed. Variable names are letters, digits, and underscores, and must not be a function or a constant. - Every variable is normalized by the kind of its source, and the result by the kind of the target, so formulas never see raw values.
- The formula must be a sum of parts that each read one variable, like
r - lorpow(x, 2) + y / 2. Formulas likex * yare rejected. - All axes read the values the device sent. Writing an axis does not change
what other formulas read from it, so above, Rz is pinned at rest while Z
still reads the right trigger. In the same way, two axes can be swapped
with
source.x = "Y"on X andsource.x = "X"on Y. - A source must be in the same report as its target, and an axis reads at most 4 sources.
- The target keeps the range of its field, also for a combined axis, see DESIGN.md.
Warning
Do not invert or swap an axis with force feedback, like the steering of a wheel or an axis of a force feedback joystick, other than as a test with the force feedback of the game turned down or off. The game computes its centering forces from the rewritten position, and the device drives itself to the end stop, see FORMULAS.md.
Without a source table, the configurations of earlier versions keep their meaning.
If an axis appears in several fields of the report descriptor, all of them are rewritten. An axis that the descriptor does not have is an error. Fields of up to 16 bits are supported, and up to 16 axis fields per device.
Errors
Unknown keys, unknown usages, axes listed twice, empty source tables, invalid formulas or variable names, and tolerances that are negative or not finite are reported when the configuration is read, with the number of the device entry and the axis. Variables that the formula does not use are a warning.
Formulas
Documentation for xmorpheo v0.2.0
A curve is a formula in the normalized input x. For centered axes, x
runs from -1 to 1 with the rest position at 0. For unipolar axes,
it runs from 0 to 1. The result uses the same range and is clamped to
it, so 2 * x saturates at half deflection.
The syntax follows the input mixing expressions of Euro Truck Simulator 2
(controls.sii), restricted to the part without state.
Syntax
- Numbers like
0.6or3, the inputx, and named constants from the[constants]table of the configuration. - With sources (see CONFIG.md), the variables named
there instead of
x. +,-,*,/with the usual precedence, unary minus, and parentheses. There is no power operator, usepow.
| Function | Result |
|---|---|
abs(v) | absolute value |
sign(v) | -1, 0, or 1; 0 for 0 |
pow(v, e) | v to the power of e |
min(a, b), max(a, b) | the smaller or larger value |
clamp(v, lo, hi) | v limited to lo..hi |
sel(c, a, b) | a if c is not 0, else b |
normalize(v, dz) | maps dz..1 to 0..1, and everything below dz to 0 |
deadzone(v, dz) | like normalize, for both directions of a centered axis |
Functions can be nested freely.
Clamping
The result of every formula is clamped to the range of its axis: -1..1
for centered axes, 0..1 for unipolar axes. So a formula needs no outer
clamp, and scaling reaches full output early: x / 0.95 is full from 95 %
of the travel on, and there is no separate function for a deadzone at the
end stops, see RECIPES.md.
Inner parts are not clamped. In
clamp((abs(x) - dz) / (1 - dz - e), 0, 1) * sign(x), the clamp keeps
the deadzone at 0, which the outer range would not do for a centered axis.
The terms of a formula in several variables are not clamped one by one
either, only their sum, see Several Variables.
The meaning of normalize and deadzone follows how ETS2 uses them. It is
inferred, not documented by ETS2.
pow of a negative number with a fractional exponent is not defined. Use
pow(abs(x), e) * sign(x) for centered axes. The tool reports the input
where a formula is not finite.
Examples
| Formula | Effect |
|---|---|
x | unchanged |
-x | inverted; not for axes with force feedback, see below |
deadzone(x, 0.05) | deadzone of 5 % around the center, full deflection stays reachable |
pow(abs(x), 1.7) * sign(x) | power curve, flat at the center |
pow(normalize(abs(x), 0.05), 1.7) * sign(x) | the ETS2 steering curve, deadzone and power |
(1 - k) * x + k * pow(x, 3) | expo curve, see below |
pow(x, 2) | for unipolar axes, finer control at the start |
x / 0.95 | full output from 95 % of the travel on, because the result is clamped |
(x - 0.05) / 0.85 | unipolar, nothing below 5 %, full from 90 % |
Warning
Do not invert an axis with force feedback, like the steering of a wheel or an axis of a force feedback joystick, other than as a test with the force feedback of the game turned down or off. The game sees the inverted position and computes its centering forces in the wrong direction, so the device drives itself to the end stop, which can be unpleasant with a strong wheel and can pinch fingers on a joystick. Spring and damper effects that run in the firmware of the device use the real position and stay correct. For lasting use, a game must invert the forces itself, like Forza Horizon 5 can. See also IDEAS.md.
Expo Curves
(1 - k) * x + k * pow(x, 3) with k between 0 and 1 keeps a linear
part at the center, unlike a power curve, so small corrections still have
an effect:
k | slope at the center | slope at full deflection | output at half deflection |
|---|---|---|---|
0 | 1 | 1 | 50 % |
0.5 | 0.5 | 2 | 31 % |
0.6 | 0.4 | 2.2 | 28 % |
0.75 | 0.25 | 2.5 | 22 % |
1 | 0 | 3 | 13 % |
The slope at the center is 1 - k, at full deflection 1 + 2k. A larger
k gives finer control around the center, at the cost of a faster
response near the end stops.
Several Variables
A formula with sources is split into a sum of parts that each depend on one
variable. Each part becomes its own curve, and the program adds them up and
clamps the sum once. So 0.5 + (r - l) / 2 works, and so does
pow(x, 2) - abs(y). Parts that combine variables, like x * y,
pow(x - y, 2), or max(x, y), cannot be split and are rejected. The
tolerance of the axis is divided among the parts, so their sum stays
within it.
Combined triggers on one centered axis, with the two triggers as unipolar
sources l and r:
| Formula | Effect |
|---|---|
r - l | right trigger turns one way, left trigger the other, both or none rest in the middle |
pow(r, 2) - pow(l, 2) | the same, with finer control at the start of the travel |
Limits
The BPF program in the kernel evaluates curves as tables of knots in one variable, with integer math only. That sets these limits.
Only sums of parts in one variable each. A product, quotient, or other
function of two variables would need a table in two dimensions, so these
are rejected when the configuration is read, with an explanation: x * y,
x / y, pow(x - y, 2), abs(x - y), and min, max, clamp, or sel
over more than one variable. Sums and differences of parts in one variable
each work, and so do constant factors, like 2 * (x - y) or
(r - l) / 2.
No state. A formula sees the current values only: no time, no smoothing or other filters, no hysteresis, and no toggles.
The range of the field. The result has the range of the field of the axis, because xmorpheo never changes the report descriptor, see DESIGN.md. A combined axis shares that range among its sources.
Sources from the same report. All variables of an axis must be fields of the same input report as the axis, or planning fails.
Capacities, checked when planning, with an error that names the limit:
| What | Limit |
|---|---|
| Field size | 16 bits |
| Fields read or written per device | 16 |
| Axes written per device | 16 |
| Variables per axis | 4 |
| Terms per device | 32 |
| Curves per device | 64 |
| Knots per curve | 1024 |
| Knots per device | 8192 |
| Value of a single term, before the sum is clamped | -4..4 |
A tolerance of 0 on a 16 bit field can need more than 1024 knots; a small tolerance like 0.1 needs about 500. The default of 0.5 steps is below what a sensor can resolve, the output moves in whole steps anyway, so a tolerance of 0 only makes sense for fields with few bits. A curve that needs too many knots is an error that names the formula, the bits, the tolerance, the knots it needs, and the smallest of a few common tolerances that fits.
Names. Variables and constants are letters, digits, and underscores, not starting with a digit. A variable must not have the name of a function or a constant.
Undefined values. pow of a negative number with a fractional
exponent, and a division by zero, are errors that name the input where
they happen.
Checking a Formula
xmorpheo curve "(1 - k) * x + k * pow(x, 3)" -c k=0.6 --bits 12
prints the canonical formula, the knots the BPF program will use, and the
output for sample inputs next to the exact value. With --format gnuplot,
it prints a plot of the curve and its error, and with --format csv, every
value, see CLI.md. Formulas that only differ in spacing or
constant names have the same canonical text and share one curve.
Recipes
Documentation for xmorpheo v0.2.0
Short configurations for common problems. Each one is a complete drop-in
for /etc/xmorpheo/conf.d, see CONFIG.md. Replace vendor,
product, and the usages with those of your device: xmorpheo template
prints them. The tests of xmorpheo parse every recipe here.
Formulas see normalized values: -1..1 for centered axes like sticks and
wheels, 0..1 for unipolar axes like pedals, triggers, and throttles, see
FORMULAS.md.
Invert an Axis
[[device]]
vendor = 0x231d
product = 0x0200
[[device.axis]]
usage = "Y"
curve = "-x"
For a unipolar axis, like a throttle, the inverse is 1 - x, with
kind = "unipolar" if the usage is not unipolar by default.
Warning
Do not invert an axis with force feedback, like the steering of a wheel or an axis of a force feedback joystick, other than as a test with the force feedback of the game turned down or off. The game sees the inverted position and computes its centering forces in the wrong direction, so the device drives itself to the end stop, which can be unpleasant with a strong wheel and can pinch fingers on a joystick. Spring and damper effects that run in the firmware of the device use the real position and stay correct. For lasting use, a game must invert the forces itself, like Forza Horizon 5 can. See also IDEAS.md.
Swap Two Axes
Each axis reads the other one. All formulas read the values the device sent, so the order does not matter. Here brake (Rz) and clutch (Y) of a wheel:
[[device]]
vendor = 0x044f
product = 0xb66e
[[device.axis]]
usage = "Rz"
kind = "unipolar"
source.x = { usage = "Y", kind = "unipolar" }
curve = "x"
[[device.axis]]
usage = "Y"
kind = "unipolar"
source.x = { usage = "Rz", kind = "unipolar" }
curve = "x"
See examples/t300rs-swap-pedals.toml.
Combine Two Pedals or Triggers on One Axis
Older games want gas and brake on one axis, resting in the middle. The target becomes centered, both sources stay unipolar:
[[device]]
vendor = 0x044f
product = 0xb66e
[[device.axis]]
usage = "Z" # gas, becomes the combined axis
kind = "centered"
source.gas = { usage = "Z", kind = "unipolar" }
source.brake = { usage = "Rz", kind = "unipolar" }
curve = "gas - brake"
[[device.axis]]
usage = "Rz" # brake, pinned at rest
kind = "unipolar"
curve = "0"
Pinning the brake does not change what the combined axis reads. See examples/xbox-combined-triggers.toml for the triggers of a gamepad.
Left-Handed Gamepad (Axes)
The sticks trade places, and so do the triggers. Here for an Xbox Wireless Controller with xpadneo, which names the right stick Rx/Ry and the triggers Z (left) and Rz (right):
[[device]]
vendor = 0x045e
product = 0x0b13
evdev = "keep" # keep the fuzz and flat xpadneo chooses
[[device.axis]]
usage = "X"
source.x = "Rx"
curve = "x"
[[device.axis]]
usage = "Y"
source.x = "Ry"
curve = "x"
[[device.axis]]
usage = "Rx"
source.x = "X"
curve = "x"
[[device.axis]]
usage = "Ry"
source.x = "Y"
curve = "x"
[[device.axis]]
usage = "Z"
kind = "unipolar"
source.x = { usage = "Rz", kind = "unipolar" }
curve = "x"
[[device.axis]]
usage = "Rz"
kind = "unipolar"
source.x = { usage = "Z", kind = "unipolar" }
curve = "x"
A curve for the sticks goes in place of x, like in
examples/xbox-wireless-controller.toml.
xmorpheo does not rewrite buttons yet, so the bumpers, the stick buttons,
and the other buttons stay where they are, see IDEAS.md.
Pin an Axis at Rest
A constant formula holds an axis still, for example a twist that should not yaw:
[[device]]
vendor = 0x231d
product = 0x0200
[[device.axis]]
usage = "Rz"
curve = "0"
For a unipolar axis, 0 is the released end.
Add a Deadzone
Around the center of a stick, and at the start of a pedal:
[[device]]
vendor = 0x045e
product = 0x0b13
[[device.axis]]
usage = "X"
curve = "deadzone(x, 0.05)"
[[device.axis]]
usage = "Z"
kind = "unipolar"
curve = "normalize(x, 0.05)"
Full deflection stays reachable. Many games apply their own deadzone, so add one only where the device needs it.
Reach Full Deflection Early
Sticks and pedals that do not quite reach their end stop, or that should
reach full output before it. The result of every formula is clamped to the
range of the axis, so scaling is enough: x / 0.95 gives full output from
95 % of the travel on, in both directions of a centered axis. With a
deadzone at the center or at the start too, map the range in between:
[constants]
dz = 0.05 # deadzone at the center or start
e = 0.05 # travel left before the end stop
[[device]]
vendor = 0x044f
product = 0xb66e
[[device.axis]]
usage = "X" # centered: 5 % deadzone, full from 95 %
curve = "clamp((abs(x) - dz) / (1 - dz - e), 0, 1) * sign(x)"
[[device.axis]]
usage = "Z" # unipolar: nothing below 5 %, full from 90 %
kind = "unipolar"
curve = "(x - dz) / (0.9 - dz)"
For the unipolar pedal, the clamp to 0..1 of the result already keeps
the start at 0. For the centered stick, the inner clamp keeps the center
at 0, see FORMULAS.md. The constants keep the
formulas readable. To combine it with another curve, put the expression in
place of x of that curve, for example pow(clamp((x - dz) / (0.9 - dz), 0, 1), 1.5) for a progressive pedal, where the clamp keeps pow away from
negative values.
Finer Control Around the Center
An expo curve keeps a reduced slope at the center and reaches full
deflection at the edges. A larger k gives finer control around the
center:
[constants]
k = 0.6
[[device]]
vendor = 0x231d
product = 0x0200
[[device.axis]]
usage = "X"
curve = "(1 - k) * x + k * pow(x, 3)"
[[device.axis]]
usage = "Y"
curve = "(1 - k) * x + k * pow(x, 3)"
See FORMULAS.md for the effect of k.
Progressive Brake
Finer control at the start of the travel of a pedal:
[[device]]
vendor = 0x044f
product = 0xb66e
[[device.axis]]
usage = "Rz"
kind = "unipolar"
curve = "pow(x, 1.5)"
Command Line
Documentation for xmorpheo v0.2.0
Devices are selected by their sysfs name like 0003:231D:0200.000A, by
their hid_id like 10, or by VENDOR:PRODUCT like 231d:0200.
xmorpheo list shows all three. Commands that load or remove programs
need root.
| Command | Root | Purpose |
|---|---|---|
xmorpheo list [-c PATH] | no | HID devices, whether a program is attached, their driver, and the file that configures them |
xmorpheo config [-c PATH] | no | the configuration files, which are active, overridden, or masked, and their contents |
xmorpheo template [DEVICE...] | no | a configuration template with all axes commented out |
xmorpheo descriptor PATH [--all] | no | the input fields of a report descriptor |
xmorpheo curve FORMULA [options] | no | the knots and sample values of a curve, as text, CSV, or a gnuplot script |
xmorpheo attach [-c PATH] DEVICE... | --all [--dry-run] [--replace] [-v] | yes | attach the configured curves |
xmorpheo detach DEVICE... | --all | yes | detach them again |
-c reads a single configuration file or directory instead of the drop-in
directories, see CONFIG.md.
list
The driver column shows the HID driver bound to the device, like
hid-generic, or - while none is bound. Without root, the attached
column shows ?, because /sys/fs/bpf is only readable by root.
config
Shows the drop-in directories, which files are active, overridden by a file
of the same name with a higher priority, or masked, the warnings, and then
the contents of the active files in the order they are read, like
systemd-analyze cat-config.
template
Prints a template for the named devices, or for all connected devices with
axes. Each axis has a comment with its bit size, position, logical range,
and default kind. Uncomment the axes to rewrite and set their curves, and
driver if the usages depend on the driver, see
CONFIG.md.
xmorpheo template 231d:0200 | sudo tee /etc/xmorpheo/conf.d/50-vkb.toml
descriptor
xmorpheo descriptor /sys/bus/hid/devices/0003:231D:0200.000A/report_descriptor
lists report ID, usage, bit size, bit offset, and logical range of each
input field. One bit fields like buttons only show with --all.
curve
xmorpheo curve "(1 - k) * x + k * pow(x, 3)" -c k=0.6 --bits 12
| Option | Default | Meaning |
|---|---|---|
--bits N | 12 | an unsigned field with N bits |
--range MIN..MAX | the logical range instead of --bits | |
--kind centered|unipolar | centered | how the axis rests |
--tolerance T | 0.5 | the fitting tolerance in steps |
-c NAME=VALUE | a constant, may be repeated | |
--format text|csv|gnuplot | text | what to print, see below |
--knots | with csv, also the knots | |
-o FILE | write to FILE instead of standard output | |
--terminal png|svg | with gnuplot, render an image instead of showing the plot | |
--output-image FILE | the image --terminal renders |
text prints the canonical formula, the knots, and the output at nine
sample inputs next to the exact value.
csv prints every raw input of the field: raw_in, the normalized input
x, the exact output of the formula as a raw value, the lut output of
the integer math that the BPF program computes, and error_lsb, their
difference in steps. With --knots, an empty line and the knots follow,
as knot_in,knot_out,slope_q24.
gnuplot prints a script with the data inline. It plots the exact curve,
the output of the integer math, the knots, the identity as a reference, and
the error in steps on the right axis. The title names the formula, the
kind, the bit width, the tolerance, and the number of knots. Fields with
more than 2048 values are thinned out to 2048 points; the error then shows
the smallest and largest error of each group of values, so no error goes
missing.
xmorpheo curve "(1 - k) * x + k * pow(x, 3)" -c k=0.6 --format gnuplot | gnuplot -p
xmorpheo curve "pow(x, 1.5)" --kind unipolar --bits 16 --format gnuplot \
--terminal png --output-image brake.png | gnuplot
curve takes formulas in x only, because it fits one curve. Formulas
with more variables, like gas - brake, go into a configuration, and
attach --dry-run shows their terms, see FORMULAS.md.
attach
Reads the configuration, finds the axes in the report descriptor of each
device, fits the curves, loads one instance of the BPF program per device,
and pins it to /sys/fs/bpf/xmorpheo/<hid_id>. Then it sets the evdev fuzz
and flat of all axes of the device to 0, or to the values of
[device.fuzz] and [device.flat]. The
program stays attached after the tool exits, until detach, unplugging,
or reboot. After installing, the udev rule does this on its own whenever a
configured device appears.
--allattaches to every connected device that the configuration names.--dry-runprints the field table, the curves, and the knot counts without loading anything, and needs no root.--replacereplaces a program that is already attached, for example after changing the configuration. Without it, such a device is an error.-v,--verboseprints the field table of each device, and the libbpf log, including the verifier log.
Without --verbose, attach prints one line per device:
VKB Gladiator EVO L (hid_id 9): attached, 3 fields, 104 knots, evdev: /dev/input/event11: set fuzz and flat of 8 of 8 axes
The evdev part says on how many axes attach changed the fuzz and flat,
or that they were already as configured, like after an earlier attach.
They stay until the device is plugged in again. The udev rule writes the
same line to the journal, see
journalctl -t xmorpheo, and more only on errors.
--replace reads the configuration, plans the device, loads and attaches
the new program, and pins it at /sys/fs/bpf/xmorpheo/<hid_id>_new
before it touches the old one. If anything fails up to there, the old
program stays and the error says why. Then it detaches the old program
and renames the new pin into place. The kernel cannot swap the program of
a HID-BPF link in place, so for that moment both run, and a single report
can pass both curves. If the rename fails, the new program runs under the
temporary name, and the next attach or detach of the device moves or
removes it.
detach
Removes the pinned link, which detaches the program. --all detaches every
program that xmorpheo pinned.
Troubleshooting
Check the rest position. Run evtest on the event node of the device
and let go of the stick. It should rest in the middle of its range, like
2048 for 0..4095. If it rests elsewhere, calibrate the device in its own
tool first, for example VKBDevCfg for VKB sticks. A curve shapes the
response around the rest position, it cannot move it.
Small movements are swallowed. The kernel sets the evdev fuzz of
joystick axes to range >> 8 and smooths changes below about twice that,
which costs resolution around the center. xmorpheo attach sets it to 0.
Check with evdev-joystick --showcal /dev/input/eventN. Without xmorpheo,
a udev rule with evdev-joystick --evdev $devnode --fuzz 0 --deadzone 0
does the same. Programs that read hidraw are not affected.
The deadzone is too large or too small. evdev flat is only a hint for
programs that read evdev. Games usually apply their own deadzone. Put a
deliberate deadzone into the curve with deadzone(x, dz).
Errors when attaching. The tool checks for root, the BPF filesystem,
and HID-BPF in the kernel and says what is missing. If the verifier
rejects the program, run attach --verbose and look at the end of the
log.
udev. The rule logs to syslog as xmorpheo:
journalctl -t xmorpheo
To see the rule run, check that it is installed, reload, and trigger the HID devices:
cat /etc/udev/rules.d/60-xmorpheo.rules
sudo udevadm control --reload
sudo udevadm trigger --action=bind --subsystem-match=hid
sudo udevadm test /sys/bus/hid/devices/<device> shows which rules match,
without running them.
Packaging
Documentation for xmorpheo v0.2.0
Notes for distribution package maintainers. INSTALL.md covers building and installing by hand.
Build and Install
make PREFIX=/usr UDEVRULESDIR=/usr/lib/udev/rules.d INSTALL_SYSCONFDIR=no
make PREFIX=/usr UDEVRULESDIR=/usr/lib/udev/rules.d INSTALL_SYSCONFDIR=no \
DESTDIR="$pkgdir" install
Give the same variables to both steps. The build puts the paths into the
binary and into generated files like the udev rule, records them in
target/dist/paths, and make install refuses a build with other paths.
make install only copies, it never builds or generates anything.
make install-check-package installs with exactly these settings into a
directory below target, fails if anything ends up below /etc, and
uninstalls again.
Variables
| Variable | Default | Meaning |
|---|---|---|
PREFIX | /usr/local | base of the other paths; packages use /usr |
BINDIR | $(PREFIX)/bin | the binary; the udev rule calls it by this path |
DATADIR | $(PREFIX)/share/xmorpheo | the examples, in examples/ |
LIBDIR | $(PREFIX)/lib/xmorpheo | conf.d for configuration shipped with the package |
SYSCONFDIR | /etc | where the tool looks for xmorpheo/conf.d of the administrator |
INSTALL_SYSCONFDIR | yes | no installs nothing below SYSCONFDIR; packages use no |
UDEVRULESDIR | /etc/udev/rules.d | the udev rule; packages use /usr/lib/udev/rules.d |
DESTDIR | empty | staging directory for make install |
ALLOW_ROOT_BUILD | empty | 1 allows make as root, for build environments that run as root |
CARGO | cargo | the cargo binary |
SYSCONFDIR and LIBDIR reach the binary at build time, through the
environment variables XMORPHEO_SYSCONFDIR and XMORPHEO_LIBDIR of cargo.
xmorpheo config shows the directories a binary uses. A distribution that
keeps the administrator’s files in /usr/etc builds with
SYSCONFDIR=/usr/etc.
What to Ship
/usr/bin/xmorpheo./usr/lib/udev/rules.d/60-xmorpheo.rules. A rule of the same name in/etc/udev/rules.doverrides it, as usual for udev./usr/share/xmorpheo/examples/*.toml, the example configurations. They are not active./usr/lib/xmorpheo/conf.d/, empty, or with configuration files the package wants active. The administrator overrides a file there with one of the same name in/etc/xmorpheo/conf.d, or masks it with an empty file or a symlink to/dev/null, see CONFIG.md.- Nothing below
/etc. xmorpheo works without/etc/xmorpheo/conf.d, a missing drop-in directory counts as empty.
The licenses are in LICENSES/, see LICENSE.md: the BPF
program is GPL-2.0-only, the tool GPL-2.0-or-later, the documentation
GPL-3.0-or-later, and the examples CC0-1.0.
After Installing and Removing
Reload the udev rules, and let them attach to devices that are already connected:
udevadm control --reload
udevadm trigger --action=bind --subsystem-match=hid
--action=bind, because the rule attaches when a driver binds to a device.
Before removing the package, detach the programs:
xmorpheo detach --all
The programs stay attached until then, or until the devices go away.
Build Requirements
- Rust with cargo. The build uses
--locked. For offline builds, vendor the dependencies withcargo vendorand point cargo to them, and keepCARGO_HOMEinside the build directory if the build environment requires that. - clang with the BPF target, and bpftool.
- The libelf and zlib development files. libbpf is built from the copy that libbpf-sys vendors.
- The BTF of a kernel: the build generates
vmlinux.hfrom/sys/kernel/btf/vmlinuxof the build host. Build hosts without it, or reproducible builds, setXMORPHEO_VMLINUX_Hto a directory with a preparedvmlinux.h. The program only useshid_bpf_opsandhid_bpf_ctx, which libbpf relocates with CO-RE, so the header does not have to match the target kernel exactly.
Runtime Requirements
- Linux 6.11 or newer with
CONFIG_HID_BPFand BTF, for HID-BPF withstruct_ops. - The BPF filesystem at
/sys/fs/bpf. systemd mounts it. libelf.so.1,libz.so.1, andlibzstd.so.1.- Loading needs
CAP_BPFandCAP_SYS_ADMIN. The udev rule runs as root.
Design
Documentation for xmorpheo v0.2.0
This document describes the architecture of xmorpheo. It covers what is built now and keeps room for planned extensions, see IDEAS.md.
Goals
- Apply response curves and deadzones to selected axes of HID joysticks and gamepads.
- Work for every consumer of the device: evdev, SDL, HID drivers such as
xpadneo, and
hidrawreaders such as games in Proton or Wine. - Keep the device identity (bus, vendor ID, product ID, report descriptor) unchanged, so games keep their bindings.
- Keep the kernel part small, device-agnostic, and free of floating point math.
Where xmorpheo Hooks In
device ──► HID core ──► HID-BPF (xmorpheo) ──┬──► hidraw ──► Proton, Wine, SDL hidapi
└──► HID driver (hid-generic, xpadneo) ──► evdev
HID-BPF programs of type hid_bpf_ops.hid_device_event run on every incoming
report before the kernel passes it to hidraw and to the raw_event hook of
the HID driver. A program can modify the report in place. This needs Linux
6.11 or newer, where HID-BPF uses struct_ops.
The report descriptor is not changed, so the report layout stays the same.
Other HID-BPF programs that fix the descriptor, for example the ones loaded by
udev-hid-bpf, can attach to the same device. xmorpheo reads the descriptor
after such fixups.
Values, Never the Descriptor
xmorpheo changes the values in reports, never the report descriptor, and it does not plan to:
- Software expects the layout and ranges of known models. SDL with its
HIDAPI drivers, Steam Input, and Wine and Proton with
hidrawparse the reports of known controllers themselves, by model, not by descriptor. Games and SDL keep their mappings and bindings by vendor and product ID. A changed range or a new field would go unseen or be misread. - A new descriptor reconnects the device, and to some software it is then another device.
- Drivers like xpadneo and hid-tmff2 fix the descriptor themselves, after the fixups of HID-BPF. A second fixup before theirs is fragile.
- Little is to gain: combined axes work within the range of their field, and lose at most one bit, like two 10 bit triggers on one 10 bit axis.
So the range of an axis is the range of its field, and buttons or axes can only be remapped onto fields the device has.
Report Layout Mismatches
The program sees the raw reports of the device, but the descriptor in sysfs
is the one after the report_fixup of the HID driver. If a driver changes
the descriptor, the fields xmorpheo finds may not match the raw reports.
As a guard, the loader stores the expected length of each input report, per
report ID, and the program leaves a report untouched when it is shorter.
Longer reports are rewritten, because some devices pad every report to the
size of their USB endpoint, like the Thrustmaster T300 RS with 64 byte
reports where its descriptor declares 15 bytes, and the HID core ignores the extra
bytes as well.
Drivers that keep the report length but move fields would still mismatch.
xpadneo, for example, splits the paddles out of the button field in its
raw_event hook. That only touches buttons, so axes stay where the
descriptor says. Any such driver must be checked before supporting it.
Components
BPF Program (bpf/)
The BPF program knows nothing about specific devices or formulas. It reads
five array maps, which the loader fills after loading, and the number of
fields and outputs in read-only data. bpf/xmorpheo.h defines their
layout and the integer math:
- Fields: up to 16 fields per device that the program reads and writes. Each holds the report ID, the expected length of that input report, the bit offset and bit size of the field (at most 16 bits), whether the field is signed, and its logical range.
- Outputs: up to 16 fields per device to write. Each holds the index of its field, whether it is centered, the multiplier from Q24 fixed point back to its raw range, and a slice of the term table.
- Terms: up to 32 per device, at most 4 per output. Each holds the index of its source field, how the source is normalized, the multiplier from its raw range to Q24, and the index of its curve. An output is the sum of its terms.
- Curves: up to 64 entries, holding the first knot and the number of knots, a slice of the knot pool.
- Knots: a pool of up to 8192 support points
{x, y, slope}in Q24 fixed point, sorted byxwithin each curve. The slope to the next knot is computed in user space, so the program needs no division.
For each input report, the program works in three bounded loops, like a
transaction: it reads all fields of the report, computes each output as
the sum of its terms from the values the device sent, then writes the
outputs. So no output depends on the order of the fields, and a field can
be the source of one output and the target of another. Fields of other
report IDs and reports shorter than expected are skipped, and an output keeps
its value if its field or any source is outside its logical range. The
computation only does integer math, with span = max - min and arithmetic shifts:
- Normalize to Q24, where
1.0is2^24:x = ((raw - min) * in_mul + 2^15) >> 16, minus2^24for centered axes.in_mulisround(2^41 / span)for centered andround(2^40 / span)for unipolar axes. - Find the segment: the last knot with
knot.x <= x, by a binary search of at most 10 steps over at most 1024 knots. - Interpolate:
y = knot.y + (((x - knot.x) * knot.slope + 2^23) >> 24).slopeisround((y1 - y0) * 2^24 / (x1 - x0))to the next knot, 0 for the last knot, and needs 64 bits. - Add up the terms of the output, then clamp the sum to
-2^24..=2^24or0..=2^24. - Denormalize:
raw = min + (((y + off) * out_mul + 2^31) >> 32), withoff = 2^24andout_mul = span * 2^7for centered axes, andoff = 0andout_mul = span * 2^8for unipolar axes.
Q24 leaves about 256 steps of the fixed point format per step of a 16 bit field, so rounding inside the math stays far below the fitting tolerance. Intermediate values are 64 bits wide, and only the final value is clamped and rounded to the raw range. All products fit in 64 bits for fields of up to 16 bits. The identity curve maps every raw value to itself.
Knots are normalized, so all axes that use the same formula share one curve, independent of their resolution.
The loader creates one instance of the program per HID device, because the
struct_ops map binds to one hid_id. Instances can reuse the maps of the
first instance, so each formula exists once on the system. For now, each
instance has its own curve and knot maps.
User-Space Tool (xmorpheo/)
A Rust crate with a library and the xmorpheo command line tool:
- Descriptor parser: parses the HID report descriptor from
/sys/bus/hid/devices/<bus>:<vid>:<pid>.<id>/report_descriptor, and lists the input fields with usage, report ID, bit offset, bit size, and logical range, and the length of each input report. - Formulas: parses curve formulas in the normalized input
x, see below. - Curves: evaluates a formula at every raw value of a field and fits
knots greedily: each linear segment extends as long as the integer
evaluation of the BPF program, before rounding to a raw value, stays
within the tolerance of the exact formula at every raw value, or rounds
to the same raw value. The tolerance defaults to half the least
significant bit of the finest field that uses the curve, and can be set
globally or per axis. Every output is within the tolerance plus half a
step of the exact formula, so within one step by default. A tolerance of
0 gives the exactly rounded curve, with a knot wherever needed. The error
bound governs the accuracy, not the knot spacing. The staircase of
integer outputs is inherent to every slope other than 1: a slope of 0.4
repeats outputs, a slope of 2 skips them. Kinks, such as
deadzone edges, get knots automatically. A curve like
x^1.7needs about 30 knots for 10 bit fields and 60 for 12 bit fields, the count doubles with every two more bits, up to about 240 for 16 bit fields. A Rust reference of the integer math tests the fit. - Configuration: reads the configuration, resolves usages and formulas, and later matches devices and selects the axes to rewrite, see below.
- Loader: opens the BPF object with libbpf-rs, through a skeleton that
build.rsgenerates, sets thehid_idand the field table, fills the maps, attaches the program, and pins the link to/sys/fs/bpf/xmorpheo/<hid_id>, so the program stays attached after the tool exits. It then sets the evdev fuzz and flat of all axes of the device to 0, or to the configured values. Before loading, it checks for the needed capabilities, the BPF filesystem, and HID-BPFstruct_opsin the kernel, and explains what is missing. - Inspection:
xmorpheo descriptor <path>lists the input fields of a report descriptor, andxmorpheo curve <formula>prints the knots of a curve for a field together with sample values, without touching any device. - Device commands:
xmorpheo listshows the HID devices with theirhid_id, whether the configuration has an entry for them, and whether a program is attached.xmorpheo templateprints a configuration template for connected devices with their axes commented out.xmorpheo attachattaches the configured curves to the named devices or, with--all, to all configured devices, and--dry-runshows the field table and knot counts without loading anything.xmorpheo detachremoves them again.
libbpf-rs is used because aya does not support HID-BPF struct_ops yet.
Configuration
The configuration is made of TOML drop-ins in conf.d directories, like
systemd: /etc, /run, <prefix>/lib, and /usr/lib, each below
xmorpheo/conf.d, from the highest priority to the lowest. A file replaces
or masks the files of the same name with a lower priority, the rest is read
in the order of the file names, and a later entry for the same device
replaces an earlier one, see CONFIG.md.
Devices match by vendor ID and product ID, plus an optional HID unique ID
(HID_UNIQ, usually the serial number) to tell identical devices apart,
and an optional HID driver, because a driver may replace the descriptor
and so change the usages of the same fields. An entry with a driver wins
over one without.
Axes are selected by HID usage. Axes not listed stay untouched.
usageis a name,X,Y,Z,Rx,Ry,Rz,Slider,Dial,Wheel,Rudder,Throttle,Accelerator,Brake,Clutch, orSteering, or a numericpage:idin hexadecimal, such as0001:0030.kindiscenteredorunipolar. It defaults by usage:Slider,Dial,Throttle,Accelerator,Brake, andClutchare unipolar, everything else is centered.tolerancesets the fitting tolerance in least significant bits, at the top level for all axes and per axis. It defaults to 0.5.[constants]holds named constants for all formulas.[device.fuzz]and[device.flat]set the evdev fuzz and flat by evdev axis name, likeABS_X, in raw units. Every other axis of a managed device gets 0.evdev = "keep"leaves the evdev fuzz and flat of a device as the driver set them.
Unknown keys, unknown usages, axes listed twice, and invalid formulas are errors.
[[device]]
name = "VKB Gladiator EVO R"
vendor = 0x231d
product = 0x0200 # 0x0201 is the Gladiator EVO L
uniq = "..." # optional, only needed for identical devices
[constants]
dz = 0.02
[[device.axis]]
usage = "X" # Generic Desktop X
curve = "pow(normalize(abs(x), dz), 1.7) * sign(x)"
[[device.axis]]
usage = "Y"
curve = "pow(normalize(abs(x), dz), 1.7) * sign(x)"
The library parses this format. It may still change until the loader applies it.
Formulas
Formulas follow the input mixing expressions of Euro Truck Simulator 2
(controls.sii), restricted to their stateless arithmetic part. The input
x is normalized to -1..1 for centered axes (sticks) and to 0..1 for
unipolar axes (triggers, throttles). The output uses the same range and is
clamped to it.
- Numbers,
x, named constants,+ - * /, unary minus, and parentheses. abs(v),sign(v)(0 for 0),pow(v, e),min(a, b),max(a, b),clamp(v, lo, hi), andsel(c, a, b)(aifcis not 0, elseb).normalize(v, dz)mapsdz..1to0..1and everything below to 0.deadzone(v, dz)does the same for both directions of a centered axis.
The meaning of normalize and deadzone is inferred from how ETS2 uses
them, not from documentation.
Constants resolve when parsing. Formulas with the same canonical text share one curve.
Device Lifecycle
When a driver binds to a HID device, the udev rule runs xmorpheo udev bind, which attaches the program if the configuration names the device.
bind instead of add, because only then the descriptor in sysfs has the
fixups of the driver and the evdev nodes exist. After a driver change, the
program is replaced, because the descriptor may differ: the new program is
planned and loaded first, then attached, and the old one detached. If that
fails, for example with an error in the configuration, the old program
stays if the report descriptor is the same as the one it was planned for,
which attach keeps in /run/xmorpheo/state/<hid_id>.rdesc next to the
pin. If the descriptor differs or is not known, the old program is
detached, because its fields may no longer match. Either way, the error
goes to the journal. The old program is also detached when no entry
matches the device with its new driver anymore. Attaching and detaching
hold a lock on the pin directory, so the rule and a manual
xmorpheo attach never attach to a device twice. When the
device disappears, the kernel detaches the program, and xmorpheo udev remove removes the stale pin. The tool can also attach to all present
devices on demand, and detach them again.
The rule runs for every HID device. Devices whose vendor and product the
configuration does not name return before any sysfs or BPF work.
/sys/fs/bpf must be mounted, systemd does that at boot. Programs run by
udev run as root and must finish quickly, udev kills them after the event
timeout; attaching takes milliseconds.
Non-Goals for Now
- Buttons. The field map is generic enough to add them later.
- A graphical user interface.
Ideas
Documentation for xmorpheo v0.2.0
Ideas for later. They are not planned for a release yet. Move an idea into DESIGN.md when work on it starts, and delete it here when done.
Remapping
- Swap buttons.
- Swap the buttons for a left-handed mode of gamepads, like the bumpers and the stick buttons. The axes already work, see RECIPES.md.
- Layers: a button that toggles between two or more mappings of the buttons and axes, like a shift key. The state goes into a BPF map per device, with the previous state of the toggle button for detecting its edges. That needs no descriptor fixup as long as a layer only remaps buttons and axes the device has, and the toggle button itself can be swallowed. Extra buttons in a second layer would need a changed descriptor, which is not planned, see DESIGN.md. Layers end the statelessness for buttons and layers, the curves stay stateless. See also switching curve sets under Curves.
- Simple macros, like auto-repeat (turbo) for a held button. The program
only runs when the device sends a report, and many devices only send on
changes, so turbo needs a timer,
bpf_timerorbpf_wq, that injects synthetic reports with the kfunchid_bpf_input_report. Open: which kernel offers that to HID-BPF struct_ops programs, how drivers react to injected reports, like the deduplication in theraw_eventof xpadneo, and what hidraw readers see.
Curves
- Curve presets as named formulas, such as “precise” or “aggressive”.
- Switch between curve sets at runtime, for example a precision curve on a button press for aiming.
- Expo curve presets of the form
(1-k)*x + k*pow(x, 3), which keep a non-zero slope at the center. - Always set the evdev fuzz of all axes of managed devices to 0 when
attaching (
EVIOCSABS), without an option. The hid-input default (fuzz = range >> 8) dates from potentiometer sticks and removes about three bits of resolution around the center of modern sensors. Curves make it worse: the input core filters output changes that a flatter curve has shrunk. - Also set flat to 0 by default, configurable per device and axis. Flat is only a deadzone hint for user space. Games, SDL, and Proton apply their own deadzones, and devices that do not center exactly, such as some older hall sensor sticks, should get a deadzone in the curve instead.
- Both make separate udev rules with
evdev-joystickunnecessary. hidraw readers are not affected.
Force Feedback
- Invert force feedback together with an inverted steering axis. HID-BPF
also hooks the way from the game to the device,
hid_hw_output_reportandhid_hw_requestinhid_bpf_ops, so a program could mirror the direction of force feedback reports. Whether that works is open, and it depends on the protocol of each device, like the one of Thrustmaster wheels that hid-tmff2 speaks.
User Interface
-
An SVG output of
xmorpheo curvewritten by the tool itself, so a plot of a curve needs no gnuplot. -
A graphical user interface, for example built with GPUI, that shows a realistic preview of the device based on its vendor and product ID, and previews the curve on live input.
Thrustmaster T300 RS, PC mode, with hid-tmff2 and hid-generic
Documentation for xmorpheo v0.2.0
Device
- Vendor ID:
0x044f - Product ID:
0xb66e, confirmed for a newer wheel with a PS3-PS4/PC switch in PC mode (PS3 normal mode in hid-tmff2). Older wheels have a PS3 switch position, which hid-tmff2 recommends for them; their product ID in that mode is not confirmed here, check it withxmorpheo list. hid-tmff2 also knows0xb66f(PS3 advanced mode) and0xb66d(PS4 normal mode). - Drivers: hid-tmff2 (driver
tmff2of the modulehid-tmff-new), or hid-generic. The upstream hid-thrustmaster only binds to0xb65dand switches the wheel into its mode, then hid-generic binds to it.
Report Descriptor with hid-tmff2
hid-tmff2 replaces the report descriptor of the wheel in its
report_fixup with a fixed one, t300rs_rdesc_nrm_fixed from
src/tmt300rs/hid-tmt300rs.c of
hid-tmff2, commit 2874a8e. The
fixup does not look at the descriptor of the wheel. This is the fixed
descriptor of 135 bytes, read from sysfs with hid-tmff2 bound. The raw
file is xmorpheo/tests/data/t300rs_pc_mode.rdesc.
05 01 09 04 a1 01 09 01 a1 00 85 07 09 30 15 00
27 ff ff 00 00 35 00 47 ff ff 00 00 75 10 95 01
81 02 09 35 26 ff 03 46 ff 03 81 02 09 32 81 02
09 31 81 02 81 03 05 09 19 01 29 0d 25 01 45 01
75 01 95 0d 81 02 75 0b 95 01 81 03 05 01 09 39
25 07 46 3b 01 55 00 65 14 75 04 81 42 65 00 81
03 85 60 06 00 ff 09 60 75 08 95 3f 26 ff 7f 15
00 46 ff 7f 36 00 80 91 02 85 02 09 02 81 02 09
14 85 14 81 02 c0 c0
Report Descriptor of the Wheel
Measured on 2026-11-26 in sysfs with hid-generic bound, so without any
fixup: the wheel in PC mode reports 044f:b66e and its own descriptor
of 130 bytes. It differs from the fixed one of hid-tmff2 in the usages
of the pedals, and in its vendor reports: report 10 is the output
report, and reports 2 and 20 have a logical maximum of 255. The raw file
is xmorpheo/tests/data/t300rs_pc_mode_hid_generic.rdesc.
05 01 09 04 a1 01 09 01 a1 00 85 07 09 30 15 00
27 ff ff 00 00 35 00 47 ff ff 00 00 75 10 95 01
81 02 09 31 26 ff 03 46 ff 03 81 02 09 35 81 02
09 36 81 02 81 03 05 09 19 01 29 0d 25 01 45 01
75 01 95 0d 81 02 75 0b 95 01 81 03 05 01 09 39
25 07 46 3b 01 55 00 65 14 75 04 81 42 65 00 81
03 85 0a 06 00 ff 09 0a 75 08 95 3f 26 ff 00 46
ff 00 91 02 85 02 09 02 81 02 09 14 85 14 81 02
c0 c0
Input Fields
Parsed with xmorpheo::descriptor::parse. Bit offsets include the report
ID byte. Input report 7 has the axes:
| Report | Usage with hid-tmff2 | Usage with hid-generic | Bit offset | Bits | Logical range | Comment in hid-tmff2 |
|---|---|---|---|---|---|---|
| 7 | Generic Desktop X (0x30) | X (0x30) | 8 | 16 | 0..65535 | wheel |
| 7 | Generic Desktop Rz (0x35) | Y (0x31) | 24 | 16 | 0..1023 | brake |
| 7 | Generic Desktop Z (0x32) | Rz (0x35) | 40 | 16 | 0..1023 | gas |
| 7 | Generic Desktop Y (0x31) | Slider (0x36) | 56 | 16 | 0..1023 | clutch |
| 7 | Buttons 1..13 | Buttons 1..13 | 88 | 1 each | 0..1 | |
| 7 | Generic Desktop Hat switch (0x39) | Hat switch (0x39) | 112 | 4 | 0..7 |
Reports 2 and 20 are vendor reports for force feedback. The pedals lie at the same places with both drivers, so the raw reports are the same.
The wheel pads input report 7 to the 64 bytes of its interrupt endpoint, measured on 2026-11-22 in the debugfs events of the HID device: the 15 bytes of the descriptor, then zeros. The HID core ignores the extra bytes.
Pedal Mapping
The fixed descriptors of hid-tmff2 name the same pedal fields differently
per mode: Rz, Z, and Y for 0xb66e, Y, Rz, and Slider for 0xb66f.
Under hid-generic, the wheel itself names them Y, Rz, and Slider in
0xb66e too. Games and their templates expect brake and clutch
differently, see
hid-tmff2#233.
Measured in Euro Truck Simulator 2 under Proton: with hid-generic, the
pedals map as the game expects, with hid-tmff2, brake and clutch are
swapped. Inferred from the sources of Proton’s Wine and SDL: Proton
reads the wheel through SDL, not hidraw, and SDL numbers the evdev axes
in the order of their codes. Under hid-generic, that is wheel, brake,
gas, and clutch, under hid-tmff2 wheel, clutch, gas, and brake. So a
configuration that swaps pedals must name the driver its usages are
written for, see examples/t300rs-swap-pedals.toml.
Measured with evtest on 2026-11-22, on a wheel in PC mode: the brake pedal moves Rz and the clutch pedal Y, as the comments in hid-tmff2 say. The pedals rest at the maximum of 1023 and go down to 0 when pressed.
VKB Gladiator EVO L
Documentation for xmorpheo v0.2.0
Device
- Vendor ID:
0x231d - Product ID:
0x0201 - bcdDevice:
0x2122 - HID_NAME:
VKB-Sim © Alex Oz 2021 VKBsim Gladiator EVO L - HID_UNIQ: empty
- Report descriptor: 313 bytes, byte-identical between the EVO L and the EVO R.
Report Descriptor
Read from /sys/bus/hid/devices/0003:231D:0201.*/report_descriptor.
05 01 09 04 a1 01 05 01 85 01 05 01 09 30 75 10
95 01 15 00 26 ff 0f 46 ff 0f 81 02 05 01 09 31
75 10 95 01 15 00 26 ff 0f 46 ff 0f 81 02 05 01
09 35 75 10 95 01 15 00 26 ff 07 46 ff 07 81 02
05 01 09 32 75 10 95 01 15 00 26 ff 07 46 ff 07
81 02 05 01 09 33 75 10 95 01 15 00 26 ff 03 46
ff 03 81 02 05 01 09 34 75 10 95 01 15 00 26 ff
03 46 ff 03 81 02 05 00 09 00 75 10 95 01 15 00
26 ff 07 46 ff 07 81 02 05 00 09 00 75 10 95 01
15 00 26 ff 07 46 ff 07 81 02 05 09 19 01 2a 20
00 15 00 25 01 75 01 96 80 00 81 02 05 01 09 39
15 00 26 07 00 35 00 46 68 01 65 14 55 01 75 04
95 01 81 42 09 00 65 00 55 00 75 04 95 03 81 01
05 01 09 00 75 10 95 01 81 01 05 01 09 00 75 10
95 01 81 01 05 01 09 00 75 10 95 01 81 01 05 01
09 00 75 08 95 17 81 01 85 0b 05 01 09 00 75 08
95 3f 81 01 85 0c 05 01 09 00 75 08 95 3f 81 01
85 08 05 01 09 00 75 08 95 3f 81 01 15 00 26 ff
00 46 ff 00 85 58 75 08 95 3f 09 00 91 02 85 59
75 08 95 80 09 00 b1 02 c0
Input Fields
Measured: parsed with xmorpheo::descriptor::parse. Bit offsets include the
report ID byte. All axes are unsigned and absolute.
| Report | Usage | Bit offset | Bits | Logical range |
|---|---|---|---|---|
| 1 | Generic Desktop X (0x30) | 8 | 16 | 0..4095 |
| 1 | Generic Desktop Y (0x31) | 24 | 16 | 0..4095 |
| 1 | Generic Desktop Rz (0x35) | 40 | 16 | 0..2047 |
| 1 | Generic Desktop Z (0x32) | 56 | 16 | 0..2047 |
| 1 | Generic Desktop Rx (0x33) | 72 | 16 | 0..1023 |
| 1 | Generic Desktop Ry (0x34) | 88 | 16 | 0..1023 |
| 1 | Undefined (page 0x00, usage 0x00) | 104 | 16 | 0..2047 |
| 1 | Undefined (page 0x00, usage 0x00) | 120 | 16 | 0..2047 |
| 1 | Buttons, 128 fields, usages 1..32, the last usage repeats | 136 | 1 each | 0..1 |
| 1 | Generic Desktop Hat switch (0x39), null state | 264 | 4 | 0..7 |
The hat switch reports 0..7 for 0..315 degrees and a null state when centered. Report 1 ends with constant padding. Reports 0x0b, 0x0c, and 0x08 are constant input reports without usages, report 0x58 is a 63 byte output report, and report 0x59 is a 128 byte feature report.
Axis Assignment
Measured with evtest, using the default VKB firmware profile:
- X/Y (
ABS_X,ABS_Y, 0..4095) are the stick. - Rz (
ABS_RZ, 0..2047) is the twist. - Z (
ABS_Z, 0..2047) is the throttle lever at the base. It is unipolar and reports 2047 at one end stop. - Rx/Ry (
ABS_RX,ABS_RY, 0..1023) are the analog ministick. With the evdev fuzz set to 0, it returns exactly to 512 after letting go. - The ministick is dual use: a click toggles it between analog (Rx/Ry)
and digital (the hat switch,
ABS_HAT0X,ABS_HAT0Y). This is a macro of the default VKB firmware profile. - With the evdev fuzz set to 0, the stick and the twist return exactly to the center after letting go (X/Y 2048, Rz 1024, measured on the EVO L). With the default fuzz of hid-input, the reported rest position stayed up to about ±4 counts off center, because the input core holds back small changes.
- Moving one axis on purpose does not move any other axis.
Measured with EVIOCGABS on Linux 7.3: Y reports fuzz 15 and flat 255, Z
and Rz report fuzz 7 and flat 127, and Rx/Ry report fuzz 3 and flat 63. X
reports fuzz 0 and flat 255.
Inferred: hid-input sets fuzz to range >> 8 and flat to range >> 4, and
a udev rule that only covered X had reset its fuzz. The input core smooths
changes below twice the fuzz, so the curve output near the center is
filtered too. Flat is only a hint for user space.
The two fields without a usage, at bits 104 and 120, are unassigned in the default VKB profile: they stayed 0 on both sticks while all controls were moved. Presumably they are free axis slots that VKBDevCfg can assign.
VKB Gladiator EVO R
Documentation for xmorpheo v0.2.0
Device
- Vendor ID:
0x231d - Product ID:
0x0200 - bcdDevice:
0x2122 - HID_NAME:
VKB-Sim © Alex Oz 2021 VKBsim Gladiator EVO R - HID_UNIQ: empty
- Report descriptor: 313 bytes, byte-identical between the EVO L and the EVO R.
Report Descriptor
Read from /sys/bus/hid/devices/0003:231D:0200.*/report_descriptor.
05 01 09 04 a1 01 05 01 85 01 05 01 09 30 75 10
95 01 15 00 26 ff 0f 46 ff 0f 81 02 05 01 09 31
75 10 95 01 15 00 26 ff 0f 46 ff 0f 81 02 05 01
09 35 75 10 95 01 15 00 26 ff 07 46 ff 07 81 02
05 01 09 32 75 10 95 01 15 00 26 ff 07 46 ff 07
81 02 05 01 09 33 75 10 95 01 15 00 26 ff 03 46
ff 03 81 02 05 01 09 34 75 10 95 01 15 00 26 ff
03 46 ff 03 81 02 05 00 09 00 75 10 95 01 15 00
26 ff 07 46 ff 07 81 02 05 00 09 00 75 10 95 01
15 00 26 ff 07 46 ff 07 81 02 05 09 19 01 2a 20
00 15 00 25 01 75 01 96 80 00 81 02 05 01 09 39
15 00 26 07 00 35 00 46 68 01 65 14 55 01 75 04
95 01 81 42 09 00 65 00 55 00 75 04 95 03 81 01
05 01 09 00 75 10 95 01 81 01 05 01 09 00 75 10
95 01 81 01 05 01 09 00 75 10 95 01 81 01 05 01
09 00 75 08 95 17 81 01 85 0b 05 01 09 00 75 08
95 3f 81 01 85 0c 05 01 09 00 75 08 95 3f 81 01
85 08 05 01 09 00 75 08 95 3f 81 01 15 00 26 ff
00 46 ff 00 85 58 75 08 95 3f 09 00 91 02 85 59
75 08 95 80 09 00 b1 02 c0
Input Fields
Measured: parsed with xmorpheo::descriptor::parse. Bit offsets include the
report ID byte. All axes are unsigned and absolute.
| Report | Usage | Bit offset | Bits | Logical range |
|---|---|---|---|---|
| 1 | Generic Desktop X (0x30) | 8 | 16 | 0..4095 |
| 1 | Generic Desktop Y (0x31) | 24 | 16 | 0..4095 |
| 1 | Generic Desktop Rz (0x35) | 40 | 16 | 0..2047 |
| 1 | Generic Desktop Z (0x32) | 56 | 16 | 0..2047 |
| 1 | Generic Desktop Rx (0x33) | 72 | 16 | 0..1023 |
| 1 | Generic Desktop Ry (0x34) | 88 | 16 | 0..1023 |
| 1 | Undefined (page 0x00, usage 0x00) | 104 | 16 | 0..2047 |
| 1 | Undefined (page 0x00, usage 0x00) | 120 | 16 | 0..2047 |
| 1 | Buttons, 128 fields, usages 1..32, the last usage repeats | 136 | 1 each | 0..1 |
| 1 | Generic Desktop Hat switch (0x39), null state | 264 | 4 | 0..7 |
The hat switch reports 0..7 for 0..315 degrees and a null state when centered. Report 1 ends with constant padding. Reports 0x0b, 0x0c, and 0x08 are constant input reports without usages, report 0x58 is a 63 byte output report, and report 0x59 is a 128 byte feature report.
Axis Assignment
Measured with evtest, using the default VKB firmware profile:
- X/Y (
ABS_X,ABS_Y, 0..4095) are the stick. - Rz (
ABS_RZ, 0..2047) is the twist. - Z (
ABS_Z, 0..2047) is the throttle lever at the base. It is unipolar and reports 2047 at one end stop. - Rx/Ry (
ABS_RX,ABS_RY, 0..1023) are the analog ministick. With the evdev fuzz set to 0, it returns exactly to 512 after letting go. - The ministick is dual use: a click toggles it between analog (Rx/Ry)
and digital (the hat switch,
ABS_HAT0X,ABS_HAT0Y). This is a macro of the default VKB firmware profile. - With the evdev fuzz set to 0, the stick and the twist return exactly to the center after letting go (X/Y 2048, Rz 1024, measured on the EVO L). With the default fuzz of hid-input, the reported rest position stayed up to about ±4 counts off center, because the input core holds back small changes.
- Moving one axis on purpose does not move any other axis.
Measured with EVIOCGABS on Linux 7.3: Y reports fuzz 15 and flat 255, Z
and Rz report fuzz 7 and flat 127, and Rx/Ry report fuzz 3 and flat 63. X
reports fuzz 0 and flat 255.
Inferred: hid-input sets fuzz to range >> 8 and flat to range >> 4, and
a udev rule that only covered X had reset its fuzz. The input core smooths
changes below twice the fuzz, so the curve output near the center is
filtered too. Flat is only a hint for user space.
The two fields without a usage, at bits 104 and 120, are unassigned in the default VKB profile: they stayed 0 on both sticks while all controls were moved. Presumably they are free axis slots that VKBDevCfg can assign.
Xbox Wireless Controller (Series X|S), Bluetooth LE, with xpadneo
Documentation for xmorpheo v0.2.0
Device
- Vendor ID:
0x045e - Product ID:
0x0b13, as in the sysfs name0005:045E:0B13.* - HID_NAME:
Xbox Wireless Controller - HID_UNIQ: the Bluetooth address of the controller
- Firmware: BLE 5.23, connected through HOGP and uhid
- Driver: xpadneo
- Report descriptor: 283 bytes, crc16
0x931d
Product ID
xpadneo changes the product ID of the HID device to 0x028e and reports
that as “pretending XB1S Windows wireless mode”. HID_ID in the uevent and
the evdev device then show 045e:028e, but the sysfs name keeps
0B13. xmorpheo matches by the sysfs name, so the configuration uses
product = 0x0b13.
Report Descriptor
Read from /sys/bus/hid/devices/0005:045E:0B13.*/report_descriptor, so
this is the descriptor after the report_fixup of xpadneo. The raw file is
xmorpheo/tests/data/xbox_series_xs_ble_xpadneo.rdesc.
05 01 09 05 a1 01 85 01 09 01 a1 00 09 30 09 31
15 00 27 ff ff 00 00 95 02 75 10 81 02 c0 09 01
a1 00 09 33 09 34 15 00 27 ff ff 00 00 95 02 75
10 81 02 c0 05 01 09 32 15 00 26 ff 03 95 01 75
0a 81 02 15 00 25 00 75 06 95 01 81 03 05 01 09
35 15 00 26 ff 03 95 01 75 0a 81 02 15 00 25 00
75 06 95 01 81 03 05 01 09 39 15 01 25 08 35 00
46 3b 01 66 14 00 75 04 95 01 81 42 75 04 95 01
15 00 25 00 35 00 45 00 65 00 81 03 05 09 19 01
29 0c 15 00 25 01 75 01 95 0c 81 02 15 00 25 00
75 01 95 04 81 03 05 0c 0a b2 00 15 00 25 01 95
01 75 01 81 02 15 00 25 00 75 07 95 01 81 03 05
0f 09 21 85 03 a1 02 09 97 15 00 25 01 75 04 95
01 91 02 15 00 25 00 75 04 95 01 91 03 09 70 15
00 25 64 75 08 95 04 91 02 09 50 66 01 10 55 0e
15 00 26 ff 00 75 08 95 01 91 02 09 a7 15 00 26
ff 00 75 08 95 01 91 02 65 00 55 00 09 7c 15 00
26 ff 00 75 08 95 01 91 02 c0 c0
Input Fields
Measured: parsed with xmorpheo::descriptor::parse. Bit offsets include the
report ID byte. Input report 1 has 17 bytes.
| Report | Usage | Bit offset | Bits | Logical range |
|---|---|---|---|---|
| 1 | Generic Desktop X (0x30) | 8 | 16 | 0..65535 |
| 1 | Generic Desktop Y (0x31) | 24 | 16 | 0..65535 |
| 1 | Generic Desktop Rx (0x33) | 40 | 16 | 0..65535 |
| 1 | Generic Desktop Ry (0x34) | 56 | 16 | 0..65535 |
| 1 | Generic Desktop Z (0x32) | 72 | 10 | 0..1023 |
| 1 | Generic Desktop Rz (0x35) | 88 | 10 | 0..1023 |
| 1 | Generic Desktop Hat switch (0x39), null state | 104 | 4 | 1..8 |
| 1 | Buttons 1..12 | 112 | 1 each | 0..1 |
| 1 | Consumer AC Share (0x0c:0xb2) | 128 | 1 | 0..1 |
Report 3 is the rumble output report.
Changes by xpadneo
From the xpadneo source, report_fixup in xpadneo/device.c:
- Right stick: usage Z becomes Rx and Rz becomes Ry.
- Triggers: Simulation Brake becomes Generic Desktop Z, and Simulation Accelerator becomes Generic Desktop Rz.
- Buttons: 15 buttons and 1 padding bit become 12 buttons and 4 padding bits.
All of these only change usages and counts within the same bits, so the
bit offsets and the report length stay as in the raw reports, which the
BPF program sees. raw_event drops repeated reports, remaps buttons, and
reads the profile bytes of Elite Series 2 controllers, but does not touch
the axes. The mouse mode of xpadneo works on the values after the curve.
With another driver, the right stick is Z and Rz, and the triggers are Brake and Accelerator, so a configuration for xpadneo does not fit.
evdev
Measured with EVIOCGABS on event28 (the gamepad node of xpadneo): the
sticks report -32768..32767 with fuzz 32 and flat 3072, the triggers
(ABS_Z, ABS_RZ) 0..1023 with fuzz 4 and flat 0. xpadneo sets these
itself. The device also has consumer control, keyboard, and mouse nodes
without absolute axes.
Changelog
Documentation for xmorpheo v0.2.0
Notable changes of each release. The format follows Keep a Changelog, and versions follow Semantic Versioning. Before 1.0, the configuration format may still change.
Unreleased
0.2.0 - 2026-11-27
Added
driverlimits a device entry to one HID driver, for drivers that replace the report descriptor and so rename the axes. An entry withdriverwins over one without.xmorpheo templateshows the driver.xmorpheo listshows the HID driver bound to each device.
Fixed
- The Thrustmaster T300 RS example also applied under hid-generic, where the wheel names its pedals differently, so it swapped brake and gas instead of brake and clutch. It now only applies with hid-tmff2 bound.
- When a driver bound to a device that the configuration names, but no entry matched the device with that driver, the udev rule kept the program that was still attached. It now detaches it.
0.1.2 - 2026-11-22
Fixed
- Reports longer than the report descriptor says were left untouched, so nothing was remapped on devices that pad their reports, like the Thrustmaster T300 RS, which sends 64 bytes for a report of 15 bytes. Longer reports are now rewritten, like the HID core reads them; shorter ones still stay untouched.
Changed
- The pedal swap of the Thrustmaster T300 RS example is now tested on the device, in Euro Truck Simulator 2 under Proton.
0.1.1 - 2026-11-16
Fixed
xmorpheo attach --replacedetached the old program before it pinned the new one, so a failure in between left the device without a program. The new program is now pinned under a temporary name first, then the old one is detached, and the new one renamed into place. If anything fails, exactly one program stays attached.- An empty source table (
source = {}) is a configuration error instead of a panic while planning. - Tolerances must be finite numbers of at least 0.
Changed
- When a udev bind fails, for example with an error in an edited
configuration, the previous program stays if the report descriptor is
unchanged. It is kept in
/run/xmorpheo/state/<hid_id>.rdesc. xmorpheo udev removelogs no errors for devices that the configuration does not name.- The error of a failed udev bind shows only once in the journal.
0.1.0 - 2026-11-16
Initial release: response curves and axis remapping for HID joysticks, gamepads, and wheels with HID-BPF, tested with VKB Gladiator EVO sticks and an Xbox Series X|S controller under xpadneo.