diff options
| author | 2018-10-06 00:23:21 +1000 | |
|---|---|---|
| committer | 2018-10-10 13:15:35 +1100 | |
| commit | 56f35ab2629c3753dbb624799bd8aaff2a179f58 (patch) | |
| tree | d4c27964cf6f7679529f1042e9d71005f1e73864 /src | |
| parent | Merge pull request #1466 from lioncash/unused (diff) | |
| download | yuzu-56f35ab2629c3753dbb624799bd8aaff2a179f58.tar.gz yuzu-56f35ab2629c3753dbb624799bd8aaff2a179f58.tar.xz yuzu-56f35ab2629c3753dbb624799bd8aaff2a179f58.zip | |
"Better Hid" rework part 1
Diffstat (limited to 'src')
22 files changed, 1500 insertions, 644 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index e4a676e91..1a9ec459f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -233,6 +233,24 @@ add_library(core STATIC | |||
| 233 | hle/service/hid/irs.h | 233 | hle/service/hid/irs.h |
| 234 | hle/service/hid/xcd.cpp | 234 | hle/service/hid/xcd.cpp |
| 235 | hle/service/hid/xcd.h | 235 | hle/service/hid/xcd.h |
| 236 | hle/service/hid/controllers/controller_base.cpp | ||
| 237 | hle/service/hid/controllers/controller_base.h | ||
| 238 | hle/service/hid/controllers/debug_pad.cpp | ||
| 239 | hle/service/hid/controllers/debug_pad.h | ||
| 240 | hle/service/hid/controllers/gesture.cpp | ||
| 241 | hle/service/hid/controllers/gesture.h | ||
| 242 | hle/service/hid/controllers/keyboard.cpp | ||
| 243 | hle/service/hid/controllers/keyboard.h | ||
| 244 | hle/service/hid/controllers/mouse.cpp | ||
| 245 | hle/service/hid/controllers/mouse.h | ||
| 246 | hle/service/hid/controllers/npad.cpp | ||
| 247 | hle/service/hid/controllers/npad.h | ||
| 248 | hle/service/hid/controllers/stubbed.cpp | ||
| 249 | hle/service/hid/controllers/stubbed.h | ||
| 250 | hle/service/hid/controllers/touchscreen.cpp | ||
| 251 | hle/service/hid/controllers/touchscreen.h | ||
| 252 | hle/service/hid/controllers/xpad.cpp | ||
| 253 | hle/service/hid/controllers/xpad.h | ||
| 236 | hle/service/lbl/lbl.cpp | 254 | hle/service/lbl/lbl.cpp |
| 237 | hle/service/lbl/lbl.h | 255 | hle/service/lbl/lbl.h |
| 238 | hle/service/ldn/ldn.cpp | 256 | hle/service/ldn/ldn.cpp |
diff --git a/src/core/hle/service/hid/controllers/controller_base.cpp b/src/core/hle/service/hid/controllers/controller_base.cpp new file mode 100644 index 000000000..f2aef5642 --- /dev/null +++ b/src/core/hle/service/hid/controllers/controller_base.cpp | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "core/hle/service/hid/controllers/controller_base.h" | ||
| 6 | |||
| 7 | namespace Service::HID { | ||
| 8 | void ControllerBase::ActivateController() { | ||
| 9 | if (is_activated) { | ||
| 10 | OnRelease(); | ||
| 11 | } | ||
| 12 | is_activated = true; | ||
| 13 | OnInit(); | ||
| 14 | } | ||
| 15 | |||
| 16 | void ControllerBase::DeactivateController() { | ||
| 17 | if (is_activated) { | ||
| 18 | OnRelease(); | ||
| 19 | } | ||
| 20 | is_activated = false; | ||
| 21 | } | ||
| 22 | |||
| 23 | bool ControllerBase::IsControllerActivated() const { | ||
| 24 | return is_activated; | ||
| 25 | } | ||
| 26 | // ControllerBase::~ControllerBase() = default; | ||
| 27 | }; // 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 new file mode 100644 index 000000000..3b1c8aad6 --- /dev/null +++ b/src/core/hle/service/hid/controllers/controller_base.h | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | #include "common/common_types.h" | ||
| 7 | #include "common/swap.h" | ||
| 8 | |||
| 9 | namespace Service::HID { | ||
| 10 | class ControllerBase { | ||
| 11 | public: | ||
| 12 | ControllerBase() = default; | ||
| 13 | |||
| 14 | // Called when the controller is initialized | ||
| 15 | virtual void OnInit() = 0; | ||
| 16 | |||
| 17 | // When the controller is released | ||
| 18 | virtual void OnRelease() = 0; | ||
| 19 | |||
| 20 | // When the controller is requesting an update for the shared memory | ||
| 21 | virtual void OnUpdate(u8* data, size_t size) = 0; | ||
| 22 | |||
| 23 | // Called when input devices should be loaded | ||
| 24 | virtual void OnLoadInputDevices() = 0; | ||
| 25 | |||
| 26 | void ActivateController(); | ||
| 27 | |||
| 28 | void DeactivateController(); | ||
| 29 | |||
| 30 | bool IsControllerActivated() const; | ||
| 31 | |||
| 32 | protected: | ||
| 33 | bool is_activated{false}; | ||
| 34 | |||
| 35 | struct CommonHeader { | ||
| 36 | s64_le timestamp; | ||
| 37 | s64_le total_entry_count; | ||
| 38 | s64_le last_entry_index; | ||
| 39 | s64_le entry_count; | ||
| 40 | }; | ||
| 41 | static_assert(sizeof(CommonHeader) == 0x20, "CommonHeader is an invalid size"); | ||
| 42 | }; | ||
| 43 | }; // 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 new file mode 100644 index 000000000..04799b233 --- /dev/null +++ b/src/core/hle/service/hid/controllers/debug_pad.cpp | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/common_types.h" | ||
| 6 | #include "common/swap.h" | ||
| 7 | #include "core/core_timing.h" | ||
| 8 | #include "core/hle/service/hid/controllers/debug_pad.h" | ||
| 9 | |||
| 10 | namespace Service::HID { | ||
| 11 | void Controller_DebugPad::OnInit() {} | ||
| 12 | void Controller_DebugPad::OnRelease() {} | ||
| 13 | void Controller_DebugPad::OnUpdate(u8* data, size_t size) { | ||
| 14 | shared_memory.header.timestamp = CoreTiming::GetTicks(); | ||
| 15 | shared_memory.header.total_entry_count = 17; | ||
| 16 | |||
| 17 | if (!IsControllerActivated()) { | ||
| 18 | shared_memory.header.entry_count = 0; | ||
| 19 | shared_memory.header.last_entry_index = 0; | ||
| 20 | return; | ||
| 21 | } | ||
| 22 | shared_memory.header.entry_count = 16; | ||
| 23 | |||
| 24 | auto& last_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; | ||
| 25 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; | ||
| 26 | auto& cur_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; | ||
| 27 | |||
| 28 | cur_entry.sampling_number = last_entry.sampling_number + 1; | ||
| 29 | cur_entry.sampling_number2 = cur_entry.sampling_number; | ||
| 30 | // TODO(ogniK): Update debug pad states | ||
| 31 | |||
| 32 | std::memcpy(data, &shared_memory, sizeof(SharedMemory)); | ||
| 33 | } | ||
| 34 | void Controller_DebugPad::OnLoadInputDevices() {} | ||
| 35 | }; // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/debug_pad.h b/src/core/hle/service/hid/controllers/debug_pad.h new file mode 100644 index 000000000..fc6f99a0b --- /dev/null +++ b/src/core/hle/service/hid/controllers/debug_pad.h | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | #include <array> | ||
| 7 | #include "common/common_funcs.h" | ||
| 8 | #include "common/common_types.h" | ||
| 9 | #include "common/swap.h" | ||
| 10 | #include "core/hle/service/hid/controllers/controller_base.h" | ||
| 11 | |||
| 12 | namespace Service::HID { | ||
| 13 | class Controller_DebugPad final : public ControllerBase { | ||
| 14 | public: | ||
| 15 | Controller_DebugPad() = default; | ||
| 16 | |||
| 17 | // Called when the controller is initialized | ||
| 18 | void OnInit() override; | ||
| 19 | |||
| 20 | // When the controller is released | ||
| 21 | void OnRelease() override; | ||
| 22 | |||
| 23 | // When the controller is requesting an update for the shared memory | ||
| 24 | void OnUpdate(u8* data, size_t size) override; | ||
| 25 | |||
| 26 | // Called when input devices should be loaded | ||
| 27 | void OnLoadInputDevices() override; | ||
| 28 | |||
| 29 | private: | ||
| 30 | struct AnalogStick { | ||
| 31 | s32_le x; | ||
| 32 | s32_le y; | ||
| 33 | }; | ||
| 34 | static_assert(sizeof(AnalogStick) == 0x8); | ||
| 35 | |||
| 36 | struct PadStates { | ||
| 37 | s64_le sampling_number; | ||
| 38 | s64_le sampling_number2; | ||
| 39 | u32_le attribute; | ||
| 40 | u32_le button_state; | ||
| 41 | AnalogStick r_stick; | ||
| 42 | AnalogStick l_stick; | ||
| 43 | }; | ||
| 44 | static_assert(sizeof(PadStates) == 0x28, "PadStates is an invalid state"); | ||
| 45 | |||
| 46 | struct SharedMemory { | ||
| 47 | CommonHeader header; | ||
| 48 | std::array<PadStates, 17> pad_states; | ||
| 49 | INSERT_PADDING_BYTES(0x138); | ||
| 50 | }; | ||
| 51 | static_assert(sizeof(SharedMemory) == 0x400, "SharedMemory is an invalid size"); | ||
| 52 | SharedMemory shared_memory{}; | ||
| 53 | }; | ||
| 54 | }; // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/core/hle/service/hid/controllers/gesture.cpp new file mode 100644 index 000000000..851ea66f3 --- /dev/null +++ b/src/core/hle/service/hid/controllers/gesture.cpp | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/common_types.h" | ||
| 6 | #include "common/swap.h" | ||
| 7 | #include "core/core_timing.h" | ||
| 8 | #include "core/hle/service/hid/controllers/gesture.h" | ||
| 9 | |||
| 10 | namespace Service::HID { | ||
| 11 | constexpr size_t SHARED_MEMORY_OFFSET = 0x3BA00; | ||
| 12 | void Controller_Gesture::OnInit() {} | ||
| 13 | void Controller_Gesture::OnRelease() {} | ||
| 14 | void Controller_Gesture::OnUpdate(u8* data, size_t size) { | ||
| 15 | shared_memory.header.timestamp = CoreTiming::GetTicks(); | ||
| 16 | shared_memory.header.total_entry_count = 17; | ||
| 17 | |||
| 18 | if (!IsControllerActivated()) { | ||
| 19 | shared_memory.header.entry_count = 0; | ||
| 20 | shared_memory.header.last_entry_index = 0; | ||
| 21 | return; | ||
| 22 | } | ||
| 23 | shared_memory.header.entry_count = 16; | ||
| 24 | |||
| 25 | auto& last_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; | ||
| 26 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; | ||
| 27 | auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; | ||
| 28 | |||
| 29 | cur_entry.sampling_number = last_entry.sampling_number + 1; | ||
| 30 | cur_entry.sampling_number2 = cur_entry.sampling_number; | ||
| 31 | // TODO(ogniK): Update gesture states | ||
| 32 | |||
| 33 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); | ||
| 34 | } | ||
| 35 | void Controller_Gesture::OnLoadInputDevices() {} | ||
| 36 | }; // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/gesture.h b/src/core/hle/service/hid/controllers/gesture.h new file mode 100644 index 000000000..f46819829 --- /dev/null +++ b/src/core/hle/service/hid/controllers/gesture.h | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | #include <array> | ||
| 7 | #include "common/common_types.h" | ||
| 8 | #include "common/swap.h" | ||
| 9 | #include "core/hle/service/hid/controllers/controller_base.h" | ||
| 10 | |||
| 11 | namespace Service::HID { | ||
| 12 | class Controller_Gesture final : public ControllerBase { | ||
| 13 | public: | ||
| 14 | Controller_Gesture() = default; | ||
| 15 | |||
| 16 | // Called when the controller is initialized | ||
| 17 | void OnInit() override; | ||
| 18 | |||
| 19 | // When the controller is released | ||
| 20 | void OnRelease() override; | ||
| 21 | |||
| 22 | // When the controller is requesting an update for the shared memory | ||
| 23 | void OnUpdate(u8* data, size_t size) override; | ||
| 24 | |||
| 25 | // Called when input devices should be loaded | ||
| 26 | void OnLoadInputDevices() override; | ||
| 27 | |||
| 28 | private: | ||
| 29 | struct Locations { | ||
| 30 | s32_le x; | ||
| 31 | s32_le y; | ||
| 32 | }; | ||
| 33 | |||
| 34 | struct GestureState { | ||
| 35 | s64_le sampling_number; | ||
| 36 | s64_le sampling_number2; | ||
| 37 | |||
| 38 | s64_le detection_count; | ||
| 39 | s32_le type; | ||
| 40 | s32_le dir; | ||
| 41 | s32_le x; | ||
| 42 | s32_le y; | ||
| 43 | s32_le delta_x; | ||
| 44 | s32_le delta_y; | ||
| 45 | f32 vel_x; | ||
| 46 | f32 vel_y; | ||
| 47 | s32_le attributes; | ||
| 48 | f32 scale; | ||
| 49 | f32 rotation; | ||
| 50 | s32_le location_count; | ||
| 51 | std::array<Locations, 4> locations{}; | ||
| 52 | }; | ||
| 53 | static_assert(sizeof(GestureState) == 0x68, "GestureState is an invalid size"); | ||
| 54 | |||
| 55 | struct SharedMemory { | ||
| 56 | CommonHeader header; | ||
| 57 | std::array<GestureState, 17> gesture_states; | ||
| 58 | }; | ||
| 59 | SharedMemory shared_memory{}; | ||
| 60 | }; | ||
| 61 | }; // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/keyboard.cpp b/src/core/hle/service/hid/controllers/keyboard.cpp new file mode 100644 index 000000000..27c39ad08 --- /dev/null +++ b/src/core/hle/service/hid/controllers/keyboard.cpp | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/common_types.h" | ||
| 6 | #include "common/swap.h" | ||
| 7 | #include "core/core_timing.h" | ||
| 8 | #include "core/hle/service/hid/controllers/keyboard.h" | ||
| 9 | |||
| 10 | namespace Service::HID { | ||
| 11 | constexpr size_t SHARED_MEMORY_OFFSET = 0x3800; | ||
| 12 | void Controller_Keyboard::OnInit() {} | ||
| 13 | void Controller_Keyboard::OnRelease() {} | ||
| 14 | void Controller_Keyboard::OnUpdate(u8* data, size_t size) { | ||
| 15 | shared_memory.header.timestamp = CoreTiming::GetTicks(); | ||
| 16 | shared_memory.header.total_entry_count = 17; | ||
| 17 | |||
| 18 | if (!IsControllerActivated()) { | ||
| 19 | shared_memory.header.entry_count = 0; | ||
| 20 | shared_memory.header.last_entry_index = 0; | ||
| 21 | return; | ||
| 22 | } | ||
| 23 | shared_memory.header.entry_count = 16; | ||
| 24 | |||
| 25 | auto& last_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; | ||
| 26 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; | ||
| 27 | auto& cur_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; | ||
| 28 | |||
| 29 | cur_entry.sampling_number = last_entry.sampling_number + 1; | ||
| 30 | cur_entry.sampling_number2 = cur_entry.sampling_number; | ||
| 31 | // TODO(ogniK): Update keyboard states | ||
| 32 | |||
| 33 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); | ||
| 34 | } | ||
| 35 | void Controller_Keyboard::OnLoadInputDevices() {} | ||
| 36 | }; // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/keyboard.h b/src/core/hle/service/hid/controllers/keyboard.h new file mode 100644 index 000000000..0463e1619 --- /dev/null +++ b/src/core/hle/service/hid/controllers/keyboard.h | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | #include <array> | ||
| 7 | #include "common/common_funcs.h" | ||
| 8 | #include "common/common_types.h" | ||
| 9 | #include "common/swap.h" | ||
| 10 | #include "core/hle/service/hid/controllers/controller_base.h" | ||
| 11 | |||
| 12 | namespace Service::HID { | ||
| 13 | class Controller_Keyboard final : public ControllerBase { | ||
| 14 | public: | ||
| 15 | Controller_Keyboard() = default; | ||
| 16 | |||
| 17 | // Called when the controller is initialized | ||
| 18 | void OnInit() override; | ||
| 19 | |||
| 20 | // When the controller is released | ||
| 21 | void OnRelease() override; | ||
| 22 | |||
| 23 | // When the controller is requesting an update for the shared memory | ||
| 24 | void OnUpdate(u8* data, size_t size) override; | ||
| 25 | |||
| 26 | // Called when input devices should be loaded | ||
| 27 | void OnLoadInputDevices() override; | ||
| 28 | |||
| 29 | private: | ||
| 30 | struct KeyboardState { | ||
| 31 | s64_le sampling_number; | ||
| 32 | s64_le sampling_number2; | ||
| 33 | |||
| 34 | s32_le modifier; | ||
| 35 | s32_le attribute; | ||
| 36 | std::array<u8, 32> key{}; | ||
| 37 | }; | ||
| 38 | static_assert(sizeof(KeyboardState) == 0x38, "KeyboardState is an invalid size"); | ||
| 39 | |||
| 40 | struct SharedMemory { | ||
| 41 | CommonHeader header; | ||
| 42 | std::array<KeyboardState, 17> pad_states; | ||
| 43 | INSERT_PADDING_BYTES(0x28); | ||
| 44 | }; | ||
| 45 | static_assert(sizeof(SharedMemory) == 0x400, "SharedMemory is an invalid size"); | ||
| 46 | SharedMemory shared_memory{}; | ||
| 47 | }; | ||
| 48 | }; // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/mouse.cpp b/src/core/hle/service/hid/controllers/mouse.cpp new file mode 100644 index 000000000..df30239e2 --- /dev/null +++ b/src/core/hle/service/hid/controllers/mouse.cpp | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/common_types.h" | ||
| 6 | #include "common/swap.h" | ||
| 7 | #include "core/core_timing.h" | ||
| 8 | #include "core/hle/service/hid/controllers/mouse.h" | ||
| 9 | |||
| 10 | namespace Service::HID { | ||
| 11 | constexpr size_t SHARED_MEMORY_OFFSET = 0x3400; | ||
| 12 | void Controller_Mouse::OnInit() {} | ||
| 13 | void Controller_Mouse::OnRelease() {} | ||
| 14 | void Controller_Mouse::OnUpdate(u8* data, size_t size) { | ||
| 15 | shared_memory.header.timestamp = CoreTiming::GetTicks(); | ||
| 16 | shared_memory.header.total_entry_count = 17; | ||
| 17 | |||
| 18 | if (!IsControllerActivated()) { | ||
| 19 | shared_memory.header.entry_count = 0; | ||
| 20 | shared_memory.header.last_entry_index = 0; | ||
| 21 | return; | ||
| 22 | } | ||
| 23 | shared_memory.header.entry_count = 16; | ||
| 24 | |||
| 25 | auto& last_entry = shared_memory.mouse_states[shared_memory.header.last_entry_index]; | ||
| 26 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; | ||
| 27 | auto& cur_entry = shared_memory.mouse_states[shared_memory.header.last_entry_index]; | ||
| 28 | |||
| 29 | cur_entry.sampling_number = last_entry.sampling_number + 1; | ||
| 30 | cur_entry.sampling_number2 = cur_entry.sampling_number; | ||
| 31 | // TODO(ogniK): Update mouse states | ||
| 32 | |||
| 33 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); | ||
| 34 | } | ||
| 35 | void Controller_Mouse::OnLoadInputDevices() {} | ||
| 36 | }; // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/mouse.h b/src/core/hle/service/hid/controllers/mouse.h new file mode 100644 index 000000000..0d7fd372d --- /dev/null +++ b/src/core/hle/service/hid/controllers/mouse.h | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | #include <array> | ||
| 7 | #include "common/common_types.h" | ||
| 8 | #include "common/swap.h" | ||
| 9 | #include "core/hle/service/hid/controllers/controller_base.h" | ||
| 10 | |||
| 11 | namespace Service::HID { | ||
| 12 | class Controller_Mouse final : public ControllerBase { | ||
| 13 | public: | ||
| 14 | Controller_Mouse() = default; | ||
| 15 | |||
| 16 | // Called when the controller is initialized | ||
| 17 | void OnInit() override; | ||
| 18 | |||
| 19 | // When the controller is released | ||
| 20 | void OnRelease() override; | ||
| 21 | |||
| 22 | // When the controller is requesting an update for the shared memory | ||
| 23 | void OnUpdate(u8* data, size_t size) override; | ||
| 24 | |||
| 25 | // Called when input devices should be loaded | ||
| 26 | void OnLoadInputDevices() override; | ||
| 27 | |||
| 28 | private: | ||
| 29 | struct MouseState { | ||
| 30 | s64_le sampling_number; | ||
| 31 | s64_le sampling_number2; | ||
| 32 | s32_le x; | ||
| 33 | s32_le y; | ||
| 34 | s32_le delta_x; | ||
| 35 | s32_le delta_y; | ||
| 36 | s32_le mouse_wheel; | ||
| 37 | s32_le button; | ||
| 38 | s32_le attribute; | ||
| 39 | }; | ||
| 40 | static_assert(sizeof(MouseState) == 0x30, "MouseState is an invalid size"); | ||
| 41 | |||
| 42 | struct SharedMemory { | ||
| 43 | CommonHeader header; | ||
| 44 | std::array<MouseState, 17> mouse_states; | ||
| 45 | }; | ||
| 46 | SharedMemory shared_memory{}; | ||
| 47 | }; | ||
| 48 | }; // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp new file mode 100644 index 000000000..a53687b91 --- /dev/null +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -0,0 +1,336 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | #include <array> | ||
| 7 | #include "common/assert.h" | ||
| 8 | #include "common/bit_field.h" | ||
| 9 | #include "common/common_types.h" | ||
| 10 | #include "common/swap.h" | ||
| 11 | #include "core/core.h" | ||
| 12 | #include "core/core_timing.h" | ||
| 13 | #include "core/frontend/input.h" | ||
| 14 | #include "core/hle/kernel/event.h" | ||
| 15 | #include "core/hle/service/hid/controllers/npad.h" | ||
| 16 | #include "core/settings.h" | ||
| 17 | |||
| 18 | namespace Service::HID { | ||
| 19 | constexpr u32 JOYCON_BODY_NEON_RED = 0xFF3C28; | ||
| 20 | constexpr u32 JOYCON_BUTTONS_NEON_RED = 0x1E0A0A; | ||
| 21 | constexpr u32 JOYCON_BODY_NEON_BLUE = 0x0AB9E6; | ||
| 22 | constexpr u32 JOYCON_BUTTONS_NEON_BLUE = 0x001E1E; | ||
| 23 | constexpr s32 HID_JOYSTICK_MAX = 0x7fff; | ||
| 24 | constexpr s32 HID_JOYSTICK_MIN = -0x7fff; | ||
| 25 | constexpr size_t NPAD_OFFSET = 0x9A00; | ||
| 26 | constexpr size_t MAX_CONTROLLER_COUNT = 9; | ||
| 27 | |||
| 28 | enum class JoystickId : size_t { Joystick_Left, Joystick_Right }; | ||
| 29 | constexpr std::array<u32, MAX_CONTROLLER_COUNT> NPAD_ID_LIST{0, 1, 2, 3, 4, 5, 6, 7, 32}; | ||
| 30 | size_t CONTROLLER_COUNT{}; | ||
| 31 | std::array<Controller_NPad::NPadControllerType, MAX_CONTROLLER_COUNT> CONNECTED_CONTROLLERS{}; | ||
| 32 | |||
| 33 | void Controller_NPad::InitNewlyAddedControler(size_t controller_idx) { | ||
| 34 | const auto controller_type = CONNECTED_CONTROLLERS[controller_idx]; | ||
| 35 | auto& controller = shared_memory_entries[controller_idx]; | ||
| 36 | if (controller_type == NPadControllerType::None) { | ||
| 37 | return; | ||
| 38 | } | ||
| 39 | controller.joy_styles.raw = 0; // Zero out | ||
| 40 | controller.device_type.raw = 0; | ||
| 41 | switch (controller_type) { | ||
| 42 | case NPadControllerType::Handheld: | ||
| 43 | controller.joy_styles.handheld.Assign(1); | ||
| 44 | controller.device_type.handheld.Assign(1); | ||
| 45 | controller.pad_assignment = NPadAssignments::Dual; | ||
| 46 | break; | ||
| 47 | case NPadControllerType::JoyLeft: | ||
| 48 | controller.joy_styles.joycon_left.Assign(1); | ||
| 49 | controller.device_type.joycon_left.Assign(1); | ||
| 50 | controller.pad_assignment = NPadAssignments::Dual; | ||
| 51 | break; | ||
| 52 | case NPadControllerType::JoyRight: | ||
| 53 | controller.joy_styles.joycon_right.Assign(1); | ||
| 54 | controller.device_type.joycon_right.Assign(1); | ||
| 55 | controller.pad_assignment = NPadAssignments::Dual; | ||
| 56 | break; | ||
| 57 | case NPadControllerType::Tabletop: | ||
| 58 | UNIMPLEMENTED_MSG("Tabletop is not implemented"); | ||
| 59 | break; | ||
| 60 | case NPadControllerType::Pokeball: | ||
| 61 | controller.joy_styles.pokeball.Assign(1); | ||
| 62 | controller.device_type.pokeball.Assign(1); | ||
| 63 | controller.pad_assignment = NPadAssignments::Single; | ||
| 64 | break; | ||
| 65 | case NPadControllerType::ProController: | ||
| 66 | controller.joy_styles.pro_controller.Assign(1); | ||
| 67 | controller.device_type.pro_controller.Assign(1); | ||
| 68 | controller.pad_assignment = NPadAssignments::Single; | ||
| 69 | break; | ||
| 70 | } | ||
| 71 | |||
| 72 | controller.single_color_error = ColorReadError::ReadOk; | ||
| 73 | controller.single_color.body_color = 0; | ||
| 74 | controller.single_color.button_color = 0; | ||
| 75 | |||
| 76 | controller.dual_color_error = ColorReadError::ReadOk; | ||
| 77 | controller.left_color.body_color = JOYCON_BODY_NEON_BLUE; | ||
| 78 | controller.left_color.button_color = JOYCON_BUTTONS_NEON_BLUE; | ||
| 79 | controller.right_color.body_color = JOYCON_BODY_NEON_RED; | ||
| 80 | controller.right_color.button_color = JOYCON_BUTTONS_NEON_RED; | ||
| 81 | |||
| 82 | controller.properties.is_verticle.Assign(1); // TODO(ogniK): Swap joycons orientations | ||
| 83 | } | ||
| 84 | |||
| 85 | void Controller_NPad::OnInit() { | ||
| 86 | auto& kernel = Core::System::GetInstance().Kernel(); | ||
| 87 | styleset_changed_event = | ||
| 88 | Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "npad:NpadStyleSetChanged"); | ||
| 89 | |||
| 90 | if (!IsControllerActivated()) | ||
| 91 | return; | ||
| 92 | size_t controller{}; | ||
| 93 | supported_npad_id_types.resize(NPAD_ID_LIST.size()); | ||
| 94 | if (style.raw == 0) { | ||
| 95 | // We want to support all controllers | ||
| 96 | style.handheld.Assign(1); | ||
| 97 | style.joycon_left.Assign(1); | ||
| 98 | style.joycon_right.Assign(1); | ||
| 99 | style.joycon_dual.Assign(1); | ||
| 100 | style.pro_controller.Assign(1); | ||
| 101 | style.pokeball.Assign(1); | ||
| 102 | } | ||
| 103 | std::memcpy(supported_npad_id_types.data(), NPAD_ID_LIST.data(), | ||
| 104 | NPAD_ID_LIST.size() * sizeof(u32)); | ||
| 105 | if (CONTROLLER_COUNT == 0) { | ||
| 106 | AddNewController(NPadControllerType::Handheld); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | void Controller_NPad::OnLoadInputDevices() { | ||
| 111 | std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, | ||
| 112 | Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END, | ||
| 113 | buttons.begin(), Input::CreateDevice<Input::ButtonDevice>); | ||
| 114 | std::transform(Settings::values.analogs.begin() + Settings::NativeAnalog::STICK_HID_BEGIN, | ||
| 115 | Settings::values.analogs.begin() + Settings::NativeAnalog::STICK_HID_END, | ||
| 116 | sticks.begin(), Input::CreateDevice<Input::AnalogDevice>); | ||
| 117 | } | ||
| 118 | |||
| 119 | void Controller_NPad::OnRelease() {} | ||
| 120 | |||
| 121 | void Controller_NPad::OnUpdate(u8* data, size_t data_len) { | ||
| 122 | if (!IsControllerActivated()) | ||
| 123 | return; | ||
| 124 | for (size_t i = 0; i < shared_memory_entries.size(); i++) { | ||
| 125 | auto& npad = shared_memory_entries[i]; | ||
| 126 | const std::array<NPadGeneric*, 7> controller_npads{&npad.main_controller_states, | ||
| 127 | &npad.handheld_states, | ||
| 128 | &npad.dual_states, | ||
| 129 | &npad.left_joy_states, | ||
| 130 | &npad.right_joy_states, | ||
| 131 | &npad.pokeball_states, | ||
| 132 | &npad.libnx}; | ||
| 133 | |||
| 134 | for (auto main_controller : controller_npads) { | ||
| 135 | main_controller->common.entry_count = 16; | ||
| 136 | main_controller->common.total_entry_count = 17; | ||
| 137 | |||
| 138 | auto& last_entry = main_controller->npad[main_controller->common.last_entry_index]; | ||
| 139 | |||
| 140 | main_controller->common.timestamp = CoreTiming::GetTicks(); | ||
| 141 | main_controller->common.last_entry_index = | ||
| 142 | (main_controller->common.last_entry_index + 1) % 17; | ||
| 143 | |||
| 144 | auto& cur_entry = main_controller->npad[main_controller->common.last_entry_index]; | ||
| 145 | |||
| 146 | cur_entry.timestamp = last_entry.timestamp + 1; | ||
| 147 | cur_entry.timestamp2 = cur_entry.timestamp; | ||
| 148 | } | ||
| 149 | |||
| 150 | if (CONNECTED_CONTROLLERS[i] == NPadControllerType::None) { | ||
| 151 | continue; | ||
| 152 | } | ||
| 153 | |||
| 154 | const auto& controller_type = CONNECTED_CONTROLLERS[i]; | ||
| 155 | |||
| 156 | // Pad states | ||
| 157 | auto pad_state = ControllerPadState{}; | ||
| 158 | using namespace Settings::NativeButton; | ||
| 159 | pad_state.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 160 | pad_state.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 161 | pad_state.x.Assign(buttons[X - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 162 | pad_state.y.Assign(buttons[Y - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 163 | pad_state.l_stick.Assign(buttons[LStick - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 164 | pad_state.r_stick.Assign(buttons[RStick - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 165 | pad_state.l.Assign(buttons[L - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 166 | pad_state.r.Assign(buttons[R - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 167 | pad_state.zl.Assign(buttons[ZL - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 168 | pad_state.zr.Assign(buttons[ZR - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 169 | pad_state.plus.Assign(buttons[Plus - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 170 | pad_state.minus.Assign(buttons[Minus - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 171 | |||
| 172 | pad_state.dleft.Assign(buttons[DLeft - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 173 | pad_state.dup.Assign(buttons[DUp - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 174 | pad_state.dright.Assign(buttons[DRight - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 175 | pad_state.ddown.Assign(buttons[DDown - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 176 | |||
| 177 | pad_state.lstickleft.Assign(buttons[LStick_Left - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 178 | pad_state.lstickup.Assign(buttons[LStick_Up - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 179 | pad_state.lstickright.Assign(buttons[LStick_Right - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 180 | pad_state.lstickdown.Assign(buttons[LStick_Down - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 181 | |||
| 182 | pad_state.rstickleft.Assign(buttons[RStick_Left - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 183 | pad_state.rstickup.Assign(buttons[RStick_Up - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 184 | pad_state.rstickright.Assign(buttons[RStick_Right - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 185 | pad_state.rstickdown.Assign(buttons[RStick_Down - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 186 | |||
| 187 | pad_state.sl.Assign(buttons[SL - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 188 | pad_state.sr.Assign(buttons[SR - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 189 | |||
| 190 | AnalogPosition lstick_entry{}; | ||
| 191 | AnalogPosition rstick_entry{}; | ||
| 192 | |||
| 193 | const auto [stick_l_x_f, stick_l_y_f] = | ||
| 194 | sticks[static_cast<size_t>(JoystickId::Joystick_Left)]->GetStatus(); | ||
| 195 | const auto [stick_r_x_f, stick_r_y_f] = | ||
| 196 | sticks[static_cast<size_t>(JoystickId::Joystick_Right)]->GetStatus(); | ||
| 197 | lstick_entry.x = static_cast<s32>(stick_l_x_f * HID_JOYSTICK_MAX); | ||
| 198 | lstick_entry.y = static_cast<s32>(stick_l_y_f * HID_JOYSTICK_MAX); | ||
| 199 | rstick_entry.x = static_cast<s32>(stick_r_x_f * HID_JOYSTICK_MAX); | ||
| 200 | rstick_entry.y = static_cast<s32>(stick_r_y_f * HID_JOYSTICK_MAX); | ||
| 201 | |||
| 202 | auto& main_controller = | ||
| 203 | npad.main_controller_states.npad[npad.main_controller_states.common.last_entry_index]; | ||
| 204 | auto& handheld_entry = | ||
| 205 | npad.handheld_states.npad[npad.handheld_states.common.last_entry_index]; | ||
| 206 | auto& dual_entry = npad.dual_states.npad[npad.dual_states.common.last_entry_index]; | ||
| 207 | auto& left_entry = npad.left_joy_states.npad[npad.left_joy_states.common.last_entry_index]; | ||
| 208 | auto& right_entry = | ||
| 209 | npad.right_joy_states.npad[npad.right_joy_states.common.last_entry_index]; | ||
| 210 | auto& pokeball_entry = | ||
| 211 | npad.pokeball_states.npad[npad.pokeball_states.common.last_entry_index]; | ||
| 212 | auto& libnx_entry = npad.libnx.npad[npad.libnx.common.last_entry_index]; | ||
| 213 | |||
| 214 | if (hold_type == NpadHoldType::Horizontal) { | ||
| 215 | // TODO(ogniK): Remap buttons for different orientations | ||
| 216 | } | ||
| 217 | |||
| 218 | switch (controller_type) { | ||
| 219 | case NPadControllerType::Handheld: | ||
| 220 | handheld_entry.connection_status.IsConnected.Assign(1); | ||
| 221 | handheld_entry.connection_status.IsWired.Assign(1); | ||
| 222 | handheld_entry.pad_states.raw = pad_state.raw; | ||
| 223 | handheld_entry.lstick = lstick_entry; | ||
| 224 | handheld_entry.rstick = rstick_entry; | ||
| 225 | break; | ||
| 226 | case NPadControllerType::JoyLeft: | ||
| 227 | left_entry.connection_status.IsConnected.Assign(1); | ||
| 228 | left_entry.pad_states.raw = pad_state.raw; | ||
| 229 | left_entry.lstick = lstick_entry; | ||
| 230 | left_entry.rstick = rstick_entry; | ||
| 231 | break; | ||
| 232 | case NPadControllerType::JoyRight: | ||
| 233 | right_entry.connection_status.IsConnected.Assign(1); | ||
| 234 | right_entry.pad_states.raw = pad_state.raw; | ||
| 235 | right_entry.lstick = lstick_entry; | ||
| 236 | right_entry.rstick = rstick_entry; | ||
| 237 | break; | ||
| 238 | case NPadControllerType::Tabletop: | ||
| 239 | // TODO(ogniK): Figure out how to add proper tabletop support | ||
| 240 | dual_entry.pad_states.raw = pad_state.raw; | ||
| 241 | dual_entry.lstick = lstick_entry; | ||
| 242 | dual_entry.rstick = rstick_entry; | ||
| 243 | dual_entry.connection_status.IsConnected.Assign(1); | ||
| 244 | break; | ||
| 245 | case NPadControllerType::Pokeball: | ||
| 246 | pokeball_entry.connection_status.IsConnected.Assign(1); | ||
| 247 | pokeball_entry.connection_status.IsWired.Assign(1); | ||
| 248 | |||
| 249 | pokeball_entry.pad_states.raw = pad_state.raw; | ||
| 250 | pokeball_entry.lstick = lstick_entry; | ||
| 251 | pokeball_entry.rstick = rstick_entry; | ||
| 252 | break; | ||
| 253 | case NPadControllerType::ProController: | ||
| 254 | main_controller.pad_states.raw = pad_state.raw; | ||
| 255 | main_controller.lstick = lstick_entry; | ||
| 256 | main_controller.rstick = rstick_entry; | ||
| 257 | main_controller.connection_status.IsConnected.Assign(1); | ||
| 258 | main_controller.connection_status.IsWired.Assign(1); | ||
| 259 | break; | ||
| 260 | } | ||
| 261 | |||
| 262 | // LibNX exclusively uses this section, so we always update it since LibNX doesn't activate | ||
| 263 | // any controllers. | ||
| 264 | libnx_entry.connection_status.IsConnected.Assign(1); | ||
| 265 | libnx_entry.connection_status.IsWired.Assign(1); | ||
| 266 | libnx_entry.pad_states.raw = pad_state.raw; | ||
| 267 | libnx_entry.lstick = lstick_entry; | ||
| 268 | libnx_entry.rstick = rstick_entry; | ||
| 269 | } | ||
| 270 | std::memcpy(data + NPAD_OFFSET, shared_memory_entries.data(), | ||
| 271 | shared_memory_entries.size() * sizeof(NPadEntry)); | ||
| 272 | } | ||
| 273 | |||
| 274 | void Controller_NPad::SetSupportedStyleSet(NPadType style_set) { | ||
| 275 | style.raw = style_set.raw; | ||
| 276 | } | ||
| 277 | |||
| 278 | Controller_NPad::NPadType Controller_NPad::GetSupportedStyleSet() const { | ||
| 279 | return style; | ||
| 280 | } | ||
| 281 | |||
| 282 | void Controller_NPad::SetSupportedNPadIdTypes(u8* data, size_t length) { | ||
| 283 | ASSERT(length > 0 && (length % sizeof(u32)) == 0); | ||
| 284 | supported_npad_id_types.resize(length / 4); | ||
| 285 | std::memcpy(supported_npad_id_types.data(), data, length); | ||
| 286 | } | ||
| 287 | |||
| 288 | void Controller_NPad::GetSupportedNpadIdTypes(u32* data, size_t max_length) { | ||
| 289 | ASSERT(max_length < supported_npad_id_types.size()); | ||
| 290 | std::memcpy(data, supported_npad_id_types.data(), supported_npad_id_types.size()); | ||
| 291 | } | ||
| 292 | |||
| 293 | size_t Controller_NPad::GetSupportedNPadIdTypesSize() const { | ||
| 294 | return supported_npad_id_types.size(); | ||
| 295 | } | ||
| 296 | |||
| 297 | void Controller_NPad::SetHoldType(NpadHoldType joy_hold_type) { | ||
| 298 | hold_type = joy_hold_type; | ||
| 299 | } | ||
| 300 | Controller_NPad::NpadHoldType Controller_NPad::GetHoldType() const { | ||
| 301 | return hold_type; | ||
| 302 | } | ||
| 303 | |||
| 304 | void Controller_NPad::SetNpadMode(u32 npad_id, NPadAssignments assignment_mode) { | ||
| 305 | ASSERT(npad_id < shared_memory_entries.size()); | ||
| 306 | shared_memory_entries[npad_id].pad_assignment = assignment_mode; | ||
| 307 | } | ||
| 308 | |||
| 309 | void Controller_NPad::VibrateController(const std::vector<u32>& controller_ids, | ||
| 310 | const std::vector<Vibration>& vibrations) { | ||
| 311 | for (size_t i = 0; i < controller_ids.size(); i++) { | ||
| 312 | if (i >= CONTROLLER_COUNT) { | ||
| 313 | continue; | ||
| 314 | } | ||
| 315 | // TODO(ogniK): Vibrate the physical controller | ||
| 316 | } | ||
| 317 | LOG_WARNING(Service_HID, "(STUBBED) called"); | ||
| 318 | last_processed_vibration = vibrations.back(); | ||
| 319 | } | ||
| 320 | |||
| 321 | Kernel::SharedPtr<Kernel::Event> Controller_NPad::GetStyleSetChangedEvent() const { | ||
| 322 | return styleset_changed_event; | ||
| 323 | } | ||
| 324 | |||
| 325 | Controller_NPad::Vibration Controller_NPad::GetLastVibration() const { | ||
| 326 | return last_processed_vibration; | ||
| 327 | } | ||
| 328 | void Controller_NPad::AddNewController(NPadControllerType controller) { | ||
| 329 | if (CONTROLLER_COUNT >= MAX_CONTROLLER_COUNT) { | ||
| 330 | LOG_ERROR(Service_HID, "Cannot connect any more controllers!"); | ||
| 331 | return; | ||
| 332 | } | ||
| 333 | CONNECTED_CONTROLLERS[CONTROLLER_COUNT] = controller; | ||
| 334 | InitNewlyAddedControler(CONTROLLER_COUNT++); | ||
| 335 | } | ||
| 336 | }; // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h new file mode 100644 index 000000000..e57b67da4 --- /dev/null +++ b/src/core/hle/service/hid/controllers/npad.h | |||
| @@ -0,0 +1,249 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | #include <array> | ||
| 7 | #include "common/common_types.h" | ||
| 8 | #include "core/frontend/input.h" | ||
| 9 | #include "core/hle/service/hid/controllers/controller_base.h" | ||
| 10 | #include "core/settings.h" | ||
| 11 | |||
| 12 | namespace Service::HID { | ||
| 13 | |||
| 14 | class Controller_NPad final : public ControllerBase { | ||
| 15 | public: | ||
| 16 | Controller_NPad() = default; | ||
| 17 | |||
| 18 | // Called when the controller is initialized | ||
| 19 | void OnInit() override; | ||
| 20 | |||
| 21 | // When the controller is released | ||
| 22 | void OnRelease() override; | ||
| 23 | |||
| 24 | // When the controller is requesting an update for the shared memory | ||
| 25 | void OnUpdate(u8* data, size_t size) override; | ||
| 26 | |||
| 27 | // Called when input devices should be loaded | ||
| 28 | void OnLoadInputDevices() override; | ||
| 29 | |||
| 30 | struct NPadType { | ||
| 31 | union { | ||
| 32 | u32_le raw{}; | ||
| 33 | |||
| 34 | BitField<0, 1, u32_le> pro_controller; | ||
| 35 | BitField<1, 1, u32_le> handheld; | ||
| 36 | BitField<2, 1, u32_le> joycon_dual; | ||
| 37 | BitField<3, 1, u32_le> joycon_left; | ||
| 38 | BitField<4, 1, u32_le> joycon_right; | ||
| 39 | |||
| 40 | BitField<6, 1, u32_le> pokeball; // TODO(ogniK): Confirm when possible | ||
| 41 | }; | ||
| 42 | }; | ||
| 43 | static_assert(sizeof(NPadType) == 4, "NPadType is an invalid size"); | ||
| 44 | |||
| 45 | struct Vibration { | ||
| 46 | f32 amp_low; | ||
| 47 | f32 freq_low; | ||
| 48 | f32 amp_high; | ||
| 49 | f32 freq_high; | ||
| 50 | }; | ||
| 51 | static_assert(sizeof(Vibration) == 0x10, "Vibration is an invalid size"); | ||
| 52 | |||
| 53 | enum class NpadHoldType : u64 { | ||
| 54 | Vertical = 0, | ||
| 55 | Horizontal = 1, | ||
| 56 | }; | ||
| 57 | |||
| 58 | enum class NPadAssignments : u32_le { | ||
| 59 | Dual = 0, | ||
| 60 | Single = 1, | ||
| 61 | }; | ||
| 62 | |||
| 63 | enum class NPadControllerType { | ||
| 64 | None, | ||
| 65 | ProController, | ||
| 66 | Handheld, | ||
| 67 | JoyLeft, | ||
| 68 | JoyRight, | ||
| 69 | Tabletop, | ||
| 70 | Pokeball | ||
| 71 | }; | ||
| 72 | |||
| 73 | void SetSupportedStyleSet(NPadType style_set); | ||
| 74 | NPadType GetSupportedStyleSet() const; | ||
| 75 | |||
| 76 | void SetSupportedNPadIdTypes(u8* data, size_t length); | ||
| 77 | void GetSupportedNpadIdTypes(u32* data, size_t max_length); | ||
| 78 | size_t GetSupportedNPadIdTypesSize() const; | ||
| 79 | |||
| 80 | void SetHoldType(NpadHoldType joy_hold_type); | ||
| 81 | NpadHoldType GetHoldType() const; | ||
| 82 | |||
| 83 | void SetNpadMode(u32 npad_id, NPadAssignments assignment_mode); | ||
| 84 | |||
| 85 | void VibrateController(const std::vector<u32>& controller_ids, | ||
| 86 | const std::vector<Vibration>& vibrations); | ||
| 87 | |||
| 88 | Kernel::SharedPtr<Kernel::Event> GetStyleSetChangedEvent() const; | ||
| 89 | Vibration GetLastVibration() const; | ||
| 90 | |||
| 91 | void AddNewController(NPadControllerType controller); | ||
| 92 | |||
| 93 | private: | ||
| 94 | struct CommonHeader { | ||
| 95 | s64_le timestamp; | ||
| 96 | s64_le total_entry_count; | ||
| 97 | s64_le last_entry_index; | ||
| 98 | s64_le entry_count; | ||
| 99 | }; | ||
| 100 | static_assert(sizeof(CommonHeader) == 0x20, "CommonHeader is an invalid size"); | ||
| 101 | |||
| 102 | struct ControllerColor { | ||
| 103 | u32_le body_color; | ||
| 104 | u32_le button_color; | ||
| 105 | }; | ||
| 106 | static_assert(sizeof(ControllerColor) == 8, "ControllerColor is an invalid size"); | ||
| 107 | |||
| 108 | struct ControllerPadState { | ||
| 109 | union { | ||
| 110 | u64_le raw{}; | ||
| 111 | // Button states | ||
| 112 | BitField<0, 1, u64_le> a; | ||
| 113 | BitField<1, 1, u64_le> b; | ||
| 114 | BitField<2, 1, u64_le> x; | ||
| 115 | BitField<3, 1, u64_le> y; | ||
| 116 | BitField<4, 1, u64_le> l_stick; | ||
| 117 | BitField<5, 1, u64_le> r_stick; | ||
| 118 | BitField<6, 1, u64_le> l; | ||
| 119 | BitField<7, 1, u64_le> r; | ||
| 120 | BitField<8, 1, u64_le> zl; | ||
| 121 | BitField<9, 1, u64_le> zr; | ||
| 122 | BitField<10, 1, u64_le> plus; | ||
| 123 | BitField<11, 1, u64_le> minus; | ||
| 124 | |||
| 125 | // D-Pad | ||
| 126 | BitField<12, 1, u64_le> dleft; | ||
| 127 | BitField<13, 1, u64_le> dup; | ||
| 128 | BitField<14, 1, u64_le> dright; | ||
| 129 | BitField<15, 1, u64_le> ddown; | ||
| 130 | |||
| 131 | // Left JoyStick | ||
| 132 | BitField<16, 1, u64_le> lstickleft; | ||
| 133 | BitField<17, 1, u64_le> lstickup; | ||
| 134 | BitField<18, 1, u64_le> lstickright; | ||
| 135 | BitField<19, 1, u64_le> lstickdown; | ||
| 136 | |||
| 137 | // Right JoyStick | ||
| 138 | BitField<20, 1, u64_le> rstickleft; | ||
| 139 | BitField<21, 1, u64_le> rstickup; | ||
| 140 | BitField<22, 1, u64_le> rstickright; | ||
| 141 | BitField<23, 1, u64_le> rstickdown; | ||
| 142 | |||
| 143 | // Not always active? | ||
| 144 | BitField<24, 1, u64_le> sl; | ||
| 145 | BitField<25, 1, u64_le> sr; | ||
| 146 | }; | ||
| 147 | }; | ||
| 148 | static_assert(sizeof(ControllerPadState) == 8, "ControllerPadState is an invalid size"); | ||
| 149 | |||
| 150 | struct AnalogPosition { | ||
| 151 | s32_le x; | ||
| 152 | s32_le y; | ||
| 153 | }; | ||
| 154 | static_assert(sizeof(AnalogPosition) == 8, "AnalogPosition is an invalid size"); | ||
| 155 | |||
| 156 | struct ConnectionState { | ||
| 157 | union { | ||
| 158 | u32_le raw{}; | ||
| 159 | BitField<0, 1, u32_le> IsConnected; | ||
| 160 | BitField<1, 1, u32_le> IsWired; | ||
| 161 | }; | ||
| 162 | }; | ||
| 163 | static_assert(sizeof(ConnectionState) == 4, "ConnectionState is an invalid size"); | ||
| 164 | |||
| 165 | struct GenericStates { | ||
| 166 | s64_le timestamp; | ||
| 167 | s64_le timestamp2; | ||
| 168 | ControllerPadState pad_states; | ||
| 169 | AnalogPosition lstick; | ||
| 170 | AnalogPosition rstick; | ||
| 171 | ConnectionState connection_status; | ||
| 172 | }; | ||
| 173 | static_assert(sizeof(GenericStates) == 0x30, "NPadGenericStates is an invalid size"); | ||
| 174 | |||
| 175 | struct NPadGeneric { | ||
| 176 | CommonHeader common; | ||
| 177 | std::array<GenericStates, 17> npad; | ||
| 178 | }; | ||
| 179 | static_assert(sizeof(NPadGeneric) == 0x350, "NPadGeneric is an invalid size"); | ||
| 180 | |||
| 181 | enum class ColorReadError : u32_le { | ||
| 182 | ReadOk = 0, | ||
| 183 | ColorDoesntExist = 1, | ||
| 184 | NoController = 2, | ||
| 185 | }; | ||
| 186 | |||
| 187 | struct NPadProperties { | ||
| 188 | union { | ||
| 189 | s64_le raw{}; | ||
| 190 | BitField<11, 1, s64_le> is_verticle; | ||
| 191 | BitField<12, 1, s64_le> is_horizontal; | ||
| 192 | }; | ||
| 193 | }; | ||
| 194 | |||
| 195 | struct NPadDevice { | ||
| 196 | union { | ||
| 197 | u32_le raw{}; | ||
| 198 | BitField<0, 1, s32_le> pro_controller; | ||
| 199 | BitField<1, 1, s32_le> handheld; | ||
| 200 | BitField<2, 1, s32_le> handheld_left; | ||
| 201 | BitField<3, 1, s32_le> handheld_right; | ||
| 202 | BitField<4, 1, s32_le> joycon_left; | ||
| 203 | BitField<5, 1, s32_le> joycon_right; | ||
| 204 | BitField<6, 1, s32_le> pokeball; | ||
| 205 | }; | ||
| 206 | }; | ||
| 207 | |||
| 208 | struct NPadEntry { | ||
| 209 | NPadType joy_styles; | ||
| 210 | NPadAssignments pad_assignment; | ||
| 211 | |||
| 212 | ColorReadError single_color_error; | ||
| 213 | ControllerColor single_color; | ||
| 214 | |||
| 215 | ColorReadError dual_color_error; | ||
| 216 | ControllerColor left_color; | ||
| 217 | ControllerColor right_color; | ||
| 218 | |||
| 219 | NPadGeneric main_controller_states; | ||
| 220 | NPadGeneric handheld_states; | ||
| 221 | NPadGeneric dual_states; | ||
| 222 | NPadGeneric left_joy_states; | ||
| 223 | NPadGeneric right_joy_states; | ||
| 224 | NPadGeneric pokeball_states; | ||
| 225 | NPadGeneric libnx; // TODO(ogniK): Find out what this actually is, libnx seems to only be | ||
| 226 | // relying on this for the time being | ||
| 227 | INSERT_PADDING_BYTES( | ||
| 228 | 0x708 * | ||
| 229 | 6); // TODO(ogniK)L SixAxis states, require more information before implementation | ||
| 230 | NPadDevice device_type; | ||
| 231 | NPadProperties properties; | ||
| 232 | INSERT_PADDING_WORDS(4); | ||
| 233 | INSERT_PADDING_BYTES(0x60); | ||
| 234 | INSERT_PADDING_BYTES(0xdf8); | ||
| 235 | }; | ||
| 236 | static_assert(sizeof(NPadEntry) == 0x5000, "NPadEntry is an invalid size"); | ||
| 237 | NPadType style{}; | ||
| 238 | std::array<NPadEntry, 10> shared_memory_entries{}; | ||
| 239 | std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID> | ||
| 240 | buttons; | ||
| 241 | std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID> sticks; | ||
| 242 | std::vector<u32> supported_npad_id_types{}; | ||
| 243 | NpadHoldType hold_type{NpadHoldType::Vertical}; | ||
| 244 | Kernel::SharedPtr<Kernel::Event> styleset_changed_event; | ||
| 245 | size_t dump_idx{}; | ||
| 246 | Vibration last_processed_vibration{}; | ||
| 247 | void InitNewlyAddedControler(size_t controller_idx); | ||
| 248 | }; | ||
| 249 | }; // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/stubbed.cpp b/src/core/hle/service/hid/controllers/stubbed.cpp new file mode 100644 index 000000000..0a602fce2 --- /dev/null +++ b/src/core/hle/service/hid/controllers/stubbed.cpp | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/common_types.h" | ||
| 6 | #include "common/swap.h" | ||
| 7 | #include "core/core_timing.h" | ||
| 8 | #include "core/hle/service/hid/controllers/stubbed.h" | ||
| 9 | |||
| 10 | namespace Service::HID { | ||
| 11 | void Controller_Stubbed::OnInit() {} | ||
| 12 | void Controller_Stubbed::OnRelease() {} | ||
| 13 | void Controller_Stubbed::OnUpdate(u8* data, size_t size) { | ||
| 14 | if (!smart_update) { | ||
| 15 | return; | ||
| 16 | } | ||
| 17 | |||
| 18 | CommonHeader header{}; | ||
| 19 | header.timestamp = CoreTiming::GetTicks(); | ||
| 20 | header.total_entry_count = 17; | ||
| 21 | header.entry_count = 0; | ||
| 22 | header.last_entry_index = 0; | ||
| 23 | |||
| 24 | std::memcpy(data + common_offset, &header, sizeof(CommonHeader)); | ||
| 25 | } | ||
| 26 | void Controller_Stubbed::OnLoadInputDevices() {} | ||
| 27 | |||
| 28 | void Controller_Stubbed::SetCommonHeaderOffset(size_t off) { | ||
| 29 | common_offset = off; | ||
| 30 | smart_update = true; | ||
| 31 | } | ||
| 32 | }; // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/stubbed.h b/src/core/hle/service/hid/controllers/stubbed.h new file mode 100644 index 000000000..ec7adacb3 --- /dev/null +++ b/src/core/hle/service/hid/controllers/stubbed.h | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | #include "common/common_types.h" | ||
| 7 | #include "core/hle/service/hid/controllers/controller_base.h" | ||
| 8 | |||
| 9 | namespace Service::HID { | ||
| 10 | class Controller_Stubbed final : public ControllerBase { | ||
| 11 | public: | ||
| 12 | Controller_Stubbed() = default; | ||
| 13 | |||
| 14 | // Called when the controller is initialized | ||
| 15 | void OnInit() override; | ||
| 16 | |||
| 17 | // When the controller is released | ||
| 18 | void OnRelease() override; | ||
| 19 | |||
| 20 | // When the controller is requesting an update for the shared memory | ||
| 21 | void OnUpdate(u8* data, size_t size) override; | ||
| 22 | |||
| 23 | // Called when input devices should be loaded | ||
| 24 | void OnLoadInputDevices() override; | ||
| 25 | |||
| 26 | void SetCommonHeaderOffset(size_t off); | ||
| 27 | |||
| 28 | private: | ||
| 29 | bool smart_update{}; | ||
| 30 | size_t common_offset{}; | ||
| 31 | }; | ||
| 32 | }; // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cpp new file mode 100644 index 000000000..b675dec8e --- /dev/null +++ b/src/core/hle/service/hid/controllers/touchscreen.cpp | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/common_types.h" | ||
| 6 | #include "common/swap.h" | ||
| 7 | #include "core/core_timing.h" | ||
| 8 | #include "core/frontend/emu_window.h" | ||
| 9 | #include "core/frontend/input.h" | ||
| 10 | #include "core/hle/service/hid/controllers/touchscreen.h" | ||
| 11 | #include "core/settings.h" | ||
| 12 | |||
| 13 | namespace Service::HID { | ||
| 14 | constexpr size_t SHARED_MEMORY_OFFSET = 0x400; | ||
| 15 | void Controller_Touchscreen::OnInit() {} | ||
| 16 | void Controller_Touchscreen::OnRelease() {} | ||
| 17 | void Controller_Touchscreen::OnUpdate(u8* data, size_t size) { | ||
| 18 | shared_memory.header.timestamp = CoreTiming::GetTicks(); | ||
| 19 | shared_memory.header.total_entry_count = 17; | ||
| 20 | |||
| 21 | if (!IsControllerActivated()) { | ||
| 22 | shared_memory.header.entry_count = 0; | ||
| 23 | shared_memory.header.last_entry_index = 0; | ||
| 24 | return; | ||
| 25 | } | ||
| 26 | shared_memory.header.entry_count = 16; | ||
| 27 | |||
| 28 | auto& last_entry = shared_memory.shared_memory_entries[shared_memory.header.last_entry_index]; | ||
| 29 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; | ||
| 30 | auto& cur_entry = shared_memory.shared_memory_entries[shared_memory.header.last_entry_index]; | ||
| 31 | |||
| 32 | cur_entry.sampling_number = last_entry.sampling_number + 1; | ||
| 33 | cur_entry.sampling_number2 = cur_entry.sampling_number; | ||
| 34 | |||
| 35 | auto [x, y, pressed] = touch_device->GetStatus(); | ||
| 36 | auto& touch_entry = cur_entry.states[0]; | ||
| 37 | if (pressed) { | ||
| 38 | touch_entry.x = static_cast<u16>(x * Layout::ScreenUndocked::Width); | ||
| 39 | touch_entry.y = static_cast<u16>(y * Layout::ScreenUndocked::Height); | ||
| 40 | touch_entry.diameter_x = 15; | ||
| 41 | touch_entry.diameter_y = 15; | ||
| 42 | touch_entry.rotation_angle = 0; | ||
| 43 | const u64 tick = CoreTiming::GetTicks(); | ||
| 44 | touch_entry.delta_time = tick - last_touch; | ||
| 45 | last_touch = tick; | ||
| 46 | touch_entry.finger = 0; | ||
| 47 | cur_entry.entry_count = 1; | ||
| 48 | } else { | ||
| 49 | cur_entry.entry_count = 0; | ||
| 50 | } | ||
| 51 | |||
| 52 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(TouchScreenSharedMemory)); | ||
| 53 | } | ||
| 54 | |||
| 55 | void Controller_Touchscreen::OnLoadInputDevices() { | ||
| 56 | touch_device = Input::CreateDevice<Input::TouchDevice>(Settings::values.touch_device); | ||
| 57 | } | ||
| 58 | }; // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/touchscreen.h b/src/core/hle/service/hid/controllers/touchscreen.h new file mode 100644 index 000000000..a516128ac --- /dev/null +++ b/src/core/hle/service/hid/controllers/touchscreen.h | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | #include "common/common_funcs.h" | ||
| 7 | #include "common/common_types.h" | ||
| 8 | #include "common/swap.h" | ||
| 9 | #include "core/frontend/input.h" | ||
| 10 | #include "core/hle/service/hid/controllers/controller_base.h" | ||
| 11 | |||
| 12 | namespace Service::HID { | ||
| 13 | class Controller_Touchscreen final : public ControllerBase { | ||
| 14 | public: | ||
| 15 | Controller_Touchscreen() = default; | ||
| 16 | |||
| 17 | // Called when the controller is initialized | ||
| 18 | void OnInit() override; | ||
| 19 | |||
| 20 | // When the controller is released | ||
| 21 | void OnRelease() override; | ||
| 22 | |||
| 23 | // When the controller is requesting an update for the shared memory | ||
| 24 | void OnUpdate(u8* data, size_t size) override; | ||
| 25 | |||
| 26 | // Called when input devices should be loaded | ||
| 27 | void OnLoadInputDevices() override; | ||
| 28 | |||
| 29 | private: | ||
| 30 | struct TouchState { | ||
| 31 | u64_le delta_time; | ||
| 32 | u32_le attribute; | ||
| 33 | u32_le finger; | ||
| 34 | u32_le x; | ||
| 35 | u32_le y; | ||
| 36 | u32_le diameter_x; | ||
| 37 | u32_le diameter_y; | ||
| 38 | u32_le rotation_angle; | ||
| 39 | }; | ||
| 40 | static_assert(sizeof(TouchState) == 0x28, "Touchstate is an invalid size"); | ||
| 41 | |||
| 42 | struct TouchScreenEntry { | ||
| 43 | s64_le sampling_number; | ||
| 44 | s64_le sampling_number2; | ||
| 45 | s32_le entry_count; | ||
| 46 | std::array<TouchState, 16> states; | ||
| 47 | }; | ||
| 48 | static_assert(sizeof(TouchScreenEntry) == 0x298, "TouchScreenEntry is an invalid size"); | ||
| 49 | |||
| 50 | struct TouchScreenSharedMemory { | ||
| 51 | CommonHeader header; | ||
| 52 | std::array<TouchScreenEntry, 17> shared_memory_entries{}; | ||
| 53 | INSERT_PADDING_BYTES(0x3c8); | ||
| 54 | }; | ||
| 55 | static_assert(sizeof(TouchScreenSharedMemory) == 0x3000, | ||
| 56 | "TouchScreenSharedMemory is an invalid size"); | ||
| 57 | TouchScreenSharedMemory shared_memory{}; | ||
| 58 | std::unique_ptr<Input::TouchDevice> touch_device; | ||
| 59 | s64_le last_touch{}; | ||
| 60 | }; | ||
| 61 | }; // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/xpad.cpp b/src/core/hle/service/hid/controllers/xpad.cpp new file mode 100644 index 000000000..521e925b7 --- /dev/null +++ b/src/core/hle/service/hid/controllers/xpad.cpp | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/common_types.h" | ||
| 6 | #include "common/swap.h" | ||
| 7 | #include "core/core_timing.h" | ||
| 8 | #include "core/hle/service/hid/controllers/xpad.h" | ||
| 9 | |||
| 10 | namespace Service::HID { | ||
| 11 | constexpr size_t SHARED_MEMORY_OFFSET = 0x3C00; | ||
| 12 | void Controller_XPad::OnInit() {} | ||
| 13 | void Controller_XPad::OnRelease() {} | ||
| 14 | void Controller_XPad::OnUpdate(u8* data, size_t size) { | ||
| 15 | for (auto& xpad_entry : shared_memory.shared_memory_entries) { | ||
| 16 | xpad_entry.header.timestamp = CoreTiming::GetTicks(); | ||
| 17 | xpad_entry.header.total_entry_count = 17; | ||
| 18 | |||
| 19 | if (!IsControllerActivated()) { | ||
| 20 | xpad_entry.header.entry_count = 0; | ||
| 21 | xpad_entry.header.last_entry_index = 0; | ||
| 22 | return; | ||
| 23 | } | ||
| 24 | xpad_entry.header.entry_count = 16; | ||
| 25 | |||
| 26 | auto& last_entry = xpad_entry.pad_states[xpad_entry.header.last_entry_index]; | ||
| 27 | xpad_entry.header.last_entry_index = (xpad_entry.header.last_entry_index + 1) % 17; | ||
| 28 | auto& cur_entry = xpad_entry.pad_states[xpad_entry.header.last_entry_index]; | ||
| 29 | |||
| 30 | cur_entry.sampling_number = last_entry.sampling_number + 1; | ||
| 31 | cur_entry.sampling_number2 = cur_entry.sampling_number; | ||
| 32 | } | ||
| 33 | // TODO(ogniK): Update xpad states | ||
| 34 | |||
| 35 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); | ||
| 36 | } | ||
| 37 | void Controller_XPad::OnLoadInputDevices() {} | ||
| 38 | }; // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/controllers/xpad.h b/src/core/hle/service/hid/controllers/xpad.h new file mode 100644 index 000000000..898fadfdc --- /dev/null +++ b/src/core/hle/service/hid/controllers/xpad.h | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | #include "common/common_funcs.h" | ||
| 7 | #include "common/common_types.h" | ||
| 8 | #include "common/swap.h" | ||
| 9 | #include "core/frontend/input.h" | ||
| 10 | #include "core/hle/service/hid/controllers/controller_base.h" | ||
| 11 | |||
| 12 | namespace Service::HID { | ||
| 13 | class Controller_XPad final : public ControllerBase { | ||
| 14 | public: | ||
| 15 | Controller_XPad() = default; | ||
| 16 | |||
| 17 | // Called when the controller is initialized | ||
| 18 | void OnInit() override; | ||
| 19 | |||
| 20 | // When the controller is released | ||
| 21 | void OnRelease() override; | ||
| 22 | |||
| 23 | // When the controller is requesting an update for the shared memory | ||
| 24 | void OnUpdate(u8* data, size_t size) override; | ||
| 25 | |||
| 26 | // Called when input devices should be loaded | ||
| 27 | void OnLoadInputDevices() override; | ||
| 28 | |||
| 29 | private: | ||
| 30 | struct AnalogStick { | ||
| 31 | s32_le x; | ||
| 32 | s32_le y; | ||
| 33 | }; | ||
| 34 | static_assert(sizeof(AnalogStick) == 0x8, "AnalogStick is an invalid size"); | ||
| 35 | |||
| 36 | struct XPadState { | ||
| 37 | s64_le sampling_number; | ||
| 38 | s64_le sampling_number2; | ||
| 39 | s32_le attributes; | ||
| 40 | u32_le pad_states; | ||
| 41 | AnalogStick x_stick; | ||
| 42 | AnalogStick y_stick; | ||
| 43 | }; | ||
| 44 | static_assert(sizeof(XPadState) == 0x28, "XPadState is an invalid size"); | ||
| 45 | |||
| 46 | struct XPadEntry { | ||
| 47 | CommonHeader header; | ||
| 48 | std::array<XPadState, 17> pad_states{}; | ||
| 49 | INSERT_PADDING_BYTES(0x138); | ||
| 50 | }; | ||
| 51 | static_assert(sizeof(XPadEntry) == 0x400, "XPadEntry is an invalid size"); | ||
| 52 | |||
| 53 | struct SharedMemory { | ||
| 54 | std::array<XPadEntry, 4> shared_memory_entries{}; | ||
| 55 | }; | ||
| 56 | static_assert(sizeof(SharedMemory) == 0x1000, "SharedMemory is an invalid size"); | ||
| 57 | SharedMemory shared_memory{}; | ||
| 58 | }; | ||
| 59 | }; // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 7c6b0a4e6..757b3b770 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <array> | ||
| 6 | #include "common/common_types.h" | ||
| 5 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 6 | #include "core/core.h" | 8 | #include "core/core.h" |
| 7 | #include "core/core_timing.h" | 9 | #include "core/core_timing.h" |
| @@ -19,6 +21,16 @@ | |||
| 19 | #include "core/hle/service/service.h" | 21 | #include "core/hle/service/service.h" |
| 20 | #include "core/settings.h" | 22 | #include "core/settings.h" |
| 21 | 23 | ||
| 24 | #include "core/hle/service/hid/controllers/controller_base.h" | ||
| 25 | #include "core/hle/service/hid/controllers/debug_pad.h" | ||
| 26 | #include "core/hle/service/hid/controllers/gesture.h" | ||
| 27 | #include "core/hle/service/hid/controllers/keyboard.h" | ||
| 28 | #include "core/hle/service/hid/controllers/mouse.h" | ||
| 29 | #include "core/hle/service/hid/controllers/npad.h" | ||
| 30 | #include "core/hle/service/hid/controllers/stubbed.h" | ||
| 31 | #include "core/hle/service/hid/controllers/touchscreen.h" | ||
| 32 | #include "core/hle/service/hid/controllers/xpad.h" | ||
| 33 | |||
| 22 | namespace Service::HID { | 34 | namespace Service::HID { |
| 23 | 35 | ||
| 24 | // Updating period for each HID device. | 36 | // Updating period for each HID device. |
| @@ -26,6 +38,22 @@ namespace Service::HID { | |||
| 26 | constexpr u64 pad_update_ticks = CoreTiming::BASE_CLOCK_RATE / 100; | 38 | constexpr u64 pad_update_ticks = CoreTiming::BASE_CLOCK_RATE / 100; |
| 27 | constexpr u64 accelerometer_update_ticks = CoreTiming::BASE_CLOCK_RATE / 100; | 39 | constexpr u64 accelerometer_update_ticks = CoreTiming::BASE_CLOCK_RATE / 100; |
| 28 | constexpr u64 gyroscope_update_ticks = CoreTiming::BASE_CLOCK_RATE / 100; | 40 | constexpr u64 gyroscope_update_ticks = CoreTiming::BASE_CLOCK_RATE / 100; |
| 41 | constexpr size_t SHARED_MEMORY_SIZE = 0x40000; | ||
| 42 | enum class HidController : size_t { | ||
| 43 | DebugPad, | ||
| 44 | Touchscreen, | ||
| 45 | Mouse, | ||
| 46 | Keyboard, | ||
| 47 | XPad, | ||
| 48 | Unknown1, | ||
| 49 | Unknown2, | ||
| 50 | Unknown3, | ||
| 51 | SixAxisSensor, | ||
| 52 | NPad, | ||
| 53 | Gesture, | ||
| 54 | |||
| 55 | MaxControllers | ||
| 56 | }; | ||
| 29 | 57 | ||
| 30 | class IAppletResource final : public ServiceFramework<IAppletResource> { | 58 | class IAppletResource final : public ServiceFramework<IAppletResource> { |
| 31 | public: | 59 | public: |
| @@ -37,19 +65,64 @@ public: | |||
| 37 | 65 | ||
| 38 | auto& kernel = Core::System::GetInstance().Kernel(); | 66 | auto& kernel = Core::System::GetInstance().Kernel(); |
| 39 | shared_mem = Kernel::SharedMemory::Create( | 67 | shared_mem = Kernel::SharedMemory::Create( |
| 40 | kernel, nullptr, 0x40000, Kernel::MemoryPermission::ReadWrite, | 68 | kernel, nullptr, SHARED_MEMORY_SIZE, Kernel::MemoryPermission::ReadWrite, |
| 41 | Kernel::MemoryPermission::Read, 0, Kernel::MemoryRegion::BASE, "HID:SharedMemory"); | 69 | Kernel::MemoryPermission::Read, 0, Kernel::MemoryRegion::BASE, "HID:SharedMemory"); |
| 42 | 70 | ||
| 71 | controllers[static_cast<size_t>(HidController::DebugPad)] = | ||
| 72 | std::make_unique<Controller_DebugPad>(); | ||
| 73 | controllers[static_cast<size_t>(HidController::Touchscreen)] = | ||
| 74 | std::make_unique<Controller_Touchscreen>(); | ||
| 75 | controllers[static_cast<size_t>(HidController::Mouse)] = | ||
| 76 | std::make_unique<Controller_Mouse>(); | ||
| 77 | controllers[static_cast<size_t>(HidController::Keyboard)] = | ||
| 78 | std::make_unique<Controller_Keyboard>(); | ||
| 79 | controllers[static_cast<size_t>(HidController::XPad)] = std::make_unique<Controller_XPad>(); | ||
| 80 | |||
| 81 | controllers[static_cast<size_t>(HidController::Unknown1)] = | ||
| 82 | std::make_unique<Controller_Stubbed>(); | ||
| 83 | controllers[static_cast<size_t>(HidController::Unknown2)] = | ||
| 84 | std::make_unique<Controller_Stubbed>(); | ||
| 85 | controllers[static_cast<size_t>(HidController::Unknown3)] = | ||
| 86 | std::make_unique<Controller_Stubbed>(); | ||
| 87 | |||
| 88 | controllers[static_cast<size_t>(HidController::SixAxisSensor)] = | ||
| 89 | std::make_unique<Controller_Stubbed>(); | ||
| 90 | |||
| 91 | controllers[static_cast<size_t>(HidController::NPad)] = std::make_unique<Controller_NPad>(); | ||
| 92 | controllers[static_cast<size_t>(HidController::Gesture)] = | ||
| 93 | std::make_unique<Controller_Gesture>(); | ||
| 94 | |||
| 95 | // Homebrew doesn't try to activate some controllers, so we activate them by default | ||
| 96 | controllers[static_cast<size_t>(HidController::NPad)]->ActivateController(); | ||
| 97 | controllers[static_cast<size_t>(HidController::Touchscreen)]->ActivateController(); | ||
| 98 | |||
| 99 | GetController<Controller_Stubbed>(HidController::Unknown1).SetCommonHeaderOffset(0x4c00); | ||
| 100 | GetController<Controller_Stubbed>(HidController::Unknown2).SetCommonHeaderOffset(0x4e00); | ||
| 101 | GetController<Controller_Stubbed>(HidController::Unknown3).SetCommonHeaderOffset(0x5000); | ||
| 102 | |||
| 43 | // Register update callbacks | 103 | // Register update callbacks |
| 44 | pad_update_event = CoreTiming::RegisterEvent( | 104 | pad_update_event = CoreTiming::RegisterEvent( |
| 45 | "HID::UpdatePadCallback", | 105 | "HID::UpdatePadCallback", |
| 46 | [this](u64 userdata, int cycles_late) { UpdatePadCallback(userdata, cycles_late); }); | 106 | [this](u64 userdata, int cycles_late) { UpdateControllers(userdata, cycles_late); }); |
| 47 | 107 | ||
| 48 | // TODO(shinyquagsire23): Other update callbacks? (accel, gyro?) | 108 | // TODO(shinyquagsire23): Other update callbacks? (accel, gyro?) |
| 49 | 109 | ||
| 50 | CoreTiming::ScheduleEvent(pad_update_ticks, pad_update_event); | 110 | CoreTiming::ScheduleEvent(pad_update_ticks, pad_update_event); |
| 51 | } | 111 | } |
| 52 | 112 | ||
| 113 | void ActivateController(HidController controller) { | ||
| 114 | controllers[static_cast<size_t>(controller)]->ActivateController(); | ||
| 115 | } | ||
| 116 | |||
| 117 | void DeactivateController(HidController controller) { | ||
| 118 | controllers[static_cast<size_t>(controller)]->DeactivateController(); | ||
| 119 | } | ||
| 120 | |||
| 121 | template <typename T> | ||
| 122 | T& GetController(HidController controller) { | ||
| 123 | return static_cast<T&>(*controllers[static_cast<size_t>(controller)]); | ||
| 124 | } | ||
| 125 | |||
| 53 | ~IAppletResource() { | 126 | ~IAppletResource() { |
| 54 | CoreTiming::UnscheduleEvent(pad_update_event, 0); | 127 | CoreTiming::UnscheduleEvent(pad_update_event, 0); |
| 55 | } | 128 | } |
| @@ -62,200 +135,15 @@ private: | |||
| 62 | LOG_DEBUG(Service_HID, "called"); | 135 | LOG_DEBUG(Service_HID, "called"); |
| 63 | } | 136 | } |
| 64 | 137 | ||
| 65 | void LoadInputDevices() { | 138 | void UpdateControllers(u64 userdata, int cycles_late) { |
| 66 | std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, | 139 | bool should_reload = Settings::values.is_device_reload_pending.exchange(false); |
| 67 | Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END, | 140 | for (const auto& controller : controllers) { |
| 68 | buttons.begin(), Input::CreateDevice<Input::ButtonDevice>); | 141 | if (should_reload) { |
| 69 | std::transform(Settings::values.analogs.begin() + Settings::NativeAnalog::STICK_HID_BEGIN, | 142 | controller->OnLoadInputDevices(); |
| 70 | Settings::values.analogs.begin() + Settings::NativeAnalog::STICK_HID_END, | ||
| 71 | sticks.begin(), Input::CreateDevice<Input::AnalogDevice>); | ||
| 72 | touch_device = Input::CreateDevice<Input::TouchDevice>(Settings::values.touch_device); | ||
| 73 | // TODO(shinyquagsire23): gyro, mouse, keyboard | ||
| 74 | } | ||
| 75 | |||
| 76 | void UpdatePadCallback(u64 userdata, int cycles_late) { | ||
| 77 | SharedMemory mem{}; | ||
| 78 | std::memcpy(&mem, shared_mem->GetPointer(), sizeof(SharedMemory)); | ||
| 79 | |||
| 80 | if (Settings::values.is_device_reload_pending.exchange(false)) | ||
| 81 | LoadInputDevices(); | ||
| 82 | |||
| 83 | // Set up controllers as neon red+blue Joy-Con attached to console | ||
| 84 | ControllerHeader& controller_header = mem.controllers[Controller_Handheld].header; | ||
| 85 | controller_header.type = ControllerType_Handheld; | ||
| 86 | controller_header.single_colors_descriptor = ColorDesc_ColorsNonexistent; | ||
| 87 | controller_header.right_color_body = JOYCON_BODY_NEON_RED; | ||
| 88 | controller_header.right_color_buttons = JOYCON_BUTTONS_NEON_RED; | ||
| 89 | controller_header.left_color_body = JOYCON_BODY_NEON_BLUE; | ||
| 90 | controller_header.left_color_buttons = JOYCON_BUTTONS_NEON_BLUE; | ||
| 91 | |||
| 92 | for (std::size_t controller = 0; controller < mem.controllers.size(); controller++) { | ||
| 93 | for (auto& layout : mem.controllers[controller].layouts) { | ||
| 94 | layout.header.num_entries = HID_NUM_ENTRIES; | ||
| 95 | layout.header.max_entry_index = HID_NUM_ENTRIES - 1; | ||
| 96 | |||
| 97 | // HID shared memory stores the state of the past 17 samples in a circlular buffer, | ||
| 98 | // each with a timestamp in number of samples since boot. | ||
| 99 | const ControllerInputEntry& last_entry = layout.entries[layout.header.latest_entry]; | ||
| 100 | |||
| 101 | layout.header.timestamp_ticks = CoreTiming::GetTicks(); | ||
| 102 | layout.header.latest_entry = (layout.header.latest_entry + 1) % HID_NUM_ENTRIES; | ||
| 103 | |||
| 104 | ControllerInputEntry& entry = layout.entries[layout.header.latest_entry]; | ||
| 105 | entry.timestamp = last_entry.timestamp + 1; | ||
| 106 | // TODO(shinyquagsire23): Is this always identical to timestamp? | ||
| 107 | entry.timestamp_2 = entry.timestamp; | ||
| 108 | |||
| 109 | // TODO(shinyquagsire23): More than just handheld input | ||
| 110 | if (controller != Controller_Handheld) | ||
| 111 | continue; | ||
| 112 | |||
| 113 | entry.connection_state = ConnectionState_Connected | ConnectionState_Wired; | ||
| 114 | |||
| 115 | // TODO(shinyquagsire23): Set up some LUTs for each layout mapping in the future? | ||
| 116 | // For now everything is just the default handheld layout, but split Joy-Con will | ||
| 117 | // rotate the face buttons and directions for certain layouts. | ||
| 118 | ControllerPadState& state = entry.buttons; | ||
| 119 | using namespace Settings::NativeButton; | ||
| 120 | state.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 121 | state.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 122 | state.x.Assign(buttons[X - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 123 | state.y.Assign(buttons[Y - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 124 | state.lstick.Assign(buttons[LStick - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 125 | state.rstick.Assign(buttons[RStick - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 126 | state.l.Assign(buttons[L - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 127 | state.r.Assign(buttons[R - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 128 | state.zl.Assign(buttons[ZL - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 129 | state.zr.Assign(buttons[ZR - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 130 | state.plus.Assign(buttons[Plus - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 131 | state.minus.Assign(buttons[Minus - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 132 | |||
| 133 | state.dleft.Assign(buttons[DLeft - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 134 | state.dup.Assign(buttons[DUp - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 135 | state.dright.Assign(buttons[DRight - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 136 | state.ddown.Assign(buttons[DDown - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 137 | |||
| 138 | state.lstick_left.Assign(buttons[LStick_Left - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 139 | state.lstick_up.Assign(buttons[LStick_Up - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 140 | state.lstick_right.Assign(buttons[LStick_Right - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 141 | state.lstick_down.Assign(buttons[LStick_Down - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 142 | |||
| 143 | state.rstick_left.Assign(buttons[RStick_Left - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 144 | state.rstick_up.Assign(buttons[RStick_Up - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 145 | state.rstick_right.Assign(buttons[RStick_Right - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 146 | state.rstick_down.Assign(buttons[RStick_Down - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 147 | |||
| 148 | state.sl.Assign(buttons[SL - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 149 | state.sr.Assign(buttons[SR - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 150 | |||
| 151 | const auto [stick_l_x_f, stick_l_y_f] = sticks[Joystick_Left]->GetStatus(); | ||
| 152 | const auto [stick_r_x_f, stick_r_y_f] = sticks[Joystick_Right]->GetStatus(); | ||
| 153 | entry.joystick_left_x = static_cast<s32>(stick_l_x_f * HID_JOYSTICK_MAX); | ||
| 154 | entry.joystick_left_y = static_cast<s32>(stick_l_y_f * HID_JOYSTICK_MAX); | ||
| 155 | entry.joystick_right_x = static_cast<s32>(stick_r_x_f * HID_JOYSTICK_MAX); | ||
| 156 | entry.joystick_right_y = static_cast<s32>(stick_r_y_f * HID_JOYSTICK_MAX); | ||
| 157 | } | 143 | } |
| 144 | controller->OnUpdate(shared_mem->GetPointer(), SHARED_MEMORY_SIZE); | ||
| 158 | } | 145 | } |
| 159 | 146 | ||
| 160 | TouchScreen& touchscreen = mem.touchscreen; | ||
| 161 | const u64 last_entry = touchscreen.header.latest_entry; | ||
| 162 | const u64 curr_entry = (last_entry + 1) % touchscreen.entries.size(); | ||
| 163 | const u64 timestamp = CoreTiming::GetTicks(); | ||
| 164 | const u64 sample_counter = touchscreen.entries[last_entry].header.timestamp + 1; | ||
| 165 | touchscreen.header.timestamp_ticks = timestamp; | ||
| 166 | touchscreen.header.num_entries = touchscreen.entries.size(); | ||
| 167 | touchscreen.header.latest_entry = curr_entry; | ||
| 168 | touchscreen.header.max_entry_index = touchscreen.entries.size(); | ||
| 169 | touchscreen.header.timestamp = timestamp; | ||
| 170 | touchscreen.entries[curr_entry].header.timestamp = sample_counter; | ||
| 171 | |||
| 172 | TouchScreenEntryTouch touch_entry{}; | ||
| 173 | auto [x, y, pressed] = touch_device->GetStatus(); | ||
| 174 | touch_entry.timestamp = timestamp; | ||
| 175 | touch_entry.x = static_cast<u16>(x * Layout::ScreenUndocked::Width); | ||
| 176 | touch_entry.y = static_cast<u16>(y * Layout::ScreenUndocked::Height); | ||
| 177 | touch_entry.touch_index = 0; | ||
| 178 | |||
| 179 | // TODO(DarkLordZach): Maybe try to derive these from EmuWindow? | ||
| 180 | touch_entry.diameter_x = 15; | ||
| 181 | touch_entry.diameter_y = 15; | ||
| 182 | touch_entry.angle = 0; | ||
| 183 | |||
| 184 | // TODO(DarkLordZach): Implement multi-touch support | ||
| 185 | if (pressed) { | ||
| 186 | touchscreen.entries[curr_entry].header.num_touches = 1; | ||
| 187 | touchscreen.entries[curr_entry].touches[0] = touch_entry; | ||
| 188 | } else { | ||
| 189 | touchscreen.entries[curr_entry].header.num_touches = 0; | ||
| 190 | } | ||
| 191 | |||
| 192 | // TODO(shinyquagsire23): Properly implement mouse | ||
| 193 | Mouse& mouse = mem.mouse; | ||
| 194 | const u64 last_mouse_entry = mouse.header.latest_entry; | ||
| 195 | const u64 curr_mouse_entry = (mouse.header.latest_entry + 1) % mouse.entries.size(); | ||
| 196 | const u64 mouse_sample_counter = mouse.entries[last_mouse_entry].timestamp + 1; | ||
| 197 | mouse.header.timestamp_ticks = timestamp; | ||
| 198 | mouse.header.num_entries = mouse.entries.size(); | ||
| 199 | mouse.header.max_entry_index = mouse.entries.size(); | ||
| 200 | mouse.header.latest_entry = curr_mouse_entry; | ||
| 201 | |||
| 202 | mouse.entries[curr_mouse_entry].timestamp = mouse_sample_counter; | ||
| 203 | mouse.entries[curr_mouse_entry].timestamp_2 = mouse_sample_counter; | ||
| 204 | |||
| 205 | // TODO(shinyquagsire23): Properly implement keyboard | ||
| 206 | Keyboard& keyboard = mem.keyboard; | ||
| 207 | const u64 last_keyboard_entry = keyboard.header.latest_entry; | ||
| 208 | const u64 curr_keyboard_entry = | ||
| 209 | (keyboard.header.latest_entry + 1) % keyboard.entries.size(); | ||
| 210 | const u64 keyboard_sample_counter = keyboard.entries[last_keyboard_entry].timestamp + 1; | ||
| 211 | keyboard.header.timestamp_ticks = timestamp; | ||
| 212 | keyboard.header.num_entries = keyboard.entries.size(); | ||
| 213 | keyboard.header.latest_entry = last_keyboard_entry; | ||
| 214 | keyboard.header.max_entry_index = keyboard.entries.size(); | ||
| 215 | |||
| 216 | keyboard.entries[curr_keyboard_entry].timestamp = keyboard_sample_counter; | ||
| 217 | keyboard.entries[curr_keyboard_entry].timestamp_2 = keyboard_sample_counter; | ||
| 218 | |||
| 219 | // TODO(shinyquagsire23): Figure out what any of these are | ||
| 220 | for (auto& input : mem.unk_input_1) { | ||
| 221 | const u64 last_input_entry = input.header.latest_entry; | ||
| 222 | const u64 curr_input_entry = (input.header.latest_entry + 1) % input.entries.size(); | ||
| 223 | const u64 input_sample_counter = input.entries[last_input_entry].timestamp + 1; | ||
| 224 | |||
| 225 | input.header.timestamp_ticks = timestamp; | ||
| 226 | input.header.num_entries = input.entries.size(); | ||
| 227 | input.header.latest_entry = last_input_entry; | ||
| 228 | input.header.max_entry_index = input.entries.size(); | ||
| 229 | |||
| 230 | input.entries[curr_input_entry].timestamp = input_sample_counter; | ||
| 231 | input.entries[curr_input_entry].timestamp_2 = input_sample_counter; | ||
| 232 | } | ||
| 233 | |||
| 234 | for (auto& input : mem.unk_input_2) { | ||
| 235 | input.header.timestamp_ticks = timestamp; | ||
| 236 | input.header.num_entries = 17; | ||
| 237 | input.header.latest_entry = 0; | ||
| 238 | input.header.max_entry_index = 0; | ||
| 239 | } | ||
| 240 | |||
| 241 | UnkInput3& input = mem.unk_input_3; | ||
| 242 | const u64 last_input_entry = input.header.latest_entry; | ||
| 243 | const u64 curr_input_entry = (input.header.latest_entry + 1) % input.entries.size(); | ||
| 244 | const u64 input_sample_counter = input.entries[last_input_entry].timestamp + 1; | ||
| 245 | |||
| 246 | input.header.timestamp_ticks = timestamp; | ||
| 247 | input.header.num_entries = input.entries.size(); | ||
| 248 | input.header.latest_entry = last_input_entry; | ||
| 249 | input.header.max_entry_index = input.entries.size(); | ||
| 250 | |||
| 251 | input.entries[curr_input_entry].timestamp = input_sample_counter; | ||
| 252 | input.entries[curr_input_entry].timestamp_2 = input_sample_counter; | ||
| 253 | |||
| 254 | // TODO(shinyquagsire23): Signal events | ||
| 255 | |||
| 256 | std::memcpy(shared_mem->GetPointer(), &mem, sizeof(SharedMemory)); | ||
| 257 | |||
| 258 | // Reschedule recurrent event | ||
| 259 | CoreTiming::ScheduleEvent(pad_update_ticks - cycles_late, pad_update_event); | 147 | CoreTiming::ScheduleEvent(pad_update_ticks - cycles_late, pad_update_event); |
| 260 | } | 148 | } |
| 261 | 149 | ||
| @@ -265,11 +153,8 @@ private: | |||
| 265 | // CoreTiming update events | 153 | // CoreTiming update events |
| 266 | CoreTiming::EventType* pad_update_event; | 154 | CoreTiming::EventType* pad_update_event; |
| 267 | 155 | ||
| 268 | // Stored input state info | 156 | std::array<std::unique_ptr<ControllerBase>, static_cast<size_t>(HidController::MaxControllers)> |
| 269 | std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID> | 157 | controllers{}; |
| 270 | buttons; | ||
| 271 | std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID> sticks; | ||
| 272 | std::unique_ptr<Input::TouchDevice> touch_device; | ||
| 273 | }; | 158 | }; |
| 274 | 159 | ||
| 275 | class IActiveVibrationDeviceList final : public ServiceFramework<IActiveVibrationDeviceList> { | 160 | class IActiveVibrationDeviceList final : public ServiceFramework<IActiveVibrationDeviceList> { |
| @@ -301,7 +186,7 @@ public: | |||
| 301 | {31, &Hid::ActivateKeyboard, "ActivateKeyboard"}, | 186 | {31, &Hid::ActivateKeyboard, "ActivateKeyboard"}, |
| 302 | {40, nullptr, "AcquireXpadIdEventHandle"}, | 187 | {40, nullptr, "AcquireXpadIdEventHandle"}, |
| 303 | {41, nullptr, "ReleaseXpadIdEventHandle"}, | 188 | {41, nullptr, "ReleaseXpadIdEventHandle"}, |
| 304 | {51, nullptr, "ActivateXpad"}, | 189 | {51, &Hid::ActivateXpad, "ActivateXpad"}, |
| 305 | {55, nullptr, "GetXpadIds"}, | 190 | {55, nullptr, "GetXpadIds"}, |
| 306 | {56, nullptr, "ActivateJoyXpad"}, | 191 | {56, nullptr, "ActivateJoyXpad"}, |
| 307 | {58, nullptr, "GetJoyXpadLifoHandle"}, | 192 | {58, nullptr, "GetJoyXpadLifoHandle"}, |
| @@ -401,16 +286,11 @@ public: | |||
| 401 | // clang-format on | 286 | // clang-format on |
| 402 | 287 | ||
| 403 | RegisterHandlers(functions); | 288 | RegisterHandlers(functions); |
| 404 | |||
| 405 | auto& kernel = Core::System::GetInstance().Kernel(); | ||
| 406 | event = Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "hid:EventHandle"); | ||
| 407 | } | 289 | } |
| 408 | ~Hid() = default; | 290 | ~Hid() = default; |
| 409 | 291 | ||
| 410 | private: | 292 | private: |
| 411 | std::shared_ptr<IAppletResource> applet_resource; | 293 | std::shared_ptr<IAppletResource> applet_resource; |
| 412 | u32 joy_hold_type{0}; | ||
| 413 | Kernel::SharedPtr<Kernel::Event> event; | ||
| 414 | 294 | ||
| 415 | void CreateAppletResource(Kernel::HLERequestContext& ctx) { | 295 | void CreateAppletResource(Kernel::HLERequestContext& ctx) { |
| 416 | if (applet_resource == nullptr) { | 296 | if (applet_resource == nullptr) { |
| @@ -423,28 +303,54 @@ private: | |||
| 423 | LOG_DEBUG(Service_HID, "called"); | 303 | LOG_DEBUG(Service_HID, "called"); |
| 424 | } | 304 | } |
| 425 | 305 | ||
| 306 | void ActivateXpad(Kernel::HLERequestContext& ctx) { | ||
| 307 | applet_resource->ActivateController(HidController::XPad); | ||
| 308 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 309 | rb.Push(RESULT_SUCCESS); | ||
| 310 | LOG_DEBUG(Service_HID, "called"); | ||
| 311 | } | ||
| 312 | |||
| 426 | void ActivateDebugPad(Kernel::HLERequestContext& ctx) { | 313 | void ActivateDebugPad(Kernel::HLERequestContext& ctx) { |
| 314 | applet_resource->ActivateController(HidController::DebugPad); | ||
| 427 | IPC::ResponseBuilder rb{ctx, 2}; | 315 | IPC::ResponseBuilder rb{ctx, 2}; |
| 428 | rb.Push(RESULT_SUCCESS); | 316 | rb.Push(RESULT_SUCCESS); |
| 429 | LOG_WARNING(Service_HID, "(STUBBED) called"); | 317 | LOG_DEBUG(Service_HID, "called"); |
| 430 | } | 318 | } |
| 431 | 319 | ||
| 432 | void ActivateTouchScreen(Kernel::HLERequestContext& ctx) { | 320 | void ActivateTouchScreen(Kernel::HLERequestContext& ctx) { |
| 321 | applet_resource->ActivateController(HidController::Touchscreen); | ||
| 433 | IPC::ResponseBuilder rb{ctx, 2}; | 322 | IPC::ResponseBuilder rb{ctx, 2}; |
| 434 | rb.Push(RESULT_SUCCESS); | 323 | rb.Push(RESULT_SUCCESS); |
| 435 | LOG_WARNING(Service_HID, "(STUBBED) called"); | 324 | LOG_DEBUG(Service_HID, "called"); |
| 436 | } | 325 | } |
| 437 | 326 | ||
| 438 | void ActivateMouse(Kernel::HLERequestContext& ctx) { | 327 | void ActivateMouse(Kernel::HLERequestContext& ctx) { |
| 328 | applet_resource->ActivateController(HidController::Mouse); | ||
| 439 | IPC::ResponseBuilder rb{ctx, 2}; | 329 | IPC::ResponseBuilder rb{ctx, 2}; |
| 440 | rb.Push(RESULT_SUCCESS); | 330 | rb.Push(RESULT_SUCCESS); |
| 441 | LOG_WARNING(Service_HID, "(STUBBED) called"); | 331 | LOG_DEBUG(Service_HID, "called"); |
| 442 | } | 332 | } |
| 443 | 333 | ||
| 444 | void ActivateKeyboard(Kernel::HLERequestContext& ctx) { | 334 | void ActivateKeyboard(Kernel::HLERequestContext& ctx) { |
| 335 | applet_resource->ActivateController(HidController::Keyboard); | ||
| 445 | IPC::ResponseBuilder rb{ctx, 2}; | 336 | IPC::ResponseBuilder rb{ctx, 2}; |
| 446 | rb.Push(RESULT_SUCCESS); | 337 | rb.Push(RESULT_SUCCESS); |
| 447 | LOG_WARNING(Service_HID, "(STUBBED) called"); | 338 | LOG_DEBUG(Service_HID, "called"); |
| 339 | } | ||
| 340 | |||
| 341 | void ActivateGesture(Kernel::HLERequestContext& ctx) { | ||
| 342 | applet_resource->ActivateController(HidController::Gesture); | ||
| 343 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 344 | rb.Push(RESULT_SUCCESS); | ||
| 345 | LOG_DEBUG(Service_HID, "called"); | ||
| 346 | } | ||
| 347 | |||
| 348 | void ActivateNpadWithRevision(Kernel::HLERequestContext& ctx) { | ||
| 349 | // Should have no effect with how our npad sets up the data | ||
| 350 | applet_resource->ActivateController(HidController::NPad); | ||
| 351 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 352 | rb.Push(RESULT_SUCCESS); | ||
| 353 | LOG_DEBUG(Service_HID, "called"); | ||
| 448 | } | 354 | } |
| 449 | 355 | ||
| 450 | void StartSixAxisSensor(Kernel::HLERequestContext& ctx) { | 356 | void StartSixAxisSensor(Kernel::HLERequestContext& ctx) { |
| @@ -468,41 +374,55 @@ private: | |||
| 468 | } | 374 | } |
| 469 | 375 | ||
| 470 | void SetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx) { | 376 | void SetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx) { |
| 377 | IPC::RequestParser rp{ctx}; | ||
| 378 | auto supported_styleset = rp.PopRaw<u32>(); | ||
| 379 | applet_resource->GetController<Controller_NPad>(HidController::NPad) | ||
| 380 | .SetSupportedStyleSet({supported_styleset}); | ||
| 381 | |||
| 471 | IPC::ResponseBuilder rb{ctx, 2}; | 382 | IPC::ResponseBuilder rb{ctx, 2}; |
| 472 | rb.Push(RESULT_SUCCESS); | 383 | rb.Push(RESULT_SUCCESS); |
| 473 | LOG_WARNING(Service_HID, "(STUBBED) called"); | 384 | |
| 385 | LOG_DEBUG(Service_HID, "called"); | ||
| 474 | } | 386 | } |
| 475 | 387 | ||
| 476 | void GetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx) { | 388 | void GetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx) { |
| 389 | std::string blah = ctx.Description(); | ||
| 390 | auto& controller = applet_resource->GetController<Controller_NPad>(HidController::NPad); | ||
| 391 | |||
| 477 | IPC::ResponseBuilder rb{ctx, 3}; | 392 | IPC::ResponseBuilder rb{ctx, 3}; |
| 478 | rb.Push(RESULT_SUCCESS); | 393 | rb.Push(RESULT_SUCCESS); |
| 479 | rb.Push<u32>(0); | 394 | rb.Push<u32>(controller.GetSupportedStyleSet().raw); |
| 480 | LOG_WARNING(Service_HID, "(STUBBED) called"); | 395 | LOG_DEBUG(Service_HID, "called"); |
| 481 | } | 396 | } |
| 482 | 397 | ||
| 483 | void SetSupportedNpadIdType(Kernel::HLERequestContext& ctx) { | 398 | void SetSupportedNpadIdType(Kernel::HLERequestContext& ctx) { |
| 399 | applet_resource->GetController<Controller_NPad>(HidController::NPad) | ||
| 400 | .SetSupportedNPadIdTypes(ctx.ReadBuffer().data(), ctx.GetReadBufferSize()); | ||
| 484 | IPC::ResponseBuilder rb{ctx, 2}; | 401 | IPC::ResponseBuilder rb{ctx, 2}; |
| 485 | rb.Push(RESULT_SUCCESS); | 402 | rb.Push(RESULT_SUCCESS); |
| 486 | LOG_WARNING(Service_HID, "(STUBBED) called"); | 403 | LOG_DEBUG(Service_HID, "called"); |
| 487 | } | 404 | } |
| 488 | 405 | ||
| 489 | void ActivateNpad(Kernel::HLERequestContext& ctx) { | 406 | void ActivateNpad(Kernel::HLERequestContext& ctx) { |
| 490 | IPC::ResponseBuilder rb{ctx, 2}; | 407 | IPC::ResponseBuilder rb{ctx, 2}; |
| 491 | rb.Push(RESULT_SUCCESS); | 408 | rb.Push(RESULT_SUCCESS); |
| 492 | LOG_WARNING(Service_HID, "(STUBBED) called"); | 409 | applet_resource->ActivateController(HidController::NPad); |
| 410 | LOG_DEBUG(Service_HID, "called"); | ||
| 493 | } | 411 | } |
| 494 | 412 | ||
| 495 | void AcquireNpadStyleSetUpdateEventHandle(Kernel::HLERequestContext& ctx) { | 413 | void AcquireNpadStyleSetUpdateEventHandle(Kernel::HLERequestContext& ctx) { |
| 496 | IPC::ResponseBuilder rb{ctx, 2, 1}; | 414 | IPC::ResponseBuilder rb{ctx, 2, 1}; |
| 497 | rb.Push(RESULT_SUCCESS); | 415 | rb.Push(RESULT_SUCCESS); |
| 498 | rb.PushCopyObjects(event); | 416 | rb.PushCopyObjects(applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 499 | LOG_WARNING(Service_HID, "(STUBBED) called"); | 417 | .GetStyleSetChangedEvent()); |
| 418 | LOG_DEBUG(Service_HID, "called"); | ||
| 500 | } | 419 | } |
| 501 | 420 | ||
| 502 | void DisconnectNpad(Kernel::HLERequestContext& ctx) { | 421 | void DisconnectNpad(Kernel::HLERequestContext& ctx) { |
| 422 | applet_resource->DeactivateController(HidController::NPad); | ||
| 503 | IPC::ResponseBuilder rb{ctx, 2}; | 423 | IPC::ResponseBuilder rb{ctx, 2}; |
| 504 | rb.Push(RESULT_SUCCESS); | 424 | rb.Push(RESULT_SUCCESS); |
| 505 | LOG_WARNING(Service_HID, "(STUBBED) called"); | 425 | LOG_DEBUG(Service_HID, "called"); |
| 506 | } | 426 | } |
| 507 | 427 | ||
| 508 | void GetPlayerLedPattern(Kernel::HLERequestContext& ctx) { | 428 | void GetPlayerLedPattern(Kernel::HLERequestContext& ctx) { |
| @@ -512,16 +432,22 @@ private: | |||
| 512 | } | 432 | } |
| 513 | 433 | ||
| 514 | void SetNpadJoyHoldType(Kernel::HLERequestContext& ctx) { | 434 | void SetNpadJoyHoldType(Kernel::HLERequestContext& ctx) { |
| 435 | auto& controller = applet_resource->GetController<Controller_NPad>(HidController::NPad); | ||
| 436 | IPC::RequestParser rp{ctx}; | ||
| 437 | auto hold_type = rp.PopRaw<u64>(); | ||
| 438 | controller.SetHoldType(Controller_NPad::NpadHoldType{hold_type}); | ||
| 439 | |||
| 515 | IPC::ResponseBuilder rb{ctx, 2}; | 440 | IPC::ResponseBuilder rb{ctx, 2}; |
| 516 | rb.Push(RESULT_SUCCESS); | 441 | rb.Push(RESULT_SUCCESS); |
| 517 | LOG_WARNING(Service_HID, "(STUBBED) called"); | 442 | LOG_DEBUG(Service_HID, "called"); |
| 518 | } | 443 | } |
| 519 | 444 | ||
| 520 | void GetNpadJoyHoldType(Kernel::HLERequestContext& ctx) { | 445 | void GetNpadJoyHoldType(Kernel::HLERequestContext& ctx) { |
| 521 | IPC::ResponseBuilder rb{ctx, 3}; | 446 | auto& controller = applet_resource->GetController<Controller_NPad>(HidController::NPad); |
| 447 | IPC::ResponseBuilder rb{ctx, 4}; | ||
| 522 | rb.Push(RESULT_SUCCESS); | 448 | rb.Push(RESULT_SUCCESS); |
| 523 | rb.Push(joy_hold_type); | 449 | rb.Push<u64>(static_cast<u64>(controller.GetHoldType())); |
| 524 | LOG_WARNING(Service_HID, "(STUBBED) called"); | 450 | LOG_DEBUG(Service_HID, "called"); |
| 525 | } | 451 | } |
| 526 | 452 | ||
| 527 | void SetNpadJoyAssignmentModeSingleByDefault(Kernel::HLERequestContext& ctx) { | 453 | void SetNpadJoyAssignmentModeSingleByDefault(Kernel::HLERequestContext& ctx) { |
| @@ -531,21 +457,57 @@ private: | |||
| 531 | } | 457 | } |
| 532 | 458 | ||
| 533 | void SendVibrationValue(Kernel::HLERequestContext& ctx) { | 459 | void SendVibrationValue(Kernel::HLERequestContext& ctx) { |
| 460 | IPC::RequestParser rp{ctx}; | ||
| 461 | auto controller_id = rp.PopRaw<u32>(); | ||
| 462 | auto vibration_values = rp.PopRaw<Controller_NPad::Vibration>(); | ||
| 463 | |||
| 534 | IPC::ResponseBuilder rb{ctx, 2}; | 464 | IPC::ResponseBuilder rb{ctx, 2}; |
| 535 | rb.Push(RESULT_SUCCESS); | 465 | rb.Push(RESULT_SUCCESS); |
| 536 | LOG_WARNING(Service_HID, "(STUBBED) called"); | 466 | |
| 467 | applet_resource->GetController<Controller_NPad>(HidController::NPad) | ||
| 468 | .VibrateController({controller_id}, {vibration_values}); | ||
| 469 | LOG_DEBUG(Service_HID, "called"); | ||
| 537 | } | 470 | } |
| 538 | 471 | ||
| 539 | void GetActualVibrationValue(Kernel::HLERequestContext& ctx) { | 472 | void SendVibrationValues(Kernel::HLERequestContext& ctx) { |
| 473 | auto controllers = ctx.ReadBuffer(0); | ||
| 474 | auto vibrations = ctx.ReadBuffer(1); | ||
| 475 | |||
| 476 | std::vector<u32> controller_list(controllers.size() / sizeof(u32)); | ||
| 477 | std::vector<Controller_NPad::Vibration> vibration_list(vibrations.size() / | ||
| 478 | sizeof(Controller_NPad::Vibration)); | ||
| 479 | |||
| 480 | std::memcpy(controller_list.data(), controllers.data(), controllers.size()); | ||
| 481 | std::memcpy(vibration_list.data(), vibrations.data(), vibrations.size()); | ||
| 482 | std::transform(controller_list.begin(), controller_list.end(), controller_list.begin(), | ||
| 483 | [](u32 controller_id) { return controller_id - 3; }); | ||
| 484 | |||
| 485 | applet_resource->GetController<Controller_NPad>(HidController::NPad) | ||
| 486 | .VibrateController(controller_list, vibration_list); | ||
| 487 | |||
| 540 | IPC::ResponseBuilder rb{ctx, 2}; | 488 | IPC::ResponseBuilder rb{ctx, 2}; |
| 541 | rb.Push(RESULT_SUCCESS); | 489 | rb.Push(RESULT_SUCCESS); |
| 542 | LOG_WARNING(Service_HID, "(STUBBED) called"); | 490 | LOG_DEBUG(Service_HID, "called"); |
| 491 | } | ||
| 492 | |||
| 493 | void GetActualVibrationValue(Kernel::HLERequestContext& ctx) { | ||
| 494 | IPC::ResponseBuilder rb{ctx, 6}; | ||
| 495 | rb.Push(RESULT_SUCCESS); | ||
| 496 | rb.PushRaw<Controller_NPad::Vibration>( | ||
| 497 | applet_resource->GetController<Controller_NPad>(HidController::NPad) | ||
| 498 | .GetLastVibration()); | ||
| 499 | LOG_DEBUG(Service_HID, "called"); | ||
| 543 | } | 500 | } |
| 544 | 501 | ||
| 545 | void SetNpadJoyAssignmentModeDual(Kernel::HLERequestContext& ctx) { | 502 | void SetNpadJoyAssignmentModeDual(Kernel::HLERequestContext& ctx) { |
| 503 | IPC::RequestParser rp{ctx}; | ||
| 504 | auto npad_id = rp.PopRaw<u32>(); | ||
| 505 | auto& controller = applet_resource->GetController<Controller_NPad>(HidController::NPad); | ||
| 506 | controller.SetNpadMode(npad_id, Controller_NPad::NPadAssignments::Dual); | ||
| 507 | |||
| 546 | IPC::ResponseBuilder rb{ctx, 2}; | 508 | IPC::ResponseBuilder rb{ctx, 2}; |
| 547 | rb.Push(RESULT_SUCCESS); | 509 | rb.Push(RESULT_SUCCESS); |
| 548 | LOG_WARNING(Service_HID, "(STUBBED) called"); | 510 | LOG_DEBUG(Service_HID, "called"); |
| 549 | } | 511 | } |
| 550 | 512 | ||
| 551 | void MergeSingleJoyAsDualJoy(Kernel::HLERequestContext& ctx) { | 513 | void MergeSingleJoyAsDualJoy(Kernel::HLERequestContext& ctx) { |
| @@ -563,8 +525,9 @@ private: | |||
| 563 | void GetVibrationDeviceInfo(Kernel::HLERequestContext& ctx) { | 525 | void GetVibrationDeviceInfo(Kernel::HLERequestContext& ctx) { |
| 564 | IPC::ResponseBuilder rb{ctx, 4}; | 526 | IPC::ResponseBuilder rb{ctx, 4}; |
| 565 | rb.Push(RESULT_SUCCESS); | 527 | rb.Push(RESULT_SUCCESS); |
| 566 | rb.Push<u64>(0); | 528 | rb.Push<u32>(1); |
| 567 | LOG_WARNING(Service_HID, "(STUBBED) called"); | 529 | rb.Push<u32>(0); |
| 530 | LOG_DEBUG(Service_HID, "called"); | ||
| 568 | } | 531 | } |
| 569 | 532 | ||
| 570 | void CreateActiveVibrationDeviceList(Kernel::HLERequestContext& ctx) { | 533 | void CreateActiveVibrationDeviceList(Kernel::HLERequestContext& ctx) { |
| @@ -574,12 +537,6 @@ private: | |||
| 574 | LOG_DEBUG(Service_HID, "called"); | 537 | LOG_DEBUG(Service_HID, "called"); |
| 575 | } | 538 | } |
| 576 | 539 | ||
| 577 | void SendVibrationValues(Kernel::HLERequestContext& ctx) { | ||
| 578 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 579 | rb.Push(RESULT_SUCCESS); | ||
| 580 | LOG_WARNING(Service_HID, "(STUBBED) called"); | ||
| 581 | } | ||
| 582 | |||
| 583 | void ActivateConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) { | 540 | void ActivateConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) { |
| 584 | IPC::ResponseBuilder rb{ctx, 2}; | 541 | IPC::ResponseBuilder rb{ctx, 2}; |
| 585 | rb.Push(RESULT_SUCCESS); | 542 | rb.Push(RESULT_SUCCESS); |
| @@ -597,18 +554,6 @@ private: | |||
| 597 | rb.Push(RESULT_SUCCESS); | 554 | rb.Push(RESULT_SUCCESS); |
| 598 | LOG_WARNING(Service_HID, "(STUBBED) called"); | 555 | LOG_WARNING(Service_HID, "(STUBBED) called"); |
| 599 | } | 556 | } |
| 600 | |||
| 601 | void ActivateGesture(Kernel::HLERequestContext& ctx) { | ||
| 602 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 603 | rb.Push(RESULT_SUCCESS); | ||
| 604 | LOG_WARNING(Service_HID, "(STUBBED) called"); | ||
| 605 | } | ||
| 606 | |||
| 607 | void ActivateNpadWithRevision(Kernel::HLERequestContext& ctx) { | ||
| 608 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 609 | rb.Push(RESULT_SUCCESS); | ||
| 610 | LOG_WARNING(Service_HID, "(STUBBED) called"); | ||
| 611 | } | ||
| 612 | }; | 557 | }; |
| 613 | 558 | ||
| 614 | class HidDbg final : public ServiceFramework<HidDbg> { | 559 | class HidDbg final : public ServiceFramework<HidDbg> { |
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 88d926808..773035460 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h | |||
| @@ -4,408 +4,12 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | 7 | namespace SM { |
| 8 | #include "common/bit_field.h" | 8 | class ServiceManager; |
| 9 | #include "common/common_types.h" | 9 | } |
| 10 | #include "core/hle/service/service.h" | ||
| 11 | 10 | ||
| 12 | namespace Service::HID { | 11 | namespace Service::HID { |
| 13 | 12 | ||
| 14 | // Begin enums and output structs | ||
| 15 | |||
| 16 | constexpr u32 HID_NUM_ENTRIES = 17; | ||
| 17 | constexpr u32 HID_NUM_LAYOUTS = 7; | ||
| 18 | constexpr s32 HID_JOYSTICK_MAX = 0x8000; | ||
| 19 | constexpr s32 HID_JOYSTICK_MIN = -0x8000; | ||
| 20 | |||
| 21 | constexpr u32 JOYCON_BODY_NEON_RED = 0xFF3C28; | ||
| 22 | constexpr u32 JOYCON_BUTTONS_NEON_RED = 0x1E0A0A; | ||
| 23 | constexpr u32 JOYCON_BODY_NEON_BLUE = 0x0AB9E6; | ||
| 24 | constexpr u32 JOYCON_BUTTONS_NEON_BLUE = 0x001E1E; | ||
| 25 | |||
| 26 | enum ControllerType : u32 { | ||
| 27 | ControllerType_ProController = 1 << 0, | ||
| 28 | ControllerType_Handheld = 1 << 1, | ||
| 29 | ControllerType_JoyconPair = 1 << 2, | ||
| 30 | ControllerType_JoyconLeft = 1 << 3, | ||
| 31 | ControllerType_JoyconRight = 1 << 4, | ||
| 32 | }; | ||
| 33 | |||
| 34 | enum ControllerLayoutType : u32 { | ||
| 35 | Layout_ProController = 0, // Pro Controller or HID gamepad | ||
| 36 | Layout_Handheld = 1, // Two Joy-Con docked to rails | ||
| 37 | Layout_Single = 2, // Horizontal single Joy-Con or pair of Joy-Con, adjusted for orientation | ||
| 38 | Layout_Left = 3, // Only raw left Joy-Con state, no orientation adjustment | ||
| 39 | Layout_Right = 4, // Only raw right Joy-Con state, no orientation adjustment | ||
| 40 | Layout_DefaultDigital = 5, // Same as next, but sticks have 8-direction values only | ||
| 41 | Layout_Default = 6, // Safe default, single Joy-Con have buttons/sticks rotated for orientation | ||
| 42 | }; | ||
| 43 | |||
| 44 | enum ControllerColorDescription { | ||
| 45 | ColorDesc_ColorsNonexistent = 1 << 1, | ||
| 46 | }; | ||
| 47 | |||
| 48 | enum ControllerConnectionState { | ||
| 49 | ConnectionState_Connected = 1 << 0, | ||
| 50 | ConnectionState_Wired = 1 << 1, | ||
| 51 | }; | ||
| 52 | |||
| 53 | enum ControllerJoystick { | ||
| 54 | Joystick_Left = 0, | ||
| 55 | Joystick_Right = 1, | ||
| 56 | }; | ||
| 57 | |||
| 58 | enum ControllerID { | ||
| 59 | Controller_Player1 = 0, | ||
| 60 | Controller_Player2 = 1, | ||
| 61 | Controller_Player3 = 2, | ||
| 62 | Controller_Player4 = 3, | ||
| 63 | Controller_Player5 = 4, | ||
| 64 | Controller_Player6 = 5, | ||
| 65 | Controller_Player7 = 6, | ||
| 66 | Controller_Player8 = 7, | ||
| 67 | Controller_Handheld = 8, | ||
| 68 | Controller_Unknown = 9, | ||
| 69 | }; | ||
| 70 | |||
| 71 | // End enums and output structs | ||
| 72 | |||
| 73 | // Begin UnkInput3 | ||
| 74 | |||
| 75 | struct UnkInput3Header { | ||
| 76 | u64 timestamp_ticks; | ||
| 77 | u64 num_entries; | ||
| 78 | u64 latest_entry; | ||
| 79 | u64 max_entry_index; | ||
| 80 | }; | ||
| 81 | static_assert(sizeof(UnkInput3Header) == 0x20, "HID UnkInput3 header structure has incorrect size"); | ||
| 82 | |||
| 83 | struct UnkInput3Entry { | ||
| 84 | u64 timestamp; | ||
| 85 | u64 timestamp_2; | ||
| 86 | u64 unk_8; | ||
| 87 | u64 unk_10; | ||
| 88 | u64 unk_18; | ||
| 89 | }; | ||
| 90 | static_assert(sizeof(UnkInput3Entry) == 0x28, "HID UnkInput3 entry structure has incorrect size"); | ||
| 91 | |||
| 92 | struct UnkInput3 { | ||
| 93 | UnkInput3Header header; | ||
| 94 | std::array<UnkInput3Entry, 17> entries; | ||
| 95 | std::array<u8, 0x138> padding; | ||
| 96 | }; | ||
| 97 | static_assert(sizeof(UnkInput3) == 0x400, "HID UnkInput3 structure has incorrect size"); | ||
| 98 | |||
| 99 | // End UnkInput3 | ||
| 100 | |||
| 101 | // Begin TouchScreen | ||
| 102 | |||
| 103 | struct TouchScreenHeader { | ||
| 104 | u64 timestamp_ticks; | ||
| 105 | u64 num_entries; | ||
| 106 | u64 latest_entry; | ||
| 107 | u64 max_entry_index; | ||
| 108 | u64 timestamp; | ||
| 109 | }; | ||
| 110 | static_assert(sizeof(TouchScreenHeader) == 0x28, | ||
| 111 | "HID touch screen header structure has incorrect size"); | ||
| 112 | |||
| 113 | struct TouchScreenEntryHeader { | ||
| 114 | u64 timestamp; | ||
| 115 | u64 num_touches; | ||
| 116 | }; | ||
| 117 | static_assert(sizeof(TouchScreenEntryHeader) == 0x10, | ||
| 118 | "HID touch screen entry header structure has incorrect size"); | ||
| 119 | |||
| 120 | struct TouchScreenEntryTouch { | ||
| 121 | u64 timestamp; | ||
| 122 | u32 padding; | ||
| 123 | u32 touch_index; | ||
| 124 | u32 x; | ||
| 125 | u32 y; | ||
| 126 | u32 diameter_x; | ||
| 127 | u32 diameter_y; | ||
| 128 | u32 angle; | ||
| 129 | u32 padding_2; | ||
| 130 | }; | ||
| 131 | static_assert(sizeof(TouchScreenEntryTouch) == 0x28, | ||
| 132 | "HID touch screen touch structure has incorrect size"); | ||
| 133 | |||
| 134 | struct TouchScreenEntry { | ||
| 135 | TouchScreenEntryHeader header; | ||
| 136 | std::array<TouchScreenEntryTouch, 16> touches; | ||
| 137 | u64 unk; | ||
| 138 | }; | ||
| 139 | static_assert(sizeof(TouchScreenEntry) == 0x298, | ||
| 140 | "HID touch screen entry structure has incorrect size"); | ||
| 141 | |||
| 142 | struct TouchScreen { | ||
| 143 | TouchScreenHeader header; | ||
| 144 | std::array<TouchScreenEntry, 17> entries; | ||
| 145 | std::array<u8, 0x3c0> padding; | ||
| 146 | }; | ||
| 147 | static_assert(sizeof(TouchScreen) == 0x3000, "HID touch screen structure has incorrect size"); | ||
| 148 | |||
| 149 | // End TouchScreen | ||
| 150 | |||
| 151 | // Begin Mouse | ||
| 152 | |||
| 153 | struct MouseHeader { | ||
| 154 | u64 timestamp_ticks; | ||
| 155 | u64 num_entries; | ||
| 156 | u64 latest_entry; | ||
| 157 | u64 max_entry_index; | ||
| 158 | }; | ||
| 159 | static_assert(sizeof(MouseHeader) == 0x20, "HID mouse header structure has incorrect size"); | ||
| 160 | |||
| 161 | struct MouseButtonState { | ||
| 162 | union { | ||
| 163 | u64 hex{}; | ||
| 164 | |||
| 165 | // Buttons | ||
| 166 | BitField<0, 1, u64> left; | ||
| 167 | BitField<1, 1, u64> right; | ||
| 168 | BitField<2, 1, u64> middle; | ||
| 169 | BitField<3, 1, u64> forward; | ||
| 170 | BitField<4, 1, u64> back; | ||
| 171 | }; | ||
| 172 | }; | ||
| 173 | |||
| 174 | struct MouseEntry { | ||
| 175 | u64 timestamp; | ||
| 176 | u64 timestamp_2; | ||
| 177 | u32 x; | ||
| 178 | u32 y; | ||
| 179 | u32 velocity_x; | ||
| 180 | u32 velocity_y; | ||
| 181 | u32 scroll_velocity_x; | ||
| 182 | u32 scroll_velocity_y; | ||
| 183 | MouseButtonState buttons; | ||
| 184 | }; | ||
| 185 | static_assert(sizeof(MouseEntry) == 0x30, "HID mouse entry structure has incorrect size"); | ||
| 186 | |||
| 187 | struct Mouse { | ||
| 188 | MouseHeader header; | ||
| 189 | std::array<MouseEntry, 17> entries; | ||
| 190 | std::array<u8, 0xB0> padding; | ||
| 191 | }; | ||
| 192 | static_assert(sizeof(Mouse) == 0x400, "HID mouse structure has incorrect size"); | ||
| 193 | |||
| 194 | // End Mouse | ||
| 195 | |||
| 196 | // Begin Keyboard | ||
| 197 | |||
| 198 | struct KeyboardHeader { | ||
| 199 | u64 timestamp_ticks; | ||
| 200 | u64 num_entries; | ||
| 201 | u64 latest_entry; | ||
| 202 | u64 max_entry_index; | ||
| 203 | }; | ||
| 204 | static_assert(sizeof(KeyboardHeader) == 0x20, "HID keyboard header structure has incorrect size"); | ||
| 205 | |||
| 206 | struct KeyboardModifierKeyState { | ||
| 207 | union { | ||
| 208 | u64 hex{}; | ||
| 209 | |||
| 210 | // Buttons | ||
| 211 | BitField<0, 1, u64> lctrl; | ||
| 212 | BitField<1, 1, u64> lshift; | ||
| 213 | BitField<2, 1, u64> lalt; | ||
| 214 | BitField<3, 1, u64> lmeta; | ||
| 215 | BitField<4, 1, u64> rctrl; | ||
| 216 | BitField<5, 1, u64> rshift; | ||
| 217 | BitField<6, 1, u64> ralt; | ||
| 218 | BitField<7, 1, u64> rmeta; | ||
| 219 | BitField<8, 1, u64> capslock; | ||
| 220 | BitField<9, 1, u64> scrolllock; | ||
| 221 | BitField<10, 1, u64> numlock; | ||
| 222 | }; | ||
| 223 | }; | ||
| 224 | |||
| 225 | struct KeyboardEntry { | ||
| 226 | u64 timestamp; | ||
| 227 | u64 timestamp_2; | ||
| 228 | KeyboardModifierKeyState modifier; | ||
| 229 | u32 keys[8]; | ||
| 230 | }; | ||
| 231 | static_assert(sizeof(KeyboardEntry) == 0x38, "HID keyboard entry structure has incorrect size"); | ||
| 232 | |||
| 233 | struct Keyboard { | ||
| 234 | KeyboardHeader header; | ||
| 235 | std::array<KeyboardEntry, 17> entries; | ||
| 236 | std::array<u8, 0x28> padding; | ||
| 237 | }; | ||
| 238 | static_assert(sizeof(Keyboard) == 0x400, "HID keyboard structure has incorrect size"); | ||
| 239 | |||
| 240 | // End Keyboard | ||
| 241 | |||
| 242 | // Begin UnkInput1 | ||
| 243 | |||
| 244 | struct UnkInput1Header { | ||
| 245 | u64 timestamp_ticks; | ||
| 246 | u64 num_entries; | ||
| 247 | u64 latest_entry; | ||
| 248 | u64 max_entry_index; | ||
| 249 | }; | ||
| 250 | static_assert(sizeof(UnkInput1Header) == 0x20, "HID UnkInput1 header structure has incorrect size"); | ||
| 251 | |||
| 252 | struct UnkInput1Entry { | ||
| 253 | u64 timestamp; | ||
| 254 | u64 timestamp_2; | ||
| 255 | u64 unk_8; | ||
| 256 | u64 unk_10; | ||
| 257 | u64 unk_18; | ||
| 258 | }; | ||
| 259 | static_assert(sizeof(UnkInput1Entry) == 0x28, "HID UnkInput1 entry structure has incorrect size"); | ||
| 260 | |||
| 261 | struct UnkInput1 { | ||
| 262 | UnkInput1Header header; | ||
| 263 | std::array<UnkInput1Entry, 17> entries; | ||
| 264 | std::array<u8, 0x138> padding; | ||
| 265 | }; | ||
| 266 | static_assert(sizeof(UnkInput1) == 0x400, "HID UnkInput1 structure has incorrect size"); | ||
| 267 | |||
| 268 | // End UnkInput1 | ||
| 269 | |||
| 270 | // Begin UnkInput2 | ||
| 271 | |||
| 272 | struct UnkInput2Header { | ||
| 273 | u64 timestamp_ticks; | ||
| 274 | u64 num_entries; | ||
| 275 | u64 latest_entry; | ||
| 276 | u64 max_entry_index; | ||
| 277 | }; | ||
| 278 | static_assert(sizeof(UnkInput2Header) == 0x20, "HID UnkInput2 header structure has incorrect size"); | ||
| 279 | |||
| 280 | struct UnkInput2 { | ||
| 281 | UnkInput2Header header; | ||
| 282 | std::array<u8, 0x1E0> padding; | ||
| 283 | }; | ||
| 284 | static_assert(sizeof(UnkInput2) == 0x200, "HID UnkInput2 structure has incorrect size"); | ||
| 285 | |||
| 286 | // End UnkInput2 | ||
| 287 | |||
| 288 | // Begin Controller | ||
| 289 | |||
| 290 | struct ControllerMAC { | ||
| 291 | u64 timestamp; | ||
| 292 | std::array<u8, 0x8> mac; | ||
| 293 | u64 unk; | ||
| 294 | u64 timestamp_2; | ||
| 295 | }; | ||
| 296 | static_assert(sizeof(ControllerMAC) == 0x20, "HID controller MAC structure has incorrect size"); | ||
| 297 | |||
| 298 | struct ControllerHeader { | ||
| 299 | u32 type; | ||
| 300 | u32 is_half; | ||
| 301 | u32 single_colors_descriptor; | ||
| 302 | u32 single_color_body; | ||
| 303 | u32 single_color_buttons; | ||
| 304 | u32 split_colors_descriptor; | ||
| 305 | u32 left_color_body; | ||
| 306 | u32 left_color_buttons; | ||
| 307 | u32 right_color_body; | ||
| 308 | u32 right_color_buttons; | ||
| 309 | }; | ||
| 310 | static_assert(sizeof(ControllerHeader) == 0x28, | ||
| 311 | "HID controller header structure has incorrect size"); | ||
| 312 | |||
| 313 | struct ControllerLayoutHeader { | ||
| 314 | u64 timestamp_ticks; | ||
| 315 | u64 num_entries; | ||
| 316 | u64 latest_entry; | ||
| 317 | u64 max_entry_index; | ||
| 318 | }; | ||
| 319 | static_assert(sizeof(ControllerLayoutHeader) == 0x20, | ||
| 320 | "HID controller layout header structure has incorrect size"); | ||
| 321 | |||
| 322 | struct ControllerPadState { | ||
| 323 | union { | ||
| 324 | u64 hex{}; | ||
| 325 | |||
| 326 | // Buttons | ||
| 327 | BitField<0, 1, u64> a; | ||
| 328 | BitField<1, 1, u64> b; | ||
| 329 | BitField<2, 1, u64> x; | ||
| 330 | BitField<3, 1, u64> y; | ||
| 331 | BitField<4, 1, u64> lstick; | ||
| 332 | BitField<5, 1, u64> rstick; | ||
| 333 | BitField<6, 1, u64> l; | ||
| 334 | BitField<7, 1, u64> r; | ||
| 335 | BitField<8, 1, u64> zl; | ||
| 336 | BitField<9, 1, u64> zr; | ||
| 337 | BitField<10, 1, u64> plus; | ||
| 338 | BitField<11, 1, u64> minus; | ||
| 339 | |||
| 340 | // D-pad buttons | ||
| 341 | BitField<12, 1, u64> dleft; | ||
| 342 | BitField<13, 1, u64> dup; | ||
| 343 | BitField<14, 1, u64> dright; | ||
| 344 | BitField<15, 1, u64> ddown; | ||
| 345 | |||
| 346 | // Left stick directions | ||
| 347 | BitField<16, 1, u64> lstick_left; | ||
| 348 | BitField<17, 1, u64> lstick_up; | ||
| 349 | BitField<18, 1, u64> lstick_right; | ||
| 350 | BitField<19, 1, u64> lstick_down; | ||
| 351 | |||
| 352 | // Right stick directions | ||
| 353 | BitField<20, 1, u64> rstick_left; | ||
| 354 | BitField<21, 1, u64> rstick_up; | ||
| 355 | BitField<22, 1, u64> rstick_right; | ||
| 356 | BitField<23, 1, u64> rstick_down; | ||
| 357 | |||
| 358 | BitField<24, 1, u64> sl; | ||
| 359 | BitField<25, 1, u64> sr; | ||
| 360 | }; | ||
| 361 | }; | ||
| 362 | |||
| 363 | struct ControllerInputEntry { | ||
| 364 | u64 timestamp; | ||
| 365 | u64 timestamp_2; | ||
| 366 | ControllerPadState buttons; | ||
| 367 | s32 joystick_left_x; | ||
| 368 | s32 joystick_left_y; | ||
| 369 | s32 joystick_right_x; | ||
| 370 | s32 joystick_right_y; | ||
| 371 | u64 connection_state; | ||
| 372 | }; | ||
| 373 | static_assert(sizeof(ControllerInputEntry) == 0x30, | ||
| 374 | "HID controller input entry structure has incorrect size"); | ||
| 375 | |||
| 376 | struct ControllerLayout { | ||
| 377 | ControllerLayoutHeader header; | ||
| 378 | std::array<ControllerInputEntry, 17> entries; | ||
| 379 | }; | ||
| 380 | static_assert(sizeof(ControllerLayout) == 0x350, | ||
| 381 | "HID controller layout structure has incorrect size"); | ||
| 382 | |||
| 383 | struct Controller { | ||
| 384 | ControllerHeader header; | ||
| 385 | std::array<ControllerLayout, HID_NUM_LAYOUTS> layouts; | ||
| 386 | std::array<u8, 0x2a70> unk_1; | ||
| 387 | ControllerMAC mac_left; | ||
| 388 | ControllerMAC mac_right; | ||
| 389 | std::array<u8, 0xdf8> unk_2; | ||
| 390 | }; | ||
| 391 | static_assert(sizeof(Controller) == 0x5000, "HID controller structure has incorrect size"); | ||
| 392 | |||
| 393 | // End Controller | ||
| 394 | |||
| 395 | struct SharedMemory { | ||
| 396 | UnkInput3 unk_input_3; | ||
| 397 | TouchScreen touchscreen; | ||
| 398 | Mouse mouse; | ||
| 399 | Keyboard keyboard; | ||
| 400 | std::array<UnkInput1, 4> unk_input_1; | ||
| 401 | std::array<UnkInput2, 3> unk_input_2; | ||
| 402 | std::array<u8, 0x800> unk_section_8; | ||
| 403 | std::array<u8, 0x4000> controller_serials; | ||
| 404 | std::array<Controller, 10> controllers; | ||
| 405 | std::array<u8, 0x4600> unk_section_9; | ||
| 406 | }; | ||
| 407 | static_assert(sizeof(SharedMemory) == 0x40000, "HID Shared Memory structure has incorrect size"); | ||
| 408 | |||
| 409 | /// Reload input devices. Used when input configuration changed | 13 | /// Reload input devices. Used when input configuration changed |
| 410 | void ReloadInputDevices(); | 14 | void ReloadInputDevices(); |
| 411 | 15 | ||
diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp index 8c07a05c2..39c0c1e63 100644 --- a/src/core/hle/service/nfp/nfp.cpp +++ b/src/core/hle/service/nfp/nfp.cpp | |||
| @@ -144,7 +144,7 @@ private: | |||
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | const u64 device_handle{0xDEAD}; | 146 | const u64 device_handle{0xDEAD}; |
| 147 | const HID::ControllerID npad_id{HID::Controller_Player1}; | 147 | const u32 npad_id{0}; // This is the first player controller id |
| 148 | State state{State::NonInitialized}; | 148 | State state{State::NonInitialized}; |
| 149 | DeviceState device_state{DeviceState::Initialized}; | 149 | DeviceState device_state{DeviceState::Initialized}; |
| 150 | Kernel::SharedPtr<Kernel::Event> activate_event; | 150 | Kernel::SharedPtr<Kernel::Event> activate_event; |