Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed-os-example-nfc-EEPROM
x_nucleo_nfc04a1.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file x_nucleo_nfc04a1.c 00004 * @author MMY Application Team 00005 * @version $Revision: 3351 $ 00006 * @date $Date: 2017-01-25 17:28:08 +0100 (Wed, 25 Jan 2017) $ 00007 * @brief This file provides nfc04a1 specific functions 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT 2017 STMicroelectronics</center></h2> 00012 * 00013 * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); 00014 * You may not use this file except in compliance with the License. 00015 * You may obtain a copy of the License at: 00016 * 00017 * http://www.st.com/myliberty 00018 * 00019 * Unless required by applicable law or agreed to in writing, software 00020 * distributed under the License is distributed on an "AS IS" BASIS, 00021 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 00022 * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, 00023 * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. 00024 * See the License for the specific language governing permissions and 00025 * limitations under the License. 00026 * 00027 ****************************************************************************** 00028 */ 00029 00030 /* Includes ------------------------------------------------------------------*/ 00031 #include "st25dv.h" 00032 #include "time.h" 00033 00034 /** @defgroup X_NUCLEO_NFC04A1 00035 * @{ 00036 */ 00037 /* Private typedef -----------------------------------------------------------*/ 00038 /* Private defines -----------------------------------------------------------*/ 00039 /* Private macros ------------------------------------------------------------*/ 00040 /* Private variables ---------------------------------------------------------*/ 00041 /* Global variables ----------------------------------------------------------*/ 00042 /** @defgroup X_NUCLEO_NFC04A1_Global_Variables 00043 * @{ 00044 */ 00045 //uint8_t NFC04A1_Led[3] = { 1 , 2 , 3 }; 00046 00047 /** 00048 * @} 00049 */ 00050 00051 /* Private function prototypes -----------------------------------------------*/ 00052 00053 NFCTAG_StatusTypeDef ST25DV_IO_Init( I2C* mi2cChannel, DigitalOut *mLPD ); 00054 NFCTAG_StatusTypeDef ST25DV_IO_MemWrite( const uint8_t * const pData, const uint8_t DevAddr, const uint16_t TarAddr, const uint16_t Size, I2C* mi2cChannel ); 00055 NFCTAG_StatusTypeDef ST25DV_IO_MemRead( uint8_t * const pData, const uint8_t DevAddr, const uint16_t TarAddr, const uint16_t Size, I2C* mi2cChannel ); 00056 NFCTAG_StatusTypeDef ST25DV_IO_Read( uint8_t * const pData, const uint8_t DevAddr, const uint16_t Size, I2C* mi2cChannel ); 00057 NFCTAG_StatusTypeDef ST25DV_IO_IsDeviceReady( const uint8_t DevAddr, const uint32_t Trials, I2C* mi2cChannel); 00058 NFCTAG_StatusTypeDef NFCTAG_ConvertStatus(uint8_t ret); 00059 00060 00061 /* Functions Definition ------------------------------------------------------*/ 00062 /** @defgroup X_NUCLEO_NFC04A1_Public_Functions 00063 * @{ 00064 */ 00065 00066 00067 00068 /** 00069 * @brief Toggles the selected LED 00070 * @param led : Specifies the Led to be toggled 00071 * @retval None 00072 */ 00073 void NFC04A1_LED_Toggle( DigitalOut* led) 00074 { 00075 *led = !(*led); 00076 } 00077 00078 00079 00080 /** 00081 * @brief This function get the GPIO value through GPIO 00082 * @param None 00083 * @retval HAL GPIO pin status 00084 */ 00085 DigitalOut NFC04A1_GPO_ReadPin( DigitalOut *mMISO ) 00086 { 00087 return *mMISO; 00088 } 00089 00090 /** 00091 * @brief This function initialize the GPIO to manage the NFCTAG LPD pin 00092 * @param None 00093 * @retval None 00094 */ 00095 00096 void NFC04A1_LPD_Init( DigitalOut *mLPD ) 00097 { 00098 *mLPD = 0; 00099 } 00100 00101 /** 00102 * @brief This function get the GPIO value through GPIO 00103 * @param None 00104 * @retval HAL GPIO pin status 00105 */ 00106 uint8_t NFC04A1_LPD_ReadPin( DigitalOut *mLPD ) 00107 { 00108 return mLPD -> read(); 00109 } 00110 00111 /** 00112 * @brief This function get the GPIO value through GPIO 00113 * @param None 00114 * @retval HAL GPIO pin status 00115 */ 00116 void NFC04A1_LPD_WritePin( uint8_t LpdPinState, DigitalOut *mLPD ) 00117 { 00118 mLPD -> write( LpdPinState ); 00119 } 00120 00121 /** 00122 * @brief This function select the i2cChannel1 speed to communicate with NFCTAG 00123 * @param i2cChannelspeedchoice Number from 0 to 5 to select i2cChannel speed 00124 * @param mi2cChannel : I2C channel 00125 * @retval HAL GPIO pin status 00126 */ 00127 void NFC04A1_Selecti2cSpeed( uint8_t i2cspeedchoice, I2C* mi2cChannel) 00128 { 00129 00130 switch( i2cspeedchoice ) 00131 { 00132 case 0: 00133 00134 mi2cChannel -> frequency(10000); 00135 break; 00136 00137 case 1: 00138 00139 mi2cChannel -> frequency(100000); 00140 break; 00141 00142 case 2: 00143 00144 mi2cChannel -> frequency(200000); 00145 break; 00146 00147 case 3: 00148 00149 mi2cChannel -> frequency(400000); 00150 break; 00151 00152 case 4: 00153 00154 mi2cChannel -> frequency(800000); 00155 break; 00156 00157 case 5: 00158 00159 mi2cChannel -> frequency(1000000); 00160 break; 00161 00162 default: 00163 00164 mi2cChannel -> frequency(1000000); 00165 break; 00166 } 00167 00168 } 00169 00170 /** 00171 * @} 00172 */ 00173 00174 /** @defgroup X_NUCLEO_NFC04A1_Private_Functions 00175 * @{ 00176 */ 00177 /******************************** LINK EEPROM COMPONENT *****************************/ 00178 00179 /** 00180 * @brief Initializes peripherals used by the i2cChannel NFCTAG driver 00181 * @param mi2cChannel : I2C channel 00182 * @param mLPD 00183 * @retval NFCTAG enum status 00184 */ 00185 NFCTAG_StatusTypeDef ST25DV_IO_Init( I2C* mi2cChannel, DigitalOut *mLPD ) 00186 { 00187 00188 00189 NFC04A1_LPD_Init( mLPD ); 00190 00191 NFC04A1_Selecti2cSpeed(3, mi2cChannel); 00192 00193 return NFCTAG_OK; 00194 } 00195 00196 /** 00197 * @brief Write data, at specific address, through i2c to the ST25DV 00198 * @param pData: pointer to the data to write 00199 * @param DevAddr : Target device address 00200 * @param TarAddr : i2c data memory address to write 00201 * @param Size : Size in bytes of the value to be written 00202 * @param mi2cChannel : I2C channel 00203 * @retval NFCTAG enum status 00204 */ 00205 NFCTAG_StatusTypeDef ST25DV_IO_MemWrite( const uint8_t * const pData, const uint8_t DevAddr, const uint16_t TarAddr, const uint16_t Size, I2C* mi2cChannel ) 00206 { 00207 00208 uint8_t ret = 4; 00209 00210 uint8_t Addr = DevAddr; 00211 00212 00213 uint8_t buffer[2]; 00214 buffer[0] = (uint8_t) (TarAddr>>8); 00215 buffer[1] = (uint8_t) (TarAddr&0xFF); 00216 00217 00218 char * pDataChar = (char*) pData; 00219 00220 00221 ret = mi2cChannel -> write(Addr, (const char*)buffer, 2 , true); 00222 00223 // Address is not OK 00224 if(ret != 0) 00225 return NFCTAG_ConvertStatus(ret); 00226 00227 ret = mi2cChannel -> write(Addr, pDataChar, Size, false); 00228 00229 return NFCTAG_ConvertStatus(ret); 00230 } 00231 00232 00233 /* 00234 * @brief Reads data at a specific address from the NFCTAG. 00235 * @param pData: pointer to store read data 00236 * @param DevAddr : Target device address 00237 * @param TarAddr : i2c data memory address to read 00238 * @param Size : Size in bytes of the value to be read 00239 * @param mi2cChannel : I2C channel 00240 * @retval NFCTAG enum status 00241 */ 00242 00243 NFCTAG_StatusTypeDef ST25DV_IO_MemRead( uint8_t * const pData, const uint8_t DevAddr, const uint16_t TarAddr, const uint16_t Size, I2C* mi2cChannel ) 00244 { 00245 00246 uint8_t ret = 4; 00247 uint8_t Addr = DevAddr; 00248 00249 uint8_t buffer[2]; 00250 buffer[0] = (uint8_t) (TarAddr>>8); 00251 buffer[1] = (uint8_t) (TarAddr&0xFF); 00252 00253 ret = mi2cChannel -> write(Addr, (const char*)buffer , 2 , false); 00254 00255 // Address is not OK 00256 if(ret != 0) 00257 return NFCTAG_ConvertStatus(ret); 00258 00259 char * pDataChar = (char*) pData; 00260 00261 ret = mi2cChannel -> read(DevAddr, pDataChar, Size, false ); 00262 00263 return NFCTAG_ConvertStatus(ret); 00264 } 00265 00266 NFCTAG_StatusTypeDef NFCTAG_ConvertStatus(uint8_t ret) { 00267 if (ret == 0) { 00268 return NFCTAG_OK; 00269 } else if ((ret == 2) || (ret == 3)) { 00270 return NFCTAG_NACK; 00271 } else { 00272 return NFCTAG_ERROR; 00273 } 00274 } 00275 00276 00277 /** 00278 * @brief Reads data at current address from the NFCTAG. 00279 * @param pData: pointer to store read data 00280 * @param DevAddr : Target device address 00281 * @param Size : Size in bytes of the value to be read 00282 * @retval NFCTAG enum status 00283 */ 00284 NFCTAG_StatusTypeDef ST25DV_IO_Read( uint8_t * const pData, const uint8_t DevAddr, const uint16_t Size, I2C* mi2cChannel ) 00285 { 00286 //this has to change( send addr then read) 00287 int i = 0; 00288 uint8_t ret = 4; 00289 00290 char * pDataChar = (char*) pData; 00291 uint8_t ReadAddr = DevAddr | 1u; 00292 ret = mi2cChannel -> read(ReadAddr, pDataChar, 1, false ); 00293 00294 00295 // Tell slave we need to read 1byte from the current register 00296 while(mi2cChannel -> read( 0 ) != 0) { 00297 pData[i++] = mi2cChannel -> read( 0 ); 00298 00299 } 00300 00301 00302 return NFCTAG_ConvertStatus( ret); 00303 } 00304 00305 00306 /** 00307 * @brief Checks if target device is ready for communication 00308 * @note This function is used with Memory devices 00309 * @param DevAddr : Target device address 00310 * @param mi2cChannel : I2C channel 00311 * @retval NFCTAG enum status 00312 */ 00313 NFCTAG_StatusTypeDef ST25DV_IO_IsDeviceReady( const uint8_t DevAddr, const uint32_t Trials, I2C* mi2cChannel) 00314 { 00315 int ret = 4; 00316 uint32_t count = 0; 00317 00318 uint8_t Addr = DevAddr; 00319 00320 00321 while ((count++ < Trials && ret) ) { 00322 ret = mi2cChannel -> write(Addr, NULL, 0 , false); 00323 } 00324 return NFCTAG_ConvertStatus(ret); 00325 } 00326 00327 00328 00329 00330 /** 00331 * @} 00332 */ 00333 00334 /** 00335 * @} 00336 */ 00337 00338 /** 00339 * @} 00340 */ 00341 00342 /******************* (C) COPYRIGHT 2017 STMicroelectronics *****END OF FILE****/
Generated on Fri Jul 15 2022 06:26:51 by
1.7.2
X-NUCLEO-NFC04A1