diff options
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 2f0ab6b2a..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() { | |||
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | DriverResult JoyconCommonProtocol::GetDeviceType(ControllerType& controller_type) { | 24 | DriverResult JoyconCommonProtocol::GetDeviceType(ControllerType& controller_type) { |
| 25 | std::vector<u8> buffer; | 25 | std::array<u8, 1> buffer{}; |
| 26 | const auto result = ReadSPI(SpiAddress::DEVICE_TYPE, 1, buffer); | 26 | const auto result = ReadRawSPI(SpiAddress::DEVICE_TYPE, buffer); |
| 27 | controller_type = ControllerType::None; | 27 | controller_type = ControllerType::None; |
| 28 | 28 | ||
| 29 | if (result == DriverResult::Success) { | 29 | if (result == DriverResult::Success) { |
| @@ -148,11 +148,13 @@ DriverResult JoyconCommonProtocol::SendVibrationReport(std::span<const u8> buffe | |||
| 148 | return SendData(local_buffer); | 148 | return SendData(local_buffer); |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | DriverResult JoyconCommonProtocol::ReadSPI(SpiAddress addr, u8 size, std::vector<u8>& output) { | 151 | DriverResult JoyconCommonProtocol::ReadRawSPI(SpiAddress addr, std::span<u8> output) { |
| 152 | constexpr std::size_t HeaderSize = 20; | ||
| 152 | constexpr std::size_t MaxTries = 10; | 153 | constexpr std::size_t MaxTries = 10; |
| 154 | const auto size = output.size(); | ||
| 153 | std::size_t tries = 0; | 155 | std::size_t tries = 0; |
| 154 | std::array<u8, 5> buffer = {0x00, 0x00, 0x00, 0x00, size}; | 156 | std::array<u8, 5> buffer = {0x00, 0x00, 0x00, 0x00, static_cast<u8>(size)}; |
| 155 | std::vector<u8> local_buffer(size + 20); | 157 | std::vector<u8> local_buffer{}; |
| 156 | 158 | ||
| 157 | buffer[0] = static_cast<u8>(static_cast<u16>(addr) & 0x00FF); | 159 | buffer[0] = static_cast<u8>(static_cast<u16>(addr) & 0x00FF); |
| 158 | buffer[1] = static_cast<u8>((static_cast<u16>(addr) & 0xFF00) >> 8); | 160 | buffer[1] = static_cast<u8>((static_cast<u16>(addr) & 0xFF00) >> 8); |
| @@ -167,8 +169,12 @@ DriverResult JoyconCommonProtocol::ReadSPI(SpiAddress addr, u8 size, std::vector | |||
| 167 | } | 169 | } |
| 168 | } while (local_buffer[15] != buffer[0] || local_buffer[16] != buffer[1]); | 170 | } while (local_buffer[15] != buffer[0] || local_buffer[16] != buffer[1]); |
| 169 | 171 | ||
| 172 | if (local_buffer.size() < size + HeaderSize) { | ||
| 173 | return DriverResult::WrongReply; | ||
| 174 | } | ||
| 175 | |||
| 170 | // Remove header from output | 176 | // Remove header from output |
| 171 | output = std::vector<u8>(local_buffer.begin() + 20, local_buffer.begin() + 20 + size); | 177 | memcpy(output.data(), local_buffer.data() + HeaderSize, size); |
| 172 | return DriverResult::Success; | 178 | return DriverResult::Success; |
| 173 | } | 179 | } |
| 174 | 180 | ||