mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2024-11-30 00:54:28 +01:00
Merge yuzu-emu#12877
This commit is contained in:
parent
1f0a2b4889
commit
5eac8567ee
@ -52,9 +52,42 @@ ResourceManager::ResourceManager(Core::System& system_,
|
|||||||
std::shared_ptr<HidFirmwareSettings> settings)
|
std::shared_ptr<HidFirmwareSettings> settings)
|
||||||
: firmware_settings{settings}, system{system_}, service_context{system_, "hid"} {
|
: firmware_settings{settings}, system{system_}, service_context{system_, "hid"} {
|
||||||
applet_resource = std::make_shared<AppletResource>(system);
|
applet_resource = std::make_shared<AppletResource>(system);
|
||||||
|
|
||||||
|
// Register update callbacks
|
||||||
|
npad_update_event = Core::Timing::CreateEvent("HID::UpdatePadCallback",
|
||||||
|
[this](s64 time, std::chrono::nanoseconds ns_late)
|
||||||
|
-> std::optional<std::chrono::nanoseconds> {
|
||||||
|
UpdateNpad(ns_late);
|
||||||
|
return std::nullopt;
|
||||||
|
});
|
||||||
|
default_update_event = Core::Timing::CreateEvent(
|
||||||
|
"HID::UpdateDefaultCallback",
|
||||||
|
[this](s64 time,
|
||||||
|
std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> {
|
||||||
|
UpdateControllers(ns_late);
|
||||||
|
return std::nullopt;
|
||||||
|
});
|
||||||
|
mouse_keyboard_update_event = Core::Timing::CreateEvent(
|
||||||
|
"HID::UpdateMouseKeyboardCallback",
|
||||||
|
[this](s64 time,
|
||||||
|
std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> {
|
||||||
|
UpdateMouseKeyboard(ns_late);
|
||||||
|
return std::nullopt;
|
||||||
|
});
|
||||||
|
motion_update_event = Core::Timing::CreateEvent(
|
||||||
|
"HID::UpdateMotionCallback",
|
||||||
|
[this](s64 time,
|
||||||
|
std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> {
|
||||||
|
UpdateMotion(ns_late);
|
||||||
|
return std::nullopt;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceManager::~ResourceManager() {
|
ResourceManager::~ResourceManager() {
|
||||||
|
system.CoreTiming().UnscheduleEvent(npad_update_event);
|
||||||
|
system.CoreTiming().UnscheduleEvent(default_update_event);
|
||||||
|
system.CoreTiming().UnscheduleEvent(mouse_keyboard_update_event);
|
||||||
|
system.CoreTiming().UnscheduleEvent(motion_update_event);
|
||||||
system.CoreTiming().UnscheduleEvent(touch_update_event);
|
system.CoreTiming().UnscheduleEvent(touch_update_event);
|
||||||
input_event->Finalize();
|
input_event->Finalize();
|
||||||
};
|
};
|
||||||
@ -201,6 +234,7 @@ void ResourceManager::InitializeHidCommonSampler() {
|
|||||||
|
|
||||||
debug_pad->SetAppletResource(applet_resource, &shared_mutex);
|
debug_pad->SetAppletResource(applet_resource, &shared_mutex);
|
||||||
digitizer->SetAppletResource(applet_resource, &shared_mutex);
|
digitizer->SetAppletResource(applet_resource, &shared_mutex);
|
||||||
|
unique_pad->SetAppletResource(applet_resource, &shared_mutex);
|
||||||
keyboard->SetAppletResource(applet_resource, &shared_mutex);
|
keyboard->SetAppletResource(applet_resource, &shared_mutex);
|
||||||
|
|
||||||
const auto settings =
|
const auto settings =
|
||||||
@ -214,6 +248,14 @@ void ResourceManager::InitializeHidCommonSampler() {
|
|||||||
home_button->SetAppletResource(applet_resource, &shared_mutex);
|
home_button->SetAppletResource(applet_resource, &shared_mutex);
|
||||||
sleep_button->SetAppletResource(applet_resource, &shared_mutex);
|
sleep_button->SetAppletResource(applet_resource, &shared_mutex);
|
||||||
capture_button->SetAppletResource(applet_resource, &shared_mutex);
|
capture_button->SetAppletResource(applet_resource, &shared_mutex);
|
||||||
|
|
||||||
|
system.CoreTiming().ScheduleLoopingEvent(npad_update_ns, npad_update_ns, npad_update_event);
|
||||||
|
system.CoreTiming().ScheduleLoopingEvent(default_update_ns, default_update_ns,
|
||||||
|
default_update_event);
|
||||||
|
system.CoreTiming().ScheduleLoopingEvent(mouse_keyboard_update_ns, mouse_keyboard_update_ns,
|
||||||
|
mouse_keyboard_update_event);
|
||||||
|
system.CoreTiming().ScheduleLoopingEvent(motion_update_ns, motion_update_ns,
|
||||||
|
motion_update_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceManager::InitializeTouchScreenSampler() {
|
void ResourceManager::InitializeTouchScreenSampler() {
|
||||||
@ -465,55 +507,9 @@ IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr<Resource
|
|||||||
{0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"},
|
{0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"},
|
||||||
};
|
};
|
||||||
RegisterHandlers(functions);
|
RegisterHandlers(functions);
|
||||||
|
|
||||||
// Register update callbacks
|
|
||||||
npad_update_event = Core::Timing::CreateEvent(
|
|
||||||
"HID::UpdatePadCallback",
|
|
||||||
[this, resource](
|
|
||||||
s64 time, std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> {
|
|
||||||
const auto guard = LockService();
|
|
||||||
resource->UpdateNpad(ns_late);
|
|
||||||
return std::nullopt;
|
|
||||||
});
|
|
||||||
default_update_event = Core::Timing::CreateEvent(
|
|
||||||
"HID::UpdateDefaultCallback",
|
|
||||||
[this, resource](
|
|
||||||
s64 time, std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> {
|
|
||||||
const auto guard = LockService();
|
|
||||||
resource->UpdateControllers(ns_late);
|
|
||||||
return std::nullopt;
|
|
||||||
});
|
|
||||||
mouse_keyboard_update_event = Core::Timing::CreateEvent(
|
|
||||||
"HID::UpdateMouseKeyboardCallback",
|
|
||||||
[this, resource](
|
|
||||||
s64 time, std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> {
|
|
||||||
const auto guard = LockService();
|
|
||||||
resource->UpdateMouseKeyboard(ns_late);
|
|
||||||
return std::nullopt;
|
|
||||||
});
|
|
||||||
motion_update_event = Core::Timing::CreateEvent(
|
|
||||||
"HID::UpdateMotionCallback",
|
|
||||||
[this, resource](
|
|
||||||
s64 time, std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> {
|
|
||||||
const auto guard = LockService();
|
|
||||||
resource->UpdateMotion(ns_late);
|
|
||||||
return std::nullopt;
|
|
||||||
});
|
|
||||||
|
|
||||||
system.CoreTiming().ScheduleLoopingEvent(npad_update_ns, npad_update_ns, npad_update_event);
|
|
||||||
system.CoreTiming().ScheduleLoopingEvent(default_update_ns, default_update_ns,
|
|
||||||
default_update_event);
|
|
||||||
system.CoreTiming().ScheduleLoopingEvent(mouse_keyboard_update_ns, mouse_keyboard_update_ns,
|
|
||||||
mouse_keyboard_update_event);
|
|
||||||
system.CoreTiming().ScheduleLoopingEvent(motion_update_ns, motion_update_ns,
|
|
||||||
motion_update_event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IAppletResource::~IAppletResource() {
|
IAppletResource::~IAppletResource() {
|
||||||
system.CoreTiming().UnscheduleEvent(npad_update_event);
|
|
||||||
system.CoreTiming().UnscheduleEvent(default_update_event);
|
|
||||||
system.CoreTiming().UnscheduleEvent(mouse_keyboard_update_event);
|
|
||||||
system.CoreTiming().UnscheduleEvent(motion_update_event);
|
|
||||||
resource_manager->FreeAppletResourceId(aruid);
|
resource_manager->FreeAppletResourceId(aruid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,6 +147,10 @@ private:
|
|||||||
std::shared_ptr<SixAxis> six_axis{nullptr};
|
std::shared_ptr<SixAxis> six_axis{nullptr};
|
||||||
std::shared_ptr<SleepButton> sleep_button{nullptr};
|
std::shared_ptr<SleepButton> sleep_button{nullptr};
|
||||||
std::shared_ptr<UniquePad> unique_pad{nullptr};
|
std::shared_ptr<UniquePad> unique_pad{nullptr};
|
||||||
|
std::shared_ptr<Core::Timing::EventType> npad_update_event;
|
||||||
|
std::shared_ptr<Core::Timing::EventType> default_update_event;
|
||||||
|
std::shared_ptr<Core::Timing::EventType> mouse_keyboard_update_event;
|
||||||
|
std::shared_ptr<Core::Timing::EventType> motion_update_event;
|
||||||
|
|
||||||
// TODO: Create these resources
|
// TODO: Create these resources
|
||||||
// std::shared_ptr<AudioControl> audio_control{nullptr};
|
// std::shared_ptr<AudioControl> audio_control{nullptr};
|
||||||
@ -179,11 +183,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
void GetSharedMemoryHandle(HLERequestContext& ctx);
|
void GetSharedMemoryHandle(HLERequestContext& ctx);
|
||||||
|
|
||||||
std::shared_ptr<Core::Timing::EventType> npad_update_event{nullptr};
|
|
||||||
std::shared_ptr<Core::Timing::EventType> default_update_event{nullptr};
|
|
||||||
std::shared_ptr<Core::Timing::EventType> mouse_keyboard_update_event{nullptr};
|
|
||||||
std::shared_ptr<Core::Timing::EventType> motion_update_event{nullptr};
|
|
||||||
|
|
||||||
u64 aruid{};
|
u64 aruid{};
|
||||||
std::shared_ptr<ResourceManager> resource_manager;
|
std::shared_ptr<ResourceManager> resource_manager;
|
||||||
};
|
};
|
||||||
|
@ -17,10 +17,6 @@ void Digitizer::OnInit() {}
|
|||||||
void Digitizer::OnRelease() {}
|
void Digitizer::OnRelease() {}
|
||||||
|
|
||||||
void Digitizer::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
void Digitizer::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||||
if (!smart_update) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::scoped_lock shared_lock{*shared_mutex};
|
std::scoped_lock shared_lock{*shared_mutex};
|
||||||
const u64 aruid = applet_resource->GetActiveAruid();
|
const u64 aruid = applet_resource->GetActiveAruid();
|
||||||
auto* data = applet_resource->GetAruidData(aruid);
|
auto* data = applet_resource->GetAruidData(aruid);
|
||||||
|
@ -20,8 +20,5 @@ public:
|
|||||||
|
|
||||||
// When the controller is requesting an update for the shared memory
|
// When the controller is requesting an update for the shared memory
|
||||||
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
|
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
|
||||||
|
|
||||||
private:
|
|
||||||
bool smart_update{};
|
|
||||||
};
|
};
|
||||||
} // namespace Service::HID
|
} // namespace Service::HID
|
||||||
|
@ -102,6 +102,8 @@ Result NPad::Activate(u64 aruid) {
|
|||||||
for (std::size_t i = 0; i < 19; ++i) {
|
for (std::size_t i = 0; i < 19; ++i) {
|
||||||
WriteEmptyEntry(npad);
|
WriteEmptyEntry(npad);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
controller.is_active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
@ -467,6 +469,13 @@ void NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_set{};
|
||||||
|
npad_resource.IsSupportedNpadStyleSet(is_set, aruid);
|
||||||
|
// Wait until style is defined
|
||||||
|
if (!is_set) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (std::size_t i = 0; i < controller_data[aruid_index].size(); ++i) {
|
for (std::size_t i = 0; i < controller_data[aruid_index].size(); ++i) {
|
||||||
auto& controller = controller_data[aruid_index][i];
|
auto& controller = controller_data[aruid_index][i];
|
||||||
controller.shared_memory =
|
controller.shared_memory =
|
||||||
@ -484,6 +493,10 @@ void NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!controller.is_active) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
RequestPadStateUpdate(aruid, controller.device->GetNpadIdType());
|
RequestPadStateUpdate(aruid, controller.device->GetNpadIdType());
|
||||||
auto& pad_state = controller.npad_pad_state;
|
auto& pad_state = controller.npad_pad_state;
|
||||||
auto& libnx_state = controller.npad_libnx_state;
|
auto& libnx_state = controller.npad_libnx_state;
|
||||||
@ -592,7 +605,9 @@ void NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
|||||||
libnx_state.npad_buttons.raw = pad_state.npad_buttons.raw;
|
libnx_state.npad_buttons.raw = pad_state.npad_buttons.raw;
|
||||||
libnx_state.l_stick = pad_state.l_stick;
|
libnx_state.l_stick = pad_state.l_stick;
|
||||||
libnx_state.r_stick = pad_state.r_stick;
|
libnx_state.r_stick = pad_state.r_stick;
|
||||||
npad->system_ext_lifo.WriteNextEntry(pad_state);
|
libnx_state.sampling_number =
|
||||||
|
npad->system_ext_lifo.ReadCurrentEntry().state.sampling_number + 1;
|
||||||
|
npad->system_ext_lifo.WriteNextEntry(libnx_state);
|
||||||
|
|
||||||
press_state |= static_cast<u64>(pad_state.npad_buttons.raw);
|
press_state |= static_cast<u64>(pad_state.npad_buttons.raw);
|
||||||
}
|
}
|
||||||
@ -1060,6 +1075,7 @@ void NPad::UnregisterAppletResourceUserId(u64 aruid) {
|
|||||||
// TODO: Remove this once abstract pad is emulated properly
|
// TODO: Remove this once abstract pad is emulated properly
|
||||||
const auto aruid_index = npad_resource.GetIndexFromAruid(aruid);
|
const auto aruid_index = npad_resource.GetIndexFromAruid(aruid);
|
||||||
for (auto& controller : controller_data[aruid_index]) {
|
for (auto& controller : controller_data[aruid_index]) {
|
||||||
|
controller.is_active = false;
|
||||||
controller.is_connected = false;
|
controller.is_connected = false;
|
||||||
controller.shared_memory = nullptr;
|
controller.shared_memory = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -164,6 +164,7 @@ private:
|
|||||||
NpadInternalState* shared_memory = nullptr;
|
NpadInternalState* shared_memory = nullptr;
|
||||||
Core::HID::EmulatedController* device = nullptr;
|
Core::HID::EmulatedController* device = nullptr;
|
||||||
|
|
||||||
|
bool is_active{};
|
||||||
bool is_connected{};
|
bool is_connected{};
|
||||||
|
|
||||||
// Dual joycons can have only one side connected
|
// Dual joycons can have only one side connected
|
||||||
|
@ -17,10 +17,6 @@ void UniquePad::OnInit() {}
|
|||||||
void UniquePad::OnRelease() {}
|
void UniquePad::OnRelease() {}
|
||||||
|
|
||||||
void UniquePad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
void UniquePad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||||
if (!smart_update) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const u64 aruid = applet_resource->GetActiveAruid();
|
const u64 aruid = applet_resource->GetActiveAruid();
|
||||||
auto* data = applet_resource->GetAruidData(aruid);
|
auto* data = applet_resource->GetAruidData(aruid);
|
||||||
|
|
||||||
|
@ -20,8 +20,5 @@ public:
|
|||||||
|
|
||||||
// When the controller is requesting an update for the shared memory
|
// When the controller is requesting an update for the shared memory
|
||||||
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
|
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
|
||||||
|
|
||||||
private:
|
|
||||||
bool smart_update{};
|
|
||||||
};
|
};
|
||||||
} // namespace Service::HID
|
} // namespace Service::HID
|
||||||
|
Loading…
Reference in New Issue
Block a user