Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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
Diff: m24sr/m24sr_class.h
- Revision:
- 21:ccc4f3fed4b3
- Parent:
- 20:aad5727cb8c6
- Child:
- 23:d07138541feb
diff -r aad5727cb8c6 -r ccc4f3fed4b3 m24sr/m24sr_class.h
--- a/m24sr/m24sr_class.h Thu Jan 28 16:38:30 2016 +0000
+++ b/m24sr/m24sr_class.h Fri Jan 29 15:06:30 2016 +0000
@@ -75,6 +75,12 @@
*/
static const NFC_GPO_MGMT DEFAULT_GPO_STATUS=HIGH_IMPEDANCE;
+
+ class Callback : public Nfc::Callback{
+ public:
+
+ };
+
/*** Constructor and Destructor Methods ***/
/**
@@ -98,22 +104,16 @@
mCommunicationType(SYNC),
mLastCommandSend(NONE),
mGpoEventInterrupt(GPOPinName),
- mComponentCallback(NULL),
mManageGPOCallback(*this),
- mReadIDCallback(*this),
- mChangePasswordRequestStatusCallback(*this),
- mRemoveAllPasswordCallback(*this),
- mChangeAccessStateCallback(*this){
+ mReadIDCallback(*this){
memset(uM24SRbuffer, 0, 0xFF * sizeof(int8_t));
uDIDbyte = 0;
RFDisablePin = 0;
- printf("init\n\r");
if(eventCallback!=NULL)
mGpoEventInterrupt.fall(eventCallback);
mGpoEventInterrupt.mode(PullUp);
mGpoEventInterrupt.disable_irq();
- printf("init End\n\r");
}
/**
@@ -142,7 +142,7 @@
return (NFC_StatusTypeDef) M24SR_GetSession();
}
- virtual NFC_StatusTypeDef KillSession(void) {
+ virtual NFC_StatusTypeDef ForceGetSession(void) {
return (NFC_StatusTypeDef) M24SR_KillSession();
}
@@ -247,6 +247,8 @@
return (NFC_StatusTypeDef) M24SR_SendInterrupt();
}
+ virtual NFC_StatusTypeDef ManageEvent();
+
/////////////////// hight level/utility function /////////////////////
/**
@@ -258,84 +260,6 @@
}
- /**
- * Enable the request of a password before reading the tag.
- * @param pCurrentWritePassword Current password (the first time use M24SR::DEFAULT_PASSWORD ).
- * @param pNewPassword Password to request before reading the tag.
- * @return return NFC_SUCCESS if no errors
- * @par The password must have a length of 16 chars.
- */
- NFC_StatusTypeDef enableReadPassword(const uint8_t* pCurrentWritePassword,
- const uint8_t* pNewPassword);
-
- /**
- * Disable the request of a password before reading the tag.
- * @param pCurrentWritePassword Current password (the first time use M24SR::DEFAULT_PASSWORD).
- * @return return NFC_SUCCESS if no errors
- * @par The password must have a length of 16 chars.
- */
- NFC_StatusTypeDef disableReadPassword(const uint8_t* pCurrentWritePassword=M24SR::DEFAULT_PASSWORD);
-
- /**
- * Enable the request of a password before writing to the tag.
- * @param pCurrentWritePassword Current password (the first time use M24SR::DEFAULT_PASSWORD).
- * @param pNewPassword Password to request before reading the tag.
- * @return return NFC_SUCCESS if no errors
- * @par The password must have a length of 16 chars.
- */
- NFC_StatusTypeDef enableWritePassword(const uint8_t* pCurrentWritePassword,
- uint8_t* pNewPassword);
-
- /**
- * Disable the request of a password before writing the tag.
- * @param pCurrentWritePassword Current password (the first time use M24SR::DEFAULT_PASSWORD).
- * @return return NFC_SUCCESS if no errors
- * @par The password must have a length of 16 chars.
- */
- NFC_StatusTypeDef disableWritePassword(const uint8_t* pCurrentWritePassword=M24SR::DEFAULT_PASSWORD);
-
- /**
- * @brief This function disables both read and write passwords.
- * @param pSuperUserPassword I2C super user password.
- * @return return NFC_SUCCESS if no errors
- * @par The password must have a length of 16 chars.
- */
- NFC_StatusTypeDef disableAllPassword(const uint8_t* pSuperUserPassword=M24SR::DEFAULT_PASSWORD);
-
- /**
- * @brief This function enables read only mode.
- * @param pCurrentWritePassword Write password is needed to enable read only mode.
- * @return return NFC_SUCCESS if no errors
- * @par The password must have a length of 16 chars.
- */
- NFC_StatusTypeDef enableReadOnly(const uint8_t* pCurrentWritePassword=M24SR::DEFAULT_PASSWORD);
-
- /**
- * @brief This function disables read only mode.
- * @param pCurrentWritePassword Write password is needed to disable read only mode.
- * @return return NFC_SUCCESS if no errors
- * @par The password must have a length of 16 chars.
- */
- NFC_StatusTypeDef disableReadOnly();
-
- /**
- * @brief This function enables write only mode.
- * @param pCurrentWritePassword Write password is needed to enable write only mode.
- * @return return NFC_SUCCESS if no errors
- * @par The password must have a length of 16 chars.
- */
- NFC_StatusTypeDef enableWriteOnly(const uint8_t* pCurrentWritePassword=M24SR::DEFAULT_PASSWORD);
-
- /**
- * @brief This function disables write only mode.
- * @param pCurrentWritePassword Write password is needed to disable write only mode.
- * @return return NFC_SUCCESS if no errors
- * @par The password must have a length of 16 chars.
- */
- NFC_StatusTypeDef disableWriteOnly();
-
- virtual NFC_StatusTypeDef ManageEvent();
-
protected:
/*** Protected Component Related Methods ***/
@@ -537,23 +461,6 @@
InterruptIn mGpoEventInterrupt;
private:
- /**
- * Object with private callback used for hide height level commands
- * that require more than one low level command.
- * This object has an height priority comparing the user callback
- */
- Nfc::Callback *mComponentCallback;
-
- /**
- * get the callback object to use
- * @return callback object to use
- */
- Nfc::Callback * getCallback(){
- if(mComponentCallback!=NULL)
- return mComponentCallback;
- return mCallback;
- }//getCallback
-
/**
* Object with the callback used to send a ManageGPO command.
@@ -610,7 +517,7 @@
onFinishCommand(nfc,status);
}
- virtual void onVerifyed(Nfc *nfc,NFC_StatusTypeDef status){
+ virtual void onVerifyed(Nfc *nfc,NFC_StatusTypeDef status,PasswordType_t, const uint8_t*){
if(status!=NFC_SUCCESS)
return onFinishCommand(nfc,status);
@@ -736,10 +643,7 @@
mParent.getCallback()->onReadId(nfc,status,mIdPtr);
}
- /**
- * component where run the command
- */
- M24SR &mParent;
+ M24SR& mParent;
/**
* location where write the read id
@@ -747,302 +651,13 @@
uint8_t *mIdPtr;
};
+ friend class ReadIDCallback;
/**
* Object containing the callback chain needed to read the component id
*/
ReadIDCallback mReadIDCallback;
/**
- * This class permit to enable/disable the password request for read/write into the tag
- * This class is equivalent to call the method:
- * To enable the request:
- * <ul>
- * <li> Verify </li>
- * <li> ChangeReferenceData </li>
- * <li> EnablePermanentState </li>
- * </ul>
- * To disable the request:
- * <ul>
- * <li> Verify </li>
- * <li> DisableVerificationRequirement </li>
- * </ul>
- */
- class ChangePasswordRequestStatusCallback : public Nfc::Callback{
-
- public:
-
- /**
- * Build the chain of callback.
- * @param parent object where send the command
- */
- ChangePasswordRequestStatusCallback(M24SR &parent):
- mParent(parent),mNewPwd(NULL),
- mType(I2CPwd),mEnable(false){}
-
- /**
- * Set the password to enable/disable.
- * @param type Type of password to enable/disable.
- * @param newPwd Array of 16bytes with the new password, if null the request will be disabled.
- */
- void setTask(PasswordType_t type, const uint8_t *newPwd){
- mNewPwd=newPwd;
- mType=type;
- mEnable=newPwd!=NULL;
- }//setTask
-
- virtual void onVerifyed(Nfc *nfc, NFC_StatusTypeDef status){
- if(status!=NFC_SUCCESS)
- return onFinishCommand(nfc,status);
- if(mEnable)
- nfc->ChangeReferenceData(mType,mNewPwd);
- else
- nfc->DisableVerificationRequirement(mType);
- }
-
- virtual void onDisableVerificationRequirement(Nfc *nfc,
- NFC_StatusTypeDef status, PasswordType_t ){
- onFinishCommand(nfc,status);
- }
-
- virtual void onChangeReferenceData(Nfc *nfc, NFC_StatusTypeDef status,
- PasswordType_t type,
- uint8_t *){
- if(status==NFC_SUCCESS)
- nfc->EnablePermanentState(type);
- else
- onFinishCommand(nfc,status);
- }
-
- virtual void onEnablePermanentState(Nfc *nfc, NFC_StatusTypeDef status,
- PasswordType_t ){
- onFinishCommand(nfc,status);
- }
-
-
- private:
-
- /**
- * Remove the private callback and call the user callback.
- * @param nfc Object where the command is run.
- * @param status Command status.
- */
- void onFinishCommand(Nfc *nfc,NFC_StatusTypeDef status){
- mParent.mComponentCallback=NULL;
- if(mEnable){
- if(mType==ReadPwd){
- mParent.getCallback()->onEnableReadPassword(nfc,status,mNewPwd);
- }else
- mParent.getCallback()->onEnableWritePassword(nfc,status,mNewPwd);
- }else{
- if(mType==ReadPwd){
- mParent.getCallback()->onDisableReadPassword(nfc,status);
- }else
- mParent.getCallback()->onDisableWritePassword(nfc,status);
- }//if-else enable
- }//onFinish
-
- M24SR &mParent;
-
- const uint8_t *mNewPwd;
- Nfc::PasswordType_t mType;
- bool mEnable;
-
- };
-
- /**
- * Object containing the callback chain needed to change the password request
- */
- ChangePasswordRequestStatusCallback mChangePasswordRequestStatusCallback;
-
- /**
- * This class permit to disable all the password request for read/write into the tag
- * This class is equivalent to call the methods:
- * <ul>
- * <li> Verify(i2c) </li>
- * <li> DisablePermanentState(Read) </li>
- * <li> DisablePermanentState(write) </li>
- * <li> DisableVerificationRequirement(Read) </li>
- * <li> DisableVerificationRequirement(write) </li>
- * <li> ChangeReferenceData(Read) </li>
- * <li> ChangeReferenceData(write) </li>
- * </ul>
- */
- class RemoveAllPasswordCallback : public Nfc::Callback{
-
- public:
-
- /**
- * Build the chain of callback.
- * @param parent object where send the command
- */
- RemoveAllPasswordCallback(M24SR &parent):
- mParent(parent){}
-
- virtual void onVerifyed(Nfc *nfc,NFC_StatusTypeDef status){
- if(status!=NFC_SUCCESS)
- return onFinishCommand(nfc,status);
- nfc->DisablePermanentState(ReadPwd);
- }
-
- virtual void onDisablePermanentState(Nfc *nfc , NFC_StatusTypeDef status,
- PasswordType_t type){
- if(status!=NFC_SUCCESS)
- return onFinishCommand(nfc,status);
- if(type==ReadPwd)
- nfc->DisablePermanentState(WritePwd);
- else
- nfc->DisableVerificationRequirement(ReadPwd);
- }
-
- virtual void onDisableVerificationRequirement(Nfc *nfc ,
- NFC_StatusTypeDef status,PasswordType_t type){
- if(status!=NFC_SUCCESS)
- return onFinishCommand(nfc,status);
- if(type==ReadPwd)
- nfc->DisableVerificationRequirement(WritePwd);
- else
- nfc->ChangeReferenceData(ReadPwd,DEFAULT_PASSWORD);
- }
-
- virtual void onChangeReferenceData(Nfc *nfc ,NFC_StatusTypeDef status,PasswordType_t type,
- uint8_t *data){
- if(status!=NFC_SUCCESS)
- return onFinishCommand(nfc,status);
- if(type==ReadPwd)
- nfc->ChangeReferenceData(WritePwd,data);
- else
- onFinishCommand(nfc,status);
- }
-
- private:
-
- /**
- * Remove the private callback and call the onDisableAllPassword callback.
- * @param nfc Object where the command is run.
- * @param status Command status.
- */
- void onFinishCommand(Nfc *nfc,NFC_StatusTypeDef status){
- mParent.mComponentCallback=NULL;
- mParent.getCallback()->onDisableAllPassword(nfc,status);
- }//onFinish
-
- M24SR &mParent;
- };
-
- /**
- * Object containing the callback chain needed remove the password request
- */
- RemoveAllPasswordCallback mRemoveAllPasswordCallback;
-
- /**
- * This class permit set the tag as read/write only
- * This class is equivalent to call the methods:
- * <ul>
- * <li> Verify(i2c) </li>
- * <li> EnablePermanentState(Read/write) </li>
- * </ul>
- * or:
- * <ul>
- * <li> Verify(i2c) </li>
- * <li> DisableVerificationRequirement(Read/write) </li>
- * </ul>
- */
- class ChangeAccessStateCallback : public Nfc::Callback{
-
- public:
-
- typedef enum{
- WRITE,
- READ
- }AccessType_t;
-
- /**
- * Build the chain of callback.
- * @param parent object where send the command
- */
- ChangeAccessStateCallback(M24SR &parent):
- mParent(parent),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
- */
- void changeAccessState(AccessType_t type,bool enable){
- mType=type;
- mEnable=enable;
- }
-
- virtual void onVerifyed(Nfc *nfc,NFC_StatusTypeDef status){
- if(status!=NFC_SUCCESS)
- return onFinishCommand(nfc,status);
-
- if(mEnable){
- nfc->DisablePermanentState(mType==WRITE? WritePwd : ReadPwd);
- }else
- nfc->EnablePermanentState(mType==WRITE? WritePwd : ReadPwd);
-
- }
-
- virtual void onDisablePermanentState(Nfc *nfc, NFC_StatusTypeDef status,
- PasswordType_t type ){
- if(status!=NFC_SUCCESS)
- return onFinishCommand(nfc,status);
-
- nfc->DisableVerificationRequirement(type);
- }
-
- virtual void onDisableVerificationRequirement(Nfc *nfc , NFC_StatusTypeDef status,
- PasswordType_t ){
- onFinishCommand(nfc,status);
- }
-
- virtual void onEnablePermanentState(Nfc *nfc ,NFC_StatusTypeDef status,PasswordType_t ){
- onFinishCommand(nfc,status);
- }
-
-
- private:
-
- /**
- * Remove the private callback and call the user callback.
- * @param nfc Object where the command is run.
- * @param status Command status.
- */
- void onFinishCommand(Nfc *nfc,NFC_StatusTypeDef status){
- mParent.mComponentCallback=NULL;
- if(mEnable){
- if(mType==READ){
- //enable read = disable write only
- mParent.getCallback()->onDisableWriteOnly(nfc,status);
- }else
- //enable write = disable read only
- mParent.getCallback()->onDisableReadOnly(nfc,status);
- }else{
- if(mType==WRITE){
- //disable write = enable read only
- mParent.getCallback()->onEnableReadOnly(nfc,status);
- }else{
- //
- mParent.getCallback()->onEnableWriteOnly(nfc,status);
- }
- }//if-else enable
- }//onFinish
-
- M24SR &mParent;
-
- AccessType_t mType;
- bool mEnable;
-
- };
-
- /**
- * Object containing the callback chain needed to change the access state
- */
- ChangeAccessStateCallback mChangeAccessStateCallback;
-
-
- /**
* Convert a generic enum to the value used by the M24SR chip.
* @param type Password type.
* @return equivalent value used inside the m24sr chip */

X-NUCLEO-NFC01A1 Dynamic NFC Tag