summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/hid
diff options
context:
space:
mode:
authorgerman77 <juangerman-13@hotmail.com>2021-11-15 04:28:38 +0100
committerNarr the Reg <juangerman-13@hotmail.com>2021-11-25 03:30:28 +0100
commitf4e5f89e6fb9d68cd4ba7d98c281584c50f0e149 (patch)
tree9e9f9114d9b7528e74e78102279411595632f048 /src/core/hle/service/hid
parentcore/hid: Fully implement native mouse (diff)
downloadyuzu-f4e5f89e6fb9d68cd4ba7d98c281584c50f0e149.tar
yuzu-f4e5f89e6fb9d68cd4ba7d98c281584c50f0e149.tar.gz
yuzu-f4e5f89e6fb9d68cd4ba7d98c281584c50f0e149.tar.bz2
yuzu-f4e5f89e6fb9d68cd4ba7d98c281584c50f0e149.tar.lz
yuzu-f4e5f89e6fb9d68cd4ba7d98c281584c50f0e149.tar.xz
yuzu-f4e5f89e6fb9d68cd4ba7d98c281584c50f0e149.tar.zst
yuzu-f4e5f89e6fb9d68cd4ba7d98c281584c50f0e149.zip
Diffstat (limited to 'src/core/hle/service/hid')
-rw-r--r--src/core/hle/service/hid/controllers/keyboard.cpp3
-rw-r--r--src/core/hle/service/hid/controllers/keyboard.h1
-rw-r--r--src/core/hle/service/hid/controllers/mouse.cpp7
-rw-r--r--src/core/hle/service/hid/controllers/mouse.h2
-rw-r--r--src/core/hle/service/hid/hid.cpp29
-rw-r--r--src/core/hle/service/hid/hid.h4
6 files changed, 28 insertions, 18 deletions
diff --git a/src/core/hle/service/hid/controllers/keyboard.cpp b/src/core/hle/service/hid/controllers/keyboard.cpp
index 0ef8af0e6..9588a6910 100644
--- a/src/core/hle/service/hid/controllers/keyboard.cpp
+++ b/src/core/hle/service/hid/controllers/keyboard.cpp
@@ -42,8 +42,7 @@ void Controller_Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing,
next_state.key = keyboard_state;
next_state.modifier = keyboard_modifier_state;
- // This is always enabled on HW. Check what it actually does
- next_state.modifier.unknown.Assign(1);
+ next_state.attribute.is_connected.Assign(1);
}
keyboard_lifo.WriteNextEntry(next_state);
diff --git a/src/core/hle/service/hid/controllers/keyboard.h b/src/core/hle/service/hid/controllers/keyboard.h
index ec5dd607c..0d61cb470 100644
--- a/src/core/hle/service/hid/controllers/keyboard.h
+++ b/src/core/hle/service/hid/controllers/keyboard.h
@@ -38,6 +38,7 @@ private:
struct KeyboardState {
s64 sampling_number;
Core::HID::KeyboardModifier modifier;
+ Core::HID::KeyboardAttribute attribute;
Core::HID::KeyboardKey key;
};
static_assert(sizeof(KeyboardState) == 0x30, "KeyboardState is an invalid size");
diff --git a/src/core/hle/service/hid/controllers/mouse.cpp b/src/core/hle/service/hid/controllers/mouse.cpp
index 9c408e7f4..ba79888ae 100644
--- a/src/core/hle/service/hid/controllers/mouse.cpp
+++ b/src/core/hle/service/hid/controllers/mouse.cpp
@@ -38,15 +38,16 @@ void Controller_Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8*
if (Settings::values.mouse_enabled) {
const auto& mouse_button_state = emulated_devices->GetMouseButtons();
const auto& mouse_position_state = emulated_devices->GetMousePosition();
- const auto& mouse_wheel_state = emulated_devices->GetMouseDeltaWheel();
+ const auto& mouse_wheel_state = emulated_devices->GetMouseWheel();
next_state.attribute.is_connected.Assign(1);
next_state.x = static_cast<s32>(mouse_position_state.x * Layout::ScreenUndocked::Width);
next_state.y = static_cast<s32>(mouse_position_state.y * Layout::ScreenUndocked::Height);
next_state.delta_x = next_state.x - last_entry.x;
next_state.delta_y = next_state.y - last_entry.y;
- next_state.delta_wheel_x = mouse_wheel_state.x;
- next_state.delta_wheel_y = mouse_wheel_state.y;
+ next_state.delta_wheel_x = mouse_wheel_state.x - last_mouse_wheel_state.x;
+ next_state.delta_wheel_y = mouse_wheel_state.y - last_mouse_wheel_state.y;
+ last_mouse_wheel_state = mouse_wheel_state;
next_state.button = mouse_button_state;
}
diff --git a/src/core/hle/service/hid/controllers/mouse.h b/src/core/hle/service/hid/controllers/mouse.h
index 25017f117..1ac69aa6f 100644
--- a/src/core/hle/service/hid/controllers/mouse.h
+++ b/src/core/hle/service/hid/controllers/mouse.h
@@ -14,6 +14,7 @@
namespace Core::HID {
class EmulatedDevices;
struct MouseState;
+struct AnalogStickState;
} // namespace Core::HID
namespace Service::HID {
@@ -37,6 +38,7 @@ private:
static_assert(sizeof(mouse_lifo) == 0x350, "mouse_lifo is an invalid size");
Core::HID::MouseState next_state{};
+ Core::HID::AnalogStickState last_mouse_wheel_state;
Core::HID::EmulatedDevices* emulated_devices;
};
} // namespace Service::HID
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index e740b4331..95fc07325 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -35,9 +35,9 @@ namespace Service::HID {
// Updating period for each HID device.
// Period time is obtained by measuring the number of samples in a second on HW using a homebrew
-constexpr auto pad_update_ns = std::chrono::nanoseconds{4 * 1000 * 1000}; // (4ms, 250Hz)
-constexpr auto keyboard_update_ns = std::chrono::nanoseconds{8 * 1000 * 1000}; // (8ms, 125Hz)
-constexpr auto motion_update_ns = std::chrono::nanoseconds{5 * 1000 * 1000}; // (5ms, 200Hz)
+constexpr auto pad_update_ns = std::chrono::nanoseconds{4 * 1000 * 1000}; // (4ms, 250Hz)
+constexpr auto mouse_keyboard_update_ns = std::chrono::nanoseconds{8 * 1000 * 1000}; // (8ms, 125Hz)
+constexpr auto motion_update_ns = std::chrono::nanoseconds{5 * 1000 * 1000}; // (5ms, 200Hz)
constexpr std::size_t SHARED_MEMORY_SIZE = 0x40000;
IAppletResource::IAppletResource(Core::System& system_,
@@ -79,11 +79,11 @@ IAppletResource::IAppletResource(Core::System& system_,
const auto guard = LockService();
UpdateControllers(user_data, ns_late);
});
- keyboard_update_event = Core::Timing::CreateEvent(
- "HID::UpdatekeyboardCallback",
+ mouse_keyboard_update_event = Core::Timing::CreateEvent(
+ "HID::UpdateMouseKeyboardCallback",
[this](std::uintptr_t user_data, std::chrono::nanoseconds ns_late) {
const auto guard = LockService();
- UpdateKeyboard(user_data, ns_late);
+ UpdateMouseKeyboard(user_data, ns_late);
});
motion_update_event = Core::Timing::CreateEvent(
"HID::UpdateMotionCallback",
@@ -93,7 +93,7 @@ IAppletResource::IAppletResource(Core::System& system_,
});
system.CoreTiming().ScheduleEvent(pad_update_ns, pad_update_event);
- system.CoreTiming().ScheduleEvent(keyboard_update_ns, keyboard_update_event);
+ system.CoreTiming().ScheduleEvent(mouse_keyboard_update_ns, mouse_keyboard_update_event);
system.CoreTiming().ScheduleEvent(motion_update_ns, motion_update_event);
system.HIDCore().ReloadInputDevices();
@@ -109,7 +109,7 @@ void IAppletResource::DeactivateController(HidController controller) {
IAppletResource::~IAppletResource() {
system.CoreTiming().UnscheduleEvent(pad_update_event, 0);
- system.CoreTiming().UnscheduleEvent(keyboard_update_event, 0);
+ system.CoreTiming().UnscheduleEvent(mouse_keyboard_update_event, 0);
system.CoreTiming().UnscheduleEvent(motion_update_event, 0);
}
@@ -130,6 +130,10 @@ void IAppletResource::UpdateControllers(std::uintptr_t user_data,
if (controller == controllers[static_cast<size_t>(HidController::Keyboard)]) {
continue;
}
+ // Mouse has it's own update event
+ if (controller == controllers[static_cast<size_t>(HidController::Mouse)]) {
+ continue;
+ }
controller->OnUpdate(core_timing, system.Kernel().GetHidSharedMem().GetPointer(),
SHARED_MEMORY_SIZE);
}
@@ -142,18 +146,21 @@ void IAppletResource::UpdateControllers(std::uintptr_t user_data,
core_timing.ScheduleEvent(pad_update_ns - ns_late, pad_update_event);
}
-void IAppletResource::UpdateKeyboard(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) {
+void IAppletResource::UpdateMouseKeyboard(std::uintptr_t user_data,
+ std::chrono::nanoseconds ns_late) {
auto& core_timing = system.CoreTiming();
+ controllers[static_cast<size_t>(HidController::Mouse)]->OnUpdate(
+ core_timing, system.Kernel().GetHidSharedMem().GetPointer(), SHARED_MEMORY_SIZE);
controllers[static_cast<size_t>(HidController::Keyboard)]->OnUpdate(
core_timing, system.Kernel().GetHidSharedMem().GetPointer(), SHARED_MEMORY_SIZE);
// If ns_late is higher than the update rate ignore the delay
- if (ns_late > keyboard_update_ns) {
+ if (ns_late > mouse_keyboard_update_ns) {
ns_late = {};
}
- core_timing.ScheduleEvent(keyboard_update_ns - ns_late, keyboard_update_event);
+ core_timing.ScheduleEvent(mouse_keyboard_update_ns - ns_late, mouse_keyboard_update_event);
}
void IAppletResource::UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) {
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h
index bbad165f8..ab0084118 100644
--- a/src/core/hle/service/hid/hid.h
+++ b/src/core/hle/service/hid/hid.h
@@ -70,13 +70,13 @@ private:
void GetSharedMemoryHandle(Kernel::HLERequestContext& ctx);
void UpdateControllers(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
- void UpdateKeyboard(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
+ void UpdateMouseKeyboard(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
void UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
KernelHelpers::ServiceContext& service_context;
std::shared_ptr<Core::Timing::EventType> pad_update_event;
- std::shared_ptr<Core::Timing::EventType> keyboard_update_event;
+ std::shared_ptr<Core::Timing::EventType> mouse_keyboard_update_event;
std::shared_ptr<Core::Timing::EventType> motion_update_event;
std::array<std::unique_ptr<ControllerBase>, static_cast<size_t>(HidController::MaxControllers)>