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
st25dv_driver.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file m24sr_driver.cpp 00004 * @author ST Central Labs 00005 * @brief This file provides a set of functions to interface with the M24SR 00006 * device. 00007 ****************************************************************************** 00008 * @attention 00009 * 00010 * <h2><center>© COPYRIGHT(c) 2018 STMicroelectronics</center></h2> 00011 * 00012 * Redistribution and use in source and binary forms, with or without modification, 00013 * are permitted provided that the following conditions are met: 00014 * 1. Redistributions of source code must retain the above copyright notice, 00015 * this list of conditions and the following disclaimer. 00016 * 2. Redistributions in binary form must reproduce the above copyright notice, 00017 * this list of conditions and the following disclaimer in the documentation 00018 * and/or other materials provided with the distribution. 00019 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00020 * may be used to endorse or promote products derived from this software 00021 * without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00024 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00026 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00027 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00028 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00029 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00031 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 ****************************************************************************** 00035 */ 00036 00037 #include <st25dv_driver.h> 00038 #include "Callback.h" 00039 00040 namespace mbed { 00041 namespace nfc { 00042 namespace vendor { 00043 namespace ST { 00044 00045 ST25dvDriver::ST25dvDriver(PinName i2c_data_pin, 00046 PinName i2c_clock_pin, 00047 PinName led1_pin, 00048 PinName led2_pin, 00049 PinName led3_pin, 00050 PinName lpd_pin, 00051 PinName gpo_pin) 00052 : _i2c_channel(i2c_data_pin, i2c_clock_pin), 00053 _led1_pin(led1_pin), 00054 _led2_pin(led2_pin), 00055 _led3_pin(led3_pin), 00056 _lpd_pin(lpd_pin), 00057 _gpo_pin(gpo_pin), 00058 _ndef_size(MAX_NDEF_SIZE), 00059 _is_device_inited(false), 00060 _is_session_started(false) { 00061 /* driver requires valid pin names */ 00062 MBED_ASSERT(i2c_data_pin != NC); 00063 MBED_ASSERT(i2c_clock_pin != NC); 00064 MBED_ASSERT(led1_pin != NC); 00065 MBED_ASSERT(led2_pin != NC); 00066 MBED_ASSERT(led3_pin != NC); 00067 MBED_ASSERT(lpd_pin != NC); 00068 MBED_ASSERT(gpo_pin != NC); 00069 } 00070 00071 int ST25dvDriver::begin(void) { 00072 int ret = 0; 00073 00074 // Light some leds 00075 ledOn(_led1_pin); 00076 wait_us( 300000 ); 00077 ledOn(_led2_pin); 00078 00079 /* NFCTAG Init */ 00080 ret = NFCTAG_Init(); 00081 if(ret != NFCTAG_OK) 00082 return ret; 00083 00084 /* Reset MBEN Dynamic */ 00085 NFCTAG_GetExtended_Drv()->ResetMBEN_Dyn( &_i2c_channel ); 00086 00087 if( NfcType5_NDEFDetection() != NDEF_OK ) { 00088 printf("NDEF not detected\r\n"); 00089 00090 CCFileStruct.MagicNumber = NFCT5_MAGICNUMBER_E1_CCFILE; 00091 CCFileStruct.Version = NFCT5_VERSION_V1_0; 00092 CCFileStruct.MemorySize = ( ST25DV_MAX_SIZE / 8 ) & 0xFF; 00093 CCFileStruct.TT5Tag = 0x05; 00094 00095 /* Init of the Type Tag 5 component */ 00096 ret = NfcType5_TT5Init(); 00097 if (ret != NDEF_OK) 00098 return ret; 00099 00100 } else { 00101 printf("NDEF detected\r\n"); 00102 } 00103 00104 ledOff( _led1_pin ); 00105 wait_us( 300000 ); 00106 ledOff( _led2_pin ); 00107 wait_us( 300000 ); 00108 ledOff( _led3_pin ); 00109 wait_us( 300000 ); 00110 return NFCTAG_OK; 00111 } 00112 00113 int ST25dvDriver::read_data(uint32_t address, uint8_t* bytes, size_t count) { 00114 00115 (void) address; 00116 (void) count; 00117 int ret = NfcType5_ReadNDEF((uint8_t*)bytes); 00118 00119 if (ret != NDEF_OK) { 00120 return ret; 00121 } 00122 return NFCTAG_OK; 00123 } 00124 00125 int ST25dvDriver::write_data(uint32_t address, const uint8_t* bytes, size_t count) { 00126 00127 (void) address; 00128 int ret = NfcType5_WriteNDEF(count, (uint8_t*)bytes); 00129 00130 if (ret != NDEF_OK) { 00131 return ret; 00132 } 00133 return NFCTAG_OK; 00134 } 00135 00136 int ST25dvDriver::get_size(void) { 00137 int ret = NfcType5_GetLength(&_ndef_size); 00138 00139 if (ret != NDEF_OK) { 00140 return ret; 00141 } 00142 return NFCTAG_OK; 00143 } 00144 00145 int ST25dvDriver::set_size(size_t count) { 00146 int ret = NfcType5_SetLength(count); 00147 00148 if (ret != NDEF_OK) { 00149 return ret; 00150 } 00151 return NFCTAG_OK; 00152 } 00153 00154 NFCTAG_StatusTypeDef ST25dvDriver::NFCTAG_Init(void) { 00155 00156 uint8_t nfctag_id; 00157 00158 if( !_is_device_inited ) 00159 { 00160 /* ST25DV Init */ 00161 if( St25Dv_i2c_Drv.Init(&_i2c_channel, &_lpd_pin) != NFCTAG_OK ) 00162 { 00163 return NFCTAG_ERROR; 00164 } 00165 00166 00167 St25Dv_i2c_Drv.ReadID(&nfctag_id, &_i2c_channel); 00168 00169 /* Check if it is the wanted chip */ 00170 if( (nfctag_id == I_AM_ST25DV04) || (nfctag_id == I_AM_ST25DV64) ) 00171 { 00172 _is_device_inited = true; 00173 Nfctag_Drv = &St25Dv_i2c_Drv; 00174 Nfctag_Drv->pData = &St25Dv_i2c_ExtDrv; 00175 } 00176 else 00177 { 00178 Nfctag_Drv = NULL; 00179 _is_device_inited = false; 00180 return NFCTAG_ERROR; 00181 } 00182 } 00183 00184 return NFCTAG_OK; 00185 } 00186 00187 00188 NFCTAG_StatusTypeDef ST25dvDriver::NFCTAG_ReadData(uint8_t * const pData, const uint16_t TarAddr, const uint16_t Size) { 00189 00190 if ( Nfctag_Drv->ReadData == NULL ) 00191 { 00192 return NFCTAG_ERROR; 00193 } 00194 00195 return Nfctag_Drv->ReadData( pData, TarAddr, Size, &_i2c_channel ); 00196 } 00197 00198 00199 NFCTAG_StatusTypeDef ST25dvDriver::NFCTAG_WriteData(const uint8_t * const pData, const uint16_t TarAddr, const uint16_t Size) { 00200 00201 if ( Nfctag_Drv->WriteData == NULL ) 00202 { 00203 return NFCTAG_ERROR; 00204 } 00205 00206 return Nfctag_Drv->WriteData( pData, TarAddr, Size, &_i2c_channel ); 00207 } 00208 00209 uint32_t ST25dvDriver::NFCTAG_GetByteSize(void) 00210 { 00211 ST25DV_MEM_SIZE mem_size; 00212 ((NFCTAG_ExtDrvTypeDef *)Nfctag_Drv->pData)->ReadMemSize( &mem_size, &_i2c_channel ); 00213 return (mem_size.BlockSize+1) * (mem_size.Mem_Size+1); 00214 } 00215 00216 /** 00217 * @brief Give extended features for component 00218 * @param None 00219 * @retval address of the Extended Component Structure 00220 */ 00221 NFCTAG_ExtDrvTypeDef* ST25dvDriver::NFCTAG_GetExtended_Drv(void) 00222 { 00223 return (NFCTAG_ExtDrvTypeDef *)Nfctag_Drv->pData; 00224 } 00225 00226 /** 00227 * @brief This function light on selected Led 00228 * @param led : Led to be lit on 00229 * @retval None 00230 */ 00231 void ST25dvDriver::ledOn(DigitalOut led) { 00232 printf("ledOn\r\n"); 00233 led.write(1); 00234 } 00235 00236 /** 00237 * @brief This function light off selected Led 00238 * @param led : Led to be lit off 00239 * @retval None 00240 */ 00241 00242 void ST25dvDriver::ledOff(DigitalOut led) { 00243 led.write(0); 00244 } 00245 00246 /** 00247 * @brief This function detects a NDEF message in a Type 5 Tag. 00248 * @details It first detects the Capability Container and then look for the NDEF TLV. 00249 * The `CCfileStruct` global variable is updated accordingly with what is detected. 00250 * @retval NDEF_OK NDEF message Tag Type 5 detected. 00251 * @retval NDEF_ERROR_NOT_FORMATED Device is not a NFC Tag Type 5 Tag. 00252 */ 00253 uint16_t ST25dvDriver::NfcType5_NDEFDetection(void) 00254 { 00255 uint8_t acc_buffer[8]; 00256 TT5_TLV_t tlv_detect; 00257 uint16_t status; 00258 uint32_t memory_size; 00259 00260 CCFileStruct.State = TT5_NO_NDEF; 00261 00262 /* Read CCFile */ 00263 status = NfcType5_ReadCCFile( acc_buffer ); 00264 00265 if( status != NDEF_OK ) 00266 { 00267 return status; 00268 } 00269 00270 /* Check Byte 0 is equal to magic number */ 00271 if( ( acc_buffer[0] != NFCT5_MAGICNUMBER_E1_CCFILE ) && ( acc_buffer[0] != NFCT5_MAGICNUMBER_E2_CCFILE ) ) 00272 { 00273 return NDEF_ERROR_NOT_FORMATTED; 00274 } 00275 /* Check Version number */ 00276 else if( ( (acc_buffer[1]&0xFC) != 0x40 ) ) 00277 { 00278 return NDEF_ERROR_NOT_FORMATTED; 00279 } 00280 00281 /* Check if CCFile is on 4 Bytes or 8 Bytes */ 00282 if( acc_buffer[2] == 0x00 ) 00283 { 00284 /* Update CCFIle structure */ 00285 CCFileStruct.MemorySize = 0x0; 00286 CCFileStruct.ExtMemorySize = (uint16_t)acc_buffer[6]; 00287 CCFileStruct.ExtMemorySize = ( CCFileStruct.ExtMemorySize << 8 ) | acc_buffer[7]; 00288 memory_size = CCFileStruct.ExtMemorySize; 00289 CCFileStruct.NDEF_offset = 8; 00290 } 00291 else 00292 { 00293 /* Update CCFIle structure */ 00294 CCFileStruct.MemorySize = acc_buffer[2]; 00295 CCFileStruct.ExtMemorySize = 0x0; 00296 memory_size = CCFileStruct.MemorySize; 00297 CCFileStruct.NDEF_offset = 4; 00298 } 00299 00300 /* Update CCFIle structure */ 00301 CCFileStruct.MagicNumber = (TT5_MagicNumber_t)acc_buffer[0]; 00302 CCFileStruct.Version = acc_buffer[1]; 00303 CCFileStruct.TT5Tag = acc_buffer[3]; 00304 00305 /* Search for position of NDEF TLV in memory and tag status */ 00306 while( ( NFCTAG_ReadData( (uint8_t *)&tlv_detect, CCFileStruct.NDEF_offset, sizeof(TT5_TLV_t) ) == NFCTAG_OK ) && ( CCFileStruct.NDEF_offset < memory_size ) ) 00307 { 00308 /* Detect first NDEF Message in memory */ 00309 if( tlv_detect.Type == NFCT5_NDEF_MSG_TLV ) 00310 { 00311 if( tlv_detect.Length == 0x00 ) 00312 { 00313 CCFileStruct.State = TT5_INITIALIZED; 00314 } 00315 else 00316 { 00317 if( CCFileStruct.Version & 0x3 ) 00318 { 00319 CCFileStruct.State = TT5_READ; 00320 } 00321 else 00322 { 00323 CCFileStruct.State = TT5_READ_WRITE; 00324 } 00325 } 00326 return NDEF_OK; 00327 } 00328 /* If Proprietary NDEF jump to end of proprietary message */ 00329 else if( tlv_detect.Type == NFCT5_PROPRIETARY_TLV ) 00330 { 00331 if( tlv_detect.Length == NFCT5_3_BYTES_L_TLV ) 00332 { 00333 CCFileStruct.NDEF_offset = CCFileStruct.NDEF_offset + tlv_detect.Length16; 00334 continue; 00335 } 00336 else 00337 { 00338 CCFileStruct.NDEF_offset = CCFileStruct.NDEF_offset + tlv_detect.Length; 00339 continue; 00340 } 00341 } 00342 /* if Terminator no NDEF detected */ 00343 else if( tlv_detect.Type == NFCT5_TERMINATOR_TLV ) 00344 { 00345 return NDEF_ERROR_NOT_FORMATTED; 00346 } 00347 00348 CCFileStruct.NDEF_offset++; 00349 } 00350 00351 return NDEF_ERROR_NOT_FORMATTED; 00352 } 00353 00354 /** 00355 * @brief This function initializes the Capability Container and an empty NDEF message in a NFC Tag. 00356 * @details The Capability Container content is defined by the global variable `CCFileStruct`. 00357 * @retval NDEF_ERROR The Tag has not been initialized. 00358 * @retval NDEF_OK The Tag has been successfully initialized. 00359 */ 00360 uint16_t ST25dvDriver::NfcType5_TT5Init(void) 00361 { 00362 NFCTAG_StatusTypeDef ret_value = NFCTAG_OK; 00363 uint16_t status; 00364 uint8_t accbuffer[8]; 00365 uint8_t cdata; 00366 00367 /* Prepare buffer to update CCFile */ 00368 accbuffer[0] = CCFileStruct.MagicNumber; 00369 accbuffer[1] = CCFileStruct.Version; 00370 accbuffer[2] = CCFileStruct.MemorySize; 00371 accbuffer[3] = CCFileStruct.TT5Tag; 00372 CCFileStruct.NDEF_offset = 0x04; 00373 00374 /* If extended memory prepare the length bytes */ 00375 if( CCFileStruct.MemorySize == NFCT5_EXTENDED_CCFILE ) 00376 { 00377 accbuffer[6] = (uint8_t)(CCFileStruct.ExtMemorySize >> 8); 00378 accbuffer[7] = (uint8_t)(CCFileStruct.ExtMemorySize & 0xFF); 00379 CCFileStruct.NDEF_offset = 0x08; 00380 } 00381 00382 /* Update CCFile */ 00383 status = NfcType5_WriteCCFile( accbuffer ); 00384 00385 00386 if( status != NDEF_OK ) 00387 { 00388 return status; 00389 } 00390 00391 /* Update NDEF TLV for INITIALIZED state */ 00392 /* Update T */ 00393 cdata = NFCT5_NDEF_MSG_TLV; 00394 ret_value = NFCTAG_WriteData( &cdata, CCFileStruct.NDEF_offset, 1 ); 00395 if( ret_value != NFCTAG_OK ) 00396 { 00397 return NDEF_ERROR; 00398 } 00399 00400 /* Update L */ 00401 cdata = 0x00; 00402 ret_value = NFCTAG_WriteData( &cdata, (CCFileStruct.NDEF_offset + 1), 1 ); 00403 if( ret_value != NFCTAG_OK ) 00404 { 00405 return NDEF_ERROR; 00406 } 00407 00408 return NDEF_OK; 00409 } 00410 00411 /** 00412 * @brief This functions writes the Capability Container in the NFC Tag. 00413 * @param pCCBuffer Pointer on the buffer containnig the Capability Container. 00414 * @retval NDEF_ERROR Error when writing the Tag. 00415 * @retval NDEF_OK The CC has been successfully written. 00416 */ 00417 uint16_t ST25dvDriver::NfcType5_WriteCCFile( const uint8_t * const pCCBuffer ) 00418 { 00419 NFCTAG_StatusTypeDef ret_value; 00420 00421 /* Write first block of CCFile */ 00422 ret_value = NFCTAG_WriteData( pCCBuffer, 0x00, 0x4 ); 00423 00424 /* If extended memory writes the next 4 bytes */ 00425 if( (pCCBuffer[2] == 0x00) && (ret_value == NFCTAG_OK) ) 00426 { 00427 ret_value = NFCTAG_WriteData( pCCBuffer + 4, 0x04, 4 ); 00428 } 00429 00430 if( ret_value != NFCTAG_OK ) 00431 { 00432 return NDEF_ERROR; 00433 } 00434 00435 return NDEF_OK; 00436 } 00437 00438 /** 00439 * @brief This functions reads the Capability Container from the NFC Tag. 00440 * @param pCCBuffer Pointer on the buffer used to store the CC. 00441 * @retval NDEF_ERROR Error when reading the Tag. 00442 * @retval NDEF_OK The CC has been successfully read. 00443 */ 00444 uint16_t ST25dvDriver::NfcType5_ReadCCFile( uint8_t * const pCCBuffer ) 00445 { 00446 NFCTAG_StatusTypeDef ret_value; 00447 00448 /* Read 4 bytes of CC File */ 00449 ret_value = NFCTAG_ReadData( pCCBuffer, 0x00, 4 ); 00450 00451 /* If extended memory reads the next 4 bytes */ 00452 if( (pCCBuffer[2] == 0x00) && (ret_value == NFCTAG_OK) ) 00453 { 00454 ret_value = NFCTAG_ReadData( pCCBuffer + 4, 0x04, 4 ); 00455 } 00456 00457 if( ret_value != NFCTAG_OK ) 00458 { 00459 return NDEF_ERROR; 00460 } 00461 00462 return NDEF_OK; 00463 } 00464 00465 /** 00466 * @brief This function reads the data stored in the NDEF message. 00467 * @param pData Pointer on the buffer used to store the read data. 00468 * @retval NDEF_ERROR_MEMORY_INTERNAL The buffer is too small for the NDEF message. 00469 * @retval NDEF_ERROR_NOT_FORMATED No Capability Container detected. 00470 * @retval NDEF_ERROR Error when reading the NDEF message. 00471 * @retval NDEF_OK NDEF message successfully read. 00472 */ 00473 uint16_t ST25dvDriver::NfcType5_ReadNDEF( uint8_t* pData ) 00474 { 00475 uint16_t status = NDEF_ERROR; 00476 TT5_TLV_t tlv; 00477 uint8_t tlv_size = 0; 00478 uint16_t DataLength; 00479 00480 /* Detect NDEF message in memory */ 00481 status = NfcType5_NDEFDetection(); 00482 if( status != NDEF_OK ) 00483 { 00484 return status; 00485 } 00486 00487 /* Read TL of Type 5 */ 00488 status = NFCTAG_ReadData( (uint8_t*)&tlv, CCFileStruct.NDEF_offset, sizeof(TT5_TLV_t) ); 00489 if( status != NDEF_OK ) 00490 { 00491 return status; 00492 } 00493 00494 /* Check if L is on 3 or 1 byte and update length in buffer */ 00495 if( tlv.Length == NFCT5_3_BYTES_L_TLV ) 00496 { 00497 tlv_size = 4; 00498 DataLength = ((tlv.Length16 >> 8)&0xff) | ((tlv.Length16&0xff)<<8); 00499 } 00500 else 00501 { 00502 tlv_size = 2; 00503 DataLength = tlv.Length; 00504 } 00505 /* If too many data to write return error */ 00506 if( DataLength > NDEF_MAX_SIZE ) 00507 { 00508 return NDEF_ERROR_MEMORY_INTERNAL; 00509 } 00510 00511 /* Check CC file is in the correct mode to proceed */ 00512 if( CCFileStruct.State == TT5_INITIALIZED ) 00513 { 00514 return NDEF_ERROR; 00515 } 00516 00517 if( DataLength > 0 ) 00518 { 00519 /* Read NDEF */ 00520 if( NFCTAG_ReadData( (pData), CCFileStruct.NDEF_offset + tlv_size, DataLength ) != NFCTAG_OK ) 00521 { 00522 return NDEF_ERROR; 00523 } 00524 } 00525 00526 return NDEF_OK; 00527 } 00528 00529 /** 00530 * @brief This function writes a NDEF message in the NFC Tag. 00531 * @param Length Number of bytes to write. 00532 * @param pData Pointer on the buffer to copy. 00533 * @retval NDEF_ERROR_MEMORY_INTERNAL Memory size is too small for the data. 00534 * @retval NDEF_ERROR_NOT_FORMATED No Capability Container detected. 00535 * @retval NDEF_ERROR Error when writing the Tag. 00536 * @retval NDEF_OK The data has been successfully written. 00537 */ 00538 uint16_t ST25dvDriver::NfcType5_WriteNDEF( uint16_t Length, uint8_t *pData ) 00539 { 00540 uint8_t tlv_size; 00541 uint32_t offset; 00542 uint8_t NfcT5_Terminator = NFCT5_TERMINATOR_TLV; 00543 00544 if(Length >= 0xFF) 00545 { 00546 tlv_size = 4; 00547 } else { 00548 tlv_size = 2; 00549 } 00550 00551 offset = CCFileStruct.NDEF_offset + tlv_size; 00552 00553 /* Continue write TLV data to EEPROM */ 00554 if(NFCTAG_WriteData( pData , offset, Length ) != NFCTAG_OK ) 00555 return NDEF_ERROR; 00556 00557 offset +=Length; 00558 00559 /* Write Terminator TLV */ 00560 if(NFCTAG_WriteData( &NfcT5_Terminator, offset, sizeof(NfcT5_Terminator) ) != NFCTAG_OK) 00561 return NDEF_ERROR; 00562 00563 return NDEF_OK; 00564 } 00565 00566 uint16_t ST25dvDriver::NfcType5_SetLength(uint16_t Length) 00567 { 00568 TT5_TLV_t tlv; 00569 uint8_t tlv_size; 00570 uint32_t offset; 00571 uint8_t NfcT5_Terminator = NFCT5_TERMINATOR_TLV; 00572 00573 uint32_t max_length = NFCTAG_GetByteSize() /* Memory size */ 00574 - ((Length >= 0xFF) ? 4 : 2) /* - TLV length */ 00575 - sizeof(NfcT5_Terminator) /* - Terminator TLV */ 00576 - CCFileStruct.NDEF_offset; /* - CCfile length */ 00577 00578 /* If too many data to write return error */ 00579 if( Length > max_length ) 00580 { 00581 return NDEF_ERROR_MEMORY_TAG; 00582 } 00583 00584 /* Detect NDEF message in memory */ 00585 if( NfcType5_NDEFDetection() != NDEF_OK ) 00586 { 00587 return NDEF_ERROR; 00588 } 00589 00590 /* Prepare TLV */ 00591 tlv.Type = NFCT5_NDEF_MSG_TLV; 00592 if(Length >= 0xFF) 00593 { 00594 tlv.Length = NFCT5_3_BYTES_L_TLV; 00595 tlv.Length16 = ((Length&0xff)<<8) | ((Length>>8)&0xff) ; 00596 tlv_size = 4; 00597 00598 } else { 00599 tlv.Length = Length; 00600 tlv_size = 2; 00601 } 00602 00603 offset = CCFileStruct.NDEF_offset; 00604 /* Start write TLV to EEPROM */ 00605 if(NFCTAG_WriteData( (uint8_t*)&tlv, offset, tlv_size )!= NFCTAG_OK) 00606 return NDEF_ERROR; 00607 00608 return NDEF_OK; 00609 } 00610 00611 /** 00612 * @brief This function reads and return the size of the NDEF message in the NFC tag. 00613 * @param Length Pointer on the NDEF size to be returned. 00614 * @retval NDEF_ERROR_NOT_FORMATED Device is not a NFC Tag Type 5 Tag. 00615 * @retval NDEF_ERROR The NDEF message size has not been read. 00616 * @retval NDEF_OK The NDEF message size has been retrieved. 00617 */ 00618 uint16_t ST25dvDriver::NfcType5_GetLength(uint16_t* Length) 00619 { 00620 00621 uint16_t status = NDEF_ERROR; 00622 TT5_TLV_t tlv; 00623 00624 /* Detect NDEF message in memory */ 00625 status = NfcType5_NDEFDetection(); 00626 if( status != NDEF_OK ) 00627 { 00628 return status; 00629 } 00630 00631 /* Read TL of Type 5 */ 00632 status = NFCTAG_ReadData( (uint8_t*)&tlv, CCFileStruct.NDEF_offset, sizeof(TT5_TLV_t) ); 00633 if( status != NFCTAG_OK ) 00634 { 00635 return NDEF_ERROR; 00636 } 00637 00638 if(tlv.Length != NFCT5_3_BYTES_L_TLV) 00639 { 00640 *Length = tlv.Length; 00641 } else { 00642 *Length = ((tlv.Length16 >> 8)&0xff) | ((tlv.Length16 & 0xff) << 8); 00643 } 00644 00645 return NDEF_OK; 00646 } 00647 00648 } //ST 00649 } //vendor 00650 } //nfc 00651 } //mbed 00652 00653 mbed::nfc::NFCEEPROMDriver* greentea_nfc_EEPROM_driver_get_instance() 00654 { 00655 static mbed::nfc::vendor::ST::ST25dvDriver instance; 00656 return &instance; 00657 } 00658 00659 /******************* (C) COPYRIGHT 2020 STMicroelectronics *****END OF FILE****/
Generated on Fri Jul 15 2022 06:26:51 by
1.7.2
X-NUCLEO-NFC04A1