hid_user.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "core/hle/service/service.h"
  6. #include "common/bit_field.h"
  7. ////////////////////////////////////////////////////////////////////////////////////////////////////
  8. // Namespace HID_User
  9. // This service is used for interfacing to physical user controls.
  10. // Uses include game pad controls, touchscreen, accelerometers, gyroscopes, and debug pad.
  11. namespace HID_User {
  12. /**
  13. * Structure of a Pad controller state.
  14. */
  15. struct PadState {
  16. union {
  17. u32 hex;
  18. BitField<0, 1, u32> a;
  19. BitField<1, 1, u32> b;
  20. BitField<2, 1, u32> select;
  21. BitField<3, 1, u32> start;
  22. BitField<4, 1, u32> right;
  23. BitField<5, 1, u32> left;
  24. BitField<6, 1, u32> up;
  25. BitField<7, 1, u32> down;
  26. BitField<8, 1, u32> r;
  27. BitField<9, 1, u32> l;
  28. BitField<10, 1, u32> x;
  29. BitField<11, 1, u32> y;
  30. BitField<28, 1, u32> circle_right;
  31. BitField<29, 1, u32> circle_left;
  32. BitField<30, 1, u32> circle_up;
  33. BitField<31, 1, u32> circle_down;
  34. };
  35. };
  36. /**
  37. * Structure of a single entry in the PadData's Pad state history array.
  38. */
  39. struct PadDataEntry {
  40. PadState current_state;
  41. PadState delta_additions;
  42. PadState delta_removals;
  43. s16 circle_pad_x;
  44. s16 circle_pad_y;
  45. };
  46. /**
  47. * Structure of all data related to the 3DS Pad.
  48. */
  49. struct PadData {
  50. s64 index_reset_ticks;
  51. s64 index_reset_ticks_previous;
  52. u32 index; // the index of the last updated Pad state history element
  53. u32 pad1;
  54. u32 pad2;
  55. PadState current_state; // same as entries[index].current_state
  56. u32 raw_circle_pad_data;
  57. u32 pad3;
  58. std::array<PadDataEntry, 8> entries; // Pad state history
  59. };
  60. // Pre-defined PadStates for single button presses
  61. const PadState PAD_NONE = {{0}};
  62. const PadState PAD_A = {{1u << 0}};
  63. const PadState PAD_B = {{1u << 1}};
  64. const PadState PAD_SELECT = {{1u << 2}};
  65. const PadState PAD_START = {{1u << 3}};
  66. const PadState PAD_RIGHT = {{1u << 4}};
  67. const PadState PAD_LEFT = {{1u << 5}};
  68. const PadState PAD_UP = {{1u << 6}};
  69. const PadState PAD_DOWN = {{1u << 7}};
  70. const PadState PAD_R = {{1u << 8}};
  71. const PadState PAD_L = {{1u << 9}};
  72. const PadState PAD_X = {{1u << 10}};
  73. const PadState PAD_Y = {{1u << 11}};
  74. const PadState PAD_CIRCLE_RIGHT = {{1u << 28}};
  75. const PadState PAD_CIRCLE_LEFT = {{1u << 29}};
  76. const PadState PAD_CIRCLE_UP = {{1u << 30}};
  77. const PadState PAD_CIRCLE_DOWN = {{1u << 31}};
  78. // Methods for updating the HID module's state
  79. void PadButtonPress(PadState pad_state);
  80. void PadButtonRelease(PadState pad_state);
  81. void PadUpdateComplete();
  82. /**
  83. * HID service interface.
  84. */
  85. class Interface : public Service::Interface {
  86. public:
  87. Interface();
  88. ~Interface();
  89. /**
  90. * Gets the string port name used by CTROS for the service
  91. * @return Port name of service
  92. */
  93. std::string GetPortName() const override {
  94. return "hid:USER";
  95. }
  96. };
  97. } // namespace