diff options
| author | 2023-06-28 00:20:38 -0600 | |
|---|---|---|
| committer | 2023-06-28 09:49:47 -0600 | |
| commit | df9685a21c105962e90dbd95133c5a1bcef7886f (patch) | |
| tree | acfd98ca20286dca669077b165943f6c4af711a6 /src/input_common/helpers/joycon_protocol/irs.cpp | |
| parent | Merge pull request #10933 from merryhime/dunno (diff) | |
| download | yuzu-df9685a21c105962e90dbd95133c5a1bcef7886f.tar.gz yuzu-df9685a21c105962e90dbd95133c5a1bcef7886f.tar.xz yuzu-df9685a21c105962e90dbd95133c5a1bcef7886f.zip | |
input_common: Remove duplicated DriverResult enum
Diffstat (limited to 'src/input_common/helpers/joycon_protocol/irs.cpp')
| -rw-r--r-- | src/input_common/helpers/joycon_protocol/irs.cpp | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/src/input_common/helpers/joycon_protocol/irs.cpp b/src/input_common/helpers/joycon_protocol/irs.cpp index 731fd5981..68b0589e3 100644 --- a/src/input_common/helpers/joycon_protocol/irs.cpp +++ b/src/input_common/helpers/joycon_protocol/irs.cpp | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project | 1 | // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include <thread> | 4 | #include "common/input.h" |
| 5 | #include "common/logging/log.h" | 5 | #include "common/logging/log.h" |
| 6 | #include "input_common/helpers/joycon_protocol/irs.h" | 6 | #include "input_common/helpers/joycon_protocol/irs.h" |
| 7 | 7 | ||
| @@ -10,21 +10,21 @@ namespace InputCommon::Joycon { | |||
| 10 | IrsProtocol::IrsProtocol(std::shared_ptr<JoyconHandle> handle) | 10 | IrsProtocol::IrsProtocol(std::shared_ptr<JoyconHandle> handle) |
| 11 | : JoyconCommonProtocol(std::move(handle)) {} | 11 | : JoyconCommonProtocol(std::move(handle)) {} |
| 12 | 12 | ||
| 13 | DriverResult IrsProtocol::EnableIrs() { | 13 | Common::Input::DriverResult IrsProtocol::EnableIrs() { |
| 14 | LOG_INFO(Input, "Enable IRS"); | 14 | LOG_INFO(Input, "Enable IRS"); |
| 15 | ScopedSetBlocking sb(this); | 15 | ScopedSetBlocking sb(this); |
| 16 | DriverResult result{DriverResult::Success}; | 16 | Common::Input::DriverResult result{Common::Input::DriverResult::Success}; |
| 17 | 17 | ||
| 18 | if (result == DriverResult::Success) { | 18 | if (result == Common::Input::DriverResult::Success) { |
| 19 | result = SetReportMode(ReportMode::NFC_IR_MODE_60HZ); | 19 | result = SetReportMode(ReportMode::NFC_IR_MODE_60HZ); |
| 20 | } | 20 | } |
| 21 | if (result == DriverResult::Success) { | 21 | if (result == Common::Input::DriverResult::Success) { |
| 22 | result = EnableMCU(true); | 22 | result = EnableMCU(true); |
| 23 | } | 23 | } |
| 24 | if (result == DriverResult::Success) { | 24 | if (result == Common::Input::DriverResult::Success) { |
| 25 | result = WaitSetMCUMode(ReportMode::NFC_IR_MODE_60HZ, MCUMode::Standby); | 25 | result = WaitSetMCUMode(ReportMode::NFC_IR_MODE_60HZ, MCUMode::Standby); |
| 26 | } | 26 | } |
| 27 | if (result == DriverResult::Success) { | 27 | if (result == Common::Input::DriverResult::Success) { |
| 28 | const MCUConfig config{ | 28 | const MCUConfig config{ |
| 29 | .command = MCUCommand::ConfigureMCU, | 29 | .command = MCUCommand::ConfigureMCU, |
| 30 | .sub_command = MCUSubCommand::SetMCUMode, | 30 | .sub_command = MCUSubCommand::SetMCUMode, |
| @@ -34,16 +34,16 @@ DriverResult IrsProtocol::EnableIrs() { | |||
| 34 | 34 | ||
| 35 | result = ConfigureMCU(config); | 35 | result = ConfigureMCU(config); |
| 36 | } | 36 | } |
| 37 | if (result == DriverResult::Success) { | 37 | if (result == Common::Input::DriverResult::Success) { |
| 38 | result = WaitSetMCUMode(ReportMode::NFC_IR_MODE_60HZ, MCUMode::IR); | 38 | result = WaitSetMCUMode(ReportMode::NFC_IR_MODE_60HZ, MCUMode::IR); |
| 39 | } | 39 | } |
| 40 | if (result == DriverResult::Success) { | 40 | if (result == Common::Input::DriverResult::Success) { |
| 41 | result = ConfigureIrs(); | 41 | result = ConfigureIrs(); |
| 42 | } | 42 | } |
| 43 | if (result == DriverResult::Success) { | 43 | if (result == Common::Input::DriverResult::Success) { |
| 44 | result = WriteRegistersStep1(); | 44 | result = WriteRegistersStep1(); |
| 45 | } | 45 | } |
| 46 | if (result == DriverResult::Success) { | 46 | if (result == Common::Input::DriverResult::Success) { |
| 47 | result = WriteRegistersStep2(); | 47 | result = WriteRegistersStep2(); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| @@ -52,12 +52,12 @@ DriverResult IrsProtocol::EnableIrs() { | |||
| 52 | return result; | 52 | return result; |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | DriverResult IrsProtocol::DisableIrs() { | 55 | Common::Input::DriverResult IrsProtocol::DisableIrs() { |
| 56 | LOG_DEBUG(Input, "Disable IRS"); | 56 | LOG_DEBUG(Input, "Disable IRS"); |
| 57 | ScopedSetBlocking sb(this); | 57 | ScopedSetBlocking sb(this); |
| 58 | DriverResult result{DriverResult::Success}; | 58 | Common::Input::DriverResult result{Common::Input::DriverResult::Success}; |
| 59 | 59 | ||
| 60 | if (result == DriverResult::Success) { | 60 | if (result == Common::Input::DriverResult::Success) { |
| 61 | result = EnableMCU(false); | 61 | result = EnableMCU(false); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| @@ -66,7 +66,7 @@ DriverResult IrsProtocol::DisableIrs() { | |||
| 66 | return result; | 66 | return result; |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | DriverResult IrsProtocol::SetIrsConfig(IrsMode mode, IrsResolution format) { | 69 | Common::Input::DriverResult IrsProtocol::SetIrsConfig(IrsMode mode, IrsResolution format) { |
| 70 | irs_mode = mode; | 70 | irs_mode = mode; |
| 71 | switch (format) { | 71 | switch (format) { |
| 72 | case IrsResolution::Size320x240: | 72 | case IrsResolution::Size320x240: |
| @@ -103,10 +103,10 @@ DriverResult IrsProtocol::SetIrsConfig(IrsMode mode, IrsResolution format) { | |||
| 103 | return EnableIrs(); | 103 | return EnableIrs(); |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | return DriverResult::Success; | 106 | return Common::Input::DriverResult::Success; |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | DriverResult IrsProtocol::RequestImage(std::span<u8> buffer) { | 109 | Common::Input::DriverResult IrsProtocol::RequestImage(std::span<u8> buffer) { |
| 110 | const u8 next_packet_fragment = | 110 | const u8 next_packet_fragment = |
| 111 | static_cast<u8>((packet_fragment + 1) % (static_cast<u8>(fragments) + 1)); | 111 | static_cast<u8>((packet_fragment + 1) % (static_cast<u8>(fragments) + 1)); |
| 112 | 112 | ||
| @@ -129,7 +129,7 @@ DriverResult IrsProtocol::RequestImage(std::span<u8> buffer) { | |||
| 129 | return RequestFrame(packet_fragment); | 129 | return RequestFrame(packet_fragment); |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | DriverResult IrsProtocol::ConfigureIrs() { | 132 | Common::Input::DriverResult IrsProtocol::ConfigureIrs() { |
| 133 | LOG_DEBUG(Input, "Configure IRS"); | 133 | LOG_DEBUG(Input, "Configure IRS"); |
| 134 | constexpr std::size_t max_tries = 28; | 134 | constexpr std::size_t max_tries = 28; |
| 135 | SubCommandResponse output{}; | 135 | SubCommandResponse output{}; |
| @@ -152,20 +152,20 @@ DriverResult IrsProtocol::ConfigureIrs() { | |||
| 152 | do { | 152 | do { |
| 153 | const auto result = SendSubCommand(SubCommand::SET_MCU_CONFIG, request_data, output); | 153 | const auto result = SendSubCommand(SubCommand::SET_MCU_CONFIG, request_data, output); |
| 154 | 154 | ||
| 155 | if (result != DriverResult::Success) { | 155 | if (result != Common::Input::DriverResult::Success) { |
| 156 | return result; | 156 | return result; |
| 157 | } | 157 | } |
| 158 | if (tries++ >= max_tries) { | 158 | if (tries++ >= max_tries) { |
| 159 | return DriverResult::WrongReply; | 159 | return Common::Input::DriverResult::WrongReply; |
| 160 | } | 160 | } |
| 161 | } while (output.command_data[0] != 0x0b); | 161 | } while (output.command_data[0] != 0x0b); |
| 162 | 162 | ||
| 163 | return DriverResult::Success; | 163 | return Common::Input::DriverResult::Success; |
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | DriverResult IrsProtocol::WriteRegistersStep1() { | 166 | Common::Input::DriverResult IrsProtocol::WriteRegistersStep1() { |
| 167 | LOG_DEBUG(Input, "WriteRegistersStep1"); | 167 | LOG_DEBUG(Input, "WriteRegistersStep1"); |
| 168 | DriverResult result{DriverResult::Success}; | 168 | Common::Input::DriverResult result{Common::Input::DriverResult::Success}; |
| 169 | constexpr std::size_t max_tries = 28; | 169 | constexpr std::size_t max_tries = 28; |
| 170 | SubCommandResponse output{}; | 170 | SubCommandResponse output{}; |
| 171 | std::size_t tries = 0; | 171 | std::size_t tries = 0; |
| @@ -197,7 +197,7 @@ DriverResult IrsProtocol::WriteRegistersStep1() { | |||
| 197 | mcu_request[36] = CalculateMCU_CRC8(mcu_request.data(), 36); | 197 | mcu_request[36] = CalculateMCU_CRC8(mcu_request.data(), 36); |
| 198 | mcu_request[37] = 0xFF; | 198 | mcu_request[37] = 0xFF; |
| 199 | 199 | ||
| 200 | if (result != DriverResult::Success) { | 200 | if (result != Common::Input::DriverResult::Success) { |
| 201 | return result; | 201 | return result; |
| 202 | } | 202 | } |
| 203 | 203 | ||
| @@ -205,26 +205,26 @@ DriverResult IrsProtocol::WriteRegistersStep1() { | |||
| 205 | result = SendSubCommand(SubCommand::SET_MCU_CONFIG, request_data, output); | 205 | result = SendSubCommand(SubCommand::SET_MCU_CONFIG, request_data, output); |
| 206 | 206 | ||
| 207 | // First time we need to set the report mode | 207 | // First time we need to set the report mode |
| 208 | if (result == DriverResult::Success && tries == 0) { | 208 | if (result == Common::Input::DriverResult::Success && tries == 0) { |
| 209 | result = SendMCUCommand(SubCommand::SET_REPORT_MODE, mcu_request); | 209 | result = SendMCUCommand(SubCommand::SET_REPORT_MODE, mcu_request); |
| 210 | } | 210 | } |
| 211 | if (result == DriverResult::Success && tries == 0) { | 211 | if (result == Common::Input::DriverResult::Success && tries == 0) { |
| 212 | GetSubCommandResponse(SubCommand::SET_MCU_CONFIG, output); | 212 | GetSubCommandResponse(SubCommand::SET_MCU_CONFIG, output); |
| 213 | } | 213 | } |
| 214 | 214 | ||
| 215 | if (result != DriverResult::Success) { | 215 | if (result != Common::Input::DriverResult::Success) { |
| 216 | return result; | 216 | return result; |
| 217 | } | 217 | } |
| 218 | if (tries++ >= max_tries) { | 218 | if (tries++ >= max_tries) { |
| 219 | return DriverResult::WrongReply; | 219 | return Common::Input::DriverResult::WrongReply; |
| 220 | } | 220 | } |
| 221 | } while (!(output.command_data[0] == 0x13 && output.command_data[2] == 0x07) && | 221 | } while (!(output.command_data[0] == 0x13 && output.command_data[2] == 0x07) && |
| 222 | output.command_data[0] != 0x23); | 222 | output.command_data[0] != 0x23); |
| 223 | 223 | ||
| 224 | return DriverResult::Success; | 224 | return Common::Input::DriverResult::Success; |
| 225 | } | 225 | } |
| 226 | 226 | ||
| 227 | DriverResult IrsProtocol::WriteRegistersStep2() { | 227 | Common::Input::DriverResult IrsProtocol::WriteRegistersStep2() { |
| 228 | LOG_DEBUG(Input, "WriteRegistersStep2"); | 228 | LOG_DEBUG(Input, "WriteRegistersStep2"); |
| 229 | constexpr std::size_t max_tries = 28; | 229 | constexpr std::size_t max_tries = 28; |
| 230 | SubCommandResponse output{}; | 230 | SubCommandResponse output{}; |
| @@ -255,18 +255,18 @@ DriverResult IrsProtocol::WriteRegistersStep2() { | |||
| 255 | do { | 255 | do { |
| 256 | const auto result = SendSubCommand(SubCommand::SET_MCU_CONFIG, request_data, output); | 256 | const auto result = SendSubCommand(SubCommand::SET_MCU_CONFIG, request_data, output); |
| 257 | 257 | ||
| 258 | if (result != DriverResult::Success) { | 258 | if (result != Common::Input::DriverResult::Success) { |
| 259 | return result; | 259 | return result; |
| 260 | } | 260 | } |
| 261 | if (tries++ >= max_tries) { | 261 | if (tries++ >= max_tries) { |
| 262 | return DriverResult::WrongReply; | 262 | return Common::Input::DriverResult::WrongReply; |
| 263 | } | 263 | } |
| 264 | } while (output.command_data[0] != 0x13 && output.command_data[0] != 0x23); | 264 | } while (output.command_data[0] != 0x13 && output.command_data[0] != 0x23); |
| 265 | 265 | ||
| 266 | return DriverResult::Success; | 266 | return Common::Input::DriverResult::Success; |
| 267 | } | 267 | } |
| 268 | 268 | ||
| 269 | DriverResult IrsProtocol::RequestFrame(u8 frame) { | 269 | Common::Input::DriverResult IrsProtocol::RequestFrame(u8 frame) { |
| 270 | std::array<u8, 38> mcu_request{}; | 270 | std::array<u8, 38> mcu_request{}; |
| 271 | mcu_request[3] = frame; | 271 | mcu_request[3] = frame; |
| 272 | mcu_request[36] = CalculateMCU_CRC8(mcu_request.data(), 36); | 272 | mcu_request[36] = CalculateMCU_CRC8(mcu_request.data(), 36); |
| @@ -274,7 +274,7 @@ DriverResult IrsProtocol::RequestFrame(u8 frame) { | |||
| 274 | return SendMCUCommand(SubCommand::SET_REPORT_MODE, mcu_request); | 274 | return SendMCUCommand(SubCommand::SET_REPORT_MODE, mcu_request); |
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | DriverResult IrsProtocol::ResendFrame(u8 frame) { | 277 | Common::Input::DriverResult IrsProtocol::ResendFrame(u8 frame) { |
| 278 | std::array<u8, 38> mcu_request{}; | 278 | std::array<u8, 38> mcu_request{}; |
| 279 | mcu_request[1] = 0x1; | 279 | mcu_request[1] = 0x1; |
| 280 | mcu_request[2] = frame; | 280 | mcu_request[2] = frame; |