diff options
Diffstat (limited to 'src/input_common/helpers/joycon_protocol/nfc.h')
| -rw-r--r-- | src/input_common/helpers/joycon_protocol/nfc.h | 74 |
1 files changed, 57 insertions, 17 deletions
diff --git a/src/input_common/helpers/joycon_protocol/nfc.h b/src/input_common/helpers/joycon_protocol/nfc.h index eb58c427d..22db95170 100644 --- a/src/input_common/helpers/joycon_protocol/nfc.h +++ b/src/input_common/helpers/joycon_protocol/nfc.h | |||
| @@ -13,26 +13,41 @@ | |||
| 13 | #include "input_common/helpers/joycon_protocol/common_protocol.h" | 13 | #include "input_common/helpers/joycon_protocol/common_protocol.h" |
| 14 | #include "input_common/helpers/joycon_protocol/joycon_types.h" | 14 | #include "input_common/helpers/joycon_protocol/joycon_types.h" |
| 15 | 15 | ||
| 16 | namespace Common::Input { | ||
| 17 | enum class DriverResult; | ||
| 18 | } | ||
| 19 | |||
| 16 | namespace InputCommon::Joycon { | 20 | namespace InputCommon::Joycon { |
| 17 | 21 | ||
| 18 | class NfcProtocol final : private JoyconCommonProtocol { | 22 | class NfcProtocol final : private JoyconCommonProtocol { |
| 19 | public: | 23 | public: |
| 20 | explicit NfcProtocol(std::shared_ptr<JoyconHandle> handle); | 24 | explicit NfcProtocol(std::shared_ptr<JoyconHandle> handle); |
| 21 | 25 | ||
| 22 | DriverResult EnableNfc(); | 26 | Common::Input::DriverResult EnableNfc(); |
| 27 | |||
| 28 | Common::Input::DriverResult DisableNfc(); | ||
| 29 | |||
| 30 | Common::Input::DriverResult StartNFCPollingMode(); | ||
| 31 | |||
| 32 | Common::Input::DriverResult StopNFCPollingMode(); | ||
| 23 | 33 | ||
| 24 | DriverResult DisableNfc(); | 34 | Common::Input::DriverResult GetTagInfo(Joycon::TagInfo& tag_info); |
| 25 | 35 | ||
| 26 | DriverResult StartNFCPollingMode(); | 36 | Common::Input::DriverResult ReadAmiibo(std::vector<u8>& data); |
| 27 | 37 | ||
| 28 | DriverResult ScanAmiibo(std::vector<u8>& data); | 38 | Common::Input::DriverResult WriteAmiibo(std::span<const u8> data); |
| 29 | 39 | ||
| 30 | DriverResult WriteAmiibo(std::span<const u8> data); | 40 | Common::Input::DriverResult ReadMifare(std::span<const MifareReadChunk> read_request, |
| 41 | std::span<MifareReadData> out_data); | ||
| 42 | |||
| 43 | Common::Input::DriverResult WriteMifare(std::span<const MifareWriteChunk> write_request); | ||
| 31 | 44 | ||
| 32 | bool HasAmiibo(); | 45 | bool HasAmiibo(); |
| 33 | 46 | ||
| 34 | bool IsEnabled() const; | 47 | bool IsEnabled() const; |
| 35 | 48 | ||
| 49 | bool IsPolling() const; | ||
| 50 | |||
| 36 | private: | 51 | private: |
| 37 | // Number of times the function will be delayed until it outputs valid data | 52 | // Number of times the function will be delayed until it outputs valid data |
| 38 | static constexpr std::size_t AMIIBO_UPDATE_DELAY = 15; | 53 | static constexpr std::size_t AMIIBO_UPDATE_DELAY = 15; |
| @@ -43,39 +58,64 @@ private: | |||
| 43 | TagUUID uuid; | 58 | TagUUID uuid; |
| 44 | }; | 59 | }; |
| 45 | 60 | ||
| 46 | DriverResult WaitUntilNfcIs(NFCStatus status); | 61 | Common::Input::DriverResult WaitUntilNfcIs(NFCStatus status); |
| 62 | |||
| 63 | Common::Input::DriverResult IsTagInRange(TagFoundData& data, std::size_t timeout_limit = 1); | ||
| 47 | 64 | ||
| 48 | DriverResult IsTagInRange(TagFoundData& data, std::size_t timeout_limit = 1); | 65 | Common::Input::DriverResult GetAmiiboData(std::vector<u8>& data); |
| 49 | 66 | ||
| 50 | DriverResult GetAmiiboData(std::vector<u8>& data); | 67 | Common::Input::DriverResult WriteAmiiboData(const TagUUID& tag_uuid, std::span<const u8> data); |
| 51 | 68 | ||
| 52 | DriverResult WriteAmiiboData(const TagUUID& tag_uuid, std::span<const u8> data); | 69 | Common::Input::DriverResult GetMifareData(const MifareUUID& tag_uuid, |
| 70 | std::span<const MifareReadChunk> read_request, | ||
| 71 | std::span<MifareReadData> out_data); | ||
| 53 | 72 | ||
| 54 | DriverResult SendStartPollingRequest(MCUCommandResponse& output, | 73 | Common::Input::DriverResult WriteMifareData(const MifareUUID& tag_uuid, |
| 55 | bool is_second_attempt = false); | 74 | std::span<const MifareWriteChunk> write_request); |
| 56 | 75 | ||
| 57 | DriverResult SendStopPollingRequest(MCUCommandResponse& output); | 76 | Common::Input::DriverResult SendStartPollingRequest(MCUCommandResponse& output, |
| 77 | bool is_second_attempt = false); | ||
| 58 | 78 | ||
| 59 | DriverResult SendNextPackageRequest(MCUCommandResponse& output, u8 packet_id); | 79 | Common::Input::DriverResult SendStopPollingRequest(MCUCommandResponse& output); |
| 60 | 80 | ||
| 61 | DriverResult SendReadAmiiboRequest(MCUCommandResponse& output, NFCPages ntag_pages); | 81 | Common::Input::DriverResult SendNextPackageRequest(MCUCommandResponse& output, u8 packet_id); |
| 62 | 82 | ||
| 63 | DriverResult SendWriteAmiiboRequest(MCUCommandResponse& output, const TagUUID& tag_uuid); | 83 | Common::Input::DriverResult SendReadAmiiboRequest(MCUCommandResponse& output, |
| 84 | NFCPages ntag_pages); | ||
| 64 | 85 | ||
| 65 | DriverResult SendWriteDataAmiiboRequest(MCUCommandResponse& output, u8 block_id, | 86 | Common::Input::DriverResult SendWriteAmiiboRequest(MCUCommandResponse& output, |
| 66 | bool is_last_packet, std::span<const u8> data); | 87 | const TagUUID& tag_uuid); |
| 88 | |||
| 89 | Common::Input::DriverResult SendWriteDataAmiiboRequest(MCUCommandResponse& output, u8 block_id, | ||
| 90 | bool is_last_packet, | ||
| 91 | std::span<const u8> data); | ||
| 92 | |||
| 93 | Common::Input::DriverResult SendReadDataMifareRequest(MCUCommandResponse& output, u8 block_id, | ||
| 94 | bool is_last_packet, | ||
| 95 | std::span<const u8> data); | ||
| 67 | 96 | ||
| 68 | std::vector<u8> SerializeWritePackage(const NFCWritePackage& package) const; | 97 | std::vector<u8> SerializeWritePackage(const NFCWritePackage& package) const; |
| 69 | 98 | ||
| 99 | std::vector<u8> SerializeMifareReadPackage(const MifareReadPackage& package) const; | ||
| 100 | |||
| 101 | std::vector<u8> SerializeMifareWritePackage(const MifareWritePackage& package) const; | ||
| 102 | |||
| 70 | NFCWritePackage MakeAmiiboWritePackage(const TagUUID& tag_uuid, std::span<const u8> data) const; | 103 | NFCWritePackage MakeAmiiboWritePackage(const TagUUID& tag_uuid, std::span<const u8> data) const; |
| 71 | 104 | ||
| 72 | NFCDataChunk MakeAmiiboChunk(u8 page, u8 size, std::span<const u8> data) const; | 105 | NFCDataChunk MakeAmiiboChunk(u8 page, u8 size, std::span<const u8> data) const; |
| 73 | 106 | ||
| 107 | MifareReadPackage MakeMifareReadPackage(const MifareUUID& tag_uuid, | ||
| 108 | std::span<const MifareReadChunk> read_request) const; | ||
| 109 | |||
| 110 | MifareWritePackage MakeMifareWritePackage(const MifareUUID& tag_uuid, | ||
| 111 | std::span<const MifareWriteChunk> read_request) const; | ||
| 112 | |||
| 74 | NFCReadBlockCommand GetReadBlockCommand(NFCPages pages) const; | 113 | NFCReadBlockCommand GetReadBlockCommand(NFCPages pages) const; |
| 75 | 114 | ||
| 76 | TagUUID GetTagUUID(std::span<const u8> data) const; | 115 | TagUUID GetTagUUID(std::span<const u8> data) const; |
| 77 | 116 | ||
| 78 | bool is_enabled{}; | 117 | bool is_enabled{}; |
| 118 | bool is_polling{}; | ||
| 79 | std::size_t update_counter{}; | 119 | std::size_t update_counter{}; |
| 80 | }; | 120 | }; |
| 81 | 121 | ||