diff options
author | Hans de Goede <hdegoede@redhat.com> | 2014-07-26 01:38:51 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2014-07-26 17:03:14 -0400 |
commit | 036e6c7b541a9a57b4e294ee4727045d81f68ca0 (patch) | |
tree | 7472d338a769a1a5aeec098a0b8a039cfa1d88e7 /drivers/input/mouse | |
parent | 40e8f53bffe074e6cd409cf484e4b55c114c93d6 (diff) |
Input: alps - process_bitmap: add alps_get_bitmap_points() helper function
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>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/mouse')
-rw-r--r-- | drivers/input/mouse/alps.c | 75 | ||||
-rw-r--r-- | 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 abe9f9bdf69a..c6af590a07d3 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, | |||
328 | } | 328 | } |
329 | } | 329 | } |
330 | 330 | ||
331 | static void alps_get_bitmap_points(unsigned int map, | ||
332 | struct alps_bitmap_point *low, | ||
333 | struct alps_bitmap_point *high, | ||
334 | int *fingers) | ||
335 | { | ||
336 | struct alps_bitmap_point *point; | ||
337 | int i, bit, prev_bit = 0; | ||
338 | |||
339 | point = low; | ||
340 | for (i = 0; map != 0; i++, map >>= 1) { | ||
341 | bit = map & 1; | ||
342 | if (bit) { | ||
343 | if (!prev_bit) { | ||
344 | point->start_bit = i; | ||
345 | (*fingers)++; | ||
346 | } | ||
347 | point->num_bits++; | ||
348 | } else { | ||
349 | if (prev_bit) | ||
350 | point = high; | ||
351 | else | ||
352 | point->num_bits = 0; | ||
353 | } | ||
354 | prev_bit = bit; | ||
355 | } | ||
356 | } | ||
357 | |||
331 | /* | 358 | /* |
332 | * Process bitmap data from v3 and v4 protocols. Returns the number of | 359 | * Process bitmap data from v3 and v4 protocols. Returns the number of |
333 | * fingers detected. A return value of 0 means at least one of the | 360 | * 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, | |||
342 | unsigned int x_map, unsigned int y_map, | 369 | unsigned int x_map, unsigned int y_map, |
343 | int *x1, int *y1, int *x2, int *y2) | 370 | int *x1, int *y1, int *x2, int *y2) |
344 | { | 371 | { |
345 | struct alps_bitmap_point { | 372 | int i, fingers_x = 0, fingers_y = 0, fingers; |
346 | int start_bit; | ||
347 | int num_bits; | ||
348 | }; | ||
349 | |||
350 | int fingers_x = 0, fingers_y = 0, fingers; | ||
351 | int i, bit, prev_bit; | ||
352 | struct alps_bitmap_point x_low = {0,}, x_high = {0,}; | 373 | struct alps_bitmap_point x_low = {0,}, x_high = {0,}; |
353 | struct alps_bitmap_point y_low = {0,}, y_high = {0,}; | 374 | struct alps_bitmap_point y_low = {0,}, y_high = {0,}; |
354 | struct alps_bitmap_point *point; | ||
355 | 375 | ||
356 | if (!x_map || !y_map) | 376 | if (!x_map || !y_map) |
357 | return 0; | 377 | return 0; |
358 | 378 | ||
359 | *x1 = *y1 = *x2 = *y2 = 0; | 379 | *x1 = *y1 = *x2 = *y2 = 0; |
360 | 380 | ||
361 | prev_bit = 0; | 381 | alps_get_bitmap_points(x_map, &x_low, &x_high, &fingers_x); |
362 | point = &x_low; | 382 | alps_get_bitmap_points(y_map, &y_low, &y_high, &fingers_y); |
363 | for (i = 0; x_map != 0; i++, x_map >>= 1) { | ||
364 | bit = x_map & 1; | ||
365 | if (bit) { | ||
366 | if (!prev_bit) { | ||
367 | point->start_bit = i; | ||
368 | fingers_x++; | ||
369 | } | ||
370 | point->num_bits++; | ||
371 | } else { | ||
372 | if (prev_bit) | ||
373 | point = &x_high; | ||
374 | else | ||
375 | point->num_bits = 0; | ||
376 | } | ||
377 | prev_bit = bit; | ||
378 | } | ||
379 | |||
380 | prev_bit = 0; | ||
381 | point = &y_low; | ||
382 | for (i = 0; y_map != 0; i++, y_map >>= 1) { | ||
383 | bit = y_map & 1; | ||
384 | if (bit) { | ||
385 | if (!prev_bit) { | ||
386 | point->start_bit = i; | ||
387 | fingers_y++; | ||
388 | } | ||
389 | point->num_bits++; | ||
390 | } else { | ||
391 | if (prev_bit) | ||
392 | point = &y_high; | ||
393 | else | ||
394 | point->num_bits = 0; | ||
395 | } | ||
396 | prev_bit = bit; | ||
397 | } | ||
398 | 383 | ||
399 | /* | 384 | /* |
400 | * Fingers can overlap, so we use the maximum count of fingers | 385 | * 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 6d2666c0d63a..e900a08b42e5 100644 --- a/drivers/input/mouse/alps.h +++ b/drivers/input/mouse/alps.h | |||
@@ -65,6 +65,11 @@ struct alps_nibble_commands { | |||
65 | unsigned char data; | 65 | unsigned char data; |
66 | }; | 66 | }; |
67 | 67 | ||
68 | struct alps_bitmap_point { | ||
69 | int start_bit; | ||
70 | int num_bits; | ||
71 | }; | ||
72 | |||
68 | /** | 73 | /** |
69 | * struct alps_fields - decoded version of the report packet | 74 | * struct alps_fields - decoded version of the report packet |
70 | * @x_map: Bitmap of active X positions for MT. | 75 | * @x_map: Bitmap of active X positions for MT. |