diff options
| author | 2018-01-16 21:54:46 -0500 | |
|---|---|---|
| committer | 2018-01-16 21:54:46 -0500 | |
| commit | dc905463dcbe12a7d472a97b38d17597ee59450e (patch) | |
| tree | 30731dccd6431d94c5a6fa8421a9ff4ec4c1259e /src | |
| parent | acc_u0: Add IPC interface and stub InitializeApplicationInfo. (diff) | |
| parent | hid: clang-format (diff) | |
| download | yuzu-dc905463dcbe12a7d472a97b38d17597ee59450e.tar.gz yuzu-dc905463dcbe12a7d472a97b38d17597ee59450e.tar.xz yuzu-dc905463dcbe12a7d472a97b38d17597ee59450e.zip | |
Merge pull request #34 from shinyquagsire23/hid-sharedmem-layouts-circbufs-meta
hid: Write to all layouts, implement circular buffers, set up controller metadata.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/hid/hid.cpp | 103 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid.h | 110 |
2 files changed, 125 insertions, 88 deletions
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 3c4259d27..6254237fa 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -65,44 +65,71 @@ private: | |||
| 65 | if (is_device_reload_pending.exchange(false)) | 65 | if (is_device_reload_pending.exchange(false)) |
| 66 | LoadInputDevices(); | 66 | LoadInputDevices(); |
| 67 | 67 | ||
| 68 | // TODO(shinyquagsire23): This is a hack! | 68 | // Set up controllers as neon red+blue Joy-Con attached to console |
| 69 | ControllerPadState& state = | 69 | ControllerHeader& controller_header = mem->controllers[Controller_Handheld].header; |
| 70 | mem->controllers[Controller_Handheld].layouts[Layout_Default].entries[0].buttons; | 70 | controller_header.type = ControllerType_Handheld | ControllerType_JoyconPair; |
| 71 | using namespace Settings::NativeButton; | 71 | controller_header.single_colors_descriptor = ColorDesc_ColorsNonexistent; |
| 72 | state.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus()); | 72 | controller_header.right_color_body = JOYCON_BODY_NEON_RED; |
| 73 | state.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus()); | 73 | controller_header.right_color_buttons = JOYCON_BUTTONS_NEON_RED; |
| 74 | state.x.Assign(buttons[X - BUTTON_HID_BEGIN]->GetStatus()); | 74 | controller_header.left_color_body = JOYCON_BODY_NEON_BLUE; |
| 75 | state.y.Assign(buttons[Y - BUTTON_HID_BEGIN]->GetStatus()); | 75 | controller_header.left_color_buttons = JOYCON_BUTTONS_NEON_BLUE; |
| 76 | state.lstick.Assign(buttons[LStick - BUTTON_HID_BEGIN]->GetStatus()); | 76 | |
| 77 | state.rstick.Assign(buttons[RStick - BUTTON_HID_BEGIN]->GetStatus()); | 77 | for (int layoutIdx = 0; layoutIdx < HID_NUM_LAYOUTS; layoutIdx++) { |
| 78 | state.l.Assign(buttons[L - BUTTON_HID_BEGIN]->GetStatus()); | 78 | ControllerLayout& layout = mem->controllers[Controller_Handheld].layouts[layoutIdx]; |
| 79 | state.r.Assign(buttons[R - BUTTON_HID_BEGIN]->GetStatus()); | 79 | layout.header.num_entries = HID_NUM_ENTRIES; |
| 80 | state.zl.Assign(buttons[ZL - BUTTON_HID_BEGIN]->GetStatus()); | 80 | layout.header.max_entry_index = HID_NUM_ENTRIES - 1; |
| 81 | state.zr.Assign(buttons[ZR - BUTTON_HID_BEGIN]->GetStatus()); | 81 | |
| 82 | state.plus.Assign(buttons[Plus - BUTTON_HID_BEGIN]->GetStatus()); | 82 | // HID shared memory stores the state of the past 17 samples in a circlular buffer, |
| 83 | state.minus.Assign(buttons[Minus - BUTTON_HID_BEGIN]->GetStatus()); | 83 | // each with a timestamp in number of samples since boot. |
| 84 | 84 | layout.header.timestamp_ticks = CoreTiming::GetTicks(); | |
| 85 | state.dleft.Assign(buttons[DLeft - BUTTON_HID_BEGIN]->GetStatus()); | 85 | layout.header.latest_entry = (layout.header.latest_entry + 1) % HID_NUM_ENTRIES; |
| 86 | state.dup.Assign(buttons[DUp - BUTTON_HID_BEGIN]->GetStatus()); | 86 | |
| 87 | state.dright.Assign(buttons[DRight - BUTTON_HID_BEGIN]->GetStatus()); | 87 | ControllerInputEntry& entry = layout.entries[layout.header.latest_entry]; |
| 88 | state.ddown.Assign(buttons[DDown - BUTTON_HID_BEGIN]->GetStatus()); | 88 | entry.connection_state = ConnectionState_Connected | ConnectionState_Wired; |
| 89 | 89 | entry.timestamp++; | |
| 90 | state.lstick_left.Assign(buttons[LStick_Left - BUTTON_HID_BEGIN]->GetStatus()); | 90 | entry.timestamp_2++; // TODO(shinyquagsire23): Is this always identical to timestamp? |
| 91 | state.lstick_up.Assign(buttons[LStick_Up - BUTTON_HID_BEGIN]->GetStatus()); | 91 | |
| 92 | state.lstick_right.Assign(buttons[LStick_Right - BUTTON_HID_BEGIN]->GetStatus()); | 92 | // TODO(shinyquagsire23): Set up some LUTs for each layout mapping in the future? |
| 93 | state.lstick_down.Assign(buttons[LStick_Down - BUTTON_HID_BEGIN]->GetStatus()); | 93 | // For now everything is just the default handheld layout, but split Joy-Con will |
| 94 | 94 | // rotate the face buttons and directions for certain layouts. | |
| 95 | state.rstick_left.Assign(buttons[RStick_Left - BUTTON_HID_BEGIN]->GetStatus()); | 95 | ControllerPadState& state = entry.buttons; |
| 96 | state.rstick_up.Assign(buttons[RStick_Up - BUTTON_HID_BEGIN]->GetStatus()); | 96 | using namespace Settings::NativeButton; |
| 97 | state.rstick_right.Assign(buttons[RStick_Right - BUTTON_HID_BEGIN]->GetStatus()); | 97 | state.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus()); |
| 98 | state.rstick_down.Assign(buttons[RStick_Down - BUTTON_HID_BEGIN]->GetStatus()); | 98 | state.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus()); |
| 99 | 99 | state.x.Assign(buttons[X - BUTTON_HID_BEGIN]->GetStatus()); | |
| 100 | state.sl.Assign(buttons[SL - BUTTON_HID_BEGIN]->GetStatus()); | 100 | state.y.Assign(buttons[Y - BUTTON_HID_BEGIN]->GetStatus()); |
| 101 | state.sr.Assign(buttons[SR - BUTTON_HID_BEGIN]->GetStatus()); | 101 | state.lstick.Assign(buttons[LStick - BUTTON_HID_BEGIN]->GetStatus()); |
| 102 | 102 | state.rstick.Assign(buttons[RStick - BUTTON_HID_BEGIN]->GetStatus()); | |
| 103 | // TODO(shinyquagsire23): Analog stick vals | 103 | state.l.Assign(buttons[L - BUTTON_HID_BEGIN]->GetStatus()); |
| 104 | 104 | state.r.Assign(buttons[R - BUTTON_HID_BEGIN]->GetStatus()); | |
| 105 | // TODO(shinyquagsire23): Update pad info proper, (circular buffers, timestamps, layouts) | 105 | state.zl.Assign(buttons[ZL - BUTTON_HID_BEGIN]->GetStatus()); |
| 106 | state.zr.Assign(buttons[ZR - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 107 | state.plus.Assign(buttons[Plus - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 108 | state.minus.Assign(buttons[Minus - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 109 | |||
| 110 | state.dleft.Assign(buttons[DLeft - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 111 | state.dup.Assign(buttons[DUp - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 112 | state.dright.Assign(buttons[DRight - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 113 | state.ddown.Assign(buttons[DDown - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 114 | |||
| 115 | state.lstick_left.Assign(buttons[LStick_Left - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 116 | state.lstick_up.Assign(buttons[LStick_Up - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 117 | state.lstick_right.Assign(buttons[LStick_Right - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 118 | state.lstick_down.Assign(buttons[LStick_Down - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 119 | |||
| 120 | state.rstick_left.Assign(buttons[RStick_Left - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 121 | state.rstick_up.Assign(buttons[RStick_Up - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 122 | state.rstick_right.Assign(buttons[RStick_Right - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 123 | state.rstick_down.Assign(buttons[RStick_Down - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 124 | |||
| 125 | state.sl.Assign(buttons[SL - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 126 | state.sr.Assign(buttons[SR - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 127 | |||
| 128 | // TODO(shinyquagsire23): Analog stick vals | ||
| 129 | |||
| 130 | // TODO(shinyquagsire23): Update pad info proper, (circular buffers, timestamps, | ||
| 131 | // layouts) | ||
| 132 | } | ||
| 106 | 133 | ||
| 107 | // TODO(shinyquagsire23): Update touch info | 134 | // TODO(shinyquagsire23): Update touch info |
| 108 | 135 | ||
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 486e64800..3de9adb4b 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h | |||
| @@ -12,6 +12,16 @@ namespace HID { | |||
| 12 | 12 | ||
| 13 | // Begin enums and output structs | 13 | // Begin enums and output structs |
| 14 | 14 | ||
| 15 | constexpr u32 HID_NUM_ENTRIES = 17; | ||
| 16 | constexpr u32 HID_NUM_LAYOUTS = 7; | ||
| 17 | constexpr s32 HID_JOYSTICK_MAX = 0x8000; | ||
| 18 | constexpr s32 HID_JOYSTICK_MIN = -0x8000; | ||
| 19 | |||
| 20 | constexpr u32 JOYCON_BODY_NEON_RED = 0xFF3C28; | ||
| 21 | constexpr u32 JOYCON_BUTTONS_NEON_RED = 0x1E0A0A; | ||
| 22 | constexpr u32 JOYCON_BODY_NEON_BLUE = 0x0AB9E6; | ||
| 23 | constexpr u32 JOYCON_BUTTONS_NEON_BLUE = 0x001E1E; | ||
| 24 | |||
| 15 | enum ControllerType : u32 { | 25 | enum ControllerType : u32 { |
| 16 | ControllerType_ProController = 1 << 0, | 26 | ControllerType_ProController = 1 << 0, |
| 17 | ControllerType_Handheld = 1 << 1, | 27 | ControllerType_Handheld = 1 << 1, |
| @@ -57,10 +67,10 @@ enum ControllerID { | |||
| 57 | // Begin TouchScreen | 67 | // Begin TouchScreen |
| 58 | 68 | ||
| 59 | struct TouchScreenHeader { | 69 | struct TouchScreenHeader { |
| 60 | u64 timestampTicks; | 70 | u64 timestamp_ticks; |
| 61 | u64 numEntries; | 71 | u64 num_entries; |
| 62 | u64 latestEntry; | 72 | u64 latest_entry; |
| 63 | u64 maxEntryIndex; | 73 | u64 max_entry_index; |
| 64 | u64 timestamp; | 74 | u64 timestamp; |
| 65 | }; | 75 | }; |
| 66 | static_assert(sizeof(TouchScreenHeader) == 0x28, | 76 | static_assert(sizeof(TouchScreenHeader) == 0x28, |
| @@ -68,7 +78,7 @@ static_assert(sizeof(TouchScreenHeader) == 0x28, | |||
| 68 | 78 | ||
| 69 | struct TouchScreenEntryHeader { | 79 | struct TouchScreenEntryHeader { |
| 70 | u64 timestamp; | 80 | u64 timestamp; |
| 71 | u64 numTouches; | 81 | u64 num_touches; |
| 72 | }; | 82 | }; |
| 73 | static_assert(sizeof(TouchScreenEntryHeader) == 0x10, | 83 | static_assert(sizeof(TouchScreenEntryHeader) == 0x10, |
| 74 | "HID touch screen entry header structure has incorrect size"); | 84 | "HID touch screen entry header structure has incorrect size"); |
| @@ -76,11 +86,11 @@ static_assert(sizeof(TouchScreenEntryHeader) == 0x10, | |||
| 76 | struct TouchScreenEntryTouch { | 86 | struct TouchScreenEntryTouch { |
| 77 | u64 timestamp; | 87 | u64 timestamp; |
| 78 | u32 padding; | 88 | u32 padding; |
| 79 | u32 touchIndex; | 89 | u32 touch_index; |
| 80 | u32 x; | 90 | u32 x; |
| 81 | u32 y; | 91 | u32 y; |
| 82 | u32 diameterX; | 92 | u32 diameter_x; |
| 83 | u32 diameterY; | 93 | u32 diameter_y; |
| 84 | u32 angle; | 94 | u32 angle; |
| 85 | u32 padding_2; | 95 | u32 padding_2; |
| 86 | }; | 96 | }; |
| @@ -107,10 +117,10 @@ static_assert(sizeof(TouchScreen) == 0x3000, "HID touch screen structure has inc | |||
| 107 | // Begin Mouse | 117 | // Begin Mouse |
| 108 | 118 | ||
| 109 | struct MouseHeader { | 119 | struct MouseHeader { |
| 110 | u64 timestampTicks; | 120 | u64 timestamp_ticks; |
| 111 | u64 numEntries; | 121 | u64 num_entries; |
| 112 | u64 latestEntry; | 122 | u64 latest_entry; |
| 113 | u64 maxEntryIndex; | 123 | u64 max_entry_index; |
| 114 | }; | 124 | }; |
| 115 | static_assert(sizeof(MouseHeader) == 0x20, "HID mouse header structure has incorrect size"); | 125 | static_assert(sizeof(MouseHeader) == 0x20, "HID mouse header structure has incorrect size"); |
| 116 | 126 | ||
| @@ -132,10 +142,10 @@ struct MouseEntry { | |||
| 132 | u64 timestamp_2; | 142 | u64 timestamp_2; |
| 133 | u32 x; | 143 | u32 x; |
| 134 | u32 y; | 144 | u32 y; |
| 135 | u32 velocityX; | 145 | u32 velocity_x; |
| 136 | u32 velocityY; | 146 | u32 velocity_y; |
| 137 | u32 scrollVelocityX; | 147 | u32 scroll_velocity_x; |
| 138 | u32 scrollVelocityY; | 148 | u32 scroll_velocity_y; |
| 139 | MouseButtonState buttons; | 149 | MouseButtonState buttons; |
| 140 | }; | 150 | }; |
| 141 | static_assert(sizeof(MouseEntry) == 0x30, "HID mouse entry structure has incorrect size"); | 151 | static_assert(sizeof(MouseEntry) == 0x30, "HID mouse entry structure has incorrect size"); |
| @@ -152,10 +162,10 @@ static_assert(sizeof(Mouse) == 0x400, "HID mouse structure has incorrect size"); | |||
| 152 | // Begin Keyboard | 162 | // Begin Keyboard |
| 153 | 163 | ||
| 154 | struct KeyboardHeader { | 164 | struct KeyboardHeader { |
| 155 | u64 timestampTicks; | 165 | u64 timestamp_ticks; |
| 156 | u64 numEntries; | 166 | u64 num_entries; |
| 157 | u64 latestEntry; | 167 | u64 latest_entry; |
| 158 | u64 maxEntryIndex; | 168 | u64 max_entry_index; |
| 159 | }; | 169 | }; |
| 160 | static_assert(sizeof(KeyboardHeader) == 0x20, "HID keyboard header structure has incorrect size"); | 170 | static_assert(sizeof(KeyboardHeader) == 0x20, "HID keyboard header structure has incorrect size"); |
| 161 | 171 | ||
| @@ -207,24 +217,24 @@ static_assert(sizeof(ControllerMAC) == 0x20, "HID controller MAC structure has i | |||
| 207 | 217 | ||
| 208 | struct ControllerHeader { | 218 | struct ControllerHeader { |
| 209 | u32 type; | 219 | u32 type; |
| 210 | u32 isHalf; | 220 | u32 is_half; |
| 211 | u32 singleColorsDescriptor; | 221 | u32 single_colors_descriptor; |
| 212 | u32 singleColorBody; | 222 | u32 single_color_body; |
| 213 | u32 singleColorButtons; | 223 | u32 single_color_buttons; |
| 214 | u32 splitColorsDescriptor; | 224 | u32 split_colors_descriptor; |
| 215 | u32 leftColorBody; | 225 | u32 left_color_body; |
| 216 | u32 leftColorButtons; | 226 | u32 left_color_buttons; |
| 217 | u32 rightColorBody; | 227 | u32 right_color_body; |
| 218 | u32 rightColorbuttons; | 228 | u32 right_color_buttons; |
| 219 | }; | 229 | }; |
| 220 | static_assert(sizeof(ControllerHeader) == 0x28, | 230 | static_assert(sizeof(ControllerHeader) == 0x28, |
| 221 | "HID controller header structure has incorrect size"); | 231 | "HID controller header structure has incorrect size"); |
| 222 | 232 | ||
| 223 | struct ControllerLayoutHeader { | 233 | struct ControllerLayoutHeader { |
| 224 | u64 timestampTicks; | 234 | u64 timestamp_ticks; |
| 225 | u64 numEntries; | 235 | u64 num_entries; |
| 226 | u64 latestEntry; | 236 | u64 latest_entry; |
| 227 | u64 maxEntryIndex; | 237 | u64 max_entry_index; |
| 228 | }; | 238 | }; |
| 229 | static_assert(sizeof(ControllerLayoutHeader) == 0x20, | 239 | static_assert(sizeof(ControllerLayoutHeader) == 0x20, |
| 230 | "HID controller layout header structure has incorrect size"); | 240 | "HID controller layout header structure has incorrect size"); |
| @@ -274,11 +284,11 @@ struct ControllerInputEntry { | |||
| 274 | u64 timestamp; | 284 | u64 timestamp; |
| 275 | u64 timestamp_2; | 285 | u64 timestamp_2; |
| 276 | ControllerPadState buttons; | 286 | ControllerPadState buttons; |
| 277 | u32 joystickLeftX; | 287 | u32 joystick_left_x; |
| 278 | u32 joystickLeftY; | 288 | u32 joystick_left_y; |
| 279 | u32 joystickRightX; | 289 | u32 joystick_right_x; |
| 280 | u32 joystickRightY; | 290 | u32 joystick_right_y; |
| 281 | u64 connectionState; | 291 | u64 connection_state; |
| 282 | }; | 292 | }; |
| 283 | static_assert(sizeof(ControllerInputEntry) == 0x30, | 293 | static_assert(sizeof(ControllerInputEntry) == 0x30, |
| 284 | "HID controller input entry structure has incorrect size"); | 294 | "HID controller input entry structure has incorrect size"); |
| @@ -294,8 +304,8 @@ struct Controller { | |||
| 294 | ControllerHeader header; | 304 | ControllerHeader header; |
| 295 | std::array<ControllerLayout, 7> layouts; | 305 | std::array<ControllerLayout, 7> layouts; |
| 296 | std::array<u8, 0x2a70> unk_1; | 306 | std::array<u8, 0x2a70> unk_1; |
| 297 | ControllerMAC macLeft; | 307 | ControllerMAC mac_left; |
| 298 | ControllerMAC macRight; | 308 | ControllerMAC mac_right; |
| 299 | std::array<u8, 0xdf8> unk_2; | 309 | std::array<u8, 0xdf8> unk_2; |
| 300 | }; | 310 | }; |
| 301 | static_assert(sizeof(Controller) == 0x5000, "HID controller structure has incorrect size"); | 311 | static_assert(sizeof(Controller) == 0x5000, "HID controller structure has incorrect size"); |
| @@ -307,17 +317,17 @@ struct SharedMemory { | |||
| 307 | TouchScreen touchscreen; | 317 | TouchScreen touchscreen; |
| 308 | Mouse mouse; | 318 | Mouse mouse; |
| 309 | Keyboard keyboard; | 319 | Keyboard keyboard; |
| 310 | std::array<u8, 0x400> unkSection1; | 320 | std::array<u8, 0x400> unk_section_1; |
| 311 | std::array<u8, 0x400> unkSection2; | 321 | std::array<u8, 0x400> unk_section_2; |
| 312 | std::array<u8, 0x400> unkSection3; | 322 | std::array<u8, 0x400> unk_section_3; |
| 313 | std::array<u8, 0x400> unkSection4; | 323 | std::array<u8, 0x400> unk_section_4; |
| 314 | std::array<u8, 0x200> unkSection5; | 324 | std::array<u8, 0x200> unk_section_5; |
| 315 | std::array<u8, 0x200> unkSection6; | 325 | std::array<u8, 0x200> unk_section_6; |
| 316 | std::array<u8, 0x200> unkSection7; | 326 | std::array<u8, 0x200> unk_section_7; |
| 317 | std::array<u8, 0x800> unkSection8; | 327 | std::array<u8, 0x800> unk_section_8; |
| 318 | std::array<u8, 0x4000> controllerSerials; | 328 | std::array<u8, 0x4000> controller_serials; |
| 319 | std::array<Controller, 10> controllers; | 329 | std::array<Controller, 10> controllers; |
| 320 | std::array<u8, 0x4600> unkSection9; | 330 | std::array<u8, 0x4600> unk_section_9; |
| 321 | }; | 331 | }; |
| 322 | static_assert(sizeof(SharedMemory) == 0x40000, "HID Shared Memory structure has incorrect size"); | 332 | static_assert(sizeof(SharedMemory) == 0x40000, "HID Shared Memory structure has incorrect size"); |
| 323 | 333 | ||