|
|
@ -35,9 +35,9 @@ namespace Service::HID {
|
|
|
|
|
|
|
|
|
|
|
|
// Updating period for each HID device.
|
|
|
|
// Updating period for each HID device.
|
|
|
|
// Period time is obtained by measuring the number of samples in a second on HW using a homebrew
|
|
|
|
// 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 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 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 auto motion_update_ns = std::chrono::nanoseconds{5 * 1000 * 1000}; // (5ms, 200Hz)
|
|
|
|
constexpr std::size_t SHARED_MEMORY_SIZE = 0x40000;
|
|
|
|
constexpr std::size_t SHARED_MEMORY_SIZE = 0x40000;
|
|
|
|
|
|
|
|
|
|
|
|
IAppletResource::IAppletResource(Core::System& system_,
|
|
|
|
IAppletResource::IAppletResource(Core::System& system_,
|
|
|
@ -79,11 +79,11 @@ IAppletResource::IAppletResource(Core::System& system_,
|
|
|
|
const auto guard = LockService();
|
|
|
|
const auto guard = LockService();
|
|
|
|
UpdateControllers(user_data, ns_late);
|
|
|
|
UpdateControllers(user_data, ns_late);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
keyboard_update_event = Core::Timing::CreateEvent(
|
|
|
|
mouse_keyboard_update_event = Core::Timing::CreateEvent(
|
|
|
|
"HID::UpdatekeyboardCallback",
|
|
|
|
"HID::UpdateMouseKeyboardCallback",
|
|
|
|
[this](std::uintptr_t user_data, std::chrono::nanoseconds ns_late) {
|
|
|
|
[this](std::uintptr_t user_data, std::chrono::nanoseconds ns_late) {
|
|
|
|
const auto guard = LockService();
|
|
|
|
const auto guard = LockService();
|
|
|
|
UpdateKeyboard(user_data, ns_late);
|
|
|
|
UpdateMouseKeyboard(user_data, ns_late);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
motion_update_event = Core::Timing::CreateEvent(
|
|
|
|
motion_update_event = Core::Timing::CreateEvent(
|
|
|
|
"HID::UpdateMotionCallback",
|
|
|
|
"HID::UpdateMotionCallback",
|
|
|
@ -93,7 +93,7 @@ IAppletResource::IAppletResource(Core::System& system_,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
system.CoreTiming().ScheduleEvent(pad_update_ns, pad_update_event);
|
|
|
|
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.CoreTiming().ScheduleEvent(motion_update_ns, motion_update_event);
|
|
|
|
|
|
|
|
|
|
|
|
system.HIDCore().ReloadInputDevices();
|
|
|
|
system.HIDCore().ReloadInputDevices();
|
|
|
@ -109,7 +109,7 @@ void IAppletResource::DeactivateController(HidController controller) {
|
|
|
|
|
|
|
|
|
|
|
|
IAppletResource::~IAppletResource() {
|
|
|
|
IAppletResource::~IAppletResource() {
|
|
|
|
system.CoreTiming().UnscheduleEvent(pad_update_event, 0);
|
|
|
|
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);
|
|
|
|
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)]) {
|
|
|
|
if (controller == controllers[static_cast<size_t>(HidController::Keyboard)]) {
|
|
|
|
continue;
|
|
|
|
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(),
|
|
|
|
controller->OnUpdate(core_timing, system.Kernel().GetHidSharedMem().GetPointer(),
|
|
|
|
SHARED_MEMORY_SIZE);
|
|
|
|
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);
|
|
|
|
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();
|
|
|
|
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(
|
|
|
|
controllers[static_cast<size_t>(HidController::Keyboard)]->OnUpdate(
|
|
|
|
core_timing, system.Kernel().GetHidSharedMem().GetPointer(), SHARED_MEMORY_SIZE);
|
|
|
|
core_timing, system.Kernel().GetHidSharedMem().GetPointer(), SHARED_MEMORY_SIZE);
|
|
|
|
|
|
|
|
|
|
|
|
// If ns_late is higher than the update rate ignore the delay
|
|
|
|
// 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 = {};
|
|
|
|
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) {
|
|
|
|
void IAppletResource::UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) {
|
|
|
|