M5Unit-NFC 0.0.3 git rev:59f5362
Loading...
Searching...
No Matches
emulation_layer_a.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_A_EMULATION_LAYER_A_HPP
18#define M5_UNIT_NFC_NFC_LAYER_A_EMULATION_LAYER_A_HPP
19
20#include "nfc/a/nfca.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, Idle, Ready, Active, Halt };
44
45 struct Adapter;
50
52 inline State state() const
53 {
54 return _state;
55 }
57 inline const m5::nfc::a::PICC& emulatePICC() const
58 {
59 return _picc;
60 }
62 inline uint32_t expiredTime() const
63 {
64 return _expired_ms;
65 }
67 void setExpiredTime(const uint32_t ms)
68 {
69 _expired_ms = ms;
70 }
71
73 bool begin(const m5::nfc::a::PICC& picc, uint8_t* ptr, const uint32_t size);
75 bool end();
77 void update();
78
79 virtual State receive_callback(const uint8_t* rx, const uint32_t rx_len);
80
81protected:
82 void update_expired();
83
84private:
85 void update_off();
86 void update_idle();
87 void update_ready();
88 void update_active();
89 void update_halt();
90
91protected:
92 uint8_t* _memory{};
93 uint32_t _memory_size{};
94
95private:
96 State _state{}, _prev{};
97 uint32_t _expired_ms{60 * 1000u};
98 unsigned int _expired_at{};
99 std::unique_ptr<Adapter> _impl;
100 m5::nfc::a::PICC _picc{};
101};
102
104// Impl for units
105struct EmulationLayerA::Adapter {
106 virtual ~Adapter() = default;
107
108 virtual bool start_emulation(const m5::nfc::a::PICC& picc) = 0;
109 virtual bool stop_emulation() = 0;
110 virtual bool transmit(const uint8_t* tx, const uint16_t tx_len, const uint32_t timeout_ms) = 0;
111
112 virtual EmulationLayerA::State update_off() = 0;
113 virtual EmulationLayerA::State update_idle() = 0;
114 virtual EmulationLayerA::State update_ready() = 0;
115 virtual EmulationLayerA::State update_active() = 0;
116 virtual EmulationLayerA::State update_halt() = 0;
117};
119
120} // namespace nfc
121} // namespace m5
122#endif
Common interface layer for each chip of the NFC-A emulation.
Definition emulation_layer_a.hpp:37
bool end()
End NFC-A emulation.
Definition emulation_layer_a.cpp:60
const m5::nfc::a::PICC & emulatePICC() const
Gets the emulated PICC information.
Definition emulation_layer_a.hpp:57
State
Emulation state for NFC-A.
Definition emulation_layer_a.hpp:43
bool begin(const m5::nfc::a::PICC &picc, uint8_t *ptr, const uint32_t size)
Begin NFC-A emulation.
Definition emulation_layer_a.cpp:31
void setExpiredTime(const uint32_t ms)
Sets the expiration time (ms)
Definition emulation_layer_a.hpp:67
uint32_t expiredTime() const
Gets the expiration time (ms)
Definition emulation_layer_a.hpp:62
void update()
Update emulation state machine.
Definition emulation_layer_a.cpp:69
State state() const
Gets the current emulation state.
Definition emulation_layer_a.hpp:52
ST25R3916 unit in CapCC1101 (SPI)
Definition unit_ST25R3916.hpp:2062
ST25R3916 Unit.
Definition unit_ST25R3916.hpp:38
Top level namespace of M5stack.
NFC related definitions.
Unit-related namespace.
NFC-A definitions.
PICC for NFC-A.
Definition nfca.hpp:335