npad.h 22 KB

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