npad.h 22 KB

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