From: Chris Ye <lzye@google.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Alexandru Ardelean <alexandru.ardelean@analog.com>,
Mark Brown <broonie@kernel.org>
Cc: linzhao.ye@gmail.com, linux-kernel@vger.kernel.org,
trivial@kernel.org, stable@vger.kernel.org,
Chris Ye <lzye@google.com>
Subject: [PATCH] ANDROID: Fix the HID usage of DPAD input event generation.
Date: Wed, 28 Oct 2020 17:00:22 -0700 [thread overview]
Message-ID: <20201029000022.667052-1-lzye@google.com> (raw)
Generic Desktop DPAD usage is mapped by hid-input, that only the first
DPAD usage maps to usage type EV_ABS and code of an axis. If HID
descriptor has DPAD UP/DOWN/LEFT/RIGHT HID usages and each of usage size
is 1 bit, then only the first one will generate input event, the rest of
the HID usages will be assigned to hat direction only.
The hid input event should check the HID report value and generate
HID event for its hat direction.
Test: Connect HID device with Generic Desktop DPAD usage and press the
DPAD to generate input events.
Signed-off-by: Chris Ye <lzye@google.com>
---
drivers/hid/hid-input.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 9770db624bfa..6c1007de3409 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -1269,7 +1269,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
struct input_dev *input;
unsigned *quirks = &hid->quirks;
- if (!usage->type)
+ if (!usage->type && !field->dpad)
return;
if (usage->type == EV_PWR) {
@@ -1286,9 +1286,17 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
int hat_dir = usage->hat_dir;
if (!hat_dir)
hat_dir = (value - usage->hat_min) * 8 / (usage->hat_max - usage->hat_min + 1) + 1;
- if (hat_dir < 0 || hat_dir > 8) hat_dir = 0;
- input_event(input, usage->type, usage->code , hid_hat_to_axis[hat_dir].x);
- input_event(input, usage->type, usage->code + 1, hid_hat_to_axis[hat_dir].y);
+ if (hat_dir < 0 || hat_dir > 8 || value == 0)
+ hat_dir = 0;
+ if (field->dpad) {
+ input_event(input, EV_ABS, field->dpad, hid_hat_to_axis[hat_dir].x);
+ input_event(input, EV_ABS, field->dpad + 1, hid_hat_to_axis[hat_dir].y);
+ } else {
+ input_event(input, usage->type, usage->code,
+ hid_hat_to_axis[hat_dir].x);
+ input_event(input, usage->type, usage->code + 1,
+ hid_hat_to_axis[hat_dir].y);
+ }
return;
}
--
2.29.1.341.ge80a0c044ae-goog
next reply other threads:[~2020-10-29 0:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-29 0:00 Chris Ye [this message]
-- strict thread matches above, loose matches on Subject: below --
2020-10-29 19:47 [PATCH] ANDROID: Fix the HID usage of DPAD input event generation Chris Ye
2020-10-28 23:51 FirstName LastName
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201029000022.667052-1-lzye@google.com \
--to=lzye@google.com \
--cc=alexandru.ardelean@analog.com \
--cc=broonie@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linzhao.ye@gmail.com \
--cc=stable@vger.kernel.org \
--cc=trivial@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).