X_NUCLEO_NFC02A1 library for M24LR
Dependencies: ST_INTERFACES
Dependents: HelloWorld_NFC02A1_mbedOS HelloWorld_NFC02A1laatste HelloWorld_NFC02A1
Fork of X_NUCLEO_NFC02A1 by
NDefNfcTagM24LR.h
00001 /** 00002 ****************************************************************************** 00003 * @file NdefNfcTagM24LR.h 00004 * @author AMG Central Lab 00005 * @version V2.0.0 00006 * @date 19 May 2017 00007 * @brief M24LR specific NDefLib derived class 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 #ifndef X_NUCLEO_NFC02A1_M24LR_NDEFNFCTAGM24LR_H_ 00039 #define X_NUCLEO_NFC02A1_M24LR_NDEFNFCTAGM24LR_H_ 00040 00041 #include <cstdlib> 00042 #include <stdint.h> 00043 00044 #include "NDefNfcTag.h" 00045 #include "Nfc.h" 00046 00047 00048 #define NDEF_OK 0 00049 #define NDEF_ERROR 1 00050 #define NDEF_ERROR_MEMORY_TAG 2 00051 #define NDEF_ERROR_MEMORY_INTERNAL 3 00052 #define NDEF_ERROR_LOCKED 4 00053 #define NDEF_ERROR_NOT_FORMATED 5 00054 00055 /** 00056 * Helper class to use the NDefLib 00057 */ 00058 00059 00060 class NDefNfcTagM24LR: public NDefLib::NDefNfcTag { 00061 00062 public: 00063 00064 /** 00065 * 00066 * @param device device to use 00067 */ 00068 NDefNfcTagM24LR (Nfc &device) : 00069 NDefLib::NDefNfcTag(), 00070 mDevice(device),mIsSessionOpen(false), 00071 mMaxReadBytes(0xFF), mMaxWriteBytes(0xFF){} 00072 00073 virtual bool open_session(bool force = false); 00074 00075 virtual bool close_session(); 00076 00077 virtual bool is_session_open(){ 00078 return mIsSessionOpen; 00079 } 00080 00081 /** 00082 * Close the open session. 00083 */ 00084 virtual ~NDefNfcTagM24LR() { 00085 if(is_session_open()) 00086 close_session(); 00087 }//~NDefNfcTagM24SR 00088 00089 protected: 00090 virtual bool writeByte(const uint8_t *buffer, uint16_t length,uint16_t offset, 00091 byteOperationCallback_t callback,CallbackStatus_t *callbackStatus); 00092 00093 virtual bool readByte(const uint16_t byteOffset, const uint16_t byteLength, 00094 uint8_t *buffer, byteOperationCallback_t callback,CallbackStatus_t *callbackStatus); 00095 00096 private: 00097 uint16_t NDefWriteByte(const uint8_t *buffer, uint16_t length,uint16_t offset); 00098 uint16_t NDefReadByte(uint16_t byteOffset, uint16_t length, uint8_t *buffer); 00099 00100 uint16_t ReadData( uint16_t Offset , uint16_t DataSize , uint8_t* pData ); 00101 uint16_t WriteData( uint16_t Offset , uint32_t DataSize , uint8_t *pData ); 00102 uint16_t NfcType5_WriteCCFile( const uint8_t * const pCCBuffer ); 00103 uint16_t NfcType5_ReadCCFile( uint8_t * const pCCBuffer ); 00104 uint16_t NfcType5_TT5Init( void ); 00105 uint16_t NfcType5_NDEFDetection( void ); 00106 Nfc &mDevice; 00107 00108 /** 00109 * true if the session is open 00110 */ 00111 bool mIsSessionOpen; 00112 00113 /** 00114 * Max length for a read operation 00115 */ 00116 uint16_t mMaxReadBytes; 00117 00118 /** 00119 * Max length for a write operation 00120 */ 00121 uint16_t mMaxWriteBytes; 00122 typedef enum 00123 { 00124 TT5_NO_NDEF = 0, 00125 TT5_INITIALIZED, 00126 TT5_READ_WRITE, 00127 TT5_READ 00128 } TT5_State; 00129 00130 /** 00131 * @brief CCfile structure 00132 */ 00133 typedef struct 00134 { 00135 uint8_t MagicNumber; /* Magic Number should be E1h or E2h */ 00136 uint8_t Version; 00137 uint8_t MemorySize; 00138 uint8_t TT5Tag; 00139 uint8_t rsved1; 00140 uint8_t rsved2; 00141 uint16_t ExtMemorySize; 00142 TT5_State State; 00143 uint32_t NDEF_offset; 00144 } sCCFileInfo; 00145 00146 sCCFileInfo CCFileStruct; 00147 }; 00148 00149 #endif /* X_NUCLEO_NFC02A1_M24LR_NDEFNFCTAGM24LR_H_ */ 00150 00151 00152 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Wed Jul 13 2022 03:37:30 by
