npad.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <array>
  5. #include <atomic>
  6. #include <mutex>
  7. #include "common/bit_field.h"
  8. #include "common/common_types.h"
  9. #include "common/vector_math.h"
  10. #include "core/hid/hid_types.h"
  11. #include "core/hle/service/hid/controllers/controller_base.h"
  12. #include "core/hle/service/hid/ring_lifo.h"
  13. namespace Core::HID {
  14. class EmulatedController;
  15. enum class ControllerTriggerType;
  16. } // namespace Core::HID
  17. namespace Kernel {
  18. class KEvent;
  19. class KReadableEvent;
  20. } // namespace Kernel
  21. namespace Service::KernelHelpers {
  22. class ServiceContext;
  23. } // namespace Service::KernelHelpers
  24. union ResultCode;
  25. namespace Service::HID {
  26. class Controller_NPad final : public ControllerBase {
  27. public:
  28. explicit Controller_NPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_,
  29. KernelHelpers::ServiceContext& service_context_);
  30. ~Controller_NPad() override;
  31. // Called when the controller is initialized
  32. void OnInit() override;
  33. // When the controller is released
  34. void OnRelease() override;
  35. // When the controller is requesting an update for the shared memory
  36. void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
  37. // When the controller is requesting a motion update for the shared memory
  38. void OnMotionUpdate(const Core::Timing::CoreTiming& core_timing) override;
  39. // This is nn::hid::GyroscopeZeroDriftMode
  40. enum class GyroscopeZeroDriftMode : u32 {
  41. Loose = 0,
  42. Standard = 1,
  43. Tight = 2,
  44. };
  45. // This is nn::hid::NpadJoyHoldType
  46. enum class NpadJoyHoldType : u64 {
  47. Vertical = 0,
  48. Horizontal = 1,
  49. };
  50. // This is nn::hid::NpadJoyAssignmentMode
  51. enum class NpadJoyAssignmentMode : u32 {
  52. Dual = 0,
  53. Single = 1,
  54. };
  55. // This is nn::hid::NpadJoyDeviceType
  56. enum class NpadJoyDeviceType : s64 {
  57. Left = 0,
  58. Right = 1,
  59. };
  60. // This is nn::hid::NpadHandheldActivationMode
  61. enum class NpadHandheldActivationMode : u64 {
  62. Dual = 0,
  63. Single = 1,
  64. None = 2,
  65. };
  66. // This is nn::hid::NpadCommunicationMode
  67. enum class NpadCommunicationMode : u64 {
  68. Mode_5ms = 0,
  69. Mode_10ms = 1,
  70. Mode_15ms = 2,
  71. Default = 3,
  72. };
  73. void SetSupportedStyleSet(Core::HID::NpadStyleTag style_set);
  74. Core::HID::NpadStyleTag GetSupportedStyleSet() const;
  75. void SetSupportedNpadIdTypes(u8* data, std::size_t length);
  76. void GetSupportedNpadIdTypes(u32* data, std::size_t max_length);
  77. std::size_t GetSupportedNpadIdTypesSize() const;
  78. void SetHoldType(NpadJoyHoldType joy_hold_type);
  79. NpadJoyHoldType GetHoldType() const;
  80. void SetNpadHandheldActivationMode(NpadHandheldActivationMode activation_mode);
  81. NpadHandheldActivationMode GetNpadHandheldActivationMode() const;
  82. void SetNpadCommunicationMode(NpadCommunicationMode communication_mode_);
  83. NpadCommunicationMode GetNpadCommunicationMode() const;
  84. ResultCode SetNpadMode(Core::HID::NpadIdType npad_id, NpadJoyDeviceType npad_device_type,
  85. NpadJoyAssignmentMode assignment_mode);
  86. bool VibrateControllerAtIndex(Core::HID::NpadIdType npad_id, std::size_t device_index,
  87. const Core::HID::VibrationValue& vibration_value);
  88. void VibrateController(const Core::HID::VibrationDeviceHandle& vibration_device_handle,
  89. const Core::HID::VibrationValue& vibration_value);
  90. void VibrateControllers(
  91. const std::vector<Core::HID::VibrationDeviceHandle>& vibration_device_handles,
  92. const std::vector<Core::HID::VibrationValue>& vibration_values);
  93. Core::HID::VibrationValue GetLastVibration(
  94. const Core::HID::VibrationDeviceHandle& vibration_device_handle) const;
  95. void InitializeVibrationDevice(const Core::HID::VibrationDeviceHandle& vibration_device_handle);
  96. void InitializeVibrationDeviceAtIndex(Core::HID::NpadIdType npad_id, std::size_t device_index);
  97. void SetPermitVibrationSession(bool permit_vibration_session);
  98. bool IsVibrationDeviceMounted(
  99. const Core::HID::VibrationDeviceHandle& vibration_device_handle) const;
  100. Kernel::KReadableEvent& GetStyleSetChangedEvent(Core::HID::NpadIdType npad_id);
  101. void SignalStyleSetChangedEvent(Core::HID::NpadIdType npad_id) const;
  102. // Adds a new controller at an index.
  103. void AddNewControllerAt(Core::HID::NpadStyleIndex controller, Core::HID::NpadIdType npad_id);
  104. // Adds a new controller at an index with connection status.
  105. void UpdateControllerAt(Core::HID::NpadStyleIndex controller, Core::HID::NpadIdType npad_id,
  106. bool connected);
  107. ResultCode DisconnectNpad(Core::HID::NpadIdType npad_id);
  108. ResultCode SetGyroscopeZeroDriftMode(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
  109. GyroscopeZeroDriftMode drift_mode);
  110. ResultCode GetGyroscopeZeroDriftMode(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
  111. GyroscopeZeroDriftMode& drift_mode) const;
  112. ResultCode IsSixAxisSensorAtRest(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
  113. bool& is_at_rest) const;
  114. ResultCode IsFirmwareUpdateAvailableForSixAxisSensor(
  115. const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_firmware_available) const;
  116. ResultCode EnableSixAxisSensorUnalteredPassthrough(
  117. const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool is_enabled);
  118. ResultCode IsSixAxisSensorUnalteredPassthroughEnabled(
  119. const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_enabled) const;
  120. ResultCode SetSixAxisEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
  121. bool sixaxis_status);
  122. ResultCode IsSixAxisSensorFusionEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
  123. bool& is_fusion_enabled) const;
  124. ResultCode SetSixAxisFusionEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
  125. bool is_fusion_enabled);
  126. ResultCode SetSixAxisFusionParameters(
  127. const Core::HID::SixAxisSensorHandle& sixaxis_handle,
  128. Core::HID::SixAxisSensorFusionParameters sixaxis_fusion_parameters);
  129. ResultCode GetSixAxisFusionParameters(
  130. const Core::HID::SixAxisSensorHandle& sixaxis_handle,
  131. Core::HID::SixAxisSensorFusionParameters& parameters) const;
  132. ResultCode GetLedPattern(Core::HID::NpadIdType npad_id, Core::HID::LedPattern& pattern) const;
  133. ResultCode IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id,
  134. bool& is_enabled) const;
  135. ResultCode SetUnintendedHomeButtonInputProtectionEnabled(bool is_protection_enabled,
  136. Core::HID::NpadIdType npad_id);
  137. void SetAnalogStickUseCenterClamp(bool use_center_clamp);
  138. void ClearAllConnectedControllers();
  139. void DisconnectAllConnectedControllers();
  140. void ConnectAllDisconnectedControllers();
  141. void ClearAllControllers();
  142. ResultCode MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1,
  143. Core::HID::NpadIdType npad_id_2);
  144. void StartLRAssignmentMode();
  145. void StopLRAssignmentMode();
  146. ResultCode SwapNpadAssignment(Core::HID::NpadIdType npad_id_1, Core::HID::NpadIdType npad_id_2);
  147. // Logical OR for all buttons presses on all controllers
  148. // Specifically for cheat engine and other features.
  149. Core::HID::NpadButton GetAndResetPressState();
  150. static bool IsNpadIdValid(Core::HID::NpadIdType npad_id);
  151. static bool IsDeviceHandleValid(const Core::HID::VibrationDeviceHandle& device_handle);
  152. static ResultCode VerifyValidSixAxisSensorHandle(
  153. const Core::HID::SixAxisSensorHandle& device_handle);
  154. private:
  155. static constexpr std::size_t NPAD_COUNT = 10;
  156. // This is nn::hid::detail::ColorAttribute
  157. enum class ColorAttribute : u32 {
  158. Ok = 0,
  159. ReadError = 1,
  160. NoController = 2,
  161. };
  162. static_assert(sizeof(ColorAttribute) == 4, "ColorAttribute is an invalid size");
  163. // This is nn::hid::detail::NpadFullKeyColorState
  164. struct NpadFullKeyColorState {
  165. ColorAttribute attribute{ColorAttribute::NoController};
  166. Core::HID::NpadControllerColor fullkey{};
  167. };
  168. static_assert(sizeof(NpadFullKeyColorState) == 0xC, "NpadFullKeyColorState is an invalid size");
  169. // This is nn::hid::detail::NpadJoyColorState
  170. struct NpadJoyColorState {
  171. ColorAttribute attribute{ColorAttribute::NoController};
  172. Core::HID::NpadControllerColor left{};
  173. Core::HID::NpadControllerColor right{};
  174. };
  175. static_assert(sizeof(NpadJoyColorState) == 0x14, "NpadJoyColorState is an invalid size");
  176. // This is nn::hid::NpadAttribute
  177. struct NpadAttribute {
  178. union {
  179. u32 raw{};
  180. BitField<0, 1, u32> is_connected;
  181. BitField<1, 1, u32> is_wired;
  182. BitField<2, 1, u32> is_left_connected;
  183. BitField<3, 1, u32> is_left_wired;
  184. BitField<4, 1, u32> is_right_connected;
  185. BitField<5, 1, u32> is_right_wired;
  186. };
  187. };
  188. static_assert(sizeof(NpadAttribute) == 4, "NpadAttribute is an invalid size");
  189. // This is nn::hid::NpadFullKeyState
  190. // This is nn::hid::NpadHandheldState
  191. // This is nn::hid::NpadJoyDualState
  192. // This is nn::hid::NpadJoyLeftState
  193. // This is nn::hid::NpadJoyRightState
  194. // This is nn::hid::NpadPalmaState
  195. // This is nn::hid::NpadSystemExtState
  196. struct NPadGenericState {
  197. s64_le sampling_number{};
  198. Core::HID::NpadButtonState npad_buttons{};
  199. Core::HID::AnalogStickState l_stick{};
  200. Core::HID::AnalogStickState r_stick{};
  201. NpadAttribute connection_status{};
  202. INSERT_PADDING_BYTES(4); // Reserved
  203. };
  204. static_assert(sizeof(NPadGenericState) == 0x28, "NPadGenericState is an invalid size");
  205. // This is nn::hid::SixAxisSensorAttribute
  206. struct SixAxisSensorAttribute {
  207. union {
  208. u32 raw{};
  209. BitField<0, 1, u32> is_connected;
  210. BitField<1, 1, u32> is_interpolated;
  211. };
  212. };
  213. static_assert(sizeof(SixAxisSensorAttribute) == 4, "SixAxisSensorAttribute is an invalid size");
  214. // This is nn::hid::SixAxisSensorState
  215. struct SixAxisSensorState {
  216. s64 delta_time{};
  217. s64 sampling_number{};
  218. Common::Vec3f accel{};
  219. Common::Vec3f gyro{};
  220. Common::Vec3f rotation{};
  221. std::array<Common::Vec3f, 3> orientation{};
  222. SixAxisSensorAttribute attribute{};
  223. INSERT_PADDING_BYTES(4); // Reserved
  224. };
  225. static_assert(sizeof(SixAxisSensorState) == 0x60, "SixAxisSensorState is an invalid size");
  226. // This is nn::hid::server::NpadGcTriggerState
  227. struct NpadGcTriggerState {
  228. s64 sampling_number{};
  229. s32 l_analog{};
  230. s32 r_analog{};
  231. };
  232. static_assert(sizeof(NpadGcTriggerState) == 0x10, "NpadGcTriggerState is an invalid size");
  233. // This is nn::hid::NpadSystemProperties
  234. struct NPadSystemProperties {
  235. union {
  236. s64 raw{};
  237. BitField<0, 1, s64> is_charging_joy_dual;
  238. BitField<1, 1, s64> is_charging_joy_left;
  239. BitField<2, 1, s64> is_charging_joy_right;
  240. BitField<3, 1, s64> is_powered_joy_dual;
  241. BitField<4, 1, s64> is_powered_joy_left;
  242. BitField<5, 1, s64> is_powered_joy_right;
  243. BitField<9, 1, s64> is_system_unsupported_button;
  244. BitField<10, 1, s64> is_system_ext_unsupported_button;
  245. BitField<11, 1, s64> is_vertical;
  246. BitField<12, 1, s64> is_horizontal;
  247. BitField<13, 1, s64> use_plus;
  248. BitField<14, 1, s64> use_minus;
  249. BitField<15, 1, s64> use_directional_buttons;
  250. };
  251. };
  252. static_assert(sizeof(NPadSystemProperties) == 0x8, "NPadSystemProperties is an invalid size");
  253. // This is nn::hid::NpadSystemButtonProperties
  254. struct NpadSystemButtonProperties {
  255. union {
  256. s32 raw{};
  257. BitField<0, 1, s32> is_home_button_protection_enabled;
  258. };
  259. };
  260. static_assert(sizeof(NpadSystemButtonProperties) == 0x4,
  261. "NPadButtonProperties is an invalid size");
  262. // This is nn::hid::system::DeviceType
  263. struct DeviceType {
  264. union {
  265. u32 raw{};
  266. BitField<0, 1, s32> fullkey;
  267. BitField<1, 1, s32> debug_pad;
  268. BitField<2, 1, s32> handheld_left;
  269. BitField<3, 1, s32> handheld_right;
  270. BitField<4, 1, s32> joycon_left;
  271. BitField<5, 1, s32> joycon_right;
  272. BitField<6, 1, s32> palma;
  273. BitField<7, 1, s32> lark_hvc_left;
  274. BitField<8, 1, s32> lark_hvc_right;
  275. BitField<9, 1, s32> lark_nes_left;
  276. BitField<10, 1, s32> lark_nes_right;
  277. BitField<11, 1, s32> handheld_lark_hvc_left;
  278. BitField<12, 1, s32> handheld_lark_hvc_right;
  279. BitField<13, 1, s32> handheld_lark_nes_left;
  280. BitField<14, 1, s32> handheld_lark_nes_right;
  281. BitField<15, 1, s32> lucia;
  282. BitField<16, 1, s32> lagon;
  283. BitField<17, 1, s32> lager;
  284. BitField<31, 1, s32> system;
  285. };
  286. };
  287. // This is nn::hid::detail::NfcXcdDeviceHandleStateImpl
  288. struct NfcXcdDeviceHandleStateImpl {
  289. u64 handle{};
  290. bool is_available{};
  291. bool is_activated{};
  292. INSERT_PADDING_BYTES(0x6); // Reserved
  293. u64 sampling_number{};
  294. };
  295. static_assert(sizeof(NfcXcdDeviceHandleStateImpl) == 0x18,
  296. "NfcXcdDeviceHandleStateImpl is an invalid size");
  297. // This is nn::hid::system::AppletFooterUiAttributesSet
  298. struct AppletFooterUiAttributes {
  299. INSERT_PADDING_BYTES(0x4);
  300. };
  301. // This is nn::hid::system::AppletFooterUiType
  302. enum class AppletFooterUiType : u8 {
  303. None = 0,
  304. HandheldNone = 1,
  305. HandheldJoyConLeftOnly = 1,
  306. HandheldJoyConRightOnly = 3,
  307. HandheldJoyConLeftJoyConRight = 4,
  308. JoyDual = 5,
  309. JoyDualLeftOnly = 6,
  310. JoyDualRightOnly = 7,
  311. JoyLeftHorizontal = 8,
  312. JoyLeftVertical = 9,
  313. JoyRightHorizontal = 10,
  314. JoyRightVertical = 11,
  315. SwitchProController = 12,
  316. CompatibleProController = 13,
  317. CompatibleJoyCon = 14,
  318. LarkHvc1 = 15,
  319. LarkHvc2 = 16,
  320. LarkNesLeft = 17,
  321. LarkNesRight = 18,
  322. Lucia = 19,
  323. Verification = 20,
  324. Lagon = 21,
  325. };
  326. struct AppletFooterUi {
  327. AppletFooterUiAttributes attributes{};
  328. AppletFooterUiType type{AppletFooterUiType::None};
  329. INSERT_PADDING_BYTES(0x5B); // Reserved
  330. };
  331. static_assert(sizeof(AppletFooterUi) == 0x60, "AppletFooterUi is an invalid size");
  332. // This is nn::hid::NpadLarkType
  333. enum class NpadLarkType : u32 {
  334. Invalid,
  335. H1,
  336. H2,
  337. NL,
  338. NR,
  339. };
  340. // This is nn::hid::NpadLuciaType
  341. enum class NpadLuciaType : u32 {
  342. Invalid,
  343. J,
  344. E,
  345. U,
  346. };
  347. // This is nn::hid::NpadLagonType
  348. enum class NpadLagonType : u32 {
  349. Invalid,
  350. };
  351. // This is nn::hid::NpadLagerType
  352. enum class NpadLagerType : u32 {
  353. Invalid,
  354. J,
  355. E,
  356. U,
  357. };
  358. struct AppletNfcXcd {
  359. union {
  360. AppletFooterUi applet_footer{};
  361. Lifo<NfcXcdDeviceHandleStateImpl, 0x2> nfc_xcd_device_lifo;
  362. };
  363. };
  364. // This is nn::hid::detail::NpadInternalState
  365. struct NpadInternalState {
  366. Core::HID::NpadStyleTag style_tag{Core::HID::NpadStyleSet::None};
  367. NpadJoyAssignmentMode assignment_mode{NpadJoyAssignmentMode::Dual};
  368. NpadFullKeyColorState fullkey_color{};
  369. NpadJoyColorState joycon_color{};
  370. Lifo<NPadGenericState, hid_entry_count> fullkey_lifo{};
  371. Lifo<NPadGenericState, hid_entry_count> handheld_lifo{};
  372. Lifo<NPadGenericState, hid_entry_count> joy_dual_lifo{};
  373. Lifo<NPadGenericState, hid_entry_count> joy_left_lifo{};
  374. Lifo<NPadGenericState, hid_entry_count> joy_right_lifo{};
  375. Lifo<NPadGenericState, hid_entry_count> palma_lifo{};
  376. Lifo<NPadGenericState, hid_entry_count> system_ext_lifo{};
  377. Lifo<SixAxisSensorState, hid_entry_count> sixaxis_fullkey_lifo{};
  378. Lifo<SixAxisSensorState, hid_entry_count> sixaxis_handheld_lifo{};
  379. Lifo<SixAxisSensorState, hid_entry_count> sixaxis_dual_left_lifo{};
  380. Lifo<SixAxisSensorState, hid_entry_count> sixaxis_dual_right_lifo{};
  381. Lifo<SixAxisSensorState, hid_entry_count> sixaxis_left_lifo{};
  382. Lifo<SixAxisSensorState, hid_entry_count> sixaxis_right_lifo{};
  383. DeviceType device_type{};
  384. INSERT_PADDING_BYTES(0x4); // Reserved
  385. NPadSystemProperties system_properties{};
  386. NpadSystemButtonProperties button_properties{};
  387. Core::HID::NpadBatteryLevel battery_level_dual{};
  388. Core::HID::NpadBatteryLevel battery_level_left{};
  389. Core::HID::NpadBatteryLevel battery_level_right{};
  390. AppletNfcXcd applet_nfc_xcd{};
  391. INSERT_PADDING_BYTES(0x20); // Unknown
  392. Lifo<NpadGcTriggerState, hid_entry_count> gc_trigger_lifo{};
  393. NpadLarkType lark_type_l_and_main{};
  394. NpadLarkType lark_type_r{};
  395. NpadLuciaType lucia_type{};
  396. NpadLagonType lagon_type{};
  397. NpadLagerType lager_type{};
  398. // FW 13.x Investigate there is some sort of bitflag related to joycons
  399. INSERT_PADDING_BYTES(0x4);
  400. INSERT_PADDING_BYTES(0xc08); // Unknown
  401. };
  402. static_assert(sizeof(NpadInternalState) == 0x5000, "NpadInternalState is an invalid size");
  403. struct VibrationData {
  404. bool device_mounted{};
  405. Core::HID::VibrationValue latest_vibration_value{};
  406. std::chrono::steady_clock::time_point last_vibration_timepoint{};
  407. };
  408. struct SixaxisParameters {
  409. bool is_fusion_enabled{true};
  410. bool unaltered_passtrough{false};
  411. Core::HID::SixAxisSensorFusionParameters fusion{};
  412. GyroscopeZeroDriftMode gyroscope_zero_drift_mode{GyroscopeZeroDriftMode::Standard};
  413. };
  414. struct NpadControllerData {
  415. Kernel::KEvent* styleset_changed_event{};
  416. NpadInternalState* shared_memory = nullptr;
  417. Core::HID::EmulatedController* device = nullptr;
  418. std::array<VibrationData, 2> vibration{};
  419. bool unintended_home_button_input_protection{};
  420. bool is_connected{};
  421. // Dual joycons can have only one side connected
  422. bool is_dual_left_connected{true};
  423. bool is_dual_right_connected{true};
  424. // Motion parameters
  425. bool sixaxis_at_rest{true};
  426. bool sixaxis_sensor_enabled{true};
  427. SixaxisParameters sixaxis_fullkey{};
  428. SixaxisParameters sixaxis_handheld{};
  429. SixaxisParameters sixaxis_dual_left{};
  430. SixaxisParameters sixaxis_dual_right{};
  431. SixaxisParameters sixaxis_left{};
  432. SixaxisParameters sixaxis_right{};
  433. SixaxisParameters sixaxis_unknown{};
  434. // Current pad state
  435. NPadGenericState npad_pad_state{};
  436. NPadGenericState npad_libnx_state{};
  437. NpadGcTriggerState npad_trigger_state{};
  438. SixAxisSensorState sixaxis_fullkey_state{};
  439. SixAxisSensorState sixaxis_handheld_state{};
  440. SixAxisSensorState sixaxis_dual_left_state{};
  441. SixAxisSensorState sixaxis_dual_right_state{};
  442. SixAxisSensorState sixaxis_left_lifo_state{};
  443. SixAxisSensorState sixaxis_right_lifo_state{};
  444. int callback_key{};
  445. };
  446. void ControllerUpdate(Core::HID::ControllerTriggerType type, std::size_t controller_idx);
  447. void InitNewlyAddedController(Core::HID::NpadIdType npad_id);
  448. bool IsControllerSupported(Core::HID::NpadStyleIndex controller) const;
  449. void RequestPadStateUpdate(Core::HID::NpadIdType npad_id);
  450. void WriteEmptyEntry(NpadInternalState* npad);
  451. NpadControllerData& GetControllerFromHandle(
  452. const Core::HID::SixAxisSensorHandle& device_handle);
  453. const NpadControllerData& GetControllerFromHandle(
  454. const Core::HID::SixAxisSensorHandle& device_handle) const;
  455. NpadControllerData& GetControllerFromHandle(
  456. const Core::HID::VibrationDeviceHandle& device_handle);
  457. const NpadControllerData& GetControllerFromHandle(
  458. const Core::HID::VibrationDeviceHandle& device_handle) const;
  459. NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id);
  460. const NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id) const;
  461. SixaxisParameters& GetSixaxisState(const Core::HID::SixAxisSensorHandle& device_handle);
  462. const SixaxisParameters& GetSixaxisState(
  463. const Core::HID::SixAxisSensorHandle& device_handle) const;
  464. std::atomic<u64> press_state{};
  465. std::array<NpadControllerData, NPAD_COUNT> controller_data{};
  466. KernelHelpers::ServiceContext& service_context;
  467. std::mutex mutex;
  468. std::vector<Core::HID::NpadIdType> supported_npad_id_types{};
  469. NpadJoyHoldType hold_type{NpadJoyHoldType::Vertical};
  470. NpadHandheldActivationMode handheld_activation_mode{NpadHandheldActivationMode::Dual};
  471. NpadCommunicationMode communication_mode{NpadCommunicationMode::Default};
  472. bool permit_vibration_session_enabled{false};
  473. bool analog_stick_use_center_clamp{false};
  474. bool is_in_lr_assignment_mode{false};
  475. bool is_controller_initialized{false};
  476. };
  477. } // namespace Service::HID