summaryrefslogtreecommitdiff
path: root/src/hid_core
diff options
context:
space:
mode:
authorGravatar liamwhite2024-02-27 12:26:26 -0500
committerGravatar GitHub2024-02-27 12:26:26 -0500
commitdc94882c9062ab88d3d5de35dcb8731111baaea2 (patch)
treeb00be6f4a4b2c826f116e212e15f4498e4b50504 /src/hid_core
parentMerge pull request #13175 from liamwhite/asan (diff)
parentservice: hid: Migrate HidServer to new IPC (diff)
downloadyuzu-dc94882c9062ab88d3d5de35dcb8731111baaea2.tar.gz
yuzu-dc94882c9062ab88d3d5de35dcb8731111baaea2.tar.xz
yuzu-dc94882c9062ab88d3d5de35dcb8731111baaea2.zip
Merge pull request #13135 from german77/hid-interface
service: hid: Migrate HidServer to new IPC
Diffstat (limited to 'src/hid_core')
-rw-r--r--src/hid_core/hid_types.h34
-rw-r--r--src/hid_core/resource_manager.cpp26
-rw-r--r--src/hid_core/resource_manager.h13
-rw-r--r--src/hid_core/resources/palma/palma.cpp24
-rw-r--r--src/hid_core/resources/palma/palma.h34
5 files changed, 54 insertions, 77 deletions
diff --git a/src/hid_core/hid_types.h b/src/hid_core/hid_types.h
index 38888fdd1..40a90c2bc 100644
--- a/src/hid_core/hid_types.h
+++ b/src/hid_core/hid_types.h
@@ -565,36 +565,28 @@ static_assert(sizeof(SixAxisSensorProperties) == 1, "SixAxisSensorProperties is
565 565
566// This is nn::hid::SixAxisSensorCalibrationParameter 566// This is nn::hid::SixAxisSensorCalibrationParameter
567struct SixAxisSensorCalibrationParameter { 567struct SixAxisSensorCalibrationParameter {
568 std::array<u8, 0x744> unknown_data{}; 568 std::array<u8, 0x744> unknown_data;
569}; 569};
570static_assert(sizeof(SixAxisSensorCalibrationParameter) == 0x744, 570static_assert(sizeof(SixAxisSensorCalibrationParameter) == 0x744,
571 "SixAxisSensorCalibrationParameter is an invalid size"); 571 "SixAxisSensorCalibrationParameter is an invalid size");
572static_assert(std::is_trivial_v<SixAxisSensorCalibrationParameter>,
573 "SixAxisSensorCalibrationParameter must be trivial.");
572 574
573// This is nn::hid::SixAxisSensorIcInformation 575// This is nn::hid::SixAxisSensorIcInformation
574struct SixAxisSensorIcInformation { 576struct SixAxisSensorIcInformation {
575 f32 angular_rate{2000.0f}; // dps 577 f32 angular_rate; // dps
576 std::array<f32, 6> unknown_gyro_data1{ 578 std::array<f32, 6> unknown_gyro_data1; // dps
577 -10.0f, -10.0f, -10.0f, 10.0f, 10.0f, 10.0f, 579 std::array<f32, 9> unknown_gyro_data2;
578 }; // dps 580 std::array<f32, 9> unknown_gyro_data3;
579 std::array<f32, 9> unknown_gyro_data2{ 581 f32 acceleration_range; // g force
580 0.95f, -0.003f, -0.003f, -0.003f, 0.95f, -0.003f, -0.003f, -0.003f, 0.95f, 582 std::array<f32, 6> unknown_accel_data1; // g force
581 }; 583 std::array<f32, 9> unknown_accel_data2;
582 std::array<f32, 9> unknown_gyro_data3{ 584 std::array<f32, 9> unknown_accel_data3;
583 1.05f, 0.003f, 0.003f, 0.003f, 1.05f, 0.003f, 0.003f, 0.003f, 1.05f,
584 };
585 f32 acceleration_range{8.0f}; // g force
586 std::array<f32, 6> unknown_accel_data1{
587 -0.0612f, -0.0612f, -0.0612f, 0.0612f, 0.0612f, 0.0612f,
588 }; // g force
589 std::array<f32, 9> unknown_accel_data2{
590 0.95f, -0.003f, -0.003f, -0.003f, 0.95f, -0.003f, -0.003f, -0.003f, 0.95f,
591 };
592 std::array<f32, 9> unknown_accel_data3{
593 1.05f, 0.003f, 0.003f, 0.003f, 1.05f, 0.003f, 0.003f, 0.003f, 1.05f,
594 };
595}; 585};
596static_assert(sizeof(SixAxisSensorIcInformation) == 0xC8, 586static_assert(sizeof(SixAxisSensorIcInformation) == 0xC8,
597 "SixAxisSensorIcInformation is an invalid size"); 587 "SixAxisSensorIcInformation is an invalid size");
588static_assert(std::is_trivial_v<SixAxisSensorIcInformation>,
589 "SixAxisSensorIcInformation must be trivial.");
598 590
599// This is nn::hid::SixAxisSensorAttribute 591// This is nn::hid::SixAxisSensorAttribute
600struct SixAxisSensorAttribute { 592struct SixAxisSensorAttribute {
diff --git a/src/hid_core/resource_manager.cpp b/src/hid_core/resource_manager.cpp
index 01261ba97..62fec03b1 100644
--- a/src/hid_core/resource_manager.cpp
+++ b/src/hid_core/resource_manager.cpp
@@ -4,7 +4,6 @@
4#include "common/logging/log.h" 4#include "common/logging/log.h"
5#include "core/core.h" 5#include "core/core.h"
6#include "core/core_timing.h" 6#include "core/core_timing.h"
7#include "core/hle/kernel/k_shared_memory.h"
8#include "core/hle/service/ipc_helpers.h" 7#include "core/hle/service/ipc_helpers.h"
9#include "core/hle/service/set/system_settings_server.h" 8#include "core/hle/service/set/system_settings_server.h"
10#include "core/hle/service/sm/sm.h" 9#include "core/hle/service/sm/sm.h"
@@ -501,29 +500,4 @@ void ResourceManager::UpdateMotion(std::chrono::nanoseconds ns_late) {
501 console_six_axis->OnUpdate(core_timing); 500 console_six_axis->OnUpdate(core_timing);
502} 501}
503 502
504IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource,
505 u64 applet_resource_user_id)
506 : ServiceFramework{system_, "IAppletResource"}, aruid{applet_resource_user_id},
507 resource_manager{resource} {
508 static const FunctionInfo functions[] = {
509 {0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"},
510 };
511 RegisterHandlers(functions);
512}
513
514IAppletResource::~IAppletResource() {
515 resource_manager->FreeAppletResourceId(aruid);
516}
517
518void IAppletResource::GetSharedMemoryHandle(HLERequestContext& ctx) {
519 Kernel::KSharedMemory* handle;
520 const auto result = resource_manager->GetSharedMemoryHandle(&handle, aruid);
521
522 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, result=0x{:X}", aruid, result.raw);
523
524 IPC::ResponseBuilder rb{ctx, 2, 1};
525 rb.Push(result);
526 rb.PushCopyObjects(handle);
527}
528
529} // namespace Service::HID 503} // namespace Service::HID
diff --git a/src/hid_core/resource_manager.h b/src/hid_core/resource_manager.h
index dc3ff01f8..5abd7e044 100644
--- a/src/hid_core/resource_manager.h
+++ b/src/hid_core/resource_manager.h
@@ -174,17 +174,4 @@ private:
174 KernelHelpers::ServiceContext service_context; 174 KernelHelpers::ServiceContext service_context;
175}; 175};
176 176
177class IAppletResource final : public ServiceFramework<IAppletResource> {
178public:
179 explicit IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource,
180 u64 applet_resource_user_id);
181 ~IAppletResource() override;
182
183private:
184 void GetSharedMemoryHandle(HLERequestContext& ctx);
185
186 u64 aruid{};
187 std::shared_ptr<ResourceManager> resource_manager;
188};
189
190} // namespace Service::HID 177} // namespace Service::HID
diff --git a/src/hid_core/resources/palma/palma.cpp b/src/hid_core/resources/palma/palma.cpp
index ea4a291fd..be3d3c0ed 100644
--- a/src/hid_core/resources/palma/palma.cpp
+++ b/src/hid_core/resources/palma/palma.cpp
@@ -56,12 +56,14 @@ Kernel::KReadableEvent& Palma::AcquirePalmaOperationCompleteEvent(
56 56
57Result Palma::GetPalmaOperationInfo(const PalmaConnectionHandle& handle, 57Result Palma::GetPalmaOperationInfo(const PalmaConnectionHandle& handle,
58 PalmaOperationType& operation_type, 58 PalmaOperationType& operation_type,
59 PalmaOperationData& data) const { 59 std::span<u8> out_data) const {
60 if (handle.npad_id != active_handle.npad_id) { 60 if (handle.npad_id != active_handle.npad_id) {
61 return InvalidPalmaHandle; 61 return InvalidPalmaHandle;
62 } 62 }
63 operation_type = operation.operation; 63 operation_type = static_cast<PalmaOperationType>(operation.operation);
64 data = operation.data; 64 std::memcpy(out_data.data(), operation.data.data(),
65 std::min(out_data.size(), operation.data.size()));
66
65 return ResultSuccess; 67 return ResultSuccess;
66} 68}
67 69
@@ -69,7 +71,7 @@ Result Palma::PlayPalmaActivity(const PalmaConnectionHandle& handle, u64 palma_a
69 if (handle.npad_id != active_handle.npad_id) { 71 if (handle.npad_id != active_handle.npad_id) {
70 return InvalidPalmaHandle; 72 return InvalidPalmaHandle;
71 } 73 }
72 operation.operation = PalmaOperationType::PlayActivity; 74 operation.operation = PackedPalmaOperationType::PlayActivity;
73 operation.result = PalmaResultSuccess; 75 operation.result = PalmaResultSuccess;
74 operation.data = {}; 76 operation.data = {};
75 operation_complete_event->Signal(); 77 operation_complete_event->Signal();
@@ -88,7 +90,7 @@ Result Palma::ReadPalmaStep(const PalmaConnectionHandle& handle) {
88 if (handle.npad_id != active_handle.npad_id) { 90 if (handle.npad_id != active_handle.npad_id) {
89 return InvalidPalmaHandle; 91 return InvalidPalmaHandle;
90 } 92 }
91 operation.operation = PalmaOperationType::ReadStep; 93 operation.operation = PackedPalmaOperationType::ReadStep;
92 operation.result = PalmaResultSuccess; 94 operation.result = PalmaResultSuccess;
93 operation.data = {}; 95 operation.data = {};
94 operation_complete_event->Signal(); 96 operation_complete_event->Signal();
@@ -117,7 +119,7 @@ Result Palma::ReadPalmaUniqueCode(const PalmaConnectionHandle& handle) {
117 if (handle.npad_id != active_handle.npad_id) { 119 if (handle.npad_id != active_handle.npad_id) {
118 return InvalidPalmaHandle; 120 return InvalidPalmaHandle;
119 } 121 }
120 operation.operation = PalmaOperationType::ReadUniqueCode; 122 operation.operation = PackedPalmaOperationType::ReadUniqueCode;
121 operation.result = PalmaResultSuccess; 123 operation.result = PalmaResultSuccess;
122 operation.data = {}; 124 operation.data = {};
123 operation_complete_event->Signal(); 125 operation_complete_event->Signal();
@@ -128,7 +130,7 @@ Result Palma::SetPalmaUniqueCodeInvalid(const PalmaConnectionHandle& handle) {
128 if (handle.npad_id != active_handle.npad_id) { 130 if (handle.npad_id != active_handle.npad_id) {
129 return InvalidPalmaHandle; 131 return InvalidPalmaHandle;
130 } 132 }
131 operation.operation = PalmaOperationType::SetUniqueCodeInvalid; 133 operation.operation = PackedPalmaOperationType::SetUniqueCodeInvalid;
132 operation.result = PalmaResultSuccess; 134 operation.result = PalmaResultSuccess;
133 operation.data = {}; 135 operation.data = {};
134 operation_complete_event->Signal(); 136 operation_complete_event->Signal();
@@ -141,7 +143,7 @@ Result Palma::WritePalmaRgbLedPatternEntry(const PalmaConnectionHandle& handle,
141 if (handle.npad_id != active_handle.npad_id) { 143 if (handle.npad_id != active_handle.npad_id) {
142 return InvalidPalmaHandle; 144 return InvalidPalmaHandle;
143 } 145 }
144 operation.operation = PalmaOperationType::WriteRgbLedPatternEntry; 146 operation.operation = PackedPalmaOperationType::WriteRgbLedPatternEntry;
145 operation.result = PalmaResultSuccess; 147 operation.result = PalmaResultSuccess;
146 operation.data = {}; 148 operation.data = {};
147 operation_complete_event->Signal(); 149 operation_complete_event->Signal();
@@ -153,7 +155,7 @@ Result Palma::WritePalmaWaveEntry(const PalmaConnectionHandle& handle, PalmaWave
153 if (handle.npad_id != active_handle.npad_id) { 155 if (handle.npad_id != active_handle.npad_id) {
154 return InvalidPalmaHandle; 156 return InvalidPalmaHandle;
155 } 157 }
156 operation.operation = PalmaOperationType::WriteWaveEntry; 158 operation.operation = PackedPalmaOperationType::WriteWaveEntry;
157 operation.result = PalmaResultSuccess; 159 operation.result = PalmaResultSuccess;
158 operation.data = {}; 160 operation.data = {};
159 operation_complete_event->Signal(); 161 operation_complete_event->Signal();
@@ -166,7 +168,7 @@ Result Palma::SetPalmaDataBaseIdentificationVersion(const PalmaConnectionHandle&
166 return InvalidPalmaHandle; 168 return InvalidPalmaHandle;
167 } 169 }
168 database_id_version = database_id_version_; 170 database_id_version = database_id_version_;
169 operation.operation = PalmaOperationType::ReadDataBaseIdentificationVersion; 171 operation.operation = PackedPalmaOperationType::ReadDataBaseIdentificationVersion;
170 operation.result = PalmaResultSuccess; 172 operation.result = PalmaResultSuccess;
171 operation.data[0] = {}; 173 operation.data[0] = {};
172 operation_complete_event->Signal(); 174 operation_complete_event->Signal();
@@ -177,7 +179,7 @@ Result Palma::GetPalmaDataBaseIdentificationVersion(const PalmaConnectionHandle&
177 if (handle.npad_id != active_handle.npad_id) { 179 if (handle.npad_id != active_handle.npad_id) {
178 return InvalidPalmaHandle; 180 return InvalidPalmaHandle;
179 } 181 }
180 operation.operation = PalmaOperationType::ReadDataBaseIdentificationVersion; 182 operation.operation = PackedPalmaOperationType::ReadDataBaseIdentificationVersion;
181 operation.result = PalmaResultSuccess; 183 operation.result = PalmaResultSuccess;
182 operation.data = {}; 184 operation.data = {};
183 operation.data[0] = static_cast<u8>(database_id_version); 185 operation.data[0] = static_cast<u8>(database_id_version);
diff --git a/src/hid_core/resources/palma/palma.h b/src/hid_core/resources/palma/palma.h
index 60259c3d8..477cbf904 100644
--- a/src/hid_core/resources/palma/palma.h
+++ b/src/hid_core/resources/palma/palma.h
@@ -4,6 +4,8 @@
4#pragma once 4#pragma once
5 5
6#include <array> 6#include <array>
7#include <span>
8
7#include "common/common_funcs.h" 9#include "common/common_funcs.h"
8#include "common/typed_address.h" 10#include "common/typed_address.h"
9#include "hid_core/hid_result.h" 11#include "hid_core/hid_result.h"
@@ -27,9 +29,31 @@ namespace Service::HID {
27class Palma final : public ControllerBase { 29class Palma final : public ControllerBase {
28public: 30public:
29 using PalmaOperationData = std::array<u8, 0x140>; 31 using PalmaOperationData = std::array<u8, 0x140>;
32 using PalmaApplicationSection = std::array<u8, 0x100>;
33 using Address = std::array<u8, 0x6>;
30 34
31 // This is nn::hid::PalmaOperationType 35 // This is nn::hid::PalmaOperationType
32 enum class PalmaOperationType { 36 enum class PalmaOperationType : u64 {
37 PlayActivity,
38 SetFrModeType,
39 ReadStep,
40 EnableStep,
41 ResetStep,
42 ReadApplicationSection,
43 WriteApplicationSection,
44 ReadUniqueCode,
45 SetUniqueCodeInvalid,
46 WriteActivityEntry,
47 WriteRgbLedPatternEntry,
48 WriteWaveEntry,
49 ReadDataBaseIdentificationVersion,
50 WriteDataBaseIdentificationVersion,
51 SuspendFeature,
52 ReadPlayLog,
53 ResetPlayLog,
54 };
55
56 enum class PackedPalmaOperationType : u32 {
33 PlayActivity, 57 PlayActivity,
34 SetFrModeType, 58 SetFrModeType,
35 ReadStep, 59 ReadStep,
@@ -75,7 +99,7 @@ public:
75 99
76 // This is nn::hid::PalmaOperationInfo 100 // This is nn::hid::PalmaOperationInfo
77 struct PalmaOperationInfo { 101 struct PalmaOperationInfo {
78 PalmaOperationType operation{}; 102 PackedPalmaOperationType operation{};
79 Result result{PalmaResultSuccess}; 103 Result result{PalmaResultSuccess};
80 PalmaOperationData data{}; 104 PalmaOperationData data{};
81 }; 105 };
@@ -92,8 +116,7 @@ public:
92 static_assert(sizeof(PalmaActivityEntry) == 0x20, "PalmaActivityEntry is an invalid size"); 116 static_assert(sizeof(PalmaActivityEntry) == 0x20, "PalmaActivityEntry is an invalid size");
93 117
94 struct PalmaConnectionHandle { 118 struct PalmaConnectionHandle {
95 Core::HID::NpadIdType npad_id; 119 alignas(8) Core::HID::NpadIdType npad_id;
96 INSERT_PADDING_BYTES(4); // Unknown
97 }; 120 };
98 static_assert(sizeof(PalmaConnectionHandle) == 0x8, 121 static_assert(sizeof(PalmaConnectionHandle) == 0x8,
99 "PalmaConnectionHandle has incorrect size."); 122 "PalmaConnectionHandle has incorrect size.");
@@ -115,8 +138,7 @@ public:
115 Kernel::KReadableEvent& AcquirePalmaOperationCompleteEvent( 138 Kernel::KReadableEvent& AcquirePalmaOperationCompleteEvent(
116 const PalmaConnectionHandle& handle) const; 139 const PalmaConnectionHandle& handle) const;
117 Result GetPalmaOperationInfo(const PalmaConnectionHandle& handle, 140 Result GetPalmaOperationInfo(const PalmaConnectionHandle& handle,
118 PalmaOperationType& operation_type, 141 PalmaOperationType& operation_type, std::span<u8> out_data) const;
119 PalmaOperationData& data) const;
120 Result PlayPalmaActivity(const PalmaConnectionHandle& handle, u64 palma_activity); 142 Result PlayPalmaActivity(const PalmaConnectionHandle& handle, u64 palma_activity);
121 Result SetPalmaFrModeType(const PalmaConnectionHandle& handle, PalmaFrModeType fr_mode_); 143 Result SetPalmaFrModeType(const PalmaConnectionHandle& handle, PalmaFrModeType fr_mode_);
122 Result ReadPalmaStep(const PalmaConnectionHandle& handle); 144 Result ReadPalmaStep(const PalmaConnectionHandle& handle);