diff options
author | David Herrmann <dh.herrmann@googlemail.com> | 2011-07-05 07:45:16 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2011-07-11 08:30:23 -0400 |
commit | 1abb9ad389f037612b6ba6b0dede2095c59cd2fa (patch) | |
tree | 48db9fb71189b63c5b776bb42d0cbf18a7eaab43 /drivers | |
parent | a4d19197627e2a8645cccd9039edf513c6384297 (diff) |
HID: wiimote: Add wiimote input button parser
Parse input report 0x30 from the wiimote as button input. We need to
send events for all buttons on every input report because the wiimote
does not send events for single buttons but always for all buttons
to us. The input layer, however, filters redundant events.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/hid/hid-wiimote.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c index c86ae92b51db..efdf62b730f3 100644 --- a/drivers/hid/hid-wiimote.c +++ b/drivers/hid/hid-wiimote.c | |||
@@ -39,6 +39,39 @@ struct wiimote_data { | |||
39 | struct work_struct worker; | 39 | struct work_struct worker; |
40 | }; | 40 | }; |
41 | 41 | ||
42 | enum wiiproto_reqs { | ||
43 | WIIPROTO_REQ_DRM_K = 0x30, | ||
44 | }; | ||
45 | |||
46 | enum wiiproto_keys { | ||
47 | WIIPROTO_KEY_LEFT, | ||
48 | WIIPROTO_KEY_RIGHT, | ||
49 | WIIPROTO_KEY_UP, | ||
50 | WIIPROTO_KEY_DOWN, | ||
51 | WIIPROTO_KEY_PLUS, | ||
52 | WIIPROTO_KEY_MINUS, | ||
53 | WIIPROTO_KEY_ONE, | ||
54 | WIIPROTO_KEY_TWO, | ||
55 | WIIPROTO_KEY_A, | ||
56 | WIIPROTO_KEY_B, | ||
57 | WIIPROTO_KEY_HOME, | ||
58 | WIIPROTO_KEY_COUNT | ||
59 | }; | ||
60 | |||
61 | static __u16 wiiproto_keymap[] = { | ||
62 | KEY_LEFT, /* WIIPROTO_KEY_LEFT */ | ||
63 | KEY_RIGHT, /* WIIPROTO_KEY_RIGHT */ | ||
64 | KEY_UP, /* WIIPROTO_KEY_UP */ | ||
65 | KEY_DOWN, /* WIIPROTO_KEY_DOWN */ | ||
66 | KEY_NEXT, /* WIIPROTO_KEY_PLUS */ | ||
67 | KEY_PREVIOUS, /* WIIPROTO_KEY_MINUS */ | ||
68 | BTN_1, /* WIIPROTO_KEY_ONE */ | ||
69 | BTN_2, /* WIIPROTO_KEY_TWO */ | ||
70 | BTN_A, /* WIIPROTO_KEY_A */ | ||
71 | BTN_B, /* WIIPROTO_KEY_B */ | ||
72 | BTN_MODE, /* WIIPROTO_KEY_HOME */ | ||
73 | }; | ||
74 | |||
42 | static ssize_t wiimote_hid_send(struct hid_device *hdev, __u8 *buffer, | 75 | static ssize_t wiimote_hid_send(struct hid_device *hdev, __u8 *buffer, |
43 | size_t count) | 76 | size_t count) |
44 | { | 77 | { |
@@ -130,6 +163,33 @@ static int wiimote_input_event(struct input_dev *dev, unsigned int type, | |||
130 | return 0; | 163 | return 0; |
131 | } | 164 | } |
132 | 165 | ||
166 | static void handler_keys(struct wiimote_data *wdata, const __u8 *payload) | ||
167 | { | ||
168 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_LEFT], | ||
169 | !!(payload[0] & 0x01)); | ||
170 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_RIGHT], | ||
171 | !!(payload[0] & 0x02)); | ||
172 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_DOWN], | ||
173 | !!(payload[0] & 0x04)); | ||
174 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_UP], | ||
175 | !!(payload[0] & 0x08)); | ||
176 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_PLUS], | ||
177 | !!(payload[0] & 0x10)); | ||
178 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_TWO], | ||
179 | !!(payload[1] & 0x01)); | ||
180 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_ONE], | ||
181 | !!(payload[1] & 0x02)); | ||
182 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_B], | ||
183 | !!(payload[1] & 0x04)); | ||
184 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_A], | ||
185 | !!(payload[1] & 0x08)); | ||
186 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_MINUS], | ||
187 | !!(payload[1] & 0x10)); | ||
188 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_HOME], | ||
189 | !!(payload[1] & 0x80)); | ||
190 | input_sync(wdata->input); | ||
191 | } | ||
192 | |||
133 | struct wiiproto_handler { | 193 | struct wiiproto_handler { |
134 | __u8 id; | 194 | __u8 id; |
135 | size_t size; | 195 | size_t size; |
@@ -137,6 +197,7 @@ struct wiiproto_handler { | |||
137 | }; | 197 | }; |
138 | 198 | ||
139 | static struct wiiproto_handler handlers[] = { | 199 | static struct wiiproto_handler handlers[] = { |
200 | { .id = WIIPROTO_REQ_DRM_K, .size = 2, .func = handler_keys }, | ||
140 | { .id = 0 } | 201 | { .id = 0 } |
141 | }; | 202 | }; |
142 | 203 | ||
@@ -167,6 +228,7 @@ static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, | |||
167 | static struct wiimote_data *wiimote_create(struct hid_device *hdev) | 228 | static struct wiimote_data *wiimote_create(struct hid_device *hdev) |
168 | { | 229 | { |
169 | struct wiimote_data *wdata; | 230 | struct wiimote_data *wdata; |
231 | int i; | ||
170 | 232 | ||
171 | wdata = kzalloc(sizeof(*wdata), GFP_KERNEL); | 233 | wdata = kzalloc(sizeof(*wdata), GFP_KERNEL); |
172 | if (!wdata) | 234 | if (!wdata) |
@@ -190,6 +252,10 @@ static struct wiimote_data *wiimote_create(struct hid_device *hdev) | |||
190 | wdata->input->id.version = wdata->hdev->version; | 252 | wdata->input->id.version = wdata->hdev->version; |
191 | wdata->input->name = WIIMOTE_NAME; | 253 | wdata->input->name = WIIMOTE_NAME; |
192 | 254 | ||
255 | set_bit(EV_KEY, wdata->input->evbit); | ||
256 | for (i = 0; i < WIIPROTO_KEY_COUNT; ++i) | ||
257 | set_bit(wiiproto_keymap[i], wdata->input->keybit); | ||
258 | |||
193 | spin_lock_init(&wdata->qlock); | 259 | spin_lock_init(&wdata->qlock); |
194 | INIT_WORK(&wdata->worker, wiimote_worker); | 260 | INIT_WORK(&wdata->worker, wiimote_worker); |
195 | 261 | ||