hid.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include "core/hle/kernel/kernel.h"
  7. #include "common/bit_field.h"
  8. namespace Service {
  9. namespace HID {
  10. // Handle to shared memory region designated to HID_User service
  11. extern Handle g_shared_mem;
  12. // Event handles
  13. extern Handle g_event_pad_or_touch_1;
  14. extern Handle g_event_pad_or_touch_2;
  15. extern Handle g_event_accelerometer;
  16. extern Handle g_event_gyroscope;
  17. extern Handle g_event_debug_pad;
  18. /**
  19. * Structure of a Pad controller state.
  20. */
  21. struct PadState {
  22. union {
  23. u32 hex;
  24. BitField<0, 1, u32> a;
  25. BitField<1, 1, u32> b;
  26. BitField<2, 1, u32> select;
  27. BitField<3, 1, u32> start;
  28. BitField<4, 1, u32> right;
  29. BitField<5, 1, u32> left;
  30. BitField<6, 1, u32> up;
  31. BitField<7, 1, u32> down;
  32. BitField<8, 1, u32> r;
  33. BitField<9, 1, u32> l;
  34. BitField<10, 1, u32> x;
  35. BitField<11, 1, u32> y;
  36. BitField<28, 1, u32> circle_right;
  37. BitField<29, 1, u32> circle_left;
  38. BitField<30, 1, u32> circle_up;
  39. BitField<31, 1, u32> circle_down;
  40. };
  41. };
  42. /**
  43. * Structure of a single entry in the PadData's Pad state history array.
  44. */
  45. struct PadDataEntry {
  46. PadState current_state;
  47. PadState delta_additions;
  48. PadState delta_removals;
  49. s16 circle_pad_x;
  50. s16 circle_pad_y;
  51. };
  52. /**
  53. * Structure of all data related to the 3DS Pad.
  54. */
  55. struct PadData {
  56. s64 index_reset_ticks;
  57. s64 index_reset_ticks_previous;
  58. u32 index; // the index of the last updated Pad state history element
  59. u32 pad1;
  60. u32 pad2;
  61. PadState current_state; // same as entries[index].current_state
  62. u32 raw_circle_pad_data;
  63. u32 pad3;
  64. std::array<PadDataEntry, 8> entries; // Pad state history
  65. };
  66. // Pre-defined PadStates for single button presses
  67. const PadState PAD_NONE = {{0}};
  68. const PadState PAD_A = {{1u << 0}};
  69. const PadState PAD_B = {{1u << 1}};
  70. const PadState PAD_SELECT = {{1u << 2}};
  71. const PadState PAD_START = {{1u << 3}};
  72. const PadState PAD_RIGHT = {{1u << 4}};
  73. const PadState PAD_LEFT = {{1u << 5}};
  74. const PadState PAD_UP = {{1u << 6}};
  75. const PadState PAD_DOWN = {{1u << 7}};
  76. const PadState PAD_R = {{1u << 8}};
  77. const PadState PAD_L = {{1u << 9}};
  78. const PadState PAD_X = {{1u << 10}};
  79. const PadState PAD_Y = {{1u << 11}};
  80. const PadState PAD_CIRCLE_RIGHT = {{1u << 28}};
  81. const PadState PAD_CIRCLE_LEFT = {{1u << 29}};
  82. const PadState PAD_CIRCLE_UP = {{1u << 30}};
  83. const PadState PAD_CIRCLE_DOWN = {{1u << 31}};
  84. // Methods for updating the HID module's state
  85. void PadButtonPress(const PadState& pad_state);
  86. void PadButtonRelease(const PadState& pad_state);
  87. void PadUpdateComplete();
  88. void HIDInit();
  89. void HIDShutdown();
  90. }
  91. }