diff options
author | bunnei <bunneidev@gmail.com> | 2023-01-29 11:43:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-29 11:43:14 +0100 |
commit | 9170387e71d4295477b74666a843a889af62b2a3 (patch) | |
tree | ee08cde9257dc4c77943b7566ee678ed8317eec2 /src/input_common/helpers/joycon_protocol/common_protocol.cpp | |
parent | Merge pull request #9691 from ameerj/msaa-texcache (diff) | |
parent | input_common: joycon: Replace ReadSPI vector with span (diff) | |
download | yuzu-9170387e71d4295477b74666a843a889af62b2a3.tar yuzu-9170387e71d4295477b74666a843a889af62b2a3.tar.gz yuzu-9170387e71d4295477b74666a843a889af62b2a3.tar.bz2 yuzu-9170387e71d4295477b74666a843a889af62b2a3.tar.lz yuzu-9170387e71d4295477b74666a843a889af62b2a3.tar.xz yuzu-9170387e71d4295477b74666a843a889af62b2a3.tar.zst yuzu-9170387e71d4295477b74666a843a889af62b2a3.zip |
Diffstat (limited to 'src/input_common/helpers/joycon_protocol/common_protocol.cpp')
-rw-r--r-- | src/input_common/helpers/joycon_protocol/common_protocol.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/input_common/helpers/joycon_protocol/common_protocol.cpp b/src/input_common/helpers/joycon_protocol/common_protocol.cpp index 417d0dcc5..0ef240344 100644 --- a/src/input_common/helpers/joycon_protocol/common_protocol.cpp +++ b/src/input_common/helpers/joycon_protocol/common_protocol.cpp @@ -22,8 +22,8 @@ void JoyconCommonProtocol::SetNonBlocking() { } DriverResult JoyconCommonProtocol::GetDeviceType(ControllerType& controller_type) { - std::vector<u8> buffer; - const auto result = ReadSPI(CalAddr::DEVICE_TYPE, 1, buffer); + std::array<u8, 1> buffer{}; + const auto result = ReadRawSPI(SpiAddress::DEVICE_TYPE, buffer); controller_type = ControllerType::None; if (result == DriverResult::Success) { @@ -148,11 +148,13 @@ DriverResult JoyconCommonProtocol::SendVibrationReport(std::span<const u8> buffe return SendData(local_buffer); } -DriverResult JoyconCommonProtocol::ReadSPI(CalAddr addr, u8 size, std::vector<u8>& output) { +DriverResult JoyconCommonProtocol::ReadRawSPI(SpiAddress addr, std::span<u8> output) { + constexpr std::size_t HeaderSize = 20; constexpr std::size_t MaxTries = 10; + const auto size = output.size(); std::size_t tries = 0; - std::array<u8, 5> buffer = {0x00, 0x00, 0x00, 0x00, size}; - std::vector<u8> local_buffer(size + 20); + std::array<u8, 5> buffer = {0x00, 0x00, 0x00, 0x00, static_cast<u8>(size)}; + std::vector<u8> local_buffer{}; buffer[0] = static_cast<u8>(static_cast<u16>(addr) & 0x00FF); buffer[1] = static_cast<u8>((static_cast<u16>(addr) & 0xFF00) >> 8); @@ -167,8 +169,12 @@ DriverResult JoyconCommonProtocol::ReadSPI(CalAddr addr, u8 size, std::vector<u8 } } while (local_buffer[15] != buffer[0] || local_buffer[16] != buffer[1]); + if (local_buffer.size() < size + HeaderSize) { + return DriverResult::WrongReply; + } + // Remove header from output - output = std::vector<u8>(local_buffer.begin() + 20, local_buffer.begin() + 20 + size); + memcpy(output.data(), local_buffer.data() + HeaderSize, size); return DriverResult::Success; } |