yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

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/mouse_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/applet_resource.cpp
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.h
hle/service/hid/controllers/controller_base.cpp
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.h
hle/service/hid/controllers/digitizer.cpp
hle/service/hid/controllers/digitizer.h
hle/service/hid/controllers/gesture.cpp
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.h
hle/service/hid/controllers/mouse.cpp
@ -574,15 +583,16 @@ add_library(core STATIC
hle/service/hid/controllers/palma.h
hle/service/hid/controllers/seven_six_axis.cpp
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.h
hle/service/hid/controllers/six_axis.cpp
hle/service/hid/controllers/six_axis.h
hle/service/hid/controllers/stubbed.cpp
hle/service/hid/controllers/stubbed.h
hle/service/hid/controllers/sleep_button.cpp
hle/service/hid/controllers/sleep_button.h
hle/service/hid/controllers/touchscreen.cpp
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.h
hle/service/hid/hidbus/ringcon.cpp

View File

@ -4,7 +4,7 @@
#include "core/core.h"
#include "core/hle/kernel/k_shared_memory.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"
namespace Service::HID {
@ -164,6 +164,22 @@ Result AppletResource::GetSharedMemoryFormat(SharedMemoryFormat** out_shared_mem
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) {
for (std::size_t i = 0; i < AruidIndexMax; i++) {
if (registration_list.flag[i] == RegistrationStatus::Initialized &&

View File

@ -4,6 +4,7 @@
#pragma once
#include <array>
#include <mutex>
#include "common/bit_field.h"
#include "common/common_types.h"
@ -20,6 +21,59 @@ class KSharedMemory;
namespace Service::HID {
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 {
public:
@ -36,6 +90,10 @@ public:
u64 GetActiveAruid();
Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, 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);
@ -52,46 +110,12 @@ public:
Result UnregisterCoreAppletResource();
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{};
AruidRegisterList registration_list{};
std::array<AruidData, AruidIndexMax> data{};
std::array<SharedMemoryHolder, AruidIndexMax> shared_memory_holder{};
s32 ref_counter{};
u64 active_vibration_aruid;
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"
namespace Service::HID {
struct CommonHeader;
class Controller_Stubbed final : public ControllerBase {
class CaptureButton final : public ControllerBase {
public:
explicit Controller_Stubbed(Core::HID::HIDCore& hid_core_, CommonHeader& ring_lifo_header);
~Controller_Stubbed() override;
explicit CaptureButton(Core::HID::HIDCore& hid_core_);
~CaptureButton() override;
// Called when the controller is initialized
void OnInit() override;
@ -23,7 +22,6 @@ public:
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
private:
CommonHeader& header;
bool smart_update{};
};
} // namespace Service::HID

View File

@ -5,13 +5,11 @@
#include "core/hid/emulated_console.h"
#include "core/hid/hid_core.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 {
ConsoleSixAxis::ConsoleSixAxis(Core::HID::HIDCore& hid_core_,
ConsoleSixAxisSensorSharedMemoryFormat& console_shared_memory)
: ControllerBase{hid_core_}, shared_memory{console_shared_memory} {
ConsoleSixAxis::ConsoleSixAxis(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {
console = hid_core.GetEmulatedConsole();
}
@ -22,6 +20,15 @@ void ConsoleSixAxis::OnInit() {}
void ConsoleSixAxis::OnRelease() {}
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()) {
return;
}

View File

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

View File

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

View File

@ -3,8 +3,11 @@
#pragma once
#include <memory>
#include "common/common_types.h"
#include "core/hle/result.h"
#include "core/hle/service/hid/controllers/applet_resource.h"
namespace Core::Timing {
class CoreTiming;
@ -12,7 +15,7 @@ class CoreTiming;
namespace Core::HID {
class HIDCore;
}
} // namespace Core::HID
namespace Service::HID {
class ControllerBase {
@ -39,8 +42,11 @@ public:
bool IsControllerActivated() const;
void SetAppletResource(std::shared_ptr<AppletResource> resource);
protected:
bool is_activated{false};
std::shared_ptr<AppletResource> applet_resource{nullptr};
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/hid_core.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/shared_memory_format.h"
#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
namespace Service::HID {
DebugPad::DebugPad(Core::HID::HIDCore& hid_core_,
DebugPadSharedMemoryFormat& debug_pad_shared_memory)
: ControllerBase{hid_core_}, shared_memory{debug_pad_shared_memory} {
DebugPad::DebugPad(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {
controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Other);
}
@ -24,6 +23,15 @@ void DebugPad::OnInit() {}
void DebugPad::OnRelease() {}
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()) {
shared_memory.debug_pad_lifo.buffer_count = 0;
shared_memory.debug_pad_lifo.buffer_tail = 0;

View File

@ -15,12 +15,9 @@ class CoreTiming;
}
namespace Service::HID {
struct DebugPadSharedMemoryFormat;
class DebugPad final : public ControllerBase {
public:
explicit DebugPad(Core::HID::HIDCore& hid_core_,
DebugPadSharedMemoryFormat& debug_pad_shared_memory);
explicit DebugPad(Core::HID::HIDCore& hid_core_);
~DebugPad() override;
// Called when the controller is initialized
@ -34,7 +31,6 @@ public:
private:
DebugPadState next_state{};
DebugPadSharedMemoryFormat& shared_memory;
Core::HID::EmulatedController* controller = nullptr;
};
} // 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/hid/emulated_console.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/shared_memory_format.h"
#include "core/hle/service/hid/controllers/types/shared_memory_format.h"
namespace Service::HID {
// 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);
}
Gesture::Gesture(Core::HID::HIDCore& hid_core_, GestureSharedMemoryFormat& gesture_shared_memory)
: ControllerBase(hid_core_), shared_memory{gesture_shared_memory} {
Gesture::Gesture(Core::HID::HIDCore& hid_core_) : ControllerBase(hid_core_) {
console = hid_core.GetEmulatedConsole();
}
Gesture::~Gesture() = default;
void Gesture::OnInit() {
shared_memory.gesture_lifo.buffer_count = 0;
shared_memory.gesture_lifo.buffer_tail = 0;
const u64 aruid = applet_resource->GetActiveAruid();
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;
}
void Gesture::OnRelease() {}
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()) {
shared_memory.gesture_lifo.buffer_count = 0;
shared_memory.gesture_lifo.buffer_tail = 0;
shared_memory->gesture_lifo.buffer_count = 0;
shared_memory->gesture_lifo.buffer_tail = 0;
return;
}
@ -46,7 +63,7 @@ void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
GestureProperties gesture = GetGestureProperties();
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);
// Only update if necessary
@ -54,7 +71,7 @@ void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
return;
}
last_update_timestamp = shared_memory.gesture_lifo.timestamp;
last_update_timestamp = shared_memory->gesture_lifo.timestamp;
UpdateGestureSharedMemory(gesture, time_difference);
}
@ -97,7 +114,7 @@ void Gesture::UpdateGestureSharedMemory(GestureProperties& gesture, f32 time_dif
GestureType type = GestureType::Idle;
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
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;
last_gesture = gesture;
shared_memory.gesture_lifo.WriteNextEntry(next_state);
shared_memory->gesture_lifo.WriteNextEntry(next_state);
}
void Gesture::NewGesture(GestureProperties& gesture, GestureType& type,
@ -300,7 +317,7 @@ void Gesture::SetSwipeEvent(GestureProperties& gesture, GestureProperties& last_
}
const GestureState& Gesture::GetLastGestureEntry() const {
return shared_memory.gesture_lifo.ReadCurrentEntry().state;
return shared_memory->gesture_lifo.ReadCurrentEntry().state;
}
GestureProperties Gesture::GetGestureProperties() {

View File

@ -18,8 +18,7 @@ struct GestureSharedMemoryFormat;
class Gesture final : public ControllerBase {
public:
explicit Gesture(Core::HID::HIDCore& hid_core_,
GestureSharedMemoryFormat& gesture_shared_memory);
explicit Gesture(Core::HID::HIDCore& hid_core_);
~Gesture() override;
// Called when the controller is initialized
@ -74,7 +73,7 @@ private:
GestureProperties GetGestureProperties();
GestureState next_state{};
GestureSharedMemoryFormat& shared_memory;
GestureSharedMemoryFormat* shared_memory;
Core::HID::EmulatedConsole* console = nullptr;
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/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/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 {
Keyboard::Keyboard(Core::HID::HIDCore& hid_core_,
KeyboardSharedMemoryFormat& keyboard_shared_memory)
: ControllerBase{hid_core_}, shared_memory{keyboard_shared_memory} {
Keyboard::Keyboard(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {
emulated_devices = hid_core.GetEmulatedDevices();
}
@ -23,6 +22,15 @@ void Keyboard::OnInit() {}
void Keyboard::OnRelease() {}
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()) {
shared_memory.keyboard_lifo.buffer_count = 0;
shared_memory.keyboard_lifo.buffer_tail = 0;

View File

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

View File

@ -5,13 +5,13 @@
#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/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 {
Mouse::Mouse(Core::HID::HIDCore& hid_core_, MouseSharedMemoryFormat& mouse_shared_memory)
: ControllerBase{hid_core_}, shared_memory{mouse_shared_memory} {
Mouse::Mouse(Core::HID::HIDCore& hid_core_) : ControllerBase{hid_core_} {
emulated_devices = hid_core.GetEmulatedDevices();
}
@ -21,6 +21,15 @@ void Mouse::OnInit() {}
void Mouse::OnRelease() {}
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()) {
shared_memory.mouse_lifo.buffer_count = 0;
shared_memory.mouse_lifo.buffer_tail = 0;

View File

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

View File

@ -16,8 +16,9 @@
#include "core/hid/hid_core.h"
#include "core/hle/kernel/k_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/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/hid_util.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,
};
NPad::NPad(Core::HID::HIDCore& hid_core_, NpadSharedMemoryFormat& npad_shared_memory_format,
KernelHelpers::ServiceContext& service_context_)
NPad::NPad(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service_context_)
: ControllerBase{hid_core_}, service_context{service_context_} {
for (std::size_t i = 0; i < controller_data.size(); ++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.vibration[Core::HID::EmulatedDeviceIndex::LeftIndex].latest_vibration_value =
Core::HID::DEFAULT_VIBRATION_VALUE;
@ -297,12 +296,20 @@ void NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
}
void NPad::OnInit() {
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
if (!IsControllerActivated()) {
return;
}
for (std::size_t i = 0; i < controller_data.size(); ++i) {
auto& controller = controller_data[i];
controller.shared_memory = &data->shared_memory_format->npad.npad_entry[i].internal_state;
controller.styleset_changed_event =
service_context.CreateEvent(fmt::format("npad:NpadStyleSetChanged_{}", i));
}
@ -355,7 +362,9 @@ void NPad::OnRelease() {
is_controller_initialized = false;
for (std::size_t i = 0; i < controller_data.size(); ++i) {
auto& controller = controller_data[i];
service_context.CloseEvent(controller.styleset_changed_event);
if (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) {
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) {
const u64 aruid = applet_resource->GetActiveAruid();
auto* data = applet_resource->GetAruidData(aruid);
if (data == nullptr) {
return;
}
if (!IsControllerActivated()) {
return;
}
for (std::size_t i = 0; i < controller_data.size(); ++i) {
auto& controller = controller_data[i];
controller.shared_memory = &data->shared_memory_format->npad.npad_entry[i].internal_state;
auto* npad = controller.shared_memory;
const auto& controller_type = controller.device->GetNpadStyleIndex();
@ -976,30 +993,6 @@ Result NPad::ResetIsSixAxisSensorDeviceNewlyAssigned(
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,
Core::HID::NpadIdType npad_id_2) {
if (!IsNpadIdValid(npad_id_1) || !IsNpadIdValid(npad_id_2)) {

View File

@ -30,14 +30,14 @@ class ServiceContext;
union Result;
namespace Service::HID {
class AppletResource;
struct NpadInternalState;
struct NpadSixAxisSensorLifo;
struct NpadSharedMemoryFormat;
class NPad final : public ControllerBase {
public:
explicit NPad(Core::HID::HIDCore& hid_core_, NpadSharedMemoryFormat& npad_shared_memory_format,
KernelHelpers::ServiceContext& service_context_);
explicit NPad(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service_context_);
~NPad() override;
// Called when the controller is initialized
@ -106,13 +106,6 @@ public:
Result ResetIsSixAxisSensorDeviceNewlyAssigned(
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 IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id,
bool& is_enabled) const;

View File

@ -3,8 +3,9 @@
#include "core/core.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/types/shared_memory_format.h"
#include "core/hle/service/hid/errors.h"
namespace Service::HID {

View File

@ -6,8 +6,8 @@
#include "core/hid/emulated_controller.h"
#include "core/hid/hid_core.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/types/shared_memory_format.h"
#include "core/hle/service/hid/errors.h"
#include "core/hle/service/hid/hid_util.h"
@ -27,14 +27,20 @@ void SixAxis::OnInit() {}
void SixAxis::OnRelease() {}
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()) {
return;
}
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];
const auto npad_id = IndexToNpadIdType(i);
const auto& controller_type = controller.device->GetNpadStyleIndex();
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_right_lifo_state = controller.sixaxis_right_lifo_state;
auto& sixaxis_fullkey_lifo = npad->GetSixAxisFullkeyLifo(npad_id);
auto& sixaxis_handheld_lifo = npad->GetSixAxisHandheldLifo(npad_id);
auto& sixaxis_dual_left_lifo = npad->GetSixAxisDualLeftLifo(npad_id);
auto& sixaxis_dual_right_lifo = npad->GetSixAxisDualRightLifo(npad_id);
auto& sixaxis_left_lifo = npad->GetSixAxisLeftLifo(npad_id);
auto& sixaxis_right_lifo = npad->GetSixAxisRightLifo(npad_id);
auto& sixaxis_fullkey_lifo = shared_memory.internal_state.sixaxis_fullkey_lifo;
auto& sixaxis_handheld_lifo = shared_memory.internal_state.sixaxis_handheld_lifo;
auto& sixaxis_dual_left_lifo = shared_memory.internal_state.sixaxis_dual_left_lifo;
auto& sixaxis_dual_right_lifo = shared_memory.internal_state.sixaxis_dual_right_lifo;
auto& sixaxis_left_lifo = shared_memory.internal_state.sixaxis_left_lifo;
auto& sixaxis_right_lifo = shared_memory.internal_state.sixaxis_right_lifo;
// Clear previous 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/hid/emulated_console.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/types/shared_memory_format.h"
namespace Service::HID {
TouchScreen::TouchScreen(Core::HID::HIDCore& hid_core_,
TouchScreenSharedMemoryFormat& touch_shared_memory)
: ControllerBase{hid_core_}, shared_memory{touch_shared_memory},
touchscreen_width(Layout::ScreenUndocked::Width),
TouchScreen::TouchScreen(Core::HID::HIDCore& hid_core_)
: ControllerBase{hid_core_}, touchscreen_width(Layout::ScreenUndocked::Width),
touchscreen_height(Layout::ScreenUndocked::Height) {
console = hid_core.GetEmulatedConsole();
}
@ -28,6 +27,14 @@ void TouchScreen::OnInit() {}
void TouchScreen::OnRelease() {}
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();
if (!IsControllerActivated()) {

View File

@ -18,8 +18,7 @@ struct TouchScreenSharedMemoryFormat;
class TouchScreen final : public ControllerBase {
public:
explicit TouchScreen(Core::HID::HIDCore& hid_core_,
TouchScreenSharedMemoryFormat& touch_shared_memory);
explicit TouchScreen(Core::HID::HIDCore& hid_core_);
~TouchScreen() override;
// Called when the controller is initialized
@ -35,7 +34,6 @@ public:
private:
TouchScreenState next_state{};
TouchScreenSharedMemoryFormat& shared_memory;
Core::HID::EmulatedConsole* console = nullptr;
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/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/debug_mouse.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/home_button.h"
#include "core/hle/service/hid/controllers/keyboard.h"
#include "core/hle/service/hid/controllers/mouse.h"
#include "core/hle/service/hid/controllers/npad.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/shared_memory_format.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/types/shared_memory_format.h"
#include "core/hle/service/hid/controllers/unique_pad.h"
namespace Service::HID {
@ -46,44 +51,15 @@ void ResourceManager::Initialize() {
}
system.HIDCore().ReloadInputDevices();
InitializeHidCommonSampler();
InitializeTouchScreenSampler();
InitializeConsoleSixAxisSampler();
InitializeAHidSampler();
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 {
return applet_resource;
}
@ -165,16 +141,65 @@ Result ResourceManager::CreateAppletResource(u64 aruid) {
if (result.IsError()) {
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);
}
Result ResourceManager::CreateAppletResourceImpl(u64 aruid) {
std::scoped_lock lock{shared_mutex};
const auto result = applet_resource->CreateAppletResource(aruid);
if (result.IsSuccess()) {
InitializeController(aruid);
}
return result;
return applet_resource->CreateAppletResource(aruid);
}
void ResourceManager::InitializeHidCommonSampler() {
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() {

View File

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