diff options
| author | 2023-06-16 21:57:21 -0600 | |
|---|---|---|
| committer | 2023-06-21 17:54:58 -0600 | |
| commit | 84d43489c5df9f450efb0293cc58161d08e3b882 (patch) | |
| tree | c4d45b021c78392956dc58d409a34632fe135d2b /src/input_common/helpers/joycon_driver.cpp | |
| parent | Merge pull request #10783 from liamwhite/memory (diff) | |
| download | yuzu-84d43489c5df9f450efb0293cc58161d08e3b882.tar.gz yuzu-84d43489c5df9f450efb0293cc58161d08e3b882.tar.xz yuzu-84d43489c5df9f450efb0293cc58161d08e3b882.zip | |
input_common: Implement native mifare support
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/helpers/joycon_driver.cpp | 118 |
1 files changed, 104 insertions, 14 deletions
diff --git a/src/input_common/helpers/joycon_driver.cpp b/src/input_common/helpers/joycon_driver.cpp index 95106f16d..2c8c66951 100644 --- a/src/input_common/helpers/joycon_driver.cpp +++ b/src/input_common/helpers/joycon_driver.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include "common/logging/log.h" | 4 | #include "common/logging/log.h" |
| 5 | #include "common/scope_exit.h" | ||
| 5 | #include "common/swap.h" | 6 | #include "common/swap.h" |
| 6 | #include "common/thread.h" | 7 | #include "common/thread.h" |
| 7 | #include "input_common/helpers/joycon_driver.h" | 8 | #include "input_common/helpers/joycon_driver.h" |
| @@ -112,7 +113,7 @@ DriverResult JoyconDriver::InitializeDevice() { | |||
| 112 | joycon_poller = std::make_unique<JoyconPoller>(device_type, left_stick_calibration, | 113 | joycon_poller = std::make_unique<JoyconPoller>(device_type, left_stick_calibration, |
| 113 | right_stick_calibration, motion_calibration); | 114 | right_stick_calibration, motion_calibration); |
| 114 | 115 | ||
| 115 | // Start pooling for data | 116 | // Start polling for data |
| 116 | is_connected = true; | 117 | is_connected = true; |
| 117 | if (!input_thread_running) { | 118 | if (!input_thread_running) { |
| 118 | input_thread = | 119 | input_thread = |
| @@ -208,7 +209,7 @@ void JoyconDriver::OnNewData(std::span<u8> buffer) { | |||
| 208 | joycon_poller->UpdateCamera(irs_protocol->GetImage(), irs_protocol->GetIrsFormat()); | 209 | joycon_poller->UpdateCamera(irs_protocol->GetImage(), irs_protocol->GetIrsFormat()); |
| 209 | } | 210 | } |
| 210 | 211 | ||
| 211 | if (nfc_protocol->IsEnabled()) { | 212 | if (nfc_protocol->IsPolling()) { |
| 212 | if (amiibo_detected) { | 213 | if (amiibo_detected) { |
| 213 | if (!nfc_protocol->HasAmiibo()) { | 214 | if (!nfc_protocol->HasAmiibo()) { |
| 214 | joycon_poller->UpdateAmiibo({}); | 215 | joycon_poller->UpdateAmiibo({}); |
| @@ -218,10 +219,10 @@ void JoyconDriver::OnNewData(std::span<u8> buffer) { | |||
| 218 | } | 219 | } |
| 219 | 220 | ||
| 220 | if (!amiibo_detected) { | 221 | if (!amiibo_detected) { |
| 221 | std::vector<u8> data(0x21C); | 222 | Joycon::TagInfo tag_info; |
| 222 | const auto result = nfc_protocol->ScanAmiibo(data); | 223 | const auto result = nfc_protocol->GetTagInfo(tag_info); |
| 223 | if (result == DriverResult::Success) { | 224 | if (result == DriverResult::Success) { |
| 224 | joycon_poller->UpdateAmiibo(data); | 225 | joycon_poller->UpdateAmiibo(tag_info); |
| 225 | amiibo_detected = true; | 226 | amiibo_detected = true; |
| 226 | } | 227 | } |
| 227 | } | 228 | } |
| @@ -247,6 +248,7 @@ void JoyconDriver::OnNewData(std::span<u8> buffer) { | |||
| 247 | } | 248 | } |
| 248 | 249 | ||
| 249 | DriverResult JoyconDriver::SetPollingMode() { | 250 | DriverResult JoyconDriver::SetPollingMode() { |
| 251 | SCOPE_EXIT({ disable_input_thread = false; }); | ||
| 250 | disable_input_thread = true; | 252 | disable_input_thread = true; |
| 251 | 253 | ||
| 252 | rumble_protocol->EnableRumble(vibration_enabled && supported_features.vibration); | 254 | rumble_protocol->EnableRumble(vibration_enabled && supported_features.vibration); |
| @@ -276,7 +278,6 @@ DriverResult JoyconDriver::SetPollingMode() { | |||
| 276 | if (irs_enabled && supported_features.irs) { | 278 | if (irs_enabled && supported_features.irs) { |
| 277 | auto result = irs_protocol->EnableIrs(); | 279 | auto result = irs_protocol->EnableIrs(); |
| 278 | if (result == DriverResult::Success) { | 280 | if (result == DriverResult::Success) { |
| 279 | disable_input_thread = false; | ||
| 280 | return result; | 281 | return result; |
| 281 | } | 282 | } |
| 282 | irs_protocol->DisableIrs(); | 283 | irs_protocol->DisableIrs(); |
| @@ -286,10 +287,6 @@ DriverResult JoyconDriver::SetPollingMode() { | |||
| 286 | if (nfc_enabled && supported_features.nfc) { | 287 | if (nfc_enabled && supported_features.nfc) { |
| 287 | auto result = nfc_protocol->EnableNfc(); | 288 | auto result = nfc_protocol->EnableNfc(); |
| 288 | if (result == DriverResult::Success) { | 289 | if (result == DriverResult::Success) { |
| 289 | result = nfc_protocol->StartNFCPollingMode(); | ||
| 290 | } | ||
| 291 | if (result == DriverResult::Success) { | ||
| 292 | disable_input_thread = false; | ||
| 293 | return result; | 290 | return result; |
| 294 | } | 291 | } |
| 295 | nfc_protocol->DisableNfc(); | 292 | nfc_protocol->DisableNfc(); |
| @@ -303,7 +300,6 @@ DriverResult JoyconDriver::SetPollingMode() { | |||
| 303 | } | 300 | } |
| 304 | if (result == DriverResult::Success) { | 301 | if (result == DriverResult::Success) { |
| 305 | ring_connected = true; | 302 | ring_connected = true; |
| 306 | disable_input_thread = false; | ||
| 307 | return result; | 303 | return result; |
| 308 | } | 304 | } |
| 309 | ring_connected = false; | 305 | ring_connected = false; |
| @@ -314,7 +310,6 @@ DriverResult JoyconDriver::SetPollingMode() { | |||
| 314 | if (passive_enabled && supported_features.passive) { | 310 | if (passive_enabled && supported_features.passive) { |
| 315 | const auto result = generic_protocol->EnablePassiveMode(); | 311 | const auto result = generic_protocol->EnablePassiveMode(); |
| 316 | if (result == DriverResult::Success) { | 312 | if (result == DriverResult::Success) { |
| 317 | disable_input_thread = false; | ||
| 318 | return result; | 313 | return result; |
| 319 | } | 314 | } |
| 320 | LOG_ERROR(Input, "Error enabling passive mode"); | 315 | LOG_ERROR(Input, "Error enabling passive mode"); |
| @@ -328,7 +323,6 @@ DriverResult JoyconDriver::SetPollingMode() { | |||
| 328 | // Switch calls this function after enabling active mode | 323 | // Switch calls this function after enabling active mode |
| 329 | generic_protocol->TriggersElapsed(); | 324 | generic_protocol->TriggersElapsed(); |
| 330 | 325 | ||
| 331 | disable_input_thread = false; | ||
| 332 | return result; | 326 | return result; |
| 333 | } | 327 | } |
| 334 | 328 | ||
| @@ -492,9 +486,63 @@ DriverResult JoyconDriver::SetRingConMode() { | |||
| 492 | return result; | 486 | return result; |
| 493 | } | 487 | } |
| 494 | 488 | ||
| 495 | DriverResult JoyconDriver::WriteNfcData(std::span<const u8> data) { | 489 | DriverResult JoyconDriver::StartNfcPolling() { |
| 496 | std::scoped_lock lock{mutex}; | 490 | std::scoped_lock lock{mutex}; |
| 491 | |||
| 492 | if (!supported_features.nfc) { | ||
| 493 | return DriverResult::NotSupported; | ||
| 494 | } | ||
| 495 | if (!nfc_protocol->IsEnabled()) { | ||
| 496 | return DriverResult::Disabled; | ||
| 497 | } | ||
| 498 | |||
| 499 | disable_input_thread = true; | ||
| 500 | const auto result = nfc_protocol->StartNFCPollingMode(); | ||
| 501 | disable_input_thread = false; | ||
| 502 | |||
| 503 | return result; | ||
| 504 | } | ||
| 505 | |||
| 506 | DriverResult JoyconDriver::StopNfcPolling() { | ||
| 507 | std::scoped_lock lock{mutex}; | ||
| 508 | |||
| 509 | if (!supported_features.nfc) { | ||
| 510 | return DriverResult::NotSupported; | ||
| 511 | } | ||
| 512 | if (!nfc_protocol->IsEnabled()) { | ||
| 513 | return DriverResult::Disabled; | ||
| 514 | } | ||
| 515 | |||
| 516 | disable_input_thread = true; | ||
| 517 | const auto result = nfc_protocol->StopNFCPollingMode(); | ||
| 518 | disable_input_thread = false; | ||
| 519 | |||
| 520 | return result; | ||
| 521 | } | ||
| 522 | |||
| 523 | DriverResult JoyconDriver::ReadAmiiboData(std::vector<u8>& out_data) { | ||
| 524 | std::scoped_lock lock{mutex}; | ||
| 525 | |||
| 526 | if (!supported_features.nfc) { | ||
| 527 | return DriverResult::NotSupported; | ||
| 528 | } | ||
| 529 | if (!nfc_protocol->IsEnabled()) { | ||
| 530 | return DriverResult::Disabled; | ||
| 531 | } | ||
| 532 | if (!amiibo_detected) { | ||
| 533 | return DriverResult::ErrorWritingData; | ||
| 534 | } | ||
| 535 | |||
| 536 | out_data.resize(0x21C); | ||
| 497 | disable_input_thread = true; | 537 | disable_input_thread = true; |
| 538 | const auto result = nfc_protocol->ReadAmiibo(out_data); | ||
| 539 | disable_input_thread = false; | ||
| 540 | |||
| 541 | return result; | ||
| 542 | } | ||
| 543 | |||
| 544 | DriverResult JoyconDriver::WriteNfcData(std::span<const u8> data) { | ||
| 545 | std::scoped_lock lock{mutex}; | ||
| 498 | 546 | ||
| 499 | if (!supported_features.nfc) { | 547 | if (!supported_features.nfc) { |
| 500 | return DriverResult::NotSupported; | 548 | return DriverResult::NotSupported; |
| @@ -506,9 +554,51 @@ DriverResult JoyconDriver::WriteNfcData(std::span<const u8> data) { | |||
| 506 | return DriverResult::ErrorWritingData; | 554 | return DriverResult::ErrorWritingData; |
| 507 | } | 555 | } |
| 508 | 556 | ||
| 557 | disable_input_thread = true; | ||
| 509 | const auto result = nfc_protocol->WriteAmiibo(data); | 558 | const auto result = nfc_protocol->WriteAmiibo(data); |
| 559 | disable_input_thread = false; | ||
| 510 | 560 | ||
| 561 | return result; | ||
| 562 | } | ||
| 563 | |||
| 564 | DriverResult JoyconDriver::ReadMifareData(std::span<const MifareReadChunk> data, | ||
| 565 | std::span<MifareReadData> out_data) { | ||
| 566 | std::scoped_lock lock{mutex}; | ||
| 567 | |||
| 568 | if (!supported_features.nfc) { | ||
| 569 | return DriverResult::NotSupported; | ||
| 570 | } | ||
| 571 | if (!nfc_protocol->IsEnabled()) { | ||
| 572 | return DriverResult::Disabled; | ||
| 573 | } | ||
| 574 | if (!amiibo_detected) { | ||
| 575 | return DriverResult::ErrorWritingData; | ||
| 576 | } | ||
| 577 | |||
| 578 | disable_input_thread = true; | ||
| 579 | const auto result = nfc_protocol->ReadMifare(data, out_data); | ||
| 580 | disable_input_thread = false; | ||
| 581 | |||
| 582 | return result; | ||
| 583 | } | ||
| 584 | |||
| 585 | DriverResult JoyconDriver::WriteMifareData(std::span<const MifareWriteChunk> data) { | ||
| 586 | std::scoped_lock lock{mutex}; | ||
| 587 | |||
| 588 | if (!supported_features.nfc) { | ||
| 589 | return DriverResult::NotSupported; | ||
| 590 | } | ||
| 591 | if (!nfc_protocol->IsEnabled()) { | ||
| 592 | return DriverResult::Disabled; | ||
| 593 | } | ||
| 594 | if (!amiibo_detected) { | ||
| 595 | return DriverResult::ErrorWritingData; | ||
| 596 | } | ||
| 597 | |||
| 598 | disable_input_thread = true; | ||
| 599 | const auto result = nfc_protocol->WriteMifare(data); | ||
| 511 | disable_input_thread = false; | 600 | disable_input_thread = false; |
| 601 | |||
| 512 | return result; | 602 | return result; |
| 513 | } | 603 | } |
| 514 | 604 | ||