summaryrefslogtreecommitdiff
path: root/src/input_common/helpers/joycon_protocol/common_protocol.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2023-01-29 02:43:14 -0800
committerGravatar GitHub2023-01-29 02:43:14 -0800
commit9170387e71d4295477b74666a843a889af62b2a3 (patch)
treeee08cde9257dc4c77943b7566ee678ed8317eec2 /src/input_common/helpers/joycon_protocol/common_protocol.cpp
parentMerge pull request #9691 from ameerj/msaa-texcache (diff)
parentinput_common: joycon: Replace ReadSPI vector with span (diff)
downloadyuzu-9170387e71d4295477b74666a843a889af62b2a3.tar.gz
yuzu-9170387e71d4295477b74666a843a889af62b2a3.tar.xz
yuzu-9170387e71d4295477b74666a843a889af62b2a3.zip
Merge pull request #9689 from german77/joycon-calibration
input_common: joycon: Remove magic numbers from calibration protocol
Diffstat (limited to 'src/input_common/helpers/joycon_protocol/common_protocol.cpp')
-rw-r--r--src/input_common/helpers/joycon_protocol/common_protocol.cpp18
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() {
22} 22}
23 23
24DriverResult JoyconCommonProtocol::GetDeviceType(ControllerType& controller_type) { 24DriverResult JoyconCommonProtocol::GetDeviceType(ControllerType& controller_type) {
25 std::vector<u8> buffer; 25 std::array<u8, 1> buffer{};
26 const auto result = ReadSPI(CalAddr::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
151DriverResult JoyconCommonProtocol::ReadSPI(CalAddr addr, u8 size, std::vector<u8>& output) { 151DriverResult 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(CalAddr addr, u8 size, std::vector<u8
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