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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
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 /** @addtogroup nfc 00031 * @{ 00032 */ 00033 00034 /** 00035 * The NFC EEPROM class represents a NFC target device connected using a wired 00036 * link (I2C, SPI, etc). 00037 * 00038 * These EEPROMs essentially provide addressable memory that can be accessed 00039 * using either a wired or NFC interface. 00040 * 00041 * In NFC mode these most often conform to one of the NFC tag types defined 00042 * by the NFC Forum, therefore encoding NDEF data in these EEPROMs will 00043 * ensure that it is understandable by a NFC reader. 00044 */ 00045 class NFCEEPROM : public NFCTarget, public NFCEEPROMDriver::Delegate { 00046 public: 00047 /** 00048 * Construct a NFCEEPROM instance. 00049 * 00050 * @param[in] driver a pointer to a NFCEEPROMDriver instance 00051 * @param[in] queue a pointer to the events queue to use 00052 * @param[in] ndef_buffer a bytes array used to store NDEF messages 00053 */ 00054 NFCEEPROM(NFCEEPROMDriver *driver, events::EventQueue *queue, const Span<uint8_t> &ndef_buffer); 00055 00056 /** 00057 * The NFCEEPROM delegate. Users of the NFCEEPROM class need to implement this delegate's methods to receive events. 00058 */ 00059 struct Delegate : NFCTarget::Delegate { 00060 /** 00061 * The NDEF message erasing request completed. 00062 * 00063 * @param[in] result NFC_OK or an error code on failure 00064 */ 00065 virtual void on_ndef_message_erased(nfc_err_t result) {} 00066 00067 /** 00068 * The NDEF message writing request completed. 00069 * 00070 * @param[in] result NFC_OK or an error code on failure 00071 */ 00072 virtual void on_ndef_message_written(nfc_err_t result) {} 00073 00074 /** 00075 * The NDEF message reading request completed. 00076 * 00077 * @param[in] result NFC_OK or an error code on failure 00078 */ 00079 virtual void on_ndef_message_read(nfc_err_t result) {} 00080 00081 protected: 00082 ~Delegate() {} 00083 }; 00084 00085 /** 00086 * Initialize the NFC EEPROM 00087 * 00088 * This method must be called before any other method call. 00089 * 00090 * @return NFC_OK, or an error. 00091 */ 00092 nfc_err_t initialize(); 00093 00094 /** 00095 * Set the delegate that will receive events generated by this EEPROM. 00096 * 00097 * @param[in] delegate the delegate instance to use 00098 */ 00099 void set_delegate(Delegate *delegate); 00100 00101 // Implementation of NFCTarget 00102 virtual void write_ndef_message(); 00103 virtual void read_ndef_message(); 00104 virtual void erase_ndef_message(); 00105 00106 private: 00107 // Implementation of NFCEEPROMDriver::Delegate 00108 virtual void on_session_started(bool success); 00109 virtual void on_session_ended(bool success); 00110 virtual void on_bytes_read(size_t count); 00111 virtual void on_bytes_written(size_t count); 00112 virtual void on_size_written(bool success); 00113 virtual void on_size_read(bool success, size_t size); 00114 virtual void on_bytes_erased(size_t count); 00115 00116 void handle_error(nfc_err_t ret); 00117 void continue_write(); 00118 void continue_read(); 00119 void continue_erase(); 00120 00121 // NFCNDEFCapable implementation 00122 virtual NFCNDEFCapable::Delegate *ndef_capable_delegate(); 00123 00124 enum nfc_eeprom_operation_t { 00125 nfc_eeprom_idle, 00126 00127 nfc_eeprom_write_start_session, 00128 nfc_eeprom_write_write_size, 00129 nfc_eeprom_write_write_bytes, 00130 nfc_eeprom_write_end_session, 00131 00132 nfc_eeprom_read_start_session, 00133 nfc_eeprom_read_read_size, 00134 nfc_eeprom_read_read_bytes, 00135 nfc_eeprom_read_end_session, 00136 00137 nfc_eeprom_erase_start_session, 00138 nfc_eeprom_erase_write_max_size, 00139 nfc_eeprom_erase_erase_bytes, 00140 nfc_eeprom_erase_write_0_size, 00141 nfc_eeprom_erase_end_session 00142 }; 00143 00144 Delegate *_delegate; 00145 NFCEEPROMDriver *_driver; 00146 events::EventQueue *_event_queue; 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 } // namespace nfc 00157 } // namespace mbed 00158 00159 #endif
Generated on Tue Jul 12 2022 13:54:38 by
