Received: by 10.223.164.221 with SMTP id h29csp1436499wrb; Wed, 11 Oct 2017 23:23:59 -0700 (PDT) X-Received: by 10.84.179.165 with SMTP id b34mr1265841plc.15.1507789439433; Wed, 11 Oct 2017 23:23:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507789439; cv=none; d=google.com; s=arc-20160816; b=TewQEXYL3nbnVE4cwv4bCC++1oj68efoz5G5UhlRbBOw+R9TFV1dybfEnAyLOvzYMB xTtT9p7mdxasF9Zffxig9aTjwRLBhRg9sbDik2VERSXCoPDwPDrZ5AIxsK1qUG2caMMN WgZ9HHiidZFn71lF5lcWpRUq7nMBCP3IPPL+ZtaQ2xqsxWYK9UVU8gKgCgZu7Az1LjDf xBDrRnNYPMk+U2dIy/X19jM8Rr8LOHTzsxHfOnhwZBtTLiyBwy+udMYKA3P/93ne7kV9 ksigzPVYZ5UO3AO8vwT2oSPQ19RIAq6rhBtVuE/scj1DAvoCdm/kZu2c2AMmPQuo94Hr hB/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=dMB4u6EsBKjQ479fqf+nQ5RZxQAMXedN/dsdLHwpb6U=; b=QwpzcK+yrufFnghFCVwjjzqKRIZ5nf8xdi/Xdkew2bs4sRSHIUPwF18soZZ3zq9puT BUpYjTN7xZE99CQcUZR1HvHNQ80srevePIqgEf1o0tIlLqdoutJ+oD6vn1wVcdxMsw8b 4RxFkzvvH2J01rXnRyxzKcA+fW1C85O4mLVZIaMUK51mTII9+ayYXKDrWrhsdCJIy0MJ pYlHVPpVVgV5Yo2ITY9HBFeOVra5QZcsC+LW3m654izId26KfVNmeFBROruFzY1NFMHl ea14xe+McH3mmymQ127y47MZymo9rKpwzvJIGfSoXPkR3m48WmBdZV6OYQuN9YQGqchp Ei6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BNbVAI6t; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d86si11894972pfb.370.2017.10.11.23.23.45; Wed, 11 Oct 2017 23:23:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BNbVAI6t; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753964AbdJLGWI (ORCPT + 99 others); Thu, 12 Oct 2017 02:22:08 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:45929 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753560AbdJLGVz (ORCPT ); Thu, 12 Oct 2017 02:21:55 -0400 Received: by mail-pf0-f180.google.com with SMTP id d28so3581882pfe.2 for ; Wed, 11 Oct 2017 23:21:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=dMB4u6EsBKjQ479fqf+nQ5RZxQAMXedN/dsdLHwpb6U=; b=BNbVAI6tc9WLDUiSj8oUyXS/tOtiuEHyYJVNwG8AqEeqJUkV4ZaXdSy5GJX1ZrRRNU PMS8xChiJhNmg8xRy+ZFHxE8WjXcXJNwS0UVaYmsNk82kmWbmk2YQ7EX1HHQbL1eCWBl 3LFQA/Mh0Hy9gqXsrvhnyKWIoT6CP/3TNJ++M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=dMB4u6EsBKjQ479fqf+nQ5RZxQAMXedN/dsdLHwpb6U=; b=iVuFeo/JwF2NSR/klURpWFrOcmX2Kx0pIMVu6J2b86LpGXy2G9gChbWBluj/P4Kz3M utH+azazcoaG7B02aXGTeEDM/HBIcevgZqmy5kc7a2SQkd/FJY1cDDQKc+3jg46Ibmdj OdQ9w7pIKcQm7capMT23wd0J8eSXwecATOeE3qDnop9C4LQ+5VEyimbMKOEXS1lP0972 zBBzpwwklsFDm65YQ+vZSfoCztVZrPaPyjXanikFuE2h7j6MQCFbFeYiejhWYedKTcsQ 1qgynD4C6MqzAF35Vemv279X8uzi/SOUZCKi1Vd50qCcQ3ECUMgffdaDK8gp7CiudUwv 9/OQ== X-Gm-Message-State: AMCzsaV1NBnBIA8BM+6KV3d3l0rTdH0q409lxBwgoho3Aa9RUpHMxHgG KIohDbMXKj5fzkvaGWP82NqE+DpJipk= X-Google-Smtp-Source: AOwi7QALmSbyLodAc4RNFhttj3dG2xOK4q8aSfTU0/cJzHS93CqlsBc0gmqqnEDBH4wp/f4eRDEzdw== X-Received: by 10.99.105.196 with SMTP id e187mr1225985pgc.360.1507789314220; Wed, 11 Oct 2017 23:21:54 -0700 (PDT) Received: from wnhuang0.tpe.corp.google.com ([2401:fa00:1:b:8c45:d2ad:712:b1f6]) by smtp.gmail.com with ESMTPSA id s88sm6275971pfe.36.2017.10.11.23.21.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Oct 2017 23:21:53 -0700 (PDT) From: Wei-Ning Huang X-Google-Original-From: Wei-Ning Huang To: LKML , Linux Input Cc: Dmitry Torokhov , Jiri Kosina , Benjamin Tissoires , Peter Hutterer , Henrik Rydberg , Wei-Ning Huang , Wei-Ning Huang , dmitry.torokhov@gmail.com, corbet@lwn.net, linux-doc@vger.kernel.org Subject: [PATCH v5] HID: hid-multitouch: support fine-grain orientation reporting Date: Thu, 12 Oct 2017 14:21:43 +0800 Message-Id: <20171012062143.39785-1-wnhuang@google.com> X-Mailer: git-send-email 2.12.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wei-Ning Huang The current hid-multitouch driver only allow the report of two orientations, vertical and horizontal. We use the Azimuth orientation usage 0x3F under the Digitizer usage page to report orientation if the device supports it. Changelog: v1 -> v2: - Fix commit message. - Remove resolution reporting for ABS_MT_ORIENTATION. v2 -> v3: - Fix commit message. v3 -> v4: - Fix ABS_MT_ORIENTATION ABS param range. - Don't set ABS_MT_ORIENTATION in ABS_DG_HEIGHT when it is already set by ABS_DG_AZIMUTH. v4 -> v5: - Improve multi-touch-protocol.rst documentation. Signed-off-by: Wei-Ning Huang Signed-off-by: Wei-Ning Huang Reviewed-by: Dmitry Torokhov --- Documentation/input/multi-touch-protocol.rst | 9 ++--- drivers/hid/hid-multitouch.c | 52 +++++++++++++++++++++++++--- include/linux/hid.h | 1 + 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/Documentation/input/multi-touch-protocol.rst b/Documentation/input/multi-touch-protocol.rst index 8035868c56bc..b51751a0cd5d 100644 --- a/Documentation/input/multi-touch-protocol.rst +++ b/Documentation/input/multi-touch-protocol.rst @@ -269,10 +269,11 @@ ABS_MT_ORIENTATION The orientation of the touching ellipse. The value should describe a signed quarter of a revolution clockwise around the touch center. The signed value range is arbitrary, but zero should be returned for an ellipse aligned with - the Y axis of the surface, a negative value when the ellipse is turned to - the left, and a positive value when the ellipse is turned to the - right. When completely aligned with the X axis, the range max should be - returned. + the Y axis (north) of the surface, a negative value when the ellipse is + turned to the left, and a positive value when the ellipse is turned to the + right. When aligned with the X axis in the positive direction, the range + max should be returned; when aligned with the X axis in the negative + direction, the range -max should be returned. Touch ellipsis are symmetrical by default. For devices capable of true 360 degree orientation, the reported orientation must exceed the range max to diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 440b999304a5..3317dae64ef7 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -84,11 +84,12 @@ MODULE_LICENSE("GPL"); #define MT_IO_FLAGS_PENDING_SLOTS 2 struct mt_slot { - __s32 x, y, cx, cy, p, w, h; + __s32 x, y, cx, cy, p, w, h, a; __s32 contactid; /* the device ContactID assigned to this slot */ bool touch_state; /* is the touch valid? */ bool inrange_state; /* is the finger in proximity of the sensor? */ bool confidence_state; /* is the touch made by a finger? */ + bool has_azimuth; /* the contact reports azimuth */ }; struct mt_class { @@ -571,8 +572,15 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, if (!(cls->quirks & MT_QUIRK_NO_AREA)) { set_abs(hi->input, ABS_MT_TOUCH_MINOR, field, cls->sn_height); - input_set_abs_params(hi->input, - ABS_MT_ORIENTATION, 0, 1, 0, 0); + + /* + * Only set ABS_MT_ORIENTATION if it is not + * already set by the HID_DG_AZIMUTH usage. + */ + if (!test_bit(ABS_MT_ORIENTATION, + hi->input->absbit)) + input_set_abs_params(hi->input, + ABS_MT_ORIENTATION, 0, 1, 0, 0); } mt_store_field(usage, td, hi); return 1; @@ -591,6 +599,21 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, td->cc_index = field->index; td->cc_value_index = usage->usage_index; return 1; + case HID_DG_AZIMUTH: + hid_map_usage(hi, usage, bit, max, + EV_ABS, ABS_MT_ORIENTATION); + /* + * Azimuth has the range of [0, MAX) representing a full + * revolution. Set ABS_MT_ORIENTATION to a quarter of + * MAX according the definition of ABS_MT_ORIENTATION + */ + input_set_abs_params(hi->input, ABS_MT_ORIENTATION, + -field->logical_maximum / 4, + field->logical_maximum / 4, + cls->sn_move ? + field->logical_maximum / cls->sn_move : 0, 0); + mt_store_field(usage, td, hi); + return 1; case HID_DG_CONTACTMAX: /* we don't set td->last_slot_field as contactcount and * contact max are global to the report */ @@ -683,6 +706,10 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input) int wide = (s->w > s->h); int major = max(s->w, s->h); int minor = min(s->w, s->h); + int orientation = wide; + + if (s->has_azimuth) + orientation = s->a; /* * divided by two to match visual scale of touch @@ -699,7 +726,8 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input) input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy); input_event(input, EV_ABS, ABS_MT_DISTANCE, !s->touch_state); - input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide); + input_event(input, EV_ABS, ABS_MT_ORIENTATION, + orientation); input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p); input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major); input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, minor); @@ -789,6 +817,22 @@ static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field, break; case HID_DG_CONTACTCOUNT: break; + case HID_DG_AZIMUTH: + /* + * Azimuth is counter-clockwise and ranges from [0, MAX) + * (a full revolution). Convert it to clockwise ranging + * [-MAX/2, MAX/2]. + * + * Note that ABS_MT_ORIENTATION require us to report + * the limit of [-MAX/4, MAX/4], but the value can go + * out of range to [-MAX/2, MAX/2] to report an upside + * down ellipsis. + */ + if (value > field->logical_maximum / 2) + value -= field->logical_maximum; + td->curdata.a = -value; + td->curdata.has_azimuth = true; + break; case HID_DG_TOUCH: /* do nothing */ break; diff --git a/include/linux/hid.h b/include/linux/hid.h index ab05a86269dc..d81b9b6fd83a 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -281,6 +281,7 @@ struct hid_item { #define HID_DG_DEVICECONFIG 0x000d000e #define HID_DG_DEVICESETTINGS 0x000d0023 +#define HID_DG_AZIMUTH 0x000d003f #define HID_DG_CONFIDENCE 0x000d0047 #define HID_DG_WIDTH 0x000d0048 #define HID_DG_HEIGHT 0x000d0049 -- 2.12.2 From 1585561564034287101@xxx Fri Dec 01 06:22:20 +0000 2017 X-GM-THRID: 1585302989845992976 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread