2023-11-15 04:34:27 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "core/hle/service/kernel_helpers.h"
|
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
|
2023-12-06 01:39:18 +01:00
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
2024-01-11 05:06:54 +01:00
|
|
|
namespace Core::HID {
|
|
|
|
struct VibrationDeviceHandle;
|
|
|
|
struct VibrationValue;
|
|
|
|
struct VibrationDeviceInfo;
|
|
|
|
} // namespace Core::HID
|
|
|
|
|
2023-11-15 04:34:27 +01:00
|
|
|
namespace Core::Timing {
|
|
|
|
struct EventType;
|
|
|
|
}
|
|
|
|
|
2023-12-06 01:39:18 +01:00
|
|
|
namespace Kernel {
|
|
|
|
class KSharedMemory;
|
|
|
|
}
|
|
|
|
|
2023-11-15 04:34:27 +01:00
|
|
|
namespace Service::HID {
|
2023-12-06 01:39:18 +01:00
|
|
|
class AppletResource;
|
2023-12-31 07:42:23 +01:00
|
|
|
class CaptureButton;
|
2023-11-17 18:46:26 +01:00
|
|
|
class Controller_Stubbed;
|
|
|
|
class ConsoleSixAxis;
|
2023-12-31 07:42:23 +01:00
|
|
|
class DebugMouse;
|
2023-11-17 18:46:26 +01:00
|
|
|
class DebugPad;
|
2023-12-31 07:42:23 +01:00
|
|
|
class Digitizer;
|
2023-11-17 18:46:26 +01:00
|
|
|
class Gesture;
|
2023-12-31 07:42:23 +01:00
|
|
|
class HomeButton;
|
2023-11-17 18:46:26 +01:00
|
|
|
class Keyboard;
|
|
|
|
class Mouse;
|
|
|
|
class NPad;
|
|
|
|
class Palma;
|
|
|
|
class SevenSixAxis;
|
|
|
|
class SixAxis;
|
2023-12-31 07:42:23 +01:00
|
|
|
class SleepButton;
|
2023-11-17 18:46:26 +01:00
|
|
|
class TouchScreen;
|
2023-12-31 07:42:23 +01:00
|
|
|
class UniquePad;
|
2024-01-11 05:06:54 +01:00
|
|
|
class NpadVibrationBase;
|
|
|
|
class NpadN64VibrationDevice;
|
|
|
|
class NpadGcVibrationDevice;
|
|
|
|
class NpadVibrationDevice;
|
|
|
|
struct HandheldConfig;
|
2023-11-15 04:34:27 +01:00
|
|
|
|
|
|
|
class ResourceManager {
|
2023-11-17 18:46:26 +01:00
|
|
|
|
2023-11-15 04:34:27 +01:00
|
|
|
public:
|
|
|
|
explicit ResourceManager(Core::System& system_);
|
|
|
|
~ResourceManager();
|
|
|
|
|
|
|
|
void Initialize();
|
|
|
|
|
2023-12-06 01:39:18 +01:00
|
|
|
std::shared_ptr<AppletResource> GetAppletResource() const;
|
2023-11-17 18:46:26 +01:00
|
|
|
std::shared_ptr<CaptureButton> GetCaptureButton() const;
|
|
|
|
std::shared_ptr<ConsoleSixAxis> GetConsoleSixAxis() const;
|
|
|
|
std::shared_ptr<DebugMouse> GetDebugMouse() const;
|
|
|
|
std::shared_ptr<DebugPad> GetDebugPad() const;
|
2023-12-14 04:39:38 +01:00
|
|
|
std::shared_ptr<Digitizer> GetDigitizer() const;
|
2023-11-17 18:46:26 +01:00
|
|
|
std::shared_ptr<Gesture> GetGesture() const;
|
|
|
|
std::shared_ptr<HomeButton> GetHomeButton() const;
|
|
|
|
std::shared_ptr<Keyboard> GetKeyboard() const;
|
|
|
|
std::shared_ptr<Mouse> GetMouse() const;
|
|
|
|
std::shared_ptr<NPad> GetNpad() const;
|
|
|
|
std::shared_ptr<Palma> GetPalma() const;
|
|
|
|
std::shared_ptr<SevenSixAxis> GetSevenSixAxis() const;
|
|
|
|
std::shared_ptr<SixAxis> GetSixAxis() const;
|
|
|
|
std::shared_ptr<SleepButton> GetSleepButton() const;
|
|
|
|
std::shared_ptr<TouchScreen> GetTouchScreen() const;
|
|
|
|
std::shared_ptr<UniquePad> GetUniquePad() const;
|
|
|
|
|
2023-12-06 01:39:18 +01:00
|
|
|
Result CreateAppletResource(u64 aruid);
|
|
|
|
|
2023-12-10 21:53:19 +01:00
|
|
|
Result RegisterCoreAppletResource();
|
|
|
|
Result UnregisterCoreAppletResource();
|
2023-12-06 01:39:18 +01:00
|
|
|
Result RegisterAppletResourceUserId(u64 aruid, bool bool_value);
|
|
|
|
void UnregisterAppletResourceUserId(u64 aruid);
|
|
|
|
|
|
|
|
Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid);
|
2023-12-10 21:53:19 +01:00
|
|
|
void FreeAppletResourceId(u64 aruid);
|
2023-12-06 01:39:18 +01:00
|
|
|
|
|
|
|
void EnableInput(u64 aruid, bool is_enabled);
|
|
|
|
void EnableSixAxisSensor(u64 aruid, bool is_enabled);
|
|
|
|
void EnablePadInput(u64 aruid, bool is_enabled);
|
|
|
|
void EnableTouchScreen(u64 aruid, bool is_enabled);
|
|
|
|
|
2024-01-11 05:06:54 +01:00
|
|
|
NpadVibrationBase* GetVibrationDevice(const Core::HID::VibrationDeviceHandle& handle);
|
|
|
|
NpadN64VibrationDevice* GetN64VibrationDevice(const Core::HID::VibrationDeviceHandle& handle);
|
|
|
|
NpadVibrationDevice* GetNSVibrationDevice(const Core::HID::VibrationDeviceHandle& handle);
|
|
|
|
NpadGcVibrationDevice* GetGcVibrationDevice(const Core::HID::VibrationDeviceHandle& handle);
|
|
|
|
Result SetAruidValidForVibration(u64 aruid, bool is_enabled);
|
|
|
|
void SetForceHandheldStyleVibration(bool is_forced);
|
|
|
|
Result IsVibrationAruidActive(u64 aruid, bool& is_active) const;
|
|
|
|
Result GetVibrationDeviceInfo(Core::HID::VibrationDeviceInfo& device_info,
|
|
|
|
const Core::HID::VibrationDeviceHandle& handle);
|
|
|
|
Result SendVibrationValue(u64 aruid, const Core::HID::VibrationDeviceHandle& handle,
|
|
|
|
const Core::HID::VibrationValue& value);
|
|
|
|
|
2023-12-23 19:58:09 +01:00
|
|
|
void UpdateControllers(std::chrono::nanoseconds ns_late);
|
|
|
|
void UpdateNpad(std::chrono::nanoseconds ns_late);
|
|
|
|
void UpdateMouseKeyboard(std::chrono::nanoseconds ns_late);
|
|
|
|
void UpdateMotion(std::chrono::nanoseconds ns_late);
|
2023-11-15 04:34:27 +01:00
|
|
|
|
|
|
|
private:
|
2023-12-10 21:53:19 +01:00
|
|
|
Result CreateAppletResourceImpl(u64 aruid);
|
2023-12-31 07:42:23 +01:00
|
|
|
void InitializeHidCommonSampler();
|
|
|
|
void InitializeTouchScreenSampler();
|
|
|
|
void InitializeConsoleSixAxisSampler();
|
|
|
|
void InitializeAHidSampler();
|
2023-12-10 21:53:19 +01:00
|
|
|
|
2023-11-15 04:34:27 +01:00
|
|
|
bool is_initialized{false};
|
2023-11-17 18:46:26 +01:00
|
|
|
|
2024-01-01 22:23:56 +01:00
|
|
|
mutable std::recursive_mutex shared_mutex;
|
2023-12-06 01:39:18 +01:00
|
|
|
std::shared_ptr<AppletResource> applet_resource = nullptr;
|
|
|
|
|
2023-11-17 18:46:26 +01:00
|
|
|
std::shared_ptr<CaptureButton> capture_button = nullptr;
|
|
|
|
std::shared_ptr<ConsoleSixAxis> console_six_axis = nullptr;
|
|
|
|
std::shared_ptr<DebugMouse> debug_mouse = nullptr;
|
|
|
|
std::shared_ptr<DebugPad> debug_pad = nullptr;
|
2023-12-14 04:39:38 +01:00
|
|
|
std::shared_ptr<Digitizer> digitizer = nullptr;
|
2023-11-17 18:46:26 +01:00
|
|
|
std::shared_ptr<Gesture> gesture = nullptr;
|
|
|
|
std::shared_ptr<HomeButton> home_button = nullptr;
|
|
|
|
std::shared_ptr<Keyboard> keyboard = nullptr;
|
|
|
|
std::shared_ptr<Mouse> mouse = nullptr;
|
|
|
|
std::shared_ptr<NPad> npad = nullptr;
|
|
|
|
std::shared_ptr<Palma> palma = nullptr;
|
|
|
|
std::shared_ptr<SevenSixAxis> seven_six_axis = nullptr;
|
|
|
|
std::shared_ptr<SixAxis> six_axis = nullptr;
|
|
|
|
std::shared_ptr<SleepButton> sleep_button = nullptr;
|
|
|
|
std::shared_ptr<TouchScreen> touch_screen = nullptr;
|
|
|
|
std::shared_ptr<UniquePad> unique_pad = nullptr;
|
|
|
|
|
2024-01-11 05:06:54 +01:00
|
|
|
std::shared_ptr<HandheldConfig> handheld_config = nullptr;
|
|
|
|
|
2023-11-17 18:46:26 +01:00
|
|
|
// TODO: Create these resources
|
|
|
|
// std::shared_ptr<AudioControl> audio_control = nullptr;
|
|
|
|
// std::shared_ptr<ButtonConfig> button_config = nullptr;
|
|
|
|
// std::shared_ptr<Config> config = nullptr;
|
|
|
|
// std::shared_ptr<Connection> connection = nullptr;
|
|
|
|
// std::shared_ptr<CustomConfig> custom_config = nullptr;
|
|
|
|
// std::shared_ptr<Digitizer> digitizer = nullptr;
|
|
|
|
// std::shared_ptr<Hdls> hdls = nullptr;
|
|
|
|
// std::shared_ptr<PlayReport> play_report = nullptr;
|
|
|
|
// std::shared_ptr<Rail> rail = nullptr;
|
2023-11-15 04:34:27 +01:00
|
|
|
|
|
|
|
Core::System& system;
|
|
|
|
KernelHelpers::ServiceContext service_context;
|
|
|
|
};
|
|
|
|
|
|
|
|
class IAppletResource final : public ServiceFramework<IAppletResource> {
|
|
|
|
public:
|
2023-12-10 21:53:19 +01:00
|
|
|
explicit IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource,
|
|
|
|
u64 applet_resource_user_id);
|
2023-11-15 04:34:27 +01:00
|
|
|
~IAppletResource() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void GetSharedMemoryHandle(HLERequestContext& ctx);
|
|
|
|
|
|
|
|
std::shared_ptr<Core::Timing::EventType> npad_update_event;
|
|
|
|
std::shared_ptr<Core::Timing::EventType> default_update_event;
|
|
|
|
std::shared_ptr<Core::Timing::EventType> mouse_keyboard_update_event;
|
|
|
|
std::shared_ptr<Core::Timing::EventType> motion_update_event;
|
2023-12-06 01:39:18 +01:00
|
|
|
|
2023-12-10 21:53:19 +01:00
|
|
|
u64 aruid;
|
2023-12-06 01:39:18 +01:00
|
|
|
std::shared_ptr<ResourceManager> resource_manager;
|
2023-11-15 04:34:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Service::HID
|