LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH] usbtouchscreen, 2.6.25
@ 2008-09-23  8:42 Søren Hauberg
  2008-09-23  8:51 ` Ondrej Zary
  2008-09-23  8:55 ` Oliver Neukum
  0 siblings, 2 replies; 9+ messages in thread
From: Søren Hauberg @ 2008-09-23  8:42 UTC (permalink / raw
  To: linux-kernel

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

Hi,
  Currently, the 'usbtouchscreen' module sends raw data from the
touchscreen directly to the user. However, in general, touchscreens
need to be calibrated, and the raw data needs to be transformed
according to the calibration, before the data can be used as an input
device. Currently, some special purpose drivers exists for this in X,
but the situation is a bit messy. I propose to add support for
calibration parameters in the kernel. That way, we can also get usable
touchscreens without X, without having to write special purpose
drivers to handle the data from the touchscreen. The attached patch
adds support for this. A module parameter (transform_xy)
enables/disables this behavior, so the patch is not very intrusive,
and should cause issues to current users.

Comments would be appricated,
Søren

P.S. I'm not subscribed to the list so please keep me in the CC.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: usbtouchscreen.patch --]
[-- Type: text/x-patch; name=usbtouchscreen.patch, Size: 3390 bytes --]

--- /root/touch/usbtouchscreen.c.org	2008-09-16 15:32:40.000000000 +0200
+++ drivers/input/touchscreen/usbtouchscreen.c	2008-09-23 10:26:43.000000000 +0200
@@ -59,6 +59,49 @@
 module_param(swap_xy, bool, 0644);
 MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped.");
 
+static int flip_x;
+module_param(flip_x, bool, 0644);
+MODULE_PARM_DESC(flip_x, "If set X is subtracted from the range_x parameter.");
+
+static int flip_y;
+module_param(flip_y, bool, 0644);
+MODULE_PARM_DESC(flip_y, "If set X is subtracted from the range_x parameter.");
+
+static int transform_xy;
+module_param(transform_xy, bool, 0644);
+MODULE_PARM_DESC(transform_xy, "If set the X-coordinate is computed as\
+ (range_x * (raw_x - min_x))/(max_x-min_x) and similar for the y-coordinate.");
+
+static int min_x;
+module_param(min_x, int, 0644);
+MODULE_PARM_DESC(min_x, "The value of the min_x parameter. See 'transform_xy'\
+ for details.");
+
+static int max_x;
+module_param(max_x, int, 0644);
+MODULE_PARM_DESC(max_x, "The value of the max_x parameter. See 'transform_xy'\
+ for details.");
+
+static int min_y;
+module_param(min_y, int, 0644);
+MODULE_PARM_DESC(min_y, "The value of the min_y parameter. See 'transform_xy'\
+ for details.");
+
+static int max_y;
+module_param(max_y, int, 0644);
+MODULE_PARM_DESC(max_y, "The value of the max_y parameter. See 'transform_xy'\
+ for details.");
+
+static int range_x;
+module_param(range_x, int, 0644);
+MODULE_PARM_DESC(range_x, "The X-coordinate of the output will be in the\
+ interval [0, range_x].");
+
+static int range_y;
+module_param(range_y, int, 0644);
+MODULE_PARM_DESC(range_y, "The Y-coordinate of the output will be in the\
+ interval [0, range_y].");
+
 /* device specifc data/functions */
 struct usbtouch_usb;
 struct usbtouch_device_info {
@@ -672,6 +715,18 @@
 /*****************************************************************************
  * Generic Part
  */
+inline int usbtouch_transform_pkt (int p, int min, int max, int phys)
+{
+  int result = (phys * (p - min))/(max-min);
+  if (result < 0) {
+    return 0;
+  } else if (result > phys) {
+    return phys;
+  } else {
+    return result;
+  }
+}
+
 static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
                                  unsigned char *pkt, int len)
 {
@@ -680,15 +735,27 @@
 	if (!type->read_data(usbtouch, pkt))
 			return;
 
-	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);
+		int tmp;
+		tmp = usbtouch->x;
+		usbtouch->x = usbtouch->y;
+		usbtouch->y = tmp;
 	}
+
+	if (transform_xy) {
+		usbtouch->x = usbtouch_transform_pkt (usbtouch->x, min_x, max_x, range_x);
+		usbtouch->y = usbtouch_transform_pkt (usbtouch->y, min_y, max_y, range_y);
+	}
+
+	if (flip_x)
+		usbtouch->x = range_x - usbtouch->x;
+
+	if (flip_y)
+		usbtouch->y = range_y - usbtouch->y;
+	
+	input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
+	input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
+	input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
 	if (type->max_press)
 		input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
 	input_sync(usbtouch->input);

[-- Attachment #3: README --]
[-- Type: application/octet-stream, Size: 96 bytes --]

Søren Hauberg <hauberg@gmail.com>: add support for calibration parameters in 'usbtouchscreen'.

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

* Re: [PATCH] usbtouchscreen, 2.6.25
  2008-09-23  8:42 [PATCH] usbtouchscreen, 2.6.25 Søren Hauberg
@ 2008-09-23  8:51 ` Ondrej Zary
  2008-09-23  9:36   ` Søren Hauberg
  2008-09-23  8:55 ` Oliver Neukum
  1 sibling, 1 reply; 9+ messages in thread
From: Ondrej Zary @ 2008-09-23  8:51 UTC (permalink / raw
  To: Søren Hauberg; +Cc: linux-kernel

On Tuesday 23 September 2008, Søren Hauberg wrote:
> Hi,
>   Currently, the 'usbtouchscreen' module sends raw data from the
> touchscreen directly to the user. However, in general, touchscreens
> need to be calibrated, and the raw data needs to be transformed
> according to the calibration, before the data can be used as an input
> device. Currently, some special purpose drivers exists for this in X,
> but the situation is a bit messy. I propose to add support for
> calibration parameters in the kernel. That way, we can also get usable
> touchscreens without X, without having to write special purpose
> drivers to handle the data from the touchscreen. The attached patch
> adds support for this. A module parameter (transform_xy)
> enables/disables this behavior, so the patch is not very intrusive,
> and should cause issues to current users.
>
> Comments would be appricated,

Calibration is a per-device thing. You can have more than one touchscreen (the 
swap_xy feature is also wrong, but better than nothing).

> Søren
>
> P.S. I'm not subscribed to the list so please keep me in the CC.

-- 
Ondrej Zary

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

* Re: [PATCH] usbtouchscreen, 2.6.25
  2008-09-23  8:42 [PATCH] usbtouchscreen, 2.6.25 Søren Hauberg
  2008-09-23  8:51 ` Ondrej Zary
@ 2008-09-23  8:55 ` Oliver Neukum
  2008-09-23  8:59   ` Søren Hauberg
  1 sibling, 1 reply; 9+ messages in thread
From: Oliver Neukum @ 2008-09-23  8:55 UTC (permalink / raw
  To: Søren Hauberg; +Cc: linux-kernel, linux-usb

Am Dienstag 23 September 2008 10:42:56 schrieb Søren Hauberg:
> calibration parameters in the kernel. That way, we can also get usable
> touchscreens without X, without having to write special purpose


Is that a realistic use?

	Regards
		Oliver

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

* Re: [PATCH] usbtouchscreen, 2.6.25
  2008-09-23  8:55 ` Oliver Neukum
@ 2008-09-23  8:59   ` Søren Hauberg
  0 siblings, 0 replies; 9+ messages in thread
From: Søren Hauberg @ 2008-09-23  8:59 UTC (permalink / raw
  To: Oliver Neukum; +Cc: linux-kernel, linux-usb

2008/9/23 Oliver Neukum <oliver@neukum.org>:
> Am Dienstag 23 September 2008 10:42:56 schrieb Søren Hauberg:
>> calibration parameters in the kernel. That way, we can also get usable
>> touchscreens without X, without having to write special purpose
>
>
> Is that a realistic use?

Perhaps for people using the framebuffer to create GUIs? To me, it's
not important, but I guess it's a positive side-effect.

Søren

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

* Re: [PATCH] usbtouchscreen, 2.6.25
  2008-09-23  8:51 ` Ondrej Zary
@ 2008-09-23  9:36   ` Søren Hauberg
  2008-09-23 14:13     ` Oliver Neukum
  0 siblings, 1 reply; 9+ messages in thread
From: Søren Hauberg @ 2008-09-23  9:36 UTC (permalink / raw
  To: Ondrej Zary; +Cc: linux-kernel

2008/9/23 Ondrej Zary <linux@rainbow-software.org>:
> Calibration is a per-device thing. You can have more than one touchscreen (the
> swap_xy feature is also wrong, but better than nothing).

Yes, this is true. I'm going to claim (and I have no factual evidence
to back this claim, I'm just making it up) that almost all touchscreen
users only have one touchscreen. So, I'd rather have something that
works for most users, then the current situation. Is it optimal? No!
Is it practical? I believe so. Using your words, it's "better than
nothing".

Søren

>> Søren
>>
>> P.S. I'm not subscribed to the list so please keep me in the CC.

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

* Re: [PATCH] usbtouchscreen, 2.6.25
  2008-09-23  9:36   ` Søren Hauberg
@ 2008-09-23 14:13     ` Oliver Neukum
  2008-09-24  7:04       ` Søren Hauberg
  0 siblings, 1 reply; 9+ messages in thread
From: Oliver Neukum @ 2008-09-23 14:13 UTC (permalink / raw
  To: Søren Hauberg; +Cc: Ondrej Zary, linux-kernel, linux-usb

Am Dienstag 23 September 2008 11:36:06 schrieb Søren Hauberg:
> 2008/9/23 Ondrej Zary <linux@rainbow-software.org>:
> > Calibration is a per-device thing. You can have more than one touchscreen (the
> > swap_xy feature is also wrong, but better than nothing).
> 
> Yes, this is true. I'm going to claim (and I have no factual evidence
> to back this claim, I'm just making it up) that almost all touchscreen
> users only have one touchscreen. So, I'd rather have something that
> works for most users, then the current situation. Is it optimal? No!
> Is it practical? I believe so. Using your words, it's "better than
> nothing".

But is it better than the X driver? How do other touchscreens do it?

	Regards
		Oliver

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

* Re: [PATCH] usbtouchscreen, 2.6.25
  2008-09-23 14:13     ` Oliver Neukum
@ 2008-09-24  7:04       ` Søren Hauberg
  2008-09-24 10:30         ` Matthew Garrett
  0 siblings, 1 reply; 9+ messages in thread
From: Søren Hauberg @ 2008-09-24  7:04 UTC (permalink / raw
  To: Oliver Neukum; +Cc: Ondrej Zary, linux-kernel, linux-usb

2008/9/23 Oliver Neukum <oliver@neukum.org>:
> Am Dienstag 23 September 2008 11:36:06 schrieb Søren Hauberg:
>> 2008/9/23 Ondrej Zary <linux@rainbow-software.org>:
>> > Calibration is a per-device thing. You can have more than one touchscreen (the
>> > swap_xy feature is also wrong, but better than nothing).
>>
>> Yes, this is true. I'm going to claim (and I have no factual evidence
>> to back this claim, I'm just making it up) that almost all touchscreen
>> users only have one touchscreen. So, I'd rather have something that
>> works for most users, then the current situation. Is it optimal? No!
>> Is it practical? I believe so. Using your words, it's "better than
>> nothing".
>
> But is it better than the X driver?

Obviously that depends on how you define "better" :-) The problem I'm
facing is that with the X driver there is no way to change calibration
without restarting X several times, which isn't acceptable for the
application we're developing. Sure, I could fix the X driver to allow
run-time changes to the calibration parameters, but that's a very
large task. On the other hand, solving the problem in the kernel was
dead-easy. So, I agree that solving the problem in-kernel might not be
the best possible solution, it's just the only one I actually have the
time to implement (and it'll work for most users).

> How do other touchscreens do it?

They seem to do nothing, i.e. let the problem be solved in user space.

Søren

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

* Re: [PATCH] usbtouchscreen, 2.6.25
  2008-09-24  7:04       ` Søren Hauberg
@ 2008-09-24 10:30         ` Matthew Garrett
  2008-09-24 12:48           ` Søren Hauberg
  0 siblings, 1 reply; 9+ messages in thread
From: Matthew Garrett @ 2008-09-24 10:30 UTC (permalink / raw
  To: Søren Hauberg; +Cc: Oliver Neukum, Ondrej Zary, linux-kernel, linux-usb

On Wed, Sep 24, 2008 at 09:04:55AM +0200, Søren Hauberg wrote:
> Obviously that depends on how you define "better" :-) The problem I'm
> facing is that with the X driver there is no way to change calibration
> without restarting X several times, which isn't acceptable for the
> application we're developing. Sure, I could fix the X driver to allow
> run-time changes to the calibration parameters, but that's a very
> large task. 

This is the sort of thing that input device properties were added for. 
If you're able to use 1.5 of the X server, it's not a huge body of work 
to add this functionality.

-- 
Matthew Garrett | mjg59@srcf.ucam.org

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

* Re: [PATCH] usbtouchscreen, 2.6.25
  2008-09-24 10:30         ` Matthew Garrett
@ 2008-09-24 12:48           ` Søren Hauberg
  0 siblings, 0 replies; 9+ messages in thread
From: Søren Hauberg @ 2008-09-24 12:48 UTC (permalink / raw
  To: Matthew Garrett; +Cc: Oliver Neukum, Ondrej Zary, linux-kernel, linux-usb

2008/9/24 Matthew Garrett <mjg59@srcf.ucam.org>:
> On Wed, Sep 24, 2008 at 09:04:55AM +0200, Søren Hauberg wrote:
>> Obviously that depends on how you define "better" :-) The problem I'm
>> facing is that with the X driver there is no way to change calibration
>> without restarting X several times, which isn't acceptable for the
>> application we're developing. Sure, I could fix the X driver to allow
>> run-time changes to the calibration parameters, but that's a very
>> large task.
>
> This is the sort of thing that input device properties were added for.
> If you're able to use 1.5 of the X server, it's not a huge body of work
> to add this functionality.

Well, 1.5 isn't an option for me. But this does remove the main
problem with handling calibration in X. So, I guess that means my
patch shouldn't be applied. I'll continue to use it in-house for a
while, but it won't be a long term solution.

Thanks,
Søren

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

end of thread, other threads:[~2008-09-24 12:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-23  8:42 [PATCH] usbtouchscreen, 2.6.25 Søren Hauberg
2008-09-23  8:51 ` Ondrej Zary
2008-09-23  9:36   ` Søren Hauberg
2008-09-23 14:13     ` Oliver Neukum
2008-09-24  7:04       ` Søren Hauberg
2008-09-24 10:30         ` Matthew Garrett
2008-09-24 12:48           ` Søren Hauberg
2008-09-23  8:55 ` Oliver Neukum
2008-09-23  8:59   ` Søren Hauberg

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 read-only IMAP folder(s) and NNTP newsgroup(s).