All of lore.kernel.org
 help / color / mirror / Atom feed
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
To: Jiri Kosina <jikos@kernel.org>
Cc: "Emmanuel Gil Peyrot" <linkmauve@linkmauve.fr>,
	linux-input@vger.kernel.org, "Ash Logan" <ash@heyquark.com>,
	"Jonathan Neuschäfer" <j.ne@posteo.net>,
	"Barnabás Pőcze" <pobrn@protonmail.com>,
	"Benjamin Tissoires" <benjamin.tissoires@redhat.com>,
	linux-kernel@vger.kernel.org,
	"Daniel J . Ogorchock" <djogorchock@gmail.com>
Subject: [PATCH v5 3/5] HID: nintendo: drc: implement touch reports
Date: Wed, 27 Oct 2021 12:10:41 +0200	[thread overview]
Message-ID: <20211027101043.31609-4-linkmauve@linkmauve.fr> (raw)
In-Reply-To: <20211027101043.31609-1-linkmauve@linkmauve.fr>

There is an inaccessible border on each side, 100 units on the left and
right sides, and 200 units at the top and bottom.  The Y axis is
inverted too, these are the two main quirks of this touch panel.

I’ve been testing with weston-simple-touch mostly, but it also with the
rest of Weston and it aligns perfectly without the need of any
additional calibration.

Signed-off-by: Ash Logan <ash@heyquark.com>
Signed-off-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
---
 drivers/hid/hid-nintendo-wiiu.c | 86 +++++++++++++++++++++++++++++++--
 1 file changed, 81 insertions(+), 5 deletions(-)

diff --git a/drivers/hid/hid-nintendo-wiiu.c b/drivers/hid/hid-nintendo-wiiu.c
index 0b9df62587ed..144316d324cb 100644
--- a/drivers/hid/hid-nintendo-wiiu.c
+++ b/drivers/hid/hid-nintendo-wiiu.c
@@ -52,15 +52,29 @@
 
 #define BUTTON_POWER	BIT(25)
 
+/* Touch constants */
+/* Resolution in pixels */
+#define RES_X		854
+#define RES_Y		480
+/* Display/touch size in mm */
+#define WIDTH		138
+#define HEIGHT		79
+#define NUM_TOUCH_POINTS 10
+#define MAX_TOUCH_RES	(1 << 12)
+#define TOUCH_BORDER_X	100
+#define TOUCH_BORDER_Y	200
+
 /*
  * The device is setup with multiple input devices:
  * - A joypad with the buttons and sticks.
+ * - The touch area which works as a touchscreen.
  */
 
 struct drc {
 	enum nintendo_driver driver;
 	struct hid_device *hdev;
 	struct input_dev *joy_input_dev;
+	struct input_dev *touch_input_dev;
 };
 
 /*
@@ -75,7 +89,7 @@ int wiiu_hid_event(struct hid_device *hdev, struct hid_report *report,
 		   u8 *data, int len)
 {
 	struct drc *drc = hid_get_drvdata(hdev);
-	int i;
+	int i, x, y, pressure, base;
 	u32 buttons;
 
 	if (len != 128)
@@ -134,6 +148,42 @@ int wiiu_hid_event(struct hid_device *hdev, struct hid_report *report,
 	input_report_abs(drc->joy_input_dev, ABS_VOLUME, data[14]);
 	input_sync(drc->joy_input_dev);
 
+	/* touch */
+	/*
+	 * Average touch points for improved accuracy.  Sadly these are always
+	 * reported extremely close from each other…  Even when the user
+	 * pressed two (or more) different points, all ten values will be
+	 * approximately in the middle of the pressure points.
+	 */
+	x = y = 0;
+	for (i = 0; i < NUM_TOUCH_POINTS; i++) {
+		base = 36 + 4 * i;
+
+		x += ((data[base + 1] & 0xF) << 8) | data[base];
+		y += ((data[base + 3] & 0xF) << 8) | data[base + 2];
+	}
+	x /= NUM_TOUCH_POINTS;
+	y /= NUM_TOUCH_POINTS;
+
+	/* Pressure reporting isn’t properly understood, so we don’t report it yet. */
+	pressure = 0;
+	pressure |= ((data[37] >> 4) & 7) << 0;
+	pressure |= ((data[39] >> 4) & 7) << 3;
+	pressure |= ((data[41] >> 4) & 7) << 6;
+	pressure |= ((data[43] >> 4) & 7) << 9;
+
+	if (pressure != 0) {
+		input_report_key(drc->touch_input_dev, BTN_TOUCH, 1);
+		input_report_key(drc->touch_input_dev, BTN_TOOL_FINGER, 1);
+
+		input_report_abs(drc->touch_input_dev, ABS_X, x);
+		input_report_abs(drc->touch_input_dev, ABS_Y, MAX_TOUCH_RES - y);
+	} else {
+		input_report_key(drc->touch_input_dev, BTN_TOUCH, 0);
+		input_report_key(drc->touch_input_dev, BTN_TOOL_FINGER, 0);
+	}
+	input_sync(drc->touch_input_dev);
+
 	/* let hidraw and hiddev handle the report */
 	return 0;
 }
@@ -225,6 +275,30 @@ static bool drc_setup_joypad(struct drc *drc,
 	return true;
 }
 
+static bool drc_setup_touch(struct drc *drc,
+			    struct hid_device *hdev)
+{
+	struct input_dev *input_dev;
+
+	input_dev = allocate_and_setup(hdev, DEVICE_NAME " touchscreen");
+	if (!input_dev)
+		return false;
+
+	drc->touch_input_dev = input_dev;
+
+	set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
+
+	input_set_abs_params(input_dev, ABS_X, TOUCH_BORDER_X, MAX_TOUCH_RES - TOUCH_BORDER_X, 20, 0);
+	input_abs_set_res(input_dev, ABS_X, RES_X / WIDTH);
+	input_set_abs_params(input_dev, ABS_Y, TOUCH_BORDER_Y, MAX_TOUCH_RES - TOUCH_BORDER_Y, 20, 0);
+	input_abs_set_res(input_dev, ABS_Y, RES_Y / HEIGHT);
+
+	input_set_capability(input_dev, EV_KEY, BTN_TOUCH);
+	input_set_capability(input_dev, EV_KEY, BTN_TOOL_FINGER);
+
+	return true;
+}
+
 int wiiu_hid_probe(struct hid_device *hdev,
 		   const struct hid_device_id *id)
 {
@@ -246,8 +320,9 @@ int wiiu_hid_probe(struct hid_device *hdev,
 		return ret;
 	}
 
-	if (!drc_setup_joypad(drc, hdev)) {
-		hid_err(hdev, "could not allocate interface\n");
+	if (!drc_setup_joypad(drc, hdev) ||
+	    !drc_setup_touch(drc, hdev)) {
+		hid_err(hdev, "could not allocate interfaces\n");
 		return -ENOMEM;
 	}
 
@@ -257,9 +332,10 @@ int wiiu_hid_probe(struct hid_device *hdev,
 		return ret;
 	}
 
-	ret = input_register_device(drc->joy_input_dev);
+	ret = input_register_device(drc->joy_input_dev) ||
+	      input_register_device(drc->touch_input_dev);
 	if (ret) {
-		hid_err(hdev, "failed to register interface\n");
+		hid_err(hdev, "failed to register interfaces\n");
 		return ret;
 	}
 
-- 
2.33.1


  parent reply	other threads:[~2021-10-27 10:11 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-02 23:28 [PATCH 0/4] RFC: HID: wiiu-drc: Add a driver for the Wii U gamepad Emmanuel Gil Peyrot
2021-05-02 23:28 ` [PATCH 1/4] HID: wiiu-drc: Add a driver for this gamepad Emmanuel Gil Peyrot
2021-05-05 22:33   ` Jonathan Neuschäfer
2021-05-06 10:07     ` Emmanuel Gil Peyrot
2021-05-06 10:29       ` Jonathan Neuschäfer
2021-05-06 11:53   ` Barnabás Pőcze
2021-05-02 23:28 ` [PATCH 2/4] HID: wiiu-drc: Implement touch reports Emmanuel Gil Peyrot
2021-05-05 22:43   ` Jonathan Neuschäfer
2021-05-06 10:20     ` Emmanuel Gil Peyrot
2021-05-02 23:28 ` [PATCH 3/4] HID: wiiu-drc: Add accelerometer, gyroscope and magnetometer readings Emmanuel Gil Peyrot
2021-05-02 23:28 ` [PATCH 4/4] HID: wiiu-drc: Add battery reporting Emmanuel Gil Peyrot
2021-05-06 11:45   ` Barnabás Pőcze
2021-05-19  8:59 ` [PATCH v3 0/4] HID: wiiu-drc: Add a driver for the Wii U gamepad Emmanuel Gil Peyrot
2021-05-19  8:59   ` [PATCH v3 1/4] HID: wiiu-drc: Add a driver for this gamepad Emmanuel Gil Peyrot
2021-05-19  8:59   ` [PATCH v3 2/4] HID: wiiu-drc: Implement touch reports Emmanuel Gil Peyrot
2021-05-19  8:59   ` [PATCH v3 3/4] HID: wiiu-drc: Add accelerometer, gyroscope and magnetometer readings Emmanuel Gil Peyrot
2021-05-19  8:59   ` [PATCH v3 4/4] HID: wiiu-drc: Add battery reporting Emmanuel Gil Peyrot
2021-09-21 15:08   ` [PATCH v3 0/4] HID: wiiu-drc: Add a driver for the Wii U gamepad Emmanuel Gil Peyrot
2021-10-19  9:14     ` Jiri Kosina
2021-10-19  9:27       ` Emmanuel Gil Peyrot
2021-10-19  9:30         ` Jiri Kosina
2021-10-19  9:36           ` Emmanuel Gil Peyrot
2021-11-04 11:21           ` Emmanuel Gil Peyrot
2021-11-05 17:27             ` François-Xavier Carton
2021-10-19 23:59         ` François-Xavier Carton
2021-10-20  6:24           ` Emmanuel Gil Peyrot
2021-10-19 11:04   ` [PATCH v4 0/5] HID: nintendo: Add support " Emmanuel Gil Peyrot
2021-10-19 11:04     ` [PATCH v4 1/5] HID: nintendo: split switch support into its own file Emmanuel Gil Peyrot
2021-10-22  8:32       ` kernel test robot
2021-10-22  8:32         ` kernel test robot
2021-10-22 10:25       ` kernel test robot
2021-10-22 10:25         ` kernel test robot
2021-10-19 11:04     ` [PATCH v4 2/5] HID: nintendo: drc: add support for the Wii U gamepad Emmanuel Gil Peyrot
2021-11-05 20:55       ` kernel test robot
2021-11-05 20:55         ` kernel test robot
2021-10-19 11:04     ` [PATCH v4 3/5] HID: nintendo: drc: implement touch reports Emmanuel Gil Peyrot
2021-10-19 11:04     ` [PATCH v4 4/5] HID: nintendo: drc: add accelerometer, gyroscope and magnetometer readings Emmanuel Gil Peyrot
2021-10-19 11:04     ` [PATCH v4 5/5] HID: nintendo: drc: add battery reporting Emmanuel Gil Peyrot
2021-10-27  8:10     ` [PATCH v4 0/5] HID: nintendo: Add support for the Wii U gamepad Jiri Kosina
2021-10-27 10:10     ` [PATCH v5 " Emmanuel Gil Peyrot
2021-10-27 10:10       ` [PATCH v5 1/5] HID: nintendo: split switch support into its own file Emmanuel Gil Peyrot
2021-10-27 10:10       ` [PATCH v5 2/5] HID: nintendo: drc: add support for the Wii U gamepad Emmanuel Gil Peyrot
2021-10-27 10:10       ` Emmanuel Gil Peyrot [this message]
2021-10-27 10:10       ` [PATCH v5 4/5] HID: nintendo: drc: add accelerometer, gyroscope and magnetometer readings Emmanuel Gil Peyrot
2021-10-27 10:10       ` [PATCH v5 5/5] HID: nintendo: drc: add battery reporting Emmanuel Gil Peyrot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211027101043.31609-4-linkmauve@linkmauve.fr \
    --to=linkmauve@linkmauve.fr \
    --cc=ash@heyquark.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=djogorchock@gmail.com \
    --cc=j.ne@posteo.net \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pobrn@protonmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.