X_NUCLEO_NFC02A1 library for M24LR

Dependencies:   ST_INTERFACES

Dependents:   HelloWorld_NFC02A1_mbedOS HelloWorld_NFC02A1laatste HelloWorld_NFC02A1

Fork of X_NUCLEO_NFC02A1 by ST Expansion SW Team

X-NUCLEO-NFC02A1 Dynamic NFC Tag Expansion Board Firmware Package

Introduction

This firmware package includes Components Device Drivers, Board Support Package and example applications for STMicroelectronics X-NUCLEO-NFC02A1 Dynamic NFC Tag Expansion Board based on M24LR.

Firmware Library

Class X_NUCLEO_NFC02A1 is intended to represent the Dynamic NFC Tag Expansion Board with the same name.
It provides an API to access to the M24LR component and to the three onboard LEDs.
It is intentionally implemented as a singleton because only one X_NUCLEO_NFC02A1 at a time might be deployed in a HW component stack.
The library also provides an implementation of the NDEF library API for M24LR, providing an simple way to read/write NDEF formatted messages from/to the M24LR dynamic NFC tag.

Example application

Hello World is a simple application to program and read an URI from the NFC tag.

Committer:
Davidroid
Date:
Wed Jul 12 12:34:12 2017 +0000
Revision:
8:7c4cf671960b
Parent:
6:8c1eca41b3a9
Updated to fit ARM mbed coding style.

Who changed what in which revision?

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