From patchwork Sun Aug 8 22:53:52 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?w4PigLByaWMgUGllbA==?= X-Patchwork-Id: 118308 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o78Mtqwo026043 for ; Sun, 8 Aug 2010 22:55:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754596Ab0HHWzx (ORCPT ); Sun, 8 Aug 2010 18:55:53 -0400 Received: from mailservice.tudelft.nl ([130.161.131.5]:38102 "EHLO mailservice.tudelft.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754705Ab0HHWzv (ORCPT ); Sun, 8 Aug 2010 18:55:51 -0400 Received: from localhost (localhost [127.0.0.1]) by amavis (Postfix) with ESMTP id 50BE4CC1E7; Mon, 9 Aug 2010 00:55:50 +0200 (CEST) X-Virus-Scanned: amavisd-new at tudelft.nl X-Spam-Flag: NO X-Spam-Score: -22.589 X-Spam-Level: X-Spam-Status: No, score=-22.589 tagged_above=-99 required=5 tests=[BAYES_00=-2.599, PROLO_LEO3=0.01, TUD_REL01=-20] autolearn=ham Received: from mailservice.tudelft.nl ([130.161.131.71]) by localhost (tudelft.nl [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id CXrIL5RgXGoa; Mon, 9 Aug 2010 00:55:49 +0200 (CEST) Received: from smtp-a.tudelft.nl (smtp-a.tudelft.nl [130.161.180.7]) by mx4.tudelft.nl (Postfix) with ESMTP id 4EFF8CC1E6; Mon, 9 Aug 2010 00:55:49 +0200 (CEST) Received: from [172.19.3.21] (63-103-dsl.ipact.nl [84.35.103.63]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-a.tudelft.nl (Postfix) with ESMTP id 14A0AB3A62; Mon, 9 Aug 2010 00:55:49 +0200 (CEST) Message-ID: <4C5F3580.2090805@tudelft.nl> Date: Mon, 09 Aug 2010 00:53:52 +0200 From: =?ISO-8859-1?Q?=C9ric_Piel?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.8) Gecko/20100808 Mandriva/3.1.2-2mdv2011.0 (2011.0) Thunderbird/3.1.2 MIME-Version: 1.0 To: Dmitry Torokhov CC: Henrik Rydberg , Chris Bagwell , "linux-input@vger.kernel.org" , Florian Ragwitz Subject: [PATCH 08/10] elantech: track finger to distinguish coordinates in 2-finger report References: <4C567F27.7070900@tudelft.nl> <4C5697C4.1020801@euromail.se> <4C56A81E.3040703@tudelft.nl> <4C56AA67.8000902@euromail.se> <4C56AD12.1080106@tudelft.nl> <4C56B00B.50204@euromail.se> <4C56B686.60606@tudelft.nl> <4C56BA13.3030104@euromail.se> <4C56BE30.2070807@tudelft.nl> <4C56C213.2010605@euromail.se> <20100802163913.GB3276@core.coreip.homeip.net> <4C5F34F4.7030503@tudelft.nl> In-Reply-To: <4C5F34F4.7030503@tudelft.nl> X-Enigmail-Version: 1.1.2 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sun, 08 Aug 2010 22:55:54 +0000 (UTC) diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c index 7fa4f29..1dd7e7c 100644 --- a/drivers/input/mouse/elantech.c +++ b/drivers/input/mouse/elantech.c @@ -242,6 +242,45 @@ static void elantech_report_absolute_v1(struct psmouse *psmouse) input_sync(dev); } +/* Store the current position of the finger, for tracking when 2 fingers */ +static void track_one_finger(struct elantech_data *etd, unsigned int x, unsigned int y) +{ + etd->prev_x = x; + etd->prev_y = y; +} + +/* Ensure that argument a contains a value closest to ref than b */ +static void find_closest_and_swap(unsigned int *ref, unsigned int *a, unsigned int *b) +{ + int dist_a = abs(*ref - *a); + int dist_b = abs(*ref - *b); + int tmp; + if (dist_b < dist_a) { + tmp = *a; + *a = *b; + *b = tmp; + } + *ref = *a; +} + +/* + * Track the coordinates reported and swap the values to improve the likelihood + * that the coordinates correspond to the real positions of the two fingers. + */ +static void +track_two_fingers(struct elantech_data *etd, + unsigned int *x1, unsigned int *y1, unsigned int *x2, unsigned int *y2) +{ + /* + * As the hardware can only report the coordinates without knowing which one + * corresponds to which finger, we try to guess according to the last known + * position, when using only one finger. + */ + find_closest_and_swap(&etd->prev_x, x1, x2); + find_closest_and_swap(&etd->prev_y, y1, y2); +} + + /* * Interpret complete data packets and report absolute mode input events for * hardware version 2. (6 byte packets) @@ -251,7 +290,7 @@ static void elantech_report_absolute_v2(struct psmouse *psmouse) struct elantech_data *etd = psmouse->private; struct input_dev *dev = psmouse->dev; unsigned char *packet = psmouse->packet; - int fingers, x1, y1, x2, y2, width = 0, pres = 0; + unsigned int fingers, x1, y1, x2, y2, width = 0, pres = 0; /* byte 0: n1 n0 . . . . R L */ fingers = (packet[0] & 0xc0) >> 6; @@ -285,6 +324,10 @@ static void elantech_report_absolute_v2(struct psmouse *psmouse) input_report_abs(dev, ABS_X, x1); input_report_abs(dev, ABS_Y, y1); + /* Only track if we are sure it's real finger coodinates */ + if (fingers == 1) + track_one_finger(etd, x1, y1); + pres = (packet[1] & 0xf0) | ((packet[4] & 0xf0) >> 4); width = ((packet[0] & 0x30) >> 2) | ((packet[3] & 0x30) >> 4); break; @@ -296,37 +339,39 @@ static void elantech_report_absolute_v2(struct psmouse *psmouse) * byte 0: . . ay8 ax8 . . . . * byte 1: ax7 ax6 ax5 ax4 ax3 ax2 ax1 ax0 */ - x1 = ((packet[0] & 0x10) << 4) | packet[1]; + x1 = (((packet[0] & 0x10) << 4) | packet[1]) << 2; /* byte 2: ay7 ay6 ay5 ay4 ay3 ay2 ay1 ay0 */ - y1 = ETP_2FT_YMAX - (((packet[0] & 0x20) << 3) | packet[2]); + y1 = (ETP_2FT_YMAX - (((packet[0] & 0x20) << 3) | packet[2])) << 2; /* * byte 3: . . by8 bx8 . . . . * byte 4: bx7 bx6 bx5 bx4 bx3 bx2 bx1 bx0 */ - x2 = ((packet[3] & 0x10) << 4) | packet[4]; + x2 = (((packet[3] & 0x10) << 4) | packet[4]) << 2; /* byte 5: by7 by8 by5 by4 by3 by2 by1 by0 */ - y2 = ETP_2FT_YMAX - (((packet[3] & 0x20) << 3) | packet[5]); + y2 = (ETP_2FT_YMAX - (((packet[3] & 0x20) << 3) | packet[5])) << 2; + + track_two_fingers(etd, &x1, &y1, &x2, &y2); /* Multitouch */ - input_report_abs(dev, ABS_MT_POSITION_X, x1 << 2); - input_report_abs(dev, ABS_MT_POSITION_Y, y1 << 2); + input_report_abs(dev, ABS_MT_POSITION_X, x1); + input_report_abs(dev, ABS_MT_POSITION_Y, y1); input_mt_sync(dev); - input_report_abs(dev, ABS_MT_POSITION_X, x2 << 2); - input_report_abs(dev, ABS_MT_POSITION_Y, y2 << 2); + input_report_abs(dev, ABS_MT_POSITION_X, x2); + input_report_abs(dev, ABS_MT_POSITION_Y, y2); input_mt_sync(dev); /* * For compatibility with the X Synaptics driver scale up * one coordinate and report as ordinary mouse movent */ - input_report_abs(dev, ABS_X, x1 << 2); - input_report_abs(dev, ABS_Y, y1 << 2); + input_report_abs(dev, ABS_X, x1); + input_report_abs(dev, ABS_Y, y1); /* * For compatibility with the proprietary X Elantech driver * report both coordinates as hat coordinates */ - input_report_abs(dev, ABS_HAT0X, x1); - input_report_abs(dev, ABS_HAT0Y, y1); - input_report_abs(dev, ABS_HAT1X, x2); - input_report_abs(dev, ABS_HAT1Y, y2); + input_report_abs(dev, ABS_HAT0X, x1 >> 2); + input_report_abs(dev, ABS_HAT0Y, y1 >> 2); + input_report_abs(dev, ABS_HAT1X, x2 >> 2); + input_report_abs(dev, ABS_HAT1Y, y2 >> 2); /* Unknown so just report sensible values */ pres = 127; diff --git a/drivers/input/mouse/elantech.h b/drivers/input/mouse/elantech.h index f6e3be5..fa9a6b4 100644 --- a/drivers/input/mouse/elantech.h +++ b/drivers/input/mouse/elantech.h @@ -111,6 +111,8 @@ struct elantech_data { unsigned char hw_version; unsigned int fw_version; unsigned char parity[256]; + unsigned int prev_x; + unsigned int prev_y; }; enum paritycheck_types {