From patchwork Fri Nov 1 20:16:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 3127601 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id ADB909F3C4 for ; Fri, 1 Nov 2013 20:16:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AF32D204AE for ; Fri, 1 Nov 2013 20:16:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 83F6C204CF for ; Fri, 1 Nov 2013 20:16:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753230Ab3KAUQx (ORCPT ); Fri, 1 Nov 2013 16:16:53 -0400 Received: from mail-ee0-f48.google.com ([74.125.83.48]:58041 "EHLO mail-ee0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753223Ab3KAUQx (ORCPT ); Fri, 1 Nov 2013 16:16:53 -0400 Received: by mail-ee0-f48.google.com with SMTP id d49so4927eek.7 for ; Fri, 01 Nov 2013 13:16:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=B/v6oSxUI8fQAnYBxlILj9rez9+IJd3BmHwIG5OWw24=; b=dyOSD7xWYapcD7XmJ9NlQZ7AoQqMj2ZUFRuxV0LxRTQJjXAJSJwnZaSsnhDxrlDJv0 Yra8DbvzZ+c7aUbII7Rbo8J/J4RCnBFAPLt+jNxu/jLjk2FFglvhv6E4LqapOYafoDQV IH95cCJS/8ztbCmZ+IcYzOOwKHWm+SNZbQviXRdT8/ovv7TpnIXvo4C4wabn4Al9B3Yi /98cpWv/jEHgC/IZUtcMWZOhHrCagWuvNZeVA8qEt/AAJHdT2sA8aHYesTF1CFx69pPT PFBN4hRSvN2FLeZC8jT2v7EcaEun8i/vBTXnYD+G7BI23Tl5vf80cGecK/9ch71Re6G9 7rjg== X-Received: by 10.14.37.4 with SMTP id x4mr4869200eea.16.1383337012379; Fri, 01 Nov 2013 13:16:52 -0700 (PDT) Received: from localhost.localdomain (stgt-5f719f65.pool.mediaWays.net. [95.113.159.101]) by mx.google.com with ESMTPSA id i1sm11797335eeg.0.2013.11.01.13.16.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Nov 2013 13:16:51 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: Dmitry Torokhov , Jiri Kosina , Peter Hutterer , Benjamin Tissoires , David Herrmann Subject: [PATCH 06/13] HID: wiimote: adjust button-mapping to gamepad rules Date: Fri, 1 Nov 2013 21:16:17 +0100 Message-Id: <1383336984-26601-7-git-send-email-dh.herrmann@gmail.com> X-Mailer: git-send-email 1.8.4.1 In-Reply-To: <1383336984-26601-1-git-send-email-dh.herrmann@gmail.com> References: <1383336984-26601-1-git-send-email-dh.herrmann@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Our gamepad API (./Documentation/input/gamepad.txt) clearly defines rules how to map buttons for gamepads. A wiimote can easily be used as gamepad and provides most of the features. Unfortunately, the gamepad API didn't exist when hid-wiimote was written. This patch changes the button-mappings to comply to gamepad rules. For compatibility reasons, we keep the old mappings if legacy-mode was enabled. Signed-off-by: David Herrmann --- drivers/hid/hid-wiimote-modules.c | 49 ++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/drivers/hid/hid-wiimote-modules.c b/drivers/hid/hid-wiimote-modules.c index 6b61f01..372fec1 100644 --- a/drivers/hid/hid-wiimote-modules.c +++ b/drivers/hid/hid-wiimote-modules.c @@ -48,7 +48,7 @@ * It uses the shared input device. */ -static const __u16 wiimod_keys_map[] = { +static const __u16 wiimod_keys_map_legacy[] = { KEY_LEFT, /* WIIPROTO_KEY_LEFT */ KEY_RIGHT, /* WIIPROTO_KEY_RIGHT */ KEY_UP, /* WIIPROTO_KEY_UP */ @@ -62,29 +62,48 @@ static const __u16 wiimod_keys_map[] = { BTN_MODE, /* WIIPROTO_KEY_HOME */ }; +static const __u16 wiimod_keys_map[] = { + BTN_DPAD_LEFT, /* WIIPROTO_KEY_LEFT */ + BTN_DPAD_RIGHT, /* WIIPROTO_KEY_RIGHT */ + BTN_DPAD_UP, /* WIIPROTO_KEY_UP */ + BTN_DPAD_DOWN, /* WIIPROTO_KEY_DOWN */ + BTN_START, /* WIIPROTO_KEY_PLUS */ + BTN_SELECT, /* WIIPROTO_KEY_MINUS */ + BTN_TRIGGER_HAPPY1, /* WIIPROTO_KEY_ONE */ + BTN_TRIGGER_HAPPY2, /* WIIPROTO_KEY_TWO */ + BTN_SOUTH, /* WIIPROTO_KEY_A */ + BTN_TR, /* WIIPROTO_KEY_B */ + BTN_MODE, /* WIIPROTO_KEY_HOME */ +}; + static void wiimod_keys_in_keys(struct wiimote_data *wdata, const __u8 *keys) { - input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_LEFT], + const __u16 *map = wiimod_keys_map; + + if (wdata->state.flags & WIIPROTO_FLAG_LEGACY) + map = wiimod_keys_map_legacy; + + input_report_key(wdata->input, map[WIIPROTO_KEY_LEFT], !!(keys[0] & 0x01)); - input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_RIGHT], + input_report_key(wdata->input, map[WIIPROTO_KEY_RIGHT], !!(keys[0] & 0x02)); - input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_DOWN], + input_report_key(wdata->input, map[WIIPROTO_KEY_DOWN], !!(keys[0] & 0x04)); - input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_UP], + input_report_key(wdata->input, map[WIIPROTO_KEY_UP], !!(keys[0] & 0x08)); - input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_PLUS], + input_report_key(wdata->input, map[WIIPROTO_KEY_PLUS], !!(keys[0] & 0x10)); - input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_TWO], + input_report_key(wdata->input, map[WIIPROTO_KEY_TWO], !!(keys[1] & 0x01)); - input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_ONE], + input_report_key(wdata->input, map[WIIPROTO_KEY_ONE], !!(keys[1] & 0x02)); - input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_B], + input_report_key(wdata->input, map[WIIPROTO_KEY_B], !!(keys[1] & 0x04)); - input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_A], + input_report_key(wdata->input, map[WIIPROTO_KEY_A], !!(keys[1] & 0x08)); - input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_MINUS], + input_report_key(wdata->input, map[WIIPROTO_KEY_MINUS], !!(keys[1] & 0x10)); - input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_HOME], + input_report_key(wdata->input, map[WIIPROTO_KEY_HOME], !!(keys[1] & 0x80)); input_sync(wdata->input); } @@ -92,11 +111,15 @@ static void wiimod_keys_in_keys(struct wiimote_data *wdata, const __u8 *keys) static int wiimod_keys_probe(const struct wiimod_ops *ops, struct wiimote_data *wdata) { + const __u16 *map = wiimod_keys_map; unsigned int i; + if (wdata->state.flags & WIIPROTO_FLAG_LEGACY) + map = wiimod_keys_map_legacy; + set_bit(EV_KEY, wdata->input->evbit); for (i = 0; i < WIIPROTO_KEY_COUNT; ++i) - set_bit(wiimod_keys_map[i], wdata->input->keybit); + set_bit(map[i], wdata->input->keybit); return 0; }