Skip to content

Commit

Permalink
xpadneo: Add paddles support
Browse files Browse the repository at this point in the history
We still silence the paddles when one of the profiles is selected, the
default profile setup maps the paddles to A, B, X, and Y.

The paddles are special because they are passed as one key by the HID
report. We need to manually remap those values to individual bits.

Maybe-affects: #344
Closes: #332
Signed-off-by: Kai Krakow <[email protected]>
  • Loading branch information
kakra committed May 26, 2022
1 parent 5845ca4 commit 9d2ce6f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
25 changes: 21 additions & 4 deletions hid-xpadneo/src/hid-xpadneo.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ static const struct usage_map xpadneo_usage_maps[] = {
/* fixup code "AC Back" from Linux report descriptor */
USAGE_MAP(0xC0224, MAP_STATIC, EV_KEY, BTN_SELECT),

/* map special buttons without HID bitmaps, corrected in event handler */
USAGE_MAP(0xC0081, MAP_STATIC, EV_KEY, BTN_PADDLES(0)), /* Four paddles */

/* hardware features handled at the raw report level */
USAGE_IGN(0xC0085), /* Profile switcher */
USAGE_IGN(0xC0099), /* Trigger scale switches */
Expand All @@ -162,9 +165,6 @@ static const struct usage_map xpadneo_usage_maps[] = {
USAGE_IGN(0x9001E), /* copy of RS */
USAGE_IGN(0xC0082), /* copy of Select button */

/* XBE2: Disable extra features until proper support is implemented */
USAGE_IGN(0xC0081), /* Four paddles */

/* XBE2: Disable unused buttons */
USAGE_IGN(0x90012), /* 6 "TRIGGER_HAPPY" buttons */
USAGE_IGN(0x90015),
Expand Down Expand Up @@ -897,6 +897,13 @@ static int xpadneo_input_configured(struct hid_device *hdev, struct hid_input *h
/* combine triggers to form a rudder, use ABS_MISC to order after dpad */
input_set_abs_params(xdata->idev, ABS_MISC, -1023, 1023, 3, 63);

/* add paddles as part of the gamepad */
__set_bit(BTN_TRIGGER_HAPPY, xdata->idev->keybit); /* workaround for Steam */
__set_bit(BTN_PADDLES(0), xdata->idev->keybit);
__set_bit(BTN_PADDLES(1), xdata->idev->keybit);
__set_bit(BTN_PADDLES(2), xdata->idev->keybit);
__set_bit(BTN_PADDLES(3), xdata->idev->keybit);

return 0;
}

Expand All @@ -906,7 +913,16 @@ static int xpadneo_event(struct hid_device *hdev, struct hid_field *field,
struct xpadneo_devdata *xdata = hid_get_drvdata(hdev);
struct input_dev *idev = xdata->idev;

if (usage->type == EV_ABS) {
if ((usage->type == EV_KEY) && (usage->code == BTN_PADDLES(0))) {
if (xdata->profile == 0) {
/* report the paddles individually */
input_report_key(idev, BTN_PADDLES(0), value & 1 ? 1 : 0);
input_report_key(idev, BTN_PADDLES(1), value & 2 ? 1 : 0);
input_report_key(idev, BTN_PADDLES(2), value & 4 ? 1 : 0);
input_report_key(idev, BTN_PADDLES(3), value & 8 ? 1 : 0);
}
goto stop_processing;
} else if (usage->type == EV_ABS) {
switch (usage->code) {
case ABS_X:
case ABS_Y:
Expand Down Expand Up @@ -1106,6 +1122,7 @@ static int xpadneo_probe(struct hid_device *hdev, const struct hid_device_id *id
case 0x0B05:
case 0x0B13:
case 0x0B20:
case 0x0B22:
hdev->product = 0x02E0;
hdev->version = 0x00000903;
break;
Expand Down
5 changes: 3 additions & 2 deletions hid-xpadneo/src/xpadneo.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ do { \
#endif

/* button aliases */
#define BTN_SHARE KEY_RECORD
#define BTN_XBOX KEY_MODE
#define BTN_PADDLES(b) (BTN_TRIGGER_HAPPY37+(b))
#define BTN_SHARE KEY_RECORD
#define BTN_XBOX KEY_MODE

/* module parameter "trigger_rumble_mode" */
#define PARAM_TRIGGER_RUMBLE_PRESSURE 0
Expand Down

0 comments on commit 9d2ce6f

Please sign in to comment.