All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Fletcher <fletcher0max@gmail.com>
To: djogorchock@gmail.com, jikos@kernel.org,
	benjamin.tissoires@redhat.com, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Max Fletcher <fletcher0max@gmail.com>
Subject: [PATCH 2/2] HID: nintendo: add parameter to swap face buttons
Date: Wed, 11 May 2022 17:15:00 -0700	[thread overview]
Message-ID: <20220512001500.16739-2-fletcher0max@gmail.com> (raw)
In-Reply-To: <20220512001500.16739-1-fletcher0max@gmail.com>

Add the module parameter "faceswap" that swaps the face (ABXY) buttons to match the printed layout. This will be helpful for people who prefer to use the Nintendo layout over the Xbox layout.

Signed-off-by: Max Fletcher <fletcher0max@gmail.com>
---
 drivers/hid/hid-nintendo.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c
index 7735971ede3f..925cdcd0ac77 100644
--- a/drivers/hid/hid-nintendo.c
+++ b/drivers/hid/hid-nintendo.c
@@ -32,6 +32,7 @@
 #include <linux/jiffies.h>
 #include <linux/leds.h>
 #include <linux/module.h>
+#include <linux/moduleparam.h>
 #include <linux/power_supply.h>
 #include <linux/spinlock.h>
 
@@ -320,6 +321,8 @@ struct joycon_imu_cal {
 	s16 scale[3];
 };
 
+bool faceswap;
+
 /*
  * All the controller's button values are stored in a u32.
  * They can be accessed with bitwise ANDs.
@@ -1351,10 +1354,17 @@ static void joycon_parse_report(struct joycon_ctlr *ctlr,
 		input_report_key(dev, BTN_START, btns & JC_BTN_PLUS);
 		input_report_key(dev, BTN_THUMBR, btns & JC_BTN_RSTICK);
 		input_report_key(dev, BTN_MODE, btns & JC_BTN_HOME);
-		input_report_key(dev, BTN_X, btns & JC_BTN_Y);
-		input_report_key(dev, BTN_Y, btns & JC_BTN_X);
-		input_report_key(dev, BTN_B, btns & JC_BTN_A);
-		input_report_key(dev, BTN_A, btns & JC_BTN_B);
+		if (!faceswap) {
+			input_report_key(dev, BTN_X, btns & JC_BTN_Y);
+			input_report_key(dev, BTN_Y, btns & JC_BTN_X);
+			input_report_key(dev, BTN_B, btns & JC_BTN_A);
+			input_report_key(dev, BTN_A, btns & JC_BTN_B);
+		} else {
+			input_report_key(dev, BTN_Y, btns & JC_BTN_Y);
+			input_report_key(dev, BTN_X, btns & JC_BTN_X);
+			input_report_key(dev, BTN_A, btns & JC_BTN_A);
+			input_report_key(dev, BTN_B, btns & JC_BTN_B);
+		}
 	}
 
 	input_sync(dev);
@@ -2313,6 +2323,10 @@ static const struct hid_device_id nintendo_hid_devices[] = {
 };
 MODULE_DEVICE_TABLE(hid, nintendo_hid_devices);
 
+module_param(faceswap, bool, 0440);
+MODULE_PARM_DESC(faceswap,
+		 "Swaps the face buttons to match the printed layout");
+
 static struct hid_driver nintendo_hid_driver = {
 	.name		= "nintendo",
 	.id_table	= nintendo_hid_devices,
-- 
2.35.3


  reply	other threads:[~2022-05-12  0:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-12  0:14 [PATCH 1/2] HID: nintendo: fix face button mappings Max Fletcher
2022-05-12  0:15 ` Max Fletcher [this message]
2022-05-13 19:58 ` Roderick Colenbrander
     [not found]   ` <CAKcX28WpKoP=HVq3zCvBh9knKFEdR0_+NmATpt9D6rFmprkFDA@mail.gmail.com>
2022-05-15  3:33     ` Roderick Colenbrander
2022-05-26 20:07       ` Maxwell Fletcher
2022-05-31 15:19   ` Martino Fontana
2022-05-31 15:31     ` Roderick Colenbrander
2022-06-04 13:11       ` Martino Fontana

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220512001500.16739-2-fletcher0max@gmail.com \
    --to=fletcher0max@gmail.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=djogorchock@gmail.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.