From 2b16d6fde1c6a892877aa969e56de39497baecb1 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Tue, 5 Apr 2022 12:28:26 +0200 Subject: [PATCH] xpadneo: Add paddles support 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: https://github.com/atar-axis/xpadneo/issues/344 Closes: https://github.com/atar-axis/xpadneo/issues/332 Signed-off-by: Kai Krakow --- hid-xpadneo/src/hid-xpadneo.c | 25 +++++++++++++++++++++---- hid-xpadneo/src/xpadneo.h | 5 +++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/hid-xpadneo/src/hid-xpadneo.c b/hid-xpadneo/src/hid-xpadneo.c index 4eb85d57..c36fa144 100644 --- a/hid-xpadneo/src/hid-xpadneo.c +++ b/hid-xpadneo/src/hid-xpadneo.c @@ -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 */ @@ -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), @@ -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; } @@ -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: @@ -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; diff --git a/hid-xpadneo/src/xpadneo.h b/hid-xpadneo/src/xpadneo.h index ff3788ed..36822a75 100644 --- a/hid-xpadneo/src/xpadneo.h +++ b/hid-xpadneo/src/xpadneo.h @@ -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