2022-04-23 04:59:50 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-10-06 00:23:21 +10:00
|
|
|
|
|
|
|
|
#pragma once
|
2018-10-06 13:14:42 +10:00
|
|
|
|
2018-10-06 00:23:21 +10:00
|
|
|
#include <array>
|
2020-11-25 07:48:00 -05:00
|
|
|
#include <atomic>
|
2021-06-22 03:16:21 -03:00
|
|
|
#include <mutex>
|
2023-02-03 00:08:45 -05:00
|
|
|
#include <span>
|
2021-06-22 03:16:21 -03:00
|
|
|
|
2018-10-06 00:23:21 +10:00
|
|
|
#include "common/common_types.h"
|
2024-01-04 20:37:43 -06:00
|
|
|
#include "hid_core/hid_types.h"
|
2024-01-10 22:06:54 -06:00
|
|
|
#include "hid_core/resources/abstracted_pad/abstract_pad.h"
|
2024-01-04 20:37:43 -06:00
|
|
|
#include "hid_core/resources/controller_base.h"
|
|
|
|
|
#include "hid_core/resources/npad/npad_resource.h"
|
|
|
|
|
#include "hid_core/resources/npad/npad_types.h"
|
2024-01-10 22:06:54 -06:00
|
|
|
#include "hid_core/resources/npad/npad_vibration.h"
|
|
|
|
|
#include "hid_core/resources/vibration/gc_vibration_device.h"
|
|
|
|
|
#include "hid_core/resources/vibration/n64_vibration_device.h"
|
|
|
|
|
#include "hid_core/resources/vibration/vibration_base.h"
|
|
|
|
|
#include "hid_core/resources/vibration/vibration_device.h"
|
2018-10-06 00:23:21 +10:00
|
|
|
|
2021-11-01 14:17:53 -06:00
|
|
|
namespace Core::HID {
|
|
|
|
|
class EmulatedController;
|
|
|
|
|
enum class ControllerTriggerType;
|
|
|
|
|
} // namespace Core::HID
|
|
|
|
|
|
2021-01-31 01:38:57 -08:00
|
|
|
namespace Kernel {
|
|
|
|
|
class KEvent;
|
|
|
|
|
class KReadableEvent;
|
|
|
|
|
} // namespace Kernel
|
|
|
|
|
|
2021-06-28 14:41:24 -07:00
|
|
|
namespace Service::KernelHelpers {
|
|
|
|
|
class ServiceContext;
|
2022-04-13 12:52:29 -05:00
|
|
|
} // namespace Service::KernelHelpers
|
|
|
|
|
|
2022-06-25 22:44:19 -05:00
|
|
|
union Result;
|
2021-06-28 14:41:24 -07:00
|
|
|
|
2018-10-06 00:23:21 +10:00
|
|
|
namespace Service::HID {
|
2023-12-31 00:42:23 -06:00
|
|
|
class AppletResource;
|
2024-01-10 22:06:54 -06:00
|
|
|
struct HandheldConfig;
|
2023-12-13 21:39:38 -06:00
|
|
|
struct NpadInternalState;
|
|
|
|
|
struct NpadSixAxisSensorLifo;
|
|
|
|
|
struct NpadSharedMemoryFormat;
|
2018-10-06 00:23:21 +10:00
|
|
|
|
2024-01-01 15:23:56 -06:00
|
|
|
class NPad final {
|
2018-10-06 00:23:21 +10:00
|
|
|
public:
|
2023-12-31 00:42:23 -06:00
|
|
|
explicit NPad(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service_context_);
|
2024-01-01 15:23:56 -06:00
|
|
|
~NPad();
|
2018-10-06 00:23:21 +10:00
|
|
|
|
2024-01-01 15:23:56 -06:00
|
|
|
Result Activate();
|
|
|
|
|
Result Activate(u64 aruid);
|
2018-10-06 00:23:21 +10:00
|
|
|
|
2024-01-01 15:23:56 -06:00
|
|
|
Result ActivateNpadResource();
|
|
|
|
|
Result ActivateNpadResource(u64 aruid);
|
2018-10-06 00:23:21 +10:00
|
|
|
|
|
|
|
|
// When the controller is requesting an update for the shared memory
|
2024-01-01 15:23:56 -06:00
|
|
|
void OnUpdate(const Core::Timing::CoreTiming& core_timing);
|
2018-10-06 00:23:21 +10:00
|
|
|
|
2024-01-01 15:23:56 -06:00
|
|
|
Result SetSupportedNpadStyleSet(u64 aruid, Core::HID::NpadStyleSet supported_style_set);
|
|
|
|
|
Result GetSupportedNpadStyleSet(u64 aruid,
|
|
|
|
|
Core::HID::NpadStyleSet& out_supported_style_set) const;
|
|
|
|
|
Result GetMaskedSupportedNpadStyleSet(u64 aruid,
|
|
|
|
|
Core::HID::NpadStyleSet& out_supported_style_set) const;
|
2018-10-06 00:23:21 +10:00
|
|
|
|
2024-01-01 15:23:56 -06:00
|
|
|
Result SetSupportedNpadIdType(u64 aruid,
|
|
|
|
|
std::span<const Core::HID::NpadIdType> supported_npad_list);
|
2018-10-06 00:23:21 +10:00
|
|
|
|
2024-01-01 15:23:56 -06:00
|
|
|
Result SetNpadJoyHoldType(u64 aruid, NpadJoyHoldType hold_type);
|
|
|
|
|
Result GetNpadJoyHoldType(u64 aruid, NpadJoyHoldType& out_hold_type) const;
|
2018-10-06 00:23:21 +10:00
|
|
|
|
2024-01-01 15:23:56 -06:00
|
|
|
Result SetNpadHandheldActivationMode(u64 aruid, NpadHandheldActivationMode mode);
|
|
|
|
|
Result GetNpadHandheldActivationMode(u64 aruid, NpadHandheldActivationMode& out_mode) const;
|
2020-09-18 10:10:30 -04:00
|
|
|
|
2024-01-01 15:23:56 -06:00
|
|
|
bool SetNpadMode(u64 aruid, Core::HID::NpadIdType& new_npad_id, Core::HID::NpadIdType npad_id,
|
2023-03-26 23:56:00 -06:00
|
|
|
NpadJoyDeviceType npad_device_type, NpadJoyAssignmentMode assignment_mode);
|
2018-10-06 00:23:21 +10:00
|
|
|
|
2024-01-01 15:23:56 -06:00
|
|
|
Result AcquireNpadStyleSetUpdateEventHandle(u64 aruid, Kernel::KReadableEvent** out_event,
|
|
|
|
|
Core::HID::NpadIdType npad_id);
|
2020-08-21 07:39:24 -04:00
|
|
|
|
2020-07-22 10:39:53 -04:00
|
|
|
// Adds a new controller at an index.
|
2024-01-01 15:23:56 -06:00
|
|
|
void AddNewControllerAt(u64 aruid, Core::HID::NpadStyleIndex controller,
|
|
|
|
|
Core::HID::NpadIdType npad_id);
|
2020-07-22 10:39:53 -04:00
|
|
|
// Adds a new controller at an index with connection status.
|
2024-01-01 15:23:56 -06:00
|
|
|
void UpdateControllerAt(u64 aruid, Core::HID::NpadStyleIndex controller,
|
|
|
|
|
Core::HID::NpadIdType npad_id, bool connected);
|
2018-10-06 00:23:21 +10:00
|
|
|
|
2024-01-01 15:23:56 -06:00
|
|
|
Result DisconnectNpad(u64 aruid, Core::HID::NpadIdType npad_id);
|
2021-11-08 20:28:09 -06:00
|
|
|
|
2022-06-25 22:44:19 -05:00
|
|
|
Result IsFirmwareUpdateAvailableForSixAxisSensor(
|
2024-01-01 15:23:56 -06:00
|
|
|
u64 aruid, const Core::HID::SixAxisSensorHandle& sixaxis_handle,
|
|
|
|
|
bool& is_firmware_available) const;
|
2022-06-25 22:44:19 -05:00
|
|
|
Result ResetIsSixAxisSensorDeviceNewlyAssigned(
|
2024-01-01 15:23:56 -06:00
|
|
|
u64 aruid, const Core::HID::SixAxisSensorHandle& sixaxis_handle);
|
2023-11-17 11:46:26 -06:00
|
|
|
|
2022-06-25 22:44:19 -05:00
|
|
|
Result GetLedPattern(Core::HID::NpadIdType npad_id, Core::HID::LedPattern& pattern) const;
|
2024-01-01 15:23:56 -06:00
|
|
|
|
|
|
|
|
Result IsUnintendedHomeButtonInputProtectionEnabled(bool& out_is_enabled, u64 aruid,
|
|
|
|
|
Core::HID::NpadIdType npad_id) const;
|
|
|
|
|
Result EnableUnintendedHomeButtonInputProtection(u64 aruid, Core::HID::NpadIdType npad_id,
|
|
|
|
|
bool is_enabled);
|
|
|
|
|
|
|
|
|
|
void SetNpadAnalogStickUseCenterClamp(u64 aruid, bool is_enabled);
|
2018-10-18 21:45:10 +11:00
|
|
|
void ClearAllConnectedControllers();
|
|
|
|
|
void DisconnectAllConnectedControllers();
|
|
|
|
|
void ConnectAllDisconnectedControllers();
|
|
|
|
|
void ClearAllControllers();
|
2018-10-07 20:17:04 +11:00
|
|
|
|
2024-01-01 15:23:56 -06:00
|
|
|
Result MergeSingleJoyAsDualJoy(u64 aruid, Core::HID::NpadIdType npad_id_1,
|
2022-06-25 22:44:19 -05:00
|
|
|
Core::HID::NpadIdType npad_id_2);
|
2024-01-01 15:23:56 -06:00
|
|
|
Result StartLrAssignmentMode(u64 aruid);
|
|
|
|
|
Result StopLrAssignmentMode(u64 aruid);
|
|
|
|
|
Result SwapNpadAssignment(u64 aruid, Core::HID::NpadIdType npad_id_1,
|
|
|
|
|
Core::HID::NpadIdType npad_id_2);
|
2019-07-01 15:12:57 +10:00
|
|
|
|
2018-12-24 16:19:16 -05:00
|
|
|
// Logical OR for all buttons presses on all controllers
|
|
|
|
|
// Specifically for cheat engine and other features.
|
2021-11-29 18:23:52 -05:00
|
|
|
Core::HID::NpadButton GetAndResetPressState();
|
2018-12-24 16:19:16 -05:00
|
|
|
|
2024-01-01 15:23:56 -06:00
|
|
|
Result ApplyNpadSystemCommonPolicy(u64 aruid);
|
|
|
|
|
Result ApplyNpadSystemCommonPolicyFull(u64 aruid);
|
|
|
|
|
Result ClearNpadSystemCommonPolicy(u64 aruid);
|
|
|
|
|
|
|
|
|
|
void SetRevision(u64 aruid, NpadRevision revision);
|
|
|
|
|
NpadRevision GetRevision(u64 aruid);
|
|
|
|
|
|
|
|
|
|
Result RegisterAppletResourceUserId(u64 aruid);
|
|
|
|
|
void UnregisterAppletResourceUserId(u64 aruid);
|
|
|
|
|
void SetNpadExternals(std::shared_ptr<AppletResource> resource,
|
2024-01-10 22:06:54 -06:00
|
|
|
std::recursive_mutex* shared_mutex,
|
|
|
|
|
std::shared_ptr<HandheldConfig> handheld_config);
|
2023-09-16 08:38:10 -06:00
|
|
|
|
2023-11-01 01:09:33 +01:00
|
|
|
AppletDetailedUiType GetAppletDetailedUiType(Core::HID::NpadIdType npad_id);
|
2018-11-03 12:55:39 -04:00
|
|
|
|
2024-01-06 21:17:57 -06:00
|
|
|
Result SetNpadCaptureButtonAssignment(u64 aruid, Core::HID::NpadStyleSet npad_style_set,
|
|
|
|
|
Core::HID::NpadButton button_assignment);
|
|
|
|
|
Result ClearNpadCaptureButtonAssignment(u64 aruid);
|
|
|
|
|
std::size_t GetNpadCaptureButtonAssignment(std::span<Core::HID::NpadButton> out_list,
|
|
|
|
|
u64 aruid) const;
|
|
|
|
|
|
2024-01-06 21:35:10 -06:00
|
|
|
Result SetNpadSystemExtStateEnabled(u64 aruid, bool is_enabled);
|
|
|
|
|
|
2024-01-06 21:54:23 -06:00
|
|
|
Result AssigningSingleOnSlSrPress(u64 aruid, bool is_enabled);
|
|
|
|
|
|
2024-01-06 22:04:14 -06:00
|
|
|
Result GetLastActiveNpad(Core::HID::NpadIdType& out_npad_id) const;
|
|
|
|
|
|
2024-01-10 22:06:54 -06:00
|
|
|
NpadVibration* GetVibrationHandler();
|
|
|
|
|
std::vector<NpadVibrationBase*> GetAllVibrationDevices();
|
|
|
|
|
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);
|
2018-10-07 20:17:04 +11:00
|
|
|
|
2024-01-10 22:06:54 -06:00
|
|
|
void UpdateHandheldAbstractState();
|
|
|
|
|
|
|
|
|
|
private:
|
2021-11-08 20:28:09 -06:00
|
|
|
struct NpadControllerData {
|
2022-04-20 12:00:26 -05:00
|
|
|
NpadInternalState* shared_memory = nullptr;
|
|
|
|
|
Core::HID::EmulatedController* device = nullptr;
|
2021-09-20 20:37:50 -05:00
|
|
|
|
2021-10-18 23:15:46 -05:00
|
|
|
bool is_connected{};
|
2021-12-05 16:17:52 -06:00
|
|
|
|
|
|
|
|
// Dual joycons can have only one side connected
|
|
|
|
|
bool is_dual_left_connected{true};
|
|
|
|
|
bool is_dual_right_connected{true};
|
2021-09-20 20:37:50 -05:00
|
|
|
|
|
|
|
|
// Current pad state
|
|
|
|
|
NPadGenericState npad_pad_state{};
|
|
|
|
|
NPadGenericState npad_libnx_state{};
|
|
|
|
|
NpadGcTriggerState npad_trigger_state{};
|
2022-04-20 12:00:26 -05:00
|
|
|
int callback_key{};
|
2021-09-20 20:37:50 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void ControllerUpdate(Core::HID::ControllerTriggerType type, std::size_t controller_idx);
|
2024-01-01 15:23:56 -06:00
|
|
|
void InitNewlyAddedController(u64 aruid, Core::HID::NpadIdType npad_id);
|
|
|
|
|
void RequestPadStateUpdate(u64 aruid, Core::HID::NpadIdType npad_id);
|
2022-04-19 15:30:32 -05:00
|
|
|
void WriteEmptyEntry(NpadInternalState* npad);
|
2019-10-17 18:09:05 -04:00
|
|
|
|
2023-11-17 11:46:26 -06:00
|
|
|
NpadControllerData& GetControllerFromHandle(
|
2024-01-01 15:23:56 -06:00
|
|
|
u64 aruid, const Core::HID::SixAxisSensorHandle& device_handle);
|
2023-11-17 11:46:26 -06:00
|
|
|
const NpadControllerData& GetControllerFromHandle(
|
2024-01-01 15:23:56 -06:00
|
|
|
u64 aruid, const Core::HID::SixAxisSensorHandle& device_handle) const;
|
|
|
|
|
NpadControllerData& GetControllerFromNpadIdType(u64 aruid, Core::HID::NpadIdType npad_id);
|
|
|
|
|
const NpadControllerData& GetControllerFromNpadIdType(u64 aruid,
|
|
|
|
|
Core::HID::NpadIdType npad_id) const;
|
2021-11-08 20:28:09 -06:00
|
|
|
|
2022-05-21 17:21:45 -05:00
|
|
|
Core::HID::SixAxisSensorProperties& GetSixaxisProperties(
|
2024-01-01 15:23:56 -06:00
|
|
|
u64 aruid, const Core::HID::SixAxisSensorHandle& device_handle);
|
2022-05-21 17:21:45 -05:00
|
|
|
const Core::HID::SixAxisSensorProperties& GetSixaxisProperties(
|
2024-01-01 15:23:56 -06:00
|
|
|
u64 aruid, const Core::HID::SixAxisSensorHandle& device_handle) const;
|
2022-05-21 16:48:05 -05:00
|
|
|
|
2024-01-01 15:23:56 -06:00
|
|
|
Core::HID::HIDCore& hid_core;
|
2021-06-28 14:41:24 -07:00
|
|
|
KernelHelpers::ServiceContext& service_context;
|
2024-01-01 15:23:56 -06:00
|
|
|
|
|
|
|
|
s32 ref_counter{};
|
|
|
|
|
mutable std::mutex mutex;
|
|
|
|
|
NPadResource npad_resource;
|
|
|
|
|
AppletResourceHolder applet_resource_holder{};
|
2024-01-10 22:06:54 -06:00
|
|
|
std::array<AbstractPad, MaxSupportedNpadIdTypes> abstracted_pads;
|
|
|
|
|
NpadVibration vibration_handler{};
|
|
|
|
|
|
2024-01-01 15:23:56 -06:00
|
|
|
Kernel::KEvent* input_event{nullptr};
|
|
|
|
|
std::mutex* input_mutex{nullptr};
|
|
|
|
|
|
|
|
|
|
std::atomic<u64> press_state{};
|
|
|
|
|
std::array<std::array<NpadControllerData, MaxSupportedNpadIdTypes>, AruidIndexMax>
|
|
|
|
|
controller_data{};
|
2018-10-06 00:23:21 +10:00
|
|
|
};
|
2018-10-06 13:14:42 +10:00
|
|
|
} // namespace Service::HID
|