Merge pull request #5 from Lawstorant/universal-quirks
Add envelope fix quirk and value clamping functions
This commit is contained in:
2
Kbuild
2
Kbuild
@@ -1,3 +1,3 @@
|
||||
obj-m := hid-new-pidff.o
|
||||
hid-new-pidff-y := hid-newpidff.o hid-pidff.o
|
||||
hid-new-pidff-y := hid-universal-pidff.o hid-pidff.o
|
||||
ccflags-y := -Idrivers/hid
|
||||
|
||||
11
README.md
11
README.md
@@ -10,10 +10,7 @@ And that's basically it
|
||||
## What devices are supported?
|
||||
### Bases:
|
||||
1. MOZA R3, R5, R9, R12, R16, R21
|
||||
1. ...
|
||||
|
||||
### Wheel rims (others yet untested):
|
||||
1. MOZA RS V2 (with Moza wheelbases)
|
||||
2. ...
|
||||
|
||||
## What works?
|
||||
1. FFB (all effects from device descriptor)
|
||||
@@ -51,13 +48,13 @@ To unload module:
|
||||
`sudo rmmod hid_moza_ff`
|
||||
|
||||
## How to set up a base parameters?
|
||||
|
||||
### MOZA
|
||||
For now, please, use [Android App](https://play.google.com/store/apps/details?id=com.gudsen.mozapithouse)
|
||||
**[Boxflat](https://github.com/Lawstorant/boxflat)** is a Linux Pit House alternative made by [@Lawstorant](https://github.com/Lawstorant)
|
||||
|
||||
**[Android App](https://play.google.com/store/apps/details?id=com.gudsen.mozapithouse)**
|
||||
|
||||
## Known issues with the driver
|
||||
1. Firmware update does not work. Please use Windows machine or Windows VM for any firmware updates
|
||||
- Buttons above 80 simply don't show up. This is a Linux limitation and we're trying to fix that in the upstream
|
||||
|
||||
## Known issues with the firmware
|
||||
You tell me please
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
PACKAGE_NAME="new-pidff"
|
||||
PACKAGE_VERSION="0.0.2"
|
||||
PACKAGE_NAME="universal-pidff"
|
||||
PACKAGE_VERSION="0.0.3"
|
||||
MAKE[0]="make KVERSION=$kernelver"
|
||||
CLEAN="make clean"
|
||||
BUILT_MODULE_NAME[0]="hid-new-pidff"
|
||||
DEST_MODULE_NAME[0]="hid-new-pidff"
|
||||
DEST_MODULE_NAME[0]="hid-universal-ff"
|
||||
DEST_MODULE_LOCATION[0]="/kernel/drivers/hid"
|
||||
AUTOINSTALL="yes"
|
||||
AUTOINSTALL="yes"
|
||||
|
||||
100
hid-pidff.c
100
hid-pidff.c
@@ -25,6 +25,14 @@
|
||||
|
||||
#define PID_EFFECTS_MAX 64
|
||||
|
||||
/*
|
||||
* This is 16384 or 90 degrees in polar coordinates (up)
|
||||
* Racing games exclusively use polar coordinates but sometimes
|
||||
* SDL/Proton mess with this value as they try to do
|
||||
* some conversions to fix FFB for flight sticks
|
||||
*/
|
||||
#define PIDFF_FIXED_DIRECTION 0x4000
|
||||
|
||||
/* Report usage table used to put reports into an array */
|
||||
|
||||
#define PID_SET_EFFECT 0
|
||||
@@ -213,6 +221,36 @@ static int pidff_rescale_signed(int i, struct hid_field *field)
|
||||
field->logical_minimum / -0x8000;
|
||||
}
|
||||
|
||||
/*
|
||||
* Clamp minimum value for the given field
|
||||
*/
|
||||
static int pidff_clamp_min(int i, struct hid_field *field)
|
||||
{
|
||||
int ret = i < field->logical_minimum ? field->logical_minimum : i;
|
||||
pr_debug("clamped min value from %d to %d\n", i, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Clamp maximum value for the given field
|
||||
*/
|
||||
static int pidff_clamp_max(int i, struct hid_field *field)
|
||||
{
|
||||
int ret = i > field->logical_maximum ? field->logical_maximum : i;
|
||||
pr_debug("clamped max value from %d to %d\n", i, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Clamp value for the given field
|
||||
*/
|
||||
static int pidff_clamp(int i, struct hid_field *field)
|
||||
{
|
||||
i = pidff_clamp_min(i, field);
|
||||
i = pidff_clamp_max(i, field);
|
||||
return i;
|
||||
}
|
||||
|
||||
static void pidff_set(struct pidff_usage *usage, u16 value)
|
||||
{
|
||||
usage->value[0] = pidff_rescale(value, 0xffff, usage->field);
|
||||
@@ -255,7 +293,11 @@ static void pidff_set_envelope_report(struct pidff_device *pidff,
|
||||
pidff->set_envelope[PID_ATTACK_TIME].value[0] = envelope->attack_length;
|
||||
pidff->set_envelope[PID_FADE_TIME].value[0] = envelope->fade_length;
|
||||
|
||||
hid_dbg(pidff->hid, "attack %u => %d\n",
|
||||
hid_dbg(pidff->hid, "attack level %u => %d\n",
|
||||
envelope->attack_level,
|
||||
pidff->set_envelope[PID_ATTACK_LEVEL].value[0]);
|
||||
|
||||
hid_dbg(pidff->hid, "fade level %u => %d\n",
|
||||
envelope->attack_level,
|
||||
pidff->set_envelope[PID_ATTACK_LEVEL].value[0]);
|
||||
|
||||
@@ -308,18 +350,14 @@ static void pidff_set_effect_report(struct pidff_device *pidff,
|
||||
/* check for device quirks */
|
||||
unsigned short direction = effect->direction;
|
||||
|
||||
if ((effect->type == FF_DAMPER ||
|
||||
effect->type == FF_FRICTION ||
|
||||
effect->type == FF_SPRING ||
|
||||
effect->type == FF_INERTIA) &&
|
||||
pidff->quirks & PIDFF_QUIRK_FIX_WHEEL_DIRECTION)
|
||||
direction = 0x3FFF;
|
||||
if (pidff->quirks & PIDFF_QUIRK_FIX_WHEEL_DIRECTION)
|
||||
direction = PIDFF_FIXED_DIRECTION;
|
||||
|
||||
pidff->set_effect[PID_EFFECT_BLOCK_INDEX].value[0] =
|
||||
pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0];
|
||||
pidff->set_effect_type->value[0] =
|
||||
pidff->create_new_effect_type->value[0];
|
||||
pidff->set_effect[PID_DURATION].value[0] =
|
||||
pidff->set_effect[PID_DURATION].value[0] =
|
||||
effect->replay.length == 0 ? 0xffff : effect->replay.length;
|
||||
pidff->set_effect[PID_TRIGGER_BUTTON].value[0] =
|
||||
effect->trigger.button;
|
||||
@@ -363,7 +401,7 @@ static void pidff_set_periodic_report(struct pidff_device *pidff,
|
||||
pidff_set_signed(&pidff->set_periodic[PID_OFFSET],
|
||||
effect->u.periodic.offset);
|
||||
pidff_set(&pidff->set_periodic[PID_PHASE], effect->u.periodic.phase);
|
||||
pidff->set_periodic[PID_PERIOD].value[0] = effect->u.periodic.period;
|
||||
pidff->set_periodic[PID_PERIOD].value[0] = pidff_clamp(effect->u.periodic.period, pidff->set_periodic[PID_PERIOD].field);
|
||||
|
||||
hid_hw_request(pidff->hid, pidff->reports[PID_SET_PERIODIC],
|
||||
HID_REQ_SET_REPORT);
|
||||
@@ -637,6 +675,17 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect,
|
||||
pidff_set_effect_report(pidff, effect);
|
||||
if (!old || pidff_needs_set_periodic(effect, old))
|
||||
pidff_set_periodic_report(pidff, effect);
|
||||
|
||||
if (pidff->quirks & PIDFF_QUIRK_FIX_PERIODIC_ENVELOPE)
|
||||
{
|
||||
effect->u.periodic.envelope.attack_level =
|
||||
effect->u.periodic.envelope.attack_level == 0
|
||||
? 0x7fff : effect->u.periodic.envelope.attack_level;
|
||||
|
||||
effect->u.periodic.envelope.fade_level =
|
||||
effect->u.periodic.envelope.fade_level == 0
|
||||
? 0x7fff : effect->u.periodic.envelope.fade_level;
|
||||
}
|
||||
if (!old ||
|
||||
pidff_needs_set_envelope(&effect->u.periodic.envelope,
|
||||
&old->u.periodic.envelope))
|
||||
@@ -1090,7 +1139,7 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev)
|
||||
|
||||
if (pidff->quirks & PIDFF_QUIRK_NO_DELAY_EFFECT) {
|
||||
hid_dbg(pidff->hid, "Find fields for set_effect without delay\n");
|
||||
if (pidff_find_fields(pidff->set_effect,
|
||||
if (pidff_find_fields(pidff->set_effect,
|
||||
pidff_set_effect_without_delay,
|
||||
pidff->reports[PID_SET_EFFECT], \
|
||||
sizeof(pidff_set_effect_without_delay), 1)) {
|
||||
@@ -1104,7 +1153,7 @@ static int pidff_init_fields(struct pidff_device *pidff, struct input_dev *dev)
|
||||
return -ENODEV;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
PIDFF_FIND_FIELDS(block_load, PID_BLOCK_LOAD, 0);
|
||||
if (!pidff->block_load[PID_EFFECT_BLOCK_INDEX].value) {
|
||||
@@ -1264,7 +1313,7 @@ static int pidff_check_autocenter(struct pidff_device *pidff,
|
||||
/*
|
||||
* Check if the device is PID and initialize it
|
||||
*/
|
||||
int hid_new_pidff_init(struct hid_device *hid, const struct hid_device_id *id)
|
||||
int hid_pidff_init(struct hid_device *hid)
|
||||
{
|
||||
struct pidff_device *pidff;
|
||||
struct hid_input *hidinput = list_entry(hid->inputs.next,
|
||||
@@ -1286,7 +1335,6 @@ int hid_new_pidff_init(struct hid_device *hid, const struct hid_device_id *id)
|
||||
return -ENOMEM;
|
||||
|
||||
pidff->hid = hid;
|
||||
pidff->quirks |= id->driver_data;
|
||||
|
||||
hid_device_io_start(hid);
|
||||
|
||||
@@ -1364,3 +1412,29 @@ int hid_new_pidff_init(struct hid_device *hid, const struct hid_device_id *id)
|
||||
kfree(pidff);
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the device is PID and initialize it
|
||||
* Add quirks after initialisation
|
||||
*/
|
||||
int hid_pidff_init_with_quirks(struct hid_device *hid, const struct hid_device_id *id)
|
||||
{
|
||||
int error = hid_pidff_init(hid);
|
||||
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
struct hid_input *hidinput = list_entry(hid->inputs.next,
|
||||
struct hid_input, list);
|
||||
struct input_dev *dev = hidinput->input;
|
||||
struct pidff_device *pidff = dev->ff->private;
|
||||
|
||||
/* set quirks on the pidff device */
|
||||
hid_device_io_start(hid);
|
||||
pidff->quirks |= id->driver_data;
|
||||
hid_device_io_stop(hid);
|
||||
|
||||
hid_dbg(dev, "Device quirks: %d\n", pidff->quirks);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
11
hid-pidff.h
11
hid-pidff.h
@@ -5,8 +5,12 @@
|
||||
/* PIDFF Quirks to solve issues with certain devices */
|
||||
|
||||
/*
|
||||
* Ignore direction for spring/damping/friction/inertia effects
|
||||
* and always set 16384
|
||||
* Always set a value > 0 for PERIODIC envelope attack and fade level
|
||||
*/
|
||||
#define PIDFF_QUIRK_FIX_PERIODIC_ENVELOPE BIT(0)
|
||||
|
||||
/*
|
||||
* Ignore direction and always set 16384 (0x4000)
|
||||
*/
|
||||
#define PIDFF_QUIRK_FIX_WHEEL_DIRECTION BIT(1)
|
||||
|
||||
@@ -16,6 +20,7 @@
|
||||
#define PIDFF_QUIRK_NO_DELAY_EFFECT BIT(2)
|
||||
|
||||
|
||||
int hid_new_pidff_init(struct hid_device *hid, const struct hid_device_id *id);
|
||||
int hid_pidff_init(struct hid_device *hid);
|
||||
int hid_pidff_init_with_quirks(struct hid_device *hid, const struct hid_device_id *id);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* Improved HID PIDFF driver
|
||||
* HID PIDFF wrapper
|
||||
* First of all targeting steering wheels and wheelbases
|
||||
*
|
||||
* Copyright (c) 2024 Makarenko Oleg
|
||||
@@ -14,15 +14,15 @@
|
||||
|
||||
static const struct hid_device_id pidff_wheel_devices[] = {
|
||||
{ HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R3),
|
||||
.driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION | PIDFF_QUIRK_FIX_0_INFINITE_LENGTH },
|
||||
.driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION | PIDFF_QUIRK_FIX_PERIODIC_ENVELOPE },
|
||||
{ HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R5),
|
||||
.driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION | PIDFF_QUIRK_FIX_0_INFINITE_LENGTH },
|
||||
.driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION | PIDFF_QUIRK_FIX_PERIODIC_ENVELOPE },
|
||||
{ HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R9),
|
||||
.driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION | PIDFF_QUIRK_FIX_0_INFINITE_LENGTH },
|
||||
.driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION | PIDFF_QUIRK_FIX_PERIODIC_ENVELOPE },
|
||||
{ HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R12),
|
||||
.driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION | PIDFF_QUIRK_FIX_0_INFINITE_LENGTH },
|
||||
.driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION | PIDFF_QUIRK_FIX_PERIODIC_ENVELOPE },
|
||||
{ HID_USB_DEVICE(USB_VENDOR_ID_MOZA, USB_DEVICE_ID_MOZA_R16_R21),
|
||||
.driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION | PIDFF_QUIRK_FIX_0_INFINITE_LENGTH },
|
||||
.driver_data = PIDFF_QUIRK_FIX_WHEEL_DIRECTION | PIDFF_QUIRK_FIX_PERIODIC_ENVELOPE },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(hid, pidff_wheel_devices);
|
||||
@@ -39,7 +39,7 @@ static u8 *moza_report_fixup(struct hid_device *hdev, __u8 *rdesc,
|
||||
}
|
||||
|
||||
|
||||
static u8 *new_pidff_report_fixup(struct hid_device *hdev, __u8 *rdesc,
|
||||
static u8 *universal_pidff_report_fixup(struct hid_device *hdev, __u8 *rdesc,
|
||||
unsigned int *rsize)
|
||||
{
|
||||
if (hdev->vendor == USB_VENDOR_ID_MOZA) {
|
||||
@@ -53,7 +53,7 @@ static u8 *new_pidff_report_fixup(struct hid_device *hdev, __u8 *rdesc,
|
||||
* Check if the device is PID and initialize it
|
||||
* Add quirks after initialisation
|
||||
*/
|
||||
static int new_pidff_probe(struct hid_device *hdev,
|
||||
static int universal_pidff_probe(struct hid_device *hdev,
|
||||
const struct hid_device_id *id)
|
||||
{
|
||||
int ret;
|
||||
@@ -69,7 +69,7 @@ static int new_pidff_probe(struct hid_device *hdev,
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = hid_new_pidff_init(hdev, id);
|
||||
ret = hid_pidff_init_with_quirks(hdev, id);
|
||||
if (ret) {
|
||||
hid_warn(hdev, "Force feedback not supported\n");
|
||||
goto err;
|
||||
@@ -80,7 +80,7 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int new_pidff_input_configured(struct hid_device *hdev,
|
||||
static int universal_pidff_input_configured(struct hid_device *hdev,
|
||||
struct hid_input *hidinput)
|
||||
{
|
||||
struct input_dev *input = hidinput->input;
|
||||
@@ -90,15 +90,15 @@ static int new_pidff_input_configured(struct hid_device *hdev,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct hid_driver new_pidff = {
|
||||
.name = "new-pidff",
|
||||
static struct hid_driver universal_pidff = {
|
||||
.name = "hid-universal-pidff",
|
||||
.id_table = pidff_wheel_devices,
|
||||
.probe = new_pidff_probe,
|
||||
.input_configured = new_pidff_input_configured,
|
||||
.report_fixup = new_pidff_report_fixup
|
||||
.probe = universal_pidff_probe,
|
||||
.input_configured = universal_pidff_input_configured,
|
||||
.report_fixup = universal_pidff_report_fixup
|
||||
};
|
||||
module_hid_driver(new_pidff);
|
||||
module_hid_driver(universal_pidff);
|
||||
|
||||
MODULE_AUTHOR("Oleg Makarenko <oleg@makarenk.ooo>");
|
||||
MODULE_DESCRIPTION("Improved HID PIDFF Driver");
|
||||
MODULE_DESCRIPTION("Universal HID PIDFF Driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
Reference in New Issue
Block a user