diff options
| author | 2023-01-27 13:12:54 -0600 | |
|---|---|---|
| committer | 2023-01-27 17:12:04 -0600 | |
| commit | 8647c727781accf79fe78c19eeee9acdb24f2927 (patch) | |
| tree | b72ad4638850786d36b7568be6cd1a933c518dd1 /src/input_common/helpers/joycon_protocol/common_protocol.h | |
| parent | Merge pull request #9685 from liamwhite/minmax (diff) | |
| download | yuzu-8647c727781accf79fe78c19eeee9acdb24f2927.tar.gz yuzu-8647c727781accf79fe78c19eeee9acdb24f2927.tar.xz yuzu-8647c727781accf79fe78c19eeee9acdb24f2927.zip | |
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 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 |