| 1 | /** |
| 2 | * @file hid.h |
| 3 | * @brief Functions that help process gamepad inputs. |
| 4 | */ |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include <nn/os/os_MutexTypes.h> |
| 9 | #include <nn/types.h> |
| 10 | #include <nn/util.h> |
| 11 | #include <nn/util/MathTypes.h> |
| 12 | #include <nn/util/util_BitFlagSet.h> |
| 13 | #include <nn/xcd.h> |
| 14 | |
| 15 | namespace nn { |
| 16 | namespace hid { |
| 17 | |
| 18 | // todo: does something like this exist in nn? |
| 19 | typedef util::Color4u8Type Color4u8; |
| 20 | |
| 21 | enum class NpadButton { |
| 22 | A = 0, |
| 23 | B = 1, |
| 24 | X = 2, |
| 25 | Y = 3, |
| 26 | StickL = 4, |
| 27 | StickR = 5, |
| 28 | L = 6, |
| 29 | R = 7, |
| 30 | ZL = 8, |
| 31 | ZR = 9, |
| 32 | Plus = 10, |
| 33 | Minus = 11, |
| 34 | Left = 12, |
| 35 | Up = 13, |
| 36 | Right = 14, |
| 37 | Down = 15, |
| 38 | StickLLeft = 16, |
| 39 | StickLUp = 17, |
| 40 | StickLRight = 18, |
| 41 | StickLDown = 19, |
| 42 | StickRLeft = 20, |
| 43 | StickRUp = 21, |
| 44 | StickRRight = 22, |
| 45 | StickRDown = 23, |
| 46 | LeftSL = 24, |
| 47 | LeftSR = 25, |
| 48 | RightSL = 26, |
| 49 | RightSR = 27, |
| 50 | Palma = 28, |
| 51 | Verification = 29, |
| 52 | HandheldLeftB = 30, // (Left B button on NES controllers in Handheld mode) |
| 53 | LeftC = 31, // [12.0.0+] (Left C button in N64 controller) |
| 54 | UpC = 32, // [12.0.0+] (Up C button in N64 controller) |
| 55 | RightC = 33, // [12.0.0+] (Right C button in N64 controller) |
| 56 | DownC = 34, // [12.0.0+] (Down C button in N64 controller) |
| 57 | }; |
| 58 | |
| 59 | enum class NpadAttribute { |
| 60 | IsConnected = 0, |
| 61 | IsWired = 1, |
| 62 | IsLeftConnected = 2, |
| 63 | IsLeftWired = 3, |
| 64 | IsRightConnected = 4, |
| 65 | IsRightWired = 5, |
| 66 | }; |
| 67 | |
| 68 | enum class NpadStyleTag { |
| 69 | NpadStyleFullKey = 0, // (Pro Controller) |
| 70 | NpadStyleHandheld = 1, // (Joy-Con controller in handheld mode) |
| 71 | NpadStyleJoyDual = 2, // (Joy-Con controller in dual mode) |
| 72 | NpadStyleJoyLeft = 3, // (Joy-Con left controller in single mode) |
| 73 | NpadStyleJoyRight = 4, // (Joy-Con right controller in single mode) |
| 74 | #if NN_SDK_VER <= NN_MAKE_VER(3, 5, 1) |
| 75 | NpadStyleInvalid = 5, |
| 76 | #else |
| 77 | NpadStyleGc = 5, // (GameCube controller) |
| 78 | NpadStylePalma = 6, // (Poké Ball Plus controller) |
| 79 | NpadStyleLark = 7, // (NES/Famicom controller) |
| 80 | NpadStyleHandheldLark = 8, // (NES/Famicom controller in handheld mode) |
| 81 | NpadStyleLucia = 9, // (SNES controller) |
| 82 | NpadStyleLagon = 10, // [12.0.0+] (N64 controller) |
| 83 | NpadStyleLager = 11, // [13.0.0+] (Sega Genesis controller) |
| 84 | #endif |
| 85 | // bits 12-28 Reserved |
| 86 | NpadStyleSystemExt = 29, // (generic external controller) |
| 87 | NpadStyleSystem = 30, // (generic controller) |
| 88 | // bit 31 Reserved |
| 89 | }; |
| 90 | |
| 91 | enum class NpadSystemProperties { |
| 92 | IsChargingJoyDual = 0, |
| 93 | IsChargingJoyLeft = 1, |
| 94 | IsChargingJoyRight = 2, |
| 95 | IsPoweredJoyDual = 3, |
| 96 | IsPoweredJoyLeft = 4, |
| 97 | IsPoweredJoyRight = 5, |
| 98 | IsUnsuportedButtonPressedOnNpadSystem = 9, |
| 99 | IsUnsuportedButtonPressedOnNpadSystemExt = 10, |
| 100 | IsAbxyButtonOriented = 11, |
| 101 | IsSlSrButtonOriented = 12, |
| 102 | IsPlusAvailable = 13, // [4.0.0+] |
| 103 | IsMinusAvailable = 14, // [4.0.0+] |
| 104 | IsDirectionalButtonsAvailable = 15, // [8.0.0+] |
| 105 | }; |
| 106 | |
| 107 | enum class NpadSystemButtonProperties { IsUnintendedHomeButtonInputProtectionEnabled }; |
| 108 | |
| 109 | enum class TouchAttribute { Transferable = 0, IsConnected = 1 }; |
| 110 | |
| 111 | enum class MouseButton { Left, Right, Middle, Forward, Back }; |
| 112 | |
| 113 | enum class MouseAttribute { Transferable, IsConnected }; |
| 114 | |
| 115 | enum class KeyboardKey { |
| 116 | A = 4, |
| 117 | B = 5, |
| 118 | C = 6, |
| 119 | D = 7, |
| 120 | E = 8, |
| 121 | F = 9, |
| 122 | G = 10, |
| 123 | H = 11, |
| 124 | I = 12, |
| 125 | J = 13, |
| 126 | K = 14, |
| 127 | L = 15, |
| 128 | M = 16, |
| 129 | N = 17, |
| 130 | O = 18, |
| 131 | P = 19, |
| 132 | Q = 20, |
| 133 | R = 21, |
| 134 | S = 22, |
| 135 | T = 23, |
| 136 | U = 24, |
| 137 | V = 25, |
| 138 | W = 26, |
| 139 | X = 27, |
| 140 | Y = 28, |
| 141 | Z = 29, |
| 142 | D1 = 30, |
| 143 | D2 = 31, |
| 144 | D3 = 32, |
| 145 | D4 = 33, |
| 146 | D5 = 34, |
| 147 | D6 = 35, |
| 148 | D7 = 36, |
| 149 | D8 = 37, |
| 150 | D9 = 38, |
| 151 | D0 = 39, |
| 152 | Return = 40, |
| 153 | Escape = 41, |
| 154 | Backspace = 42, |
| 155 | Tab = 43, |
| 156 | Space = 44, |
| 157 | Minus = 45, |
| 158 | Plus = 46, |
| 159 | OpenBracket = 47, |
| 160 | CloseBracket = 48, |
| 161 | Pipe = 49, |
| 162 | Tilde = 50, |
| 163 | Semicolon = 51, |
| 164 | Quote = 52, |
| 165 | Backquote = 53, |
| 166 | Comma = 54, |
| 167 | Period = 55, |
| 168 | Slash = 56, |
| 169 | CapsLock = 57, |
| 170 | F1 = 58, |
| 171 | F2 = 59, |
| 172 | F3 = 60, |
| 173 | F4 = 61, |
| 174 | F5 = 62, |
| 175 | F6 = 63, |
| 176 | F7 = 64, |
| 177 | F8 = 65, |
| 178 | F9 = 66, |
| 179 | F10 = 67, |
| 180 | F11 = 68, |
| 181 | F12 = 69, |
| 182 | PrintScreen = 70, |
| 183 | ScrollLock = 71, |
| 184 | Pause = 72, |
| 185 | Insert = 73, |
| 186 | Home = 74, |
| 187 | PageUp = 75, |
| 188 | Delete = 76, |
| 189 | End = 77, |
| 190 | PageDown = 78, |
| 191 | RightArrow = 79, |
| 192 | LeftArrow = 80, |
| 193 | DownArrow = 81, |
| 194 | UpArrow = 82, |
| 195 | NumLock = 83, |
| 196 | NumPadDivide = 84, |
| 197 | NumPadMultiply = 85, |
| 198 | NumPadSubtract = 86, |
| 199 | NumPadAdd = 87, |
| 200 | NumPadEnter = 88, |
| 201 | NumPad1 = 89, |
| 202 | NumPad2 = 90, |
| 203 | NumPad3 = 91, |
| 204 | NumPad4 = 92, |
| 205 | NumPad5 = 93, |
| 206 | NumPad6 = 94, |
| 207 | NumPad7 = 95, |
| 208 | NumPad8 = 96, |
| 209 | NumPad9 = 97, |
| 210 | NumPad0 = 98, |
| 211 | NumPadDot = 99, |
| 212 | Backslash = 100, |
| 213 | Application = 101, |
| 214 | Power = 102, |
| 215 | NumPadEquals = 103, |
| 216 | F13 = 104, |
| 217 | F14 = 105, |
| 218 | F15 = 106, |
| 219 | F16 = 107, |
| 220 | F17 = 108, |
| 221 | F18 = 109, |
| 222 | F19 = 110, |
| 223 | F20 = 111, |
| 224 | F21 = 112, |
| 225 | F22 = 113, |
| 226 | F23 = 114, |
| 227 | F24 = 115, |
| 228 | NumPadComma = 133, |
| 229 | Ro = 135, |
| 230 | KatakanaHiragana = 136, |
| 231 | Yen = 137, |
| 232 | Henkan = 138, |
| 233 | Muhenkan = 139, |
| 234 | NumPadCommaPc98 = 140, |
| 235 | HangulEnglish = 144, |
| 236 | Hanja = 145, |
| 237 | Katakana = 146, |
| 238 | Hiragana = 147, |
| 239 | ZenkakuHankaku = 148, |
| 240 | LeftControl = 224, |
| 241 | LeftShift = 225, |
| 242 | LeftAlt = 226, |
| 243 | LeftGui = 227, |
| 244 | RightControl = 228, |
| 245 | RightShift = 229, |
| 246 | RightAlt = 230, |
| 247 | RightGui = 231, |
| 248 | }; |
| 249 | |
| 250 | enum class KeyboardModifier { |
| 251 | Control, |
| 252 | Shift, |
| 253 | LeftAlt, |
| 254 | RightAlt, |
| 255 | Gui, |
| 256 | CapsLock, |
| 257 | ScrollLock, |
| 258 | NumLock, |
| 259 | Katakana, |
| 260 | Hiragana |
| 261 | }; |
| 262 | |
| 263 | enum class DebugPadButton { A, B, X, Y, L, R, ZL, ZR, Start, Select, Left, Up, Right, Down }; |
| 264 | |
| 265 | enum class DebugPadAttribute { IsConnected }; |
| 266 | |
| 267 | enum class BasicXpadButton {}; |
| 268 | |
| 269 | enum class BasicXpadAttribute {}; |
| 270 | |
| 271 | enum class GestureType { Idle, Complete, Cancel, Touch, Press, Tap, Pan, Swipe, Pinch, Rotate }; |
| 272 | |
| 273 | enum class GestureDirection { None, Left, Up, Right, Down }; |
| 274 | |
| 275 | enum class GestureAttribute { IsNewTouch = 4, IsDoubleTap = 8 }; |
| 276 | |
| 277 | enum class SixAxisSensorAttribute { IsConnected, IsInterpolated }; |
| 278 | |
| 279 | enum class NpadJoyHoldType { Vertical, Horizontal }; |
| 280 | |
| 281 | enum class NpadJoyDeviceType { Left, Right }; |
| 282 | |
| 283 | enum class NpadHandheldActivationMode { Dual, Single, None }; |
| 284 | |
| 285 | enum class NpadJoyAssignmentMode { Dual, Single }; |
| 286 | |
| 287 | enum class DigitizerAttribute {}; |
| 288 | |
| 289 | enum class DigitizerButton {}; |
| 290 | |
| 291 | enum class VibrationDeviceType { Unknown, LinearResonantActuator, GcErm, Erm }; |
| 292 | |
| 293 | enum class VibrationDevicePosition { None, Left, Right }; |
| 294 | |
| 295 | enum class NpadLarkType { Invalid, H1, H2, NL, NR }; |
| 296 | |
| 297 | enum class NpadLuciaType { Invalid, J, E, U }; |
| 298 | |
| 299 | enum class NpadLagerType { Invalid, J, E, U }; |
| 300 | |
| 301 | typedef nn::util::BitFlagSet<32, NpadAttribute> NpadAttributeSet; |
| 302 | typedef nn::util::BitFlagSet<64, NpadButton> NpadButtonSet; |
| 303 | typedef nn::util::BitFlagSet<32, NpadStyleTag> NpadStyleSet; |
| 304 | typedef nn::util::BitFlagSet<32, MouseButton> MouseButtonSet; |
| 305 | typedef nn::util::BitFlagSet<32, MouseAttribute> MouseAttributeSet; |
| 306 | typedef nn::util::BitFlagSet<32, TouchAttribute> TouchAttributeSet; |
| 307 | typedef nn::util::BitFlagSet<32, DebugPadButton> DebugPadButtonSet; |
| 308 | typedef nn::util::BitFlagSet<32, DebugPadAttribute> DebugPadAttributeSet; |
| 309 | typedef nn::util::BitFlagSet<32, BasicXpadButton> BasicXpadButtonSet; |
| 310 | typedef nn::util::BitFlagSet<32, BasicXpadAttribute> BasicXpadAttributeSet; |
| 311 | typedef nn::util::BitFlagSet<32, GestureAttribute> GestureAttributeSet; |
| 312 | typedef nn::util::BitFlagSet<32, SixAxisSensorAttribute> SixAxisSensorAttributeSet; |
| 313 | typedef nn::util::BitFlagSet<32, DigitizerAttribute> DigitizerAttributeSet; |
| 314 | typedef nn::util::BitFlagSet<32, DigitizerButton> DigitizerButtonSet; |
| 315 | |
| 316 | struct AnalogStickState { |
| 317 | s32 mX; |
| 318 | s32 mY; |
| 319 | }; |
| 320 | |
| 321 | struct ControllerSupportArg { |
| 322 | u8 mMinPlayerCount; |
| 323 | u8 mMaxPlayerCount; |
| 324 | u8 mTakeOverConnection; |
| 325 | bool mLeftJustify; |
| 326 | bool mPermitJoyconDual; |
| 327 | bool mSingleMode; |
| 328 | bool mUseColors; |
| 329 | Color4u8 mColors[4]; |
| 330 | u8 mUsingControllerNames; |
| 331 | char mControllerNames[4][0x81]; |
| 332 | }; |
| 333 | |
| 334 | struct ControllerSupportArgV2 { |
| 335 | u8 mMinPlayerCount; |
| 336 | u8 mMaxPlayerCount; |
| 337 | u8 mTakeOverConnection; |
| 338 | bool mLeftJustify; |
| 339 | bool mPermitJoyconDual; |
| 340 | bool mSingleMode; |
| 341 | bool mUseColors; |
| 342 | Color4u8 mColors[8]; |
| 343 | u8 mUsingControllerNames; |
| 344 | char mControllerNames[8][0x81]; |
| 345 | }; |
| 346 | |
| 347 | struct ControllerSupportResultInfo { |
| 348 | s8 mPlayerCount; |
| 349 | s32 mSelectedId; |
| 350 | s32 mResult; |
| 351 | }; |
| 352 | |
| 353 | struct NpadControllerColor { |
| 354 | Color4u8 mMain; |
| 355 | Color4u8 mSub; |
| 356 | }; |
| 357 | |
| 358 | struct DebugPadState { |
| 359 | u64 mSamplingNumber; |
| 360 | DebugPadAttributeSet mAttributes; |
| 361 | DebugPadButtonSet mButtons; |
| 362 | AnalogStickState mAnalogStickR; |
| 363 | AnalogStickState mAnalogStickL; |
| 364 | }; |
| 365 | |
| 366 | struct TouchState { |
| 367 | u64 mDeltaTime; |
| 368 | TouchAttributeSet mAttributes; |
| 369 | s32 mFingerId; |
| 370 | s32 mX; |
| 371 | s32 mY; |
| 372 | s32 mDiameterX; |
| 373 | s32 mDiameterY; |
| 374 | s32 mRotationAngle; |
| 375 | }; |
| 376 | |
| 377 | template <u64 N> |
| 378 | struct TouchScreenState { |
| 379 | u64 mSamplingNumber; |
| 380 | s32 mCount; |
| 381 | TouchState mTouches[N]; |
| 382 | }; |
| 383 | |
| 384 | struct MouseState { |
| 385 | u64 mSamplingNumber; |
| 386 | s32 mX; |
| 387 | s32 mY; |
| 388 | s32 mDeltaX; |
| 389 | s32 mDeltaY; |
| 390 | s32 mWheelDeltaX; |
| 391 | s32 mWheelDeltaY; |
| 392 | MouseButtonSet mButtons; |
| 393 | MouseAttributeSet mAttributes; |
| 394 | }; |
| 395 | |
| 396 | struct KeyboardState { |
| 397 | u64 mSamplingNumber; |
| 398 | nn::util::BitFlagSet<32, KeyboardModifier> mModifiers; |
| 399 | nn::util::BitFlagSet<256, KeyboardKey> mKeys; |
| 400 | }; |
| 401 | |
| 402 | struct BasicXpadState { |
| 403 | u64 mSamplingNumber; |
| 404 | BasicXpadAttributeSet mAttributes; |
| 405 | BasicXpadButtonSet mButtons; |
| 406 | AnalogStickState mAnalogStickL; |
| 407 | AnalogStickState mAnalogStickR; |
| 408 | }; |
| 409 | |
| 410 | struct NpadBaseState { |
| 411 | u64 mSamplingNumber; |
| 412 | NpadButtonSet mButtons; |
| 413 | AnalogStickState mAnalogStickL; |
| 414 | AnalogStickState mAnalogStickR; |
| 415 | NpadAttributeSet mAttributes; |
| 416 | }; |
| 417 | |
| 418 | struct NpadFullKeyState : NpadBaseState {}; |
| 419 | |
| 420 | struct NpadHandheldState : NpadBaseState {}; |
| 421 | |
| 422 | struct NpadJoyDualState : NpadBaseState {}; |
| 423 | |
| 424 | struct NpadJoyLeftState : NpadBaseState {}; |
| 425 | |
| 426 | struct NpadJoyRightState : NpadBaseState {}; |
| 427 | |
| 428 | struct NpadPalmaState : NpadBaseState {}; |
| 429 | |
| 430 | struct DirectionState { |
| 431 | f32 mMtx[3][3]; |
| 432 | }; |
| 433 | |
| 434 | struct SixAxisSensorState { |
| 435 | u64 mDeltaTime; |
| 436 | u64 mSamplingNumber; |
| 437 | f32 mAcceleration[3]; |
| 438 | f32 mAngularVelocity[3]; |
| 439 | f32 mAngle[3]; |
| 440 | DirectionState mDirection; |
| 441 | SixAxisSensorAttributeSet mAttributes; |
| 442 | }; |
| 443 | |
| 444 | struct GesturePoint { |
| 445 | s32 mX; |
| 446 | s32 mY; |
| 447 | }; |
| 448 | |
| 449 | struct GestureState { |
| 450 | u64 mSamplingNumber; |
| 451 | u64 mContextNumber; |
| 452 | GestureType mType; |
| 453 | GestureDirection mDirection; |
| 454 | s32 mX; |
| 455 | s32 mY; |
| 456 | s32 mDeltaX; |
| 457 | s32 mDeltaY; |
| 458 | f32 mVelocityX; |
| 459 | f32 mVelocityY; |
| 460 | GestureAttributeSet mAttributes; |
| 461 | f32 mScale; |
| 462 | f32 mRotationAngle; |
| 463 | s32 mPointCount; |
| 464 | GesturePoint mPoint[4]; |
| 465 | }; |
| 466 | |
| 467 | struct DigitizerState { |
| 468 | u64 mSamplingNumber; |
| 469 | u8 padding_8[0x8]; |
| 470 | DigitizerAttributeSet mAttributes; |
| 471 | DigitizerButtonSet mButtons; |
| 472 | u8 padding[0x40]; |
| 473 | }; |
| 474 | |
| 475 | struct SixAxisSensorHandle { |
| 476 | union { |
| 477 | u32 typeValue; |
| 478 | struct { |
| 479 | u8 mNpadStyleIndex; |
| 480 | u8 mPlayerNumber; |
| 481 | u8 mDeviceIndex; |
| 482 | }; |
| 483 | }; |
| 484 | }; |
| 485 | |
| 486 | struct VibrationDeviceHandle { |
| 487 | union { |
| 488 | u32 typeValue; |
| 489 | struct { |
| 490 | u8 mNpadStyleIndex; |
| 491 | u8 mPlayerNumber; |
| 492 | u8 mDeviceIndex; |
| 493 | }; |
| 494 | }; |
| 495 | }; |
| 496 | |
| 497 | struct VibrationDeviceInfo { |
| 498 | VibrationDeviceType mDeviceType; |
| 499 | VibrationDevicePosition mPosition; |
| 500 | }; |
| 501 | |
| 502 | struct VibrationValue { |
| 503 | f32 mAmplitudeLow; |
| 504 | f32 mFrequencyLow; |
| 505 | f32 mAmplitudeHigh; |
| 506 | f32 mFrequencyHigh; |
| 507 | }; |
| 508 | |
| 509 | void InitializeNpad(); |
| 510 | void SetSupportedNpadIdType(const u32*, u64); |
| 511 | void SetSupportedNpadStyleSet(NpadStyleSet); |
| 512 | NpadStyleSet GetNpadStyleSet(const u32& port); |
| 513 | s32 ShowControllerSupport(ControllerSupportResultInfo*, const ControllerSupportArg&); |
| 514 | |
| 515 | void GetNpadState(NpadFullKeyState*, const u32& port); |
| 516 | void GetNpadState(NpadHandheldState*, const u32& port); |
| 517 | void GetNpadState(NpadJoyDualState*, const u32& port); |
| 518 | void GetNpadState(NpadJoyLeftState*, const u32& port); |
| 519 | void GetNpadState(NpadJoyRightState*, const u32& port); |
| 520 | |
| 521 | void GetNpadStates(NpadFullKeyState*, s32, const u32& port); |
| 522 | void GetNpadStates(NpadHandheldState*, s32, const u32& port); |
| 523 | void GetNpadStates(NpadJoyDualState*, s32, const u32& port); |
| 524 | void GetNpadStates(NpadJoyLeftState*, s32, const u32& port); |
| 525 | void GetNpadStates(NpadJoyRightState*, s32, const u32& port); |
| 526 | |
| 527 | void InitializeMouse(); |
| 528 | void InitializeKeyboard(); |
| 529 | |
| 530 | void GetMouseState(MouseState*); |
| 531 | void GetKeyboardState(KeyboardState*); |
| 532 | |
| 533 | namespace system { |
| 534 | |
| 535 | typedef u8 UniquePadSerialNumber[0x10]; |
| 536 | typedef u32 BatteryLevel; |
| 537 | |
| 538 | enum class UniquePadType : u64 { |
| 539 | Embedded, |
| 540 | FullKeyController, |
| 541 | RightController, |
| 542 | LeftController, |
| 543 | DebugPadController |
| 544 | }; |
| 545 | |
| 546 | enum class UniquePadInterface { Embedded, Rail, Bluetooth, Usb }; |
| 547 | |
| 548 | enum class HomeButton {}; |
| 549 | |
| 550 | enum class SleepButton {}; |
| 551 | |
| 552 | enum class CaptureButton {}; |
| 553 | |
| 554 | enum class AnalogStickManualCalibrationStage : u64 { |
| 555 | ReleaseFromRight, |
| 556 | ReleaseFromBottom, |
| 557 | ReleaseFromLeft, |
| 558 | ReleaseFromTop, |
| 559 | Rotate, |
| 560 | Update, |
| 561 | Completed, |
| 562 | Clear, |
| 563 | ClearCompleted |
| 564 | }; |
| 565 | |
| 566 | enum class SixAxisSensorUserCalibrationStage : u64 { Measuring, Update, Completed }; |
| 567 | |
| 568 | enum class DeviceType { |
| 569 | FullKey, |
| 570 | DebugPad, |
| 571 | HandheldLeft, |
| 572 | HandheldRight, |
| 573 | JoyLeft, |
| 574 | JoyRight, |
| 575 | Palma, |
| 576 | LarkHvcLeft, |
| 577 | LarkHvcRight, |
| 578 | LarkNesLeft, |
| 579 | LarkNesRight, |
| 580 | HandheldLarkHvcLeft, |
| 581 | HandheldLarkHvcRight, |
| 582 | HandheldLarkNesLeft, |
| 583 | HandheldLarkNesRight, |
| 584 | Lucia, |
| 585 | Lagon, // [12.0.0+] |
| 586 | Lager, // [13.0.0+] |
| 587 | System = 31 |
| 588 | }; |
| 589 | |
| 590 | enum class : u8 { |
| 591 | , |
| 592 | HandheldNone, |
| 593 | HandheldJoyConLeftOnly, |
| 594 | HandheldJoyConRightOnly, |
| 595 | HandheldLeftJoyConRight, |
| 596 | , |
| 597 | , |
| 598 | , |
| 599 | , |
| 600 | , |
| 601 | , |
| 602 | , |
| 603 | , |
| 604 | , |
| 605 | , |
| 606 | , |
| 607 | , |
| 608 | , |
| 609 | , |
| 610 | , |
| 611 | , |
| 612 | , // [13.0.0+] |
| 613 | }; |
| 614 | |
| 615 | enum class {}; |
| 616 | |
| 617 | typedef nn::util::BitFlagSet<64, HomeButton> HomeButtonSet; |
| 618 | typedef nn::util::BitFlagSet<64, SleepButton> SleepButtonSet; |
| 619 | typedef nn::util::BitFlagSet<64, CaptureButton> CaptureButtonSet; |
| 620 | typedef nn::util::BitFlagSet<32, AppletFooterUiAttribute> ; |
| 621 | |
| 622 | struct HomeButtonState { |
| 623 | u64 mSamplingNumber; |
| 624 | HomeButtonSet mButtons; |
| 625 | }; |
| 626 | |
| 627 | struct SleepButtonState { |
| 628 | u64 mSamplingNumber; |
| 629 | SleepButtonSet mButtons; |
| 630 | }; |
| 631 | |
| 632 | struct CaptureButtonState { |
| 633 | u64 mSamplingNumber; |
| 634 | CaptureButtonSet mButtons; |
| 635 | }; |
| 636 | |
| 637 | struct NpadSystemState : NpadBaseState {}; |
| 638 | |
| 639 | struct NpadSystemExtState : NpadBaseState {}; |
| 640 | |
| 641 | struct InputSourceState { |
| 642 | u64 mTimestamp; |
| 643 | }; |
| 644 | |
| 645 | } // namespace system |
| 646 | |
| 647 | namespace tmp { |
| 648 | |
| 649 | struct SixAxisSensorCountState { |
| 650 | u8 padding[0x28]; |
| 651 | }; |
| 652 | |
| 653 | } // namespace tmp |
| 654 | |
| 655 | namespace detail { |
| 656 | |
| 657 | template <typename T> |
| 658 | |
| 659 | class AtomicStorage { |
| 660 | public: |
| 661 | u64 mSamplingNumber; |
| 662 | T mStorage; |
| 663 | }; |
| 664 | |
| 665 | template <typename T, s32 N, typename Atomic> |
| 666 | struct RingLifo { |
| 667 | u64 mTimestamp; |
| 668 | u64 mBufferCount = N + 1; |
| 669 | u64 mTail = 0; |
| 670 | u64 mCount = 0; |
| 671 | Atomic mStorage[N + 1]; |
| 672 | }; |
| 673 | |
| 674 | } // namespace detail |
| 675 | |
| 676 | namespace server { |
| 677 | |
| 678 | typedef detail::RingLifo<DigitizerState, 16, detail::AtomicStorage<DigitizerState>> DigitizerLifo; |
| 679 | |
| 680 | struct DigitizerSharedMemoryFormat { |
| 681 | DigitizerLifo mLifo; |
| 682 | u8 padding[0x1000 - sizeof(DigitizerLifo)]; |
| 683 | }; |
| 684 | |
| 685 | struct NpadGcTriggerState { |
| 686 | u64 mSamplingNumber; |
| 687 | u32 mTriggerL; |
| 688 | u32 mTriggerR; |
| 689 | }; |
| 690 | |
| 691 | enum class SixAxisSensorProperties { |
| 692 | IsSixAxisSensorDeviceNewlyAssigned, |
| 693 | IsFirmwareUpdateAvailableForSixAxisSensor |
| 694 | }; |
| 695 | |
| 696 | } // namespace server |
| 697 | |
| 698 | namespace detail { |
| 699 | |
| 700 | enum class AnalogStickCalibrationFlags {}; |
| 701 | enum class SixAxisSensorUserCalibrationFlags {}; |
| 702 | enum class ColorAttribute { Ok, ReadError, NoController }; |
| 703 | |
| 704 | typedef AtomicStorage<TouchScreenState<16>> TouchScreenStateAtomicStorage; |
| 705 | typedef AtomicStorage<server::NpadGcTriggerState> NpadGcTriggerStateAtomicStorage; |
| 706 | |
| 707 | typedef nn::util::BitFlagSet<32, AnalogStickCalibrationFlags> AnalogStickCalibrationFlagsSet; |
| 708 | typedef nn::util::BitFlagSet<32, SixAxisSensorUserCalibrationFlags> |
| 709 | SixAxisSensorUserCalibrationFlagsSet; |
| 710 | typedef nn::util::BitFlagSet<64, NpadSystemProperties> NpadSystemPropertiesSet; |
| 711 | typedef nn::util::BitFlagSet<32, NpadSystemButtonProperties> NpadSystemButtonPropertiesSet; |
| 712 | |
| 713 | struct InputDetectorState { |
| 714 | system::InputSourceState mInputSourceState; |
| 715 | u64 mSamplingNumber; |
| 716 | }; |
| 717 | |
| 718 | struct UniquePadConfig { |
| 719 | system::UniquePadType mType; |
| 720 | system::UniquePadInterface mInterface; |
| 721 | system::UniquePadSerialNumber mSerialNumber; |
| 722 | u32 mControllerNumber; |
| 723 | bool mIsActive; |
| 724 | u64 mSamplingNumber; |
| 725 | }; |
| 726 | |
| 727 | struct AnalogStickCalibrationStateImpl { |
| 728 | AnalogStickState mState; |
| 729 | AnalogStickCalibrationFlagsSet mFlags; |
| 730 | system::AnalogStickManualCalibrationStage mStage; |
| 731 | u64 mSamplingNumber; |
| 732 | }; |
| 733 | |
| 734 | struct SixAxisSensorUserCalibrationState { |
| 735 | SixAxisSensorUserCalibrationFlagsSet mFlags; |
| 736 | system::SixAxisSensorUserCalibrationStage mStage; |
| 737 | u64 mSamplingNumber; |
| 738 | }; |
| 739 | |
| 740 | struct NfcXcdDeviceHandleStateImpl { |
| 741 | xcd::DeviceHandle mHandle; |
| 742 | bool mIsAvailable; |
| 743 | bool mIsActivated; |
| 744 | u64 mSamplingNumber; |
| 745 | }; |
| 746 | |
| 747 | typedef RingLifo<MouseState, 16, AtomicStorage<MouseState>> MouseLifo; |
| 748 | typedef RingLifo<DebugPadState, 16, AtomicStorage<DebugPadState>> DebugPadLifo; |
| 749 | typedef RingLifo<KeyboardState, 16, AtomicStorage<KeyboardState>> KeyboardLifo; |
| 750 | typedef RingLifo<BasicXpadState, 16, AtomicStorage<BasicXpadState>> BasicXpadLifo; |
| 751 | typedef RingLifo<NpadFullKeyState, 16, AtomicStorage<NpadFullKeyState>> NpadFullKeyLifo; |
| 752 | typedef RingLifo<NpadJoyDualState, 16, AtomicStorage<NpadJoyDualState>> NpadJoyDualLifo; |
| 753 | typedef RingLifo<NpadJoyLeftState, 16, AtomicStorage<NpadJoyLeftState>> NpadJoyLeftLifo; |
| 754 | typedef RingLifo<TouchScreenState<16ul>, 16, TouchScreenStateAtomicStorage> TouchScreenLifo; |
| 755 | typedef RingLifo<NpadHandheldState, 16, AtomicStorage<NpadHandheldState>> NpadHandheldLifo; |
| 756 | typedef RingLifo<NpadJoyRightState, 16, AtomicStorage<NpadJoyRightState>> NpadJoyRightLifo; |
| 757 | typedef RingLifo<tmp::SixAxisSensorCountState, 32, AtomicStorage<tmp::SixAxisSensorCountState>> |
| 758 | SixAxisSensorCountStateLifo; |
| 759 | typedef RingLifo<system::HomeButtonState, 16, AtomicStorage<system::HomeButtonState>> |
| 760 | HomeButtonLifo; |
| 761 | typedef RingLifo<system::NpadSystemState, 16, AtomicStorage<system::NpadSystemState>> |
| 762 | NpadSystemLifo; |
| 763 | typedef RingLifo<system::SleepButtonState, 16, AtomicStorage<system::SleepButtonState>> |
| 764 | SleepButtonLifo; |
| 765 | typedef RingLifo<system::CaptureButtonState, 16, AtomicStorage<system::CaptureButtonState>> |
| 766 | CaptureButtonLifo; |
| 767 | typedef RingLifo<system::NpadSystemExtState, 16, AtomicStorage<system::NpadSystemExtState>> |
| 768 | NpadSystemExtLifo; |
| 769 | typedef RingLifo<UniquePadConfig, 1, AtomicStorage<UniquePadConfig>> UniquePadConfigLifo; |
| 770 | typedef RingLifo<GestureState, 16, AtomicStorage<GestureState>> GestureLifo; |
| 771 | typedef RingLifo<InputDetectorState, 1, AtomicStorage<InputDetectorState>> InputDetectorLifo; |
| 772 | typedef RingLifo<NfcXcdDeviceHandleStateImpl, 1, AtomicStorage<NfcXcdDeviceHandleStateImpl>> |
| 773 | NfcXcdDeviceHandleState; |
| 774 | typedef RingLifo<AnalogStickCalibrationStateImpl, 1, AtomicStorage<AnalogStickCalibrationStateImpl>> |
| 775 | AnalogStickCalibrationStateImplLifo; |
| 776 | typedef RingLifo<SixAxisSensorUserCalibrationState, 1, |
| 777 | AtomicStorage<SixAxisSensorUserCalibrationState>> |
| 778 | SixAxisSensorUserCalibrationStateLifo; |
| 779 | typedef RingLifo<SixAxisSensorState, 16, AtomicStorage<SixAxisSensorState>> NpadSixAxisSensorLifo; |
| 780 | typedef RingLifo<SixAxisSensorState, 32, AtomicStorage<SixAxisSensorState>> SixAxisSensorStateLifo; |
| 781 | typedef RingLifo<SixAxisSensorState, 16, NpadGcTriggerStateAtomicStorage> NpadGcTriggerLifo; |
| 782 | |
| 783 | struct DebugPadSharedMemoryFormat { |
| 784 | DebugPadLifo mLifo; |
| 785 | u8 padding[0x400 - sizeof(DebugPadLifo)]; |
| 786 | }; |
| 787 | |
| 788 | struct TouchScreenSharedMemoryFormat { |
| 789 | TouchScreenLifo mLifo; |
| 790 | u8 padding[0x3000 - sizeof(TouchScreenLifo)]; |
| 791 | }; |
| 792 | |
| 793 | struct MouseSharedMemoryFormat { |
| 794 | MouseLifo mLifo; |
| 795 | u8 padding[0x400 - sizeof(MouseLifo)]; |
| 796 | }; |
| 797 | |
| 798 | struct KeyboardSharedMemoryFormat { |
| 799 | KeyboardLifo mLifo; |
| 800 | u8 padding[0x400 - sizeof(KeyboardLifo)]; |
| 801 | }; |
| 802 | |
| 803 | struct BasicXpadSharedMemoryEntry { |
| 804 | BasicXpadLifo mLifo; |
| 805 | u8 padding[0x400 - sizeof(BasicXpadLifo)]; |
| 806 | }; |
| 807 | |
| 808 | struct BasicXpadSharedMemoryFormat { |
| 809 | BasicXpadSharedMemoryEntry mEntries[4]; |
| 810 | }; |
| 811 | |
| 812 | struct HomeButtonSharedMemoryFormat { |
| 813 | HomeButtonLifo mLifo; |
| 814 | u8 padding[0x200 - sizeof(HomeButtonLifo)]; |
| 815 | }; |
| 816 | |
| 817 | struct SleepButtonSharedMemoryFormat { |
| 818 | SleepButtonLifo mLifo; |
| 819 | u8 padding[0x200 - sizeof(SleepButtonLifo)]; |
| 820 | }; |
| 821 | |
| 822 | struct CaptureButtonSharedMemoryFormat { |
| 823 | CaptureButtonLifo mLifo; |
| 824 | u8 padding[0x200 - sizeof(CaptureButtonLifo)]; |
| 825 | }; |
| 826 | |
| 827 | struct InputDetectorSharedMemoryEntry { |
| 828 | InputDetectorLifo mLifo; |
| 829 | u8 padding[0x80 - sizeof(InputDetectorLifo)]; |
| 830 | }; |
| 831 | |
| 832 | struct InputDetectorSharedMemoryFormat { |
| 833 | InputDetectorSharedMemoryEntry mEntries[16]; |
| 834 | }; |
| 835 | |
| 836 | struct UniquePadSharedMemoryEntry { |
| 837 | UniquePadConfigLifo mUniquePadConfigLifo; |
| 838 | AnalogStickCalibrationStateImplLifo mAnalogStickCalibrationStateImplLifo[2]; |
| 839 | SixAxisSensorUserCalibrationStateLifo mSixAxisSensorUserCalibrationStateLifo; |
| 840 | os::MutexType mMutex; |
| 841 | u8 padding[0x400 - 0x1f0]; |
| 842 | }; |
| 843 | |
| 844 | struct UniquePadSharedMemoryFormat { |
| 845 | UniquePadSharedMemoryEntry mEntries[16]; |
| 846 | }; |
| 847 | |
| 848 | struct NpadFullKeyColorState { |
| 849 | ColorAttribute mAttribute; |
| 850 | NpadControllerColor mFullKey; |
| 851 | }; |
| 852 | |
| 853 | struct NpadJoyColorState { |
| 854 | ColorAttribute mAttribute; |
| 855 | NpadControllerColor mLeft; |
| 856 | NpadControllerColor mRight; |
| 857 | }; |
| 858 | |
| 859 | struct NpadInternalState { |
| 860 | NpadStyleSet mStyleSet; |
| 861 | NpadJoyAssignmentMode mJoyAssignmentMode; |
| 862 | NpadFullKeyColorState mFullKeyColor; |
| 863 | NpadJoyColorState mJoyColor; |
| 864 | NpadFullKeyLifo mFullKeyLifo; |
| 865 | NpadHandheldLifo mHandheldLifo; |
| 866 | NpadJoyDualLifo mJoyDualLifo; |
| 867 | NpadJoyLeftLifo mJoyLeftLifo; |
| 868 | NpadJoyRightLifo mJoyRightLifo; |
| 869 | NpadSystemLifo mSystemLifo; |
| 870 | NpadSystemExtLifo mSystemExtLifo; |
| 871 | NpadSixAxisSensorLifo mFullKeySixAxisSensorLifo; |
| 872 | NpadSixAxisSensorLifo mHandheldSixAxisSensorLifo; |
| 873 | NpadSixAxisSensorLifo mJoyDualLeftSixAxisSensorLifo; |
| 874 | NpadSixAxisSensorLifo mJoyDualRightSixAxisSensorLifo; |
| 875 | NpadSixAxisSensorLifo mJoyLeftSixAxisSensorLifo; |
| 876 | NpadSixAxisSensorLifo mJoyRightSixAxisSensorLifo; |
| 877 | system::DeviceType mDeviceType; |
| 878 | NpadSystemPropertiesSet mSystemProperties; |
| 879 | NpadSystemButtonPropertiesSet mSystemButtonProperties; |
| 880 | system::BatteryLevel mBatteryLevelJoyDual; |
| 881 | system::BatteryLevel mBatteryLevelJoyLeft; |
| 882 | system::BatteryLevel mBatteryLevelJoyRight; |
| 883 | #if NN_SDK_VER < NN_MAKE_VER(9, 0, 0) |
| 884 | NfcXcdDeviceHandleState mNfcXcdDeviceHandle; |
| 885 | os::MutexType mMutex; |
| 886 | u8 padding[0x20]; |
| 887 | #else |
| 888 | system::AppletFooterUiAttributeSet mAppletFooterUiAttributes; |
| 889 | system::AppletFooterUiType mAppletFooterUiType; |
| 890 | u8 padding[0x7b]; |
| 891 | #endif |
| 892 | NpadGcTriggerLifo GcTriggerLifo; |
| 893 | NpadLarkType mLarkTypeLAndMain; |
| 894 | NpadLarkType mLarkTypeR; |
| 895 | NpadLuciaType mLuciaType; |
| 896 | NpadLagerType mLagerType; |
| 897 | server::SixAxisSensorProperties mSixAxisSensorProperties[6]; // [13.0.0+] |
| 898 | }; |
| 899 | |
| 900 | struct NpadSharedMemoryEntry { |
| 901 | NpadInternalState mInternalState; |
| 902 | u8 padding[0x5000 - sizeof(NpadInternalState)]; |
| 903 | }; |
| 904 | |
| 905 | struct NpadSharedMemoryFormat { |
| 906 | NpadSharedMemoryEntry mEntries[10]; |
| 907 | }; |
| 908 | |
| 909 | struct GestureSharedMemoryFormat { |
| 910 | GestureLifo mLifo; |
| 911 | u8 padding[0x800 - sizeof(GestureLifo)]; |
| 912 | }; |
| 913 | |
| 914 | struct ConsoleSixAxisSensorSharedMemoryFormat { |
| 915 | u64 mSamplingNumber; |
| 916 | bool mIsSevenSixAxisSensorAtRest; |
| 917 | u32 mVerticalizationError; |
| 918 | f32 mGyroBias[3]; |
| 919 | u8 padding[0x19e4]; |
| 920 | }; |
| 921 | |
| 922 | struct SharedMemoryFormat { |
| 923 | DebugPadSharedMemoryFormat mDebugPad; |
| 924 | TouchScreenSharedMemoryFormat mTouchScreen; |
| 925 | MouseSharedMemoryFormat mMouse; |
| 926 | KeyboardSharedMemoryFormat mKeyboard; |
| 927 | #if NN_SDK_VER < NN_MAKE_VER(10, 0, 0) |
| 928 | BasicXpadSharedMemoryFormat mBasicXpad; |
| 929 | #else |
| 930 | server::DigitizerSharedMemoryFormat mDigitizer; |
| 931 | #endif |
| 932 | HomeButtonSharedMemoryFormat mHomeButton; |
| 933 | SleepButtonSharedMemoryFormat mSleepButton; |
| 934 | CaptureButtonSharedMemoryFormat mCaptureButton; |
| 935 | InputDetectorSharedMemoryFormat mInputDetector; |
| 936 | #if NN_SDK_VER < NN_MAKE_VER(5, 0, 0) |
| 937 | UniquePadSharedMemoryFormat mUniquePad; |
| 938 | #else |
| 939 | u8 padding_5a00[sizeof(UniquePadSharedMemoryFormat)]; |
| 940 | #endif |
| 941 | NpadSharedMemoryFormat mNpad; |
| 942 | GestureSharedMemoryFormat mGesture; |
| 943 | #if NN_SDK_VER < NN_MAKE_VER(5, 0, 0) |
| 944 | u8 padding_3c200[sizeof(ConsoleSixAxisSensorSharedMemoryFormat)]; |
| 945 | #else |
| 946 | ConsoleSixAxisSensorSharedMemoryFormat mConsoleSixAxisSensor; |
| 947 | #endif |
| 948 | #if NN_SDK_VER >= NN_MAKE_VER(16, 0, 0) |
| 949 | MouseSharedMemoryFormat mDebugMouse; |
| 950 | #else |
| 951 | u8 padding_3dc00[sizeof(MouseSharedMemoryFormat)]; |
| 952 | #endif |
| 953 | u8 padding_3e000[0x2000]; |
| 954 | }; |
| 955 | |
| 956 | static_assert(sizeof(SharedMemoryFormat) == 0x40000); |
| 957 | |
| 958 | struct SharedMemoryType { |
| 959 | u8 padding[0x40]; |
| 960 | }; |
| 961 | |
| 962 | struct SharedMemoryHolder { |
| 963 | bool mIsOwner; |
| 964 | bool mIsCreated; |
| 965 | bool mIsMapped; |
| 966 | SharedMemoryType mSharedMemory; |
| 967 | SharedMemoryFormat* mAddress; |
| 968 | }; |
| 969 | |
| 970 | } // namespace detail |
| 971 | } // namespace hid |
| 972 | } // namespace nn |
| 973 | |