From 9a9e81f2e9b93d0028654c7ee50e9ebacee0e5d6 Mon Sep 17 00:00:00 2001 From: german Date: Sun, 10 Jan 2021 13:47:56 -0600 Subject: [PATCH] Fix npad struct to match switchbrew --- .../hle/service/am/applets/controller.cpp | 2 +- src/core/hle/service/hid/controllers/npad.cpp | 129 +++++++++--------- src/core/hle/service/hid/controllers/npad.h | 108 +++++++++------ .../configuration/configure_input_player.cpp | 2 +- 4 files changed, 135 insertions(+), 106 deletions(-) diff --git a/src/core/hle/service/am/applets/controller.cpp b/src/core/hle/service/am/applets/controller.cpp index 7edfca64e0..d7d3ee99ad 100644 --- a/src/core/hle/service/am/applets/controller.cpp +++ b/src/core/hle/service/am/applets/controller.cpp @@ -37,7 +37,7 @@ static Core::Frontend::ControllerParameters ConvertToFrontendParameters( .border_colors = std::move(identification_colors), .enable_explain_text = enable_text, .explain_text = std::move(text), - .allow_pro_controller = npad_style_set.pro_controller == 1, + .allow_pro_controller = npad_style_set.fullkey == 1, .allow_handheld = npad_style_set.handheld == 1, .allow_dual_joycons = npad_style_set.joycon_dual == 1, .allow_left_joycon = npad_style_set.joycon_left == 1, diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 251db1f84a..5d91e6fc18 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -156,76 +156,77 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) { styleset_changed_events[controller_idx].writable->Signal(); return; } - controller.joy_styles.raw = 0; // Zero out + controller.style_set.raw = 0; // Zero out controller.device_type.raw = 0; - controller.properties.raw = 0; + controller.system_properties.raw = 0; switch (controller_type) { case NPadControllerType::None: UNREACHABLE(); break; case NPadControllerType::ProController: - controller.joy_styles.pro_controller.Assign(1); - controller.device_type.pro_controller.Assign(1); - controller.properties.is_vertical.Assign(1); - controller.properties.use_plus.Assign(1); - controller.properties.use_minus.Assign(1); - controller.pad_assignment = NpadAssignments::Single; + controller.style_set.fullkey.Assign(1); + controller.device_type.fullkey.Assign(1); + controller.system_properties.is_vertical.Assign(1); + controller.system_properties.use_plus.Assign(1); + controller.system_properties.use_minus.Assign(1); + controller.assignment_mode = NpadAssignments::Single; break; case NPadControllerType::Handheld: - controller.joy_styles.handheld.Assign(1); - controller.device_type.handheld.Assign(1); - controller.properties.is_vertical.Assign(1); - controller.properties.use_plus.Assign(1); - controller.properties.use_minus.Assign(1); - controller.pad_assignment = NpadAssignments::Dual; + controller.style_set.handheld.Assign(1); + controller.device_type.handheld_left.Assign(1); + controller.device_type.handheld_right.Assign(1); + controller.system_properties.is_vertical.Assign(1); + controller.system_properties.use_plus.Assign(1); + controller.system_properties.use_minus.Assign(1); + controller.assignment_mode = NpadAssignments::Dual; break; case NPadControllerType::JoyDual: - controller.joy_styles.joycon_dual.Assign(1); + controller.style_set.joycon_dual.Assign(1); controller.device_type.joycon_left.Assign(1); controller.device_type.joycon_right.Assign(1); - controller.properties.is_vertical.Assign(1); - controller.properties.use_plus.Assign(1); - controller.properties.use_minus.Assign(1); - controller.pad_assignment = NpadAssignments::Dual; + controller.system_properties.is_vertical.Assign(1); + controller.system_properties.use_plus.Assign(1); + controller.system_properties.use_minus.Assign(1); + controller.assignment_mode = NpadAssignments::Dual; break; case NPadControllerType::JoyLeft: - controller.joy_styles.joycon_left.Assign(1); + controller.style_set.joycon_left.Assign(1); controller.device_type.joycon_left.Assign(1); - controller.properties.is_horizontal.Assign(1); - controller.properties.use_minus.Assign(1); - controller.pad_assignment = NpadAssignments::Single; + controller.system_properties.is_horizontal.Assign(1); + controller.system_properties.use_minus.Assign(1); + controller.assignment_mode = NpadAssignments::Single; break; case NPadControllerType::JoyRight: - controller.joy_styles.joycon_right.Assign(1); + controller.style_set.joycon_right.Assign(1); controller.device_type.joycon_right.Assign(1); - controller.properties.is_horizontal.Assign(1); - controller.properties.use_plus.Assign(1); - controller.pad_assignment = NpadAssignments::Single; + controller.system_properties.is_horizontal.Assign(1); + controller.system_properties.use_plus.Assign(1); + controller.assignment_mode = NpadAssignments::Single; break; case NPadControllerType::Pokeball: - controller.joy_styles.pokeball.Assign(1); - controller.device_type.pokeball.Assign(1); - controller.pad_assignment = NpadAssignments::Single; + controller.style_set.palma.Assign(1); + controller.device_type.palma.Assign(1); + controller.assignment_mode = NpadAssignments::Single; break; } - controller.single_color_error = ColorReadError::ReadOk; - controller.single_color.body_color = 0; - controller.single_color.button_color = 0; + controller.fullkey_color.attribute = ColorAttributes::Ok; + controller.fullkey_color.fullkey.body = 0; + controller.fullkey_color.fullkey.button = 0; - controller.dual_color_error = ColorReadError::ReadOk; - controller.left_color.body_color = + controller.joycon_color.attribute = ColorAttributes::Ok; + controller.joycon_color.left.body = Settings::values.players.GetValue()[controller_idx].body_color_left; - controller.left_color.button_color = + controller.joycon_color.left.button = Settings::values.players.GetValue()[controller_idx].button_color_left; - controller.right_color.body_color = + controller.joycon_color.right.body = Settings::values.players.GetValue()[controller_idx].body_color_right; - controller.right_color.button_color = + controller.joycon_color.right.button = Settings::values.players.GetValue()[controller_idx].button_color_right; - controller.battery_level[0] = BATTERY_FULL; - controller.battery_level[1] = BATTERY_FULL; - controller.battery_level[2] = BATTERY_FULL; + controller.battery_level_dual = BATTERY_FULL; + controller.battery_level_left = BATTERY_FULL; + controller.battery_level_right = BATTERY_FULL; SignalStyleSetChangedEvent(IndexToNPad(controller_idx)); } @@ -249,8 +250,8 @@ void Controller_NPad::OnInit() { style.joycon_left.Assign(1); style.joycon_right.Assign(1); style.joycon_dual.Assign(1); - style.pro_controller.Assign(1); - style.pokeball.Assign(1); + style.fullkey.Assign(1); + style.palma.Assign(1); } std::transform(Settings::values.players.GetValue().begin(), @@ -404,13 +405,10 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* } for (std::size_t i = 0; i < shared_memory_entries.size(); ++i) { auto& npad = shared_memory_entries[i]; - const std::array controller_npads{&npad.main_controller_states, - &npad.handheld_states, - &npad.dual_states, - &npad.left_joy_states, - &npad.right_joy_states, - &npad.pokeball_states, - &npad.libnx}; + const std::array controller_npads{ + &npad.fullkey_states, &npad.handheld_states, &npad.joy_dual_states, + &npad.joy_left_states, &npad.joy_right_states, &npad.palma_states, + &npad.system_ext_states}; for (auto* main_controller : controller_npads) { main_controller->common.entry_count = 16; @@ -440,16 +438,16 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* auto& pad_state = npad_pad_states[npad_index]; auto& main_controller = - npad.main_controller_states.npad[npad.main_controller_states.common.last_entry_index]; + npad.fullkey_states.npad[npad.fullkey_states.common.last_entry_index]; auto& handheld_entry = npad.handheld_states.npad[npad.handheld_states.common.last_entry_index]; - auto& dual_entry = npad.dual_states.npad[npad.dual_states.common.last_entry_index]; - auto& left_entry = npad.left_joy_states.npad[npad.left_joy_states.common.last_entry_index]; + auto& dual_entry = npad.joy_dual_states.npad[npad.joy_dual_states.common.last_entry_index]; + auto& left_entry = npad.joy_left_states.npad[npad.joy_left_states.common.last_entry_index]; auto& right_entry = - npad.right_joy_states.npad[npad.right_joy_states.common.last_entry_index]; - auto& pokeball_entry = - npad.pokeball_states.npad[npad.pokeball_states.common.last_entry_index]; - auto& libnx_entry = npad.libnx.npad[npad.libnx.common.last_entry_index]; + npad.joy_right_states.npad[npad.joy_right_states.common.last_entry_index]; + auto& pokeball_entry = npad.palma_states.npad[npad.palma_states.common.last_entry_index]; + auto& libnx_entry = + npad.system_ext_states.npad[npad.system_ext_states.common.last_entry_index]; libnx_entry.connection_status.raw = 0; libnx_entry.connection_status.IsConnected.Assign(1); @@ -554,7 +552,7 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing } const std::array controller_sixaxes{ - &npad.sixaxis_full, &npad.sixaxis_handheld, &npad.sixaxis_dual_left, + &npad.sixaxis_fullkey, &npad.sixaxis_handheld, &npad.sixaxis_dual_left, &npad.sixaxis_dual_right, &npad.sixaxis_left, &npad.sixaxis_right, }; @@ -592,7 +590,7 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing } auto& full_sixaxis_entry = - npad.sixaxis_full.sixaxis[npad.sixaxis_full.common.last_entry_index]; + npad.sixaxis_fullkey.sixaxis[npad.sixaxis_fullkey.common.last_entry_index]; auto& handheld_sixaxis_entry = npad.sixaxis_handheld.sixaxis[npad.sixaxis_handheld.common.last_entry_index]; auto& dual_left_sixaxis_entry = @@ -727,8 +725,8 @@ Controller_NPad::NpadCommunicationMode Controller_NPad::GetNpadCommunicationMode void Controller_NPad::SetNpadMode(u32 npad_id, NpadAssignments assignment_mode) { const std::size_t npad_index = NPadIdToIndex(npad_id); ASSERT(npad_index < shared_memory_entries.size()); - if (shared_memory_entries[npad_index].pad_assignment != assignment_mode) { - shared_memory_entries[npad_index].pad_assignment = assignment_mode; + if (shared_memory_entries[npad_index].assignment_mode != assignment_mode) { + shared_memory_entries[npad_index].assignment_mode = assignment_mode; } } @@ -935,9 +933,10 @@ void Controller_NPad::DisconnectNpadAtIndex(std::size_t npad_index) { connected_controllers[npad_index].is_connected = false; auto& controller = shared_memory_entries[npad_index]; - controller.joy_styles.raw = 0; // Zero out + controller.style_set.raw = 0; // Zero out controller.device_type.raw = 0; - controller.properties.raw = 0; + controller.system_properties.raw = 0; + controller.button_properties.raw = 0; SignalStyleSetChangedEvent(IndexToNPad(npad_index)); } @@ -1113,7 +1112,7 @@ bool Controller_NPad::IsControllerSupported(NPadControllerType controller) const [](u32 npad_id) { return npad_id <= MAX_NPAD_ID; })) { switch (controller) { case NPadControllerType::ProController: - return style.pro_controller; + return style.fullkey; case NPadControllerType::JoyDual: return style.joycon_dual; case NPadControllerType::JoyLeft: @@ -1121,7 +1120,7 @@ bool Controller_NPad::IsControllerSupported(NPadControllerType controller) const case NPadControllerType::JoyRight: return style.joycon_right; case NPadControllerType::Pokeball: - return style.pokeball; + return style.palma; default: return false; } diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index e5778921f3..d791e327c4 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h @@ -90,10 +90,10 @@ public: }; enum class NpadCommunicationMode : u64 { - Unknown0 = 0, - Unknown1 = 1, - Unknown2 = 2, - Unknown3 = 3, + Mode_5ms = 0, + Mode_10ms = 1, + Mode_15ms = 2, + Default = 3, }; struct DeviceHandle { @@ -108,13 +108,13 @@ public: union { u32_le raw{}; - BitField<0, 1, u32> pro_controller; + BitField<0, 1, u32> fullkey; BitField<1, 1, u32> handheld; BitField<2, 1, u32> joycon_dual; BitField<3, 1, u32> joycon_left; BitField<4, 1, u32> joycon_right; BitField<5, 1, u32> gamecube; - BitField<6, 1, u32> pokeball; + BitField<6, 1, u32> palma; BitField<7, 1, u32> lark; BitField<8, 1, u32> handheld_lark; BitField<9, 1, u32> lucia; @@ -243,12 +243,32 @@ private: }; static_assert(sizeof(CommonHeader) == 0x20, "CommonHeader is an invalid size"); + enum class ColorAttributes : u32_le { + Ok = 0, + ReadError = 1, + NoController = 2, + }; + static_assert(sizeof(ColorAttributes) == 4, "ColorAttributes is an invalid size"); + struct ControllerColor { - u32_le body_color; - u32_le button_color; + u32_le body; + u32_le button; }; static_assert(sizeof(ControllerColor) == 8, "ControllerColor is an invalid size"); + struct FullKeyColor { + ColorAttributes attribute; + ControllerColor fullkey; + }; + static_assert(sizeof(FullKeyColor) == 0xC, "FullKeyColor is an invalid size"); + + struct JoyconColor { + ColorAttributes attribute; + ControllerColor left; + ControllerColor right; + }; + static_assert(sizeof(JoyconColor) == 0x14, "JoyconColor is an invalid size"); + struct ControllerPadState { union { u64_le raw{}; @@ -365,13 +385,7 @@ private: }; static_assert(sizeof(SixAxisGeneric) == 0x708, "SixAxisGeneric is an invalid size"); - enum class ColorReadError : u32_le { - ReadOk = 0, - ColorDoesntExist = 1, - NoController = 2, - }; - - struct NPadProperties { + struct NPadSystemProperties { union { s64_le raw{}; BitField<0, 1, s64> is_charging_joy_dual; @@ -389,17 +403,36 @@ private: BitField<15, 1, s64> use_directional_buttons; }; }; + static_assert(sizeof(NPadSystemProperties) == 0x8, "NPadSystemProperties is an invalid size"); + + struct NPadButtonProperties { + union { + s32_le raw{}; + BitField<0, 1, s32> is_home_button_protection_enabled; + }; + }; + static_assert(sizeof(NPadButtonProperties) == 0x4, "NPadButtonProperties is an invalid size"); struct NPadDevice { union { u32_le raw{}; - BitField<0, 1, s32> pro_controller; - BitField<1, 1, s32> handheld; + BitField<0, 1, s32> fullkey; + BitField<1, 1, s32> debug_pad; BitField<2, 1, s32> handheld_left; BitField<3, 1, s32> handheld_right; BitField<4, 1, s32> joycon_left; BitField<5, 1, s32> joycon_right; - BitField<6, 1, s32> pokeball; + BitField<6, 1, s32> palma; + BitField<7, 1, s32> lark_hvc_left; + BitField<8, 1, s32> lark_hvc_right; + BitField<9, 1, s32> lark_nes_left; + BitField<10, 1, s32> lark_nes_right; + BitField<11, 1, s32> handheld_lark_hvc_left; + BitField<12, 1, s32> handheld_lark_hvc_right; + BitField<13, 1, s32> handheld_lark_nes_left; + BitField<14, 1, s32> handheld_lark_nes_right; + BitField<15, 1, s32> lucia; + BitField<31, 1, s32> system; }; }; @@ -411,34 +444,31 @@ private: }; struct NPadEntry { - NpadStyleSet joy_styles; - NpadAssignments pad_assignment; + NpadStyleSet style_set; + NpadAssignments assignment_mode; + FullKeyColor fullkey_color; + JoyconColor joycon_color; - ColorReadError single_color_error; - ControllerColor single_color; - - ColorReadError dual_color_error; - ControllerColor left_color; - ControllerColor right_color; - - NPadGeneric main_controller_states; + NPadGeneric fullkey_states; NPadGeneric handheld_states; - NPadGeneric dual_states; - NPadGeneric left_joy_states; - NPadGeneric right_joy_states; - NPadGeneric pokeball_states; - NPadGeneric libnx; // TODO(ogniK): Find out what this actually is, libnx seems to only be - // relying on this for the time being - SixAxisGeneric sixaxis_full; + NPadGeneric joy_dual_states; + NPadGeneric joy_left_states; + NPadGeneric joy_right_states; + NPadGeneric palma_states; + NPadGeneric system_ext_states; + SixAxisGeneric sixaxis_fullkey; SixAxisGeneric sixaxis_handheld; SixAxisGeneric sixaxis_dual_left; SixAxisGeneric sixaxis_dual_right; SixAxisGeneric sixaxis_left; SixAxisGeneric sixaxis_right; NPadDevice device_type; - NPadProperties properties; - INSERT_PADDING_WORDS(1); - std::array battery_level; + INSERT_PADDING_BYTES(0x4); // reserved + NPadSystemProperties system_properties; + NPadButtonProperties button_properties; + u32 battery_level_dual; + u32 battery_level_left; + u32 battery_level_right; INSERT_PADDING_BYTES(0x5c); INSERT_PADDING_BYTES(0xdf8); }; @@ -477,7 +507,7 @@ private: NpadHoldType hold_type{NpadHoldType::Vertical}; NpadHandheldActivationMode handheld_activation_mode{NpadHandheldActivationMode::Dual}; // NpadCommunicationMode is unknown, default value is 1 - NpadCommunicationMode communication_mode{NpadCommunicationMode::Unknown1}; + NpadCommunicationMode communication_mode{NpadCommunicationMode::Default}; // Each controller should have their own styleset changed event std::array styleset_changed_events; std::array, 10> last_vibration_timepoints; diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index fbe36046b3..a129dc46b2 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp @@ -886,7 +886,7 @@ void ConfigureInputPlayer::SetConnectableControllers() { index_controller_type_pairs.clear(); ui->comboControllerType->clear(); - if (enable_all || npad_style_set.pro_controller == 1) { + if (enable_all || npad_style_set.fullkey == 1) { index_controller_type_pairs.emplace_back(ui->comboControllerType->count(), Settings::ControllerType::ProController); ui->comboControllerType->addItem(tr("Pro Controller"));