The HID standard defines usages that allow digitizers to report the pen's
height, tilt, and rotation and which are used by Wacom's new "MobileStudio
Pro" devices.

Note that 'hidinput_calc_abs_res' expects ABS_Z (historically used by our
driver to report twist) to have linear units. To ensure it calculates a
resolution with the actually-angular units provided in the HID descriptor
we nedd to lie and tell it we're calculating it for the (rotational) ABS_RZ
axis instead.

Signed-off-by: Jason Gerecke <jason.gere...@wacom.com>
Reviewed-by: Benjamin Tissoires <benjamin.tissoi...@redhat.com>
[jason.gere...@wacom.com: Imported into input-wacom repository (50066a0)]
Signed-off-by: Jason Gerecke <jason.gere...@wacom.com>
[jason.gere...@wacom.com: backported from input-wacom repository (84e7649)]
Signed-off-by: Jason Gerecke <jason.gere...@wacom.com>
---
 3.17/wacom_wac.c | 28 ++++++++++++++++++++++++++--
 3.17/wacom_wac.h | 12 ++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/3.17/wacom_wac.c b/3.17/wacom_wac.c
index c610f3f..8b50416 100644
--- a/3.17/wacom_wac.c
+++ b/3.17/wacom_wac.c
@@ -1447,6 +1447,11 @@ static void wacom_map_usage(struct input_dev *input, 
struct hid_usage *usage,
 {
        int fmin = field->logical_minimum;
        int fmax = field->logical_maximum;
+       int resolution_code = code;
+
+       if (usage->hid == HID_DG_TWIST) {
+               resolution_code = ABS_RZ;
+       }
 
        usage->type = type;
        usage->code = code;
@@ -1457,7 +1462,7 @@ static void wacom_map_usage(struct input_dev *input, 
struct hid_usage *usage,
        case EV_ABS:
                input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
                input_abs_set_res(input, code,
-                                 hidinput_calc_abs_res(field, code));
+                                 hidinput_calc_abs_res(field, 
resolution_code));
                break;
        case EV_KEY:
                input_set_capability(input, EV_KEY, code);
@@ -1482,6 +1487,9 @@ static void wacom_wac_pen_usage_mapping(struct hid_device 
*hdev,
        case HID_GD_Y:
                wacom_map_usage(input, usage, field, EV_ABS, ABS_Y, 4);
                break;
+       case HID_GD_Z:
+               wacom_map_usage(input, usage, field, EV_ABS, ABS_DISTANCE, 0);
+               break;
        case HID_DG_TIPPRESSURE:
                wacom_map_usage(input, usage, field, EV_ABS, ABS_PRESSURE, 0);
                break;
@@ -1492,6 +1500,15 @@ static void wacom_wac_pen_usage_mapping(struct 
hid_device *hdev,
                wacom_map_usage(input, usage, field, EV_KEY,
                                BTN_TOOL_RUBBER, 0);
                break;
+       case HID_DG_TILT_X:
+               wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_X, 0);
+               break;
+       case HID_DG_TILT_Y:
+               wacom_map_usage(input, usage, field, EV_ABS, ABS_TILT_Y, 0);
+               break;
+       case HID_DG_TWIST:
+               wacom_map_usage(input, usage, field, EV_ABS, ABS_Z, 0);
+               break;
        case HID_DG_ERASER:
        case HID_DG_TIPSWITCH:
                wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0);
@@ -1515,8 +1532,15 @@ static int wacom_wac_pen_event(struct hid_device *hdev, 
struct hid_field *field,
        struct wacom_wac *wacom_wac = &wacom->wacom_wac;
        struct input_dev *input = wacom_wac->pen_input;
 
-       /* checking which Tool / tip switch to send */
        switch (usage->hid) {
+       case HID_GD_Z:
+               /*
+                * HID_GD_Z "should increase as the control's position is
+                * moved from high to low", while ABS_DISTANCE instead
+                * increases in value as the tool moves from low to high.
+                */
+               value = field->logical_maximum - value;
+               break;
        case HID_DG_INRANGE:
                wacom_wac->hid_data.inrange_state = value;
                return 0;
diff --git a/3.17/wacom_wac.h b/3.17/wacom_wac.h
index 7ea5794..8faa7fe 100644
--- a/3.17/wacom_wac.h
+++ b/3.17/wacom_wac.h
@@ -84,6 +84,18 @@
 #define WACOM_DEVICETYPE_WL_MONITOR     0x0008
 #define WACOM_DEVICETYPE_DIRECT         0x0010
 
+#ifndef HID_DG_TILT_X
+#define HID_DG_TILT_X                   (HID_UP_DIGITIZER | 0x3D)
+#endif
+
+#ifndef HID_DG_TILT_Y
+#define HID_DG_TILT_Y                   (HID_UP_DIGITIZER | 0x3E)
+#endif
+
+#ifndef HID_DG_TWIST
+#define HID_DG_TWIST                    (HID_UP_DIGITIZER | 0x41)
+#endif
+
 #define WACOM_HID_UP_WACOMDIGITIZER     0xff0d0000
 #define WACOM_HID_WD_DIGITIZER          (WACOM_HID_UP_WACOMDIGITIZER | 0x01)
 #define WACOM_HID_UP_G9                 0xff090000
-- 
2.10.2


------------------------------------------------------------------------------
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to