Skip to content

Commit

Permalink
hid-xpadneo: Allow adding and removing quirk flags
Browse files Browse the repository at this point in the history
Signed-off-by: Kai Krakow <[email protected]>
  • Loading branch information
kakra committed Mar 28, 2021
1 parent ccaa674 commit 8716cc0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ files in `/sys/module/hid_xpadneo/parameters`:
* Trigger-only rumble is not possible
* `quirks` (default empty)
* Let's you adjust the quirk mode of your controller
* Comma separated list of `address:flags` pairs
* Comma separated list of `address:flags` pairs (use `+flags` or `-flags` to change flags instead)
* Specify your controller MAC address in the format `11:22:33:44:55:66`
* Specify the flags as sum of the following:
* `1` if your controller does not support pulse parameters (i.e., 8BitDo controllers)
Expand Down
14 changes: 11 additions & 3 deletions hid-xpadneo/src/hid-xpadneo.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static struct {
} param_quirks;
module_param_array_named(quirks, param_quirks.args, charp, &param_quirks.nargs, 0644);
MODULE_PARM_DESC(quirks,
"(string) Override device quirks, specify as: \"MAC1:quirks1[,...16]\""
"(string) Override or change device quirks, specify as: \"MAC1{:,+,-}quirks1[,...16]\""
", MAC format = 11:22:33:44:55:66"
", no pulse parameters = " __stringify(XPADNEO_QUIRK_NO_PULSE)
", no trigger rumble = " __stringify(XPADNEO_QUIRK_NO_TRIGGER_RUMBLE)
Expand Down Expand Up @@ -1102,16 +1102,24 @@ static int xpadneo_init_hw(struct hid_device *hdev)
for (i = 0; i < param_quirks.nargs; i++) {
int offset = strnlen(xdata->gamepad->uniq, 18);
if ((strncasecmp(xdata->gamepad->uniq, param_quirks.args[i], offset) == 0)
&& (param_quirks.args[i][offset] == ':')) {
&& ((param_quirks.args[i][offset] == ':')
|| (param_quirks.args[i][offset] == '+')
|| (param_quirks.args[i][offset] == '-'))) {
char *quirks_arg = &param_quirks.args[i][offset + 1];
u32 quirks = 0;
ret = kstrtou32(quirks_arg, 0, &quirks);
if (ret) {
hid_err(hdev, "quirks override invalid: %s\n", quirks_arg);
goto err_free_name;
} else {
} else if (param_quirks.args[i][offset] == ':') {
hid_info(hdev, "quirks override: %s\n", xdata->gamepad->uniq);
xdata->quirks = quirks;
} else if (param_quirks.args[i][offset] == '-') {
hid_info(hdev, "quirks removed: %s flag 0x%08X\n", xdata->gamepad->uniq, quirks);
xdata->quirks &= ~quirks;
} else {
hid_info(hdev, "quirks added: %s flags 0x%08X\n", xdata->gamepad->uniq, quirks);
xdata->quirks |= quirks;
}
break;
}
Expand Down

0 comments on commit 8716cc0

Please sign in to comment.