suyu/src/core/hle/service/hid/hid.h

340 lines
9.1 KiB
C
Raw Normal View History

// Copyright 2018 yuzu emulator team
2014-12-17 06:38:14 +01:00
// Licensed under GPLv2 or any later version
2014-04-17 02:58:36 +02:00
// Refer to the license.txt file included.
#pragma once
#include "core/hle/service/service.h"
2018-01-15 10:21:02 +01:00
#include "core/settings.h"
namespace Service::HID {
2014-04-17 02:58:36 +02:00
2018-01-15 08:13:18 +01:00
// Begin enums and output structs
constexpr u32 HID_NUM_ENTRIES = 17;
constexpr u32 HID_NUM_LAYOUTS = 7;
constexpr s32 HID_JOYSTICK_MAX = 0x8000;
constexpr s32 HID_JOYSTICK_MIN = -0x8000;
2018-01-17 03:22:12 +01:00
constexpr u32 JOYCON_BODY_NEON_RED = 0xFF3C28;
constexpr u32 JOYCON_BUTTONS_NEON_RED = 0x1E0A0A;
constexpr u32 JOYCON_BODY_NEON_BLUE = 0x0AB9E6;
constexpr u32 JOYCON_BUTTONS_NEON_BLUE = 0x001E1E;
enum ControllerType : u32 {
2018-01-15 08:13:18 +01:00
ControllerType_ProController = 1 << 0,
ControllerType_Handheld = 1 << 1,
ControllerType_JoyconPair = 1 << 2,
ControllerType_JoyconLeft = 1 << 3,
ControllerType_JoyconRight = 1 << 4,
};
enum ControllerLayoutType : u32 {
2018-01-15 08:13:18 +01:00
Layout_ProController = 0, // Pro Controller or HID gamepad
Layout_Handheld = 1, // Two Joy-Con docked to rails
Layout_Single = 2, // Horizontal single Joy-Con or pair of Joy-Con, adjusted for orientation
Layout_Left = 3, // Only raw left Joy-Con state, no orientation adjustment
Layout_Right = 4, // Only raw right Joy-Con state, no orientation adjustment
Layout_DefaultDigital = 5, // Same as next, but sticks have 8-direction values only
Layout_Default = 6, // Safe default, single Joy-Con have buttons/sticks rotated for orientation
};
enum ControllerColorDescription {
2018-01-15 08:13:18 +01:00
ColorDesc_ColorsNonexistent = 1 << 1,
};
enum ControllerConnectionState {
2018-01-15 08:13:18 +01:00
ConnectionState_Connected = 1 << 0,
ConnectionState_Wired = 1 << 1,
};
enum ControllerID {
2018-01-15 08:13:18 +01:00
Controller_Player1 = 0,
Controller_Player2 = 1,
Controller_Player3 = 2,
Controller_Player4 = 3,
Controller_Player5 = 4,
Controller_Player6 = 5,
Controller_Player7 = 6,
Controller_Player8 = 7,
Controller_Handheld = 8,
Controller_Unknown = 9,
};
// End enums and output structs
// Begin TouchScreen
2018-01-15 08:13:18 +01:00
struct TouchScreenHeader {
2018-01-17 03:22:12 +01:00
u64 timestamp_ticks;
u64 num_entries;
u64 latest_entry;
u64 max_entry_index;
2018-01-15 08:13:18 +01:00
u64 timestamp;
};
static_assert(sizeof(TouchScreenHeader) == 0x28,
2018-01-15 08:13:18 +01:00
"HID touch screen header structure has incorrect size");
struct TouchScreenEntryHeader {
2018-01-15 08:13:18 +01:00
u64 timestamp;
2018-01-17 03:22:12 +01:00
u64 num_touches;
2018-01-15 08:13:18 +01:00
};
static_assert(sizeof(TouchScreenEntryHeader) == 0x10,
2018-01-15 08:13:18 +01:00
"HID touch screen entry header structure has incorrect size");
struct TouchScreenEntryTouch {
2018-01-15 08:13:18 +01:00
u64 timestamp;
u32 padding;
2018-01-17 03:22:12 +01:00
u32 touch_index;
2018-01-15 08:13:18 +01:00
u32 x;
u32 y;
2018-01-17 03:22:12 +01:00
u32 diameter_x;
u32 diameter_y;
2018-01-15 08:13:18 +01:00
u32 angle;
u32 padding_2;
};
static_assert(sizeof(TouchScreenEntryTouch) == 0x28,
2018-01-15 08:13:18 +01:00
"HID touch screen touch structure has incorrect size");
struct TouchScreenEntry {
TouchScreenEntryHeader header;
std::array<TouchScreenEntryTouch, 16> touches;
2018-01-15 08:13:18 +01:00
u64 unk;
};
static_assert(sizeof(TouchScreenEntry) == 0x298,
2018-01-15 08:13:18 +01:00
"HID touch screen entry structure has incorrect size");
struct TouchScreen {
TouchScreenHeader header;
std::array<TouchScreenEntry, 17> entries;
2018-01-15 08:13:18 +01:00
std::array<u8, 0x3c0> padding;
};
static_assert(sizeof(TouchScreen) == 0x3000, "HID touch screen structure has incorrect size");
2018-01-15 08:13:18 +01:00
// End TouchScreen
2018-01-15 08:13:18 +01:00
// Begin Mouse
2018-01-15 08:13:18 +01:00
struct MouseHeader {
2018-01-17 03:22:12 +01:00
u64 timestamp_ticks;
u64 num_entries;
u64 latest_entry;
u64 max_entry_index;
2018-01-15 08:13:18 +01:00
};
static_assert(sizeof(MouseHeader) == 0x20, "HID mouse header structure has incorrect size");
2018-01-15 08:13:18 +01:00
struct MouseButtonState {
2018-01-15 08:13:18 +01:00
union {
u64 hex{};
// Buttons
BitField<0, 1, u64> left;
BitField<1, 1, u64> right;
BitField<2, 1, u64> middle;
BitField<3, 1, u64> forward;
BitField<4, 1, u64> back;
};
};
struct MouseEntry {
2018-01-15 08:13:18 +01:00
u64 timestamp;
u64 timestamp_2;
u32 x;
u32 y;
2018-01-17 03:22:12 +01:00
u32 velocity_x;
u32 velocity_y;
u32 scroll_velocity_x;
u32 scroll_velocity_y;
MouseButtonState buttons;
2018-01-15 08:13:18 +01:00
};
static_assert(sizeof(MouseEntry) == 0x30, "HID mouse entry structure has incorrect size");
2018-01-15 08:13:18 +01:00
struct Mouse {
MouseHeader header;
std::array<MouseEntry, 17> entries;
2018-01-15 08:13:18 +01:00
std::array<u8, 0xB0> padding;
};
static_assert(sizeof(Mouse) == 0x400, "HID mouse structure has incorrect size");
2018-01-15 08:13:18 +01:00
// End Mouse
2018-01-15 08:13:18 +01:00
// Begin Keyboard
2018-01-15 08:13:18 +01:00
struct KeyboardHeader {
2018-01-17 03:22:12 +01:00
u64 timestamp_ticks;
u64 num_entries;
u64 latest_entry;
u64 max_entry_index;
2018-01-15 08:13:18 +01:00
};
2018-01-15 10:21:02 +01:00
static_assert(sizeof(KeyboardHeader) == 0x20, "HID keyboard header structure has incorrect size");
2018-01-15 08:13:18 +01:00
struct KeyboardModifierKeyState {
2018-01-15 08:13:18 +01:00
union {
u64 hex{};
// Buttons
BitField<0, 1, u64> lctrl;
BitField<1, 1, u64> lshift;
BitField<2, 1, u64> lalt;
BitField<3, 1, u64> lmeta;
BitField<4, 1, u64> rctrl;
BitField<5, 1, u64> rshift;
BitField<6, 1, u64> ralt;
BitField<7, 1, u64> rmeta;
BitField<8, 1, u64> capslock;
BitField<9, 1, u64> scrolllock;
BitField<10, 1, u64> numlock;
};
};
struct KeyboardEntry {
2018-01-15 08:13:18 +01:00
u64 timestamp;
u64 timestamp_2;
KeyboardModifierKeyState modifier;
2018-01-15 08:13:18 +01:00
u32 keys[8];
};
static_assert(sizeof(KeyboardEntry) == 0x38, "HID keyboard entry structure has incorrect size");
2018-01-15 08:13:18 +01:00
struct Keyboard {
KeyboardHeader header;
std::array<KeyboardEntry, 17> entries;
2018-01-15 08:13:18 +01:00
std::array<u8, 0x28> padding;
};
static_assert(sizeof(Keyboard) == 0x400, "HID keyboard structure has incorrect size");
2018-01-15 08:13:18 +01:00
// End Keyboard
2018-01-15 08:13:18 +01:00
// Begin Controller
2018-01-15 08:13:18 +01:00
struct ControllerMAC {
2018-01-15 08:13:18 +01:00
u64 timestamp;
std::array<u8, 0x8> mac;
u64 unk;
u64 timestamp_2;
};
static_assert(sizeof(ControllerMAC) == 0x20, "HID controller MAC structure has incorrect size");
2018-01-15 08:13:18 +01:00
struct ControllerHeader {
2018-01-15 08:13:18 +01:00
u32 type;
2018-01-17 03:22:12 +01:00
u32 is_half;
u32 single_colors_descriptor;
u32 single_color_body;
u32 single_color_buttons;
u32 split_colors_descriptor;
u32 left_color_body;
u32 left_color_buttons;
u32 right_color_body;
u32 right_color_buttons;
2018-01-15 08:13:18 +01:00
};
static_assert(sizeof(ControllerHeader) == 0x28,
2018-01-15 08:13:18 +01:00
"HID controller header structure has incorrect size");
struct ControllerLayoutHeader {
2018-01-17 03:22:12 +01:00
u64 timestamp_ticks;
u64 num_entries;
u64 latest_entry;
u64 max_entry_index;
2018-01-15 08:13:18 +01:00
};
static_assert(sizeof(ControllerLayoutHeader) == 0x20,
2018-01-15 08:13:18 +01:00
"HID controller layout header structure has incorrect size");
struct ControllerPadState {
2018-01-15 08:13:18 +01:00
union {
u64 hex{};
// Buttons
BitField<0, 1, u64> a;
BitField<1, 1, u64> b;
BitField<2, 1, u64> x;
BitField<3, 1, u64> y;
BitField<4, 1, u64> lstick;
BitField<5, 1, u64> rstick;
BitField<6, 1, u64> l;
BitField<7, 1, u64> r;
BitField<8, 1, u64> zl;
BitField<9, 1, u64> zr;
BitField<10, 1, u64> plus;
BitField<11, 1, u64> minus;
// D-pad buttons
BitField<12, 1, u64> dleft;
BitField<13, 1, u64> dup;
BitField<14, 1, u64> dright;
BitField<15, 1, u64> ddown;
// Left stick directions
BitField<16, 1, u64> lstick_left;
BitField<17, 1, u64> lstick_up;
BitField<18, 1, u64> lstick_right;
BitField<19, 1, u64> lstick_down;
// Right stick directions
BitField<20, 1, u64> rstick_left;
BitField<21, 1, u64> rstick_up;
BitField<22, 1, u64> rstick_right;
BitField<23, 1, u64> rstick_down;
BitField<24, 1, u64> sl;
BitField<25, 1, u64> sr;
};
};
struct ControllerInputEntry {
2018-01-15 08:13:18 +01:00
u64 timestamp;
u64 timestamp_2;
ControllerPadState buttons;
2018-01-17 03:22:12 +01:00
u32 joystick_left_x;
u32 joystick_left_y;
u32 joystick_right_x;
u32 joystick_right_y;
u64 connection_state;
2018-01-15 08:13:18 +01:00
};
static_assert(sizeof(ControllerInputEntry) == 0x30,
2018-01-15 08:13:18 +01:00
"HID controller input entry structure has incorrect size");
struct ControllerLayout {
ControllerLayoutHeader header;
std::array<ControllerInputEntry, 17> entries;
2018-01-15 08:13:18 +01:00
};
static_assert(sizeof(ControllerLayout) == 0x350,
2018-01-15 08:13:18 +01:00
"HID controller layout structure has incorrect size");
struct Controller {
ControllerHeader header;
std::array<ControllerLayout, 7> layouts;
2018-01-15 08:13:18 +01:00
std::array<u8, 0x2a70> unk_1;
2018-01-17 03:22:12 +01:00
ControllerMAC mac_left;
ControllerMAC mac_right;
2018-01-15 08:13:18 +01:00
std::array<u8, 0xdf8> unk_2;
};
static_assert(sizeof(Controller) == 0x5000, "HID controller structure has incorrect size");
2018-01-15 08:13:18 +01:00
// End Controller
2018-01-15 08:13:18 +01:00
struct SharedMemory {
2018-01-15 08:13:18 +01:00
std::array<u8, 0x400> header;
TouchScreen touchscreen;
Mouse mouse;
Keyboard keyboard;
2018-01-17 03:22:12 +01:00
std::array<u8, 0x400> unk_section_1;
std::array<u8, 0x400> unk_section_2;
std::array<u8, 0x400> unk_section_3;
std::array<u8, 0x400> unk_section_4;
std::array<u8, 0x200> unk_section_5;
std::array<u8, 0x200> unk_section_6;
std::array<u8, 0x200> unk_section_7;
std::array<u8, 0x800> unk_section_8;
std::array<u8, 0x4000> controller_serials;
std::array<Controller, 10> controllers;
2018-01-17 03:22:12 +01:00
std::array<u8, 0x4600> unk_section_9;
2018-01-15 08:13:18 +01:00
};
static_assert(sizeof(SharedMemory) == 0x40000, "HID Shared Memory structure has incorrect size");
2018-01-15 08:13:18 +01:00
2017-01-20 21:46:39 +01:00
/// Reload input devices. Used when input configuration changed
void ReloadInputDevices();
2017-10-13 03:21:49 +02:00
/// Registers all HID services with the specified service manager.
void InstallInterfaces(SM::ServiceManager& service_manager);
} // namespace Service::HID