Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

HID: Wiimote: Treat the d-pad as an analogue stick

The controllers from the Super Nintendo Classic Edition (AKA the SNES
Mini) appear as a Classic Controller Pro when connected to a Wii
Remote. All the buttons work as the same, with the d-pad being mapped
the same as the d-pad on the Classic Controller Pro. This differs from
the behaviour of most controllers with d-pads and no analogue sticks,
where the d-pad maps to ABS_HAT1X for left and right, and ABS_HAT1Y
for up and down. This patch adds an option to the hid-wiimote module
to make the Super Nintendo Classic Controller behave this way.

The patch has been tested with a Super Nintendo Classic Controller
plugged into a Wii Remote in both with the option both enabled and
disabled. When enabled the d-pad acts as the analogue control, and
when disabled it acts as it did before the patch was applied. This
patch has not been tested with e Wii Classic Controller (either the
original or the pro version) as I do not have one of these
controllers.

Although I have not tested it with these controllers, I think it is
likely this patch will also work with the NES Classic Edition
Controllers.

Signed-off-by: Daniel G. Morse <dmorse@speedfox.co.uk>
Reviewed-by: David Rheinsberg <david.rheinsberg@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>

authored by

Daniel G. Morse and committed by
Jiri Kosina
a8cbf80e a789d5f8

+50 -24
+5
drivers/hid/hid-wiimote-core.c
··· 1870 1870 USB_DEVICE_ID_NINTENDO_WIIMOTE2) }, 1871 1871 { } 1872 1872 }; 1873 + 1874 + bool wiimote_dpad_as_analog = false; 1875 + module_param_named(dpad_as_analog, wiimote_dpad_as_analog, bool, 0644); 1876 + MODULE_PARM_DESC(dpad_as_analog, "Use D-Pad as main analog input"); 1877 + 1873 1878 MODULE_DEVICE_TABLE(hid, wiimote_hid_devices); 1874 1879 1875 1880 static struct hid_driver wiimote_hid_driver = {
+43 -24
drivers/hid/hid-wiimote-modules.c
··· 1088 1088 * is the same as before. 1089 1089 */ 1090 1090 1091 + static const s8 digital_to_analog[3] = {0x20, 0, -0x20}; 1092 + 1091 1093 if (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE) { 1092 - lx = ext[0] & 0x3e; 1093 - ly = ext[1] & 0x3e; 1094 + if (wiimote_dpad_as_analog) { 1095 + lx = digital_to_analog[1 - !(ext[4] & 0x80) 1096 + + !(ext[1] & 0x01)]; 1097 + ly = digital_to_analog[1 - !(ext[4] & 0x40) 1098 + + !(ext[0] & 0x01)]; 1099 + } else { 1100 + lx = (ext[0] & 0x3e) - 0x20; 1101 + ly = (ext[1] & 0x3e) - 0x20; 1102 + } 1094 1103 } else { 1095 - lx = ext[0] & 0x3f; 1096 - ly = ext[1] & 0x3f; 1104 + if (wiimote_dpad_as_analog) { 1105 + lx = digital_to_analog[1 - !(ext[4] & 0x80) 1106 + + !(ext[5] & 0x02)]; 1107 + ly = digital_to_analog[1 - !(ext[4] & 0x40) 1108 + + !(ext[5] & 0x01)]; 1109 + } else { 1110 + lx = (ext[0] & 0x3f) - 0x20; 1111 + ly = (ext[1] & 0x3f) - 0x20; 1112 + } 1097 1113 } 1098 1114 1099 1115 rx = (ext[0] >> 3) & 0x18; ··· 1126 1110 rt <<= 1; 1127 1111 lt <<= 1; 1128 1112 1129 - input_report_abs(wdata->extension.input, ABS_HAT1X, lx - 0x20); 1130 - input_report_abs(wdata->extension.input, ABS_HAT1Y, ly - 0x20); 1113 + input_report_abs(wdata->extension.input, ABS_HAT1X, lx); 1114 + input_report_abs(wdata->extension.input, ABS_HAT1Y, ly); 1131 1115 input_report_abs(wdata->extension.input, ABS_HAT2X, rx - 0x20); 1132 1116 input_report_abs(wdata->extension.input, ABS_HAT2Y, ry - 0x20); 1133 1117 input_report_abs(wdata->extension.input, ABS_HAT3X, rt); 1134 1118 input_report_abs(wdata->extension.input, ABS_HAT3Y, lt); 1135 1119 1136 - input_report_key(wdata->extension.input, 1137 - wiimod_classic_map[WIIMOD_CLASSIC_KEY_RIGHT], 1138 - !(ext[4] & 0x80)); 1139 - input_report_key(wdata->extension.input, 1140 - wiimod_classic_map[WIIMOD_CLASSIC_KEY_DOWN], 1141 - !(ext[4] & 0x40)); 1142 1120 input_report_key(wdata->extension.input, 1143 1121 wiimod_classic_map[WIIMOD_CLASSIC_KEY_LT], 1144 1122 !(ext[4] & 0x20)); ··· 1167 1157 wiimod_classic_map[WIIMOD_CLASSIC_KEY_ZR], 1168 1158 !(ext[5] & 0x04)); 1169 1159 1170 - if (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE) { 1160 + if (!wiimote_dpad_as_analog) { 1171 1161 input_report_key(wdata->extension.input, 1172 - wiimod_classic_map[WIIMOD_CLASSIC_KEY_LEFT], 1173 - !(ext[1] & 0x01)); 1162 + wiimod_classic_map[WIIMOD_CLASSIC_KEY_RIGHT], 1163 + !(ext[4] & 0x80)); 1174 1164 input_report_key(wdata->extension.input, 1175 - wiimod_classic_map[WIIMOD_CLASSIC_KEY_UP], 1176 - !(ext[0] & 0x01)); 1177 - } else { 1178 - input_report_key(wdata->extension.input, 1179 - wiimod_classic_map[WIIMOD_CLASSIC_KEY_LEFT], 1180 - !(ext[5] & 0x02)); 1181 - input_report_key(wdata->extension.input, 1182 - wiimod_classic_map[WIIMOD_CLASSIC_KEY_UP], 1183 - !(ext[5] & 0x01)); 1165 + wiimod_classic_map[WIIMOD_CLASSIC_KEY_DOWN], 1166 + !(ext[4] & 0x40)); 1167 + 1168 + if (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE) { 1169 + input_report_key(wdata->extension.input, 1170 + wiimod_classic_map[WIIMOD_CLASSIC_KEY_LEFT], 1171 + !(ext[1] & 0x01)); 1172 + input_report_key(wdata->extension.input, 1173 + wiimod_classic_map[WIIMOD_CLASSIC_KEY_UP], 1174 + !(ext[0] & 0x01)); 1175 + } else { 1176 + input_report_key(wdata->extension.input, 1177 + wiimod_classic_map[WIIMOD_CLASSIC_KEY_LEFT], 1178 + !(ext[5] & 0x02)); 1179 + input_report_key(wdata->extension.input, 1180 + wiimod_classic_map[WIIMOD_CLASSIC_KEY_UP], 1181 + !(ext[5] & 0x01)); 1182 + } 1184 1183 } 1185 1184 1186 1185 input_sync(wdata->extension.input);
+2
drivers/hid/hid-wiimote.h
··· 162 162 struct work_struct init_worker; 163 163 }; 164 164 165 + extern bool wiimote_dpad_as_analog; 166 + 165 167 /* wiimote modules */ 166 168 167 169 enum wiimod_module {