mbed OS 5 example application using X-NUCLEO-NFC02A1

Dependencies:   NDefLib X_NUCLEO_NFC02A1

Fork of HelloWorld_NFC02A1 by ST

Committer:
rosarium
Date:
Wed Sep 28 11:26:49 2016 +0000
Revision:
2:6f1b1f7f8d12
Parent:
1:11ae12d41082
New Nfc interface file integrated.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rosarium 1:11ae12d41082 1 /**
rosarium 1:11ae12d41082 2 ******************************************************************************
rosarium 1:11ae12d41082 3 * @file NdefNfcTagM24LR.h
rosarium 1:11ae12d41082 4 * @author AMG Central Lab
rosarium 1:11ae12d41082 5 * @version V1.0.0
rosarium 1:11ae12d41082 6 * @date 30 Aug 2016
rosarium 1:11ae12d41082 7 * @brief M24LR specific NDefLib derived class
rosarium 1:11ae12d41082 8 ******************************************************************************
rosarium 1:11ae12d41082 9 * @attention
rosarium 1:11ae12d41082 10 *
rosarium 1:11ae12d41082 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
rosarium 1:11ae12d41082 12 *
rosarium 1:11ae12d41082 13 * Redistribution and use in source and binary forms, with or without modification,
rosarium 1:11ae12d41082 14 * are permitted provided that the following conditions are met:
rosarium 1:11ae12d41082 15 * 1. Redistributions of source code must retain the above copyright notice,
rosarium 1:11ae12d41082 16 * this list of conditions and the following disclaimer.
rosarium 1:11ae12d41082 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
rosarium 1:11ae12d41082 18 * this list of conditions and the following disclaimer in the documentation
rosarium 1:11ae12d41082 19 * and/or other materials provided with the distribution.
rosarium 1:11ae12d41082 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
rosarium 1:11ae12d41082 21 * may be used to endorse or promote products derived from this software
rosarium 1:11ae12d41082 22 * without specific prior written permission.
rosarium 1:11ae12d41082 23 *
rosarium 1:11ae12d41082 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
rosarium 1:11ae12d41082 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
rosarium 1:11ae12d41082 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
rosarium 1:11ae12d41082 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
rosarium 1:11ae12d41082 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
rosarium 1:11ae12d41082 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
rosarium 1:11ae12d41082 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
rosarium 1:11ae12d41082 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
rosarium 1:11ae12d41082 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
rosarium 1:11ae12d41082 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
rosarium 1:11ae12d41082 34 *
rosarium 1:11ae12d41082 35 ******************************************************************************
rosarium 1:11ae12d41082 36 */
rosarium 1:11ae12d41082 37
rosarium 1:11ae12d41082 38 #ifndef X_NUCLEO_NFC02A1_M24LR_NDEFNFCTAGM24LR_H_
rosarium 1:11ae12d41082 39 #define X_NUCLEO_NFC02A1_M24LR_NDEFNFCTAGM24LR_H_
rosarium 1:11ae12d41082 40
rosarium 1:11ae12d41082 41 #include <cstdlib>
rosarium 1:11ae12d41082 42 #include <stdint.h>
rosarium 1:11ae12d41082 43
rosarium 1:11ae12d41082 44 #include "NDefNfcTag.h"
rosarium 2:6f1b1f7f8d12 45 #include "Nfc.h"
rosarium 1:11ae12d41082 46
rosarium 2:6f1b1f7f8d12 47 #define NFC_OK 0
rosarium 1:11ae12d41082 48 #define NDEF_OK 0
rosarium 1:11ae12d41082 49 #define NDEF_ERROR 1
rosarium 1:11ae12d41082 50 #define NDEF_ERROR_MEMORY_TAG 2
rosarium 1:11ae12d41082 51 #define NDEF_ERROR_MEMORY_INTERNAL 3
rosarium 1:11ae12d41082 52 #define NDEF_ERROR_LOCKED 4
rosarium 1:11ae12d41082 53 #define NDEF_ERROR_NOT_FORMATED 5
rosarium 1:11ae12d41082 54
rosarium 1:11ae12d41082 55 /**
rosarium 1:11ae12d41082 56 * Helper class to use the NDefLib
rosarium 1:11ae12d41082 57 */
rosarium 1:11ae12d41082 58
rosarium 1:11ae12d41082 59
rosarium 1:11ae12d41082 60 class NDefNfcTagM24LR: public NDefLib::NDefNfcTag {
rosarium 1:11ae12d41082 61
rosarium 1:11ae12d41082 62 public:
rosarium 1:11ae12d41082 63
rosarium 1:11ae12d41082 64 /**
rosarium 1:11ae12d41082 65 *
rosarium 1:11ae12d41082 66 * @param device device to use
rosarium 1:11ae12d41082 67 */
rosarium 1:11ae12d41082 68 NDefNfcTagM24LR(Nfc &device) :
rosarium 1:11ae12d41082 69 NDefLib::NDefNfcTag(),
rosarium 1:11ae12d41082 70 mDevice(device),mIsSessionOpen(false),
rosarium 1:11ae12d41082 71 mMaxReadBytes(0xFF), mMaxWriteBytes(0xFF){}
rosarium 1:11ae12d41082 72
rosarium 1:11ae12d41082 73 virtual bool openSession(bool force = false);
rosarium 1:11ae12d41082 74
rosarium 1:11ae12d41082 75 virtual bool closeSession();
rosarium 1:11ae12d41082 76
rosarium 1:11ae12d41082 77 virtual bool isSessionOpen(){
rosarium 1:11ae12d41082 78 return mIsSessionOpen;
rosarium 1:11ae12d41082 79 }
rosarium 2:6f1b1f7f8d12 80
rosarium 1:11ae12d41082 81 /**
rosarium 1:11ae12d41082 82 * Close the open session.
rosarium 1:11ae12d41082 83 */
rosarium 1:11ae12d41082 84 virtual ~NDefNfcTagM24LR(){
rosarium 1:11ae12d41082 85 if(isSessionOpen())
rosarium 1:11ae12d41082 86 closeSession();
rosarium 1:11ae12d41082 87 }//~NDefNfcTagM24SR
rosarium 1:11ae12d41082 88
rosarium 1:11ae12d41082 89 protected:
rosarium 1:11ae12d41082 90
rosarium 1:11ae12d41082 91 virtual bool writeByte(const uint8_t *buffer, uint16_t length,uint16_t offset,
rosarium 1:11ae12d41082 92 byteOperationCallback_t callback,CallbackStatus_t *callbackStatus);
rosarium 1:11ae12d41082 93
rosarium 1:11ae12d41082 94 virtual bool readByte(const uint16_t byteOffset, const uint16_t byteLength,
rosarium 1:11ae12d41082 95 uint8_t *buffer, byteOperationCallback_t callback,CallbackStatus_t *callbackStatus);
rosarium 1:11ae12d41082 96 bool NDefWriteByte(const uint8_t *buffer, uint16_t length,uint16_t offset);
rosarium 1:11ae12d41082 97
rosarium 1:11ae12d41082 98
rosarium 2:6f1b1f7f8d12 99
rosarium 1:11ae12d41082 100
rosarium 1:11ae12d41082 101 private:
rosarium 2:6f1b1f7f8d12 102 bool NDefReadByte(const uint16_t byteOffset, const uint16_t length,
rosarium 2:6f1b1f7f8d12 103 uint8_t *buffer);
rosarium 1:11ae12d41082 104
rosarium 2:6f1b1f7f8d12 105 uint16_t ReadData( uint16_t Offset , uint16_t DataSize , uint8_t* pData );
rosarium 2:6f1b1f7f8d12 106 uint16_t WriteData( uint16_t Offset , uint32_t DataSize , uint8_t *pData );
rosarium 2:6f1b1f7f8d12 107 uint16_t NfcType5_WriteCCFile( const uint8_t * const pCCBuffer );
rosarium 2:6f1b1f7f8d12 108 uint16_t NfcType5_ReadCCFile( uint8_t * const pCCBuffer );
rosarium 2:6f1b1f7f8d12 109 uint16_t NfcType5_TT5Init( void );
rosarium 2:6f1b1f7f8d12 110 uint16_t NfcType5_NDEFDetection( void );
rosarium 1:11ae12d41082 111 Nfc &mDevice;
rosarium 1:11ae12d41082 112
rosarium 1:11ae12d41082 113 /**
rosarium 1:11ae12d41082 114 * true if the session is open
rosarium 1:11ae12d41082 115 */
rosarium 1:11ae12d41082 116 bool mIsSessionOpen;
rosarium 1:11ae12d41082 117
rosarium 1:11ae12d41082 118 /**
rosarium 1:11ae12d41082 119 * Max length for a read operation
rosarium 1:11ae12d41082 120 */
rosarium 1:11ae12d41082 121 uint16_t mMaxReadBytes;
rosarium 1:11ae12d41082 122
rosarium 1:11ae12d41082 123 /**
rosarium 1:11ae12d41082 124 * Max length for a write operation
rosarium 1:11ae12d41082 125 */
rosarium 1:11ae12d41082 126 uint16_t mMaxWriteBytes;
rosarium 2:6f1b1f7f8d12 127 typedef enum
rosarium 2:6f1b1f7f8d12 128 {
rosarium 2:6f1b1f7f8d12 129 TT5_NO_NDEF = 0,
rosarium 2:6f1b1f7f8d12 130 TT5_INITIALIZED,
rosarium 2:6f1b1f7f8d12 131 TT5_READ_WRITE,
rosarium 2:6f1b1f7f8d12 132 TT5_READ
rosarium 2:6f1b1f7f8d12 133 } TT5_State;
rosarium 2:6f1b1f7f8d12 134
rosarium 2:6f1b1f7f8d12 135 /**
rosarium 2:6f1b1f7f8d12 136 * @brief CCfile structure
rosarium 2:6f1b1f7f8d12 137 */
rosarium 2:6f1b1f7f8d12 138 typedef struct
rosarium 2:6f1b1f7f8d12 139 {
rosarium 2:6f1b1f7f8d12 140 uint8_t MagicNumber; /* Magic Number should be E1h or E2h */
rosarium 2:6f1b1f7f8d12 141 uint8_t Version;
rosarium 2:6f1b1f7f8d12 142 uint8_t MemorySize;
rosarium 2:6f1b1f7f8d12 143 uint8_t TT5Tag;
rosarium 2:6f1b1f7f8d12 144 uint8_t rsved1;
rosarium 2:6f1b1f7f8d12 145 uint8_t rsved2;
rosarium 2:6f1b1f7f8d12 146 uint16_t ExtMemorySize;
rosarium 2:6f1b1f7f8d12 147 TT5_State State;
rosarium 2:6f1b1f7f8d12 148 uint32_t NDEF_offset;
rosarium 2:6f1b1f7f8d12 149 }sCCFileInfo;
rosarium 1:11ae12d41082 150
rosarium 1:11ae12d41082 151 sCCFileInfo CCFileStruct;
rosarium 1:11ae12d41082 152
rosarium 1:11ae12d41082 153 };
rosarium 1:11ae12d41082 154
rosarium 1:11ae12d41082 155 #endif /* X_NUCLEO_NFC02A1_M24LR_NDEFNFCTAGM24LR_H_ */
rosarium 2:6f1b1f7f8d12 156
rosarium 2:6f1b1f7f8d12 157
rosarium 2:6f1b1f7f8d12 158 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/