diff options
| author | 2018-01-15 02:21:02 -0700 | |
|---|---|---|
| committer | 2018-01-15 02:30:58 -0700 | |
| commit | 1ea49442f9c21aa20559894ae18353cee1179c76 (patch) | |
| tree | 7439d2e399cbdcd02528c85c9039c286c6586b80 /src | |
| parent | hid: Remove redundant HID prefix on structs/enums (diff) | |
| download | yuzu-1ea49442f9c21aa20559894ae18353cee1179c76.tar.gz yuzu-1ea49442f9c21aa20559894ae18353cee1179c76.tar.xz yuzu-1ea49442f9c21aa20559894ae18353cee1179c76.zip | |
hid: Bare-minimum sharedmem input
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/hid/hid.cpp | 86 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid.h | 4 |
2 files changed, 88 insertions, 2 deletions
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 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <atomic> | ||
| 5 | #include "common/logging/log.h" | 6 | #include "common/logging/log.h" |
| 7 | #include "core/core_timing.h" | ||
| 8 | #include "core/frontend/input.h" | ||
| 6 | #include "core/hle/ipc_helpers.h" | 9 | #include "core/hle/ipc_helpers.h" |
| 7 | #include "core/hle/kernel/client_port.h" | 10 | #include "core/hle/kernel/client_port.h" |
| 8 | #include "core/hle/kernel/client_session.h" | 11 | #include "core/hle/kernel/client_session.h" |
| @@ -13,6 +16,12 @@ | |||
| 13 | namespace Service { | 16 | namespace Service { |
| 14 | namespace HID { | 17 | namespace HID { |
| 15 | 18 | ||
| 19 | // Updating period for each HID device. | ||
| 20 | // TODO(shinyquagsire23): These need better values. | ||
| 21 | constexpr u64 pad_update_ticks = BASE_CLOCK_RATE / 234; | ||
| 22 | constexpr u64 accelerometer_update_ticks = BASE_CLOCK_RATE / 104; | ||
| 23 | constexpr u64 gyroscope_update_ticks = BASE_CLOCK_RATE / 101; | ||
| 24 | |||
| 16 | class IAppletResource final : public ServiceFramework<IAppletResource> { | 25 | class IAppletResource final : public ServiceFramework<IAppletResource> { |
| 17 | public: | 26 | public: |
| 18 | IAppletResource() : ServiceFramework("IAppletResource") { | 27 | IAppletResource() : ServiceFramework("IAppletResource") { |
| @@ -24,6 +33,15 @@ public: | |||
| 24 | shared_mem = Kernel::SharedMemory::Create( | 33 | shared_mem = Kernel::SharedMemory::Create( |
| 25 | nullptr, 0x40000, Kernel::MemoryPermission::ReadWrite, Kernel::MemoryPermission::Read, | 34 | nullptr, 0x40000, Kernel::MemoryPermission::ReadWrite, Kernel::MemoryPermission::Read, |
| 26 | 0, Kernel::MemoryRegion::BASE, "HID:SharedMemory"); | 35 | 0, Kernel::MemoryRegion::BASE, "HID:SharedMemory"); |
| 36 | |||
| 37 | // Register update callbacks | ||
| 38 | pad_update_event = CoreTiming::RegisterEvent( | ||
| 39 | "HID::UpdatePadCallback", | ||
| 40 | [this](u64 userdata, int cycles_late) { UpdatePadCallback(userdata, cycles_late); }); | ||
| 41 | |||
| 42 | // TODO(shinyquagsire23): Other update callbacks? (accel, gyro?) | ||
| 43 | |||
| 44 | CoreTiming::ScheduleEvent(pad_update_ticks, pad_update_event); | ||
| 27 | } | 45 | } |
| 28 | 46 | ||
| 29 | private: | 47 | private: |
| @@ -34,8 +52,76 @@ private: | |||
| 34 | LOG_DEBUG(Service, "called"); | 52 | LOG_DEBUG(Service, "called"); |
| 35 | } | 53 | } |
| 36 | 54 | ||
| 55 | void LoadInputDevices() { | ||
| 56 | std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, | ||
| 57 | Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END, | ||
| 58 | buttons.begin(), Input::CreateDevice<Input::ButtonDevice>); | ||
| 59 | // TODO(shinyquagsire23): sticks, gyro, touch, mouse, keyboard | ||
| 60 | } | ||
| 61 | |||
| 62 | void UpdatePadCallback(u64 userdata, int cycles_late) { | ||
| 63 | SharedMemory* mem = reinterpret_cast<SharedMemory*>(shared_mem->GetPointer()); | ||
| 64 | |||
| 65 | if (is_device_reload_pending.exchange(false)) | ||
| 66 | LoadInputDevices(); | ||
| 67 | |||
| 68 | // TODO(shinyquagsire23): This is a hack! | ||
| 69 | ControllerPadState& state = | ||
| 70 | mem->controllers[Controller_Handheld].layouts[Layout_Default].entries[0].buttons; | ||
| 71 | using namespace Settings::NativeButton; | ||
| 72 | state.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 73 | state.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 74 | state.x.Assign(buttons[X - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 75 | state.y.Assign(buttons[Y - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 76 | state.lstick.Assign(buttons[LStick - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 77 | state.rstick.Assign(buttons[RStick - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 78 | state.l.Assign(buttons[L - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 79 | state.r.Assign(buttons[R - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 80 | state.zl.Assign(buttons[ZL - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 81 | state.zr.Assign(buttons[ZR - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 82 | state.plus.Assign(buttons[Plus - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 83 | state.minus.Assign(buttons[Minus - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 84 | |||
| 85 | state.dleft.Assign(buttons[DLeft - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 86 | state.dup.Assign(buttons[DUp - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 87 | state.dright.Assign(buttons[DRight - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 88 | state.ddown.Assign(buttons[DDown - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 89 | |||
| 90 | state.lstick_left.Assign(buttons[LStick_Left - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 91 | state.lstick_up.Assign(buttons[LStick_Up - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 92 | state.lstick_right.Assign(buttons[LStick_Right - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 93 | state.lstick_down.Assign(buttons[LStick_Down - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 94 | |||
| 95 | state.rstick_left.Assign(buttons[RStick_Left - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 96 | state.rstick_up.Assign(buttons[RStick_Up - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 97 | state.rstick_right.Assign(buttons[RStick_Right - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 98 | state.rstick_down.Assign(buttons[RStick_Down - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 99 | |||
| 100 | state.sl.Assign(buttons[SL - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 101 | state.sr.Assign(buttons[SR - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 102 | |||
| 103 | // TODO(shinyquagsire23): Analog stick vals | ||
| 104 | |||
| 105 | // TODO(shinyquagsire23): Update pad info proper, (circular buffers, timestamps, layouts) | ||
| 106 | |||
| 107 | // TODO(shinyquagsire23): Update touch info | ||
| 108 | |||
| 109 | // TODO(shinyquagsire23): Signal events | ||
| 110 | |||
| 111 | // Reschedule recurrent event | ||
| 112 | CoreTiming::ScheduleEvent(pad_update_ticks - cycles_late, pad_update_event); | ||
| 113 | } | ||
| 114 | |||
| 37 | // Handle to shared memory region designated to HID service | 115 | // Handle to shared memory region designated to HID service |
| 38 | Kernel::SharedPtr<Kernel::SharedMemory> shared_mem; | 116 | Kernel::SharedPtr<Kernel::SharedMemory> shared_mem; |
| 117 | |||
| 118 | // CoreTiming update events | ||
| 119 | CoreTiming::EventType* pad_update_event; | ||
| 120 | |||
| 121 | // Stored input state info | ||
| 122 | std::atomic<bool> is_device_reload_pending{true}; | ||
| 123 | std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID> | ||
| 124 | buttons; | ||
| 39 | }; | 125 | }; |
| 40 | 126 | ||
| 41 | class Hid final : public ServiceFramework<Hid> { | 127 | class Hid final : public ServiceFramework<Hid> { |
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 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "core/hle/service/service.h" | 7 | #include "core/hle/service/service.h" |
| 8 | #include "core/settings.h" | ||
| 8 | 9 | ||
| 9 | namespace Service { | 10 | namespace Service { |
| 10 | namespace HID { | 11 | namespace HID { |
| @@ -156,8 +157,7 @@ struct KeyboardHeader { | |||
| 156 | u64 latestEntry; | 157 | u64 latestEntry; |
| 157 | u64 maxEntryIndex; | 158 | u64 maxEntryIndex; |
| 158 | }; | 159 | }; |
| 159 | static_assert(sizeof(KeyboardHeader) == 0x20, | 160 | static_assert(sizeof(KeyboardHeader) == 0x20, "HID keyboard header structure has incorrect size"); |
| 160 | "HID keyboard header structure has incorrect size"); | ||
| 161 | 161 | ||
| 162 | struct KeyboardModifierKeyState { | 162 | struct KeyboardModifierKeyState { |
| 163 | union { | 163 | union { |