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: atar-axis#344
Closes: atar-axis#332
Signed-off-by: Kai Krakow <[email protected]>
  • Loading branch information
kakra committed Apr 5, 2022
1 parent dad62c1 commit 2b16d6f
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 @@ -136,6 +136,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 @@ -161,9 +164,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 @@ -932,6 +932,13 @@ static int xpadneo_input_configured(struct hid_device *hdev, struct hid_input *h
__clear_bit(BTN_XBOX, xdata->gamepad->keybit);
__clear_bit(BTN_SHARE, xdata->gamepad->keybit);

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

return 0;
}

Expand All @@ -942,7 +949,16 @@ static int xpadneo_event(struct hid_device *hdev, struct hid_field *field,
struct input_dev *gamepad = xdata->gamepad;
struct input_dev *consumer = xdata->consumer;

if (usage->type == EV_ABS) {
if ((usage->type == EV_KEY) && (usage->code == BTN_PADDLES(0))) {
if (gamepad && xdata->profile == 0) {
/* report the paddles individually */
input_report_key(gamepad, BTN_PADDLES(0), value & 1 ? 1 : 0);
input_report_key(gamepad, BTN_PADDLES(1), value & 2 ? 1 : 0);
input_report_key(gamepad, BTN_PADDLES(2), value & 4 ? 1 : 0);
input_report_key(gamepad, 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 @@ -1183,6 +1199,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 @@ -48,8 +48,9 @@ do { \
} while (0)

/* 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 2b16d6f

Please sign in to comment.