X_NUCLEO_NFC02A1 library for M24LR
Dependencies: ST_INTERFACES
Dependents: HelloWorld_NFC02A1_mbedOS HelloWorld_NFC02A1laatste HelloWorld_NFC02A1
Fork of X_NUCLEO_NFC02A1 by
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.
Diff: m24lr/NDefNfcTagM24LR.cpp
- Revision:
- 5:900640bf1cff
- Parent:
- 4:0287f5476fe0
- Child:
- 6:8c1eca41b3a9
--- a/m24lr/NDefNfcTagM24LR.cpp Fri Sep 30 11:46:18 2016 +0000 +++ b/m24lr/NDefNfcTagM24LR.cpp Mon Oct 03 11:57:23 2016 +0000 @@ -96,9 +96,6 @@ uint8_t atlv_detect[4]; uint8_t index = 0; - /* Do not include length bytes */ - DataSize -= FIRST_RECORD_OFFSET; - /* If too many data to write return error */ if( DataSize > NDEF_MAX_SIZE ) { @@ -119,30 +116,36 @@ return status; } - /* Check if L is on 3 or 1 byte and update length in buffer */ if( atlv_detect[1] == NFCT5_3_BYTES_L_TLV ) - { - pData[0] = atlv_detect[2]; - pData[1] = atlv_detect[3]; - index += 4; + index=2; + + if(Offset==0 && DataSize>=2){ + if( atlv_detect[1] == NFCT5_3_BYTES_L_TLV ) + { + pData[0] = atlv_detect[2]; + pData[1] = atlv_detect[3]; + + } + else + { + pData[0] = 0x00; + pData[1] = atlv_detect[1]; + + } + DataSize-=2; + pData+=2; } - else - { - pData[0] = 0x00; - pData[1] = atlv_detect[1]; - index += 2; - } - + /* Check CC file is in the correct mode to proceed */ if( CCFileStruct.State == TT5_INITIALIZED ) { return NDEF_ERROR; } - if( ((Offset == 0) && (DataSize > 0)) || (Offset > 0) ) + if(DataSize > 0) { /* Read NDEF */ - if( NDefReadByte(CCFileStruct.NDEF_offset + index + Offset, DataSize, (pData + FIRST_RECORD_OFFSET)) != NFC_SUCCESS ) + if( NDefReadByte(CCFileStruct.NDEF_offset + index + Offset, DataSize, pData) != NFC_SUCCESS ) { return NDEF_ERROR; } @@ -499,12 +502,28 @@ } uint16_t NDefNfcTagM24LR::NDefWriteByte(const uint8_t *buffer, uint16_t length,uint16_t offset){ - return mDevice.UpdateBinary(offset, length, (uint8_t*)buffer); + uint16_t status; + do{ + uint8_t writeLength =(uint8_t) std::min<uint16_t>(0xFF,length); + status= mDevice.UpdateBinary(offset, writeLength, (uint8_t*)buffer); + offset+=writeLength; + buffer+=writeLength; + length-=writeLength; + }while(status==NDEF_OK && length!=0); + return status; } -uint16_t NDefNfcTagM24LR::NDefReadByte(const uint16_t byteOffset, const uint16_t length, uint8_t *buffer){ - return mDevice.ReadBinary(byteOffset, length, (uint8_t*)buffer); +uint16_t NDefNfcTagM24LR::NDefReadByte(uint16_t byteOffset, uint16_t length, uint8_t *buffer){ + uint16_t status; + do{ + uint8_t readBuffer = (uint8_t)std::min<uint16_t>(0xFF,length); + status= mDevice.ReadBinary(byteOffset, readBuffer, (uint8_t*)buffer); + byteOffset+=readBuffer; + buffer+=readBuffer; + length-=readBuffer; + }while(status==NDEF_OK && length!=0); + return status; } /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/