mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Javier Carrasco <javier.carrasco@wolfvision.net>
To: linux-input@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Henrik Rydberg <rydberg@bitmath.org>,
	Javier Carrasco <javier.carrasco@wolfvision.net>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Stephen Boyd <sboyd@kernel.org>,
	Sebastian Reichel <sre@kernel.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Uwe Kleine-g <u.kleine-koenig@pengutronix.de>,
	Bastian Hecht <hechtb@gmail.com>,
	Michael Riesch <michael.riesch@wolfvision.net>
Subject: [RFC v1 3/4] Input: st1232 - add virtual touchscreen and buttons handling
Date: Tue, 25 Apr 2023 13:50:48 +0200	[thread overview]
Message-ID: <20230425115049.870003-4-javier.carrasco@wolfvision.net> (raw)
In-Reply-To: <20230425115049.870003-1-javier.carrasco@wolfvision.net>

Use ts-virtobj to support overlay objects such as buttons and resized
frames defined in the device tree.

Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net>
---
 drivers/input/touchscreen/st1232.c | 41 ++++++++++++++++++++++--------
 1 file changed, 31 insertions(+), 10 deletions(-)

diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c
index f49566dc96f8..025f43c532d8 100644
--- a/drivers/input/touchscreen/st1232.c
+++ b/drivers/input/touchscreen/st1232.c
@@ -22,6 +22,7 @@
 #include <linux/pm_qos.h>
 #include <linux/slab.h>
 #include <linux/types.h>
+#include <linux/input/ts-virtobj.h>
 
 #define ST1232_TS_NAME	"st1232-ts"
 #define ST1633_TS_NAME	"st1633-ts"
@@ -56,6 +57,7 @@ struct st1232_ts_data {
 	struct touchscreen_properties prop;
 	struct dev_pm_qos_request low_latency_req;
 	struct gpio_desc *reset_gpio;
+	struct ts_virtobj_map *map;
 	const struct st_chip_info *chip_info;
 	int read_buf_len;
 	u8 *read_buf;
@@ -133,6 +135,7 @@ static int st1232_ts_parse_and_report(struct st1232_ts_data *ts)
 	struct input_mt_pos pos[ST_TS_MAX_FINGERS];
 	u8 z[ST_TS_MAX_FINGERS];
 	int slots[ST_TS_MAX_FINGERS];
+	bool button_slot[ST_TS_MAX_FINGERS] = {false};
 	int n_contacts = 0;
 	int i;
 
@@ -143,6 +146,11 @@ static int st1232_ts_parse_and_report(struct st1232_ts_data *ts)
 			unsigned int x = ((buf[0] & 0x70) << 4) | buf[1];
 			unsigned int y = ((buf[0] & 0x07) << 8) | buf[2];
 
+			if (ts_virtobj_button_event(ts->map, ts->input_dev, x, y))
+				button_slot[n_contacts] = true;
+			else if (!ts_virtobj_mt_on_touchscreen(ts->map, &x, &y))
+				continue;
+
 			touchscreen_set_mt_pos(&pos[n_contacts],
 					       &ts->prop, x, y);
 
@@ -158,12 +166,16 @@ static int st1232_ts_parse_and_report(struct st1232_ts_data *ts)
 	for (i = 0; i < n_contacts; i++) {
 		input_mt_slot(input, slots[i]);
 		input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
-		input_report_abs(input, ABS_MT_POSITION_X, pos[i].x);
-		input_report_abs(input, ABS_MT_POSITION_Y, pos[i].y);
+		if (!button_slot[i]) {
+			input_report_abs(input, ABS_MT_POSITION_X, pos[i].x);
+			input_report_abs(input, ABS_MT_POSITION_Y, pos[i].y);
+		}
 		if (ts->chip_info->have_z)
 			input_report_abs(input, ABS_MT_TOUCH_MAJOR, z[i]);
 	}
 
+	if (!n_contacts)
+		ts_virtobj_button_release_pressed(ts->map, ts->input_dev);
 	input_mt_sync_frame(input);
 	input_sync(input);
 
@@ -266,6 +278,11 @@ static int st1232_ts_probe(struct i2c_client *client)
 	ts->client = client;
 	ts->input_dev = input_dev;
 
+	/* map virtual objects if defined in the device tree */
+	ts->map = ts_virtobj_map_objects(&ts->client->dev, ts->input_dev);
+	if (IS_ERR(ts->map))
+		return PTR_ERR(ts->map);
+
 	ts->reset_gpio = devm_gpiod_get_optional(&client->dev, NULL,
 						 GPIOD_OUT_HIGH);
 	if (IS_ERR(ts->reset_gpio)) {
@@ -292,18 +309,22 @@ static int st1232_ts_probe(struct i2c_client *client)
 	if (error)
 		return error;
 
-	/* Read resolution from the chip */
-	error = st1232_ts_read_resolution(ts, &max_x, &max_y);
-	if (error) {
-		dev_err(&client->dev,
-			"Failed to read resolution: %d\n", error);
-		return error;
-	}
-
 	if (ts->chip_info->have_z)
 		input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0,
 				     ts->chip_info->max_area, 0, 0);
 
+	if (ts_virtobj_mapped_touchscreen(ts->map)) {
+		ts_virtobj_retrieve_abs(ts->map, &max_x, &max_y);
+	} else {
+		/* Read resolution from the chip */
+		error = st1232_ts_read_resolution(ts, &max_x, &max_y);
+		if (error) {
+			dev_err(&client->dev,
+				"Failed to read resolution: %d\n", error);
+			return error;
+		}
+	}
+
 	input_set_abs_params(input_dev, ABS_MT_POSITION_X,
 			     0, max_x, 0, 0);
 	input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
-- 
2.37.2


  parent reply	other threads:[~2023-04-25 11:51 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-25 11:50 [RFC v1 0/4] Input: support virtual objects on touchscreens Javier Carrasco
2023-04-25 11:50 ` [RFC v1 1/4] Input: ts-virtobj - Add touchsreen virtual object handling to the core Javier Carrasco
2023-04-25 11:50 ` [RFC v1 2/4] dt-bindings: touchscreen: add virtual-touchscreen and virtual-buttons properties Javier Carrasco
2023-04-25 11:50 ` Javier Carrasco [this message]
2023-04-25 11:50 ` [RFC v1 4/4] dt-bindings: input: touchscreen: st1232: add virtual objects to the example Javier Carrasco
2023-04-25 15:29 ` [RFC v1 0/4] Input: support virtual objects on touchscreens Thomas Weißschuh
2023-04-25 16:02   ` Jeff LaBundy
2023-04-27 15:59     ` Javier Carrasco
2023-04-27 17:23       ` Jeff LaBundy
2023-04-28  6:08         ` Javier Carrasco
2023-05-04  4:29         ` Peter Hutterer
2023-05-06 18:35           ` Jeff LaBundy
2023-04-27 11:04 ` Pavel Machek
2023-04-27 11:11   ` Michael Riesch
2023-04-27 13:15     ` Pavel Machek
2023-04-27 17:45       ` Jeff LaBundy
2023-05-01 12:32 ` Linus Walleij

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=20230425115049.870003-4-javier.carrasco@wolfvision.net \
    --to=javier.carrasco@wolfvision.net \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=hechtb@gmail.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.riesch@wolfvision.net \
    --cc=robh+dt@kernel.org \
    --cc=rydberg@bitmath.org \
    --cc=sboyd@kernel.org \
    --cc=sre@kernel.org \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=ulf.hansson@linaro.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®