diff options
| author | David Herrmann <dh.herrmann@googlemail.com> | 2012-09-17 06:31:35 -0400 |
|---|---|---|
| committer | Jiri Kosina <jkosina@suse.cz> | 2012-09-17 11:19:49 -0400 |
| commit | 5ad67fbc2a0f5b7e744ce2263a2340b7ebe92e00 (patch) | |
| tree | 1a22a367f1bf3bbdb06aa9279be9987b3a43f6fc /drivers/hid | |
| parent | 5b6e7f1c169db10632459c28f148011e039187bd (diff) | |
HID: wiimote: Add Nintendo Balance-Board support
The Nintendo Balance-Board is a controller which behaves exactly like the
Wii Remote but reports all its data through a special extension device.
Hence, we can simply add the Balance-Board as extension device and we get
full support for it.
Tested-by: Florian Echtler <floe@butterbrot.org>
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid')
| -rw-r--r-- | drivers/hid/hid-wiimote-ext.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/drivers/hid/hid-wiimote-ext.c b/drivers/hid/hid-wiimote-ext.c index 0a1805c9b0e5..ae022b863593 100644 --- a/drivers/hid/hid-wiimote-ext.c +++ b/drivers/hid/hid-wiimote-ext.c | |||
| @@ -34,6 +34,7 @@ enum wiiext_type { | |||
| 34 | WIIEXT_NONE, /* placeholder */ | 34 | WIIEXT_NONE, /* placeholder */ |
| 35 | WIIEXT_CLASSIC, /* Nintendo classic controller */ | 35 | WIIEXT_CLASSIC, /* Nintendo classic controller */ |
| 36 | WIIEXT_NUNCHUCK, /* Nintendo nunchuck controller */ | 36 | WIIEXT_NUNCHUCK, /* Nintendo nunchuck controller */ |
| 37 | WIIEXT_BALANCE_BOARD, /* Nintendo balance board controller */ | ||
| 37 | }; | 38 | }; |
| 38 | 39 | ||
| 39 | enum wiiext_keys { | 40 | enum wiiext_keys { |
| @@ -151,6 +152,8 @@ static __u8 ext_read(struct wiimote_ext *ext) | |||
| 151 | type = WIIEXT_NUNCHUCK; | 152 | type = WIIEXT_NUNCHUCK; |
| 152 | else if (rmem[0] == 0x01 && rmem[1] == 0x01) | 153 | else if (rmem[0] == 0x01 && rmem[1] == 0x01) |
| 153 | type = WIIEXT_CLASSIC; | 154 | type = WIIEXT_CLASSIC; |
| 155 | else if (rmem[0] == 0x04 && rmem[1] == 0x02) | ||
| 156 | type = WIIEXT_BALANCE_BOARD; | ||
| 154 | } | 157 | } |
| 155 | 158 | ||
| 156 | wiimote_cmd_release(ext->wdata); | 159 | wiimote_cmd_release(ext->wdata); |
| @@ -509,6 +512,55 @@ static void handler_classic(struct wiimote_ext *ext, const __u8 *payload) | |||
| 509 | input_sync(ext->input); | 512 | input_sync(ext->input); |
| 510 | } | 513 | } |
| 511 | 514 | ||
| 515 | static void handler_balance_board(struct wiimote_ext *ext, const __u8 *payload) | ||
| 516 | { | ||
| 517 | __s32 val[4]; | ||
| 518 | |||
| 519 | /* Byte | 8 7 6 5 4 3 2 1 | | ||
| 520 | * -----+--------------------------+ | ||
| 521 | * 1 | Top Right <15:8> | | ||
| 522 | * 2 | Top Right <7:0> | | ||
| 523 | * -----+--------------------------+ | ||
| 524 | * 3 | Bottom Right <15:8> | | ||
| 525 | * 4 | Bottom Right <7:0> | | ||
| 526 | * -----+--------------------------+ | ||
| 527 | * 5 | Top Left <15:8> | | ||
| 528 | * 6 | Top Left <7:0> | | ||
| 529 | * -----+--------------------------+ | ||
| 530 | * 7 | Bottom Left <15:8> | | ||
| 531 | * 8 | Bottom Left <7:0> | | ||
| 532 | * -----+--------------------------+ | ||
| 533 | * | ||
| 534 | * These values represent the weight-measurements of the Wii-balance | ||
| 535 | * board with 16bit precision. | ||
| 536 | * | ||
| 537 | * The balance-board is never reported interleaved with motionp. | ||
| 538 | */ | ||
| 539 | |||
| 540 | val[0] = payload[0]; | ||
| 541 | val[0] <<= 8; | ||
| 542 | val[0] |= payload[1]; | ||
| 543 | |||
| 544 | val[1] = payload[2]; | ||
| 545 | val[1] <<= 8; | ||
| 546 | val[1] |= payload[3]; | ||
| 547 | |||
| 548 | val[2] = payload[4]; | ||
| 549 | val[2] <<= 8; | ||
| 550 | val[2] |= payload[5]; | ||
| 551 | |||
| 552 | val[3] = payload[6]; | ||
| 553 | val[3] <<= 8; | ||
| 554 | val[3] |= payload[7]; | ||
| 555 | |||
| 556 | input_report_abs(ext->input, ABS_HAT0X, val[0]); | ||
| 557 | input_report_abs(ext->input, ABS_HAT0Y, val[1]); | ||
| 558 | input_report_abs(ext->input, ABS_HAT1X, val[2]); | ||
| 559 | input_report_abs(ext->input, ABS_HAT1Y, val[3]); | ||
| 560 | |||
| 561 | input_sync(ext->input); | ||
| 562 | } | ||
| 563 | |||
| 512 | /* call this with state.lock spinlock held */ | 564 | /* call this with state.lock spinlock held */ |
| 513 | void wiiext_handle(struct wiimote_data *wdata, const __u8 *payload) | 565 | void wiiext_handle(struct wiimote_data *wdata, const __u8 *payload) |
| 514 | { | 566 | { |
| @@ -523,6 +575,8 @@ void wiiext_handle(struct wiimote_data *wdata, const __u8 *payload) | |||
| 523 | handler_nunchuck(ext, payload); | 575 | handler_nunchuck(ext, payload); |
| 524 | } else if (ext->ext_type == WIIEXT_CLASSIC) { | 576 | } else if (ext->ext_type == WIIEXT_CLASSIC) { |
| 525 | handler_classic(ext, payload); | 577 | handler_classic(ext, payload); |
| 578 | } else if (ext->ext_type == WIIEXT_BALANCE_BOARD) { | ||
| 579 | handler_balance_board(ext, payload); | ||
| 526 | } | 580 | } |
| 527 | } | 581 | } |
| 528 | 582 | ||
| @@ -551,6 +605,11 @@ static ssize_t wiiext_show(struct device *dev, struct device_attribute *attr, | |||
| 551 | return sprintf(buf, "motionp+classic\n"); | 605 | return sprintf(buf, "motionp+classic\n"); |
| 552 | else | 606 | else |
| 553 | return sprintf(buf, "classic\n"); | 607 | return sprintf(buf, "classic\n"); |
| 608 | } else if (type == WIIEXT_BALANCE_BOARD) { | ||
| 609 | if (motionp) | ||
| 610 | return sprintf(buf, "motionp+balanceboard\n"); | ||
| 611 | else | ||
| 612 | return sprintf(buf, "balanceboard\n"); | ||
| 554 | } else { | 613 | } else { |
| 555 | if (motionp) | 614 | if (motionp) |
| 556 | return sprintf(buf, "motionp\n"); | 615 | return sprintf(buf, "motionp\n"); |
