From patchwork Fri Oct 7 22:16:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 9367711 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 0AF4C608A6 for ; Fri, 7 Oct 2016 22:18:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F19432983D for ; Fri, 7 Oct 2016 22:18:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9C652984C; Fri, 7 Oct 2016 22:18:05 +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 C092C2983E for ; Fri, 7 Oct 2016 22:18:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757448AbcJGWSC (ORCPT ); Fri, 7 Oct 2016 18:18:02 -0400 Received: from mail-qk0-f195.google.com ([209.85.220.195]:35566 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757021AbcJGWSB (ORCPT ); Fri, 7 Oct 2016 18:18:01 -0400 Received: by mail-qk0-f195.google.com with SMTP id v138so2086839qka.2 for ; Fri, 07 Oct 2016 15:17:08 -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=Q5oowPPDAA1oxLDvlUvxAAFh+Mw3cRLyMo4YDOJohFE=; b=cHLG9dZHWssj/nGjXZ+fc2mzbD5gkSqq69Mhx+nfJHdVhHaW7TTM/j0OO8FUHS/awm XZHCKPKQknNAlFMeRlv1UQRXgAV5q9+7yp3aM6BycGSb+tV2+uZ/pJAf3EAjC76zyr8c QHhX4JpbZngj9C2xJ4hMDarHy7jzngvDD+ZsB6YR8DC668xZG9mTybYq07QATv0eMZjL AKO0qU1ON9amR1qTC0FhEPAVnVTZeUGUeNV9JCikD9MZ0gw0muLIW0y1hQtmkENBlzHu CkDc0d2T3uP2mwooS2880Ev1IPnveE78ldrO6wdEibNKSvMwzt4zjd6jRo54W428Dm32 Viqg== 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=Q5oowPPDAA1oxLDvlUvxAAFh+Mw3cRLyMo4YDOJohFE=; b=dLJ9QMMVOQGGW0oZ+peBtV7xu8TYJs0YjR28OOuVIMJdM1EkQBkzXblcT1mb2aDmZf JsTzdcmn1PvcRdQhgmnS8iCwH5Q3MCZrBmPgHaRAaoiTT8Bop1t14/n1eYb4cYvGklN2 vM3Hk9UrHzEN+Ls2y/fwrcc5Ui7VLq21tU3qNquw3TP5UH8OLvfeCEIwapYtPKByTQ6U pTv+4wGipm/cydWw4gr9nNUDwSN+k5p8u7BFWIu+NOj/4ZQPmBvkPQ3ifE5KTga5j7Ub F8Ox7bTlmJd7sQKyxoD8KP26iPF9fdtbcxgjh5D5+X2pEKR/bhm1Qo4PgpIYk8DPnzRs hDnQ== X-Gm-Message-State: AA6/9RkU4VR13eYYt47rfl1NgRDDvvL7y7xx3zplUdFqk/vg6ONoTzqhruwo1lm6GhMvlA== X-Received: by 10.55.155.15 with SMTP id d15mr21222196qke.115.1475878628257; Fri, 07 Oct 2016 15:17:08 -0700 (PDT) Received: from wacom-arch2.corp.onewacom.com ([50.225.60.4]) by smtp.gmail.com with ESMTPSA id u63sm7633162qkd.16.2016.10.07.15.17.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Oct 2016 15:17:07 -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 v2 03/18] HID: wacom: Refactor button-to-key translation into function Date: Fri, 7 Oct 2016 15:16:38 -0700 Message-Id: <20161007221653.26941-3-killertofu@gmail.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161007221653.26941-1-killertofu@gmail.com> References: <20161006212231.31440-1-killertofu@gmail.com> <20161007221653.26941-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 Reviewed-by: Benjamin Tissoires --- 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,