From e08c132175232aca748321be3fb76b309c281eb6 Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Mon, 15 Jan 2018 00:13:18 -0700 Subject: hid: Add sharedmem structs --- src/core/hle/service/hid/hid.h | 312 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 312 insertions(+) (limited to 'src/core/hle/service/hid') diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index f7621f62d..7803778d4 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -9,6 +9,318 @@ namespace Service { namespace HID { +// Begin enums and output structs + +enum HIDControllerType : u32 { + ControllerType_ProController = 1 << 0, + ControllerType_Handheld = 1 << 1, + ControllerType_JoyconPair = 1 << 2, + ControllerType_JoyconLeft = 1 << 3, + ControllerType_JoyconRight = 1 << 4, +}; + +enum HIDControllerLayoutType : u32 { + 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 HIDControllerColorDescription { + ColorDesc_ColorsNonexistent = 1 << 1, +}; + +enum HIDControllerConnectionState { + ConnectionState_Connected = 1 << 0, + ConnectionState_Wired = 1 << 1, +}; + +enum HIDControllerID { + 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 HIDTouchScreen + +struct HIDTouchScreenHeader { + u64 timestampTicks; + u64 numEntries; + u64 latestEntry; + u64 maxEntryIndex; + u64 timestamp; +}; +static_assert(sizeof(HIDTouchScreenHeader) == 0x28, + "HID touch screen header structure has incorrect size"); + +struct HIDTouchScreenEntryHeader { + u64 timestamp; + u64 numTouches; +}; +static_assert(sizeof(HIDTouchScreenEntryHeader) == 0x10, + "HID touch screen entry header structure has incorrect size"); + +struct HIDTouchScreenEntryTouch { + u64 timestamp; + u32 padding; + u32 touchIndex; + u32 x; + u32 y; + u32 diameterX; + u32 diameterY; + u32 angle; + u32 padding_2; +}; +static_assert(sizeof(HIDTouchScreenEntryTouch) == 0x28, + "HID touch screen touch structure has incorrect size"); + +struct HIDTouchScreenEntry { + HIDTouchScreenEntryHeader header; + std::array touches; + u64 unk; +}; +static_assert(sizeof(HIDTouchScreenEntry) == 0x298, + "HID touch screen entry structure has incorrect size"); + +struct HIDTouchScreen { + HIDTouchScreenHeader header; + std::array entries; + std::array padding; +}; +static_assert(sizeof(HIDTouchScreen) == 0x3000, "HID touch screen structure has incorrect size"); + +// End HIDTouchScreen + +// Begin HIDMouse + +struct HIDMouseHeader { + u64 timestampTicks; + u64 numEntries; + u64 latestEntry; + u64 maxEntryIndex; +}; +static_assert(sizeof(HIDMouseHeader) == 0x20, "HID mouse header structure has incorrect size"); + +struct HIDMouseButtonState { + 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 HIDMouseEntry { + u64 timestamp; + u64 timestamp_2; + u32 x; + u32 y; + u32 velocityX; + u32 velocityY; + u32 scrollVelocityX; + u32 scrollVelocityY; + HIDMouseButtonState buttons; +}; +static_assert(sizeof(HIDMouseEntry) == 0x30, "HID mouse entry structure has incorrect size"); + +struct HIDMouse { + HIDMouseHeader header; + std::array entries; + std::array padding; +}; +static_assert(sizeof(HIDMouse) == 0x400, "HID mouse structure has incorrect size"); + +// End HIDMouse + +// Begin HIDKeyboard + +struct HIDKeyboardHeader { + u64 timestampTicks; + u64 numEntries; + u64 latestEntry; + u64 maxEntryIndex; +}; +static_assert(sizeof(HIDKeyboardHeader) == 0x20, + "HID keyboard header structure has incorrect size"); + +struct HIDKeyboardModifierKeyState { + 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 HIDKeyboardEntry { + u64 timestamp; + u64 timestamp_2; + HIDKeyboardModifierKeyState modifier; + u32 keys[8]; +}; +static_assert(sizeof(HIDKeyboardEntry) == 0x38, "HID keyboard entry structure has incorrect size"); + +struct HIDKeyboard { + HIDKeyboardHeader header; + std::array entries; + std::array padding; +}; +static_assert(sizeof(HIDKeyboard) == 0x400, "HID keyboard structure has incorrect size"); + +// End HIDKeyboard + +// Begin HIDController + +struct HIDControllerMAC { + u64 timestamp; + std::array mac; + u64 unk; + u64 timestamp_2; +}; +static_assert(sizeof(HIDControllerMAC) == 0x20, "HID controller MAC structure has incorrect size"); + +struct HIDControllerHeader { + u32 type; + u32 isHalf; + u32 singleColorsDescriptor; + u32 singleColorBody; + u32 singleColorButtons; + u32 splitColorsDescriptor; + u32 leftColorBody; + u32 leftColorButtons; + u32 rightColorBody; + u32 rightColorbuttons; +}; +static_assert(sizeof(HIDControllerHeader) == 0x28, + "HID controller header structure has incorrect size"); + +struct HIDControllerLayoutHeader { + u64 timestampTicks; + u64 numEntries; + u64 latestEntry; + u64 maxEntryIndex; +}; +static_assert(sizeof(HIDControllerLayoutHeader) == 0x20, + "HID controller layout header structure has incorrect size"); + +struct HIDControllerPadState { + 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 HIDControllerInputEntry { + u64 timestamp; + u64 timestamp_2; + HIDControllerPadState buttons; + u32 joystickLeftX; + u32 joystickLeftY; + u32 joystickRightX; + u32 joystickRightY; + u64 connectionState; +}; +static_assert(sizeof(HIDControllerInputEntry) == 0x30, + "HID controller input entry structure has incorrect size"); + +struct HIDControllerLayout { + HIDControllerLayoutHeader header; + std::array entries; +}; +static_assert(sizeof(HIDControllerLayout) == 0x350, + "HID controller layout structure has incorrect size"); + +struct HIDController { + HIDControllerHeader header; + std::array layouts; + std::array unk_1; + HIDControllerMAC macLeft; + HIDControllerMAC macRight; + std::array unk_2; +}; +static_assert(sizeof(HIDController) == 0x5000, "HID controller structure has incorrect size"); + +// End HIDController + +struct HIDSharedMemory { + std::array header; + HIDTouchScreen touchscreen; + HIDMouse mouse; + HIDKeyboard keyboard; + std::array unkSection1; + std::array unkSection2; + std::array unkSection3; + std::array unkSection4; + std::array unkSection5; + std::array unkSection6; + std::array unkSection7; + std::array unkSection8; + std::array controllerSerials; + std::array controllers; + std::array unkSection9; +}; +static_assert(sizeof(HIDSharedMemory) == 0x40000, "HID Shared Memory structure has incorrect size"); + /// Reload input devices. Used when input configuration changed void ReloadInputDevices(); -- cgit v1.2.3 From bb1fcfac3377ca207b3cfc0c50ecae2b31462cd5 Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Mon, 15 Jan 2018 01:49:32 -0700 Subject: hid: Remove redundant HID prefix on structs/enums --- src/core/hle/service/hid/hid.h | 146 ++++++++++++++++++++--------------------- 1 file changed, 73 insertions(+), 73 deletions(-) (limited to 'src/core/hle/service/hid') diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 7803778d4..7fd45d56f 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -11,7 +11,7 @@ namespace HID { // Begin enums and output structs -enum HIDControllerType : u32 { +enum ControllerType : u32 { ControllerType_ProController = 1 << 0, ControllerType_Handheld = 1 << 1, ControllerType_JoyconPair = 1 << 2, @@ -19,7 +19,7 @@ enum HIDControllerType : u32 { ControllerType_JoyconRight = 1 << 4, }; -enum HIDControllerLayoutType : u32 { +enum ControllerLayoutType : u32 { 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 @@ -29,16 +29,16 @@ enum HIDControllerLayoutType : u32 { Layout_Default = 6, // Safe default, single Joy-Con have buttons/sticks rotated for orientation }; -enum HIDControllerColorDescription { +enum ControllerColorDescription { ColorDesc_ColorsNonexistent = 1 << 1, }; -enum HIDControllerConnectionState { +enum ControllerConnectionState { ConnectionState_Connected = 1 << 0, ConnectionState_Wired = 1 << 1, }; -enum HIDControllerID { +enum ControllerID { Controller_Player1 = 0, Controller_Player2 = 1, Controller_Player3 = 2, @@ -53,26 +53,26 @@ enum HIDControllerID { // End enums and output structs -// Begin HIDTouchScreen +// Begin TouchScreen -struct HIDTouchScreenHeader { +struct TouchScreenHeader { u64 timestampTicks; u64 numEntries; u64 latestEntry; u64 maxEntryIndex; u64 timestamp; }; -static_assert(sizeof(HIDTouchScreenHeader) == 0x28, +static_assert(sizeof(TouchScreenHeader) == 0x28, "HID touch screen header structure has incorrect size"); -struct HIDTouchScreenEntryHeader { +struct TouchScreenEntryHeader { u64 timestamp; u64 numTouches; }; -static_assert(sizeof(HIDTouchScreenEntryHeader) == 0x10, +static_assert(sizeof(TouchScreenEntryHeader) == 0x10, "HID touch screen entry header structure has incorrect size"); -struct HIDTouchScreenEntryTouch { +struct TouchScreenEntryTouch { u64 timestamp; u32 padding; u32 touchIndex; @@ -83,37 +83,37 @@ struct HIDTouchScreenEntryTouch { u32 angle; u32 padding_2; }; -static_assert(sizeof(HIDTouchScreenEntryTouch) == 0x28, +static_assert(sizeof(TouchScreenEntryTouch) == 0x28, "HID touch screen touch structure has incorrect size"); -struct HIDTouchScreenEntry { - HIDTouchScreenEntryHeader header; - std::array touches; +struct TouchScreenEntry { + TouchScreenEntryHeader header; + std::array touches; u64 unk; }; -static_assert(sizeof(HIDTouchScreenEntry) == 0x298, +static_assert(sizeof(TouchScreenEntry) == 0x298, "HID touch screen entry structure has incorrect size"); -struct HIDTouchScreen { - HIDTouchScreenHeader header; - std::array entries; +struct TouchScreen { + TouchScreenHeader header; + std::array entries; std::array padding; }; -static_assert(sizeof(HIDTouchScreen) == 0x3000, "HID touch screen structure has incorrect size"); +static_assert(sizeof(TouchScreen) == 0x3000, "HID touch screen structure has incorrect size"); -// End HIDTouchScreen +// End TouchScreen -// Begin HIDMouse +// Begin Mouse -struct HIDMouseHeader { +struct MouseHeader { u64 timestampTicks; u64 numEntries; u64 latestEntry; u64 maxEntryIndex; }; -static_assert(sizeof(HIDMouseHeader) == 0x20, "HID mouse header structure has incorrect size"); +static_assert(sizeof(MouseHeader) == 0x20, "HID mouse header structure has incorrect size"); -struct HIDMouseButtonState { +struct MouseButtonState { union { u64 hex{}; @@ -126,7 +126,7 @@ struct HIDMouseButtonState { }; }; -struct HIDMouseEntry { +struct MouseEntry { u64 timestamp; u64 timestamp_2; u32 x; @@ -135,31 +135,31 @@ struct HIDMouseEntry { u32 velocityY; u32 scrollVelocityX; u32 scrollVelocityY; - HIDMouseButtonState buttons; + MouseButtonState buttons; }; -static_assert(sizeof(HIDMouseEntry) == 0x30, "HID mouse entry structure has incorrect size"); +static_assert(sizeof(MouseEntry) == 0x30, "HID mouse entry structure has incorrect size"); -struct HIDMouse { - HIDMouseHeader header; - std::array entries; +struct Mouse { + MouseHeader header; + std::array entries; std::array padding; }; -static_assert(sizeof(HIDMouse) == 0x400, "HID mouse structure has incorrect size"); +static_assert(sizeof(Mouse) == 0x400, "HID mouse structure has incorrect size"); -// End HIDMouse +// End Mouse -// Begin HIDKeyboard +// Begin Keyboard -struct HIDKeyboardHeader { +struct KeyboardHeader { u64 timestampTicks; u64 numEntries; u64 latestEntry; u64 maxEntryIndex; }; -static_assert(sizeof(HIDKeyboardHeader) == 0x20, +static_assert(sizeof(KeyboardHeader) == 0x20, "HID keyboard header structure has incorrect size"); -struct HIDKeyboardModifierKeyState { +struct KeyboardModifierKeyState { union { u64 hex{}; @@ -178,34 +178,34 @@ struct HIDKeyboardModifierKeyState { }; }; -struct HIDKeyboardEntry { +struct KeyboardEntry { u64 timestamp; u64 timestamp_2; - HIDKeyboardModifierKeyState modifier; + KeyboardModifierKeyState modifier; u32 keys[8]; }; -static_assert(sizeof(HIDKeyboardEntry) == 0x38, "HID keyboard entry structure has incorrect size"); +static_assert(sizeof(KeyboardEntry) == 0x38, "HID keyboard entry structure has incorrect size"); -struct HIDKeyboard { - HIDKeyboardHeader header; - std::array entries; +struct Keyboard { + KeyboardHeader header; + std::array entries; std::array padding; }; -static_assert(sizeof(HIDKeyboard) == 0x400, "HID keyboard structure has incorrect size"); +static_assert(sizeof(Keyboard) == 0x400, "HID keyboard structure has incorrect size"); -// End HIDKeyboard +// End Keyboard -// Begin HIDController +// Begin Controller -struct HIDControllerMAC { +struct ControllerMAC { u64 timestamp; std::array mac; u64 unk; u64 timestamp_2; }; -static_assert(sizeof(HIDControllerMAC) == 0x20, "HID controller MAC structure has incorrect size"); +static_assert(sizeof(ControllerMAC) == 0x20, "HID controller MAC structure has incorrect size"); -struct HIDControllerHeader { +struct ControllerHeader { u32 type; u32 isHalf; u32 singleColorsDescriptor; @@ -217,19 +217,19 @@ struct HIDControllerHeader { u32 rightColorBody; u32 rightColorbuttons; }; -static_assert(sizeof(HIDControllerHeader) == 0x28, +static_assert(sizeof(ControllerHeader) == 0x28, "HID controller header structure has incorrect size"); -struct HIDControllerLayoutHeader { +struct ControllerLayoutHeader { u64 timestampTicks; u64 numEntries; u64 latestEntry; u64 maxEntryIndex; }; -static_assert(sizeof(HIDControllerLayoutHeader) == 0x20, +static_assert(sizeof(ControllerLayoutHeader) == 0x20, "HID controller layout header structure has incorrect size"); -struct HIDControllerPadState { +struct ControllerPadState { union { u64 hex{}; @@ -270,43 +270,43 @@ struct HIDControllerPadState { }; }; -struct HIDControllerInputEntry { +struct ControllerInputEntry { u64 timestamp; u64 timestamp_2; - HIDControllerPadState buttons; + ControllerPadState buttons; u32 joystickLeftX; u32 joystickLeftY; u32 joystickRightX; u32 joystickRightY; u64 connectionState; }; -static_assert(sizeof(HIDControllerInputEntry) == 0x30, +static_assert(sizeof(ControllerInputEntry) == 0x30, "HID controller input entry structure has incorrect size"); -struct HIDControllerLayout { - HIDControllerLayoutHeader header; - std::array entries; +struct ControllerLayout { + ControllerLayoutHeader header; + std::array entries; }; -static_assert(sizeof(HIDControllerLayout) == 0x350, +static_assert(sizeof(ControllerLayout) == 0x350, "HID controller layout structure has incorrect size"); -struct HIDController { - HIDControllerHeader header; - std::array layouts; +struct Controller { + ControllerHeader header; + std::array layouts; std::array unk_1; - HIDControllerMAC macLeft; - HIDControllerMAC macRight; + ControllerMAC macLeft; + ControllerMAC macRight; std::array unk_2; }; -static_assert(sizeof(HIDController) == 0x5000, "HID controller structure has incorrect size"); +static_assert(sizeof(Controller) == 0x5000, "HID controller structure has incorrect size"); -// End HIDController +// End Controller -struct HIDSharedMemory { +struct SharedMemory { std::array header; - HIDTouchScreen touchscreen; - HIDMouse mouse; - HIDKeyboard keyboard; + TouchScreen touchscreen; + Mouse mouse; + Keyboard keyboard; std::array unkSection1; std::array unkSection2; std::array unkSection3; @@ -316,10 +316,10 @@ struct HIDSharedMemory { std::array unkSection7; std::array unkSection8; std::array controllerSerials; - std::array controllers; + std::array controllers; std::array unkSection9; }; -static_assert(sizeof(HIDSharedMemory) == 0x40000, "HID Shared Memory structure has incorrect size"); +static_assert(sizeof(SharedMemory) == 0x40000, "HID Shared Memory structure has incorrect size"); /// Reload input devices. Used when input configuration changed void ReloadInputDevices(); -- cgit v1.2.3 From 1ea49442f9c21aa20559894ae18353cee1179c76 Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Mon, 15 Jan 2018 02:21:02 -0700 Subject: hid: Bare-minimum sharedmem input --- src/core/hle/service/hid/hid.cpp | 86 ++++++++++++++++++++++++++++++++++++++++ src/core/hle/service/hid/hid.h | 4 +- 2 files changed, 88 insertions(+), 2 deletions(-) (limited to 'src/core/hle/service/hid') diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 3f74aed06..3c4259d27 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -2,7 +2,10 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include "common/logging/log.h" +#include "core/core_timing.h" +#include "core/frontend/input.h" #include "core/hle/ipc_helpers.h" #include "core/hle/kernel/client_port.h" #include "core/hle/kernel/client_session.h" @@ -13,6 +16,12 @@ namespace Service { namespace HID { +// Updating period for each HID device. +// TODO(shinyquagsire23): These need better values. +constexpr u64 pad_update_ticks = BASE_CLOCK_RATE / 234; +constexpr u64 accelerometer_update_ticks = BASE_CLOCK_RATE / 104; +constexpr u64 gyroscope_update_ticks = BASE_CLOCK_RATE / 101; + class IAppletResource final : public ServiceFramework { public: IAppletResource() : ServiceFramework("IAppletResource") { @@ -24,6 +33,15 @@ public: shared_mem = Kernel::SharedMemory::Create( nullptr, 0x40000, Kernel::MemoryPermission::ReadWrite, Kernel::MemoryPermission::Read, 0, Kernel::MemoryRegion::BASE, "HID:SharedMemory"); + + // Register update callbacks + pad_update_event = CoreTiming::RegisterEvent( + "HID::UpdatePadCallback", + [this](u64 userdata, int cycles_late) { UpdatePadCallback(userdata, cycles_late); }); + + // TODO(shinyquagsire23): Other update callbacks? (accel, gyro?) + + CoreTiming::ScheduleEvent(pad_update_ticks, pad_update_event); } private: @@ -34,8 +52,76 @@ private: LOG_DEBUG(Service, "called"); } + void LoadInputDevices() { + std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, + Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END, + buttons.begin(), Input::CreateDevice); + // TODO(shinyquagsire23): sticks, gyro, touch, mouse, keyboard + } + + void UpdatePadCallback(u64 userdata, int cycles_late) { + SharedMemory* mem = reinterpret_cast(shared_mem->GetPointer()); + + if (is_device_reload_pending.exchange(false)) + LoadInputDevices(); + + // TODO(shinyquagsire23): This is a hack! + ControllerPadState& state = + mem->controllers[Controller_Handheld].layouts[Layout_Default].entries[0].buttons; + using namespace Settings::NativeButton; + state.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus()); + state.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus()); + state.x.Assign(buttons[X - BUTTON_HID_BEGIN]->GetStatus()); + state.y.Assign(buttons[Y - BUTTON_HID_BEGIN]->GetStatus()); + state.lstick.Assign(buttons[LStick - BUTTON_HID_BEGIN]->GetStatus()); + state.rstick.Assign(buttons[RStick - BUTTON_HID_BEGIN]->GetStatus()); + state.l.Assign(buttons[L - BUTTON_HID_BEGIN]->GetStatus()); + state.r.Assign(buttons[R - BUTTON_HID_BEGIN]->GetStatus()); + state.zl.Assign(buttons[ZL - BUTTON_HID_BEGIN]->GetStatus()); + state.zr.Assign(buttons[ZR - BUTTON_HID_BEGIN]->GetStatus()); + state.plus.Assign(buttons[Plus - BUTTON_HID_BEGIN]->GetStatus()); + state.minus.Assign(buttons[Minus - BUTTON_HID_BEGIN]->GetStatus()); + + state.dleft.Assign(buttons[DLeft - BUTTON_HID_BEGIN]->GetStatus()); + state.dup.Assign(buttons[DUp - BUTTON_HID_BEGIN]->GetStatus()); + state.dright.Assign(buttons[DRight - BUTTON_HID_BEGIN]->GetStatus()); + state.ddown.Assign(buttons[DDown - BUTTON_HID_BEGIN]->GetStatus()); + + state.lstick_left.Assign(buttons[LStick_Left - BUTTON_HID_BEGIN]->GetStatus()); + state.lstick_up.Assign(buttons[LStick_Up - BUTTON_HID_BEGIN]->GetStatus()); + state.lstick_right.Assign(buttons[LStick_Right - BUTTON_HID_BEGIN]->GetStatus()); + state.lstick_down.Assign(buttons[LStick_Down - BUTTON_HID_BEGIN]->GetStatus()); + + state.rstick_left.Assign(buttons[RStick_Left - BUTTON_HID_BEGIN]->GetStatus()); + state.rstick_up.Assign(buttons[RStick_Up - BUTTON_HID_BEGIN]->GetStatus()); + state.rstick_right.Assign(buttons[RStick_Right - BUTTON_HID_BEGIN]->GetStatus()); + state.rstick_down.Assign(buttons[RStick_Down - BUTTON_HID_BEGIN]->GetStatus()); + + state.sl.Assign(buttons[SL - BUTTON_HID_BEGIN]->GetStatus()); + state.sr.Assign(buttons[SR - BUTTON_HID_BEGIN]->GetStatus()); + + // TODO(shinyquagsire23): Analog stick vals + + // TODO(shinyquagsire23): Update pad info proper, (circular buffers, timestamps, layouts) + + // TODO(shinyquagsire23): Update touch info + + // TODO(shinyquagsire23): Signal events + + // Reschedule recurrent event + CoreTiming::ScheduleEvent(pad_update_ticks - cycles_late, pad_update_event); + } + // Handle to shared memory region designated to HID service Kernel::SharedPtr shared_mem; + + // CoreTiming update events + CoreTiming::EventType* pad_update_event; + + // Stored input state info + std::atomic is_device_reload_pending{true}; + std::array, Settings::NativeButton::NUM_BUTTONS_HID> + buttons; }; class Hid final : public ServiceFramework { diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 7fd45d56f..486e64800 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -5,6 +5,7 @@ #pragma once #include "core/hle/service/service.h" +#include "core/settings.h" namespace Service { namespace HID { @@ -156,8 +157,7 @@ struct KeyboardHeader { u64 latestEntry; u64 maxEntryIndex; }; -static_assert(sizeof(KeyboardHeader) == 0x20, - "HID keyboard header structure has incorrect size"); +static_assert(sizeof(KeyboardHeader) == 0x20, "HID keyboard header structure has incorrect size"); struct KeyboardModifierKeyState { union { -- cgit v1.2.3