Mistake on this page?
Report an issue in GitHub or email us
NFCEEPROM.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2018 ARM Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MBED_NFC_EEPROM_H
18 #define MBED_NFC_EEPROM_H
19 
20 #include <stdint.h>
21 #include "events/EventQueue.h"
22 
23 #include "NFCDefinitions.h"
24 #include "NFCTarget.h"
25 #include "NFCEEPROMDriver.h"
26 
27 namespace mbed {
28 namespace nfc {
29 
30 /** @addtogroup nfc
31  * @{
32  */
33 
34 /**
35  * The NFC EEPROM class represents a NFC target device connected using a wired
36  * link (I2C, SPI, etc).
37  *
38  * These EEPROMs essentially provide addressable memory that can be accessed
39  * using either a wired or NFC interface.
40  *
41  * In NFC mode these most often conform to one of the NFC tag types defined
42  * by the NFC Forum, therefore encoding NDEF data in these EEPROMs will
43  * ensure that it is understandable by a NFC reader.
44  */
46 public:
47  /**
48  * Construct a NFCEEPROM instance.
49  *
50  * @param[in] driver a pointer to a NFCEEPROMDriver instance
51  * @param[in] queue a pointer to the events queue to use
52  * @param[in] ndef_buffer a bytes array used to store NDEF messages
53  */
54  NFCEEPROM(NFCEEPROMDriver *driver, events::EventQueue *queue, const Span<uint8_t> &ndef_buffer);
55 
56  /**
57  * The NFCEEPROM delegate. Users of the NFCEEPROM class need to implement this delegate's methods to receive events.
58  */
60  /**
61  * The NDEF message erasing request completed.
62  *
63  * @param[in] result NFC_OK or an error code on failure
64  */
65  virtual void on_ndef_message_erased(nfc_err_t result) {}
66 
67  /**
68  * The NDEF message writing request completed.
69  *
70  * @param[in] result NFC_OK or an error code on failure
71  */
72  virtual void on_ndef_message_written(nfc_err_t result) {}
73 
74  /**
75  * The NDEF message reading request completed.
76  *
77  * @param[in] result NFC_OK or an error code on failure
78  */
79  virtual void on_ndef_message_read(nfc_err_t result) {}
80 
81  protected:
82  ~Delegate() {}
83  };
84 
85  /**
86  * Initialize the NFC EEPROM
87  *
88  * This method must be called before any other method call.
89  *
90  * @return NFC_OK, or an error.
91  */
93 
94  /**
95  * Set the delegate that will receive events generated by this EEPROM.
96  *
97  * @param[in] delegate the delegate instance to use
98  */
99  void set_delegate(Delegate *delegate);
100 
101  // Implementation of NFCTarget
102  virtual void write_ndef_message();
103  virtual void read_ndef_message();
104  virtual void erase_ndef_message();
105 
106 private:
107  // Implementation of NFCEEPROMDriver::Delegate
108  virtual void on_session_started(bool success);
109  virtual void on_session_ended(bool success);
110  virtual void on_bytes_read(size_t count);
111  virtual void on_bytes_written(size_t count);
112  virtual void on_size_written(bool success);
113  virtual void on_size_read(bool success, size_t size);
114  virtual void on_bytes_erased(size_t count);
115 
116  void handle_error(nfc_err_t ret);
117  void continue_write();
118  void continue_read();
119  void continue_erase();
120 
121  // NFCNDEFCapable implementation
122  virtual NFCNDEFCapable::Delegate *ndef_capable_delegate();
123 
124  enum nfc_eeprom_operation_t {
125  nfc_eeprom_idle,
126 
127  nfc_eeprom_write_start_session,
128  nfc_eeprom_write_write_size,
129  nfc_eeprom_write_write_bytes,
130  nfc_eeprom_write_end_session,
131 
132  nfc_eeprom_read_start_session,
133  nfc_eeprom_read_read_size,
134  nfc_eeprom_read_read_bytes,
135  nfc_eeprom_read_end_session,
136 
137  nfc_eeprom_erase_start_session,
138  nfc_eeprom_erase_write_max_size,
139  nfc_eeprom_erase_erase_bytes,
140  nfc_eeprom_erase_write_0_size,
141  nfc_eeprom_erase_end_session
142  };
143 
144  Delegate *_delegate;
145  NFCEEPROMDriver *_driver;
146  events::EventQueue *_event_queue;
147  bool _initialized;
148 
149  nfc_eeprom_operation_t _current_op;
150  ac_buffer_t _ndef_buffer_reader;
151  size_t _ndef_buffer_read_sz;
152  uint32_t _eeprom_address;
153  nfc_err_t _operation_result;
154 };
155 /** @}*/
156 } // namespace nfc
157 } // namespace mbed
158 
159 #endif
NFCEEPROM(NFCEEPROMDriver *driver, events::EventQueue *queue, const Span< uint8_t > &ndef_buffer)
Construct a NFCEEPROM instance.
virtual void on_ndef_message_read(nfc_err_t result)
The NDEF message reading request completed.
Definition: NFCEEPROM.h:79
EventQueue.
Definition: EventQueue.h:62
The abstraction for a NFC EEPROM driver.
This class represents a NFC target (either a remote target when the local controller in in initiator ...
Definition: NFCTarget.h:40
nfc_err_t initialize()
Initialize the NFC EEPROM.
The NFCEEPROM delegate.
Definition: NFCEEPROM.h:59
virtual void on_ndef_message_erased(nfc_err_t result)
The NDEF message erasing request completed.
Definition: NFCEEPROM.h:65
int nfc_err_t
Type for NFC errors.
Definition: nfc_errors.h:59
virtual void write_ndef_message()
Write a NDEF message to the target.
void set_delegate(Delegate *delegate)
Set the delegate that will receive events generated by this EEPROM.
The NFC EEPROM class represents a NFC target device connected using a wired link (I2C, SPI, etc).
Definition: NFCEEPROM.h:45
virtual void on_ndef_message_written(nfc_err_t result)
The NDEF message writing request completed.
Definition: NFCEEPROM.h:72
virtual void erase_ndef_message()
Erase the NDEF message in the target.
virtual void read_ndef_message()
Read a NDEF message from the target.
Definition: ATHandler.h:46
The NFCEEPROMDriver delegate.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.