mirror of
https://github.com/edk2-porting/linux-next.git
synced 2025-01-04 19:54:03 +08:00
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>
This commit is contained in:
parent
40e8f53bff
commit
036e6c7b54
@ -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
|
* 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
|
* 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,
|
unsigned int x_map, unsigned int y_map,
|
||||||
int *x1, int *y1, int *x2, int *y2)
|
int *x1, int *y1, int *x2, int *y2)
|
||||||
{
|
{
|
||||||
struct alps_bitmap_point {
|
int i, fingers_x = 0, fingers_y = 0, fingers;
|
||||||
int start_bit;
|
|
||||||
int num_bits;
|
|
||||||
};
|
|
||||||
|
|
||||||
int fingers_x = 0, fingers_y = 0, fingers;
|
|
||||||
int i, bit, prev_bit;
|
|
||||||
struct alps_bitmap_point x_low = {0,}, x_high = {0,};
|
struct alps_bitmap_point x_low = {0,}, x_high = {0,};
|
||||||
struct alps_bitmap_point y_low = {0,}, y_high = {0,};
|
struct alps_bitmap_point y_low = {0,}, y_high = {0,};
|
||||||
struct alps_bitmap_point *point;
|
|
||||||
|
|
||||||
if (!x_map || !y_map)
|
if (!x_map || !y_map)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
*x1 = *y1 = *x2 = *y2 = 0;
|
*x1 = *y1 = *x2 = *y2 = 0;
|
||||||
|
|
||||||
prev_bit = 0;
|
alps_get_bitmap_points(x_map, &x_low, &x_high, &fingers_x);
|
||||||
point = &x_low;
|
alps_get_bitmap_points(y_map, &y_low, &y_high, &fingers_y);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fingers can overlap, so we use the maximum count of fingers
|
* Fingers can overlap, so we use the maximum count of fingers
|
||||||
|
@ -65,6 +65,11 @@ struct alps_nibble_commands {
|
|||||||
unsigned char data;
|
unsigned char data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct alps_bitmap_point {
|
||||||
|
int start_bit;
|
||||||
|
int num_bits;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* struct alps_fields - decoded version of the report packet
|
* struct alps_fields - decoded version of the report packet
|
||||||
* @x_map: Bitmap of active X positions for MT.
|
* @x_map: Bitmap of active X positions for MT.
|
||||||
|
Loading…
Reference in New Issue
Block a user