Firmware library for the X-NUCLEO-NFC01A1 Dynamic NFC Tag board.

Dependencies:   M24SR

Dependents:   NFC M2M_2016_STM32 MyongjiElec_capstone1 IDW01M1_Cloud_IBM ... more

Fork of X_NUCLEO_NFC01A1 by ST Expansion SW Team

X-NUCLEO-NFC01A1 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-NFC01A1 Dynamic NFC Tag Expansion Board based on M24SR.

Firmware Library

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

Example applications

1. Hello World
2. Asynchronous Hello World

Revision:
33:e6b7e74be1d5
Parent:
29:7a2dfd06cb29
--- a/m24sr/NDefNfcTagM24SR.cpp	Thu May 18 15:20:43 2017 +0000
+++ b/m24sr/NDefNfcTagM24SR.cpp	Wed Jul 12 14:15:02 2017 +0000
@@ -49,44 +49,40 @@
 ////////////////////////////START  OpenSessionCallBack/////////////////////////
 NDefNfcTagM24SR::OpenSessionCallBack::
 	OpenSessionCallBack(NDefNfcTagM24SR& sender):
-		mSender(sender),mNTrials(OPENSESSION_NTRIALS){}
+		mSender(sender), mNTrials(OPENSESSION_NTRIALS){}
 
-void NDefNfcTagM24SR::OpenSessionCallBack::on_session_open(M24SR *nfc,
-		M24SR::StatusTypeDef status){
-	if(status==M24SR::M24SR_SUCCESS){
+void NDefNfcTagM24SR::OpenSessionCallBack::on_session_open(M24SR *nfc, M24SR::StatusTypeDef status) {
+	if (status==M24SR::M24SR_SUCCESS) {
 		nfc->select_application();
-	}else{
+	} else {
 		mSender.mCallBack->on_session_open(&mSender,false);
 	}
 }
 
-void NDefNfcTagM24SR::OpenSessionCallBack::on_selected_application(M24SR *nfc,
-		M24SR::StatusTypeDef status){
-	if(status==M24SR::M24SR_SUCCESS){
+void NDefNfcTagM24SR::OpenSessionCallBack::on_selected_application(M24SR *nfc, M24SR::StatusTypeDef status) {
+	if (status==M24SR::M24SR_SUCCESS) {
 		nfc->select_CC_file();
-	}else{
-		if(mNTrials==0)
+	} else {
+		if (mNTrials==0) {
 			mSender.mCallBack->on_session_open(&mSender,false);
-		else{
+		} else {
 			mNTrials--;
 			nfc->select_application();
 		}//if-else
 	}//if-else
 }
 
-void NDefNfcTagM24SR::OpenSessionCallBack::on_selected_CC_file(M24SR *nfc,
-		M24SR::StatusTypeDef status){
-	if(status==M24SR::M24SR_SUCCESS){
+void NDefNfcTagM24SR::OpenSessionCallBack::on_selected_CC_file(M24SR *nfc, M24SR::StatusTypeDef status) {
+	if (status==M24SR::M24SR_SUCCESS) {
 		nfc->read_binary(0x0000, CC_FILE_LENGTH_BYTE, CCFile);
-	}else{
+	} else {
 		mSender.mCallBack->on_session_open(&mSender,false);
 	}
 }
 
-void NDefNfcTagM24SR::OpenSessionCallBack::on_read_byte(M24SR *nfc,
-		M24SR::StatusTypeDef status,uint16_t offset,uint8_t *readByte, uint16_t nReadByte){
+void NDefNfcTagM24SR::OpenSessionCallBack::on_read_byte(M24SR *nfc, M24SR::StatusTypeDef status, uint16_t offset, uint8_t *readByte, uint16_t nReadByte) {
 	(void)offset;
-	if(status!=M24SR::M24SR_SUCCESS || nReadByte!=CC_FILE_LENGTH_BYTE){
+	if (status!=M24SR::M24SR_SUCCESS || nReadByte!=CC_FILE_LENGTH_BYTE) {
 		return mSender.mCallBack->on_session_open(&mSender,false);
 	}//else
 	uint16_t NDefFileId = (uint16_t) ((readByte[0x09] << 8) | readByte[0x0A]);
@@ -95,8 +91,7 @@
 	nfc->select_NDEF_file(NDefFileId);
 }
 
-void NDefNfcTagM24SR::OpenSessionCallBack::on_selected_NDEF_file(M24SR *nfc,
-		M24SR::StatusTypeDef status){
+void NDefNfcTagM24SR::OpenSessionCallBack::on_selected_NDEF_file(M24SR *nfc, M24SR::StatusTypeDef status){
 	(void)nfc;
 
 	mSender.mIsSessionOpen = status==M24SR::M24SR_SUCCESS;
@@ -106,18 +101,17 @@
 
 bool NDefNfcTagM24SR::open_session(bool force) {
 
-	if (is_session_open()){
+	if (is_session_open()) {
 		mCallBack->on_session_open(this,true);
 		return true;
 	}
 
 	mDevice.set_callback(&mOpenSessionCallback);
-	if(force)
+	if (force) {
 		return mDevice.force_get_session() == M24SR::M24SR_SUCCESS;
-	else
+	} else {
 		return mDevice.get_session() == M24SR::M24SR_SUCCESS;
-
-
+	}
 }
 
 bool NDefNfcTagM24SR::close_session() {
@@ -126,26 +120,25 @@
 }
 
 void NDefNfcTagM24SR::WriteByteCallback::on_updated_binary(M24SR *nfc,
-		M24SR::StatusTypeDef status,uint16_t startOffset, uint8_t *writeByte,uint16_t nWriteByte){
+	M24SR::StatusTypeDef status,uint16_t startOffset, uint8_t *writeByte,uint16_t nWriteByte){
 
-	if(status!=M24SR::M24SR_SUCCESS){ // error -> finish to write
+	if (status!=M24SR::M24SR_SUCCESS){ // error -> finish to write
 		mCallback(mCallbackParam,false,mByteToWrite,mNByteToWrite);
 		return;
 	}//else
 
 	mByteWrote+=nWriteByte;
-	if(mByteWrote==mNByteToWrite){ //write all -> finish
+	if (mByteWrote==mNByteToWrite) { //write all -> finish
 		mCallback(mCallbackParam,true,mByteToWrite,mNByteToWrite);
-	}else{ //else write another slice
-		uint16_t tempLenght = std::min(mSender.mMaxWriteBytes,
-				(uint16_t)(mNByteToWrite-mByteWrote));
+	} else { //else write another slice
+		uint16_t tempLenght = std::min(mSender.mMaxWriteBytes, (uint16_t)(mNByteToWrite-mByteWrote));
 		nfc->update_binary(startOffset+nWriteByte,tempLenght,writeByte+nWriteByte);
 	}//if-else
 }
 
 bool NDefNfcTagM24SR::writeByte(const uint8_t *buffer, uint16_t length,uint16_t offset,
-		byteOperationCallback_t callback,CallbackStatus_t *callbackStatus){
-	if(!is_session_open())
+	byteOperationCallback_t callback,CallbackStatus_t *callbackStatus){
+	if (!is_session_open())
 		callback(callbackStatus,false,buffer,length);
 	//else
 	mWriteByteCallback.set_task(buffer,length,callback,callbackStatus);
@@ -153,34 +146,31 @@
 
 	if (length > mMaxWriteBytes) {
 		return mDevice.update_binary(offset, mMaxWriteBytes,(uint8_t*) buffer) == M24SR::M24SR_SUCCESS;
-	}else{
+	} else {
 		return mDevice.update_binary(offset,length,(uint8_t*)buffer) == M24SR::M24SR_SUCCESS;
 	}//if-else
-
 }
 
 void NDefNfcTagM24SR::ReadByteCallback::on_read_byte(M24SR *nfc,
-		M24SR::StatusTypeDef status,uint16_t startOffset, uint8_t *readBffer,uint16_t nReadByte){
+	M24SR::StatusTypeDef status,uint16_t startOffset, uint8_t *readBffer,uint16_t nReadByte){
 
-	if(status!=M24SR::M24SR_SUCCESS){ // error -> finish to write
+	if (status!=M24SR::M24SR_SUCCESS) { // error -> finish to write
 		mCallback(mCallbackParam,false,mBuffer,mNByteToRead);
 		return;
 	}//else
 
 	mByteRead += nReadByte;
-	if(mByteRead==mNByteToRead){ //read all -> finish
+	if (mByteRead==mNByteToRead) { //read all -> finish
 		mCallback(mCallbackParam,true,mBuffer,mNByteToRead);
-	}else{ //else write another slice
-		uint16_t tempLenght = std::min(mSender.mMaxReadBytes,
-				(uint16_t)(mNByteToRead-mByteRead));
+	} else { //else write another slice
+		uint16_t tempLenght = std::min(mSender.mMaxReadBytes, (uint16_t)(mNByteToRead-mByteRead));
 		nfc->read_binary(startOffset+nReadByte,tempLenght,readBffer+nReadByte);
 	}//if-else
-
 }
 
 bool NDefNfcTagM24SR::readByte(const uint16_t byteOffset, const uint16_t length,
-		uint8_t *buffer, byteOperationCallback_t callback,CallbackStatus_t *callbackStatus){
-	if(!is_session_open()){
+	uint8_t *buffer, byteOperationCallback_t callback,CallbackStatus_t *callbackStatus) {
+	if (!is_session_open()) {
 		return callback(callbackStatus,false,buffer,length);
 	}
 	//else
@@ -189,8 +179,7 @@
 
 	if (length > mMaxReadBytes) {
 		return mDevice.read_binary(byteOffset, mMaxReadBytes,buffer)== M24SR::M24SR_SUCCESS;;
-	}else{
+	} else {
 		return mDevice.read_binary(byteOffset,length,buffer)== M24SR::M24SR_SUCCESS;;
 	}//if-else
-
 }