X_NUCLEO_NFC02A1 library for M24LR
Dependencies: ST_INTERFACES
Dependents: HelloWorld_NFC02A1_mbedOS HelloWorld_NFC02A1laatste HelloWorld_NFC02A1
Fork of X_NUCLEO_NFC02A1 by
X-NUCLEO-NFC02A1 Dynamic NFC Tag Expansion Board Firmware Package
Introduction
This firmware package includes Components Device Drivers, Board Support Package and example applications for STMicroelectronics X-NUCLEO-NFC02A1 Dynamic NFC Tag Expansion Board based on M24LR.
Firmware Library
Class X_NUCLEO_NFC02A1 is intended to represent the Dynamic NFC Tag Expansion Board with the same name.
It provides an API to access to the M24LR component and to the three onboard LEDs.
It is intentionally implemented as a singleton because only one X_NUCLEO_NFC02A1 at a time might be deployed in a HW component stack.
The library also provides an implementation of the NDEF library API for M24LR, providing an simple way to read/write NDEF formatted messages from/to the M24LR dynamic NFC tag.
Example application
Hello World is a simple application to program and read an URI from the NFC tag.
Revision 6:8c1eca41b3a9, committed 2017-05-19
- Comitter:
- giovannivisentini
- Date:
- Fri May 19 07:51:32 2017 +0000
- Parent:
- 5:900640bf1cff
- Child:
- 7:b876cdcf095a
- Commit message:
- update with the ARM mBed coding style
Changed in this revision
--- a/Common/common.h Mon Oct 03 11:57:23 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-/**
- ******************************************************************************
- * @file common.h
- * @author AST
- * @version V1.0.0
- * @date 1 April 2015
- * @brief Header file containing generic component 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 __COMMON_H__
-#define __COMMON_H__
-#include <stdint.h>
-
-/* Types ---------------------------------------------------------------------*/
-
-/**
- * @brief NFCTAG status enumerator definition
- */
-typedef enum
-{
- NFCTAG_OK = 0,
- NFCTAG_ERROR = 1,
- NFCTAG_BUSY = 2,
- NFCTAG_TIMEOUT = 3
-} NFCTAG_StatusTypeDef;
-typedef NFCTAG_StatusTypeDef (*ReadFnDataPtr)( uint8_t * const, const uint16_t, const uint16_t ) ;
-typedef NFCTAG_StatusTypeDef (*WriteFnDataPtr)( const uint8_t * const, const uint16_t, const uint16_t) ;
-#endif
--- a/Common/component.h Mon Oct 03 11:57:23 2016 +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 Header file containing generic component 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/ST_INTERFACES.lib Mon Oct 03 11:57:23 2016 +0000 +++ b/ST_INTERFACES.lib Fri May 19 07:51:32 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/ST_INTERFACES/#a7810e7acf8d +https://developer.mbed.org/teams/ST/code/ST_INTERFACES/#d3c9b33b992c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/XNucleoNFC02A1.cpp Fri May 19 07:51:32 2017 +0000
@@ -0,0 +1,76 @@
+/**
+ ******************************************************************************
+ * @file XNucleoNFC02A1.h
+ * @author AMG Central Lab
+ * @version V2.0.0
+ * @date 19 May 2017
+ * @brief Singleton class that controls all the electronics inside the
+ * XNucleoNFC02A1 expansion board
+ ******************************************************************************
+ *
+ * COPYRIGHT(c) 2016 STMicroelectronics
+ *
+ * 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.
+ *
+ ******************************************************************************
+ */
+
+#include <XNucleoNFC02A1.h>
+
+const uint8_t XNucleoNFC02A1::M24LR_ADDR= 0xAE; //0xAC; //rp
+const uint8_t XNucleoNFC02A1::M24LR_ADDR_DATA = 0xA6;
+const PinName XNucleoNFC02A1::DEFAULT_SDA_PIN=D14;
+const PinName XNucleoNFC02A1::DEFAULT_SDL_PIN=D15;
+
+
+const PinName XNucleoNFC02A1::DEFAULT_GPO_PIN=D12;
+const PinName XNucleoNFC02A1::DEFAULT_RF_DISABLE_PIN=D11;
+const PinName XNucleoNFC02A1::DEFAULT_LED1_PIN=D5;
+const PinName XNucleoNFC02A1::DEFAULT_LED2_PIN=D4;
+const PinName XNucleoNFC02A1::DEFAULT_LED3_PIN=D2;
+
+XNucleoNFC02A1 *XNucleoNFC02A1::mInstance = NULL;
+
+XNucleoNFC02A1* XNucleoNFC02A1::instance(DevI2C &devI2C,
+ const PinName &gpoName,
+ const PinName &RFDisableName, const PinName &led1Name,
+ const PinName &led2Name, const PinName &led3Name) {
+ if (mInstance == NULL) { // the first time
+ mInstance = new XNucleoNFC02A1(devI2C,gpoName,
+ RFDisableName,led1Name,led2Name,led3Name);
+ if (mInstance != NULL) { //allocation ok
+ const int status = mInstance->mM24LR.initialization();
+ //if (status != NFC_SUCCESS) { //initialization failed
+ if (status != 0) {
+ delete mInstance;
+ error(
+ "Failed to init XNucleoNFC02A1 expansion board!\r\nError:0x%X\r\n",
+ status);
+ } //if init
+ } //if instance !=NULL
+ } //if instance
+ return mInstance;
+}
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/XNucleoNFC02A1.h Fri May 19 07:51:32 2017 +0000
@@ -0,0 +1,148 @@
+/**
+ ******************************************************************************
+ * @file X_NUCLEO_NFC02A1.cpp
+ * @author AMG Central Lab
+ * @version V2.0.0
+ * @date 19 May 2017
+ * @brief Singleton class that controls all the electronics inside the
+ * X_NUCLEO_NFC02A1 expansion board.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2016 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 X_NUCLEO_NFC02A1_H_
+#define X_NUCLEO_NFC02A1_H_
+#include <stdint.h>
+
+#include "mbed.h"
+
+#include "m24lr/M24LR.h"
+
+/**
+ * Singleton class that controls all the electronics inside the X_NUCLEO_NFC02A1 expansion board.
+ */
+class XNucleoNFC02A1 {
+
+public:
+
+private:
+ /**
+ * Pointer to the singleton instance, NULL if not allocated.
+ */
+ static XNucleoNFC02A1 *mInstance;
+ /**
+ * I2C address of the M24LR chip.
+ */
+ static const uint8_t M24LR_ADDR;
+
+ static const uint8_t M24LR_ADDR_DATA;
+
+ /**
+ * Constructor
+ * @param devI2C I2C channel used to communicate with the board.
+ * @param eventCallback Function that will be called when the gpo pin status change.
+ * @param gpoName Name of the gpio pin of the M24LR chip.
+ * @param RFDisableName Pin that controls the rf antenna status.
+ * @param led1Name Pin to control the led1 status.
+ * @param led2Name Pin to control the led1 status.
+ * @param led3Name Pin to control the led1 status.
+ */
+ XNucleoNFC02A1(DevI2C &devI2C,
+ const PinName &gpoName, const PinName &RFDisableName,
+ const PinName &led1Name, const PinName &led2Name,
+ const PinName &led3Name):
+ mM24LR(M24LR_ADDR, M24LR_ADDR_DATA, devI2C),
+ mNfcLed1(led1Name),mNfcLed2(led2Name),mNfcLed3(led3Name){}
+
+public:
+ static const PinName DEFAULT_SDA_PIN; //!< Default pin used for the M24LR SDA signal.
+ static const PinName DEFAULT_SDL_PIN; //!< Default pin used for the M24LR SDL signal.
+ static const PinName DEFAULT_GPO_PIN; //!< Default pin used for the M24LR GPO signal.
+ static const PinName DEFAULT_RF_DISABLE_PIN; //!< Default pin used for M24LR RF_DISABLE signal.
+ static const PinName DEFAULT_LED1_PIN; //!< Default pin to control the led 1.
+ static const PinName DEFAULT_LED2_PIN; //!< Default pin to control the led 2.
+ static const PinName DEFAULT_LED3_PIN; //!< Default pin to control the led 3.
+
+ /**
+ * Create or return an instance of X_NUCLEO_NFC02A1.
+ * @param devI2C I2C channel used to communicate with the board.
+ * @param eventCallback Function that will be called when the gpo pin status change.
+ * @param gpoName Name of the gpio pin of the M24LR chip.
+ * @param RFDisableName Pin that controls the rf antenna status.
+ * @param led1Name Pin to control the led1 status.
+ * @param led2Name Pin to control the led1 status.
+ * @param led3Name Pin to control the led1 status.
+ */
+ static XNucleoNFC02A1* instance(DevI2C &devI2C,
+ const PinName &gpoName = DEFAULT_GPO_PIN,
+ const PinName &RFDisableName = DEFAULT_RF_DISABLE_PIN,
+ const PinName &led1Name = DEFAULT_LED1_PIN,
+ const PinName &led2Name = DEFAULT_LED2_PIN,
+ const PinName &led3Name = DEFAULT_LED3_PIN);
+
+ /**
+ * @return board led1.
+ */
+ DigitalOut& get_led1() {
+ return mNfcLed1;
+ }
+
+ /**
+ * @return board led2.
+ */
+ DigitalOut& get_led2() {
+ return mNfcLed2;
+ }
+
+ /**
+ * @return board led3.
+ */
+ DigitalOut& get_led3() {
+ return mNfcLed3;
+ }
+
+ /**
+ * @return NFC Chip.
+ */
+ M24LR& get_M24LR() {
+ return mM24LR;
+ }
+
+ virtual ~XNucleoNFC02A1() {
+ }
+
+private:
+ M24LR mM24LR;
+
+ DigitalOut mNfcLed1;
+ DigitalOut mNfcLed2;
+ DigitalOut mNfcLed3;
+
+};
+#endif /* X_NUCLEO_NFC02A1_H_ */
--- a/X_NUCLEO_NFC02A1.cpp Mon Oct 03 11:57:23 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +0,0 @@
-/**
- ******************************************************************************
- * @file X_NUCLEO_NFC02A1.h
- * @author AMG Central Lab
- * @date 30 Aug 2016
- * @brief Singleton class that controls all the electronics inside the
- * X_NUCLEO_NFC02A1 expansion board
- ******************************************************************************
- *
- * COPYRIGHT(c) 2016 STMicroelectronics
- *
- * 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.
- *
- ******************************************************************************
- */
-
-#include <X_NUCLEO_NFC02A1.h>
-
-const uint8_t X_NUCLEO_NFC02A1::M24LR_ADDR= 0xAE; //0xAC; //rp
-const uint8_t X_NUCLEO_NFC02A1::M24LR_ADDR_DATA = 0xA6;
-const PinName X_NUCLEO_NFC02A1::DEFAULT_SDA_PIN=D14;
-const PinName X_NUCLEO_NFC02A1::DEFAULT_SDL_PIN=D15;
-
-
-const PinName X_NUCLEO_NFC02A1::DEFAULT_GPO_PIN=D12;
-const PinName X_NUCLEO_NFC02A1::DEFAULT_RF_DISABLE_PIN=D11;
-const PinName X_NUCLEO_NFC02A1::DEFAULT_LED1_PIN=D5;
-const PinName X_NUCLEO_NFC02A1::DEFAULT_LED2_PIN=D4;
-const PinName X_NUCLEO_NFC02A1::DEFAULT_LED3_PIN=D2;
-
-X_NUCLEO_NFC02A1 *X_NUCLEO_NFC02A1::mInstance = NULL;
-
-X_NUCLEO_NFC02A1* X_NUCLEO_NFC02A1::Instance(DevI2C &devI2C,
- const PinName &gpoName,
- const PinName &RFDisableName, const PinName &led1Name,
- const PinName &led2Name, const PinName &led3Name) {
- if (mInstance == NULL) { // the first time
- mInstance = new X_NUCLEO_NFC02A1(devI2C,gpoName,
- RFDisableName,led1Name,led2Name,led3Name);
- if (mInstance != NULL) { //allocation ok
- const int status = mInstance->mM24LR.Initialization();
- //if (status != NFC_SUCCESS) { //initialization failed
- if (status != 0) {
- delete mInstance;
- error(
- "Failed to init X_NUCLEO_NFC02A1 expansion board!\r\nError:0x%X\r\n",
- status);
- } //if init
- } //if instance !=NULL
- } //if instance
- return mInstance;
-}
-
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- a/X_NUCLEO_NFC02A1.h Mon Oct 03 11:57:23 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,152 +0,0 @@
-/**
- ******************************************************************************
- * @file X_NUCLEO_NFC02A1.cpp
- * @author AMG Central Lab
- * @version 1.0.0
- * @date 30 Aug 2016
- * @brief Singleton class that controls all the electronics inside the
- * X_NUCLEO_NFC02A1 expansion board.
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT(c) 2016 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 X_NUCLEO_NFC02A1_H_
-#define X_NUCLEO_NFC02A1_H_
-#include <stdint.h>
-
-#include "mbed.h"
-
-#include "m24lr/m24lr.h"
-
-/**
- * Singleton class that controls all the electronics inside the X_NUCLEO_NFC02A1 expansion board.
- */
-class X_NUCLEO_NFC02A1 {
-
-public:
-
-private:
- /**
- * Ponter to the singleton instance, NULL if not allocated.
- */
- static X_NUCLEO_NFC02A1 *mInstance;
- /**
- * I2C address of the M24LR chip.
- */
- static const uint8_t M24LR_ADDR;
-
- static const uint8_t M24LR_ADDR_DATA;
-
- /**
- * Constructor
- * @param devI2C I2C channel used to communicate with the board.
- * @param eventCallback Function that will be called when the gpo pin status change.
- * @param gpoName Name of the gpio pin of the M24LR chip.
- * @param RFDisableName Pin that controls the rf antenna status.
- * @param led1Name Pin to control the led1 status.
- * @param led2Name Pin to control the led1 status.
- * @param led3Name Pin to control the led1 status.
- */
- X_NUCLEO_NFC02A1(DevI2C &devI2C,
- const PinName &gpoName, const PinName &RFDisableName,
- const PinName &led1Name, const PinName &led2Name,
- const PinName &led3Name):
- mM24LR(M24LR_ADDR, M24LR_ADDR_DATA, devI2C),
- mNfcLed1(led1Name),mNfcLed2(led2Name),mNfcLed3(led3Name){}
-
-public:
- static const PinName DEFAULT_SDA_PIN; //!< Default pin used for the M24LR SDA signal.
- static const PinName DEFAULT_SDL_PIN; //!< Default pin used for the M24LR SDL signal.
- static const PinName DEFAULT_GPO_PIN; //!< Default pin used for the M24LR GPO signal.
- static const PinName DEFAULT_RF_DISABLE_PIN; //!< Default pin used for M24LR RF_DISABLE signal.
- static const PinName DEFAULT_LED1_PIN; //!< Default pin to control the led 1.
- static const PinName DEFAULT_LED2_PIN; //!< Default pin to control the led 2.
- static const PinName DEFAULT_LED3_PIN; //!< Default pin to control the led 3.
-
- /**
- * Create or return an instance of X_NUCLEO_NFC02A1.
- * @param devI2C I2C channel used to communicate with the board.
- * @param eventCallback Function that will be called when the gpo pin status change.
- * @param gpoName Name of the gpio pin of the M24LR chip.
- * @param RFDisableName Pin that controls the rf antenna status.
- * @param led1Name Pin to control the led1 status.
- * @param led2Name Pin to control the led1 status.
- * @param led3Name Pin to control the led1 status.
- */
- static X_NUCLEO_NFC02A1* Instance(DevI2C &devI2C,
- const PinName &gpoName = DEFAULT_GPO_PIN,
- const PinName &RFDisableName = DEFAULT_RF_DISABLE_PIN,
- const PinName &led1Name = DEFAULT_LED1_PIN,
- const PinName &led2Name = DEFAULT_LED2_PIN,
- const PinName &led3Name = DEFAULT_LED3_PIN);
-
- /**
- * @return board led1.
- */
- DigitalOut& getLed1() {
- return mNfcLed1;
- }
-
- /**
- * @return board led2.
- */
- DigitalOut& getLed2() {
- return mNfcLed2;
- }
-
- /**
- * @return board led3.
- */
- DigitalOut& getLed3() {
- return mNfcLed3;
- }
-
- /**
- * @return NFC Chip.
- */
- M24LR& getNFCTagM24LR() {
- return mM24LR;
- }
-
- M24LR& getM24LR() {
- return mM24LR;
- }
-
- virtual ~X_NUCLEO_NFC02A1() {
- }
-
-private:
- M24LR mM24LR;
-
- DigitalOut mNfcLed1;
- DigitalOut mNfcLed2;
- DigitalOut mNfcLed3;
-
-};
-#endif /* X_NUCLEO_NFC02A1_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/m24lr/M24LR.cpp Fri May 19 07:51:32 2017 +0000
@@ -0,0 +1,1022 @@
+/**
+ ******************************************************************************
+ * @file m24lr.cpp
+ * @author AMG Central Lab
+ * @version V2.0.0
+ * @date 19 May 2017
+ * @brief M24LR driver file.
+ ******************************************************************************
+ * @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.
+ *
+ ******************************************************************************
+ */
+
+
+
+#include "M24LR.h"
+
+uint8_t M24LR::NfctagInitialized = 0;
+
+
+/**
+ * @brief This function activate Energy Harvesting mode
+ */
+void M24LR::enable_energy_harvesting( void )
+{
+ /* Initialise M24LR Board */
+
+ /* Enable Energy Harvesting */
+ i2c_set_EH( );
+
+ /* Store configuration in non Volatile Memory */
+ i2c_enable_EH_mode();
+ i2c_write_EH_cfg( M24LR_EH_Cfg_6MA );
+
+}
+/**
+ * @brief Set M24LR nfctag Initialization
+ * @param None
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::initialization( void )
+{
+ uint8_t nfctag_id = 0;
+
+ if( NfctagInitialized == 0 )
+ {
+
+ /* M24LR Init */
+ if( i2c_init() != NFCTAG_OK )
+ {
+ return NFCTAG_ERROR;
+ }
+
+ /* Check M24LR driver ID */
+ i2c_read_id(&nfctag_id);
+ if( (nfctag_id == I_AM_M24LR04) || (nfctag_id == I_AM_M24LR16) || (nfctag_id == I_AM_M24LR64) )
+ {
+ NfctagInitialized = 1;
+ // Nfctag_Drv = &M24lr_i2c_Drv;
+ // Nfctag_Drv->pData = &M24lr_i2c_ExtDrv;
+ }
+ else
+ {
+ NfctagInitialized = 0;
+ // Nfctag_Drv = NULL;
+ // NfctagInitialized = 0;
+ return NFCTAG_ERROR;
+ }
+ }
+
+ return NFCTAG_OK;
+}
+
+/**
+ * @brief Set M24LR Initialization
+ * @param None
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_init( void )
+{
+ /* Configure the low level interface */
+ return(NFCTAG_OK);
+ // return mM24LR_IO.Init( );
+}
+
+/**
+ * @brief Read M24LR ID
+ * @param pICRef : pointer to store ID
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_read_id( uint8_t * const pData )
+{
+ uint8_t *pBuffer = (uint8_t *)pData;
+ NFCTAG_StatusTypeDef status;
+ /* Read ICRef on device */
+ //return M24LR_i2c_read_register( pICRef, M24LR_ICREF_REG, 1 );
+ /* Before calling this function M24LR must be ready, here is a check to detect an issue */
+ status = i2c_read_register(pBuffer, M24LR_ICREF_REG, 1);
+
+ if (status == 0)
+ return NFCTAG_OK;
+ return NFCTAG_TIMEOUT;
+
+}
+
+/**
+ * @brief Check M24LR availability
+ * @param Trials : number of max tentative tried
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_is_device_ready( const uint32_t Trials )
+{
+ /* Test i2c with M24LR */
+ // return mM24LR_IO.IsDeviceReady( M24LR_ADDR_DATA_I2C, Trials );
+ uint8_t status = 1;
+ char buffer;
+ while (status != 0) {
+ /* for device is ready address in M24Lr is M24LR_ADDR_DATA_I2C */
+ status = dev_I2C.read(i2c_address_data, &buffer, 1, false);
+ }
+ if ( status == 0 )
+ return NFCTAG_OK;
+ else
+ return NFCTAG_TIMEOUT;
+
+}
+
+/**
+ * @brief Configure M24LR GPO
+ * @param ITConf : 0x01 = RFBUSY, 0x02 = RFWIP
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_configure_GPO( const uint16_t ITConf )
+{
+ NFCTAG_StatusTypeDef status = NFCTAG_ERROR;
+
+ /* Configure GPO function on M24LR */
+ if( (ITConf & M24LR_IT_BUSY_MASK) == M24LR_IT_BUSY_MASK )
+ {
+ status = i2c_setRF_Busy( );
+ }
+ else if( (ITConf & M24LR_IT_WIP_MASK) == M24LR_IT_WIP_MASK )
+ {
+ status = i2c_set_RF_WIP( );
+ }
+ return status;
+}
+
+/**
+ * @brief Configure GPO as RF WriteInProgress
+ * @param None
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_set_RF_WIP( void )
+{
+ uint8_t reg_value;
+ NFCTAG_StatusTypeDef status;
+ status = i2c_read_register(®_value, M24LR_CFG_REG, 1);
+
+
+ if( status != NFCTAG_OK )
+ {
+ return status;
+ }
+
+ /* Update register value for WIP configuration */
+ reg_value |= M24LR_CFG_WIPBUSY_MASK;
+
+ /* Write CFG register */
+ return i2c_write_register( ®_value, M24LR_CFG_REG, 1 );
+}
+
+
+/**
+ * @brief Get Configuration of M24LR GPO
+ * @param GPOStatus : 0x01 = RFBUSY, 0x02 = RFWIP
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_get_GPO_status( uint16_t * const pGPOStatus )
+{
+ uint8_t reg_value;
+ NFCTAG_StatusTypeDef status;
+
+ /* Read actual value of CFG register */
+ status = i2c_read_register( ®_value, M24LR_CFG_REG, 1 );
+ if( status != NFCTAG_OK )
+ {
+ return status;
+ }
+
+ /* Extract RF WIP/BUSY information */
+ if( (reg_value & M24LR_CFG_WIPBUSY_MASK) == M24LR_CFG_WIPBUSY_MASK )
+ {
+ *pGPOStatus = M24LR_IT_WIP_MASK;
+ }
+ else
+ {
+ *pGPOStatus = M24LR_IT_BUSY_MASK;
+ }
+
+ return NFCTAG_OK;
+}
+
+/**
+ * @brief Read N bytes starting from specified I2C address
+ * @param pData : pointer of the data to store
+ * @param TarAddr : I2C data memory address to read
+ * @param NbByte : number of bytes to read
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_read_data( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte )
+{
+ int status;
+ /* Before calling this function M24LR must be ready, here is a check to detect an issue */
+ if( i2c_is_device_ready( 1 ) != NFCTAG_OK )
+ {
+ return NFCTAG_TIMEOUT;
+ }
+ /* Rosarium : To check M24LR_ADDR_DATA_I2C is this case */
+ /* return M24lr_IO_MemRead( pData, M24LR_ADDR_DATA_I2C, TarAddr, NbByte ); */
+ status = dev_I2C.i2c_read(pData, i2c_address_data, TarAddr, NbByte);
+ if ( status == 0 )
+ return NFCTAG_OK;
+ else
+ return NFCTAG_TIMEOUT;
+}
+
+/**
+ * @brief Write N data bytes starting from specified I2C Address
+ * @brief if I2C_Write_Lock bit = 0 or I2C_Password present => ack (modification OK)
+ * @brief if I2C_Write_Lock bit = 1 and no I2C_Password present => No ack (no modification)
+ * @param pData : pointer of the data to write
+ * @param TarAddr : I2C data memory address to write
+ * @param NbByte : number of bytes to write
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_write_data( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte )
+{
+ int status;
+ uint8_t align_mem_offset;
+ uint16_t bytes_to_write = NbByte;
+ uint16_t mem_addr = TarAddr;
+ uint8_t *pdata_index = (uint8_t *)pData;
+
+ /* Before calling this function M24LR must be ready, here is a check to detect an issue */
+ if( i2c_is_device_ready( 1 ) != NFCTAG_OK )
+ {
+ return NFCTAG_TIMEOUT;
+ }
+
+ /* M24LR can write a maximum of 4 bytes in EEPROM per i2c communication */
+ do
+ {
+ /* To write data in M24LR, data must be aligned on the same row in memory */
+ /* align_mem_offset is used to copy only Bytes that are on the same row in memory */
+ if( bytes_to_write > M24LR_PAGEWRITE_NBBYTE )
+ {
+ /* DataSize higher than max page write, copy data by page */
+ align_mem_offset = M24LR_PAGEWRITE_NBBYTE - (mem_addr % M24LR_PAGEWRITE_NBBYTE);
+ }
+ else
+ {
+ /* DataSize lower or equal to max page write, copy only last bytes */
+ align_mem_offset = bytes_to_write;
+ }
+ /* Write align_mem_offset bytes in memory */
+ /* Rosarium to Check as the address here is 0xA6 rather than 0xAE */
+ /* Rosarium dev_I2C.i2c_write(pdata_index, M24LR_ADDR_DATA_I2C, mem_addr, align_mem_offset); */
+ status = dev_I2C.i2c_write(pdata_index, i2c_address_data, mem_addr, align_mem_offset);
+
+ /* update index, dest address, size for next write */
+ pdata_index += align_mem_offset;
+ mem_addr += align_mem_offset;
+ bytes_to_write -= align_mem_offset;
+ /* Poll until EEPROM is available */
+ while( i2c_is_device_ready( 1 ) != NFCTAG_OK ) {};
+ }
+ while( ( bytes_to_write > 0 ) && ( status == NFCTAG_OK ) );
+ if ( status == 0 )
+ return NFCTAG_OK;
+ else
+ return NFCTAG_ERROR;
+}
+
+/**
+ * @brief Read N register bytes starting from specified I2C address
+ * @param pData : pointer of the data to store
+ * @param TarAddr : I2C memory address to read
+ * @param NbByte : number of bytes to read
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_read_register( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte )
+{
+ /* Before calling read function M24LR must be ready, here is a check to detect an issue */
+ int status;
+
+ /* Before calling any read function M24LR must be ready, here is a check to detect an issue */
+ if( i2c_is_device_ready( 1 ) != NFCTAG_OK )
+ {
+ return NFCTAG_TIMEOUT;
+ }
+ /* Read actual value of register */
+ status = dev_I2C.i2c_read(pData, i2c_address_syst, TarAddr, NbByte);
+
+ if ( status == 0 )
+ return NFCTAG_OK;
+ else
+ return NFCTAG_TIMEOUT;
+}
+
+/**
+ * @brief Write N bytes to specific register
+ * @param pData : pointer of the data to write
+ * @param TarAddr : I2C register address to write
+ * @param NbByte : number of bytes to write
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_write_register( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte )
+{
+ int status;
+ uint8_t align_mem_offset;
+ uint16_t bytes_to_write = NbByte;
+ uint16_t mem_addr = TarAddr;
+ uint8_t *pdata_index = (uint8_t *)pData;
+
+ /* Before calling this function M24LR must be ready, here is a check to detect an issue */
+ if( i2c_is_device_ready( 1 ) != NFCTAG_OK )
+ {
+ return NFCTAG_TIMEOUT;
+ }
+
+ /* M24LR can write a maximum of 4 bytes in EEPROM per i2c communication */
+ do
+ {
+ /* To write data in M24LR, data must be aligned on the same row in memory */
+ /* align_mem_offset is used to copy only Bytes that are on the same row in memory */
+ if( bytes_to_write > M24LR_PAGEWRITE_NBBYTE )
+ {
+ /* DataSize higher than max page write, copy data by page */
+ align_mem_offset = M24LR_PAGEWRITE_NBBYTE - (mem_addr % M24LR_PAGEWRITE_NBBYTE);
+ }
+ else
+ {
+ /* DataSize lower or equal to max page write, copy only last bytes */
+ align_mem_offset = bytes_to_write;
+ }
+ /* Write align_mem_offset bytes in register */
+ // status = M24lr_IO_MemWrite( pdata_index, M24LR_ADDR_SYST_I2C, mem_addr, align_mem_offset );
+ status = dev_I2C.i2c_write(pdata_index, i2c_address_syst, mem_addr, align_mem_offset);
+ /* update index, dest address, size for next write */
+ pdata_index += align_mem_offset;
+ mem_addr += align_mem_offset;
+ bytes_to_write -= align_mem_offset;
+ /* Poll until EEPROM is available */
+ while( i2c_is_device_ready( 1 ) != NFCTAG_OK ) {};
+ }
+ while( ( bytes_to_write > 0 ) && ( status == NFCTAG_OK ) );
+
+ if ( status == 0 )
+ return NFCTAG_OK;
+ else
+ return NFCTAG_ERROR;
+}
+
+/**
+ * @brief Read M24LR UID
+ * @param UID : M24LR_UID pointer of the UID to store
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_read_UID( M24LR_UID * const pUid )
+{
+ uint8_t areg_value[8];
+ uint8_t i;
+ NFCTAG_StatusTypeDef status;
+
+ /* Read actual value of UID registers */
+ status = i2c_read_register( areg_value, M24LR_UID_REG, 8 );
+ if( status != NFCTAG_OK )
+ {
+ return status;
+ }
+
+ /* Store information in 2 WORD */
+ pUid->MSB_UID = 0;
+
+ for( i = 0; i < 4; i++ )
+ {
+ pUid->MSB_UID = (pUid->MSB_UID << 8) | areg_value[7 - i];
+ }
+
+ pUid->LSB_UID = 0;
+
+ for( i = 0; i < 4; i++ )
+ {
+ pUid->LSB_UID = (pUid->LSB_UID << 8) | areg_value[3 - i];
+ }
+
+ return NFCTAG_OK;
+}
+
+/**
+ * @brief Read DSFID
+ * @param pData : pointer of the DSFID to store
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_read_DSFID( uint8_t * const pDsfid )
+{
+ /* Read actual value of DSFID register */
+ return i2c_read_register( pDsfid, M24LR_DSFID_REG, 1 );
+}
+
+/**
+ * @brief Read AFI
+ * @param pData : pointer of the AFI to store
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_read_AFI( uint8_t * const pAfi )
+{
+ /* Read actual value of AFI register */
+ return i2c_read_register( pAfi, M24LR_AFI_REG, 1 );
+}
+
+/**
+ * @brief Read status of I2C Lock Sectors
+ * @param Lock_sector : M24LR_Lock_Sectors pointer of the I2c lock sector status to store
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_read_I2C_lock_sector( M24LR_Lock_Sectors * const pLock_sector )
+{
+ uint8_t areg_value[8];
+ NFCTAG_StatusTypeDef status;
+
+ /* Read actual value of I2c Write Lock registers */
+ status = i2c_read_register( areg_value, M24LR_LOCK_REG, 8 );
+ if( status != NFCTAG_OK )
+ {
+ return status;
+ }
+
+ /* Dispatch information to corresponding struct member */
+ pLock_sector->sectors_63_56 = areg_value[7];
+ pLock_sector->sectors_55_48 = areg_value[6];
+ pLock_sector->sectors_47_40 = areg_value[5];
+ pLock_sector->sectors_39_32 = areg_value[4];
+ pLock_sector->sectors_31_24 = areg_value[3];
+ pLock_sector->sectors_23_16 = areg_value[2];
+ pLock_sector->sectors_15_8 = areg_value[1];
+ pLock_sector->sectors_7_0 = areg_value[0];
+
+ return NFCTAG_OK;
+}
+
+/**
+ * @brief Lock I2C write on an EEPROM Sectors
+ * @brief Need a presentation of I2C Password to be effective
+ * @param Sector : EEPROM Sector number to lock (between 0 to 63)
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_I2C_lock_sector( const uint8_t Sector )
+{
+ NFCTAG_StatusTypeDef status;
+ uint8_t reg_value = 0;
+ uint16_t sector_write_lock_addr;
+
+ /* Compute register address */
+ sector_write_lock_addr = M24LR_LOCK_REG | (Sector >> 3);
+
+ /* Read actual WriteLockStatus */
+ status = i2c_read_register( ®_value, sector_write_lock_addr, 1 );
+ if( status != NFCTAG_OK )
+ {
+ return status;
+ }
+
+ /* Compute and update new WriteLockStatus */
+ reg_value |= 1 << ( Sector % 8 );
+
+ /* Write WriteLock register */
+ return i2c_write_register( ®_value, sector_write_lock_addr, 1 );
+}
+
+/**
+ * @brief UnLock I2C write on a EEPROM Sector
+ * @brief Need an presentation of I2C Password to be effective
+ * @param pSector : EEPROM Sector number to unlock (between 0 to 63)
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_I2C_unlock_sector( const uint8_t Sector )
+{
+ NFCTAG_StatusTypeDef status;
+ uint8_t reg_value = 0;
+ uint16_t sector_write_lock_addr;
+
+ /* Compute register address */
+ sector_write_lock_addr = M24LR_LOCK_REG | (Sector >> 3);
+
+ /* Read actual WriteLockStatus */
+ status = i2c_read_register( ®_value, sector_write_lock_addr, 1 );
+ if( status != NFCTAG_OK )
+ {
+ return status;
+ }
+
+ /* Compute and update new WriteLockStatus */
+ reg_value &= ~( 1 << ( Sector % 8 ) );
+
+ /* Write WriteLock register */
+ return i2c_write_register( ®_value, sector_write_lock_addr, 1 );
+}
+
+/**
+ * @brief Present I2C password, authorize I2C write
+ * @param PassWord : Password value on 32bits
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_present_I2C_password( const uint32_t PassWord )
+{
+ uint8_t ai2c_message[9] = {0};
+ uint8_t i;
+
+ /* Build I2C Message with Password + Validation code 0x09 + Password */
+ ai2c_message[4] = 0x09;
+ i = 0;
+ while( i < 4 )
+ {
+ ai2c_message[i] = ( PassWord >> (i * 8) ) & 0xFF;
+ ai2c_message[i + 5] = ( PassWord >> (i * 8) ) & 0xFF;
+ i++;
+ };
+
+ /* Present password to M24LR */
+ return i2c_write_register( ai2c_message, M24LR_I2C_PWD_REG, 9 );
+}
+
+/**
+ * @brief Write new I2C password
+ * @brief Need to present good I2CPassword before using this function
+ * @param PassWord : new I2C PassWord value on 32bits
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_write_I2C_password( const uint32_t PassWord )
+{
+ uint8_t ai2c_message[9] = {0};
+ uint8_t i;
+
+ /* Build I2C Message with Password + Validation code 0x07 + Password */
+ ai2c_message[4] = 0x07;
+ i = 0;
+ while( i < 4 )
+ {
+ ai2c_message[i] = ( PassWord >> (i * 8) ) & 0xFF;
+ ai2c_message[i + 5] = ( PassWord >> (i * 8) ) & 0xFF;
+ i++;
+ };
+
+ /* Write Password to register */
+ return i2c_write_register( ai2c_message, M24LR_I2C_PWD_REG, 9 );
+}
+
+/**
+ * @brief Read SectorSecurityStatus (defining RF access allowed)
+ * @param SectorNb : Sector number to get RF security status
+ * @param pData : M24LR_SECTOR_SEC pointer of the data to store
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_read_SSSx( const uint8_t SectorNb, M24LR_SECTOR_SEC * const pData )
+{
+ uint8_t reg_value;
+ NFCTAG_StatusTypeDef status;
+ uint16_t sector_security_addr;
+
+ /* Compute Sector Security register address */
+ sector_security_addr = M24LR_SSS_REG | SectorNb;
+
+ /* Read actual value of SectorSecurityStatus register */
+ status = i2c_read_register( ®_value, sector_security_addr, 1 );
+ if( status != NFCTAG_OK )
+ {
+ return status;
+ }
+
+ /* Extract Sector Security Status configuration */
+ pData->SectorLock = reg_value & M24LR_SSS_LOCK_MASK;
+ pData->RW_Protection = (reg_value & M24LR_SSS_RW_MASK) >> 1;
+ pData->PassCtrl = (reg_value & M24LR_SSS_PASSCTRL_MASK) >> 3;
+
+ return NFCTAG_OK;
+}
+
+/**
+ * @brief Write SectorSecurityStatus (defining RF access allowed)
+ * @brief Need an presentation of I2C Password to be effective
+ * @param SectorNb : Sector number to set RF security
+ * @param pData : M24LR_SECTOR_SEC pointer of the data to write
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_write_SSSx( const uint8_t SectorNb, const M24LR_SECTOR_SEC * const pData )
+{
+ uint8_t reg_value;
+ uint16_t sector_security_addr;
+
+ /* Compute Sector Security register address */
+ sector_security_addr = M24LR_SSS_REG | SectorNb;
+
+ /* Update Sector Security Status */
+ reg_value = (pData->PassCtrl << 3) & M24LR_SSS_PASSCTRL_MASK;
+ reg_value |= ((pData->RW_Protection << 1) & M24LR_SSS_RW_MASK);
+ reg_value |= (pData->SectorLock & M24LR_SSS_LOCK_MASK);
+
+ /* Write SectorSecurityStatus register */
+ return i2c_write_register( ®_value, sector_security_addr, 1 );
+}
+
+/**
+ * @brief Read Memory Size info
+ * @param SizeInfo : M24LR_Mem_Size pointer of the data to store
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_read_mem_size( M24LR_Mem_Size * const pSizeInfo )
+{
+ uint8_t areg_value[3];
+ NFCTAG_StatusTypeDef status;
+
+ /* Read actual value of Mem_Size register */
+ status = i2c_read_register( areg_value, M24LR_MEMSIZE_REG, 3 );
+ if( status != NFCTAG_OK )
+ {
+ return status;
+ }
+
+ /* Extract Mem information */
+ pSizeInfo->BlockSize = areg_value[2];
+ pSizeInfo->Mem_Size = areg_value[1];
+ pSizeInfo->Mem_Size = (pSizeInfo->Mem_Size << 8) | areg_value[0];
+
+ return NFCTAG_OK;
+}
+
+/**
+ * @brief Get GPO Configuration status
+ * @param Rf_Wip_Busy : M24LR_GPO_STATUS pointer of the data to store
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_get_RF_WIP_busy( M24LR_GPO_STATUS * const pRf_Wip_Busy )
+{
+ uint8_t reg_value;
+ NFCTAG_StatusTypeDef status;
+
+ /* Read actual value of CFG register */
+ status = i2c_read_register( ®_value, M24LR_CFG_REG, 1 );
+ if( status != NFCTAG_OK )
+ {
+ return status;
+ }
+
+ /* Extract RF WIP/BUSY information */
+ if( (reg_value & M24LR_CFG_WIPBUSY_MASK) == M24LR_CFG_WIPBUSY_MASK )
+ {
+ *pRf_Wip_Busy = M24LR_GPO_WIP;
+ }
+ else
+ {
+ *pRf_Wip_Busy = M24LR_GPO_BUSY;
+ }
+
+ return NFCTAG_OK;
+}
+
+/**
+ * @brief Configure GPO as RF Busy
+ * @param None
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_setRF_Busy( void )
+{
+ uint8_t reg_value;
+ int status;
+
+ /* Read actual value of CFG register */
+ status = dev_I2C.i2c_read( ®_value, i2c_address_syst, (uint16_t)M24LR_CFG_REG, 1 );
+ if( status != 0 )
+ {
+ return NFCTAG_TIMEOUT;
+ }
+
+ /* Update register value for BUSY configuration */
+ reg_value &= !M24LR_CFG_WIPBUSY_MASK;
+
+ /* Write CFG register */
+ status = i2c_write_register( ®_value, M24LR_CFG_REG, 1 );
+ if ( status == 0 )
+ return NFCTAG_OK;
+ else
+ return NFCTAG_TIMEOUT;
+}
+
+
+/**
+ * @brief Get Energy harvesting mode status
+ * @param EH_mode : M24LR_EH_MODE_STATUS pointer of the data to store
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_read_EH_mode( M24LR_EH_MODE_STATUS * const pEH_mode )
+{
+ uint8_t reg_value;
+ NFCTAG_StatusTypeDef status;
+
+ /* Read actual value of CFG register */
+ status = i2c_read_register( ®_value, M24LR_CFG_REG, 1 );
+ if( status != NFCTAG_OK )
+ {
+ return status;
+ }
+
+ /* Extract EH_mode configuration */
+ if( (reg_value & M24LR_CFG_EHMODE_MASK) == M24LR_CFG_EHMODE_MASK )
+ {
+ *pEH_mode = M24LR_EH_MODE_DISABLE;
+ }
+ else
+ {
+ *pEH_mode = M24LR_EH_MODE_ENABLE;
+ }
+
+ return NFCTAG_OK;
+}
+
+/**
+ * @brief Enable Energy harvesting mode
+ * @param None
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_enable_EH_mode( void )
+{
+ uint8_t reg_value;
+ NFCTAG_StatusTypeDef status;
+
+ /* Read actual value of CFG register */
+ status = i2c_read_register( ®_value, M24LR_CFG_REG, 1 );
+ if( status != NFCTAG_OK )
+ {
+ return status;
+ }
+
+ /* Update EH_mode */
+ reg_value &= ~M24LR_CFG_EHMODE_MASK;
+
+ /* Write CFG register */
+ return i2c_write_register( ®_value, M24LR_CFG_REG, 1 );
+}
+
+/**
+ * @brief Disable Energy harvesting mode
+ * @param None
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_disable_EH_mode( void )
+{
+ uint8_t reg_value;
+ NFCTAG_StatusTypeDef status;
+
+ /* Read actual value of CFG register */
+ status = i2c_read_register( ®_value, M24LR_CFG_REG, 1 );
+ if( status != NFCTAG_OK )
+ {
+ return status;
+ }
+
+ /* Update EH_mode */
+ reg_value |= M24LR_CFG_EHMODE_MASK;
+
+ /* Write CFG register */
+ return i2c_write_register( ®_value, M24LR_CFG_REG, 1 );
+}
+
+/**
+ * @brief Read Vout sink current configuration status for Energy Harvesting
+ * @param EH_Cfg : M24LR_EH_CFG_VOUT pointer of the data to store
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_read_EH_cfg( M24LR_EH_CFG_VOUT * const pEH_Cfg )
+{
+ uint8_t reg_value;
+ NFCTAG_StatusTypeDef status;
+
+ /* Read actual value of CFG register */
+ status = i2c_read_register( ®_value, M24LR_CFG_REG, 1 );
+ if( status != NFCTAG_OK )
+ {
+ return status;
+ }
+
+ /* Extract Vout configuration for EH information */
+ reg_value &= (M24LR_CFG_EHCFG1_MASK | M24LR_CFG_EHCFG0_MASK);
+ switch( reg_value )
+ {
+ case 0:
+ *pEH_Cfg = M24LR_EH_Cfg_6MA;
+ break;
+ case 1:
+ *pEH_Cfg = M24LR_EH_Cfg_3MA;
+ break;
+ case 2:
+ *pEH_Cfg = M24LR_EH_Cfg_1MA;
+ break;
+ case 3:
+ *pEH_Cfg = M24LR_EH_Cfg_300UA;
+ break;
+
+ default:
+ *pEH_Cfg = M24LR_EH_Cfg_6MA;
+ }
+
+ return NFCTAG_OK;
+}
+
+/**
+ * @brief Write Vout sink current configuration status for Energy Harvesting
+ * @param EH_Cfg : M24LR_EH_CFG_VOUT value to configure Vout
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_write_EH_cfg( const M24LR_EH_CFG_VOUT EH_Cfg )
+{
+ uint8_t reg_value;
+ NFCTAG_StatusTypeDef status;
+
+ /* Read actual value of CFG register */
+ status = i2c_read_register( ®_value, M24LR_CFG_REG, 1 );
+ if( status != NFCTAG_OK )
+ {
+ return status;
+ }
+
+ /* Update Vout configuration */
+ reg_value &= ~(M24LR_CFG_EHCFG1_MASK | M24LR_CFG_EHCFG0_MASK);
+ reg_value |= EH_Cfg;
+
+ /* Write CFG register */
+ return i2c_write_register( ®_value, M24LR_CFG_REG, 1 );
+}
+
+/**
+ * @brief Get Energy Harvesting status
+ * @param EH_Val : M24LR_EH_STATUS pointer of the data to store
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_get_EH( M24LR_EH_STATUS * const pEH_Val )
+{
+ uint8_t reg_value;
+ NFCTAG_StatusTypeDef status;
+
+ /* Read actual value of CTRL register */
+ status = i2c_read_register( ®_value, M24LR_CTRL_REG, 1 );
+ if( status != NFCTAG_OK )
+ {
+ return status;
+ }
+
+ /* Extract EH information */
+ if( (reg_value & M24LR_CTRL_EHEN_MASK) == M24LR_CTRL_EHEN_MASK )
+ {
+ *pEH_Val = M24LR_EH_ENABLE;
+ }
+ else
+ {
+ *pEH_Val = M24LR_EH_DISABLE;
+ }
+
+ return NFCTAG_OK;
+}
+
+/**
+ * @brief Enable Energy Harvesting
+ * @param None
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_set_EH( void )
+{
+ uint8_t reg_value;
+ NFCTAG_StatusTypeDef status;
+
+ /* Read actual value of CTRL register */
+ status = i2c_read_register( ®_value, M24LR_CTRL_REG, 1 );
+ if( status != NFCTAG_OK )
+ {
+ return status;
+ }
+
+ /* Update EH configuration */
+ reg_value |= M24LR_CTRL_EHEN_MASK;
+
+ /* Write CTRL Register */
+ return i2c_write_register( ®_value, M24LR_CTRL_REG, 1 );
+}
+
+/**
+ * @brief Disable Energy Harvesting
+ * @param None
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_reset_EH( void )
+{
+ uint8_t reg_value;
+ NFCTAG_StatusTypeDef status;
+
+ /* Read actual value of CTRL register */
+ status = i2c_read_register( ®_value, M24LR_CTRL_REG, 1 );
+ if( status != NFCTAG_OK )
+ {
+ return status;
+ }
+
+ /* Update EH configuration */
+ reg_value &= ~M24LR_CTRL_EHEN_MASK;
+
+ /* Write CTRL register */
+ return i2c_write_register( ®_value, M24LR_CTRL_REG, 1 );
+}
+
+/**
+ * @brief Check if RF Field is present in front of M24LR
+ * @param pRF_Field : M24LR_FIELD_STATUS pointer of the data to store
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_get_RF_field( M24LR_FIELD_STATUS * const pRF_Field )
+{
+ NFCTAG_StatusTypeDef status;
+ uint8_t reg_value = 0;
+
+ /* Read actual value of CTRL register */
+ status = i2c_read_register( ®_value, M24LR_CTRL_REG, 1 );
+
+ /* Extract RF Field information */
+ if( status == NFCTAG_OK )
+ {
+ if( (reg_value & M24LR_CTRL_FIELD_MASK) == M24LR_CTRL_FIELD_MASK )
+ {
+ *pRF_Field = M24LR_FIELD_ON;
+ }
+ else
+ {
+ *pRF_Field = M24LR_FIELD_OFF;
+ }
+
+ return NFCTAG_OK;
+ }
+
+ return status;
+}
+
+/**
+ * @brief Check if Write Timing is good
+ * @param pT_Prog : M24LR_T_PROG_STATUS pointer of the data to store
+ * @retval NFCTAG enum status
+ */
+NFCTAG_StatusTypeDef M24LR::i2c_get_TProg( M24LR_T_PROG_STATUS * const pT_Prog )
+{
+ NFCTAG_StatusTypeDef status;
+ uint8_t reg_value = 0;
+
+ /* Read actual value of CTRL register */
+ status = i2c_read_register( ®_value, M24LR_CTRL_REG, 1 );
+
+ /* Extract T-Prog information */
+ if( status == NFCTAG_OK )
+ {
+ if( (reg_value & M24LR_CTRL_TPROG_MASK) == M24LR_CTRL_TPROG_MASK )
+ {
+ *pT_Prog = M24LR_T_PROG_OK;
+ }
+ else
+ {
+ *pT_Prog = M24LR_T_PROG_NO;
+ }
+
+ return NFCTAG_OK;
+ }
+ else
+ return status;
+}
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/******************* (C) COPYRIGHT 2016 STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/m24lr/M24LR.h Fri May 19 07:51:32 2017 +0000
@@ -0,0 +1,303 @@
+/**
+ ******************************************************************************
+ * @file m24lr.h
+ * @author AMG Central Lab
+ * @version V2.0.0
+ * @date 19 May 2017
+ * @brief header file for M24LR driver .
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2016 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 __M24LR_H
+#define __M24LR_H
+
+#include "DevI2C.h"
+#include "Nfc.h"
+#include "NDefNfcTag.h"
+#include "NDefNfcTagM24LR.h"
+
+//#include "lib_NDEF_URI.h"
+ /* Exported constants --------------------------------------------------------*/
+/** @defgroup M24LR_Exported_Constants
+ * @{
+ */
+#define I_AM_M24LR04 0x5A
+#define I_AM_M24LR16 0x4E
+#define I_AM_M24LR64 0x5E
+
+#ifndef NULL
+#define NULL (void *) 0
+#endif
+
+#define M24LR_PAGEWRITE_NBBYTE 4
+
+#define M24LR_ADDR_DATA_I2C 0xA6
+#define M24LR_ADDR_SYST_I2C 0xAE
+#define M24LR_I2C_TIMEOUT 200 /* I2C Time out (ms), this is the maximum time needed by M24LR to complete any command */
+
+#define M24LR_IT_BUSY_MASK 0x01
+#define M24LR_IT_WIP_MASK 0x02
+
+/* Registers address */
+#define M24LR_SSS_REG 0x0000
+#define M24LR_LOCK_REG 0x0800
+#define M24LR_I2C_PWD_REG 0x0900
+#define M24LR_CFG_REG 0x0910
+#define M24LR_AFI_REG 0x0912
+#define M24LR_DSFID_REG 0x0913
+#define M24LR_UID_REG 0x0914
+#define M24LR_ICREF_REG 0x091C
+#define M24LR_MEMSIZE_REG 0x091D
+#define M24LR_CTRL_REG 0x0920
+
+/* Registers mask */
+#define M24LR_SSS_LOCK_MASK 0x01
+#define M24LR_SSS_RW_MASK 0x06
+#define M24LR_SSS_PASSCTRL_MASK 0x18
+#define M24LR_LOCK_MASK 0x0F
+
+#define M24LR_CFG_EHCFG0_MASK 0x01
+#define M24LR_CFG_EHCFG1_MASK 0x02
+#define M24LR_CFG_EHMODE_MASK 0x04
+#define M24LR_CFG_WIPBUSY_MASK 0x08
+
+#define M24LR_CTRL_EHEN_MASK 0x01
+#define M24LR_CTRL_FIELD_MASK 0x02
+#define M24LR_CTRL_TPROG_MASK 0x80
+
+
+/**
+ * @brief NFCTAG status enumerator definition
+ */
+typedef enum
+{
+ NFCTAG_OK = 0,
+ NFCTAG_ERROR = 1,
+ NFCTAG_BUSY = 2,
+ NFCTAG_TIMEOUT = 3
+} NFCTAG_StatusTypeDef;
+
+/**
+ * @brief M24LR VOUT Configuration enumerator definition
+ */
+typedef enum
+{
+ M24LR_EH_Cfg_6MA = 0,
+ M24LR_EH_Cfg_3MA,
+ M24LR_EH_Cfg_1MA,
+ M24LR_EH_Cfg_300UA
+} M24LR_EH_CFG_VOUT;
+
+/**
+ * @brief M24LR FIELD status enumerator definition
+ */
+typedef enum
+{
+ M24LR_FIELD_OFF = 0,
+ M24LR_FIELD_ON
+} M24LR_FIELD_STATUS;
+
+/**
+ * @brief M24LR TT-PROG status enumerator definition
+ */
+typedef enum
+{
+ M24LR_T_PROG_NO = 0,
+ M24LR_T_PROG_OK
+} M24LR_T_PROG_STATUS;
+
+/**
+ * @brief M24LR Energy Harvesting status enumerator definition
+ */
+typedef enum
+{
+ M24LR_EH_DISABLE = 0,
+ M24LR_EH_ENABLE
+} M24LR_EH_STATUS;
+
+/**
+ * @brief M24LR Energy Harvesting mode enumerator definition
+ */
+typedef enum
+{
+ M24LR_EH_MODE_ENABLE = 0,
+ M24LR_EH_MODE_DISABLE
+} M24LR_EH_MODE_STATUS;
+
+/**
+ * @brief M24LR GPO status enumerator definition
+ */
+typedef enum
+{
+ M24LR_GPO_BUSY = 0,
+ M24LR_GPO_WIP
+} M24LR_GPO_STATUS;
+
+/**
+ * @brief M24LR Memory information structure definition
+ */
+typedef struct
+{
+ uint8_t BlockSize;
+ uint16_t Mem_Size;
+} M24LR_Mem_Size;
+
+/**
+ * @brief M24LR I2C Write Lock register structure definition
+ */
+typedef struct
+{
+ uint8_t sectors_7_0;
+ uint8_t sectors_15_8;
+ uint8_t sectors_23_16;
+ uint8_t sectors_31_24;
+ uint8_t sectors_39_32;
+ uint8_t sectors_47_40;
+ uint8_t sectors_55_48;
+ uint8_t sectors_63_56;
+} M24LR_Lock_Sectors;
+
+/**
+ * @brief M24LR UID information structure definition
+ */
+typedef struct
+{
+ uint32_t MSB_UID;
+ uint32_t LSB_UID;
+} M24LR_UID;
+
+/**
+ * @brief M24LR Sector Security register structure definition
+ */
+typedef struct
+{
+ uint8_t SectorLock;
+ uint8_t RW_Protection;
+ uint8_t PassCtrl;
+} M24LR_SECTOR_SEC;
+
+
+ /**
+ * @}
+ */
+
+class M24LR : public Nfc {
+public:
+ NFCTAG_StatusTypeDef i2c_init( void );
+ NFCTAG_StatusTypeDef i2c_read_id( uint8_t * const pICRef );
+ NFCTAG_StatusTypeDef i2c_is_device_ready( const uint32_t Trials );
+ NFCTAG_StatusTypeDef i2c_configure_GPO( const uint16_t ITConf );
+ NFCTAG_StatusTypeDef i2c_get_GPO_status( uint16_t * const pGPOStatus );
+ NFCTAG_StatusTypeDef i2c_read_data( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte );
+ NFCTAG_StatusTypeDef i2c_write_data( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte );
+ NFCTAG_StatusTypeDef i2c_read_register( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte );
+ NFCTAG_StatusTypeDef i2c_write_register( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte );
+
+
+ /* Extended Functions */
+ NFCTAG_StatusTypeDef i2c_read_UID( M24LR_UID * const pUid );
+ NFCTAG_StatusTypeDef i2c_read_DSFID( uint8_t * const pDsfid );
+ NFCTAG_StatusTypeDef i2c_read_AFI( uint8_t * const pAfi );
+ NFCTAG_StatusTypeDef i2c_read_I2C_lock_sector( M24LR_Lock_Sectors * const pLock_sector );
+ NFCTAG_StatusTypeDef i2c_I2C_lock_sector( const uint8_t Sector );
+ NFCTAG_StatusTypeDef i2c_I2C_unlock_sector( const uint8_t Sector );
+ NFCTAG_StatusTypeDef i2c_present_I2C_password( const uint32_t PassWord );
+ NFCTAG_StatusTypeDef i2c_write_I2C_password( const uint32_t PassWord );
+ NFCTAG_StatusTypeDef i2c_read_SSSx( const uint8_t SectorNb, M24LR_SECTOR_SEC * const pData );
+ NFCTAG_StatusTypeDef i2c_write_SSSx( const uint8_t SectorNb, const M24LR_SECTOR_SEC * const pData );
+ NFCTAG_StatusTypeDef i2c_read_mem_size( M24LR_Mem_Size * const pSizeInfo );
+ NFCTAG_StatusTypeDef i2c_get_RF_WIP_busy( M24LR_GPO_STATUS * const pRf_Wip_Busy );
+ NFCTAG_StatusTypeDef i2c_setRF_Busy( void );
+ NFCTAG_StatusTypeDef i2c_set_RF_WIP( void );
+ NFCTAG_StatusTypeDef i2c_read_EH_mode( M24LR_EH_MODE_STATUS * const pEH_mode );
+ NFCTAG_StatusTypeDef i2c_enable_EH_mode( void );
+ NFCTAG_StatusTypeDef i2c_disable_EH_mode( void );
+ NFCTAG_StatusTypeDef i2c_read_EH_cfg( M24LR_EH_CFG_VOUT * const pEH_Cfg );
+ NFCTAG_StatusTypeDef i2c_write_EH_cfg( const M24LR_EH_CFG_VOUT EH_Cfg );
+ NFCTAG_StatusTypeDef i2c_get_EH( M24LR_EH_STATUS * const pEH_Val );
+ NFCTAG_StatusTypeDef i2c_set_EH( void );
+ NFCTAG_StatusTypeDef i2c_reset_EH( void );
+ NFCTAG_StatusTypeDef i2c_get_RF_field( M24LR_FIELD_STATUS * const pRF_Field );
+ NFCTAG_StatusTypeDef i2c_get_TProg( M24LR_T_PROG_STATUS * const pT_Prog );
+
+ void enable_energy_harvesting( void );
+ NFCTAG_StatusTypeDef initialization( void );
+
+ virtual int read_binary(uint16_t Offset, uint8_t NbByteToRead,
+ uint8_t *pBufferRead) {
+ return i2c_read_data( pBufferRead, Offset, NbByteToRead );
+
+ }
+
+ virtual int update_binary(uint16_t Offset,
+ uint8_t NbByteToWrite,uint8_t *pDataToWrite) {
+ return i2c_write_data( pDataToWrite, Offset, NbByteToWrite );
+ }
+
+ M24LR(uint8_t const address, uint8_t const addressData, DevI2C &devI2C ):
+ NDefTagUtil(*this), i2c_address_syst(address), i2c_address_data(addressData), dev_I2C(devI2C) {}
+
+
+ NDefLib::NDefNfcTag& get_NDef_tag(){
+ return NDefTagUtil;
+ }
+
+
+ virtual int init(void *ptr) {
+ (void)ptr;
+ return i2c_init();
+ }
+
+ virtual int read_id(uint8_t *id) {
+ return i2c_read_id(id);
+ }
+ private:
+ static uint8_t NfctagInitialized;
+
+
+ /*
+ * Object implementing the interface to use the NDefLib.
+ */
+ NDefNfcTagM24LR NDefTagUtil;
+
+ uint8_t i2c_address_syst;
+ uint8_t i2c_address_data;
+ DevI2C dev_I2C;
+};
+
+
+
+
+#endif /* __M24LR_H */
+
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- a/m24lr/NDefNfcTagM24LR.cpp Mon Oct 03 11:57:23 2016 +0000
+++ b/m24lr/NDefNfcTagM24LR.cpp Fri May 19 07:51:32 2017 +0000
@@ -2,8 +2,8 @@
******************************************************************************
* @file NdefNfcTagM24LR.cpp
* @author AMG Central Lab
- * @version V1.0.0
- * @date 30 Aug 2016
+ * @version V2.0.0
+ * @date 19 May 2017
* @brief Wrapper class of the NDefLib library to write/read NDEF messages.
******************************************************************************
* @attention
@@ -451,7 +451,7 @@
return NDEF_ERROR_NOT_FORMATED;
}
-bool NDefNfcTagM24LR::openSession(bool force) {
+bool NDefNfcTagM24LR::open_session(bool force) {
uint16_t status;
status = NfcType5_NDEFDetection();
@@ -470,7 +470,7 @@
}
-bool NDefNfcTagM24LR::closeSession()
+bool NDefNfcTagM24LR::close_session()
{
return true;
@@ -505,7 +505,7 @@
uint16_t status;
do{
uint8_t writeLength =(uint8_t) std::min<uint16_t>(0xFF,length);
- status= mDevice.UpdateBinary(offset, writeLength, (uint8_t*)buffer);
+ status= mDevice.update_binary(offset, writeLength, (uint8_t*)buffer);
offset+=writeLength;
buffer+=writeLength;
length-=writeLength;
@@ -518,7 +518,7 @@
uint16_t status;
do{
uint8_t readBuffer = (uint8_t)std::min<uint16_t>(0xFF,length);
- status= mDevice.ReadBinary(byteOffset, readBuffer, (uint8_t*)buffer);
+ status= mDevice.read_binary(byteOffset, readBuffer, (uint8_t*)buffer);
byteOffset+=readBuffer;
buffer+=readBuffer;
length-=readBuffer;
--- a/m24lr/NDefNfcTagM24LR.h Mon Oct 03 11:57:23 2016 +0000
+++ b/m24lr/NDefNfcTagM24LR.h Fri May 19 07:51:32 2017 +0000
@@ -2,8 +2,8 @@
******************************************************************************
* @file NdefNfcTagM24LR.h
* @author AMG Central Lab
- * @version V1.0.0
- * @date 30 Aug 2016
+ * @version V2.0.0
+ * @date 19 May 2017
* @brief M24LR specific NDefLib derived class
******************************************************************************
* @attention
@@ -70,11 +70,11 @@
mDevice(device),mIsSessionOpen(false),
mMaxReadBytes(0xFF), mMaxWriteBytes(0xFF){}
- virtual bool openSession(bool force = false);
+ virtual bool open_session(bool force = false);
- virtual bool closeSession();
+ virtual bool close_session();
- virtual bool isSessionOpen(){
+ virtual bool is_session_open(){
return mIsSessionOpen;
}
@@ -82,8 +82,8 @@
* Close the open session.
*/
virtual ~NDefNfcTagM24LR(){
- if(isSessionOpen())
- closeSession();
+ if(is_session_open())
+ close_session();
}//~NDefNfcTagM24SR
protected:
--- a/m24lr/m24lr.cpp Mon Oct 03 11:57:23 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1022 +0,0 @@
-/**
- ******************************************************************************
- * @file m24lr.cpp
- * @author AMG Central Lab
- * @version V1.0.0
- * @date 30 Aug 2016
- * @brief M24LR driver file.
- ******************************************************************************
- * @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.
- *
- ******************************************************************************
- */
-
-
-
-#include "m24lr.h"
-
-uint8_t M24LR::NfctagInitialized = 0;
-
-
-/**
- * @brief This function activate Energy Harvesting mode
- */
-void M24LR::Enable_EnergyHarvesting( void )
-{
- /* Initialise M24LR Board */
-
- /* Enable Energy Harvesting */
- i2c_SetEH( );
-
- /* Store configuration in non Volatile Memory */
- i2c_Enable_EH_mode();
- i2c_WriteEH_Cfg( M24LR_EH_Cfg_6MA );
-
-}
-/**
- * @brief Set M24LR nfctag Initialization
- * @param None
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::Initialization( void )
-{
- uint8_t nfctag_id = 0;
-
- if( NfctagInitialized == 0 )
- {
-
- /* M24LR Init */
- if( i2c_Init() != NFCTAG_OK )
- {
- return NFCTAG_ERROR;
- }
-
- /* Check M24LR driver ID */
- i2c_ReadID(&nfctag_id);
- if( (nfctag_id == I_AM_M24LR04) || (nfctag_id == I_AM_M24LR16) || (nfctag_id == I_AM_M24LR64) )
- {
- NfctagInitialized = 1;
- // Nfctag_Drv = &M24lr_i2c_Drv;
- // Nfctag_Drv->pData = &M24lr_i2c_ExtDrv;
- }
- else
- {
- NfctagInitialized = 0;
- // Nfctag_Drv = NULL;
- // NfctagInitialized = 0;
- return NFCTAG_ERROR;
- }
- }
-
- return NFCTAG_OK;
-}
-
-/**
- * @brief Set M24LR Initialization
- * @param None
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_Init( void )
-{
- /* Configure the low level interface */
- return(NFCTAG_OK);
- // return mM24LR_IO.Init( );
-}
-
-/**
- * @brief Read M24LR ID
- * @param pICRef : pointer to store ID
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_ReadID( uint8_t * const pData )
-{
- uint8_t *pBuffer = (uint8_t *)pData;
- NFCTAG_StatusTypeDef status;
- /* Read ICRef on device */
- //return M24LR_i2c_ReadRegister( pICRef, M24LR_ICREF_REG, 1 );
- /* Before calling this function M24LR must be ready, here is a check to detect an issue */
- status = i2c_ReadRegister(pBuffer, M24LR_ICREF_REG, 1);
-
- if (status == 0)
- return NFCTAG_OK;
- return NFCTAG_TIMEOUT;
-
-}
-
-/**
- * @brief Check M24LR availability
- * @param Trials : number of max tentative tried
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_IsDeviceReady( const uint32_t Trials )
-{
- /* Test i2c with M24LR */
- // return mM24LR_IO.IsDeviceReady( M24LR_ADDR_DATA_I2C, Trials );
- uint8_t status = 1;
- char buffer;
- while (status != 0) {
- /* for device is ready address in M24Lr is M24LR_ADDR_DATA_I2C */
- status = dev_I2C.read(i2c_address_data, &buffer, 1, false);
- }
- if ( status == 0 )
- return NFCTAG_OK;
- else
- return NFCTAG_TIMEOUT;
-
-}
-
-/**
- * @brief Configure M24LR GPO
- * @param ITConf : 0x01 = RFBUSY, 0x02 = RFWIP
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_ConfigureGPO( const uint16_t ITConf )
-{
- NFCTAG_StatusTypeDef status = NFCTAG_ERROR;
-
- /* Configure GPO function on M24LR */
- if( (ITConf & M24LR_IT_BUSY_MASK) == M24LR_IT_BUSY_MASK )
- {
- status = i2c_SetRFBUSY( );
- }
- else if( (ITConf & M24LR_IT_WIP_MASK) == M24LR_IT_WIP_MASK )
- {
- status = i2c_SetRFWIP( );
- }
- return status;
-}
-
-/**
- * @brief Configure GPO as RF WriteInProgress
- * @param None
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_SetRFWIP( void )
-{
- uint8_t reg_value;
- NFCTAG_StatusTypeDef status;
- status = i2c_ReadRegister(®_value, M24LR_CFG_REG, 1);
-
-
- if( status != NFCTAG_OK )
- {
- return status;
- }
-
- /* Update register value for WIP configuration */
- reg_value |= M24LR_CFG_WIPBUSY_MASK;
-
- /* Write CFG register */
- return i2c_WriteRegister( ®_value, M24LR_CFG_REG, 1 );
-}
-
-
-/**
- * @brief Get Configuration of M24LR GPO
- * @param GPOStatus : 0x01 = RFBUSY, 0x02 = RFWIP
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_GetGPOStatus( uint16_t * const pGPOStatus )
-{
- uint8_t reg_value;
- NFCTAG_StatusTypeDef status;
-
- /* Read actual value of CFG register */
- status = i2c_ReadRegister( ®_value, M24LR_CFG_REG, 1 );
- if( status != NFCTAG_OK )
- {
- return status;
- }
-
- /* Extract RF WIP/BUSY information */
- if( (reg_value & M24LR_CFG_WIPBUSY_MASK) == M24LR_CFG_WIPBUSY_MASK )
- {
- *pGPOStatus = M24LR_IT_WIP_MASK;
- }
- else
- {
- *pGPOStatus = M24LR_IT_BUSY_MASK;
- }
-
- return NFCTAG_OK;
-}
-
-/**
- * @brief Read N bytes starting from specified I2C address
- * @param pData : pointer of the data to store
- * @param TarAddr : I2C data memory address to read
- * @param NbByte : number of bytes to read
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_ReadData( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte )
-{
- int status;
- /* Before calling this function M24LR must be ready, here is a check to detect an issue */
- if( i2c_IsDeviceReady( 1 ) != NFCTAG_OK )
- {
- return NFCTAG_TIMEOUT;
- }
- /* Rosarium : To check M24LR_ADDR_DATA_I2C is this case */
- /* return M24lr_IO_MemRead( pData, M24LR_ADDR_DATA_I2C, TarAddr, NbByte ); */
- status = dev_I2C.i2c_read(pData, i2c_address_data, TarAddr, NbByte);
- if ( status == 0 )
- return NFCTAG_OK;
- else
- return NFCTAG_TIMEOUT;
-}
-
-/**
- * @brief Write N data bytes starting from specified I2C Address
- * @brief if I2C_Write_Lock bit = 0 or I2C_Password present => ack (modification OK)
- * @brief if I2C_Write_Lock bit = 1 and no I2C_Password present => No ack (no modification)
- * @param pData : pointer of the data to write
- * @param TarAddr : I2C data memory address to write
- * @param NbByte : number of bytes to write
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_WriteData( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte )
-{
- int status;
- uint8_t align_mem_offset;
- uint16_t bytes_to_write = NbByte;
- uint16_t mem_addr = TarAddr;
- uint8_t *pdata_index = (uint8_t *)pData;
-
- /* Before calling this function M24LR must be ready, here is a check to detect an issue */
- if( i2c_IsDeviceReady( 1 ) != NFCTAG_OK )
- {
- return NFCTAG_TIMEOUT;
- }
-
- /* M24LR can write a maximum of 4 bytes in EEPROM per i2c communication */
- do
- {
- /* To write data in M24LR, data must be aligned on the same row in memory */
- /* align_mem_offset is used to copy only Bytes that are on the same row in memory */
- if( bytes_to_write > M24LR_PAGEWRITE_NBBYTE )
- {
- /* DataSize higher than max page write, copy data by page */
- align_mem_offset = M24LR_PAGEWRITE_NBBYTE - (mem_addr % M24LR_PAGEWRITE_NBBYTE);
- }
- else
- {
- /* DataSize lower or equal to max page write, copy only last bytes */
- align_mem_offset = bytes_to_write;
- }
- /* Write align_mem_offset bytes in memory */
- /* Rosarium to Check as the address here is 0xA6 rather than 0xAE */
- /* Rosarium dev_I2C.i2c_write(pdata_index, M24LR_ADDR_DATA_I2C, mem_addr, align_mem_offset); */
- status = dev_I2C.i2c_write(pdata_index, i2c_address_data, mem_addr, align_mem_offset);
-
- /* update index, dest address, size for next write */
- pdata_index += align_mem_offset;
- mem_addr += align_mem_offset;
- bytes_to_write -= align_mem_offset;
- /* Poll until EEPROM is available */
- while( i2c_IsDeviceReady( 1 ) != NFCTAG_OK ) {};
- }
- while( ( bytes_to_write > 0 ) && ( status == NFCTAG_OK ) );
- if ( status == 0 )
- return NFCTAG_OK;
- else
- return NFCTAG_ERROR;
-}
-
-/**
- * @brief Read N register bytes starting from specified I2C address
- * @param pData : pointer of the data to store
- * @param TarAddr : I2C memory address to read
- * @param NbByte : number of bytes to read
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_ReadRegister( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte )
-{
- /* Before calling read function M24LR must be ready, here is a check to detect an issue */
- int status;
-
- /* Before calling any read function M24LR must be ready, here is a check to detect an issue */
- if( i2c_IsDeviceReady( 1 ) != NFCTAG_OK )
- {
- return NFCTAG_TIMEOUT;
- }
- /* Read actual value of register */
- status = dev_I2C.i2c_read(pData, i2c_address_syst, TarAddr, NbByte);
-
- if ( status == 0 )
- return NFCTAG_OK;
- else
- return NFCTAG_TIMEOUT;
-}
-
-/**
- * @brief Write N bytes to specific register
- * @param pData : pointer of the data to write
- * @param TarAddr : I2C register address to write
- * @param NbByte : number of bytes to write
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_WriteRegister( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte )
-{
- int status;
- uint8_t align_mem_offset;
- uint16_t bytes_to_write = NbByte;
- uint16_t mem_addr = TarAddr;
- uint8_t *pdata_index = (uint8_t *)pData;
-
- /* Before calling this function M24LR must be ready, here is a check to detect an issue */
- if( i2c_IsDeviceReady( 1 ) != NFCTAG_OK )
- {
- return NFCTAG_TIMEOUT;
- }
-
- /* M24LR can write a maximum of 4 bytes in EEPROM per i2c communication */
- do
- {
- /* To write data in M24LR, data must be aligned on the same row in memory */
- /* align_mem_offset is used to copy only Bytes that are on the same row in memory */
- if( bytes_to_write > M24LR_PAGEWRITE_NBBYTE )
- {
- /* DataSize higher than max page write, copy data by page */
- align_mem_offset = M24LR_PAGEWRITE_NBBYTE - (mem_addr % M24LR_PAGEWRITE_NBBYTE);
- }
- else
- {
- /* DataSize lower or equal to max page write, copy only last bytes */
- align_mem_offset = bytes_to_write;
- }
- /* Write align_mem_offset bytes in register */
- // status = M24lr_IO_MemWrite( pdata_index, M24LR_ADDR_SYST_I2C, mem_addr, align_mem_offset );
- status = dev_I2C.i2c_write(pdata_index, i2c_address_syst, mem_addr, align_mem_offset);
- /* update index, dest address, size for next write */
- pdata_index += align_mem_offset;
- mem_addr += align_mem_offset;
- bytes_to_write -= align_mem_offset;
- /* Poll until EEPROM is available */
- while( i2c_IsDeviceReady( 1 ) != NFCTAG_OK ) {};
- }
- while( ( bytes_to_write > 0 ) && ( status == NFCTAG_OK ) );
-
- if ( status == 0 )
- return NFCTAG_OK;
- else
- return NFCTAG_ERROR;
-}
-
-/**
- * @brief Read M24LR UID
- * @param UID : M24LR_UID pointer of the UID to store
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_ReadUID( M24LR_UID * const pUid )
-{
- uint8_t areg_value[8];
- uint8_t i;
- NFCTAG_StatusTypeDef status;
-
- /* Read actual value of UID registers */
- status = i2c_ReadRegister( areg_value, M24LR_UID_REG, 8 );
- if( status != NFCTAG_OK )
- {
- return status;
- }
-
- /* Store information in 2 WORD */
- pUid->MSB_UID = 0;
-
- for( i = 0; i < 4; i++ )
- {
- pUid->MSB_UID = (pUid->MSB_UID << 8) | areg_value[7 - i];
- }
-
- pUid->LSB_UID = 0;
-
- for( i = 0; i < 4; i++ )
- {
- pUid->LSB_UID = (pUid->LSB_UID << 8) | areg_value[3 - i];
- }
-
- return NFCTAG_OK;
-}
-
-/**
- * @brief Read DSFID
- * @param pData : pointer of the DSFID to store
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_ReadDSFID( uint8_t * const pDsfid )
-{
- /* Read actual value of DSFID register */
- return i2c_ReadRegister( pDsfid, M24LR_DSFID_REG, 1 );
-}
-
-/**
- * @brief Read AFI
- * @param pData : pointer of the AFI to store
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_ReadAFI( uint8_t * const pAfi )
-{
- /* Read actual value of AFI register */
- return i2c_ReadRegister( pAfi, M24LR_AFI_REG, 1 );
-}
-
-/**
- * @brief Read status of I2C Lock Sectors
- * @param Lock_sector : M24LR_Lock_Sectors pointer of the I2c lock sector status to store
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_ReadI2CLockSector( M24LR_Lock_Sectors * const pLock_sector )
-{
- uint8_t areg_value[8];
- NFCTAG_StatusTypeDef status;
-
- /* Read actual value of I2c Write Lock registers */
- status = i2c_ReadRegister( areg_value, M24LR_LOCK_REG, 8 );
- if( status != NFCTAG_OK )
- {
- return status;
- }
-
- /* Dispatch information to corresponding struct member */
- pLock_sector->sectors_63_56 = areg_value[7];
- pLock_sector->sectors_55_48 = areg_value[6];
- pLock_sector->sectors_47_40 = areg_value[5];
- pLock_sector->sectors_39_32 = areg_value[4];
- pLock_sector->sectors_31_24 = areg_value[3];
- pLock_sector->sectors_23_16 = areg_value[2];
- pLock_sector->sectors_15_8 = areg_value[1];
- pLock_sector->sectors_7_0 = areg_value[0];
-
- return NFCTAG_OK;
-}
-
-/**
- * @brief Lock I2C write on an EEPROM Sectors
- * @brief Need a presentation of I2C Password to be effective
- * @param Sector : EEPROM Sector number to lock (between 0 to 63)
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_I2CLockSector( const uint8_t Sector )
-{
- NFCTAG_StatusTypeDef status;
- uint8_t reg_value = 0;
- uint16_t sector_write_lock_addr;
-
- /* Compute register address */
- sector_write_lock_addr = M24LR_LOCK_REG | (Sector >> 3);
-
- /* Read actual WriteLockStatus */
- status = i2c_ReadRegister( ®_value, sector_write_lock_addr, 1 );
- if( status != NFCTAG_OK )
- {
- return status;
- }
-
- /* Compute and update new WriteLockStatus */
- reg_value |= 1 << ( Sector % 8 );
-
- /* Write WriteLock register */
- return i2c_WriteRegister( ®_value, sector_write_lock_addr, 1 );
-}
-
-/**
- * @brief UnLock I2C write on a EEPROM Sector
- * @brief Need an presentation of I2C Password to be effective
- * @param pSector : EEPROM Sector number to unlock (between 0 to 63)
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_I2CUnlockSector( const uint8_t Sector )
-{
- NFCTAG_StatusTypeDef status;
- uint8_t reg_value = 0;
- uint16_t sector_write_lock_addr;
-
- /* Compute register address */
- sector_write_lock_addr = M24LR_LOCK_REG | (Sector >> 3);
-
- /* Read actual WriteLockStatus */
- status = i2c_ReadRegister( ®_value, sector_write_lock_addr, 1 );
- if( status != NFCTAG_OK )
- {
- return status;
- }
-
- /* Compute and update new WriteLockStatus */
- reg_value &= ~( 1 << ( Sector % 8 ) );
-
- /* Write WriteLock register */
- return i2c_WriteRegister( ®_value, sector_write_lock_addr, 1 );
-}
-
-/**
- * @brief Present I2C password, authorize I2C write
- * @param PassWord : Password value on 32bits
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_PresentI2CPassword( const uint32_t PassWord )
-{
- uint8_t ai2c_message[9] = {0};
- uint8_t i;
-
- /* Build I2C Message with Password + Validation code 0x09 + Password */
- ai2c_message[4] = 0x09;
- i = 0;
- while( i < 4 )
- {
- ai2c_message[i] = ( PassWord >> (i * 8) ) & 0xFF;
- ai2c_message[i + 5] = ( PassWord >> (i * 8) ) & 0xFF;
- i++;
- };
-
- /* Present password to M24LR */
- return i2c_WriteRegister( ai2c_message, M24LR_I2C_PWD_REG, 9 );
-}
-
-/**
- * @brief Write new I2C password
- * @brief Need to present good I2CPassword before using this function
- * @param PassWord : new I2C PassWord value on 32bits
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_WriteI2CPassword( const uint32_t PassWord )
-{
- uint8_t ai2c_message[9] = {0};
- uint8_t i;
-
- /* Build I2C Message with Password + Validation code 0x07 + Password */
- ai2c_message[4] = 0x07;
- i = 0;
- while( i < 4 )
- {
- ai2c_message[i] = ( PassWord >> (i * 8) ) & 0xFF;
- ai2c_message[i + 5] = ( PassWord >> (i * 8) ) & 0xFF;
- i++;
- };
-
- /* Write Password to register */
- return i2c_WriteRegister( ai2c_message, M24LR_I2C_PWD_REG, 9 );
-}
-
-/**
- * @brief Read SectorSecurityStatus (defining RF access allowed)
- * @param SectorNb : Sector number to get RF security status
- * @param pData : M24LR_SECTOR_SEC pointer of the data to store
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_ReadSSSx( const uint8_t SectorNb, M24LR_SECTOR_SEC * const pData )
-{
- uint8_t reg_value;
- NFCTAG_StatusTypeDef status;
- uint16_t sector_security_addr;
-
- /* Compute Sector Security register address */
- sector_security_addr = M24LR_SSS_REG | SectorNb;
-
- /* Read actual value of SectorSecurityStatus register */
- status = i2c_ReadRegister( ®_value, sector_security_addr, 1 );
- if( status != NFCTAG_OK )
- {
- return status;
- }
-
- /* Extract Sector Security Status configuration */
- pData->SectorLock = reg_value & M24LR_SSS_LOCK_MASK;
- pData->RW_Protection = (reg_value & M24LR_SSS_RW_MASK) >> 1;
- pData->PassCtrl = (reg_value & M24LR_SSS_PASSCTRL_MASK) >> 3;
-
- return NFCTAG_OK;
-}
-
-/**
- * @brief Write SectorSecurityStatus (defining RF access allowed)
- * @brief Need an presentation of I2C Password to be effective
- * @param SectorNb : Sector number to set RF security
- * @param pData : M24LR_SECTOR_SEC pointer of the data to write
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_WriteSSSx( const uint8_t SectorNb, const M24LR_SECTOR_SEC * const pData )
-{
- uint8_t reg_value;
- uint16_t sector_security_addr;
-
- /* Compute Sector Security register address */
- sector_security_addr = M24LR_SSS_REG | SectorNb;
-
- /* Update Sector Security Status */
- reg_value = (pData->PassCtrl << 3) & M24LR_SSS_PASSCTRL_MASK;
- reg_value |= ((pData->RW_Protection << 1) & M24LR_SSS_RW_MASK);
- reg_value |= (pData->SectorLock & M24LR_SSS_LOCK_MASK);
-
- /* Write SectorSecurityStatus register */
- return i2c_WriteRegister( ®_value, sector_security_addr, 1 );
-}
-
-/**
- * @brief Read Memory Size info
- * @param SizeInfo : M24LR_Mem_Size pointer of the data to store
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_ReadMemSize( M24LR_Mem_Size * const pSizeInfo )
-{
- uint8_t areg_value[3];
- NFCTAG_StatusTypeDef status;
-
- /* Read actual value of Mem_Size register */
- status = i2c_ReadRegister( areg_value, M24LR_MEMSIZE_REG, 3 );
- if( status != NFCTAG_OK )
- {
- return status;
- }
-
- /* Extract Mem information */
- pSizeInfo->BlockSize = areg_value[2];
- pSizeInfo->Mem_Size = areg_value[1];
- pSizeInfo->Mem_Size = (pSizeInfo->Mem_Size << 8) | areg_value[0];
-
- return NFCTAG_OK;
-}
-
-/**
- * @brief Get GPO Configuration status
- * @param Rf_Wip_Busy : M24LR_GPO_STATUS pointer of the data to store
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_GetRF_WIP_BUSY( M24LR_GPO_STATUS * const pRf_Wip_Busy )
-{
- uint8_t reg_value;
- NFCTAG_StatusTypeDef status;
-
- /* Read actual value of CFG register */
- status = i2c_ReadRegister( ®_value, M24LR_CFG_REG, 1 );
- if( status != NFCTAG_OK )
- {
- return status;
- }
-
- /* Extract RF WIP/BUSY information */
- if( (reg_value & M24LR_CFG_WIPBUSY_MASK) == M24LR_CFG_WIPBUSY_MASK )
- {
- *pRf_Wip_Busy = M24LR_GPO_WIP;
- }
- else
- {
- *pRf_Wip_Busy = M24LR_GPO_BUSY;
- }
-
- return NFCTAG_OK;
-}
-
-/**
- * @brief Configure GPO as RF Busy
- * @param None
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_SetRFBUSY( void )
-{
- uint8_t reg_value;
- int status;
-
- /* Read actual value of CFG register */
- status = dev_I2C.i2c_read( ®_value, i2c_address_syst, (uint16_t)M24LR_CFG_REG, 1 );
- if( status != 0 )
- {
- return NFCTAG_TIMEOUT;
- }
-
- /* Update register value for BUSY configuration */
- reg_value &= !M24LR_CFG_WIPBUSY_MASK;
-
- /* Write CFG register */
- status = i2c_WriteRegister( ®_value, M24LR_CFG_REG, 1 );
- if ( status == 0 )
- return NFCTAG_OK;
- else
- return NFCTAG_TIMEOUT;
-}
-
-
-/**
- * @brief Get Energy harvesting mode status
- * @param EH_mode : M24LR_EH_MODE_STATUS pointer of the data to store
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_Read_EH_mode( M24LR_EH_MODE_STATUS * const pEH_mode )
-{
- uint8_t reg_value;
- NFCTAG_StatusTypeDef status;
-
- /* Read actual value of CFG register */
- status = i2c_ReadRegister( ®_value, M24LR_CFG_REG, 1 );
- if( status != NFCTAG_OK )
- {
- return status;
- }
-
- /* Extract EH_mode configuration */
- if( (reg_value & M24LR_CFG_EHMODE_MASK) == M24LR_CFG_EHMODE_MASK )
- {
- *pEH_mode = M24LR_EH_MODE_DISABLE;
- }
- else
- {
- *pEH_mode = M24LR_EH_MODE_ENABLE;
- }
-
- return NFCTAG_OK;
-}
-
-/**
- * @brief Enable Energy harvesting mode
- * @param None
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_Enable_EH_mode( void )
-{
- uint8_t reg_value;
- NFCTAG_StatusTypeDef status;
-
- /* Read actual value of CFG register */
- status = i2c_ReadRegister( ®_value, M24LR_CFG_REG, 1 );
- if( status != NFCTAG_OK )
- {
- return status;
- }
-
- /* Update EH_mode */
- reg_value &= ~M24LR_CFG_EHMODE_MASK;
-
- /* Write CFG register */
- return i2c_WriteRegister( ®_value, M24LR_CFG_REG, 1 );
-}
-
-/**
- * @brief Disable Energy harvesting mode
- * @param None
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_Disable_EH_mode( void )
-{
- uint8_t reg_value;
- NFCTAG_StatusTypeDef status;
-
- /* Read actual value of CFG register */
- status = i2c_ReadRegister( ®_value, M24LR_CFG_REG, 1 );
- if( status != NFCTAG_OK )
- {
- return status;
- }
-
- /* Update EH_mode */
- reg_value |= M24LR_CFG_EHMODE_MASK;
-
- /* Write CFG register */
- return i2c_WriteRegister( ®_value, M24LR_CFG_REG, 1 );
-}
-
-/**
- * @brief Read Vout sink current configuration status for Energy Harvesting
- * @param EH_Cfg : M24LR_EH_CFG_VOUT pointer of the data to store
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_ReadEH_Cfg( M24LR_EH_CFG_VOUT * const pEH_Cfg )
-{
- uint8_t reg_value;
- NFCTAG_StatusTypeDef status;
-
- /* Read actual value of CFG register */
- status = i2c_ReadRegister( ®_value, M24LR_CFG_REG, 1 );
- if( status != NFCTAG_OK )
- {
- return status;
- }
-
- /* Extract Vout configuration for EH information */
- reg_value &= (M24LR_CFG_EHCFG1_MASK | M24LR_CFG_EHCFG0_MASK);
- switch( reg_value )
- {
- case 0:
- *pEH_Cfg = M24LR_EH_Cfg_6MA;
- break;
- case 1:
- *pEH_Cfg = M24LR_EH_Cfg_3MA;
- break;
- case 2:
- *pEH_Cfg = M24LR_EH_Cfg_1MA;
- break;
- case 3:
- *pEH_Cfg = M24LR_EH_Cfg_300UA;
- break;
-
- default:
- *pEH_Cfg = M24LR_EH_Cfg_6MA;
- }
-
- return NFCTAG_OK;
-}
-
-/**
- * @brief Write Vout sink current configuration status for Energy Harvesting
- * @param EH_Cfg : M24LR_EH_CFG_VOUT value to configure Vout
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_WriteEH_Cfg( const M24LR_EH_CFG_VOUT EH_Cfg )
-{
- uint8_t reg_value;
- NFCTAG_StatusTypeDef status;
-
- /* Read actual value of CFG register */
- status = i2c_ReadRegister( ®_value, M24LR_CFG_REG, 1 );
- if( status != NFCTAG_OK )
- {
- return status;
- }
-
- /* Update Vout configuration */
- reg_value &= ~(M24LR_CFG_EHCFG1_MASK | M24LR_CFG_EHCFG0_MASK);
- reg_value |= EH_Cfg;
-
- /* Write CFG register */
- return i2c_WriteRegister( ®_value, M24LR_CFG_REG, 1 );
-}
-
-/**
- * @brief Get Energy Harvesting status
- * @param EH_Val : M24LR_EH_STATUS pointer of the data to store
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_GetEH( M24LR_EH_STATUS * const pEH_Val )
-{
- uint8_t reg_value;
- NFCTAG_StatusTypeDef status;
-
- /* Read actual value of CTRL register */
- status = i2c_ReadRegister( ®_value, M24LR_CTRL_REG, 1 );
- if( status != NFCTAG_OK )
- {
- return status;
- }
-
- /* Extract EH information */
- if( (reg_value & M24LR_CTRL_EHEN_MASK) == M24LR_CTRL_EHEN_MASK )
- {
- *pEH_Val = M24LR_EH_ENABLE;
- }
- else
- {
- *pEH_Val = M24LR_EH_DISABLE;
- }
-
- return NFCTAG_OK;
-}
-
-/**
- * @brief Enable Energy Harvesting
- * @param None
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_SetEH( void )
-{
- uint8_t reg_value;
- NFCTAG_StatusTypeDef status;
-
- /* Read actual value of CTRL register */
- status = i2c_ReadRegister( ®_value, M24LR_CTRL_REG, 1 );
- if( status != NFCTAG_OK )
- {
- return status;
- }
-
- /* Update EH configuration */
- reg_value |= M24LR_CTRL_EHEN_MASK;
-
- /* Write CTRL Register */
- return i2c_WriteRegister( ®_value, M24LR_CTRL_REG, 1 );
-}
-
-/**
- * @brief Disable Energy Harvesting
- * @param None
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_ResetEH( void )
-{
- uint8_t reg_value;
- NFCTAG_StatusTypeDef status;
-
- /* Read actual value of CTRL register */
- status = i2c_ReadRegister( ®_value, M24LR_CTRL_REG, 1 );
- if( status != NFCTAG_OK )
- {
- return status;
- }
-
- /* Update EH configuration */
- reg_value &= ~M24LR_CTRL_EHEN_MASK;
-
- /* Write CTRL register */
- return i2c_WriteRegister( ®_value, M24LR_CTRL_REG, 1 );
-}
-
-/**
- * @brief Check if RF Field is present in front of M24LR
- * @param pRF_Field : M24LR_FIELD_STATUS pointer of the data to store
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_GetRFField( M24LR_FIELD_STATUS * const pRF_Field )
-{
- NFCTAG_StatusTypeDef status;
- uint8_t reg_value = 0;
-
- /* Read actual value of CTRL register */
- status = i2c_ReadRegister( ®_value, M24LR_CTRL_REG, 1 );
-
- /* Extract RF Field information */
- if( status == NFCTAG_OK )
- {
- if( (reg_value & M24LR_CTRL_FIELD_MASK) == M24LR_CTRL_FIELD_MASK )
- {
- *pRF_Field = M24LR_FIELD_ON;
- }
- else
- {
- *pRF_Field = M24LR_FIELD_OFF;
- }
-
- return NFCTAG_OK;
- }
-
- return status;
-}
-
-/**
- * @brief Check if Write Timing is good
- * @param pT_Prog : M24LR_T_PROG_STATUS pointer of the data to store
- * @retval NFCTAG enum status
- */
-NFCTAG_StatusTypeDef M24LR::i2c_GetTProg( M24LR_T_PROG_STATUS * const pT_Prog )
-{
- NFCTAG_StatusTypeDef status;
- uint8_t reg_value = 0;
-
- /* Read actual value of CTRL register */
- status = i2c_ReadRegister( ®_value, M24LR_CTRL_REG, 1 );
-
- /* Extract T-Prog information */
- if( status == NFCTAG_OK )
- {
- if( (reg_value & M24LR_CTRL_TPROG_MASK) == M24LR_CTRL_TPROG_MASK )
- {
- *pT_Prog = M24LR_T_PROG_OK;
- }
- else
- {
- *pT_Prog = M24LR_T_PROG_NO;
- }
-
- return NFCTAG_OK;
- }
- else
- return status;
-}
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/******************* (C) COPYRIGHT 2016 STMicroelectronics *****END OF FILE****/
--- a/m24lr/m24lr.h Mon Oct 03 11:57:23 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,294 +0,0 @@
-/**
- ******************************************************************************
- * @file m24lr.h
- * @author AMG Central Lab
- * @version V1.0.0
- * @date 30 Aug 2016
- * @brief header file for M24LR driver .
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT(c) 2016 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 __M24LR_H
-#define __M24LR_H
-
-#include "common.h"
-#include "DevI2C.h"
-#include "Nfc.h"
-#include "NDefNfcTag.h"
-#include "NDefNfcTagM24LR.h"
-
-//#include "lib_NDEF_URI.h"
- /* Exported constants --------------------------------------------------------*/
-/** @defgroup M24LR_Exported_Constants
- * @{
- */
-#define I_AM_M24LR04 0x5A
-#define I_AM_M24LR16 0x4E
-#define I_AM_M24LR64 0x5E
-
-#ifndef NULL
-#define NULL (void *) 0
-#endif
-
-#define M24LR_PAGEWRITE_NBBYTE 4
-
-#define M24LR_ADDR_DATA_I2C 0xA6
-#define M24LR_ADDR_SYST_I2C 0xAE
-#define M24LR_I2C_TIMEOUT 200 /* I2C Time out (ms), this is the maximum time needed by M24LR to complete any command */
-
-#define M24LR_IT_BUSY_MASK 0x01
-#define M24LR_IT_WIP_MASK 0x02
-
-/* Registers address */
-#define M24LR_SSS_REG 0x0000
-#define M24LR_LOCK_REG 0x0800
-#define M24LR_I2C_PWD_REG 0x0900
-#define M24LR_CFG_REG 0x0910
-#define M24LR_AFI_REG 0x0912
-#define M24LR_DSFID_REG 0x0913
-#define M24LR_UID_REG 0x0914
-#define M24LR_ICREF_REG 0x091C
-#define M24LR_MEMSIZE_REG 0x091D
-#define M24LR_CTRL_REG 0x0920
-
-/* Registers mask */
-#define M24LR_SSS_LOCK_MASK 0x01
-#define M24LR_SSS_RW_MASK 0x06
-#define M24LR_SSS_PASSCTRL_MASK 0x18
-#define M24LR_LOCK_MASK 0x0F
-
-#define M24LR_CFG_EHCFG0_MASK 0x01
-#define M24LR_CFG_EHCFG1_MASK 0x02
-#define M24LR_CFG_EHMODE_MASK 0x04
-#define M24LR_CFG_WIPBUSY_MASK 0x08
-
-#define M24LR_CTRL_EHEN_MASK 0x01
-#define M24LR_CTRL_FIELD_MASK 0x02
-#define M24LR_CTRL_TPROG_MASK 0x80
-
-
-
-/**
- * @brief M24LR VOUT Configuration enumerator definition
- */
-typedef enum
-{
- M24LR_EH_Cfg_6MA = 0,
- M24LR_EH_Cfg_3MA,
- M24LR_EH_Cfg_1MA,
- M24LR_EH_Cfg_300UA
-} M24LR_EH_CFG_VOUT;
-
-/**
- * @brief M24LR FIELD status enumerator definition
- */
-typedef enum
-{
- M24LR_FIELD_OFF = 0,
- M24LR_FIELD_ON
-} M24LR_FIELD_STATUS;
-
-/**
- * @brief M24LR TT-PROG status enumerator definition
- */
-typedef enum
-{
- M24LR_T_PROG_NO = 0,
- M24LR_T_PROG_OK
-} M24LR_T_PROG_STATUS;
-
-/**
- * @brief M24LR Energy Harvesting status enumerator definition
- */
-typedef enum
-{
- M24LR_EH_DISABLE = 0,
- M24LR_EH_ENABLE
-} M24LR_EH_STATUS;
-
-/**
- * @brief M24LR Energy Harvesting mode enumerator definition
- */
-typedef enum
-{
- M24LR_EH_MODE_ENABLE = 0,
- M24LR_EH_MODE_DISABLE
-} M24LR_EH_MODE_STATUS;
-
-/**
- * @brief M24LR GPO status enumerator definition
- */
-typedef enum
-{
- M24LR_GPO_BUSY = 0,
- M24LR_GPO_WIP
-} M24LR_GPO_STATUS;
-
-/**
- * @brief M24LR Memory information structure definition
- */
-typedef struct
-{
- uint8_t BlockSize;
- uint16_t Mem_Size;
-} M24LR_Mem_Size;
-
-/**
- * @brief M24LR I2C Write Lock register structure definition
- */
-typedef struct
-{
- uint8_t sectors_7_0;
- uint8_t sectors_15_8;
- uint8_t sectors_23_16;
- uint8_t sectors_31_24;
- uint8_t sectors_39_32;
- uint8_t sectors_47_40;
- uint8_t sectors_55_48;
- uint8_t sectors_63_56;
-} M24LR_Lock_Sectors;
-
-/**
- * @brief M24LR UID information structure definition
- */
-typedef struct
-{
- uint32_t MSB_UID;
- uint32_t LSB_UID;
-} M24LR_UID;
-
-/**
- * @brief M24LR Sector Security register structure definition
- */
-typedef struct
-{
- uint8_t SectorLock;
- uint8_t RW_Protection;
- uint8_t PassCtrl;
-} M24LR_SECTOR_SEC;
-
-
- /**
- * @}
- */
-
-class M24LR : public Nfc {
-public:
- NFCTAG_StatusTypeDef i2c_Init( void );
- NFCTAG_StatusTypeDef i2c_ReadID( uint8_t * const pICRef );
- NFCTAG_StatusTypeDef i2c_IsDeviceReady( const uint32_t Trials );
- NFCTAG_StatusTypeDef i2c_ConfigureGPO( const uint16_t ITConf );
- NFCTAG_StatusTypeDef i2c_GetGPOStatus( uint16_t * const pGPOStatus );
- NFCTAG_StatusTypeDef i2c_ReadData( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte );
- NFCTAG_StatusTypeDef i2c_WriteData( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte );
- NFCTAG_StatusTypeDef i2c_ReadRegister( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte );
- NFCTAG_StatusTypeDef i2c_WriteRegister( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte );
-
-
- /* Extended Functions */
- NFCTAG_StatusTypeDef i2c_ReadUID( M24LR_UID * const pUid );
- NFCTAG_StatusTypeDef i2c_ReadDSFID( uint8_t * const pDsfid );
- NFCTAG_StatusTypeDef i2c_ReadAFI( uint8_t * const pAfi );
- NFCTAG_StatusTypeDef i2c_ReadI2CLockSector( M24LR_Lock_Sectors * const pLock_sector );
- NFCTAG_StatusTypeDef i2c_I2CLockSector( const uint8_t Sector );
- NFCTAG_StatusTypeDef i2c_I2CUnlockSector( const uint8_t Sector );
- NFCTAG_StatusTypeDef i2c_PresentI2CPassword( const uint32_t PassWord );
- NFCTAG_StatusTypeDef i2c_WriteI2CPassword( const uint32_t PassWord );
- NFCTAG_StatusTypeDef i2c_ReadSSSx( const uint8_t SectorNb, M24LR_SECTOR_SEC * const pData );
- NFCTAG_StatusTypeDef i2c_WriteSSSx( const uint8_t SectorNb, const M24LR_SECTOR_SEC * const pData );
- NFCTAG_StatusTypeDef i2c_ReadMemSize( M24LR_Mem_Size * const pSizeInfo );
- NFCTAG_StatusTypeDef i2c_GetRF_WIP_BUSY( M24LR_GPO_STATUS * const pRf_Wip_Busy );
- NFCTAG_StatusTypeDef i2c_SetRFBUSY( void );
- NFCTAG_StatusTypeDef i2c_SetRFWIP( void );
- NFCTAG_StatusTypeDef i2c_Read_EH_mode( M24LR_EH_MODE_STATUS * const pEH_mode );
- NFCTAG_StatusTypeDef i2c_Enable_EH_mode( void );
- NFCTAG_StatusTypeDef i2c_Disable_EH_mode( void );
- NFCTAG_StatusTypeDef i2c_ReadEH_Cfg( M24LR_EH_CFG_VOUT * const pEH_Cfg );
- NFCTAG_StatusTypeDef i2c_WriteEH_Cfg( const M24LR_EH_CFG_VOUT EH_Cfg );
- NFCTAG_StatusTypeDef i2c_GetEH( M24LR_EH_STATUS * const pEH_Val );
- NFCTAG_StatusTypeDef i2c_SetEH( void );
- NFCTAG_StatusTypeDef i2c_ResetEH( void );
- NFCTAG_StatusTypeDef i2c_GetRFField( M24LR_FIELD_STATUS * const pRF_Field );
- NFCTAG_StatusTypeDef i2c_GetTProg( M24LR_T_PROG_STATUS * const pT_Prog );
-
- void Enable_EnergyHarvesting( void );
- NFCTAG_StatusTypeDef Initialization( void );
-
- virtual int ReadBinary(uint16_t Offset, uint8_t NbByteToRead,
- uint8_t *pBufferRead) {
- return (NFC_StatusTypeDef) i2c_ReadData( pBufferRead, Offset, NbByteToRead );
-
- }
-
- virtual int UpdateBinary(uint16_t Offset,
- uint8_t NbByteToWrite,uint8_t *pDataToWrite) {
- return (NFC_StatusTypeDef) i2c_WriteData( pDataToWrite, Offset, NbByteToWrite );
- }
-
- M24LR(uint8_t const address, uint8_t const addressData, DevI2C &devI2C ):
- NDefTagUtil(*this), i2c_address_syst(address), i2c_address_data(addressData), dev_I2C(devI2C) {}
-
-
- NDefLib::NDefNfcTag& getNDefTag(){
- return NDefTagUtil;
- }
-
-
- virtual int Init(void *ptr) {
- (void)ptr;
- return (NFC_StatusTypeDef) i2c_Init();
- }
-
- virtual int ReadID(uint8_t *id) {
- return (NFC_StatusTypeDef) i2c_ReadID(id);
- }
- private:
- static uint8_t NfctagInitialized;
-
-
- /*
- * Object implementing the interface to use the NDefLib.
- */
- NDefNfcTagM24LR NDefTagUtil;
-
- uint8_t i2c_address_syst;
- uint8_t i2c_address_data;
- DevI2C dev_I2C;
-};
-
-
-
-
-#endif /* __M24LR_H */
-
-
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

X-NUCLEO-NFC02A1 Dynamic NFC tag