linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Yunkang Tang <yunkang.tang@cn.alps.com>,
	linux-input@vger.kernel.org, Hans de Goede <hdegoede@redhat.com>
Subject: [PATCH 04/14] alps: process_bitmap: Add alps_get_bitmap_points() helper function
Date: Wed,  9 Jul 2014 17:24:09 +0200	[thread overview]
Message-ID: <1404919459-23561-5-git-send-email-hdegoede@redhat.com> (raw)
In-Reply-To: <1404919459-23561-1-git-send-email-hdegoede@redhat.com>

Factor out the identical code for getting the bitmap points for x and y into
a helper function.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/input/mouse/alps.c | 75 +++++++++++++++++++---------------------------
 drivers/input/mouse/alps.h |  5 ++++
 2 files changed, 35 insertions(+), 45 deletions(-)

diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 5768fb6..00c735d 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -328,6 +328,33 @@ static void alps_process_bitmap_dolphin(struct alps_data *priv,
 	}
 }
 
+static void alps_get_bitmap_points(unsigned int map,
+				   struct alps_bitmap_point *low,
+				   struct alps_bitmap_point *high,
+				   int *fingers)
+{
+	struct alps_bitmap_point *point;
+	int i, bit, prev_bit = 0;
+
+	point = low;
+	for (i = 0; map != 0; i++, map >>= 1) {
+		bit = map & 1;
+		if (bit) {
+			if (!prev_bit) {
+				point->start_bit = i;
+				(*fingers)++;
+			}
+			point->num_bits++;
+		} else {
+			if (prev_bit)
+				point = high;
+			else
+				point->num_bits = 0;
+		}
+		prev_bit = bit;
+	}
+}
+
 /*
  * Process bitmap data from v3 and v4 protocols. Returns the number of
  * fingers detected. A return value of 0 means at least one of the
@@ -342,59 +369,17 @@ static int alps_process_bitmap(struct alps_data *priv,
 			       unsigned int x_map, unsigned int y_map,
 			       int *x1, int *y1, int *x2, int *y2)
 {
-	struct alps_bitmap_point {
-		int start_bit;
-		int num_bits;
-	};
-
-	int fingers_x = 0, fingers_y = 0, fingers;
-	int i, bit, prev_bit;
+	int i, fingers_x = 0, fingers_y = 0, fingers;
 	struct alps_bitmap_point x_low = {0,}, x_high = {0,};
 	struct alps_bitmap_point y_low = {0,}, y_high = {0,};
-	struct alps_bitmap_point *point;
 
 	if (!x_map || !y_map)
 		return 0;
 
 	*x1 = *y1 = *x2 = *y2 = 0;
 
-	prev_bit = 0;
-	point = &x_low;
-	for (i = 0; x_map != 0; i++, x_map >>= 1) {
-		bit = x_map & 1;
-		if (bit) {
-			if (!prev_bit) {
-				point->start_bit = i;
-				fingers_x++;
-			}
-			point->num_bits++;
-		} else {
-			if (prev_bit)
-				point = &x_high;
-			else
-				point->num_bits = 0;
-		}
-		prev_bit = bit;
-	}
-
-	prev_bit = 0;
-	point = &y_low;
-	for (i = 0; y_map != 0; i++, y_map >>= 1) {
-		bit = y_map & 1;
-		if (bit) {
-			if (!prev_bit) {
-				point->start_bit = i;
-				fingers_y++;
-			}
-			point->num_bits++;
-		} else {
-			if (prev_bit)
-				point = &y_high;
-			else
-				point->num_bits = 0;
-		}
-		prev_bit = bit;
-	}
+	alps_get_bitmap_points(x_map, &x_low, &x_high, &fingers_x);
+	alps_get_bitmap_points(y_map, &y_low, &y_high, &fingers_y);
 
 	/*
 	 * Fingers can overlap, so we use the maximum count of fingers
diff --git a/drivers/input/mouse/alps.h b/drivers/input/mouse/alps.h
index 6d2666c..e900a08 100644
--- a/drivers/input/mouse/alps.h
+++ b/drivers/input/mouse/alps.h
@@ -65,6 +65,11 @@ struct alps_nibble_commands {
 	unsigned char data;
 };
 
+struct alps_bitmap_point {
+	int start_bit;
+	int num_bits;
+};
+
 /**
  * struct alps_fields - decoded version of the report packet
  * @x_map: Bitmap of active X positions for MT.
-- 
2.0.0


  parent reply	other threads:[~2014-07-09 15:24 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-09 15:24 [PATCH 00/14] alps: bugfixes, cleanups and new hardware support Hans de Goede
2014-07-09 15:24 ` [PATCH 01/14] alps: Fix rushmore packet decoding Hans de Goede
2014-07-09 15:24 ` [PATCH 02/14] alps: Always report 2 fingers (or more) when receiving mt data on v3 models Hans de Goede
2014-07-09 15:24 ` [PATCH 03/14] alps: process_bitmap: Don't invert the Y-axis on Rushmore Hans de Goede
2014-07-09 15:24 ` Hans de Goede [this message]
2014-07-09 15:24 ` [PATCH 05/14] alps: process_bitmap: Fix counting of high point bits Hans de Goede
2014-07-09 15:24 ` [PATCH 06/14] alps: process_bitmap: Round down when spreading adjescent fingers over 2 points Hans de Goede
2014-07-09 15:24 ` [PATCH 07/14] alps: Use struct input_mt_pos to track coordinates Hans de Goede
2014-07-09 15:24 ` [PATCH 08/14] alps: Use input_mt_assign_slots && input_mt_sync_frame instead of DIY Hans de Goede
2014-07-09 15:24 ` [PATCH 09/14] alps: Use single touch data when v3 mt data contains only one finger Hans de Goede
2014-07-09 15:24 ` [PATCH 10/14] alps: Add an alps_report_semi_mt_data function Hans de Goede
2014-07-09 15:24 ` [PATCH 11/14] alps: Report 2 touches when we've > 2 fingers Hans de Goede
2014-07-09 15:24 ` [PATCH 12/14] alps: Change decode function prototype to return an int Hans de Goede
2014-07-09 15:24 ` [PATCH 13/14] alps: Cache firmware version Hans de Goede
2014-07-09 15:24 ` [PATCH 14/14] alps: Add support for v7 devices Hans de Goede
2014-07-26  5:58   ` Dmitry Torokhov
2014-07-26  8:22     ` Hans de Goede
2014-07-26  5:59 ` [PATCH 00/14] alps: bugfixes, cleanups and new hardware support Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1404919459-23561-5-git-send-email-hdegoede@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=yunkang.tang@cn.alps.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).