linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usbtouchscreen: adds support for inverting X or Y axis (or both)
@ 2015-06-07 23:38 Philippe Coval
  2015-07-13 10:15 ` [PATCH v2] " Philippe Coval
  0 siblings, 1 reply; 7+ messages in thread
From: Philippe Coval @ 2015-06-07 23:38 UTC (permalink / raw)
  To: dmitry.torokhov, poeschel
  Cc: Philippe Coval, Ondrej Zary, linux-input, linux-kernel,
	Philippe Coval

Invert Y is needed (together with swap XY) for some touchscreens :
- LeadingTouch screens (at least for some of them)
- cartft 8in4 (USB ID=0eef:0001)

Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
Bug-Link: https://bugs.tizen.org/jira/browse/TC-2522
Cc: linux-input@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Philippe Coval <philippe.coval@open.eurogiciel.org>
---
 drivers/input/touchscreen/usbtouchscreen.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index f2c6c35..af7e6f3 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -63,6 +63,12 @@
 static bool swap_xy;
 module_param(swap_xy, bool, 0644);
 MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped.");
+static int invert_x;
+module_param(invert_x, bool, 0644);
+MODULE_PARM_DESC(invert_x, "Invert X axis.");
+static int invert_y;
+module_param(invert_y, bool, 0644);
+MODULE_PARM_DESC(invert_y, "Invert Y axis.");
 
 static bool hwcalib_xy;
 module_param(hwcalib_xy, bool, 0644);
@@ -1303,6 +1309,7 @@ static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
                                  unsigned char *pkt, int len)
 {
 	struct usbtouch_device_info *type = usbtouch->type;
+	int x, y;
 
 	if (!type->read_data(usbtouch, pkt))
 			return;
@@ -1310,12 +1317,20 @@ static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
 	input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
 
 	if (swap_xy) {
-		input_report_abs(usbtouch->input, ABS_X, usbtouch->y);
-		input_report_abs(usbtouch->input, ABS_Y, usbtouch->x);
+		x = usbtouch->y;
+		y = usbtouch->x;
 	} else {
-		input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
-		input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
+		x = usbtouch->x;
+		y = usbtouch->y;
 	}
+	if (invert_x)
+		x = type->max_xc - x + type->min_xc;
+	if (invert_y)
+		y = type->max_yc - y + type->min_yc;
+
+	input_report_abs(usbtouch->input, ABS_X, x);
+	input_report_abs(usbtouch->input, ABS_Y, y);
+
 	if (type->max_press)
 		input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
 	input_sync(usbtouch->input);
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2] usbtouchscreen: adds support for inverting X or Y axis (or both)
  2015-06-07 23:38 [PATCH] usbtouchscreen: adds support for inverting X or Y axis (or both) Philippe Coval
@ 2015-07-13 10:15 ` Philippe Coval
  2015-07-13 10:28   ` Bastien Nocera
  2015-07-27 22:16   ` [PATCH v3] usbtouchscreen: add option for inverting X or Y axis Philippe Coval
  0 siblings, 2 replies; 7+ messages in thread
From: Philippe Coval @ 2015-07-13 10:15 UTC (permalink / raw)
  To: poeschel, dmitry.torokhov
  Cc: Philippe Coval, Ondrej Zary, linux-input, linux-kernel,
	Philippe Coval

Invert Y is needed (together with swap XY) for some touchscreens :
- LeadingTouch screens (at least for some of them)
- CarTft 8in4 (USB ID=0eef:0001)

Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
Bug-Link: https://bugs.tizen.org/jira/browse/TC-2522
Cc: linux-input@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Philippe Coval <philippe.coval@open.eurogiciel.org>
---

ChangeLog:

* v1: Initial version from me :
  Rebased on v4.1.0-rc6
  https://lkml.org/lkml/2015/6/7/191
  Note it is based on Ondrej Zary's patch (2007):
  https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg136266.html
  Test demo on tizen cartft 8inch4 :
  https://www.youtube.com/watch?v=4L9Bjfy8oDM
* v2: Use bool not int for options variables
  Rebased on v4.2-rc2
  Latest unmerged version can be picked from :
  https://github.com/rzr/linux/tree/for-upstream

 drivers/input/touchscreen/usbtouchscreen.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index f2c6c35..af7e6f3 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -63,6 +63,12 @@
 static bool swap_xy;
 module_param(swap_xy, bool, 0644);
 MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped.");
+static int invert_x;
+module_param(invert_x, bool, 0644);
+MODULE_PARM_DESC(invert_x, "Invert X axis.");
+static int invert_y;
+module_param(invert_y, bool, 0644);
+MODULE_PARM_DESC(invert_y, "Invert Y axis.");
 
 static bool hwcalib_xy;
 module_param(hwcalib_xy, bool, 0644);
@@ -1303,6 +1309,7 @@ static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
                                  unsigned char *pkt, int len)
 {
 	struct usbtouch_device_info *type = usbtouch->type;
+	int x, y;
 
 	if (!type->read_data(usbtouch, pkt))
 			return;
@@ -1310,12 +1317,20 @@ static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
 	input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
 
 	if (swap_xy) {
-		input_report_abs(usbtouch->input, ABS_X, usbtouch->y);
-		input_report_abs(usbtouch->input, ABS_Y, usbtouch->x);
+		x = usbtouch->y;
+		y = usbtouch->x;
 	} else {
-		input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
-		input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
+		x = usbtouch->x;
+		y = usbtouch->y;
 	}
+	if (invert_x)
+		x = type->max_xc - x + type->min_xc;
+	if (invert_y)
+		y = type->max_yc - y + type->min_yc;
+
+	input_report_abs(usbtouch->input, ABS_X, x);
+	input_report_abs(usbtouch->input, ABS_Y, y);
+
 	if (type->max_press)
 		input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
 	input_sync(usbtouch->input);
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] usbtouchscreen: adds support for inverting X or Y axis (or both)
  2015-07-13 10:15 ` [PATCH v2] " Philippe Coval
@ 2015-07-13 10:28   ` Bastien Nocera
  2015-07-13 10:41     ` Philippe Coval
  2015-07-27 22:16   ` [PATCH v3] usbtouchscreen: add option for inverting X or Y axis Philippe Coval
  1 sibling, 1 reply; 7+ messages in thread
From: Bastien Nocera @ 2015-07-13 10:28 UTC (permalink / raw)
  To: Philippe Coval, poeschel, dmitry.torokhov
  Cc: Ondrej Zary, linux-input, linux-kernel, Philippe Coval

On Mon, 2015-07-13 at 12:15 +0200, Philippe Coval wrote:
> Invert Y is needed (together with swap XY) for some touchscreens :
> - LeadingTouch screens (at least for some of them)
> - CarTft 8in4 (USB ID=0eef:0001)

Wouldn't it be useful to force those settings for touchscreen devices
which you can detect? That would make it work out-of-the-box on those
devices.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] usbtouchscreen: adds support for inverting X or Y axis (or both)
  2015-07-13 10:28   ` Bastien Nocera
@ 2015-07-13 10:41     ` Philippe Coval
  0 siblings, 0 replies; 7+ messages in thread
From: Philippe Coval @ 2015-07-13 10:41 UTC (permalink / raw)
  To: Bastien Nocera, poeschel, dmitry.torokhov
  Cc: Ondrej Zary, linux-input, linux-kernel, Philippe Coval

[-- Attachment #1: Type: text/plain, Size: 1105 bytes --]

On 07/13/2015 12:28 PM, Bastien Nocera wrote:
> On Mon, 2015-07-13 at 12:15 +0200, Philippe Coval wrote:
>> Invert Y is needed (together with swap XY) for some touchscreens :
>> - LeadingTouch screens (at least for some of them)
>> - CarTft 8in4 (USB ID=0eef:0001)
> 
> Wouldn't it be useful to force those settings for touchscreen devices
> which you can detect? That would make it work out-of-the-box on those
> devices.
> 
Hi,

That's what I am doing, but userland (using udev rules),
since I am really unsure we can rely on USB id...

For now, I don't think it's a good idea to force any behaviour,
that can cause regressions on other ones.

In a longer term, it would be good to keep a list of all those screens
and see what should be the prefered behaviour per identification.

Note, I don't have any screen anymore.

Thanks for feedback


-- 
 mailto:philippe.coval@eurogiciel.fr  --  gpg:0x467094BC
 xmpp:philippe.coval.pro@gmail.com
 https://dockr.eurogiciel.fr/blogs/embedded/author/pcl/
                                                                      .



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3] usbtouchscreen: add option for inverting X or Y axis
  2015-07-13 10:15 ` [PATCH v2] " Philippe Coval
  2015-07-13 10:28   ` Bastien Nocera
@ 2015-07-27 22:16   ` Philippe Coval
  2015-07-27 22:28     ` Dmitry Torokhov
  1 sibling, 1 reply; 7+ messages in thread
From: Philippe Coval @ 2015-07-27 22:16 UTC (permalink / raw)
  To: dmitry.torokhov, bernhard.bender
  Cc: Philippe Coval, linux-input, linux-kernel, Philippe Coval

Invert Y is needed (together with swap XY) for some touchscreens,
at least for some of them :

- CarTft 8in4 (type=eGalax, USB=0eef:0001)
- LeadingTouch

Since there is not guarantee that
those above devices will all behave the same,
it's safer to configure them userland using udev rules.

This way is safer than hardcoding options per "recognized" model,
and possible regressions will be avoided in a first place.

Credits-to: Ondrej Zary <linux@rainbow-software.org>
Link:  https://lkml.org/lkml/2015/6/7/191
Bug-Link: https://bugs.tizen.org/jira/browse/TC-2522
Cc: linux-input@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Philippe Coval <philippe.coval@open.eurogiciel.org>
---

ChangeLog:

* v1: Initial version from me :
  Rebased on v4.1.0-rc6
  https://lkml.org/lkml/2015/6/7/191
  Note it is based on Ondrej Zary's patch (2007):
  https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg136266.html
  Test demo on tizen cartft 8inch4 :
  https://www.youtube.com/watch?v=4L9Bjfy8oDM
* v2: Use bool not int for options variables
  Rebased on v4.2-rc2
  Latest unmerged version can be picked from :
  https://github.com/rzr/linux/tree/for-upstream
* v3: Use bool static vars (for real), update commit message
  Rebased on v4.2-rc4
  https://github.com/dtor/input/pull/2

 drivers/input/touchscreen/usbtouchscreen.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index 2c41107..cfdfb9f 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -64,6 +64,14 @@ static bool swap_xy;
 module_param(swap_xy, bool, 0644);
 MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped.");
 
+static bool invert_x;
+module_param(invert_x, bool, 0644);
+MODULE_PARM_DESC(invert_x, "Invert X axis.");
+
+static bool invert_y;
+module_param(invert_y, bool, 0644);
+MODULE_PARM_DESC(invert_y, "Invert Y axis.");
+
 static bool hwcalib_xy;
 module_param(hwcalib_xy, bool, 0644);
 MODULE_PARM_DESC(hwcalib_xy, "If set hw-calibrated X/Y are used if available");
@@ -1306,6 +1314,7 @@ static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
                                  unsigned char *pkt, int len)
 {
 	struct usbtouch_device_info *type = usbtouch->type;
+	int x, y;
 
 	if (!type->read_data(usbtouch, pkt))
 			return;
@@ -1313,12 +1322,20 @@ static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
 	input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
 
 	if (swap_xy) {
-		input_report_abs(usbtouch->input, ABS_X, usbtouch->y);
-		input_report_abs(usbtouch->input, ABS_Y, usbtouch->x);
+		x = usbtouch->y;
+		y = usbtouch->x;
 	} else {
-		input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
-		input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
+		x = usbtouch->x;
+		y = usbtouch->y;
 	}
+	if (invert_x)
+		x = type->max_xc - x + type->min_xc;
+	if (invert_y)
+		y = type->max_yc - y + type->min_yc;
+
+	input_report_abs(usbtouch->input, ABS_X, x);
+	input_report_abs(usbtouch->input, ABS_Y, y);
+
 	if (type->max_press)
 		input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
 	input_sync(usbtouch->input);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v3] usbtouchscreen: add option for inverting X or Y axis
  2015-07-27 22:16   ` [PATCH v3] usbtouchscreen: add option for inverting X or Y axis Philippe Coval
@ 2015-07-27 22:28     ` Dmitry Torokhov
  2015-10-09 22:21       ` Philippe Coval
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Torokhov @ 2015-07-27 22:28 UTC (permalink / raw)
  To: Philippe Coval; +Cc: bernhard.bender, linux-input, linux-kernel, Philippe Coval

On Tue, Jul 28, 2015 at 12:16:01AM +0200, Philippe Coval wrote:
> Invert Y is needed (together with swap XY) for some touchscreens,
> at least for some of them :
> 
> - CarTft 8in4 (type=eGalax, USB=0eef:0001)
> - LeadingTouch
> 
> Since there is not guarantee that
> those above devices will all behave the same,
> it's safer to configure them userland using udev rules.
> 
> This way is safer than hardcoding options per "recognized" model,
> and possible regressions will be avoided in a first place.

Does the following still work?

Thanks.

-- 
Dmitry

Input: usbtouchscreen - add option for inverting X or Y axis

From: Philippe Coval <rzr@gna.org>

Invert Y is needed (together with swap XY) for some touchscreens,
at least for some of them:

- CarTft 8in4 (type=eGalax, USB=0eef:0001)
- LeadingTouch

Since there is not guarantee that those above devices will all behave the
same, it's safer to configure them from userland using udev rules.

This way is safer than hard-coding options per "recognized" model,
and possible regressions will be avoided in a first place.

Credits-to: Ondrej Zary <linux@rainbow-software.org>
Link:  https://lkml.org/lkml/2015/6/7/191
Bug-Link: https://bugs.tizen.org/jira/browse/TC-2522
Signed-off-by: Philippe Coval <philippe.coval@open.eurogiciel.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/touchscreen/usbtouchscreen.c |   25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index 2c41107..d283077 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -64,6 +64,14 @@ static bool swap_xy;
 module_param(swap_xy, bool, 0644);
 MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped.");
 
+static bool invert_x;
+module_param(invert_x, bool, 0644);
+MODULE_PARM_DESC(invert_x, "Invert X axis.");
+
+static bool invert_y;
+module_param(invert_y, bool, 0644);
+MODULE_PARM_DESC(invert_y, "Invert Y axis.");
+
 static bool hwcalib_xy;
 module_param(hwcalib_xy, bool, 0644);
 MODULE_PARM_DESC(hwcalib_xy, "If set hw-calibrated X/Y are used if available");
@@ -1312,13 +1320,16 @@ static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
 
 	input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
 
-	if (swap_xy) {
-		input_report_abs(usbtouch->input, ABS_X, usbtouch->y);
-		input_report_abs(usbtouch->input, ABS_Y, usbtouch->x);
-	} else {
-		input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
-		input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
-	}
+	if (swap_xy)
+		swap(usbtouch->y, usbtouch->x);
+	if (invert_x)
+		usbtouch->x = type->max_xc - usbtouch->x + type->min_xc;
+	if (invert_y)
+		usbtouch->y = type->max_yc - usbtouch->y + type->min_yc;
+
+	input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
+	input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
+
 	if (type->max_press)
 		input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
 	input_sync(usbtouch->input);

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v3] usbtouchscreen: add option for inverting X or Y axis
  2015-07-27 22:28     ` Dmitry Torokhov
@ 2015-10-09 22:21       ` Philippe Coval
  0 siblings, 0 replies; 7+ messages in thread
From: Philippe Coval @ 2015-10-09 22:21 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Philippe Coval, bernhard.bender, linux-input, linux-kernel

On 7/28/15, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> On Tue, Jul 28, 2015 at 12:16:01AM +0200, Philippe Coval wrote:
>> Invert Y is needed (together with swap XY) for some touchscreens,
>> at least for some of them :
>>
>> - CarTft 8in4 (type=eGalax, USB=0eef:0001)
>> - LeadingTouch
>>
>> Since there is not guarantee that
>> those above devices will all behave the same,
>> it's safer to configure them userland using udev rules.
>>
>> This way is safer than hardcoding options per "recognized" model,
>> and possible regressions will be avoided in a first place.
>
> Does the following still work?

Hi,

First apologies for delay.

Actually, I wished someone else will give you feedback earlier
since I don't have this screen anymore.

Anyway I know it worked well once applied to some 4.2 rc version.
(and also merged downstream in tizen on 3.14)

Doesn't the change look trivial ?
Do we assume it will work on later versions too ?

For the record here is the reference of the mentioned touchscreen :

MM500
http://www.cartft.com/catalog/il/477

I've contacted vendor, and It's not for sale anymore
(under this brand at least).

Regards

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-10-09 22:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-07 23:38 [PATCH] usbtouchscreen: adds support for inverting X or Y axis (or both) Philippe Coval
2015-07-13 10:15 ` [PATCH v2] " Philippe Coval
2015-07-13 10:28   ` Bastien Nocera
2015-07-13 10:41     ` Philippe Coval
2015-07-27 22:16   ` [PATCH v3] usbtouchscreen: add option for inverting X or Y axis Philippe Coval
2015-07-27 22:28     ` Dmitry Torokhov
2015-10-09 22:21       ` Philippe Coval

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).