diff options
| author | 2022-05-21 17:10:20 -0500 | |
|---|---|---|
| committer | 2022-05-27 10:22:36 -0500 | |
| commit | 240f59a4c8319ec5f0c0e5fd34e8f9c5a458751e (patch) | |
| tree | a2d814d9be7ca3c2547399090f451dbc3694d56b | |
| parent | service: hid: Implement EnableSixAxisSensorUnalteredPassthrough and IsSixAxis... (diff) | |
| download | yuzu-240f59a4c8319ec5f0c0e5fd34e8f9c5a458751e.tar.gz yuzu-240f59a4c8319ec5f0c0e5fd34e8f9c5a458751e.tar.xz yuzu-240f59a4c8319ec5f0c0e5fd34e8f9c5a458751e.zip | |
service: hid: Implement LoadSixAxisSensorCalibrationParameter and GetSixAxisSensorIcInformation
Needed by Nintendo Switch Sports
Diffstat (limited to '')
| -rw-r--r-- | src/core/hid/hid_types.h | 33 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.cpp | 32 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.h | 8 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid.cpp | 64 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid.h | 2 |
5 files changed, 136 insertions, 3 deletions
diff --git a/src/core/hid/hid_types.h b/src/core/hid/hid_types.h index 26ec1091b..00ba23535 100644 --- a/src/core/hid/hid_types.h +++ b/src/core/hid/hid_types.h | |||
| @@ -498,6 +498,39 @@ struct SixAxisSensorFusionParameters { | |||
| 498 | static_assert(sizeof(SixAxisSensorFusionParameters) == 8, | 498 | static_assert(sizeof(SixAxisSensorFusionParameters) == 8, |
| 499 | "SixAxisSensorFusionParameters is an invalid size"); | 499 | "SixAxisSensorFusionParameters is an invalid size"); |
| 500 | 500 | ||
| 501 | // This is nn::hid::SixAxisSensorCalibrationParameter | ||
| 502 | struct SixAxisSensorCalibrationParameter { | ||
| 503 | std::array<u8, 0x744> unknown_data{}; | ||
| 504 | }; | ||
| 505 | static_assert(sizeof(SixAxisSensorCalibrationParameter) == 0x744, | ||
| 506 | "SixAxisSensorCalibrationParameter is an invalid size"); | ||
| 507 | |||
| 508 | // This is nn::hid::SixAxisSensorIcInformation | ||
| 509 | struct SixAxisSensorIcInformation { | ||
| 510 | f32 angular_rate{2000.0f}; // dps | ||
| 511 | std::array<f32, 6> unknown_gyro_data1{ | ||
| 512 | -10.0f, -10.0f, -10.0f, 10.0f, 10.0f, 10.0f, | ||
| 513 | }; // dps | ||
| 514 | std::array<f32, 9> unknown_gyro_data2{ | ||
| 515 | 0.95f, -0.003f, -0.003f, -0.003f, 0.95f, -0.003f, -0.003f, -0.003f, 0.95f, | ||
| 516 | }; | ||
| 517 | std::array<f32, 9> unknown_gyro_data3{ | ||
| 518 | 1.05f, 0.003f, 0.003f, 0.003f, 1.05f, 0.003f, 0.003f, 0.003f, 1.05f, | ||
| 519 | }; | ||
| 520 | f32 acceleration_range{8.0f}; // g force | ||
| 521 | std::array<f32, 6> unknown_accel_data1{ | ||
| 522 | -0.0612f, -0.0612f, -0.0612f, 0.0612f, 0.0612f, 0.0612f, | ||
| 523 | }; // g force | ||
| 524 | std::array<f32, 9> unknown_accel_data2{ | ||
| 525 | 0.95f, -0.003f, -0.003f, -0.003f, 0.95f, -0.003f, -0.003f, -0.003f, 0.95f, | ||
| 526 | }; | ||
| 527 | std::array<f32, 9> unknown_accel_data3{ | ||
| 528 | 1.05f, 0.003f, 0.003f, 0.003f, 1.05f, 0.003f, 0.003f, 0.003f, 1.05f, | ||
| 529 | }; | ||
| 530 | }; | ||
| 531 | static_assert(sizeof(SixAxisSensorIcInformation) == 0xC8, | ||
| 532 | "SixAxisSensorIcInformation is an invalid size"); | ||
| 533 | |||
| 501 | // This is nn::hid::VibrationDeviceHandle | 534 | // This is nn::hid::VibrationDeviceHandle |
| 502 | struct VibrationDeviceHandle { | 535 | struct VibrationDeviceHandle { |
| 503 | NpadStyleIndex npad_type{NpadStyleIndex::None}; | 536 | NpadStyleIndex npad_type{NpadStyleIndex::None}; |
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index c9909ad5a..9ce25c641 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -66,7 +66,7 @@ ResultCode Controller_NPad::VerifyValidSixAxisSensorHandle( | |||
| 66 | if (!device_index) { | 66 | if (!device_index) { |
| 67 | return NpadDeviceIndexOutOfRange; | 67 | return NpadDeviceIndexOutOfRange; |
| 68 | } | 68 | } |
| 69 | // This doesn't get validaded on nnsdk | 69 | // This doesn't get validated on nnsdk |
| 70 | const bool npad_type = device_handle.npad_type < Core::HID::NpadStyleIndex::MaxNpadType; | 70 | const bool npad_type = device_handle.npad_type < Core::HID::NpadStyleIndex::MaxNpadType; |
| 71 | if (!npad_type) { | 71 | if (!npad_type) { |
| 72 | return NpadInvalidHandle; | 72 | return NpadInvalidHandle; |
| @@ -1100,6 +1100,36 @@ ResultCode Controller_NPad::IsSixAxisSensorUnalteredPassthroughEnabled( | |||
| 1100 | return ResultSuccess; | 1100 | return ResultSuccess; |
| 1101 | } | 1101 | } |
| 1102 | 1102 | ||
| 1103 | ResultCode Controller_NPad::LoadSixAxisSensorCalibrationParameter( | ||
| 1104 | const Core::HID::SixAxisSensorHandle& sixaxis_handle, | ||
| 1105 | Core::HID::SixAxisSensorCalibrationParameter& calibration) const { | ||
| 1106 | const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); | ||
| 1107 | if (is_valid.IsError()) { | ||
| 1108 | LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); | ||
| 1109 | return is_valid; | ||
| 1110 | } | ||
| 1111 | |||
| 1112 | // TODO: Request this data to the controller. On error return 0xd8ca | ||
| 1113 | const auto& sixaxis = GetSixaxisState(sixaxis_handle); | ||
| 1114 | calibration = sixaxis.calibration; | ||
| 1115 | return ResultSuccess; | ||
| 1116 | } | ||
| 1117 | |||
| 1118 | ResultCode Controller_NPad::GetSixAxisSensorIcInformation( | ||
| 1119 | const Core::HID::SixAxisSensorHandle& sixaxis_handle, | ||
| 1120 | Core::HID::SixAxisSensorIcInformation& ic_information) const { | ||
| 1121 | const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); | ||
| 1122 | if (is_valid.IsError()) { | ||
| 1123 | LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); | ||
| 1124 | return is_valid; | ||
| 1125 | } | ||
| 1126 | |||
| 1127 | // TODO: Request this data to the controller. On error return 0xd8ca | ||
| 1128 | const auto& sixaxis = GetSixaxisState(sixaxis_handle); | ||
| 1129 | ic_information = sixaxis.ic_information; | ||
| 1130 | return ResultSuccess; | ||
| 1131 | } | ||
| 1132 | |||
| 1103 | ResultCode Controller_NPad::SetSixAxisEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, | 1133 | ResultCode Controller_NPad::SetSixAxisEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, |
| 1104 | bool sixaxis_status) { | 1134 | bool sixaxis_status) { |
| 1105 | const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); | 1135 | const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); |
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index 951f46425..2e2e1d07f 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h | |||
| @@ -155,6 +155,12 @@ public: | |||
| 155 | const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool is_enabled); | 155 | const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool is_enabled); |
| 156 | ResultCode IsSixAxisSensorUnalteredPassthroughEnabled( | 156 | ResultCode IsSixAxisSensorUnalteredPassthroughEnabled( |
| 157 | const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_enabled) const; | 157 | const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_enabled) const; |
| 158 | ResultCode LoadSixAxisSensorCalibrationParameter( | ||
| 159 | const Core::HID::SixAxisSensorHandle& sixaxis_handle, | ||
| 160 | Core::HID::SixAxisSensorCalibrationParameter& calibration) const; | ||
| 161 | ResultCode GetSixAxisSensorIcInformation( | ||
| 162 | const Core::HID::SixAxisSensorHandle& sixaxis_handle, | ||
| 163 | Core::HID::SixAxisSensorIcInformation& ic_information) const; | ||
| 158 | ResultCode SetSixAxisEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, | 164 | ResultCode SetSixAxisEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, |
| 159 | bool sixaxis_status); | 165 | bool sixaxis_status); |
| 160 | ResultCode IsSixAxisSensorFusionEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, | 166 | ResultCode IsSixAxisSensorFusionEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, |
| @@ -474,6 +480,8 @@ private: | |||
| 474 | bool is_fusion_enabled{true}; | 480 | bool is_fusion_enabled{true}; |
| 475 | bool unaltered_passtrough{false}; | 481 | bool unaltered_passtrough{false}; |
| 476 | Core::HID::SixAxisSensorFusionParameters fusion{}; | 482 | Core::HID::SixAxisSensorFusionParameters fusion{}; |
| 483 | Core::HID::SixAxisSensorCalibrationParameter calibration{}; | ||
| 484 | Core::HID::SixAxisSensorIcInformation ic_information{}; | ||
| 477 | GyroscopeZeroDriftMode gyroscope_zero_drift_mode{GyroscopeZeroDriftMode::Standard}; | 485 | GyroscopeZeroDriftMode gyroscope_zero_drift_mode{GyroscopeZeroDriftMode::Standard}; |
| 478 | }; | 486 | }; |
| 479 | 487 | ||
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 1fb3b790c..19d12cf51 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -260,8 +260,8 @@ Hid::Hid(Core::System& system_) | |||
| 260 | {84, &Hid::EnableSixAxisSensorUnalteredPassthrough, "EnableSixAxisSensorUnalteredPassthrough"}, | 260 | {84, &Hid::EnableSixAxisSensorUnalteredPassthrough, "EnableSixAxisSensorUnalteredPassthrough"}, |
| 261 | {85, &Hid::IsSixAxisSensorUnalteredPassthroughEnabled, "IsSixAxisSensorUnalteredPassthroughEnabled"}, | 261 | {85, &Hid::IsSixAxisSensorUnalteredPassthroughEnabled, "IsSixAxisSensorUnalteredPassthroughEnabled"}, |
| 262 | {86, nullptr, "StoreSixAxisSensorCalibrationParameter"}, | 262 | {86, nullptr, "StoreSixAxisSensorCalibrationParameter"}, |
| 263 | {87, nullptr, "LoadSixAxisSensorCalibrationParameter"}, | 263 | {87, &Hid::LoadSixAxisSensorCalibrationParameter, "LoadSixAxisSensorCalibrationParameter"}, |
| 264 | {88, nullptr, "GetSixAxisSensorIcInformation"}, | 264 | {88, &Hid::GetSixAxisSensorIcInformation, "GetSixAxisSensorIcInformation"}, |
| 265 | {89, nullptr, "ResetIsSixAxisSensorDeviceNewlyAssigned"}, | 265 | {89, nullptr, "ResetIsSixAxisSensorDeviceNewlyAssigned"}, |
| 266 | {91, &Hid::ActivateGesture, "ActivateGesture"}, | 266 | {91, &Hid::ActivateGesture, "ActivateGesture"}, |
| 267 | {100, &Hid::SetSupportedNpadStyleSet, "SetSupportedNpadStyleSet"}, | 267 | {100, &Hid::SetSupportedNpadStyleSet, "SetSupportedNpadStyleSet"}, |
| @@ -870,6 +870,66 @@ void Hid::IsSixAxisSensorUnalteredPassthroughEnabled(Kernel::HLERequestContext& | |||
| 870 | rb.Push(is_unaltered_sisxaxis_enabled); | 870 | rb.Push(is_unaltered_sisxaxis_enabled); |
| 871 | } | 871 | } |
| 872 | 872 | ||
| 873 | void Hid::LoadSixAxisSensorCalibrationParameter(Kernel::HLERequestContext& ctx) { | ||
| 874 | IPC::RequestParser rp{ctx}; | ||
| 875 | struct Parameters { | ||
| 876 | Core::HID::SixAxisSensorHandle sixaxis_handle; | ||
| 877 | INSERT_PADDING_WORDS_NOINIT(1); | ||
| 878 | u64 applet_resource_user_id; | ||
| 879 | }; | ||
| 880 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 881 | |||
| 882 | const auto parameters{rp.PopRaw<Parameters>()}; | ||
| 883 | |||
| 884 | Core::HID::SixAxisSensorCalibrationParameter calibration{}; | ||
| 885 | auto& controller = GetAppletResource()->GetController<Controller_NPad>(HidController::NPad); | ||
| 886 | const auto result = | ||
| 887 | controller.LoadSixAxisSensorCalibrationParameter(parameters.sixaxis_handle, calibration); | ||
| 888 | |||
| 889 | LOG_WARNING( | ||
| 890 | Service_HID, | ||
| 891 | "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", | ||
| 892 | parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, | ||
| 893 | parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); | ||
| 894 | |||
| 895 | if (result.IsSuccess()) { | ||
| 896 | ctx.WriteBuffer(calibration); | ||
| 897 | } | ||
| 898 | |||
| 899 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 900 | rb.Push(result); | ||
| 901 | } | ||
| 902 | |||
| 903 | void Hid::GetSixAxisSensorIcInformation(Kernel::HLERequestContext& ctx) { | ||
| 904 | IPC::RequestParser rp{ctx}; | ||
| 905 | struct Parameters { | ||
| 906 | Core::HID::SixAxisSensorHandle sixaxis_handle; | ||
| 907 | INSERT_PADDING_WORDS_NOINIT(1); | ||
| 908 | u64 applet_resource_user_id; | ||
| 909 | }; | ||
| 910 | static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); | ||
| 911 | |||
| 912 | const auto parameters{rp.PopRaw<Parameters>()}; | ||
| 913 | |||
| 914 | Core::HID::SixAxisSensorIcInformation ic_information{}; | ||
| 915 | auto& controller = GetAppletResource()->GetController<Controller_NPad>(HidController::NPad); | ||
| 916 | const auto result = | ||
| 917 | controller.GetSixAxisSensorIcInformation(parameters.sixaxis_handle, ic_information); | ||
| 918 | |||
| 919 | LOG_WARNING( | ||
| 920 | Service_HID, | ||
| 921 | "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", | ||
| 922 | parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, | ||
| 923 | parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); | ||
| 924 | |||
| 925 | if (result.IsSuccess()) { | ||
| 926 | ctx.WriteBuffer(ic_information); | ||
| 927 | } | ||
| 928 | |||
| 929 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 930 | rb.Push(result); | ||
| 931 | } | ||
| 932 | |||
| 873 | void Hid::ActivateGesture(Kernel::HLERequestContext& ctx) { | 933 | void Hid::ActivateGesture(Kernel::HLERequestContext& ctx) { |
| 874 | IPC::RequestParser rp{ctx}; | 934 | IPC::RequestParser rp{ctx}; |
| 875 | struct Parameters { | 935 | struct Parameters { |
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index b8515a002..726a031de 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h | |||
| @@ -115,6 +115,8 @@ private: | |||
| 115 | void IsFirmwareUpdateAvailableForSixAxisSensor(Kernel::HLERequestContext& ctx); | 115 | void IsFirmwareUpdateAvailableForSixAxisSensor(Kernel::HLERequestContext& ctx); |
| 116 | void EnableSixAxisSensorUnalteredPassthrough(Kernel::HLERequestContext& ctx); | 116 | void EnableSixAxisSensorUnalteredPassthrough(Kernel::HLERequestContext& ctx); |
| 117 | void IsSixAxisSensorUnalteredPassthroughEnabled(Kernel::HLERequestContext& ctx); | 117 | void IsSixAxisSensorUnalteredPassthroughEnabled(Kernel::HLERequestContext& ctx); |
| 118 | void LoadSixAxisSensorCalibrationParameter(Kernel::HLERequestContext& ctx); | ||
| 119 | void GetSixAxisSensorIcInformation(Kernel::HLERequestContext& ctx); | ||
| 118 | void ActivateGesture(Kernel::HLERequestContext& ctx); | 120 | void ActivateGesture(Kernel::HLERequestContext& ctx); |
| 119 | void SetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx); | 121 | void SetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx); |
| 120 | void GetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx); | 122 | void GetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx); |