From d20a883194b02e3462b268c5257584c6354edc17 Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Tue, 16 Jan 2018 03:14:27 -0700 Subject: hid: Write to all layouts, implement circular buffers, set up controller metadata. --- src/core/hle/service/hid/hid.cpp | 103 ++++++++++++++++++++++++--------------- src/core/hle/service/hid/hid.h | 7 ++- 2 files changed, 71 insertions(+), 39 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 3c4259d27..81eceb027 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -65,44 +65,71 @@ private: if (is_device_reload_pending.exchange(false)) LoadInputDevices(); - // TODO(shinyquagsire23): This is a hack! - ControllerPadState& state = - mem->controllers[Controller_Handheld].layouts[Layout_Default].entries[0].buttons; - using namespace Settings::NativeButton; - state.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus()); - state.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus()); - state.x.Assign(buttons[X - BUTTON_HID_BEGIN]->GetStatus()); - state.y.Assign(buttons[Y - BUTTON_HID_BEGIN]->GetStatus()); - state.lstick.Assign(buttons[LStick - BUTTON_HID_BEGIN]->GetStatus()); - state.rstick.Assign(buttons[RStick - BUTTON_HID_BEGIN]->GetStatus()); - state.l.Assign(buttons[L - BUTTON_HID_BEGIN]->GetStatus()); - state.r.Assign(buttons[R - BUTTON_HID_BEGIN]->GetStatus()); - state.zl.Assign(buttons[ZL - BUTTON_HID_BEGIN]->GetStatus()); - state.zr.Assign(buttons[ZR - BUTTON_HID_BEGIN]->GetStatus()); - state.plus.Assign(buttons[Plus - BUTTON_HID_BEGIN]->GetStatus()); - state.minus.Assign(buttons[Minus - BUTTON_HID_BEGIN]->GetStatus()); - - state.dleft.Assign(buttons[DLeft - BUTTON_HID_BEGIN]->GetStatus()); - state.dup.Assign(buttons[DUp - BUTTON_HID_BEGIN]->GetStatus()); - state.dright.Assign(buttons[DRight - BUTTON_HID_BEGIN]->GetStatus()); - state.ddown.Assign(buttons[DDown - BUTTON_HID_BEGIN]->GetStatus()); - - state.lstick_left.Assign(buttons[LStick_Left - BUTTON_HID_BEGIN]->GetStatus()); - state.lstick_up.Assign(buttons[LStick_Up - BUTTON_HID_BEGIN]->GetStatus()); - state.lstick_right.Assign(buttons[LStick_Right - BUTTON_HID_BEGIN]->GetStatus()); - state.lstick_down.Assign(buttons[LStick_Down - BUTTON_HID_BEGIN]->GetStatus()); - - state.rstick_left.Assign(buttons[RStick_Left - BUTTON_HID_BEGIN]->GetStatus()); - state.rstick_up.Assign(buttons[RStick_Up - BUTTON_HID_BEGIN]->GetStatus()); - state.rstick_right.Assign(buttons[RStick_Right - BUTTON_HID_BEGIN]->GetStatus()); - state.rstick_down.Assign(buttons[RStick_Down - BUTTON_HID_BEGIN]->GetStatus()); - - state.sl.Assign(buttons[SL - BUTTON_HID_BEGIN]->GetStatus()); - state.sr.Assign(buttons[SR - BUTTON_HID_BEGIN]->GetStatus()); - - // TODO(shinyquagsire23): Analog stick vals - - // TODO(shinyquagsire23): Update pad info proper, (circular buffers, timestamps, layouts) + // Set up controllers as neon red+blue Joy-Con attached to console + ControllerHeader& controllerHeader = mem->controllers[Controller_Handheld].header; + controllerHeader.type = ControllerType_Handheld | ControllerType_JoyconPair; + controllerHeader.singleColorsDescriptor = ColorDesc_ColorsNonexistent; + controllerHeader.rightColorBody = 0xFF3C28; + controllerHeader.rightColorButtons = 0x1E0A0A; + controllerHeader.leftColorBody = 0x0AB9E6; + controllerHeader.leftColorButtons = 0x001E1E; + + for (int layoutIdx = 0; layoutIdx < HID_NUM_LAYOUTS; layoutIdx++) + { + ControllerLayout& layout = mem->controllers[Controller_Handheld].layouts[layoutIdx]; + layout.header.numEntries = HID_NUM_ENTRIES; + layout.header.maxEntryIndex = HID_NUM_ENTRIES - 1; + + // HID shared memory stores the state of the past 17 samples in a circlular buffer, + // each with a timestamp in number of samples since boot. + layout.header.timestampTicks = CoreTiming::GetTicks(); + layout.header.latestEntry = (layout.header.latestEntry + 1) % HID_NUM_ENTRIES; + + ControllerInputEntry& entry = layout.entries[layout.header.latestEntry]; + entry.connectionState = ConnectionState_Connected | ConnectionState_Wired; + entry.timestamp++; + entry.timestamp_2++; // TODO(shinyquagsire23): Is this always identical to timestamp? + + // TODO(shinyquagsire23): Set up some LUTs for each layout mapping in the future? + // For now everything is just the default handheld layout, but split Joy-Con will + // rotate the face buttons and directions for certain layouts. + ControllerPadState& state = entry.buttons; + using namespace Settings::NativeButton; + state.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus()); + state.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus()); + state.x.Assign(buttons[X - BUTTON_HID_BEGIN]->GetStatus()); + state.y.Assign(buttons[Y - BUTTON_HID_BEGIN]->GetStatus()); + state.lstick.Assign(buttons[LStick - BUTTON_HID_BEGIN]->GetStatus()); + state.rstick.Assign(buttons[RStick - BUTTON_HID_BEGIN]->GetStatus()); + state.l.Assign(buttons[L - BUTTON_HID_BEGIN]->GetStatus()); + state.r.Assign(buttons[R - BUTTON_HID_BEGIN]->GetStatus()); + state.zl.Assign(buttons[ZL - BUTTON_HID_BEGIN]->GetStatus()); + state.zr.Assign(buttons[ZR - BUTTON_HID_BEGIN]->GetStatus()); + state.plus.Assign(buttons[Plus - BUTTON_HID_BEGIN]->GetStatus()); + state.minus.Assign(buttons[Minus - BUTTON_HID_BEGIN]->GetStatus()); + + state.dleft.Assign(buttons[DLeft - BUTTON_HID_BEGIN]->GetStatus()); + state.dup.Assign(buttons[DUp - BUTTON_HID_BEGIN]->GetStatus()); + state.dright.Assign(buttons[DRight - BUTTON_HID_BEGIN]->GetStatus()); + state.ddown.Assign(buttons[DDown - BUTTON_HID_BEGIN]->GetStatus()); + + state.lstick_left.Assign(buttons[LStick_Left - BUTTON_HID_BEGIN]->GetStatus()); + state.lstick_up.Assign(buttons[LStick_Up - BUTTON_HID_BEGIN]->GetStatus()); + state.lstick_right.Assign(buttons[LStick_Right - BUTTON_HID_BEGIN]->GetStatus()); + state.lstick_down.Assign(buttons[LStick_Down - BUTTON_HID_BEGIN]->GetStatus()); + + state.rstick_left.Assign(buttons[RStick_Left - BUTTON_HID_BEGIN]->GetStatus()); + state.rstick_up.Assign(buttons[RStick_Up - BUTTON_HID_BEGIN]->GetStatus()); + state.rstick_right.Assign(buttons[RStick_Right - BUTTON_HID_BEGIN]->GetStatus()); + state.rstick_down.Assign(buttons[RStick_Down - BUTTON_HID_BEGIN]->GetStatus()); + + state.sl.Assign(buttons[SL - BUTTON_HID_BEGIN]->GetStatus()); + state.sr.Assign(buttons[SR - BUTTON_HID_BEGIN]->GetStatus()); + + // TODO(shinyquagsire23): Analog stick vals + + // TODO(shinyquagsire23): Update pad info proper, (circular buffers, timestamps, layouts) + } // TODO(shinyquagsire23): Update touch info diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 486e64800..dbffd3a74 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -12,6 +12,11 @@ namespace HID { // Begin enums and output structs +constexpr u32 HID_NUM_ENTRIES = 17; +constexpr u32 HID_NUM_LAYOUTS = 7; +constexpr s32 HID_JOYSTICK_MAX = 0x8000; +constexpr s32 HID_JOYSTICK_MIN = -0x8000; + enum ControllerType : u32 { ControllerType_ProController = 1 << 0, ControllerType_Handheld = 1 << 1, @@ -215,7 +220,7 @@ struct ControllerHeader { u32 leftColorBody; u32 leftColorButtons; u32 rightColorBody; - u32 rightColorbuttons; + u32 rightColorButtons; }; static_assert(sizeof(ControllerHeader) == 0x28, "HID controller header structure has incorrect size"); -- cgit v1.2.3 From 36b89787ce705cc74e0ba07c11dcbf3d7a704011 Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Tue, 16 Jan 2018 19:22:12 -0700 Subject: hid: Adjust for style guide --- src/core/hle/service/hid/hid.cpp | 26 +++++----- src/core/hle/service/hid/hid.h | 105 ++++++++++++++++++++------------------- 2 files changed, 68 insertions(+), 63 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 81eceb027..42e0f1e12 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -66,27 +66,27 @@ private: LoadInputDevices(); // Set up controllers as neon red+blue Joy-Con attached to console - ControllerHeader& controllerHeader = mem->controllers[Controller_Handheld].header; - controllerHeader.type = ControllerType_Handheld | ControllerType_JoyconPair; - controllerHeader.singleColorsDescriptor = ColorDesc_ColorsNonexistent; - controllerHeader.rightColorBody = 0xFF3C28; - controllerHeader.rightColorButtons = 0x1E0A0A; - controllerHeader.leftColorBody = 0x0AB9E6; - controllerHeader.leftColorButtons = 0x001E1E; + ControllerHeader& controller_header = mem->controllers[Controller_Handheld].header; + controller_header.type = ControllerType_Handheld | ControllerType_JoyconPair; + controller_header.single_colors_descriptor = ColorDesc_ColorsNonexistent; + controller_header.right_color_body = JOYCON_BODY_NEON_RED; + controller_header.right_color_buttons = JOYCON_BUTTONS_NEON_RED; + controller_header.left_color_body = JOYCON_BODY_NEON_BLUE; + controller_header.left_color_buttons = JOYCON_BUTTONS_NEON_BLUE; for (int layoutIdx = 0; layoutIdx < HID_NUM_LAYOUTS; layoutIdx++) { ControllerLayout& layout = mem->controllers[Controller_Handheld].layouts[layoutIdx]; - layout.header.numEntries = HID_NUM_ENTRIES; - layout.header.maxEntryIndex = HID_NUM_ENTRIES - 1; + layout.header.num_entries = HID_NUM_ENTRIES; + layout.header.max_entry_index = HID_NUM_ENTRIES - 1; // HID shared memory stores the state of the past 17 samples in a circlular buffer, // each with a timestamp in number of samples since boot. - layout.header.timestampTicks = CoreTiming::GetTicks(); - layout.header.latestEntry = (layout.header.latestEntry + 1) % HID_NUM_ENTRIES; + layout.header.timestamp_ticks = CoreTiming::GetTicks(); + layout.header.latest_entry = (layout.header.latest_entry + 1) % HID_NUM_ENTRIES; - ControllerInputEntry& entry = layout.entries[layout.header.latestEntry]; - entry.connectionState = ConnectionState_Connected | ConnectionState_Wired; + ControllerInputEntry& entry = layout.entries[layout.header.latest_entry]; + entry.connection_state = ConnectionState_Connected | ConnectionState_Wired; entry.timestamp++; entry.timestamp_2++; // TODO(shinyquagsire23): Is this always identical to timestamp? diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index dbffd3a74..3de9adb4b 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -17,6 +17,11 @@ constexpr u32 HID_NUM_LAYOUTS = 7; constexpr s32 HID_JOYSTICK_MAX = 0x8000; constexpr s32 HID_JOYSTICK_MIN = -0x8000; +constexpr u32 JOYCON_BODY_NEON_RED = 0xFF3C28; +constexpr u32 JOYCON_BUTTONS_NEON_RED = 0x1E0A0A; +constexpr u32 JOYCON_BODY_NEON_BLUE = 0x0AB9E6; +constexpr u32 JOYCON_BUTTONS_NEON_BLUE = 0x001E1E; + enum ControllerType : u32 { ControllerType_ProController = 1 << 0, ControllerType_Handheld = 1 << 1, @@ -62,10 +67,10 @@ enum ControllerID { // Begin TouchScreen struct TouchScreenHeader { - u64 timestampTicks; - u64 numEntries; - u64 latestEntry; - u64 maxEntryIndex; + u64 timestamp_ticks; + u64 num_entries; + u64 latest_entry; + u64 max_entry_index; u64 timestamp; }; static_assert(sizeof(TouchScreenHeader) == 0x28, @@ -73,7 +78,7 @@ static_assert(sizeof(TouchScreenHeader) == 0x28, struct TouchScreenEntryHeader { u64 timestamp; - u64 numTouches; + u64 num_touches; }; static_assert(sizeof(TouchScreenEntryHeader) == 0x10, "HID touch screen entry header structure has incorrect size"); @@ -81,11 +86,11 @@ static_assert(sizeof(TouchScreenEntryHeader) == 0x10, struct TouchScreenEntryTouch { u64 timestamp; u32 padding; - u32 touchIndex; + u32 touch_index; u32 x; u32 y; - u32 diameterX; - u32 diameterY; + u32 diameter_x; + u32 diameter_y; u32 angle; u32 padding_2; }; @@ -112,10 +117,10 @@ static_assert(sizeof(TouchScreen) == 0x3000, "HID touch screen structure has inc // Begin Mouse struct MouseHeader { - u64 timestampTicks; - u64 numEntries; - u64 latestEntry; - u64 maxEntryIndex; + u64 timestamp_ticks; + u64 num_entries; + u64 latest_entry; + u64 max_entry_index; }; static_assert(sizeof(MouseHeader) == 0x20, "HID mouse header structure has incorrect size"); @@ -137,10 +142,10 @@ struct MouseEntry { u64 timestamp_2; u32 x; u32 y; - u32 velocityX; - u32 velocityY; - u32 scrollVelocityX; - u32 scrollVelocityY; + u32 velocity_x; + u32 velocity_y; + u32 scroll_velocity_x; + u32 scroll_velocity_y; MouseButtonState buttons; }; static_assert(sizeof(MouseEntry) == 0x30, "HID mouse entry structure has incorrect size"); @@ -157,10 +162,10 @@ static_assert(sizeof(Mouse) == 0x400, "HID mouse structure has incorrect size"); // Begin Keyboard struct KeyboardHeader { - u64 timestampTicks; - u64 numEntries; - u64 latestEntry; - u64 maxEntryIndex; + u64 timestamp_ticks; + u64 num_entries; + u64 latest_entry; + u64 max_entry_index; }; static_assert(sizeof(KeyboardHeader) == 0x20, "HID keyboard header structure has incorrect size"); @@ -212,24 +217,24 @@ static_assert(sizeof(ControllerMAC) == 0x20, "HID controller MAC structure has i struct ControllerHeader { u32 type; - u32 isHalf; - u32 singleColorsDescriptor; - u32 singleColorBody; - u32 singleColorButtons; - u32 splitColorsDescriptor; - u32 leftColorBody; - u32 leftColorButtons; - u32 rightColorBody; - u32 rightColorButtons; + u32 is_half; + u32 single_colors_descriptor; + u32 single_color_body; + u32 single_color_buttons; + u32 split_colors_descriptor; + u32 left_color_body; + u32 left_color_buttons; + u32 right_color_body; + u32 right_color_buttons; }; static_assert(sizeof(ControllerHeader) == 0x28, "HID controller header structure has incorrect size"); struct ControllerLayoutHeader { - u64 timestampTicks; - u64 numEntries; - u64 latestEntry; - u64 maxEntryIndex; + u64 timestamp_ticks; + u64 num_entries; + u64 latest_entry; + u64 max_entry_index; }; static_assert(sizeof(ControllerLayoutHeader) == 0x20, "HID controller layout header structure has incorrect size"); @@ -279,11 +284,11 @@ struct ControllerInputEntry { u64 timestamp; u64 timestamp_2; ControllerPadState buttons; - u32 joystickLeftX; - u32 joystickLeftY; - u32 joystickRightX; - u32 joystickRightY; - u64 connectionState; + u32 joystick_left_x; + u32 joystick_left_y; + u32 joystick_right_x; + u32 joystick_right_y; + u64 connection_state; }; static_assert(sizeof(ControllerInputEntry) == 0x30, "HID controller input entry structure has incorrect size"); @@ -299,8 +304,8 @@ struct Controller { ControllerHeader header; std::array layouts; std::array unk_1; - ControllerMAC macLeft; - ControllerMAC macRight; + ControllerMAC mac_left; + ControllerMAC mac_right; std::array unk_2; }; static_assert(sizeof(Controller) == 0x5000, "HID controller structure has incorrect size"); @@ -312,17 +317,17 @@ struct SharedMemory { TouchScreen touchscreen; Mouse mouse; Keyboard keyboard; - std::array unkSection1; - std::array unkSection2; - std::array unkSection3; - std::array unkSection4; - std::array unkSection5; - std::array unkSection6; - std::array unkSection7; - std::array unkSection8; - std::array controllerSerials; + std::array unk_section_1; + std::array unk_section_2; + std::array unk_section_3; + std::array unk_section_4; + std::array unk_section_5; + std::array unk_section_6; + std::array unk_section_7; + std::array unk_section_8; + std::array controller_serials; std::array controllers; - std::array unkSection9; + std::array unk_section_9; }; static_assert(sizeof(SharedMemory) == 0x40000, "HID Shared Memory structure has incorrect size"); -- cgit v1.2.3 From eff90550a12f0edc696aedd055eea063634c24a1 Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Tue, 16 Jan 2018 19:22:58 -0700 Subject: hid: clang-format --- src/core/hle/service/hid/hid.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 42e0f1e12..6254237fa 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -74,8 +74,7 @@ private: controller_header.left_color_body = JOYCON_BODY_NEON_BLUE; controller_header.left_color_buttons = JOYCON_BUTTONS_NEON_BLUE; - for (int layoutIdx = 0; layoutIdx < HID_NUM_LAYOUTS; layoutIdx++) - { + for (int layoutIdx = 0; layoutIdx < HID_NUM_LAYOUTS; layoutIdx++) { ControllerLayout& layout = mem->controllers[Controller_Handheld].layouts[layoutIdx]; layout.header.num_entries = HID_NUM_ENTRIES; layout.header.max_entry_index = HID_NUM_ENTRIES - 1; @@ -128,7 +127,8 @@ private: // TODO(shinyquagsire23): Analog stick vals - // TODO(shinyquagsire23): Update pad info proper, (circular buffers, timestamps, layouts) + // TODO(shinyquagsire23): Update pad info proper, (circular buffers, timestamps, + // layouts) } // TODO(shinyquagsire23): Update touch info -- cgit v1.2.3