This application provides a set of demos with X-NUCLEO-NFC01A1 expansion board.
Dependencies: NDefLib X_NUCLEO_NFC01A1 mbed
Fork of X-MBED-NFC1 by
This application provides a set of demos with X-NUCLEO-NFC01A1 expansion board.
The available demos are:
- SAMPLE_WRITE_URL: write a tag with the ST home page URL
- SAMPLE_COUNT_CLICK: create a custom tag to count and report the user button clicks.
- SAMPLE_WRITE_AND_CHANGE_ALL: write a tag with all the supported records and update the tag contents when the user button is pressed.
- SAMPLE_LOCK_TAG_CONTENT: use the M24SR component API to set the NFC tag as read-only.
To enable the different demos comment/uncomment the SAMPLE_* macros provided in main.cpp .
Revision 4:f40b3505070c, committed 2015-12-03
- Comitter:
- giovannivisentini
- Date:
- Thu Dec 03 13:44:40 2015 +0000
- Parent:
- 3:f7f818ee694e
- Child:
- 5:3b300c8235b7
- Commit message:
- move the driver file in a separate library + split the sample in different files
Changed in this revision
--- a/Common/component.h Tue Dec 01 16:01:24 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,0 @@
-/**
- ******************************************************************************
- * @file component.h
- * @author AST
- * @version V1.0.0
- * @date 1 April 2015
- * @brief Generic header file containing a generic component's definitions
- * and I/O functions.
- ******************************************************************************
- * @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.
- *
- ******************************************************************************
- */
-
-
-/* Prevent recursive inclusion -----------------------------------------------*/
-
-#ifndef __COMPONENT_H__
-#define __COMPONENT_H__
-
-
-/* Types ---------------------------------------------------------------------*/
-
-/**
- * @brief Component's Context structure definition.
- */
-typedef struct
-{
- /* Identity. */
- uint8_t who_am_i;
-
- /* ACTION ----------------------------------------------------------------*/
- /* There should be only a unique identifier for each component, which */
- /* should be the "who_am_i" parameter, hence this parameter is optional. */
- /* -----------------------------------------------------------------------*/
- /* Type. */
- uint8_t type;
-
- /* Configuration. */
- uint8_t address;
-
- /* Pointer to the Data. */
- void *pData;
-
- /* Pointer to the Virtual Table. */
- void *pVTable;
-
- /* ACTION ----------------------------------------------------------------*/
- /* There should be only a unique virtual table for each component, which */
- /* should be the "pVTable" parameter, hence this parameter is optional. */
- /* -----------------------------------------------------------------------*/
- /* Pointer to the Extended Virtual Table. */
- void *pExtVTable;
-} DrvContextTypeDef;
-
-/**
- * @brief Component's Status enumerator definition.
- */
-typedef enum
-{
- COMPONENT_OK = 0,
- COMPONENT_ERROR,
- COMPONENT_TIMEOUT,
- COMPONENT_NOT_IMPLEMENTED
-} DrvStatusTypeDef;
-
-#endif
--- a/Common/nfc.h Tue Dec 01 16:01:24 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,181 +0,0 @@
-/**
- ******************************************************************************
- * @file nfc.h
- * @author ST Central Labs
- * @version V1.0.0
- * @date 14-October-2015
- * @brief This header file contains the functions prototypes for the
- * NFC device driver.
- ******************************************************************************
- * @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.
- *
- ******************************************************************************
- */
-#ifndef __NFC_H_
-#define __NFC_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Includes ------------------------------------------------------------------*/
-#include <stdint.h>
-#include "component.h"
-/** @addtogroup BSP
- * @{
- */
-
-/** @addtogroup Components
- * @{
- */
-
-/** @addtogroup NFC
- * @{
- */
-
-/** @defgroup NFC_Exported_Types
- * @{
- */
-
-/**
- * @brief NFC init structure definition
- */
-typedef void* NFC_InitTypeDef;
-/**
- * @brief NFC status enumerator definition
- */
-typedef enum {
- NFC_SUCCESS=0x0000,
- NFC_ERROR=0x6F00,
- NFC_FILE_OVERFLOW_LE = 0x6280,
- NFC_EOF = 0x6282,
- NFC_PASSWORD_REQUIRED = 0x6300,
- NFC_PASSWORD_INCORRECT = 0x63C0,
- NFC_PASSWORD_INCORRECT1RETRY = 0x63C1,
- NFC_PASSWORD_INCORRECT2RETRY = 0x63C2,
- NFC_WRONG_LENGHT = 0x6700,
- NFC_UNSUCESSFUL_UPDATING = 0x6581,
- NFC_INCOPATIBLE_COMMAND= 0x6981,
- NFC_SECURITY_UNSATISFIED = 0x6982,
- NFC_REFERENCE_DATA_NOT_USABLE = 0x6984,
-
- NFC_INCORRECT_PARAMETER = 0x6a80,
- NFC_FILE_NOT_FOUND=0x6a82,
- NFC_FILE_OVERFLOW_LC = 0x6A84, //TODO difference with Le??
-
- NFC_INCORRECT_P1_OR_P2 = 0x6A86, //TODO better name?
- NFC_RF_SESSION_KILLED=0x6500,
- NFC_INS_NOT_SUPPORTED=0x6D00,
- NFC_CLASS_NOT_SUPPORTED=0x6E00,
-
- //IOError
- NFC_IO_ERROR_I2CTIMEOUT=0x0011,
- NFC_IO_ERROR_CRC=0x0012,
- NFC_IO_ERROR_NACK=0x0013,
- NFC_IO_ERROR_PARAMETER=0x0014,
- NFC_IO_ERROR_NBATEMPT=0x0015,
- NFC_IO_NOACKNOWLEDGE=0x0016
-} NFC_StatusTypeDef;
-
-/**
- * @brief NFC component identifier enumerator definition.
- */
-typedef enum
-{
- NFC_NONE_COMPONENT = 0,
- NFC_M24SR_COMPONENT = 1
-} NFC_ComponentTypeDef;
-
-
-/**
- * @brief NFC driver structure definition
- */
-typedef struct {
- /* Generic */
- NFC_StatusTypeDef (*Init) (void *handle, NFC_InitTypeDef *init);
- NFC_StatusTypeDef (*ReadID) (void *handle, uint8_t *id);
-
- /* Interrupts */
- NFC_StatusTypeDef (*SendInterrupt)(void *handle);
-
- /* Specific */
- //I2C session Commands:
- NFC_StatusTypeDef (*GetSession)(void *handle);
- NFC_StatusTypeDef (*KillSession)(void *handle);
- NFC_StatusTypeDef (*Deselect)(void *handle);
-
- //NFC forum type 4 commands:
- NFC_StatusTypeDef (*SelectApplication)(void *handle);
- NFC_StatusTypeDef (*SelectCCfile)(void *handle);
- NFC_StatusTypeDef (*SelectNDEFfile)(void *handle, uint16_t NDEFfileId);
- NFC_StatusTypeDef (*SelectSystemfile)(void *handle);
- NFC_StatusTypeDef (*ReadBinary)(void *handle, uint16_t Offset, uint8_t NbByteToRead, uint8_t *pBufferRead);
- NFC_StatusTypeDef (*UpdateBinary)(void *handle, uint16_t Offset, uint8_t NbByteToWrite, uint8_t *pDataToWrite);
-
- //ISO/IEC 7816-4 commands:
- NFC_StatusTypeDef (*Verify)(void *handle, uint16_t uPwdId, uint8_t NbPwdByte, uint8_t *pPwd);
- NFC_StatusTypeDef (*ChangeReferenceData)(void *handle, uint16_t uPwdId, uint8_t *pPwd);
- NFC_StatusTypeDef (*EnableVerificationRequirement)(void *handle, uint16_t uReadOrWrite);
- NFC_StatusTypeDef (*DisableVerificationRequirement)(void *handle, uint16_t uReadOrWrite);
-
- //ST Specific
- NFC_StatusTypeDef (*STReadBinary)(void *handle, uint16_t Offset, uint8_t NbByteToRead, uint8_t *pBufferRead);
- NFC_StatusTypeDef (*EnablePermanentState)(void *handle, uint16_t uReadOrWrite);
- NFC_StatusTypeDef (*DisablePermanentState)(void *handle, uint16_t uReadOrWrite);
-
- //??
-
- NFC_StatusTypeDef (*StateControl)(void *handle, uint8_t uSetOrReset);
- NFC_StatusTypeDef (*ManageI2CGPO)(void *handle, uint8_t GPO_I2Cconfig);
- NFC_StatusTypeDef (*ManageRFGPO)(void *handle, uint8_t GPO_RFconfig);
- NFC_StatusTypeDef (*RFConfig)(void *handle, uint8_t OnOffChoice);
-
-} NFC_DrvVTableTypeDef;
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __NFC_H_ */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- a/Interfaces/Component_class.h Tue Dec 01 16:01:24 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-/**
- ******************************************************************************
- * @file Component_class.h
- * @author AST / EST
- * @version V0.0.1
- * @date 13-April-2015
- * @brief This file contains the abstract class describing the interface of a
- * generic component.
- ******************************************************************************
- * @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.
- *
- ******************************************************************************
- */
-
-
-/* Define to prevent from recursive inclusion --------------------------------*/
-
-#ifndef __COMPONENT_CLASS_H
-#define __COMPONENT_CLASS_H
-
-
-/* Includes ------------------------------------------------------------------*/
-
-#include <stdint.h>
-
-
-/* Classes ------------------------------------------------------------------*/
-
-/** An abstract class for Generic components.
- */
-class Component
-{
-public:
- /**
- * @brief Initialization of the component.
- * @param[out] ptr Pointer to device specific initalization structure.
- * @return 0 in case of success, an error code otherwise.
- */
- virtual int Init(void *ptr) = 0;
-
- /**
- * @brief Get ID of the component.
- * @param[out] id Pointer to where to store the ID to.
- * @return 0 in case of success, an error code otherwise.
- */
- virtual int ReadID(uint8_t *id) = 0;
-
- virtual ~Component(){};
-};
-
-#endif /* __COMPONENT_CLASS_H */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- a/Interfaces/Nfc_class.h Tue Dec 01 16:01:24 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,162 +0,0 @@
-/**
- ******************************************************************************
- * @file Nfc_class.h
- * @author AST / EST
- * @version V0.0.1
- * @date 13-April-2015
- * @brief This file contains the abstract class describing the interface of a
- * nfc component.
- ******************************************************************************
- * @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.
- *
- ******************************************************************************
- */
-
-
-/* Generated with Stm32CubeTOO -----------------------------------------------*/
-
-/* Define to prevent from recursive inclusion --------------------------------*/
-
-#ifndef __NFC_CLASS_H
-#define __NFC_CLASS_H
-
-
-/* Includes ------------------------------------------------------------------*/
-
-#include "Component_class.h"
-
-
-/* Classes ------------------------------------------------------------------*/
-
-/** An abstract class for Nfc components.
- */
-class Nfc : public Component
-{
-public:
-
- /**
- * possible password to set
- */
- typedef enum{
- ReadPwd=READ_PWD, //!< password to use before read the tag
- WritePwd=WRITE_PWD,//!< password to use before write the tag
- I2CPwd=I2C_PWD, //!< root password, used only thought nfc
- }PasswordType_t;
-
-
- /**
- * open a i2c connection with the tag if an RF connection isn't already open
- * @return operation status
- */
- virtual NFC_StatusTypeDef GetSession(void) = 0;
- /**
- * force to open an i2c connection , abort the RF connection
- * @return
- */
- virtual NFC_StatusTypeDef KillSession(void) = 0;
-
- /**
- * close an i2c connection
- * @return
- */
- virtual NFC_StatusTypeDef Deselect(void) = 0;
-
- /**
- * Select the application file
- * @return
- */
- virtual NFC_StatusTypeDef SelectApplication(void) = 0;
-
- /**
- * select the CC file
- * @return
- */
- virtual NFC_StatusTypeDef SelectCCfile(void) = 0;
-
- /**
- * select the ndef file
- * @param NDEFfileId file id to open
- * @return
- */
- virtual NFC_StatusTypeDef SelectNDEFfile(uint16_t NDEFfileId) = 0;
-
- /**
- * select the system file
- * @return
- */
- virtual NFC_StatusTypeDef SelectSystemfile(void) = 0;
-
- /**
- * read data from the tag
- * @param Offset offset where start to read
- * @param NbByteToRead number of byte to read
- * @param[out] pBufferRead buffer where store the read data
- * @return
- */
- virtual NFC_StatusTypeDef ReadBinary(uint16_t Offset, uint8_t NbByteToRead, uint8_t *pBufferRead) = 0;
-
- /**
- * write data to the tag
- * @param Offset offset where start to write
- * @param NbByteToWrite number of byte to write
- * @param pDataToWrite buffer to write
- * @return
- */
- virtual NFC_StatusTypeDef UpdateBinary(uint16_t Offset, uint8_t NbByteToWrite, uint8_t *pDataToWrite) = 0;
-
- /**
- * check that the password is correct
- * @param uPwdId password type
- * @param NbPwdByte password size ( must be 0x10)
- * @param pPwd password buffer
- * @return
- */
- virtual NFC_StatusTypeDef Verify(PasswordType_t uPwdId, uint8_t NbPwdByte,const uint8_t *pPwd) = 0;
-
- /**
- * change the pa
- * @param uPwdId
- * @param pPwd
- * @return
- */
- virtual NFC_StatusTypeDef ChangeReferenceData(PasswordType_t uPwdId,const uint8_t *pPwd) = 0;
- virtual NFC_StatusTypeDef EnableVerificationRequirement(PasswordType_t uReadOrWrite) = 0;
- virtual NFC_StatusTypeDef DisableVerificationRequirement(PasswordType_t uReadOrWrite) = 0;
- virtual NFC_StatusTypeDef STReadBinary(uint16_t Offset, uint8_t NbByteToRead, uint8_t *pBufferRead) = 0;
- virtual NFC_StatusTypeDef EnablePermanentState(PasswordType_t uReadOrWrite) = 0;
- virtual NFC_StatusTypeDef DisablePermanentState(PasswordType_t uReadOrWrite) = 0;
- virtual NFC_StatusTypeDef StateControl(uint8_t uSetOrReset) = 0;
- virtual NFC_StatusTypeDef ManageI2CGPO(uint8_t GPO_I2Cconfig) = 0;
- virtual NFC_StatusTypeDef ManageRFGPO(uint8_t GPO_RFconfig) = 0;
- virtual NFC_StatusTypeDef RFConfig(uint8_t OnOffChoice) = 0;
-
- virtual ~Nfc(){};
-};
-
-#endif /* __NFC_CLASS_H */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/Sample_countClick.cpp Thu Dec 03 13:44:40 2015 +0000
@@ -0,0 +1,86 @@
+
+#include "mbed.h"
+
+#include "Type4NfcTagSTM24SR.h"
+#include "NDefLib/RecordType/RecordText.h"
+
+#include "X_NUCLEO_NFC01A1.h"
+
+class MyRecord : public NDefLib::RecordText{
+
+private:
+ char nClickStringBuffer[12];
+ uint32_t nClick;
+
+ void syncTextValue(){
+ sprintf(nClickStringBuffer,"%d",nClick);
+ setText(nClickStringBuffer);
+ }
+
+public:
+
+ MyRecord():nClick(0){
+ syncTextValue();
+ }
+
+ void incrementClick(){
+ nClick++;
+ syncTextValue();
+ }
+
+};
+
+static void writeMessage(X_NUCLEO_NFC01A1 *nfcNucleo,NDefLib::Message &msg){
+ Type4NfcTagSTM24SR tag(nfcNucleo->getM24SR());
+ //open the i2c session with the nfc chip
+ if(tag.openSession()){
+ nfcNucleo->getLed1()=! nfcNucleo->getLed1();
+
+ //write the tag
+ if(tag.write(msg)){
+ nfcNucleo->getLed2()=!nfcNucleo->getLed2();
+ }//if
+
+ //close the i2c session
+ if(tag.closeSession())
+ nfcNucleo->getLed3()=!nfcNucleo->getLed3();
+ }//if open session
+}//writeMessage
+
+
+static volatile bool buttonPress=false;
+
+static void setButtonPress(){
+ buttonPress=true;
+}//if buttonPress
+
+void sample_countClick() {
+ I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
+ i2cChannel.frequency(400000);
+
+ X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
+ //create the wrapper for use the NdefLib
+ Type4NfcTagSTM24SR tag(nfcNucleo->getM24SR());
+
+ InterruptIn userButton(USER_BUTTON);
+ userButton.fall(setButtonPress);
+
+ //create the NDef message and record
+ NDefLib::Message msg;
+ MyRecord rClickCount;
+ msg.addRecord(&rClickCount);
+
+ writeMessage(nfcNucleo,msg);
+
+ while(true){
+
+ if(buttonPress){
+ rClickCount.incrementClick();
+ writeMessage(nfcNucleo,msg);
+ buttonPress=false;
+ }//if
+ //wait next event
+ __WFE();
+ }//while
+
+}//sample_countClick
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/Sample_writeAndChangeAll.cpp Thu Dec 03 13:44:40 2015 +0000
@@ -0,0 +1,275 @@
+#include "mbed.h"
+
+#include "Type4NfcTagSTM24SR.h"
+
+#include "NDefLib/RecordType/RecordAAR.h"
+#include "NDefLib/RecordType/RecordSMS.h"
+#include "NDefLib/RecordType/RecordGeo.h"
+#include "NDefLib/RecordType/RecordURI.h"
+#include "NDefLib/RecordType/RecordMail.h"
+#include "NDefLib/RecordType/RecordText.h"
+#include "NDefLib/RecordType/RecordMimeType.h"
+#include "NDefLib/RecordType/RecordVCard.h"
+
+#include "X_NUCLEO_NFC01A1.h"
+
+static Serial pc(SERIAL_TX, SERIAL_RX);
+
+static void shiftLed(DigitalOut &led1,DigitalOut &led2,DigitalOut &led3){
+ const uint8_t prevLed1=led1;
+ const uint8_t prevLed2=led2;
+ const uint8_t prevLed3=led3;
+ led1=prevLed3;
+ led2=prevLed1;
+ led3=prevLed2;
+}
+
+static void setNFCTag(NDefLib::Type4NfcTag &tag){
+
+ bool writeStatus,closeStatus;
+ if(tag.openSession()){
+ NDefLib::Message msg;
+
+ NDefLib::RecordAAR rAAR("com.st.BlueMS");
+ msg.addRecord(&rAAR);
+
+ NDefLib::RecordSMS rSMS("123456789","st.com.BlueMS");
+ msg.addRecord(&rSMS);
+
+ NDefLib::RecordGeo rGeo(123.123,-456.789);
+ msg.addRecord(&rGeo);
+
+ NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"http://www.st.com");
+ msg.addRecord(&rUri);
+
+ NDefLib::RecordMail rMail("mail@st.com","ciao","da nfc tag");
+ msg.addRecord(&rMail);
+
+ NDefLib::RecordMimeType rText1("text/plain",(const uint8_t*)"ciao",4);
+ msg.addRecord(&rText1);
+
+ NDefLib::RecordText rText3(NDefLib::RecordText::UTF8,"it","ciao");
+ msg.addRecord(&rText3);
+
+ NDefLib::RecordVCard::VCardInfo_t cardInfo;
+ cardInfo[NDefLib::RecordVCard::FORMATTED_NAME]="prova prova1";
+ cardInfo[NDefLib::RecordVCard::ADDRESS_HOME]=";;1 Main St.;Springfield;IL;12345;USA";
+ cardInfo[NDefLib::RecordVCard::ADDRESS_WORK]=";;2 Main St.;Springfield;IL;12345;USA";
+ cardInfo[NDefLib::RecordVCard::EMAIL_WORK]="workmail@st.com";
+ cardInfo[NDefLib::RecordVCard::EMAIL_HOME]="homemail@st.com";
+ cardInfo[NDefLib::RecordVCard::GEO]="39.95;-75.1667";
+ cardInfo[NDefLib::RecordVCard::IMPP]="aim:johndoe@aol.com";
+ cardInfo[NDefLib::RecordVCard::NAME]="prova2;prova3";
+ cardInfo[NDefLib::RecordVCard::NICKNAME]="test";
+ cardInfo[NDefLib::RecordVCard::NOTE]="A good test";
+ cardInfo[NDefLib::RecordVCard::ORGANIZATION]="STM";
+ cardInfo[NDefLib::RecordVCard::TEL_HOME]="123";
+ cardInfo[NDefLib::RecordVCard::TEL_MOBILE]="456";
+ cardInfo[NDefLib::RecordVCard::TEL_WORK]="789";
+ cardInfo[NDefLib::RecordVCard::TITLE]="King";
+ cardInfo[NDefLib::RecordVCard::URL]="www.st.com";
+ cardInfo[NDefLib::RecordVCard::PHOTO_URI]="http://www.st.com/st-web-ui/static/active/en/fragment/multimedia/image/picture/customer_focus.jpg";
+ NDefLib::RecordVCard rVCard(cardInfo);
+ msg.addRecord(&rVCard);
+
+ writeStatus = tag.write(msg);
+
+ closeStatus = tag.closeSession();
+
+ }else
+ pc.printf("Error open Session\n\r");
+
+ if(writeStatus)
+ pc.printf("writeOk\n\r");
+ else
+ pc.printf("writeFail\n\r");
+
+ if(closeStatus)
+ pc.printf("closeOk\n\r");
+ else
+ pc.printf("CloseFail\n\r");
+}
+
+static void printRecord(NDefLib::Record *r){
+ using namespace NDefLib;
+ switch(r->getType()){
+ case Record::TYPE_TEXT: {
+ RecordText *temp = (RecordText*)r;
+ pc.printf("Read Text: %s\r\n",temp->getText().c_str());
+ break; }
+ case Record::TYPE_AAR:{
+ RecordAAR *temp = (RecordAAR*)r;
+ pc.printf("Read ARR: %s\r\n",temp->getPackage().c_str());
+ break; }
+ case Record::TYPE_MIME:{
+ RecordMimeType *temp = (RecordMimeType*)r;
+ pc.printf("Read mimeType: %s\r\n",temp->getMimeType().c_str());
+ pc.printf("Read mimeData: %s\r\n",
+ std::string((const char*)temp->getMimeData(),
+ temp->getMimeDataLenght()).c_str());
+ break;}
+ case Record::TYPE_URI:{
+ RecordURI *temp = (RecordURI*)r;
+ pc.printf("Read uriId: %d\r\n",temp->getUriId());
+ pc.printf("Read uriType: %s\r\n",temp->getUriType().c_str());
+ pc.printf("Read uriContent: %s\r\n",temp->getContent().c_str());
+ break;}
+ case Record::TYPE_URI_MAIL:{
+ RecordMail *temp = (RecordMail*)r;
+ pc.printf("Read Dest: %s\r\n",temp->getToAddress().c_str());
+ pc.printf("Read Subject: %s\r\n",temp->getSubject().c_str());
+ pc.printf("Read Body: %s\r\n",temp->getBody().c_str());
+ break;}
+ case Record::TYPE_URI_SMS:{
+ RecordSMS *temp = (RecordSMS*)r;
+ pc.printf("Read number: %s\r\n",temp->getNumber().c_str());
+ pc.printf("Read message: %s\r\n",temp->getMessagge().c_str());
+ break;}
+ case Record::TYPE_URI_GEOLOCATION:{
+ RecordGeo *temp = (RecordGeo*)r;
+ pc.printf("Read lat: %f\r\n",temp->getLatitude());
+ pc.printf("Read long: %f\r\n",temp->getLongitude());
+ break;}
+ case Record::TYPE_MIME_VCARD:{
+ const RecordVCard *temp = (RecordVCard*)r;
+ pc.printf("Read Name: %s\r\n",(*temp)[RecordVCard::NAME].c_str());
+ pc.printf("Read Mail: %s\r\n",(*temp)[RecordVCard::EMAIL_WORK].c_str());
+ pc.printf("Read ORG: %s\r\n",(*temp)[RecordVCard::ORGANIZATION].c_str());
+ break;}
+ case Record::TYPE_UNKNOWN:{
+ pc.printf("Unknown record\r\n");
+ break;}
+ }//switch
+}
+
+static void changeRecord(NDefLib::Record *r){
+ using namespace NDefLib;
+ switch(r->getType()){
+ case Record::TYPE_TEXT: {
+ RecordText *temp = (RecordText*)r;
+ temp->setText("CIAOCiao");
+ break; }
+ case Record::TYPE_AAR:{
+ RecordAAR *temp = (RecordAAR*)r;
+ temp->setPackage("set Package Ok");
+ break; }
+ case Record::TYPE_MIME:{
+ RecordMimeType *temp = (RecordMimeType*)r;
+ temp->copyMimeData((const uint8_t *)"String2",sizeof("String2"));
+ break;}
+ case Record::TYPE_URI:{
+ RecordURI *temp = (RecordURI*)r;
+ temp->setContent("google.it");
+ break;}
+ case Record::TYPE_URI_MAIL:{
+ RecordMail *temp = (RecordMail*)r;
+ temp->setToAddress("newMail@st.com");
+ temp->setSubject("tag change");
+ temp->setBody("read/change Works!");
+ break;}
+ case Record::TYPE_URI_SMS:{
+ RecordSMS *temp = (RecordSMS*)r;
+ temp->setMessage("Message Change");
+ temp->setNumber("0987654321");
+ break;}
+ case Record::TYPE_URI_GEOLOCATION:{
+ RecordGeo *temp = (RecordGeo*)r;
+ temp->setLatitude(-temp->getLatitude());
+ temp->setLongitude(-temp->getLongitude());
+ break;}
+ case Record::TYPE_MIME_VCARD:{
+ RecordVCard *temp = (RecordVCard*)r;
+ (*temp)[RecordVCard::NAME]="name change";
+ (*temp)[RecordVCard::NICKNAME]="nic change";
+ break;}
+ case Record::TYPE_UNKNOWN:{
+ pc.printf("Unknown record\r\n");
+ break;}
+ }//switch
+}
+
+static void readNfcTag(NDefLib::Type4NfcTag &tag){
+ using namespace NDefLib;
+
+ if(tag.openSession()){
+ NDefLib::Message readMsg;
+
+ tag.read(&readMsg);
+
+ if(readMsg.getNRecords()==0){
+ pc.printf("Error Read\r\n");
+ }else{
+ for(uint32_t i=0;i<readMsg.getNRecords();i++){
+ Record *r = readMsg[i];
+ printRecord(r);
+ delete r;
+ }//for
+ }//if-else
+
+ tag.closeSession();
+ }else{
+ pc.printf("Error open read Session\n\r");
+ }
+}
+
+
+static void changeNfcTag(NDefLib::Type4NfcTag &tag){
+ using namespace NDefLib;
+
+ if(tag.openSession()){
+ NDefLib::Message readMsg;
+
+ tag.read(&readMsg);
+
+ if(readMsg.getNRecords()==0){
+ pc.printf("Error Read\r\n");
+ }else{
+ for(uint32_t i=0;i<readMsg.getNRecords();i++){
+ Record *r = readMsg[i];
+ changeRecord(r);
+ }//for
+ tag.write(readMsg);
+ }//if-else
+
+ tag.closeSession();
+ }else{
+ pc.printf("Error open SessionChange\n\r");
+ }
+}
+
+static volatile bool buttonPress=false;
+
+static void setButtonPress(){
+ buttonPress=true;
+}
+
+void sample_writeAndChangeAll() {
+ I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
+ i2cChannel.frequency(400000);
+ DigitalOut nucleoLed(LED1);
+
+ X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
+ Type4NfcTagSTM24SR tag(nfcNucleo->getM24SR());
+ InterruptIn mybutton(USER_BUTTON);
+
+ nfcNucleo->getLed1()=1;
+ nfcNucleo->getLed2()=0;
+ nfcNucleo->getLed3()=0;
+
+ setNFCTag(tag);
+ readNfcTag(tag);
+
+ mybutton.fall(setButtonPress);
+
+ while(true) {
+ wait(1);
+ nucleoLed = !nucleoLed;
+ shiftLed(nfcNucleo->getLed1(),nfcNucleo->getLed2(),nfcNucleo->getLed3());
+ if(buttonPress){
+ changeNfcTag(tag);
+ readNfcTag(tag);
+ buttonPress=false;
+ }
+ }
+
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/Sample_writeUrl.cpp Thu Dec 03 13:44:40 2015 +0000
@@ -0,0 +1,39 @@
+#include "mbed.h"
+
+#include "Type4NfcTagSTM24SR.h"
+#include "NDefLib/RecordType/RecordURI.h"
+
+#include "X_NUCLEO_NFC01A1.h"
+
+void sample_writeUrl() {
+ Serial pc(SERIAL_TX, SERIAL_RX);
+ I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
+ i2cChannel.frequency(400000);
+ X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
+ //create the wrapper for use the NdefLib
+ Type4NfcTagSTM24SR tag(nfcNucleo->getM24SR());
+ pc.printf("System Init done: !\n\r");
+ //open the i2c session with the nfc chip
+ if(tag.openSession()){
+ nfcNucleo->getLed1()=1;
+
+ //create the NDef message and record
+ NDefLib::Message msg;
+ NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"st.com");
+ msg.addRecord(&rUri);
+
+ //write the tag
+ if(tag.write(msg)){
+ pc.printf("Tag writed \n\r");
+ nfcNucleo->getLed2()=1;
+ }
+
+
+ //close the i2c session
+ if(!tag.closeSession()){
+ pc.printf("Error Closing the session\n\r");
+ }else
+ nfcNucleo->getLed3()=1;
+ }else
+ pc.printf("Error open Session\n\r");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Samples/Samples.h Thu Dec 03 13:44:40 2015 +0000 @@ -0,0 +1,8 @@ +#ifndef __SAMPLES_H__ +#define __SAMPLES_H__ + +void sample_writeUrl(); +void sample_countClick(); +void sample_writeAndChangeAll(); + +#endif /* __SAMPLES_H__ */ \ No newline at end of file
--- a/Type4NfcTagSTM24SR.cpp Tue Dec 01 16:01:24 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,125 +0,0 @@
-/*
- * Type4NfcTagSTM24SR.cpp
- *
- * Created on: Nov 5, 2015
- * Author: giovanni visentini
- */
-
-#include <Type4NfcTagSTM24SR.h>
-
-/* wait 1sec, driver is configured to let 200ms for command to complete */
-/* which is enough for all commands except GetSession if RF session is already opened */
-/* Smartphone generaly release the session within the second, but customer can modify this value */
-#define OPENSESSION_NTRIALS 5
-
-#define CC_FILE_LENGTH_BYTE 15
-
-bool Type4NfcTagSTM24SR::openSession(bool force) {
-
- if (isSessionOpen())
- return true;
- //else
- if (force)
- mDevice.KillSession();
-
- int8_t nTrials = OPENSESSION_NTRIALS;
- NFC_StatusTypeDef status = NFC_ERROR;
- while (status != NFC_SUCCESS && nTrials) {
- status = mDevice.GetSession();
- nTrials--;
- }
-
- if (status != NFC_SUCCESS) {
- return false;
- } //else
-
- //Select the NFC type 4 application
- if (mDevice.SelectApplication() != NFC_SUCCESS)
- return false;
-
- if (mDevice.SelectCCfile() != NFC_SUCCESS)
- return false;
-
- uint8_t CCFile[CC_FILE_LENGTH_BYTE];
- /* read the first 15 bytes of the CC file */
- if (mDevice.ReadBinary(0x0000, CC_FILE_LENGTH_BYTE, CCFile) != NFC_SUCCESS)
- return false;
-
- //read the ndefFileId
- uint16_t ndefFileId = (uint16_t) ((CCFile[0x09] << 8) | CCFile[0x0A]);
- mMaxReadBytes = (uint16_t) ((CCFile[0x03] << 8) | CCFile[0x04]);
- mMaxWriteBytes = (uint16_t) ((CCFile[0x05] << 8) | CCFile[0x06]);
-
- //openit
- if (mDevice.SelectNDEFfile(ndefFileId) != NFC_SUCCESS)
- return false;
-
- Type4NfcTag::openSession();
- return true;
-}
-
-bool Type4NfcTagSTM24SR::closeSession() {
-
- //no open session
- if (!isSessionOpen())
- return true;
-
- //close the CC file
- if (mDevice.Deselect() != NFC_SUCCESS)
- return false;
-
- Type4NfcTag::closeSession();
- return true;
-}
-
-bool Type4NfcTagSTM24SR::writeByte(const uint8_t *buffer, uint16_t length, uint16_t offset) {
-
- NFC_StatusTypeDef status = NFC_SUCCESS;
- bool prevSessionStatus = isSessionOpen();
- if (!prevSessionStatus) {
- //try to acquire a session or fail
- if (openSession(false))
- return false;
- } //if
-
- if (length > mMaxWriteBytes) {
- do {
- status = mDevice.UpdateBinary(offset, mMaxWriteBytes,(uint8_t*) buffer);
- offset += mMaxWriteBytes;
- buffer += mMaxWriteBytes;
- length -= mMaxWriteBytes;
- } while (length > mMaxWriteBytes && status == NFC_SUCCESS);
- } //if
-
- //finish to write the buffer
- if (status == NFC_SUCCESS && mMaxWriteBytes)
- status = mDevice.UpdateBinary(offset, length,(uint8_t*) buffer);
-
- if (status == NFC_SUCCESS) {
- if (!prevSessionStatus) // if the session was closed, try close it
- return closeSession();
- else
- return true;
- } else
- return false;
-}
-
-bool Type4NfcTagSTM24SR::readByte(uint16_t byteOffset, uint16_t byteLength,
- uint8_t *buffer) {
- NFC_StatusTypeDef status = NFC_SUCCESS;
- uint16_t offset = byteOffset;
- if (byteLength > mMaxReadBytes) {
- do {
- status = mDevice.ReadBinary(offset, mMaxReadBytes, buffer);
- offset += mMaxReadBytes;
- buffer += mMaxReadBytes;
- byteLength -= mMaxReadBytes;
- } while (byteLength > mMaxWriteBytes && status == NFC_SUCCESS);
- } //if
- //finish to write the buffer
- if (status == NFC_SUCCESS && mMaxWriteBytes)
- status = mDevice.ReadBinary(offset, byteLength, buffer);
-
- return status == NFC_SUCCESS;
-}
-
--- a/Type4NfcTagSTM24SR.h Tue Dec 01 16:01:24 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,225 +0,0 @@
-/*
- * Type4NfcTagSTM24SR.h
- *
- * Created on: Nov 5, 2015
- * Author: giovanni visentini
- */
-
-#ifndef TYPE4NFCTAGSTM24SR_H_
-#define TYPE4NFCTAGSTM24SR_H_
-#include <stdint.h>
-#include "m24sr/m24sr_class.h"
-
-#include "NDefLib/Type4NfcTag.h"
-
-/**
- * implement the abstract method for use the NDefLib
- */
-class Type4NfcTagSTM24SR: public NDefLib::Type4NfcTag {
-
-public:
- /**
- *
- * @param device device where write the Ndef tags
- */
- Type4NfcTagSTM24SR(M24SR &device) :
- mDevice(device), mMaxReadBytes(0xFF), mMaxWriteBytes(
- 0xFF) {
- }
-
-
- virtual bool openSession(bool force = false);
- virtual bool closeSession();
-
- /**
- * close the open session
- */
- virtual ~Type4NfcTagSTM24SR() {
- if(isSessionOpen())
- closeSession();
- }//~Type4NfcTagSTM24SR
-
- bool enableReadPassword(const uint8_t* pCurrentWritePassword,
- const uint8_t* pNewPassword) {
- if (!isSessionOpen())
- return false;
-
- if (mDevice.Verify(M24SR::WritePwd, 0x10, pCurrentWritePassword)
- == NFC_SUCCESS) {
- /* Set new password */
- if (mDevice.ChangeReferenceData(M24SR::ReadPwd, pNewPassword)
- == NFC_SUCCESS)
- return mDevice.EnableVerificationRequirement(M24SR::ReadPwd)
- == NFC_SUCCESS;
- } //else
- /* M24SR already lock but password not known */
- return false;
-
- }
-
- bool disableReadPassword(const uint8_t* pCurrentWritePassword) {
- if (!isSessionOpen())
- return false;
-
- if (mDevice.Verify(M24SR::WritePwd, 0x10, pCurrentWritePassword)
- == NFC_SUCCESS) {
- /* Set new password */
- return mDevice.DisableVerificationRequirement(M24SR::ReadPwd)
- == NFC_SUCCESS;
- } else {
- /* M24SR already lock but password not known */
- return false;
- }
- }
-
- bool enableWritePassword(const uint8_t* pCurrentWritePassword,
- uint8_t* pNewPassword) {
- if (!isSessionOpen())
- return false;
-
- /* check we have the good password */
- if (mDevice.Verify(M24SR::WritePwd, 0x10, pCurrentWritePassword)
- == NFC_SUCCESS) {
- /* Set new password */
- if (mDevice.ChangeReferenceData(M24SR::WritePwd, pNewPassword)
- == NFC_SUCCESS)
- return mDevice.EnableVerificationRequirement(M24SR::WritePwd)
- == NFC_SUCCESS;
- }
- return false;
- }
-
- bool disableWritePassword(const uint8_t* pCurrentWritePassword) {
- if (!isSessionOpen())
- return false;
-
- if (mDevice.Verify(M24SR::WritePwd, 0x10, pCurrentWritePassword)
- == NFC_SUCCESS)
- return mDevice.DisableVerificationRequirement(M24SR::WritePwd)
- == NFC_SUCCESS;
- return false;
- }
-
- /**
- * @brief This fonction desactivate the need of read and write password for next access
- * @param pSuperUserPassword : I2C super user password to overwrite read and write password
- * @retval SUCCESS : M24SR access is now free (no password needed)
- * @retval ERROR : operation does not complete
- */
- bool disableAllPassword(const uint8_t* pSuperUserPassword) {
- if (!isSessionOpen())
- return false;
-
- if (mDevice.Verify(M24SR::WritePwd, 0x10, pSuperUserPassword)
- == NFC_SUCCESS) {
- mDevice.DisablePermanentState(M24SR::ReadPwd);
- mDevice.DisablePermanentState(M24SR::WritePwd);
-
- mDevice.DisableVerificationRequirement(M24SR::ReadPwd);
- mDevice.DisableVerificationRequirement(M24SR::WritePwd);
-
- /* reset password */
- mDevice.ChangeReferenceData(M24SR::ReadPwd, pSuperUserPassword);
- mDevice.ChangeReferenceData(M24SR::WritePwd, pSuperUserPassword);
- return true;
- }
- return false;
- }
-
- /**
- * @brief This fonction enable read only mode
- * @param pCurrentWritePassword : Write password is needed to have right to enable read only mode
- * @retval SUCCESS : M24SR access is now forbidden in write mode
- * @retval ERROR : operation does not complete
- */
- bool enableReadOnly(const uint8_t* pCurrentWritePassword) {
- if (!isSessionOpen())
- return false;
-
- if (mDevice.Verify(M24SR::WritePwd, 0x10, pCurrentWritePassword)
- == NFC_SUCCESS) {
- /* lock write to have read only */
- return mDevice.EnablePermanentState(M24SR::WritePwd) == NFC_SUCCESS;
- }
- return false;
- }
-
- /**
- * @brief This fonction disable read only mode
- * @param pCurrentWritePassword : Write password is needed to have right to disable read only mode
- * @retval SUCCESS : M24SR write access is now allowed
- * @retval ERROR : operation does not complete
- */
- bool disableReadOnly() {
- if (!isSessionOpen())
- return false;
-
- if (mDevice.Verify(M24SR::I2CPwd, 0x10, M24SR::DEFAULT_PASSWORD)
- == NFC_SUCCESS) {
- /* disable write protection to disable read only mode */
- if (mDevice.DisablePermanentState(M24SR::WritePwd) == NFC_SUCCESS)
- return mDevice.DisableVerificationRequirement(M24SR::WritePwd)
- == NFC_SUCCESS;
- } //if
- return false;
- }
-
- /**
- * @brief This fonction enable write only mode
- * @param pCurrentWritePassword : Write password is needed to have right to enable write only mode
- * @retval SUCCESS : M24SR access is now forbidden in read mode
- * @retval ERROR : operation does not complete
- */
- bool enableWriteOnly(const uint8_t* pCurrentWritePassword) {
- if (!isSessionOpen())
- return false;
-
- if (mDevice.Verify(M24SR::WritePwd, 0x10, pCurrentWritePassword)
- == NFC_SUCCESS) {
- /* disable read access and keep write */
- return mDevice.EnablePermanentState(M24SR::ReadPwd) == NFC_SUCCESS;
- }
- return false;
- }
-
- /**
- * @brief This fonction disable write only mode
- * @param pCurrentWritePassword : Write password is needed to have right to disable write only mode
- * @retval SUCCESS : M24SR read access is now allowed
- * @retval ERROR : operation does not complete
- */
- bool disableWriteOnly() {
- if (!isSessionOpen())
- return false;
-
- if (mDevice.Verify(M24SR::I2CPwd, 0x10, M24SR::DEFAULT_PASSWORD)
- == NFC_SUCCESS) {
- /* disable write only -> enable write acces */
- if (mDevice.DisablePermanentState(M24SR::ReadPwd) == NFC_SUCCESS)
- return mDevice.DisableVerificationRequirement(M24SR::ReadPwd)
- == NFC_SUCCESS;
- }
- return false;
- }
-
-protected:
- virtual bool writeByte(const uint8_t *buffer, const uint16_t length, uint16_t offset);
- virtual bool readByte(const uint16_t byteOffset, const uint16_t byteLength,
- uint8_t *buffer);
-
-private:
-
- M24SR &mDevice;
-
- /**
- * max length for a read operation
- */
- uint16_t mMaxReadBytes;
-
- /**
- * max length for a write operation
- */
- uint16_t mMaxWriteBytes;
-};
-
-#endif /* TYPE4NFCTAGSTM24SR_H_ */
--- a/X_NUCLEO_NFC01A1.cpp Tue Dec 01 16:01:24 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-/*
- * X_NUCLEO_NFC01A1.cpp
- *
- * Created on: Nov 5, 2015
- * Author: giovanni visentini
- */
-
-#include <X_NUCLEO_NFC01A1.h>
-
-const uint8_t X_NUCLEO_NFC01A1::M24SR_ADDR=0xAC;
-const PinName X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN=D14;
-const PinName X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN=D15;
-
-
-
-const PinName X_NUCLEO_NFC01A1::GPO_PIN=D12;
-const PinName X_NUCLEO_NFC01A1::RF_DISABLE_PIN=D11;
-const PinName X_NUCLEO_NFC01A1::LED1_PIN=D5;
-const PinName X_NUCLEO_NFC01A1::LED2_PIN=D4;
-const PinName X_NUCLEO_NFC01A1::LED3_PIN=D2;
-
-X_NUCLEO_NFC01A1 *X_NUCLEO_NFC01A1::mInstance = NULL;
-
-X_NUCLEO_NFC01A1* X_NUCLEO_NFC01A1::Instance(I2C &devI2C) {
- if (mInstance == NULL) { // the first time
- mInstance = new X_NUCLEO_NFC01A1(devI2C);
- if (mInstance != NULL) { //allocation ok
- const int status = mInstance->mM24SR.Init(NULL);
- if (status != NFC_SUCCESS) { //initialization failed
- delete mInstance;
- error(
- "Failed to init X_NUCLEO_NFC01A1 expansion board!\r\nError:0x%X\r\n",
- status);
- } //if init
- } //if instance !=NULL
- } //if instance
- return mInstance;
-}
--- a/X_NUCLEO_NFC01A1.h Tue Dec 01 16:01:24 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,97 +0,0 @@
-/*
- * X_NUCLEO_NFC01A1.h
- *
- * Created on: Nov 5, 2015
- * Author: giovanni visentini
- */
-
-#ifndef X_NUCLEO_NFC01A1_H_
-#define X_NUCLEO_NFC01A1_H_
-#include <stdint.h>
-
-#include "mbed.h"
-
-#include "m24sr/m24sr_class.h"
-
-/**
- * singleton class that controls all the electronics inside the X_NUCLEO_NFC01A1 expansion board
- */
-class X_NUCLEO_NFC01A1 {
-
-private:
- /**
- * ponter to the singleton instance, NULL if we did't build one
- */
- static X_NUCLEO_NFC01A1 *mInstance;
- /**
- * i2c address of the m24sr chip
- */
- static const uint8_t M24SR_ADDR;
-
- static const PinName GPO_PIN;
- static const PinName RF_DISABLE_PIN;
- static const PinName LED1_PIN;
- static const PinName LED2_PIN;
- static const PinName LED3_PIN;
-
- /**
- * constructor
- * @param devI2C i2c channel used for communicate with the board
- * @param gpoName pin of the gpio pin of the M24SR chip
- * @param RFDisableName pin for disable the rf antenna
- * @param led1Name pin for control the led1 status
- * @param led2Name pin for control the led1 status
- * @param led3Name pin for control the led1 status
- */
- //TODO FIX all this the pin name?
- X_NUCLEO_NFC01A1(I2C &devI2C) :
- mM24SR(M24SR_ADDR, devI2C, GPO_PIN, RF_DISABLE_PIN), mNfcLed1(
- LED1_PIN), mNfcLed2(LED2_PIN), mNfcLed3(LED3_PIN) { }
-
-public:
- const static PinName DEFAULT_SDA_PIN;
- const static PinName DEFAULT_SDL_PIN;
-
- static X_NUCLEO_NFC01A1* Instance(I2C &devI2C);
-
- /**
- * @return board led1
- */
- DigitalOut& getLed1() {
- return mNfcLed1;
- }
-
- /**
- * @return board led2
- */
- DigitalOut& getLed2() {
- return mNfcLed2;
- }
-
- /**
- * @return board led3
- */
- DigitalOut& getLed3() {
- return mNfcLed3;
- }
-
- /**
- * @return NFC Chip
- */
- M24SR& getM24SR() {
- return mM24SR;
- }
-
- virtual ~X_NUCLEO_NFC01A1() {
- }
-
-private:
-
- M24SR mM24SR;
- DigitalOut mNfcLed1;
- DigitalOut mNfcLed2;
- DigitalOut mNfcLed3;
-
-};
-
-#endif /* X_NUCLEO_NFC01A1_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/X_NUCLEO_NFC01A1.lib Thu Dec 03 13:44:40 2015 +0000 @@ -0,0 +1,1 @@ +X_NUCLEO_NFC01A1#969a2be49f41
--- a/m24sr/m24sr.h Tue Dec 01 16:01:24 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,293 +0,0 @@
-/**
- ******************************************************************************
- * @file m24sr.h
- * @author MMY Application Team
- * @version V1.2.0
- * @date 20-October-2014
- * @brief This file provides a set of functions needed to manage M24SR
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
- *
- * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License");
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.st.com/software_license_agreement_liberty_v2
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- */
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __DRV_M24SR_H
-#define __DRV_M24SR_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Includes ------------------------------------------------------------------*/
-#include "Common/nfc.h"
-
-/** @addtogroup M24SR_Driver
- * @{
- */
-
-/** @addtogroup drv_M24SR
- * @{
- */
-
-/* Exported types ------------------------------------------------------------*/
-
-/**
- * @brief APDU-Header command structure
- */
-typedef struct {
- uint8_t CLA; /* Command class */
- uint8_t INS; /* Operation code */
- uint8_t P1; /* Selection Mode */
- uint8_t P2; /* Selection Option */
-} C_APDU_Header;
-
-/**
- * @brief APDU-Body command structure
- */
-typedef struct {
- uint8_t LC; /* Data field length */
- const uint8_t *pData; /* Command parameters */
- uint8_t LE; /* Expected length of data to be returned */
-} C_APDU_Body;
-
-/**
- * @brief APDU Command structure
- */
-typedef struct {
- C_APDU_Header Header;
- C_APDU_Body Body;
-} C_APDU;
-
-/**
- * @brief SC response structure
- */
-typedef struct {
- uint8_t *pData; /* Data returned from the card */ // pointer on the transceiver buffer = ReaderRecBuf[CR95HF_DATA_OFFSET ];
- uint8_t SW1; /* Command Processing status */
- uint8_t SW2; /* Command Processing qualification */
-} R_APDU;
-
-/**
- * @brief GPO mode structure
- */
-typedef enum {
- RF_GPO = 0, I2C_GPO = 1
-} M24SR_GPO_MODE;
-
-/**
- * @brief GPO state structure
- */
-typedef enum {
- HIGH_IMPEDANCE = 0,
- SESSION_OPENED,
- WIP,
- I2C_ANSWER_READY,
- INTERRUPT,
- STATE_CONTROL
-} M24SR_GPO_MGMT;
-
-typedef enum {
- M24SR_WAITINGTIME_UNKNOWN = 0,
- M24SR_WAITINGTIME_POLLING,
- M24SR_WAITINGTIME_TIMEOUT,
- M24SR_WAITINGTIME_GPO,
- M24SR_INTERRUPT_GPO
-} M24SR_WAITINGTIME_MGMT;
-
-/* Exported constants --------------------------------------------------------*/
-
-/** @defgroup lib_M24SR_Exported_Constants
- * @{
- */
-
-/* ---------------------- status code ----------------------------------------*/
-#define UB_STATUS_OFFSET 4
-#define LB_STATUS_OFFSET 3
-#define I_AM_M24SR ((uint8_t)0xB4)
-#define I_AM_M24SR_AUTOMOTIVE ((uint8_t)0xBC)
-
-#define M24SR_NBBYTE_INVALID 0xFFFE
-
-/** @defgroup drv_M24SR_File_Identifier
- * @{
- */
-#define SYSTEM_FILE_ID_BYTES {0xE1,0x01}
-#define CC_FILE_ID_BYTES {0xE1,0x03}
-#define NDEF_FILE_ID 0x0001
-/**
- * @}
- */
-
-/** @defgroup drv_M24SR_Password_Management
- * @{
- */
-#define READ_PWD 0x0001
-#define WRITE_PWD 0x0002
-#define I2C_PWD 0x0003
-
-/*-------------------------- Verify command answer ----------------------------*/
-/**
- * @}
- */
-
-/** @defgroup drv_M24SR_Command_Management
- * @{
- */
-
-/* special M24SR command ----------------------------------------------------------------------*/
-#define M24SR_OPENSESSION_COMMAND {0x26}
-#define M24SR_KILLSESSION_COMMAND {0x52}
-
-/* APDU Command: class list -------------------------------------------*/
-#define C_APDU_CLA_DEFAULT 0x00
-#define C_APDU_CLA_ST 0xA2
-
-/*------------------------ Data Area Management Commands ---------------------*/
-#define C_APDU_SELECT_FILE 0xA4
-#define C_APDU_GET_RESPONCE 0xC0
-#define C_APDU_STATUS 0xF2
-#define C_APDU_UPDATE_BINARY 0xD6
-#define C_APDU_READ_BINARY 0xB0
-#define C_APDU_WRITE_BINARY 0xD0
-#define C_APDU_UPDATE_RECORD 0xDC
-#define C_APDU_READ_RECORD 0xB2
-
-/*-------------------------- Safety Management Commands ----------------------*/
-#define C_APDU_VERIFY 0x20
-#define C_APDU_CHANGE 0x24
-#define C_APDU_DISABLE 0x26
-#define C_APDU_ENABLE 0x28
-
-/*-------------------------- Gpio Management Commands ------------------------*/
-#define C_APDU_INTERRUPT 0xD6
-
-/* Length ----------------------------------------------------------------------------------*/
-#define M24SR_STATUS_NBBYTE 2
-#define M24SR_CRC_NBBYTE 2
-#define M24SR_STATUSRESPONSE_NBBYTE 5
-#define M24SR_DESELECTREQUEST_COMMAND {0xC2,0xE0,0xB4}
-#define M24SR_DESELECTRESPONSE_NBBYTE 3
-#define M24SR_WATINGTIMEEXTRESPONSE_NBBYTE 4
-#define M24SR_PASSWORD_NBBYTE 0x10
-#define M24SR_SELECTAPPLICATION_COMMAND {0xD2,0x76,0x00,0x00,0x85,0x01,0x01}
-/* Command structure ------------------------------------------------------------------------*/
-#define M24SR_CMDSTRUCT_SELECTAPPLICATION 0x01FF
-#define M24SR_CMDSTRUCT_SELECTCCFILE 0x017F
-#define M24SR_CMDSTRUCT_SELECTNDEFFILE 0x017F
-#define M24SR_CMDSTRUCT_READBINARY 0x019F
-#define M24SR_CMDSTRUCT_UPDATEBINARY 0x017F
-#define M24SR_CMDSTRUCT_VERIFYBINARYWOPWD 0x013F
-#define M24SR_CMDSTRUCT_VERIFYBINARYWITHPWD 0x017F
-#define M24SR_CMDSTRUCT_CHANGEREFDATA 0x017F
-#define M24SR_CMDSTRUCT_ENABLEVERIFREQ 0x011F
-#define M24SR_CMDSTRUCT_DISABLEVERIFREQ 0x011F
-#define M24SR_CMDSTRUCT_SENDINTERRUPT 0x013F
-#define M24SR_CMDSTRUCT_GPOSTATE 0x017F
-
-/* Command structure Mask -------------------------------------------------------------------*/
-#define M24SR_PCB_NEEDED 0x0001 /* PCB byte present or not */
-#define M24SR_CLA_NEEDED 0x0002 /* CLA byte present or not */
-#define M24SR_INS_NEEDED 0x0004 /* Operation code present or not*/
-#define M24SR_P1_NEEDED 0x0008 /* Selection Mode present or not*/
-#define M24SR_P2_NEEDED 0x0010 /* Selection Option present or not*/
-#define M24SR_LC_NEEDED 0x0020 /* Data field length byte present or not */
-#define M24SR_DATA_NEEDED 0x0040 /* Data present or not */
-#define M24SR_LE_NEEDED 0x0080 /* Expected length present or not */
-#define M24SR_CRC_NEEDED 0x0100 /* 2 CRC bytes present or not */
-
-#define M24SR_DID_NEEDED 0x08 /* DID byte present or not */
-
-/**
- * @}
- */
-
-/* Offset ----------------------------------------------------------------------------------*/
-#define M24SR_OFFSET_PCB 0
-#define M24SR_OFFSET_CLASS 1
-#define M24SR_OFFSET_INS 2
-#define M24SR_OFFSET_P1 3
-
-/* mask ------------------------------------------------------------------------------------*/
-#define M24SR_MASK_BLOCK 0xC0
-#define M24SR_MASK_IBLOCK 0x00
-#define M24SR_MASK_RBLOCK 0x80
-#define M24SR_MASK_SBLOCK 0xC0
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/* Exported macro ------------------------------------------------------------*/
-
-/** @brief Get Most Significant Byte
- * @param val: number where MSB must be extracted
- * @retval MSB
- */
-#define GETMSB(val) ( (uint8_t) ((val & 0xFF00 )>>8) )
-
-/** @brief Get Least Significant Byte
- * @param val: number where LSB must be extracted
- * @retval LSB
- */
-#define GETLSB(val) ( (uint8_t) (val & 0x00FF ))
-
-/** @brief Used to toggle the block number by adding 0 or 1 to default block number value
- * @param val: number to know if incrementation is needed
- * @retval 0 or 1 if incrementation needed
- */
-#define TOGGLE(val) ((val != 0x00)? 0x00 : 0x01)
-
-typedef struct {
- C_APDU command;
- //static R_APDU Response;
- uint8_t dataBuffer[0xFF];
- uint8_t uM24SRbuffer[0xFF];
- uint8_t uDIDbyte;
-} M24SR_DrvDataTypeDef;
-
-extern NFC_StatusTypeDef M24SR_IO_Init(void *handle);
-extern NFC_StatusTypeDef M24SR_IO_IsAnswerReady(void *handle);
-extern NFC_StatusTypeDef M24SR_IO_SendI2Ccommand(void *handle, uint8_t NbByte,
- uint8_t *pBuffer);
-extern NFC_StatusTypeDef M24SR_IO_ReceiveI2Cresponse(void *handle,
- uint8_t NbByte, uint8_t *pBuffer);
-extern NFC_StatusTypeDef M24SR_IO_PollI2C(void *handle);
-extern void M24SR_IO_GPO_ReadPin(void *handle, GPIO_PinState *pPinState);
-extern void M24SR_IO_RFDIS_WritePin(void *handle, GPIO_PinState PinState);
-extern void M24SR_IO_SetI2CSynchroMode(void *handle,
- M24SR_WAITINGTIME_MGMT mode);
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __DRV_M24SR_H */
-
-/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
--- a/m24sr/m24sr_class.cpp Tue Dec 01 16:01:24 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1235 +0,0 @@
-/**
- ******************************************************************************
- * @file m24sr_class.cpp
- * @author MMY Application Team
- * @version V1.2.0
- * @date 20-October-2014
- * @brief This file provides a set of functions to interface with the M24SR
- * device.
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT(c) 2014 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.
- *
- ******************************************************************************
- */
-
-
-
-/* Includes ------------------------------------------------------------------*/
-#include "m24sr_class.h"
-#include "m24sr.h"
-
-/**
- * default password, it is used also for reach the super user mode throught 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 };
-
-/** @addtogroup M24SR_Driver
- * @{
- * @brief <b>This folder contains the driver layer of M24SR family (M24SR64, M24SR16, M24SR04, M24SR02)</b>
- */
-
-/** @defgroup drv_M24SR
- * @{
- * @brief This file contains the driver which implements all the M24SR commands.
- */
-
-#ifndef errchk
-
-/** value return by the NFC chip when a command is successfully done */
-#define NFC_COMMAND_SUCCESS 0x9000
-
-/** call the fCall funtion and check that the return status is NFC_COMMAND_SUCCESS,
- * otherwise return the error status*/
-#define errchk(fCall) {\
- const NFC_StatusTypeDef status = (fCall); \
- if((status!=NFC_SUCCESS)) \
- return status; \
- }\
-
-#endif
-
-/**
- * @brief This function updates the CRC
- * @param None
- * @retval None
- */
-uint16_t M24SR_UpdateCrc(uint8_t ch, uint16_t *lpwCrc) {
- ch = (ch ^ (uint8_t) ((*lpwCrc) & 0x00FF));
- ch = (ch ^ (ch << 4));
- *lpwCrc = (*lpwCrc >> 8) ^ ((uint16_t) ch << 8) ^ ((uint16_t) ch << 3)
- ^ ((uint16_t) ch >> 4);
-
- return (*lpwCrc);
-}
-
-/**
- * @brief This function returns the CRC 16
- * @param Data : pointer on the data used to compute the CRC16
- * @param Length : number of byte of the data
- * @retval CRC16
- */
-uint16_t M24SR_ComputeCrc(uint8_t *Data, uint8_t Length) {
- uint8_t chBlock;
- uint16_t wCrc = 0x6363; // ITU-V.41
-
- do {
- chBlock = *Data++;
- M24SR_UpdateCrc(chBlock, &wCrc);
- } while (--Length);
-
- return wCrc;
-}
-
-/**
- * @brief This function computes the CRC16 residue as defined by CRC ISO/IEC 13239
- * @param DataIn : input to data
- * @param Length : Number of bits of DataIn
- * @retval Status (SW1&SW2) : CRC16 residue is correct
- * @retval M24SR_ERROR_CRC : CRC16 residue is false
- */
-NFC_StatusTypeDef M24SR_IsCorrectCRC16Residue(uint8_t *DataIn, uint8_t Length) {
- uint16_t ResCRC = 0x0000;
-
- /* check the CRC16 Residue */
- if (Length != 0)
- ResCRC = M24SR_ComputeCrc(DataIn, Length);
-
- if (ResCRC == 0x0000) {
- /* Good CRC, but error status from M24SR */
- return (NFC_StatusTypeDef) (((DataIn[Length - UB_STATUS_OFFSET] << 8)
- & 0xFF00) | (DataIn[Length - LB_STATUS_OFFSET] & 0x00FF));
- } else {
- ResCRC = 0x0000;
- ResCRC = M24SR_ComputeCrc(DataIn, 5);
- if (ResCRC != 0x0000) {
- /* Bad CRC */
- return NFC_IO_ERROR_CRC;
- } else {
- /* Good CRC, but error status from M24SR */
- return (NFC_StatusTypeDef) (((DataIn[1] << 8) & 0xFF00)
- | (DataIn[2] & 0x00FF));
- }
- }
-}
-
-/**
- * @brief This functions creates an I block command according to the structures CommandStructure and data->command.
- * @param Command : structue which contains the field of the different parameter
- * @param CommandStructure : structure that contain the structure of the command (if the different field are presnet or not
- * @param NbByte : number of byte of the command
- * @param pCommand : pointer of the command created
- */
-void M24SR_BuildIBlockCommand(uint16_t CommandStructure, C_APDU *Command,
- uint8_t uDIDbyte, uint16_t *NbByte, uint8_t *pCommand) {
- uint16_t uCRC16;
- static uint8_t BlockNumber = 0x01;
-
- (*NbByte) = 0;
-
- /* add the PCD byte */
- if ((CommandStructure & M24SR_PCB_NEEDED) != 0) {
- /* toggle the block number */
- BlockNumber = TOGGLE(BlockNumber);
- /* Add the I block byte */
- pCommand[(*NbByte)++] = 0x02 | BlockNumber;
- }
-
- /* add the DID byte */
- if ((BlockNumber & M24SR_DID_NEEDED) != 0) {
- /* Add the I block byte */
- pCommand[(*NbByte)++] = uDIDbyte;
- }
-
- /* add the Class byte */
- if ((CommandStructure & M24SR_CLA_NEEDED) != 0) {
- pCommand[(*NbByte)++] = Command->Header.CLA;
- }
- /* add the instruction byte byte */
- if ((CommandStructure & M24SR_INS_NEEDED) != 0) {
- pCommand[(*NbByte)++] = Command->Header.INS;
- }
- /* add the Selection Mode byte */
- if ((CommandStructure & M24SR_P1_NEEDED) != 0) {
- pCommand[(*NbByte)++] = Command->Header.P1;
- }
- /* add the Selection Mode byte */
- if ((CommandStructure & M24SR_P2_NEEDED) != 0) {
- pCommand[(*NbByte)++] = Command->Header.P2;
- }
- /* add Data field lengthbyte */
- if ((CommandStructure & M24SR_LC_NEEDED) != 0) {
- pCommand[(*NbByte)++] = Command->Body.LC;
- }
- /* add Data field */
- if ((CommandStructure & M24SR_DATA_NEEDED) != 0) {
- memcpy(&(pCommand[(*NbByte)]), Command->Body.pData, Command->Body.LC);
- (*NbByte) += Command->Body.LC;
- }
- /* add Le field */
- if ((CommandStructure & M24SR_LE_NEEDED) != 0) {
- pCommand[(*NbByte)++] = Command->Body.LE;
- }
- /* add CRC field */
- if ((CommandStructure & M24SR_CRC_NEEDED) != 0) {
- uCRC16 = M24SR_ComputeCrc(pCommand, (uint8_t) (*NbByte));
- /* append the CRC16 */
- pCommand[(*NbByte)++] = GETLSB(uCRC16);
- pCommand[(*NbByte)++] = GETMSB(uCRC16);
- }
-
-}
-
-#if 0
-/**
- * @brief This function return M24SR_STATUS_SUCCESS if the pBuffer is an I-block
- * @param pBuffer : pointer of the data
- * @retval M24SR_STATUS_SUCCESS : the data is a I-Block
- * @retval M24SR_ERROR_DEFAULT : the data is not a I-Block
- */
-static int8_t IsIBlock (uint8_t *pBuffer)
-{
-
- if ((pBuffer[M24SR_OFFSET_PCB] & M24SR_MASK_BLOCK) == M24SR_MASK_IBLOCK)
- {
- return M24SR_STATUS_SUCCESS;
- }
- else
- {
- return M24SR_ERROR_DEFAULT;
- }
-
-}
-
-/**
- * @brief This function return M24SR_STATUS_SUCCESS if the pBuffer is an R-block
- * @param pBuffer : pointer of the data
- * @retval M24SR_STATUS_SUCCESS : the data is a R-Block
- * @retval M24SR_ERROR_DEFAULT : the data is not a R-Block
- */
-static int8_t IsRBlock (uint8_t *pBuffer)
-{
-
- if ((pBuffer[M24SR_OFFSET_PCB] & M24SR_MASK_BLOCK) == M24SR_MASK_RBLOCK)
- {
- return M24SR_STATUS_SUCCESS;
- }
- else
- {
- return M24SR_ERROR_DEFAULT;
- }
-
-}
-#endif
-
-/**
- * @brief This function return M24SR_STATUS_SUCCESS if the pBuffer is an s-block
- * @param pBuffer : pointer of the data
- * @retval M24SR_STATUS_SUCCESS : the data is a S-Block
- * @retval M24SR_ERROR_DEFAULT : the data is not a S-Block
- */
-static NFC_StatusTypeDef IsSBlock(uint8_t *pBuffer) {
-
- if ((pBuffer[M24SR_OFFSET_PCB] & M24SR_MASK_BLOCK) == M24SR_MASK_SBLOCK) {
- return NFC_SUCCESS;
- } else {
- return NFC_ERROR;
- }
-
-}
-
-/**
- * @brief This function sends the FWT extension command (S-Block format)
- * @param FWTbyte : FWT value
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- */
-NFC_StatusTypeDef M24SR::M24SR_FWTExtension(uint8_t FWTbyte) {
- uint8_t pBuffer[M24SR_STATUSRESPONSE_NBBYTE];
- NFC_StatusTypeDef status;
- uint8_t NthByte = 0;
- uint16_t uCRC16;
-
- /* create the response */
- pBuffer[NthByte++] = 0xF2;
- pBuffer[NthByte++] = FWTbyte;
- /* compute the CRC */
- uCRC16 = M24SR_ComputeCrc(pBuffer, 0x02);
- /* append the CRC16 */
- pBuffer[NthByte++] = GETLSB(uCRC16);
- pBuffer[NthByte++] = GETMSB(uCRC16);
-
- /* send the request */
- errchk(M24SR_IO_SendI2Ccommand(NthByte, pBuffer));
- errchk(M24SR_IO_IsAnswerReady());
- /* read the response */
- errchk(
- M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , pBuffer ));
-
- status = M24SR_IsCorrectCRC16Residue(pBuffer, M24SR_STATUSRESPONSE_NBBYTE);
-
- if(status == NFC_COMMAND_SUCCESS)
- return NFC_SUCCESS;
- else
- return status;
-}
-
-/**
- * @brief This function sends the KillSession command to the M24SR device
- * @param None
- * @retval NFC_SUCCESS : the function is successful.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- */
-NFC_StatusTypeDef M24SR::M24SR_KillSession(void) {
- uint8_t commandBuffer[] = M24SR_KILLSESSION_COMMAND;
-
- errchk(M24SR_IO_SendI2Ccommand(sizeof(commandBuffer), commandBuffer));
-
- /* Insure no access will be done just after open session */
- /* The only way here is to poll I2C to know when M24SR is ready */
- /* GPO can not be use with KillSession command */
- errchk(M24SR_IO_PollI2C());
-
- return NFC_SUCCESS;
-}
-
-/**
- * @brief This function sends the Deselect command (S-Block format)
- * @retval NFC_SUCCESS : the function is successful.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- */
-NFC_StatusTypeDef M24SR::M24SR_Deselect(void) {
- uint8_t pBuffer[] = M24SR_DESELECTREQUEST_COMMAND;
-
- /* send the request */
- errchk(M24SR_IO_SendI2Ccommand(sizeof(pBuffer), pBuffer));
-
- errchk(M24SR_IO_IsAnswerReady());
- /* flush the M24SR buffer */
- errchk(M24SR_IO_ReceiveI2Cresponse(sizeof(pBuffer), pBuffer));
-
- return NFC_SUCCESS;
-}
-
-/**
- * @brief This function sends the SelectApplication command
- * @retval NFC_SUCCESS : the function is successful.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- */
-NFC_StatusTypeDef M24SR::M24SR_SelectApplication(void) {
-
- C_APDU command;
- uint8_t *pBuffer = uM24SRbuffer;
- uint8_t pDataIn[M24SR_STATUSRESPONSE_NBBYTE];
- uint8_t pDataOut[] = M24SR_SELECTAPPLICATION_COMMAND;
- uint8_t uLe = 0x00;
- NFC_StatusTypeDef status;
- uint16_t uP1P2 =0x0400,
- NbByte;
-
- /* build the command */
- command.Header.CLA = C_APDU_CLA_DEFAULT;
- command.Header.INS = C_APDU_SELECT_FILE;
- /* copy the offset */
- command.Header.P1 = GETMSB(uP1P2);
- command.Header.P2 = GETLSB(uP1P2);
- /* copy the number of byte of the data field */
- command.Body.LC = sizeof(pDataOut);
- /* copy the data */
- command.Body.pData = pDataOut;
- /* copy the number of byte to read */
- command.Body.LE = uLe;
- /* build the I²C command */
- M24SR_BuildIBlockCommand( M24SR_CMDSTRUCT_SELECTAPPLICATION, &command,
- uDIDbyte, &NbByte, pBuffer);
-
- /* send the request */
- errchk(M24SR_IO_SendI2Ccommand(NbByte, pBuffer));
- errchk(M24SR_IO_IsAnswerReady());
- /* read the response */
- errchk(M24SR_IO_ReceiveI2Cresponse(sizeof(pDataIn), pDataIn));
-
- status= M24SR_IsCorrectCRC16Residue(pDataIn, sizeof(pDataIn));
-
- if(status == NFC_COMMAND_SUCCESS)
- return NFC_SUCCESS;
- else
- return status;
-
-}
-
-/**
- * @brief This function initialize the M24SR device
- * @retval None
- */
-NFC_StatusTypeDef M24SR::M24SR_Init(NFC_InitTypeDef *notUsed) {
- (void) notUsed;
-
- errchk(M24SR_KillSession())
- errchk(M24SR_ManageI2CGPO(I2C_ANSWER_READY))
- errchk(M24SR_Deselect())
-
- return NFC_SUCCESS;
-}
-
-NFC_StatusTypeDef M24SR::M24SR_ReadID(uint8_t *nfc_id) {
- if (!nfc_id) {
- return NFC_ERROR;
- }
-
- errchk(M24SR_SelectApplication())
-
- return M24SR_ReadBinary(0x0011, 1, nfc_id);
-}
-
-/**
- * @brief This function sends the GetSession command to the M24SR device
- * @retval NFC_SUCCESS : the function is successful.
- * @retval Status (SW1&SW2) : if operation does not complete.
- */
-NFC_StatusTypeDef M24SR::M24SR_GetSession(void) {
- uint8_t commandBuffer[] = M24SR_OPENSESSION_COMMAND;
-
- errchk(M24SR_IO_SendI2Ccommand(sizeof(commandBuffer), commandBuffer));
-
- /* Insure no access will be done just after open session */
- /* The only way here is to poll I2C to know when M24SR is ready */
- /* GPO can not be use with GetSession command */
- errchk(M24SR_IO_PollI2C());
-
- return NFC_SUCCESS;
-
-}
-
-/**
- * @brief This function sends the SelectCCFile command
- * @retval NFC_SUCCESS : the function is successful.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- * @retval Status (SW1&SW2) : if operation does not complete for another reason.
- */
-NFC_StatusTypeDef M24SR::M24SR_SelectCCfile(void) {
- C_APDU command;
-
- uint8_t *pBuffer = uM24SRbuffer;
- uint8_t pDataIn[M24SR_STATUSRESPONSE_NBBYTE];
- uint8_t pDataOut[] = CC_FILE_ID_BYTES;
- NFC_StatusTypeDef status;
- uint16_t uP1P2 =0x000C,
- NbByte;
-
- /* build the command */
- command.Header.CLA = C_APDU_CLA_DEFAULT;
- command.Header.INS = C_APDU_SELECT_FILE;
- /* copy the offset */
- command.Header.P1 = GETMSB(uP1P2);
- command.Header.P2 = GETLSB(uP1P2);
- /* copy the number of byte of the data field */
- command.Body.LC = sizeof(pDataOut);
- command.Body.pData = pDataOut;
- /* build the I²C command */
- M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_SELECTCCFILE, &command, uDIDbyte,
- &NbByte, pBuffer);
-
- /* send the request */
- errchk(M24SR_IO_SendI2Ccommand(NbByte, pBuffer));
- errchk(M24SR_IO_IsAnswerReady());
- /* read the response */
- errchk(M24SR_IO_ReceiveI2Cresponse(sizeof(pDataIn), pDataIn));
-
- status = M24SR_IsCorrectCRC16Residue(pDataIn, sizeof(pDataIn));
-
- if(status == NFC_COMMAND_SUCCESS)
- return NFC_SUCCESS;
- else
- return status;
-}
-
-/**
- * @brief This function sends the SelectSystemFile command
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- */
-NFC_StatusTypeDef M24SR::M24SR_SelectSystemfile(void) {
- C_APDU command;
-
- uint8_t *pBuffer = uM24SRbuffer;
- uint8_t pDataIn[M24SR_STATUSRESPONSE_NBBYTE];
- uint8_t pDataOut[] = SYSTEM_FILE_ID_BYTES;
- NFC_StatusTypeDef status;
- uint16_t uP1P2 =0x000C,
- NbByte;
-
- /* build the command */
- command.Header.CLA = C_APDU_CLA_DEFAULT;
- command.Header.INS = C_APDU_SELECT_FILE;
- /* copy the offset */
- command.Header.P1 = GETMSB(uP1P2);
- command.Header.P2 = GETLSB(uP1P2);
- /* copy the number of byte of the data field */
- command.Body.LC = sizeof(pDataOut);
- command.Body.pData = pDataOut;
- /* build the I²C command */
- M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_SELECTCCFILE, &command, uDIDbyte,
- &NbByte, pBuffer);
-
- /* send the request */
- errchk(M24SR_IO_SendI2Ccommand(NbByte, pBuffer));
- errchk(M24SR_IO_IsAnswerReady());
- /* read the response */
- errchk(M24SR_IO_ReceiveI2Cresponse(sizeof(pDataIn), pDataIn));
-
- status = M24SR_IsCorrectCRC16Residue(pDataIn, sizeof(pDataIn));
-
- if(status == NFC_COMMAND_SUCCESS)
- return NFC_SUCCESS;
- else
- return status;
-}
-
-/**
- * @brief This function sends the SelectNDEFfile command
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- */
-NFC_StatusTypeDef M24SR::M24SR_SelectNDEFfile(uint16_t NDEFfileId) {
- C_APDU command;
- uint8_t *pBuffer = uM24SRbuffer;
- uint8_t pDataIn[M24SR_STATUSRESPONSE_NBBYTE];
- uint8_t pDataOut[] = { GETMSB(NDEFfileId), GETLSB(NDEFfileId) };
- NFC_StatusTypeDef status;
- uint16_t uP1P2 = 0x000C, NbByte;
-
- /* build the command */
- command.Header.CLA = C_APDU_CLA_DEFAULT;
- command.Header.INS = C_APDU_SELECT_FILE;
- /* copy the offset */
- command.Header.P1 = GETMSB(uP1P2);
- command.Header.P2 = GETLSB(uP1P2);
- /* copy the number of byte of the data field */
- command.Body.LC = sizeof(pDataOut);
- command.Body.pData = pDataOut;
- /* copy the offset */
- /* build the I²C command */
- M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_SELECTNDEFFILE, &command, uDIDbyte,
- &NbByte, pBuffer);
-
- /* send the request */
- errchk(M24SR_IO_SendI2Ccommand(NbByte, pBuffer));
- errchk(M24SR_IO_IsAnswerReady());
- /* read the response */
- errchk(M24SR_IO_ReceiveI2Cresponse(sizeof(pDataIn), pDataIn));
-
- status = M24SR_IsCorrectCRC16Residue(pDataIn, sizeof(pDataIn));
- if(status == NFC_COMMAND_SUCCESS)
- return NFC_SUCCESS;
- else
- return status;
-
-}
-
-/**
- * @brief This function sends a read binary command
- * @param Offset : first byte to read
- * @param NbByteToRead : number of byte to read
- * @param pBufferRead : pointer of the buffer read from the M24SR device
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- */
-NFC_StatusTypeDef M24SR::M24SR_ReadBinary(uint16_t Offset, uint8_t NbByteToRead,
- uint8_t *pBufferRead) {
- C_APDU command;
- uint8_t *pBuffer = uM24SRbuffer;
- NFC_StatusTypeDef status;
- uint16_t NbByte;
-
- /* build the command */
- command.Header.CLA = C_APDU_CLA_DEFAULT;
- command.Header.INS = C_APDU_READ_BINARY;
- /* copy the offset */
- command.Header.P1 = GETMSB(Offset);
- command.Header.P2 = GETLSB(Offset);
- /* copy the number of byte to read */
- command.Body.LE = NbByteToRead;
-
- M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_READBINARY, &command, uDIDbyte,
- &NbByte, pBuffer);
-
- errchk(M24SR_IO_SendI2Ccommand(NbByte, pBuffer));
- errchk(M24SR_IO_IsAnswerReady());
- errchk(
- M24SR_IO_ReceiveI2Cresponse (NbByteToRead + M24SR_STATUSRESPONSE_NBBYTE , pBuffer ));
-
- status = M24SR_IsCorrectCRC16Residue(pBuffer,
- NbByteToRead + M24SR_STATUSRESPONSE_NBBYTE);
- if(status != NFC_COMMAND_SUCCESS)
- return status;
- /* retrieve the data without SW1 & SW2 as provided as return value of the function */
- memcpy(pBufferRead, &pBuffer[1], NbByteToRead);
- return NFC_SUCCESS;
-
-}
-
-/**
- * @brief This function sends a ST read binary command (no error if access is not inside NDEF file)
- * @param Offset : first byte to read
- * @param NbByteToRead : number of byte to read
- * @param pBufferRead : pointer of the buffer read from the M24SR device
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- */
-NFC_StatusTypeDef M24SR::M24SR_STReadBinary(uint16_t Offset,
- uint8_t NbByteToRead, uint8_t *pBufferRead) {
- C_APDU command;
- uint8_t *pBuffer = uM24SRbuffer;
- NFC_StatusTypeDef status;
- uint16_t NbByte;
-
- /* build the command */
- command.Header.CLA = C_APDU_CLA_ST;
- command.Header.INS = C_APDU_READ_BINARY;
- /* copy the offset */
- command.Header.P1 = GETMSB(Offset);
- command.Header.P2 = GETLSB(Offset);
- /* copy the number of byte to read */
- command.Body.LE = NbByteToRead;
-
- M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_READBINARY, &command, uDIDbyte,
- &NbByte, pBuffer);
-
- errchk(M24SR_IO_SendI2Ccommand(NbByte, pBuffer));
- errchk(M24SR_IO_IsAnswerReady());
- errchk(
- M24SR_IO_ReceiveI2Cresponse (NbByteToRead + M24SR_STATUSRESPONSE_NBBYTE , pBuffer ));
-
- status = M24SR_IsCorrectCRC16Residue(pBuffer,
- NbByteToRead + M24SR_STATUSRESPONSE_NBBYTE);
-
- if(status != NFC_COMMAND_SUCCESS)
- return status;
- /* retrieve the data without SW1 & SW2 as provided as return value of the function */
- memcpy(pBufferRead, &pBuffer[1], NbByteToRead);
- return NFC_SUCCESS;
-}
-
-/**
- * @brief This function sends a Update binary command
- * @param Offset : first byte to read
- * @param NbByteToWrite : number of byte to write
- * @param pBufferRead : pointer of the buffer read from the M24SR device
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- */
-NFC_StatusTypeDef M24SR::M24SR_UpdateBinary(uint16_t Offset,
- uint8_t NbByteToWrite, uint8_t *pDataToWrite) {
- //TODO check the length of the data to write
- C_APDU command;
-
- uint8_t *pBuffer = uM24SRbuffer;
- NFC_StatusTypeDef status;
- uint16_t NbByte;
-
- /* build the command */
- command.Header.CLA = C_APDU_CLA_DEFAULT;
- command.Header.INS = C_APDU_UPDATE_BINARY;
- /* copy the offset */
- command.Header.P1 = GETMSB(Offset);
- command.Header.P2 = GETLSB(Offset);
- /* copy the number of byte of the data field */
- command.Body.LC = NbByteToWrite;
- command.Body.pData = pDataToWrite;
- /* copy the File Id */
- //memcpy(command.Body.pData ,pDataToWrite, NbByteToWrite );
- M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_UPDATEBINARY, &command, uDIDbyte,
- &NbByte, pBuffer);
-
- errchk(M24SR_IO_SendI2Ccommand(NbByte, pBuffer));
- errchk(M24SR_IO_IsAnswerReady());
- errchk(
- M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , pBuffer ));
- /* if the response is a Watiting frame extenstion request */
-
- if (IsSBlock(pBuffer) == NFC_SUCCESS) {
- /*check the CRC */
- status =M24SR_IsCorrectCRC16Residue(pBuffer,
- M24SR_WATINGTIMEEXTRESPONSE_NBBYTE);
- // TODO: why if we check ==NFC_Commandsuccess it fail?
- if (status != NFC_IO_ERROR_CRC) {
- /* send the FrameExension response*/
- errchk(M24SR_FWTExtension(pBuffer[M24SR_OFFSET_PCB + 1]));
- }else
- return status;
- } else {
- status = M24SR_IsCorrectCRC16Residue(pBuffer,
- M24SR_STATUSRESPONSE_NBBYTE);
- if(status!=NFC_COMMAND_SUCCESS)
- return status;
- }
-
- return NFC_SUCCESS;
-
-}
-
-/**
- * @brief This function sends the Verify command
- * @param uPwdId : PasswordId ( 0x0001 : Read NDEF pwd or 0x0002 : Write NDEF pwd or 0x0003 : I2C pwd)
- * @param NbPwdByte : Number of byte ( 0x00 or 0x10)
- * @param pPwd : pointer on the passwaord
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- */
-NFC_StatusTypeDef M24SR::M24SR_Verify(uint16_t uPwdId, uint8_t NbPwdByte,
- const uint8_t *pPwd) {
- C_APDU command;
-
- uint8_t *pBuffer = uM24SRbuffer;
- NFC_StatusTypeDef status = NFC_SUCCESS;
- uint16_t NbByte;
-
- /*check the parameters */
- if (uPwdId > 0x0003) {
- return NFC_IO_ERROR_PARAMETER;
- }
- if ((NbPwdByte != 0x00) && (NbPwdByte != 0x10)) {
- return NFC_IO_ERROR_PARAMETER;
- }
-
- /* build the command */
- command.Header.CLA = C_APDU_CLA_DEFAULT;
- command.Header.INS = C_APDU_VERIFY;
- /* copy the Password Id */
- command.Header.P1 = GETMSB(uPwdId);
- command.Header.P2 = GETLSB(uPwdId);
- /* copy the number of byte of the data field */
- command.Body.LC = NbPwdByte;
-
- if (NbPwdByte == 0x10) {
- /* copy the password */
- command.Body.pData = pPwd;
- /* build the I2C command */
- M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_VERIFYBINARYWITHPWD, &command,
- uDIDbyte, &NbByte, pBuffer);
- } else {
- command.Body.pData = NULL;
- /* build the I2C command */
- M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_VERIFYBINARYWOPWD, &command,
- uDIDbyte, &NbByte, pBuffer);
- }
-
- /* send the request */
- errchk(M24SR_IO_SendI2Ccommand(NbByte, pBuffer));
- /* wait for answer ready */
- errchk(M24SR_IO_IsAnswerReady());
- /* read the response */
- errchk(
- M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , pBuffer ));
-
- status = M24SR_IsCorrectCRC16Residue(pBuffer, M24SR_STATUSRESPONSE_NBBYTE);
- if(status == NFC_COMMAND_SUCCESS)
- return NFC_SUCCESS;
- else
- return status;
-
-}
-
-/**
- * @brief This function sends the ChangeReferenceData command
- * @param uPwdId : PasswordId ( 0x0001 : Read NDEF pwd or 0x0002 : Write NDEF pwd or 0x0003 : I2C pwd)
- * @param pPwd : pointer on the passwaord
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- */
-NFC_StatusTypeDef M24SR::M24SR_ChangeReferenceData(uint16_t uPwdId,
- uint8_t *pPwd) {
- C_APDU command;
- uint8_t *pBuffer = uM24SRbuffer;
- NFC_StatusTypeDef status;
- uint16_t NbByte;
-
- /*check the parameters */
- if (uPwdId > 0x0003) {
- return NFC_IO_ERROR_PARAMETER;
- }
-
- /* build the command */
- command.Header.CLA = C_APDU_CLA_DEFAULT;
- command.Header.INS = C_APDU_CHANGE;
- /* copy the Password Id */
- command.Header.P1 = GETMSB(uPwdId);
- command.Header.P2 = GETLSB(uPwdId);
- /* copy the number of byte of the data field */
- command.Body.LC = M24SR_PASSWORD_NBBYTE;
- /* copy the password */
- command.Body.pData = pPwd;
- /* build the I²C command */
- M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_CHANGEREFDATA, &command, uDIDbyte,
- &NbByte, pBuffer);
-
- /* send the request */
- errchk(M24SR_IO_SendI2Ccommand(NbByte, pBuffer));
- errchk(M24SR_IO_IsAnswerReady());
- /* read the response */
- errchk(
- M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , pBuffer ));
-
- status = M24SR_IsCorrectCRC16Residue(pBuffer, M24SR_STATUSRESPONSE_NBBYTE);
-
- if(status == NFC_COMMAND_SUCCESS)
- return NFC_SUCCESS;
- else
- return status;
-}
-
-/**
- * @brief This function sends the EnableVerificationRequirement command
- * @param uReadOrWrite : enable the read or write protection ( 0x0001 : Read or 0x0002 : Write )
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- */
-NFC_StatusTypeDef M24SR::M24SR_EnableVerificationRequirement(
- uint16_t uReadOrWrite) {
- C_APDU command;
- uint8_t *pBuffer = uM24SRbuffer;
- NFC_StatusTypeDef status = NFC_SUCCESS;
- uint16_t NbByte;
-
- /*check the parameters */
- if ((uReadOrWrite != 0x0001) && (uReadOrWrite != 0x0002)) {
- return NFC_IO_ERROR_PARAMETER;
- }
-
- /* build the command */
- command.Header.CLA = C_APDU_CLA_DEFAULT;
- command.Header.INS = C_APDU_ENABLE;
- /* copy the Password Id */
- command.Header.P1 = GETMSB(uReadOrWrite);
- command.Header.P2 = GETLSB(uReadOrWrite);
- /* build the I²C command */
- M24SR_BuildIBlockCommand( M24SR_CMDSTRUCT_ENABLEVERIFREQ, &command,
- uDIDbyte, &NbByte, pBuffer);
-
- /* send the request */
- errchk(M24SR_IO_SendI2Ccommand(NbByte, pBuffer));
- /* The right access to be updated in EEPROM need at least 6ms */
- errchk(M24SR_IO_IsAnswerReady());
- /* read the response */
- errchk(
- M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , pBuffer ));
-
- status = M24SR_IsCorrectCRC16Residue(pBuffer, M24SR_STATUSRESPONSE_NBBYTE);
- if(status == NFC_COMMAND_SUCCESS)
- return NFC_SUCCESS;
- else
- return status;
-}
-
-/**
- * @brief This function sends the DisableVerificationRequirement command
- * @param uReadOrWrite : enable the read or write protection ( 0x0001 : Read or 0x0002 : Write )
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- */
-NFC_StatusTypeDef M24SR::M24SR_DisableVerificationRequirement(
- uint16_t uReadOrWrite) {
- C_APDU command;
- uint8_t *pBuffer = uM24SRbuffer;
- NFC_StatusTypeDef status = NFC_SUCCESS;
- uint16_t NbByte;
-
- /*check the parameters */
- if ((uReadOrWrite != 0x0001) && (uReadOrWrite != 0x0002)) {
- return NFC_IO_ERROR_PARAMETER;
- }
-
- /* build the command */
- command.Header.CLA = C_APDU_CLA_DEFAULT;
- command.Header.INS = C_APDU_DISABLE;
- /* copy the Password Id */
- command.Header.P1 = GETMSB(uReadOrWrite);
- command.Header.P2 = GETLSB(uReadOrWrite);
- /* build the I²C command */
- M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_DISABLEVERIFREQ, &command,
- uDIDbyte, &NbByte, pBuffer);
-
- /* send the request */
- errchk(M24SR_IO_SendI2Ccommand(NbByte, pBuffer));
- /* The right access to be updated in EEPROM need at least 6ms */
- errchk(M24SR_IO_IsAnswerReady());
- /* read the response */
- errchk(
- M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , pBuffer ));
-
- status = M24SR_IsCorrectCRC16Residue(pBuffer, M24SR_STATUSRESPONSE_NBBYTE);
-
- if(status == NFC_COMMAND_SUCCESS)
- return NFC_SUCCESS;
- else
- return status;
-
-}
-
-/**
- * @brief This function sends the EnablePermananentState command
- * @param uReadOrWrite : enable the read or write protection ( 0x0001 : Read or 0x0002 : Write )
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- */
-NFC_StatusTypeDef M24SR::M24SR_EnablePermanentState(uint16_t uReadOrWrite) {
- C_APDU command;
-
- uint8_t *pBuffer = uM24SRbuffer;
- NFC_StatusTypeDef status = NFC_SUCCESS;
- uint16_t NbByte;
-
- /*check the parameters */
- if ((uReadOrWrite != 0x0001) && (uReadOrWrite != 0x0002)) {
- return NFC_IO_ERROR_PARAMETER;
- }
-
- /* build the command */
- command.Header.CLA = C_APDU_CLA_ST;
- command.Header.INS = C_APDU_ENABLE;
- /* copy the Password Id */
- command.Header.P1 = GETMSB(uReadOrWrite);
- command.Header.P2 = GETLSB(uReadOrWrite);
- /* build the I²C command */
- M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_ENABLEVERIFREQ, &command, uDIDbyte,
- &NbByte, pBuffer);
-
- /* send the request */
- errchk(M24SR_IO_SendI2Ccommand(NbByte, pBuffer));
- errchk(M24SR_IO_IsAnswerReady());
- /* read the response */
- errchk(
- M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , pBuffer ));
-
- status = M24SR_IsCorrectCRC16Residue(pBuffer, M24SR_STATUSRESPONSE_NBBYTE);
- if(status == NFC_COMMAND_SUCCESS)
- return NFC_SUCCESS;
- else
- return status;
-}
-
-/**
- * @brief This function sends the DisablePermanentState command
- * @param uReadOrWrite : enable the read or write protection ( 0x0001 : Read or 0x0002 : Write )
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- */
-NFC_StatusTypeDef M24SR::M24SR_DisablePermanentState(uint16_t uReadOrWrite) {
- C_APDU command;
-
- uint8_t *pBuffer = uM24SRbuffer;
- NFC_StatusTypeDef status = NFC_SUCCESS;
- uint16_t NbByte;
-
- /*check the parameters */
- if ((uReadOrWrite != 0x0001) && (uReadOrWrite != 0x0002)) {
- return NFC_IO_ERROR_PARAMETER;
- }
-
- /* build the command */
- command.Header.CLA = C_APDU_CLA_ST;
- command.Header.INS = C_APDU_DISABLE;
- /* copy the Password Id */
- command.Header.P1 = GETMSB(uReadOrWrite);
- command.Header.P2 = GETLSB(uReadOrWrite);
- /* build the I²C command */
- M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_DISABLEVERIFREQ, &command,
- uDIDbyte, &NbByte, pBuffer);
-
- /* send the request */
- errchk(M24SR_IO_SendI2Ccommand(NbByte, pBuffer));
- errchk(M24SR_IO_IsAnswerReady());
- /* read the response */
- errchk(
- M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , pBuffer ));
-
- status = M24SR_IsCorrectCRC16Residue(pBuffer, M24SR_STATUSRESPONSE_NBBYTE);
-
- if(status == NFC_COMMAND_SUCCESS)
- return NFC_SUCCESS;
- else
- return status;
-}
-
-/**
- * @brief This function generates a interrupt on GPO pin
- * @param None
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- */
-NFC_StatusTypeDef M24SR::M24SR_SendInterrupt(void) {
- C_APDU command;
-
- uint8_t *pBuffer = uM24SRbuffer;
- uint16_t uP1P2 = 0x001E;
- NFC_StatusTypeDef status = NFC_SUCCESS;
- uint16_t NbByte;
-
- status = M24SR_ManageI2CGPO(INTERRUPT);
-
- /* build the command */
- command.Header.CLA = C_APDU_CLA_ST;
- command.Header.INS = C_APDU_INTERRUPT;
- /* copy the Password Id */
- command.Header.P1 = GETMSB(uP1P2);
- command.Header.P2 = GETLSB(uP1P2);
- command.Body.LC = 0x00;
- /* build the I²C command */
- M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_SENDINTERRUPT, &command, uDIDbyte,
- &NbByte, pBuffer);
-
- /* send the request */
- errchk(M24SR_IO_SendI2Ccommand(NbByte, pBuffer));
- errchk(M24SR_IO_IsAnswerReady());
- /* read the response */
- errchk(
- M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , pBuffer ));
-
- status = M24SR_IsCorrectCRC16Residue(pBuffer, M24SR_STATUSRESPONSE_NBBYTE);
-
- if(status == NFC_COMMAND_SUCCESS)
- return NFC_SUCCESS;
- else
- return status;
-
-}
-
-/**
- * @brief This function force GPO pin to low state or high Z
- * @param uSetOrReset : select if GPO must be low (reset) or HiZ
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- */
-NFC_StatusTypeDef M24SR::M24SR_StateControl(uint8_t uSetOrReset) {
- C_APDU command;
- uint8_t *pBuffer = uM24SRbuffer;
- uint16_t uP1P2 = 0x001F;
- NFC_StatusTypeDef status = NFC_SUCCESS;
- uint16_t NbByte;
-
- /*check the parameters */
- if ((uSetOrReset != 0x01) && (uSetOrReset != 0x00)) {
- return NFC_IO_ERROR_PARAMETER;
- }
-
- status = M24SR_ManageI2CGPO(STATE_CONTROL);
-
- /* build the command */
- command.Header.CLA = C_APDU_CLA_ST;
- command.Header.INS = C_APDU_INTERRUPT;
- /* copy the Password Id */
- command.Header.P1 = GETMSB(uP1P2);
- command.Header.P2 = GETLSB(uP1P2);
- command.Body.LC = 0x01;
- command.Body.pData = &uSetOrReset;
- /* copy the data */
- //memcpy(command.Body.pData , &uSetOrReset, 0x01 );
- //command.Body.LE = 0x00 ;
- /* build the I²C command */
- M24SR_BuildIBlockCommand( M24SR_CMDSTRUCT_GPOSTATE, &command, uDIDbyte,
- &NbByte, pBuffer);
-
- /* send the request */
- errchk(M24SR_IO_SendI2Ccommand(NbByte, pBuffer));
- errchk(M24SR_IO_IsAnswerReady());
- /* read the response */
- errchk(
- M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , pBuffer ));
-
- status = M24SR_IsCorrectCRC16Residue(pBuffer, M24SR_STATUSRESPONSE_NBBYTE);
-
- if(status == NFC_COMMAND_SUCCESS)
- return NFC_SUCCESS;
- else
- return status;
-}
-
-/**
- * @brief This function configure GPO purpose for I2C session
- * @param GPO_I2Cconfig: GPO configuration to set
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- */
-NFC_StatusTypeDef M24SR::M24SR_ManageI2CGPO(M24SR_GPO_MGMT GPO_I2Cconfig) {
- uint8_t GPO_config = 0;
-
- if (GPO_I2Cconfig > STATE_CONTROL) {
- return NFC_IO_ERROR_PARAMETER;
- }
-
- /* we must not be in interrupt mode for I2C synchro as we will change GPO purpose */
- M24SR_IO_SetI2CSynchroMode(M24SR_WAITINGTIME_POLLING);
-
- errchk(M24SR_SelectApplication());
-
- errchk(M24SR_SelectSystemfile());
-
- errchk(M24SR_ReadBinary(0x0004, 0x01, &GPO_config))
-
- /* Update only GPO purpose for I2C */
- GPO_config = (GPO_config & 0xF0) | GPO_I2Cconfig;
-
- errchk(M24SR_Verify(I2C_PWD, 0x10, DEFAULT_PASSWORD));
-
- errchk(M24SR_UpdateBinary(0x0004, 0x01, &(GPO_config)));
-
- /* if we have set interrupt mode for I2C synchro we can enable interrupt mode */
- if (GPO_I2Cconfig == I2C_ANSWER_READY)
- M24SR_IO_SetI2CSynchroMode(M24SR_INTERRUPT_GPO);
-
- return NFC_SUCCESS;
-}
-
-/**
- * @brief This function configure GPO purpose for RF session
- *
- * @param GPO_RFconfig: GPO configuration to set
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- */
-NFC_StatusTypeDef M24SR::M24SR_ManageRFGPO(M24SR_GPO_MGMT GPO_RFconfig) {
- uint8_t GPO_config;
-
- if (GPO_RFconfig > STATE_CONTROL) {
- return NFC_IO_ERROR_PARAMETER;
- }
-
- errchk(M24SR_SelectApplication())
- errchk(M24SR_SelectSystemfile())
- errchk(M24SR_ReadBinary(0x0004, 0x01, &GPO_config))
-
- /* Update only GPO purpose for I2C */
- GPO_config = (GPO_config & 0x0F) | (GPO_RFconfig << 4);
-
- errchk(M24SR_SelectSystemfile())
- errchk(M24SR_Verify(I2C_PWD, 0x10, DEFAULT_PASSWORD))
- errchk(M24SR_UpdateBinary(0x0004, 0x01, &(GPO_config)))
-
- return NFC_SUCCESS;
-}
-
-/**
- * @brief This function enable or disable RF communication
- * @param OnOffChoice: GPO configuration to set
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- */
-NFC_StatusTypeDef M24SR::M24SR_RFConfig(uint8_t OnOffChoice) {
- /* Disable RF */
- if (OnOffChoice != 0) {
- M24SR_IO_RFDIS_WritePin(GPIO_PIN_RESET);
- } else {
- M24SR_IO_RFDIS_WritePin(GPIO_PIN_SET);
- }
- return NFC_SUCCESS;
-}
-
-NFC_StatusTypeDef M24SR::M24SR_IO_SendI2Ccommand(uint8_t NbByte,
- uint8_t *pBuffer) {
- int ret = dev_i2c.write(address, (char*) pBuffer, NbByte);
- if (ret == 0)
- return NFC_SUCCESS;
- return NFC_IO_ERROR_I2CTIMEOUT;
-}
-
-NFC_StatusTypeDef M24SR::M24SR_IO_ReceiveI2Cresponse(uint8_t NbByte,
- uint8_t *pBuffer) {
- int ret = dev_i2c.read(address, (char*) pBuffer, NbByte);
- if (ret == 0)
- return NFC_SUCCESS;
-
- return NFC_IO_ERROR_I2CTIMEOUT;
-}
-
-#define M24SR_POLL_DELAY 10
-#define M24SR_I2C_POLLING 200 /* In case M24SR will reply ACK failed allow to perform retry before returning error (HAL option not used) */
-
-NFC_StatusTypeDef M24SR::M24SR_IO_PollI2C(void) {
-
- int status = 1;
- uint32_t nbTry = 0;
- char buffer;
- //
- wait_ms(M24SR_POLL_DELAY);
- while (status != 0 && nbTry < M24SR_I2C_POLLING) {
- status = dev_i2c.read(address, &buffer, 1, false);
- nbTry++;
- }
-
- if (status == 0)
- return NFC_SUCCESS;
- //else
- return NFC_IO_ERROR_I2CTIMEOUT;
-}
-
-NFC_StatusTypeDef M24SR::M24SR_IO_IsAnswerReady(void) {
- uint32_t retry = 0xFFFFF;
- int8_t stable = 0;
- GPIO_PinState PinState;
-
- switch (syncMode) {
- case M24SR_WAITINGTIME_POLLING:
- return M24SR_IO_PollI2C();
-
- case M24SR_WAITINGTIME_TIMEOUT:
- // M24SR FWI=5 => (256*16/fc)*2^5=9.6ms but M24SR ask for extended time to program up to 246Bytes.
- // can be improved by
- wait_ms(80);
- return NFC_SUCCESS;
-
- case M24SR_WAITINGTIME_GPO:
- do {
- M24SR_IO_GPO_ReadPin(&PinState);
- if (PinState == GPIO_PIN_RESET) {
- stable++;
- }
- retry--;
- } while (stable < 5 && retry > 0);
- if (!retry)
- goto Error;
- return NFC_SUCCESS;
-
- case M24SR_INTERRUPT_GPO:
-
- /* Check if the GPIO is not already low before calling this function */
- M24SR_IO_GPO_ReadPin(&PinState);
- answerReadyInterrupt.enable_irq();
- if (PinState == GPIO_PIN_SET) {
- while (!interruptIsFired)
- __WFE();
- }
- //the interrupt is disable insde the interrupt callback
- //answerReadyInterrupt.disable_irq();
- interruptIsFired = false;
- return NFC_SUCCESS;
-
- default:
- return NFC_IO_ERROR_I2CTIMEOUT;
- }
-
- Error: return NFC_IO_ERROR_I2CTIMEOUT;
-}
-
-/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
--- a/m24sr/m24sr_class.h Tue Dec 01 16:01:24 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,335 +0,0 @@
-/**
- ******************************************************************************
- * @file m24sr_class.h
- * @author MMY Application Team
- * @version V1.2.0
- * @date 20-October-2014
- * @brief This file provides a set of functions to interface with the M24SR
- * device.
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT(c) 2014 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"
-
-/* Classes -------------------------------------------------------------------*/
-
-/** Class representing a M24SR component.
- */
-class M24SR: public Nfc {
-
-public:
-
- 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.
- */
- 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) {
-
- 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 ***/
- 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((uint16_t) pwdId,
- (uint8_t) NbPwdByte, pPwd);
- }
-
- virtual NFC_StatusTypeDef ChangeReferenceData(PasswordType_t pwdId,
- const uint8_t *pPwd) {
- return (NFC_StatusTypeDef) M24SR_ChangeReferenceData((uint16_t) pwdId,
- (uint8_t *) pPwd);
- }
-
- virtual NFC_StatusTypeDef EnableVerificationRequirement(
- PasswordType_t uReadOrWrite) {
- return (NFC_StatusTypeDef) M24SR_EnableVerificationRequirement(
- (uint16_t) uReadOrWrite);
- }
-
- virtual NFC_StatusTypeDef DisableVerificationRequirement(
- PasswordType_t uReadOrWrite) {
- return (NFC_StatusTypeDef) M24SR_DisableVerificationRequirement(
- (uint16_t) 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(
- (uint16_t) uReadOrWrite);
- }
-
- virtual NFC_StatusTypeDef DisablePermanentState(PasswordType_t uReadOrWrite) {
- return (NFC_StatusTypeDef) M24SR_DisablePermanentState(
- (uint16_t) 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);
- }
-
- /*** Public Interrupt Related Methods ***/
- virtual NFC_StatusTypeDef SendInterrupt(void) {
- return (NFC_StatusTypeDef) M24SR_SendInterrupt();
- }
-
-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);
-
-
- // platform specific IO method
- NFC_StatusTypeDef M24SR_IO_IsAnswerReady(void);
- NFC_StatusTypeDef M24SR_IO_SendI2Ccommand(uint8_t NbByte, uint8_t *pBuffer);
- NFC_StatusTypeDef M24SR_IO_ReceiveI2Cresponse(uint8_t NbByte,
- uint8_t *pBuffer);
-
- NFC_StatusTypeDef M24SR_IO_PollI2C(void);
-
- void M24SR_IO_GPO_ReadPin(GPIO_PinState *pPinState) {
- if (GPOPin == 0)
- (*pPinState) = GPIO_PIN_RESET;
- else
- (*pPinState) = GPIO_PIN_SET;
- }
-
- void M24SR_IO_RFDIS_WritePin(GPIO_PinState PinState) {
- if (PinState == GPIO_PIN_RESET)
- RFDisablePin = 0;
- else
- RFDisablePin = 1;
- }
-
- void M24SR_IO_SetI2CSynchroMode(M24SR_WAITINGTIME_MGMT mode) {
- syncMode = mode;
- }
-
- /**
- * callback trigger when the chip finish to do a command
- */
- 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 for disable the rf chip functionality
- */
- DigitalOut RFDisablePin;
-
- /**
- * pin used as interrupt
- */
- InterruptIn answerReadyInterrupt;
-
- /**
- * method used for wait the chip response
- */
- M24SR_WAITINGTIME_MGMT syncMode;
-
- /**
- * buffer used for build the command to send to the chip
- */
- uint8_t uM24SRbuffer[0xFF];
-
- /**
- * ???
- */
- uint8_t uDIDbyte;
-
- /**
- * state variable change when the interrupt is fired
- */
- volatile bool interruptIsFired;
-};
-
-#endif // __M24SR_CLASS_H
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- a/main.cpp Tue Dec 01 16:01:24 2015 +0000
+++ b/main.cpp Thu Dec 03 13:44:40 2015 +0000
@@ -1,441 +1,20 @@
-#if 0
-#include "mbed.h"
-
-#include "Type4NfcTagSTM24SR.h"
-
-#include "NDefLib/RecordType/RecordAAR.h"
-#include "NDefLib/RecordType/RecordSMS.h"
-#include "NDefLib/RecordType/RecordGeo.h"
-#include "NDefLib/RecordType/RecordURI.h"
-#include "NDefLib/RecordType/RecordMail.h"
-#include "NDefLib/RecordType/RecordText.h"
-#include "NDefLib/RecordType/RecordMimeType.h"
-#include "NDefLib/RecordType/RecordVCard.h"
-
-#include "X_NUCLEO_NFC01A1.h"
-
-Serial pc(SERIAL_TX, SERIAL_RX);
-
-DigitalOut myled(LED1);
-
-void shiftLed(DigitalOut &led1,DigitalOut &led2,DigitalOut &led3){
- const uint8_t prevLed1=led1;
- const uint8_t prevLed2=led2;
- const uint8_t prevLed3=led3;
- led1=prevLed3;
- led2=prevLed1;
- led3=prevLed2;
-}
-
-static const uint32_t MAX_WRITE_TRY=1;
-
-void setNFCTag(NDefLib::Type4NfcTag &tag){
-
- bool writeStatus,closeStatus;
- if(tag.openSession()){
- NDefLib::Message msg;
-
- NDefLib::RecordAAR rAAR("com.st.BlueMS");
- msg.addRecord(&rAAR);
-
- NDefLib::RecordSMS rSMS("123456789","st.com.BlueMS");
- msg.addRecord(&rSMS);
-
- NDefLib::RecordGeo rGeo(123.123,-456.789);
- msg.addRecord(&rGeo);
-
- NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"http://www.st.com");
- msg.addRecord(&rUri);
-
- NDefLib::RecordMail rMail("mail@st.com","ciao","da nfc tag");
- msg.addRecord(&rMail);
-
- NDefLib::RecordMimeType rText1("text/plain",(const uint8_t*)"ciao",4);
- msg.addRecord(&rText1);
-
- NDefLib::RecordText rText3(NDefLib::RecordText::UTF8,"it","ciao");
- msg.addRecord(&rText3);
-
- NDefLib::RecordVCard::VCardInfo_t cardInfo;
- cardInfo[NDefLib::RecordVCard::FORMATTED_NAME]="prova prova1";
- cardInfo[NDefLib::RecordVCard::ADDRESS_HOME]=";;1 Main St.;Springfield;IL;12345;USA";
- cardInfo[NDefLib::RecordVCard::ADDRESS_WORK]=";;2 Main St.;Springfield;IL;12345;USA";
- cardInfo[NDefLib::RecordVCard::EMAIL_WORK]="workmail@st.com";
- cardInfo[NDefLib::RecordVCard::EMAIL_HOME]="homemail@st.com";
- cardInfo[NDefLib::RecordVCard::GEO]="39.95;-75.1667";
- cardInfo[NDefLib::RecordVCard::IMPP]="aim:johndoe@aol.com";
- cardInfo[NDefLib::RecordVCard::NAME]="prova2;prova3";
- cardInfo[NDefLib::RecordVCard::NICKNAME]="test";
- cardInfo[NDefLib::RecordVCard::NOTE]="A good test";
- cardInfo[NDefLib::RecordVCard::ORGANIZATION]="STM";
- cardInfo[NDefLib::RecordVCard::TEL_HOME]="123";
- cardInfo[NDefLib::RecordVCard::TEL_MOBILE]="456";
- cardInfo[NDefLib::RecordVCard::TEL_WORK]="789";
- cardInfo[NDefLib::RecordVCard::TITLE]="King";
- cardInfo[NDefLib::RecordVCard::URL]="www.st.com";
- cardInfo[NDefLib::RecordVCard::PHOTO_URI]="http://www.st.com/st-web-ui/static/active/en/fragment/multimedia/image/picture/customer_focus.jpg";
- NDefLib::RecordVCard rVCard(cardInfo);
- msg.addRecord(&rVCard);
-
- uint32_t writeTry=0;
- do{
- writeStatus = tag.write(msg);
- writeTry++;
- }while(!writeStatus && writeTry<MAX_WRITE_TRY);
-
- closeStatus = tag.closeSession();
-
- }else
- pc.printf("Error open Session\n\r");
-
- if(writeStatus)
- pc.printf("writeOk\n\r");
- else
- pc.printf("writeFail\n\r");
-
- if(closeStatus)
- pc.printf("closeOk\n\r");
- else
- pc.printf("CloseFail\n\r");
-
-/*
- sURI_Info URI;
- sAARInfo aar;
- sSMSInfo sms;
- std::strcpy(sms.PhoneNumber,"123456789\0");
- std::strcpy(sms.Message,"st.com.BlueMS\0");
- std::strcpy(sms.Information,"\0");
-
- std::strcpy(aar.PakageName,"st.com.BlueMS");
-
- // Prepare URI NDEF message content
- std::strcpy(URI.protocol,URI_ID_0x01_STRING);
- std::strcpy(URI.URI_Message,"st3.com");
- std::strcpy(URI.Information,"\0");
-
-
- while (TT4_Init() != NFC_OK);
- // Prepare URI NDEF message content
- std::strcpy(URI.protocol,URI_ID_0x01_STRING);
- std::strcpy(URI.URI_Message,"st2.com");
- std::strcpy(URI.Information,"\0");
- //while (TT4_WriteURI(&URI) != NFC_OK);
- while (TT4_WriteSMS(&sms) != NFC_OK);
- //while (TT4_Write(&sms) != NFC_OK);
-*/
-}
-
-void printRecord(NDefLib::Record *r){
- using namespace NDefLib;
- switch(r->getType()){
- case Record::TYPE_TEXT: {
- RecordText *temp = (RecordText*)r;
- pc.printf("Read Text: %s\r\n",temp->getText().c_str());
- break; }
- case Record::TYPE_AAR:{
- RecordAAR *temp = (RecordAAR*)r;
- pc.printf("Read ARR: %s\r\n",temp->getPackage().c_str());
- break; }
- case Record::TYPE_MIME:{
- RecordMimeType *temp = (RecordMimeType*)r;
- pc.printf("Read mimeType: %s\r\n",temp->getMimeType().c_str());
- pc.printf("Read mimeData: %s\r\n",
- std::string((const char*)temp->getMimeData(),
- temp->getMimeDataLenght()).c_str());
- break;}
- case Record::TYPE_URI:{
- RecordURI *temp = (RecordURI*)r;
- pc.printf("Read uriId: %d\r\n",temp->getUriId());
- pc.printf("Read uriType: %s\r\n",temp->getUriType().c_str());
- pc.printf("Read uriContent: %s\r\n",temp->getContent().c_str());
- break;}
- case Record::TYPE_URI_MAIL:{
- RecordMail *temp = (RecordMail*)r;
- pc.printf("Read Dest: %s\r\n",temp->getToAddress().c_str());
- pc.printf("Read Subject: %s\r\n",temp->getSubject().c_str());
- pc.printf("Read Body: %s\r\n",temp->getBody().c_str());
- break;}
- case Record::TYPE_URI_SMS:{
- RecordSMS *temp = (RecordSMS*)r;
- pc.printf("Read number: %s\r\n",temp->getNumber().c_str());
- pc.printf("Read message: %s\r\n",temp->getMessagge().c_str());
- break;}
- case Record::TYPE_URI_GEOLOCATION:{
- RecordGeo *temp = (RecordGeo*)r;
- pc.printf("Read lat: %f\r\n",temp->getLatitude());
- pc.printf("Read long: %f\r\n",temp->getLongitude());
- break;}
- case Record::TYPE_MIME_VCARD:{
- const RecordVCard *temp = (RecordVCard*)r;
- pc.printf("Read Name: %s\r\n",(*temp)[RecordVCard::NAME].c_str());
- pc.printf("Read Mail: %s\r\n",(*temp)[RecordVCard::EMAIL_WORK].c_str());
- pc.printf("Read ORG: %s\r\n",(*temp)[RecordVCard::ORGANIZATION].c_str());
- break;}
- case Record::TYPE_UNKNOWN:{
- pc.printf("Unknown record\r\n");
- break;}
- }//switch
-}
+#include "Samples/Samples.h"
+
+ //#define SAMPLE_WRITE_URL
+//#define SAMPLE_COUNT_CLICK
+#define SAMPLE_WRITE_AND_CHANGE_ALL
+
+int main(void)
+{
+#ifdef SAMPLE_WRITE_URL
+ sample_writeUrl();
+#endif /* SAMPLE_WRITE_URL */
-void changeRecord(NDefLib::Record *r){
- using namespace NDefLib;
- switch(r->getType()){
- case Record::TYPE_TEXT: {
- RecordText *temp = (RecordText*)r;
- temp->setText("CIAOCiao");
- break; }
- case Record::TYPE_AAR:{
- RecordAAR *temp = (RecordAAR*)r;
- temp->setPackage("set Package Ok");
- break; }
- case Record::TYPE_MIME:{
- RecordMimeType *temp = (RecordMimeType*)r;
- temp->copyMimeData((const uint8_t *)"String2",sizeof("String2"));
- break;}
- case Record::TYPE_URI:{
- RecordURI *temp = (RecordURI*)r;
- temp->setContent("google.it");
- break;}
- case Record::TYPE_URI_MAIL:{
- RecordMail *temp = (RecordMail*)r;
- temp->setToAddress("newMail@st.com");
- temp->setSubject("tag change");
- temp->setBody("read/change Works!");
- break;}
- case Record::TYPE_URI_SMS:{
- RecordSMS *temp = (RecordSMS*)r;
- temp->setMessage("Message Change");
- temp->setNumber("0987654321");
- break;}
- case Record::TYPE_URI_GEOLOCATION:{
- RecordGeo *temp = (RecordGeo*)r;
- temp->setLatitude(-temp->getLatitude());
- temp->setLongitude(-temp->getLongitude());
- break;}
- case Record::TYPE_MIME_VCARD:{
- RecordVCard *temp = (RecordVCard*)r;
- (*temp)[RecordVCard::NAME]="name change";
- (*temp)[RecordVCard::NICKNAME]="nic change";
- break;}
- case Record::TYPE_UNKNOWN:{
- pc.printf("Unknown record\r\n");
- break;}
- }//switch
-}
-
-void readNfcTag(NDefLib::Type4NfcTag &tag){
- using namespace NDefLib;
-
- if(tag.openSession()){
- NDefLib::Message readMsg;
-
- tag.read(&readMsg);
-
- if(readMsg.getNRecords()==0){
- pc.printf("Error Read\r\n");
- }else{
- for(uint32_t i=0;i<readMsg.getNRecords();i++){
- Record *r = readMsg[i];
- printRecord(r);
- delete r;
- }//for
- }//if-else
-
- tag.closeSession();
- }else{
- pc.printf("Error open Session2\n\r");
- }
-}
-
-
-void changeNfcTag(NDefLib::Type4NfcTag &tag){
- using namespace NDefLib;
-
- if(tag.openSession()){
- NDefLib::Message readMsg;
-
- tag.read(&readMsg);
-
- if(readMsg.getNRecords()==0){
- pc.printf("Error Read\r\n");
- }else{
- for(uint32_t i=0;i<readMsg.getNRecords();i++){
- Record *r = readMsg[i];
- changeRecord(r);
- }//for
- tag.write(readMsg);
- }//if-else
-
- tag.closeSession();
- }else{
- pc.printf("Error open SessionChange\n\r");
- }
-}
-
-static bool buttonPress=false;
-void setButtonPress(){
- buttonPress=true;
-}
-
-int main() {
- I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
- i2cChannel.frequency(400000);
- X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
- Type4NfcTagSTM24SR tag(nfcNucleo->getM24SR());
- InterruptIn mybutton(USER_BUTTON);
- pc.printf("Hello World !\n\r");
- nfcNucleo->getLed1()=1;
- nfcNucleo->getLed2()=0;
- nfcNucleo->getLed3()=0;
-
- setNFCTag(tag);
- readNfcTag(tag);
-
- mybutton.fall(setButtonPress);
-
- while(1) {
- wait(1);
- myled = !myled;
- shiftLed(nfcNucleo->getLed1(),nfcNucleo->getLed2(),nfcNucleo->getLed3());
- if(buttonPress){
- changeNfcTag(tag);
- readNfcTag(tag);
- buttonPress=false;
- }
- }
-
-}
-#endif
+#ifdef SAMPLE_COUNT_CLICK
+ sample_countClick();
+#endif /* SAMPLE_COUNT_CLICK */
-#if 0
-#include "mbed.h"
-
-#include "Type4NfcTagSTM24SR.h"
-#include "NDefLib/RecordType/RecordURI.h"
-
-#include "X_NUCLEO_NFC01A1.h"
-
-int main() {
- Serial pc(SERIAL_TX, SERIAL_RX);
- I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
- i2cChannel.frequency(400000);
- X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
- //create the wrapper for use the NdefLib
- Type4NfcTagSTM24SR tag(nfcNucleo->getM24SR());
- pc.printf("System Init done: !\n\r");
- //open the i2c session with the nfc chip
- if(tag.openSession()){
- nfcNucleo->getLed1()=1;
-
- //create the NDef message and record
- NDefLib::Message msg;
- NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"st.com");
- msg.addRecord(&rUri);
-
- //write the tag
- if(tag.write(msg)){
- pc.printf("Tag writed \n\r");
- nfcNucleo->getLed2()=1;
- }
-
-
- //close the i2c session
- if(!tag.closeSession()){
- pc.printf("Error Closing the session\n\r");
- }else
- nfcNucleo->getLed3()=1;
- }else
- pc.printf("Error open Session\n\r");
-
- return 0;
-}
-
-#endif
-
-#if 1
-
-#include "mbed.h"
-
-#include "Type4NfcTagSTM24SR.h"
-#include "NDefLib/RecordType/RecordText.h"
-
-#include "X_NUCLEO_NFC01A1.h"
-
-class MyRecord : public NDefLib::RecordText{
-
-private:
- char nClickStringBuffer[12];
- uint32_t nClick;
-
- void syncTextValue(){
- sprintf(nClickStringBuffer,"%d",nClick);
- setText(nClickStringBuffer);
- }
-
-public:
-
- MyRecord():nClick(0){
- syncTextValue();
- }
-
- void incrementClick(){
- nClick++;
- syncTextValue();
- }
-
-};
-
-static volatile bool buttonPress=false;
-
-void setButtonPress(){
- buttonPress=true;
-}//if buttonPress
-
-void writeMessage(X_NUCLEO_NFC01A1 *nfcNucleo,NDefLib::Message &msg){
- Type4NfcTagSTM24SR tag(nfcNucleo->getM24SR());
- //open the i2c session with the nfc chip
- if(tag.openSession()){
- nfcNucleo->getLed1()=! nfcNucleo->getLed1();
-
- //write the tag
- if(tag.write(msg)){
- nfcNucleo->getLed2()=!nfcNucleo->getLed2();
- }//if
-
- //close the i2c session
- if(tag.closeSession())
- nfcNucleo->getLed3()=!nfcNucleo->getLed3();
- }//if open session
-}
-
-void main() {
- I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
- i2cChannel.frequency(400000);
-
- X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
- //create the wrapper for use the NdefLib
- Type4NfcTagSTM24SR tag(nfcNucleo->getM24SR());
-
- InterruptIn userButton(USER_BUTTON);
- userButton.fall(setButtonPress);
-
- //create the NDef message and record
- NDefLib::Message msg;
- MyRecord rClickCount;
- msg.addRecord(&rClickCount);
-
- writeMessage(nfcNucleo,msg);
-
- while(1){
-
- if(buttonPress){
- rClickCount.incrementClick();
- writeMessage(nfcNucleo,msg);
- buttonPress=false;
- }//if
-
- }//while
-
-}//main
-
-#endif
+#ifdef SAMPLE_WRITE_AND_CHANGE_ALL
+ sample_writeAndChangeAll();
+#endif /* SAMPLE_WRITE_AND_CHANGE_ALL */
+}
\ No newline at end of file
