summaryrefslogtreecommitdiff
path: root/src/input_common/helpers/joycon_protocol/irs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/helpers/joycon_protocol/irs.cpp')
-rw-r--r--src/input_common/helpers/joycon_protocol/irs.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/input_common/helpers/joycon_protocol/irs.cpp b/src/input_common/helpers/joycon_protocol/irs.cpp
index 9dfa503c2..09e17bc5b 100644
--- a/src/input_common/helpers/joycon_protocol/irs.cpp
+++ b/src/input_common/helpers/joycon_protocol/irs.cpp
@@ -12,8 +12,8 @@ IrsProtocol::IrsProtocol(std::shared_ptr<JoyconHandle> handle)
12 12
13DriverResult IrsProtocol::EnableIrs() { 13DriverResult IrsProtocol::EnableIrs() {
14 LOG_INFO(Input, "Enable IRS"); 14 LOG_INFO(Input, "Enable IRS");
15 ScopedSetBlocking sb(this);
15 DriverResult result{DriverResult::Success}; 16 DriverResult result{DriverResult::Success};
16 SetBlocking();
17 17
18 if (result == DriverResult::Success) { 18 if (result == DriverResult::Success) {
19 result = SetReportMode(ReportMode::NFC_IR_MODE_60HZ); 19 result = SetReportMode(ReportMode::NFC_IR_MODE_60HZ);
@@ -49,14 +49,13 @@ DriverResult IrsProtocol::EnableIrs() {
49 49
50 is_enabled = true; 50 is_enabled = true;
51 51
52 SetNonBlocking();
53 return result; 52 return result;
54} 53}
55 54
56DriverResult IrsProtocol::DisableIrs() { 55DriverResult IrsProtocol::DisableIrs() {
57 LOG_DEBUG(Input, "Disable IRS"); 56 LOG_DEBUG(Input, "Disable IRS");
57 ScopedSetBlocking sb(this);
58 DriverResult result{DriverResult::Success}; 58 DriverResult result{DriverResult::Success};
59 SetBlocking();
60 59
61 if (result == DriverResult::Success) { 60 if (result == DriverResult::Success) {
62 result = EnableMCU(false); 61 result = EnableMCU(false);
@@ -64,7 +63,6 @@ DriverResult IrsProtocol::DisableIrs() {
64 63
65 is_enabled = false; 64 is_enabled = false;
66 65
67 SetNonBlocking();
68 return result; 66 return result;
69} 67}
70 68
@@ -148,7 +146,7 @@ DriverResult IrsProtocol::ConfigureIrs() {
148 }; 146 };
149 buf_image.resize((static_cast<u8>(fragments) + 1) * 300); 147 buf_image.resize((static_cast<u8>(fragments) + 1) * 300);
150 148
151 std::vector<u8> request_data(sizeof(IrsConfigure)); 149 std::array<u8, sizeof(IrsConfigure)> request_data{};
152 memcpy(request_data.data(), &irs_configuration, sizeof(IrsConfigure)); 150 memcpy(request_data.data(), &irs_configuration, sizeof(IrsConfigure));
153 request_data[37] = CalculateMCU_CRC8(request_data.data() + 1, 36); 151 request_data[37] = CalculateMCU_CRC8(request_data.data() + 1, 36);
154 do { 152 do {
@@ -191,7 +189,7 @@ DriverResult IrsProtocol::WriteRegistersStep1() {
191 .crc = {}, 189 .crc = {},
192 }; 190 };
193 191
194 std::vector<u8> request_data(sizeof(IrsWriteRegisters)); 192 std::array<u8, sizeof(IrsWriteRegisters)> request_data{};
195 memcpy(request_data.data(), &irs_registers, sizeof(IrsWriteRegisters)); 193 memcpy(request_data.data(), &irs_registers, sizeof(IrsWriteRegisters));
196 request_data[37] = CalculateMCU_CRC8(request_data.data() + 1, 36); 194 request_data[37] = CalculateMCU_CRC8(request_data.data() + 1, 36);
197 195
@@ -208,7 +206,7 @@ DriverResult IrsProtocol::WriteRegistersStep1() {
208 206
209 // First time we need to set the report mode 207 // First time we need to set the report mode
210 if (result == DriverResult::Success && tries == 0) { 208 if (result == DriverResult::Success && tries == 0) {
211 result = SendMcuCommand(SubCommand::SET_REPORT_MODE, mcu_request); 209 result = SendMCUCommand(SubCommand::SET_REPORT_MODE, mcu_request);
212 } 210 }
213 if (result == DriverResult::Success && tries == 0) { 211 if (result == DriverResult::Success && tries == 0) {
214 GetSubCommandResponse(SubCommand::SET_MCU_CONFIG, output); 212 GetSubCommandResponse(SubCommand::SET_MCU_CONFIG, output);
@@ -250,7 +248,7 @@ DriverResult IrsProtocol::WriteRegistersStep2() {
250 .crc = {}, 248 .crc = {},
251 }; 249 };
252 250
253 std::vector<u8> request_data(sizeof(IrsWriteRegisters)); 251 std::array<u8, sizeof(IrsWriteRegisters)> request_data{};
254 memcpy(request_data.data(), &irs_registers, sizeof(IrsWriteRegisters)); 252 memcpy(request_data.data(), &irs_registers, sizeof(IrsWriteRegisters));
255 request_data[37] = CalculateMCU_CRC8(request_data.data() + 1, 36); 253 request_data[37] = CalculateMCU_CRC8(request_data.data() + 1, 36);
256 do { 254 do {
@@ -272,7 +270,7 @@ DriverResult IrsProtocol::RequestFrame(u8 frame) {
272 mcu_request[3] = frame; 270 mcu_request[3] = frame;
273 mcu_request[36] = CalculateMCU_CRC8(mcu_request.data(), 36); 271 mcu_request[36] = CalculateMCU_CRC8(mcu_request.data(), 36);
274 mcu_request[37] = 0xFF; 272 mcu_request[37] = 0xFF;
275 return SendMcuCommand(SubCommand::SET_REPORT_MODE, mcu_request); 273 return SendMCUCommand(SubCommand::SET_REPORT_MODE, mcu_request);
276} 274}
277 275
278DriverResult IrsProtocol::ResendFrame(u8 frame) { 276DriverResult IrsProtocol::ResendFrame(u8 frame) {
@@ -282,7 +280,7 @@ DriverResult IrsProtocol::ResendFrame(u8 frame) {
282 mcu_request[3] = 0x0; 280 mcu_request[3] = 0x0;
283 mcu_request[36] = CalculateMCU_CRC8(mcu_request.data(), 36); 281 mcu_request[36] = CalculateMCU_CRC8(mcu_request.data(), 36);
284 mcu_request[37] = 0xFF; 282 mcu_request[37] = 0xFF;
285 return SendMcuCommand(SubCommand::SET_REPORT_MODE, mcu_request); 283 return SendMCUCommand(SubCommand::SET_REPORT_MODE, mcu_request);
286} 284}
287 285
288std::vector<u8> IrsProtocol::GetImage() const { 286std::vector<u8> IrsProtocol::GetImage() const {