|
| 1 | +/** |
| 2 | + ****************************************************************************** |
| 3 | + * @file st25dv_nfctag.c |
| 4 | + * @author MMY Application Team |
| 5 | + * @version $Revision: 3306 $ |
| 6 | + * @date $Date: 2017-01-13 11:18:15 +0100 (Fri, 13 Jan 2017) $ |
| 7 | + * @brief This file provides a set of functions needed to manage a nfc dual |
| 8 | + * interface eeprom memory. |
| 9 | + ****************************************************************************** |
| 10 | + * @attention |
| 11 | + * |
| 12 | + * <h2><center>© COPYRIGHT 2017 STMicroelectronics</center></h2> |
| 13 | + * |
| 14 | + * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); |
| 15 | + * You may not use this file except in compliance with the License. |
| 16 | + * You may obtain a copy of the License at: |
| 17 | + * |
| 18 | + * http://www.st.com/myliberty |
| 19 | + * |
| 20 | + * Unless required by applicable law or agreed to in writing, software |
| 21 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 22 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, |
| 23 | + * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, |
| 24 | + * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. |
| 25 | + * See the License for the specific language governing permissions and |
| 26 | + * limitations under the License. |
| 27 | + * |
| 28 | + ****************************************************************************** |
| 29 | + */ |
| 30 | + |
| 31 | +/* Includes ------------------------------------------------------------------*/ |
| 32 | +#include "st25dv_nfctag.h" |
| 33 | +#include "Arduino.h" |
| 34 | +/** @addtogroup BSP |
| 35 | + * @{ |
| 36 | + */ |
| 37 | + |
| 38 | +/** @defgroup ST25DV_NFCTAG |
| 39 | + * @{ |
| 40 | + */ |
| 41 | +/* Private typedef -----------------------------------------------------------*/ |
| 42 | +/* Private defines -----------------------------------------------------------*/ |
| 43 | +/** @defgroup ST25DV_NFCTAG_Private_Defines |
| 44 | + * @{ |
| 45 | + */ |
| 46 | +#ifndef NULL |
| 47 | +#define NULL (void *) 0 |
| 48 | +#endif |
| 49 | +/** |
| 50 | + * @} |
| 51 | + */ |
| 52 | + |
| 53 | +/* Private macros ------------------------------------------------------------*/ |
| 54 | +/* Private variables ---------------------------------------------------------*/ |
| 55 | +/* Global variables ----------------------------------------------------------*/ |
| 56 | +/** @defgroup ST25DV_NFCTAG_Private_Variables |
| 57 | + * @{ |
| 58 | + */ |
| 59 | +static NFCTAG_DrvTypeDef *Nfctag_Drv = NULL; |
| 60 | +static uint8_t NfctagInitialized = 0; |
| 61 | +/** |
| 62 | + * @} |
| 63 | + */ |
| 64 | +/* Private function prototypes -----------------------------------------------*/ |
| 65 | +/* Functions Definition ------------------------------------------------------*/ |
| 66 | +/** @defgroup ST25DV_NFCTAG_Public_Functions |
| 67 | + * @{ |
| 68 | + */ |
| 69 | +/** |
| 70 | + * @brief Initializes peripherals used by the I2C NFCTAG driver |
| 71 | + * @param None |
| 72 | + * @retval NFCTAG enum status |
| 73 | + */ |
| 74 | +NFCTAG_StatusTypeDef BSP_NFCTAG_Init( void ) |
| 75 | +{ |
| 76 | + uint8_t nfctag_id = 0; |
| 77 | + |
| 78 | + if( !NfctagInitialized ) |
| 79 | + { |
| 80 | + if( St25Dv_i2c_Drv.Init == NULL ) |
| 81 | + { |
| 82 | + return NFCTAG_ERROR; |
| 83 | + } |
| 84 | + /* ST25DV Init */ |
| 85 | + if( St25Dv_i2c_Drv.Init() != NFCTAG_OK ) |
| 86 | + { |
| 87 | + return NFCTAG_ERROR; |
| 88 | + } |
| 89 | + |
| 90 | + /* Check ST25DV driver ID */ |
| 91 | + St25Dv_i2c_Drv.ReadID(&nfctag_id); |
| 92 | + |
| 93 | + if( (nfctag_id == I_AM_ST25DV04) || (nfctag_id == I_AM_ST25DV64) ) |
| 94 | + { |
| 95 | + NfctagInitialized = 1; |
| 96 | + Nfctag_Drv = &St25Dv_i2c_Drv; |
| 97 | + Nfctag_Drv->pData = &St25Dv_i2c_ExtDrv; |
| 98 | + } |
| 99 | + else |
| 100 | + { |
| 101 | + Nfctag_Drv = NULL; |
| 102 | + NfctagInitialized = 0; |
| 103 | + return NFCTAG_ERROR; |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + return NFCTAG_OK; |
| 108 | +} |
| 109 | + |
| 110 | +/** |
| 111 | + * @brief Deinitializes peripherals used by the I2C NFCTAG driver |
| 112 | + * @param None |
| 113 | + * @retval None |
| 114 | + */ |
| 115 | +void BSP_NFCTAG_DeInit( void ) |
| 116 | +{ |
| 117 | + Nfctag_Drv->pData = NULL; |
| 118 | + Nfctag_Drv = NULL; |
| 119 | + NfctagInitialized = 0; |
| 120 | +} |
| 121 | + |
| 122 | +/** |
| 123 | + * @brief Check if the nfctag is initialized |
| 124 | + * @param None |
| 125 | + * @retval 0 if the nfctag is not initialized, 1 if the nfctag is already initialized |
| 126 | + */ |
| 127 | +uint8_t BSP_NFCTAG_isInitialized( void ) |
| 128 | +{ |
| 129 | + return NfctagInitialized; |
| 130 | +} |
| 131 | + |
| 132 | +/** |
| 133 | + * @brief Read the ID of the nfctag |
| 134 | + * @param wai_id : the pointer where the who_am_i of the device is stored |
| 135 | + * @retval NFCTAG enum status |
| 136 | + */ |
| 137 | +NFCTAG_StatusTypeDef BSP_NFCTAG_ReadID( uint8_t * const wai_id ) |
| 138 | +{ |
| 139 | + if ( Nfctag_Drv->ReadID == NULL ) |
| 140 | + { |
| 141 | + return NFCTAG_ERROR; |
| 142 | + } |
| 143 | + |
| 144 | + return Nfctag_Drv->ReadID( wai_id ); |
| 145 | +} |
| 146 | + |
| 147 | +/** |
| 148 | + * @brief Return the size of the nfctag |
| 149 | + * @retval Size of the NFCtag in Bytes |
| 150 | + */ |
| 151 | +uint32_t BSP_NFCTAG_GetByteSize( void ) |
| 152 | +{ |
| 153 | + ST25DV_MEM_SIZE mem_size; |
| 154 | + ((NFCTAG_ExtDrvTypeDef *)Nfctag_Drv->pData)->ReadMemSize( &mem_size ); |
| 155 | + return (mem_size.BlockSize+1) * (mem_size.Mem_Size+1); |
| 156 | +} |
| 157 | + |
| 158 | +/** |
| 159 | + * @brief Check if the nfctag is available |
| 160 | + * @param Trials : Number of trials |
| 161 | + * @retval NFCTAG enum status |
| 162 | + */ |
| 163 | +NFCTAG_StatusTypeDef BSP_NFCTAG_IsDeviceReady( const uint32_t Trials ) |
| 164 | +{ |
| 165 | + if ( Nfctag_Drv->IsReady == NULL ) |
| 166 | + { |
| 167 | + return NFCTAG_ERROR; |
| 168 | + } |
| 169 | + |
| 170 | + return Nfctag_Drv->IsReady( Trials ); |
| 171 | +} |
| 172 | + |
| 173 | +/** |
| 174 | + * @brief Configure nfctag interrupt |
| 175 | + * @param ITConfig : store interrupt to configure |
| 176 | + * - 0x01 => RF BUSY |
| 177 | + * - 0x02 => WIP |
| 178 | + * @retval NFCTAG enum status |
| 179 | + */ |
| 180 | +NFCTAG_StatusTypeDef BSP_NFCTAG_ConfigIT( const uint16_t ITConfig ) |
| 181 | +{ |
| 182 | + if ( Nfctag_Drv->ConfigIT == NULL ) |
| 183 | + { |
| 184 | + return NFCTAG_ERROR; |
| 185 | + } |
| 186 | + return Nfctag_Drv->ConfigIT( ITConfig ); |
| 187 | +} |
| 188 | + |
| 189 | +/** |
| 190 | + * @brief Get nfctag interrupt configutration |
| 191 | + * @param ITConfig : store interrupt configuration |
| 192 | + * - 0x01 => RF BUSY |
| 193 | + * - 0x02 => WIP |
| 194 | + * @retval NFCTAG enum status |
| 195 | + */ |
| 196 | +NFCTAG_StatusTypeDef BSP_NFCTAG_GetITStatus( uint16_t * const ITConfig ) |
| 197 | +{ |
| 198 | + if ( Nfctag_Drv->GetITStatus == NULL ) |
| 199 | + { |
| 200 | + return NFCTAG_ERROR; |
| 201 | + } |
| 202 | + |
| 203 | + return Nfctag_Drv->GetITStatus( ITConfig ); |
| 204 | +} |
| 205 | + |
| 206 | +/** |
| 207 | + * @brief Reads data in the nfctag at specific address |
| 208 | + * @param pData : pointer to store read data |
| 209 | + * @param TarAddr : I2C data memory address to read |
| 210 | + * @param Size : Size in bytes of the value to be read |
| 211 | + * @retval NFCTAG enum status |
| 212 | + */ |
| 213 | +NFCTAG_StatusTypeDef BSP_NFCTAG_ReadData( uint8_t * const pData, const uint16_t TarAddr, const uint16_t Size ) |
| 214 | +{ |
| 215 | + if ( Nfctag_Drv->ReadData == NULL ) |
| 216 | + { |
| 217 | + return NFCTAG_ERROR; |
| 218 | + } |
| 219 | + |
| 220 | + return Nfctag_Drv->ReadData( pData, TarAddr, Size ); |
| 221 | +} |
| 222 | + |
| 223 | +/** |
| 224 | + * @brief Writes data in the nfctag at specific address |
| 225 | + * @param pData : pointer to the data to write |
| 226 | + * @param TarAddr : I2C data memory address to write |
| 227 | + * @param Size : Size in bytes of the value to be written |
| 228 | + * @retval NFCTAG enum status |
| 229 | + */ |
| 230 | +NFCTAG_StatusTypeDef BSP_NFCTAG_WriteData( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t Size ) |
| 231 | +{ |
| 232 | + if ( Nfctag_Drv->WriteData == NULL ) |
| 233 | + { |
| 234 | + return NFCTAG_ERROR; |
| 235 | + } |
| 236 | + |
| 237 | + return Nfctag_Drv->WriteData( pData, TarAddr, Size ); |
| 238 | +} |
| 239 | + |
| 240 | +/** |
| 241 | + * @brief Reads nfctag Register |
| 242 | + * @param pData : pointer to store read data |
| 243 | + * @param TarAddr : I2C register address to read |
| 244 | + * @param Size : Size in bytes of the value to be read |
| 245 | + * @retval NFCTAG enum status |
| 246 | + */ |
| 247 | +NFCTAG_StatusTypeDef BSP_NFCTAG_ReadRegister( uint8_t * const pData, const uint16_t TarAddr, const uint16_t Size ) |
| 248 | +{ |
| 249 | + if ( Nfctag_Drv->ReadRegister == NULL ) |
| 250 | + { |
| 251 | + return NFCTAG_ERROR; |
| 252 | + } |
| 253 | + |
| 254 | + return Nfctag_Drv->ReadRegister( pData, TarAddr, Size ); |
| 255 | +} |
| 256 | + |
| 257 | +/** |
| 258 | + * @brief Writes nfctag Register |
| 259 | + * @param pData : pointer to the data to write |
| 260 | + * @param TarAddr : I2C register address to write |
| 261 | + * @param Size : Size in bytes of the value to be written |
| 262 | + * @retval NFCTAG enum status |
| 263 | + */ |
| 264 | +NFCTAG_StatusTypeDef BSP_NFCTAG_WriteRegister( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t Size ) |
| 265 | +{ |
| 266 | + NFCTAG_StatusTypeDef ret_value; |
| 267 | + if ( Nfctag_Drv->WriteRegister == NULL ) |
| 268 | + { |
| 269 | + return NFCTAG_ERROR; |
| 270 | + } |
| 271 | + |
| 272 | + ret_value = Nfctag_Drv->WriteRegister( pData, TarAddr, Size ); |
| 273 | + if( ret_value == NFCTAG_OK ) |
| 274 | + { |
| 275 | + while( BSP_NFCTAG_IsDeviceReady( 1 ) != NFCTAG_OK ) {}; |
| 276 | + return NFCTAG_OK; |
| 277 | + } |
| 278 | + |
| 279 | + return ret_value; |
| 280 | +} |
| 281 | + |
| 282 | +/** |
| 283 | + * @brief Give extended features for component |
| 284 | + * @param None |
| 285 | + * @retval address of the Extended Component Structure |
| 286 | + */ |
| 287 | +NFCTAG_ExtDrvTypeDef *BSP_NFCTAG_GetExtended_Drv( void ) |
| 288 | +{ |
| 289 | + return (NFCTAG_ExtDrvTypeDef *)Nfctag_Drv->pData; |
| 290 | +} |
| 291 | + |
| 292 | +/** |
| 293 | + * @} |
| 294 | + */ |
| 295 | + |
| 296 | +/** |
| 297 | + * @} |
| 298 | + */ |
| 299 | + |
| 300 | +/** |
| 301 | + * @} |
| 302 | + */ |
| 303 | + |
| 304 | +/******************* (C) COPYRIGHT 2017 STMicroelectronics *****END OF FILE****/ |
0 commit comments