diff options
author | Narr the Reg <juangerman-13@hotmail.com> | 2024-02-07 23:43:28 +0100 |
---|---|---|
committer | Narr the Reg <juangerman-13@hotmail.com> | 2024-02-08 01:07:32 +0100 |
commit | b4d88a7bb406c033c3cd5c6bca6ce913fac1bcdd (patch) | |
tree | 1e1dd7aa5bc3f544316c744cf1f28f508becb6a9 /src/hid_core/hidbus | |
parent | Merge pull request #12883 from FernandoS27/memory_manager_mem (diff) | |
download | yuzu-b4d88a7bb406c033c3cd5c6bca6ce913fac1bcdd.tar yuzu-b4d88a7bb406c033c3cd5c6bca6ce913fac1bcdd.tar.gz yuzu-b4d88a7bb406c033c3cd5c6bca6ce913fac1bcdd.tar.bz2 yuzu-b4d88a7bb406c033c3cd5c6bca6ce913fac1bcdd.tar.lz yuzu-b4d88a7bb406c033c3cd5c6bca6ce913fac1bcdd.tar.xz yuzu-b4d88a7bb406c033c3cd5c6bca6ce913fac1bcdd.tar.zst yuzu-b4d88a7bb406c033c3cd5c6bca6ce913fac1bcdd.zip |
Diffstat (limited to 'src/hid_core/hidbus')
-rw-r--r-- | src/hid_core/hidbus/hidbus_base.h | 2 | ||||
-rw-r--r-- | src/hid_core/hidbus/ringcon.cpp | 77 | ||||
-rw-r--r-- | src/hid_core/hidbus/ringcon.h | 26 | ||||
-rw-r--r-- | src/hid_core/hidbus/starlink.cpp | 2 | ||||
-rw-r--r-- | src/hid_core/hidbus/starlink.h | 2 | ||||
-rw-r--r-- | src/hid_core/hidbus/stubbed.cpp | 2 | ||||
-rw-r--r-- | src/hid_core/hidbus/stubbed.h | 2 |
7 files changed, 56 insertions, 57 deletions
diff --git a/src/hid_core/hidbus/hidbus_base.h b/src/hid_core/hidbus/hidbus_base.h index ec41684e1..c948606e4 100644 --- a/src/hid_core/hidbus/hidbus_base.h +++ b/src/hid_core/hidbus/hidbus_base.h @@ -160,7 +160,7 @@ public: } // Returns a reply from a command - virtual std::vector<u8> GetReply() const { + virtual u64 GetReply(std::span<u8> out_data) const { return {}; } diff --git a/src/hid_core/hidbus/ringcon.cpp b/src/hid_core/hidbus/ringcon.cpp index cedf25c16..4f5eaa505 100644 --- a/src/hid_core/hidbus/ringcon.cpp +++ b/src/hid_core/hidbus/ringcon.cpp @@ -90,32 +90,32 @@ u8 RingController::GetDeviceId() const { return device_id; } -std::vector<u8> RingController::GetReply() const { +u64 RingController::GetReply(std::span<u8> out_data) const { const RingConCommands current_command = command; switch (current_command) { case RingConCommands::GetFirmwareVersion: - return GetFirmwareVersionReply(); + return GetFirmwareVersionReply(out_data); case RingConCommands::ReadId: - return GetReadIdReply(); + return GetReadIdReply(out_data); case RingConCommands::c20105: - return GetC020105Reply(); + return GetC020105Reply(out_data); case RingConCommands::ReadUnkCal: - return GetReadUnkCalReply(); + return GetReadUnkCalReply(out_data); case RingConCommands::ReadFactoryCal: - return GetReadFactoryCalReply(); + return GetReadFactoryCalReply(out_data); case RingConCommands::ReadUserCal: - return GetReadUserCalReply(); + return GetReadUserCalReply(out_data); case RingConCommands::ReadRepCount: - return GetReadRepCountReply(); + return GetReadRepCountReply(out_data); case RingConCommands::ReadTotalPushCount: - return GetReadTotalPushCountReply(); + return GetReadTotalPushCountReply(out_data); case RingConCommands::ResetRepCount: - return GetResetRepCountReply(); + return GetResetRepCountReply(out_data); case RingConCommands::SaveCalData: - return GetSaveDataReply(); + return GetSaveDataReply(out_data); default: - return GetErrorReply(); + return GetErrorReply(out_data); } } @@ -163,16 +163,16 @@ bool RingController::SetCommand(std::span<const u8> data) { } } -std::vector<u8> RingController::GetFirmwareVersionReply() const { +u64 RingController::GetFirmwareVersionReply(std::span<u8> out_data) const { const FirmwareVersionReply reply{ .status = DataValid::Valid, .firmware = version, }; - return GetDataVector(reply); + return GetData(reply, out_data); } -std::vector<u8> RingController::GetReadIdReply() const { +u64 RingController::GetReadIdReply(std::span<u8> out_data) const { // The values are hardcoded from a real joycon const ReadIdReply reply{ .status = DataValid::Valid, @@ -184,83 +184,83 @@ std::vector<u8> RingController::GetReadIdReply() const { .id_h_x4 = 8245, }; - return GetDataVector(reply); + return GetData(reply, out_data); } -std::vector<u8> RingController::GetC020105Reply() const { +u64 RingController::GetC020105Reply(std::span<u8> out_data) const { const Cmd020105Reply reply{ .status = DataValid::Valid, .data = 1, }; - return GetDataVector(reply); + return GetData(reply, out_data); } -std::vector<u8> RingController::GetReadUnkCalReply() const { +u64 RingController::GetReadUnkCalReply(std::span<u8> out_data) const { const ReadUnkCalReply reply{ .status = DataValid::Valid, .data = 0, }; - return GetDataVector(reply); + return GetData(reply, out_data); } -std::vector<u8> RingController::GetReadFactoryCalReply() const { +u64 RingController::GetReadFactoryCalReply(std::span<u8> out_data) const { const ReadFactoryCalReply reply{ .status = DataValid::Valid, .calibration = factory_calibration, }; - return GetDataVector(reply); + return GetData(reply, out_data); } -std::vector<u8> RingController::GetReadUserCalReply() const { +u64 RingController::GetReadUserCalReply(std::span<u8> out_data) const { const ReadUserCalReply reply{ .status = DataValid::Valid, .calibration = user_calibration, }; - return GetDataVector(reply); + return GetData(reply, out_data); } -std::vector<u8> RingController::GetReadRepCountReply() const { +u64 RingController::GetReadRepCountReply(std::span<u8> out_data) const { const GetThreeByteReply reply{ .status = DataValid::Valid, .data = {total_rep_count, 0, 0}, .crc = GetCrcValue({total_rep_count, 0, 0, 0}), }; - return GetDataVector(reply); + return GetData(reply, out_data); } -std::vector<u8> RingController::GetReadTotalPushCountReply() const { +u64 RingController::GetReadTotalPushCountReply(std::span<u8> out_data) const { const GetThreeByteReply reply{ .status = DataValid::Valid, .data = {total_push_count, 0, 0}, .crc = GetCrcValue({total_push_count, 0, 0, 0}), }; - return GetDataVector(reply); + return GetData(reply, out_data); } -std::vector<u8> RingController::GetResetRepCountReply() const { - return GetReadRepCountReply(); +u64 RingController::GetResetRepCountReply(std::span<u8> out_data) const { + return GetReadRepCountReply(out_data); } -std::vector<u8> RingController::GetSaveDataReply() const { +u64 RingController::GetSaveDataReply(std::span<u8> out_data) const { const StatusReply reply{ .status = DataValid::Valid, }; - return GetDataVector(reply); + return GetData(reply, out_data); } -std::vector<u8> RingController::GetErrorReply() const { +u64 RingController::GetErrorReply(std::span<u8> out_data) const { const ErrorReply reply{ .status = DataValid::BadCRC, }; - return GetDataVector(reply); + return GetData(reply, out_data); } u8 RingController::GetCrcValue(const std::vector<u8>& data) const { @@ -281,12 +281,11 @@ u8 RingController::GetCrcValue(const std::vector<u8>& data) const { } template <typename T> -std::vector<u8> RingController::GetDataVector(const T& reply) const { +u64 RingController::GetData(const T& reply, std::span<u8> out_data) const { static_assert(std::is_trivially_copyable_v<T>); - std::vector<u8> data; - data.resize(sizeof(reply)); - std::memcpy(data.data(), &reply, sizeof(reply)); - return data; + const auto data_size = static_cast<u64>(std::min(sizeof(reply), out_data.size())); + std::memcpy(out_data.data(), &reply, data_size); + return data_size; } } // namespace Service::HID diff --git a/src/hid_core/hidbus/ringcon.h b/src/hid_core/hidbus/ringcon.h index 0953e8100..a48eeed45 100644 --- a/src/hid_core/hidbus/ringcon.h +++ b/src/hid_core/hidbus/ringcon.h @@ -34,7 +34,7 @@ public: bool SetCommand(std::span<const u8> data) override; // Returns a reply from a command - std::vector<u8> GetReply() const override; + u64 GetReply(std::span<u8> data) const override; private: // These values are obtained from a real ring controller @@ -184,44 +184,44 @@ private: RingConData GetSensorValue() const; // Returns 8 byte reply with firmware version - std::vector<u8> GetFirmwareVersionReply() const; + u64 GetFirmwareVersionReply(std::span<u8> out_data) const; // Returns 16 byte reply with ID values - std::vector<u8> GetReadIdReply() const; + u64 GetReadIdReply(std::span<u8> out_data) const; // (STUBBED) Returns 8 byte reply - std::vector<u8> GetC020105Reply() const; + u64 GetC020105Reply(std::span<u8> out_data) const; // (STUBBED) Returns 8 byte empty reply - std::vector<u8> GetReadUnkCalReply() const; + u64 GetReadUnkCalReply(std::span<u8> out_data) const; // Returns 20 byte reply with factory calibration values - std::vector<u8> GetReadFactoryCalReply() const; + u64 GetReadFactoryCalReply(std::span<u8> out_data) const; // Returns 20 byte reply with user calibration values - std::vector<u8> GetReadUserCalReply() const; + u64 GetReadUserCalReply(std::span<u8> out_data) const; // Returns 8 byte reply - std::vector<u8> GetReadRepCountReply() const; + u64 GetReadRepCountReply(std::span<u8> out_data) const; // Returns 8 byte reply - std::vector<u8> GetReadTotalPushCountReply() const; + u64 GetReadTotalPushCountReply(std::span<u8> out_data) const; // Returns 8 byte reply - std::vector<u8> GetResetRepCountReply() const; + u64 GetResetRepCountReply(std::span<u8> out_data) const; // Returns 4 byte save data reply - std::vector<u8> GetSaveDataReply() const; + u64 GetSaveDataReply(std::span<u8> out_data) const; // Returns 8 byte error reply - std::vector<u8> GetErrorReply() const; + u64 GetErrorReply(std::span<u8> out_data) const; // Returns 8 bit redundancy check from provided data u8 GetCrcValue(const std::vector<u8>& data) const; // Converts structs to an u8 vector equivalent template <typename T> - std::vector<u8> GetDataVector(const T& reply) const; + u64 GetData(const T& reply, std::span<u8> out_data) const; RingConCommands command{RingConCommands::Error}; diff --git a/src/hid_core/hidbus/starlink.cpp b/src/hid_core/hidbus/starlink.cpp index 31b263aa1..1c4df1d8c 100644 --- a/src/hid_core/hidbus/starlink.cpp +++ b/src/hid_core/hidbus/starlink.cpp @@ -38,7 +38,7 @@ u8 Starlink::GetDeviceId() const { return DEVICE_ID; } -std::vector<u8> Starlink::GetReply() const { +u64 Starlink::GetReply(std::span<u8> out_data) const { return {}; } diff --git a/src/hid_core/hidbus/starlink.h b/src/hid_core/hidbus/starlink.h index ee37763b4..695b69748 100644 --- a/src/hid_core/hidbus/starlink.h +++ b/src/hid_core/hidbus/starlink.h @@ -31,7 +31,7 @@ public: bool SetCommand(std::span<const u8> data) override; // Returns a reply from a command - std::vector<u8> GetReply() const override; + u64 GetReply(std::span<u8> out_data) const override; }; } // namespace Service::HID diff --git a/src/hid_core/hidbus/stubbed.cpp b/src/hid_core/hidbus/stubbed.cpp index f16051aa9..658922a4f 100644 --- a/src/hid_core/hidbus/stubbed.cpp +++ b/src/hid_core/hidbus/stubbed.cpp @@ -38,7 +38,7 @@ u8 HidbusStubbed::GetDeviceId() const { return DEVICE_ID; } -std::vector<u8> HidbusStubbed::GetReply() const { +u64 HidbusStubbed::GetReply(std::span<u8> out_data) const { return {}; } diff --git a/src/hid_core/hidbus/stubbed.h b/src/hid_core/hidbus/stubbed.h index 7a711cea0..f05280b3a 100644 --- a/src/hid_core/hidbus/stubbed.h +++ b/src/hid_core/hidbus/stubbed.h @@ -31,7 +31,7 @@ public: bool SetCommand(std::span<const u8> data) override; // Returns a reply from a command - std::vector<u8> GetReply() const override; + u64 GetReply(std::span<u8> out_data) const override; }; } // namespace Service::HID |