diff mbox series

[3/3] HID: gamecube-adapter: make axis limits parameters

Message ID 20200506004801.9478-3-fx.carton91@gmail.com
State New
Headers show
Series [1/3] HID: gamecube-adapter: add nintendo gamecube adapter | expand

Commit Message

François-Xavier Carton May 6, 2020, 12:48 a.m. UTC
The axes do not cover the full 0-255 range, with different limit values
for each axis. The limits are made module parameters so they can be
configured.

Signed-off-by: François-Xavier Carton <fx.carton91@gmail.com>
---
 drivers/hid/hid-gamecube-adapter.c | 36 +++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/drivers/hid/hid-gamecube-adapter.c b/drivers/hid/hid-gamecube-adapter.c
index b4022ff5b4b4..6a2fb908de3c 100644
--- a/drivers/hid/hid-gamecube-adapter.c
+++ b/drivers/hid/hid-gamecube-adapter.c
@@ -19,6 +19,30 @@ 
 #include <linux/usb.h>
 #include "usbhid/usbhid.h"
 
+static unsigned int left_stick_min = 0;
+module_param(left_stick_min, uint, 0644);
+MODULE_PARM_DESC(left_stick_min, "Minimum value for left stick.");
+
+static unsigned int left_stick_max = 255;
+module_param(left_stick_max, uint, 0644);
+MODULE_PARM_DESC(left_stick_max, "Maximum value for left stick.");
+
+static unsigned int right_stick_min = 0;
+module_param(right_stick_min, uint, 0644);
+MODULE_PARM_DESC(right_stick_min, "Minimum value for right stick (C stick).");
+
+static unsigned int right_stick_max = 255;
+module_param(right_stick_max, uint, 0644);
+MODULE_PARM_DESC(right_stick_max, "Maximum value for right stick (C stick).");
+
+static unsigned int shoulder_min = 0;
+module_param(shoulder_min, uint, 0644);
+MODULE_PARM_DESC(shoulder_min, "Minimum value for shoulders.");
+
+static unsigned int shoulder_max = 255;
+module_param(shoulder_max, uint, 0644);
+MODULE_PARM_DESC(shoulder_max, "Maximum value for shoulders.");
+
 enum gamecube_output {
 	GC_CMD_INIT = 0x13,
 	GC_CMD_RUMBLE = 0x11
@@ -136,10 +160,6 @@  static const unsigned int gamecube_buttons[] = {
 	BTN_DPAD_LEFT, BTN_DPAD_RIGHT, BTN_DPAD_DOWN, BTN_DPAD_UP
 };
 
-static const unsigned int gamecube_axes[] = {
-	ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_Z, ABS_RZ
-};
-
 static const char* gamecube_ctrl_name(enum gamecube_ctrl_flags flags)
 {
 	switch (flags & GC_TYPES) {
@@ -179,8 +199,12 @@  static int gamecube_ctrl_create(struct gamecube_ctrl *ctrl)
 
 	for (i = 0; i < ARRAY_SIZE(gamecube_buttons); i++)
 		input_set_capability(input, EV_KEY, gamecube_buttons[i]);
-	for (i = 0; i < ARRAY_SIZE(gamecube_axes); i++)
-		input_set_abs_params(input, gamecube_axes[i], 0, 255, 0, 0);
+	input_set_abs_params(input, ABS_X, left_stick_min, left_stick_max, 0, 0);
+	input_set_abs_params(input, ABS_Y, left_stick_min, left_stick_max, 0, 0);
+	input_set_abs_params(input, ABS_RX, right_stick_min, right_stick_max, 0, 0);
+	input_set_abs_params(input, ABS_RY, right_stick_min, right_stick_max, 0, 0);
+	input_set_abs_params(input, ABS_Z, shoulder_min, shoulder_max, 0, 0);
+	input_set_abs_params(input, ABS_RZ, shoulder_min, shoulder_max, 0, 0);
 #ifdef CONFIG_HID_GAMECUBE_ADAPTER_FF
 	input_set_capability(input, EV_FF, FF_RUMBLE);
 	if (input_ff_create_memless(input, NULL, gamecube_rumble_play))