Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: nRF51_Vdd TextLCD BME280
NFCEEPROM.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2018 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef MBED_NFC_EEPROM_H 00018 #define MBED_NFC_EEPROM_H 00019 00020 #include <stdint.h> 00021 #include "events/EventQueue.h" 00022 00023 #include "NFCDefinitions.h" 00024 #include "NFCTarget.h" 00025 #include "NFCEEPROMDriver.h" 00026 00027 namespace mbed { 00028 namespace nfc { 00029 00030 /** 00031 * @addtogroup nfc 00032 * @{ 00033 */ 00034 00035 /** 00036 * The NFC EEPROM class represents a NFC target device connected using a wired 00037 * link (I2C, SPI, etc). 00038 * 00039 * These EEPROMs essentially provide addressable memory that can be accessed 00040 * using either a wired or NFC interface. 00041 * 00042 * In NFC mode these most often conform to one of the NFC tag types defined 00043 * by the NFC Forum, therefore encoding NDEF data in these EEPROMs will 00044 * ensure that it is understandable by a NFC reader. 00045 */ 00046 class NFCEEPROM : public NFCTarget, public NFCEEPROMDriver::Delegate { 00047 public: 00048 /** 00049 * Construct a NFCEEPROM instance. 00050 * 00051 * @param[in] driver a pointer to a NFCEEPROMDriver instance 00052 * @param[in] queue a pointer to the events queue to use 00053 * @param[in] ndef_buffer a bytes array used to store NDEF messages 00054 */ 00055 NFCEEPROM(NFCEEPROMDriver *driver, events::EventQueue *queue, const Span<uint8_t> &ndef_buffer); 00056 00057 /** 00058 * The NFCEEPROM delegate. Users of the NFCEEPROM class need to implement this delegate's methods to receive events. 00059 */ 00060 struct Delegate : NFCTarget::Delegate { 00061 /** 00062 * The NDEF message erasing request completed. 00063 * 00064 * @param[in] result NFC_OK or an error code on failure 00065 */ 00066 virtual void on_ndef_message_erased(nfc_err_t result) {} 00067 00068 /** 00069 * The NDEF message writing request completed. 00070 * 00071 * @param[in] result NFC_OK or an error code on failure 00072 */ 00073 virtual void on_ndef_message_written(nfc_err_t result) {} 00074 00075 /** 00076 * The NDEF message reading request completed. 00077 * 00078 * @param[in] result NFC_OK or an error code on failure 00079 */ 00080 virtual void on_ndef_message_read(nfc_err_t result) {} 00081 00082 protected: 00083 ~Delegate() {} 00084 }; 00085 00086 /** 00087 * Initialize the NFC EEPROM 00088 * 00089 * This method must be called before any other method call. 00090 * 00091 * @return NFC_OK, or an error. 00092 */ 00093 nfc_err_t initialize(); 00094 00095 /** 00096 * Set the delegate that will receive events generated by this EEPROM. 00097 * 00098 * @param[in] delegate the delegate instance to use 00099 */ 00100 void set_delegate(Delegate *delegate); 00101 00102 // Implementation of NFCTarget 00103 virtual void write_ndef_message(); 00104 virtual void read_ndef_message(); 00105 virtual void erase_ndef_message(); 00106 00107 private: 00108 // Implementation of NFCEEPROMDriver::Delegate 00109 virtual void on_session_started(bool success); 00110 virtual void on_session_ended(bool success); 00111 virtual void on_bytes_read(size_t count); 00112 virtual void on_bytes_written(size_t count); 00113 virtual void on_size_written(bool success); 00114 virtual void on_size_read(bool success, size_t size); 00115 virtual void on_bytes_erased(size_t count); 00116 00117 void handle_error(nfc_err_t ret); 00118 void continue_write(); 00119 void continue_read(); 00120 void continue_erase(); 00121 00122 // NFCNDEFCapable implementation 00123 virtual NFCNDEFCapable::Delegate *ndef_capable_delegate(); 00124 00125 enum nfc_eeprom_operation_t { 00126 nfc_eeprom_idle, 00127 00128 nfc_eeprom_write_start_session, 00129 nfc_eeprom_write_write_size, 00130 nfc_eeprom_write_write_bytes, 00131 nfc_eeprom_write_end_session, 00132 00133 nfc_eeprom_read_start_session, 00134 nfc_eeprom_read_read_size, 00135 nfc_eeprom_read_read_bytes, 00136 nfc_eeprom_read_end_session, 00137 00138 nfc_eeprom_erase_start_session, 00139 nfc_eeprom_erase_write_max_size, 00140 nfc_eeprom_erase_erase_bytes, 00141 nfc_eeprom_erase_write_0_size, 00142 nfc_eeprom_erase_end_session 00143 }; 00144 00145 Delegate *_delegate; 00146 NFCEEPROMDriver *_driver; 00147 bool _initialized; 00148 00149 nfc_eeprom_operation_t _current_op; 00150 ac_buffer_t _ndef_buffer_reader; 00151 size_t _ndef_buffer_read_sz; 00152 uint32_t _eeprom_address; 00153 nfc_err_t _operation_result; 00154 }; 00155 00156 /** 00157 * @} 00158 */ 00159 00160 00161 } // namespace nfc 00162 } // namespace mbed 00163 00164 #endif
Generated on Tue Jul 12 2022 15:15:54 by
