Deglobalize System: Hid
This commit is contained in:
parent
a9e9570d84
commit
28181919a6
20 changed files with 44 additions and 37 deletions
|
@ -9,12 +9,12 @@ namespace Service::HID {
|
||||||
ControllerBase::ControllerBase() = default;
|
ControllerBase::ControllerBase() = default;
|
||||||
ControllerBase::~ControllerBase() = default;
|
ControllerBase::~ControllerBase() = default;
|
||||||
|
|
||||||
void ControllerBase::ActivateController() {
|
void ControllerBase::ActivateController(Core::System& system) {
|
||||||
if (is_activated) {
|
if (is_activated) {
|
||||||
OnRelease();
|
OnRelease();
|
||||||
}
|
}
|
||||||
is_activated = true;
|
is_activated = true;
|
||||||
OnInit();
|
OnInit(system);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControllerBase::DeactivateController() {
|
void ControllerBase::DeactivateController() {
|
||||||
|
|
|
@ -11,6 +11,10 @@ namespace Core::Timing {
|
||||||
class CoreTiming;
|
class CoreTiming;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class System;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Service::HID {
|
namespace Service::HID {
|
||||||
class ControllerBase {
|
class ControllerBase {
|
||||||
public:
|
public:
|
||||||
|
@ -18,7 +22,7 @@ public:
|
||||||
virtual ~ControllerBase();
|
virtual ~ControllerBase();
|
||||||
|
|
||||||
// Called when the controller is initialized
|
// Called when the controller is initialized
|
||||||
virtual void OnInit() = 0;
|
virtual void OnInit(Core::System& system) = 0;
|
||||||
|
|
||||||
// When the controller is released
|
// When the controller is released
|
||||||
virtual void OnRelease() = 0;
|
virtual void OnRelease() = 0;
|
||||||
|
@ -30,7 +34,7 @@ public:
|
||||||
// Called when input devices should be loaded
|
// Called when input devices should be loaded
|
||||||
virtual void OnLoadInputDevices() = 0;
|
virtual void OnLoadInputDevices() = 0;
|
||||||
|
|
||||||
void ActivateController();
|
void ActivateController(Core::System& system);
|
||||||
|
|
||||||
void DeactivateController();
|
void DeactivateController();
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ enum class JoystickId : std::size_t { Joystick_Left, Joystick_Right };
|
||||||
Controller_DebugPad::Controller_DebugPad() = default;
|
Controller_DebugPad::Controller_DebugPad() = default;
|
||||||
Controller_DebugPad::~Controller_DebugPad() = default;
|
Controller_DebugPad::~Controller_DebugPad() = default;
|
||||||
|
|
||||||
void Controller_DebugPad::OnInit() {}
|
void Controller_DebugPad::OnInit(Core::System& system) {}
|
||||||
|
|
||||||
void Controller_DebugPad::OnRelease() {}
|
void Controller_DebugPad::OnRelease() {}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
~Controller_DebugPad() override;
|
~Controller_DebugPad() override;
|
||||||
|
|
||||||
// Called when the controller is initialized
|
// Called when the controller is initialized
|
||||||
void OnInit() override;
|
void OnInit(Core::System& system) override;
|
||||||
|
|
||||||
// When the controller is released
|
// When the controller is released
|
||||||
void OnRelease() override;
|
void OnRelease() override;
|
||||||
|
|
|
@ -13,7 +13,7 @@ constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3BA00;
|
||||||
Controller_Gesture::Controller_Gesture() = default;
|
Controller_Gesture::Controller_Gesture() = default;
|
||||||
Controller_Gesture::~Controller_Gesture() = default;
|
Controller_Gesture::~Controller_Gesture() = default;
|
||||||
|
|
||||||
void Controller_Gesture::OnInit() {}
|
void Controller_Gesture::OnInit(Core::System& system) {}
|
||||||
|
|
||||||
void Controller_Gesture::OnRelease() {}
|
void Controller_Gesture::OnRelease() {}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ public:
|
||||||
~Controller_Gesture() override;
|
~Controller_Gesture() override;
|
||||||
|
|
||||||
// Called when the controller is initialized
|
// Called when the controller is initialized
|
||||||
void OnInit() override;
|
void OnInit(Core::System& system) override;
|
||||||
|
|
||||||
// When the controller is released
|
// When the controller is released
|
||||||
void OnRelease() override;
|
void OnRelease() override;
|
||||||
|
|
|
@ -15,7 +15,7 @@ constexpr u8 KEYS_PER_BYTE = 8;
|
||||||
Controller_Keyboard::Controller_Keyboard() = default;
|
Controller_Keyboard::Controller_Keyboard() = default;
|
||||||
Controller_Keyboard::~Controller_Keyboard() = default;
|
Controller_Keyboard::~Controller_Keyboard() = default;
|
||||||
|
|
||||||
void Controller_Keyboard::OnInit() {}
|
void Controller_Keyboard::OnInit(Core::System& system) {}
|
||||||
|
|
||||||
void Controller_Keyboard::OnRelease() {}
|
void Controller_Keyboard::OnRelease() {}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ public:
|
||||||
~Controller_Keyboard() override;
|
~Controller_Keyboard() override;
|
||||||
|
|
||||||
// Called when the controller is initialized
|
// Called when the controller is initialized
|
||||||
void OnInit() override;
|
void OnInit(Core::System& system) override;
|
||||||
|
|
||||||
// When the controller is released
|
// When the controller is released
|
||||||
void OnRelease() override;
|
void OnRelease() override;
|
||||||
|
|
|
@ -14,7 +14,7 @@ constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3400;
|
||||||
Controller_Mouse::Controller_Mouse() = default;
|
Controller_Mouse::Controller_Mouse() = default;
|
||||||
Controller_Mouse::~Controller_Mouse() = default;
|
Controller_Mouse::~Controller_Mouse() = default;
|
||||||
|
|
||||||
void Controller_Mouse::OnInit() {}
|
void Controller_Mouse::OnInit(Core::System& system) {}
|
||||||
void Controller_Mouse::OnRelease() {}
|
void Controller_Mouse::OnRelease() {}
|
||||||
|
|
||||||
void Controller_Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
|
void Controller_Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
|
||||||
|
|
|
@ -18,7 +18,7 @@ public:
|
||||||
~Controller_Mouse() override;
|
~Controller_Mouse() override;
|
||||||
|
|
||||||
// Called when the controller is initialized
|
// Called when the controller is initialized
|
||||||
void OnInit() override;
|
void OnInit(Core::System& system) override;
|
||||||
|
|
||||||
// When the controller is released
|
// When the controller is released
|
||||||
void OnRelease() override;
|
void OnRelease() override;
|
||||||
|
|
|
@ -167,8 +167,8 @@ void Controller_NPad::InitNewlyAddedControler(std::size_t controller_idx) {
|
||||||
controller.battery_level[2] = BATTERY_FULL;
|
controller.battery_level[2] = BATTERY_FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller_NPad::OnInit() {
|
void Controller_NPad::OnInit(Core::System& system) {
|
||||||
auto& kernel = Core::System::GetInstance().Kernel();
|
auto& kernel = system.Kernel();
|
||||||
styleset_changed_event = Kernel::WritableEvent::CreateEventPair(
|
styleset_changed_event = Kernel::WritableEvent::CreateEventPair(
|
||||||
kernel, Kernel::ResetType::Automatic, "npad:NpadStyleSetChanged");
|
kernel, Kernel::ResetType::Automatic, "npad:NpadStyleSetChanged");
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ public:
|
||||||
~Controller_NPad() override;
|
~Controller_NPad() override;
|
||||||
|
|
||||||
// Called when the controller is initialized
|
// Called when the controller is initialized
|
||||||
void OnInit() override;
|
void OnInit(Core::System& system) override;
|
||||||
|
|
||||||
// When the controller is released
|
// When the controller is released
|
||||||
void OnRelease() override;
|
void OnRelease() override;
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace Service::HID {
|
||||||
Controller_Stubbed::Controller_Stubbed() = default;
|
Controller_Stubbed::Controller_Stubbed() = default;
|
||||||
Controller_Stubbed::~Controller_Stubbed() = default;
|
Controller_Stubbed::~Controller_Stubbed() = default;
|
||||||
|
|
||||||
void Controller_Stubbed::OnInit() {}
|
void Controller_Stubbed::OnInit(Core::System& system) {}
|
||||||
|
|
||||||
void Controller_Stubbed::OnRelease() {}
|
void Controller_Stubbed::OnRelease() {}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ public:
|
||||||
~Controller_Stubbed() override;
|
~Controller_Stubbed() override;
|
||||||
|
|
||||||
// Called when the controller is initialized
|
// Called when the controller is initialized
|
||||||
void OnInit() override;
|
void OnInit(Core::System& system) override;
|
||||||
|
|
||||||
// When the controller is released
|
// When the controller is released
|
||||||
void OnRelease() override;
|
void OnRelease() override;
|
||||||
|
|
|
@ -16,7 +16,7 @@ constexpr std::size_t SHARED_MEMORY_OFFSET = 0x400;
|
||||||
Controller_Touchscreen::Controller_Touchscreen() = default;
|
Controller_Touchscreen::Controller_Touchscreen() = default;
|
||||||
Controller_Touchscreen::~Controller_Touchscreen() = default;
|
Controller_Touchscreen::~Controller_Touchscreen() = default;
|
||||||
|
|
||||||
void Controller_Touchscreen::OnInit() {}
|
void Controller_Touchscreen::OnInit(Core::System& system) {}
|
||||||
|
|
||||||
void Controller_Touchscreen::OnRelease() {}
|
void Controller_Touchscreen::OnRelease() {}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ public:
|
||||||
~Controller_Touchscreen() override;
|
~Controller_Touchscreen() override;
|
||||||
|
|
||||||
// Called when the controller is initialized
|
// Called when the controller is initialized
|
||||||
void OnInit() override;
|
void OnInit(Core::System& system) override;
|
||||||
|
|
||||||
// When the controller is released
|
// When the controller is released
|
||||||
void OnRelease() override;
|
void OnRelease() override;
|
||||||
|
|
|
@ -13,7 +13,7 @@ constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C00;
|
||||||
Controller_XPad::Controller_XPad() = default;
|
Controller_XPad::Controller_XPad() = default;
|
||||||
Controller_XPad::~Controller_XPad() = default;
|
Controller_XPad::~Controller_XPad() = default;
|
||||||
|
|
||||||
void Controller_XPad::OnInit() {}
|
void Controller_XPad::OnInit(Core::System& system) {}
|
||||||
|
|
||||||
void Controller_XPad::OnRelease() {}
|
void Controller_XPad::OnRelease() {}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ public:
|
||||||
~Controller_XPad() override;
|
~Controller_XPad() override;
|
||||||
|
|
||||||
// Called when the controller is initialized
|
// Called when the controller is initialized
|
||||||
void OnInit() override;
|
void OnInit(Core::System& system) override;
|
||||||
|
|
||||||
// When the controller is released
|
// When the controller is released
|
||||||
void OnRelease() override;
|
void OnRelease() override;
|
||||||
|
|
|
@ -42,13 +42,14 @@ constexpr s64 accelerometer_update_ticks = static_cast<s64>(Core::Timing::BASE_C
|
||||||
constexpr s64 gyroscope_update_ticks = static_cast<s64>(Core::Timing::BASE_CLOCK_RATE / 100);
|
constexpr s64 gyroscope_update_ticks = static_cast<s64>(Core::Timing::BASE_CLOCK_RATE / 100);
|
||||||
constexpr std::size_t SHARED_MEMORY_SIZE = 0x40000;
|
constexpr std::size_t SHARED_MEMORY_SIZE = 0x40000;
|
||||||
|
|
||||||
IAppletResource::IAppletResource() : ServiceFramework("IAppletResource") {
|
IAppletResource::IAppletResource(Core::System& system)
|
||||||
|
: ServiceFramework("IAppletResource"), system(system) {
|
||||||
static const FunctionInfo functions[] = {
|
static const FunctionInfo functions[] = {
|
||||||
{0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"},
|
{0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"},
|
||||||
};
|
};
|
||||||
RegisterHandlers(functions);
|
RegisterHandlers(functions);
|
||||||
|
|
||||||
auto& kernel = Core::System::GetInstance().Kernel();
|
auto& kernel = system.Kernel();
|
||||||
shared_mem = Kernel::SharedMemory::Create(
|
shared_mem = Kernel::SharedMemory::Create(
|
||||||
kernel, nullptr, SHARED_MEMORY_SIZE, Kernel::MemoryPermission::ReadWrite,
|
kernel, nullptr, SHARED_MEMORY_SIZE, Kernel::MemoryPermission::ReadWrite,
|
||||||
Kernel::MemoryPermission::Read, 0, Kernel::MemoryRegion::BASE, "HID:SharedMemory");
|
Kernel::MemoryPermission::Read, 0, Kernel::MemoryRegion::BASE, "HID:SharedMemory");
|
||||||
|
@ -66,15 +67,15 @@ IAppletResource::IAppletResource() : ServiceFramework("IAppletResource") {
|
||||||
MakeController<Controller_Gesture>(HidController::Gesture);
|
MakeController<Controller_Gesture>(HidController::Gesture);
|
||||||
|
|
||||||
// Homebrew doesn't try to activate some controllers, so we activate them by default
|
// Homebrew doesn't try to activate some controllers, so we activate them by default
|
||||||
GetController<Controller_NPad>(HidController::NPad).ActivateController();
|
GetController<Controller_NPad>(HidController::NPad).ActivateController(system);
|
||||||
GetController<Controller_Touchscreen>(HidController::Touchscreen).ActivateController();
|
GetController<Controller_Touchscreen>(HidController::Touchscreen).ActivateController(system);
|
||||||
|
|
||||||
GetController<Controller_Stubbed>(HidController::Unknown1).SetCommonHeaderOffset(0x4c00);
|
GetController<Controller_Stubbed>(HidController::Unknown1).SetCommonHeaderOffset(0x4c00);
|
||||||
GetController<Controller_Stubbed>(HidController::Unknown2).SetCommonHeaderOffset(0x4e00);
|
GetController<Controller_Stubbed>(HidController::Unknown2).SetCommonHeaderOffset(0x4e00);
|
||||||
GetController<Controller_Stubbed>(HidController::Unknown3).SetCommonHeaderOffset(0x5000);
|
GetController<Controller_Stubbed>(HidController::Unknown3).SetCommonHeaderOffset(0x5000);
|
||||||
|
|
||||||
// Register update callbacks
|
// Register update callbacks
|
||||||
auto& core_timing = Core::System::GetInstance().CoreTiming();
|
auto& core_timing = system.CoreTiming();
|
||||||
pad_update_event =
|
pad_update_event =
|
||||||
core_timing.RegisterEvent("HID::UpdatePadCallback", [this](u64 userdata, s64 cycles_late) {
|
core_timing.RegisterEvent("HID::UpdatePadCallback", [this](u64 userdata, s64 cycles_late) {
|
||||||
UpdateControllers(userdata, cycles_late);
|
UpdateControllers(userdata, cycles_late);
|
||||||
|
@ -88,7 +89,7 @@ IAppletResource::IAppletResource() : ServiceFramework("IAppletResource") {
|
||||||
}
|
}
|
||||||
|
|
||||||
void IAppletResource::ActivateController(HidController controller) {
|
void IAppletResource::ActivateController(HidController controller) {
|
||||||
controllers[static_cast<size_t>(controller)]->ActivateController();
|
controllers[static_cast<size_t>(controller)]->ActivateController(system);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IAppletResource::DeactivateController(HidController controller) {
|
void IAppletResource::DeactivateController(HidController controller) {
|
||||||
|
@ -96,7 +97,7 @@ void IAppletResource::DeactivateController(HidController controller) {
|
||||||
}
|
}
|
||||||
|
|
||||||
IAppletResource ::~IAppletResource() {
|
IAppletResource ::~IAppletResource() {
|
||||||
Core::System::GetInstance().CoreTiming().UnscheduleEvent(pad_update_event, 0);
|
system.CoreTiming().UnscheduleEvent(pad_update_event, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IAppletResource::GetSharedMemoryHandle(Kernel::HLERequestContext& ctx) {
|
void IAppletResource::GetSharedMemoryHandle(Kernel::HLERequestContext& ctx) {
|
||||||
|
@ -108,7 +109,7 @@ void IAppletResource::GetSharedMemoryHandle(Kernel::HLERequestContext& ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void IAppletResource::UpdateControllers(u64 userdata, s64 cycles_late) {
|
void IAppletResource::UpdateControllers(u64 userdata, s64 cycles_late) {
|
||||||
auto& core_timing = Core::System::GetInstance().CoreTiming();
|
auto& core_timing = system.CoreTiming();
|
||||||
|
|
||||||
const bool should_reload = Settings::values.is_device_reload_pending.exchange(false);
|
const bool should_reload = Settings::values.is_device_reload_pending.exchange(false);
|
||||||
for (const auto& controller : controllers) {
|
for (const auto& controller : controllers) {
|
||||||
|
@ -141,13 +142,13 @@ private:
|
||||||
|
|
||||||
std::shared_ptr<IAppletResource> Hid::GetAppletResource() {
|
std::shared_ptr<IAppletResource> Hid::GetAppletResource() {
|
||||||
if (applet_resource == nullptr) {
|
if (applet_resource == nullptr) {
|
||||||
applet_resource = std::make_shared<IAppletResource>();
|
applet_resource = std::make_shared<IAppletResource>(system);
|
||||||
}
|
}
|
||||||
|
|
||||||
return applet_resource;
|
return applet_resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
Hid::Hid() : ServiceFramework("hid") {
|
Hid::Hid(Core::System& system) : ServiceFramework("hid"), system(system) {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
static const FunctionInfo functions[] = {
|
static const FunctionInfo functions[] = {
|
||||||
{0, &Hid::CreateAppletResource, "CreateAppletResource"},
|
{0, &Hid::CreateAppletResource, "CreateAppletResource"},
|
||||||
|
@ -286,7 +287,7 @@ void Hid::CreateAppletResource(Kernel::HLERequestContext& ctx) {
|
||||||
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||||
|
|
||||||
if (applet_resource == nullptr) {
|
if (applet_resource == nullptr) {
|
||||||
applet_resource = std::make_shared<IAppletResource>();
|
applet_resource = std::make_shared<IAppletResource>(system);
|
||||||
}
|
}
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
||||||
|
@ -1053,8 +1054,8 @@ void ReloadInputDevices() {
|
||||||
Settings::values.is_device_reload_pending.store(true);
|
Settings::values.is_device_reload_pending.store(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstallInterfaces(SM::ServiceManager& service_manager) {
|
void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) {
|
||||||
std::make_shared<Hid>()->InstallAsService(service_manager);
|
std::make_shared<Hid>(system)->InstallAsService(service_manager);
|
||||||
std::make_shared<HidBus>()->InstallAsService(service_manager);
|
std::make_shared<HidBus>()->InstallAsService(service_manager);
|
||||||
std::make_shared<HidDbg>()->InstallAsService(service_manager);
|
std::make_shared<HidDbg>()->InstallAsService(service_manager);
|
||||||
std::make_shared<HidSys>()->InstallAsService(service_manager);
|
std::make_shared<HidSys>()->InstallAsService(service_manager);
|
||||||
|
|
|
@ -42,7 +42,7 @@ enum class HidController : std::size_t {
|
||||||
|
|
||||||
class IAppletResource final : public ServiceFramework<IAppletResource> {
|
class IAppletResource final : public ServiceFramework<IAppletResource> {
|
||||||
public:
|
public:
|
||||||
IAppletResource();
|
IAppletResource(Core::System& system);
|
||||||
~IAppletResource() override;
|
~IAppletResource() override;
|
||||||
|
|
||||||
void ActivateController(HidController controller);
|
void ActivateController(HidController controller);
|
||||||
|
@ -70,6 +70,7 @@ private:
|
||||||
Kernel::SharedPtr<Kernel::SharedMemory> shared_mem;
|
Kernel::SharedPtr<Kernel::SharedMemory> shared_mem;
|
||||||
|
|
||||||
Core::Timing::EventType* pad_update_event;
|
Core::Timing::EventType* pad_update_event;
|
||||||
|
Core::System& system;
|
||||||
|
|
||||||
std::array<std::unique_ptr<ControllerBase>, static_cast<size_t>(HidController::MaxControllers)>
|
std::array<std::unique_ptr<ControllerBase>, static_cast<size_t>(HidController::MaxControllers)>
|
||||||
controllers{};
|
controllers{};
|
||||||
|
@ -77,7 +78,7 @@ private:
|
||||||
|
|
||||||
class Hid final : public ServiceFramework<Hid> {
|
class Hid final : public ServiceFramework<Hid> {
|
||||||
public:
|
public:
|
||||||
Hid();
|
Hid(Core::System& system);
|
||||||
~Hid() override;
|
~Hid() override;
|
||||||
|
|
||||||
std::shared_ptr<IAppletResource> GetAppletResource();
|
std::shared_ptr<IAppletResource> GetAppletResource();
|
||||||
|
@ -126,12 +127,13 @@ private:
|
||||||
void SwapNpadAssignment(Kernel::HLERequestContext& ctx);
|
void SwapNpadAssignment(Kernel::HLERequestContext& ctx);
|
||||||
|
|
||||||
std::shared_ptr<IAppletResource> applet_resource;
|
std::shared_ptr<IAppletResource> applet_resource;
|
||||||
|
Core::System& system;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Reload input devices. Used when input configuration changed
|
/// Reload input devices. Used when input configuration changed
|
||||||
void ReloadInputDevices();
|
void ReloadInputDevices();
|
||||||
|
|
||||||
/// Registers all HID services with the specified service manager.
|
/// Registers all HID services with the specified service manager.
|
||||||
void InstallInterfaces(SM::ServiceManager& service_manager);
|
void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system);
|
||||||
|
|
||||||
} // namespace Service::HID
|
} // namespace Service::HID
|
||||||
|
|
Loading…
Reference in a new issue