Commit a8a09c85 authored by Jason Gerecke's avatar Jason Gerecke Committed by Jiri Kosina

HID: wacom: Replace magic masks and comparisons with switch cases

Reasoning through the conditions under which a particular block of code
in 'wacom_intuos_general' will be reached is not at all easy due to the
sheer number of magic masks and comparisons. Remove these and replace
them with a switch statement over the various 'types' of packets that
will be encountered.
Signed-off-by: default avatarJason Gerecke <jason.gerecke@wacom.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 16e0a6a0
...@@ -886,6 +886,7 @@ static int wacom_intuos_general(struct wacom_wac *wacom) ...@@ -886,6 +886,7 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
unsigned char *data = wacom->data; unsigned char *data = wacom->data;
struct input_dev *input = wacom->pen_input; struct input_dev *input = wacom->pen_input;
int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0; int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
unsigned char type = (data[1] >> 1) & 0x0F;
unsigned int t; unsigned int t;
if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ && if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ &&
...@@ -902,8 +903,12 @@ static int wacom_intuos_general(struct wacom_wac *wacom) ...@@ -902,8 +903,12 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f)); input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
} }
/* general pen packet */ switch (type) {
if ((data[1] & 0xb8) == 0xa0) { case 0x00:
case 0x01:
case 0x02:
case 0x03:
/* general pen packet */
t = (data[6] << 2) | ((data[7] >> 6) & 3); t = (data[6] << 2) | ((data[7] >> 6) & 3);
if (features->pressure_max == 2047) { if (features->pressure_max == 2047) {
t = (t << 1) | (data[1] & 1); t = (t << 1) | (data[1] & 1);
...@@ -917,36 +922,40 @@ static int wacom_intuos_general(struct wacom_wac *wacom) ...@@ -917,36 +922,40 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
input_report_key(input, BTN_STYLUS, data[1] & 2); input_report_key(input, BTN_STYLUS, data[1] & 2);
input_report_key(input, BTN_STYLUS2, data[1] & 4); input_report_key(input, BTN_STYLUS2, data[1] & 4);
input_report_key(input, BTN_TOUCH, t > 10); input_report_key(input, BTN_TOUCH, t > 10);
} break;
/* airbrush second packet */ case 0x0a:
if ((data[1] & 0xbc) == 0xb4) { case 0x0b:
/* airbrush second packet */
input_report_abs(input, ABS_WHEEL, input_report_abs(input, ABS_WHEEL,
(data[6] << 2) | ((data[7] >> 6) & 3)); (data[6] << 2) | ((data[7] >> 6) & 3));
input_report_abs(input, ABS_TILT_X, input_report_abs(input, ABS_TILT_X,
(((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64); (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64); input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
} break;
/* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */ case 0x05:
if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0 || (data[1] & 0xbc) == 0xac) { case 0x07:
/* Rotation packet */
if (data[1] & 0x02) { if (features->type >= INTUOS3S) {
/* Rotation packet */ /* I3 marker pen rotation */
if (features->type >= INTUOS3S) { t = (data[6] << 3) | ((data[7] >> 5) & 7);
/* I3 marker pen rotation */ t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
t = (data[6] << 3) | ((data[7] >> 5) & 7); ((t-1) / 2 + 450)) : (450 - t / 2) ;
t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) : input_report_abs(input, ABS_Z, t);
((t-1) / 2 + 450)) : (450 - t / 2) ; } else {
input_report_abs(input, ABS_Z, t); /* 4D mouse rotation packet */
} else { t = (data[6] << 3) | ((data[7] >> 5) & 7);
/* 4D mouse rotation packet */ input_report_abs(input, ABS_RZ, (data[7] & 0x20) ?
t = (data[6] << 3) | ((data[7] >> 5) & 7); ((t - 1) / 2) : -t / 2);
input_report_abs(input, ABS_RZ, (data[7] & 0x20) ? }
((t - 1) / 2) : -t / 2); break;
}
} else if (!(data[1] & 0x10) && features->type < INTUOS3S) { /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */
case 0x04:
case 0x06:
case 0x08:
if (features->type < INTUOS3S && type != 0x08) {
/* 4D mouse packet */ /* 4D mouse packet */
input_report_key(input, BTN_LEFT, data[8] & 0x01); input_report_key(input, BTN_LEFT, data[8] & 0x01);
input_report_key(input, BTN_MIDDLE, data[8] & 0x02); input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
...@@ -956,8 +965,8 @@ static int wacom_intuos_general(struct wacom_wac *wacom) ...@@ -956,8 +965,8 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
input_report_key(input, BTN_EXTRA, data[8] & 0x10); input_report_key(input, BTN_EXTRA, data[8] & 0x10);
t = (data[6] << 2) | ((data[7] >> 6) & 3); t = (data[6] << 2) | ((data[7] >> 6) & 3);
input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t); input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
}
} else if (wacom->tool[idx] == BTN_TOOL_MOUSE) { else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
/* I4 mouse */ /* I4 mouse */
if (features->type >= INTUOS4S && features->type <= INTUOSPL) { if (features->type >= INTUOS4S && features->type <= INTUOSPL) {
input_report_key(input, BTN_LEFT, data[6] & 0x01); input_report_key(input, BTN_LEFT, data[6] & 0x01);
...@@ -985,10 +994,11 @@ static int wacom_intuos_general(struct wacom_wac *wacom) ...@@ -985,10 +994,11 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
input_report_key(input, BTN_EXTRA, data[8] & 0x20); input_report_key(input, BTN_EXTRA, data[8] & 0x20);
} }
} }
} else if ((features->type < INTUOS3S || features->type == INTUOS3L || }
features->type == INTUOS4L || features->type == INTUOS5L || else if ((features->type < INTUOS3S || features->type == INTUOS3L ||
features->type == INTUOSPL) && features->type == INTUOS4L || features->type == INTUOS5L ||
wacom->tool[idx] == BTN_TOOL_LENS) { features->type == INTUOSPL) &&
wacom->tool[idx] == BTN_TOOL_LENS) {
/* Lens cursor packets */ /* Lens cursor packets */
input_report_key(input, BTN_LEFT, data[8] & 0x01); input_report_key(input, BTN_LEFT, data[8] & 0x01);
input_report_key(input, BTN_MIDDLE, data[8] & 0x02); input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
...@@ -996,6 +1006,15 @@ static int wacom_intuos_general(struct wacom_wac *wacom) ...@@ -996,6 +1006,15 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
input_report_key(input, BTN_SIDE, data[8] & 0x10); input_report_key(input, BTN_SIDE, data[8] & 0x10);
input_report_key(input, BTN_EXTRA, data[8] & 0x08); input_report_key(input, BTN_EXTRA, data[8] & 0x08);
} }
break;
case 0x09:
case 0x0c:
case 0x0d:
case 0x0e:
case 0x0f:
/* unhandled */
break;
} }
input_report_abs(input, ABS_MISC, wacom->id[idx]); /* report tool id */ input_report_abs(input, ABS_MISC, wacom->id[idx]); /* report tool id */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment