input_common: joycon: Remove magic numbers from calibration protocol

This commit is contained in:
Narr the Reg 2023-01-27 13:12:54 -06:00
parent 55da8e8ed8
commit f20ec6f69b
6 changed files with 203 additions and 108 deletions

View file

@ -100,7 +100,26 @@ public:
* @param size in bytes to be read
* @returns output buffer containing the responce
*/
DriverResult ReadSPI(CalAddr addr, u8 size, std::vector<u8>& output);
DriverResult ReadSPI(SpiAddress addr, u8 size, std::vector<u8>& output);
template <typename Output>
requires(std::is_trivially_copyable_v<Output>)
DriverResult ReadSPI(SpiAddress addr, Output& output) {
std::vector<u8> buffer;
output = {};
const auto result = ReadSPI(addr, sizeof(Output), buffer);
if (result != DriverResult::Success) {
return result;
}
if (buffer.size() != sizeof(Output)) {
return DriverResult::WrongReply;
}
std::memcpy(&output, buffer.data(), sizeof(Output));
return DriverResult::Success;
}
/**
* Enables MCU chip on the joycon