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