summaryrefslogtreecommitdiffstats
path: root/src/input_common/helpers/joycon_protocol/common_protocol.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/helpers/joycon_protocol/common_protocol.h')
-rw-r--r--src/input_common/helpers/joycon_protocol/common_protocol.h21
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:
* @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