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
m24sr/m24sr_class.h
- Committer:
- giovannivisentini
- Date:
- 2016-01-15
- Revision:
- 14:7e3d436b19ee
- Parent:
- 12:d1f5eaa85deb
- Parent:
- 13:840a9c7f90b9
- Child:
- 15:67e136b6921d
File content as of revision 14:7e3d436b19ee:
/**
******************************************************************************
* @file m24sr_class.h
* @author ST Central Labs
* @version V1.0.0
* @date 05 Nov 2015
* @brief This file provides a set of functions to interface with the M24SR
* device.
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Revision ------------------------------------------------------------------*/
/*
Based on: X-CUBE-MEMS1/trunk/Drivers/BSP/Components/m24sr/m24sr.h
Revision: M24SR Driver V1.0.0
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __M24SR_CLASS_H
#define __M24SR_CLASS_H
/* Includes ------------------------------------------------------------------*/
#include "mbed.h"
#include "I2C.h"
#include "m24sr.h"
#include "Interfaces/Nfc_class.h"
#include "NDefNfcTagM24SR.h"
/* Classes -------------------------------------------------------------------*/
/**
* Class representing a M24SR component.
*/
class M24SR: public Nfc {
public:
/**
* Default password used to change the write/read permission
*/
static const uint8_t DEFAULT_PASSWORD[16];
/*** Constructor and Destructor Methods ***/
/**
* @brief Constructor.
* @param address I2C address of the component.
* @param I2C I2C device to be used for communication.
* @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,
const PinName& RFDISPinName) :
Nfc(), address(address), dev_I2C(I2C), GPOPin(GPOPinName), RFDisablePin(
RFDISPinName), answerReadyInterrupt(GPOPinName), interruptIsFired(
false),NDefTagUtil(*this) {
memset(uM24SRbuffer, 0, 0xFF * sizeof(int8_t));
syncMode = M24SR_WAITINGTIME_POLLING;
uDIDbyte = 0;
RFDisablePin = 0;
GPOPin.mode(PullNone);
answerReadyInterrupt.disable_irq();
answerReadyInterrupt.fall(this,
&M24SR::M24SR_AnswerReadyInterruptCallback);
answerReadyInterrupt.mode(PullUp);
}
/**
* @brief Destructor.
*/
virtual ~M24SR(void) {
}
/*** Public Component Related Methods ***/
/**
* @brief This function initializes the M24SR device.
* @param ptr Configure parameters, not used.
* @return NFC_SUCCESS if no errors
*/
virtual int Init(void *ptr) {
return (NFC_StatusTypeDef) M24SR_Init((NFC_InitTypeDef*)ptr);
}
virtual int ReadID(uint8_t *id) {
return (NFC_StatusTypeDef) M24SR_ReadID((uint8_t *) id);
}
/** lock the tag channel */
virtual NFC_StatusTypeDef GetSession(void) {
return (NFC_StatusTypeDef) M24SR_GetSession();
}
virtual NFC_StatusTypeDef KillSession(void) {
return (NFC_StatusTypeDef) M24SR_KillSession();
}
virtual NFC_StatusTypeDef Deselect(void) {
return (NFC_StatusTypeDef) M24SR_Deselect();
}
////////// tag4 command ////////////////////
virtual NFC_StatusTypeDef SelectApplication(void) {
return (NFC_StatusTypeDef) M24SR_SelectApplication();
}
virtual NFC_StatusTypeDef SelectCCfile(void) {
return (NFC_StatusTypeDef) M24SR_SelectCCfile();
}
virtual NFC_StatusTypeDef SelectNDEFfile(uint16_t NDEFfileId) {
return (NFC_StatusTypeDef) M24SR_SelectNDEFfile((uint16_t) NDEFfileId);
}
virtual NFC_StatusTypeDef SelectSystemfile(void) {
return (NFC_StatusTypeDef) M24SR_SelectSystemfile();
}
virtual NFC_StatusTypeDef ReadBinary(uint16_t Offset, uint8_t NbByteToRead,
uint8_t *pBufferRead) {
return (NFC_StatusTypeDef) M24SR_ReadBinary((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);
}
/////////////////// iso 7816-4 commands //////////////////////////
virtual NFC_StatusTypeDef Verify(PasswordType_t pwdId, uint8_t NbPwdByte,
const uint8_t *pPwd) {
return (NFC_StatusTypeDef) M24SR_Verify(passwordTypeToConst(pwdId),
(uint8_t) NbPwdByte, pPwd);
}
virtual NFC_StatusTypeDef ChangeReferenceData(PasswordType_t pwdId,
const uint8_t *pPwd) {
return (NFC_StatusTypeDef) M24SR_ChangeReferenceData(passwordTypeToConst(pwdId),
(uint8_t *) pPwd);
}
virtual NFC_StatusTypeDef EnableVerificationRequirement(
PasswordType_t uReadOrWrite) {
return (NFC_StatusTypeDef) M24SR_EnableVerificationRequirement(
passwordTypeToConst(uReadOrWrite));
}
virtual NFC_StatusTypeDef DisableVerificationRequirement(
PasswordType_t uReadOrWrite) {
return (NFC_StatusTypeDef) M24SR_DisableVerificationRequirement(
passwordTypeToConst(uReadOrWrite));
}
////////////////////// ST proprietary //////////////////////////////////
virtual NFC_StatusTypeDef STReadBinary(uint16_t Offset,
uint8_t NbByteToRead, uint8_t *pBufferRead) {
return (NFC_StatusTypeDef) M24SR_STReadBinary((uint16_t) Offset,
(uint8_t) NbByteToRead, (uint8_t *) pBufferRead);
}
virtual NFC_StatusTypeDef EnablePermanentState(PasswordType_t uReadOrWrite) {
return (NFC_StatusTypeDef) M24SR_EnablePermanentState(
passwordTypeToConst(uReadOrWrite));
}
virtual NFC_StatusTypeDef DisablePermanentState(PasswordType_t uReadOrWrite) {
return (NFC_StatusTypeDef) M24SR_DisablePermanentState(
passwordTypeToConst(uReadOrWrite));
}
///////////////////// chip configuration /////////////////////////////////
virtual NFC_StatusTypeDef StateControl(uint8_t uSetOrReset) {
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 ManageRFGPO(uint8_t GPO_RFconfig) {
return (NFC_StatusTypeDef) M24SR_ManageRFGPO(
(M24SR_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();
}
/////////////////// hight level/utility function /////////////////////
/**
* Get an implementation of NDefNfcTag to use the library NDefLib.
* @return an object of type NdefNfcTag
*/
NDefLib::NDefNfcTag& getNDefTag(){
return NDefTagUtil;
}
/**
* 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();
protected:
/*** Protected Component Related Methods ***/
NFC_StatusTypeDef M24SR_Init(NFC_InitTypeDef *);
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,
uint8_t *pBufferRead);
NFC_StatusTypeDef M24SR_UpdateBinary(uint16_t Offset, uint8_t NbByteToWrite,
uint8_t *pDataToWrite);
NFC_StatusTypeDef M24SR_Verify(uint16_t uPwdId, uint8_t NbPwdByte,
const uint8_t *pPwd);
NFC_StatusTypeDef M24SR_ChangeReferenceData(uint16_t uPwdId, uint8_t *pPwd);
NFC_StatusTypeDef M24SR_EnableVerificationRequirement(
uint16_t uReadOrWrite);
NFC_StatusTypeDef M24SR_DisableVerificationRequirement(
uint16_t uReadOrWrite);
NFC_StatusTypeDef M24SR_EnablePermanentState(uint16_t uReadOrWrite);
NFC_StatusTypeDef M24SR_DisablePermanentState(uint16_t uReadOrWrite);
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);
/**
* Wait until the answer is ready.
*/
NFC_StatusTypeDef M24SR_IO_IsAnswerReady(void);
/**
* Send a command to the component.
* @param NbByte Lenght of the command.
* @param pBuffer Buffer containing the command.
* @return NFC_SUCCESS if no errors
*/
NFC_StatusTypeDef M24SR_IO_SendI2Ccommand(uint8_t NbByte, uint8_t *pBuffer);
/**
* Read a command response.
* @param NbByte Number of bytes to read.
* @param pBuffer Buffer to store the response into.
* @return NFC_SUCCESS if no errors
*/
NFC_StatusTypeDef M24SR_IO_ReceiveI2Cresponse(uint8_t NbByte,
uint8_t *pBuffer);
/**
* Do an active polling on the I2C bus until the answer is ready.
* @return NFC_SUCCESS if no errors
*/
NFC_StatusTypeDef M24SR_IO_PollI2C(void);
/**
* Read the gpo pin.
* @param[out] pPinState Variable to store the pin state into.
*/
void M24SR_IO_GPO_ReadPin(uint8_t *pPinState) {
*pPinState= GPOPin.read();
}
/**
* Write the gpo pin.
* @param pPinState Pin state to write.
*/
void M24SR_IO_RFDIS_WritePin(uint8_t PinState) {
if (PinState == 0)
RFDisablePin = 0;
else
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() {
interruptIsFired = true;
answerReadyInterrupt.disable_irq();
}
/*** Component's Instance Variables ***/
/* Identity */
uint8_t who_am_i;
/* Type */
uint8_t type;
/* I2C address */
uint8_t address;
/* IO Device. */
I2C &dev_I2C;
/* GPIO */
DigitalIn GPOPin;
/**
* Pin used to disable the rf chip functionality.
*/
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
/**
* ???
*/
uint8_t uDIDbyte;
/**
* State variable changes when the interrupt is fired.
*/
volatile bool interruptIsFired;
/**
* Object implementing the interface to use the NDefLib.
*/
NDefNfcTagM24SR NDefTagUtil;
private:
/**
* 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){
case ReadPwd:
return READ_PWD;
case WritePwd:
return WRITE_PWD;
case I2CPwd:
default:
return I2C_PWD;
}
}//passwordTypeToConst
};
#endif // __M24SR_CLASS_H
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

X-NUCLEO-NFC01A1 Dynamic NFC Tag