summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar german772022-05-21 17:21:45 -0500
committerGravatar Narr the Reg2022-05-27 10:22:37 -0500
commita1f2610522dd7d66f370dacc821f2b30029a218e (patch)
tree42684db4bc71578b13d8f301816e231e8c058391
parentservice: hid: Implement LoadSixAxisSensorCalibrationParameter and GetSixAxisS... (diff)
downloadyuzu-a1f2610522dd7d66f370dacc821f2b30029a218e.tar.gz
yuzu-a1f2610522dd7d66f370dacc821f2b30029a218e.tar.xz
yuzu-a1f2610522dd7d66f370dacc821f2b30029a218e.zip
service: hid: Implement ResetIsSixAxisSensorDeviceNewlyAssigned
Needed by Nintendo Switch Sports
Diffstat (limited to '')
-rw-r--r--src/core/hid/hid_types.h10
-rw-r--r--src/core/hle/service/hid/controllers/npad.cpp77
-rw-r--r--src/core/hle/service/hid/controllers/npad.h16
-rw-r--r--src/core/hle/service/hid/hid.cpp27
-rw-r--r--src/core/hle/service/hid/hid.h1
5 files changed, 125 insertions, 6 deletions
diff --git a/src/core/hid/hid_types.h b/src/core/hid/hid_types.h
index 00ba23535..9f76f9bcb 100644
--- a/src/core/hid/hid_types.h
+++ b/src/core/hid/hid_types.h
@@ -498,6 +498,16 @@ struct SixAxisSensorFusionParameters {
498static_assert(sizeof(SixAxisSensorFusionParameters) == 8, 498static_assert(sizeof(SixAxisSensorFusionParameters) == 8,
499 "SixAxisSensorFusionParameters is an invalid size"); 499 "SixAxisSensorFusionParameters is an invalid size");
500 500
501// This is nn::hid::server::SixAxisSensorProperties
502struct SixAxisSensorProperties {
503 union {
504 u8 raw{};
505 BitField<0, 1, u8> is_newly_assigned;
506 BitField<1, 1, u8> is_firmware_update_available;
507 };
508};
509static_assert(sizeof(SixAxisSensorProperties) == 1, "SixAxisSensorProperties is an invalid size");
510
501// This is nn::hid::SixAxisSensorCalibrationParameter 511// This is nn::hid::SixAxisSensorCalibrationParameter
502struct SixAxisSensorCalibrationParameter { 512struct SixAxisSensorCalibrationParameter {
503 std::array<u8, 0x744> unknown_data{}; 513 std::array<u8, 0x744> unknown_data{};
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index 9ce25c641..1e04ee3f2 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -169,6 +169,7 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
169 shared_memory->system_properties.use_plus.Assign(1); 169 shared_memory->system_properties.use_plus.Assign(1);
170 shared_memory->system_properties.use_minus.Assign(1); 170 shared_memory->system_properties.use_minus.Assign(1);
171 shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::SwitchProController; 171 shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::SwitchProController;
172 shared_memory->sixaxis_fullkey_properties.is_newly_assigned.Assign(1);
172 break; 173 break;
173 case Core::HID::NpadStyleIndex::Handheld: 174 case Core::HID::NpadStyleIndex::Handheld:
174 shared_memory->style_tag.handheld.Assign(1); 175 shared_memory->style_tag.handheld.Assign(1);
@@ -181,16 +182,19 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
181 shared_memory->assignment_mode = NpadJoyAssignmentMode::Dual; 182 shared_memory->assignment_mode = NpadJoyAssignmentMode::Dual;
182 shared_memory->applet_nfc_xcd.applet_footer.type = 183 shared_memory->applet_nfc_xcd.applet_footer.type =
183 AppletFooterUiType::HandheldJoyConLeftJoyConRight; 184 AppletFooterUiType::HandheldJoyConLeftJoyConRight;
185 shared_memory->sixaxis_handheld_properties.is_newly_assigned.Assign(1);
184 break; 186 break;
185 case Core::HID::NpadStyleIndex::JoyconDual: 187 case Core::HID::NpadStyleIndex::JoyconDual:
186 shared_memory->style_tag.joycon_dual.Assign(1); 188 shared_memory->style_tag.joycon_dual.Assign(1);
187 if (controller.is_dual_left_connected) { 189 if (controller.is_dual_left_connected) {
188 shared_memory->device_type.joycon_left.Assign(1); 190 shared_memory->device_type.joycon_left.Assign(1);
189 shared_memory->system_properties.use_minus.Assign(1); 191 shared_memory->system_properties.use_minus.Assign(1);
192 shared_memory->sixaxis_dual_left_properties.is_newly_assigned.Assign(1);
190 } 193 }
191 if (controller.is_dual_right_connected) { 194 if (controller.is_dual_right_connected) {
192 shared_memory->device_type.joycon_right.Assign(1); 195 shared_memory->device_type.joycon_right.Assign(1);
193 shared_memory->system_properties.use_plus.Assign(1); 196 shared_memory->system_properties.use_plus.Assign(1);
197 shared_memory->sixaxis_dual_right_properties.is_newly_assigned.Assign(1);
194 } 198 }
195 shared_memory->system_properties.use_directional_buttons.Assign(1); 199 shared_memory->system_properties.use_directional_buttons.Assign(1);
196 shared_memory->system_properties.is_vertical.Assign(1); 200 shared_memory->system_properties.is_vertical.Assign(1);
@@ -209,6 +213,7 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
209 shared_memory->system_properties.is_horizontal.Assign(1); 213 shared_memory->system_properties.is_horizontal.Assign(1);
210 shared_memory->system_properties.use_minus.Assign(1); 214 shared_memory->system_properties.use_minus.Assign(1);
211 shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::JoyLeftHorizontal; 215 shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::JoyLeftHorizontal;
216 shared_memory->sixaxis_left_properties.is_newly_assigned.Assign(1);
212 break; 217 break;
213 case Core::HID::NpadStyleIndex::JoyconRight: 218 case Core::HID::NpadStyleIndex::JoyconRight:
214 shared_memory->style_tag.joycon_right.Assign(1); 219 shared_memory->style_tag.joycon_right.Assign(1);
@@ -216,6 +221,7 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
216 shared_memory->system_properties.is_horizontal.Assign(1); 221 shared_memory->system_properties.is_horizontal.Assign(1);
217 shared_memory->system_properties.use_plus.Assign(1); 222 shared_memory->system_properties.use_plus.Assign(1);
218 shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::JoyRightHorizontal; 223 shared_memory->applet_nfc_xcd.applet_footer.type = AppletFooterUiType::JoyRightHorizontal;
224 shared_memory->sixaxis_right_properties.is_newly_assigned.Assign(1);
219 break; 225 break;
220 case Core::HID::NpadStyleIndex::GameCube: 226 case Core::HID::NpadStyleIndex::GameCube:
221 shared_memory->style_tag.gamecube.Assign(1); 227 shared_memory->style_tag.gamecube.Assign(1);
@@ -226,6 +232,7 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
226 case Core::HID::NpadStyleIndex::Pokeball: 232 case Core::HID::NpadStyleIndex::Pokeball:
227 shared_memory->style_tag.palma.Assign(1); 233 shared_memory->style_tag.palma.Assign(1);
228 shared_memory->device_type.palma.Assign(1); 234 shared_memory->device_type.palma.Assign(1);
235 shared_memory->sixaxis_fullkey_properties.is_newly_assigned.Assign(1);
229 break; 236 break;
230 case Core::HID::NpadStyleIndex::NES: 237 case Core::HID::NpadStyleIndex::NES:
231 shared_memory->style_tag.lark.Assign(1); 238 shared_memory->style_tag.lark.Assign(1);
@@ -997,6 +1004,12 @@ ResultCode Controller_NPad::DisconnectNpad(Core::HID::NpadIdType npad_id) {
997 shared_memory->device_type.raw = 0; 1004 shared_memory->device_type.raw = 0;
998 shared_memory->system_properties.raw = 0; 1005 shared_memory->system_properties.raw = 0;
999 shared_memory->button_properties.raw = 0; 1006 shared_memory->button_properties.raw = 0;
1007 shared_memory->sixaxis_fullkey_properties.raw = 0;
1008 shared_memory->sixaxis_handheld_properties.raw = 0;
1009 shared_memory->sixaxis_dual_left_properties.raw = 0;
1010 shared_memory->sixaxis_dual_right_properties.raw = 0;
1011 shared_memory->sixaxis_left_properties.raw = 0;
1012 shared_memory->sixaxis_right_properties.raw = 0;
1000 shared_memory->battery_level_dual = 0; 1013 shared_memory->battery_level_dual = 0;
1001 shared_memory->battery_level_left = 0; 1014 shared_memory->battery_level_left = 0;
1002 shared_memory->battery_level_right = 0; 1015 shared_memory->battery_level_right = 0;
@@ -1069,8 +1082,8 @@ ResultCode Controller_NPad::IsFirmwareUpdateAvailableForSixAxisSensor(
1069 return is_valid; 1082 return is_valid;
1070 } 1083 }
1071 1084
1072 // We don't support joycon firmware updates 1085 const auto& sixaxis_properties = GetSixaxisProperties(sixaxis_handle);
1073 is_firmware_available = false; 1086 is_firmware_available = sixaxis_properties.is_firmware_update_available != 0;
1074 return ResultSuccess; 1087 return ResultSuccess;
1075} 1088}
1076 1089
@@ -1130,6 +1143,20 @@ ResultCode Controller_NPad::GetSixAxisSensorIcInformation(
1130 return ResultSuccess; 1143 return ResultSuccess;
1131} 1144}
1132 1145
1146ResultCode Controller_NPad::ResetIsSixAxisSensorDeviceNewlyAssigned(
1147 const Core::HID::SixAxisSensorHandle& sixaxis_handle) {
1148 const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle);
1149 if (is_valid.IsError()) {
1150 LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw);
1151 return is_valid;
1152 }
1153
1154 auto& sixaxis_properties = GetSixaxisProperties(sixaxis_handle);
1155 sixaxis_properties.is_newly_assigned.Assign(0);
1156
1157 return ResultSuccess;
1158}
1159
1133ResultCode Controller_NPad::SetSixAxisEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, 1160ResultCode Controller_NPad::SetSixAxisEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
1134 bool sixaxis_status) { 1161 bool sixaxis_status) {
1135 const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); 1162 const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle);
@@ -1477,6 +1504,52 @@ const Controller_NPad::NpadControllerData& Controller_NPad::GetControllerFromNpa
1477 return controller_data[npad_index]; 1504 return controller_data[npad_index];
1478} 1505}
1479 1506
1507Core::HID::SixAxisSensorProperties& Controller_NPad::GetSixaxisProperties(
1508 const Core::HID::SixAxisSensorHandle& sixaxis_handle) {
1509 auto& controller = GetControllerFromHandle(sixaxis_handle);
1510 switch (sixaxis_handle.npad_type) {
1511 case Core::HID::NpadStyleIndex::ProController:
1512 case Core::HID::NpadStyleIndex::Pokeball:
1513 return controller.shared_memory->sixaxis_fullkey_properties;
1514 case Core::HID::NpadStyleIndex::Handheld:
1515 return controller.shared_memory->sixaxis_handheld_properties;
1516 case Core::HID::NpadStyleIndex::JoyconDual:
1517 if (sixaxis_handle.device_index == Core::HID::DeviceIndex::Left) {
1518 return controller.shared_memory->sixaxis_dual_left_properties;
1519 }
1520 return controller.shared_memory->sixaxis_dual_right_properties;
1521 case Core::HID::NpadStyleIndex::JoyconLeft:
1522 return controller.shared_memory->sixaxis_left_properties;
1523 case Core::HID::NpadStyleIndex::JoyconRight:
1524 return controller.shared_memory->sixaxis_right_properties;
1525 default:
1526 return controller.shared_memory->sixaxis_fullkey_properties;
1527 }
1528}
1529
1530const Core::HID::SixAxisSensorProperties& Controller_NPad::GetSixaxisProperties(
1531 const Core::HID::SixAxisSensorHandle& sixaxis_handle) const {
1532 const auto& controller = GetControllerFromHandle(sixaxis_handle);
1533 switch (sixaxis_handle.npad_type) {
1534 case Core::HID::NpadStyleIndex::ProController:
1535 case Core::HID::NpadStyleIndex::Pokeball:
1536 return controller.shared_memory->sixaxis_fullkey_properties;
1537 case Core::HID::NpadStyleIndex::Handheld:
1538 return controller.shared_memory->sixaxis_handheld_properties;
1539 case Core::HID::NpadStyleIndex::JoyconDual:
1540 if (sixaxis_handle.device_index == Core::HID::DeviceIndex::Left) {
1541 return controller.shared_memory->sixaxis_dual_left_properties;
1542 }
1543 return controller.shared_memory->sixaxis_dual_right_properties;
1544 case Core::HID::NpadStyleIndex::JoyconLeft:
1545 return controller.shared_memory->sixaxis_left_properties;
1546 case Core::HID::NpadStyleIndex::JoyconRight:
1547 return controller.shared_memory->sixaxis_right_properties;
1548 default:
1549 return controller.shared_memory->sixaxis_fullkey_properties;
1550 }
1551}
1552
1480Controller_NPad::SixaxisParameters& Controller_NPad::GetSixaxisState( 1553Controller_NPad::SixaxisParameters& Controller_NPad::GetSixaxisState(
1481 const Core::HID::SixAxisSensorHandle& sixaxis_handle) { 1554 const Core::HID::SixAxisSensorHandle& sixaxis_handle) {
1482 auto& controller = GetControllerFromHandle(sixaxis_handle); 1555 auto& controller = GetControllerFromHandle(sixaxis_handle);
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h
index 2e2e1d07f..0b662b7f8 100644
--- a/src/core/hle/service/hid/controllers/npad.h
+++ b/src/core/hle/service/hid/controllers/npad.h
@@ -161,6 +161,8 @@ public:
161 ResultCode GetSixAxisSensorIcInformation( 161 ResultCode GetSixAxisSensorIcInformation(
162 const Core::HID::SixAxisSensorHandle& sixaxis_handle, 162 const Core::HID::SixAxisSensorHandle& sixaxis_handle,
163 Core::HID::SixAxisSensorIcInformation& ic_information) const; 163 Core::HID::SixAxisSensorIcInformation& ic_information) const;
164 ResultCode ResetIsSixAxisSensorDeviceNewlyAssigned(
165 const Core::HID::SixAxisSensorHandle& sixaxis_handle);
164 ResultCode SetSixAxisEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, 166 ResultCode SetSixAxisEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
165 bool sixaxis_status); 167 bool sixaxis_status);
166 ResultCode IsSixAxisSensorFusionEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, 168 ResultCode IsSixAxisSensorFusionEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle,
@@ -464,9 +466,13 @@ private:
464 NpadLuciaType lucia_type{}; 466 NpadLuciaType lucia_type{};
465 NpadLagonType lagon_type{}; 467 NpadLagonType lagon_type{};
466 NpadLagerType lager_type{}; 468 NpadLagerType lager_type{};
467 // FW 13.x Investigate there is some sort of bitflag related to joycons 469 Core::HID::SixAxisSensorProperties sixaxis_fullkey_properties;
468 INSERT_PADDING_BYTES(0x4); 470 Core::HID::SixAxisSensorProperties sixaxis_handheld_properties;
469 INSERT_PADDING_BYTES(0xc08); // Unknown 471 Core::HID::SixAxisSensorProperties sixaxis_dual_left_properties;
472 Core::HID::SixAxisSensorProperties sixaxis_dual_right_properties;
473 Core::HID::SixAxisSensorProperties sixaxis_left_properties;
474 Core::HID::SixAxisSensorProperties sixaxis_right_properties;
475 INSERT_PADDING_BYTES(0xc06); // Unknown
470 }; 476 };
471 static_assert(sizeof(NpadInternalState) == 0x5000, "NpadInternalState is an invalid size"); 477 static_assert(sizeof(NpadInternalState) == 0x5000, "NpadInternalState is an invalid size");
472 478
@@ -539,6 +545,10 @@ private:
539 NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id); 545 NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id);
540 const NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id) const; 546 const NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id) const;
541 547
548 Core::HID::SixAxisSensorProperties& GetSixaxisProperties(
549 const Core::HID::SixAxisSensorHandle& device_handle);
550 const Core::HID::SixAxisSensorProperties& GetSixaxisProperties(
551 const Core::HID::SixAxisSensorHandle& device_handle) const;
542 SixaxisParameters& GetSixaxisState(const Core::HID::SixAxisSensorHandle& device_handle); 552 SixaxisParameters& GetSixaxisState(const Core::HID::SixAxisSensorHandle& device_handle);
543 const SixaxisParameters& GetSixaxisState( 553 const SixaxisParameters& GetSixaxisState(
544 const Core::HID::SixAxisSensorHandle& device_handle) const; 554 const Core::HID::SixAxisSensorHandle& device_handle) const;
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index 19d12cf51..8a496c38c 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -262,7 +262,7 @@ Hid::Hid(Core::System& system_)
262 {86, nullptr, "StoreSixAxisSensorCalibrationParameter"}, 262 {86, nullptr, "StoreSixAxisSensorCalibrationParameter"},
263 {87, &Hid::LoadSixAxisSensorCalibrationParameter, "LoadSixAxisSensorCalibrationParameter"}, 263 {87, &Hid::LoadSixAxisSensorCalibrationParameter, "LoadSixAxisSensorCalibrationParameter"},
264 {88, &Hid::GetSixAxisSensorIcInformation, "GetSixAxisSensorIcInformation"}, 264 {88, &Hid::GetSixAxisSensorIcInformation, "GetSixAxisSensorIcInformation"},
265 {89, nullptr, "ResetIsSixAxisSensorDeviceNewlyAssigned"}, 265 {89, &Hid::ResetIsSixAxisSensorDeviceNewlyAssigned, "ResetIsSixAxisSensorDeviceNewlyAssigned"},
266 {91, &Hid::ActivateGesture, "ActivateGesture"}, 266 {91, &Hid::ActivateGesture, "ActivateGesture"},
267 {100, &Hid::SetSupportedNpadStyleSet, "SetSupportedNpadStyleSet"}, 267 {100, &Hid::SetSupportedNpadStyleSet, "SetSupportedNpadStyleSet"},
268 {101, &Hid::GetSupportedNpadStyleSet, "GetSupportedNpadStyleSet"}, 268 {101, &Hid::GetSupportedNpadStyleSet, "GetSupportedNpadStyleSet"},
@@ -930,6 +930,31 @@ void Hid::GetSixAxisSensorIcInformation(Kernel::HLERequestContext& ctx) {
930 rb.Push(result); 930 rb.Push(result);
931} 931}
932 932
933void Hid::ResetIsSixAxisSensorDeviceNewlyAssigned(Kernel::HLERequestContext& ctx) {
934 IPC::RequestParser rp{ctx};
935 struct Parameters {
936 Core::HID::SixAxisSensorHandle sixaxis_handle;
937 INSERT_PADDING_WORDS_NOINIT(1);
938 u64 applet_resource_user_id;
939 };
940 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
941
942 const auto parameters{rp.PopRaw<Parameters>()};
943
944 auto& controller = GetAppletResource()->GetController<Controller_NPad>(HidController::NPad);
945 const auto result =
946 controller.ResetIsSixAxisSensorDeviceNewlyAssigned(parameters.sixaxis_handle);
947
948 LOG_WARNING(
949 Service_HID,
950 "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
951 parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id,
952 parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id);
953
954 IPC::ResponseBuilder rb{ctx, 2};
955 rb.Push(result);
956}
957
933void Hid::ActivateGesture(Kernel::HLERequestContext& ctx) { 958void Hid::ActivateGesture(Kernel::HLERequestContext& ctx) {
934 IPC::RequestParser rp{ctx}; 959 IPC::RequestParser rp{ctx};
935 struct Parameters { 960 struct Parameters {
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h
index 726a031de..ac4333022 100644
--- a/src/core/hle/service/hid/hid.h
+++ b/src/core/hle/service/hid/hid.h
@@ -117,6 +117,7 @@ private:
117 void IsSixAxisSensorUnalteredPassthroughEnabled(Kernel::HLERequestContext& ctx); 117 void IsSixAxisSensorUnalteredPassthroughEnabled(Kernel::HLERequestContext& ctx);
118 void LoadSixAxisSensorCalibrationParameter(Kernel::HLERequestContext& ctx); 118 void LoadSixAxisSensorCalibrationParameter(Kernel::HLERequestContext& ctx);
119 void GetSixAxisSensorIcInformation(Kernel::HLERequestContext& ctx); 119 void GetSixAxisSensorIcInformation(Kernel::HLERequestContext& ctx);
120 void ResetIsSixAxisSensorDeviceNewlyAssigned(Kernel::HLERequestContext& ctx);
120 void ActivateGesture(Kernel::HLERequestContext& ctx); 121 void ActivateGesture(Kernel::HLERequestContext& ctx);
121 void SetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx); 122 void SetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx);
122 void GetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx); 123 void GetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx);