linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* ALPS v4 Semi-mt Support
@ 2012-04-10 14:01 George Pantalos
  0 siblings, 0 replies; 10+ messages in thread
From: George Pantalos @ 2012-04-10 14:01 UTC (permalink / raw)
  To: linux-input

Hello,

I have created a crude patch to add Semi-MT support for v4 ALPS touchpads 
based on the work by Seth Forshee. [1]

This patch works ok for Single-Touch Events however the Left Half side of the 
touchpad is far less accurate than the Right Half for Semi-mt events 
(synclient -m 10 shows f alternating constantly between 1 and 2 fingers with 
two fingers touching it and one finger touch erroneously reports as 2 finger 
touch sometimes.)

I hope this is useful and maybe it could be improved and approved :)

Sorry for the code quality, I am not a programmer.

[1]  http://people.canonical.com/~sforshee/alps-touchpad/psmouse-
alps-0.10/

^ permalink raw reply	[flat|nested] 10+ messages in thread
* ALPS v4 Semi-mt Support
@ 2012-04-10 14:02 George Pantalos
  2012-04-10 15:21 ` Seth Forshee
  0 siblings, 1 reply; 10+ messages in thread
From: George Pantalos @ 2012-04-10 14:02 UTC (permalink / raw)
  To: linux-input

--- drivers/input/mouse/alps.c	2012-03-19 01:15:34.000000000 +0200
+++ drivers/input/mouse/alps.c.new	2012-04-09 17:14:25.193621808 +0300
@@ -604,11 +604,59 @@
 
 static void alps_process_packet_v4(struct psmouse *psmouse)
 {
+        struct alps_data *priv = psmouse->private;
 	unsigned char *packet = psmouse->packet;
 	struct input_dev *dev = psmouse->dev;
 	int x, y, z;
 	int left, right;
+	int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
+	int fingers = 0, bmap_fingers;
+	unsigned int x_bitmap, y_bitmap;
+
+	if (priv->multi_packet) {
+          if (packet[6] != 0x00) { 
+		priv->multi_data_v4[2] = packet[6];
+		priv->multi_data_v4[3] = packet[7];
+		priv->multi_packet = 1;
+		if (priv->last_fingers > 1)
+		return;
+          } else {
+		priv->multi_data_v4[4] = packet[6];
+		priv->multi_data_v4[5] = packet[7];
+
+		fingers = 0;
+		priv->multi_packet = 0;
+		x_bitmap = ((priv->multi_data_v4[2] & 0x1f) << 10) | /*0x1f*/
+			   ((priv->multi_data_v4[3] & 0x60) << 3) |
+			   ((priv->multi_data_v4[0] & 0x3f) << 2) |
+			   ((priv->multi_data_v4[1] & 0x60) >> 5);
+		y_bitmap = ((priv->multi_data_v4[5] & 0x01) << 10) |
+			   ((priv->multi_data_v4[3] & 0x1f) << 5) |
+			    (priv->multi_data_v4[1] & 0x1f);
+	  
+		bmap_fingers = alps_process_bitmap(x_bitmap, y_bitmap,
+						  &x1, &y1, &x2, &y2);
+		if (bmap_fingers > 1) {
+			fingers = bmap_fingers;
+		}
+	  
+		priv->last_fingers = fingers;
 
+          /*packet = priv->multi_data;*/
+          /*packet = packet;*/
+	  }
+	}
+
+	if (!priv->multi_packet && (packet[6] & 0x40)) {
+		priv->multi_packet = 1;
+		priv->multi_data_v4[0] = packet[6];
+		priv->multi_data_v4[1] = packet[7];
+		if (priv->last_fingers > 1)
+		return;
+	}
+	
+        /*priv->multi_packet = 0;*/
+        
 	left = packet[4] & 0x01;
 	right = packet[4] & 0x02;
 
@@ -617,21 +665,33 @@
 	y = ((packet[2] & 0x7f) << 4) | (packet[3] & 0x0f);
 	z = packet[5] & 0x7f;
 
+	if (!fingers) {
+		x1 = x;
+		y1 = y;
+		fingers = z > 0 ? 1 : 0;
+	}
+
 	if (z >= 64)
 		input_report_key(dev, BTN_TOUCH, 1);
 	else
 		input_report_key(dev, BTN_TOUCH, 0);
 
+	alps_report_semi_mt_data(dev, fingers, x1, y1, x2, y2);
+
+	input_report_key(dev, BTN_TOOL_FINGER, fingers == 1);
+	input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2);
+	input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3);
+	input_report_key(dev, BTN_TOOL_QUADTAP, fingers == 4);
+
+	input_report_key(dev, BTN_LEFT, left);
+	input_report_key(dev, BTN_RIGHT, right);
+
 	if (z > 0) {
 		input_report_abs(dev, ABS_X, x);
 		input_report_abs(dev, ABS_Y, y);
 	}
 	input_report_abs(dev, ABS_PRESSURE, z);
 
-	input_report_key(dev, BTN_TOOL_FINGER, z > 0);
-	input_report_key(dev, BTN_LEFT, left);
-	input_report_key(dev, BTN_RIGHT, right);
-
 	input_sync(dev);
 }
 
@@ -1567,8 +1627,18 @@
 		set_bit(BTN_TOOL_QUADTAP, dev1->keybit);
 		/* fall through */
 	case ALPS_PROTO_V4:
-		input_set_abs_params(dev1, ABS_X, 0, ALPS_V3_X_MAX, 0, 0);
-		input_set_abs_params(dev1, ABS_Y, 0, ALPS_V3_Y_MAX, 0, 0);
+		set_bit(INPUT_PROP_SEMI_MT, dev1->propbit);
+		input_mt_init_slots(dev1, 2);
+                input_set_abs_params(dev1, ABS_X, 0, ALPS_V3_X_MAX, 0, 0);
+                input_set_abs_params(dev1, ABS_Y, 0, ALPS_V3_Y_MAX, 0, 0);
+
+		input_set_abs_params(dev1, ABS_MT_POSITION_X, 0, 
ALPS_V3_X_MAX, 0, 0);
+		input_set_abs_params(dev1, ABS_MT_POSITION_Y, 0, 
ALPS_V3_Y_MAX, 0, 0);
+
+		set_bit(BTN_TOOL_DOUBLETAP, dev1->keybit);
+		set_bit(BTN_TOOL_TRIPLETAP, dev1->keybit);
+		set_bit(BTN_TOOL_QUADTAP, dev1->keybit);
+		/* fall through */
 		break;
 	}
 
--- drivers/input/mouse/alps.h	2012-03-19 01:15:34.000000000 +0200
+++ drivers/input/mouse/alps.h.new	2012-04-09 17:17:32.733618703 +0300
@@ -39,6 +39,8 @@
 	int prev_fin;			/* Finger bit from previous packet */
 	int multi_packet;		/* Multi-packet data in progress */
 	unsigned char multi_data[6];	/* Saved multi-packet data */
+	unsigned char multi_data_v4[6];
+	int last_fingers;
 	u8 quirks;
 	struct timer_list timer;
 };


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

end of thread, other threads:[~2012-04-17 15:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-10 14:01 ALPS v4 Semi-mt Support George Pantalos
  -- strict thread matches above, loose matches on Subject: below --
2012-04-10 14:02 George Pantalos
2012-04-10 15:21 ` Seth Forshee
2012-04-10 21:59   ` Seth Forshee
2012-04-16 14:24     ` George Pantalos
2012-04-16 21:24       ` Seth Forshee
2012-04-16 22:21         ` George Pantalos
2012-04-17 13:16           ` Seth Forshee
2012-04-17  0:52         ` George Pantalos
2012-04-17 15:22           ` Seth Forshee

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