BSP library for the STMicroelectronics X-NUCLEO-NFC04A1

Dependents:   mbed-os-nfc04a1 Wiagro-Lanza34-XDot

Committer:
DiegoOstuni
Date:
Thu Nov 14 10:30:13 2019 +0000
Revision:
0:cf62b690f57c
Files added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DiegoOstuni 0:cf62b690f57c 1 /**
DiegoOstuni 0:cf62b690f57c 2 ******************************************************************************
DiegoOstuni 0:cf62b690f57c 3 * @file x_nucleo_nfc04a1.c
DiegoOstuni 0:cf62b690f57c 4 * @author MMY Application Team
DiegoOstuni 0:cf62b690f57c 5 * @version $Revision: 3351 $
DiegoOstuni 0:cf62b690f57c 6 * @date $Date: 2017-01-25 17:28:08 +0100 (Wed, 25 Jan 2017) $
DiegoOstuni 0:cf62b690f57c 7 * @brief This file provides nfc04a1 specific functions
DiegoOstuni 0:cf62b690f57c 8 ******************************************************************************
DiegoOstuni 0:cf62b690f57c 9 * @attention
DiegoOstuni 0:cf62b690f57c 10 *
DiegoOstuni 0:cf62b690f57c 11 * <h2><center>&copy; COPYRIGHT 2017 STMicroelectronics</center></h2>
DiegoOstuni 0:cf62b690f57c 12 *
DiegoOstuni 0:cf62b690f57c 13 * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
DiegoOstuni 0:cf62b690f57c 14 * You may not use this file except in compliance with the License.
DiegoOstuni 0:cf62b690f57c 15 * You may obtain a copy of the License at:
DiegoOstuni 0:cf62b690f57c 16 *
DiegoOstuni 0:cf62b690f57c 17 * http://www.st.com/myliberty
DiegoOstuni 0:cf62b690f57c 18 *
DiegoOstuni 0:cf62b690f57c 19 * Unless required by applicable law or agreed to in writing, software
DiegoOstuni 0:cf62b690f57c 20 * distributed under the License is distributed on an "AS IS" BASIS,
DiegoOstuni 0:cf62b690f57c 21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
DiegoOstuni 0:cf62b690f57c 22 * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
DiegoOstuni 0:cf62b690f57c 23 * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
DiegoOstuni 0:cf62b690f57c 24 * See the License for the specific language governing permissions and
DiegoOstuni 0:cf62b690f57c 25 * limitations under the License.
DiegoOstuni 0:cf62b690f57c 26 *
DiegoOstuni 0:cf62b690f57c 27 ******************************************************************************
DiegoOstuni 0:cf62b690f57c 28 */
DiegoOstuni 0:cf62b690f57c 29
DiegoOstuni 0:cf62b690f57c 30 /* Includes ------------------------------------------------------------------*/
DiegoOstuni 0:cf62b690f57c 31 #include "x_nucleo_nfc04a1.h"
DiegoOstuni 0:cf62b690f57c 32 //#include "x_nucleo_nfc04a1_nfctag.h"
DiegoOstuni 0:cf62b690f57c 33 //#include "mbed.h"
DiegoOstuni 0:cf62b690f57c 34 //#include "PinNames.h"
DiegoOstuni 0:cf62b690f57c 35 #include "time.h"
DiegoOstuni 0:cf62b690f57c 36
DiegoOstuni 0:cf62b690f57c 37 /*
DiegoOstuni 0:cf62b690f57c 38 #if define
DiegoOstuni 0:cf62b690f57c 39 define
DiegoOstuni 0:cf62b690f57c 40 #endif
DiegoOstuni 0:cf62b690f57c 41 */
DiegoOstuni 0:cf62b690f57c 42
DiegoOstuni 0:cf62b690f57c 43
DiegoOstuni 0:cf62b690f57c 44 /*Stream *_serial = NULL;
DiegoOstuni 0:cf62b690f57c 45 #if defined(ARDUINO_SAM_DUE)
DiegoOstuni 0:cf62b690f57c 46 TwoWire *_wire = &Wire1;
DiegoOstuni 0:cf62b690f57c 47 #else
DiegoOstuni 0:cf62b690f57c 48 TwoWire *_wire = &Wire;
DiegoOstuni 0:cf62b690f57c 49 #endif
DiegoOstuni 0:cf62b690f57c 50 * @addtogroup BSP
DiegoOstuni 0:cf62b690f57c 51 * @{
DiegoOstuni 0:cf62b690f57c 52 */
DiegoOstuni 0:cf62b690f57c 53
DiegoOstuni 0:cf62b690f57c 54 /** @defgroup X_NUCLEO_NFC04A1
DiegoOstuni 0:cf62b690f57c 55 * @{
DiegoOstuni 0:cf62b690f57c 56 */
DiegoOstuni 0:cf62b690f57c 57 /* Private typedef -----------------------------------------------------------*/
DiegoOstuni 0:cf62b690f57c 58 /* Private defines -----------------------------------------------------------*/
DiegoOstuni 0:cf62b690f57c 59 /* Private macros ------------------------------------------------------------*/
DiegoOstuni 0:cf62b690f57c 60 /* Private variables ---------------------------------------------------------*/
DiegoOstuni 0:cf62b690f57c 61 /* Global variables ----------------------------------------------------------*/
DiegoOstuni 0:cf62b690f57c 62 /** @defgroup X_NUCLEO_NFC04A1_Global_Variables
DiegoOstuni 0:cf62b690f57c 63 * @{
DiegoOstuni 0:cf62b690f57c 64 */
DiegoOstuni 0:cf62b690f57c 65 //uint8_t NFC04A1_Led[3] = { 1 , 2 , 3 };
DiegoOstuni 0:cf62b690f57c 66
DiegoOstuni 0:cf62b690f57c 67 /**
DiegoOstuni 0:cf62b690f57c 68 * @}
DiegoOstuni 0:cf62b690f57c 69 */
DiegoOstuni 0:cf62b690f57c 70
DiegoOstuni 0:cf62b690f57c 71 /* Private function prototypes -----------------------------------------------*/
DiegoOstuni 0:cf62b690f57c 72
DiegoOstuni 0:cf62b690f57c 73 NFCTAG_StatusTypeDef ST25DV_IO_Init( I2C* mi2cChannel, DigitalOut *mLPD );
DiegoOstuni 0:cf62b690f57c 74 NFCTAG_StatusTypeDef ST25DV_IO_MemWrite( const uint8_t * const pData, const uint8_t DevAddr, const uint16_t TarAddr, const uint16_t Size, I2C* mi2cChannel );
DiegoOstuni 0:cf62b690f57c 75 NFCTAG_StatusTypeDef ST25DV_IO_MemRead( uint8_t * const pData, const uint8_t DevAddr, const uint16_t TarAddr, const uint16_t Size, I2C* mi2cChannel );
DiegoOstuni 0:cf62b690f57c 76 NFCTAG_StatusTypeDef ST25DV_IO_Read( uint8_t * const pData, const uint8_t DevAddr, const uint16_t Size, I2C* mi2cChannel );
DiegoOstuni 0:cf62b690f57c 77 NFCTAG_StatusTypeDef ST25DV_IO_IsDeviceReady( const uint8_t DevAddr, const uint32_t Trials, I2C* mi2cChannel);
DiegoOstuni 0:cf62b690f57c 78 NFCTAG_StatusTypeDef NFCTAG_ConvertStatus(uint8_t ret);
DiegoOstuni 0:cf62b690f57c 79
DiegoOstuni 0:cf62b690f57c 80
DiegoOstuni 0:cf62b690f57c 81 /* Functions Definition ------------------------------------------------------*/
DiegoOstuni 0:cf62b690f57c 82 /** @defgroup X_NUCLEO_NFC04A1_Public_Functions
DiegoOstuni 0:cf62b690f57c 83 * @{
DiegoOstuni 0:cf62b690f57c 84 */
DiegoOstuni 0:cf62b690f57c 85
DiegoOstuni 0:cf62b690f57c 86
DiegoOstuni 0:cf62b690f57c 87
DiegoOstuni 0:cf62b690f57c 88 /**
DiegoOstuni 0:cf62b690f57c 89 * @brief Toggles the selected LED
DiegoOstuni 0:cf62b690f57c 90 * @param led : Specifies the Led to be toggled
DiegoOstuni 0:cf62b690f57c 91 * @retval None
DiegoOstuni 0:cf62b690f57c 92 */
DiegoOstuni 0:cf62b690f57c 93 void NFC04A1_LED_Toggle( DigitalOut* led)
DiegoOstuni 0:cf62b690f57c 94 {
DiegoOstuni 0:cf62b690f57c 95 *led = !(*led);
DiegoOstuni 0:cf62b690f57c 96 }
DiegoOstuni 0:cf62b690f57c 97
DiegoOstuni 0:cf62b690f57c 98
DiegoOstuni 0:cf62b690f57c 99
DiegoOstuni 0:cf62b690f57c 100 /**
DiegoOstuni 0:cf62b690f57c 101 * @brief This function get the GPIO value through GPIO
DiegoOstuni 0:cf62b690f57c 102 * @param None
DiegoOstuni 0:cf62b690f57c 103 * @retval HAL GPIO pin status
DiegoOstuni 0:cf62b690f57c 104 */
DiegoOstuni 0:cf62b690f57c 105 DigitalOut NFC04A1_GPO_ReadPin( DigitalOut *mMISO )
DiegoOstuni 0:cf62b690f57c 106 {
DiegoOstuni 0:cf62b690f57c 107 return *mMISO;
DiegoOstuni 0:cf62b690f57c 108 }
DiegoOstuni 0:cf62b690f57c 109
DiegoOstuni 0:cf62b690f57c 110 /**
DiegoOstuni 0:cf62b690f57c 111 * @brief This function initialize the GPIO to manage the NFCTAG LPD pin
DiegoOstuni 0:cf62b690f57c 112 * @param None
DiegoOstuni 0:cf62b690f57c 113 * @retval None
DiegoOstuni 0:cf62b690f57c 114 */
DiegoOstuni 0:cf62b690f57c 115
DiegoOstuni 0:cf62b690f57c 116 void NFC04A1_LPD_Init( DigitalOut *mLPD )
DiegoOstuni 0:cf62b690f57c 117 {
DiegoOstuni 0:cf62b690f57c 118 *mLPD = 0;
DiegoOstuni 0:cf62b690f57c 119 }
DiegoOstuni 0:cf62b690f57c 120
DiegoOstuni 0:cf62b690f57c 121 /**
DiegoOstuni 0:cf62b690f57c 122 * @brief This function get the GPIO value through GPIO
DiegoOstuni 0:cf62b690f57c 123 * @param None
DiegoOstuni 0:cf62b690f57c 124 * @retval HAL GPIO pin status
DiegoOstuni 0:cf62b690f57c 125 */
DiegoOstuni 0:cf62b690f57c 126 uint8_t NFC04A1_LPD_ReadPin( DigitalOut *mLPD )
DiegoOstuni 0:cf62b690f57c 127 {
DiegoOstuni 0:cf62b690f57c 128 return mLPD -> read();
DiegoOstuni 0:cf62b690f57c 129 }
DiegoOstuni 0:cf62b690f57c 130
DiegoOstuni 0:cf62b690f57c 131 /**
DiegoOstuni 0:cf62b690f57c 132 * @brief This function get the GPIO value through GPIO
DiegoOstuni 0:cf62b690f57c 133 * @param None
DiegoOstuni 0:cf62b690f57c 134 * @retval HAL GPIO pin status
DiegoOstuni 0:cf62b690f57c 135 */
DiegoOstuni 0:cf62b690f57c 136 void NFC04A1_LPD_WritePin( uint8_t LpdPinState, DigitalOut *mLPD )
DiegoOstuni 0:cf62b690f57c 137 {
DiegoOstuni 0:cf62b690f57c 138 mLPD -> write( LpdPinState );
DiegoOstuni 0:cf62b690f57c 139 }
DiegoOstuni 0:cf62b690f57c 140
DiegoOstuni 0:cf62b690f57c 141 /**
DiegoOstuni 0:cf62b690f57c 142 * @brief This function select the i2cChannel1 speed to communicate with NFCTAG
DiegoOstuni 0:cf62b690f57c 143 * @param i2cChannelspeedchoice Number from 0 to 5 to select i2cChannel speed
DiegoOstuni 0:cf62b690f57c 144 * @param mi2cChannel : I2C channel
DiegoOstuni 0:cf62b690f57c 145 * @retval HAL GPIO pin status
DiegoOstuni 0:cf62b690f57c 146 */
DiegoOstuni 0:cf62b690f57c 147 void NFC04A1_Selecti2cSpeed( uint8_t i2cspeedchoice, I2C* mi2cChannel)
DiegoOstuni 0:cf62b690f57c 148 {
DiegoOstuni 0:cf62b690f57c 149
DiegoOstuni 0:cf62b690f57c 150 switch( i2cspeedchoice )
DiegoOstuni 0:cf62b690f57c 151 {
DiegoOstuni 0:cf62b690f57c 152 case 0:
DiegoOstuni 0:cf62b690f57c 153
DiegoOstuni 0:cf62b690f57c 154 mi2cChannel -> frequency(10000);
DiegoOstuni 0:cf62b690f57c 155 break;
DiegoOstuni 0:cf62b690f57c 156
DiegoOstuni 0:cf62b690f57c 157 case 1:
DiegoOstuni 0:cf62b690f57c 158
DiegoOstuni 0:cf62b690f57c 159 mi2cChannel -> frequency(100000);
DiegoOstuni 0:cf62b690f57c 160 break;
DiegoOstuni 0:cf62b690f57c 161
DiegoOstuni 0:cf62b690f57c 162 case 2:
DiegoOstuni 0:cf62b690f57c 163
DiegoOstuni 0:cf62b690f57c 164 mi2cChannel -> frequency(200000);
DiegoOstuni 0:cf62b690f57c 165 break;
DiegoOstuni 0:cf62b690f57c 166
DiegoOstuni 0:cf62b690f57c 167 case 3:
DiegoOstuni 0:cf62b690f57c 168
DiegoOstuni 0:cf62b690f57c 169 mi2cChannel -> frequency(400000);
DiegoOstuni 0:cf62b690f57c 170 break;
DiegoOstuni 0:cf62b690f57c 171
DiegoOstuni 0:cf62b690f57c 172 case 4:
DiegoOstuni 0:cf62b690f57c 173
DiegoOstuni 0:cf62b690f57c 174 mi2cChannel -> frequency(800000);
DiegoOstuni 0:cf62b690f57c 175 break;
DiegoOstuni 0:cf62b690f57c 176
DiegoOstuni 0:cf62b690f57c 177 case 5:
DiegoOstuni 0:cf62b690f57c 178
DiegoOstuni 0:cf62b690f57c 179 mi2cChannel -> frequency(1000000);
DiegoOstuni 0:cf62b690f57c 180 break;
DiegoOstuni 0:cf62b690f57c 181
DiegoOstuni 0:cf62b690f57c 182 default:
DiegoOstuni 0:cf62b690f57c 183
DiegoOstuni 0:cf62b690f57c 184 mi2cChannel -> frequency(1000000);
DiegoOstuni 0:cf62b690f57c 185 break;
DiegoOstuni 0:cf62b690f57c 186 }
DiegoOstuni 0:cf62b690f57c 187
DiegoOstuni 0:cf62b690f57c 188 }
DiegoOstuni 0:cf62b690f57c 189
DiegoOstuni 0:cf62b690f57c 190 /**
DiegoOstuni 0:cf62b690f57c 191 * @}
DiegoOstuni 0:cf62b690f57c 192 */
DiegoOstuni 0:cf62b690f57c 193
DiegoOstuni 0:cf62b690f57c 194 /** @defgroup X_NUCLEO_NFC04A1_Private_Functions
DiegoOstuni 0:cf62b690f57c 195 * @{
DiegoOstuni 0:cf62b690f57c 196 */
DiegoOstuni 0:cf62b690f57c 197 /******************************** LINK EEPROM COMPONENT *****************************/
DiegoOstuni 0:cf62b690f57c 198
DiegoOstuni 0:cf62b690f57c 199 /**
DiegoOstuni 0:cf62b690f57c 200 * @brief Initializes peripherals used by the i2cChannel NFCTAG driver
DiegoOstuni 0:cf62b690f57c 201 * @param mi2cChannel : I2C channel
DiegoOstuni 0:cf62b690f57c 202 * @param mLPD
DiegoOstuni 0:cf62b690f57c 203 * @retval NFCTAG enum status
DiegoOstuni 0:cf62b690f57c 204 */
DiegoOstuni 0:cf62b690f57c 205 NFCTAG_StatusTypeDef ST25DV_IO_Init( I2C* mi2cChannel, DigitalOut *mLPD )
DiegoOstuni 0:cf62b690f57c 206 {
DiegoOstuni 0:cf62b690f57c 207
DiegoOstuni 0:cf62b690f57c 208
DiegoOstuni 0:cf62b690f57c 209 NFC04A1_LPD_Init( mLPD );
DiegoOstuni 0:cf62b690f57c 210
DiegoOstuni 0:cf62b690f57c 211 NFC04A1_Selecti2cSpeed(3, mi2cChannel);
DiegoOstuni 0:cf62b690f57c 212
DiegoOstuni 0:cf62b690f57c 213 return NFCTAG_OK;
DiegoOstuni 0:cf62b690f57c 214 }
DiegoOstuni 0:cf62b690f57c 215
DiegoOstuni 0:cf62b690f57c 216 /**
DiegoOstuni 0:cf62b690f57c 217 * @brief Write data, at specific address, through i2c to the ST25DV
DiegoOstuni 0:cf62b690f57c 218 * @param pData: pointer to the data to write
DiegoOstuni 0:cf62b690f57c 219 * @param DevAddr : Target device address
DiegoOstuni 0:cf62b690f57c 220 * @param TarAddr : i2c data memory address to write
DiegoOstuni 0:cf62b690f57c 221 * @param Size : Size in bytes of the value to be written
DiegoOstuni 0:cf62b690f57c 222 * @param mi2cChannel : I2C channel
DiegoOstuni 0:cf62b690f57c 223 * @retval NFCTAG enum status
DiegoOstuni 0:cf62b690f57c 224 */
DiegoOstuni 0:cf62b690f57c 225 NFCTAG_StatusTypeDef ST25DV_IO_MemWrite( const uint8_t * const pData, const uint8_t DevAddr, const uint16_t TarAddr, const uint16_t Size, I2C* mi2cChannel )
DiegoOstuni 0:cf62b690f57c 226 {
DiegoOstuni 0:cf62b690f57c 227
DiegoOstuni 0:cf62b690f57c 228 uint8_t ret = 4;
DiegoOstuni 0:cf62b690f57c 229
DiegoOstuni 0:cf62b690f57c 230 uint8_t Addr = DevAddr;
DiegoOstuni 0:cf62b690f57c 231
DiegoOstuni 0:cf62b690f57c 232
DiegoOstuni 0:cf62b690f57c 233 uint8_t buffer[2];
DiegoOstuni 0:cf62b690f57c 234 buffer[0] = (uint8_t) (TarAddr>>8);
DiegoOstuni 0:cf62b690f57c 235 buffer[1] = (uint8_t) (TarAddr&0xFF);
DiegoOstuni 0:cf62b690f57c 236
DiegoOstuni 0:cf62b690f57c 237
DiegoOstuni 0:cf62b690f57c 238 char * pDataChar = (char*) pData;
DiegoOstuni 0:cf62b690f57c 239
DiegoOstuni 0:cf62b690f57c 240
DiegoOstuni 0:cf62b690f57c 241 ret = mi2cChannel -> write(Addr, (const char*)buffer, 2 , true);
DiegoOstuni 0:cf62b690f57c 242
DiegoOstuni 0:cf62b690f57c 243 // Address is not OK
DiegoOstuni 0:cf62b690f57c 244 if(ret != 0)
DiegoOstuni 0:cf62b690f57c 245 return NFCTAG_ConvertStatus(ret);
DiegoOstuni 0:cf62b690f57c 246
DiegoOstuni 0:cf62b690f57c 247 ret = mi2cChannel -> write(Addr, pDataChar, Size, false);
DiegoOstuni 0:cf62b690f57c 248
DiegoOstuni 0:cf62b690f57c 249 return NFCTAG_ConvertStatus(ret);
DiegoOstuni 0:cf62b690f57c 250 }
DiegoOstuni 0:cf62b690f57c 251
DiegoOstuni 0:cf62b690f57c 252
DiegoOstuni 0:cf62b690f57c 253 /*
DiegoOstuni 0:cf62b690f57c 254 * @brief Reads data at a specific address from the NFCTAG.
DiegoOstuni 0:cf62b690f57c 255 * @param pData: pointer to store read data
DiegoOstuni 0:cf62b690f57c 256 * @param DevAddr : Target device address
DiegoOstuni 0:cf62b690f57c 257 * @param TarAddr : i2c data memory address to read
DiegoOstuni 0:cf62b690f57c 258 * @param Size : Size in bytes of the value to be read
DiegoOstuni 0:cf62b690f57c 259 * @param mi2cChannel : I2C channel
DiegoOstuni 0:cf62b690f57c 260 * @retval NFCTAG enum status
DiegoOstuni 0:cf62b690f57c 261 */
DiegoOstuni 0:cf62b690f57c 262
DiegoOstuni 0:cf62b690f57c 263 NFCTAG_StatusTypeDef ST25DV_IO_MemRead( uint8_t * const pData, const uint8_t DevAddr, const uint16_t TarAddr, const uint16_t Size, I2C* mi2cChannel )
DiegoOstuni 0:cf62b690f57c 264 {
DiegoOstuni 0:cf62b690f57c 265
DiegoOstuni 0:cf62b690f57c 266 uint8_t ret = 4;
DiegoOstuni 0:cf62b690f57c 267 uint8_t Addr = DevAddr;
DiegoOstuni 0:cf62b690f57c 268
DiegoOstuni 0:cf62b690f57c 269 uint8_t buffer[2];
DiegoOstuni 0:cf62b690f57c 270 buffer[0] = (uint8_t) (TarAddr>>8);
DiegoOstuni 0:cf62b690f57c 271 buffer[1] = (uint8_t) (TarAddr&0xFF);
DiegoOstuni 0:cf62b690f57c 272
DiegoOstuni 0:cf62b690f57c 273 ret = mi2cChannel -> write(Addr, (const char*)buffer , 2 , false);
DiegoOstuni 0:cf62b690f57c 274
DiegoOstuni 0:cf62b690f57c 275 // Address is not OK
DiegoOstuni 0:cf62b690f57c 276 if(ret != 0)
DiegoOstuni 0:cf62b690f57c 277 return NFCTAG_ConvertStatus(ret);
DiegoOstuni 0:cf62b690f57c 278
DiegoOstuni 0:cf62b690f57c 279 char * pDataChar = (char*) pData;
DiegoOstuni 0:cf62b690f57c 280
DiegoOstuni 0:cf62b690f57c 281 ret = mi2cChannel -> read(DevAddr, pDataChar, Size, false );
DiegoOstuni 0:cf62b690f57c 282
DiegoOstuni 0:cf62b690f57c 283 return NFCTAG_ConvertStatus(ret);
DiegoOstuni 0:cf62b690f57c 284 }
DiegoOstuni 0:cf62b690f57c 285
DiegoOstuni 0:cf62b690f57c 286 NFCTAG_StatusTypeDef NFCTAG_ConvertStatus(uint8_t ret) {
DiegoOstuni 0:cf62b690f57c 287 if (ret == 0) {
DiegoOstuni 0:cf62b690f57c 288 return NFCTAG_OK;
DiegoOstuni 0:cf62b690f57c 289 } else if ((ret == 2) || (ret == 3)) {
DiegoOstuni 0:cf62b690f57c 290 return NFCTAG_NACK;
DiegoOstuni 0:cf62b690f57c 291 } else {
DiegoOstuni 0:cf62b690f57c 292 return NFCTAG_ERROR;
DiegoOstuni 0:cf62b690f57c 293 }
DiegoOstuni 0:cf62b690f57c 294 }
DiegoOstuni 0:cf62b690f57c 295
DiegoOstuni 0:cf62b690f57c 296
DiegoOstuni 0:cf62b690f57c 297 /**
DiegoOstuni 0:cf62b690f57c 298 * @brief Reads data at current address from the NFCTAG.
DiegoOstuni 0:cf62b690f57c 299 * @param pData: pointer to store read data
DiegoOstuni 0:cf62b690f57c 300 * @param DevAddr : Target device address
DiegoOstuni 0:cf62b690f57c 301 * @param Size : Size in bytes of the value to be read
DiegoOstuni 0:cf62b690f57c 302 * @retval NFCTAG enum status
DiegoOstuni 0:cf62b690f57c 303 */
DiegoOstuni 0:cf62b690f57c 304 NFCTAG_StatusTypeDef ST25DV_IO_Read( uint8_t * const pData, const uint8_t DevAddr, const uint16_t Size, I2C* mi2cChannel )
DiegoOstuni 0:cf62b690f57c 305 {
DiegoOstuni 0:cf62b690f57c 306 //this has to change( send addr then read)
DiegoOstuni 0:cf62b690f57c 307 int i = 0;
DiegoOstuni 0:cf62b690f57c 308 uint8_t ret = 4;
DiegoOstuni 0:cf62b690f57c 309
DiegoOstuni 0:cf62b690f57c 310 char * pDataChar = (char*) pData;
DiegoOstuni 0:cf62b690f57c 311 uint8_t ReadAddr = DevAddr | 1u;
DiegoOstuni 0:cf62b690f57c 312 ret = mi2cChannel -> read(ReadAddr, pDataChar, 1, false );
DiegoOstuni 0:cf62b690f57c 313
DiegoOstuni 0:cf62b690f57c 314
DiegoOstuni 0:cf62b690f57c 315 // Tell slave we need to read 1byte from the current register
DiegoOstuni 0:cf62b690f57c 316 while(mi2cChannel -> read( 0 ) != 0) {
DiegoOstuni 0:cf62b690f57c 317 pData[i++] = mi2cChannel -> read( 0 );
DiegoOstuni 0:cf62b690f57c 318
DiegoOstuni 0:cf62b690f57c 319 }
DiegoOstuni 0:cf62b690f57c 320
DiegoOstuni 0:cf62b690f57c 321
DiegoOstuni 0:cf62b690f57c 322 return NFCTAG_ConvertStatus( ret);
DiegoOstuni 0:cf62b690f57c 323 }
DiegoOstuni 0:cf62b690f57c 324
DiegoOstuni 0:cf62b690f57c 325
DiegoOstuni 0:cf62b690f57c 326 /**
DiegoOstuni 0:cf62b690f57c 327 * @brief Checks if target device is ready for communication
DiegoOstuni 0:cf62b690f57c 328 * @note This function is used with Memory devices
DiegoOstuni 0:cf62b690f57c 329 * @param DevAddr : Target device address
DiegoOstuni 0:cf62b690f57c 330 * @param mi2cChannel : I2C channel
DiegoOstuni 0:cf62b690f57c 331 * @retval NFCTAG enum status
DiegoOstuni 0:cf62b690f57c 332 */
DiegoOstuni 0:cf62b690f57c 333 NFCTAG_StatusTypeDef ST25DV_IO_IsDeviceReady( const uint8_t DevAddr, const uint32_t Trials, I2C* mi2cChannel)
DiegoOstuni 0:cf62b690f57c 334 {
DiegoOstuni 0:cf62b690f57c 335 int ret = 4;
DiegoOstuni 0:cf62b690f57c 336 uint32_t count = 0;
DiegoOstuni 0:cf62b690f57c 337
DiegoOstuni 0:cf62b690f57c 338 uint8_t Addr = DevAddr;
DiegoOstuni 0:cf62b690f57c 339
DiegoOstuni 0:cf62b690f57c 340
DiegoOstuni 0:cf62b690f57c 341 while ((count++ < Trials && ret) ) {
DiegoOstuni 0:cf62b690f57c 342 ret = mi2cChannel -> write(Addr, NULL, 0 , false);
DiegoOstuni 0:cf62b690f57c 343 }
DiegoOstuni 0:cf62b690f57c 344 return NFCTAG_ConvertStatus(ret);
DiegoOstuni 0:cf62b690f57c 345 }
DiegoOstuni 0:cf62b690f57c 346
DiegoOstuni 0:cf62b690f57c 347
DiegoOstuni 0:cf62b690f57c 348
DiegoOstuni 0:cf62b690f57c 349
DiegoOstuni 0:cf62b690f57c 350 /**
DiegoOstuni 0:cf62b690f57c 351 * @}
DiegoOstuni 0:cf62b690f57c 352 */
DiegoOstuni 0:cf62b690f57c 353
DiegoOstuni 0:cf62b690f57c 354 /**
DiegoOstuni 0:cf62b690f57c 355 * @}
DiegoOstuni 0:cf62b690f57c 356 */
DiegoOstuni 0:cf62b690f57c 357
DiegoOstuni 0:cf62b690f57c 358 /**
DiegoOstuni 0:cf62b690f57c 359 * @}
DiegoOstuni 0:cf62b690f57c 360 */
DiegoOstuni 0:cf62b690f57c 361
DiegoOstuni 0:cf62b690f57c 362 /******************* (C) COPYRIGHT 2017 STMicroelectronics *****END OF FILE****/