diff options
| author | 2023-12-31 00:42:23 -0600 | |
|---|---|---|
| committer | 2023-12-31 10:51:01 -0600 | |
| commit | 865abfc37c5b3e8945d833bd44db428ad720bd58 (patch) | |
| tree | af37ccf552aad0403898fb371e639393efe7b9d4 /src/core/hle/service/hid | |
| parent | Merge pull request #12509 from liamwhite/ktrace (diff) | |
| download | yuzu-865abfc37c5b3e8945d833bd44db428ad720bd58.tar.gz yuzu-865abfc37c5b3e8945d833bd44db428ad720bd58.tar.xz yuzu-865abfc37c5b3e8945d833bd44db428ad720bd58.zip | |
service: hid: Use applet resource to get latest shared memory handle
Diffstat (limited to 'src/core/hle/service/hid')
36 files changed, 698 insertions, 227 deletions
diff --git a/src/core/hle/service/hid/controllers/applet_resource.cpp b/src/core/hle/service/hid/controllers/applet_resource.cpp index c8e74c764..b4ff663c2 100644 --- a/src/core/hle/service/hid/controllers/applet_resource.cpp +++ b/src/core/hle/service/hid/controllers/applet_resource.cpp | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | #include "core/core.h" | 4 | #include "core/core.h" |
| 5 | #include "core/hle/kernel/k_shared_memory.h" | 5 | #include "core/hle/kernel/k_shared_memory.h" |
| 6 | #include "core/hle/service/hid/controllers/applet_resource.h" | 6 | #include "core/hle/service/hid/controllers/applet_resource.h" |
| 7 | #include "core/hle/service/hid/controllers/shared_memory_format.h" | 7 | #include "core/hle/service/hid/controllers/types/shared_memory_format.h" |
| 8 | #include "core/hle/service/hid/errors.h" | 8 | #include "core/hle/service/hid/errors.h" |
| 9 | 9 | ||
| 10 | namespace Service::HID { | 10 | namespace Service::HID { |
| @@ -164,6 +164,22 @@ Result AppletResource::GetSharedMemoryFormat(SharedMemoryFormat** out_shared_mem | |||
| 164 | return ResultSuccess; | 164 | return ResultSuccess; |
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | AruidData* AppletResource::GetAruidData(u64 aruid) { | ||
| 168 | const u64 aruid_index = GetIndexFromAruid(aruid); | ||
| 169 | if (aruid_index == AruidIndexMax) { | ||
| 170 | return nullptr; | ||
| 171 | } | ||
| 172 | return &data[aruid_index]; | ||
| 173 | } | ||
| 174 | |||
| 175 | AruidData* AppletResource::GetAruidDataByIndex(std::size_t aruid_index) { | ||
| 176 | return &data[aruid_index]; | ||
| 177 | } | ||
| 178 | |||
| 179 | bool AppletResource::IsVibrationAruidActive(u64 aruid) const { | ||
| 180 | return aruid == 0 || aruid == active_vibration_aruid; | ||
| 181 | } | ||
| 182 | |||
| 167 | u64 AppletResource::GetIndexFromAruid(u64 aruid) { | 183 | u64 AppletResource::GetIndexFromAruid(u64 aruid) { |
| 168 | for (std::size_t i = 0; i < AruidIndexMax; i++) { | 184 | for (std::size_t i = 0; i < AruidIndexMax; i++) { |
| 169 | if (registration_list.flag[i] == RegistrationStatus::Initialized && | 185 | if (registration_list.flag[i] == RegistrationStatus::Initialized && |
diff --git a/src/core/hle/service/hid/controllers/applet_resource.h b/src/core/hle/service/hid/controllers/applet_resource.h index e7991f93a..52cc4cf42 100644 --- a/src/core/hle/service/hid/controllers/applet_resource.h +++ b/src/core/hle/service/hid/controllers/applet_resource.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <array> | 6 | #include <array> |
| 7 | #include <mutex> | ||
| 7 | 8 | ||
| 8 | #include "common/bit_field.h" | 9 | #include "common/bit_field.h" |
| 9 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| @@ -20,6 +21,59 @@ class KSharedMemory; | |||
| 20 | 21 | ||
| 21 | namespace Service::HID { | 22 | namespace Service::HID { |
| 22 | struct SharedMemoryFormat; | 23 | struct SharedMemoryFormat; |
| 24 | class AppletResource; | ||
| 25 | class NPadResource; | ||
| 26 | |||
| 27 | static constexpr std::size_t AruidIndexMax = 0x20; | ||
| 28 | |||
| 29 | enum class RegistrationStatus : u32 { | ||
| 30 | None, | ||
| 31 | Initialized, | ||
| 32 | PendingDelete, | ||
| 33 | }; | ||
| 34 | |||
| 35 | struct DataStatusFlag { | ||
| 36 | union { | ||
| 37 | u32 raw{}; | ||
| 38 | |||
| 39 | BitField<0, 1, u32> is_initialized; | ||
| 40 | BitField<1, 1, u32> is_assigned; | ||
| 41 | BitField<16, 1, u32> enable_pad_input; | ||
| 42 | BitField<17, 1, u32> enable_six_axis_sensor; | ||
| 43 | BitField<18, 1, u32> bit_18; | ||
| 44 | BitField<19, 1, u32> is_palma_connectable; | ||
| 45 | BitField<20, 1, u32> enable_palma_boost_mode; | ||
| 46 | BitField<21, 1, u32> enable_touchscreen; | ||
| 47 | }; | ||
| 48 | }; | ||
| 49 | |||
| 50 | struct AruidRegisterList { | ||
| 51 | std::array<RegistrationStatus, AruidIndexMax> flag{}; | ||
| 52 | std::array<u64, AruidIndexMax> aruid{}; | ||
| 53 | }; | ||
| 54 | static_assert(sizeof(AruidRegisterList) == 0x180, "AruidRegisterList is an invalid size"); | ||
| 55 | |||
| 56 | struct AruidData { | ||
| 57 | DataStatusFlag flag{}; | ||
| 58 | u64 aruid{}; | ||
| 59 | SharedMemoryFormat* shared_memory_format{nullptr}; | ||
| 60 | }; | ||
| 61 | |||
| 62 | struct HandheldConfig { | ||
| 63 | bool is_handheld_hid_enabled; | ||
| 64 | bool is_force_handheld; | ||
| 65 | bool is_joycon_rail_enabled; | ||
| 66 | bool is_force_handheld_style_vibration; | ||
| 67 | }; | ||
| 68 | static_assert(sizeof(HandheldConfig) == 0x4, "HandheldConfig is an invalid size"); | ||
| 69 | |||
| 70 | struct AppletResourceHolder { | ||
| 71 | std::shared_ptr<AppletResource> applet_resource{nullptr}; | ||
| 72 | std::recursive_mutex* shared_mutex{nullptr}; | ||
| 73 | NPadResource* shared_npad_resource{nullptr}; | ||
| 74 | std::shared_ptr<HandheldConfig> handheld_config{nullptr}; | ||
| 75 | long* handle_1; | ||
| 76 | }; | ||
| 23 | 77 | ||
| 24 | class AppletResource { | 78 | class AppletResource { |
| 25 | public: | 79 | public: |
| @@ -36,6 +90,10 @@ public: | |||
| 36 | u64 GetActiveAruid(); | 90 | u64 GetActiveAruid(); |
| 37 | Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid); | 91 | Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid); |
| 38 | Result GetSharedMemoryFormat(SharedMemoryFormat** out_shared_memory_format, u64 aruid); | 92 | Result GetSharedMemoryFormat(SharedMemoryFormat** out_shared_memory_format, u64 aruid); |
| 93 | AruidData* GetAruidData(u64 aruid); | ||
| 94 | AruidData* GetAruidDataByIndex(std::size_t aruid_index); | ||
| 95 | |||
| 96 | bool IsVibrationAruidActive(u64 aruid) const; | ||
| 39 | 97 | ||
| 40 | u64 GetIndexFromAruid(u64 aruid); | 98 | u64 GetIndexFromAruid(u64 aruid); |
| 41 | 99 | ||
| @@ -52,46 +110,12 @@ public: | |||
| 52 | Result UnregisterCoreAppletResource(); | 110 | Result UnregisterCoreAppletResource(); |
| 53 | 111 | ||
| 54 | private: | 112 | private: |
| 55 | static constexpr std::size_t AruidIndexMax = 0x20; | ||
| 56 | |||
| 57 | enum RegistrationStatus : u32 { | ||
| 58 | None, | ||
| 59 | Initialized, | ||
| 60 | PendingDelete, | ||
| 61 | }; | ||
| 62 | |||
| 63 | struct DataStatusFlag { | ||
| 64 | union { | ||
| 65 | u32 raw{}; | ||
| 66 | |||
| 67 | BitField<0, 1, u32> is_initialized; | ||
| 68 | BitField<1, 1, u32> is_assigned; | ||
| 69 | BitField<16, 1, u32> enable_pad_input; | ||
| 70 | BitField<17, 1, u32> enable_six_axis_sensor; | ||
| 71 | BitField<18, 1, u32> bit_18; | ||
| 72 | BitField<19, 1, u32> is_palma_connectable; | ||
| 73 | BitField<20, 1, u32> enable_palma_boost_mode; | ||
| 74 | BitField<21, 1, u32> enable_touchscreen; | ||
| 75 | }; | ||
| 76 | }; | ||
| 77 | |||
| 78 | struct AruidRegisterList { | ||
| 79 | std::array<RegistrationStatus, AruidIndexMax> flag{}; | ||
| 80 | std::array<u64, AruidIndexMax> aruid{}; | ||
| 81 | }; | ||
| 82 | static_assert(sizeof(AruidRegisterList) == 0x180, "AruidRegisterList is an invalid size"); | ||
| 83 | |||
| 84 | struct AruidData { | ||
| 85 | DataStatusFlag flag{}; | ||
| 86 | u64 aruid{}; | ||
| 87 | SharedMemoryFormat* shared_memory_format{nullptr}; | ||
| 88 | }; | ||
| 89 | |||
| 90 | u64 active_aruid{}; | 113 | u64 active_aruid{}; |
| 91 | AruidRegisterList registration_list{}; | 114 | AruidRegisterList registration_list{}; |
| 92 | std::array<AruidData, AruidIndexMax> data{}; | 115 | std::array<AruidData, AruidIndexMax> data{}; |
| 93 | std::array<SharedMemoryHolder, AruidIndexMax> shared_memory_holder{}; | 116 | std::array<SharedMemoryHolder, AruidIndexMax> shared_memory_holder{}; |
| 94 | s32 ref_counter{}; | 117 | s32 ref_counter{}; |
| 118 | u64 active_vibration_aruid; | ||
| 95 | 119 | ||
| 96 | Core::System& system; | 120 | Core::System& system; |
| 97 | }; | 121 | }; |
diff --git a/src/core/hle/service/hid/controllers/capture_button.cpp b/src/core/hle/service/hid/controllers/capture_button.cpp new file mode 100644 index 000000000..8b486fcb5 --- /dev/null +++ b/src/core/hle/service/hid/controllers/capture_button.cpp | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "core/core_timing.h" | ||
| 5 | #include "core/hle/service/hid/controllers/applet_resource.h" | ||
| 6 | #include "core/hle/service/hid/controllers/capture_button.h" | ||
| 7 | #include "core/hle/service/hid/controllers/types/shared_memory_format.h" | ||
| 8 | |||
| 9 | namespace Service::HID { | ||
| 10 | |||
| 11 | CaptureButton::CaptureButton(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {} | ||
| 12 | |||
| 13 | CaptureButton::~CaptureButton() = default; | ||
| 14 | |||
| 15 | void CaptureButton::OnInit() {} | ||
| 16 | |||
| 17 | void CaptureButton::OnRelease() {} | ||
| 18 | |||
| 19 | void CaptureButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | ||
| 20 | if (!smart_update) { | ||
| 21 | return; | ||
| 22 | } | ||
| 23 | |||
| 24 | const u64 aruid = applet_resource->GetActiveAruid(); | ||
| 25 | auto* data = applet_resource->GetAruidData(aruid); | ||
| 26 | |||
| 27 | if (data == nullptr) { | ||
| 28 | return; | ||
| 29 | } | ||
| 30 | |||
| 31 | auto& header = data->shared_memory_format->capture_button.header; | ||
| 32 | header.timestamp = core_timing.GetGlobalTimeNs().count(); | ||
| 33 | header.total_entry_count = 17; | ||
| 34 | header.entry_count = 0; | ||
| 35 | header.last_entry_index = 0; | ||
| 36 | } | ||
| 37 | |||
| 38 | } // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/stubbed.h b/src/core/hle/service/hid/controllers/capture_button.h index d2052fb17..dcc4715c5 100644 --- a/src/core/hle/service/hid/controllers/stubbed.h +++ b/src/core/hle/service/hid/controllers/capture_button.h | |||
| @@ -6,12 +6,11 @@ | |||
| 6 | #include "core/hle/service/hid/controllers/controller_base.h" | 6 | #include "core/hle/service/hid/controllers/controller_base.h" |
| 7 | 7 | ||
| 8 | namespace Service::HID { | 8 | namespace Service::HID { |
| 9 | struct CommonHeader; | ||
| 10 | 9 | ||
| 11 | class Controller_Stubbed final : public ControllerBase { | 10 | class CaptureButton final : public ControllerBase { |
| 12 | public: | 11 | public: |
| 13 | explicit Controller_Stubbed(Core::HID::HIDCore& hid_core_, CommonHeader& ring_lifo_header); | 12 | explicit CaptureButton(Core::HID::HIDCore& hid_core_); |
| 14 | ~Controller_Stubbed() override; | 13 | ~CaptureButton() override; |
| 15 | 14 | ||
| 16 | // Called when the controller is initialized | 15 | // Called when the controller is initialized |
| 17 | void OnInit() override; | 16 | void OnInit() override; |
| @@ -23,7 +22,6 @@ public: | |||
| 23 | void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; | 22 | void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; |
| 24 | 23 | ||
| 25 | private: | 24 | private: |
| 26 | CommonHeader& header; | ||
| 27 | bool smart_update{}; | 25 | bool smart_update{}; |
| 28 | }; | 26 | }; |
| 29 | } // namespace Service::HID | 27 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/console_six_axis.cpp b/src/core/hle/service/hid/controllers/console_six_axis.cpp index 3961d2b5f..8eba2c292 100644 --- a/src/core/hle/service/hid/controllers/console_six_axis.cpp +++ b/src/core/hle/service/hid/controllers/console_six_axis.cpp | |||
| @@ -5,13 +5,11 @@ | |||
| 5 | #include "core/hid/emulated_console.h" | 5 | #include "core/hid/emulated_console.h" |
| 6 | #include "core/hid/hid_core.h" | 6 | #include "core/hid/hid_core.h" |
| 7 | #include "core/hle/service/hid/controllers/console_six_axis.h" | 7 | #include "core/hle/service/hid/controllers/console_six_axis.h" |
| 8 | #include "core/hle/service/hid/controllers/shared_memory_format.h" | 8 | #include "core/hle/service/hid/controllers/types/shared_memory_format.h" |
| 9 | 9 | ||
| 10 | namespace Service::HID { | 10 | namespace Service::HID { |
| 11 | 11 | ||
| 12 | ConsoleSixAxis::ConsoleSixAxis(Core::HID::HIDCore& hid_core_, | 12 | ConsoleSixAxis::ConsoleSixAxis(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} { |
| 13 | ConsoleSixAxisSensorSharedMemoryFormat& console_shared_memory) | ||
| 14 | : ControllerBase{hid_core_}, shared_memory{console_shared_memory} { | ||
| 15 | console = hid_core.GetEmulatedConsole(); | 13 | console = hid_core.GetEmulatedConsole(); |
| 16 | } | 14 | } |
| 17 | 15 | ||
| @@ -22,6 +20,15 @@ void ConsoleSixAxis::OnInit() {} | |||
| 22 | void ConsoleSixAxis::OnRelease() {} | 20 | void ConsoleSixAxis::OnRelease() {} |
| 23 | 21 | ||
| 24 | void ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | 22 | void ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { |
| 23 | const u64 aruid = applet_resource->GetActiveAruid(); | ||
| 24 | auto* data = applet_resource->GetAruidData(aruid); | ||
| 25 | |||
| 26 | if (data == nullptr) { | ||
| 27 | return; | ||
| 28 | } | ||
| 29 | |||
| 30 | ConsoleSixAxisSensorSharedMemoryFormat& shared_memory = data->shared_memory_format->console; | ||
| 31 | |||
| 25 | if (!IsControllerActivated()) { | 32 | if (!IsControllerActivated()) { |
| 26 | return; | 33 | return; |
| 27 | } | 34 | } |
diff --git a/src/core/hle/service/hid/controllers/console_six_axis.h b/src/core/hle/service/hid/controllers/console_six_axis.h index 3d1c9ce23..e3351f83c 100644 --- a/src/core/hle/service/hid/controllers/console_six_axis.h +++ b/src/core/hle/service/hid/controllers/console_six_axis.h | |||
| @@ -10,12 +10,9 @@ class EmulatedConsole; | |||
| 10 | } // namespace Core::HID | 10 | } // namespace Core::HID |
| 11 | 11 | ||
| 12 | namespace Service::HID { | 12 | namespace Service::HID { |
| 13 | struct ConsoleSixAxisSensorSharedMemoryFormat; | ||
| 14 | |||
| 15 | class ConsoleSixAxis final : public ControllerBase { | 13 | class ConsoleSixAxis final : public ControllerBase { |
| 16 | public: | 14 | public: |
| 17 | explicit ConsoleSixAxis(Core::HID::HIDCore& hid_core_, | 15 | explicit ConsoleSixAxis(Core::HID::HIDCore& hid_core_); |
| 18 | ConsoleSixAxisSensorSharedMemoryFormat& console_shared_memory); | ||
| 19 | ~ConsoleSixAxis() override; | 16 | ~ConsoleSixAxis() override; |
| 20 | 17 | ||
| 21 | // Called when the controller is initialized | 18 | // Called when the controller is initialized |
| @@ -28,7 +25,6 @@ public: | |||
| 28 | void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; | 25 | void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; |
| 29 | 26 | ||
| 30 | private: | 27 | private: |
| 31 | ConsoleSixAxisSensorSharedMemoryFormat& shared_memory; | ||
| 32 | Core::HID::EmulatedConsole* console = nullptr; | 28 | Core::HID::EmulatedConsole* console = nullptr; |
| 33 | }; | 29 | }; |
| 34 | } // namespace Service::HID | 30 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/controller_base.cpp b/src/core/hle/service/hid/controllers/controller_base.cpp index 0bcd87062..2083ccfad 100644 --- a/src/core/hle/service/hid/controllers/controller_base.cpp +++ b/src/core/hle/service/hid/controllers/controller_base.cpp | |||
| @@ -31,4 +31,9 @@ void ControllerBase::DeactivateController() { | |||
| 31 | bool ControllerBase::IsControllerActivated() const { | 31 | bool ControllerBase::IsControllerActivated() const { |
| 32 | return is_activated; | 32 | return is_activated; |
| 33 | } | 33 | } |
| 34 | |||
| 35 | void ControllerBase::SetAppletResource(std::shared_ptr<AppletResource> resource) { | ||
| 36 | applet_resource = resource; | ||
| 37 | } | ||
| 38 | |||
| 34 | } // namespace Service::HID | 39 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/controller_base.h b/src/core/hle/service/hid/controllers/controller_base.h index 4326c7821..759ae0053 100644 --- a/src/core/hle/service/hid/controllers/controller_base.h +++ b/src/core/hle/service/hid/controllers/controller_base.h | |||
| @@ -3,8 +3,11 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <memory> | ||
| 7 | |||
| 6 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 7 | #include "core/hle/result.h" | 9 | #include "core/hle/result.h" |
| 10 | #include "core/hle/service/hid/controllers/applet_resource.h" | ||
| 8 | 11 | ||
| 9 | namespace Core::Timing { | 12 | namespace Core::Timing { |
| 10 | class CoreTiming; | 13 | class CoreTiming; |
| @@ -12,7 +15,7 @@ class CoreTiming; | |||
| 12 | 15 | ||
| 13 | namespace Core::HID { | 16 | namespace Core::HID { |
| 14 | class HIDCore; | 17 | class HIDCore; |
| 15 | } | 18 | } // namespace Core::HID |
| 16 | 19 | ||
| 17 | namespace Service::HID { | 20 | namespace Service::HID { |
| 18 | class ControllerBase { | 21 | class ControllerBase { |
| @@ -39,8 +42,11 @@ public: | |||
| 39 | 42 | ||
| 40 | bool IsControllerActivated() const; | 43 | bool IsControllerActivated() const; |
| 41 | 44 | ||
| 45 | void SetAppletResource(std::shared_ptr<AppletResource> resource); | ||
| 46 | |||
| 42 | protected: | 47 | protected: |
| 43 | bool is_activated{false}; | 48 | bool is_activated{false}; |
| 49 | std::shared_ptr<AppletResource> applet_resource{nullptr}; | ||
| 44 | 50 | ||
| 45 | Core::HID::HIDCore& hid_core; | 51 | Core::HID::HIDCore& hid_core; |
| 46 | }; | 52 | }; |
diff --git a/src/core/hle/service/hid/controllers/debug_mouse.cpp b/src/core/hle/service/hid/controllers/debug_mouse.cpp new file mode 100644 index 000000000..f2f1a27f8 --- /dev/null +++ b/src/core/hle/service/hid/controllers/debug_mouse.cpp | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "core/core_timing.h" | ||
| 5 | #include "core/frontend/emu_window.h" | ||
| 6 | #include "core/hid/emulated_devices.h" | ||
| 7 | #include "core/hid/hid_core.h" | ||
| 8 | #include "core/hle/service/hid/controllers/applet_resource.h" | ||
| 9 | #include "core/hle/service/hid/controllers/debug_mouse.h" | ||
| 10 | #include "core/hle/service/hid/controllers/types/shared_memory_format.h" | ||
| 11 | |||
| 12 | namespace Service::HID { | ||
| 13 | |||
| 14 | DebugMouse::DebugMouse(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} { | ||
| 15 | emulated_devices = hid_core.GetEmulatedDevices(); | ||
| 16 | } | ||
| 17 | |||
| 18 | DebugMouse::~DebugMouse() = default; | ||
| 19 | |||
| 20 | void DebugMouse::OnInit() {} | ||
| 21 | void DebugMouse::OnRelease() {} | ||
| 22 | |||
| 23 | void DebugMouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | ||
| 24 | const u64 aruid = applet_resource->GetActiveAruid(); | ||
| 25 | auto* data = applet_resource->GetAruidData(aruid); | ||
| 26 | |||
| 27 | if (data == nullptr) { | ||
| 28 | return; | ||
| 29 | } | ||
| 30 | |||
| 31 | MouseSharedMemoryFormat& shared_memory = data->shared_memory_format->debug_mouse; | ||
| 32 | |||
| 33 | if (!IsControllerActivated()) { | ||
| 34 | shared_memory.mouse_lifo.buffer_count = 0; | ||
| 35 | shared_memory.mouse_lifo.buffer_tail = 0; | ||
| 36 | return; | ||
| 37 | } | ||
| 38 | |||
| 39 | next_state = {}; | ||
| 40 | |||
| 41 | const auto& last_entry = shared_memory.mouse_lifo.ReadCurrentEntry().state; | ||
| 42 | next_state.sampling_number = last_entry.sampling_number + 1; | ||
| 43 | |||
| 44 | if (Settings::values.mouse_enabled) { | ||
| 45 | const auto& mouse_button_state = emulated_devices->GetMouseButtons(); | ||
| 46 | const auto& mouse_position_state = emulated_devices->GetMousePosition(); | ||
| 47 | const auto& mouse_wheel_state = emulated_devices->GetMouseWheel(); | ||
| 48 | next_state.attribute.is_connected.Assign(1); | ||
| 49 | next_state.x = static_cast<s32>(mouse_position_state.x * Layout::ScreenUndocked::Width); | ||
| 50 | next_state.y = static_cast<s32>(mouse_position_state.y * Layout::ScreenUndocked::Height); | ||
| 51 | next_state.delta_x = next_state.x - last_entry.x; | ||
| 52 | next_state.delta_y = next_state.y - last_entry.y; | ||
| 53 | next_state.delta_wheel_x = mouse_wheel_state.x - last_mouse_wheel_state.x; | ||
| 54 | next_state.delta_wheel_y = mouse_wheel_state.y - last_mouse_wheel_state.y; | ||
| 55 | |||
| 56 | last_mouse_wheel_state = mouse_wheel_state; | ||
| 57 | next_state.button = mouse_button_state; | ||
| 58 | } | ||
| 59 | |||
| 60 | shared_memory.mouse_lifo.WriteNextEntry(next_state); | ||
| 61 | } | ||
| 62 | |||
| 63 | } // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/debug_mouse.h b/src/core/hle/service/hid/controllers/debug_mouse.h new file mode 100644 index 000000000..ec939fa9f --- /dev/null +++ b/src/core/hle/service/hid/controllers/debug_mouse.h | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "core/hle/service/hid/controllers/controller_base.h" | ||
| 7 | |||
| 8 | namespace Core::HID { | ||
| 9 | class EmulatedDevices; | ||
| 10 | struct MouseState; | ||
| 11 | struct AnalogStickState; | ||
| 12 | } // namespace Core::HID | ||
| 13 | |||
| 14 | namespace Service::HID { | ||
| 15 | class DebugMouse final : public ControllerBase { | ||
| 16 | public: | ||
| 17 | explicit DebugMouse(Core::HID::HIDCore& hid_core_); | ||
| 18 | ~DebugMouse() override; | ||
| 19 | |||
| 20 | // Called when the controller is initialized | ||
| 21 | void OnInit() override; | ||
| 22 | |||
| 23 | // When the controller is released | ||
| 24 | void OnRelease() override; | ||
| 25 | |||
| 26 | // When the controller is requesting an update for the shared memory | ||
| 27 | void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; | ||
| 28 | |||
| 29 | private: | ||
| 30 | Core::HID::MouseState next_state{}; | ||
| 31 | Core::HID::AnalogStickState last_mouse_wheel_state{}; | ||
| 32 | Core::HID::EmulatedDevices* emulated_devices = nullptr; | ||
| 33 | }; | ||
| 34 | } // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/debug_pad.cpp b/src/core/hle/service/hid/controllers/debug_pad.cpp index 7d2370b4f..1811cf620 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.cpp +++ b/src/core/hle/service/hid/controllers/debug_pad.cpp | |||
| @@ -6,14 +6,13 @@ | |||
| 6 | #include "core/hid/emulated_controller.h" | 6 | #include "core/hid/emulated_controller.h" |
| 7 | #include "core/hid/hid_core.h" | 7 | #include "core/hid/hid_core.h" |
| 8 | #include "core/hid/hid_types.h" | 8 | #include "core/hid/hid_types.h" |
| 9 | #include "core/hle/service/hid/controllers/applet_resource.h" | ||
| 9 | #include "core/hle/service/hid/controllers/debug_pad.h" | 10 | #include "core/hle/service/hid/controllers/debug_pad.h" |
| 10 | #include "core/hle/service/hid/controllers/shared_memory_format.h" | 11 | #include "core/hle/service/hid/controllers/types/shared_memory_format.h" |
| 11 | 12 | ||
| 12 | namespace Service::HID { | 13 | namespace Service::HID { |
| 13 | 14 | ||
| 14 | DebugPad::DebugPad(Core::HID::HIDCore& hid_core_, | 15 | DebugPad::DebugPad(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} { |
| 15 | DebugPadSharedMemoryFormat& debug_pad_shared_memory) | ||
| 16 | : ControllerBase{hid_core_}, shared_memory{debug_pad_shared_memory} { | ||
| 17 | controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Other); | 16 | controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Other); |
| 18 | } | 17 | } |
| 19 | 18 | ||
| @@ -24,6 +23,15 @@ void DebugPad::OnInit() {} | |||
| 24 | void DebugPad::OnRelease() {} | 23 | void DebugPad::OnRelease() {} |
| 25 | 24 | ||
| 26 | void DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | 25 | void DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { |
| 26 | const u64 aruid = applet_resource->GetActiveAruid(); | ||
| 27 | auto* data = applet_resource->GetAruidData(aruid); | ||
| 28 | |||
| 29 | if (data == nullptr) { | ||
| 30 | return; | ||
| 31 | } | ||
| 32 | |||
| 33 | DebugPadSharedMemoryFormat& shared_memory = data->shared_memory_format->debug_pad; | ||
| 34 | |||
| 27 | if (!IsControllerActivated()) { | 35 | if (!IsControllerActivated()) { |
| 28 | shared_memory.debug_pad_lifo.buffer_count = 0; | 36 | shared_memory.debug_pad_lifo.buffer_count = 0; |
| 29 | shared_memory.debug_pad_lifo.buffer_tail = 0; | 37 | shared_memory.debug_pad_lifo.buffer_tail = 0; |
diff --git a/src/core/hle/service/hid/controllers/debug_pad.h b/src/core/hle/service/hid/controllers/debug_pad.h index 8ab29eca8..dd00b2402 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.h +++ b/src/core/hle/service/hid/controllers/debug_pad.h | |||
| @@ -15,12 +15,9 @@ class CoreTiming; | |||
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | namespace Service::HID { | 17 | namespace Service::HID { |
| 18 | struct DebugPadSharedMemoryFormat; | ||
| 19 | |||
| 20 | class DebugPad final : public ControllerBase { | 18 | class DebugPad final : public ControllerBase { |
| 21 | public: | 19 | public: |
| 22 | explicit DebugPad(Core::HID::HIDCore& hid_core_, | 20 | explicit DebugPad(Core::HID::HIDCore& hid_core_); |
| 23 | DebugPadSharedMemoryFormat& debug_pad_shared_memory); | ||
| 24 | ~DebugPad() override; | 21 | ~DebugPad() override; |
| 25 | 22 | ||
| 26 | // Called when the controller is initialized | 23 | // Called when the controller is initialized |
| @@ -34,7 +31,6 @@ public: | |||
| 34 | 31 | ||
| 35 | private: | 32 | private: |
| 36 | DebugPadState next_state{}; | 33 | DebugPadState next_state{}; |
| 37 | DebugPadSharedMemoryFormat& shared_memory; | ||
| 38 | Core::HID::EmulatedController* controller = nullptr; | 34 | Core::HID::EmulatedController* controller = nullptr; |
| 39 | }; | 35 | }; |
| 40 | } // namespace Service::HID | 36 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/digitizer.cpp b/src/core/hle/service/hid/controllers/digitizer.cpp new file mode 100644 index 000000000..c01580fd6 --- /dev/null +++ b/src/core/hle/service/hid/controllers/digitizer.cpp | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "core/core_timing.h" | ||
| 5 | #include "core/hle/service/hid/controllers/applet_resource.h" | ||
| 6 | #include "core/hle/service/hid/controllers/digitizer.h" | ||
| 7 | #include "core/hle/service/hid/controllers/types/shared_memory_format.h" | ||
| 8 | |||
| 9 | namespace Service::HID { | ||
| 10 | |||
| 11 | Digitizer::Digitizer(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {} | ||
| 12 | |||
| 13 | Digitizer::~Digitizer() = default; | ||
| 14 | |||
| 15 | void Digitizer::OnInit() {} | ||
| 16 | |||
| 17 | void Digitizer::OnRelease() {} | ||
| 18 | |||
| 19 | void Digitizer::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | ||
| 20 | if (!smart_update) { | ||
| 21 | return; | ||
| 22 | } | ||
| 23 | |||
| 24 | const u64 aruid = applet_resource->GetActiveAruid(); | ||
| 25 | auto* data = applet_resource->GetAruidData(aruid); | ||
| 26 | |||
| 27 | if (data == nullptr) { | ||
| 28 | return; | ||
| 29 | } | ||
| 30 | |||
| 31 | auto& header = data->shared_memory_format->digitizer.header; | ||
| 32 | header.timestamp = core_timing.GetGlobalTimeNs().count(); | ||
| 33 | header.total_entry_count = 17; | ||
| 34 | header.entry_count = 0; | ||
| 35 | header.last_entry_index = 0; | ||
| 36 | } | ||
| 37 | |||
| 38 | } // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/digitizer.h b/src/core/hle/service/hid/controllers/digitizer.h new file mode 100644 index 000000000..d81f814c3 --- /dev/null +++ b/src/core/hle/service/hid/controllers/digitizer.h | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "core/hle/service/hid/controllers/controller_base.h" | ||
| 7 | |||
| 8 | namespace Service::HID { | ||
| 9 | |||
| 10 | class Digitizer final : public ControllerBase { | ||
| 11 | public: | ||
| 12 | explicit Digitizer(Core::HID::HIDCore& hid_core_); | ||
| 13 | ~Digitizer() override; | ||
| 14 | |||
| 15 | // Called when the controller is initialized | ||
| 16 | void OnInit() override; | ||
| 17 | |||
| 18 | // When the controller is released | ||
| 19 | void OnRelease() override; | ||
| 20 | |||
| 21 | // When the controller is requesting an update for the shared memory | ||
| 22 | void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; | ||
| 23 | |||
| 24 | private: | ||
| 25 | bool smart_update{}; | ||
| 26 | }; | ||
| 27 | } // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/core/hle/service/hid/controllers/gesture.cpp index f658005f6..6e686fe65 100644 --- a/src/core/hle/service/hid/controllers/gesture.cpp +++ b/src/core/hle/service/hid/controllers/gesture.cpp | |||
| @@ -6,8 +6,9 @@ | |||
| 6 | #include "core/frontend/emu_window.h" | 6 | #include "core/frontend/emu_window.h" |
| 7 | #include "core/hid/emulated_console.h" | 7 | #include "core/hid/emulated_console.h" |
| 8 | #include "core/hid/hid_core.h" | 8 | #include "core/hid/hid_core.h" |
| 9 | #include "core/hle/service/hid/controllers/applet_resource.h" | ||
| 9 | #include "core/hle/service/hid/controllers/gesture.h" | 10 | #include "core/hle/service/hid/controllers/gesture.h" |
| 10 | #include "core/hle/service/hid/controllers/shared_memory_format.h" | 11 | #include "core/hle/service/hid/controllers/types/shared_memory_format.h" |
| 11 | 12 | ||
| 12 | namespace Service::HID { | 13 | namespace Service::HID { |
| 13 | // HW is around 700, value is set to 400 to make it easier to trigger with mouse | 14 | // HW is around 700, value is set to 400 to make it easier to trigger with mouse |
| @@ -21,24 +22,40 @@ constexpr f32 Square(s32 num) { | |||
| 21 | return static_cast<f32>(num * num); | 22 | return static_cast<f32>(num * num); |
| 22 | } | 23 | } |
| 23 | 24 | ||
| 24 | Gesture::Gesture(Core::HID::HIDCore& hid_core_, GestureSharedMemoryFormat& gesture_shared_memory) | 25 | Gesture::Gesture(Core::HID::HIDCore& hid_core_) : ControllerBase(hid_core_) { |
| 25 | : ControllerBase(hid_core_), shared_memory{gesture_shared_memory} { | ||
| 26 | console = hid_core.GetEmulatedConsole(); | 26 | console = hid_core.GetEmulatedConsole(); |
| 27 | } | 27 | } |
| 28 | Gesture::~Gesture() = default; | 28 | Gesture::~Gesture() = default; |
| 29 | 29 | ||
| 30 | void Gesture::OnInit() { | 30 | void Gesture::OnInit() { |
| 31 | shared_memory.gesture_lifo.buffer_count = 0; | 31 | const u64 aruid = applet_resource->GetActiveAruid(); |
| 32 | shared_memory.gesture_lifo.buffer_tail = 0; | 32 | auto* data = applet_resource->GetAruidData(aruid); |
| 33 | |||
| 34 | if (data == nullptr) { | ||
| 35 | return; | ||
| 36 | } | ||
| 37 | |||
| 38 | shared_memory = &data->shared_memory_format->gesture; | ||
| 39 | shared_memory->gesture_lifo.buffer_count = 0; | ||
| 40 | shared_memory->gesture_lifo.buffer_tail = 0; | ||
| 33 | force_update = true; | 41 | force_update = true; |
| 34 | } | 42 | } |
| 35 | 43 | ||
| 36 | void Gesture::OnRelease() {} | 44 | void Gesture::OnRelease() {} |
| 37 | 45 | ||
| 38 | void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | 46 | void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) { |
| 47 | const u64 aruid = applet_resource->GetActiveAruid(); | ||
| 48 | auto* data = applet_resource->GetAruidData(aruid); | ||
| 49 | |||
| 50 | if (data == nullptr) { | ||
| 51 | return; | ||
| 52 | } | ||
| 53 | |||
| 54 | shared_memory = &data->shared_memory_format->gesture; | ||
| 55 | |||
| 39 | if (!IsControllerActivated()) { | 56 | if (!IsControllerActivated()) { |
| 40 | shared_memory.gesture_lifo.buffer_count = 0; | 57 | shared_memory->gesture_lifo.buffer_count = 0; |
| 41 | shared_memory.gesture_lifo.buffer_tail = 0; | 58 | shared_memory->gesture_lifo.buffer_tail = 0; |
| 42 | return; | 59 | return; |
| 43 | } | 60 | } |
| 44 | 61 | ||
| @@ -46,7 +63,7 @@ void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | |||
| 46 | 63 | ||
| 47 | GestureProperties gesture = GetGestureProperties(); | 64 | GestureProperties gesture = GetGestureProperties(); |
| 48 | f32 time_difference = | 65 | f32 time_difference = |
| 49 | static_cast<f32>(shared_memory.gesture_lifo.timestamp - last_update_timestamp) / | 66 | static_cast<f32>(shared_memory->gesture_lifo.timestamp - last_update_timestamp) / |
| 50 | (1000 * 1000 * 1000); | 67 | (1000 * 1000 * 1000); |
| 51 | 68 | ||
| 52 | // Only update if necessary | 69 | // Only update if necessary |
| @@ -54,7 +71,7 @@ void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | |||
| 54 | return; | 71 | return; |
| 55 | } | 72 | } |
| 56 | 73 | ||
| 57 | last_update_timestamp = shared_memory.gesture_lifo.timestamp; | 74 | last_update_timestamp = shared_memory->gesture_lifo.timestamp; |
| 58 | UpdateGestureSharedMemory(gesture, time_difference); | 75 | UpdateGestureSharedMemory(gesture, time_difference); |
| 59 | } | 76 | } |
| 60 | 77 | ||
| @@ -97,7 +114,7 @@ void Gesture::UpdateGestureSharedMemory(GestureProperties& gesture, f32 time_dif | |||
| 97 | GestureType type = GestureType::Idle; | 114 | GestureType type = GestureType::Idle; |
| 98 | GestureAttribute attributes{}; | 115 | GestureAttribute attributes{}; |
| 99 | 116 | ||
| 100 | const auto& last_entry = shared_memory.gesture_lifo.ReadCurrentEntry().state; | 117 | const auto& last_entry = shared_memory->gesture_lifo.ReadCurrentEntry().state; |
| 101 | 118 | ||
| 102 | // Reset next state to default | 119 | // Reset next state to default |
| 103 | next_state.sampling_number = last_entry.sampling_number + 1; | 120 | next_state.sampling_number = last_entry.sampling_number + 1; |
| @@ -127,7 +144,7 @@ void Gesture::UpdateGestureSharedMemory(GestureProperties& gesture, f32 time_dif | |||
| 127 | next_state.points = gesture.points; | 144 | next_state.points = gesture.points; |
| 128 | last_gesture = gesture; | 145 | last_gesture = gesture; |
| 129 | 146 | ||
| 130 | shared_memory.gesture_lifo.WriteNextEntry(next_state); | 147 | shared_memory->gesture_lifo.WriteNextEntry(next_state); |
| 131 | } | 148 | } |
| 132 | 149 | ||
| 133 | void Gesture::NewGesture(GestureProperties& gesture, GestureType& type, | 150 | void Gesture::NewGesture(GestureProperties& gesture, GestureType& type, |
| @@ -300,7 +317,7 @@ void Gesture::SetSwipeEvent(GestureProperties& gesture, GestureProperties& last_ | |||
| 300 | } | 317 | } |
| 301 | 318 | ||
| 302 | const GestureState& Gesture::GetLastGestureEntry() const { | 319 | const GestureState& Gesture::GetLastGestureEntry() const { |
| 303 | return shared_memory.gesture_lifo.ReadCurrentEntry().state; | 320 | return shared_memory->gesture_lifo.ReadCurrentEntry().state; |
| 304 | } | 321 | } |
| 305 | 322 | ||
| 306 | GestureProperties Gesture::GetGestureProperties() { | 323 | GestureProperties Gesture::GetGestureProperties() { |
diff --git a/src/core/hle/service/hid/controllers/gesture.h b/src/core/hle/service/hid/controllers/gesture.h index 41fdfcd03..78da1552a 100644 --- a/src/core/hle/service/hid/controllers/gesture.h +++ b/src/core/hle/service/hid/controllers/gesture.h | |||
| @@ -18,8 +18,7 @@ struct GestureSharedMemoryFormat; | |||
| 18 | 18 | ||
| 19 | class Gesture final : public ControllerBase { | 19 | class Gesture final : public ControllerBase { |
| 20 | public: | 20 | public: |
| 21 | explicit Gesture(Core::HID::HIDCore& hid_core_, | 21 | explicit Gesture(Core::HID::HIDCore& hid_core_); |
| 22 | GestureSharedMemoryFormat& gesture_shared_memory); | ||
| 23 | ~Gesture() override; | 22 | ~Gesture() override; |
| 24 | 23 | ||
| 25 | // Called when the controller is initialized | 24 | // Called when the controller is initialized |
| @@ -74,7 +73,7 @@ private: | |||
| 74 | GestureProperties GetGestureProperties(); | 73 | GestureProperties GetGestureProperties(); |
| 75 | 74 | ||
| 76 | GestureState next_state{}; | 75 | GestureState next_state{}; |
| 77 | GestureSharedMemoryFormat& shared_memory; | 76 | GestureSharedMemoryFormat* shared_memory; |
| 78 | Core::HID::EmulatedConsole* console = nullptr; | 77 | Core::HID::EmulatedConsole* console = nullptr; |
| 79 | 78 | ||
| 80 | std::array<Core::HID::TouchFinger, MAX_POINTS> fingers{}; | 79 | std::array<Core::HID::TouchFinger, MAX_POINTS> fingers{}; |
diff --git a/src/core/hle/service/hid/controllers/home_button.cpp b/src/core/hle/service/hid/controllers/home_button.cpp new file mode 100644 index 000000000..71dd9bc08 --- /dev/null +++ b/src/core/hle/service/hid/controllers/home_button.cpp | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "core/core_timing.h" | ||
| 5 | #include "core/hle/service/hid/controllers/applet_resource.h" | ||
| 6 | #include "core/hle/service/hid/controllers/home_button.h" | ||
| 7 | #include "core/hle/service/hid/controllers/types/shared_memory_format.h" | ||
| 8 | |||
| 9 | namespace Service::HID { | ||
| 10 | |||
| 11 | HomeButton::HomeButton(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {} | ||
| 12 | |||
| 13 | HomeButton::~HomeButton() = default; | ||
| 14 | |||
| 15 | void HomeButton::OnInit() {} | ||
| 16 | |||
| 17 | void HomeButton::OnRelease() {} | ||
| 18 | |||
| 19 | void HomeButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | ||
| 20 | if (!smart_update) { | ||
| 21 | return; | ||
| 22 | } | ||
| 23 | |||
| 24 | const u64 aruid = applet_resource->GetActiveAruid(); | ||
| 25 | auto* data = applet_resource->GetAruidData(aruid); | ||
| 26 | |||
| 27 | if (data == nullptr) { | ||
| 28 | return; | ||
| 29 | } | ||
| 30 | |||
| 31 | auto& header = data->shared_memory_format->home_button.header; | ||
| 32 | header.timestamp = core_timing.GetGlobalTimeNs().count(); | ||
| 33 | header.total_entry_count = 17; | ||
| 34 | header.entry_count = 0; | ||
| 35 | header.last_entry_index = 0; | ||
| 36 | } | ||
| 37 | |||
| 38 | } // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/home_button.h b/src/core/hle/service/hid/controllers/home_button.h new file mode 100644 index 000000000..e91c2aa5d --- /dev/null +++ b/src/core/hle/service/hid/controllers/home_button.h | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "core/hle/service/hid/controllers/controller_base.h" | ||
| 7 | |||
| 8 | namespace Service::HID { | ||
| 9 | |||
| 10 | class HomeButton final : public ControllerBase { | ||
| 11 | public: | ||
| 12 | explicit HomeButton(Core::HID::HIDCore& hid_core_); | ||
| 13 | ~HomeButton() override; | ||
| 14 | |||
| 15 | // Called when the controller is initialized | ||
| 16 | void OnInit() override; | ||
| 17 | |||
| 18 | // When the controller is released | ||
| 19 | void OnRelease() override; | ||
| 20 | |||
| 21 | // When the controller is requesting an update for the shared memory | ||
| 22 | void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; | ||
| 23 | |||
| 24 | private: | ||
| 25 | bool smart_update{}; | ||
| 26 | }; | ||
| 27 | } // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/keyboard.cpp b/src/core/hle/service/hid/controllers/keyboard.cpp index 871e5036a..c72b3e5ce 100644 --- a/src/core/hle/service/hid/controllers/keyboard.cpp +++ b/src/core/hle/service/hid/controllers/keyboard.cpp | |||
| @@ -5,14 +5,13 @@ | |||
| 5 | #include "core/core_timing.h" | 5 | #include "core/core_timing.h" |
| 6 | #include "core/hid/emulated_devices.h" | 6 | #include "core/hid/emulated_devices.h" |
| 7 | #include "core/hid/hid_core.h" | 7 | #include "core/hid/hid_core.h" |
| 8 | #include "core/hle/service/hid/controllers/applet_resource.h" | ||
| 8 | #include "core/hle/service/hid/controllers/keyboard.h" | 9 | #include "core/hle/service/hid/controllers/keyboard.h" |
| 9 | #include "core/hle/service/hid/controllers/shared_memory_format.h" | 10 | #include "core/hle/service/hid/controllers/types/shared_memory_format.h" |
| 10 | 11 | ||
| 11 | namespace Service::HID { | 12 | namespace Service::HID { |
| 12 | 13 | ||
| 13 | Keyboard::Keyboard(Core::HID::HIDCore& hid_core_, | 14 | Keyboard::Keyboard(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} { |
| 14 | KeyboardSharedMemoryFormat& keyboard_shared_memory) | ||
| 15 | : ControllerBase{hid_core_}, shared_memory{keyboard_shared_memory} { | ||
| 16 | emulated_devices = hid_core.GetEmulatedDevices(); | 15 | emulated_devices = hid_core.GetEmulatedDevices(); |
| 17 | } | 16 | } |
| 18 | 17 | ||
| @@ -23,6 +22,15 @@ void Keyboard::OnInit() {} | |||
| 23 | void Keyboard::OnRelease() {} | 22 | void Keyboard::OnRelease() {} |
| 24 | 23 | ||
| 25 | void Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | 24 | void Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing) { |
| 25 | const u64 aruid = applet_resource->GetActiveAruid(); | ||
| 26 | auto* data = applet_resource->GetAruidData(aruid); | ||
| 27 | |||
| 28 | if (data == nullptr) { | ||
| 29 | return; | ||
| 30 | } | ||
| 31 | |||
| 32 | KeyboardSharedMemoryFormat& shared_memory = data->shared_memory_format->keyboard; | ||
| 33 | |||
| 26 | if (!IsControllerActivated()) { | 34 | if (!IsControllerActivated()) { |
| 27 | shared_memory.keyboard_lifo.buffer_count = 0; | 35 | shared_memory.keyboard_lifo.buffer_count = 0; |
| 28 | shared_memory.keyboard_lifo.buffer_tail = 0; | 36 | shared_memory.keyboard_lifo.buffer_tail = 0; |
diff --git a/src/core/hle/service/hid/controllers/keyboard.h b/src/core/hle/service/hid/controllers/keyboard.h index 4d72171b9..e8ca326c6 100644 --- a/src/core/hle/service/hid/controllers/keyboard.h +++ b/src/core/hle/service/hid/controllers/keyboard.h | |||
| @@ -7,12 +7,9 @@ | |||
| 7 | #include "core/hle/service/hid/controllers/types/keyboard_types.h" | 7 | #include "core/hle/service/hid/controllers/types/keyboard_types.h" |
| 8 | 8 | ||
| 9 | namespace Service::HID { | 9 | namespace Service::HID { |
| 10 | struct KeyboardSharedMemoryFormat; | ||
| 11 | |||
| 12 | class Keyboard final : public ControllerBase { | 10 | class Keyboard final : public ControllerBase { |
| 13 | public: | 11 | public: |
| 14 | explicit Keyboard(Core::HID::HIDCore& hid_core_, | 12 | explicit Keyboard(Core::HID::HIDCore& hid_core_); |
| 15 | KeyboardSharedMemoryFormat& keyboard_shared_memory); | ||
| 16 | ~Keyboard() override; | 13 | ~Keyboard() override; |
| 17 | 14 | ||
| 18 | // Called when the controller is initialized | 15 | // Called when the controller is initialized |
| @@ -26,7 +23,6 @@ public: | |||
| 26 | 23 | ||
| 27 | private: | 24 | private: |
| 28 | KeyboardState next_state{}; | 25 | KeyboardState next_state{}; |
| 29 | KeyboardSharedMemoryFormat& shared_memory; | ||
| 30 | Core::HID::EmulatedDevices* emulated_devices = nullptr; | 26 | Core::HID::EmulatedDevices* emulated_devices = nullptr; |
| 31 | }; | 27 | }; |
| 32 | } // namespace Service::HID | 28 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/mouse.cpp b/src/core/hle/service/hid/controllers/mouse.cpp index de5b2c804..58deafbc5 100644 --- a/src/core/hle/service/hid/controllers/mouse.cpp +++ b/src/core/hle/service/hid/controllers/mouse.cpp | |||
| @@ -5,13 +5,13 @@ | |||
| 5 | #include "core/frontend/emu_window.h" | 5 | #include "core/frontend/emu_window.h" |
| 6 | #include "core/hid/emulated_devices.h" | 6 | #include "core/hid/emulated_devices.h" |
| 7 | #include "core/hid/hid_core.h" | 7 | #include "core/hid/hid_core.h" |
| 8 | #include "core/hle/service/hid/controllers/applet_resource.h" | ||
| 8 | #include "core/hle/service/hid/controllers/mouse.h" | 9 | #include "core/hle/service/hid/controllers/mouse.h" |
| 9 | #include "core/hle/service/hid/controllers/shared_memory_format.h" | 10 | #include "core/hle/service/hid/controllers/types/shared_memory_format.h" |
| 10 | 11 | ||
| 11 | namespace Service::HID { | 12 | namespace Service::HID { |
| 12 | 13 | ||
| 13 | Mouse::Mouse(Core::HID::HIDCore& hid_core_, MouseSharedMemoryFormat& mouse_shared_memory) | 14 | Mouse::Mouse(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} { |
| 14 | : ControllerBase{hid_core_}, shared_memory{mouse_shared_memory} { | ||
| 15 | emulated_devices = hid_core.GetEmulatedDevices(); | 15 | emulated_devices = hid_core.GetEmulatedDevices(); |
| 16 | } | 16 | } |
| 17 | 17 | ||
| @@ -21,6 +21,15 @@ void Mouse::OnInit() {} | |||
| 21 | void Mouse::OnRelease() {} | 21 | void Mouse::OnRelease() {} |
| 22 | 22 | ||
| 23 | void Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | 23 | void Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) { |
| 24 | const u64 aruid = applet_resource->GetActiveAruid(); | ||
| 25 | auto* data = applet_resource->GetAruidData(aruid); | ||
| 26 | |||
| 27 | if (data == nullptr) { | ||
| 28 | return; | ||
| 29 | } | ||
| 30 | |||
| 31 | MouseSharedMemoryFormat& shared_memory = data->shared_memory_format->mouse; | ||
| 32 | |||
| 24 | if (!IsControllerActivated()) { | 33 | if (!IsControllerActivated()) { |
| 25 | shared_memory.mouse_lifo.buffer_count = 0; | 34 | shared_memory.mouse_lifo.buffer_count = 0; |
| 26 | shared_memory.mouse_lifo.buffer_tail = 0; | 35 | shared_memory.mouse_lifo.buffer_tail = 0; |
diff --git a/src/core/hle/service/hid/controllers/mouse.h b/src/core/hle/service/hid/controllers/mouse.h index 363f316a5..cefad956c 100644 --- a/src/core/hle/service/hid/controllers/mouse.h +++ b/src/core/hle/service/hid/controllers/mouse.h | |||
| @@ -12,11 +12,9 @@ struct AnalogStickState; | |||
| 12 | } // namespace Core::HID | 12 | } // namespace Core::HID |
| 13 | 13 | ||
| 14 | namespace Service::HID { | 14 | namespace Service::HID { |
| 15 | struct MouseSharedMemoryFormat; | ||
| 16 | |||
| 17 | class Mouse final : public ControllerBase { | 15 | class Mouse final : public ControllerBase { |
| 18 | public: | 16 | public: |
| 19 | explicit Mouse(Core::HID::HIDCore& hid_core_, MouseSharedMemoryFormat& mouse_shared_memory); | 17 | explicit Mouse(Core::HID::HIDCore& hid_core_); |
| 20 | ~Mouse() override; | 18 | ~Mouse() override; |
| 21 | 19 | ||
| 22 | // Called when the controller is initialized | 20 | // Called when the controller is initialized |
| @@ -31,7 +29,6 @@ public: | |||
| 31 | private: | 29 | private: |
| 32 | Core::HID::MouseState next_state{}; | 30 | Core::HID::MouseState next_state{}; |
| 33 | Core::HID::AnalogStickState last_mouse_wheel_state{}; | 31 | Core::HID::AnalogStickState last_mouse_wheel_state{}; |
| 34 | MouseSharedMemoryFormat& shared_memory; | ||
| 35 | Core::HID::EmulatedDevices* emulated_devices = nullptr; | 32 | Core::HID::EmulatedDevices* emulated_devices = nullptr; |
| 36 | }; | 33 | }; |
| 37 | } // namespace Service::HID | 34 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 53a737cf5..c7aa606bc 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -16,8 +16,9 @@ | |||
| 16 | #include "core/hid/hid_core.h" | 16 | #include "core/hid/hid_core.h" |
| 17 | #include "core/hle/kernel/k_event.h" | 17 | #include "core/hle/kernel/k_event.h" |
| 18 | #include "core/hle/kernel/k_readable_event.h" | 18 | #include "core/hle/kernel/k_readable_event.h" |
| 19 | #include "core/hle/service/hid/controllers/applet_resource.h" | ||
| 19 | #include "core/hle/service/hid/controllers/npad.h" | 20 | #include "core/hle/service/hid/controllers/npad.h" |
| 20 | #include "core/hle/service/hid/controllers/shared_memory_format.h" | 21 | #include "core/hle/service/hid/controllers/types/shared_memory_format.h" |
| 21 | #include "core/hle/service/hid/errors.h" | 22 | #include "core/hle/service/hid/errors.h" |
| 22 | #include "core/hle/service/hid/hid_util.h" | 23 | #include "core/hle/service/hid/hid_util.h" |
| 23 | #include "core/hle/service/kernel_helpers.h" | 24 | #include "core/hle/service/kernel_helpers.h" |
| @@ -30,12 +31,10 @@ constexpr std::array<Core::HID::NpadIdType, 10> npad_id_list{ | |||
| 30 | Core::HID::NpadIdType::Handheld, | 31 | Core::HID::NpadIdType::Handheld, |
| 31 | }; | 32 | }; |
| 32 | 33 | ||
| 33 | NPad::NPad(Core::HID::HIDCore& hid_core_, NpadSharedMemoryFormat& npad_shared_memory_format, | 34 | NPad::NPad(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service_context_) |
| 34 | KernelHelpers::ServiceContext& service_context_) | ||
| 35 | : ControllerBase{hid_core_}, service_context{service_context_} { | 35 | : ControllerBase{hid_core_}, service_context{service_context_} { |
| 36 | for (std::size_t i = 0; i < controller_data.size(); ++i) { | 36 | for (std::size_t i = 0; i < controller_data.size(); ++i) { |
| 37 | auto& controller = controller_data[i]; | 37 | auto& controller = controller_data[i]; |
| 38 | controller.shared_memory = &npad_shared_memory_format.npad_entry[i].internal_state; | ||
| 39 | controller.device = hid_core.GetEmulatedControllerByIndex(i); | 38 | controller.device = hid_core.GetEmulatedControllerByIndex(i); |
| 40 | controller.vibration[Core::HID::EmulatedDeviceIndex::LeftIndex].latest_vibration_value = | 39 | controller.vibration[Core::HID::EmulatedDeviceIndex::LeftIndex].latest_vibration_value = |
| 41 | Core::HID::DEFAULT_VIBRATION_VALUE; | 40 | Core::HID::DEFAULT_VIBRATION_VALUE; |
| @@ -297,12 +296,20 @@ void NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) { | |||
| 297 | } | 296 | } |
| 298 | 297 | ||
| 299 | void NPad::OnInit() { | 298 | void NPad::OnInit() { |
| 299 | const u64 aruid = applet_resource->GetActiveAruid(); | ||
| 300 | auto* data = applet_resource->GetAruidData(aruid); | ||
| 301 | |||
| 302 | if (data == nullptr) { | ||
| 303 | return; | ||
| 304 | } | ||
| 305 | |||
| 300 | if (!IsControllerActivated()) { | 306 | if (!IsControllerActivated()) { |
| 301 | return; | 307 | return; |
| 302 | } | 308 | } |
| 303 | 309 | ||
| 304 | for (std::size_t i = 0; i < controller_data.size(); ++i) { | 310 | for (std::size_t i = 0; i < controller_data.size(); ++i) { |
| 305 | auto& controller = controller_data[i]; | 311 | auto& controller = controller_data[i]; |
| 312 | controller.shared_memory = &data->shared_memory_format->npad.npad_entry[i].internal_state; | ||
| 306 | controller.styleset_changed_event = | 313 | controller.styleset_changed_event = |
| 307 | service_context.CreateEvent(fmt::format("npad:NpadStyleSetChanged_{}", i)); | 314 | service_context.CreateEvent(fmt::format("npad:NpadStyleSetChanged_{}", i)); |
| 308 | } | 315 | } |
| @@ -355,7 +362,9 @@ void NPad::OnRelease() { | |||
| 355 | is_controller_initialized = false; | 362 | is_controller_initialized = false; |
| 356 | for (std::size_t i = 0; i < controller_data.size(); ++i) { | 363 | for (std::size_t i = 0; i < controller_data.size(); ++i) { |
| 357 | auto& controller = controller_data[i]; | 364 | auto& controller = controller_data[i]; |
| 358 | service_context.CloseEvent(controller.styleset_changed_event); | 365 | if (controller.styleset_changed_event) { |
| 366 | service_context.CloseEvent(controller.styleset_changed_event); | ||
| 367 | } | ||
| 359 | for (std::size_t device_idx = 0; device_idx < controller.vibration.size(); ++device_idx) { | 368 | for (std::size_t device_idx = 0; device_idx < controller.vibration.size(); ++device_idx) { |
| 360 | VibrateControllerAtIndex(controller.device->GetNpadIdType(), device_idx, {}); | 369 | VibrateControllerAtIndex(controller.device->GetNpadIdType(), device_idx, {}); |
| 361 | } | 370 | } |
| @@ -432,12 +441,20 @@ void NPad::RequestPadStateUpdate(Core::HID::NpadIdType npad_id) { | |||
| 432 | } | 441 | } |
| 433 | 442 | ||
| 434 | void NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | 443 | void NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { |
| 444 | const u64 aruid = applet_resource->GetActiveAruid(); | ||
| 445 | auto* data = applet_resource->GetAruidData(aruid); | ||
| 446 | |||
| 447 | if (data == nullptr) { | ||
| 448 | return; | ||
| 449 | } | ||
| 450 | |||
| 435 | if (!IsControllerActivated()) { | 451 | if (!IsControllerActivated()) { |
| 436 | return; | 452 | return; |
| 437 | } | 453 | } |
| 438 | 454 | ||
| 439 | for (std::size_t i = 0; i < controller_data.size(); ++i) { | 455 | for (std::size_t i = 0; i < controller_data.size(); ++i) { |
| 440 | auto& controller = controller_data[i]; | 456 | auto& controller = controller_data[i]; |
| 457 | controller.shared_memory = &data->shared_memory_format->npad.npad_entry[i].internal_state; | ||
| 441 | auto* npad = controller.shared_memory; | 458 | auto* npad = controller.shared_memory; |
| 442 | 459 | ||
| 443 | const auto& controller_type = controller.device->GetNpadStyleIndex(); | 460 | const auto& controller_type = controller.device->GetNpadStyleIndex(); |
| @@ -976,30 +993,6 @@ Result NPad::ResetIsSixAxisSensorDeviceNewlyAssigned( | |||
| 976 | return ResultSuccess; | 993 | return ResultSuccess; |
| 977 | } | 994 | } |
| 978 | 995 | ||
| 979 | NpadSixAxisSensorLifo& NPad::GetSixAxisFullkeyLifo(Core::HID::NpadIdType npad_id) { | ||
| 980 | return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_fullkey_lifo; | ||
| 981 | } | ||
| 982 | |||
| 983 | NpadSixAxisSensorLifo& NPad::GetSixAxisHandheldLifo(Core::HID::NpadIdType npad_id) { | ||
| 984 | return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_handheld_lifo; | ||
| 985 | } | ||
| 986 | |||
| 987 | NpadSixAxisSensorLifo& NPad::GetSixAxisDualLeftLifo(Core::HID::NpadIdType npad_id) { | ||
| 988 | return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_dual_left_lifo; | ||
| 989 | } | ||
| 990 | |||
| 991 | NpadSixAxisSensorLifo& NPad::GetSixAxisDualRightLifo(Core::HID::NpadIdType npad_id) { | ||
| 992 | return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_dual_right_lifo; | ||
| 993 | } | ||
| 994 | |||
| 995 | NpadSixAxisSensorLifo& NPad::GetSixAxisLeftLifo(Core::HID::NpadIdType npad_id) { | ||
| 996 | return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_left_lifo; | ||
| 997 | } | ||
| 998 | |||
| 999 | NpadSixAxisSensorLifo& NPad::GetSixAxisRightLifo(Core::HID::NpadIdType npad_id) { | ||
| 1000 | return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_right_lifo; | ||
| 1001 | } | ||
| 1002 | |||
| 1003 | Result NPad::MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1, | 996 | Result NPad::MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1, |
| 1004 | Core::HID::NpadIdType npad_id_2) { | 997 | Core::HID::NpadIdType npad_id_2) { |
| 1005 | if (!IsNpadIdValid(npad_id_1) || !IsNpadIdValid(npad_id_2)) { | 998 | if (!IsNpadIdValid(npad_id_1) || !IsNpadIdValid(npad_id_2)) { |
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index 4e2412356..80cfcb2bb 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h | |||
| @@ -30,14 +30,14 @@ class ServiceContext; | |||
| 30 | union Result; | 30 | union Result; |
| 31 | 31 | ||
| 32 | namespace Service::HID { | 32 | namespace Service::HID { |
| 33 | class AppletResource; | ||
| 33 | struct NpadInternalState; | 34 | struct NpadInternalState; |
| 34 | struct NpadSixAxisSensorLifo; | 35 | struct NpadSixAxisSensorLifo; |
| 35 | struct NpadSharedMemoryFormat; | 36 | struct NpadSharedMemoryFormat; |
| 36 | 37 | ||
| 37 | class NPad final : public ControllerBase { | 38 | class NPad final : public ControllerBase { |
| 38 | public: | 39 | public: |
| 39 | explicit NPad(Core::HID::HIDCore& hid_core_, NpadSharedMemoryFormat& npad_shared_memory_format, | 40 | explicit NPad(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service_context_); |
| 40 | KernelHelpers::ServiceContext& service_context_); | ||
| 41 | ~NPad() override; | 41 | ~NPad() override; |
| 42 | 42 | ||
| 43 | // Called when the controller is initialized | 43 | // Called when the controller is initialized |
| @@ -106,13 +106,6 @@ public: | |||
| 106 | Result ResetIsSixAxisSensorDeviceNewlyAssigned( | 106 | Result ResetIsSixAxisSensorDeviceNewlyAssigned( |
| 107 | const Core::HID::SixAxisSensorHandle& sixaxis_handle); | 107 | const Core::HID::SixAxisSensorHandle& sixaxis_handle); |
| 108 | 108 | ||
| 109 | NpadSixAxisSensorLifo& GetSixAxisFullkeyLifo(Core::HID::NpadIdType npad_id); | ||
| 110 | NpadSixAxisSensorLifo& GetSixAxisHandheldLifo(Core::HID::NpadIdType npad_id); | ||
| 111 | NpadSixAxisSensorLifo& GetSixAxisDualLeftLifo(Core::HID::NpadIdType npad_id); | ||
| 112 | NpadSixAxisSensorLifo& GetSixAxisDualRightLifo(Core::HID::NpadIdType npad_id); | ||
| 113 | NpadSixAxisSensorLifo& GetSixAxisLeftLifo(Core::HID::NpadIdType npad_id); | ||
| 114 | NpadSixAxisSensorLifo& GetSixAxisRightLifo(Core::HID::NpadIdType npad_id); | ||
| 115 | |||
| 116 | Result GetLedPattern(Core::HID::NpadIdType npad_id, Core::HID::LedPattern& pattern) const; | 109 | Result GetLedPattern(Core::HID::NpadIdType npad_id, Core::HID::LedPattern& pattern) const; |
| 117 | Result IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id, | 110 | Result IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id, |
| 118 | bool& is_enabled) const; | 111 | bool& is_enabled) const; |
diff --git a/src/core/hle/service/hid/controllers/shared_memory_holder.cpp b/src/core/hle/service/hid/controllers/shared_memory_holder.cpp index 51581188e..0bc5169c6 100644 --- a/src/core/hle/service/hid/controllers/shared_memory_holder.cpp +++ b/src/core/hle/service/hid/controllers/shared_memory_holder.cpp | |||
| @@ -3,8 +3,9 @@ | |||
| 3 | 3 | ||
| 4 | #include "core/core.h" | 4 | #include "core/core.h" |
| 5 | #include "core/hle/kernel/k_shared_memory.h" | 5 | #include "core/hle/kernel/k_shared_memory.h" |
| 6 | #include "core/hle/service/hid/controllers/shared_memory_format.h" | 6 | #include "core/hle/service/hid/controllers/applet_resource.h" |
| 7 | #include "core/hle/service/hid/controllers/shared_memory_holder.h" | 7 | #include "core/hle/service/hid/controllers/shared_memory_holder.h" |
| 8 | #include "core/hle/service/hid/controllers/types/shared_memory_format.h" | ||
| 8 | #include "core/hle/service/hid/errors.h" | 9 | #include "core/hle/service/hid/errors.h" |
| 9 | 10 | ||
| 10 | namespace Service::HID { | 11 | namespace Service::HID { |
diff --git a/src/core/hle/service/hid/controllers/six_axis.cpp b/src/core/hle/service/hid/controllers/six_axis.cpp index 36b72f9ea..a5a67dea6 100644 --- a/src/core/hle/service/hid/controllers/six_axis.cpp +++ b/src/core/hle/service/hid/controllers/six_axis.cpp | |||
| @@ -6,8 +6,8 @@ | |||
| 6 | #include "core/hid/emulated_controller.h" | 6 | #include "core/hid/emulated_controller.h" |
| 7 | #include "core/hid/hid_core.h" | 7 | #include "core/hid/hid_core.h" |
| 8 | #include "core/hle/service/hid/controllers/npad.h" | 8 | #include "core/hle/service/hid/controllers/npad.h" |
| 9 | #include "core/hle/service/hid/controllers/shared_memory_format.h" | ||
| 10 | #include "core/hle/service/hid/controllers/six_axis.h" | 9 | #include "core/hle/service/hid/controllers/six_axis.h" |
| 10 | #include "core/hle/service/hid/controllers/types/shared_memory_format.h" | ||
| 11 | #include "core/hle/service/hid/errors.h" | 11 | #include "core/hle/service/hid/errors.h" |
| 12 | #include "core/hle/service/hid/hid_util.h" | 12 | #include "core/hle/service/hid/hid_util.h" |
| 13 | 13 | ||
| @@ -27,14 +27,20 @@ void SixAxis::OnInit() {} | |||
| 27 | void SixAxis::OnRelease() {} | 27 | void SixAxis::OnRelease() {} |
| 28 | 28 | ||
| 29 | void SixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | 29 | void SixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { |
| 30 | const u64 aruid = applet_resource->GetActiveAruid(); | ||
| 31 | auto* data = applet_resource->GetAruidData(aruid); | ||
| 32 | |||
| 33 | if (data == nullptr) { | ||
| 34 | return; | ||
| 35 | } | ||
| 36 | |||
| 30 | if (!IsControllerActivated()) { | 37 | if (!IsControllerActivated()) { |
| 31 | return; | 38 | return; |
| 32 | } | 39 | } |
| 33 | 40 | ||
| 34 | for (std::size_t i = 0; i < controller_data.size(); ++i) { | 41 | for (std::size_t i = 0; i < controller_data.size(); ++i) { |
| 42 | NpadSharedMemoryEntry& shared_memory = data->shared_memory_format->npad.npad_entry[i]; | ||
| 35 | auto& controller = controller_data[i]; | 43 | auto& controller = controller_data[i]; |
| 36 | |||
| 37 | const auto npad_id = IndexToNpadIdType(i); | ||
| 38 | const auto& controller_type = controller.device->GetNpadStyleIndex(); | 44 | const auto& controller_type = controller.device->GetNpadStyleIndex(); |
| 39 | 45 | ||
| 40 | if (controller_type == Core::HID::NpadStyleIndex::None || | 46 | if (controller_type == Core::HID::NpadStyleIndex::None || |
| @@ -50,12 +56,12 @@ void SixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | |||
| 50 | auto& sixaxis_left_lifo_state = controller.sixaxis_left_lifo_state; | 56 | auto& sixaxis_left_lifo_state = controller.sixaxis_left_lifo_state; |
| 51 | auto& sixaxis_right_lifo_state = controller.sixaxis_right_lifo_state; | 57 | auto& sixaxis_right_lifo_state = controller.sixaxis_right_lifo_state; |
| 52 | 58 | ||
| 53 | auto& sixaxis_fullkey_lifo = npad->GetSixAxisFullkeyLifo(npad_id); | 59 | auto& sixaxis_fullkey_lifo = shared_memory.internal_state.sixaxis_fullkey_lifo; |
| 54 | auto& sixaxis_handheld_lifo = npad->GetSixAxisHandheldLifo(npad_id); | 60 | auto& sixaxis_handheld_lifo = shared_memory.internal_state.sixaxis_handheld_lifo; |
| 55 | auto& sixaxis_dual_left_lifo = npad->GetSixAxisDualLeftLifo(npad_id); | 61 | auto& sixaxis_dual_left_lifo = shared_memory.internal_state.sixaxis_dual_left_lifo; |
| 56 | auto& sixaxis_dual_right_lifo = npad->GetSixAxisDualRightLifo(npad_id); | 62 | auto& sixaxis_dual_right_lifo = shared_memory.internal_state.sixaxis_dual_right_lifo; |
| 57 | auto& sixaxis_left_lifo = npad->GetSixAxisLeftLifo(npad_id); | 63 | auto& sixaxis_left_lifo = shared_memory.internal_state.sixaxis_left_lifo; |
| 58 | auto& sixaxis_right_lifo = npad->GetSixAxisRightLifo(npad_id); | 64 | auto& sixaxis_right_lifo = shared_memory.internal_state.sixaxis_right_lifo; |
| 59 | 65 | ||
| 60 | // Clear previous state | 66 | // Clear previous state |
| 61 | sixaxis_fullkey_state = {}; | 67 | sixaxis_fullkey_state = {}; |
diff --git a/src/core/hle/service/hid/controllers/sleep_button.cpp b/src/core/hle/service/hid/controllers/sleep_button.cpp new file mode 100644 index 000000000..978dc4c1f --- /dev/null +++ b/src/core/hle/service/hid/controllers/sleep_button.cpp | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "core/core_timing.h" | ||
| 5 | #include "core/hle/service/hid/controllers/applet_resource.h" | ||
| 6 | #include "core/hle/service/hid/controllers/sleep_button.h" | ||
| 7 | #include "core/hle/service/hid/controllers/types/shared_memory_format.h" | ||
| 8 | |||
| 9 | namespace Service::HID { | ||
| 10 | |||
| 11 | SleepButton::SleepButton(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {} | ||
| 12 | |||
| 13 | SleepButton::~SleepButton() = default; | ||
| 14 | |||
| 15 | void SleepButton::OnInit() {} | ||
| 16 | |||
| 17 | void SleepButton::OnRelease() {} | ||
| 18 | |||
| 19 | void SleepButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | ||
| 20 | if (!smart_update) { | ||
| 21 | return; | ||
| 22 | } | ||
| 23 | |||
| 24 | const u64 aruid = applet_resource->GetActiveAruid(); | ||
| 25 | auto* data = applet_resource->GetAruidData(aruid); | ||
| 26 | |||
| 27 | if (data == nullptr) { | ||
| 28 | return; | ||
| 29 | } | ||
| 30 | |||
| 31 | auto& header = data->shared_memory_format->capture_button.header; | ||
| 32 | header.timestamp = core_timing.GetGlobalTimeNs().count(); | ||
| 33 | header.total_entry_count = 17; | ||
| 34 | header.entry_count = 0; | ||
| 35 | header.last_entry_index = 0; | ||
| 36 | } | ||
| 37 | |||
| 38 | } // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/sleep_button.h b/src/core/hle/service/hid/controllers/sleep_button.h new file mode 100644 index 000000000..59964bf63 --- /dev/null +++ b/src/core/hle/service/hid/controllers/sleep_button.h | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "core/hle/service/hid/controllers/controller_base.h" | ||
| 7 | |||
| 8 | namespace Service::HID { | ||
| 9 | |||
| 10 | class SleepButton final : public ControllerBase { | ||
| 11 | public: | ||
| 12 | explicit SleepButton(Core::HID::HIDCore& hid_core_); | ||
| 13 | ~SleepButton() override; | ||
| 14 | |||
| 15 | // Called when the controller is initialized | ||
| 16 | void OnInit() override; | ||
| 17 | |||
| 18 | // When the controller is released | ||
| 19 | void OnRelease() override; | ||
| 20 | |||
| 21 | // When the controller is requesting an update for the shared memory | ||
| 22 | void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; | ||
| 23 | |||
| 24 | private: | ||
| 25 | bool smart_update{}; | ||
| 26 | }; | ||
| 27 | } // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/stubbed.cpp b/src/core/hle/service/hid/controllers/stubbed.cpp deleted file mode 100644 index e2a5f5d79..000000000 --- a/src/core/hle/service/hid/controllers/stubbed.cpp +++ /dev/null | |||
| @@ -1,31 +0,0 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "core/core_timing.h" | ||
| 5 | #include "core/hle/service/hid/controllers/shared_memory_format.h" | ||
| 6 | #include "core/hle/service/hid/controllers/stubbed.h" | ||
| 7 | |||
| 8 | namespace Service::HID { | ||
| 9 | |||
| 10 | Controller_Stubbed::Controller_Stubbed(Core::HID::HIDCore& hid_core_, | ||
| 11 | CommonHeader& ring_lifo_header) | ||
| 12 | : ControllerBase{hid_core_}, header{ring_lifo_header} {} | ||
| 13 | |||
| 14 | Controller_Stubbed::~Controller_Stubbed() = default; | ||
| 15 | |||
| 16 | void Controller_Stubbed::OnInit() {} | ||
| 17 | |||
| 18 | void Controller_Stubbed::OnRelease() {} | ||
| 19 | |||
| 20 | void Controller_Stubbed::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | ||
| 21 | if (!smart_update) { | ||
| 22 | return; | ||
| 23 | } | ||
| 24 | |||
| 25 | header.timestamp = core_timing.GetGlobalTimeNs().count(); | ||
| 26 | header.total_entry_count = 17; | ||
| 27 | header.entry_count = 0; | ||
| 28 | header.last_entry_index = 0; | ||
| 29 | } | ||
| 30 | |||
| 31 | } // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cpp index 469750006..291dc707e 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.cpp +++ b/src/core/hle/service/hid/controllers/touchscreen.cpp | |||
| @@ -8,15 +8,14 @@ | |||
| 8 | #include "core/frontend/emu_window.h" | 8 | #include "core/frontend/emu_window.h" |
| 9 | #include "core/hid/emulated_console.h" | 9 | #include "core/hid/emulated_console.h" |
| 10 | #include "core/hid/hid_core.h" | 10 | #include "core/hid/hid_core.h" |
| 11 | #include "core/hle/service/hid/controllers/shared_memory_format.h" | 11 | #include "core/hle/service/hid/controllers/applet_resource.h" |
| 12 | #include "core/hle/service/hid/controllers/touchscreen.h" | 12 | #include "core/hle/service/hid/controllers/touchscreen.h" |
| 13 | #include "core/hle/service/hid/controllers/types/shared_memory_format.h" | ||
| 13 | 14 | ||
| 14 | namespace Service::HID { | 15 | namespace Service::HID { |
| 15 | 16 | ||
| 16 | TouchScreen::TouchScreen(Core::HID::HIDCore& hid_core_, | 17 | TouchScreen::TouchScreen(Core::HID::HIDCore& hid_core_) |
| 17 | TouchScreenSharedMemoryFormat& touch_shared_memory) | 18 | : ControllerBase{hid_core_}, touchscreen_width(Layout::ScreenUndocked::Width), |
| 18 | : ControllerBase{hid_core_}, shared_memory{touch_shared_memory}, | ||
| 19 | touchscreen_width(Layout::ScreenUndocked::Width), | ||
| 20 | touchscreen_height(Layout::ScreenUndocked::Height) { | 19 | touchscreen_height(Layout::ScreenUndocked::Height) { |
| 21 | console = hid_core.GetEmulatedConsole(); | 20 | console = hid_core.GetEmulatedConsole(); |
| 22 | } | 21 | } |
| @@ -28,6 +27,14 @@ void TouchScreen::OnInit() {} | |||
| 28 | void TouchScreen::OnRelease() {} | 27 | void TouchScreen::OnRelease() {} |
| 29 | 28 | ||
| 30 | void TouchScreen::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | 29 | void TouchScreen::OnUpdate(const Core::Timing::CoreTiming& core_timing) { |
| 30 | const u64 aruid = applet_resource->GetActiveAruid(); | ||
| 31 | auto* data = applet_resource->GetAruidData(aruid); | ||
| 32 | |||
| 33 | if (data == nullptr) { | ||
| 34 | return; | ||
| 35 | } | ||
| 36 | |||
| 37 | TouchScreenSharedMemoryFormat& shared_memory = data->shared_memory_format->touch_screen; | ||
| 31 | shared_memory.touch_screen_lifo.timestamp = core_timing.GetGlobalTimeNs().count(); | 38 | shared_memory.touch_screen_lifo.timestamp = core_timing.GetGlobalTimeNs().count(); |
| 32 | 39 | ||
| 33 | if (!IsControllerActivated()) { | 40 | if (!IsControllerActivated()) { |
diff --git a/src/core/hle/service/hid/controllers/touchscreen.h b/src/core/hle/service/hid/controllers/touchscreen.h index 5b6305bfc..945d359be 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.h +++ b/src/core/hle/service/hid/controllers/touchscreen.h | |||
| @@ -18,8 +18,7 @@ struct TouchScreenSharedMemoryFormat; | |||
| 18 | 18 | ||
| 19 | class TouchScreen final : public ControllerBase { | 19 | class TouchScreen final : public ControllerBase { |
| 20 | public: | 20 | public: |
| 21 | explicit TouchScreen(Core::HID::HIDCore& hid_core_, | 21 | explicit TouchScreen(Core::HID::HIDCore& hid_core_); |
| 22 | TouchScreenSharedMemoryFormat& touch_shared_memory); | ||
| 23 | ~TouchScreen() override; | 22 | ~TouchScreen() override; |
| 24 | 23 | ||
| 25 | // Called when the controller is initialized | 24 | // Called when the controller is initialized |
| @@ -35,7 +34,6 @@ public: | |||
| 35 | 34 | ||
| 36 | private: | 35 | private: |
| 37 | TouchScreenState next_state{}; | 36 | TouchScreenState next_state{}; |
| 38 | TouchScreenSharedMemoryFormat& shared_memory; | ||
| 39 | Core::HID::EmulatedConsole* console = nullptr; | 37 | Core::HID::EmulatedConsole* console = nullptr; |
| 40 | 38 | ||
| 41 | std::array<Core::HID::TouchFinger, MAX_FINGERS> fingers{}; | 39 | std::array<Core::HID::TouchFinger, MAX_FINGERS> fingers{}; |
diff --git a/src/core/hle/service/hid/controllers/shared_memory_format.h b/src/core/hle/service/hid/controllers/types/shared_memory_format.h index 2986c113e..2986c113e 100644 --- a/src/core/hle/service/hid/controllers/shared_memory_format.h +++ b/src/core/hle/service/hid/controllers/types/shared_memory_format.h | |||
diff --git a/src/core/hle/service/hid/controllers/unique_pad.cpp b/src/core/hle/service/hid/controllers/unique_pad.cpp new file mode 100644 index 000000000..8230501a5 --- /dev/null +++ b/src/core/hle/service/hid/controllers/unique_pad.cpp | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "core/core_timing.h" | ||
| 5 | #include "core/hle/service/hid/controllers/applet_resource.h" | ||
| 6 | #include "core/hle/service/hid/controllers/types/shared_memory_format.h" | ||
| 7 | #include "core/hle/service/hid/controllers/unique_pad.h" | ||
| 8 | |||
| 9 | namespace Service::HID { | ||
| 10 | |||
| 11 | UniquePad::UniquePad(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {} | ||
| 12 | |||
| 13 | UniquePad::~UniquePad() = default; | ||
| 14 | |||
| 15 | void UniquePad::OnInit() {} | ||
| 16 | |||
| 17 | void UniquePad::OnRelease() {} | ||
| 18 | |||
| 19 | void UniquePad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | ||
| 20 | if (!smart_update) { | ||
| 21 | return; | ||
| 22 | } | ||
| 23 | |||
| 24 | const u64 aruid = applet_resource->GetActiveAruid(); | ||
| 25 | auto* data = applet_resource->GetAruidData(aruid); | ||
| 26 | |||
| 27 | if (data == nullptr) { | ||
| 28 | return; | ||
| 29 | } | ||
| 30 | |||
| 31 | auto& header = data->shared_memory_format->capture_button.header; | ||
| 32 | header.timestamp = core_timing.GetGlobalTimeNs().count(); | ||
| 33 | header.total_entry_count = 17; | ||
| 34 | header.entry_count = 0; | ||
| 35 | header.last_entry_index = 0; | ||
| 36 | } | ||
| 37 | |||
| 38 | } // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/unique_pad.h b/src/core/hle/service/hid/controllers/unique_pad.h new file mode 100644 index 000000000..966368264 --- /dev/null +++ b/src/core/hle/service/hid/controllers/unique_pad.h | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "core/hle/service/hid/controllers/controller_base.h" | ||
| 7 | |||
| 8 | namespace Service::HID { | ||
| 9 | |||
| 10 | class UniquePad final : public ControllerBase { | ||
| 11 | public: | ||
| 12 | explicit UniquePad(Core::HID::HIDCore& hid_core_); | ||
| 13 | ~UniquePad() override; | ||
| 14 | |||
| 15 | // Called when the controller is initialized | ||
| 16 | void OnInit() override; | ||
| 17 | |||
| 18 | // When the controller is released | ||
| 19 | void OnRelease() override; | ||
| 20 | |||
| 21 | // When the controller is requesting an update for the shared memory | ||
| 22 | void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; | ||
| 23 | |||
| 24 | private: | ||
| 25 | bool smart_update{}; | ||
| 26 | }; | ||
| 27 | } // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/resource_manager.cpp b/src/core/hle/service/hid/resource_manager.cpp index 6c6cbd802..7b689d085 100644 --- a/src/core/hle/service/hid/resource_manager.cpp +++ b/src/core/hle/service/hid/resource_manager.cpp | |||
| @@ -10,18 +10,23 @@ | |||
| 10 | #include "core/hle/service/ipc_helpers.h" | 10 | #include "core/hle/service/ipc_helpers.h" |
| 11 | 11 | ||
| 12 | #include "core/hle/service/hid/controllers/applet_resource.h" | 12 | #include "core/hle/service/hid/controllers/applet_resource.h" |
| 13 | #include "core/hle/service/hid/controllers/capture_button.h" | ||
| 13 | #include "core/hle/service/hid/controllers/console_six_axis.h" | 14 | #include "core/hle/service/hid/controllers/console_six_axis.h" |
| 15 | #include "core/hle/service/hid/controllers/debug_mouse.h" | ||
| 14 | #include "core/hle/service/hid/controllers/debug_pad.h" | 16 | #include "core/hle/service/hid/controllers/debug_pad.h" |
| 17 | #include "core/hle/service/hid/controllers/digitizer.h" | ||
| 15 | #include "core/hle/service/hid/controllers/gesture.h" | 18 | #include "core/hle/service/hid/controllers/gesture.h" |
| 19 | #include "core/hle/service/hid/controllers/home_button.h" | ||
| 16 | #include "core/hle/service/hid/controllers/keyboard.h" | 20 | #include "core/hle/service/hid/controllers/keyboard.h" |
| 17 | #include "core/hle/service/hid/controllers/mouse.h" | 21 | #include "core/hle/service/hid/controllers/mouse.h" |
| 18 | #include "core/hle/service/hid/controllers/npad.h" | 22 | #include "core/hle/service/hid/controllers/npad.h" |
| 19 | #include "core/hle/service/hid/controllers/palma.h" | 23 | #include "core/hle/service/hid/controllers/palma.h" |
| 20 | #include "core/hle/service/hid/controllers/seven_six_axis.h" | 24 | #include "core/hle/service/hid/controllers/seven_six_axis.h" |
| 21 | #include "core/hle/service/hid/controllers/shared_memory_format.h" | ||
| 22 | #include "core/hle/service/hid/controllers/six_axis.h" | 25 | #include "core/hle/service/hid/controllers/six_axis.h" |
| 23 | #include "core/hle/service/hid/controllers/stubbed.h" | 26 | #include "core/hle/service/hid/controllers/sleep_button.h" |
| 24 | #include "core/hle/service/hid/controllers/touchscreen.h" | 27 | #include "core/hle/service/hid/controllers/touchscreen.h" |
| 28 | #include "core/hle/service/hid/controllers/types/shared_memory_format.h" | ||
| 29 | #include "core/hle/service/hid/controllers/unique_pad.h" | ||
| 25 | 30 | ||
| 26 | namespace Service::HID { | 31 | namespace Service::HID { |
| 27 | 32 | ||
| @@ -46,42 +51,13 @@ void ResourceManager::Initialize() { | |||
| 46 | } | 51 | } |
| 47 | 52 | ||
| 48 | system.HIDCore().ReloadInputDevices(); | 53 | system.HIDCore().ReloadInputDevices(); |
| 49 | is_initialized = true; | ||
| 50 | } | ||
| 51 | |||
| 52 | void ResourceManager::InitializeController(u64 aruid) { | ||
| 53 | SharedMemoryFormat* shared_memory = nullptr; | ||
| 54 | const auto result = applet_resource->GetSharedMemoryFormat(&shared_memory, aruid); | ||
| 55 | if (result.IsError()) { | ||
| 56 | return; | ||
| 57 | } | ||
| 58 | |||
| 59 | debug_pad = std::make_shared<DebugPad>(system.HIDCore(), shared_memory->debug_pad); | ||
| 60 | mouse = std::make_shared<Mouse>(system.HIDCore(), shared_memory->mouse); | ||
| 61 | debug_mouse = std::make_shared<DebugMouse>(system.HIDCore(), shared_memory->debug_mouse); | ||
| 62 | keyboard = std::make_shared<Keyboard>(system.HIDCore(), shared_memory->keyboard); | ||
| 63 | unique_pad = std::make_shared<UniquePad>(system.HIDCore(), shared_memory->unique_pad.header); | ||
| 64 | npad = std::make_shared<NPad>(system.HIDCore(), shared_memory->npad, service_context); | ||
| 65 | gesture = std::make_shared<Gesture>(system.HIDCore(), shared_memory->gesture); | ||
| 66 | touch_screen = std::make_shared<TouchScreen>(system.HIDCore(), shared_memory->touch_screen); | ||
| 67 | 54 | ||
| 68 | palma = std::make_shared<Palma>(system.HIDCore(), service_context); | 55 | InitializeHidCommonSampler(); |
| 56 | InitializeTouchScreenSampler(); | ||
| 57 | InitializeConsoleSixAxisSampler(); | ||
| 58 | InitializeAHidSampler(); | ||
| 69 | 59 | ||
| 70 | home_button = std::make_shared<HomeButton>(system.HIDCore(), shared_memory->home_button.header); | 60 | is_initialized = true; |
| 71 | sleep_button = | ||
| 72 | std::make_shared<SleepButton>(system.HIDCore(), shared_memory->sleep_button.header); | ||
| 73 | capture_button = | ||
| 74 | std::make_shared<CaptureButton>(system.HIDCore(), shared_memory->capture_button.header); | ||
| 75 | digitizer = std::make_shared<Digitizer>(system.HIDCore(), shared_memory->digitizer.header); | ||
| 76 | |||
| 77 | six_axis = std::make_shared<SixAxis>(system.HIDCore(), npad); | ||
| 78 | console_six_axis = std::make_shared<ConsoleSixAxis>(system.HIDCore(), shared_memory->console); | ||
| 79 | seven_six_axis = std::make_shared<SevenSixAxis>(system); | ||
| 80 | |||
| 81 | // Homebrew doesn't try to activate some controllers, so we activate them by default | ||
| 82 | npad->Activate(); | ||
| 83 | six_axis->Activate(); | ||
| 84 | touch_screen->Activate(); | ||
| 85 | } | 61 | } |
| 86 | 62 | ||
| 87 | std::shared_ptr<AppletResource> ResourceManager::GetAppletResource() const { | 63 | std::shared_ptr<AppletResource> ResourceManager::GetAppletResource() const { |
| @@ -165,16 +141,65 @@ Result ResourceManager::CreateAppletResource(u64 aruid) { | |||
| 165 | if (result.IsError()) { | 141 | if (result.IsError()) { |
| 166 | return result; | 142 | return result; |
| 167 | } | 143 | } |
| 144 | |||
| 145 | // Homebrew doesn't try to activate some controllers, so we activate them by default | ||
| 146 | npad->Activate(); | ||
| 147 | six_axis->Activate(); | ||
| 148 | touch_screen->Activate(); | ||
| 149 | |||
| 168 | return GetNpad()->Activate(aruid); | 150 | return GetNpad()->Activate(aruid); |
| 169 | } | 151 | } |
| 170 | 152 | ||
| 171 | Result ResourceManager::CreateAppletResourceImpl(u64 aruid) { | 153 | Result ResourceManager::CreateAppletResourceImpl(u64 aruid) { |
| 172 | std::scoped_lock lock{shared_mutex}; | 154 | std::scoped_lock lock{shared_mutex}; |
| 173 | const auto result = applet_resource->CreateAppletResource(aruid); | 155 | return applet_resource->CreateAppletResource(aruid); |
| 174 | if (result.IsSuccess()) { | 156 | } |
| 175 | InitializeController(aruid); | 157 | |
| 176 | } | 158 | void ResourceManager::InitializeHidCommonSampler() { |
| 177 | return result; | 159 | debug_pad = std::make_shared<DebugPad>(system.HIDCore()); |
| 160 | mouse = std::make_shared<Mouse>(system.HIDCore()); | ||
| 161 | debug_mouse = std::make_shared<DebugMouse>(system.HIDCore()); | ||
| 162 | keyboard = std::make_shared<Keyboard>(system.HIDCore()); | ||
| 163 | unique_pad = std::make_shared<UniquePad>(system.HIDCore()); | ||
| 164 | npad = std::make_shared<NPad>(system.HIDCore(), service_context); | ||
| 165 | gesture = std::make_shared<Gesture>(system.HIDCore()); | ||
| 166 | home_button = std::make_shared<HomeButton>(system.HIDCore()); | ||
| 167 | sleep_button = std::make_shared<SleepButton>(system.HIDCore()); | ||
| 168 | capture_button = std::make_shared<CaptureButton>(system.HIDCore()); | ||
| 169 | digitizer = std::make_shared<Digitizer>(system.HIDCore()); | ||
| 170 | |||
| 171 | palma = std::make_shared<Palma>(system.HIDCore(), service_context); | ||
| 172 | six_axis = std::make_shared<SixAxis>(system.HIDCore(), npad); | ||
| 173 | |||
| 174 | debug_pad->SetAppletResource(applet_resource); | ||
| 175 | digitizer->SetAppletResource(applet_resource); | ||
| 176 | keyboard->SetAppletResource(applet_resource); | ||
| 177 | npad->SetAppletResource(applet_resource); | ||
| 178 | six_axis->SetAppletResource(applet_resource); | ||
| 179 | mouse->SetAppletResource(applet_resource); | ||
| 180 | debug_mouse->SetAppletResource(applet_resource); | ||
| 181 | home_button->SetAppletResource(applet_resource); | ||
| 182 | sleep_button->SetAppletResource(applet_resource); | ||
| 183 | capture_button->SetAppletResource(applet_resource); | ||
| 184 | } | ||
| 185 | |||
| 186 | void ResourceManager::InitializeTouchScreenSampler() { | ||
| 187 | gesture = std::make_shared<Gesture>(system.HIDCore()); | ||
| 188 | touch_screen = std::make_shared<TouchScreen>(system.HIDCore()); | ||
| 189 | |||
| 190 | touch_screen->SetAppletResource(applet_resource); | ||
| 191 | gesture->SetAppletResource(applet_resource); | ||
| 192 | } | ||
| 193 | |||
| 194 | void ResourceManager::InitializeConsoleSixAxisSampler() { | ||
| 195 | console_six_axis = std::make_shared<ConsoleSixAxis>(system.HIDCore()); | ||
| 196 | seven_six_axis = std::make_shared<SevenSixAxis>(system); | ||
| 197 | |||
| 198 | console_six_axis->SetAppletResource(applet_resource); | ||
| 199 | } | ||
| 200 | |||
| 201 | void ResourceManager::InitializeAHidSampler() { | ||
| 202 | // TODO | ||
| 178 | } | 203 | } |
| 179 | 204 | ||
| 180 | Result ResourceManager::RegisterCoreAppletResource() { | 205 | Result ResourceManager::RegisterCoreAppletResource() { |
diff --git a/src/core/hle/service/hid/resource_manager.h b/src/core/hle/service/hid/resource_manager.h index 5ad7cb564..7df1567cc 100644 --- a/src/core/hle/service/hid/resource_manager.h +++ b/src/core/hle/service/hid/resource_manager.h | |||
| @@ -20,24 +20,23 @@ class KSharedMemory; | |||
| 20 | 20 | ||
| 21 | namespace Service::HID { | 21 | namespace Service::HID { |
| 22 | class AppletResource; | 22 | class AppletResource; |
| 23 | class CaptureButton; | ||
| 23 | class Controller_Stubbed; | 24 | class Controller_Stubbed; |
| 24 | class ConsoleSixAxis; | 25 | class ConsoleSixAxis; |
| 26 | class DebugMouse; | ||
| 25 | class DebugPad; | 27 | class DebugPad; |
| 28 | class Digitizer; | ||
| 26 | class Gesture; | 29 | class Gesture; |
| 30 | class HomeButton; | ||
| 27 | class Keyboard; | 31 | class Keyboard; |
| 28 | class Mouse; | 32 | class Mouse; |
| 29 | class NPad; | 33 | class NPad; |
| 30 | class Palma; | 34 | class Palma; |
| 31 | class SevenSixAxis; | 35 | class SevenSixAxis; |
| 32 | class SixAxis; | 36 | class SixAxis; |
| 37 | class SleepButton; | ||
| 33 | class TouchScreen; | 38 | class TouchScreen; |
| 34 | 39 | class UniquePad; | |
| 35 | using CaptureButton = Controller_Stubbed; | ||
| 36 | using DebugMouse = Mouse; | ||
| 37 | using Digitizer = Controller_Stubbed; | ||
| 38 | using HomeButton = Controller_Stubbed; | ||
| 39 | using SleepButton = Controller_Stubbed; | ||
| 40 | using UniquePad = Controller_Stubbed; | ||
| 41 | 40 | ||
| 42 | class ResourceManager { | 41 | class ResourceManager { |
| 43 | 42 | ||
| @@ -46,7 +45,6 @@ public: | |||
| 46 | ~ResourceManager(); | 45 | ~ResourceManager(); |
| 47 | 46 | ||
| 48 | void Initialize(); | 47 | void Initialize(); |
| 49 | void InitializeController(u64 aruid); | ||
| 50 | 48 | ||
| 51 | std::shared_ptr<AppletResource> GetAppletResource() const; | 49 | std::shared_ptr<AppletResource> GetAppletResource() const; |
| 52 | std::shared_ptr<CaptureButton> GetCaptureButton() const; | 50 | std::shared_ptr<CaptureButton> GetCaptureButton() const; |
| @@ -88,6 +86,10 @@ public: | |||
| 88 | 86 | ||
| 89 | private: | 87 | private: |
| 90 | Result CreateAppletResourceImpl(u64 aruid); | 88 | Result CreateAppletResourceImpl(u64 aruid); |
| 89 | void InitializeHidCommonSampler(); | ||
| 90 | void InitializeTouchScreenSampler(); | ||
| 91 | void InitializeConsoleSixAxisSampler(); | ||
| 92 | void InitializeAHidSampler(); | ||
| 91 | 93 | ||
| 92 | bool is_initialized{false}; | 94 | bool is_initialized{false}; |
| 93 | 95 | ||