summaryrefslogtreecommitdiffstats
path: root/src/input_common/helpers/joycon_protocol/nfc.h
diff options
context:
space:
mode:
authorliamwhite <liamwhite@users.noreply.github.com>2023-01-24 15:29:37 +0100
committerGitHub <noreply@github.com>2023-01-24 15:29:37 +0100
commita68af583ea378b48e2ed5a19f519a815ba89e40f (patch)
tree2983c14a7d4bc2797259c7d97462a439bec629f3 /src/input_common/helpers/joycon_protocol/nfc.h
parentMerge pull request #9555 from abouvier/catch2-update (diff)
parentcore: hid: Make use of SCOPE_EXIT and SCOPE_GUARD where applicable (diff)
downloadyuzu-a68af583ea378b48e2ed5a19f519a815ba89e40f.tar
yuzu-a68af583ea378b48e2ed5a19f519a815ba89e40f.tar.gz
yuzu-a68af583ea378b48e2ed5a19f519a815ba89e40f.tar.bz2
yuzu-a68af583ea378b48e2ed5a19f519a815ba89e40f.tar.lz
yuzu-a68af583ea378b48e2ed5a19f519a815ba89e40f.tar.xz
yuzu-a68af583ea378b48e2ed5a19f519a815ba89e40f.tar.zst
yuzu-a68af583ea378b48e2ed5a19f519a815ba89e40f.zip
Diffstat (limited to 'src/input_common/helpers/joycon_protocol/nfc.h')
-rw-r--r--src/input_common/helpers/joycon_protocol/nfc.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/input_common/helpers/joycon_protocol/nfc.h b/src/input_common/helpers/joycon_protocol/nfc.h
new file mode 100644
index 000000000..e63665aa9
--- /dev/null
+++ b/src/input_common/helpers/joycon_protocol/nfc.h
@@ -0,0 +1,61 @@
+// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+// Based on dkms-hid-nintendo implementation, CTCaer joycon toolkit and dekuNukem reverse
+// engineering https://github.com/nicman23/dkms-hid-nintendo/blob/master/src/hid-nintendo.c
+// https://github.com/CTCaer/jc_toolkit
+// https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering
+
+#pragma once
+
+#include <vector>
+
+#include "input_common/helpers/joycon_protocol/common_protocol.h"
+#include "input_common/helpers/joycon_protocol/joycon_types.h"
+
+namespace InputCommon::Joycon {
+
+class NfcProtocol final : private JoyconCommonProtocol {
+public:
+ explicit NfcProtocol(std::shared_ptr<JoyconHandle> handle);
+
+ DriverResult EnableNfc();
+
+ DriverResult DisableNfc();
+
+ DriverResult StartNFCPollingMode();
+
+ DriverResult ScanAmiibo(std::vector<u8>& data);
+
+ bool HasAmiibo();
+
+ bool IsEnabled() const;
+
+private:
+ struct TagFoundData {
+ u8 type;
+ std::vector<u8> uuid;
+ };
+
+ DriverResult WaitUntilNfcIsReady();
+
+ DriverResult StartPolling(TagFoundData& data);
+
+ DriverResult ReadTag(const TagFoundData& data);
+
+ DriverResult GetAmiiboData(std::vector<u8>& data);
+
+ DriverResult SendStartPollingRequest(std::vector<u8>& output);
+
+ DriverResult SendStopPollingRequest(std::vector<u8>& output);
+
+ DriverResult SendStartWaitingRecieveRequest(std::vector<u8>& output);
+
+ DriverResult SendReadAmiiboRequest(std::vector<u8>& output, NFCPages ntag_pages);
+
+ NFCReadBlockCommand GetReadBlockCommand(NFCPages pages) const;
+
+ bool is_enabled{};
+};
+
+} // namespace InputCommon::Joycon