From patchwork Thu Oct 6 21:22:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 9365325 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 066556077E for ; Thu, 6 Oct 2016 21:22:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E566029253 for ; Thu, 6 Oct 2016 21:22:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9F7229256; Thu, 6 Oct 2016 21:22:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89B5329253 for ; Thu, 6 Oct 2016 21:22:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935168AbcJFVWq (ORCPT ); Thu, 6 Oct 2016 17:22:46 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:36405 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935071AbcJFVWq (ORCPT ); Thu, 6 Oct 2016 17:22:46 -0400 Received: by mail-qt0-f193.google.com with SMTP id y38so833017qta.3 for ; Thu, 06 Oct 2016 14:22:46 -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=dPC7hKL6ToHdUPKPfBWACvg0ySoOwWvZbO4O3x9YOSw=; b=oBES1DHzpSQjYzBO9OgbfaIoQld4PxXBoJme1Eyl5I6/WnUBWw4DKaUPS1LI55UavV Uklh5Kc4YBeLWCZHKZnmlDZPiadSdCsnrYRB/jxA6ByCAa0KCsFLY0JKCeJX5mAVpEEw 7pOu5HKacB52Tv2rn+05dvKDTEjlqpMWIfYl9/4rW0NLldeKTL8OycLueXeqOEtwUrjO oFgwI3UczkLrc7U+wbdG22mu8v3J7dDerzBY/NoRpy2ZyfW+kTw2qn2f8OjW6XHz4AqP /vsXOo90qrVsWWXixYwOm5qgCoqNouGI1ME67P3hJOZZVEpMVp3DY4BThOiCT/EMQwZ8 9C8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dPC7hKL6ToHdUPKPfBWACvg0ySoOwWvZbO4O3x9YOSw=; b=S8gNBhmsKTXeUOQA1Z1ZQzQcJojkRb1Ax7mfDwkJemrwd03cvc0C2D72sNmVYOS6gw 9pzqYJVEZz+/j8Gtu4u2XqBNH4wf+OiCUmDWBbEaqfddC8XH3SojQ6ZaeI4aJhgymm/P OSVDD36O8OLxjhR5zK1HVql1ImGDfTnZC6YoTsa9qZFtddURpVlAkyjOCgKInCD5+G6m skA7EndauSRLCvljGOriviWaf3p/z8AIA75ESq+1gz0JOqEUD4wbXKl0IWAUVB41fZgP CaFA93z6cnFBuZ+Qb3b3XAaRN+TbE1aIjhNSHIQ3HXtXrceEz1RuMd5notDQ+BEvYo7O TNrA== X-Gm-Message-State: AA6/9Rn+uF+kZBs/a1G1TUjfVTos5aXOYSE905iC255r3XwlNAVkN8+a+MAfcjai8Ei9LQ== X-Received: by 10.200.53.82 with SMTP id z18mr17177758qtb.82.1475788965421; Thu, 06 Oct 2016 14:22:45 -0700 (PDT) Received: from wacom-arch2.corp.onewacom.com ([50.225.60.4]) by smtp.gmail.com with ESMTPSA id m4sm5773714qkf.29.2016.10.06.14.22.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Oct 2016 14:22:44 -0700 (PDT) From: Jason Gerecke To: linux-input@vger.kernel.org, Jiri Kosina Cc: Benjamin Tissoires , Ping Cheng , Ping Cheng , Aaron Skomra , Jason Gerecke , Jason Gerecke Subject: [PATCH 03/19] HID: wacom: Refactor button-to-key translation into function Date: Thu, 6 Oct 2016 14:22:15 -0700 Message-Id: <20161006212231.31440-4-killertofu@gmail.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161006212231.31440-1-killertofu@gmail.com> References: <20161006212231.31440-1-killertofu@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This just centralizes the logic used in both wacom_setup_numbered_buttons and wacom_report_numbered_buttons so that they don't drift out of sync. Signed-off-by: Jason Gerecke --- drivers/hid/wacom_wac.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index e09830c..a9f6d11 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -2779,17 +2779,29 @@ int wacom_setup_touch_input_capabilities(struct input_dev *input_dev, return 0; } +static int wacom_numbered_button_to_key(int n) +{ + if (n < 10) + return BTN_0 + n; + else if (n < 16) + return BTN_A + (n-10); + else if (n < 18) + return BTN_BASE + (n-16); + else + return 0; +} + static void wacom_setup_numbered_buttons(struct input_dev *input_dev, int button_count) { int i; - for (i = 0; i < button_count && i < 10; i++) - __set_bit(BTN_0 + i, input_dev->keybit); - for (i = 10; i < button_count && i < 16; i++) - __set_bit(BTN_A + (i-10), input_dev->keybit); - for (i = 16; i < button_count && i < 18; i++) - __set_bit(BTN_BASE + (i-16), input_dev->keybit); + for (i = 0; i < button_count; i++) { + int key = wacom_numbered_button_to_key(i); + + if (key) + __set_bit(key, input_dev->keybit); + } } static void wacom_24hd_update_leds(struct wacom *wacom, int mask, int group) @@ -2891,12 +2903,12 @@ static void wacom_report_numbered_buttons(struct input_dev *input_dev, for (i = 0; i < wacom->led.count; i++) wacom_update_led(wacom, button_count, mask, i); - for (i = 0; i < button_count && i < 10; i++) - input_report_key(input_dev, BTN_0 + i, mask & (1 << i)); - for (i = 10; i < button_count && i < 16; i++) - input_report_key(input_dev, BTN_A + (i-10), mask & (1 << i)); - for (i = 16; i < button_count && i < 18; i++) - input_report_key(input_dev, BTN_BASE + (i-16), mask & (1 << i)); + for (i = 0; i < button_count; i++) { + int key = wacom_numbered_button_to_key(i); + + if (key) + input_report_key(input_dev, key, mask & (1 << i)); + } } int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,