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:
- 19:0b65a5813059
- Parent:
- 18:10def2fefa8a
- Child:
- 20:aad5727cb8c6
- Child:
- 22:ac2e9a086341
diff -r 10def2fefa8a -r 0b65a5813059 m24sr/m24sr_class.h
--- a/m24sr/m24sr_class.h Fri Jan 22 09:04:51 2016 +0000
+++ b/m24sr/m24sr_class.h Thu Jan 28 14:01:18 2016 +0000
@@ -69,28 +69,49 @@
* Default password used to change the write/read permission
*/
static const uint8_t DEFAULT_PASSWORD[16];
-
+
+ /**
+ * Default gpo status
+ */
+ static const NFC_GPO_MGMT DEFAULT_GPO_STATUS=HIGH_IMPEDANCE;
+
/*** Constructor and Destructor Methods ***/
/**
* @brief Constructor.
* @param address I2C address of the component.
* @param I2C I2C device to be used for communication.
+ * @param eventCallback Function that will be called when the gpo pin status change.
* @param GPOPinName Pin used as GPIO.
* @param RFDISPinName Pin used to disable the RF function.
*/
- M24SR(const uint8_t address, I2C &I2C, const PinName& GPOPinName,
+ M24SR(const uint8_t address, I2C &I2C,gpoEventCallback eventCallback, const PinName& GPOPinName,
const PinName& RFDISPinName) :
- Nfc(), address(address), dev_I2C(I2C), GPOPin(GPOPinName), RFDisablePin(
- RFDISPinName), answerReadyInterrupt(GPOPinName), interruptIsFired(
- false),NDefTagUtil(*this) {
+ Nfc(),
+ who_am_i(0),
+ type(0),
+ address(address),
+ dev_I2C(I2C),
+ GPOPin(GPOPinName),
+ RFDisablePin(RFDISPinName),
+ NDefTagUtil(*this),
+ mCommunicationType(SYNC),
+ mLastCommandSend(NONE),
+ mGpoEventInterrupt(GPOPinName),
+ mComponentCallback(NULL),
+ mManageGPOCallback(*this),
+ mReadIDCallback(*this),
+ mChangePasswordRequestStatusCallback(*this),
+ mRemoveAllPasswordCallback(*this),
+ mChangeAccessStateCallback(*this){
+
memset(uM24SRbuffer, 0, 0xFF * sizeof(int8_t));
uDIDbyte = 0;
RFDisablePin = 0;
- GPOPin.mode(PullNone);
- answerReadyInterrupt.fall(this,
- &M24SR::M24SR_AnswerReadyInterruptCallback);
- answerReadyInterrupt.mode(PullUp);
+
+ mGpoEventInterrupt.fall(eventCallback);
+ mGpoEventInterrupt.mode(PullUp);
+ mGpoEventInterrupt.disable_irq();
}
/**
@@ -130,30 +151,30 @@
////////// tag4 command ////////////////////
virtual NFC_StatusTypeDef SelectApplication(void) {
- return (NFC_StatusTypeDef) M24SR_SelectApplication();
+ return M24SR_SendSelectApplication();
}
virtual NFC_StatusTypeDef SelectCCfile(void) {
- return (NFC_StatusTypeDef) M24SR_SelectCCfile();
+ return M24SR_SendSelectCCfile();
}
virtual NFC_StatusTypeDef SelectNDEFfile(uint16_t NDEFfileId) {
- return (NFC_StatusTypeDef) M24SR_SelectNDEFfile((uint16_t) NDEFfileId);
+ return M24SR_SendSelectNDEFfile(NDEFfileId);
}
virtual NFC_StatusTypeDef SelectSystemfile(void) {
- return (NFC_StatusTypeDef) M24SR_SelectSystemfile();
+ return M24SR_SendSelectSystemfile();
}
virtual NFC_StatusTypeDef ReadBinary(uint16_t Offset, uint8_t NbByteToRead,
uint8_t *pBufferRead) {
- return (NFC_StatusTypeDef) M24SR_ReadBinary((uint16_t) Offset,
+ return (NFC_StatusTypeDef) M24SR_SendReadBinary((uint16_t) Offset,
(uint8_t) NbByteToRead, (uint8_t *) pBufferRead);
}
virtual NFC_StatusTypeDef UpdateBinary(uint16_t Offset,
- uint8_t NbByteToWrite, uint8_t *pDataToWrite) {
- return (NFC_StatusTypeDef) M24SR_UpdateBinary((uint16_t) Offset,
+ uint8_t NbByteToWrite,uint8_t *pDataToWrite) {
+ return (NFC_StatusTypeDef) M24SR_SendUpdateBinary((uint16_t) Offset,
(uint8_t) NbByteToWrite, (uint8_t *) pDataToWrite);
}
@@ -161,25 +182,25 @@
virtual NFC_StatusTypeDef Verify(PasswordType_t pwdId, uint8_t NbPwdByte,
const uint8_t *pPwd) {
- return (NFC_StatusTypeDef) M24SR_Verify(passwordTypeToConst(pwdId),
+ return (NFC_StatusTypeDef) M24SR_SendVerify(passwordTypeToConst(pwdId),
(uint8_t) NbPwdByte, pPwd);
}
virtual NFC_StatusTypeDef ChangeReferenceData(PasswordType_t pwdId,
const uint8_t *pPwd) {
- return (NFC_StatusTypeDef) M24SR_ChangeReferenceData(passwordTypeToConst(pwdId),
+ return (NFC_StatusTypeDef) M24SR_SendChangeReferenceData(passwordTypeToConst(pwdId),
(uint8_t *) pPwd);
}
virtual NFC_StatusTypeDef EnableVerificationRequirement(
PasswordType_t uReadOrWrite) {
- return (NFC_StatusTypeDef) M24SR_EnableVerificationRequirement(
+ return (NFC_StatusTypeDef) M24SR_SendEnableVerificationRequirement(
passwordTypeToConst(uReadOrWrite));
}
virtual NFC_StatusTypeDef DisableVerificationRequirement(
PasswordType_t uReadOrWrite) {
- return (NFC_StatusTypeDef) M24SR_DisableVerificationRequirement(
+ return (NFC_StatusTypeDef) M24SR_SendDisableVerificationRequirement(
passwordTypeToConst(uReadOrWrite));
}
@@ -187,17 +208,17 @@
virtual NFC_StatusTypeDef STReadBinary(uint16_t Offset,
uint8_t NbByteToRead, uint8_t *pBufferRead) {
- return (NFC_StatusTypeDef) M24SR_STReadBinary((uint16_t) Offset,
+ return (NFC_StatusTypeDef) M24SR_SendSTReadBinary((uint16_t) Offset,
(uint8_t) NbByteToRead, (uint8_t *) pBufferRead);
}
virtual NFC_StatusTypeDef EnablePermanentState(PasswordType_t uReadOrWrite) {
- return (NFC_StatusTypeDef) M24SR_EnablePermanentState(
+ return (NFC_StatusTypeDef) M24SR_SendEnablePermanentState(
passwordTypeToConst(uReadOrWrite));
}
virtual NFC_StatusTypeDef DisablePermanentState(PasswordType_t uReadOrWrite) {
- return (NFC_StatusTypeDef) M24SR_DisablePermanentState(
+ return (NFC_StatusTypeDef) M24SR_SendDisablePermanentState(
passwordTypeToConst(uReadOrWrite));
}
@@ -206,25 +227,20 @@
return (NFC_StatusTypeDef) M24SR_StateControl((uint8_t) uSetOrReset);
}
- virtual NFC_StatusTypeDef ManageI2CGPO(uint8_t GPO_I2Cconfig) {
- return (NFC_StatusTypeDef) M24SR_ManageI2CGPO(
- (M24SR_GPO_MGMT) GPO_I2Cconfig);
+ virtual NFC_StatusTypeDef ManageI2CGPO(NFC_GPO_MGMT GPO_I2Cconfig) {
+ return (NFC_StatusTypeDef) M24SR_ManageI2CGPO(GPO_I2Cconfig);
}
virtual NFC_StatusTypeDef ManageRFGPO(uint8_t GPO_RFconfig) {
return (NFC_StatusTypeDef) M24SR_ManageRFGPO(
- (M24SR_GPO_MGMT) GPO_RFconfig);
+ (NFC_GPO_MGMT) GPO_RFconfig);
}
virtual NFC_StatusTypeDef RFConfig(uint8_t OnOffChoice) {
return (NFC_StatusTypeDef) M24SR_RFConfig((uint8_t) OnOffChoice);
}
- /**
- * Generates a negative pulse on the GPO pin.
- * Pulse starts immediately after the command is issued and ends at the end of the RF response.
- * @return NFC_SUCCESS if no errors
- */
+
virtual NFC_StatusTypeDef SendInterrupt(void) {
return (NFC_StatusTypeDef) M24SR_SendInterrupt();
}
@@ -316,6 +332,8 @@
*/
NFC_StatusTypeDef disableWriteOnly();
+ virtual NFC_StatusTypeDef ManageEvent();
+
protected:
/*** Protected Component Related Methods ***/
@@ -324,41 +342,66 @@
NFC_StatusTypeDef M24SR_ReadID(uint8_t *nfc_id);
NFC_StatusTypeDef M24SR_GetSession(void);
NFC_StatusTypeDef M24SR_KillSession(void);
+
NFC_StatusTypeDef M24SR_Deselect(void);
- NFC_StatusTypeDef M24SR_SelectApplication(void);
- NFC_StatusTypeDef M24SR_SelectCCfile(void);
- NFC_StatusTypeDef M24SR_SelectNDEFfile(uint16_t NDEFfileId);
- NFC_StatusTypeDef M24SR_SelectSystemfile(void);
- NFC_StatusTypeDef M24SR_ReadBinary(uint16_t Offset, uint8_t NbByteToRead,
- uint8_t *pBufferRead);
- NFC_StatusTypeDef M24SR_STReadBinary(uint16_t Offset, uint8_t NbByteToRead,
+ NFC_StatusTypeDef M24SR_ReceiveDeselect(void);
+
+ NFC_StatusTypeDef M24SR_SendSelectApplication(void);
+ NFC_StatusTypeDef M24SR_ReceiveSelectApplication(void);
+
+ NFC_StatusTypeDef M24SR_SendSelectCCfile(void);
+ NFC_StatusTypeDef M24SR_ReceiveSelectCCfile(void);
+
+ NFC_StatusTypeDef M24SR_SendSelectNDEFfile(uint16_t NDEFfileId);
+ NFC_StatusTypeDef M24SR_ReceiveSelectNDEFfile();
+
+ NFC_StatusTypeDef M24SR_SendSelectSystemfile(void);
+ NFC_StatusTypeDef M24SR_ReceiveSelectSystemfile(void);
+
+ NFC_StatusTypeDef M24SR_SendReadBinary(uint16_t Offset, uint8_t NbByteToRead,
uint8_t *pBufferRead);
- NFC_StatusTypeDef M24SR_UpdateBinary(uint16_t Offset, uint8_t NbByteToWrite,
+ NFC_StatusTypeDef M24SR_SendSTReadBinary(uint16_t Offset, uint8_t NbByteToRead,
+ uint8_t *pBufferRead);
+ NFC_StatusTypeDef M24SR_ReceiveReadBinary(void);
+
+ NFC_StatusTypeDef M24SR_SendUpdateBinary(uint16_t Offset, uint8_t NbByteToWrite,
uint8_t *pDataToWrite);
- NFC_StatusTypeDef M24SR_Verify(uint16_t uPwdId, uint8_t NbPwdByte,
+ NFC_StatusTypeDef M24SR_ReceiveUpdateBinary();
+
+ NFC_StatusTypeDef M24SR_SendVerify(uint16_t uPwdId, uint8_t NbPwdByte,
const uint8_t *pPwd);
- NFC_StatusTypeDef M24SR_ChangeReferenceData(uint16_t uPwdId, uint8_t *pPwd);
- NFC_StatusTypeDef M24SR_EnableVerificationRequirement(
+ NFC_StatusTypeDef M24SR_ReceiveVerify();
+
+ NFC_StatusTypeDef M24SR_SendChangeReferenceData(uint16_t uPwdId, uint8_t *pPwd);
+ NFC_StatusTypeDef M24SR_ReceiveChangeReferenceData();
+
+ NFC_StatusTypeDef M24SR_SendEnableVerificationRequirement(
uint16_t uReadOrWrite);
- NFC_StatusTypeDef M24SR_DisableVerificationRequirement(
+ NFC_StatusTypeDef M24SR_ReceiveEnableVerificationRequirement();
+
+ NFC_StatusTypeDef M24SR_SendDisableVerificationRequirement(
uint16_t uReadOrWrite);
- NFC_StatusTypeDef M24SR_EnablePermanentState(uint16_t uReadOrWrite);
- NFC_StatusTypeDef M24SR_DisablePermanentState(uint16_t uReadOrWrite);
+ NFC_StatusTypeDef M24SR_ReceiveDisableVerificationRequirement();
+
+ NFC_StatusTypeDef M24SR_SendEnablePermanentState(uint16_t uReadOrWrite);
+ NFC_StatusTypeDef M24SR_ReceiveEnablePermanentState();
+
+ NFC_StatusTypeDef M24SR_SendDisablePermanentState(uint16_t uReadOrWrite);
+ NFC_StatusTypeDef M24SR_ReceiveDisablePermanentState();
+
NFC_StatusTypeDef M24SR_SendInterrupt(void);
NFC_StatusTypeDef M24SR_StateControl(uint8_t uSetOrReset);
- NFC_StatusTypeDef M24SR_ManageI2CGPO(M24SR_GPO_MGMT GPO_I2Cconfig);
- NFC_StatusTypeDef M24SR_ManageRFGPO(M24SR_GPO_MGMT GPO_RFconfig);
- NFC_StatusTypeDef M24SR_RFConfig(uint8_t OnOffChoice);
- NFC_StatusTypeDef M24SR_FWTExtension(uint8_t FWTbyte);
+
+ NFC_StatusTypeDef M24SR_ManageI2CGPO(NFC_GPO_MGMT GPO_I2Cconfig);
+ NFC_StatusTypeDef M24SR_ManageRFGPO(NFC_GPO_MGMT GPO_RFconfig);
- /**
- * Wait until the answer is ready.
- */
- NFC_StatusTypeDef M24SR_IO_IsAnswerReady(void);
+ NFC_StatusTypeDef M24SR_RFConfig(uint8_t OnOffChoice);
+ NFC_StatusTypeDef M24SR_SendFWTExtension(uint8_t FWTbyte);
+
/**
* Send a command to the component.
- * @param NbByte Lenght of the command.
+ * @param NbByte Length of the command.
* @param pBuffer Buffer containing the command.
* @return NFC_SUCCESS if no errors
*/
@@ -398,27 +441,6 @@
RFDisablePin = 1;
}
- /**
- * Set the command synchronous answer mode.
- * @param mode How to wait the I2C rensponse.
- */
- void M24SR_IO_SetI2CSynchroMode(M24SR_WAITINGTIME_MGMT mode) {
- syncMode = mode;
- }
-
- /**
- * Callback triggers when a command is completed.
- */
- void M24SR_AnswerReadyInterruptCallback() {
- /**
- * register the interrupt only if we are waiting for it
- * the gpo can became low also for other reason
- */
- if(syncMode==M24SR_INTERRUPT_GPO){
- interruptIsFired=true;
- }//if
- }
-
/*** Component's Instance Variables ***/
/* Identity */
@@ -442,16 +464,6 @@
DigitalOut RFDisablePin;
/**
- * Pin used as interrupt.
- */
- InterruptIn answerReadyInterrupt;
-
- /**
- * Method used to wait the chip response.
- */
- M24SR_WAITINGTIME_MGMT syncMode;
-
- /**
* Buffer used to build the command to send to the chip.
*/
uint8_t uM24SRbuffer[0xFF];//max command length is 255
@@ -462,18 +474,564 @@
uint8_t uDIDbyte;
/**
- * State variable changes when the interrupt is fired.
- */
- volatile bool interruptIsFired;
-
- /**
* Object implementing the interface to use the NDefLib.
*/
NDefNfcTagM24SR NDefTagUtil;
-
+
+ /**
+ * command that the component can accept
+ */
+ typedef enum{
+ NONE, //!< NONE
+ DESELECT, //!< DESELECT
+ SELECT_APPLICATION, //!< SELECT_APPLICATION
+ SELECT_CC_FILE, //!< SELECT_CC_FILE
+ SELECT_NDEF_FILE, //!< SELECT_NDEF_FILE
+ SELECT_SYSTEM_FILE, //!< SELECT_SYSTEM_FILE
+ READ, //!< READ
+ UPDATE, //!< UPDATE
+ VERIFY, //!< VERIFY
+ MANAGE_I2C_GPO, //!< MANAGE_I2C_GPO
+ MANAGE_RF_GPO, //!< MANAGE_RF_GPO
+ CHANGE_REFERENCE_DATA, //!< CHANGE_REFERENCE_DATA
+ ENABLE_VERIFICATION_REQUIREMENT, //!< ENABLE_VERIFICATION_REQUIREMENT
+ DISABLE_VERIFICATION_REQUIREMENT,//!< DISABLE_VERIFICATION_REQUIREMENT
+ ENABLE_PERMANET_STATE, //!< ENABLE_PERMANET_STATE
+ DISABLE_PERMANET_STATE, //!< DISABLE_PERMANET_STATE
+ }M24SR_command_t;
+
+ /**
+ * parameter used for invoke the command
+ */
+ typedef struct{
+ uint8_t *data; //!< data
+ uint16_t length; //!< number of byte in the data array
+ uint16_t offset; //!< offset parameter used in the read/write command
+ }M24SR_command_data_t;
+
+ /**
+ * communication mode used by this device
+ */
+ typedef enum{
+ SYNC,//!< SYNC wait the command response before return
+ ASYNC//!< ASYNC use a callback for notify the end of a command
+ }M24SR_communication_t;
+
+ /**
+ * type of communication that we are using
+ */
+ M24SR_communication_t mCommunicationType;
+
+ /**
+ * the class is wait the answer of this command
+ */
+ M24SR_command_t mLastCommandSend;
+
+ /**
+ * parameter used for invoke the last command
+ */
+ M24SR_command_data_t mLastCommandData;
+
+ 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.
+ * This class is equivalent to call the method:
+ * <ul>
+ * <li> SelectedApplication </li>
+ * <li> SelectSystemfile </li>
+ * <li> ReadBinar: read the old value </li>
+ * <li> onVerifyed </li>
+ * <li> onUpdatedBinary: write the new value</li>
+ * </ul>
+ */
+ class ManageGPOCallback : public Nfc::Callback{
+
+ public:
+
+ /**
+ * Create the MamageGpoCallback command chain.
+ * @param parent component where run the command.
+ */
+ ManageGPOCallback(M24SR &parent):mParent(parent),
+ mGpoConfig(HIGH_IMPEDANCE),mReadGpoConfig(0),mI2CGpo(true){}
+
+
+ /**
+ * Command parameters
+ * @param i2cGpo true if you want change the i2c gpo, false for change the rf gpo.
+ * @param newConfig new gpo function.
+ */
+ void setNewGpoConfig(bool i2cGpo,NFC_GPO_MGMT newConfig){
+ mGpoConfig=newConfig;
+ mI2CGpo =i2cGpo;
+ }
+
+ virtual void onSelectedApplication(Nfc *nfc,NFC_StatusTypeDef status){
+ if(status==NFC_SUCCESS)
+ nfc->SelectSystemfile();
+ else
+ onFinishCommand(nfc,status);
+ }
+
+ virtual void onSelectedSystemFile(Nfc *nfc,NFC_StatusTypeDef status){
+ if(status==NFC_SUCCESS)
+ nfc->ReadBinary(0x0004, 0x01, &mReadGpoConfig);
+ else
+ onFinishCommand(nfc,status);
+ }
+
+ virtual void onReadByte(Nfc *nfc,NFC_StatusTypeDef status,
+ uint16_t,uint8_t*, uint16_t ){
+ if(status==NFC_SUCCESS)
+ nfc->Verify(M24SR::I2CPwd, 0x10, M24SR::DEFAULT_PASSWORD);
+ else
+ onFinishCommand(nfc,status);
+ }
+
+ virtual void onVerifyed(Nfc *nfc,NFC_StatusTypeDef status){
+ if(status!=NFC_SUCCESS)
+ return onFinishCommand(nfc,status);
+
+ if(mI2CGpo)
+ mReadGpoConfig = (mReadGpoConfig & 0xF0) | (uint8_t)mGpoConfig;
+ else
+ mReadGpoConfig = (mReadGpoConfig & 0x0F) | (((uint8_t)mGpoConfig)<<4);
+
+ nfc->UpdateBinary(0x0004, 0x01, &mReadGpoConfig);
+ }
+
+ virtual void onUpdatedBinary(Nfc *nfc,NFC_StatusTypeDef status,
+ uint16_t , uint8_t*, uint16_t ){
+
+ if(status==NFC_SUCCESS){
+ if (mGpoConfig == I2C_ANSWER_READY){
+ mParent.mCommunicationType = ASYNC;
+ }else{
+ mParent.mCommunicationType = SYNC;
+ }//if-else
+ }//status
+ onFinishCommand(nfc,status);
+ }
+
+ private:
+
+ /**
+ * Remove the private callback and call the user callback
+ * @param nfc Object where the command complete
+ * @param status Command status
+ */
+ void onFinishCommand(Nfc *nfc,NFC_StatusTypeDef status){
+ mParent.mComponentCallback=NULL;
+ if(mI2CGpo){
+ mParent.mCallback->onManageI2CGPO(nfc,status,mGpoConfig);
+ }else{
+ mParent.mCallback->onManageRFGPO(nfc,status,mGpoConfig);
+ }//if-else
+ }//onFinishCommand
+
+ /**
+ * component where run the command
+ */
+ M24SR &mParent;
+
+ /** new gpo function that this class has to write */
+ NFC_GPO_MGMT mGpoConfig;
+
+ /**
+ * variable where store the read gpo configuration
+ */
+ uint8_t mReadGpoConfig;
+
+ /**
+ * true for change the i2c gpo, false for change the rf gpo
+ */
+ bool mI2CGpo;
+
+ };
+
+ /**
+ * Object containing the callback chain needed to change the gpo function
+ */
+ ManageGPOCallback mManageGPOCallback;
+
+
+ /**
+ * Object with the callback used to read the component ID
+ * This class is equivalent to call the method:
+ * <ul>
+ * <li> SelectedApplication </li>
+ * <li> SelectSystemfile </li>
+ * <li> ReadBinary </li>
+ * </ul>
+ */
+ class ReadIDCallback : public Nfc::Callback{
+
+ public:
+
+ /**
+ * build the chain of callback
+ * @param parent object where send the command
+ */
+ ReadIDCallback(M24SR &parent):mParent(parent),mIdPtr(NULL){}
+
+ /**
+ * set the location where write the result
+ * @param idPtr
+ */
+ void readIdOn(uint8_t *idPtr){
+ mIdPtr=idPtr;
+ }
+
+ virtual void onSelectedApplication(Nfc *nfc,NFC_StatusTypeDef status){
+ if(status==NFC_SUCCESS){
+ nfc->SelectSystemfile();
+ }else
+ onFinishCommand(nfc,status);
+
+ }
+
+ virtual void onSelectedSystemFile(Nfc *nfc,NFC_StatusTypeDef status){
+ if(status==NFC_SUCCESS){
+ nfc->ReadBinary(0x0011, 0x01, mIdPtr);
+ }else
+ onFinishCommand(nfc,status);
+ }
+
+ virtual void onReadByte(Nfc *nfc,NFC_StatusTypeDef status,
+ uint16_t ,uint8_t *, uint16_t ){
+ onFinishCommand(nfc,status);
+ }
+
+ private:
+
+ /**
+ * remove the private callback and call the user onReadId function
+ * @param nfc object where the command run
+ * @param status command status
+ */
+ void onFinishCommand(Nfc *nfc,NFC_StatusTypeDef status){
+ mParent.mComponentCallback=NULL;
+ mParent.getCallback()->onReadId(nfc,status,mIdPtr);
+ }
+
+ /**
+ * component where run the command
+ */
+ M24SR &mParent;
+
+ /**
+ * location where write the read id
+ */
+ uint8_t *mIdPtr;
+ };
+
+ /**
+ * 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->EnablePermanentState(mType==WRITE? WritePwd : ReadPwd);
+ }else
+ nfc->DisableVerificationRequirement(mType==WRITE? WritePwd : ReadPwd);
+ }
+
+ 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 */
@@ -486,9 +1044,25 @@
case I2CPwd:
default:
return I2C_PWD;
- }
+ }//switch
}//passwordTypeToConst
+ /**
+ * convert a uint16 into an enum value
+ * @param type
+ * @return
+ */
+ PasswordType_t constToPasswordType(const uint16_t type)const{
+ switch(type){
+ case READ_PWD:
+ return ReadPwd;
+ case WRITE_PWD:
+ return WritePwd;
+ case I2C_PWD:
+ default:
+ return I2CPwd;
+ }//switch
+ }//passwordTypeToConst
};
#endif // __M24SR_CLASS_H

X-NUCLEO-NFC01A1 Dynamic NFC Tag