From patchwork Fri Nov 1 20:16:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 3127621 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 23C98BEEB2 for ; Fri, 1 Nov 2013 20:17:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0CAD3204AE for ; Fri, 1 Nov 2013 20:17:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C7192204CF for ; Fri, 1 Nov 2013 20:16:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753282Ab3KAUQ5 (ORCPT ); Fri, 1 Nov 2013 16:16:57 -0400 Received: from mail-ea0-f177.google.com ([209.85.215.177]:38449 "EHLO mail-ea0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753223Ab3KAUQ5 (ORCPT ); Fri, 1 Nov 2013 16:16:57 -0400 Received: by mail-ea0-f177.google.com with SMTP id f15so2253680eak.22 for ; Fri, 01 Nov 2013 13:16:55 -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=A6lSN+0FJjdnBVPDh3R67hkglZ3vHJ4hk38J00AOLEI=; b=sJUv6GPB2uPO7X7V9vLOIPnPy/OKrQeDvYHYJwX4ITykLtnWhbHcQX+EcVtmIQy2ZE QI/TpjhIv5yziadY62vLqqhhZd6JyCXG9+bqozJouVXZhD/VEuk0/H3zk5XQRgjVoEzt UNvaaS42lBtyXDRmN284c6o7QPtGfTZQGWK5eI3GlLcUTrOJfYr0trIc+rKZaAPVZilQ jMqVNp8r8eqQGbyFtGDuNKJMXHoViEoF7AeLQ/Q21/u9Z3IemEnQ8XmjPgnCoe3h7V2o cax0AUdj9/nvcA0NhT37h4zSwEANpHEY4sgRxpr2fYnIrHvkFqdo3RoR2lBuFEV3VtDW C9/w== X-Received: by 10.14.241.74 with SMTP id f50mr4865813eer.29.1383337015846; Fri, 01 Nov 2013 13:16:55 -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.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Nov 2013 13:16:54 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: Dmitry Torokhov , Jiri Kosina , Peter Hutterer , Benjamin Tissoires , David Herrmann Subject: [PATCH 08/13] HID: wiimote: map classic controller as gamepad Date: Fri, 1 Nov 2013 21:16:19 +0100 Message-Id: <1383336984-26601-9-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 Adjust the mappings for the classic-controller extension so it's reported as normal gamepad. Keep the compatibility mappings so legacy-mode still works. Signed-off-by: David Herrmann --- drivers/hid/hid-wiimote-modules.c | 144 ++++++++++++++++++++++++++------------ 1 file changed, 100 insertions(+), 44 deletions(-) diff --git a/drivers/hid/hid-wiimote-modules.c b/drivers/hid/hid-wiimote-modules.c index a02059c..f3de94e 100644 --- a/drivers/hid/hid-wiimote-modules.c +++ b/drivers/hid/hid-wiimote-modules.c @@ -1090,7 +1090,7 @@ enum wiimod_classic_keys { WIIMOD_CLASSIC_KEY_NUM, }; -static const __u16 wiimod_classic_map[] = { +static const __u16 wiimod_classic_map_legacy[] = { BTN_A, /* WIIMOD_CLASSIC_KEY_A */ BTN_B, /* WIIMOD_CLASSIC_KEY_B */ BTN_X, /* WIIMOD_CLASSIC_KEY_X */ @@ -1108,10 +1108,32 @@ static const __u16 wiimod_classic_map[] = { BTN_TR, /* WIIMOD_CLASSIC_KEY_RT */ }; +static const __u16 wiimod_classic_map[] = { + BTN_EAST, /* WIIMOD_CLASSIC_KEY_A */ + BTN_SOUTH, /* WIIMOD_CLASSIC_KEY_B */ + BTN_NORTH, /* WIIMOD_CLASSIC_KEY_X */ + BTN_WEST, /* WIIMOD_CLASSIC_KEY_Y */ + BTN_TL2, /* WIIMOD_CLASSIC_KEY_ZL */ + BTN_TR2, /* WIIMOD_CLASSIC_KEY_ZR */ + BTN_START, /* WIIMOD_CLASSIC_KEY_PLUS */ + BTN_SELECT, /* WIIMOD_CLASSIC_KEY_MINUS */ + BTN_MODE, /* WIIMOD_CLASSIC_KEY_HOME */ + BTN_DPAD_LEFT, /* WIIMOD_CLASSIC_KEY_LEFT */ + BTN_DPAD_RIGHT, /* WIIMOD_CLASSIC_KEY_RIGHT */ + BTN_DPAD_UP, /* WIIMOD_CLASSIC_KEY_UP */ + BTN_DPAD_DOWN, /* WIIMOD_CLASSIC_KEY_DOWN */ + BTN_TL, /* WIIMOD_CLASSIC_KEY_LT */ + BTN_TR, /* WIIMOD_CLASSIC_KEY_RT */ +}; + static void wiimod_classic_in_ext(struct wiimote_data *wdata, const __u8 *ext) { + const __u16 *map = wiimod_classic_map; __s8 rx, ry, lx, ly, lt, rt; + if (wdata->state.flags & WIIPROTO_FLAG_LEGACY) + map = wiimod_classic_map_legacy; + /* Byte | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | * -----+-----+-----+-----+-----+-----+-----+-----+-----+ * 1 | RX <5:4> | LX <5:0> | @@ -1177,66 +1199,75 @@ static void wiimod_classic_in_ext(struct wiimote_data *wdata, const __u8 *ext) rt <<= 1; lt <<= 1; - input_report_abs(wdata->extension.input, ABS_HAT1X, lx - 0x20); - input_report_abs(wdata->extension.input, ABS_HAT1Y, ly - 0x20); - input_report_abs(wdata->extension.input, ABS_HAT2X, rx - 0x20); - input_report_abs(wdata->extension.input, ABS_HAT2Y, ry - 0x20); - input_report_abs(wdata->extension.input, ABS_HAT3X, rt); - input_report_abs(wdata->extension.input, ABS_HAT3Y, lt); + if (wdata->state.flags & WIIPROTO_FLAG_LEGACY) { + input_report_abs(wdata->extension.input, ABS_HAT1X, lx - 0x20); + input_report_abs(wdata->extension.input, ABS_HAT1Y, ly - 0x20); + input_report_abs(wdata->extension.input, ABS_HAT2X, rx - 0x20); + input_report_abs(wdata->extension.input, ABS_HAT2Y, ry - 0x20); + input_report_abs(wdata->extension.input, ABS_HAT3X, rt); + input_report_abs(wdata->extension.input, ABS_HAT3Y, lt); + } else { + input_report_abs(wdata->extension.input, ABS_X, lx - 0x20); + input_report_abs(wdata->extension.input, ABS_Y, 0x20 - ly); + input_report_abs(wdata->extension.input, ABS_RX, rx - 0x20); + input_report_abs(wdata->extension.input, ABS_RY, 0x20 - ry); + input_report_abs(wdata->extension.input, ABS_HAT1X, rt); + input_report_abs(wdata->extension.input, ABS_HAT1Y, lt); + } input_report_key(wdata->extension.input, - wiimod_classic_map[WIIMOD_CLASSIC_KEY_RIGHT], + map[WIIMOD_CLASSIC_KEY_RIGHT], !(ext[4] & 0x80)); input_report_key(wdata->extension.input, - wiimod_classic_map[WIIMOD_CLASSIC_KEY_DOWN], + map[WIIMOD_CLASSIC_KEY_DOWN], !(ext[4] & 0x40)); input_report_key(wdata->extension.input, - wiimod_classic_map[WIIMOD_CLASSIC_KEY_LT], + map[WIIMOD_CLASSIC_KEY_LT], !(ext[4] & 0x20)); input_report_key(wdata->extension.input, - wiimod_classic_map[WIIMOD_CLASSIC_KEY_MINUS], + map[WIIMOD_CLASSIC_KEY_MINUS], !(ext[4] & 0x10)); input_report_key(wdata->extension.input, - wiimod_classic_map[WIIMOD_CLASSIC_KEY_HOME], + map[WIIMOD_CLASSIC_KEY_HOME], !(ext[4] & 0x08)); input_report_key(wdata->extension.input, - wiimod_classic_map[WIIMOD_CLASSIC_KEY_PLUS], + map[WIIMOD_CLASSIC_KEY_PLUS], !(ext[4] & 0x04)); input_report_key(wdata->extension.input, - wiimod_classic_map[WIIMOD_CLASSIC_KEY_RT], + map[WIIMOD_CLASSIC_KEY_RT], !(ext[4] & 0x02)); input_report_key(wdata->extension.input, - wiimod_classic_map[WIIMOD_CLASSIC_KEY_ZL], + map[WIIMOD_CLASSIC_KEY_ZL], !(ext[5] & 0x80)); input_report_key(wdata->extension.input, - wiimod_classic_map[WIIMOD_CLASSIC_KEY_B], + map[WIIMOD_CLASSIC_KEY_B], !(ext[5] & 0x40)); input_report_key(wdata->extension.input, - wiimod_classic_map[WIIMOD_CLASSIC_KEY_Y], + map[WIIMOD_CLASSIC_KEY_Y], !(ext[5] & 0x20)); input_report_key(wdata->extension.input, - wiimod_classic_map[WIIMOD_CLASSIC_KEY_A], + map[WIIMOD_CLASSIC_KEY_A], !(ext[5] & 0x10)); input_report_key(wdata->extension.input, - wiimod_classic_map[WIIMOD_CLASSIC_KEY_X], + map[WIIMOD_CLASSIC_KEY_X], !(ext[5] & 0x08)); input_report_key(wdata->extension.input, - wiimod_classic_map[WIIMOD_CLASSIC_KEY_ZR], + map[WIIMOD_CLASSIC_KEY_ZR], !(ext[5] & 0x04)); if (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE) { input_report_key(wdata->extension.input, - wiimod_classic_map[WIIMOD_CLASSIC_KEY_LEFT], + map[WIIMOD_CLASSIC_KEY_LEFT], !(ext[1] & 0x01)); input_report_key(wdata->extension.input, - wiimod_classic_map[WIIMOD_CLASSIC_KEY_UP], + map[WIIMOD_CLASSIC_KEY_UP], !(ext[0] & 0x01)); } else { input_report_key(wdata->extension.input, - wiimod_classic_map[WIIMOD_CLASSIC_KEY_LEFT], + map[WIIMOD_CLASSIC_KEY_LEFT], !(ext[5] & 0x02)); input_report_key(wdata->extension.input, - wiimod_classic_map[WIIMOD_CLASSIC_KEY_UP], + map[WIIMOD_CLASSIC_KEY_UP], !(ext[5] & 0x01)); } @@ -1270,12 +1301,16 @@ static void wiimod_classic_close(struct input_dev *dev) static int wiimod_classic_probe(const struct wiimod_ops *ops, struct wiimote_data *wdata) { + const __u16 *map = wiimod_classic_map; int ret, i; wdata->extension.input = input_allocate_device(); if (!wdata->extension.input) return -ENOMEM; + if (wdata->state.flags & WIIPROTO_FLAG_LEGACY) + map = wiimod_classic_map_legacy; + input_set_drvdata(wdata->extension.input, wdata); wdata->extension.input->open = wiimod_classic_open; wdata->extension.input->close = wiimod_classic_close; @@ -1288,28 +1323,49 @@ static int wiimod_classic_probe(const struct wiimod_ops *ops, set_bit(EV_KEY, wdata->extension.input->evbit); for (i = 0; i < WIIMOD_CLASSIC_KEY_NUM; ++i) - set_bit(wiimod_classic_map[i], - wdata->extension.input->keybit); + set_bit(map[i], wdata->extension.input->keybit); set_bit(EV_ABS, wdata->extension.input->evbit); - set_bit(ABS_HAT1X, wdata->extension.input->absbit); - set_bit(ABS_HAT1Y, wdata->extension.input->absbit); - set_bit(ABS_HAT2X, wdata->extension.input->absbit); - set_bit(ABS_HAT2Y, wdata->extension.input->absbit); - set_bit(ABS_HAT3X, wdata->extension.input->absbit); - set_bit(ABS_HAT3Y, wdata->extension.input->absbit); - input_set_abs_params(wdata->extension.input, - ABS_HAT1X, -30, 30, 1, 1); - input_set_abs_params(wdata->extension.input, - ABS_HAT1Y, -30, 30, 1, 1); - input_set_abs_params(wdata->extension.input, - ABS_HAT2X, -30, 30, 1, 1); - input_set_abs_params(wdata->extension.input, - ABS_HAT2Y, -30, 30, 1, 1); - input_set_abs_params(wdata->extension.input, - ABS_HAT3X, -30, 30, 1, 1); - input_set_abs_params(wdata->extension.input, - ABS_HAT3Y, -30, 30, 1, 1); + + if (wdata->state.flags & WIIPROTO_FLAG_LEGACY) { + set_bit(ABS_HAT1X, wdata->extension.input->absbit); + set_bit(ABS_HAT1Y, wdata->extension.input->absbit); + set_bit(ABS_HAT2X, wdata->extension.input->absbit); + set_bit(ABS_HAT2Y, wdata->extension.input->absbit); + set_bit(ABS_HAT3X, wdata->extension.input->absbit); + set_bit(ABS_HAT3Y, wdata->extension.input->absbit); + input_set_abs_params(wdata->extension.input, + ABS_HAT1X, -30, 30, 1, 1); + input_set_abs_params(wdata->extension.input, + ABS_HAT1Y, -30, 30, 1, 1); + input_set_abs_params(wdata->extension.input, + ABS_HAT2X, -30, 30, 1, 1); + input_set_abs_params(wdata->extension.input, + ABS_HAT2Y, -30, 30, 1, 1); + input_set_abs_params(wdata->extension.input, + ABS_HAT3X, -30, 30, 1, 1); + input_set_abs_params(wdata->extension.input, + ABS_HAT3Y, -30, 30, 1, 1); + } else { + set_bit(ABS_X, wdata->extension.input->absbit); + set_bit(ABS_Y, wdata->extension.input->absbit); + set_bit(ABS_RX, wdata->extension.input->absbit); + set_bit(ABS_RY, wdata->extension.input->absbit); + set_bit(ABS_HAT1X, wdata->extension.input->absbit); + set_bit(ABS_HAT1Y, wdata->extension.input->absbit); + input_set_abs_params(wdata->extension.input, + ABS_X, -24, 24, 1, 1); + input_set_abs_params(wdata->extension.input, + ABS_Y, -24, 24, 1, 1); + input_set_abs_params(wdata->extension.input, + ABS_RX, -24, 24, 1, 1); + input_set_abs_params(wdata->extension.input, + ABS_RY, -24, 24, 1, 1); + input_set_abs_params(wdata->extension.input, + ABS_HAT1X, 0, 52, 1, 1); + input_set_abs_params(wdata->extension.input, + ABS_HAT1Y, 0, 52, 1, 1); + } ret = input_register_device(wdata->extension.input); if (ret)