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
Diff: m24sr/M24SR.h
- Revision:
- 33:e6b7e74be1d5
- Parent:
- 32:9fc4f9195d28
- Child:
- 34:b76765d2cc68
--- a/m24sr/M24SR.h Thu May 18 15:20:43 2017 +0000
+++ b/m24sr/M24SR.h Wed Jul 12 14:15:02 2017 +0000
@@ -157,37 +157,37 @@
/** called when GetSession or ForceGetSession completes
* @see M24SR#GetSession
* @see M24SR#ForceGetSession */
- virtual void on_session_open(M24SR *nfc,StatusTypeDef status){
+ virtual void on_session_open(M24SR *nfc,StatusTypeDef status) {
(void)nfc; (void)status;
}
/** called when Deselect completes
* @see M24SR#Deselect */
- virtual void on_deselect(M24SR *nfc,StatusTypeDef status){
+ virtual void on_deselect(M24SR *nfc,StatusTypeDef status) {
(void)nfc; (void)status;
}
/** called when SelectedApplication completes
* @see M24SR#SelectedApplication */
- virtual void on_selected_application(M24SR *nfc,StatusTypeDef status){
+ virtual void on_selected_application(M24SR *nfc,StatusTypeDef status) {
(void)nfc; (void)status;
}
/** called when SelectedCCFile completes
* @see M24SR#SelectedCCFile */
- virtual void on_selected_CC_file(M24SR *nfc,StatusTypeDef status){
+ virtual void on_selected_CC_file(M24SR *nfc,StatusTypeDef status) {
(void)nfc; (void)status;
}
/** called when SelectedNDEFFile completes
* @see M24SR#SelectedNDEFFile */
- virtual void on_selected_NDEF_file(M24SR *nfc,StatusTypeDef status){
+ virtual void on_selected_NDEF_file(M24SR *nfc,StatusTypeDef status) {
(void)nfc; (void)status;
}
/** called when SelectedSystemFile completes
* @see M24SR#SelectedSystemFile */
- virtual void on_selected_system_file(M24SR *nfc,StatusTypeDef status){
+ virtual void on_selected_system_file(M24SR *nfc,StatusTypeDef status) {
(void)nfc; (void)status;
}
@@ -195,130 +195,130 @@
* @see M24SR#read_binary
* @see M24SR#STReadBinary */
virtual void on_read_byte(M24SR *nfc,StatusTypeDef status,
- uint16_t offset,uint8_t *readByte, uint16_t nReadByte){
+ uint16_t offset,uint8_t *readByte, uint16_t nReadByte) {
(void)nfc; (void)status;(void)offset; (void)readByte; (void)nReadByte;
}
/** called when UpdatedBinary completes
* @see M24SR#UpdatedBinary */
virtual void on_updated_binary(M24SR *nfc,StatusTypeDef status,uint16_t offset,
- uint8_t *writeByte,uint16_t nWriteByte){
+ uint8_t *writeByte,uint16_t nWriteByte) {
(void)nfc; (void)status; (void)writeByte; (void)nWriteByte; (void)offset;
}
/** called when Verify completes
* @see M24SR#Verify */
virtual void on_verified(M24SR *nfc,StatusTypeDef status,PasswordType_t uPwdId,
- const uint8_t *pwd){
+ const uint8_t *pwd) {
(void)nfc; (void)status;(void)uPwdId;(void)pwd;
}
/** called when ManageI2CGPO completes
* @see M24SR#ManageI2CGPO */
- virtual void on_manage_I2C_GPO(M24SR *nfc,StatusTypeDef status,NFC_GPO_MGMT newStatus){
+ virtual void on_manage_I2C_GPO(M24SR *nfc,StatusTypeDef status,NFC_GPO_MGMT newStatus) {
(void)nfc; (void)status;(void)newStatus;
}
/** called when ManageRFGPO completes
* @see M24SR#ManageRFGPO */
- virtual void on_manage_RF_GPO(M24SR *nfc,StatusTypeDef status,NFC_GPO_MGMT newStatus){
+ virtual void on_manage_RF_GPO(M24SR *nfc,StatusTypeDef status,NFC_GPO_MGMT newStatus) {
(void)nfc; (void)status;(void)newStatus;
}
/** called when ChangeReferenceData completes
* @see M24SR#ChangeReferenceData */
virtual void on_change_reference_data(M24SR *nfc ,StatusTypeDef status,PasswordType_t type,
- uint8_t *data){
+ uint8_t *data) {
(void)nfc; (void)status;(void)type;(void)data;
}
/** called when EnableVerificationRequirement completes
* @see M24SR#EnableVerificationRequirement */
- virtual void on_enable_verification_requirement(M24SR *nfc ,StatusTypeDef status,PasswordType_t type){
+ virtual void on_enable_verification_requirement(M24SR *nfc ,StatusTypeDef status,PasswordType_t type) {
(void)nfc; (void)status;(void)type;
}
/** called when disable_verification_requirement completes
* @see M24SR#disable_verification_requirement */
- virtual void on_disable_verification_requirement(M24SR *nfc , StatusTypeDef status,PasswordType_t type){
+ virtual void on_disable_verification_requirement(M24SR *nfc , StatusTypeDef status,PasswordType_t type) {
(void)nfc; (void)status;(void)type;
}
/** called when EnablePermanentState completes
* @see M24SR#EnablePermanentState */
- virtual void on_enable_permanent_state(M24SR *nfc, StatusTypeDef status, PasswordType_t type){
+ virtual void on_enable_permanent_state(M24SR *nfc, StatusTypeDef status, PasswordType_t type) {
(void)nfc; (void)status;(void)type;
}
/** called when DisablePermanentState completes
* @see M24SR#DisablePermanentState */
- virtual void on_disable_permanent_state(M24SR *nfc, StatusTypeDef status, PasswordType_t type){
+ virtual void on_disable_permanent_state(M24SR *nfc, StatusTypeDef status, PasswordType_t type) {
(void)nfc; (void)status;(void)type;
}
/** called when ReadId completes
* @see M24SR#ReadId */
- virtual void on_read_id(M24SR *nfc, StatusTypeDef status, uint8_t *id){
+ virtual void on_read_id(M24SR *nfc, StatusTypeDef status, uint8_t *id) {
(void)nfc; (void)status;(void)id;
}
/** called when EnableReadPassword completes
* @see M24SR#EnableReadPassword */
- virtual void on_enable_read_password(M24SR *nfc, StatusTypeDef status,const uint8_t *newPwd){
+ virtual void on_enable_read_password(M24SR *nfc, StatusTypeDef status,const uint8_t *newPwd) {
(void)nfc; (void)status;(void)newPwd;
}
/** called when EnableWritePassword completes
* @see M24SR#EnableWritePassword */
- virtual void on_enable_write_password(M24SR *nfc, StatusTypeDef status,const uint8_t *newPwd){
+ virtual void on_enable_write_password(M24SR *nfc, StatusTypeDef status,const uint8_t *newPwd) {
(void)nfc; (void)status;(void)newPwd;
}
/** called when DisableReadPassword completes
* @see M24SR#DisableReadPassword */
- virtual void on_disable_read_password(M24SR *nfc, StatusTypeDef status){
+ virtual void on_disable_read_password(M24SR *nfc, StatusTypeDef status) {
(void)nfc; (void)status;
}
/** called when DisableWritePassword completes
* @see M24SR#DisableWritePassword */
- virtual void on_disable_write_password(M24SR *nfc, StatusTypeDef status){
+ virtual void on_disable_write_password(M24SR *nfc, StatusTypeDef status) {
(void)nfc; (void)status;
}
/** called when DisableAllPassword completes
* @see M24SR#DisableAllPassword */
- virtual void on_disable_all_password(M24SR *nfc, StatusTypeDef status){
+ virtual void on_disable_all_password(M24SR *nfc, StatusTypeDef status) {
(void)nfc; (void)status;
}
/** called when EnableReadOnly completes
* @see M24SR#EnableReadOnly */
- virtual void on_enable_read_only(M24SR *nfc,StatusTypeDef status){
+ virtual void on_enable_read_only(M24SR *nfc,StatusTypeDef status) {
(void)nfc; (void)status;
}
/** called when EnableWriteOnly completes
* @see M24SR#EnableWriteOnly */
- virtual void on_enable_write_only(M24SR *nfc,StatusTypeDef status){
+ virtual void on_enable_write_only(M24SR *nfc,StatusTypeDef status) {
(void)nfc; (void)status;
}
/** called when DisableReadOnly completes
* @see M24SR#DisableReadOnly */
- virtual void on_disable_read_only(M24SR *nfc,StatusTypeDef status){
+ virtual void on_disable_read_only(M24SR *nfc,StatusTypeDef status) {
(void)nfc; (void)status;
}
/** called when DisableWriteOnly completes
* @see M24SR#DisableWriteOnly */
- virtual void on_disable_write_only(M24SR *nfc,StatusTypeDef status){
+ virtual void on_disable_write_only(M24SR *nfc,StatusTypeDef status) {
(void)nfc; (void)status;
}
- virtual ~Callbacks(){};
+ virtual ~Callbacks() {};
};
/*** Constructor and Destructor Methods ***/
@@ -533,11 +533,12 @@
* Change the function to call when a command ends.
* @param commandCallback Object containing the callback, if NULL it will use empty callback
*/
- void set_callback(Callbacks *commandCallback){
- if(commandCallback!=NULL)
+ void set_callback(Callbacks *commandCallback) {
+ if (commandCallback!=NULL) {
mCallback = commandCallback;
- else
+ } else {
mCallback = &defaultCallback;
+ }
}
@@ -551,8 +552,7 @@
* @return return M24SR_SUCCESS if no errors
* @par The password must have a length of 16 chars.
*/
- StatusTypeDef enable_read_password(const uint8_t* pCurrentWritePassword,
- const uint8_t* pNewPassword) {
+ StatusTypeDef enable_read_password(const uint8_t* pCurrentWritePassword, const uint8_t* pNewPassword) {
//enable the callback for change the gpo
mComponentCallback = &mChangePasswordRequestStatusCallback;
@@ -581,8 +581,7 @@
* @return return M24SR_SUCCESS if no errors
* @par The password must have a length of 16 chars.
*/
- StatusTypeDef enable_write_password(const uint8_t* pCurrentWritePassword,
- uint8_t* pNewPassword) {
+ StatusTypeDef enable_write_password(const uint8_t* pCurrentWritePassword, uint8_t* pNewPassword) {
//enable the callback for change the gpo
mComponentCallback = &mChangePasswordRequestStatusCallback;
mChangePasswordRequestStatusCallback.set_task(WritePwd,pNewPassword);
@@ -609,7 +608,7 @@
* @return return M24SR_SUCCESS if no errors
* @par The password must have a length of 16 chars.
*/
- StatusTypeDef disable_all_password(const uint8_t* pSuperUserPassword){
+ StatusTypeDef disable_all_password(const uint8_t* pSuperUserPassword) {
mComponentCallback = &mRemoveAllPasswordCallback;
return verify(M24SR::I2CPwd, 0x10, pSuperUserPassword);
}
@@ -620,8 +619,7 @@
* @return return M24SR_SUCCESS if no errors
* @par The password must have a length of 16 chars.
*/
- StatusTypeDef enable_read_only(const uint8_t* pCurrentWritePassword){
-
+ StatusTypeDef enable_read_only(const uint8_t* pCurrentWritePassword) {
mComponentCallback = &mChangeAccessStateCallback;
//disable write = read only
mChangeAccessStateCallback.change_access_state(ChangeAccessStateCallback::WRITE,false);
@@ -638,6 +636,7 @@
StatusTypeDef disable_read_only(const uint8_t* pCurrentWritePassword) {
mComponentCallback = &mChangeAccessStateCallback;
mChangeAccessStateCallback.change_access_state(ChangeAccessStateCallback::WRITE,true);
+
return verify(M24SR::I2CPwd, 0x10,pCurrentWritePassword);
}
@@ -649,13 +648,11 @@
* @par The password must have a length of 16 chars.
*/
StatusTypeDef enable_write_only(const uint8_t* pCurrentWritePassword) {
-
mComponentCallback = &mChangeAccessStateCallback;
//disable read = enable write only
mChangeAccessStateCallback.change_access_state(ChangeAccessStateCallback::READ,false);
return verify(M24SR::WritePwd, 0x10, pCurrentWritePassword);
-
}
/**
@@ -667,6 +664,7 @@
StatusTypeDef disable_write_only(const uint8_t* pCurrentWritePassword) {
mComponentCallback = &mChangeAccessStateCallback;
mChangeAccessStateCallback.change_access_state(ChangeAccessStateCallback::READ,true);
+
return verify(M24SR::I2CPwd, 0x10, pCurrentWritePassword);
}
@@ -687,8 +685,6 @@
StatusTypeDef M24SR_GetSession(void);
StatusTypeDef M24SR_ForceSession(void);
-
-
StatusTypeDef M24SR_Deselect(void);
StatusTypeDef M24SR_ReceiveDeselect(void);
@@ -759,8 +755,7 @@
* @param pBuffer Buffer to store the response into.
* @return M24SR_SUCCESS if no errors
*/
- StatusTypeDef M24SR_IO_ReceiveI2Cresponse(uint8_t NbByte,
- uint8_t *pBuffer);
+ StatusTypeDef M24SR_IO_ReceiveI2Cresponse(uint8_t NbByte, uint8_t *pBuffer);
/**
* Do an active polling on the I2C bus until the answer is ready.
@@ -773,7 +768,7 @@
* @param[out] pPinState Variable to store the pin state into.
*/
void M24SR_IO_GPO_ReadPin(uint8_t *pPinState) {
- *pPinState= GPOPin.read();
+ *pPinState = GPOPin.read();
}
/**
@@ -781,10 +776,12 @@
* @param pPinState Pin state to write.
*/
void M24SR_IO_RFDIS_WritePin(uint8_t PinState) {
- if (PinState == 0)
+ if (PinState == 0) {
RFDisablePin = 0;
- else
+ }
+ else {
RFDisablePin = 1;
+ }
}
/*** Component's Instance Variables ***/
@@ -899,9 +896,10 @@
* get the callback object to use
* @return callback object to use
*/
- Callbacks * getCallback(){
- if(mComponentCallback!=NULL)
+ Callbacks * getCallback() {
+ if (mComponentCallback != NULL) {
return mComponentCallback;
+ }
return mCallback;
}//getCallback
@@ -925,7 +923,7 @@
* <li> disable_verification_requirement </li>
* </ul>
*/
- class ChangePasswordRequestStatusCallback : public Callbacks{
+ class ChangePasswordRequestStatusCallback : public Callbacks {
public:
@@ -933,45 +931,48 @@
* Build the chain of callbacks.
*/
ChangePasswordRequestStatusCallback():
- mNewPwd(NULL),mType(I2CPwd),mEnable(false){}
+ 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 set_task(PasswordType_t type, const uint8_t *newPwd){
+ void set_task(PasswordType_t type, const uint8_t *newPwd) {
mNewPwd=newPwd;
mType=type;
mEnable=newPwd!=NULL;
}//setTask
virtual void on_verified(M24SR *nfc, StatusTypeDef status,PasswordType_t ,
- const uint8_t *){
- if(status!=M24SR_SUCCESS)
+ const uint8_t *) {
+ if (status!=M24SR_SUCCESS) {
return onFinishCommand(nfc,status);
- if(mEnable)
+ }
+ if (mEnable) {
nfc->change_reference_data(mType,mNewPwd);
- else
+ } else {
nfc->disable_verification_requirement(mType);
+ }
}
virtual void on_disable_verification_requirement(M24SR *nfc,
- StatusTypeDef status, PasswordType_t ){
+ StatusTypeDef status, PasswordType_t ) {
onFinishCommand(nfc,status);
}
virtual void on_change_reference_data(M24SR *nfc, StatusTypeDef status,
PasswordType_t type,
- uint8_t *){
- if(status==M24SR_SUCCESS)
+ uint8_t *) {
+ if (status==M24SR_SUCCESS) {
nfc->enable_permanent_state(type);
- else
+ } else {
onFinishCommand(nfc,status);
+ }
}
virtual void on_enable_permanent_state(M24SR *nfc, StatusTypeDef status,
- PasswordType_t ){
+ PasswordType_t ) {
onFinishCommand(nfc,status);
}
@@ -983,19 +984,21 @@
* @param nfc Object triggering the command.
* @param status Command status.
*/
- void onFinishCommand(M24SR *nfc,StatusTypeDef status){
+ void onFinishCommand(M24SR *nfc,StatusTypeDef status) {
nfc->mComponentCallback=NULL;
- if(mEnable){
- if(mType==ReadPwd){
+ if (mEnable) {
+ if (mType==ReadPwd) {
nfc->getCallback()->on_enable_read_password(nfc,status,mNewPwd);
- }else
+ } else {
nfc->getCallback()->on_enable_write_password(nfc,status,mNewPwd);
- }else{
- if(mType==ReadPwd){
+ }
+ } else {
+ if (mType==ReadPwd) {
nfc->getCallback()->on_disable_read_password(nfc,status);
- }else
+ } else {
nfc->getCallback()->on_disable_write_password(nfc,status);
+ }
}//if-else enable
}//onFinish
@@ -1003,209 +1006,217 @@
PasswordType_t mType;
bool mEnable;
- };
-
-
- /**
- * Object containing the callback chain needed to change the password request
- */
- ChangePasswordRequestStatusCallback mChangePasswordRequestStatusCallback;
- friend class ChangePasswordRequestStatusCallback;
+ };
- /**
- * This class permits to disable all the password requests to read/write into the tag
- * This class is equivalent to calling the methods:
- * <ul>
- * <li> Verify(i2c) </li>
- * <li> DisablePermanentState(Read) </li>
- * <li> DisablePermanentState(write) </li>
- * <li> disable_verification_requirement(Read) </li>
- * <li> disable_verification_requirement(write) </li>
- * <li> ChangeReferenceData(Read) </li>
- * <li> ChangeReferenceData(write) </li>
- * </ul>
- */
- class RemoveAllPasswordCallback : public Callbacks{
-
- /**
- * 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:
-
- /**
- * Build the chain of callbacks.
- */
- RemoveAllPasswordCallback():mI2CPwd(NULL){}
-
- virtual void on_verified(M24SR *nfc,StatusTypeDef status,
- PasswordType_t,const uint8_t* data){
- if(status!=M24SR_SUCCESS)
- return onFinishCommand(nfc,status);
- mI2CPwd = data;
- nfc->disable_permanent_state(ReadPwd);
- }
+ /**
+ * Object containing the callback chain needed to change the password request
+ */
+ ChangePasswordRequestStatusCallback mChangePasswordRequestStatusCallback;
+ friend class ChangePasswordRequestStatusCallback;
- virtual void on_disable_permanent_state(M24SR *nfc , StatusTypeDef status,
- PasswordType_t type){
- if(status!=M24SR_SUCCESS)
- return onFinishCommand(nfc,status);
- if(type==ReadPwd)
- nfc->disable_permanent_state(WritePwd);
- else
- nfc->disable_verification_requirement(ReadPwd);
- }
-
- virtual void on_disable_verification_requirement(M24SR *nfc ,
- StatusTypeDef status,PasswordType_t type){
- if(status!=M24SR_SUCCESS)
- return onFinishCommand(nfc,status);
- if(type==ReadPwd)
- nfc->disable_verification_requirement(WritePwd);
- else
- nfc->change_reference_data(ReadPwd,mI2CPwd);
- }
-
- virtual void on_change_reference_data(M24SR *nfc ,StatusTypeDef status,PasswordType_t type,
- uint8_t *data){
- if(status!=M24SR_SUCCESS)
- return onFinishCommand(nfc,status);
- if(type==ReadPwd)
- nfc->change_reference_data(WritePwd,data);
- else
- onFinishCommand(nfc,status);
- }
-
- private:
-
- /**
- * Remove the private callback and call the onDisableAllPassword callback.
- * @param nfc Object triggering the command.
- * @param status Command status.
- */
- void onFinishCommand(M24SR *nfc,StatusTypeDef status){
- nfc->mComponentCallback=NULL;
- mI2CPwd=NULL;
- nfc->getCallback()->on_disable_all_password(nfc,status);
- }//onFinish
-
- };
-
-
- /**
- * Object containing the callback chain needed to remove the password request
- */
- RemoveAllPasswordCallback mRemoveAllPasswordCallback;
- friend class RemoveAllPasswordCallback;
+ /**
+ * This class permits to disable all the password requests to read/write into the tag
+ * This class is equivalent to calling the methods:
+ * <ul>
+ * <li> Verify(i2c) </li>
+ * <li> DisablePermanentState(Read) </li>
+ * <li> DisablePermanentState(write) </li>
+ * <li> disable_verification_requirement(Read) </li>
+ * <li> disable_verification_requirement(write) </li>
+ * <li> ChangeReferenceData(Read) </li>
+ * <li> ChangeReferenceData(write) </li>
+ * </ul>
+ */
+ class RemoveAllPasswordCallback : public Callbacks{
/**
- * This class permits to set the tag as read/write only
- * This class is equivalent to calling the methods:
- * <ul>
- * <li> Verify(i2c) </li>
- * <li> EnablePermanentState(Read/write) </li>
- * </ul>
- * or:
- * <ul>
- * <li> Verify(i2c) </li>
- * <li> DisablePermanentState</li>
- * <li> disable_verification_requirement(Read/write) </li>
- * </ul>
+ * Store the default password used for open a super user session
+ * it will be set as default read/write password
*/
- class ChangeAccessStateCallback : public Callbacks{
+ const uint8_t *mI2CPwd;
+
+ public:
+
+ /**
+ * Build the chain of callbacks.
+ */
+ RemoveAllPasswordCallback():mI2CPwd(NULL) {}
- public:
+ virtual void on_verified(M24SR *nfc,StatusTypeDef status,
+ PasswordType_t,const uint8_t* data) {
+ if (status!=M24SR_SUCCESS) {
+ return onFinishCommand(nfc,status);
+ }
+ mI2CPwd = data;
+ nfc->disable_permanent_state(ReadPwd);
+ }
- typedef enum{
- WRITE,
- READ
- }AccessType_t;
+ virtual void on_disable_permanent_state(M24SR *nfc , StatusTypeDef status,
+ PasswordType_t type) {
+ if (status!=M24SR_SUCCESS) {
+ return onFinishCommand(nfc,status);
+ }
+ if (type==ReadPwd) {
+ nfc->disable_permanent_state(WritePwd);
+ } else {
+ nfc->disable_verification_requirement(ReadPwd);
+ }
+ }
+
+ virtual void on_disable_verification_requirement(M24SR *nfc ,
+ StatusTypeDef status,PasswordType_t type) {
+ if (status!=M24SR_SUCCESS) {
+ return onFinishCommand(nfc,status);
+ }
+ if (type==ReadPwd) {
+ nfc->disable_verification_requirement(WritePwd);
+ } else {
+ nfc->change_reference_data(ReadPwd,mI2CPwd);
+ }
+ }
+
+ virtual void on_change_reference_data(M24SR *nfc ,StatusTypeDef status,PasswordType_t type,
+ uint8_t *data) {
+ if (status!=M24SR_SUCCESS) {
+ return onFinishCommand(nfc,status);
+ }
+ if (type==ReadPwd) {
+ nfc->change_reference_data(WritePwd,data);
+ } else {
+ onFinishCommand(nfc,status);
+ }
+ }
+
+ private:
- /**
- * Build the chain of callbacks.
- */
- ChangeAccessStateCallback():mType(WRITE),mEnable(false){}
+ /**
+ * Remove the private callback and call the onDisableAllPassword callback.
+ * @param nfc Object triggering the command.
+ * @param status Command status.
+ */
+ void onFinishCommand(M24SR *nfc,StatusTypeDef status) {
+ nfc->mComponentCallback=NULL;
+ mI2CPwd=NULL;
+ nfc->getCallback()->on_disable_all_password(nfc,status);
+ }//onFinish
+
+ };
+
+
+ /**
+ * Object containing the callback chain needed to remove the password request
+ */
+ RemoveAllPasswordCallback mRemoveAllPasswordCallback;
+ friend class RemoveAllPasswordCallback;
- /**
- * Set the access to enable/disable an access type.
- * @param type Access type.
- * @param enable True to enable the state, False to disable it.
- */
- void change_access_state(AccessType_t type,bool enable){
- mType=type;
- mEnable=enable;
- }
+ /**
+ * This class permits to set the tag as read/write only
+ * This class is equivalent to calling the methods:
+ * <ul>
+ * <li> Verify(i2c) </li>
+ * <li> EnablePermanentState(Read/write) </li>
+ * </ul>
+ * or:
+ * <ul>
+ * <li> Verify(i2c) </li>
+ * <li> DisablePermanentState</li>
+ * <li> disable_verification_requirement(Read/write) </li>
+ * </ul>
+ */
+ class ChangeAccessStateCallback : public Callbacks{
+
+ public:
- virtual void on_verified(M24SR *nfc,StatusTypeDef status,
- PasswordType_t,const uint8_t*){
- if(status!=M24SR_SUCCESS)
- return onFinishCommand(nfc,status);
+ typedef enum{
+ WRITE,
+ READ
+ }AccessType_t;
+
+ /**
+ * Build the chain of callbacks.
+ */
+ ChangeAccessStateCallback():mType(WRITE),mEnable(false) {}
- if(mEnable){
- nfc->disable_permanent_state(mType==WRITE? WritePwd : ReadPwd);
- }else
- nfc->enable_permanent_state(mType==WRITE? WritePwd : ReadPwd);
+ /**
+ * Set the access to enable/disable an access type.
+ * @param type Access type.
+ * @param enable True to enable the state, False to disable it.
+ */
+ void change_access_state(AccessType_t type,bool enable) {
+ mType=type;
+ mEnable=enable;
+ }
+ virtual void on_verified(M24SR *nfc,StatusTypeDef status,
+ PasswordType_t,const uint8_t*) {
+ if (status!=M24SR_SUCCESS){
+ return onFinishCommand(nfc,status);
}
- virtual void on_disable_permanent_state(M24SR *nfc, StatusTypeDef status,
- PasswordType_t type ){
- if(status!=M24SR_SUCCESS)
- return onFinishCommand(nfc,status);
-
- nfc->disable_verification_requirement(type);
+ if (mEnable) {
+ nfc->disable_permanent_state(mType==WRITE? WritePwd : ReadPwd);
+ } else {
+ nfc->enable_permanent_state(mType==WRITE? WritePwd : ReadPwd);
}
- virtual void on_disable_verification_requirement(M24SR *nfc , StatusTypeDef status,
- PasswordType_t ){
- onFinishCommand(nfc,status);
+ }
+
+ virtual void on_disable_permanent_state(M24SR *nfc, StatusTypeDef status,
+ PasswordType_t type ) {
+ if (status!=M24SR_SUCCESS) {
+ return onFinishCommand(nfc,status);
}
- virtual void on_enable_permanent_state(M24SR *nfc ,StatusTypeDef status,PasswordType_t ){
- onFinishCommand(nfc,status);
- }
+ nfc->disable_verification_requirement(type);
+ }
+
+ virtual void on_disable_verification_requirement(M24SR *nfc , StatusTypeDef status, PasswordType_t ) {
+ onFinishCommand(nfc,status);
+ }
+
+ virtual void on_enable_permanent_state(M24SR *nfc ,StatusTypeDef status,PasswordType_t ) {
+ onFinishCommand(nfc,status);
+ }
- private:
+ private:
- /**
- * Remove the private callback and call the user callback.
- * @param nfc Object triggering the command.
- * @param status Command status.
- */
- void onFinishCommand(M24SR *nfc,StatusTypeDef status){
- nfc->mComponentCallback=NULL;
- if(mEnable){
- if(mType==READ){
- //enable read = disable write only
- nfc->getCallback()->on_disable_write_only(nfc,status);
- }else
- //enable write = disable read only
- nfc->getCallback()->on_disable_read_only(nfc,status);
- }else{
- if(mType==WRITE){
- //disable write = enable read only
- nfc->getCallback()->on_enable_read_only(nfc,status);
- }else{
- //
- nfc->getCallback()->on_enable_write_only(nfc,status);
- }
- }//if-else enable
- }//onFinish
+ /**
+ * Remove the private callback and call the user callback.
+ * @param nfc Object triggering the command.
+ * @param status Command status.
+ */
+ void onFinishCommand(M24SR *nfc,StatusTypeDef status) {
+ nfc->mComponentCallback=NULL;
+ if (mEnable) {
+ if (mType==READ) {
+ //enable read = disable write only
+ nfc->getCallback()->on_disable_write_only(nfc,status);
+ } else {}
+ //enable write = disable read only
+ nfc->getCallback()->on_disable_read_only(nfc,status);
+ }
+ } else {
+ if (mType==WRITE) {
+ //disable write = enable read only
+ nfc->getCallback()->on_enable_read_only(nfc,status);
+ } else {
+ //
+ nfc->getCallback()->on_enable_write_only(nfc,status);
+ }
+ }//if-else enable
+ }//onFinish
- AccessType_t mType;
- bool mEnable;
-
- };
+ AccessType_t mType;
+ bool mEnable;
+ };
- /**
- * Object containing the callback chain needed to change the access state
- */
- ChangeAccessStateCallback mChangeAccessStateCallback;
- friend class ChangeAccessStateCallback;
+ /**
+ * Object containing the callback chain needed to change the access state
+ */
+ ChangeAccessStateCallback mChangeAccessStateCallback;
+ friend class ChangeAccessStateCallback;
/**
@@ -1228,7 +1239,7 @@
* @param parent Parent component to run the command on.
*/
ManageGPOCallback(M24SR &parent):mParent(parent),
- mGpoConfig(HIGH_IMPEDANCE),mReadGpoConfig(0),mI2CGpo(true){}
+ mGpoConfig(HIGH_IMPEDANCE),mReadGpoConfig(0),mI2CGpo(true) {}
/**
@@ -1236,52 +1247,57 @@
* @param i2cGpo true to change the i2c gpo, false for the rf gpo.
* @param newConfig new gpo function.
*/
- void set_new_GPO_config(bool i2cGpo,NFC_GPO_MGMT newConfig){
+ void set_new_GPO_config(bool i2cGpo,NFC_GPO_MGMT newConfig) {
mGpoConfig=newConfig;
mI2CGpo =i2cGpo;
}
- virtual void on_selected_application(M24SR *nfc,StatusTypeDef status){
- if(status==M24SR_SUCCESS)
+ virtual void on_selected_application(M24SR *nfc,StatusTypeDef status) {
+ if (status==M24SR_SUCCESS) {
nfc->select_system_file();
- else
+ } else {
onFinishCommand(nfc,status);
+ }
}
- virtual void on_selected_system_file(M24SR *nfc,StatusTypeDef status){
- if(status==M24SR_SUCCESS)
+ virtual void on_selected_system_file(M24SR *nfc,StatusTypeDef status) {
+ if (status==M24SR_SUCCESS) {
nfc->read_binary(0x0004, 0x01, &mReadGpoConfig);
- else
+ } else {
onFinishCommand(nfc,status);
+ }
}
virtual void on_read_byte(M24SR *nfc,StatusTypeDef status,
- uint16_t,uint8_t*, uint16_t ){
- if(status==M24SR_SUCCESS)
+ uint16_t,uint8_t*, uint16_t ) {
+ if (status==M24SR_SUCCESS) {
nfc->verify(M24SR::I2CPwd, 0x10, M24SR::DEFAULT_PASSWORD);
- else
+ } else {
onFinishCommand(nfc,status);
+ }
}
- virtual void on_verified(M24SR *nfc,StatusTypeDef status,PasswordType_t, const uint8_t*){
- if(status!=M24SR_SUCCESS)
+ virtual void on_verified(M24SR *nfc,StatusTypeDef status,PasswordType_t, const uint8_t*) {
+ if (status!=M24SR_SUCCESS) {
return onFinishCommand(nfc,status);
+ }
- if(mI2CGpo)
+ if (mI2CGpo) {
mReadGpoConfig = (mReadGpoConfig & 0xF0) | (uint8_t)mGpoConfig;
- else
+ } else {
mReadGpoConfig = (mReadGpoConfig & 0x0F) | (((uint8_t)mGpoConfig)<<4);
+ }
nfc->update_binary(0x0004, 0x01, &mReadGpoConfig);
}
virtual void on_updated_binary(M24SR *nfc,StatusTypeDef status,
- uint16_t , uint8_t*, uint16_t ){
+ uint16_t , uint8_t*, uint16_t ) {
- if(status==M24SR_SUCCESS){
- if (mGpoConfig == I2C_ANSWER_READY){
+ if (status==M24SR_SUCCESS) {
+ if (mGpoConfig == I2C_ANSWER_READY) {
mParent.mCommunicationType = ASYNC;
- }else{
+ } else {
mParent.mCommunicationType = SYNC;
}//if-else
}//status
@@ -1295,11 +1311,11 @@
* @param nfc Object where the command was send to.
* @param status Command status.
*/
- void onFinishCommand(M24SR *nfc,StatusTypeDef status){
+ void onFinishCommand(M24SR *nfc,StatusTypeDef status) {
mParent.mComponentCallback=NULL;
- if(mI2CGpo){
+ if (mI2CGpo) {
mParent.mCallback->on_manage_I2C_GPO(nfc,status,mGpoConfig);
- }else{
+ } else {
mParent.mCallback->on_manage_RF_GPO(nfc,status,mGpoConfig);
}//if-else
}//onFinishCommand
@@ -1329,7 +1345,6 @@
*/
ManageGPOCallback mManageGPOCallback;
-
/**
* Object with the callback used to read the component ID
* This class is equivalent to calling the methods:
@@ -1339,62 +1354,64 @@
* <li> read_binary </li>
* </ul>
*/
- class ReadIDCallback : public Callbacks{
+ class ReadIDCallback : public Callbacks {
- public:
+ public:
- /**
- * Build the chain of callbacks.
- * @param parent object where to send the command to.
- */
- ReadIDCallback(M24SR &parent):mParent(parent),mIdPtr(NULL){}
+ /**
+ * Build the chain of callbacks.
+ * @param parent object where to send the command to.
+ */
+ ReadIDCallback(M24SR &parent):mParent(parent),mIdPtr(NULL) {}
- /**
- * Set the variable containing the result
- * @param idPtr
- */
- void read_id_on(uint8_t *idPtr){
- mIdPtr=idPtr;
- }
+ /**
+ * Set the variable containing the result
+ * @param idPtr
+ */
+ void read_id_on(uint8_t *idPtr) {
+ mIdPtr = idPtr;
+ }
- virtual void on_selected_application(M24SR *nfc,StatusTypeDef status){
- if(status==M24SR_SUCCESS){
- nfc->select_system_file();
- }else
- onFinishCommand(nfc,status);
+ virtual void on_selected_application(M24SR *nfc,StatusTypeDef status) {
+ if (status==M24SR_SUCCESS) {
+ nfc->select_system_file();
+ } else {
+ onFinishCommand(nfc,status);
+ }
- }
+ }
- virtual void on_selected_system_file(M24SR *nfc,StatusTypeDef status){
- if(status==M24SR_SUCCESS){
- nfc->read_binary(0x0011, 0x01, mIdPtr);
- }else
- onFinishCommand(nfc,status);
- }
+ virtual void on_selected_system_file(M24SR *nfc,StatusTypeDef status) {
+ if (status==M24SR_SUCCESS) {
+ nfc->read_binary(0x0011, 0x01, mIdPtr);
+ } else {
+ onFinishCommand(nfc,status);
+ }
+ }
- virtual void on_read_byte(M24SR *nfc,StatusTypeDef status,
- uint16_t ,uint8_t *, uint16_t ){
- onFinishCommand(nfc,status);
- }
+ virtual void on_read_byte(M24SR *nfc,StatusTypeDef status,
+ uint16_t ,uint8_t *, uint16_t ) {
+ onFinishCommand(nfc,status);
+ }
- private:
+ private:
- /**
- * Remove the private callback and call the user onReadId function.
- * @param nfc Object where the command was send.
- * @param status Command status.
- */
- void onFinishCommand(M24SR *nfc,StatusTypeDef status){
- mParent.mComponentCallback=NULL;
- mParent.getCallback()->on_read_id(nfc,status,mIdPtr);
- }
+ /**
+ * Remove the private callback and call the user onReadId function.
+ * @param nfc Object where the command was send.
+ * @param status Command status.
+ */
+ void onFinishCommand(M24SR *nfc,StatusTypeDef status) {
+ mParent.mComponentCallback=NULL;
+ mParent.getCallback()->on_read_id(nfc,status,mIdPtr);
+ }
- M24SR& mParent;
+ M24SR& mParent;
- /**
- * pointer to read id
- */
- uint8_t *mIdPtr;
+ /**
+ * pointer to read id
+ */
+ uint8_t *mIdPtr;
};
@@ -1408,8 +1425,8 @@
* Convert a generic enum to the value used by the M24SR chip.
* @param type Password type.
* @return equivalent value used inside the m24sr chip */
- uint16_t passwordTypeToConst(const PasswordType_t &type)const{
- switch(type){
+ uint16_t passwordTypeToConst(const PasswordType_t &type) const {
+ switch (type) {
case ReadPwd:
return READ_PWD;
case WritePwd:
@@ -1426,7 +1443,7 @@
* @return
*/
PasswordType_t constToPasswordType(const uint16_t type)const{
- switch(type){
+ switch(type) {
case READ_PWD:
return ReadPwd;
case WRITE_PWD:
@@ -1440,4 +1457,5 @@
#endif // __M24SR_CLASS_H
+
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

X-NUCLEO-NFC01A1 Dynamic NFC Tag