Some Wacom devices contain contain Pen and Pad usages in
the same report. Future devices of this type may utilize
HID Descriptors.

The generic code path of the Wacom driver previously
assumed pen, touch, and pad reports were delivered in
separate reports. This patch adds support for processing
each collection of a report separately, in order to support
reports with multiple tools.

Signed-off-by: Aaron Armstrong Skomra <sko...@gmail.com>
Reviewed-by: Ping Cheng <ping.ch...@wacom.com>
Reviewed-by: Jason Gerecke <jason.gere...@wacom.com>
Signed-off-by: Jiri Kosina <jkos...@suse.cz>
[aaron.sko...@wacom.com: Imported into input-wacom repository (f8b6a74719b5)]
Signed-off-by: Aaron Armstrong Skomra <aaron.sko...@wacom.com>
[aaron.sko...@wacom.com: Backported from input-wacom repository (1e73b7d08a1a)]
Signed-off-by: Aaron Armstrong Skomra <aaron.sko...@wacom.com>
---
 3.17/wacom_wac.c | 94 ++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 68 insertions(+), 26 deletions(-)

diff --git a/3.17/wacom_wac.c b/3.17/wacom_wac.c
index ef3b48c159e3..162aa2536c25 100644
--- a/3.17/wacom_wac.c
+++ b/3.17/wacom_wac.c
@@ -2088,7 +2088,7 @@ static void wacom_wac_pad_pre_report(struct hid_device 
*hdev,
 }
 
 static void wacom_wac_pad_report(struct hid_device *hdev,
-               struct hid_report *report)
+               struct hid_report *report, struct hid_field *field)
 {
        struct wacom *wacom = hid_get_drvdata(hdev);
        struct wacom_wac *wacom_wac = &wacom->wacom_wac;
@@ -2096,7 +2096,7 @@ static void wacom_wac_pad_report(struct hid_device *hdev,
        bool active = wacom_wac->hid_data.inrange_state != 0;
 
        /* report prox for expresskey events */
-       if ((wacom_equivalent_usage(report->field[0]->physical) == 
HID_DG_TABLETFUNCTIONKEY) &&
+       if ((wacom_equivalent_usage(field->physical) == 
HID_DG_TABLETFUNCTIONKEY) &&
            wacom_wac->hid_data.pad_input_event_flag) {
                input_event(input, EV_ABS, ABS_MISC, active ? PAD_DEVICE_ID : 
0);
                input_sync(input);
@@ -2643,11 +2643,13 @@ void wacom_wac_event(struct hid_device *hdev, struct 
hid_field *field,
                wacom_wac_finger_event(hdev, field, usage, value);
 }
 
-static void wacom_report_events(struct hid_device *hdev, struct hid_report 
*report)
+static void wacom_report_events(struct hid_device *hdev,
+                               struct hid_report *report, int collection_index,
+                               int field_index)
 {
        int r;
 
-       for (r = 0; r < report->maxfield; r++) {
+       for (r = field_index; r < report->maxfield; r++) {
                struct hid_field *field;
                unsigned count, n;
 
@@ -2657,30 +2659,23 @@ static void wacom_report_events(struct hid_device 
*hdev, struct hid_report *repo
                if (!(HID_MAIN_ITEM_VARIABLE & field->flags))
                        continue;
 
-               for (n = 0; n < count; n++)
-                       wacom_wac_event(hdev, field, &field->usage[n], 
field->value[n]);
+               for (n = 0 ; n < count; n++) {
+                       if (field->usage[n].collection_index == 
collection_index)
+                               wacom_wac_event(hdev, field, &field->usage[n],
+                                               field->value[n]);
+                       else
+                               return;
+               }
        }
 }
 
-void wacom_wac_report(struct hid_device *hdev, struct hid_report *report)
+int wacom_wac_collection(struct hid_device *hdev, struct hid_report *report,
+                        int collection_index, struct hid_field *field,
+                        int field_index)
 {
        struct wacom *wacom = hid_get_drvdata(hdev);
-       struct wacom_wac *wacom_wac = &wacom->wacom_wac;
-       struct hid_field *field = report->field[0];
-
-       if (wacom_wac->features.type != HID_GENERIC)
-               return;
-
-       wacom_wac_battery_pre_report(hdev, report);
-
-       if (WACOM_PAD_FIELD(field) && wacom->wacom_wac.pad_input)
-               wacom_wac_pad_pre_report(hdev, report);
-       else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
-               wacom_wac_pen_pre_report(hdev, report);
-       else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
-               wacom_wac_finger_pre_report(hdev, report);
 
-       wacom_report_events(hdev, report);
+       wacom_report_events(hdev, report, collection_index, field_index);
 
        /*
         * Non-input reports may be sent prior to the device being
@@ -2690,16 +2685,63 @@ void wacom_wac_report(struct hid_device *hdev, struct 
hid_report *report)
         * processing functions.
         */
        if (report->type != HID_INPUT_REPORT)
-               return;
-
-       wacom_wac_battery_report(hdev, report);
+               return -1;
 
        if (WACOM_PAD_FIELD(field) && wacom->wacom_wac.pad_input)
-               wacom_wac_pad_report(hdev, report);
+               wacom_wac_pad_report(hdev, report, field);
        else if (WACOM_PEN_FIELD(field) && wacom->wacom_wac.pen_input)
                wacom_wac_pen_report(hdev, report);
        else if (WACOM_FINGER_FIELD(field) && wacom->wacom_wac.touch_input)
                wacom_wac_finger_report(hdev, report);
+
+       return 0;
+}
+
+void wacom_wac_report(struct hid_device *hdev, struct hid_report *report)
+{
+       struct wacom *wacom = hid_get_drvdata(hdev);
+       struct wacom_wac *wacom_wac = &wacom->wacom_wac;
+       struct hid_field *field;
+       bool pad_in_hid_field = false, pen_in_hid_field = false,
+               finger_in_hid_field = false;
+       int r;
+       int prev_collection = -1;
+
+       if (wacom_wac->features.type != HID_GENERIC)
+               return;
+
+       for (r = 0; r < report->maxfield; r++) {
+               field = report->field[r];
+
+               if (WACOM_PAD_FIELD(field))
+                       pad_in_hid_field = true;
+               if (WACOM_PEN_FIELD(field))
+                       pen_in_hid_field = true;
+               if (WACOM_FINGER_FIELD(field))
+                       finger_in_hid_field = true;
+       }
+
+       wacom_wac_battery_pre_report(hdev, report);
+
+       if (pad_in_hid_field && wacom->wacom_wac.pad_input)
+               wacom_wac_pad_pre_report(hdev, report);
+       if (pen_in_hid_field && wacom->wacom_wac.pen_input)
+               wacom_wac_pen_pre_report(hdev, report);
+       if (finger_in_hid_field && wacom->wacom_wac.touch_input)
+               wacom_wac_finger_pre_report(hdev, report);
+
+       for (r = 0; r < report->maxfield; r++) {
+               field = report->field[r];
+
+               if (field->usage[0].collection_index != prev_collection) {
+                       if (wacom_wac_collection(hdev, report,
+                               field->usage[0].collection_index, field, r) < 0)
+                               return;
+                       prev_collection = field->usage[0].collection_index;
+               }
+       }
+
+       wacom_wac_battery_report(hdev, report);
 }
 
 static int wacom_bpt_touch(struct wacom_wac *wacom)
-- 
2.7.4


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to