From patchwork Thu Oct 20 01:03:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 9385687 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 987CE607D0 for ; Thu, 20 Oct 2016 01:04:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88E2328DD7 for ; Thu, 20 Oct 2016 01:04:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D7B7296F3; Thu, 20 Oct 2016 01:04:15 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 2065928DD7 for ; Thu, 20 Oct 2016 01:04:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754126AbcJTBEO (ORCPT ); Wed, 19 Oct 2016 21:04:14 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33787 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753662AbcJTBEN (ORCPT ); Wed, 19 Oct 2016 21:04:13 -0400 Received: by mail-pf0-f193.google.com with SMTP id i85so3838973pfa.0 for ; Wed, 19 Oct 2016 18:04:13 -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=mAVpAsw5fq4KgRdx75BLdqwfseQmmBhEzpBgMOSpS44=; b=S4SBjZsOHp9MGbhsE8fDxLaw3IiDSqr3PjMXVYwIaY+iIrsHDtfYjXIeT5pnUdeTyv OW/yPPt/5cELplX1t8idmofAaWVuy70KbyJxcXqbwARUQNGQuUnOSjrBiMo0mvpY9oJu zrj9OJTE40RJ8uEFy86241L/7hC+euqhmSE23nhNpgkoUVY4vg4zDwXzP03OIphICJ2m PdFXZu77rN3yXhCNgu9P6eScxG5JkbFjHF7xcwGh0HP77ISxNbcQZMqivHW8kLEUzWcC m0pUx98tbFNARuEYW1bZF0Nm4skNttWFCIVIQ7ziF/AA+AytcxJQUKnEq1GL4xjC2kb2 LRSQ== 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=mAVpAsw5fq4KgRdx75BLdqwfseQmmBhEzpBgMOSpS44=; b=C28C5sxJNvqS9DsimSpqfO7CTXniGuMpuQ4ATUg+ff552OoYAizVNRS5e3JcMuOrik g+bwWWRF17+h5FXSfHJj3urqVVBr1K7XfLtOYjOsSv8JPobRQnKolcqSIRb9qINrP+V5 kyb2NcxnqyfMCLUKwllxMY/MWrmEs78+myBNhH8bubh08AJBCK3FFVP7ie5uM6dhrjNW 2i8Lj420sNBEC6UKH8zQUaUETZqASvtdgtw3QdIl1G0L4vWcWsZjZqt6ycrw8g62Ilti ZCREErlCpw6Z/BrmP9qnW+Mw625C065/uYosALZb87rF6McsQLa30ZtKXE5CfJadnunu zR1w== X-Gm-Message-State: AA6/9Rkw57i1KR63NSk+U/aRP5JTfp0aWcQIw6+g+QQ/MsfbsPR+pMloMN51QFAmAn8jYA== X-Received: by 10.98.149.149 with SMTP id c21mr16557614pfk.100.1476925452946; Wed, 19 Oct 2016 18:04:12 -0700 (PDT) Received: from wtc005007.corp.onewacom.com ([50.225.60.4]) by smtp.gmail.com with ESMTPSA id d15sm877372pfl.90.2016.10.19.18.04.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Oct 2016 18:04:12 -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 v3 03/18] HID: wacom: Refactor button-to-key translation into function Date: Wed, 19 Oct 2016 18:03:39 -0700 Message-Id: <20161020010354.4049-3-killertofu@gmail.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161020010354.4049-1-killertofu@gmail.com> References: <20161006212231.31440-1-killertofu@gmail.com> <20161020010354.4049-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 3038954..8071c18 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -2769,17 +2769,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) @@ -2881,12 +2893,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,