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
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 23:d07138541feb, committed 2016-02-01
- Comitter:
- giovannivisentini
- Date:
- Mon Feb 01 15:32:40 2016 +0000
- Parent:
- 21:ccc4f3fed4b3
- Child:
- 24:9f98eafa2d39
- Commit message:
- update docs
Changed in this revision
--- a/Interfaces/Nfc_class.h Fri Jan 29 15:06:30 2016 +0000
+++ b/Interfaces/Nfc_class.h Mon Feb 01 15:32:40 2016 +0000
@@ -60,7 +60,7 @@
* thought a callback.
* The default behavior is sync mode.
* For enable the async mode you have to call the ManageI2CGPO(I2C_ANSWER_READY) function.
- * Then when an interrupt happen you have to call the {@link ManageInterrupt} function.
+ * When the component notify an interrupt you have to call the {@link ManageInterrupt} function.
* Note that when you call ManageI2CGPO with other parameters the component will return in sync mode.
*/
class Nfc : public Component
@@ -76,6 +76,10 @@
I2CPwd, //!< Root password, used only thought nfc
}PasswordType_t;
+ /**
+ * Function that will be called when an interrupt is fired,
+ * this function must be set if you want use the component in async mode.
+ */
typedef void(*gpoEventCallback)(void);
/**
@@ -231,7 +235,7 @@
virtual NFC_StatusTypeDef SelectCCfile(void) = 0;
/**
- * Select the ndef file.
+ * Select the NDEF file.
* @param NDEFfileId File id to open.
* @return NFC_SUCCESS if the file is selected
*/
@@ -330,6 +334,8 @@
* @brief This function configures GPO for I2C session.
* @param GPO_I2Cconfig GPO configuration to set.
* @return NFC_SUCCESS if no errors
+ * @par if the configuration is I2C_ANSWER_READY, the component will start to work
+ * in async mode.
*/
virtual NFC_StatusTypeDef ManageI2CGPO(NFC_GPO_MGMT GPO_I2Cconfig) = 0;
@@ -355,8 +361,8 @@
virtual NFC_StatusTypeDef SendInterrupt(void)=0;
/**
- * Change the function to call when a command ends
- * @param commandCallback object containings the callback, if NULL it will use empty callback
+ * Change the function to call when a command ends.
+ * @param commandCallback Object containing the callback, if NULL it will use empty callback
*/
void SetCallback(Callback *commandCallback){
if(commandCallback!=NULL)
@@ -366,7 +372,7 @@
}
/**
- * function to call when the component fire an interrupt
+ * Function to call when the component fire an interrupt.
* @return last operation status
*/
virtual NFC_StatusTypeDef ManageEvent()=0;
@@ -381,7 +387,7 @@
* @return return NFC_SUCCESS if no errors
* @par The password must have a length of 16 chars.
*/
- NFC_StatusTypeDef enableReadPassword(const uint8_t* pCurrentWritePassword,
+ NFC_StatusTypeDef EnableReadPassword(const uint8_t* pCurrentWritePassword,
const uint8_t* pNewPassword) {
//enable the callback for change the gpo
@@ -397,7 +403,7 @@
* @return return NFC_SUCCESS if no errors
* @par The password must have a length of 16 chars.
*/
- NFC_StatusTypeDef disableReadPassword(const uint8_t* pCurrentWritePassword) {
+ NFC_StatusTypeDef DisableReadPassword(const uint8_t* pCurrentWritePassword) {
mComponentCallback = &mChangePasswordRequestStatusCallback;
mChangePasswordRequestStatusCallback.setTask(ReadPwd,NULL);
@@ -411,7 +417,7 @@
* @return return NFC_SUCCESS if no errors
* @par The password must have a length of 16 chars.
*/
- NFC_StatusTypeDef enableWritePassword(const uint8_t* pCurrentWritePassword,
+ NFC_StatusTypeDef EnableWritePassword(const uint8_t* pCurrentWritePassword,
uint8_t* pNewPassword) {
//enable the callback for change the gpo
mComponentCallback = &mChangePasswordRequestStatusCallback;
@@ -426,7 +432,7 @@
* @return return NFC_SUCCESS if no errors
* @par The password must have a length of 16 chars.
*/
- NFC_StatusTypeDef disableWritePassword(const uint8_t* pCurrentWritePassword) {
+ NFC_StatusTypeDef DisableWritePassword(const uint8_t* pCurrentWritePassword) {
mComponentCallback = &mChangePasswordRequestStatusCallback;
mChangePasswordRequestStatusCallback.setTask(WritePwd,NULL);
@@ -439,9 +445,8 @@
* @return return NFC_SUCCESS if no errors
* @par The password must have a length of 16 chars.
*/
- NFC_StatusTypeDef disableAllPassword(const uint8_t* pSuperUserPassword){
+ NFC_StatusTypeDef DisableAllPassword(const uint8_t* pSuperUserPassword){
mComponentCallback = &mRemoveAllPasswordCallback;
- mRemoveAllPasswordCallback.setPwd(pSuperUserPassword);
return Verify(Nfc::I2CPwd, 0x10, pSuperUserPassword);
}
@@ -451,13 +456,13 @@
* @return return NFC_SUCCESS if no errors
* @par The password must have a length of 16 chars.
*/
- NFC_StatusTypeDef enableReadOnly(const uint8_t* pCurrentWritePassword){
+ NFC_StatusTypeDef EnableReadOnly(const uint8_t* pCurrentWritePassword){
mComponentCallback = &mChangeAccessStateCallback;
//disable write = read only
mChangeAccessStateCallback.changeAccessState(ChangeAccessStateCallback::WRITE,false);
- return Verify(Nfc::I2CPwd, 0x10, pCurrentWritePassword);
+ return Verify(Nfc::WritePwd, 0x10, pCurrentWritePassword);
}
/**
@@ -466,7 +471,7 @@
* @return return NFC_SUCCESS if no errors
* @par The password must have a length of 16 chars.
*/
- NFC_StatusTypeDef disableReadOnly(const uint8_t* pCurrentWritePassword) {
+ NFC_StatusTypeDef DisableReadOnly(const uint8_t* pCurrentWritePassword) {
mComponentCallback = &mChangeAccessStateCallback;
mChangeAccessStateCallback.changeAccessState(ChangeAccessStateCallback::WRITE,true);
return Verify(Nfc::I2CPwd, 0x10,pCurrentWritePassword);
@@ -479,13 +484,13 @@
* @return return NFC_SUCCESS if no errors
* @par The password must have a length of 16 chars.
*/
- NFC_StatusTypeDef enableWriteOnly(const uint8_t* pCurrentWritePassword) {
+ NFC_StatusTypeDef EnableWriteOnly(const uint8_t* pCurrentWritePassword) {
mComponentCallback = &mChangeAccessStateCallback;
//disable read = enable write only
mChangeAccessStateCallback.changeAccessState(ChangeAccessStateCallback::READ,false);
- return Verify(Nfc::I2CPwd, 0x10, pCurrentWritePassword);
+ return Verify(Nfc::WritePwd, 0x10, pCurrentWritePassword);
}
@@ -495,7 +500,7 @@
* @return return NFC_SUCCESS if no errors
* @par The password must have a length of 16 chars.
*/
- NFC_StatusTypeDef disableWriteOnly(const uint8_t* pCurrentWritePassword) {
+ NFC_StatusTypeDef DisableWriteOnly(const uint8_t* pCurrentWritePassword) {
mComponentCallback = &mChangeAccessStateCallback;
mChangeAccessStateCallback.changeAccessState(ChangeAccessStateCallback::READ,true);
return Verify(Nfc::I2CPwd, 0x10, pCurrentWritePassword);
@@ -530,7 +535,7 @@
/**
- * This class permit to enable/disable the password request for read/write into the tag
+ * This class permit to enable/disable the password request to read/write into the tag
* This class is equivalent to call the method:
* To enable the request:
* <ul>
@@ -625,14 +630,15 @@
};
- friend class ChangePasswordRequestStatusCallback;
+
/**
* Object containing the callback chain needed to change the password request
*/
ChangePasswordRequestStatusCallback mChangePasswordRequestStatusCallback;
+ friend class ChangePasswordRequestStatusCallback;
/**
- * This class permit to disable all the password request for read/write into the tag
+ * This class permit to disable all the password request to read/write into the tag
* This class is equivalent to call the methods:
* <ul>
* <li> Verify(i2c) </li>
@@ -646,6 +652,10 @@
*/
class RemoveAllPasswordCallback : public Nfc::Callback{
+ /**
+ * Store the default password used for open a super user session
+ * it will be set as default read/write password
+ */
const uint8_t *mI2CPwd;
public:
@@ -656,14 +666,11 @@
*/
RemoveAllPasswordCallback():mI2CPwd(NULL){}
- void setPwd(const uint8_t *pwd){
- mI2CPwd = pwd;
- }
-
virtual void onVerifyed(Nfc *nfc,NFC_StatusTypeDef status,
- PasswordType_t,const uint8_t*){
+ PasswordType_t,const uint8_t* data){
if(status!=NFC_SUCCESS)
return onFinishCommand(nfc,status);
+ mI2CPwd = data;
nfc->DisablePermanentState(ReadPwd);
}
@@ -712,11 +719,12 @@
};
- friend class RemoveAllPasswordCallback;
+
/**
* Object containing the callback chain needed remove the password request
*/
RemoveAllPasswordCallback mRemoveAllPasswordCallback;
+ friend class RemoveAllPasswordCallback;
/**
* This class permit set the tag as read/write only
@@ -748,9 +756,9 @@
ChangeAccessStateCallback():mType(WRITE),mEnable(false){}
/**
- * Set the access to enable/disable
- * @param type Type to enable or disable
- * @param enable true for enable the state, false for disable it
+ * Set the access to enable/disable.
+ * @param type Type to enable or disable.
+ * @param enable true for enable the state, false for disable it.
*/
void changeAccessState(AccessType_t type,bool enable){
mType=type;
@@ -819,11 +827,12 @@
};
- friend class ChangeAccessStateCallback;
+
/**
* Object containing the callback chain needed to change the access state
*/
ChangeAccessStateCallback mChangeAccessStateCallback;
+ friend class ChangeAccessStateCallback;
};
--- a/m24sr/NDefNfcTagM24SR.cpp Fri Jan 29 15:06:30 2016 +0000 +++ b/m24sr/NDefNfcTagM24SR.cpp Mon Feb 01 15:32:40 2016 +0000 @@ -193,4 +193,3 @@ }//if-else } -
--- a/m24sr/NDefNfcTagM24SR.h Fri Jan 29 15:06:30 2016 +0000
+++ b/m24sr/NDefNfcTagM24SR.h Mon Feb 01 15:32:40 2016 +0000
@@ -115,6 +115,7 @@
class OpenSessionCallBack: public Nfc::Callback{
public:
OpenSessionCallBack(NDefNfcTagM24SR &sender);
+
virtual void onSessionOpen(Nfc *nfc,NFC_StatusTypeDef status);
virtual void onSelectedApplication(Nfc *nfc,NFC_StatusTypeDef status);
virtual void onSelectedCCFile(Nfc *nfc,NFC_StatusTypeDef status);
@@ -123,12 +124,24 @@
virtual void onSelectedNDEFFile(Nfc *nfc,NFC_StatusTypeDef status);
private:
+ /**
+ * Object that send the open session callback
+ */
NDefNfcTagM24SR &mSender;
+
+ /**
+ * number of trials done for open the session
+ */
uint32_t mNTrials;
+
+ /**
+ * buffer where read the CC file
+ */
uint8_t CCFile[15];
};
OpenSessionCallBack mOpenSessionCallback;
+ friend class OpenSessionCallBack;
/**
* Class containing the callback needed to close a session
@@ -148,10 +161,15 @@
}//if-else
}
private:
+
+ /**
+ * Object that send the open session callback
+ */
NDefNfcTagM24SR &mSender;
};
CloseSessionCallBack mCloseSessionCallback;
+ friend class OpenSessionCallBack;
/**
* Class containing the callback needed to write a buffer
@@ -173,10 +191,10 @@
/**
* Set the buffer to write and the function to call when finish
- * @param buffer buffer to write
- * @param nByte number of bytes to write
- * @param callback function to call when the write ends
- * @param param parameter to pass to the callback function
+ * @param buffer Buffer to write.
+ * @param nByte Number of bytes to write.
+ * @param callback Function to call when the write ends.
+ * @param param Parameter to pass to the callback function.
*/
void setTask(const uint8_t *buffer,uint16_t nByte,
byteOperationCallback_t callback,CallbackStatus_t *param){
@@ -192,6 +210,7 @@
private:
+
/** buffer to write */
const uint8_t *mByteToWrite;
/** length of the buffer */
@@ -209,6 +228,7 @@
};
WriteByteCallback mWriteByteCallback;
+ friend class WriteByteCallback;
/**
* Class containing the callback needed to read a buffer
@@ -282,6 +302,7 @@
};
ReadByteCallback mReadByteCallback;
+ friend class ReadByteCallback;
};
--- a/m24sr/m24sr_class.cpp Fri Jan 29 15:06:30 2016 +0000
+++ b/m24sr/m24sr_class.cpp Mon Feb 01 15:32:40 2016 +0000
@@ -54,7 +54,7 @@
#define M24SR_MAX_BYTE_OPERATION_LENGHT (246)
/**
- * default password, also used to enable super user mode throught the I2C channel
+ * default password, also used to enable super user mode through the I2C channel
*/
const uint8_t M24SR::DEFAULT_PASSWORD[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
@@ -281,7 +281,7 @@
NFC_StatusTypeDef M24SR::M24SR_Init(M24SR_InitTypeDef *notUsed) {
(void) notUsed;
//force to open a i2c session
- errchk(M24SR_KillSession())
+ errchk(M24SR_ForceSession())
//leave the gpo always up
errchk(M24SR_ManageI2CGPO(DEFAULT_GPO_STATUS))
errchk(M24SR_ManageRFGPO(DEFAULT_GPO_STATUS))
@@ -297,7 +297,7 @@
* @param None
* @return NFC_SUCCESS if no errors
*/
-NFC_StatusTypeDef M24SR::M24SR_KillSession(void) {
+NFC_StatusTypeDef M24SR::M24SR_ForceSession(void) {
uint8_t commandBuffer[] = M24SR_KILLSESSION_COMMAND;
NFC_StatusTypeDef status;
status = M24SR_IO_SendI2Ccommand(sizeof(commandBuffer), commandBuffer);
--- a/m24sr/m24sr_class.h Fri Jan 29 15:06:30 2016 +0000
+++ b/m24sr/m24sr_class.h Mon Feb 01 15:32:40 2016 +0000
@@ -71,16 +71,10 @@
static const uint8_t DEFAULT_PASSWORD[16];
/**
- * Default gpo status
+ * Default gpo status -> the gpo will remain high
*/
static const NFC_GPO_MGMT DEFAULT_GPO_STATUS=HIGH_IMPEDANCE;
-
- class Callback : public Nfc::Callback{
- public:
-
- };
-
/*** Constructor and Destructor Methods ***/
/**
@@ -143,7 +137,7 @@
}
virtual NFC_StatusTypeDef ForceGetSession(void) {
- return (NFC_StatusTypeDef) M24SR_KillSession();
+ return (NFC_StatusTypeDef) M24SR_ForceSession();
}
virtual NFC_StatusTypeDef Deselect(void) {
@@ -267,7 +261,9 @@
NFC_StatusTypeDef M24SR_Init(M24SR_InitTypeDef *);
NFC_StatusTypeDef M24SR_ReadID(uint8_t *nfc_id);
NFC_StatusTypeDef M24SR_GetSession(void);
- NFC_StatusTypeDef M24SR_KillSession(void);
+ NFC_StatusTypeDef M24SR_ForceSession(void);
+
+
NFC_StatusTypeDef M24SR_Deselect(void);
NFC_StatusTypeDef M24SR_ReceiveDeselect(void);
@@ -405,7 +401,7 @@
NDefNfcTagM24SR NDefTagUtil;
/**
- * command that the component can accept
+ * Command that the component can accept
*/
typedef enum{
NONE, //!< NONE
@@ -427,7 +423,8 @@
}M24SR_command_t;
/**
- * parameter used for invoke the command
+ * User parameter used invoke the command, it is used for remember the data between a
+ * command and a rensponse
*/
typedef struct{
uint8_t *data; //!< data
@@ -436,7 +433,7 @@
}M24SR_command_data_t;
/**
- * communication mode used by this device
+ * Communication mode used by this device
*/
typedef enum{
SYNC,//!< SYNC wait the command response before return
@@ -444,20 +441,23 @@
}M24SR_communication_t;
/**
- * type of communication that we are using
+ * Type of communication that we are using
*/
M24SR_communication_t mCommunicationType;
/**
- * the class is wait the answer of this command
+ * The class is wait the answer of this command
*/
M24SR_command_t mLastCommandSend;
/**
- * parameter used for invoke the last command
+ * Parameter used for invoke the last command
*/
M24SR_command_data_t mLastCommandData;
+ /**
+ * Interrupt object fired when the gpo status change
+ */
InterruptIn mGpoEventInterrupt;
private:

X-NUCLEO-NFC01A1 Dynamic NFC Tag