service: hid: Use applet resource to get latest shared memory handle

This commit is contained in:
Narr the Reg 2023-12-31 00:42:23 -06:00
parent 09bfc852dc
commit 865abfc37c
37 changed files with 712 additions and 231 deletions

View file

@ -553,17 +553,26 @@ add_library(core STATIC
hle/service/hid/controllers/types/keyboard_types.h hle/service/hid/controllers/types/keyboard_types.h
hle/service/hid/controllers/types/mouse_types.h hle/service/hid/controllers/types/mouse_types.h
hle/service/hid/controllers/types/npad_types.h hle/service/hid/controllers/types/npad_types.h
hle/service/hid/controllers/types/shared_memory_format.h
hle/service/hid/controllers/types/touch_types.h hle/service/hid/controllers/types/touch_types.h
hle/service/hid/controllers/applet_resource.cpp hle/service/hid/controllers/applet_resource.cpp
hle/service/hid/controllers/applet_resource.h hle/service/hid/controllers/applet_resource.h
hle/service/hid/controllers/capture_button.cpp
hle/service/hid/controllers/capture_button.h
hle/service/hid/controllers/console_six_axis.cpp hle/service/hid/controllers/console_six_axis.cpp
hle/service/hid/controllers/console_six_axis.h hle/service/hid/controllers/console_six_axis.h
hle/service/hid/controllers/controller_base.cpp hle/service/hid/controllers/controller_base.cpp
hle/service/hid/controllers/controller_base.h hle/service/hid/controllers/controller_base.h
hle/service/hid/controllers/debug_mouse.cpp
hle/service/hid/controllers/debug_mouse.h
hle/service/hid/controllers/debug_pad.cpp hle/service/hid/controllers/debug_pad.cpp
hle/service/hid/controllers/debug_pad.h hle/service/hid/controllers/debug_pad.h
hle/service/hid/controllers/digitizer.cpp
hle/service/hid/controllers/digitizer.h
hle/service/hid/controllers/gesture.cpp hle/service/hid/controllers/gesture.cpp
hle/service/hid/controllers/gesture.h hle/service/hid/controllers/gesture.h
hle/service/hid/controllers/home_button.cpp
hle/service/hid/controllers/home_button.h
hle/service/hid/controllers/keyboard.cpp hle/service/hid/controllers/keyboard.cpp
hle/service/hid/controllers/keyboard.h hle/service/hid/controllers/keyboard.h
hle/service/hid/controllers/mouse.cpp hle/service/hid/controllers/mouse.cpp
@ -574,15 +583,16 @@ add_library(core STATIC
hle/service/hid/controllers/palma.h hle/service/hid/controllers/palma.h
hle/service/hid/controllers/seven_six_axis.cpp hle/service/hid/controllers/seven_six_axis.cpp
hle/service/hid/controllers/seven_six_axis.h hle/service/hid/controllers/seven_six_axis.h
hle/service/hid/controllers/shared_memory_format.h
hle/service/hid/controllers/shared_memory_holder.cpp hle/service/hid/controllers/shared_memory_holder.cpp
hle/service/hid/controllers/shared_memory_holder.h hle/service/hid/controllers/shared_memory_holder.h
hle/service/hid/controllers/six_axis.cpp hle/service/hid/controllers/six_axis.cpp
hle/service/hid/controllers/six_axis.h hle/service/hid/controllers/six_axis.h
hle/service/hid/controllers/stubbed.cpp hle/service/hid/controllers/sleep_button.cpp
hle/service/hid/controllers/stubbed.h hle/service/hid/controllers/sleep_button.h
hle/service/hid/controllers/touchscreen.cpp hle/service/hid/controllers/touchscreen.cpp
hle/service/hid/controllers/touchscreen.h hle/service/hid/controllers/touchscreen.h
hle/service/hid/controllers/unique_pad.cpp
hle/service/hid/controllers/unique_pad.h
hle/service/hid/hidbus/hidbus_base.cpp hle/service/hid/hidbus/hidbus_base.cpp
hle/service/hid/hidbus/hidbus_base.h hle/service/hid/hidbus/hidbus_base.h
hle/service/hid/hidbus/ringcon.cpp hle/service/hid/hidbus/ringcon.cpp

View file

@ -4,7 +4,7 @@
#include "core/core.h" #include "core/core.h"
#include "core/hle/kernel/k_shared_memory.h" #include "core/hle/kernel/k_shared_memory.h"
#include "core/hle/service/hid/controllers/applet_resource.h" #include "core/hle/service/hid/controllers/applet_resource.h"
#include "core/hle/service/hid/controllers/shared_memory_format.h" #include "core/hle/service/hid/controllers/types/shared_memory_format.h"
#include "core/hle/service/hid/errors.h" #include "core/hle/service/hid/errors.h"
namespace Service::HID { namespace Service::HID {
@ -164,6 +164,22 @@ Result AppletResource::GetSharedMemoryFormat(SharedMemoryFormat** out_shared_mem
return ResultSuccess; return ResultSuccess;
} }
AruidData* AppletResource::GetAruidData(u64 aruid) {
const u64 aruid_index = GetIndexFromAruid(aruid);
if (aruid_index == AruidIndexMax) {
return nullptr;
}
return &data[aruid_index];
}
AruidData* AppletResource::GetAruidDataByIndex(std::size_t aruid_index) {
return &data[aruid_index];
}
bool AppletResource::IsVibrationAruidActive(u64 aruid) const {
return aruid == 0 || aruid == active_vibration_aruid;
}
u64 AppletResource::GetIndexFromAruid(u64 aruid) { u64 AppletResource::GetIndexFromAruid(u64 aruid) {
for (std::size_t i = 0; i < AruidIndexMax; i++) { for (std::size_t i = 0; i < AruidIndexMax; i++) {
if (registration_list.flag[i] == RegistrationStatus::Initialized && if (registration_list.flag[i] == RegistrationStatus::Initialized &&

View file

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <array> #include <array>
#include <mutex>
#include "common/bit_field.h" #include "common/bit_field.h"
#include "common/common_types.h" #include "common/common_types.h"
@ -20,6 +21,59 @@ class KSharedMemory;
namespace Service::HID { namespace Service::HID {
struct SharedMemoryFormat; struct SharedMemoryFormat;
class AppletResource;
class NPadResource;
static constexpr std::size_t AruidIndexMax = 0x20;
enum class RegistrationStatus : u32 {
None,
Initialized,
PendingDelete,
};
struct DataStatusFlag {
union {
u32 raw{};
BitField<0, 1, u32> is_initialized;
BitField<1, 1, u32> is_assigned;
BitField<16, 1, u32> enable_pad_input;
BitField<17, 1, u32> enable_six_axis_sensor;
BitField<18, 1, u32> bit_18;
BitField<19, 1, u32> is_palma_connectable;
BitField<20, 1, u32> enable_palma_boost_mode;
BitField<21, 1, u32> enable_touchscreen;
};
};
struct AruidRegisterList {
std::array<RegistrationStatus, AruidIndexMax> flag{};
std::array<u64, AruidIndexMax> aruid{};
};
static_assert(sizeof(AruidRegisterList) == 0x180, "AruidRegisterList is an invalid size");
struct AruidData {
DataStatusFlag flag{};
u64 aruid{};
SharedMemoryFormat* shared_memory_format{nullptr};
};
struct HandheldConfig {
bool is_handheld_hid_enabled;
bool is_force_handheld;
bool is_joycon_rail_enabled;
bool is_force_handheld_style_vibration;
};
static_assert(sizeof(HandheldConfig) == 0x4, "HandheldConfig is an invalid size");
struct AppletResourceHolder {
std::shared_ptr<AppletResource> applet_resource{nullptr};
std::recursive_mutex* shared_mutex{nullptr};
NPadResource* shared_npad_resource{nullptr};
std::shared_ptr<HandheldConfig> handheld_config{nullptr};
long* handle_1;
};
class AppletResource { class AppletResource {
public: public:
@ -36,6 +90,10 @@ public:
u64 GetActiveAruid(); u64 GetActiveAruid();
Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid); Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid);
Result GetSharedMemoryFormat(SharedMemoryFormat** out_shared_memory_format, u64 aruid); Result GetSharedMemoryFormat(SharedMemoryFormat** out_shared_memory_format, u64 aruid);
AruidData* GetAruidData(u64 aruid);
AruidData* GetAruidDataByIndex(std::size_t aruid_index);
bool IsVibrationAruidActive(u64 aruid) const;
u64 GetIndexFromAruid(u64 aruid); u64 GetIndexFromAruid(u64 aruid);
@ -52,46 +110,12 @@ public:
Result UnregisterCoreAppletResource(); Result UnregisterCoreAppletResource();
private: private:
static constexpr std::size_t AruidIndexMax = 0x20;
enum RegistrationStatus : u32 {
None,
Initialized,
PendingDelete,
};
struct DataStatusFlag {
union {
u32 raw{};
BitField<0, 1, u32> is_initialized;
BitField<1, 1, u32> is_assigned;
BitField<16, 1, u32> enable_pad_input;
BitField<17, 1, u32> enable_six_axis_sensor;
BitField<18, 1, u32> bit_18;
BitField<19, 1, u32> is_palma_connectable;
BitField<20, 1, u32> enable_palma_boost_mode;
BitField<21, 1, u32> enable_touchscreen;
};
};
struct AruidRegisterList {
std::array<RegistrationStatus, AruidIndexMax> flag{};
std::array<u64, AruidIndexMax> aruid{};
};
static_assert(sizeof(AruidRegisterList) == 0x180, "AruidRegisterList is an invalid size");
struct AruidData {
DataStatusFlag flag{};
u64 aruid{};
SharedMemoryFormat* shared_memory_format{nullptr};
};
u64 active_aruid{}; u64 active_aruid{};
AruidRegisterList registration_list{}; AruidRegisterList registration_list{};
std::array<AruidData, AruidIndexMax> data{}; std::array<AruidData, AruidIndexMax> data{};
std::array<SharedMemoryHolder, AruidIndexMax> shared_memory_holder{}; std::array<SharedMemoryHolder, AruidIndexMax> shared_memory_holder{};
s32 ref_counter{}; s32 ref_counter{};
u64 active_vibration_aruid;
Core::System& system; Core::System& system;
}; };

View file

@ -0,0 +1,38 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core_timing.h"
#include "core/hle/service/hid/controllers/applet_resource.h"
#include "core/hle/service/hid/controllers/capture_button.h"
#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
namespace Service::HID {
CaptureButton::CaptureButton(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {}
CaptureButton::~CaptureButton() = default;
void CaptureButton::OnInit() {}
void CaptureButton::OnRelease() {}
void CaptureButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
if (!smart_update) {
return;
}
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
auto& header = data->shared_memory_format->capture_button.header;
header.timestamp = core_timing.GetGlobalTimeNs().count();
header.total_entry_count = 17;
header.entry_count = 0;
header.last_entry_index = 0;
}
} // namespace Service::HID

View file

@ -6,12 +6,11 @@
#include "core/hle/service/hid/controllers/controller_base.h" #include "core/hle/service/hid/controllers/controller_base.h"
namespace Service::HID { namespace Service::HID {
struct CommonHeader;
class Controller_Stubbed final : public ControllerBase { class CaptureButton final : public ControllerBase {
public: public:
explicit Controller_Stubbed(Core::HID::HIDCore& hid_core_, CommonHeader& ring_lifo_header); explicit CaptureButton(Core::HID::HIDCore& hid_core_);
~Controller_Stubbed() override; ~CaptureButton() override;
// Called when the controller is initialized // Called when the controller is initialized
void OnInit() override; void OnInit() override;
@ -23,7 +22,6 @@ public:
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
private: private:
CommonHeader& header;
bool smart_update{}; bool smart_update{};
}; };
} // namespace Service::HID } // namespace Service::HID

View file

@ -5,13 +5,11 @@
#include "core/hid/emulated_console.h" #include "core/hid/emulated_console.h"
#include "core/hid/hid_core.h" #include "core/hid/hid_core.h"
#include "core/hle/service/hid/controllers/console_six_axis.h" #include "core/hle/service/hid/controllers/console_six_axis.h"
#include "core/hle/service/hid/controllers/shared_memory_format.h" #include "core/hle/service/hid/controllers/types/shared_memory_format.h"
namespace Service::HID { namespace Service::HID {
ConsoleSixAxis::ConsoleSixAxis(Core::HID::HIDCore& hid_core_, ConsoleSixAxis::ConsoleSixAxis(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {
ConsoleSixAxisSensorSharedMemoryFormat& console_shared_memory)
: ControllerBase{hid_core_}, shared_memory{console_shared_memory} {
console = hid_core.GetEmulatedConsole(); console = hid_core.GetEmulatedConsole();
} }
@ -22,6 +20,15 @@ void ConsoleSixAxis::OnInit() {}
void ConsoleSixAxis::OnRelease() {} void ConsoleSixAxis::OnRelease() {}
void ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { void ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
ConsoleSixAxisSensorSharedMemoryFormat& shared_memory = data->shared_memory_format->console;
if (!IsControllerActivated()) { if (!IsControllerActivated()) {
return; return;
} }

View file

@ -10,12 +10,9 @@ class EmulatedConsole;
} // namespace Core::HID } // namespace Core::HID
namespace Service::HID { namespace Service::HID {
struct ConsoleSixAxisSensorSharedMemoryFormat;
class ConsoleSixAxis final : public ControllerBase { class ConsoleSixAxis final : public ControllerBase {
public: public:
explicit ConsoleSixAxis(Core::HID::HIDCore& hid_core_, explicit ConsoleSixAxis(Core::HID::HIDCore& hid_core_);
ConsoleSixAxisSensorSharedMemoryFormat& console_shared_memory);
~ConsoleSixAxis() override; ~ConsoleSixAxis() override;
// Called when the controller is initialized // Called when the controller is initialized
@ -28,7 +25,6 @@ public:
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
private: private:
ConsoleSixAxisSensorSharedMemoryFormat& shared_memory;
Core::HID::EmulatedConsole* console = nullptr; Core::HID::EmulatedConsole* console = nullptr;
}; };
} // namespace Service::HID } // namespace Service::HID

View file

@ -31,4 +31,9 @@ void ControllerBase::DeactivateController() {
bool ControllerBase::IsControllerActivated() const { bool ControllerBase::IsControllerActivated() const {
return is_activated; return is_activated;
} }
void ControllerBase::SetAppletResource(std::shared_ptr<AppletResource> resource) {
applet_resource = resource;
}
} // namespace Service::HID } // namespace Service::HID

View file

@ -3,8 +3,11 @@
#pragma once #pragma once
#include <memory>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hle/result.h" #include "core/hle/result.h"
#include "core/hle/service/hid/controllers/applet_resource.h"
namespace Core::Timing { namespace Core::Timing {
class CoreTiming; class CoreTiming;
@ -12,7 +15,7 @@ class CoreTiming;
namespace Core::HID { namespace Core::HID {
class HIDCore; class HIDCore;
} } // namespace Core::HID
namespace Service::HID { namespace Service::HID {
class ControllerBase { class ControllerBase {
@ -39,8 +42,11 @@ public:
bool IsControllerActivated() const; bool IsControllerActivated() const;
void SetAppletResource(std::shared_ptr<AppletResource> resource);
protected: protected:
bool is_activated{false}; bool is_activated{false};
std::shared_ptr<AppletResource> applet_resource{nullptr};
Core::HID::HIDCore& hid_core; Core::HID::HIDCore& hid_core;
}; };

View file

@ -0,0 +1,63 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core_timing.h"
#include "core/frontend/emu_window.h"
#include "core/hid/emulated_devices.h"
#include "core/hid/hid_core.h"
#include "core/hle/service/hid/controllers/applet_resource.h"
#include "core/hle/service/hid/controllers/debug_mouse.h"
#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
namespace Service::HID {
DebugMouse::DebugMouse(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {
emulated_devices = hid_core.GetEmulatedDevices();
}
DebugMouse::~DebugMouse() = default;
void DebugMouse::OnInit() {}
void DebugMouse::OnRelease() {}
void DebugMouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
MouseSharedMemoryFormat& shared_memory = data->shared_memory_format->debug_mouse;
if (!IsControllerActivated()) {
shared_memory.mouse_lifo.buffer_count = 0;
shared_memory.mouse_lifo.buffer_tail = 0;
return;
}
next_state = {};
const auto& last_entry = shared_memory.mouse_lifo.ReadCurrentEntry().state;
next_state.sampling_number = last_entry.sampling_number + 1;
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->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 - 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;
}
shared_memory.mouse_lifo.WriteNextEntry(next_state);
}
} // namespace Service::HID

View file

@ -0,0 +1,34 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "core/hle/service/hid/controllers/controller_base.h"
namespace Core::HID {
class EmulatedDevices;
struct MouseState;
struct AnalogStickState;
} // namespace Core::HID
namespace Service::HID {
class DebugMouse final : public ControllerBase {
public:
explicit DebugMouse(Core::HID::HIDCore& hid_core_);
~DebugMouse() override;
// Called when the controller is initialized
void OnInit() override;
// When the controller is released
void OnRelease() override;
// When the controller is requesting an update for the shared memory
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
private:
Core::HID::MouseState next_state{};
Core::HID::AnalogStickState last_mouse_wheel_state{};
Core::HID::EmulatedDevices* emulated_devices = nullptr;
};
} // namespace Service::HID

View file

@ -6,14 +6,13 @@
#include "core/hid/emulated_controller.h" #include "core/hid/emulated_controller.h"
#include "core/hid/hid_core.h" #include "core/hid/hid_core.h"
#include "core/hid/hid_types.h" #include "core/hid/hid_types.h"
#include "core/hle/service/hid/controllers/applet_resource.h"
#include "core/hle/service/hid/controllers/debug_pad.h" #include "core/hle/service/hid/controllers/debug_pad.h"
#include "core/hle/service/hid/controllers/shared_memory_format.h" #include "core/hle/service/hid/controllers/types/shared_memory_format.h"
namespace Service::HID { namespace Service::HID {
DebugPad::DebugPad(Core::HID::HIDCore& hid_core_, DebugPad::DebugPad(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {
DebugPadSharedMemoryFormat& debug_pad_shared_memory)
: ControllerBase{hid_core_}, shared_memory{debug_pad_shared_memory} {
controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Other); controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Other);
} }
@ -24,6 +23,15 @@ void DebugPad::OnInit() {}
void DebugPad::OnRelease() {} void DebugPad::OnRelease() {}
void DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { void DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
DebugPadSharedMemoryFormat& shared_memory = data->shared_memory_format->debug_pad;
if (!IsControllerActivated()) { if (!IsControllerActivated()) {
shared_memory.debug_pad_lifo.buffer_count = 0; shared_memory.debug_pad_lifo.buffer_count = 0;
shared_memory.debug_pad_lifo.buffer_tail = 0; shared_memory.debug_pad_lifo.buffer_tail = 0;

View file

@ -15,12 +15,9 @@ class CoreTiming;
} }
namespace Service::HID { namespace Service::HID {
struct DebugPadSharedMemoryFormat;
class DebugPad final : public ControllerBase { class DebugPad final : public ControllerBase {
public: public:
explicit DebugPad(Core::HID::HIDCore& hid_core_, explicit DebugPad(Core::HID::HIDCore& hid_core_);
DebugPadSharedMemoryFormat& debug_pad_shared_memory);
~DebugPad() override; ~DebugPad() override;
// Called when the controller is initialized // Called when the controller is initialized
@ -34,7 +31,6 @@ public:
private: private:
DebugPadState next_state{}; DebugPadState next_state{};
DebugPadSharedMemoryFormat& shared_memory;
Core::HID::EmulatedController* controller = nullptr; Core::HID::EmulatedController* controller = nullptr;
}; };
} // namespace Service::HID } // namespace Service::HID

View file

@ -0,0 +1,38 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core_timing.h"
#include "core/hle/service/hid/controllers/applet_resource.h"
#include "core/hle/service/hid/controllers/digitizer.h"
#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
namespace Service::HID {
Digitizer::Digitizer(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {}
Digitizer::~Digitizer() = default;
void Digitizer::OnInit() {}
void Digitizer::OnRelease() {}
void Digitizer::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
if (!smart_update) {
return;
}
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
auto& header = data->shared_memory_format->digitizer.header;
header.timestamp = core_timing.GetGlobalTimeNs().count();
header.total_entry_count = 17;
header.entry_count = 0;
header.last_entry_index = 0;
}
} // namespace Service::HID

View file

@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "core/hle/service/hid/controllers/controller_base.h"
namespace Service::HID {
class Digitizer final : public ControllerBase {
public:
explicit Digitizer(Core::HID::HIDCore& hid_core_);
~Digitizer() override;
// Called when the controller is initialized
void OnInit() override;
// When the controller is released
void OnRelease() override;
// When the controller is requesting an update for the shared memory
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
private:
bool smart_update{};
};
} // namespace Service::HID

View file

@ -6,8 +6,9 @@
#include "core/frontend/emu_window.h" #include "core/frontend/emu_window.h"
#include "core/hid/emulated_console.h" #include "core/hid/emulated_console.h"
#include "core/hid/hid_core.h" #include "core/hid/hid_core.h"
#include "core/hle/service/hid/controllers/applet_resource.h"
#include "core/hle/service/hid/controllers/gesture.h" #include "core/hle/service/hid/controllers/gesture.h"
#include "core/hle/service/hid/controllers/shared_memory_format.h" #include "core/hle/service/hid/controllers/types/shared_memory_format.h"
namespace Service::HID { namespace Service::HID {
// HW is around 700, value is set to 400 to make it easier to trigger with mouse // HW is around 700, value is set to 400 to make it easier to trigger with mouse
@ -21,24 +22,40 @@ constexpr f32 Square(s32 num) {
return static_cast<f32>(num * num); return static_cast<f32>(num * num);
} }
Gesture::Gesture(Core::HID::HIDCore& hid_core_, GestureSharedMemoryFormat& gesture_shared_memory) Gesture::Gesture(Core::HID::HIDCore& hid_core_) : ControllerBase(hid_core_) {
: ControllerBase(hid_core_), shared_memory{gesture_shared_memory} {
console = hid_core.GetEmulatedConsole(); console = hid_core.GetEmulatedConsole();
} }
Gesture::~Gesture() = default; Gesture::~Gesture() = default;
void Gesture::OnInit() { void Gesture::OnInit() {
shared_memory.gesture_lifo.buffer_count = 0; const u64 aruid = applet_resource->GetActiveAruid();
shared_memory.gesture_lifo.buffer_tail = 0; auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
shared_memory = &data->shared_memory_format->gesture;
shared_memory->gesture_lifo.buffer_count = 0;
shared_memory->gesture_lifo.buffer_tail = 0;
force_update = true; force_update = true;
} }
void Gesture::OnRelease() {} void Gesture::OnRelease() {}
void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) { void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
shared_memory = &data->shared_memory_format->gesture;
if (!IsControllerActivated()) { if (!IsControllerActivated()) {
shared_memory.gesture_lifo.buffer_count = 0; shared_memory->gesture_lifo.buffer_count = 0;
shared_memory.gesture_lifo.buffer_tail = 0; shared_memory->gesture_lifo.buffer_tail = 0;
return; return;
} }
@ -46,7 +63,7 @@ void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
GestureProperties gesture = GetGestureProperties(); GestureProperties gesture = GetGestureProperties();
f32 time_difference = f32 time_difference =
static_cast<f32>(shared_memory.gesture_lifo.timestamp - last_update_timestamp) / static_cast<f32>(shared_memory->gesture_lifo.timestamp - last_update_timestamp) /
(1000 * 1000 * 1000); (1000 * 1000 * 1000);
// Only update if necessary // Only update if necessary
@ -54,7 +71,7 @@ void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
return; return;
} }
last_update_timestamp = shared_memory.gesture_lifo.timestamp; last_update_timestamp = shared_memory->gesture_lifo.timestamp;
UpdateGestureSharedMemory(gesture, time_difference); UpdateGestureSharedMemory(gesture, time_difference);
} }
@ -97,7 +114,7 @@ void Gesture::UpdateGestureSharedMemory(GestureProperties& gesture, f32 time_dif
GestureType type = GestureType::Idle; GestureType type = GestureType::Idle;
GestureAttribute attributes{}; GestureAttribute attributes{};
const auto& last_entry = shared_memory.gesture_lifo.ReadCurrentEntry().state; const auto& last_entry = shared_memory->gesture_lifo.ReadCurrentEntry().state;
// Reset next state to default // Reset next state to default
next_state.sampling_number = last_entry.sampling_number + 1; next_state.sampling_number = last_entry.sampling_number + 1;
@ -127,7 +144,7 @@ void Gesture::UpdateGestureSharedMemory(GestureProperties& gesture, f32 time_dif
next_state.points = gesture.points; next_state.points = gesture.points;
last_gesture = gesture; last_gesture = gesture;
shared_memory.gesture_lifo.WriteNextEntry(next_state); shared_memory->gesture_lifo.WriteNextEntry(next_state);
} }
void Gesture::NewGesture(GestureProperties& gesture, GestureType& type, void Gesture::NewGesture(GestureProperties& gesture, GestureType& type,
@ -300,7 +317,7 @@ void Gesture::SetSwipeEvent(GestureProperties& gesture, GestureProperties& last_
} }
const GestureState& Gesture::GetLastGestureEntry() const { const GestureState& Gesture::GetLastGestureEntry() const {
return shared_memory.gesture_lifo.ReadCurrentEntry().state; return shared_memory->gesture_lifo.ReadCurrentEntry().state;
} }
GestureProperties Gesture::GetGestureProperties() { GestureProperties Gesture::GetGestureProperties() {

View file

@ -18,8 +18,7 @@ struct GestureSharedMemoryFormat;
class Gesture final : public ControllerBase { class Gesture final : public ControllerBase {
public: public:
explicit Gesture(Core::HID::HIDCore& hid_core_, explicit Gesture(Core::HID::HIDCore& hid_core_);
GestureSharedMemoryFormat& gesture_shared_memory);
~Gesture() override; ~Gesture() override;
// Called when the controller is initialized // Called when the controller is initialized
@ -74,7 +73,7 @@ private:
GestureProperties GetGestureProperties(); GestureProperties GetGestureProperties();
GestureState next_state{}; GestureState next_state{};
GestureSharedMemoryFormat& shared_memory; GestureSharedMemoryFormat* shared_memory;
Core::HID::EmulatedConsole* console = nullptr; Core::HID::EmulatedConsole* console = nullptr;
std::array<Core::HID::TouchFinger, MAX_POINTS> fingers{}; std::array<Core::HID::TouchFinger, MAX_POINTS> fingers{};

View file

@ -0,0 +1,38 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core_timing.h"
#include "core/hle/service/hid/controllers/applet_resource.h"
#include "core/hle/service/hid/controllers/home_button.h"
#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
namespace Service::HID {
HomeButton::HomeButton(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {}
HomeButton::~HomeButton() = default;
void HomeButton::OnInit() {}
void HomeButton::OnRelease() {}
void HomeButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
if (!smart_update) {
return;
}
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
auto& header = data->shared_memory_format->home_button.header;
header.timestamp = core_timing.GetGlobalTimeNs().count();
header.total_entry_count = 17;
header.entry_count = 0;
header.last_entry_index = 0;
}
} // namespace Service::HID

View file

@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "core/hle/service/hid/controllers/controller_base.h"
namespace Service::HID {
class HomeButton final : public ControllerBase {
public:
explicit HomeButton(Core::HID::HIDCore& hid_core_);
~HomeButton() override;
// Called when the controller is initialized
void OnInit() override;
// When the controller is released
void OnRelease() override;
// When the controller is requesting an update for the shared memory
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
private:
bool smart_update{};
};
} // namespace Service::HID

View file

@ -5,14 +5,13 @@
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/hid/emulated_devices.h" #include "core/hid/emulated_devices.h"
#include "core/hid/hid_core.h" #include "core/hid/hid_core.h"
#include "core/hle/service/hid/controllers/applet_resource.h"
#include "core/hle/service/hid/controllers/keyboard.h" #include "core/hle/service/hid/controllers/keyboard.h"
#include "core/hle/service/hid/controllers/shared_memory_format.h" #include "core/hle/service/hid/controllers/types/shared_memory_format.h"
namespace Service::HID { namespace Service::HID {
Keyboard::Keyboard(Core::HID::HIDCore& hid_core_, Keyboard::Keyboard(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {
KeyboardSharedMemoryFormat& keyboard_shared_memory)
: ControllerBase{hid_core_}, shared_memory{keyboard_shared_memory} {
emulated_devices = hid_core.GetEmulatedDevices(); emulated_devices = hid_core.GetEmulatedDevices();
} }
@ -23,6 +22,15 @@ void Keyboard::OnInit() {}
void Keyboard::OnRelease() {} void Keyboard::OnRelease() {}
void Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing) { void Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
KeyboardSharedMemoryFormat& shared_memory = data->shared_memory_format->keyboard;
if (!IsControllerActivated()) { if (!IsControllerActivated()) {
shared_memory.keyboard_lifo.buffer_count = 0; shared_memory.keyboard_lifo.buffer_count = 0;
shared_memory.keyboard_lifo.buffer_tail = 0; shared_memory.keyboard_lifo.buffer_tail = 0;

View file

@ -7,12 +7,9 @@
#include "core/hle/service/hid/controllers/types/keyboard_types.h" #include "core/hle/service/hid/controllers/types/keyboard_types.h"
namespace Service::HID { namespace Service::HID {
struct KeyboardSharedMemoryFormat;
class Keyboard final : public ControllerBase { class Keyboard final : public ControllerBase {
public: public:
explicit Keyboard(Core::HID::HIDCore& hid_core_, explicit Keyboard(Core::HID::HIDCore& hid_core_);
KeyboardSharedMemoryFormat& keyboard_shared_memory);
~Keyboard() override; ~Keyboard() override;
// Called when the controller is initialized // Called when the controller is initialized
@ -26,7 +23,6 @@ public:
private: private:
KeyboardState next_state{}; KeyboardState next_state{};
KeyboardSharedMemoryFormat& shared_memory;
Core::HID::EmulatedDevices* emulated_devices = nullptr; Core::HID::EmulatedDevices* emulated_devices = nullptr;
}; };
} // namespace Service::HID } // namespace Service::HID

View file

@ -5,13 +5,13 @@
#include "core/frontend/emu_window.h" #include "core/frontend/emu_window.h"
#include "core/hid/emulated_devices.h" #include "core/hid/emulated_devices.h"
#include "core/hid/hid_core.h" #include "core/hid/hid_core.h"
#include "core/hle/service/hid/controllers/applet_resource.h"
#include "core/hle/service/hid/controllers/mouse.h" #include "core/hle/service/hid/controllers/mouse.h"
#include "core/hle/service/hid/controllers/shared_memory_format.h" #include "core/hle/service/hid/controllers/types/shared_memory_format.h"
namespace Service::HID { namespace Service::HID {
Mouse::Mouse(Core::HID::HIDCore& hid_core_, MouseSharedMemoryFormat& mouse_shared_memory) Mouse::Mouse(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {
: ControllerBase{hid_core_}, shared_memory{mouse_shared_memory} {
emulated_devices = hid_core.GetEmulatedDevices(); emulated_devices = hid_core.GetEmulatedDevices();
} }
@ -21,6 +21,15 @@ void Mouse::OnInit() {}
void Mouse::OnRelease() {} void Mouse::OnRelease() {}
void Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) { void Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
MouseSharedMemoryFormat& shared_memory = data->shared_memory_format->mouse;
if (!IsControllerActivated()) { if (!IsControllerActivated()) {
shared_memory.mouse_lifo.buffer_count = 0; shared_memory.mouse_lifo.buffer_count = 0;
shared_memory.mouse_lifo.buffer_tail = 0; shared_memory.mouse_lifo.buffer_tail = 0;

View file

@ -12,11 +12,9 @@ struct AnalogStickState;
} // namespace Core::HID } // namespace Core::HID
namespace Service::HID { namespace Service::HID {
struct MouseSharedMemoryFormat;
class Mouse final : public ControllerBase { class Mouse final : public ControllerBase {
public: public:
explicit Mouse(Core::HID::HIDCore& hid_core_, MouseSharedMemoryFormat& mouse_shared_memory); explicit Mouse(Core::HID::HIDCore& hid_core_);
~Mouse() override; ~Mouse() override;
// Called when the controller is initialized // Called when the controller is initialized
@ -31,7 +29,6 @@ public:
private: private:
Core::HID::MouseState next_state{}; Core::HID::MouseState next_state{};
Core::HID::AnalogStickState last_mouse_wheel_state{}; Core::HID::AnalogStickState last_mouse_wheel_state{};
MouseSharedMemoryFormat& shared_memory;
Core::HID::EmulatedDevices* emulated_devices = nullptr; Core::HID::EmulatedDevices* emulated_devices = nullptr;
}; };
} // namespace Service::HID } // namespace Service::HID

View file

@ -16,8 +16,9 @@
#include "core/hid/hid_core.h" #include "core/hid/hid_core.h"
#include "core/hle/kernel/k_event.h" #include "core/hle/kernel/k_event.h"
#include "core/hle/kernel/k_readable_event.h" #include "core/hle/kernel/k_readable_event.h"
#include "core/hle/service/hid/controllers/applet_resource.h"
#include "core/hle/service/hid/controllers/npad.h" #include "core/hle/service/hid/controllers/npad.h"
#include "core/hle/service/hid/controllers/shared_memory_format.h" #include "core/hle/service/hid/controllers/types/shared_memory_format.h"
#include "core/hle/service/hid/errors.h" #include "core/hle/service/hid/errors.h"
#include "core/hle/service/hid/hid_util.h" #include "core/hle/service/hid/hid_util.h"
#include "core/hle/service/kernel_helpers.h" #include "core/hle/service/kernel_helpers.h"
@ -30,12 +31,10 @@ constexpr std::array<Core::HID::NpadIdType, 10> npad_id_list{
Core::HID::NpadIdType::Handheld, Core::HID::NpadIdType::Handheld,
}; };
NPad::NPad(Core::HID::HIDCore& hid_core_, NpadSharedMemoryFormat& npad_shared_memory_format, NPad::NPad(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service_context_)
KernelHelpers::ServiceContext& service_context_)
: ControllerBase{hid_core_}, service_context{service_context_} { : ControllerBase{hid_core_}, service_context{service_context_} {
for (std::size_t i = 0; i < controller_data.size(); ++i) { for (std::size_t i = 0; i < controller_data.size(); ++i) {
auto& controller = controller_data[i]; auto& controller = controller_data[i];
controller.shared_memory = &npad_shared_memory_format.npad_entry[i].internal_state;
controller.device = hid_core.GetEmulatedControllerByIndex(i); controller.device = hid_core.GetEmulatedControllerByIndex(i);
controller.vibration[Core::HID::EmulatedDeviceIndex::LeftIndex].latest_vibration_value = controller.vibration[Core::HID::EmulatedDeviceIndex::LeftIndex].latest_vibration_value =
Core::HID::DEFAULT_VIBRATION_VALUE; Core::HID::DEFAULT_VIBRATION_VALUE;
@ -297,12 +296,20 @@ void NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
} }
void NPad::OnInit() { void NPad::OnInit() {
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
if (!IsControllerActivated()) { if (!IsControllerActivated()) {
return; return;
} }
for (std::size_t i = 0; i < controller_data.size(); ++i) { for (std::size_t i = 0; i < controller_data.size(); ++i) {
auto& controller = controller_data[i]; auto& controller = controller_data[i];
controller.shared_memory = &data->shared_memory_format->npad.npad_entry[i].internal_state;
controller.styleset_changed_event = controller.styleset_changed_event =
service_context.CreateEvent(fmt::format("npad:NpadStyleSetChanged_{}", i)); service_context.CreateEvent(fmt::format("npad:NpadStyleSetChanged_{}", i));
} }
@ -355,7 +362,9 @@ void NPad::OnRelease() {
is_controller_initialized = false; is_controller_initialized = false;
for (std::size_t i = 0; i < controller_data.size(); ++i) { for (std::size_t i = 0; i < controller_data.size(); ++i) {
auto& controller = controller_data[i]; auto& controller = controller_data[i];
if (controller.styleset_changed_event) {
service_context.CloseEvent(controller.styleset_changed_event); service_context.CloseEvent(controller.styleset_changed_event);
}
for (std::size_t device_idx = 0; device_idx < controller.vibration.size(); ++device_idx) { for (std::size_t device_idx = 0; device_idx < controller.vibration.size(); ++device_idx) {
VibrateControllerAtIndex(controller.device->GetNpadIdType(), device_idx, {}); VibrateControllerAtIndex(controller.device->GetNpadIdType(), device_idx, {});
} }
@ -432,12 +441,20 @@ void NPad::RequestPadStateUpdate(Core::HID::NpadIdType npad_id) {
} }
void NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { void NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
if (!IsControllerActivated()) { if (!IsControllerActivated()) {
return; return;
} }
for (std::size_t i = 0; i < controller_data.size(); ++i) { for (std::size_t i = 0; i < controller_data.size(); ++i) {
auto& controller = controller_data[i]; auto& controller = controller_data[i];
controller.shared_memory = &data->shared_memory_format->npad.npad_entry[i].internal_state;
auto* npad = controller.shared_memory; auto* npad = controller.shared_memory;
const auto& controller_type = controller.device->GetNpadStyleIndex(); const auto& controller_type = controller.device->GetNpadStyleIndex();
@ -976,30 +993,6 @@ Result NPad::ResetIsSixAxisSensorDeviceNewlyAssigned(
return ResultSuccess; return ResultSuccess;
} }
NpadSixAxisSensorLifo& NPad::GetSixAxisFullkeyLifo(Core::HID::NpadIdType npad_id) {
return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_fullkey_lifo;
}
NpadSixAxisSensorLifo& NPad::GetSixAxisHandheldLifo(Core::HID::NpadIdType npad_id) {
return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_handheld_lifo;
}
NpadSixAxisSensorLifo& NPad::GetSixAxisDualLeftLifo(Core::HID::NpadIdType npad_id) {
return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_dual_left_lifo;
}
NpadSixAxisSensorLifo& NPad::GetSixAxisDualRightLifo(Core::HID::NpadIdType npad_id) {
return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_dual_right_lifo;
}
NpadSixAxisSensorLifo& NPad::GetSixAxisLeftLifo(Core::HID::NpadIdType npad_id) {
return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_left_lifo;
}
NpadSixAxisSensorLifo& NPad::GetSixAxisRightLifo(Core::HID::NpadIdType npad_id) {
return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_right_lifo;
}
Result NPad::MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1, Result NPad::MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1,
Core::HID::NpadIdType npad_id_2) { Core::HID::NpadIdType npad_id_2) {
if (!IsNpadIdValid(npad_id_1) || !IsNpadIdValid(npad_id_2)) { if (!IsNpadIdValid(npad_id_1) || !IsNpadIdValid(npad_id_2)) {

View file

@ -30,14 +30,14 @@ class ServiceContext;
union Result; union Result;
namespace Service::HID { namespace Service::HID {
class AppletResource;
struct NpadInternalState; struct NpadInternalState;
struct NpadSixAxisSensorLifo; struct NpadSixAxisSensorLifo;
struct NpadSharedMemoryFormat; struct NpadSharedMemoryFormat;
class NPad final : public ControllerBase { class NPad final : public ControllerBase {
public: public:
explicit NPad(Core::HID::HIDCore& hid_core_, NpadSharedMemoryFormat& npad_shared_memory_format, explicit NPad(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service_context_);
KernelHelpers::ServiceContext& service_context_);
~NPad() override; ~NPad() override;
// Called when the controller is initialized // Called when the controller is initialized
@ -106,13 +106,6 @@ public:
Result ResetIsSixAxisSensorDeviceNewlyAssigned( Result ResetIsSixAxisSensorDeviceNewlyAssigned(
const Core::HID::SixAxisSensorHandle& sixaxis_handle); const Core::HID::SixAxisSensorHandle& sixaxis_handle);
NpadSixAxisSensorLifo& GetSixAxisFullkeyLifo(Core::HID::NpadIdType npad_id);
NpadSixAxisSensorLifo& GetSixAxisHandheldLifo(Core::HID::NpadIdType npad_id);
NpadSixAxisSensorLifo& GetSixAxisDualLeftLifo(Core::HID::NpadIdType npad_id);
NpadSixAxisSensorLifo& GetSixAxisDualRightLifo(Core::HID::NpadIdType npad_id);
NpadSixAxisSensorLifo& GetSixAxisLeftLifo(Core::HID::NpadIdType npad_id);
NpadSixAxisSensorLifo& GetSixAxisRightLifo(Core::HID::NpadIdType npad_id);
Result GetLedPattern(Core::HID::NpadIdType npad_id, Core::HID::LedPattern& pattern) const; Result GetLedPattern(Core::HID::NpadIdType npad_id, Core::HID::LedPattern& pattern) const;
Result IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id, Result IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id,
bool& is_enabled) const; bool& is_enabled) const;

View file

@ -3,8 +3,9 @@
#include "core/core.h" #include "core/core.h"
#include "core/hle/kernel/k_shared_memory.h" #include "core/hle/kernel/k_shared_memory.h"
#include "core/hle/service/hid/controllers/shared_memory_format.h" #include "core/hle/service/hid/controllers/applet_resource.h"
#include "core/hle/service/hid/controllers/shared_memory_holder.h" #include "core/hle/service/hid/controllers/shared_memory_holder.h"
#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
#include "core/hle/service/hid/errors.h" #include "core/hle/service/hid/errors.h"
namespace Service::HID { namespace Service::HID {

View file

@ -6,8 +6,8 @@
#include "core/hid/emulated_controller.h" #include "core/hid/emulated_controller.h"
#include "core/hid/hid_core.h" #include "core/hid/hid_core.h"
#include "core/hle/service/hid/controllers/npad.h" #include "core/hle/service/hid/controllers/npad.h"
#include "core/hle/service/hid/controllers/shared_memory_format.h"
#include "core/hle/service/hid/controllers/six_axis.h" #include "core/hle/service/hid/controllers/six_axis.h"
#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
#include "core/hle/service/hid/errors.h" #include "core/hle/service/hid/errors.h"
#include "core/hle/service/hid/hid_util.h" #include "core/hle/service/hid/hid_util.h"
@ -27,14 +27,20 @@ void SixAxis::OnInit() {}
void SixAxis::OnRelease() {} void SixAxis::OnRelease() {}
void SixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { void SixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
if (!IsControllerActivated()) { if (!IsControllerActivated()) {
return; return;
} }
for (std::size_t i = 0; i < controller_data.size(); ++i) { for (std::size_t i = 0; i < controller_data.size(); ++i) {
NpadSharedMemoryEntry& shared_memory = data->shared_memory_format->npad.npad_entry[i];
auto& controller = controller_data[i]; auto& controller = controller_data[i];
const auto npad_id = IndexToNpadIdType(i);
const auto& controller_type = controller.device->GetNpadStyleIndex(); const auto& controller_type = controller.device->GetNpadStyleIndex();
if (controller_type == Core::HID::NpadStyleIndex::None || if (controller_type == Core::HID::NpadStyleIndex::None ||
@ -50,12 +56,12 @@ void SixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
auto& sixaxis_left_lifo_state = controller.sixaxis_left_lifo_state; auto& sixaxis_left_lifo_state = controller.sixaxis_left_lifo_state;
auto& sixaxis_right_lifo_state = controller.sixaxis_right_lifo_state; auto& sixaxis_right_lifo_state = controller.sixaxis_right_lifo_state;
auto& sixaxis_fullkey_lifo = npad->GetSixAxisFullkeyLifo(npad_id); auto& sixaxis_fullkey_lifo = shared_memory.internal_state.sixaxis_fullkey_lifo;
auto& sixaxis_handheld_lifo = npad->GetSixAxisHandheldLifo(npad_id); auto& sixaxis_handheld_lifo = shared_memory.internal_state.sixaxis_handheld_lifo;
auto& sixaxis_dual_left_lifo = npad->GetSixAxisDualLeftLifo(npad_id); auto& sixaxis_dual_left_lifo = shared_memory.internal_state.sixaxis_dual_left_lifo;
auto& sixaxis_dual_right_lifo = npad->GetSixAxisDualRightLifo(npad_id); auto& sixaxis_dual_right_lifo = shared_memory.internal_state.sixaxis_dual_right_lifo;
auto& sixaxis_left_lifo = npad->GetSixAxisLeftLifo(npad_id); auto& sixaxis_left_lifo = shared_memory.internal_state.sixaxis_left_lifo;
auto& sixaxis_right_lifo = npad->GetSixAxisRightLifo(npad_id); auto& sixaxis_right_lifo = shared_memory.internal_state.sixaxis_right_lifo;
// Clear previous state // Clear previous state
sixaxis_fullkey_state = {}; sixaxis_fullkey_state = {};

View file

@ -0,0 +1,38 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core_timing.h"
#include "core/hle/service/hid/controllers/applet_resource.h"
#include "core/hle/service/hid/controllers/sleep_button.h"
#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
namespace Service::HID {
SleepButton::SleepButton(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {}
SleepButton::~SleepButton() = default;
void SleepButton::OnInit() {}
void SleepButton::OnRelease() {}
void SleepButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
if (!smart_update) {
return;
}
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
auto& header = data->shared_memory_format->capture_button.header;
header.timestamp = core_timing.GetGlobalTimeNs().count();
header.total_entry_count = 17;
header.entry_count = 0;
header.last_entry_index = 0;
}
} // namespace Service::HID

View file

@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "core/hle/service/hid/controllers/controller_base.h"
namespace Service::HID {
class SleepButton final : public ControllerBase {
public:
explicit SleepButton(Core::HID::HIDCore& hid_core_);
~SleepButton() override;
// Called when the controller is initialized
void OnInit() override;
// When the controller is released
void OnRelease() override;
// When the controller is requesting an update for the shared memory
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
private:
bool smart_update{};
};
} // namespace Service::HID

View file

@ -1,31 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core_timing.h"
#include "core/hle/service/hid/controllers/shared_memory_format.h"
#include "core/hle/service/hid/controllers/stubbed.h"
namespace Service::HID {
Controller_Stubbed::Controller_Stubbed(Core::HID::HIDCore& hid_core_,
CommonHeader& ring_lifo_header)
: ControllerBase{hid_core_}, header{ring_lifo_header} {}
Controller_Stubbed::~Controller_Stubbed() = default;
void Controller_Stubbed::OnInit() {}
void Controller_Stubbed::OnRelease() {}
void Controller_Stubbed::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
if (!smart_update) {
return;
}
header.timestamp = core_timing.GetGlobalTimeNs().count();
header.total_entry_count = 17;
header.entry_count = 0;
header.last_entry_index = 0;
}
} // namespace Service::HID

View file

@ -8,15 +8,14 @@
#include "core/frontend/emu_window.h" #include "core/frontend/emu_window.h"
#include "core/hid/emulated_console.h" #include "core/hid/emulated_console.h"
#include "core/hid/hid_core.h" #include "core/hid/hid_core.h"
#include "core/hle/service/hid/controllers/shared_memory_format.h" #include "core/hle/service/hid/controllers/applet_resource.h"
#include "core/hle/service/hid/controllers/touchscreen.h" #include "core/hle/service/hid/controllers/touchscreen.h"
#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
namespace Service::HID { namespace Service::HID {
TouchScreen::TouchScreen(Core::HID::HIDCore& hid_core_, TouchScreen::TouchScreen(Core::HID::HIDCore& hid_core_)
TouchScreenSharedMemoryFormat& touch_shared_memory) : ControllerBase{hid_core_}, touchscreen_width(Layout::ScreenUndocked::Width),
: ControllerBase{hid_core_}, shared_memory{touch_shared_memory},
touchscreen_width(Layout::ScreenUndocked::Width),
touchscreen_height(Layout::ScreenUndocked::Height) { touchscreen_height(Layout::ScreenUndocked::Height) {
console = hid_core.GetEmulatedConsole(); console = hid_core.GetEmulatedConsole();
} }
@ -28,6 +27,14 @@ void TouchScreen::OnInit() {}
void TouchScreen::OnRelease() {} void TouchScreen::OnRelease() {}
void TouchScreen::OnUpdate(const Core::Timing::CoreTiming& core_timing) { void TouchScreen::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
TouchScreenSharedMemoryFormat& shared_memory = data->shared_memory_format->touch_screen;
shared_memory.touch_screen_lifo.timestamp = core_timing.GetGlobalTimeNs().count(); shared_memory.touch_screen_lifo.timestamp = core_timing.GetGlobalTimeNs().count();
if (!IsControllerActivated()) { if (!IsControllerActivated()) {

View file

@ -18,8 +18,7 @@ struct TouchScreenSharedMemoryFormat;
class TouchScreen final : public ControllerBase { class TouchScreen final : public ControllerBase {
public: public:
explicit TouchScreen(Core::HID::HIDCore& hid_core_, explicit TouchScreen(Core::HID::HIDCore& hid_core_);
TouchScreenSharedMemoryFormat& touch_shared_memory);
~TouchScreen() override; ~TouchScreen() override;
// Called when the controller is initialized // Called when the controller is initialized
@ -35,7 +34,6 @@ public:
private: private:
TouchScreenState next_state{}; TouchScreenState next_state{};
TouchScreenSharedMemoryFormat& shared_memory;
Core::HID::EmulatedConsole* console = nullptr; Core::HID::EmulatedConsole* console = nullptr;
std::array<Core::HID::TouchFinger, MAX_FINGERS> fingers{}; std::array<Core::HID::TouchFinger, MAX_FINGERS> fingers{};

View file

@ -0,0 +1,38 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core_timing.h"
#include "core/hle/service/hid/controllers/applet_resource.h"
#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
#include "core/hle/service/hid/controllers/unique_pad.h"
namespace Service::HID {
UniquePad::UniquePad(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {}
UniquePad::~UniquePad() = default;
void UniquePad::OnInit() {}
void UniquePad::OnRelease() {}
void UniquePad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
if (!smart_update) {
return;
}
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
auto& header = data->shared_memory_format->capture_button.header;
header.timestamp = core_timing.GetGlobalTimeNs().count();
header.total_entry_count = 17;
header.entry_count = 0;
header.last_entry_index = 0;
}
} // namespace Service::HID

View file

@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "core/hle/service/hid/controllers/controller_base.h"
namespace Service::HID {
class UniquePad final : public ControllerBase {
public:
explicit UniquePad(Core::HID::HIDCore& hid_core_);
~UniquePad() override;
// Called when the controller is initialized
void OnInit() override;
// When the controller is released
void OnRelease() override;
// When the controller is requesting an update for the shared memory
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
private:
bool smart_update{};
};
} // namespace Service::HID

View file

@ -10,18 +10,23 @@
#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/ipc_helpers.h"
#include "core/hle/service/hid/controllers/applet_resource.h" #include "core/hle/service/hid/controllers/applet_resource.h"
#include "core/hle/service/hid/controllers/capture_button.h"
#include "core/hle/service/hid/controllers/console_six_axis.h" #include "core/hle/service/hid/controllers/console_six_axis.h"
#include "core/hle/service/hid/controllers/debug_mouse.h"
#include "core/hle/service/hid/controllers/debug_pad.h" #include "core/hle/service/hid/controllers/debug_pad.h"
#include "core/hle/service/hid/controllers/digitizer.h"
#include "core/hle/service/hid/controllers/gesture.h" #include "core/hle/service/hid/controllers/gesture.h"
#include "core/hle/service/hid/controllers/home_button.h"
#include "core/hle/service/hid/controllers/keyboard.h" #include "core/hle/service/hid/controllers/keyboard.h"
#include "core/hle/service/hid/controllers/mouse.h" #include "core/hle/service/hid/controllers/mouse.h"
#include "core/hle/service/hid/controllers/npad.h" #include "core/hle/service/hid/controllers/npad.h"
#include "core/hle/service/hid/controllers/palma.h" #include "core/hle/service/hid/controllers/palma.h"
#include "core/hle/service/hid/controllers/seven_six_axis.h" #include "core/hle/service/hid/controllers/seven_six_axis.h"
#include "core/hle/service/hid/controllers/shared_memory_format.h"
#include "core/hle/service/hid/controllers/six_axis.h" #include "core/hle/service/hid/controllers/six_axis.h"
#include "core/hle/service/hid/controllers/stubbed.h" #include "core/hle/service/hid/controllers/sleep_button.h"
#include "core/hle/service/hid/controllers/touchscreen.h" #include "core/hle/service/hid/controllers/touchscreen.h"
#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
#include "core/hle/service/hid/controllers/unique_pad.h"
namespace Service::HID { namespace Service::HID {
@ -46,44 +51,15 @@ void ResourceManager::Initialize() {
} }
system.HIDCore().ReloadInputDevices(); system.HIDCore().ReloadInputDevices();
InitializeHidCommonSampler();
InitializeTouchScreenSampler();
InitializeConsoleSixAxisSampler();
InitializeAHidSampler();
is_initialized = true; is_initialized = true;
} }
void ResourceManager::InitializeController(u64 aruid) {
SharedMemoryFormat* shared_memory = nullptr;
const auto result = applet_resource->GetSharedMemoryFormat(&shared_memory, aruid);
if (result.IsError()) {
return;
}
debug_pad = std::make_shared<DebugPad>(system.HIDCore(), shared_memory->debug_pad);
mouse = std::make_shared<Mouse>(system.HIDCore(), shared_memory->mouse);
debug_mouse = std::make_shared<DebugMouse>(system.HIDCore(), shared_memory->debug_mouse);
keyboard = std::make_shared<Keyboard>(system.HIDCore(), shared_memory->keyboard);
unique_pad = std::make_shared<UniquePad>(system.HIDCore(), shared_memory->unique_pad.header);
npad = std::make_shared<NPad>(system.HIDCore(), shared_memory->npad, service_context);
gesture = std::make_shared<Gesture>(system.HIDCore(), shared_memory->gesture);
touch_screen = std::make_shared<TouchScreen>(system.HIDCore(), shared_memory->touch_screen);
palma = std::make_shared<Palma>(system.HIDCore(), service_context);
home_button = std::make_shared<HomeButton>(system.HIDCore(), shared_memory->home_button.header);
sleep_button =
std::make_shared<SleepButton>(system.HIDCore(), shared_memory->sleep_button.header);
capture_button =
std::make_shared<CaptureButton>(system.HIDCore(), shared_memory->capture_button.header);
digitizer = std::make_shared<Digitizer>(system.HIDCore(), shared_memory->digitizer.header);
six_axis = std::make_shared<SixAxis>(system.HIDCore(), npad);
console_six_axis = std::make_shared<ConsoleSixAxis>(system.HIDCore(), shared_memory->console);
seven_six_axis = std::make_shared<SevenSixAxis>(system);
// Homebrew doesn't try to activate some controllers, so we activate them by default
npad->Activate();
six_axis->Activate();
touch_screen->Activate();
}
std::shared_ptr<AppletResource> ResourceManager::GetAppletResource() const { std::shared_ptr<AppletResource> ResourceManager::GetAppletResource() const {
return applet_resource; return applet_resource;
} }
@ -165,16 +141,65 @@ Result ResourceManager::CreateAppletResource(u64 aruid) {
if (result.IsError()) { if (result.IsError()) {
return result; return result;
} }
// Homebrew doesn't try to activate some controllers, so we activate them by default
npad->Activate();
six_axis->Activate();
touch_screen->Activate();
return GetNpad()->Activate(aruid); return GetNpad()->Activate(aruid);
} }
Result ResourceManager::CreateAppletResourceImpl(u64 aruid) { Result ResourceManager::CreateAppletResourceImpl(u64 aruid) {
std::scoped_lock lock{shared_mutex}; std::scoped_lock lock{shared_mutex};
const auto result = applet_resource->CreateAppletResource(aruid); return applet_resource->CreateAppletResource(aruid);
if (result.IsSuccess()) { }
InitializeController(aruid);
} void ResourceManager::InitializeHidCommonSampler() {
return result; debug_pad = std::make_shared<DebugPad>(system.HIDCore());
mouse = std::make_shared<Mouse>(system.HIDCore());
debug_mouse = std::make_shared<DebugMouse>(system.HIDCore());
keyboard = std::make_shared<Keyboard>(system.HIDCore());
unique_pad = std::make_shared<UniquePad>(system.HIDCore());
npad = std::make_shared<NPad>(system.HIDCore(), service_context);
gesture = std::make_shared<Gesture>(system.HIDCore());
home_button = std::make_shared<HomeButton>(system.HIDCore());
sleep_button = std::make_shared<SleepButton>(system.HIDCore());
capture_button = std::make_shared<CaptureButton>(system.HIDCore());
digitizer = std::make_shared<Digitizer>(system.HIDCore());
palma = std::make_shared<Palma>(system.HIDCore(), service_context);
six_axis = std::make_shared<SixAxis>(system.HIDCore(), npad);
debug_pad->SetAppletResource(applet_resource);
digitizer->SetAppletResource(applet_resource);
keyboard->SetAppletResource(applet_resource);
npad->SetAppletResource(applet_resource);
six_axis->SetAppletResource(applet_resource);
mouse->SetAppletResource(applet_resource);
debug_mouse->SetAppletResource(applet_resource);
home_button->SetAppletResource(applet_resource);
sleep_button->SetAppletResource(applet_resource);
capture_button->SetAppletResource(applet_resource);
}
void ResourceManager::InitializeTouchScreenSampler() {
gesture = std::make_shared<Gesture>(system.HIDCore());
touch_screen = std::make_shared<TouchScreen>(system.HIDCore());
touch_screen->SetAppletResource(applet_resource);
gesture->SetAppletResource(applet_resource);
}
void ResourceManager::InitializeConsoleSixAxisSampler() {
console_six_axis = std::make_shared<ConsoleSixAxis>(system.HIDCore());
seven_six_axis = std::make_shared<SevenSixAxis>(system);
console_six_axis->SetAppletResource(applet_resource);
}
void ResourceManager::InitializeAHidSampler() {
// TODO
} }
Result ResourceManager::RegisterCoreAppletResource() { Result ResourceManager::RegisterCoreAppletResource() {

View file

@ -20,24 +20,23 @@ class KSharedMemory;
namespace Service::HID { namespace Service::HID {
class AppletResource; class AppletResource;
class CaptureButton;
class Controller_Stubbed; class Controller_Stubbed;
class ConsoleSixAxis; class ConsoleSixAxis;
class DebugMouse;
class DebugPad; class DebugPad;
class Digitizer;
class Gesture; class Gesture;
class HomeButton;
class Keyboard; class Keyboard;
class Mouse; class Mouse;
class NPad; class NPad;
class Palma; class Palma;
class SevenSixAxis; class SevenSixAxis;
class SixAxis; class SixAxis;
class SleepButton;
class TouchScreen; class TouchScreen;
class UniquePad;
using CaptureButton = Controller_Stubbed;
using DebugMouse = Mouse;
using Digitizer = Controller_Stubbed;
using HomeButton = Controller_Stubbed;
using SleepButton = Controller_Stubbed;
using UniquePad = Controller_Stubbed;
class ResourceManager { class ResourceManager {
@ -46,7 +45,6 @@ public:
~ResourceManager(); ~ResourceManager();
void Initialize(); void Initialize();
void InitializeController(u64 aruid);
std::shared_ptr<AppletResource> GetAppletResource() const; std::shared_ptr<AppletResource> GetAppletResource() const;
std::shared_ptr<CaptureButton> GetCaptureButton() const; std::shared_ptr<CaptureButton> GetCaptureButton() const;
@ -88,6 +86,10 @@ public:
private: private:
Result CreateAppletResourceImpl(u64 aruid); Result CreateAppletResourceImpl(u64 aruid);
void InitializeHidCommonSampler();
void InitializeTouchScreenSampler();
void InitializeConsoleSixAxisSampler();
void InitializeAHidSampler();
bool is_initialized{false}; bool is_initialized{false};