M5Unit-NFC 0.1.0 git rev:93745b5
Loading...
Searching...
No Matches
emulation_layer_f.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
17#ifndef M5_UNIT_NFC_NFC_LAYER_F_EMULATION_LAYER_F_HPP
18#define M5_UNIT_NFC_NFC_LAYER_F_EMULATION_LAYER_F_HPP
19
20#include "nfc/f/nfcf.hpp"
21#include <vector>
22#include <memory>
23
24namespace m5 {
25
26namespace unit {
27class UnitST25R3916;
28class CapST25R3916;
29} // namespace unit
30
31namespace nfc {
32
38public:
43 enum class State { None, Off, Communicated, Selected };
44
45 struct Adapter;
50 virtual ~EmulationLayerF();
51
53 inline State state() const
54 {
55 return _state;
56 }
58 inline const m5::nfc::f::PICC& emulatePICC() const
59 {
60 return _picc;
61 }
63 inline uint32_t expiredTime() const
64 {
65 return _expired_ms;
66 }
68 void setExpiredTime(const uint32_t ms)
69 {
70 _expired_ms = ms;
71 }
72
74 bool begin(const m5::nfc::f::PICC& picc, uint8_t* ptr, const uint32_t size);
76 bool end();
78 void update();
79
80 virtual State receive_callback(const State s, const uint8_t* rx, const uint32_t rx_len);
81
82protected:
83 void update_expired();
84
85private:
86 void update_off();
87 void update_communicated();
88 void update_selected();
89
90protected:
91 uint8_t* _memory{};
92 uint32_t _memory_size{};
93
94private:
95 State _state{}, _prev{};
96 uint32_t _expired_ms{60 * 1000u};
97 unsigned int _expired_at{};
98 std::unique_ptr<Adapter> _impl;
99 m5::nfc::f::PICC _picc{};
100};
101
103// Impl for units
104struct EmulationLayerF::Adapter {
105 virtual ~Adapter() = default;
106
107 virtual bool start_emulation(const m5::nfc::f::PICC& picc) = 0;
108 virtual bool stop_emulation() = 0;
109 virtual bool transmit(const uint8_t* tx, const uint16_t tx_len, const uint32_t timeout_ms) = 0;
110
111 virtual EmulationLayerF::State update_off() = 0;
112 virtual EmulationLayerF::State update_communicated() = 0;
113 virtual EmulationLayerF::State update_selected() = 0;
114};
116
117} // namespace nfc
118} // namespace m5
119#endif
Common interface layer for each chip of the NFC-F emulation.
Definition emulation_layer_f.hpp:37
void setExpiredTime(const uint32_t ms)
Sets the expiration time (ms)
Definition emulation_layer_f.hpp:68
State state() const
Gets the current emulation state.
Definition emulation_layer_f.hpp:53
const m5::nfc::f::PICC & emulatePICC() const
Gets the emulated PICC information.
Definition emulation_layer_f.hpp:58
State
Emulation state for NFC-F.
Definition emulation_layer_f.hpp:43
bool end()
End NFC-F emulation.
Definition emulation_layer_f.cpp:103
bool begin(const m5::nfc::f::PICC &picc, uint8_t *ptr, const uint32_t size)
Begin NFC-F emulation.
Definition emulation_layer_f.cpp:70
uint32_t expiredTime() const
Gets the expiration time (ms)
Definition emulation_layer_f.hpp:63
void update()
Update emulation state machine.
Definition emulation_layer_f.cpp:112
ST25R3916 unit in CapCC1101 (SPI)
Definition unit_ST25R3916.hpp:2113
ST25R3916 Unit.
Definition unit_ST25R3916.hpp:39
Top level namespace of M5Stack.
NFC related definitions.
Unit-related namespace.
NFC-F definitions.
PICC information for NFC-F.
Definition nfcf.hpp:490