diff options
author | Narr the Reg <juangerman-13@hotmail.com> | 2023-01-27 13:12:54 -0600 |
---|---|---|
committer | Narr the Reg <juangerman-13@hotmail.com> | 2023-01-27 17:12:04 -0600 |
commit | 8647c727781accf79fe78c19eeee9acdb24f2927 (patch) | |
tree | b72ad4638850786d36b7568be6cd1a933c518dd1 /src/input_common/helpers/joycon_protocol/common_protocol.h | |
parent | e54d08fc1fa79f6c0e66f2e2ef06f21ca36cf881 (diff) |
input_common: joycon: Remove magic numbers from calibration protocol
Diffstat (limited to 'src/input_common/helpers/joycon_protocol/common_protocol.h')
-rw-r--r-- | src/input_common/helpers/joycon_protocol/common_protocol.h | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/input_common/helpers/joycon_protocol/common_protocol.h b/src/input_common/helpers/joycon_protocol/common_protocol.h index 903bcf4025..675eacf68b 100644 --- a/src/input_common/helpers/joycon_protocol/common_protocol.h +++ b/src/input_common/helpers/joycon_protocol/common_protocol.h @@ -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 |