nfc.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. // Based on dkms-hid-nintendo implementation, CTCaer joycon toolkit and dekuNukem reverse
  4. // engineering https://github.com/nicman23/dkms-hid-nintendo/blob/master/src/hid-nintendo.c
  5. // https://github.com/CTCaer/jc_toolkit
  6. // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering
  7. #pragma once
  8. #include <vector>
  9. #include "input_common/helpers/joycon_protocol/common_protocol.h"
  10. #include "input_common/helpers/joycon_protocol/joycon_types.h"
  11. namespace InputCommon::Joycon {
  12. class NfcProtocol final : private JoyconCommonProtocol {
  13. public:
  14. explicit NfcProtocol(std::shared_ptr<JoyconHandle> handle);
  15. DriverResult EnableNfc();
  16. DriverResult DisableNfc();
  17. DriverResult StartNFCPollingMode();
  18. DriverResult ScanAmiibo(std::vector<u8>& data);
  19. bool HasAmiibo();
  20. bool IsEnabled() const;
  21. private:
  22. // Number of times the function will be delayed until it outputs valid data
  23. static constexpr std::size_t AMIIBO_UPDATE_DELAY = 15;
  24. struct TagFoundData {
  25. u8 type;
  26. std::vector<u8> uuid;
  27. };
  28. DriverResult WaitUntilNfcIsReady();
  29. DriverResult WaitUntilNfcIsPolling();
  30. DriverResult IsTagInRange(TagFoundData& data, std::size_t timeout_limit = 1);
  31. DriverResult GetAmiiboData(std::vector<u8>& data);
  32. DriverResult SendStartPollingRequest(MCUCommandResponse& output);
  33. DriverResult SendStopPollingRequest(MCUCommandResponse& output);
  34. DriverResult SendNextPackageRequest(MCUCommandResponse& output, u8 packet_id);
  35. DriverResult SendReadAmiiboRequest(MCUCommandResponse& output, NFCPages ntag_pages);
  36. NFCReadBlockCommand GetReadBlockCommand(NFCPages pages) const;
  37. bool is_enabled{};
  38. std::size_t update_counter{};
  39. };
  40. } // namespace InputCommon::Joycon