2020-08-25 19:23:38 +00:00
|
|
|
/*
|
2021-01-26 03:03:26 +00:00
|
|
|
* Copyright (c) 2020-2021 ndeadly
|
2020-08-25 19:23:38 +00:00
|
|
|
*
|
2020-08-26 22:50:34 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
2020-08-25 19:23:38 +00:00
|
|
|
*
|
2020-08-26 22:50:34 +00:00
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
2020-08-25 19:23:38 +00:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-06-02 21:24:40 +00:00
|
|
|
#pragma once
|
2020-08-26 18:52:47 +00:00
|
|
|
#include "emulated_switch_controller.hpp"
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-07-11 11:43:21 +00:00
|
|
|
namespace ams::controller {
|
2020-06-02 21:24:40 +00:00
|
|
|
|
|
|
|
enum WiiControllerLEDs {
|
|
|
|
WiiControllerLEDs_P1 = 0x10,
|
|
|
|
WiiControllerLEDs_P2 = 0x20,
|
|
|
|
WiiControllerLEDs_P3 = 0x40,
|
|
|
|
WiiControllerLEDs_P4 = 0x80,
|
|
|
|
};
|
|
|
|
|
2020-07-30 20:04:15 +00:00
|
|
|
enum WiiExtensionController {
|
|
|
|
WiiExtensionController_None,
|
|
|
|
WiiExtensionController_Nunchuck,
|
|
|
|
WiiExtensionController_Classic,
|
|
|
|
WiiExtensionController_ClassicPro,
|
|
|
|
WiiExtensionController_WiiUPro,
|
2020-09-24 00:40:33 +00:00
|
|
|
WiiExtensionController_TaTaCon,
|
2020-07-30 20:04:15 +00:00
|
|
|
WiiExtensionController_Unsupported,
|
|
|
|
};
|
|
|
|
|
2020-06-09 20:39:30 +00:00
|
|
|
struct WiiButtonData {
|
|
|
|
uint8_t dpad_left : 1;
|
|
|
|
uint8_t dpad_right : 1;
|
|
|
|
uint8_t dpad_down : 1;
|
|
|
|
uint8_t dpad_up : 1;
|
|
|
|
uint8_t plus : 1;
|
|
|
|
uint8_t : 0;
|
|
|
|
|
|
|
|
uint8_t two : 1;
|
|
|
|
uint8_t one : 1;
|
|
|
|
uint8_t B : 1;
|
|
|
|
uint8_t A : 1;
|
|
|
|
uint8_t minus : 1;
|
|
|
|
uint8_t : 2;
|
|
|
|
uint8_t home : 1;
|
2020-07-11 11:43:21 +00:00
|
|
|
} __attribute__ ((__packed__));
|
2020-06-09 20:39:30 +00:00
|
|
|
|
2020-07-09 22:46:11 +00:00
|
|
|
struct WiiAccelerometerData {
|
2020-07-30 20:04:15 +00:00
|
|
|
uint8_t x;
|
|
|
|
uint8_t y;
|
|
|
|
uint8_t z;
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
|
|
struct WiiClassicControllerButtonData {
|
2020-08-11 23:04:32 +00:00
|
|
|
uint8_t : 1;
|
|
|
|
uint8_t R : 1;
|
|
|
|
uint8_t plus : 1;
|
|
|
|
uint8_t home : 1;
|
|
|
|
uint8_t minus : 1;
|
|
|
|
uint8_t L : 1;
|
|
|
|
uint8_t dpad_down : 1;
|
|
|
|
uint8_t dpad_right : 1;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-08-11 23:04:32 +00:00
|
|
|
uint8_t dpad_up : 1;
|
|
|
|
uint8_t dpad_left : 1;
|
|
|
|
uint8_t ZR : 1;
|
|
|
|
uint8_t X : 1;
|
|
|
|
uint8_t A : 1;
|
|
|
|
uint8_t Y : 1;
|
|
|
|
uint8_t B : 1;
|
|
|
|
uint8_t ZL : 1;
|
2020-07-11 11:43:21 +00:00
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
2020-07-30 20:04:15 +00:00
|
|
|
struct WiiNunchuckExtensionData {
|
|
|
|
uint8_t stick_x;
|
|
|
|
uint8_t stick_y;
|
|
|
|
uint8_t accel_x_92;
|
|
|
|
uint8_t accel_y_92;
|
|
|
|
uint8_t accel_z_92;
|
|
|
|
|
|
|
|
uint8_t Z : 1;
|
2020-08-11 23:30:03 +00:00
|
|
|
uint8_t C : 1;
|
|
|
|
uint8_t accel_x_10 : 2;
|
|
|
|
uint8_t accel_y_10 : 2;
|
|
|
|
uint8_t accel_z_10 : 2;
|
2020-08-14 22:33:37 +00:00
|
|
|
} __attribute__ ((__packed__));
|
2020-07-30 20:04:15 +00:00
|
|
|
|
|
|
|
struct WiiUProButtonData {
|
|
|
|
uint8_t : 1;
|
|
|
|
uint8_t R : 1;
|
|
|
|
uint8_t plus : 1;
|
|
|
|
uint8_t home : 1;
|
|
|
|
uint8_t minus : 1;
|
|
|
|
uint8_t L : 1;
|
|
|
|
uint8_t dpad_down : 1;
|
|
|
|
uint8_t dpad_right : 1;
|
|
|
|
|
|
|
|
uint8_t dpad_up : 1;
|
|
|
|
uint8_t dpad_left : 1;
|
|
|
|
uint8_t ZR : 1;
|
|
|
|
uint8_t X : 1;
|
|
|
|
uint8_t A : 1;
|
|
|
|
uint8_t Y : 1;
|
|
|
|
uint8_t B : 1;
|
|
|
|
uint8_t ZL : 1;
|
|
|
|
|
|
|
|
uint8_t rstick_press : 1;
|
|
|
|
uint8_t lstick_press : 1;
|
|
|
|
uint8_t : 0;
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
|
|
struct WiiUProExtensionData {
|
|
|
|
uint16_t left_stick_x;
|
|
|
|
uint16_t right_stick_x;
|
|
|
|
uint16_t left_stick_y;
|
|
|
|
uint16_t right_stick_y;
|
|
|
|
WiiUProButtonData buttons;
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
2020-09-24 00:40:33 +00:00
|
|
|
struct TaTaConExtensionData {
|
|
|
|
uint8_t _unk0[5];
|
|
|
|
|
|
|
|
uint8_t : 3;
|
|
|
|
uint8_t R_rim : 1;
|
|
|
|
uint8_t R_center : 1;
|
|
|
|
uint8_t L_rim : 1;
|
|
|
|
uint8_t L_center : 1;
|
|
|
|
uint8_t : 0;
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
2020-07-21 10:13:28 +00:00
|
|
|
struct WiiOutputReport0x10 {
|
2020-10-02 21:32:19 +00:00
|
|
|
uint8_t rumble : 1;
|
|
|
|
uint8_t : 0;
|
2020-07-21 10:13:28 +00:00
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
|
|
struct WiiOutputReport0x11 {
|
2020-10-02 21:32:19 +00:00
|
|
|
uint8_t rumble : 1;
|
|
|
|
uint8_t : 3;
|
|
|
|
uint8_t leds : 4;
|
2020-07-21 10:13:28 +00:00
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
|
|
struct WiiOutputReport0x12 {
|
2020-10-02 21:32:19 +00:00
|
|
|
uint8_t rumble : 1;
|
|
|
|
uint8_t : 0;
|
2020-07-21 10:13:28 +00:00
|
|
|
uint8_t report_mode;
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
|
|
struct WiiOutputReport0x14 {
|
|
|
|
uint8_t : 5;
|
|
|
|
uint8_t speaker_enable : 1;
|
|
|
|
uint8_t : 0;
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
|
|
struct WiiOutputReport0x15 {
|
2020-10-02 21:32:19 +00:00
|
|
|
uint8_t rumble : 1;
|
|
|
|
uint8_t : 0;
|
2020-07-21 10:13:28 +00:00
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
|
|
struct WiiOutputReport0x16 {
|
|
|
|
uint32_t address;
|
|
|
|
uint8_t size;
|
|
|
|
uint8_t data[16];
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
|
|
struct WiiOutputReport0x17 {
|
|
|
|
uint32_t address;
|
|
|
|
uint16_t size;
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
|
|
struct WiiOutputReport0x18 {
|
|
|
|
uint8_t size;
|
|
|
|
uint8_t speaker_data[20];
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
|
|
struct WiiOutputReport0x19 {
|
|
|
|
uint8_t : 5;
|
|
|
|
uint8_t speaker_mute : 1;
|
|
|
|
uint8_t : 0;
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
2020-07-11 18:30:17 +00:00
|
|
|
struct WiiInputReport0x20 {
|
|
|
|
WiiButtonData buttons;
|
2020-07-30 20:04:15 +00:00
|
|
|
uint8_t battery_critical : 1;
|
|
|
|
uint8_t extension_connected : 1;
|
|
|
|
uint8_t speaker_enabled : 1;
|
|
|
|
uint8_t ir_enabled : 1;
|
|
|
|
uint8_t led_state : 4;
|
2020-07-11 18:30:17 +00:00
|
|
|
uint8_t _pad[2];
|
|
|
|
uint8_t battery;
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
|
|
struct WiiInputReport0x21 {
|
|
|
|
WiiButtonData buttons;
|
|
|
|
uint8_t size : 4;
|
|
|
|
uint8_t error : 4;
|
|
|
|
uint16_t address;
|
|
|
|
uint8_t data[16];
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
|
|
struct WiiInputReport0x22 {
|
|
|
|
WiiButtonData buttons;
|
|
|
|
uint8_t report_id;
|
|
|
|
uint8_t error;
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
|
|
struct WiiInputReport0x30 {
|
2020-07-11 11:43:21 +00:00
|
|
|
WiiButtonData buttons;
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
2020-07-11 13:24:00 +00:00
|
|
|
struct WiiInputReport0x31 {
|
2020-07-11 11:43:21 +00:00
|
|
|
WiiButtonData buttons;
|
|
|
|
WiiAccelerometerData accel;
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
2020-07-11 13:24:00 +00:00
|
|
|
struct WiiInputReport0x32 {
|
2020-07-11 11:43:21 +00:00
|
|
|
WiiButtonData buttons;
|
|
|
|
uint8_t extension[8];
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
2020-07-11 13:24:00 +00:00
|
|
|
struct WiiInputReport0x33 {
|
2020-07-11 11:43:21 +00:00
|
|
|
WiiButtonData buttons;
|
|
|
|
WiiAccelerometerData accel;
|
|
|
|
uint8_t ir[12];
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
2020-07-11 13:24:00 +00:00
|
|
|
struct WiiInputReport0x34 {
|
2020-07-11 11:43:21 +00:00
|
|
|
WiiButtonData buttons;
|
|
|
|
uint8_t extension[19];
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
2020-07-11 13:24:00 +00:00
|
|
|
struct WiiInputReport0x35 {
|
2020-07-11 11:43:21 +00:00
|
|
|
WiiButtonData buttons;
|
|
|
|
WiiAccelerometerData accel;
|
|
|
|
uint8_t extension[16];
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
2020-07-11 13:24:00 +00:00
|
|
|
struct WiiInputReport0x36 {
|
2020-07-11 11:43:21 +00:00
|
|
|
WiiButtonData buttons;
|
|
|
|
uint8_t ir[10];
|
|
|
|
uint8_t extension[9];
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
2020-07-11 13:24:00 +00:00
|
|
|
struct WiiInputReport0x37 {
|
2020-07-11 11:43:21 +00:00
|
|
|
WiiButtonData buttons;
|
|
|
|
WiiAccelerometerData accel;
|
|
|
|
uint8_t ir[10];
|
|
|
|
uint8_t extension[6];
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
2020-07-11 13:24:00 +00:00
|
|
|
struct WiiInputReport0x3d {
|
2020-07-11 11:43:21 +00:00
|
|
|
uint8_t extension[21];
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
|
|
|
|
struct WiiReportData {
|
|
|
|
uint8_t id;
|
|
|
|
union {
|
2020-07-11 18:30:17 +00:00
|
|
|
WiiOutputReport0x10 output0x10;
|
|
|
|
WiiOutputReport0x11 output0x11;
|
|
|
|
WiiOutputReport0x12 output0x12;
|
|
|
|
WiiOutputReport0x14 output0x14;
|
|
|
|
WiiOutputReport0x15 output0x15;
|
|
|
|
WiiOutputReport0x16 output0x16;
|
|
|
|
WiiOutputReport0x17 output0x17;
|
|
|
|
WiiOutputReport0x18 output0x18;
|
|
|
|
WiiOutputReport0x19 output0x19;
|
2020-07-21 10:13:28 +00:00
|
|
|
WiiInputReport0x20 input0x20;
|
|
|
|
WiiInputReport0x21 input0x21;
|
|
|
|
WiiInputReport0x22 input0x22;
|
|
|
|
WiiInputReport0x30 input0x30;
|
|
|
|
WiiInputReport0x31 input0x31;
|
|
|
|
WiiInputReport0x32 input0x32;
|
|
|
|
WiiInputReport0x33 input0x33;
|
|
|
|
WiiInputReport0x34 input0x34;
|
|
|
|
WiiInputReport0x35 input0x35;
|
|
|
|
WiiInputReport0x36 input0x36;
|
|
|
|
WiiInputReport0x37 input0x37;
|
|
|
|
WiiInputReport0x3d input0x3d;
|
2020-07-11 11:43:21 +00:00
|
|
|
};
|
|
|
|
} __attribute__ ((__packed__));
|
2020-07-09 22:46:11 +00:00
|
|
|
|
2020-08-17 21:17:02 +00:00
|
|
|
class WiiController : public EmulatedSwitchController {
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-07-30 20:04:15 +00:00
|
|
|
public:
|
2020-08-26 18:52:47 +00:00
|
|
|
static constexpr const HardwareID hardware_ids[] = {
|
|
|
|
{0x057e, 0x0306}, // Official Wiimote
|
|
|
|
{0x057e, 0x0330}, // Official Wii U Pro Controller
|
|
|
|
};
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
WiiController(const bluetooth::Address *address)
|
|
|
|
: EmulatedSwitchController(address)
|
2020-10-02 21:32:19 +00:00
|
|
|
, m_extension(WiiExtensionController_None)
|
|
|
|
, m_rumble_state(0) { };
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
Result Initialize(void);
|
2020-10-02 21:32:19 +00:00
|
|
|
Result SetVibration(const SwitchRumbleData *left, const SwitchRumbleData *right);
|
2020-10-03 09:53:12 +00:00
|
|
|
Result CancelVibration(void);
|
2020-10-02 21:32:19 +00:00
|
|
|
Result SetPlayerLed(uint8_t led_mask);
|
2020-10-03 15:22:21 +00:00
|
|
|
void UpdateControllerState(const bluetooth::HidReport *report);
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
protected:
|
2020-10-03 15:22:21 +00:00
|
|
|
void HandleInputReport0x20(const WiiReportData *src);
|
|
|
|
void HandleInputReport0x21(const WiiReportData *src);
|
|
|
|
void HandleInputReport0x22(const WiiReportData *src);
|
|
|
|
void HandleInputReport0x30(const WiiReportData *src);
|
|
|
|
void HandleInputReport0x31(const WiiReportData *src);
|
|
|
|
void HandleInputReport0x32(const WiiReportData *src);
|
|
|
|
void HandleInputReport0x34(const WiiReportData *src);
|
|
|
|
|
|
|
|
void MapButtonsHorizontalOrientation(const WiiButtonData *buttons);
|
|
|
|
void MapButtonsVerticalOrientation(const WiiButtonData *buttons);
|
|
|
|
|
|
|
|
void MapExtensionBytes(const uint8_t ext[]);
|
|
|
|
void MapNunchuckExtension(const uint8_t ext[]);
|
|
|
|
void MapClassicControllerExtension(const uint8_t ext[]);
|
|
|
|
void MapWiiUProControllerExtension(const uint8_t ext[]);
|
|
|
|
void MapTaTaConExtension(const uint8_t ext[]);
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
Result WriteMemory(uint32_t write_addr, const uint8_t *data, uint8_t size);
|
|
|
|
Result ReadMemory(uint32_t read_addr, uint16_t size);
|
2020-07-27 17:39:09 +00:00
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
Result SetReportMode(uint8_t mode);
|
|
|
|
Result QueryStatus(void);
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-07-30 20:04:15 +00:00
|
|
|
WiiExtensionController m_extension;
|
2020-10-02 21:32:19 +00:00
|
|
|
bool m_rumble_state;
|
2020-06-02 21:24:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|