Fork of the GitHub version
Revision 0:cf62b690f57c, committed 2019-11-14
- Comitter:
- DiegoOstuni
- Date:
- Thu Nov 14 10:30:13 2019 +0000
- Commit message:
- Files added
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Thu Nov 14 10:30:13 2019 +0000 @@ -0,0 +1,52 @@ +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LICENSE Thu Nov 14 10:30:13 2019 +0000 @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Thu Nov 14 10:30:13 2019 +0000 @@ -0,0 +1,4 @@ +# BSP +BSP is a library for STMicroelectronics X-NUCLEO-NFC04A1. +# Overview +This library contains all the functions to read and write the memory of the chip, to initialize some settings of the device or the I2C Channel.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x_nucleo_nfc04a1.cpp Thu Nov 14 10:30:13 2019 +0000 @@ -0,0 +1,362 @@ +/** + ****************************************************************************** + * @file x_nucleo_nfc04a1.c + * @author MMY Application Team + * @version $Revision: 3351 $ + * @date $Date: 2017-01-25 17:28:08 +0100 (Wed, 25 Jan 2017) $ + * @brief This file provides nfc04a1 specific functions + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2017 STMicroelectronics</center></h2> + * + * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/myliberty + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, + * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "x_nucleo_nfc04a1.h" +//#include "x_nucleo_nfc04a1_nfctag.h" +//#include "mbed.h" +//#include "PinNames.h" +#include "time.h" + +/* +#if define +define +#endif +*/ + + +/*Stream *_serial = NULL; +#if defined(ARDUINO_SAM_DUE) +TwoWire *_wire = &Wire1; +#else +TwoWire *_wire = &Wire; +#endif +* @addtogroup BSP + * @{ + */ + +/** @defgroup X_NUCLEO_NFC04A1 + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private defines -----------------------------------------------------------*/ +/* Private macros ------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Global variables ----------------------------------------------------------*/ +/** @defgroup X_NUCLEO_NFC04A1_Global_Variables + * @{ + */ +//uint8_t NFC04A1_Led[3] = { 1 , 2 , 3 }; + +/** + * @} + */ + +/* Private function prototypes -----------------------------------------------*/ + +NFCTAG_StatusTypeDef ST25DV_IO_Init( I2C* mi2cChannel, DigitalOut *mLPD ); +NFCTAG_StatusTypeDef ST25DV_IO_MemWrite( const uint8_t * const pData, const uint8_t DevAddr, const uint16_t TarAddr, const uint16_t Size, I2C* mi2cChannel ); +NFCTAG_StatusTypeDef ST25DV_IO_MemRead( uint8_t * const pData, const uint8_t DevAddr, const uint16_t TarAddr, const uint16_t Size, I2C* mi2cChannel ); +NFCTAG_StatusTypeDef ST25DV_IO_Read( uint8_t * const pData, const uint8_t DevAddr, const uint16_t Size, I2C* mi2cChannel ); +NFCTAG_StatusTypeDef ST25DV_IO_IsDeviceReady( const uint8_t DevAddr, const uint32_t Trials, I2C* mi2cChannel); +NFCTAG_StatusTypeDef NFCTAG_ConvertStatus(uint8_t ret); + + +/* Functions Definition ------------------------------------------------------*/ +/** @defgroup X_NUCLEO_NFC04A1_Public_Functions + * @{ + */ + + + +/** + * @brief Toggles the selected LED + * @param led : Specifies the Led to be toggled + * @retval None + */ +void NFC04A1_LED_Toggle( DigitalOut* led) +{ + *led = !(*led); +} + + + +/** + * @brief This function get the GPIO value through GPIO + * @param None + * @retval HAL GPIO pin status + */ +DigitalOut NFC04A1_GPO_ReadPin( DigitalOut *mMISO ) +{ + return *mMISO; +} + +/** + * @brief This function initialize the GPIO to manage the NFCTAG LPD pin + * @param None + * @retval None + */ + +void NFC04A1_LPD_Init( DigitalOut *mLPD ) +{ + *mLPD = 0; +} + +/** + * @brief This function get the GPIO value through GPIO + * @param None + * @retval HAL GPIO pin status + */ +uint8_t NFC04A1_LPD_ReadPin( DigitalOut *mLPD ) +{ + return mLPD -> read(); +} + +/** + * @brief This function get the GPIO value through GPIO + * @param None + * @retval HAL GPIO pin status + */ +void NFC04A1_LPD_WritePin( uint8_t LpdPinState, DigitalOut *mLPD ) +{ + mLPD -> write( LpdPinState ); +} + +/** + * @brief This function select the i2cChannel1 speed to communicate with NFCTAG + * @param i2cChannelspeedchoice Number from 0 to 5 to select i2cChannel speed + * @param mi2cChannel : I2C channel + * @retval HAL GPIO pin status + */ +void NFC04A1_Selecti2cSpeed( uint8_t i2cspeedchoice, I2C* mi2cChannel) +{ + + switch( i2cspeedchoice ) + { + case 0: + + mi2cChannel -> frequency(10000); + break; + + case 1: + + mi2cChannel -> frequency(100000); + break; + + case 2: + + mi2cChannel -> frequency(200000); + break; + + case 3: + + mi2cChannel -> frequency(400000); + break; + + case 4: + + mi2cChannel -> frequency(800000); + break; + + case 5: + + mi2cChannel -> frequency(1000000); + break; + + default: + + mi2cChannel -> frequency(1000000); + break; + } + +} + +/** + * @} + */ + +/** @defgroup X_NUCLEO_NFC04A1_Private_Functions + * @{ + */ +/******************************** LINK EEPROM COMPONENT *****************************/ + +/** + * @brief Initializes peripherals used by the i2cChannel NFCTAG driver + * @param mi2cChannel : I2C channel + * @param mLPD + * @retval NFCTAG enum status + */ +NFCTAG_StatusTypeDef ST25DV_IO_Init( I2C* mi2cChannel, DigitalOut *mLPD ) +{ + + + NFC04A1_LPD_Init( mLPD ); + + NFC04A1_Selecti2cSpeed(3, mi2cChannel); + + return NFCTAG_OK; +} + +/** + * @brief Write data, at specific address, through i2c to the ST25DV + * @param pData: pointer to the data to write + * @param DevAddr : Target device address + * @param TarAddr : i2c data memory address to write + * @param Size : Size in bytes of the value to be written + * @param mi2cChannel : I2C channel + * @retval NFCTAG enum status + */ +NFCTAG_StatusTypeDef ST25DV_IO_MemWrite( const uint8_t * const pData, const uint8_t DevAddr, const uint16_t TarAddr, const uint16_t Size, I2C* mi2cChannel ) +{ + + uint8_t ret = 4; + + uint8_t Addr = DevAddr; + + + uint8_t buffer[2]; + buffer[0] = (uint8_t) (TarAddr>>8); + buffer[1] = (uint8_t) (TarAddr&0xFF); + + + char * pDataChar = (char*) pData; + + + ret = mi2cChannel -> write(Addr, (const char*)buffer, 2 , true); + + // Address is not OK + if(ret != 0) + return NFCTAG_ConvertStatus(ret); + + ret = mi2cChannel -> write(Addr, pDataChar, Size, false); + + return NFCTAG_ConvertStatus(ret); +} + + +/* + * @brief Reads data at a specific address from the NFCTAG. + * @param pData: pointer to store read data + * @param DevAddr : Target device address + * @param TarAddr : i2c data memory address to read + * @param Size : Size in bytes of the value to be read + * @param mi2cChannel : I2C channel + * @retval NFCTAG enum status + */ + +NFCTAG_StatusTypeDef ST25DV_IO_MemRead( uint8_t * const pData, const uint8_t DevAddr, const uint16_t TarAddr, const uint16_t Size, I2C* mi2cChannel ) +{ + + uint8_t ret = 4; + uint8_t Addr = DevAddr; + + uint8_t buffer[2]; + buffer[0] = (uint8_t) (TarAddr>>8); + buffer[1] = (uint8_t) (TarAddr&0xFF); + + ret = mi2cChannel -> write(Addr, (const char*)buffer , 2 , false); + + // Address is not OK + if(ret != 0) + return NFCTAG_ConvertStatus(ret); + + char * pDataChar = (char*) pData; + + ret = mi2cChannel -> read(DevAddr, pDataChar, Size, false ); + + return NFCTAG_ConvertStatus(ret); +} + +NFCTAG_StatusTypeDef NFCTAG_ConvertStatus(uint8_t ret) { + if (ret == 0) { + return NFCTAG_OK; + } else if ((ret == 2) || (ret == 3)) { + return NFCTAG_NACK; + } else { + return NFCTAG_ERROR; + } +} + + +/** + * @brief Reads data at current address from the NFCTAG. + * @param pData: pointer to store read data + * @param DevAddr : Target device address + * @param Size : Size in bytes of the value to be read + * @retval NFCTAG enum status + */ +NFCTAG_StatusTypeDef ST25DV_IO_Read( uint8_t * const pData, const uint8_t DevAddr, const uint16_t Size, I2C* mi2cChannel ) +{ + //this has to change( send addr then read) + int i = 0; + uint8_t ret = 4; + + char * pDataChar = (char*) pData; + uint8_t ReadAddr = DevAddr | 1u; + ret = mi2cChannel -> read(ReadAddr, pDataChar, 1, false ); + + +// Tell slave we need to read 1byte from the current register + while(mi2cChannel -> read( 0 ) != 0) { + pData[i++] = mi2cChannel -> read( 0 ); + + } + + + return NFCTAG_ConvertStatus( ret); +} + + +/** +* @brief Checks if target device is ready for communication +* @note This function is used with Memory devices +* @param DevAddr : Target device address +* @param mi2cChannel : I2C channel +* @retval NFCTAG enum status +*/ +NFCTAG_StatusTypeDef ST25DV_IO_IsDeviceReady( const uint8_t DevAddr, const uint32_t Trials, I2C* mi2cChannel) +{ + int ret = 4; + uint32_t count = 0; + + uint8_t Addr = DevAddr; + + + while ((count++ < Trials && ret) ) { + ret = mi2cChannel -> write(Addr, NULL, 0 , false); + } + return NFCTAG_ConvertStatus(ret); +} + + + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/******************* (C) COPYRIGHT 2017 STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x_nucleo_nfc04a1.h Thu Nov 14 10:30:13 2019 +0000 @@ -0,0 +1,128 @@ +/** + ****************************************************************************** + * @file x_nucleo_nfc04a1.h + * @author MMY Application Team + * @version $Revision: 3351 $ + * @date $Date: 2017-01-25 17:28:08 +0100 (Wed, 25 Jan 2017) $ + * @brief This file contains definitions for the x_nucleo_nfc04a1.c + * board specific functions. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2017 STMicroelectronics</center></h2> + * + * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/myliberty + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, + * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +#include "x_nucleo_nfc04a1_nfctag.h" +#include "x_nucleo_nfc04.h" +#include "mbed.h" +//#include "PinNames.h" + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __X_NUCLEO_NFC04A1_H +#define __X_NUCLEO_NFC04A1_H + + + +/* Includes ------------------------------------------------------------------*/ +//#include "ST25DV/st25dv.h" + +/** @addtogroup BSP + * @{ + */ + +/** @addtogroup X_NUCLEO_NFC04A1 + * @{ + */ + +/* Exported types ------------------------------------------------------------*/ +/** @defgroup X_NUCLEO_NFC04A1_Exported_Types + * @{ + */ +/** + * @brief NFC04A1 Led enumerator definition + */ +typedef enum +{ + GREEN_LED = 0, + BLUE_LED , + YELLOW_LED +}NFC04A1_Led_E; + +/** + * @brief NFC04A1 Ack Nack enumerator definition + */ +typedef enum +{ + I2CANSW_ACK = 0, + I2CANSW_NACK +}NFC04A1_I2CANSW_E; + + + +/** + * @brief NFC04A1 Led structure definition + */ + +typedef struct +{ + uint16_t NFC04A1_LED_PIN; +}NFC04A1_Led_TypeDef; + +/** + * @} + */ +/* Exported constants --------------------------------------------------------*/ +/** @defgroup X_NUCLEO_NFC04A1_Exported_Constants + * @{ + */ +#define ST25DV_I2C_SPEED NFC04A1_ST25DV_I2C_SPEED_1M +#define NFC04A1_I2C_TIMEOUT ST25DV_I2C_TIMEOUT +/** + * @} + */ + +/* External variables --------------------------------------------------------*/ +/* Exported macro ------------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ +/** @defgroup ST25DV_NUCLEO_Exported_Functions + * @{ + */ +void NFC04A1_LED_Toggle( DigitalOut* led); +DigitalOut NFC04A1_GPO_ReadPin( DigitalOut *mMISO ); +void NFC04A1_LPD_Init( DigitalOut *mLPD ); +uint8_t NFC04A1_LPD_ReadPin( void ); +void NFC04A1_LPD_WritePin( uint8_t LpdPinState, DigitalOut *mLPD ); +void NFC04A1_SelectI2cSpeed( uint8_t i2cspeedchoice, I2C* mi2cChannel); +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + + + +#endif /* __X_NUCLEO_NFC04A1_H */ + +/******************* (C) COPYRIGHT 2017 STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x_nucleo_nfc04a1_nfctag.cpp Thu Nov 14 10:30:13 2019 +0000 @@ -0,0 +1,316 @@ +/** + ****************************************************************************** + * @file x_nucleo_nfc04a1_nfctag.c + * @author MMY Application Team + * @version $Revision: 3306 $ + * @date $Date: 2017-01-13 11:18:15 +0100 (Fri, 13 Jan 2017) $ + * @brief This file provides a set of functions needed to manage a nfc dual + * interface eeprom memory. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2017 STMicroelectronics</center></h2> + * + * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/myliberty + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, + * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "x_nucleo_nfc04a1_nfctag.h" +//#include <cstddef.h> + +/** @addtogroup BSP + * @{ + */ + +/** @addtogroup X_NUCLEO_NFC04A1 + * @{ + */ + +/** @defgroup X_NUCLEO_NFC04A1_NFCTAG + * @{ + */ +/* Private typedef -----------------------------------------------------------*/ +/* Private defines -----------------------------------------------------------*/ +/** @defgroup X_NUCLEO_NFC04A1_NFCTAG_Private_Defines + * @{ + */ +/*#ifndef NULL +#define NULL (void *) 0 +#endif*/ +/** + * @} + */ + +/* Private macros ------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Global variables ----------------------------------------------------------*/ +/** @defgroup X_NUCLEO_NFC04A1_NFCTAG_Private_Variables + * @{ + */ +static NFCTAG_DrvTypeDef *Nfctag_Drv = NULL; +static uint8_t NfctagInitialized = 0; +/** + * @} + */ +/* Private function prototypes -----------------------------------------------*/ +/* Functions Definition ------------------------------------------------------*/ +/** @defgroup X_NUCLEO_NFC04A1_NFCTAG_Public_Functions + * @{ + */ +/** + * @brief Initializes peripherals used by the I2C NFCTAG driver + * @param None + * @retval NFCTAG enum status + */ +NFCTAG_StatusTypeDef BSP_NFCTAG_Init(I2C* mi2cChannel, DigitalOut * mLPD) +{ + uint8_t nfctag_id; + + if( !NfctagInitialized ) + { + /* ST25DV Init */ + if( St25Dv_i2c_Drv.Init(mi2cChannel, mLPD) != NFCTAG_OK ) + { + return NFCTAG_ERROR; + } + + + St25Dv_i2c_Drv.ReadID(&nfctag_id, mi2cChannel); + + /* Check if it is the wanted chip */ + if( (nfctag_id == I_AM_ST25DV04) || (nfctag_id == I_AM_ST25DV64) ) + { + NfctagInitialized = 1; + Nfctag_Drv = &St25Dv_i2c_Drv; + Nfctag_Drv->pData = &St25Dv_i2c_ExtDrv; + } + else + { + Nfctag_Drv = NULL; + NfctagInitialized = 0; + return NFCTAG_ERROR; + } + } + + return NFCTAG_OK; +} + +/** + * @brief Deinitializes peripherals used by the I2C NFCTAG driver + * @param None + * @retval None + */ +void BSP_NFCTAG_DeInit( void ) +{ + Nfctag_Drv->pData = NULL; + Nfctag_Drv = NULL; + NfctagInitialized = 0; +} + +/** + * @brief Check if the nfctag is initialized + * @param None + * @retval 0 if the nfctag is not initialized, 1 if the nfctag is already initialized + */ +uint8_t BSP_NFCTAG_isInitialized( void ) +{ + return NfctagInitialized; +} + +/** + * @brief Read the ID of the nfctag + * @param wai_id : the pointer where the who_am_i of the device is stored + * @param mi2cChannel : I2C channel + * @retval NFCTAG enum status + */ +NFCTAG_StatusTypeDef BSP_NFCTAG_ReadID( uint8_t * const wai_id, I2C * mi2cChannel ) +{ + if ( Nfctag_Drv->ReadID == NULL ) + { + return NFCTAG_ERROR; + } + + return Nfctag_Drv->ReadID( wai_id, mi2cChannel ); +} + +/** + * @brief Return the size of the nfctag + * @param mi2cChannel : I2C channel + * @retval Size of the NFCtag in Bytes + */ +uint32_t BSP_NFCTAG_GetByteSize( I2C * mi2cChannel ) +{ + ST25DV_MEM_SIZE mem_size; + ((NFCTAG_ExtDrvTypeDef *)Nfctag_Drv->pData)->ReadMemSize( &mem_size, mi2cChannel ); + return (mem_size.BlockSize+1) * (mem_size.Mem_Size+1); +} + +/** + * @brief Check if the nfctag is available + * @param Trials : Number of trials + * @param mi2cChannel : I2C channel + * @retval NFCTAG enum status + */ +NFCTAG_StatusTypeDef BSP_NFCTAG_IsDeviceReady( const uint32_t Trials, I2C * mi2cChannel, const uint16_t TarAddr ) +{ + if ( Nfctag_Drv->IsReady == NULL ) + { + return NFCTAG_ERROR; + } + + return Nfctag_Drv->IsReady( Trials, mi2cChannel); +} + +/** + * @brief Configure nfctag interrupt + * @param ITConfig : store interrupt to configure + * - 0x01 => RF BUSY + * - 0x02 => WIP + * @retval NFCTAG enum status + */ +NFCTAG_StatusTypeDef BSP_NFCTAG_ConfigIT( const uint16_t ITConfig, I2C * mi2cChannel ) +{ + if ( Nfctag_Drv->ConfigIT == NULL ) + { + return NFCTAG_ERROR; + } + return Nfctag_Drv->ConfigIT( ITConfig, mi2cChannel ); +} + +/** + * @brief Get nfctag interrupt configutration + * @param ITConfig : store interrupt configuration + * - 0x01 => RF BUSY + * - 0x02 => WIP + * @retval NFCTAG enum status + */ +NFCTAG_StatusTypeDef BSP_NFCTAG_GetITStatus( uint16_t * const ITConfig, I2C * mi2cChannel ) +{ + if ( Nfctag_Drv->GetITStatus == NULL ) + { + return NFCTAG_ERROR; + } + + return Nfctag_Drv->GetITStatus( ITConfig, mi2cChannel ); +} + +/** + * @brief Reads data in the nfctag at specific address + * @param pData : pointer to store read data + * @param TarAddr : I2C data memory address to read + * @param Size : Size in bytes of the value to be read + * @param mi2cChannel : I2C channel + * @retval NFCTAG enum status + */ +NFCTAG_StatusTypeDef BSP_NFCTAG_ReadData( uint8_t * const pData, const uint16_t TarAddr, const uint16_t Size, I2C * mi2cChannel ) +{ + if ( Nfctag_Drv->ReadData == NULL ) + { + return NFCTAG_ERROR; + } + + return Nfctag_Drv->ReadData( pData, TarAddr, Size, mi2cChannel ); +} + +/** + * @brief Writes data in the nfctag at specific address + * @param pData : pointer to the data to write + * @param TarAddr : I2C data memory address to write + * @param Size : Size in bytes of the value to be written + * @param mi2cChannel : I2C channel + * @retval NFCTAG enum status + */ +NFCTAG_StatusTypeDef BSP_NFCTAG_WriteData( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t Size, I2C * mi2cChannel ) +{ + if ( Nfctag_Drv->WriteData == NULL ) + { + return NFCTAG_ERROR; + } + + return Nfctag_Drv->WriteData( pData, TarAddr, Size, mi2cChannel ); +} + +/** + * @brief Reads nfctag Register + * @param pData : pointer to store read data + * @param TarAddr : I2C register address to read + * @param Size : Size in bytes of the value to be read + * @retval NFCTAG enum status + */ +NFCTAG_StatusTypeDef BSP_NFCTAG_ReadRegister( uint8_t * const pData, const uint16_t TarAddr, const uint16_t Size, I2C * mi2cChannel ) +{ + if ( Nfctag_Drv->ReadRegister == NULL ) + { + return NFCTAG_ERROR; + } + + return Nfctag_Drv->ReadRegister( pData, TarAddr, Size, mi2cChannel ); +} + +/** + * @brief Writes nfctag Register + * @param pData : pointer to the data to write + * @param TarAddr : I2C register address to write + * @param Size : Size in bytes of the value to be written + * @param mi2cChannel : I2C channel + * @retval NFCTAG enum status + */ +NFCTAG_StatusTypeDef BSP_NFCTAG_WriteRegister( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t Size, I2C * mi2cChannel ) +{ + NFCTAG_StatusTypeDef ret_value; + if ( Nfctag_Drv->WriteRegister == NULL ) + { + return NFCTAG_ERROR; + } + + ret_value = Nfctag_Drv->WriteRegister( pData, TarAddr, Size, mi2cChannel ); + if( ret_value == NFCTAG_OK ) + { + while( BSP_NFCTAG_IsDeviceReady( 1, mi2cChannel, TarAddr ) != NFCTAG_OK ) {}; + return NFCTAG_OK; + } + + return ret_value; +} + +/** + * @brief Give extended features for component + * @param None + * @retval address of the Extended Component Structure + */ +NFCTAG_ExtDrvTypeDef *BSP_NFCTAG_GetExtended_Drv( void ) +{ + return (NFCTAG_ExtDrvTypeDef *)Nfctag_Drv->pData; +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/******************* (C) COPYRIGHT 2017 STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/x_nucleo_nfc04a1_nfctag.h Thu Nov 14 10:30:13 2019 +0000 @@ -0,0 +1,96 @@ +/** + ****************************************************************************** + * @file x_nucleo_nfc04a1_nfctag.h + * @author MMY Application Team + * @version $Revision: 2983 $ + * @date $Date: 2016-09-27 15:08:30 +0200 (Tue, 27 Sep 2016) $ + * @brief This file contains definitions for the x_nucleo_nfc04a1_nfctag.c + * specific functions. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT 2017 STMicroelectronics</center></h2> + * + * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/myliberty + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, + * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __X_NUCLEO_NFC04A1_NFCTAG_H +#define __X_NUCLEO_NFC04A1_NFCTAG_H +/* Includes ------------------------------------------------------------------*/ +#include "x_nucleo_nfc04a1.h" +#include "ST25DV/st25dv.h" +//#include "mbed.h" + + + +/** @addtogroup BSP + * @{ + */ + +/** @addtogroup X_NUCLEO_NFC04A1 + * @{ + */ + +/** @addtogroup X_NUCLEO_NFC04A1_NFCTAG + * @{ + */ +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +#define NFCTAG_4K_SIZE ((uint32_t) 0x200) +#define NFCTAG_16K_SIZE ((uint32_t) 0x800) +#define NFCTAG_64K_SIZE ((uint32_t) 0x2000) +/* External variables --------------------------------------------------------*/ +/* Exported macro ------------------------------------------------------------*/ +/* Exported function --------------------------------------------------------*/ +/** @defgroup X_NUCLEO_NFC04A1_NFCTAG_Exported_Functions + * @{ + */ +NFCTAG_StatusTypeDef BSP_NFCTAG_Init(I2C* mi2cChannel, DigitalOut* mLPD); +void BSP_NFCTAG_DeInit( void ); +uint8_t BSP_NFCTAG_isInitialized( void ); +NFCTAG_StatusTypeDef BSP_NFCTAG_ReadID( uint8_t * const wai_id, I2C * mi2cChannel ); +uint32_t BSP_NFCTAG_GetByteSize( I2C* mi2cChannel ); +NFCTAG_StatusTypeDef BSP_NFCTAG_IsDeviceReady( const uint32_t Trials, I2C * mi2cChannel, const uint16_t TarAddr ); +NFCTAG_StatusTypeDef BSP_NFCTAG_ConfigIT( const uint16_t ITConfig, I2C * mi2cChannel ); +NFCTAG_StatusTypeDef BSP_NFCTAG_GetITStatus( uint16_t * const ITConfig, I2C * mi2cChannel ); +NFCTAG_StatusTypeDef BSP_NFCTAG_ReadData( uint8_t * const pData, const uint16_t TarAddr, const uint16_t Size, I2C * mi2cChannel ); +NFCTAG_StatusTypeDef BSP_NFCTAG_WriteData( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t Size, I2C * mi2cChannel ); +NFCTAG_StatusTypeDef BSP_NFCTAG_ReadRegister( uint8_t * const pData, const uint16_t TarAddr, const uint16_t Size, I2C * mi2cChannel ); +NFCTAG_StatusTypeDef BSP_NFCTAG_WriteRegister( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t Size, I2C * mi2cChannel ); +NFCTAG_ExtDrvTypeDef *BSP_NFCTAG_GetExtended_Drv( void ); +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + + + +#endif /* __X_NUCLEO_NFC04A1_NFCTAG_H */ + +/******************* (C) COPYRIGHT 2017 STMicroelectronics *****END OF FILE****/