From 8b013098be2c91ea5e15225c8b39ace08fdd7448 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Sat, 19 Feb 2022 11:01:50 +0100 Subject: HID: uclogic: Replace pen_frame_flag with subreport_list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace a single pen_frame_flag in struct uclogic_params with subreport_list in struct uclogic_params_pen to prepare for handling more subreports in Huion HS610. Signed-off-by: Nikolai Kondrashov Signed-off-by: José Expósito Signed-off-by: Jiri Kosina --- drivers/hid/hid-uclogic-core.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'drivers/hid/hid-uclogic-core.c') diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c index 26849f1f5459..7092f86517a5 100644 --- a/drivers/hid/hid-uclogic-core.c +++ b/drivers/hid/hid-uclogic-core.c @@ -350,26 +350,40 @@ static int uclogic_raw_event(struct hid_device *hdev, unsigned int report_id = report->id; struct uclogic_drvdata *drvdata = hid_get_drvdata(hdev); struct uclogic_params *params = &drvdata->params; + struct uclogic_params_pen_subreport *subreport; + struct uclogic_params_pen_subreport *subreport_list_end; /* Do not handle anything but input reports */ if (report->type != HID_INPUT_REPORT) return 0; - /* Tweak pen reports, if necessary */ - if ((report_id == params->pen.id) && (size >= 2)) { - /* If it's the "virtual" frame controls report */ - if (params->frame.id != 0 && - data[1] & params->pen_frame_flag) { - /* Change to virtual frame controls report ID */ - report_id = data[0] = params->frame.id; - } else { - return uclogic_raw_event_pen(drvdata, data, size); + while (true) { + /* Tweak pen reports, if necessary */ + if ((report_id == params->pen.id) && (size >= 2)) { + subreport_list_end = + params->pen.subreport_list + + ARRAY_SIZE(params->pen.subreport_list); + /* Try to match a subreport */ + for (subreport = params->pen.subreport_list; + subreport < subreport_list_end && + (data[1] & subreport->mask) != subreport->mask; + subreport++); + /* If a subreport matched */ + if (subreport < subreport_list_end) { + /* Change to subreport ID, and restart */ + report_id = data[0] = subreport->id; + continue; + } else { + return uclogic_raw_event_pen(drvdata, data, size); + } } - } - /* Tweak frame control reports, if necessary */ - if (report_id == params->frame.id) - return uclogic_raw_event_frame(drvdata, data, size); + /* Tweak frame control reports, if necessary */ + if (report_id == params->frame.id) + return uclogic_raw_event_frame(drvdata, data, size); + + break; + } return 0; } -- cgit v1.2.3