hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/hid/hid-wiimote-modules.c
....@@ -1,13 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Device Modules for Nintendo Wii / Wii U HID Driver
34 * Copyright (c) 2011-2013 David Herrmann <dh.herrmann@gmail.com>
45 */
56
67 /*
7
- * This program is free software; you can redistribute it and/or modify it
8
- * under the terms of the GNU General Public License as published by the Free
9
- * Software Foundation; either version 2 of the License, or (at your option)
10
- * any later version.
118 */
129
1310 /*
....@@ -1091,12 +1088,28 @@
10911088 * is the same as before.
10921089 */
10931090
1091
+ static const s8 digital_to_analog[3] = {0x20, 0, -0x20};
1092
+
10941093 if (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE) {
1095
- lx = ext[0] & 0x3e;
1096
- 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
+ }
10971103 } else {
1098
- lx = ext[0] & 0x3f;
1099
- 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
+ }
11001113 }
11011114
11021115 rx = (ext[0] >> 3) & 0x18;
....@@ -1113,19 +1126,13 @@
11131126 rt <<= 1;
11141127 lt <<= 1;
11151128
1116
- input_report_abs(wdata->extension.input, ABS_HAT1X, lx - 0x20);
1117
- input_report_abs(wdata->extension.input, ABS_HAT1Y, ly - 0x20);
1129
+ input_report_abs(wdata->extension.input, ABS_HAT1X, lx);
1130
+ input_report_abs(wdata->extension.input, ABS_HAT1Y, ly);
11181131 input_report_abs(wdata->extension.input, ABS_HAT2X, rx - 0x20);
11191132 input_report_abs(wdata->extension.input, ABS_HAT2Y, ry - 0x20);
11201133 input_report_abs(wdata->extension.input, ABS_HAT3X, rt);
11211134 input_report_abs(wdata->extension.input, ABS_HAT3Y, lt);
11221135
1123
- input_report_key(wdata->extension.input,
1124
- wiimod_classic_map[WIIMOD_CLASSIC_KEY_RIGHT],
1125
- !(ext[4] & 0x80));
1126
- input_report_key(wdata->extension.input,
1127
- wiimod_classic_map[WIIMOD_CLASSIC_KEY_DOWN],
1128
- !(ext[4] & 0x40));
11291136 input_report_key(wdata->extension.input,
11301137 wiimod_classic_map[WIIMOD_CLASSIC_KEY_LT],
11311138 !(ext[4] & 0x20));
....@@ -1160,20 +1167,29 @@
11601167 wiimod_classic_map[WIIMOD_CLASSIC_KEY_ZR],
11611168 !(ext[5] & 0x04));
11621169
1163
- if (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE) {
1170
+ if (!wiimote_dpad_as_analog) {
11641171 input_report_key(wdata->extension.input,
1165
- wiimod_classic_map[WIIMOD_CLASSIC_KEY_LEFT],
1166
- !(ext[1] & 0x01));
1172
+ wiimod_classic_map[WIIMOD_CLASSIC_KEY_RIGHT],
1173
+ !(ext[4] & 0x80));
11671174 input_report_key(wdata->extension.input,
1168
- wiimod_classic_map[WIIMOD_CLASSIC_KEY_UP],
1169
- !(ext[0] & 0x01));
1170
- } else {
1171
- input_report_key(wdata->extension.input,
1172
- wiimod_classic_map[WIIMOD_CLASSIC_KEY_LEFT],
1173
- !(ext[5] & 0x02));
1174
- input_report_key(wdata->extension.input,
1175
- wiimod_classic_map[WIIMOD_CLASSIC_KEY_UP],
1176
- !(ext[5] & 0x01));
1175
+ wiimod_classic_map[WIIMOD_CLASSIC_KEY_DOWN],
1176
+ !(ext[4] & 0x40));
1177
+
1178
+ if (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE) {
1179
+ input_report_key(wdata->extension.input,
1180
+ wiimod_classic_map[WIIMOD_CLASSIC_KEY_LEFT],
1181
+ !(ext[1] & 0x01));
1182
+ input_report_key(wdata->extension.input,
1183
+ wiimod_classic_map[WIIMOD_CLASSIC_KEY_UP],
1184
+ !(ext[0] & 0x01));
1185
+ } else {
1186
+ input_report_key(wdata->extension.input,
1187
+ wiimod_classic_map[WIIMOD_CLASSIC_KEY_LEFT],
1188
+ !(ext[5] & 0x02));
1189
+ input_report_key(wdata->extension.input,
1190
+ wiimod_classic_map[WIIMOD_CLASSIC_KEY_UP],
1191
+ !(ext[5] & 0x01));
1192
+ }
11771193 }
11781194
11791195 input_sync(wdata->extension.input);