diff options
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 903bcf402..675eacf68 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: | |||
| 100 | * @param size in bytes to be read | 100 | * @param size in bytes to be read |
| 101 | * @returns output buffer containing the responce | 101 | * @returns output buffer containing the responce |
| 102 | */ | 102 | */ |
| 103 | DriverResult ReadSPI(CalAddr addr, u8 size, std::vector<u8>& output); | 103 | DriverResult ReadSPI(SpiAddress addr, u8 size, std::vector<u8>& output); |
| 104 | |||
| 105 | template <typename Output> | ||
| 106 | requires(std::is_trivially_copyable_v<Output>) | ||
| 107 | DriverResult ReadSPI(SpiAddress addr, Output& output) { | ||
| 108 | std::vector<u8> buffer; | ||
| 109 | output = {}; | ||
| 110 | |||
| 111 | const auto result = ReadSPI(addr, sizeof(Output), buffer); | ||
| 112 | if (result != DriverResult::Success) { | ||
| 113 | return result; | ||
| 114 | } | ||
| 115 | |||
| 116 | if (buffer.size() != sizeof(Output)) { | ||
| 117 | return DriverResult::WrongReply; | ||
| 118 | } | ||
| 119 | |||
| 120 | std::memcpy(&output, buffer.data(), sizeof(Output)); | ||
| 121 | return DriverResult::Success; | ||
| 122 | } | ||
| 104 | 123 | ||
| 105 | /** | 124 | /** |
| 106 | * Enables MCU chip on the joycon | 125 | * Enables MCU chip on the joycon |