diff options
| author | 2024-01-28 19:19:21 -0600 | |
|---|---|---|
| committer | 2024-01-28 19:28:37 -0600 | |
| commit | b8f16f3538fac8d4434905d531885b9862706bd0 (patch) | |
| tree | 2e582d1d36fbc340f0175ad816362faccb20eee8 /src | |
| parent | Merge pull request #12555 from flodavid/fix-gamemode-setting (diff) | |
| download | yuzu-b8f16f3538fac8d4434905d531885b9862706bd0.tar.gz yuzu-b8f16f3538fac8d4434905d531885b9862706bd0.tar.xz yuzu-b8f16f3538fac8d4434905d531885b9862706bd0.zip | |
service: hid: Implement home, capture and sleep buttons
Diffstat (limited to 'src')
| -rw-r--r-- | src/hid_core/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/hid_core/hid_types.h | 10 | ||||
| -rw-r--r-- | src/hid_core/resources/shared_memory_format.h | 13 | ||||
| -rw-r--r-- | src/hid_core/resources/system_buttons/capture_button.cpp | 26 | ||||
| -rw-r--r-- | src/hid_core/resources/system_buttons/capture_button.h | 3 | ||||
| -rw-r--r-- | src/hid_core/resources/system_buttons/home_button.cpp | 26 | ||||
| -rw-r--r-- | src/hid_core/resources/system_buttons/home_button.h | 3 | ||||
| -rw-r--r-- | src/hid_core/resources/system_buttons/sleep_button.cpp | 23 | ||||
| -rw-r--r-- | src/hid_core/resources/system_buttons/sleep_button.h | 3 | ||||
| -rw-r--r-- | src/hid_core/resources/system_buttons/system_button_types.h | 31 | ||||
| -rw-r--r-- | src/hid_core/resources/unique_pad/unique_pad.cpp | 2 |
11 files changed, 104 insertions, 37 deletions
diff --git a/src/hid_core/CMakeLists.txt b/src/hid_core/CMakeLists.txt index aa85502b5..64cd6e726 100644 --- a/src/hid_core/CMakeLists.txt +++ b/src/hid_core/CMakeLists.txt | |||
| @@ -96,6 +96,7 @@ add_library(hid_core STATIC | |||
| 96 | resources/system_buttons/home_button.h | 96 | resources/system_buttons/home_button.h |
| 97 | resources/system_buttons/sleep_button.cpp | 97 | resources/system_buttons/sleep_button.cpp |
| 98 | resources/system_buttons/sleep_button.h | 98 | resources/system_buttons/sleep_button.h |
| 99 | resources/system_buttons/system_button_types.h | ||
| 99 | resources/touch_screen/gesture.cpp | 100 | resources/touch_screen/gesture.cpp |
| 100 | resources/touch_screen/gesture.h | 101 | resources/touch_screen/gesture.h |
| 101 | resources/touch_screen/gesture_types.h | 102 | resources/touch_screen/gesture_types.h |
diff --git a/src/hid_core/hid_types.h b/src/hid_core/hid_types.h index a01292a70..b310ab72d 100644 --- a/src/hid_core/hid_types.h +++ b/src/hid_core/hid_types.h | |||
| @@ -437,6 +437,16 @@ struct LedPattern { | |||
| 437 | }; | 437 | }; |
| 438 | }; | 438 | }; |
| 439 | 439 | ||
| 440 | struct SleepButtonState { | ||
| 441 | union { | ||
| 442 | u64 raw{}; | ||
| 443 | |||
| 444 | // Buttons | ||
| 445 | BitField<0, 1, u64> sleep; | ||
| 446 | }; | ||
| 447 | }; | ||
| 448 | static_assert(sizeof(SleepButtonState) == 0x8, "SleepButtonState has incorrect size."); | ||
| 449 | |||
| 440 | struct HomeButtonState { | 450 | struct HomeButtonState { |
| 441 | union { | 451 | union { |
| 442 | u64 raw{}; | 452 | u64 raw{}; |
diff --git a/src/hid_core/resources/shared_memory_format.h b/src/hid_core/resources/shared_memory_format.h index 2ae0004ba..49755c8dc 100644 --- a/src/hid_core/resources/shared_memory_format.h +++ b/src/hid_core/resources/shared_memory_format.h | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | #include "hid_core/resources/mouse/mouse_types.h" | 12 | #include "hid_core/resources/mouse/mouse_types.h" |
| 13 | #include "hid_core/resources/npad/npad_types.h" | 13 | #include "hid_core/resources/npad/npad_types.h" |
| 14 | #include "hid_core/resources/ring_lifo.h" | 14 | #include "hid_core/resources/ring_lifo.h" |
| 15 | #include "hid_core/resources/system_buttons/system_button_types.h" | ||
| 15 | #include "hid_core/resources/touch_screen/touch_types.h" | 16 | #include "hid_core/resources/touch_screen/touch_types.h" |
| 16 | 17 | ||
| 17 | namespace Service::HID { | 18 | namespace Service::HID { |
| @@ -75,24 +76,24 @@ static_assert(sizeof(DigitizerSharedMemoryFormat) == 0x1000, | |||
| 75 | 76 | ||
| 76 | // This is nn::hid::detail::HomeButtonSharedMemoryFormat | 77 | // This is nn::hid::detail::HomeButtonSharedMemoryFormat |
| 77 | struct HomeButtonSharedMemoryFormat { | 78 | struct HomeButtonSharedMemoryFormat { |
| 78 | CommonHeader header; | 79 | Lifo<HomeButtonState, HidEntryCount> home_lifo{}; |
| 79 | INSERT_PADDING_BYTES(0x1E0); | 80 | INSERT_PADDING_BYTES(0x48); |
| 80 | }; | 81 | }; |
| 81 | static_assert(sizeof(HomeButtonSharedMemoryFormat) == 0x200, | 82 | static_assert(sizeof(HomeButtonSharedMemoryFormat) == 0x200, |
| 82 | "HomeButtonSharedMemoryFormat is an invalid size"); | 83 | "HomeButtonSharedMemoryFormat is an invalid size"); |
| 83 | 84 | ||
| 84 | // This is nn::hid::detail::SleepButtonSharedMemoryFormat | 85 | // This is nn::hid::detail::SleepButtonSharedMemoryFormat |
| 85 | struct SleepButtonSharedMemoryFormat { | 86 | struct SleepButtonSharedMemoryFormat { |
| 86 | CommonHeader header; | 87 | Lifo<SleepButtonState, HidEntryCount> sleep_lifo{}; |
| 87 | INSERT_PADDING_BYTES(0x1E0); | 88 | INSERT_PADDING_BYTES(0x48); |
| 88 | }; | 89 | }; |
| 89 | static_assert(sizeof(SleepButtonSharedMemoryFormat) == 0x200, | 90 | static_assert(sizeof(SleepButtonSharedMemoryFormat) == 0x200, |
| 90 | "SleepButtonSharedMemoryFormat is an invalid size"); | 91 | "SleepButtonSharedMemoryFormat is an invalid size"); |
| 91 | 92 | ||
| 92 | // This is nn::hid::detail::CaptureButtonSharedMemoryFormat | 93 | // This is nn::hid::detail::CaptureButtonSharedMemoryFormat |
| 93 | struct CaptureButtonSharedMemoryFormat { | 94 | struct CaptureButtonSharedMemoryFormat { |
| 94 | CommonHeader header; | 95 | Lifo<CaptureButtonState, HidEntryCount> capture_lifo{}; |
| 95 | INSERT_PADDING_BYTES(0x1E0); | 96 | INSERT_PADDING_BYTES(0x48); |
| 96 | }; | 97 | }; |
| 97 | static_assert(sizeof(CaptureButtonSharedMemoryFormat) == 0x200, | 98 | static_assert(sizeof(CaptureButtonSharedMemoryFormat) == 0x200, |
| 98 | "CaptureButtonSharedMemoryFormat is an invalid size"); | 99 | "CaptureButtonSharedMemoryFormat is an invalid size"); |
diff --git a/src/hid_core/resources/system_buttons/capture_button.cpp b/src/hid_core/resources/system_buttons/capture_button.cpp index 70973ae25..95eb60424 100644 --- a/src/hid_core/resources/system_buttons/capture_button.cpp +++ b/src/hid_core/resources/system_buttons/capture_button.cpp | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include "core/core_timing.h" | 4 | #include "core/core_timing.h" |
| 5 | #include "hid_core/frontend/emulated_controller.h" | ||
| 6 | #include "hid_core/hid_core.h" | ||
| 5 | #include "hid_core/resources/applet_resource.h" | 7 | #include "hid_core/resources/applet_resource.h" |
| 6 | #include "hid_core/resources/shared_memory_format.h" | 8 | #include "hid_core/resources/shared_memory_format.h" |
| 7 | #include "hid_core/resources/system_buttons/capture_button.h" | 9 | #include "hid_core/resources/system_buttons/capture_button.h" |
| @@ -17,10 +19,6 @@ void CaptureButton::OnInit() {} | |||
| 17 | void CaptureButton::OnRelease() {} | 19 | void CaptureButton::OnRelease() {} |
| 18 | 20 | ||
| 19 | void CaptureButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | 21 | void CaptureButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { |
| 20 | if (!smart_update) { | ||
| 21 | return; | ||
| 22 | } | ||
| 23 | |||
| 24 | std::scoped_lock shared_lock{*shared_mutex}; | 22 | std::scoped_lock shared_lock{*shared_mutex}; |
| 25 | const u64 aruid = applet_resource->GetActiveAruid(); | 23 | const u64 aruid = applet_resource->GetActiveAruid(); |
| 26 | auto* data = applet_resource->GetAruidData(aruid); | 24 | auto* data = applet_resource->GetAruidData(aruid); |
| @@ -29,11 +27,21 @@ void CaptureButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | |||
| 29 | return; | 27 | return; |
| 30 | } | 28 | } |
| 31 | 29 | ||
| 32 | auto& header = data->shared_memory_format->capture_button.header; | 30 | auto& shared_memory = data->shared_memory_format->capture_button; |
| 33 | header.timestamp = core_timing.GetGlobalTimeNs().count(); | 31 | |
| 34 | header.total_entry_count = 17; | 32 | if (!IsControllerActivated()) { |
| 35 | header.entry_count = 0; | 33 | shared_memory.capture_lifo.buffer_count = 0; |
| 36 | header.last_entry_index = 0; | 34 | shared_memory.capture_lifo.buffer_tail = 0; |
| 35 | return; | ||
| 36 | } | ||
| 37 | |||
| 38 | const auto& last_entry = shared_memory.capture_lifo.ReadCurrentEntry().state; | ||
| 39 | next_state.sampling_number = last_entry.sampling_number + 1; | ||
| 40 | |||
| 41 | auto* controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); | ||
| 42 | next_state.buttons.raw = controller->GetHomeButtons().raw; | ||
| 43 | |||
| 44 | shared_memory.capture_lifo.WriteNextEntry(next_state); | ||
| 37 | } | 45 | } |
| 38 | 46 | ||
| 39 | } // namespace Service::HID | 47 | } // namespace Service::HID |
diff --git a/src/hid_core/resources/system_buttons/capture_button.h b/src/hid_core/resources/system_buttons/capture_button.h index ad95d7cad..f362ef90b 100644 --- a/src/hid_core/resources/system_buttons/capture_button.h +++ b/src/hid_core/resources/system_buttons/capture_button.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include "hid_core/resources/controller_base.h" | 6 | #include "hid_core/resources/controller_base.h" |
| 7 | #include "hid_core/resources/system_buttons/system_button_types.h" | ||
| 7 | 8 | ||
| 8 | namespace Service::HID { | 9 | namespace Service::HID { |
| 9 | 10 | ||
| @@ -22,6 +23,6 @@ public: | |||
| 22 | void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; | 23 | void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; |
| 23 | 24 | ||
| 24 | private: | 25 | private: |
| 25 | bool smart_update{}; | 26 | CaptureButtonState next_state{}; |
| 26 | }; | 27 | }; |
| 27 | } // namespace Service::HID | 28 | } // namespace Service::HID |
diff --git a/src/hid_core/resources/system_buttons/home_button.cpp b/src/hid_core/resources/system_buttons/home_button.cpp index f9c1f44b5..f665338f3 100644 --- a/src/hid_core/resources/system_buttons/home_button.cpp +++ b/src/hid_core/resources/system_buttons/home_button.cpp | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include "core/core_timing.h" | 4 | #include "core/core_timing.h" |
| 5 | #include "hid_core/frontend/emulated_controller.h" | ||
| 6 | #include "hid_core/hid_core.h" | ||
| 5 | #include "hid_core/resources/applet_resource.h" | 7 | #include "hid_core/resources/applet_resource.h" |
| 6 | #include "hid_core/resources/shared_memory_format.h" | 8 | #include "hid_core/resources/shared_memory_format.h" |
| 7 | #include "hid_core/resources/system_buttons/home_button.h" | 9 | #include "hid_core/resources/system_buttons/home_button.h" |
| @@ -17,10 +19,6 @@ void HomeButton::OnInit() {} | |||
| 17 | void HomeButton::OnRelease() {} | 19 | void HomeButton::OnRelease() {} |
| 18 | 20 | ||
| 19 | void HomeButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | 21 | void HomeButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { |
| 20 | if (!smart_update) { | ||
| 21 | return; | ||
| 22 | } | ||
| 23 | |||
| 24 | std::scoped_lock shared_lock{*shared_mutex}; | 22 | std::scoped_lock shared_lock{*shared_mutex}; |
| 25 | const u64 aruid = applet_resource->GetActiveAruid(); | 23 | const u64 aruid = applet_resource->GetActiveAruid(); |
| 26 | auto* data = applet_resource->GetAruidData(aruid); | 24 | auto* data = applet_resource->GetAruidData(aruid); |
| @@ -29,11 +27,21 @@ void HomeButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | |||
| 29 | return; | 27 | return; |
| 30 | } | 28 | } |
| 31 | 29 | ||
| 32 | auto& header = data->shared_memory_format->home_button.header; | 30 | auto& shared_memory = data->shared_memory_format->home_button; |
| 33 | header.timestamp = core_timing.GetGlobalTimeNs().count(); | 31 | |
| 34 | header.total_entry_count = 17; | 32 | if (!IsControllerActivated()) { |
| 35 | header.entry_count = 0; | 33 | shared_memory.home_lifo.buffer_count = 0; |
| 36 | header.last_entry_index = 0; | 34 | shared_memory.home_lifo.buffer_tail = 0; |
| 35 | return; | ||
| 36 | } | ||
| 37 | |||
| 38 | const auto& last_entry = shared_memory.home_lifo.ReadCurrentEntry().state; | ||
| 39 | next_state.sampling_number = last_entry.sampling_number + 1; | ||
| 40 | |||
| 41 | auto* controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); | ||
| 42 | next_state.buttons.raw = controller->GetHomeButtons().raw; | ||
| 43 | |||
| 44 | shared_memory.home_lifo.WriteNextEntry(next_state); | ||
| 37 | } | 45 | } |
| 38 | 46 | ||
| 39 | } // namespace Service::HID | 47 | } // namespace Service::HID |
diff --git a/src/hid_core/resources/system_buttons/home_button.h b/src/hid_core/resources/system_buttons/home_button.h index ecf8327f4..a9374828d 100644 --- a/src/hid_core/resources/system_buttons/home_button.h +++ b/src/hid_core/resources/system_buttons/home_button.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include "hid_core/resources/controller_base.h" | 6 | #include "hid_core/resources/controller_base.h" |
| 7 | #include "hid_core/resources/system_buttons/system_button_types.h" | ||
| 7 | 8 | ||
| 8 | namespace Service::HID { | 9 | namespace Service::HID { |
| 9 | 10 | ||
| @@ -22,6 +23,6 @@ public: | |||
| 22 | void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; | 23 | void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; |
| 23 | 24 | ||
| 24 | private: | 25 | private: |
| 25 | bool smart_update{}; | 26 | HomeButtonState next_state{}; |
| 26 | }; | 27 | }; |
| 27 | } // namespace Service::HID | 28 | } // namespace Service::HID |
diff --git a/src/hid_core/resources/system_buttons/sleep_button.cpp b/src/hid_core/resources/system_buttons/sleep_button.cpp index 22adf501f..159663246 100644 --- a/src/hid_core/resources/system_buttons/sleep_button.cpp +++ b/src/hid_core/resources/system_buttons/sleep_button.cpp | |||
| @@ -17,10 +17,6 @@ void SleepButton::OnInit() {} | |||
| 17 | void SleepButton::OnRelease() {} | 17 | void SleepButton::OnRelease() {} |
| 18 | 18 | ||
| 19 | void SleepButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | 19 | void SleepButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { |
| 20 | if (!smart_update) { | ||
| 21 | return; | ||
| 22 | } | ||
| 23 | |||
| 24 | std::scoped_lock shared_lock{*shared_mutex}; | 20 | std::scoped_lock shared_lock{*shared_mutex}; |
| 25 | const u64 aruid = applet_resource->GetActiveAruid(); | 21 | const u64 aruid = applet_resource->GetActiveAruid(); |
| 26 | auto* data = applet_resource->GetAruidData(aruid); | 22 | auto* data = applet_resource->GetAruidData(aruid); |
| @@ -29,11 +25,20 @@ void SleepButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | |||
| 29 | return; | 25 | return; |
| 30 | } | 26 | } |
| 31 | 27 | ||
| 32 | auto& header = data->shared_memory_format->capture_button.header; | 28 | auto& shared_memory = data->shared_memory_format->sleep_button; |
| 33 | header.timestamp = core_timing.GetGlobalTimeNs().count(); | 29 | |
| 34 | header.total_entry_count = 17; | 30 | if (!IsControllerActivated()) { |
| 35 | header.entry_count = 0; | 31 | shared_memory.sleep_lifo.buffer_count = 0; |
| 36 | header.last_entry_index = 0; | 32 | shared_memory.sleep_lifo.buffer_tail = 0; |
| 33 | return; | ||
| 34 | } | ||
| 35 | |||
| 36 | const auto& last_entry = shared_memory.sleep_lifo.ReadCurrentEntry().state; | ||
| 37 | next_state.sampling_number = last_entry.sampling_number + 1; | ||
| 38 | |||
| 39 | next_state.buttons.raw = 0; | ||
| 40 | |||
| 41 | shared_memory.sleep_lifo.WriteNextEntry(next_state); | ||
| 37 | } | 42 | } |
| 38 | 43 | ||
| 39 | } // namespace Service::HID | 44 | } // namespace Service::HID |
diff --git a/src/hid_core/resources/system_buttons/sleep_button.h b/src/hid_core/resources/system_buttons/sleep_button.h index f9ed38c33..f8ac5031b 100644 --- a/src/hid_core/resources/system_buttons/sleep_button.h +++ b/src/hid_core/resources/system_buttons/sleep_button.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include "hid_core/resources/controller_base.h" | 6 | #include "hid_core/resources/controller_base.h" |
| 7 | #include "hid_core/resources/system_buttons/system_button_types.h" | ||
| 7 | 8 | ||
| 8 | namespace Service::HID { | 9 | namespace Service::HID { |
| 9 | 10 | ||
| @@ -22,6 +23,6 @@ public: | |||
| 22 | void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; | 23 | void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; |
| 23 | 24 | ||
| 24 | private: | 25 | private: |
| 25 | bool smart_update{}; | 26 | SleepButtonState next_state{}; |
| 26 | }; | 27 | }; |
| 27 | } // namespace Service::HID | 28 | } // namespace Service::HID |
diff --git a/src/hid_core/resources/system_buttons/system_button_types.h b/src/hid_core/resources/system_buttons/system_button_types.h new file mode 100644 index 000000000..929e1dc4c --- /dev/null +++ b/src/hid_core/resources/system_buttons/system_button_types.h | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "hid_core/hid_types.h" | ||
| 7 | |||
| 8 | namespace Service::HID { | ||
| 9 | |||
| 10 | // This is nn::hid::system::SleepButtonState | ||
| 11 | struct SleepButtonState { | ||
| 12 | s64 sampling_number{}; | ||
| 13 | Core::HID::SleepButtonState buttons; | ||
| 14 | }; | ||
| 15 | static_assert(sizeof(SleepButtonState) == 0x10, "SleepButtonState is an invalid size"); | ||
| 16 | |||
| 17 | // This is nn::hid::system::HomeButtonState | ||
| 18 | struct HomeButtonState { | ||
| 19 | s64 sampling_number{}; | ||
| 20 | Core::HID::HomeButtonState buttons; | ||
| 21 | }; | ||
| 22 | static_assert(sizeof(HomeButtonState) == 0x10, "HomeButtonState is an invalid size"); | ||
| 23 | |||
| 24 | // This is nn::hid::system::SleepButtonState | ||
| 25 | struct CaptureButtonState { | ||
| 26 | s64 sampling_number{}; | ||
| 27 | Core::HID::CaptureButtonState buttons; | ||
| 28 | }; | ||
| 29 | static_assert(sizeof(CaptureButtonState) == 0x10, "CaptureButtonState is an invalid size"); | ||
| 30 | |||
| 31 | } // namespace Service::HID | ||
diff --git a/src/hid_core/resources/unique_pad/unique_pad.cpp b/src/hid_core/resources/unique_pad/unique_pad.cpp index 892bbe3c9..89fc57269 100644 --- a/src/hid_core/resources/unique_pad/unique_pad.cpp +++ b/src/hid_core/resources/unique_pad/unique_pad.cpp | |||
| @@ -28,7 +28,7 @@ void UniquePad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { | |||
| 28 | return; | 28 | return; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | auto& header = data->shared_memory_format->capture_button.header; | 31 | auto& header = data->shared_memory_format->unique_pad.header; |
| 32 | header.timestamp = core_timing.GetGlobalTimeNs().count(); | 32 | header.timestamp = core_timing.GetGlobalTimeNs().count(); |
| 33 | header.total_entry_count = 17; | 33 | header.total_entry_count = 17; |
| 34 | header.entry_count = 0; | 34 | header.entry_count = 0; |