M5Unit-NFC 0.1.1 git rev:9bb1360
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
40public:
45 enum class State { None, Off, Idle, Ready, Active, Halt };
46
47 struct Adapter;
52 virtual ~EmulationLayerA();
53
55 inline State state() const
56 {
57 return _state;
58 }
60 inline const m5::nfc::a::PICC& emulatePICC() const
61 {
62 return _picc;
63 }
65 inline uint32_t expiredTime() const
66 {
67 return _expired_ms;
68 }
70 void setExpiredTime(const uint32_t ms)
71 {
72 _expired_ms = ms;
73 }
74
76 bool begin(const m5::nfc::a::PICC& picc, uint8_t* ptr, const uint32_t size);
78 bool end();
80 void update();
81
82 virtual State receive_callback(const uint8_t* rx, const uint32_t rx_len);
83
84protected:
85 void update_expired();
86
87private:
88 void update_off();
89 void update_idle();
90 void update_ready();
91 void update_active();
92 void update_halt();
93
94protected:
95 uint8_t* _memory{};
96 uint32_t _memory_size{};
97
98private:
99 State _state{}, _prev{};
100 uint32_t _expired_ms{60 * 1000u};
101 unsigned int _expired_at{};
102 std::unique_ptr<Adapter> _impl;
103 m5::nfc::a::PICC _picc{};
104};
105
107// Impl for units
108struct EmulationLayerA::Adapter {
109 virtual ~Adapter() = default;
110
111 virtual bool start_emulation(const m5::nfc::a::PICC& picc) = 0;
112 virtual bool stop_emulation() = 0;
113 virtual bool transmit(const uint8_t* tx, const uint16_t tx_len, const uint32_t timeout_ms) = 0;
114
115 virtual EmulationLayerA::State update_off() = 0;
116 virtual EmulationLayerA::State update_idle() = 0;
117 virtual EmulationLayerA::State update_ready() = 0;
118 virtual EmulationLayerA::State update_active() = 0;
119 virtual EmulationLayerA::State update_halt() = 0;
120};
122
123} // namespace nfc
124} // namespace m5
125#endif
Common interface layer for each chip of the NFC-A emulation.
Definition emulation_layer_a.hpp:39
bool end()
End NFC-A emulation.
Definition emulation_layer_a.cpp:62
const m5::nfc::a::PICC & emulatePICC() const
Gets the emulated PICC information.
Definition emulation_layer_a.hpp:60
State
Emulation state for NFC-A.
Definition emulation_layer_a.hpp:45
bool begin(const m5::nfc::a::PICC &picc, uint8_t *ptr, const uint32_t size)
Begin NFC-A emulation.
Definition emulation_layer_a.cpp:33
void setExpiredTime(const uint32_t ms)
Sets the expiration time (ms)
Definition emulation_layer_a.hpp:70
uint32_t expiredTime() const
Gets the expiration time (ms)
Definition emulation_layer_a.hpp:65
void update()
Update emulation state machine.
Definition emulation_layer_a.cpp:72
State state() const
Gets the current emulation state.
Definition emulation_layer_a.hpp:55
ST25R3916 unit in CapCC1101 (SPI)
Definition unit_ST25R3916.hpp:2150
ST25R3916 Unit.
Definition unit_ST25R3916.hpp:39
Top level namespace of M5Stack.
NFC related definitions.
Unit-related namespace.
NFC-A definitions.
PICC for NFC-A.
Definition nfca.hpp:481