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 c5196c7 commit c5aa70c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
23 changes: 19 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), /* 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,12 @@ 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_HAPPY1, xdata->gamepad->keybit);
__set_bit(BTN_TRIGGER_HAPPY2, xdata->gamepad->keybit);
__set_bit(BTN_TRIGGER_HAPPY3, xdata->gamepad->keybit);
__set_bit(BTN_TRIGGER_HAPPY4, xdata->gamepad->keybit);

return 0;
}

Expand All @@ -942,7 +948,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)) {
if (gamepad && xdata->profile == 0) {
/* report the paddles individually */
input_report_key(gamepad, BTN_TRIGGER_HAPPY1, value & 1 ? 1 : 0);
input_report_key(gamepad, BTN_TRIGGER_HAPPY2, value & 2 ? 1 : 0);
input_report_key(gamepad, BTN_TRIGGER_HAPPY3, value & 4 ? 1 : 0);
input_report_key(gamepad, BTN_TRIGGER_HAPPY4, value & 8 ? 1 : 0);
}
goto stop_processing;
} else if (usage->type == EV_ABS) {
switch (usage->code) {
case ABS_X:
case ABS_Y:
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_SHARE KEY_RECORD
#define BTN_XBOX KEY_MODE
#define BTN_PADDLES BTN_TRIGGER_HAPPY1 // ..BTN_TRIGGER_HAPPY4

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

0 comments on commit c5aa70c

Please sign in to comment.