Skip to contentSkip to conversation

usbtouchscreen, 2.6.25

PATCH In review Søren Hauberg 4 participants 9 messages Sep 23, 2008 – Sep 24, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usbtouchscreen, 2.6.25

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.

input/touchscreen/usbtouchscreen.c renamed from root/touch/usbtouchscreen.c.org +74 -7
@@ -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);
#1 lore raw

Am Dienstag 23 September 2008 10:42:56 schrieb Søren Hauberg:

Quoted 2 lines

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

#2 lore raw

2008/9/23 Oliver Neukum <[email protected]>:

Quoted 6 lines

Am Dienstag 23 September 2008 10:42:56 schrieb Søren Hauberg:

Quoted 2 lines

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

#3 lore raw
In reply to Søren Hauberg
Quoted 14 lines · Søren Hauberg

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.

Quoted 1 line

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).

Quoted 3 lines

Søren

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

Signature · 1 line
Ondrej Zary
#4 lore raw

2008/9/23 Ondrej Zary <[email protected]>:

Quoted 2 lines

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

Quoted 3 lines
Quoted 3 lines

Søren

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

#5 lore raw

Am Dienstag 23 September 2008 11:36:06 schrieb Søren Hauberg:

Quoted 10 lines

2008/9/23 Ondrej Zary <[email protected]>:

Quoted 2 lines

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

#6 lore raw

2008/9/23 Oliver Neukum <[email protected]>:

Quoted 5 lines

Am Dienstag 23 September 2008 11:36:06 schrieb Søren Hauberg:

Quoted 4 lines

2008/9/23 Ondrej Zary <[email protected]>:

Quoted 2 lines

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

Quoted 8 lines
Quoted 6 lines

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).

Quoted 1 line

How do other touchscreens do it?

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

Søren

#7 lore raw
Quoted 6 lines · Søren Hauberg

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.

Signature · 1 line
Matthew Garrett | [email protected]
#8 lore raw

2008/9/24 Matthew Garrett <[email protected]>:

Quoted 11 lines · Søren Hauberg
Quoted 6 lines

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