diff --git a/kernel_module/hid-saitek-x52.c b/kernel_module/hid-saitek-x52.c index 8ba2439..7170cc1 100644 --- a/kernel_module/hid-saitek-x52.c +++ b/kernel_module/hid-saitek-x52.c @@ -53,163 +53,34 @@ static void _parse_axis_report(struct input_dev *input_dev, input_report_abs(input_dev, ABS_Z, data[4]); input_report_abs(input_dev, ABS_RX, data[5]); input_report_abs(input_dev, ABS_RY, data[6]); - input_report_abs(input_dev, ABS_MISC, data[7]); + input_report_abs(input_dev, ABS_THROTTLE, data[7]); /* Mouse stick is always the last byte of the report */ - input_report_abs(input_dev, ABS_TILT_X, data[len-1] & 0xf); - input_report_abs(input_dev, ABS_TILT_Y, data[len-1] >> 4); + input_report_abs(input_dev, ABS_MISC, data[len-1] & 0xf); + input_report_abs(input_dev, ABS_MISC+1, data[len-1] >> 4); /* Hat is always the upper nibble of the penultimate byte of the report */ input_report_abs(input_dev, ABS_HAT0X, hat_to_axis[hat][0]); input_report_abs(input_dev, ABS_HAT0Y, hat_to_axis[hat][1]); } -/********************************************************************** - * Mapping buttons - * =============== - * - * The X52 and X52 Pro report the buttons in different orders. In order - * to let a userspace application handle them in a generic fashion, we - * define a map for buttons to BTN_* defines, so that one button (eg. clutch) - * will send the same ID on both X52 and X52 Pro - * - * The map is defined below. - ********************************************************************** - */ -#define X52_TRIGGER_1 BTN_TRIGGER_HAPPY1 -#define X52_TRIGGER_2 BTN_TRIGGER_HAPPY2 -#define X52_BTN_FIRE BTN_TRIGGER_HAPPY3 -#define X52_BTN_A BTN_TRIGGER_HAPPY4 -#define X52_BTN_B BTN_TRIGGER_HAPPY5 -#define X52_BTN_C BTN_TRIGGER_HAPPY6 -#define X52_BTN_D BTN_TRIGGER_HAPPY7 -#define X52_BTN_E BTN_TRIGGER_HAPPY8 -#define X52_BTN_PINKIE BTN_TRIGGER_HAPPY9 -#define X52_BTN_T1_UP BTN_TRIGGER_HAPPY10 -#define X52_BTN_T1_DN BTN_TRIGGER_HAPPY11 -#define X52_BTN_T2_UP BTN_TRIGGER_HAPPY12 -#define X52_BTN_T2_DN BTN_TRIGGER_HAPPY13 -#define X52_BTN_T3_UP BTN_TRIGGER_HAPPY14 -#define X52_BTN_T3_DN BTN_TRIGGER_HAPPY15 -#define X52_BTN_CLUTCH BTN_TRIGGER_HAPPY16 -#define X52_MOUSE_LEFT BTN_TRIGGER_HAPPY17 -#define X52_MOUSE_RIGHT BTN_TRIGGER_HAPPY18 -#define X52_MOUSE_FORWARD BTN_TRIGGER_HAPPY19 -#define X52_MOUSE_BACKWARD BTN_TRIGGER_HAPPY20 -#define X52_STICK_POV_N BTN_TRIGGER_HAPPY21 -#define X52_STICK_POV_E BTN_TRIGGER_HAPPY22 -#define X52_STICK_POV_S BTN_TRIGGER_HAPPY23 -#define X52_STICK_POV_W BTN_TRIGGER_HAPPY24 -#define X52_THROT_POV_N BTN_TRIGGER_HAPPY25 -#define X52_THROT_POV_E BTN_TRIGGER_HAPPY26 -#define X52_THROT_POV_S BTN_TRIGGER_HAPPY27 -#define X52_THROT_POV_W BTN_TRIGGER_HAPPY28 -#define X52_MODE_1 BTN_TRIGGER_HAPPY29 -#define X52_MODE_2 BTN_TRIGGER_HAPPY30 -#define X52_MODE_3 BTN_TRIGGER_HAPPY31 -#define X52_BTN_FUNCTION BTN_TRIGGER_HAPPY32 -#define X52_BTN_START_STOP BTN_TRIGGER_HAPPY33 -#define X52_BTN_RESET BTN_TRIGGER_HAPPY34 -#define X52_BTN_PG_UP BTN_TRIGGER_HAPPY35 -#define X52_BTN_PG_DN BTN_TRIGGER_HAPPY36 -#define X52_BTN_UP BTN_TRIGGER_HAPPY37 -#define X52_BTN_DN BTN_TRIGGER_HAPPY38 -#define X52_BTN_MFD_SELECT BTN_TRIGGER_HAPPY39 - static void _parse_button_report(struct input_dev *input_dev, int is_pro, u8 *data, int num_buttons) { int i; int idx; int btn; - - // Map X52 buttons from report to fixed button ID - // This should be defined in the order provided in the report. - static const int x52_buttons[] = { - X52_TRIGGER_1, - X52_BTN_FIRE, - X52_BTN_A, - X52_BTN_B, - X52_BTN_C, - X52_BTN_PINKIE, - X52_BTN_D, - X52_BTN_E, - X52_BTN_T1_UP, - X52_BTN_T1_DN, - X52_BTN_T2_UP, - X52_BTN_T2_DN, - X52_BTN_T3_UP, - X52_BTN_T3_DN, - X52_TRIGGER_2, - X52_STICK_POV_N, - X52_STICK_POV_E, - X52_STICK_POV_S, - X52_STICK_POV_W, - X52_THROT_POV_N, - X52_THROT_POV_E, - X52_THROT_POV_S, - X52_THROT_POV_W, - X52_MODE_1, - X52_MODE_2, - X52_MODE_3, - X52_BTN_FUNCTION, - X52_BTN_START_STOP, - X52_BTN_RESET, - X52_BTN_CLUTCH, - X52_MOUSE_LEFT, - X52_MOUSE_RIGHT, - X52_MOUSE_FORWARD, - X52_MOUSE_BACKWARD, - }; - - static const int pro_buttons[] = { - X52_TRIGGER_1, - X52_BTN_FIRE, - X52_BTN_A, - X52_BTN_B, - X52_BTN_C, - X52_BTN_PINKIE, - X52_BTN_D, - X52_BTN_E, - X52_BTN_T1_UP, - X52_BTN_T1_DN, - X52_BTN_T2_UP, - X52_BTN_T2_DN, - X52_BTN_T3_UP, - X52_BTN_T3_DN, - X52_TRIGGER_2, - X52_MOUSE_LEFT, - X52_MOUSE_FORWARD, - X52_MOUSE_BACKWARD, - X52_MOUSE_RIGHT, - X52_STICK_POV_N, - X52_STICK_POV_E, - X52_STICK_POV_S, - X52_STICK_POV_W, - X52_THROT_POV_N, - X52_THROT_POV_E, - X52_THROT_POV_S, - X52_THROT_POV_W, - X52_MODE_1, - X52_MODE_2, - X52_MODE_3, - X52_BTN_CLUTCH, - X52_BTN_FUNCTION, - X52_BTN_START_STOP, - X52_BTN_RESET, - X52_BTN_PG_UP, - X52_BTN_PG_DN, - X52_BTN_UP, - X52_BTN_DN, - X52_BTN_MFD_SELECT, - }; - - const int *btn_map = is_pro ? pro_buttons : x52_buttons ; + int report_button; for (i = 0; i < num_buttons; i++) { idx = 8 + (i / BITS_PER_BYTE); btn = !!(data[idx] & (1 << (i % BITS_PER_BYTE))); - input_report_key(input_dev, btn_map[i], btn); + if (i <= 0xf) { + report_button = BTN_JOYSTICK + i; + } else { + report_button = BTN_TRIGGER_HAPPY + i - 0x10; + } + input_report_key(input_dev, report_button, btn); } } @@ -273,12 +144,14 @@ static int x52_input_configured(struct hid_device *dev, */ max_btn = is_pro ? 39 : 34 ; - for (i = 0; i < max_btn; i++) { - set_bit(BTN_TRIGGER_HAPPY1 + i, input_dev->keybit); + for (i = 0; i < 0x10; i++) { + set_bit(BTN_JOYSTICK + i, input_dev->keybit); + } + for (i = 0x10; i < max_btn; i++) { + set_bit(BTN_TRIGGER_HAPPY + i - 0x10, input_dev->keybit); } /* Both X52 and X52 Pro have the same number of axes, only the ranges vary */ - set_bit(ABS_X, input_dev->absbit); set_bit(ABS_Y, input_dev->absbit); set_bit(ABS_Z, input_dev->absbit); @@ -286,11 +159,11 @@ static int x52_input_configured(struct hid_device *dev, set_bit(ABS_RY, input_dev->absbit); set_bit(ABS_RZ, input_dev->absbit); set_bit(ABS_RZ, input_dev->absbit); + set_bit(ABS_THROTTLE, input_dev->absbit); set_bit(ABS_HAT0X, input_dev->absbit); set_bit(ABS_HAT0Y, input_dev->absbit); - set_bit(ABS_TILT_X, input_dev->absbit); - set_bit(ABS_TILT_Y, input_dev->absbit); set_bit(ABS_MISC, input_dev->absbit); + set_bit(ABS_MISC+1, input_dev->absbit); max_stick = is_pro ? 1023 : 2047; input_set_abs_params(input_dev, ABS_X, 0, max_stick, max_stick >> 8, max_stick >> 4); @@ -299,11 +172,11 @@ static int x52_input_configured(struct hid_device *dev, input_set_abs_params(input_dev, ABS_RX, 0, 255, 0, 15); input_set_abs_params(input_dev, ABS_RY, 0, 255, 0, 15); input_set_abs_params(input_dev, ABS_Z, 0, 255, 0, 15); - input_set_abs_params(input_dev, ABS_MISC, 0, 255, 0, 15); + input_set_abs_params(input_dev, ABS_THROTTLE, 0, 255, 0, 15); input_set_abs_params(input_dev, ABS_HAT0X, -1, 1, 0, 0); input_set_abs_params(input_dev, ABS_HAT0Y, -1, 1, 0, 0); - input_set_abs_params(input_dev, ABS_TILT_X, 0, 15, 0, 0); - input_set_abs_params(input_dev, ABS_TILT_Y, 0, 15, 0, 0); + input_set_abs_params(input_dev, ABS_MISC, 0, 15, 0, 0); + input_set_abs_params(input_dev, ABS_MISC+1, 0, 15, 0, 0); return 0; }