diff options
author | Dmitry Torokhov <dtor@insightbb.com> | 2007-07-18 01:20:34 -0400 |
---|---|---|
committer | Dmitry Torokhov <dtor@insightbb.com> | 2007-07-18 01:20:34 -0400 |
commit | 20b3cdd6773be09f7bf52113de0d0c37da287f29 (patch) | |
tree | 398dd07c816de53fc1c476c72365ddee3c52f51a /drivers/input/joystick/xpad.c | |
parent | 5517853712f1f6daac8a7b2590f9b821e767aa13 (diff) |
Input: xpad - use le16_to_cpup when parsing data stream
Use avaliable functions instead of doing it all manually.
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/joystick/xpad.c')
-rw-r--r-- | drivers/input/joystick/xpad.c | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index 28080395899c..623629a69b03 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c | |||
@@ -223,12 +223,16 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d | |||
223 | struct input_dev *dev = xpad->dev; | 223 | struct input_dev *dev = xpad->dev; |
224 | 224 | ||
225 | /* left stick */ | 225 | /* left stick */ |
226 | input_report_abs(dev, ABS_X, (__s16) (((__s16)data[13] << 8) | data[12])); | 226 | input_report_abs(dev, ABS_X, |
227 | input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[15] << 8) | data[14])); | 227 | (__s16) le16_to_cpup((__le16 *)(data + 12))); |
228 | input_report_abs(dev, ABS_Y, | ||
229 | (__s16) le16_to_cpup((__le16 *)(data + 14))); | ||
228 | 230 | ||
229 | /* right stick */ | 231 | /* right stick */ |
230 | input_report_abs(dev, ABS_RX, (__s16) (((__s16)data[17] << 8) | data[16])); | 232 | input_report_abs(dev, ABS_RX, |
231 | input_report_abs(dev, ABS_RY, (__s16) (((__s16)data[19] << 8) | data[18])); | 233 | (__s16) le16_to_cpup((__le16 *)(data + 16))); |
234 | input_report_abs(dev, ABS_RY, | ||
235 | (__s16) le16_to_cpup((__le16 *)(data + 18))); | ||
232 | 236 | ||
233 | /* triggers left/right */ | 237 | /* triggers left/right */ |
234 | input_report_abs(dev, ABS_Z, data[10]); | 238 | input_report_abs(dev, ABS_Z, data[10]); |
@@ -236,8 +240,10 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d | |||
236 | 240 | ||
237 | /* digital pad */ | 241 | /* digital pad */ |
238 | if (xpad->dpad_mapping == MAP_DPAD_TO_AXES) { | 242 | if (xpad->dpad_mapping == MAP_DPAD_TO_AXES) { |
239 | input_report_abs(dev, ABS_HAT0X, !!(data[2] & 0x08) - !!(data[2] & 0x04)); | 243 | input_report_abs(dev, ABS_HAT0X, |
240 | input_report_abs(dev, ABS_HAT0Y, !!(data[2] & 0x02) - !!(data[2] & 0x01)); | 244 | !!(data[2] & 0x08) - !!(data[2] & 0x04)); |
245 | input_report_abs(dev, ABS_HAT0Y, | ||
246 | !!(data[2] & 0x02) - !!(data[2] & 0x01)); | ||
241 | } else /* xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS */ { | 247 | } else /* xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS */ { |
242 | input_report_key(dev, BTN_LEFT, data[2] & 0x04); | 248 | input_report_key(dev, BTN_LEFT, data[2] & 0x04); |
243 | input_report_key(dev, BTN_RIGHT, data[2] & 0x08); | 249 | input_report_key(dev, BTN_RIGHT, data[2] & 0x08); |
@@ -274,14 +280,17 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d | |||
274 | * http://www.free60.org/wiki/Gamepad | 280 | * http://www.free60.org/wiki/Gamepad |
275 | */ | 281 | */ |
276 | 282 | ||
277 | static void xpad360_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) | 283 | static void xpad360_process_packet(struct usb_xpad *xpad, |
284 | u16 cmd, unsigned char *data) | ||
278 | { | 285 | { |
279 | struct input_dev *dev = xpad->dev; | 286 | struct input_dev *dev = xpad->dev; |
280 | 287 | ||
281 | /* digital pad */ | 288 | /* digital pad */ |
282 | if (xpad->dpad_mapping == MAP_DPAD_TO_AXES) { | 289 | if (xpad->dpad_mapping == MAP_DPAD_TO_AXES) { |
283 | input_report_abs(dev, ABS_HAT0X, !!(data[2] & 0x08) - !!(data[2] & 0x04)); | 290 | input_report_abs(dev, ABS_HAT0X, |
284 | input_report_abs(dev, ABS_HAT0Y, !!(data[2] & 0x02) - !!(data[2] & 0x01)); | 291 | !!(data[2] & 0x08) - !!(data[2] & 0x04)); |
292 | input_report_abs(dev, ABS_HAT0Y, | ||
293 | !!(data[2] & 0x02) - !!(data[2] & 0x01)); | ||
285 | } else if (xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS) { | 294 | } else if (xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS) { |
286 | /* dpad as buttons (right, left, down, up) */ | 295 | /* dpad as buttons (right, left, down, up) */ |
287 | input_report_key(dev, BTN_LEFT, data[2] & 0x04); | 296 | input_report_key(dev, BTN_LEFT, data[2] & 0x04); |
@@ -308,12 +317,16 @@ static void xpad360_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char | |||
308 | input_report_key(dev, BTN_MODE, data[3] & 0x04); | 317 | input_report_key(dev, BTN_MODE, data[3] & 0x04); |
309 | 318 | ||
310 | /* left stick */ | 319 | /* left stick */ |
311 | input_report_abs(dev, ABS_X, (__s16) (((__s16)data[7] << 8) | (__s16)data[6])); | 320 | input_report_abs(dev, ABS_X, |
312 | input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[9] << 8) | (__s16)data[8])); | 321 | (__s16) le16_to_cpup((__le16 *)(data + 6))); |
322 | input_report_abs(dev, ABS_Y, | ||
323 | (__s16) le16_to_cpup((__le16 *)(data + 8))); | ||
313 | 324 | ||
314 | /* right stick */ | 325 | /* right stick */ |
315 | input_report_abs(dev, ABS_RX, (__s16) (((__s16)data[11] << 8) | (__s16)data[10])); | 326 | input_report_abs(dev, ABS_RX, |
316 | input_report_abs(dev, ABS_RY, (__s16) (((__s16)data[13] << 8) | (__s16)data[12])); | 327 | (__s16) le16_to_cpup((__le16 *)(data + 10))); |
328 | input_report_abs(dev, ABS_RY, | ||
329 | (__s16) le16_to_cpup((__le16 *)(data + 12))); | ||
317 | 330 | ||
318 | /* triggers left/right */ | 331 | /* triggers left/right */ |
319 | input_report_abs(dev, ABS_Z, data[4]); | 332 | input_report_abs(dev, ABS_Z, data[4]); |
@@ -335,10 +348,12 @@ static void xpad_irq_in(struct urb *urb) | |||
335 | case -ENOENT: | 348 | case -ENOENT: |
336 | case -ESHUTDOWN: | 349 | case -ESHUTDOWN: |
337 | /* this urb is terminated, clean up */ | 350 | /* this urb is terminated, clean up */ |
338 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); | 351 | dbg("%s - urb shutting down with status: %d", |
352 | __FUNCTION__, urb->status); | ||
339 | return; | 353 | return; |
340 | default: | 354 | default: |
341 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); | 355 | dbg("%s - nonzero urb status received: %d", |
356 | __FUNCTION__, urb->status); | ||
342 | goto exit; | 357 | goto exit; |
343 | } | 358 | } |
344 | 359 | ||
@@ -367,10 +382,12 @@ static void xpad_irq_out(struct urb *urb) | |||
367 | case -ENOENT: | 382 | case -ENOENT: |
368 | case -ESHUTDOWN: | 383 | case -ESHUTDOWN: |
369 | /* this urb is terminated, clean up */ | 384 | /* this urb is terminated, clean up */ |
370 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); | 385 | dbg("%s - urb shutting down with status: %d", |
386 | __FUNCTION__, urb->status); | ||
371 | return; | 387 | return; |
372 | default: | 388 | default: |
373 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); | 389 | dbg("%s - nonzero urb status received: %d", |
390 | __FUNCTION__, urb->status); | ||
374 | goto exit; | 391 | goto exit; |
375 | } | 392 | } |
376 | 393 | ||
@@ -378,7 +395,7 @@ exit: | |||
378 | retval = usb_submit_urb(urb, GFP_ATOMIC); | 395 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
379 | if (retval) | 396 | if (retval) |
380 | err("%s - usb_submit_urb failed with result %d", | 397 | err("%s - usb_submit_urb failed with result %d", |
381 | __FUNCTION__, retval); | 398 | __FUNCTION__, retval); |
382 | } | 399 | } |
383 | 400 | ||
384 | static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) | 401 | static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) |
@@ -595,7 +612,7 @@ static void xpad_set_up_abs(struct input_dev *input_dev, signed short abs) | |||
595 | 612 | ||
596 | static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id) | 613 | static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id) |
597 | { | 614 | { |
598 | struct usb_device *udev = interface_to_usbdev (intf); | 615 | struct usb_device *udev = interface_to_usbdev(intf); |
599 | struct usb_xpad *xpad; | 616 | struct usb_xpad *xpad; |
600 | struct input_dev *input_dev; | 617 | struct input_dev *input_dev; |
601 | struct usb_endpoint_descriptor *ep_irq_in; | 618 | struct usb_endpoint_descriptor *ep_irq_in; |