This is a driver needed by NFCEEPROOM constructor for the ST ST25DV NFC chip.

Dependents:   mbed-os-example-nfc-EEPROM

Committer:
apalmieri
Date:
Tue Jan 28 15:54:19 2020 +0000
Revision:
0:dd89565c6276
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
apalmieri 0:dd89565c6276 1 /**
apalmieri 0:dd89565c6276 2 ******************************************************************************
apalmieri 0:dd89565c6276 3 * @file st25dv.c
apalmieri 0:dd89565c6276 4 * @author MMY Application Team
apalmieri 0:dd89565c6276 5 * @version $Revision: 3308 $
apalmieri 0:dd89565c6276 6 * @date $Date: 2017-01-13 11:19:33 +0100 (Fri, 13 Jan 2017) $
apalmieri 0:dd89565c6276 7 * @brief This file provides set of driver functions to manage communication
apalmieri 0:dd89565c6276 8 * between BSP and ST25DV chip.
apalmieri 0:dd89565c6276 9 ******************************************************************************
apalmieri 0:dd89565c6276 10 * @attention
apalmieri 0:dd89565c6276 11 *
apalmieri 0:dd89565c6276 12 * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
apalmieri 0:dd89565c6276 13 *
apalmieri 0:dd89565c6276 14 * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
apalmieri 0:dd89565c6276 15 * You may not use this file except in compliance with the License.
apalmieri 0:dd89565c6276 16 * You may obtain a copy of the License at:
apalmieri 0:dd89565c6276 17 *
apalmieri 0:dd89565c6276 18 * http://www.st.com/myliberty
apalmieri 0:dd89565c6276 19 *
apalmieri 0:dd89565c6276 20 * Unless required by applicable law or agreed to in writing, software
apalmieri 0:dd89565c6276 21 * distributed under the License is distributed on an "AS IS" BASIS,
apalmieri 0:dd89565c6276 22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
apalmieri 0:dd89565c6276 23 * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
apalmieri 0:dd89565c6276 24 * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
apalmieri 0:dd89565c6276 25 * See the License for the specific language governing permissions and
apalmieri 0:dd89565c6276 26 * limitations under the License.
apalmieri 0:dd89565c6276 27 *
apalmieri 0:dd89565c6276 28 ******************************************************************************
apalmieri 0:dd89565c6276 29 */
apalmieri 0:dd89565c6276 30
apalmieri 0:dd89565c6276 31 /* Includes ------------------------------------------------------------------*/
apalmieri 0:dd89565c6276 32 #include "st25dv.h"
apalmieri 0:dd89565c6276 33
apalmieri 0:dd89565c6276 34 #include "st25dv_driver.h"
apalmieri 0:dd89565c6276 35
apalmieri 0:dd89565c6276 36
apalmieri 0:dd89565c6276 37
apalmieri 0:dd89565c6276 38
apalmieri 0:dd89565c6276 39 /** @addtogroup BSP
apalmieri 0:dd89565c6276 40 * @{
apalmieri 0:dd89565c6276 41 */
apalmieri 0:dd89565c6276 42
apalmieri 0:dd89565c6276 43 /** @defgroup ST25DV ST25DV driver
apalmieri 0:dd89565c6276 44 * @brief This module implements the functions to drive the ST25DV NFC dynamic tag.
apalmieri 0:dd89565c6276 45 * @details As recommended by the STM32 Cube methodology, this driver provides a standard structure to expose the NFC tag standard API.\n
apalmieri 0:dd89565c6276 46 * It also provides an extended API through its extended driver structure.\n
apalmieri 0:dd89565c6276 47 * To be usable on any MCU, this driver calls several IOBus functions.
apalmieri 0:dd89565c6276 48 * The IOBus functions are implemented outside this driver, and are in charge of accessing the MCU peripherals used for the communication with the tag.
apalmieri 0:dd89565c6276 49 * @{
apalmieri 0:dd89565c6276 50 */
apalmieri 0:dd89565c6276 51
apalmieri 0:dd89565c6276 52 /* External variables --------------------------------------------------------*/
apalmieri 0:dd89565c6276 53 /* Private typedef -----------------------------------------------------------*/
apalmieri 0:dd89565c6276 54 /* Private defines -----------------------------------------------------------*/
apalmieri 0:dd89565c6276 55 /** @brief This component driver only supports 1 instance of the component */
apalmieri 0:dd89565c6276 56 #define ST25DV_MAX_INSTANCE 1
apalmieri 0:dd89565c6276 57
apalmieri 0:dd89565c6276 58
apalmieri 0:dd89565c6276 59 /* Private macros ------------------------------------------------------------*/
apalmieri 0:dd89565c6276 60 /* Private function prototypes -----------------------------------------------*/
apalmieri 0:dd89565c6276 61 NFCTAG_StatusTypeDef ST25DV_i2c_Init( I2C * mi2cChannel, DigitalOut* mLPD );
apalmieri 0:dd89565c6276 62 NFCTAG_StatusTypeDef ST25DV_i2c_ReadID( uint8_t * const pICRef, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 63 NFCTAG_StatusTypeDef ST25DV_i2c_ReadICRev( uint8_t * const pICRev, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 64 NFCTAG_StatusTypeDef ST25DV_i2c_IsDeviceReady( const uint32_t Trials, I2C * mi2cChannel);
apalmieri 0:dd89565c6276 65 NFCTAG_StatusTypeDef ST25DV_i2c_GetGPOStatus( uint16_t * const pGPOStatus, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 66 NFCTAG_StatusTypeDef ST25DV_i2c_ConfigureGPO( const uint16_t ITConf, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 67 NFCTAG_StatusTypeDef ST25DV_i2c_ReadITPulse( ST25DV_PULSE_DURATION * const pITtime, I2C * mi2cChannel);
apalmieri 0:dd89565c6276 68 NFCTAG_StatusTypeDef ST25DV_i2c_WriteITPulse( const ST25DV_PULSE_DURATION ITtime, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 69 NFCTAG_StatusTypeDef ST25DV_i2c_ReadData( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 70 NFCTAG_StatusTypeDef ST25DV_i2c_WriteData( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 71 NFCTAG_StatusTypeDef ST25DV_i2c_ReadDataCurrentAddr( uint8_t * const pData, const uint16_t NbByte, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 72 NFCTAG_StatusTypeDef ST25DV_i2c_ReadRegister( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte , I2C * mi2cChannel);
apalmieri 0:dd89565c6276 73 NFCTAG_StatusTypeDef ST25DV_i2c_WriteRegister( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 74 NFCTAG_StatusTypeDef ST25DV_i2c_ReadUID( ST25DV_UID * const pUid, I2C * mi2cChannel);
apalmieri 0:dd89565c6276 75 NFCTAG_StatusTypeDef ST25DV_i2c_ReadDSFID( uint8_t * const pDsfid, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 76 NFCTAG_StatusTypeDef ST25DV_i2c_ReadDsfidRFProtection( ST25DV_LOCK_STATUS * const pLockDsfid, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 77 NFCTAG_StatusTypeDef ST25DV_i2c_ReadAFI( uint8_t * const pAfi, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 78 NFCTAG_StatusTypeDef ST25DV_i2c_ReadAfiRFProtection( ST25DV_LOCK_STATUS * const pLockAfi, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 79 NFCTAG_StatusTypeDef ST25DV_i2c_ReadI2CProtectZone( ST25DV_I2C_PROT_ZONE * const pProtZone, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 80 NFCTAG_StatusTypeDef ST25DV_i2c_WriteI2CProtectZonex( const ST25DV_PROTECTION_ZONE Zone, const ST25DV_PROTECTION_CONF ReadWriteProtection, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 81 NFCTAG_StatusTypeDef ST25DV_i2c_ReadLockCCFile( ST25DV_LOCK_CCFILE * const pLockCCFile, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 82 NFCTAG_StatusTypeDef ST25DV_i2c_WriteLockCCFile( const ST25DV_CCFILE_BLOCK NbBlockCCFile, const ST25DV_LOCK_STATUS LockCCFile, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 83 NFCTAG_StatusTypeDef ST25DV_i2c_ReadLockCFG( ST25DV_LOCK_STATUS * const pLockCfg, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 84 NFCTAG_StatusTypeDef ST25DV_i2c_WriteLockCFG( const ST25DV_LOCK_STATUS LockCfg, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 85 NFCTAG_StatusTypeDef ST25DV_i2c_PresentI2CPassword( const ST25DV_PASSWD PassWord, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 86 NFCTAG_StatusTypeDef ST25DV_i2c_WriteI2CPassword( const ST25DV_PASSWD PassWord, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 87 NFCTAG_StatusTypeDef ST25DV_i2c_ReadRFZxSS( const ST25DV_PROTECTION_ZONE Zone, ST25DV_RF_PROT_ZONE * const pRfprotZone, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 88 NFCTAG_StatusTypeDef ST25DV_i2c_WriteRFZxSS( const ST25DV_PROTECTION_ZONE Zone, const ST25DV_RF_PROT_ZONE RfProtZone , I2C * mi2cChannel);
apalmieri 0:dd89565c6276 89 NFCTAG_StatusTypeDef ST25DV_i2c_ReadEndZonex( const ST25DV_END_ZONE EndZone, uint8_t * const pEndZ, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 90 NFCTAG_StatusTypeDef ST25DV_i2c_WriteEndZonex( const ST25DV_END_ZONE EndZone, const uint8_t EndZ, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 91 NFCTAG_StatusTypeDef ST25DV_i2c_InitEndZone( I2C * mi2cChannel );
apalmieri 0:dd89565c6276 92 NFCTAG_StatusTypeDef ST25DV_i2c_CreateUserZone( uint16_t Zone1Length, uint16_t Zone2Length, uint16_t Zone3Length, uint16_t Zone4Length, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 93 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMemSize( ST25DV_MEM_SIZE * const pSizeInfo, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 94 NFCTAG_StatusTypeDef ST25DV_i2c_ReadEHMode( ST25DV_EH_MODE_STATUS * const pEH_mode, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 95 NFCTAG_StatusTypeDef ST25DV_i2c_WriteEHMode( const ST25DV_EH_MODE_STATUS EH_mode, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 96 NFCTAG_StatusTypeDef ST25DV_i2c_ReadRFMngt( ST25DV_RF_MNGT * const pRF_Mngt, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 97 NFCTAG_StatusTypeDef ST25DV_i2c_WriteRFMngt( const uint8_t Rfmngt, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 98 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFDisable( ST25DV_EN_STATUS * const pRFDisable, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 99 NFCTAG_StatusTypeDef ST25DV_i2c_SetRFDisable( I2C * mi2cChannel );
apalmieri 0:dd89565c6276 100 NFCTAG_StatusTypeDef ST25DV_i2c_ResetRFDisable( I2C * mi2cChannel );
apalmieri 0:dd89565c6276 101 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFSleep( ST25DV_EN_STATUS * const pRFSleep, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 102 NFCTAG_StatusTypeDef ST25DV_i2c_SetRFSleep( I2C * mi2cChannel );
apalmieri 0:dd89565c6276 103 NFCTAG_StatusTypeDef ST25DV_i2c_ResetRFSleep( I2C * mi2cChannel );
apalmieri 0:dd89565c6276 104 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMBMode( ST25DV_EN_STATUS * const pMB_mode, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 105 NFCTAG_StatusTypeDef ST25DV_i2c_WriteMBMode( const ST25DV_EN_STATUS MB_mode, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 106 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMBWDG( uint8_t * const pWdgDela, I2C * mi2cChannely );
apalmieri 0:dd89565c6276 107 NFCTAG_StatusTypeDef ST25DV_i2c_WriteMBWDG( const uint8_t WdgDelay, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 108 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMailboxData( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 109 NFCTAG_StatusTypeDef ST25DV_i2c_WriteMailboxData( const uint8_t * const pData, const uint16_t NbByte, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 110 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMailboxRegister( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 111 NFCTAG_StatusTypeDef ST25DV_i2c_WriteMailboxRegister( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 112 NFCTAG_StatusTypeDef ST25DV_i2c_ReadI2CSecuritySession_Dyn( ST25DV_I2CSSO_STATUS * const pSession, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 113 NFCTAG_StatusTypeDef ST25DV_i2c_ReadITSTStatus_Dyn( uint8_t * const pITStatus, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 114 NFCTAG_StatusTypeDef ST25DV_i2c_ReadGPO_Dyn( uint8_t *GPOConfig, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 115 NFCTAG_StatusTypeDef ST25DV_i2c_GetGPO_en_Dyn( ST25DV_EN_STATUS * const pGPO_en, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 116 NFCTAG_StatusTypeDef ST25DV_i2c_SetGPO_en_Dyn( I2C * mi2cChannel );
apalmieri 0:dd89565c6276 117 NFCTAG_StatusTypeDef ST25DV_i2c_ResetGPO_en_Dyn( I2C * mi2cChannel );
apalmieri 0:dd89565c6276 118 NFCTAG_StatusTypeDef ST25DV_i2c_ReadEHCtrl_Dyn( ST25DV_EH_CTRL * const pEH_CTRL, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 119 NFCTAG_StatusTypeDef ST25DV_i2c_GetEHENMode_Dyn( ST25DV_EN_STATUS * const pEH_Val, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 120 NFCTAG_StatusTypeDef ST25DV_i2c_SetEHENMode_Dyn( I2C * mi2cChannel );
apalmieri 0:dd89565c6276 121 NFCTAG_StatusTypeDef ST25DV_i2c_ResetEHENMode_Dyn( I2C * mi2cChannel );
apalmieri 0:dd89565c6276 122 NFCTAG_StatusTypeDef ST25DV_i2c_GetEHON_Dyn( ST25DV_EN_STATUS * const pEHON, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 123 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFField_Dyn( ST25DV_FIELD_STATUS * const pRF_Field, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 124 NFCTAG_StatusTypeDef ST25DV_i2c_GetVCC_Dyn( ST25DV_VCC_STATUS * const pVCC, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 125 NFCTAG_StatusTypeDef ST25DV_i2c_ReadRFMngt_Dyn( ST25DV_RF_MNGT * const pRF_Mngt, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 126 NFCTAG_StatusTypeDef ST25DV_i2c_WriteRFMngt_Dyn( const uint8_t RF_Mngt, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 127 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFDisable_Dyn( ST25DV_EN_STATUS * const pRFDisable, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 128 NFCTAG_StatusTypeDef ST25DV_i2c_SetRFDisable_Dyn( I2C * mi2cChannel );
apalmieri 0:dd89565c6276 129 NFCTAG_StatusTypeDef ST25DV_i2c_ResetRFDisable_Dyn( I2C * mi2cChannel );
apalmieri 0:dd89565c6276 130 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFSleep_Dyn( ST25DV_EN_STATUS * const pRFSleep, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 131 NFCTAG_StatusTypeDef ST25DV_i2c_SetRFSleep_Dyn( I2C * mi2cChannel );
apalmieri 0:dd89565c6276 132 NFCTAG_StatusTypeDef ST25DV_i2c_ResetRFSleep_Dyn( I2C * mi2cChannel );
apalmieri 0:dd89565c6276 133 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMBCtrl_Dyn( ST25DV_MB_CTRL_DYN_STATUS * const pCtrlStatus, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 134 NFCTAG_StatusTypeDef ST25DV_i2c_GetMBEN_Dyn( ST25DV_EN_STATUS * const pMBEN, I2C * mi2cChannel);
apalmieri 0:dd89565c6276 135 NFCTAG_StatusTypeDef ST25DV_i2c_SetMBEN_Dyn( I2C * mi2cChannel );
apalmieri 0:dd89565c6276 136 NFCTAG_StatusTypeDef ST25DV_i2c_ResetMBEN_Dyn( I2C * mi2cChannel );
apalmieri 0:dd89565c6276 137 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMBLength_Dyn( uint8_t * const pMBLength, I2C * mi2cChannel );
apalmieri 0:dd89565c6276 138
apalmieri 0:dd89565c6276 139 /* Global variables ---------------------------------------------------------*/
apalmieri 0:dd89565c6276 140 /**
apalmieri 0:dd89565c6276 141 * @brief Standard NFC tag driver API for the ST25DV.
apalmieri 0:dd89565c6276 142 * @details Provides a generic way to access the ST25DV implementation of the NFC tag standard driver functions.
apalmieri 0:dd89565c6276 143 */
apalmieri 0:dd89565c6276 144 NFCTAG_DrvTypeDef St25Dv_i2c_Drv =
apalmieri 0:dd89565c6276 145 {
apalmieri 0:dd89565c6276 146 ST25DV_i2c_Init,
apalmieri 0:dd89565c6276 147 ST25DV_i2c_ReadID,
apalmieri 0:dd89565c6276 148 ST25DV_i2c_IsDeviceReady,
apalmieri 0:dd89565c6276 149 ST25DV_i2c_GetGPOStatus,
apalmieri 0:dd89565c6276 150 ST25DV_i2c_ConfigureGPO,
apalmieri 0:dd89565c6276 151 ST25DV_i2c_ReadData,
apalmieri 0:dd89565c6276 152 ST25DV_i2c_WriteData,
apalmieri 0:dd89565c6276 153 ST25DV_i2c_ReadRegister,
apalmieri 0:dd89565c6276 154 ST25DV_i2c_WriteRegister,
apalmieri 0:dd89565c6276 155 NULL
apalmieri 0:dd89565c6276 156 };
apalmieri 0:dd89565c6276 157
apalmieri 0:dd89565c6276 158 /**
apalmieri 0:dd89565c6276 159 * @brief Extended NFC tag driver API for the ST25DV.
apalmieri 0:dd89565c6276 160 * @details Provides a generic way to access the ST25DV extended driver functions.
apalmieri 0:dd89565c6276 161 */
apalmieri 0:dd89565c6276 162 NFCTAG_ExtDrvTypeDef St25Dv_i2c_ExtDrv =
apalmieri 0:dd89565c6276 163 {
apalmieri 0:dd89565c6276 164 ST25DV_i2c_ReadICRev,
apalmieri 0:dd89565c6276 165 ST25DV_i2c_WriteITPulse,
apalmieri 0:dd89565c6276 166 ST25DV_i2c_ReadITPulse,
apalmieri 0:dd89565c6276 167 ST25DV_i2c_ReadDataCurrentAddr,
apalmieri 0:dd89565c6276 168 ST25DV_i2c_ReadUID,
apalmieri 0:dd89565c6276 169 ST25DV_i2c_ReadDSFID,
apalmieri 0:dd89565c6276 170 ST25DV_i2c_ReadDsfidRFProtection,
apalmieri 0:dd89565c6276 171 ST25DV_i2c_ReadAFI,
apalmieri 0:dd89565c6276 172 ST25DV_i2c_ReadAfiRFProtection,
apalmieri 0:dd89565c6276 173 ST25DV_i2c_ReadI2CProtectZone,
apalmieri 0:dd89565c6276 174 ST25DV_i2c_WriteI2CProtectZonex,
apalmieri 0:dd89565c6276 175 ST25DV_i2c_ReadLockCCFile,
apalmieri 0:dd89565c6276 176 ST25DV_i2c_WriteLockCCFile,
apalmieri 0:dd89565c6276 177 ST25DV_i2c_ReadLockCFG,
apalmieri 0:dd89565c6276 178 ST25DV_i2c_WriteLockCFG,
apalmieri 0:dd89565c6276 179 ST25DV_i2c_PresentI2CPassword,
apalmieri 0:dd89565c6276 180 ST25DV_i2c_WriteI2CPassword,
apalmieri 0:dd89565c6276 181 ST25DV_i2c_ReadRFZxSS,
apalmieri 0:dd89565c6276 182 ST25DV_i2c_WriteRFZxSS,
apalmieri 0:dd89565c6276 183 ST25DV_i2c_ReadEndZonex,
apalmieri 0:dd89565c6276 184 ST25DV_i2c_WriteEndZonex,
apalmieri 0:dd89565c6276 185 ST25DV_i2c_InitEndZone,
apalmieri 0:dd89565c6276 186 ST25DV_i2c_CreateUserZone,
apalmieri 0:dd89565c6276 187 ST25DV_i2c_ReadMemSize,
apalmieri 0:dd89565c6276 188 ST25DV_i2c_ReadEHMode,
apalmieri 0:dd89565c6276 189 ST25DV_i2c_WriteEHMode,
apalmieri 0:dd89565c6276 190 ST25DV_i2c_ReadRFMngt,
apalmieri 0:dd89565c6276 191 ST25DV_i2c_WriteRFMngt,
apalmieri 0:dd89565c6276 192 ST25DV_i2c_GetRFDisable,
apalmieri 0:dd89565c6276 193 ST25DV_i2c_SetRFDisable,
apalmieri 0:dd89565c6276 194 ST25DV_i2c_ResetRFDisable,
apalmieri 0:dd89565c6276 195 ST25DV_i2c_GetRFSleep,
apalmieri 0:dd89565c6276 196 ST25DV_i2c_SetRFSleep,
apalmieri 0:dd89565c6276 197 ST25DV_i2c_ResetRFSleep,
apalmieri 0:dd89565c6276 198 ST25DV_i2c_ReadMBMode,
apalmieri 0:dd89565c6276 199 ST25DV_i2c_WriteMBMode,
apalmieri 0:dd89565c6276 200 ST25DV_i2c_ReadMBWDG,
apalmieri 0:dd89565c6276 201 ST25DV_i2c_WriteMBWDG,
apalmieri 0:dd89565c6276 202 ST25DV_i2c_ReadMailboxData,
apalmieri 0:dd89565c6276 203 ST25DV_i2c_WriteMailboxData,
apalmieri 0:dd89565c6276 204 ST25DV_i2c_ReadMailboxRegister,
apalmieri 0:dd89565c6276 205 ST25DV_i2c_WriteMailboxRegister,
apalmieri 0:dd89565c6276 206 ST25DV_i2c_ReadI2CSecuritySession_Dyn,
apalmieri 0:dd89565c6276 207 ST25DV_i2c_ReadITSTStatus_Dyn,
apalmieri 0:dd89565c6276 208 ST25DV_i2c_ReadGPO_Dyn,
apalmieri 0:dd89565c6276 209 ST25DV_i2c_GetGPO_en_Dyn,
apalmieri 0:dd89565c6276 210 ST25DV_i2c_SetGPO_en_Dyn,
apalmieri 0:dd89565c6276 211 ST25DV_i2c_ResetGPO_en_Dyn,
apalmieri 0:dd89565c6276 212 ST25DV_i2c_ReadEHCtrl_Dyn,
apalmieri 0:dd89565c6276 213 ST25DV_i2c_GetEHENMode_Dyn,
apalmieri 0:dd89565c6276 214 ST25DV_i2c_SetEHENMode_Dyn,
apalmieri 0:dd89565c6276 215 ST25DV_i2c_ResetEHENMode_Dyn,
apalmieri 0:dd89565c6276 216 ST25DV_i2c_GetEHON_Dyn,
apalmieri 0:dd89565c6276 217 ST25DV_i2c_GetRFField_Dyn,
apalmieri 0:dd89565c6276 218 ST25DV_i2c_GetVCC_Dyn,
apalmieri 0:dd89565c6276 219 ST25DV_i2c_ReadRFMngt_Dyn,
apalmieri 0:dd89565c6276 220 ST25DV_i2c_WriteRFMngt_Dyn,
apalmieri 0:dd89565c6276 221 ST25DV_i2c_GetRFDisable_Dyn,
apalmieri 0:dd89565c6276 222 ST25DV_i2c_SetRFDisable_Dyn,
apalmieri 0:dd89565c6276 223 ST25DV_i2c_ResetRFDisable_Dyn,
apalmieri 0:dd89565c6276 224 ST25DV_i2c_GetRFSleep_Dyn,
apalmieri 0:dd89565c6276 225 ST25DV_i2c_SetRFSleep_Dyn,
apalmieri 0:dd89565c6276 226 ST25DV_i2c_ResetRFSleep_Dyn,
apalmieri 0:dd89565c6276 227 ST25DV_i2c_ReadMBCtrl_Dyn,
apalmieri 0:dd89565c6276 228 ST25DV_i2c_GetMBEN_Dyn,
apalmieri 0:dd89565c6276 229 ST25DV_i2c_SetMBEN_Dyn,
apalmieri 0:dd89565c6276 230 ST25DV_i2c_ResetMBEN_Dyn,
apalmieri 0:dd89565c6276 231 ST25DV_i2c_ReadMBLength_Dyn
apalmieri 0:dd89565c6276 232 };
apalmieri 0:dd89565c6276 233
apalmieri 0:dd89565c6276 234
apalmieri 0:dd89565c6276 235 /** @brief ST25DV instances by address. */
apalmieri 0:dd89565c6276 236 uint8_t aSt25Dv[ST25DV_MAX_INSTANCE] = {0};
apalmieri 0:dd89565c6276 237
apalmieri 0:dd89565c6276 238
apalmieri 0:dd89565c6276 239 /* Public functions ---------------------------------------------------------*/
apalmieri 0:dd89565c6276 240 /**
apalmieri 0:dd89565c6276 241 * @brief ST25DV nfctag Initialization.
apalmieri 0:dd89565c6276 242 * @param mi2cChannel : I2C channel
apalmieri 0:dd89565c6276 243 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 244 */
apalmieri 0:dd89565c6276 245 NFCTAG_StatusTypeDef ST25DV_i2c_Init( I2C* mi2cChannel, DigitalOut * mLPD )
apalmieri 0:dd89565c6276 246 {
apalmieri 0:dd89565c6276 247 /* Configure the low level interface */
apalmieri 0:dd89565c6276 248 return ST25DV_IO_Init( mi2cChannel, mLPD );
apalmieri 0:dd89565c6276 249 }
apalmieri 0:dd89565c6276 250
apalmieri 0:dd89565c6276 251 /**
apalmieri 0:dd89565c6276 252 * @brief Reads the ST25DV ID.
apalmieri 0:dd89565c6276 253 * @param pICRef Pointeron a uint8_t used to return the ST25DV ID.
apalmieri 0:dd89565c6276 254 * @param mi2cChannel : I2C channel
apalmieri 0:dd89565c6276 255 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 256 */
apalmieri 0:dd89565c6276 257 NFCTAG_StatusTypeDef ST25DV_i2c_ReadID( uint8_t * const pICRef, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 258 {
apalmieri 0:dd89565c6276 259 /* Read ICRef on device */
apalmieri 0:dd89565c6276 260 return ST25DV_i2c_ReadRegister( pICRef, ST25DV_ICREF_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 261 }
apalmieri 0:dd89565c6276 262
apalmieri 0:dd89565c6276 263 /**
apalmieri 0:dd89565c6276 264 * @brief Reads the ST25DV IC Revision.
apalmieri 0:dd89565c6276 265 * @param pICRev Pointer on the uint8_t used to return the ST25DV IC Revision number.
apalmieri 0:dd89565c6276 266 * @param mi2cChannel : I2C channel
apalmieri 0:dd89565c6276 267 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 268 */
apalmieri 0:dd89565c6276 269 NFCTAG_StatusTypeDef ST25DV_i2c_ReadICRev( uint8_t * const pICRev, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 270 {
apalmieri 0:dd89565c6276 271 /* Read ICRev on device */
apalmieri 0:dd89565c6276 272 return ST25DV_i2c_ReadRegister( pICRev, ST25DV_ICREV_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 273 }
apalmieri 0:dd89565c6276 274
apalmieri 0:dd89565c6276 275 /**
apalmieri 0:dd89565c6276 276 * @brief Checks the ST25DV availability.
apalmieri 0:dd89565c6276 277 * @details The ST25DV I2C is NACKed when a RF communication is on-going.
apalmieri 0:dd89565c6276 278 * This function determines if the ST25DV is ready to answer an I2C request.
apalmieri 0:dd89565c6276 279 * @param Trials Max number of tentative.
apalmieri 0:dd89565c6276 280 * @param mi2cChannel : I2C channel
apalmieri 0:dd89565c6276 281 * @retval NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 282 */
apalmieri 0:dd89565c6276 283 NFCTAG_StatusTypeDef ST25DV_i2c_IsDeviceReady( const uint32_t Trials, I2C * mi2cChannel)
apalmieri 0:dd89565c6276 284 {
apalmieri 0:dd89565c6276 285 /* Test communication with device */
apalmieri 0:dd89565c6276 286 return ST25DV_IO_IsDeviceReady( ST25DV_ADDR_DATA_I2C, Trials, mi2cChannel);
apalmieri 0:dd89565c6276 287 }
apalmieri 0:dd89565c6276 288
apalmieri 0:dd89565c6276 289 /**
apalmieri 0:dd89565c6276 290 * @brief Reads the ST25DV GPO configuration.
apalmieri 0:dd89565c6276 291 * @param pGPOStatus Pointer on a uint16_t used to return the current GPO consiguration, as:
apalmieri 0:dd89565c6276 292 * - RFUSERSTATE = 0x01
apalmieri 0:dd89565c6276 293 * - RFBUSY = 0x02
apalmieri 0:dd89565c6276 294 * - RFINTERRUPT = 0x04
apalmieri 0:dd89565c6276 295 * - FIELDFALLING = 0x08
apalmieri 0:dd89565c6276 296 * - FIELDRISING = 0x10
apalmieri 0:dd89565c6276 297 * - RFPUTMSG = 0x20
apalmieri 0:dd89565c6276 298 * - RFGETMSG = 0x40
apalmieri 0:dd89565c6276 299 * - RFWRITE = 0x80
apalmieri 0:dd89565c6276 300 * @param mi2cChannel : I2C channel
apalmieri 0:dd89565c6276 301 * @retval NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 302 */
apalmieri 0:dd89565c6276 303 NFCTAG_StatusTypeDef ST25DV_i2c_GetGPOStatus( uint16_t * const pGPOStatus, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 304 {
apalmieri 0:dd89565c6276 305 uint8_t reg_value;
apalmieri 0:dd89565c6276 306 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 307
apalmieri 0:dd89565c6276 308 /* Read value of GPO register */
apalmieri 0:dd89565c6276 309 status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_GPO_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 310 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 311 return status;
apalmieri 0:dd89565c6276 312
apalmieri 0:dd89565c6276 313 /* Extract GPO configuration */
apalmieri 0:dd89565c6276 314 *pGPOStatus = (uint16_t)reg_value;
apalmieri 0:dd89565c6276 315
apalmieri 0:dd89565c6276 316 return NFCTAG_OK;
apalmieri 0:dd89565c6276 317 }
apalmieri 0:dd89565c6276 318
apalmieri 0:dd89565c6276 319 /**
apalmieri 0:dd89565c6276 320 * @brief Configures the ST25DV GPO.
apalmieri 0:dd89565c6276 321 * @details Needs the I2C Password presentation to be effective.
apalmieri 0:dd89565c6276 322 * @param ITConf Provides the GPO configuration to apply:
apalmieri 0:dd89565c6276 323 * - RFUSERSTATE = 0x01
apalmieri 0:dd89565c6276 324 * - RFBUSY = 0x02
apalmieri 0:dd89565c6276 325 * - RFINTERRUPT = 0x04
apalmieri 0:dd89565c6276 326 * - FIELDFALLING = 0x08
apalmieri 0:dd89565c6276 327 * - FIELDRISING = 0x10
apalmieri 0:dd89565c6276 328 * - RFPUTMSG = 0x20
apalmieri 0:dd89565c6276 329 * - RFGETMSG = 0x40
apalmieri 0:dd89565c6276 330 * - RFWRITE = 0x80
apalmieri 0:dd89565c6276 331 *
apalmieri 0:dd89565c6276 332 * @param mi2cChannel : I2C channel
apalmieri 0:dd89565c6276 333 *
apalmieri 0:dd89565c6276 334 * @retval NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 335 */
apalmieri 0:dd89565c6276 336 NFCTAG_StatusTypeDef ST25DV_i2c_ConfigureGPO( const uint16_t ITConf, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 337 {
apalmieri 0:dd89565c6276 338 /* Write GPO configuration to register */
apalmieri 0:dd89565c6276 339 return ST25DV_i2c_WriteRegister( (uint8_t *)&ITConf, ST25DV_GPO_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 340 }
apalmieri 0:dd89565c6276 341
apalmieri 0:dd89565c6276 342
apalmieri 0:dd89565c6276 343 /**
apalmieri 0:dd89565c6276 344 * @brief Reads the ST25DV ITtime duration for the GPO pulses.
apalmieri 0:dd89565c6276 345 * @param pITtime Pointer used to return the coefficient for the GPO Pulse duration (Pulse duration = 302,06 us - ITtime * 512 / fc).
apalmieri 0:dd89565c6276 346 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 347 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 348 */
apalmieri 0:dd89565c6276 349 NFCTAG_StatusTypeDef ST25DV_i2c_ReadITPulse( ST25DV_PULSE_DURATION * const pITtime, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 350 {
apalmieri 0:dd89565c6276 351 uint8_t reg_value;
apalmieri 0:dd89565c6276 352 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 353
apalmieri 0:dd89565c6276 354 /* Read ITtime register value */
apalmieri 0:dd89565c6276 355 status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_ITTIME_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 356 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 357 {
apalmieri 0:dd89565c6276 358 return status;
apalmieri 0:dd89565c6276 359 }
apalmieri 0:dd89565c6276 360
apalmieri 0:dd89565c6276 361 /* Extract delay coefficient value */
apalmieri 0:dd89565c6276 362 *pITtime = (ST25DV_PULSE_DURATION)reg_value;
apalmieri 0:dd89565c6276 363
apalmieri 0:dd89565c6276 364 return NFCTAG_OK;
apalmieri 0:dd89565c6276 365 }
apalmieri 0:dd89565c6276 366
apalmieri 0:dd89565c6276 367 /**
apalmieri 0:dd89565c6276 368 * @brief Configures the ST25DV ITtime duration for the GPO pulse.
apalmieri 0:dd89565c6276 369 * @details Needs the I2C Password presentation to be effective.
apalmieri 0:dd89565c6276 370 * @param ITtime Coefficient for the Pulse duration to be written (Pulse duration = 302,06 us - ITtime * 512 / fc)
apalmieri 0:dd89565c6276 371 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 372 * @retval NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 373 */
apalmieri 0:dd89565c6276 374 NFCTAG_StatusTypeDef ST25DV_i2c_WriteITPulse( const ST25DV_PULSE_DURATION ITtime, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 375 {
apalmieri 0:dd89565c6276 376 uint8_t reg_value;
apalmieri 0:dd89565c6276 377
apalmieri 0:dd89565c6276 378 /* prepare data to write */
apalmieri 0:dd89565c6276 379 reg_value = (uint8_t)ITtime;
apalmieri 0:dd89565c6276 380
apalmieri 0:dd89565c6276 381 /* Write value for ITtime register */
apalmieri 0:dd89565c6276 382 return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_ITTIME_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 383 }
apalmieri 0:dd89565c6276 384
apalmieri 0:dd89565c6276 385 /**
apalmieri 0:dd89565c6276 386 * @brief Reads N bytes of Data, starting from the specified I2C address.
apalmieri 0:dd89565c6276 387 * @param pData Pointer used to return the read data.
apalmieri 0:dd89565c6276 388 * @param TarAddr I2C data memory address to read.
apalmieri 0:dd89565c6276 389 * @param NbByte Number of bytes to be read.
apalmieri 0:dd89565c6276 390 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 391 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 392 */
apalmieri 0:dd89565c6276 393 NFCTAG_StatusTypeDef ST25DV_i2c_ReadData( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel)
apalmieri 0:dd89565c6276 394 {
apalmieri 0:dd89565c6276 395 /* Read Data in user memory */
apalmieri 0:dd89565c6276 396 return ST25DV_IO_MemRead( pData, ST25DV_ADDR_DATA_I2C, TarAddr, NbByte, mi2cChannel );
apalmieri 0:dd89565c6276 397 }
apalmieri 0:dd89565c6276 398
apalmieri 0:dd89565c6276 399 /**
apalmieri 0:dd89565c6276 400 * @brief Writes N bytes of Data starting from the specified I2C Address.
apalmieri 0:dd89565c6276 401 * @param pData Pointer on the data to be written.
apalmieri 0:dd89565c6276 402 * @param TarAddr I2C data memory address to be written.
apalmieri 0:dd89565c6276 403 * @param NbByte Number of bytes to be written.
apalmieri 0:dd89565c6276 404 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 405 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 406 */
apalmieri 0:dd89565c6276 407 NFCTAG_StatusTypeDef ST25DV_i2c_WriteData( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C* mi2cChannel )
apalmieri 0:dd89565c6276 408 {
apalmieri 0:dd89565c6276 409 NFCTAG_StatusTypeDef ret;
apalmieri 0:dd89565c6276 410 NFCTAG_StatusTypeDef pollstatus;
apalmieri 0:dd89565c6276 411 uint16_t split_data_nb;
apalmieri 0:dd89565c6276 412 const uint8_t *pdata_index = (const uint8_t *)pData;
apalmieri 0:dd89565c6276 413
apalmieri 0:dd89565c6276 414 uint16_t bytes_to_write = NbByte;
apalmieri 0:dd89565c6276 415 uint16_t mem_addr = TarAddr;
apalmieri 0:dd89565c6276 416
apalmieri 0:dd89565c6276 417 /* ST25DV can write a maximum of 256 bytes in EEPROM per i2c communication */
apalmieri 0:dd89565c6276 418 do
apalmieri 0:dd89565c6276 419 {
apalmieri 0:dd89565c6276 420 /* Split write if data to write is superior of max write bytes for ST25DV */
apalmieri 0:dd89565c6276 421 if( bytes_to_write > ST25DV_MAX_WRITE_BYTE )
apalmieri 0:dd89565c6276 422 {
apalmieri 0:dd89565c6276 423 /* DataSize higher than max page write, copy data by page */
apalmieri 0:dd89565c6276 424 split_data_nb = (uint16_t)ST25DV_MAX_WRITE_BYTE;
apalmieri 0:dd89565c6276 425 }
apalmieri 0:dd89565c6276 426 else
apalmieri 0:dd89565c6276 427 {
apalmieri 0:dd89565c6276 428 /* DataSize lower or equal to max page write, copy only last bytes */
apalmieri 0:dd89565c6276 429 split_data_nb = bytes_to_write;
apalmieri 0:dd89565c6276 430 }
apalmieri 0:dd89565c6276 431 /* Write split_data_nb bytes in memory */
apalmieri 0:dd89565c6276 432 ret = ST25DV_IO_MemWrite( pdata_index, ST25DV_ADDR_DATA_I2C, mem_addr, split_data_nb, mi2cChannel);
apalmieri 0:dd89565c6276 433
apalmieri 0:dd89565c6276 434 Timer t;
apalmieri 0:dd89565c6276 435 /* POLLING, NEW CODE */
apalmieri 0:dd89565c6276 436 if( ret == 0 )
apalmieri 0:dd89565c6276 437 {
apalmieri 0:dd89565c6276 438 /* Poll until EEPROM is available */
apalmieri 0:dd89565c6276 439
apalmieri 0:dd89565c6276 440 int ms = 0;
apalmieri 0:dd89565c6276 441 /* Wait until ST25DV is ready or timeout occurs */
apalmieri 0:dd89565c6276 442 do
apalmieri 0:dd89565c6276 443 {
apalmieri 0:dd89565c6276 444 t.start();
apalmieri 0:dd89565c6276 445 pollstatus = ST25DV_IO_IsDeviceReady( ST25DV_ADDR_DATA_I2C , 1, mi2cChannel);
apalmieri 0:dd89565c6276 446 ms = t.read_ms();
apalmieri 0:dd89565c6276 447 t.stop();
apalmieri 0:dd89565c6276 448 } while( ( ms < ST25DV_I2C_TIMEOUT) && (pollstatus != NFCTAG_OK) );
apalmieri 0:dd89565c6276 449
apalmieri 0:dd89565c6276 450
apalmieri 0:dd89565c6276 451 if( pollstatus != NFCTAG_OK )
apalmieri 0:dd89565c6276 452 {
apalmieri 0:dd89565c6276 453 return NFCTAG_TIMEOUT;
apalmieri 0:dd89565c6276 454 }
apalmieri 0:dd89565c6276 455 }
apalmieri 0:dd89565c6276 456
apalmieri 0:dd89565c6276 457 /* update index, dest address, size for next write */
apalmieri 0:dd89565c6276 458 pdata_index += split_data_nb;
apalmieri 0:dd89565c6276 459 mem_addr += split_data_nb;
apalmieri 0:dd89565c6276 460 bytes_to_write -= split_data_nb;
apalmieri 0:dd89565c6276 461 }
apalmieri 0:dd89565c6276 462 while( ( bytes_to_write > 0 ) && ( ret == NFCTAG_OK ) );
apalmieri 0:dd89565c6276 463
apalmieri 0:dd89565c6276 464 return ret;
apalmieri 0:dd89565c6276 465 }
apalmieri 0:dd89565c6276 466
apalmieri 0:dd89565c6276 467 /**
apalmieri 0:dd89565c6276 468 * @brief Reads N bytes of Data, starting at current address.
apalmieri 0:dd89565c6276 469 * @param pData Pointer used to return the read data.
apalmieri 0:dd89565c6276 470 * @param NbByte Number of bytes to be read.
apalmieri 0:dd89565c6276 471 * @param mi2cChannel : I2C channel
apalmieri 0:dd89565c6276 472 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 473 */
apalmieri 0:dd89565c6276 474 NFCTAG_StatusTypeDef ST25DV_i2c_ReadDataCurrentAddr( uint8_t * const pData, const uint16_t NbByte, I2C* mi2cChannel )
apalmieri 0:dd89565c6276 475 {
apalmieri 0:dd89565c6276 476 /* Read Data in user memory */
apalmieri 0:dd89565c6276 477 return ST25DV_IO_Read( pData, ST25DV_ADDR_DATA_I2C, NbByte, mi2cChannel );
apalmieri 0:dd89565c6276 478 }
apalmieri 0:dd89565c6276 479
apalmieri 0:dd89565c6276 480 /**
apalmieri 0:dd89565c6276 481 * @brief Reads N bytes from Registers, starting at the specified I2C address.
apalmieri 0:dd89565c6276 482 * @param pData Pointer used to return the read data.
apalmieri 0:dd89565c6276 483 * @param TarAddr I2C memory address to be read.
apalmieri 0:dd89565c6276 484 * @param NbByte Number of bytes to be read.
apalmieri 0:dd89565c6276 485 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 486 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 487 */
apalmieri 0:dd89565c6276 488 NFCTAG_StatusTypeDef ST25DV_i2c_ReadRegister( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 489 {
apalmieri 0:dd89565c6276 490 /* Read Data in system memory */
apalmieri 0:dd89565c6276 491 return ST25DV_IO_MemRead( pData, ST25DV_ADDR_SYST_I2C, TarAddr, NbByte, mi2cChannel );
apalmieri 0:dd89565c6276 492 }
apalmieri 0:dd89565c6276 493
apalmieri 0:dd89565c6276 494 /**
apalmieri 0:dd89565c6276 495 * @brief Writes N bytes to the specified register.
apalmieri 0:dd89565c6276 496 * @details Needs the I2C Password presentation to be effective.
apalmieri 0:dd89565c6276 497 * @param pData Pointer on the data to be written.
apalmieri 0:dd89565c6276 498 * @param TarAddr I2C register address to written.
apalmieri 0:dd89565c6276 499 * @param NbByte Number of bytes to be written.
apalmieri 0:dd89565c6276 500 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 501 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 502 */
apalmieri 0:dd89565c6276 503 NFCTAG_StatusTypeDef ST25DV_i2c_WriteRegister( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 504 {
apalmieri 0:dd89565c6276 505 NFCTAG_StatusTypeDef ret;
apalmieri 0:dd89565c6276 506 NFCTAG_StatusTypeDef pollstatus;
apalmieri 0:dd89565c6276 507 uint8_t split_data_nb;
apalmieri 0:dd89565c6276 508 uint16_t bytes_to_write = NbByte;
apalmieri 0:dd89565c6276 509 uint16_t mem_addr = TarAddr;
apalmieri 0:dd89565c6276 510 const uint8_t *pdata_index = (const uint8_t *)pData;
apalmieri 0:dd89565c6276 511
apalmieri 0:dd89565c6276 512 /* ST25DV can write a maximum of 256 bytes in EEPROM per i2c communication */
apalmieri 0:dd89565c6276 513 do
apalmieri 0:dd89565c6276 514 {
apalmieri 0:dd89565c6276 515 /* Split write if data to write is superior of max write bytes for ST25DV */
apalmieri 0:dd89565c6276 516 if( bytes_to_write > ST25DV_MAX_WRITE_BYTE )
apalmieri 0:dd89565c6276 517 {
apalmieri 0:dd89565c6276 518 /* DataSize higher than max page write, copy data by page */
apalmieri 0:dd89565c6276 519 split_data_nb = (uint8_t)ST25DV_MAX_WRITE_BYTE;
apalmieri 0:dd89565c6276 520 }
apalmieri 0:dd89565c6276 521 else
apalmieri 0:dd89565c6276 522 {
apalmieri 0:dd89565c6276 523 /* DataSize lower or equal to max page write, copy only last bytes */
apalmieri 0:dd89565c6276 524 split_data_nb = bytes_to_write;
apalmieri 0:dd89565c6276 525 }
apalmieri 0:dd89565c6276 526 /* Write split_data_nb bytes in register */
apalmieri 0:dd89565c6276 527 ret = ST25DV_IO_MemWrite( pdata_index, ST25DV_ADDR_SYST_I2C, mem_addr, split_data_nb, mi2cChannel);
apalmieri 0:dd89565c6276 528
apalmieri 0:dd89565c6276 529 Timer t;
apalmieri 0:dd89565c6276 530 /* POLLING, NEW CODE */
apalmieri 0:dd89565c6276 531 if( ret == 0 )
apalmieri 0:dd89565c6276 532 {
apalmieri 0:dd89565c6276 533 int ms = 0;
apalmieri 0:dd89565c6276 534 /* Wait until ST25DV is ready or timeout occurs */
apalmieri 0:dd89565c6276 535 do
apalmieri 0:dd89565c6276 536 {
apalmieri 0:dd89565c6276 537 t.start();
apalmieri 0:dd89565c6276 538 pollstatus = ST25DV_IO_IsDeviceReady( ST25DV_ADDR_DATA_I2C , 1, mi2cChannel);
apalmieri 0:dd89565c6276 539 ms = t.read_ms();
apalmieri 0:dd89565c6276 540 t.stop();
apalmieri 0:dd89565c6276 541 } while( ( ms < ST25DV_I2C_TIMEOUT) && (pollstatus != NFCTAG_OK) );
apalmieri 0:dd89565c6276 542
apalmieri 0:dd89565c6276 543 if( pollstatus != NFCTAG_OK )
apalmieri 0:dd89565c6276 544 {
apalmieri 0:dd89565c6276 545 return NFCTAG_TIMEOUT;
apalmieri 0:dd89565c6276 546 }
apalmieri 0:dd89565c6276 547 }
apalmieri 0:dd89565c6276 548
apalmieri 0:dd89565c6276 549
apalmieri 0:dd89565c6276 550 /* update index, dest address, size for next write */
apalmieri 0:dd89565c6276 551 pdata_index += split_data_nb;
apalmieri 0:dd89565c6276 552 mem_addr += split_data_nb;
apalmieri 0:dd89565c6276 553 bytes_to_write -= split_data_nb;
apalmieri 0:dd89565c6276 554 }
apalmieri 0:dd89565c6276 555 while( ( bytes_to_write > 0 ) && ( ret == NFCTAG_OK ) );
apalmieri 0:dd89565c6276 556
apalmieri 0:dd89565c6276 557
apalmieri 0:dd89565c6276 558
apalmieri 0:dd89565c6276 559 return ret;
apalmieri 0:dd89565c6276 560 }
apalmieri 0:dd89565c6276 561
apalmieri 0:dd89565c6276 562 /**
apalmieri 0:dd89565c6276 563 * @brief Reads the ST25DV UID.
apalmieri 0:dd89565c6276 564 * @param pUid Pointer used to return the ST25DV UID value.
apalmieri 0:dd89565c6276 565 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 566 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 567 */
apalmieri 0:dd89565c6276 568 NFCTAG_StatusTypeDef ST25DV_i2c_ReadUID( ST25DV_UID * const pUid, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 569 {
apalmieri 0:dd89565c6276 570 uint8_t reg_value[8];
apalmieri 0:dd89565c6276 571 uint8_t i;
apalmieri 0:dd89565c6276 572 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 573
apalmieri 0:dd89565c6276 574 /* Read value of UID registers */
apalmieri 0:dd89565c6276 575 status = ST25DV_i2c_ReadRegister( reg_value, ST25DV_UID_REG, 8, mi2cChannel );
apalmieri 0:dd89565c6276 576 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 577 {
apalmieri 0:dd89565c6276 578 return status;
apalmieri 0:dd89565c6276 579 }
apalmieri 0:dd89565c6276 580
apalmieri 0:dd89565c6276 581 /* Store information in 2 WORD */
apalmieri 0:dd89565c6276 582 pUid->MsbUid = 0;
apalmieri 0:dd89565c6276 583
apalmieri 0:dd89565c6276 584 for( i = 0; i < 4; i++ )
apalmieri 0:dd89565c6276 585 {
apalmieri 0:dd89565c6276 586 pUid->MsbUid = (pUid->MsbUid << 8) | reg_value[7 - i];
apalmieri 0:dd89565c6276 587 }
apalmieri 0:dd89565c6276 588
apalmieri 0:dd89565c6276 589 pUid->LsbUid = 0;
apalmieri 0:dd89565c6276 590
apalmieri 0:dd89565c6276 591 for( i = 0; i < 4; i++ )
apalmieri 0:dd89565c6276 592 {
apalmieri 0:dd89565c6276 593 pUid->LsbUid = (pUid->LsbUid << 8) | reg_value[3 - i];
apalmieri 0:dd89565c6276 594 }
apalmieri 0:dd89565c6276 595
apalmieri 0:dd89565c6276 596 return NFCTAG_OK;
apalmieri 0:dd89565c6276 597 }
apalmieri 0:dd89565c6276 598
apalmieri 0:dd89565c6276 599 /**
apalmieri 0:dd89565c6276 600 * @brief Reads the ST25DV DSFID.
apalmieri 0:dd89565c6276 601 * @param pDsfid Pointer used to return the ST25DV DSFID value.
apalmieri 0:dd89565c6276 602 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 603 */
apalmieri 0:dd89565c6276 604 NFCTAG_StatusTypeDef ST25DV_i2c_ReadDSFID( uint8_t * const pDsfid, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 605 {
apalmieri 0:dd89565c6276 606 /* Read DSFID register */
apalmieri 0:dd89565c6276 607 return ST25DV_i2c_ReadRegister( pDsfid, ST25DV_DSFID_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 608 }
apalmieri 0:dd89565c6276 609
apalmieri 0:dd89565c6276 610 /**
apalmieri 0:dd89565c6276 611 * @brief Reads the ST25DV DSFID RF Lock state.
apalmieri 0:dd89565c6276 612 * @param pLockDsfid Pointer on a ST25DV_LOCK_STATUS used to return the DSFID lock state.
apalmieri 0:dd89565c6276 613 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 614 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 615 */
apalmieri 0:dd89565c6276 616 NFCTAG_StatusTypeDef ST25DV_i2c_ReadDsfidRFProtection( ST25DV_LOCK_STATUS * const pLockDsfid, I2C * mi2cChannel)
apalmieri 0:dd89565c6276 617 {
apalmieri 0:dd89565c6276 618 uint8_t reg_value;
apalmieri 0:dd89565c6276 619 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 620
apalmieri 0:dd89565c6276 621 /* Read register */
apalmieri 0:dd89565c6276 622 status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_LOCKDSFID_REG, 1 , mi2cChannel);
apalmieri 0:dd89565c6276 623 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 624 {
apalmieri 0:dd89565c6276 625 return status;
apalmieri 0:dd89565c6276 626 }
apalmieri 0:dd89565c6276 627
apalmieri 0:dd89565c6276 628 /* Extract Lock Status */
apalmieri 0:dd89565c6276 629 if( reg_value == 0 )
apalmieri 0:dd89565c6276 630 {
apalmieri 0:dd89565c6276 631 *pLockDsfid = ST25DV_UNLOCKED;
apalmieri 0:dd89565c6276 632 }
apalmieri 0:dd89565c6276 633 else
apalmieri 0:dd89565c6276 634 {
apalmieri 0:dd89565c6276 635 *pLockDsfid = ST25DV_LOCKED;
apalmieri 0:dd89565c6276 636 }
apalmieri 0:dd89565c6276 637 return NFCTAG_OK;
apalmieri 0:dd89565c6276 638 }
apalmieri 0:dd89565c6276 639
apalmieri 0:dd89565c6276 640 /**
apalmieri 0:dd89565c6276 641 * @brief Reads the ST25DV AFI.
apalmieri 0:dd89565c6276 642 * @param pAfi Pointer used to return the ST25DV AFI value.
apalmieri 0:dd89565c6276 643 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 644 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 645 */
apalmieri 0:dd89565c6276 646 NFCTAG_StatusTypeDef ST25DV_i2c_ReadAFI( uint8_t * const pAfi, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 647 {
apalmieri 0:dd89565c6276 648 /* Read AFI register */
apalmieri 0:dd89565c6276 649 return ST25DV_i2c_ReadRegister( pAfi, ST25DV_AFI_REG, 1 , mi2cChannel);
apalmieri 0:dd89565c6276 650 }
apalmieri 0:dd89565c6276 651
apalmieri 0:dd89565c6276 652 /**
apalmieri 0:dd89565c6276 653 * @brief Reads the AFI RF Lock state.
apalmieri 0:dd89565c6276 654 * @param pLockAfi Pointer on a ST25DV_LOCK_STATUS used to return the ASFID lock state.
apalmieri 0:dd89565c6276 655 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 656 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 657 */
apalmieri 0:dd89565c6276 658 NFCTAG_StatusTypeDef ST25DV_i2c_ReadAfiRFProtection( ST25DV_LOCK_STATUS * const pLockAfi, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 659 {
apalmieri 0:dd89565c6276 660 uint8_t reg_value;
apalmieri 0:dd89565c6276 661 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 662
apalmieri 0:dd89565c6276 663 /* Read register */
apalmieri 0:dd89565c6276 664 status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_LOCKAFI_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 665 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 666 {
apalmieri 0:dd89565c6276 667 return status;
apalmieri 0:dd89565c6276 668 }
apalmieri 0:dd89565c6276 669
apalmieri 0:dd89565c6276 670 /* Extract Lock Status */
apalmieri 0:dd89565c6276 671 if( reg_value == 0 )
apalmieri 0:dd89565c6276 672 {
apalmieri 0:dd89565c6276 673 *pLockAfi = ST25DV_UNLOCKED;
apalmieri 0:dd89565c6276 674 }
apalmieri 0:dd89565c6276 675 else
apalmieri 0:dd89565c6276 676 {
apalmieri 0:dd89565c6276 677 *pLockAfi = ST25DV_LOCKED;
apalmieri 0:dd89565c6276 678 }
apalmieri 0:dd89565c6276 679 return NFCTAG_OK;
apalmieri 0:dd89565c6276 680 }
apalmieri 0:dd89565c6276 681
apalmieri 0:dd89565c6276 682 /**
apalmieri 0:dd89565c6276 683 * @brief Reads the I2C Protected Area state.
apalmieri 0:dd89565c6276 684 * @param pProtZone Pointer on a ST25DV_I2C_PROT_ZONE structure used to return the Protected Area state.
apalmieri 0:dd89565c6276 685 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 686 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 687 */
apalmieri 0:dd89565c6276 688 NFCTAG_StatusTypeDef ST25DV_i2c_ReadI2CProtectZone( ST25DV_I2C_PROT_ZONE * const pProtZone, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 689 {
apalmieri 0:dd89565c6276 690 uint8_t reg_value;
apalmieri 0:dd89565c6276 691 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 692
apalmieri 0:dd89565c6276 693 /* Read value of I2c Protected Zone register */
apalmieri 0:dd89565c6276 694 status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_I2CZSS_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 695 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 696 {
apalmieri 0:dd89565c6276 697 return status;
apalmieri 0:dd89565c6276 698 }
apalmieri 0:dd89565c6276 699
apalmieri 0:dd89565c6276 700 /* Dispatch information to corresponding struct member */
apalmieri 0:dd89565c6276 701 pProtZone->ProtectZone1 = (ST25DV_PROTECTION_CONF)( (reg_value & ST25DV_I2CZSS_PZ1_MASK) >> ST25DV_I2CZSS_PZ1_SHIFT );
apalmieri 0:dd89565c6276 702 pProtZone->ProtectZone2 = (ST25DV_PROTECTION_CONF)( (reg_value & ST25DV_I2CZSS_PZ2_MASK) >> ST25DV_I2CZSS_PZ2_SHIFT );
apalmieri 0:dd89565c6276 703 pProtZone->ProtectZone3 = (ST25DV_PROTECTION_CONF)( (reg_value & ST25DV_I2CZSS_PZ3_MASK) >> ST25DV_I2CZSS_PZ3_SHIFT );
apalmieri 0:dd89565c6276 704 pProtZone->ProtectZone4 = (ST25DV_PROTECTION_CONF)( (reg_value & ST25DV_I2CZSS_PZ4_MASK) >> ST25DV_I2CZSS_PZ4_SHIFT );
apalmieri 0:dd89565c6276 705
apalmieri 0:dd89565c6276 706 return NFCTAG_OK;
apalmieri 0:dd89565c6276 707 }
apalmieri 0:dd89565c6276 708
apalmieri 0:dd89565c6276 709 /**
apalmieri 0:dd89565c6276 710 * @brief Sets the I2C write-protected state to an EEPROM Area.
apalmieri 0:dd89565c6276 711 * @details Needs the I2C Password presentation to be effective.
apalmieri 0:dd89565c6276 712 * @param Zone ST25DV_PROTECTION_ZONE value coresponding to the area to protect.
apalmieri 0:dd89565c6276 713 * @param ReadWriteProtection ST25DV_PROTECTION_CONF value corresponding to the protection to be set.
apalmieri 0:dd89565c6276 714 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 715 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 716 */
apalmieri 0:dd89565c6276 717 NFCTAG_StatusTypeDef ST25DV_i2c_WriteI2CProtectZonex( const ST25DV_PROTECTION_ZONE Zone, const ST25DV_PROTECTION_CONF ReadWriteProtection, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 718 {
apalmieri 0:dd89565c6276 719 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 720 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 721
apalmieri 0:dd89565c6276 722 /* Read actual i2c Zone Security Status */
apalmieri 0:dd89565c6276 723 status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_I2CZSS_REG, 1, mi2cChannel);
apalmieri 0:dd89565c6276 724 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 725 return status;
apalmieri 0:dd89565c6276 726
apalmieri 0:dd89565c6276 727 /* Compute and update new i2c Zone Security Status */
apalmieri 0:dd89565c6276 728 switch( Zone )
apalmieri 0:dd89565c6276 729 {
apalmieri 0:dd89565c6276 730 case ST25DV_PROT_ZONE1:
apalmieri 0:dd89565c6276 731 reg_value &= ST25DV_I2CZSS_PZ1_FIELD;
apalmieri 0:dd89565c6276 732 /* Read protection is not allowed for Zone 1 */
apalmieri 0:dd89565c6276 733 reg_value |= (ReadWriteProtection & 0x01) << ST25DV_I2CZSS_PZ1_SHIFT;
apalmieri 0:dd89565c6276 734 break;
apalmieri 0:dd89565c6276 735 case ST25DV_PROT_ZONE2:
apalmieri 0:dd89565c6276 736 reg_value &= ST25DV_I2CZSS_PZ2_FIELD;
apalmieri 0:dd89565c6276 737 reg_value |= ReadWriteProtection << ST25DV_I2CZSS_PZ2_SHIFT;
apalmieri 0:dd89565c6276 738 break;
apalmieri 0:dd89565c6276 739 case ST25DV_PROT_ZONE3:
apalmieri 0:dd89565c6276 740 reg_value &= ST25DV_I2CZSS_PZ3_FIELD;
apalmieri 0:dd89565c6276 741 reg_value |= ReadWriteProtection << ST25DV_I2CZSS_PZ3_SHIFT;
apalmieri 0:dd89565c6276 742 break;
apalmieri 0:dd89565c6276 743 case ST25DV_PROT_ZONE4:
apalmieri 0:dd89565c6276 744 reg_value &= ST25DV_I2CZSS_PZ4_FIELD;
apalmieri 0:dd89565c6276 745 reg_value |= ReadWriteProtection << ST25DV_I2CZSS_PZ4_SHIFT;
apalmieri 0:dd89565c6276 746 break;
apalmieri 0:dd89565c6276 747
apalmieri 0:dd89565c6276 748 default:
apalmieri 0:dd89565c6276 749 return NFCTAG_ERROR;
apalmieri 0:dd89565c6276 750 }
apalmieri 0:dd89565c6276 751
apalmieri 0:dd89565c6276 752 /* Write I2CZSS register */
apalmieri 0:dd89565c6276 753 return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_I2CZSS_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 754 }
apalmieri 0:dd89565c6276 755
apalmieri 0:dd89565c6276 756 /**
apalmieri 0:dd89565c6276 757 * @brief Reads the CCile protection state.
apalmieri 0:dd89565c6276 758 * @param pLockCCFile Pointer on a ST25DV_LOCK_CCFILE value corresponding to the lock state of the CCFile.
apalmieri 0:dd89565c6276 759 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 760 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 761 */
apalmieri 0:dd89565c6276 762 NFCTAG_StatusTypeDef ST25DV_i2c_ReadLockCCFile( ST25DV_LOCK_CCFILE * const pLockCCFile, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 763 {
apalmieri 0:dd89565c6276 764 uint8_t reg_value;
apalmieri 0:dd89565c6276 765 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 766
apalmieri 0:dd89565c6276 767 /* Get actual LOCKCCFILE register value */
apalmieri 0:dd89565c6276 768 status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_LOCKCCFILE_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 769 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 770 {
apalmieri 0:dd89565c6276 771 return status;
apalmieri 0:dd89565c6276 772 }
apalmieri 0:dd89565c6276 773
apalmieri 0:dd89565c6276 774 /* Extract CCFile block information */
apalmieri 0:dd89565c6276 775 if( (reg_value & ST25DV_LOCKCCFILE_BLCK0_MASK) == ST25DV_LOCKCCFILE_BLCK0_MASK )
apalmieri 0:dd89565c6276 776 {
apalmieri 0:dd89565c6276 777 pLockCCFile->LckBck0 = ST25DV_LOCKED;
apalmieri 0:dd89565c6276 778 }
apalmieri 0:dd89565c6276 779 else
apalmieri 0:dd89565c6276 780 {
apalmieri 0:dd89565c6276 781 pLockCCFile->LckBck0 = ST25DV_UNLOCKED;
apalmieri 0:dd89565c6276 782 }
apalmieri 0:dd89565c6276 783
apalmieri 0:dd89565c6276 784 if( (reg_value & ST25DV_LOCKCCFILE_BLCK1_MASK) == ST25DV_LOCKCCFILE_BLCK1_MASK )
apalmieri 0:dd89565c6276 785 {
apalmieri 0:dd89565c6276 786 pLockCCFile->LckBck1 = ST25DV_LOCKED;
apalmieri 0:dd89565c6276 787 }
apalmieri 0:dd89565c6276 788 else
apalmieri 0:dd89565c6276 789 {
apalmieri 0:dd89565c6276 790 pLockCCFile->LckBck1 = ST25DV_UNLOCKED;
apalmieri 0:dd89565c6276 791 }
apalmieri 0:dd89565c6276 792
apalmieri 0:dd89565c6276 793 return status;
apalmieri 0:dd89565c6276 794 }
apalmieri 0:dd89565c6276 795
apalmieri 0:dd89565c6276 796 /**
apalmieri 0:dd89565c6276 797 * @brief Locks the CCile to prevent any RF write access.
apalmieri 0:dd89565c6276 798 * @details Needs the I2C Password presentation to be effective.
apalmieri 0:dd89565c6276 799 * @param NbBlockCCFile ST25DV_CCFILE_BLOCK value corresponding to the number of blocks to be locked.
apalmieri 0:dd89565c6276 800 * @param LockCCFile ST25DV_LOCK_CCFILE value corresponding to the lock state to apply on the CCFile.
apalmieri 0:dd89565c6276 801 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 802 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 803 */
apalmieri 0:dd89565c6276 804 NFCTAG_StatusTypeDef ST25DV_i2c_WriteLockCCFile( const ST25DV_CCFILE_BLOCK NbBlockCCFile, const ST25DV_LOCK_STATUS LockCCFile, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 805 {
apalmieri 0:dd89565c6276 806 uint8_t reg_value;
apalmieri 0:dd89565c6276 807
apalmieri 0:dd89565c6276 808 /* Configure value to write on register */
apalmieri 0:dd89565c6276 809 if( NbBlockCCFile == ST25DV_CCFILE_1BLCK )
apalmieri 0:dd89565c6276 810 {
apalmieri 0:dd89565c6276 811 if( LockCCFile == ST25DV_LOCKED )
apalmieri 0:dd89565c6276 812 {
apalmieri 0:dd89565c6276 813 reg_value = ST25DV_LOCKCCFILE_BLCK0_MASK;
apalmieri 0:dd89565c6276 814 }
apalmieri 0:dd89565c6276 815 else
apalmieri 0:dd89565c6276 816 {
apalmieri 0:dd89565c6276 817 reg_value = 0x00;
apalmieri 0:dd89565c6276 818 }
apalmieri 0:dd89565c6276 819 }
apalmieri 0:dd89565c6276 820 else
apalmieri 0:dd89565c6276 821 {
apalmieri 0:dd89565c6276 822 if( LockCCFile == ST25DV_LOCKED )
apalmieri 0:dd89565c6276 823 {
apalmieri 0:dd89565c6276 824 reg_value = ST25DV_LOCKCCFILE_BLCK0_MASK | ST25DV_LOCKCCFILE_BLCK1_MASK;
apalmieri 0:dd89565c6276 825 }
apalmieri 0:dd89565c6276 826 else
apalmieri 0:dd89565c6276 827 {
apalmieri 0:dd89565c6276 828 reg_value = 0x00;
apalmieri 0:dd89565c6276 829 }
apalmieri 0:dd89565c6276 830 }
apalmieri 0:dd89565c6276 831
apalmieri 0:dd89565c6276 832 /* Write LOCKCCFILE register */
apalmieri 0:dd89565c6276 833 return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_LOCKCCFILE_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 834 }
apalmieri 0:dd89565c6276 835
apalmieri 0:dd89565c6276 836 /**
apalmieri 0:dd89565c6276 837 * @brief Reads the Cfg registers protection.
apalmieri 0:dd89565c6276 838 * @param pLockCfg Pointer on a ST25DV_LOCK_STATUS value corresponding to the Cfg registers lock state.
apalmieri 0:dd89565c6276 839 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 840 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 841 */
apalmieri 0:dd89565c6276 842 NFCTAG_StatusTypeDef ST25DV_i2c_ReadLockCFG( ST25DV_LOCK_STATUS * const pLockCfg, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 843 {
apalmieri 0:dd89565c6276 844 uint8_t reg_value;
apalmieri 0:dd89565c6276 845 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 846
apalmieri 0:dd89565c6276 847 /* Get actual LOCKCCFILE register value */
apalmieri 0:dd89565c6276 848 status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_LOCKCFG_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 849 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 850 {
apalmieri 0:dd89565c6276 851 return status;
apalmieri 0:dd89565c6276 852 }
apalmieri 0:dd89565c6276 853
apalmieri 0:dd89565c6276 854 /* Extract LOCKCFG block information */
apalmieri 0:dd89565c6276 855 if( (reg_value & ST25DV_LOCKCFG_B0_MASK) == ST25DV_LOCKCFG_B0_MASK )
apalmieri 0:dd89565c6276 856 {
apalmieri 0:dd89565c6276 857 *pLockCfg = ST25DV_LOCKED;
apalmieri 0:dd89565c6276 858 }
apalmieri 0:dd89565c6276 859 else
apalmieri 0:dd89565c6276 860 {
apalmieri 0:dd89565c6276 861 *pLockCfg = ST25DV_UNLOCKED;
apalmieri 0:dd89565c6276 862 }
apalmieri 0:dd89565c6276 863 return NFCTAG_OK;
apalmieri 0:dd89565c6276 864 }
apalmieri 0:dd89565c6276 865
apalmieri 0:dd89565c6276 866 /**
apalmieri 0:dd89565c6276 867 * @brief Lock/Unlock the Cfg registers, to prevent any RF write access.
apalmieri 0:dd89565c6276 868 * @details Needs the I2C Password presentation to be effective.
apalmieri 0:dd89565c6276 869 * @param LockCfg ST25DV_LOCK_STATUS value corresponding to the lock state to be written.
apalmieri 0:dd89565c6276 870 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 871 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 872 */
apalmieri 0:dd89565c6276 873 NFCTAG_StatusTypeDef ST25DV_i2c_WriteLockCFG( const ST25DV_LOCK_STATUS LockCfg, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 874 {
apalmieri 0:dd89565c6276 875 uint8_t reg_value;
apalmieri 0:dd89565c6276 876
apalmieri 0:dd89565c6276 877 /* Configure value to write on register */
apalmieri 0:dd89565c6276 878 reg_value = (uint8_t)LockCfg;
apalmieri 0:dd89565c6276 879
apalmieri 0:dd89565c6276 880 /* Write LOCKCFG register */
apalmieri 0:dd89565c6276 881 return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_LOCKCFG_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 882 }
apalmieri 0:dd89565c6276 883
apalmieri 0:dd89565c6276 884 /**
apalmieri 0:dd89565c6276 885 * @brief Presents I2C password, to authorize the I2C writes to protected areas.
apalmieri 0:dd89565c6276 886 * @param PassWord Password value on 32bits
apalmieri 0:dd89565c6276 887 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 888 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 889 */
apalmieri 0:dd89565c6276 890 NFCTAG_StatusTypeDef ST25DV_i2c_PresentI2CPassword( const ST25DV_PASSWD PassWord, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 891 {
apalmieri 0:dd89565c6276 892 uint8_t ai2c_message[17] = {0};
apalmieri 0:dd89565c6276 893 uint8_t i;
apalmieri 0:dd89565c6276 894
apalmieri 0:dd89565c6276 895 /* Build I2C Message with Password + Validation code 0x09 + Password */
apalmieri 0:dd89565c6276 896 ai2c_message[8] = 0x09;
apalmieri 0:dd89565c6276 897 for( i = 0; i < 4; i++ )
apalmieri 0:dd89565c6276 898 {
apalmieri 0:dd89565c6276 899 ai2c_message[i] = ( PassWord.MsbPasswd >> ( (3 - i) * 8) ) & 0xFF;
apalmieri 0:dd89565c6276 900 ai2c_message[i + 4] = ( PassWord.LsbPasswd >> ( (3 - i) * 8) ) & 0xFF;
apalmieri 0:dd89565c6276 901 ai2c_message[i + 9] = ai2c_message[i];
apalmieri 0:dd89565c6276 902 ai2c_message[i + 13] = ai2c_message[i + 4];
apalmieri 0:dd89565c6276 903 };
apalmieri 0:dd89565c6276 904
apalmieri 0:dd89565c6276 905 /* Present password to ST25DV */
apalmieri 0:dd89565c6276 906 return ST25DV_i2c_WriteRegister( ai2c_message, ST25DV_I2CPASSWD_REG, 17, mi2cChannel );
apalmieri 0:dd89565c6276 907 }
apalmieri 0:dd89565c6276 908
apalmieri 0:dd89565c6276 909 /**
apalmieri 0:dd89565c6276 910 * @brief Writes a new I2C password.
apalmieri 0:dd89565c6276 911 * @details Needs the I2C Password presentation to be effective.
apalmieri 0:dd89565c6276 912 * @param PassWord New I2C PassWord value on 32bits.
apalmieri 0:dd89565c6276 913 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 914 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 915 */
apalmieri 0:dd89565c6276 916 NFCTAG_StatusTypeDef ST25DV_i2c_WriteI2CPassword( const ST25DV_PASSWD PassWord, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 917 {
apalmieri 0:dd89565c6276 918 uint8_t ai2c_message[17] = {0};
apalmieri 0:dd89565c6276 919 uint8_t i;
apalmieri 0:dd89565c6276 920
apalmieri 0:dd89565c6276 921 /* Build I2C Message with Password + Validation code 0x07 + Password */
apalmieri 0:dd89565c6276 922 ai2c_message[8] = 0x07;
apalmieri 0:dd89565c6276 923
apalmieri 0:dd89565c6276 924 for( i = 0; i < 4; i++ )
apalmieri 0:dd89565c6276 925 {
apalmieri 0:dd89565c6276 926 ai2c_message[i] = ( PassWord.MsbPasswd >> ( (3 - i) * 8) ) & 0xFF;
apalmieri 0:dd89565c6276 927 ai2c_message[i + 4] = ( PassWord.LsbPasswd >> ( (3 - i) * 8) ) & 0xFF;
apalmieri 0:dd89565c6276 928 ai2c_message[i + 9] = ai2c_message[i];
apalmieri 0:dd89565c6276 929 ai2c_message[i + 13] = ai2c_message[i + 4];
apalmieri 0:dd89565c6276 930 };
apalmieri 0:dd89565c6276 931
apalmieri 0:dd89565c6276 932 /* Write new password in I2CPASSWD register */
apalmieri 0:dd89565c6276 933 return ST25DV_i2c_WriteRegister( ai2c_message, ST25DV_I2CPASSWD_REG, 17, mi2cChannel );
apalmieri 0:dd89565c6276 934 }
apalmieri 0:dd89565c6276 935
apalmieri 0:dd89565c6276 936 /**
apalmieri 0:dd89565c6276 937 * @brief Reads the RF Zone Security Status (defining the allowed RF accesses).
apalmieri 0:dd89565c6276 938 * @param Zone ST25DV_PROTECTION_ZONE value coresponding to the protected area.
apalmieri 0:dd89565c6276 939 * @param pRfprotZone Pointer on a ST25DV_RF_PROT_ZONE value corresponding to the area protection state.
apalmieri 0:dd89565c6276 940 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 941 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 942 */
apalmieri 0:dd89565c6276 943 NFCTAG_StatusTypeDef ST25DV_i2c_ReadRFZxSS( const ST25DV_PROTECTION_ZONE Zone, ST25DV_RF_PROT_ZONE * const pRfprotZone, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 944 {
apalmieri 0:dd89565c6276 945 uint8_t reg_value;
apalmieri 0:dd89565c6276 946 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 947 uint16_t sector_security_addr;
apalmieri 0:dd89565c6276 948
apalmieri 0:dd89565c6276 949 /* Select Sector Security register address */
apalmieri 0:dd89565c6276 950 switch( Zone )
apalmieri 0:dd89565c6276 951 {
apalmieri 0:dd89565c6276 952 case ST25DV_PROT_ZONE1:
apalmieri 0:dd89565c6276 953 sector_security_addr = ST25DV_RFZ1SS_REG;
apalmieri 0:dd89565c6276 954 break;
apalmieri 0:dd89565c6276 955 case ST25DV_PROT_ZONE2:
apalmieri 0:dd89565c6276 956 sector_security_addr = ST25DV_RFZ2SS_REG;
apalmieri 0:dd89565c6276 957 break;
apalmieri 0:dd89565c6276 958 case ST25DV_PROT_ZONE3:
apalmieri 0:dd89565c6276 959 sector_security_addr = ST25DV_RFZ3SS_REG;
apalmieri 0:dd89565c6276 960 break;
apalmieri 0:dd89565c6276 961 case ST25DV_PROT_ZONE4:
apalmieri 0:dd89565c6276 962 sector_security_addr = ST25DV_RFZ4SS_REG;
apalmieri 0:dd89565c6276 963 break;
apalmieri 0:dd89565c6276 964
apalmieri 0:dd89565c6276 965 default:
apalmieri 0:dd89565c6276 966 return NFCTAG_ERROR;
apalmieri 0:dd89565c6276 967 }
apalmieri 0:dd89565c6276 968
apalmieri 0:dd89565c6276 969 /* Read actual value of Sector Security Status register */
apalmieri 0:dd89565c6276 970 status = ST25DV_i2c_ReadRegister( &reg_value, sector_security_addr, 1, mi2cChannel );
apalmieri 0:dd89565c6276 971 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 972 {
apalmieri 0:dd89565c6276 973 return status;
apalmieri 0:dd89565c6276 974 }
apalmieri 0:dd89565c6276 975
apalmieri 0:dd89565c6276 976 /* Extract Sector Security Status configuration */
apalmieri 0:dd89565c6276 977 pRfprotZone->PasswdCtrl = (ST25DV_PASSWD_PROT_STATUS)((reg_value & ST25DV_RFZSS_PWDCTRL_MASK) >> ST25DV_RFZSS_PWDCTRL_SHIFT);
apalmieri 0:dd89565c6276 978 pRfprotZone->RWprotection = (ST25DV_PROTECTION_CONF)((reg_value & ST25DV_RFZSS_RWPROT_MASK) >> ST25DV_RFZSS_RWPROT_SHIFT);
apalmieri 0:dd89565c6276 979
apalmieri 0:dd89565c6276 980 return NFCTAG_OK;
apalmieri 0:dd89565c6276 981 }
apalmieri 0:dd89565c6276 982
apalmieri 0:dd89565c6276 983 /**
apalmieri 0:dd89565c6276 984 * @brief Writes the RF Zone Security Status (defining the allowed RF accesses)
apalmieri 0:dd89565c6276 985 * @details Needs the I2C Password presentation to be effective.
apalmieri 0:dd89565c6276 986 * @param Zone ST25DV_PROTECTION_ZONE value corresponding to the area on which to set the RF protection.
apalmieri 0:dd89565c6276 987 * @param RfProtZone Pointer on a ST25DV_RF_PROT_ZONE value defininf the protection to be set on the area.
apalmieri 0:dd89565c6276 988 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 989 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 990 */
apalmieri 0:dd89565c6276 991 NFCTAG_StatusTypeDef ST25DV_i2c_WriteRFZxSS( const ST25DV_PROTECTION_ZONE Zone, const ST25DV_RF_PROT_ZONE RfProtZone, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 992 {
apalmieri 0:dd89565c6276 993 uint8_t reg_value;
apalmieri 0:dd89565c6276 994 uint16_t sector_security_addr;
apalmieri 0:dd89565c6276 995
apalmieri 0:dd89565c6276 996 /* Select Sector Security register address */
apalmieri 0:dd89565c6276 997 switch( Zone )
apalmieri 0:dd89565c6276 998 {
apalmieri 0:dd89565c6276 999 case ST25DV_PROT_ZONE1:
apalmieri 0:dd89565c6276 1000 sector_security_addr = ST25DV_RFZ1SS_REG;
apalmieri 0:dd89565c6276 1001 break;
apalmieri 0:dd89565c6276 1002 case ST25DV_PROT_ZONE2:
apalmieri 0:dd89565c6276 1003 sector_security_addr = ST25DV_RFZ2SS_REG;
apalmieri 0:dd89565c6276 1004 break;
apalmieri 0:dd89565c6276 1005 case ST25DV_PROT_ZONE3:
apalmieri 0:dd89565c6276 1006 sector_security_addr = ST25DV_RFZ3SS_REG;
apalmieri 0:dd89565c6276 1007 break;
apalmieri 0:dd89565c6276 1008 case ST25DV_PROT_ZONE4:
apalmieri 0:dd89565c6276 1009 sector_security_addr = ST25DV_RFZ4SS_REG;
apalmieri 0:dd89565c6276 1010 break;
apalmieri 0:dd89565c6276 1011
apalmieri 0:dd89565c6276 1012 default:
apalmieri 0:dd89565c6276 1013 return NFCTAG_ERROR;
apalmieri 0:dd89565c6276 1014 }
apalmieri 0:dd89565c6276 1015
apalmieri 0:dd89565c6276 1016 /* Update Sector Security Status */
apalmieri 0:dd89565c6276 1017 reg_value = (RfProtZone.RWprotection << ST25DV_RFZSS_RWPROT_SHIFT) & ST25DV_RFZSS_RWPROT_MASK;
apalmieri 0:dd89565c6276 1018 reg_value |= ((RfProtZone.PasswdCtrl << ST25DV_RFZSS_PWDCTRL_SHIFT) & ST25DV_RFZSS_PWDCTRL_MASK);
apalmieri 0:dd89565c6276 1019
apalmieri 0:dd89565c6276 1020 /* Write Sector Security register */
apalmieri 0:dd89565c6276 1021 return ST25DV_i2c_WriteRegister( &reg_value, sector_security_addr, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1022 }
apalmieri 0:dd89565c6276 1023
apalmieri 0:dd89565c6276 1024 /**
apalmieri 0:dd89565c6276 1025 * @brief Reads the value of the an area end address.
apalmieri 0:dd89565c6276 1026 * @param EndZone ST25DV_END_ZONE value corresponding to an area end address.
apalmieri 0:dd89565c6276 1027 * @param pEndZ Pointer used to return the end address of the area.
apalmieri 0:dd89565c6276 1028 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1029 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1030 */
apalmieri 0:dd89565c6276 1031 NFCTAG_StatusTypeDef ST25DV_i2c_ReadEndZonex( const ST25DV_END_ZONE EndZone, uint8_t * const pEndZ, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1032 {
apalmieri 0:dd89565c6276 1033 uint16_t mem_addr;
apalmieri 0:dd89565c6276 1034
apalmieri 0:dd89565c6276 1035 /* End zone register address to read */
apalmieri 0:dd89565c6276 1036 switch( EndZone )
apalmieri 0:dd89565c6276 1037 {
apalmieri 0:dd89565c6276 1038 case ST25DV_ZONE_END1:
apalmieri 0:dd89565c6276 1039 mem_addr = ST25DV_END1_REG;
apalmieri 0:dd89565c6276 1040 break;
apalmieri 0:dd89565c6276 1041 case ST25DV_ZONE_END2:
apalmieri 0:dd89565c6276 1042 mem_addr = ST25DV_END2_REG;
apalmieri 0:dd89565c6276 1043 break;
apalmieri 0:dd89565c6276 1044 case ST25DV_ZONE_END3:
apalmieri 0:dd89565c6276 1045 mem_addr = ST25DV_END3_REG;
apalmieri 0:dd89565c6276 1046 break;
apalmieri 0:dd89565c6276 1047
apalmieri 0:dd89565c6276 1048 default:
apalmieri 0:dd89565c6276 1049 return NFCTAG_ERROR;
apalmieri 0:dd89565c6276 1050 }
apalmieri 0:dd89565c6276 1051
apalmieri 0:dd89565c6276 1052 /* Read the corresponding End zone */
apalmieri 0:dd89565c6276 1053 return ST25DV_i2c_ReadRegister( pEndZ, mem_addr, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1054 }
apalmieri 0:dd89565c6276 1055
apalmieri 0:dd89565c6276 1056 /**
apalmieri 0:dd89565c6276 1057 * @brief Sets the end address of an area.
apalmieri 0:dd89565c6276 1058 * @details Needs the I2C Password presentation to be effective.
apalmieri 0:dd89565c6276 1059 * @note The ST25DV answers a NACK when setting the EndZone2 & EndZone3 to same value than repectively EndZone1 & EndZone2.\n
apalmieri 0:dd89565c6276 1060 * These NACKs are ok.
apalmieri 0:dd89565c6276 1061 * @param EndZone ST25DV_END_ZONE value corresponding to an area.
apalmieri 0:dd89565c6276 1062 * @param EndZ End zone value to be written.
apalmieri 0:dd89565c6276 1063 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1064 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1065 */
apalmieri 0:dd89565c6276 1066 NFCTAG_StatusTypeDef ST25DV_i2c_WriteEndZonex( const ST25DV_END_ZONE EndZone, const uint8_t EndZ , I2C * mi2cChannel)
apalmieri 0:dd89565c6276 1067 {
apalmieri 0:dd89565c6276 1068 uint16_t mem_addr;
apalmieri 0:dd89565c6276 1069 NFCTAG_StatusTypeDef ret;
apalmieri 0:dd89565c6276 1070
apalmieri 0:dd89565c6276 1071 /* End zone register address to write */
apalmieri 0:dd89565c6276 1072 switch( EndZone )
apalmieri 0:dd89565c6276 1073 {
apalmieri 0:dd89565c6276 1074 case ST25DV_ZONE_END1:
apalmieri 0:dd89565c6276 1075 mem_addr = ST25DV_END1_REG;
apalmieri 0:dd89565c6276 1076 break;
apalmieri 0:dd89565c6276 1077 case ST25DV_ZONE_END2:
apalmieri 0:dd89565c6276 1078 mem_addr = ST25DV_END2_REG;
apalmieri 0:dd89565c6276 1079 break;
apalmieri 0:dd89565c6276 1080 case ST25DV_ZONE_END3:
apalmieri 0:dd89565c6276 1081 mem_addr = ST25DV_END3_REG;
apalmieri 0:dd89565c6276 1082 break;
apalmieri 0:dd89565c6276 1083
apalmieri 0:dd89565c6276 1084 default:
apalmieri 0:dd89565c6276 1085 return NFCTAG_ERROR;
apalmieri 0:dd89565c6276 1086 }
apalmieri 0:dd89565c6276 1087
apalmieri 0:dd89565c6276 1088 /* Write the corresponding End zone value in register */
apalmieri 0:dd89565c6276 1089 ret = ST25DV_i2c_WriteRegister( &EndZ, mem_addr, 1,mi2cChannel );
apalmieri 0:dd89565c6276 1090
apalmieri 0:dd89565c6276 1091 return ret;
apalmieri 0:dd89565c6276 1092 }
apalmieri 0:dd89565c6276 1093
apalmieri 0:dd89565c6276 1094 /**
apalmieri 0:dd89565c6276 1095 * @brief Initializes the end address of the ST25DV areas with their default values (end of memory).
apalmieri 0:dd89565c6276 1096 * @details Needs the I2C Password presentation to be effective..
apalmieri 0:dd89565c6276 1097 * The ST25DV answers a NACK when setting the EndZone2 & EndZone3 to same value than repectively EndZone1 & EndZone2.
apalmieri 0:dd89565c6276 1098 * These NACKs are ok.
apalmieri 0:dd89565c6276 1099 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1100 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1101 */
apalmieri 0:dd89565c6276 1102 NFCTAG_StatusTypeDef ST25DV_i2c_InitEndZone( I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1103 {
apalmieri 0:dd89565c6276 1104 uint8_t endval = 0xFF;
apalmieri 0:dd89565c6276 1105 uint32_t maxmemlength;
apalmieri 0:dd89565c6276 1106 ST25DV_MEM_SIZE memsize;
apalmieri 0:dd89565c6276 1107 NFCTAG_StatusTypeDef ret;
apalmieri 0:dd89565c6276 1108
apalmieri 0:dd89565c6276 1109 memsize.Mem_Size = 0;
apalmieri 0:dd89565c6276 1110 memsize.BlockSize = 0;
apalmieri 0:dd89565c6276 1111
apalmieri 0:dd89565c6276 1112 /* Get EEPROM mem size */
apalmieri 0:dd89565c6276 1113 ST25DV_i2c_ReadMemSize( &memsize, mi2cChannel );
apalmieri 0:dd89565c6276 1114 maxmemlength = (memsize.Mem_Size + 1) * (memsize.BlockSize + 1);
apalmieri 0:dd89565c6276 1115
apalmieri 0:dd89565c6276 1116 /* Compute Max value for endzone register */
apalmieri 0:dd89565c6276 1117 endval = (maxmemlength / 32) - 1;
apalmieri 0:dd89565c6276 1118
apalmieri 0:dd89565c6276 1119 /* Write EndZone value to ST25DV registers */
apalmieri 0:dd89565c6276 1120 ret = ST25DV_i2c_WriteEndZonex( ST25DV_ZONE_END3, endval, mi2cChannel );
apalmieri 0:dd89565c6276 1121 if( (ret != NFCTAG_OK) && (ret != NFCTAG_NACK) )
apalmieri 0:dd89565c6276 1122 {
apalmieri 0:dd89565c6276 1123 return ret;
apalmieri 0:dd89565c6276 1124 }
apalmieri 0:dd89565c6276 1125
apalmieri 0:dd89565c6276 1126 ret = ST25DV_i2c_WriteEndZonex( ST25DV_ZONE_END2, endval, mi2cChannel );
apalmieri 0:dd89565c6276 1127 if( (ret != NFCTAG_OK) && (ret != NFCTAG_NACK) )
apalmieri 0:dd89565c6276 1128 {
apalmieri 0:dd89565c6276 1129 return ret;
apalmieri 0:dd89565c6276 1130 }
apalmieri 0:dd89565c6276 1131
apalmieri 0:dd89565c6276 1132 ret = ST25DV_i2c_WriteEndZonex( ST25DV_ZONE_END1, endval, mi2cChannel );
apalmieri 0:dd89565c6276 1133 if( (ret != NFCTAG_OK) && (ret != NFCTAG_NACK) )
apalmieri 0:dd89565c6276 1134 {
apalmieri 0:dd89565c6276 1135 return ret;
apalmieri 0:dd89565c6276 1136 }
apalmieri 0:dd89565c6276 1137
apalmieri 0:dd89565c6276 1138 return ret;
apalmieri 0:dd89565c6276 1139 }
apalmieri 0:dd89565c6276 1140
apalmieri 0:dd89565c6276 1141 /**
apalmieri 0:dd89565c6276 1142 * @brief Creates user areas with defined lengths.
apalmieri 0:dd89565c6276 1143 * @details Needs the I2C Password presentation to be effective.
apalmieri 0:dd89565c6276 1144 * @param Zone1Length Length of area1 in bytes (32 to 8192, 0x20 to 0x2000)
apalmieri 0:dd89565c6276 1145 * @param Zone2Length Length of area2 in bytes (0 to 8128, 0x00 to 0x1FC0)
apalmieri 0:dd89565c6276 1146 * @param Zone3Length Length of area3 in bytes (0 to 8064, 0x00 to 0x1F80)
apalmieri 0:dd89565c6276 1147 * @param Zone4Length Length of area4 in bytes (0 to 8000, 0x00 to 0x1F40)
apalmieri 0:dd89565c6276 1148 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1149 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1150 */
apalmieri 0:dd89565c6276 1151 NFCTAG_StatusTypeDef ST25DV_i2c_CreateUserZone( uint16_t Zone1Length, uint16_t Zone2Length, uint16_t Zone3Length, uint16_t Zone4Length, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1152 {
apalmieri 0:dd89565c6276 1153 uint8_t EndVal;
apalmieri 0:dd89565c6276 1154 ST25DV_MEM_SIZE memsize;
apalmieri 0:dd89565c6276 1155 uint16_t maxmemlength = 0;
apalmieri 0:dd89565c6276 1156 NFCTAG_StatusTypeDef ret;
apalmieri 0:dd89565c6276 1157
apalmieri 0:dd89565c6276 1158 memsize.Mem_Size = 0;
apalmieri 0:dd89565c6276 1159 memsize.BlockSize = 0;
apalmieri 0:dd89565c6276 1160
apalmieri 0:dd89565c6276 1161 ST25DV_i2c_ReadMemSize( &memsize, mi2cChannel );
apalmieri 0:dd89565c6276 1162
apalmieri 0:dd89565c6276 1163 maxmemlength = (memsize.Mem_Size + 1) * (memsize.BlockSize + 1);
apalmieri 0:dd89565c6276 1164
apalmieri 0:dd89565c6276 1165 /* Checks that values of different zones are in bounds */
apalmieri 0:dd89565c6276 1166 if( ( Zone1Length < 32 ) || ( Zone1Length > maxmemlength ) || ( Zone2Length > (maxmemlength - 32) )
apalmieri 0:dd89565c6276 1167 || ( Zone3Length > (maxmemlength - 64) ) || ( Zone4Length > (maxmemlength - 96) ) )
apalmieri 0:dd89565c6276 1168 {
apalmieri 0:dd89565c6276 1169 return NFCTAG_ERROR;
apalmieri 0:dd89565c6276 1170 }
apalmieri 0:dd89565c6276 1171
apalmieri 0:dd89565c6276 1172 /* Checks that the total is less than the authorised maximum */
apalmieri 0:dd89565c6276 1173 if( ( Zone1Length + Zone2Length + Zone3Length + Zone4Length ) > maxmemlength )
apalmieri 0:dd89565c6276 1174 {
apalmieri 0:dd89565c6276 1175 return NFCTAG_ERROR;
apalmieri 0:dd89565c6276 1176 }
apalmieri 0:dd89565c6276 1177
apalmieri 0:dd89565c6276 1178 /* if The value for each Length is not a multiple of 64 correct it. */
apalmieri 0:dd89565c6276 1179 if( (Zone1Length % 32) != 0 )
apalmieri 0:dd89565c6276 1180 {
apalmieri 0:dd89565c6276 1181 Zone1Length = Zone1Length - ( Zone1Length % 32 );
apalmieri 0:dd89565c6276 1182 }
apalmieri 0:dd89565c6276 1183
apalmieri 0:dd89565c6276 1184 if( (Zone2Length % 32) != 0 )
apalmieri 0:dd89565c6276 1185 {
apalmieri 0:dd89565c6276 1186 Zone2Length = Zone2Length - ( Zone2Length % 32 );
apalmieri 0:dd89565c6276 1187 }
apalmieri 0:dd89565c6276 1188
apalmieri 0:dd89565c6276 1189 if( (Zone3Length % 32) != 0 )
apalmieri 0:dd89565c6276 1190 {
apalmieri 0:dd89565c6276 1191 Zone3Length = Zone3Length - ( Zone3Length % 32 );
apalmieri 0:dd89565c6276 1192 }
apalmieri 0:dd89565c6276 1193
apalmieri 0:dd89565c6276 1194 /* First right 0xFF in each Endx value */
apalmieri 0:dd89565c6276 1195 ret = ST25DV_i2c_InitEndZone( mi2cChannel );
apalmieri 0:dd89565c6276 1196 if( (ret != NFCTAG_OK) && (ret != NFCTAG_NACK) )
apalmieri 0:dd89565c6276 1197 {
apalmieri 0:dd89565c6276 1198 return ret;
apalmieri 0:dd89565c6276 1199 }
apalmieri 0:dd89565c6276 1200
apalmieri 0:dd89565c6276 1201 /* Then Write corresponding value for each zone */
apalmieri 0:dd89565c6276 1202 EndVal = (uint8_t)( (Zone1Length / 32 ) - 1 );
apalmieri 0:dd89565c6276 1203 ret = ST25DV_i2c_WriteEndZonex( ST25DV_ZONE_END1, EndVal, mi2cChannel );
apalmieri 0:dd89565c6276 1204 if( (ret != NFCTAG_OK) && (ret != NFCTAG_NACK) )
apalmieri 0:dd89565c6276 1205 {
apalmieri 0:dd89565c6276 1206 return ret;
apalmieri 0:dd89565c6276 1207 }
apalmieri 0:dd89565c6276 1208
apalmieri 0:dd89565c6276 1209 EndVal = (uint8_t)( ((Zone1Length + Zone2Length) / 32 ) - 1 );
apalmieri 0:dd89565c6276 1210 ret = ST25DV_i2c_WriteEndZonex( ST25DV_ZONE_END2, EndVal, mi2cChannel );
apalmieri 0:dd89565c6276 1211 if( (ret != NFCTAG_OK) && (ret != NFCTAG_NACK) )
apalmieri 0:dd89565c6276 1212 {
apalmieri 0:dd89565c6276 1213 return ret;
apalmieri 0:dd89565c6276 1214 }
apalmieri 0:dd89565c6276 1215
apalmieri 0:dd89565c6276 1216 EndVal = (uint8_t)( ((Zone1Length + Zone2Length + Zone3Length) / 32 ) - 1 );
apalmieri 0:dd89565c6276 1217 ret = ST25DV_i2c_WriteEndZonex( ST25DV_ZONE_END3, EndVal, mi2cChannel );
apalmieri 0:dd89565c6276 1218 if( (ret != NFCTAG_OK) && (ret != NFCTAG_NACK) )
apalmieri 0:dd89565c6276 1219 {
apalmieri 0:dd89565c6276 1220 return ret;
apalmieri 0:dd89565c6276 1221 }
apalmieri 0:dd89565c6276 1222
apalmieri 0:dd89565c6276 1223 return NFCTAG_OK;
apalmieri 0:dd89565c6276 1224 }
apalmieri 0:dd89565c6276 1225
apalmieri 0:dd89565c6276 1226 /**
apalmieri 0:dd89565c6276 1227 * @brief Reads the ST25DV Memory Size.
apalmieri 0:dd89565c6276 1228 * @param pSizeInfo Pointer on a ST25DV_MEM_SIZE structure used to return the Memory size information.
apalmieri 0:dd89565c6276 1229 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1230 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1231 */
apalmieri 0:dd89565c6276 1232 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMemSize( ST25DV_MEM_SIZE * const pSizeInfo, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1233 {
apalmieri 0:dd89565c6276 1234 uint8_t reg_value[3];
apalmieri 0:dd89565c6276 1235 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1236
apalmieri 0:dd89565c6276 1237 /* Read actual value of MEM_SIZE register,cheeeeeeeeeeeeeck*/
apalmieri 0:dd89565c6276 1238 status = ST25DV_i2c_ReadRegister( reg_value, ST25DV_MEM_SIZE_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1239 status = ST25DV_i2c_ReadRegister( reg_value + 1, ST25DV_MEM_SIZE_REG + 1, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1240 status = ST25DV_i2c_ReadRegister( reg_value + 2, ST25DV_MEM_SIZE_REG + 2, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1241
apalmieri 0:dd89565c6276 1242
apalmieri 0:dd89565c6276 1243 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 1244 return status;
apalmieri 0:dd89565c6276 1245
apalmieri 0:dd89565c6276 1246 /* Extract Memory information */
apalmieri 0:dd89565c6276 1247 pSizeInfo->BlockSize = reg_value[2];
apalmieri 0:dd89565c6276 1248 pSizeInfo->Mem_Size = reg_value[1];
apalmieri 0:dd89565c6276 1249 pSizeInfo->Mem_Size = (pSizeInfo->Mem_Size << 8) | reg_value[0];
apalmieri 0:dd89565c6276 1250 return NFCTAG_OK;
apalmieri 0:dd89565c6276 1251 }
apalmieri 0:dd89565c6276 1252
apalmieri 0:dd89565c6276 1253 /**
apalmieri 0:dd89565c6276 1254 * @brief Reads the Energy harvesting mode.
apalmieri 0:dd89565c6276 1255 * @param pEH_mode Pointer on a ST25DV_EH_MODE_STATUS value corresponding to the Energy Harvesting state.
apalmieri 0:dd89565c6276 1256 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1257 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1258 */
apalmieri 0:dd89565c6276 1259 NFCTAG_StatusTypeDef ST25DV_i2c_ReadEHMode( ST25DV_EH_MODE_STATUS * const pEH_mode, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1260 {
apalmieri 0:dd89565c6276 1261 uint8_t reg_value;
apalmieri 0:dd89565c6276 1262 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1263
apalmieri 0:dd89565c6276 1264 /* Read actual value of EH_MODE register */
apalmieri 0:dd89565c6276 1265 status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_EH_MODE_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1266 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 1267 return status;
apalmieri 0:dd89565c6276 1268
apalmieri 0:dd89565c6276 1269 /* Extract EH_mode configuration */
apalmieri 0:dd89565c6276 1270 if( (reg_value & ST25DV_EH_MODE_MASK) == ST25DV_EH_MODE_MASK )
apalmieri 0:dd89565c6276 1271 {
apalmieri 0:dd89565c6276 1272 *pEH_mode = ST25DV_EH_ON_DEMAND;
apalmieri 0:dd89565c6276 1273 }
apalmieri 0:dd89565c6276 1274 else
apalmieri 0:dd89565c6276 1275 {
apalmieri 0:dd89565c6276 1276 *pEH_mode = ST25DV_EH_ACTIVE_AFTER_BOOT;
apalmieri 0:dd89565c6276 1277 }
apalmieri 0:dd89565c6276 1278
apalmieri 0:dd89565c6276 1279 return NFCTAG_OK;
apalmieri 0:dd89565c6276 1280 }
apalmieri 0:dd89565c6276 1281
apalmieri 0:dd89565c6276 1282 /**
apalmieri 0:dd89565c6276 1283 * @brief Sets the Energy harvesting mode.
apalmieri 0:dd89565c6276 1284 * @details Needs the I2C Password presentation to be effective.
apalmieri 0:dd89565c6276 1285 * @param EH_mode ST25DV_EH_MODE_STATUS value for the Energy harvesting mode to be set.
apalmieri 0:dd89565c6276 1286 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1287 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1288 */
apalmieri 0:dd89565c6276 1289 NFCTAG_StatusTypeDef ST25DV_i2c_WriteEHMode( const ST25DV_EH_MODE_STATUS EH_mode, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1290 {
apalmieri 0:dd89565c6276 1291 uint8_t reg_value;
apalmieri 0:dd89565c6276 1292
apalmieri 0:dd89565c6276 1293 /* Update EH_mode */
apalmieri 0:dd89565c6276 1294 reg_value = (uint8_t)EH_mode;
apalmieri 0:dd89565c6276 1295
apalmieri 0:dd89565c6276 1296 /* Write EH_MODE register */
apalmieri 0:dd89565c6276 1297 return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_EH_MODE_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1298 }
apalmieri 0:dd89565c6276 1299
apalmieri 0:dd89565c6276 1300 /**
apalmieri 0:dd89565c6276 1301 * @brief Reads the RF Management configuration.
apalmieri 0:dd89565c6276 1302 * @param pRF_Mngt Pointer on a ST25DV_RF_MNGT structure used to return the RF Management configuration.
apalmieri 0:dd89565c6276 1303 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1304 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1305 */
apalmieri 0:dd89565c6276 1306 NFCTAG_StatusTypeDef ST25DV_i2c_ReadRFMngt( ST25DV_RF_MNGT * const pRF_Mngt, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1307 {
apalmieri 0:dd89565c6276 1308 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1309 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 1310
apalmieri 0:dd89565c6276 1311 /* Read actual value of RF_MNGT register */
apalmieri 0:dd89565c6276 1312 status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1313
apalmieri 0:dd89565c6276 1314 if( status == NFCTAG_OK )
apalmieri 0:dd89565c6276 1315 {
apalmieri 0:dd89565c6276 1316 /* Extract RF Disable information */
apalmieri 0:dd89565c6276 1317 if( (reg_value & ST25DV_RF_MNGT_RFDIS_MASK) == ST25DV_RF_MNGT_RFDIS_MASK )
apalmieri 0:dd89565c6276 1318 {
apalmieri 0:dd89565c6276 1319 pRF_Mngt->RfDisable = ST25DV_ENABLE;
apalmieri 0:dd89565c6276 1320 }
apalmieri 0:dd89565c6276 1321 else
apalmieri 0:dd89565c6276 1322 {
apalmieri 0:dd89565c6276 1323 pRF_Mngt->RfDisable = ST25DV_DISABLE;
apalmieri 0:dd89565c6276 1324 }
apalmieri 0:dd89565c6276 1325
apalmieri 0:dd89565c6276 1326 /* Extract RF Sleep information */
apalmieri 0:dd89565c6276 1327 if( (reg_value & ST25DV_RF_MNGT_RFSLEEP_MASK) == ST25DV_RF_MNGT_RFSLEEP_MASK )
apalmieri 0:dd89565c6276 1328 {
apalmieri 0:dd89565c6276 1329 pRF_Mngt->RfSleep = ST25DV_ENABLE;
apalmieri 0:dd89565c6276 1330 }
apalmieri 0:dd89565c6276 1331 else
apalmieri 0:dd89565c6276 1332 {
apalmieri 0:dd89565c6276 1333 pRF_Mngt->RfSleep = ST25DV_DISABLE;
apalmieri 0:dd89565c6276 1334 }
apalmieri 0:dd89565c6276 1335 }
apalmieri 0:dd89565c6276 1336
apalmieri 0:dd89565c6276 1337 return status;
apalmieri 0:dd89565c6276 1338 }
apalmieri 0:dd89565c6276 1339
apalmieri 0:dd89565c6276 1340 /**
apalmieri 0:dd89565c6276 1341 * @brief Sets the RF Management configuration.
apalmieri 0:dd89565c6276 1342 * @details Needs the I2C Password presentation to be effective.
apalmieri 0:dd89565c6276 1343 * @param Rfmngt Value of the RF Management configuration to be written.
apalmieri 0:dd89565c6276 1344 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1345 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1346 */
apalmieri 0:dd89565c6276 1347 NFCTAG_StatusTypeDef ST25DV_i2c_WriteRFMngt( const uint8_t Rfmngt, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1348 {
apalmieri 0:dd89565c6276 1349 /* Write RF_MNGT register */
apalmieri 0:dd89565c6276 1350 return ST25DV_i2c_WriteRegister( &Rfmngt, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1351 }
apalmieri 0:dd89565c6276 1352
apalmieri 0:dd89565c6276 1353 /**
apalmieri 0:dd89565c6276 1354 * @brief Reads the RFDisable register information.
apalmieri 0:dd89565c6276 1355 * @param pRFDisable Pointer on a ST25DV_EN_STATUS value corresponding to the RF Disable status.
apalmieri 0:dd89565c6276 1356 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1357 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1358 */
apalmieri 0:dd89565c6276 1359 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFDisable( ST25DV_EN_STATUS * const pRFDisable, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1360 {
apalmieri 0:dd89565c6276 1361 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1362 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 1363
apalmieri 0:dd89565c6276 1364 /* Read actual value of RF_MNGT register */
apalmieri 0:dd89565c6276 1365 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1366
apalmieri 0:dd89565c6276 1367 /* Extract RFDisable information */
apalmieri 0:dd89565c6276 1368 if( status == NFCTAG_OK )
apalmieri 0:dd89565c6276 1369 {
apalmieri 0:dd89565c6276 1370 if( (reg_value & ST25DV_RF_MNGT_RFDIS_MASK) == ST25DV_RF_MNGT_RFDIS_MASK )
apalmieri 0:dd89565c6276 1371 {
apalmieri 0:dd89565c6276 1372 *pRFDisable = ST25DV_ENABLE;
apalmieri 0:dd89565c6276 1373 }
apalmieri 0:dd89565c6276 1374 else
apalmieri 0:dd89565c6276 1375 {
apalmieri 0:dd89565c6276 1376 *pRFDisable = ST25DV_DISABLE;
apalmieri 0:dd89565c6276 1377 }
apalmieri 0:dd89565c6276 1378 return NFCTAG_OK;
apalmieri 0:dd89565c6276 1379 }
apalmieri 0:dd89565c6276 1380
apalmieri 0:dd89565c6276 1381 return status;
apalmieri 0:dd89565c6276 1382 }
apalmieri 0:dd89565c6276 1383
apalmieri 0:dd89565c6276 1384 /**
apalmieri 0:dd89565c6276 1385 * @brief Sets the RF Disable configuration.
apalmieri 0:dd89565c6276 1386 * @details Needs the I2C Password presentation to be effective.7
apalmieri 0:dd89565c6276 1387 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1388 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1389 */
apalmieri 0:dd89565c6276 1390 NFCTAG_StatusTypeDef ST25DV_i2c_SetRFDisable( I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1391 {
apalmieri 0:dd89565c6276 1392 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1393 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 1394
apalmieri 0:dd89565c6276 1395 /* Read actual value of RF_RMNGT register */
apalmieri 0:dd89565c6276 1396 status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1397 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 1398 {
apalmieri 0:dd89565c6276 1399 return status;
apalmieri 0:dd89565c6276 1400 }
apalmieri 0:dd89565c6276 1401
apalmieri 0:dd89565c6276 1402 /* Update RF Disable field configuration */
apalmieri 0:dd89565c6276 1403 reg_value |= ST25DV_RF_MNGT_RFDIS_MASK;
apalmieri 0:dd89565c6276 1404
apalmieri 0:dd89565c6276 1405 /* Write RF_MNGT register */
apalmieri 0:dd89565c6276 1406 return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1407 }
apalmieri 0:dd89565c6276 1408
apalmieri 0:dd89565c6276 1409 /**
apalmieri 0:dd89565c6276 1410 * @brief Resets the RF Disable configuration
apalmieri 0:dd89565c6276 1411 * @details Needs the I2C Password presentation to be effective.
apalmieri 0:dd89565c6276 1412 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1413 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1414 */
apalmieri 0:dd89565c6276 1415 NFCTAG_StatusTypeDef ST25DV_i2c_ResetRFDisable( I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1416 {
apalmieri 0:dd89565c6276 1417 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1418 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 1419
apalmieri 0:dd89565c6276 1420 /* Read actual value of RF_RMNGT register */
apalmieri 0:dd89565c6276 1421 status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1422 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 1423 {
apalmieri 0:dd89565c6276 1424 return status;
apalmieri 0:dd89565c6276 1425 }
apalmieri 0:dd89565c6276 1426
apalmieri 0:dd89565c6276 1427 /* Update RF Disable field configuration */
apalmieri 0:dd89565c6276 1428 reg_value &= ST25DV_RF_MNGT_RFDIS_FIELD;
apalmieri 0:dd89565c6276 1429
apalmieri 0:dd89565c6276 1430 /* Write RF_MNGT register */
apalmieri 0:dd89565c6276 1431 return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1432 }
apalmieri 0:dd89565c6276 1433
apalmieri 0:dd89565c6276 1434 /**
apalmieri 0:dd89565c6276 1435 * @brief Reads the RFSleep register information.
apalmieri 0:dd89565c6276 1436 * @param pRFSleep Pointer on a ST25DV_EN_STATUS value corresponding to the RF Sleep status.
apalmieri 0:dd89565c6276 1437 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1438 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1439 */
apalmieri 0:dd89565c6276 1440 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFSleep( ST25DV_EN_STATUS * const pRFSleep, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1441 {
apalmieri 0:dd89565c6276 1442 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1443 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 1444
apalmieri 0:dd89565c6276 1445 /* Read actual value of RF_MNGT register */
apalmieri 0:dd89565c6276 1446 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1447
apalmieri 0:dd89565c6276 1448 /* Extract RFSleep information */
apalmieri 0:dd89565c6276 1449 if( status == NFCTAG_OK )
apalmieri 0:dd89565c6276 1450 {
apalmieri 0:dd89565c6276 1451 if( (reg_value & ST25DV_RF_MNGT_RFDIS_MASK) == ST25DV_RF_MNGT_RFDIS_MASK )
apalmieri 0:dd89565c6276 1452 {
apalmieri 0:dd89565c6276 1453 *pRFSleep = ST25DV_ENABLE;
apalmieri 0:dd89565c6276 1454 }
apalmieri 0:dd89565c6276 1455 else
apalmieri 0:dd89565c6276 1456 {
apalmieri 0:dd89565c6276 1457 *pRFSleep = ST25DV_DISABLE;
apalmieri 0:dd89565c6276 1458 }
apalmieri 0:dd89565c6276 1459 return NFCTAG_OK;
apalmieri 0:dd89565c6276 1460 }
apalmieri 0:dd89565c6276 1461
apalmieri 0:dd89565c6276 1462 return status;
apalmieri 0:dd89565c6276 1463 }
apalmieri 0:dd89565c6276 1464
apalmieri 0:dd89565c6276 1465 /**
apalmieri 0:dd89565c6276 1466 * @brief Sets the RF Sleep configuration.
apalmieri 0:dd89565c6276 1467 * @details Needs the I2C Password presentation to be effective.
apalmieri 0:dd89565c6276 1468 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1469 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1470 */
apalmieri 0:dd89565c6276 1471 NFCTAG_StatusTypeDef ST25DV_i2c_SetRFSleep( I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1472 {
apalmieri 0:dd89565c6276 1473 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1474 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 1475
apalmieri 0:dd89565c6276 1476 /* Read actual value of RF_RMNGT register */
apalmieri 0:dd89565c6276 1477 status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1478 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 1479 {
apalmieri 0:dd89565c6276 1480 return status;
apalmieri 0:dd89565c6276 1481 }
apalmieri 0:dd89565c6276 1482
apalmieri 0:dd89565c6276 1483 /* Update RF Sleep field configuration */
apalmieri 0:dd89565c6276 1484 reg_value |= ST25DV_RF_MNGT_RFSLEEP_MASK;
apalmieri 0:dd89565c6276 1485
apalmieri 0:dd89565c6276 1486 /* Write RF_MNGT register */
apalmieri 0:dd89565c6276 1487 return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_RF_MNGT_REG, 1,mi2cChannel );
apalmieri 0:dd89565c6276 1488 }
apalmieri 0:dd89565c6276 1489
apalmieri 0:dd89565c6276 1490 /**
apalmieri 0:dd89565c6276 1491 * @brief Resets the RF Sleep configuration.
apalmieri 0:dd89565c6276 1492 * @details Needs the I2C Password presentation to be effective.
apalmieri 0:dd89565c6276 1493 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1494 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1495 */
apalmieri 0:dd89565c6276 1496 NFCTAG_StatusTypeDef ST25DV_i2c_ResetRFSleep( I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1497 {
apalmieri 0:dd89565c6276 1498 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1499 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 1500
apalmieri 0:dd89565c6276 1501 /* Read actual value of RF_RMNGT register */
apalmieri 0:dd89565c6276 1502 status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1503 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 1504 {
apalmieri 0:dd89565c6276 1505 return status;
apalmieri 0:dd89565c6276 1506 }
apalmieri 0:dd89565c6276 1507
apalmieri 0:dd89565c6276 1508 /* Update RF Sleep field configuration */
apalmieri 0:dd89565c6276 1509 reg_value &= ST25DV_RF_MNGT_RFSLEEP_FIELD;
apalmieri 0:dd89565c6276 1510
apalmieri 0:dd89565c6276 1511 /* Write RF_MNGT register */
apalmieri 0:dd89565c6276 1512 return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1513 }
apalmieri 0:dd89565c6276 1514
apalmieri 0:dd89565c6276 1515 /**
apalmieri 0:dd89565c6276 1516 * @brief Reads the Mailbox mode.
apalmieri 0:dd89565c6276 1517 * @param pMB_mode Pointer on a ST25DV_EH_MODE_STATUS value used to return the Mailbox mode.
apalmieri 0:dd89565c6276 1518 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1519 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1520 */
apalmieri 0:dd89565c6276 1521 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMBMode( ST25DV_EN_STATUS * const pMB_mode, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1522 {
apalmieri 0:dd89565c6276 1523 uint8_t reg_value;
apalmieri 0:dd89565c6276 1524 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1525
apalmieri 0:dd89565c6276 1526 /* Read actual value of MB_MODE register */
apalmieri 0:dd89565c6276 1527 status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_MB_MODE_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1528 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 1529 {
apalmieri 0:dd89565c6276 1530 return status;
apalmieri 0:dd89565c6276 1531 }
apalmieri 0:dd89565c6276 1532
apalmieri 0:dd89565c6276 1533 /* Extract Mailbox mode status */
apalmieri 0:dd89565c6276 1534 if( (reg_value & ST25DV_MB_MODE_RW_MASK) == ST25DV_MB_MODE_RW_MASK )
apalmieri 0:dd89565c6276 1535 {
apalmieri 0:dd89565c6276 1536 *pMB_mode = ST25DV_ENABLE;
apalmieri 0:dd89565c6276 1537 }
apalmieri 0:dd89565c6276 1538 else
apalmieri 0:dd89565c6276 1539 {
apalmieri 0:dd89565c6276 1540 *pMB_mode = ST25DV_DISABLE;
apalmieri 0:dd89565c6276 1541 }
apalmieri 0:dd89565c6276 1542
apalmieri 0:dd89565c6276 1543 return NFCTAG_OK;
apalmieri 0:dd89565c6276 1544 }
apalmieri 0:dd89565c6276 1545
apalmieri 0:dd89565c6276 1546 /**
apalmieri 0:dd89565c6276 1547 * @brief Sets the Mailbox mode.
apalmieri 0:dd89565c6276 1548 * @details Needs the I2C Password presentation to be effective.
apalmieri 0:dd89565c6276 1549 * @param MB_mode ST25DV_EN_STATUS value corresponding to the Mailbox mode to be set.
apalmieri 0:dd89565c6276 1550 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1551 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1552 */
apalmieri 0:dd89565c6276 1553 NFCTAG_StatusTypeDef ST25DV_i2c_WriteMBMode( const ST25DV_EN_STATUS MB_mode, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1554 {
apalmieri 0:dd89565c6276 1555 uint8_t reg_value;
apalmieri 0:dd89565c6276 1556
apalmieri 0:dd89565c6276 1557 /* Update Mailbox mode status */
apalmieri 0:dd89565c6276 1558 reg_value = (uint8_t)MB_mode;
apalmieri 0:dd89565c6276 1559
apalmieri 0:dd89565c6276 1560 /* Write MB_MODE register */
apalmieri 0:dd89565c6276 1561 return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_MB_MODE_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1562 }
apalmieri 0:dd89565c6276 1563
apalmieri 0:dd89565c6276 1564 /**
apalmieri 0:dd89565c6276 1565 * @brief Reads the Mailbox watchdog duration coefficient.
apalmieri 0:dd89565c6276 1566 * @param pWdgDelay Pointer on a uint8_t used to return the watchdog duration coefficient.
apalmieri 0:dd89565c6276 1567 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1568 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1569 */
apalmieri 0:dd89565c6276 1570 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMBWDG( uint8_t * const pWdgDelay, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1571 {
apalmieri 0:dd89565c6276 1572 uint8_t reg_value;
apalmieri 0:dd89565c6276 1573 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1574
apalmieri 0:dd89565c6276 1575 /* Read actual value of MB_WDG register */
apalmieri 0:dd89565c6276 1576 status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_MB_WDG_REG, 1 , mi2cChannel);
apalmieri 0:dd89565c6276 1577 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 1578 {
apalmieri 0:dd89565c6276 1579 return status;
apalmieri 0:dd89565c6276 1580 }
apalmieri 0:dd89565c6276 1581
apalmieri 0:dd89565c6276 1582 /* Extract watchdog coefficient delay configuration */
apalmieri 0:dd89565c6276 1583 *pWdgDelay = (reg_value & ST25DV_MB_WDG_DELAY_MASK) >> ST25DV_MB_WDG_DELAY_SHIFT;
apalmieri 0:dd89565c6276 1584
apalmieri 0:dd89565c6276 1585 return NFCTAG_OK;
apalmieri 0:dd89565c6276 1586 }
apalmieri 0:dd89565c6276 1587
apalmieri 0:dd89565c6276 1588 /**
apalmieri 0:dd89565c6276 1589 * @brief Writes the Mailbox watchdog coefficient delay
apalmieri 0:dd89565c6276 1590 * @details Needs the I2C Password presentation to be effective.
apalmieri 0:dd89565c6276 1591 * @param WdgDelay Watchdog duration coefficient to be written (Watch dog duration = MB_WDG*30 ms +/- 6%).
apalmieri 0:dd89565c6276 1592 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1593 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1594 */
apalmieri 0:dd89565c6276 1595 NFCTAG_StatusTypeDef ST25DV_i2c_WriteMBWDG( const uint8_t WdgDelay, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1596 {
apalmieri 0:dd89565c6276 1597 uint8_t reg_value;
apalmieri 0:dd89565c6276 1598
apalmieri 0:dd89565c6276 1599 /* Set Watchdog coefficient delay */
apalmieri 0:dd89565c6276 1600 reg_value = WdgDelay & ST25DV_MB_WDG_DELAY_MASK;
apalmieri 0:dd89565c6276 1601
apalmieri 0:dd89565c6276 1602 /* Write MB_MODE register */
apalmieri 0:dd89565c6276 1603 return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_MB_WDG_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1604 }
apalmieri 0:dd89565c6276 1605
apalmieri 0:dd89565c6276 1606 /**
apalmieri 0:dd89565c6276 1607 * @brief Reads N bytes of data from the Mailbox, starting at the specified byte offset.
apalmieri 0:dd89565c6276 1608 * @param pData Pointer on the buffer used to return the read data.
apalmieri 0:dd89565c6276 1609 * @param Offset Offset in the Mailbox memory, byte number to start the read.
apalmieri 0:dd89565c6276 1610 * @param NbByte Number of bytes to be read.
apalmieri 0:dd89565c6276 1611 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1612 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1613 */
apalmieri 0:dd89565c6276 1614 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMailboxData( uint8_t * const pData, const uint16_t Offset, const uint16_t NbByte, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1615 {
apalmieri 0:dd89565c6276 1616 if( Offset > ST25DV_MAX_MAILBOX_LENGTH )
apalmieri 0:dd89565c6276 1617 {
apalmieri 0:dd89565c6276 1618 return NFCTAG_ERROR;
apalmieri 0:dd89565c6276 1619 }
apalmieri 0:dd89565c6276 1620
apalmieri 0:dd89565c6276 1621 /* Read Data in user memory */
apalmieri 0:dd89565c6276 1622 return ST25DV_IO_MemRead( pData, ST25DV_ADDR_DATA_I2C, ST25DV_MAILBOX_RAM_REG + Offset, NbByte, mi2cChannel );
apalmieri 0:dd89565c6276 1623 }
apalmieri 0:dd89565c6276 1624
apalmieri 0:dd89565c6276 1625 /**
apalmieri 0:dd89565c6276 1626 * @brief Writes N bytes of data in the Mailbox, starting from first Mailbox Address.
apalmieri 0:dd89565c6276 1627 * @param pData Pointer to the buffer containing the data to be written.
apalmieri 0:dd89565c6276 1628 * @param NbByte Number of bytes to be written.
apalmieri 0:dd89565c6276 1629 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1630 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1631 */
apalmieri 0:dd89565c6276 1632 NFCTAG_StatusTypeDef ST25DV_i2c_WriteMailboxData( const uint8_t * const pData, const uint16_t NbByte, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1633 {
apalmieri 0:dd89565c6276 1634 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1635
apalmieri 0:dd89565c6276 1636 /* ST25DV can write a maximum of 256 bytes in Mailbox */
apalmieri 0:dd89565c6276 1637 if( NbByte < ST25DV_MAX_MAILBOX_LENGTH )
apalmieri 0:dd89565c6276 1638 {
apalmieri 0:dd89565c6276 1639 /* Write NbByte data in memory */
apalmieri 0:dd89565c6276 1640 status = ST25DV_IO_MemWrite( pData, ST25DV_ADDR_DATA_I2C, ST25DV_MAILBOX_RAM_REG, NbByte, mi2cChannel);
apalmieri 0:dd89565c6276 1641 }
apalmieri 0:dd89565c6276 1642 else
apalmieri 0:dd89565c6276 1643 {
apalmieri 0:dd89565c6276 1644 status = NFCTAG_ERROR;
apalmieri 0:dd89565c6276 1645 }
apalmieri 0:dd89565c6276 1646
apalmieri 0:dd89565c6276 1647 return status;
apalmieri 0:dd89565c6276 1648 }
apalmieri 0:dd89565c6276 1649
apalmieri 0:dd89565c6276 1650 /**
apalmieri 0:dd89565c6276 1651 * @brief Reads N bytes from the mailbox registers, starting at the specified I2C address.
apalmieri 0:dd89565c6276 1652 * @param pData Pointer on the buffer used to return the data.
apalmieri 0:dd89565c6276 1653 * @param TarAddr I2C memory address to be read.
apalmieri 0:dd89565c6276 1654 * @param NbByte Number of bytes to be read.
apalmieri 0:dd89565c6276 1655 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1656 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1657 */
apalmieri 0:dd89565c6276 1658 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMailboxRegister( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1659 {
apalmieri 0:dd89565c6276 1660 if( (TarAddr < ST25DV_GPO_DYN_REG) || (TarAddr > ST25DV_MBLEN_DYN_REG) )
apalmieri 0:dd89565c6276 1661 {
apalmieri 0:dd89565c6276 1662 return NFCTAG_ERROR;
apalmieri 0:dd89565c6276 1663 }
apalmieri 0:dd89565c6276 1664
apalmieri 0:dd89565c6276 1665 return ST25DV_IO_MemRead( pData, ST25DV_ADDR_DATA_I2C, TarAddr, NbByte, mi2cChannel );
apalmieri 0:dd89565c6276 1666 }
apalmieri 0:dd89565c6276 1667
apalmieri 0:dd89565c6276 1668 /**
apalmieri 0:dd89565c6276 1669 * @brief Writes N bytes to the specified mailbox register.
apalmieri 0:dd89565c6276 1670 * @param pData Pointer on the data to be written.
apalmieri 0:dd89565c6276 1671 * @param TarAddr I2C register address to be written.
apalmieri 0:dd89565c6276 1672 * @param NbByte Number of bytes to be written.
apalmieri 0:dd89565c6276 1673 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1674 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1675 */
apalmieri 0:dd89565c6276 1676 NFCTAG_StatusTypeDef ST25DV_i2c_WriteMailboxRegister( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1677 {
apalmieri 0:dd89565c6276 1678 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1679
apalmieri 0:dd89565c6276 1680 if( (TarAddr < ST25DV_GPO_DYN_REG) || (TarAddr > ST25DV_MBLEN_DYN_REG) )
apalmieri 0:dd89565c6276 1681 {
apalmieri 0:dd89565c6276 1682 return NFCTAG_ERROR;
apalmieri 0:dd89565c6276 1683 }
apalmieri 0:dd89565c6276 1684
apalmieri 0:dd89565c6276 1685 /* ST25DV can write a maximum of 256 bytes in Mailbox */
apalmieri 0:dd89565c6276 1686 if( NbByte < ST25DV_MAX_MAILBOX_LENGTH )
apalmieri 0:dd89565c6276 1687 {
apalmieri 0:dd89565c6276 1688 /* Write NbByte data in memory */
apalmieri 0:dd89565c6276 1689 status = ST25DV_IO_MemWrite( pData, ST25DV_ADDR_DATA_I2C, TarAddr, NbByte, mi2cChannel);
apalmieri 0:dd89565c6276 1690 }
apalmieri 0:dd89565c6276 1691 else
apalmieri 0:dd89565c6276 1692 {
apalmieri 0:dd89565c6276 1693 status = NFCTAG_ERROR;
apalmieri 0:dd89565c6276 1694 }
apalmieri 0:dd89565c6276 1695
apalmieri 0:dd89565c6276 1696 return status;
apalmieri 0:dd89565c6276 1697 }
apalmieri 0:dd89565c6276 1698
apalmieri 0:dd89565c6276 1699 /**
apalmieri 0:dd89565c6276 1700 * @brief Reads the status of the security session open register.
apalmieri 0:dd89565c6276 1701 * @param pSession Pointer on a ST25DV_I2CSSO_STATUS value used to return the session status.
apalmieri 0:dd89565c6276 1702 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1703 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1704 */
apalmieri 0:dd89565c6276 1705 NFCTAG_StatusTypeDef ST25DV_i2c_ReadI2CSecuritySession_Dyn( ST25DV_I2CSSO_STATUS * const pSession, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1706 {
apalmieri 0:dd89565c6276 1707 uint8_t reg_value;
apalmieri 0:dd89565c6276 1708 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1709
apalmieri 0:dd89565c6276 1710 /* Read actual value of I2C_SSO_DYN register */
apalmieri 0:dd89565c6276 1711 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_I2C_SSO_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1712 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 1713 {
apalmieri 0:dd89565c6276 1714 return status;
apalmieri 0:dd89565c6276 1715 }
apalmieri 0:dd89565c6276 1716
apalmieri 0:dd89565c6276 1717 /* Extract Open session information */
apalmieri 0:dd89565c6276 1718 if( (reg_value & ST25DV_I2C_SSO_DYN_I2CSSO_MASK) == ST25DV_I2C_SSO_DYN_I2CSSO_MASK )
apalmieri 0:dd89565c6276 1719 {
apalmieri 0:dd89565c6276 1720 *pSession = ST25DV_SESSION_OPEN;
apalmieri 0:dd89565c6276 1721 }
apalmieri 0:dd89565c6276 1722 else
apalmieri 0:dd89565c6276 1723 {
apalmieri 0:dd89565c6276 1724 *pSession = ST25DV_SESSION_CLOSED;
apalmieri 0:dd89565c6276 1725 }
apalmieri 0:dd89565c6276 1726
apalmieri 0:dd89565c6276 1727 return NFCTAG_OK;
apalmieri 0:dd89565c6276 1728 }
apalmieri 0:dd89565c6276 1729
apalmieri 0:dd89565c6276 1730 /**
apalmieri 0:dd89565c6276 1731 * @brief Reads the IT status register from the ST25DV.
apalmieri 0:dd89565c6276 1732 * @param pITStatus Pointer on uint8_t, used to return the IT status, such as:
apalmieri 0:dd89565c6276 1733 * - RFUSERSTATE = 0x01
apalmieri 0:dd89565c6276 1734 * - RFBUSY = 0x02
apalmieri 0:dd89565c6276 1735 * - RFINTERRUPT = 0x04
apalmieri 0:dd89565c6276 1736 * - FIELDFALLING = 0x08
apalmieri 0:dd89565c6276 1737 * - FIELDRISING = 0x10
apalmieri 0:dd89565c6276 1738 * - RFPUTMSG = 0x20
apalmieri 0:dd89565c6276 1739 * - RFGETMSG = 0x40
apalmieri 0:dd89565c6276 1740 * - RFWRITE = 0x80
apalmieri 0:dd89565c6276 1741 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1742 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1743 */
apalmieri 0:dd89565c6276 1744 NFCTAG_StatusTypeDef ST25DV_i2c_ReadITSTStatus_Dyn( uint8_t * const pITStatus, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1745 {
apalmieri 0:dd89565c6276 1746 /* Read value of ITStatus register */
apalmieri 0:dd89565c6276 1747 return ST25DV_i2c_ReadMailboxRegister( pITStatus, ST25DV_ITSTS_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1748 }
apalmieri 0:dd89565c6276 1749
apalmieri 0:dd89565c6276 1750 /**
apalmieri 0:dd89565c6276 1751 * @brief Read value of dynamic GPO register configuration.
apalmieri 0:dd89565c6276 1752 * @param pGPO ST25DV_GPO pointer of the dynamic GPO configuration to store.
apalmieri 0:dd89565c6276 1753 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1754 * @retval NFCTAG enum status.
apalmieri 0:dd89565c6276 1755 */
apalmieri 0:dd89565c6276 1756 NFCTAG_StatusTypeDef ST25DV_i2c_ReadGPO_Dyn( uint8_t *GPOConfig, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1757 {
apalmieri 0:dd89565c6276 1758 /* Read actual value of ST25DV_GPO_DYN_REG register */
apalmieri 0:dd89565c6276 1759 return ST25DV_i2c_ReadMailboxRegister( GPOConfig, ST25DV_GPO_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1760 }
apalmieri 0:dd89565c6276 1761
apalmieri 0:dd89565c6276 1762
apalmieri 0:dd89565c6276 1763 /**
apalmieri 0:dd89565c6276 1764 * @brief Get dynamique GPO enable status
apalmieri 0:dd89565c6276 1765 * @param pGPO_en ST25DV_EN_STATUS pointer of the GPO enable status to store
apalmieri 0:dd89565c6276 1766 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1767 * @retval NFCTAG enum status
apalmieri 0:dd89565c6276 1768 */
apalmieri 0:dd89565c6276 1769 NFCTAG_StatusTypeDef ST25DV_i2c_GetGPO_en_Dyn( ST25DV_EN_STATUS * const pGPO_en, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1770 {
apalmieri 0:dd89565c6276 1771 uint8_t reg_value;
apalmieri 0:dd89565c6276 1772 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1773 /* Read actual value of GPO_DYN register */
apalmieri 0:dd89565c6276 1774 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_GPO_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1775 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 1776 {
apalmieri 0:dd89565c6276 1777 return status;
apalmieri 0:dd89565c6276 1778 }
apalmieri 0:dd89565c6276 1779
apalmieri 0:dd89565c6276 1780 /* Extract GPO enable status information */
apalmieri 0:dd89565c6276 1781 if( (reg_value & ST25DV_GPO_DYN_ENABLE_MASK) == ST25DV_GPO_DYN_ENABLE_MASK )
apalmieri 0:dd89565c6276 1782 {
apalmieri 0:dd89565c6276 1783 *pGPO_en = ST25DV_ENABLE;
apalmieri 0:dd89565c6276 1784 }
apalmieri 0:dd89565c6276 1785 else
apalmieri 0:dd89565c6276 1786 {
apalmieri 0:dd89565c6276 1787 *pGPO_en = ST25DV_DISABLE;
apalmieri 0:dd89565c6276 1788 }
apalmieri 0:dd89565c6276 1789
apalmieri 0:dd89565c6276 1790 return NFCTAG_OK;
apalmieri 0:dd89565c6276 1791 }
apalmieri 0:dd89565c6276 1792
apalmieri 0:dd89565c6276 1793 /**
apalmieri 0:dd89565c6276 1794 * @brief Set dynamique GPO enable configuration.
apalmieri 0:dd89565c6276 1795 * @param None No parameters.
apalmieri 0:dd89565c6276 1796 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1797 * @retval NFCTAG enum status.
apalmieri 0:dd89565c6276 1798 */
apalmieri 0:dd89565c6276 1799 NFCTAG_StatusTypeDef ST25DV_i2c_SetGPO_en_Dyn( I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1800 {
apalmieri 0:dd89565c6276 1801 uint8_t reg_value;
apalmieri 0:dd89565c6276 1802 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1803
apalmieri 0:dd89565c6276 1804 /* Read actual value of GPO_DYN register */
apalmieri 0:dd89565c6276 1805 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_GPO_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1806 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 1807 {
apalmieri 0:dd89565c6276 1808 return status;
apalmieri 0:dd89565c6276 1809 }
apalmieri 0:dd89565c6276 1810
apalmieri 0:dd89565c6276 1811 /* Update GPO enable configuration */
apalmieri 0:dd89565c6276 1812 reg_value |= ST25DV_GPO_DYN_ENABLE_MASK;
apalmieri 0:dd89565c6276 1813
apalmieri 0:dd89565c6276 1814 /* Write GPO_DYN Register */
apalmieri 0:dd89565c6276 1815 return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_GPO_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1816 }
apalmieri 0:dd89565c6276 1817
apalmieri 0:dd89565c6276 1818 /**
apalmieri 0:dd89565c6276 1819 * @brief Reset dynamique GPO enable configuration.
apalmieri 0:dd89565c6276 1820 * @param None No parameters.
apalmieri 0:dd89565c6276 1821 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1822 * @retval NFCTAG enum status.
apalmieri 0:dd89565c6276 1823 */
apalmieri 0:dd89565c6276 1824 NFCTAG_StatusTypeDef ST25DV_i2c_ResetGPO_en_Dyn( I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1825 {
apalmieri 0:dd89565c6276 1826 uint8_t reg_value;
apalmieri 0:dd89565c6276 1827 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1828
apalmieri 0:dd89565c6276 1829 /* Read actual value of GPO_DYN register */
apalmieri 0:dd89565c6276 1830 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_GPO_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1831 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 1832 {
apalmieri 0:dd89565c6276 1833 return status;
apalmieri 0:dd89565c6276 1834 }
apalmieri 0:dd89565c6276 1835
apalmieri 0:dd89565c6276 1836 /* Update GPO enable configuration */
apalmieri 0:dd89565c6276 1837 reg_value &= ST25DV_GPO_DYN_ENABLE_FIELD;
apalmieri 0:dd89565c6276 1838
apalmieri 0:dd89565c6276 1839 /* Write GPO_DYN Register */
apalmieri 0:dd89565c6276 1840 return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_GPO_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1841 }
apalmieri 0:dd89565c6276 1842
apalmieri 0:dd89565c6276 1843 /**
apalmieri 0:dd89565c6276 1844 * @brief Read value of dynamic EH Ctrl register configuration
apalmieri 0:dd89565c6276 1845 * @param pEH_CTRL : ST25DV_EH_CTRL pointer of the dynamic EH Ctrl configuration to store
apalmieri 0:dd89565c6276 1846 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1847 * @retval NFCTAG enum status
apalmieri 0:dd89565c6276 1848 */
apalmieri 0:dd89565c6276 1849 NFCTAG_StatusTypeDef ST25DV_i2c_ReadEHCtrl_Dyn( ST25DV_EH_CTRL * const pEH_CTRL, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1850 {
apalmieri 0:dd89565c6276 1851 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1852 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 1853
apalmieri 0:dd89565c6276 1854 /* Read actual value of ST25DV_EH_CTRL_DYN_REG register */
apalmieri 0:dd89565c6276 1855 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1856
apalmieri 0:dd89565c6276 1857 if( status == NFCTAG_OK )
apalmieri 0:dd89565c6276 1858 {
apalmieri 0:dd89565c6276 1859 /* Extract EH EN Mode configuration */
apalmieri 0:dd89565c6276 1860 if( (reg_value & ST25DV_EH_CTRL_DYN_EH_EN_MASK) == ST25DV_EH_CTRL_DYN_EH_EN_MASK )
apalmieri 0:dd89565c6276 1861 {
apalmieri 0:dd89565c6276 1862 pEH_CTRL->EH_EN_Mode = ST25DV_ENABLE;
apalmieri 0:dd89565c6276 1863 }
apalmieri 0:dd89565c6276 1864 else
apalmieri 0:dd89565c6276 1865 {
apalmieri 0:dd89565c6276 1866 pEH_CTRL->EH_EN_Mode = ST25DV_DISABLE;
apalmieri 0:dd89565c6276 1867 }
apalmieri 0:dd89565c6276 1868
apalmieri 0:dd89565c6276 1869 /* Extract EH_ON configuration */
apalmieri 0:dd89565c6276 1870 if( (reg_value & ST25DV_EH_CTRL_DYN_EH_ON_MASK) == ST25DV_EH_CTRL_DYN_EH_ON_MASK )
apalmieri 0:dd89565c6276 1871 {
apalmieri 0:dd89565c6276 1872 pEH_CTRL->EH_on = ST25DV_ENABLE;
apalmieri 0:dd89565c6276 1873 }
apalmieri 0:dd89565c6276 1874 else
apalmieri 0:dd89565c6276 1875 {
apalmieri 0:dd89565c6276 1876 pEH_CTRL->EH_on = ST25DV_DISABLE;
apalmieri 0:dd89565c6276 1877 }
apalmieri 0:dd89565c6276 1878
apalmieri 0:dd89565c6276 1879 /* Extract FIELD_ON configuration */
apalmieri 0:dd89565c6276 1880 if( (reg_value & ST25DV_EH_CTRL_DYN_FIELD_ON_MASK) == ST25DV_EH_CTRL_DYN_FIELD_ON_MASK )
apalmieri 0:dd89565c6276 1881 {
apalmieri 0:dd89565c6276 1882 pEH_CTRL->Field_on = ST25DV_ENABLE;
apalmieri 0:dd89565c6276 1883 }
apalmieri 0:dd89565c6276 1884 else
apalmieri 0:dd89565c6276 1885 {
apalmieri 0:dd89565c6276 1886 pEH_CTRL->Field_on = ST25DV_DISABLE;
apalmieri 0:dd89565c6276 1887 }
apalmieri 0:dd89565c6276 1888
apalmieri 0:dd89565c6276 1889 /* Extract VCC_ON configuration */
apalmieri 0:dd89565c6276 1890 if( (reg_value & ST25DV_EH_CTRL_DYN_VCC_ON_MASK) == ST25DV_EH_CTRL_DYN_VCC_ON_MASK )
apalmieri 0:dd89565c6276 1891 {
apalmieri 0:dd89565c6276 1892 pEH_CTRL->VCC_on = ST25DV_ENABLE;
apalmieri 0:dd89565c6276 1893 }
apalmieri 0:dd89565c6276 1894 else
apalmieri 0:dd89565c6276 1895 {
apalmieri 0:dd89565c6276 1896 pEH_CTRL->VCC_on = ST25DV_DISABLE;
apalmieri 0:dd89565c6276 1897 }
apalmieri 0:dd89565c6276 1898
apalmieri 0:dd89565c6276 1899 return NFCTAG_OK;
apalmieri 0:dd89565c6276 1900 }
apalmieri 0:dd89565c6276 1901
apalmieri 0:dd89565c6276 1902 return status;
apalmieri 0:dd89565c6276 1903 }
apalmieri 0:dd89565c6276 1904
apalmieri 0:dd89565c6276 1905 /**
apalmieri 0:dd89565c6276 1906 * @brief Reads the Energy Harvesting dynamic status.
apalmieri 0:dd89565c6276 1907 * @param pEH_Val Pointer on a ST25DV_EN_STATUS value used to return the Energy Harvesting dynamic status.
apalmieri 0:dd89565c6276 1908 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1909 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1910 */
apalmieri 0:dd89565c6276 1911 NFCTAG_StatusTypeDef ST25DV_i2c_GetEHENMode_Dyn( ST25DV_EN_STATUS * const pEH_Val, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1912 {
apalmieri 0:dd89565c6276 1913 uint8_t reg_value;
apalmieri 0:dd89565c6276 1914 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1915
apalmieri 0:dd89565c6276 1916 /* Read actual value of EH_CTRL_DYN register */
apalmieri 0:dd89565c6276 1917 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1918 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 1919 {
apalmieri 0:dd89565c6276 1920 return status;
apalmieri 0:dd89565c6276 1921 }
apalmieri 0:dd89565c6276 1922
apalmieri 0:dd89565c6276 1923 /* Extract Energy Harvesting status information */
apalmieri 0:dd89565c6276 1924 if( (reg_value & ST25DV_EH_CTRL_DYN_EH_EN_MASK) == ST25DV_EH_CTRL_DYN_EH_EN_MASK )
apalmieri 0:dd89565c6276 1925 {
apalmieri 0:dd89565c6276 1926 *pEH_Val = ST25DV_ENABLE;
apalmieri 0:dd89565c6276 1927 }
apalmieri 0:dd89565c6276 1928 else
apalmieri 0:dd89565c6276 1929 {
apalmieri 0:dd89565c6276 1930 *pEH_Val = ST25DV_DISABLE;
apalmieri 0:dd89565c6276 1931 }
apalmieri 0:dd89565c6276 1932
apalmieri 0:dd89565c6276 1933 return NFCTAG_OK;
apalmieri 0:dd89565c6276 1934 }
apalmieri 0:dd89565c6276 1935
apalmieri 0:dd89565c6276 1936 /**
apalmieri 0:dd89565c6276 1937 * @brief Dynamically sets the Energy Harvesting mode.
apalmieri 0:dd89565c6276 1938 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1939 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1940 */
apalmieri 0:dd89565c6276 1941 NFCTAG_StatusTypeDef ST25DV_i2c_SetEHENMode_Dyn( I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1942 {
apalmieri 0:dd89565c6276 1943 uint8_t reg_value;
apalmieri 0:dd89565c6276 1944 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1945
apalmieri 0:dd89565c6276 1946 /* Read actual value of EH_CTRL_DYN register */
apalmieri 0:dd89565c6276 1947 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1948 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 1949 {
apalmieri 0:dd89565c6276 1950 return status;
apalmieri 0:dd89565c6276 1951 }
apalmieri 0:dd89565c6276 1952
apalmieri 0:dd89565c6276 1953 /* Update Energy Harvesting configuration */
apalmieri 0:dd89565c6276 1954 reg_value |= ST25DV_EH_CTRL_DYN_EH_EN_MASK;
apalmieri 0:dd89565c6276 1955
apalmieri 0:dd89565c6276 1956 /* Write EH_CTRL_DYN Register */
apalmieri 0:dd89565c6276 1957 return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1958 }
apalmieri 0:dd89565c6276 1959
apalmieri 0:dd89565c6276 1960 /**
apalmieri 0:dd89565c6276 1961 * @brief Dynamically unsets the Energy Harvesting mode.
apalmieri 0:dd89565c6276 1962 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1963 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1964 */
apalmieri 0:dd89565c6276 1965 NFCTAG_StatusTypeDef ST25DV_i2c_ResetEHENMode_Dyn( I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1966 {
apalmieri 0:dd89565c6276 1967 uint8_t reg_value;
apalmieri 0:dd89565c6276 1968 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1969
apalmieri 0:dd89565c6276 1970 /* Read actual value of EH_CTRL_DYN register */
apalmieri 0:dd89565c6276 1971 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1972 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 1973 {
apalmieri 0:dd89565c6276 1974 return status;
apalmieri 0:dd89565c6276 1975 }
apalmieri 0:dd89565c6276 1976
apalmieri 0:dd89565c6276 1977 /* Update Energy Harvesting configuration */
apalmieri 0:dd89565c6276 1978 reg_value &= ST25DV_EH_CTRL_DYN_EH_EN_FIELD;
apalmieri 0:dd89565c6276 1979
apalmieri 0:dd89565c6276 1980 /* Write EH_CTRL_DYN Register */
apalmieri 0:dd89565c6276 1981 return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1982 }
apalmieri 0:dd89565c6276 1983
apalmieri 0:dd89565c6276 1984 /**
apalmieri 0:dd89565c6276 1985 * @brief Reads the EH_ON status from the EH_CTRL_DYN register.
apalmieri 0:dd89565c6276 1986 * @param pEHON Pointer on a ST25DV_EN_STATUS value used to return the EHON status.
apalmieri 0:dd89565c6276 1987 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 1988 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 1989 */
apalmieri 0:dd89565c6276 1990 NFCTAG_StatusTypeDef ST25DV_i2c_GetEHON_Dyn( ST25DV_EN_STATUS * const pEHON, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 1991 {
apalmieri 0:dd89565c6276 1992 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 1993 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 1994
apalmieri 0:dd89565c6276 1995 /* Read actual value of EH_CTRL_DYN register */
apalmieri 0:dd89565c6276 1996 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 1997
apalmieri 0:dd89565c6276 1998 /* Extract RF Field information */
apalmieri 0:dd89565c6276 1999 if( status == NFCTAG_OK )
apalmieri 0:dd89565c6276 2000 {
apalmieri 0:dd89565c6276 2001 if( (reg_value & ST25DV_EH_CTRL_DYN_EH_ON_MASK) == ST25DV_EH_CTRL_DYN_EH_ON_MASK )
apalmieri 0:dd89565c6276 2002 {
apalmieri 0:dd89565c6276 2003 *pEHON = ST25DV_ENABLE;
apalmieri 0:dd89565c6276 2004 }
apalmieri 0:dd89565c6276 2005 else
apalmieri 0:dd89565c6276 2006 {
apalmieri 0:dd89565c6276 2007 *pEHON = ST25DV_DISABLE;
apalmieri 0:dd89565c6276 2008 }
apalmieri 0:dd89565c6276 2009 return NFCTAG_OK;
apalmieri 0:dd89565c6276 2010 }
apalmieri 0:dd89565c6276 2011
apalmieri 0:dd89565c6276 2012 return status;
apalmieri 0:dd89565c6276 2013 }
apalmieri 0:dd89565c6276 2014
apalmieri 0:dd89565c6276 2015 /**
apalmieri 0:dd89565c6276 2016 * @brief Checks if RF Field is present in front of the ST25DV.
apalmieri 0:dd89565c6276 2017 * @param pRF_Field Pointer on a ST25DV_FIELD_STATUS value used to return the field presence.
apalmieri 0:dd89565c6276 2018 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 2019 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 2020 */
apalmieri 0:dd89565c6276 2021 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFField_Dyn( ST25DV_FIELD_STATUS * const pRF_Field, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 2022 {
apalmieri 0:dd89565c6276 2023 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 2024 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 2025
apalmieri 0:dd89565c6276 2026 /* Read actual value of EH_CTRL_DYN register */
apalmieri 0:dd89565c6276 2027 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2028
apalmieri 0:dd89565c6276 2029 /* Extract RF Field information */
apalmieri 0:dd89565c6276 2030 if( status == NFCTAG_OK )
apalmieri 0:dd89565c6276 2031 {
apalmieri 0:dd89565c6276 2032 if( (reg_value & ST25DV_EH_CTRL_DYN_FIELD_ON_MASK) == ST25DV_EH_CTRL_DYN_FIELD_ON_MASK )
apalmieri 0:dd89565c6276 2033 {
apalmieri 0:dd89565c6276 2034 *pRF_Field = ST25DV_FIELD_ON;
apalmieri 0:dd89565c6276 2035 }
apalmieri 0:dd89565c6276 2036 else
apalmieri 0:dd89565c6276 2037 {
apalmieri 0:dd89565c6276 2038 *pRF_Field = ST25DV_FIELD_OFF;
apalmieri 0:dd89565c6276 2039 }
apalmieri 0:dd89565c6276 2040 return NFCTAG_OK;
apalmieri 0:dd89565c6276 2041 }
apalmieri 0:dd89565c6276 2042
apalmieri 0:dd89565c6276 2043 return status;
apalmieri 0:dd89565c6276 2044 }
apalmieri 0:dd89565c6276 2045
apalmieri 0:dd89565c6276 2046 /**
apalmieri 0:dd89565c6276 2047 * @brief Check if VCC is supplying the ST25DV.
apalmieri 0:dd89565c6276 2048 * @param pVCC ST25DV_VCC_STATUS pointer of the VCC status to store
apalmieri 0:dd89565c6276 2049 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 2050 * @retval NFCTAG enum status.
apalmieri 0:dd89565c6276 2051 */
apalmieri 0:dd89565c6276 2052 NFCTAG_StatusTypeDef ST25DV_i2c_GetVCC_Dyn( ST25DV_VCC_STATUS * const pVCC, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 2053 {
apalmieri 0:dd89565c6276 2054 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 2055 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 2056
apalmieri 0:dd89565c6276 2057 /* Read actual value of EH_CTRL_DYN register */
apalmieri 0:dd89565c6276 2058 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2059
apalmieri 0:dd89565c6276 2060 /* Extract VCC information */
apalmieri 0:dd89565c6276 2061 if( status == NFCTAG_OK )
apalmieri 0:dd89565c6276 2062 {
apalmieri 0:dd89565c6276 2063 if( (reg_value & ST25DV_EH_CTRL_DYN_VCC_ON_MASK) == ST25DV_EH_CTRL_DYN_VCC_ON_MASK )
apalmieri 0:dd89565c6276 2064 {
apalmieri 0:dd89565c6276 2065 *pVCC = ST25DV_VCC_ON;
apalmieri 0:dd89565c6276 2066 }
apalmieri 0:dd89565c6276 2067 else
apalmieri 0:dd89565c6276 2068 {
apalmieri 0:dd89565c6276 2069 *pVCC = ST25DV_VCC_OFF;
apalmieri 0:dd89565c6276 2070 }
apalmieri 0:dd89565c6276 2071 return NFCTAG_OK;
apalmieri 0:dd89565c6276 2072 }
apalmieri 0:dd89565c6276 2073
apalmieri 0:dd89565c6276 2074 return status;
apalmieri 0:dd89565c6276 2075 }
apalmieri 0:dd89565c6276 2076
apalmieri 0:dd89565c6276 2077 /**
apalmieri 0:dd89565c6276 2078 * @brief Read value of dynamic RF Management configuration
apalmieri 0:dd89565c6276 2079 * @param pRF_Mngt : ST25DV_RF_MNGT pointer of the dynamic RF Management configuration to store
apalmieri 0:dd89565c6276 2080 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 2081 * @retval NFCTAG enum status
apalmieri 0:dd89565c6276 2082 */
apalmieri 0:dd89565c6276 2083 NFCTAG_StatusTypeDef ST25DV_i2c_ReadRFMngt_Dyn( ST25DV_RF_MNGT * const pRF_Mngt, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 2084 {
apalmieri 0:dd89565c6276 2085 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 2086 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 2087
apalmieri 0:dd89565c6276 2088 /* Read actual value of RF_MNGT_DYN register */
apalmieri 0:dd89565c6276 2089 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2090
apalmieri 0:dd89565c6276 2091 if( status == NFCTAG_OK )
apalmieri 0:dd89565c6276 2092 {
apalmieri 0:dd89565c6276 2093 /* Extract RF Disable configuration */
apalmieri 0:dd89565c6276 2094 if( (reg_value & ST25DV_RF_MNGT_DYN_RFDIS_MASK) == ST25DV_RF_MNGT_DYN_RFDIS_MASK )
apalmieri 0:dd89565c6276 2095 {
apalmieri 0:dd89565c6276 2096 pRF_Mngt->RfDisable = ST25DV_ENABLE;
apalmieri 0:dd89565c6276 2097 }
apalmieri 0:dd89565c6276 2098 else
apalmieri 0:dd89565c6276 2099 {
apalmieri 0:dd89565c6276 2100 pRF_Mngt->RfDisable = ST25DV_DISABLE;
apalmieri 0:dd89565c6276 2101 }
apalmieri 0:dd89565c6276 2102
apalmieri 0:dd89565c6276 2103 /* Extract RF Sleep configuration */
apalmieri 0:dd89565c6276 2104 if( (reg_value & ST25DV_RF_MNGT_DYN_RFSLEEP_MASK) == ST25DV_RF_MNGT_DYN_RFSLEEP_MASK )
apalmieri 0:dd89565c6276 2105 {
apalmieri 0:dd89565c6276 2106 pRF_Mngt->RfSleep = ST25DV_ENABLE;
apalmieri 0:dd89565c6276 2107 }
apalmieri 0:dd89565c6276 2108 else
apalmieri 0:dd89565c6276 2109 {
apalmieri 0:dd89565c6276 2110 pRF_Mngt->RfSleep = ST25DV_DISABLE;
apalmieri 0:dd89565c6276 2111 }
apalmieri 0:dd89565c6276 2112
apalmieri 0:dd89565c6276 2113 return NFCTAG_OK;
apalmieri 0:dd89565c6276 2114 }
apalmieri 0:dd89565c6276 2115
apalmieri 0:dd89565c6276 2116 return status;
apalmieri 0:dd89565c6276 2117 }
apalmieri 0:dd89565c6276 2118
apalmieri 0:dd89565c6276 2119 /**
apalmieri 0:dd89565c6276 2120 * @brief Writes a value to the RF Management dynamic register.
apalmieri 0:dd89565c6276 2121 * @param RF_Mngt Value to be written to the RF Management dynamic register.
apalmieri 0:dd89565c6276 2122 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 2123 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 2124 */
apalmieri 0:dd89565c6276 2125 NFCTAG_StatusTypeDef ST25DV_i2c_WriteRFMngt_Dyn( const uint8_t RF_Mngt, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 2126 {
apalmieri 0:dd89565c6276 2127 /* Write value to RF_MNGT_DYN register */
apalmieri 0:dd89565c6276 2128 return ST25DV_i2c_WriteMailboxRegister( &RF_Mngt, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2129 }
apalmieri 0:dd89565c6276 2130
apalmieri 0:dd89565c6276 2131 /**
apalmieri 0:dd89565c6276 2132 * @brief Reads the RFDisable dynamic register information.
apalmieri 0:dd89565c6276 2133 * @param pRFDisable Pointer on a ST25DV_EN_STATUS value used to return the RF Disable state.
apalmieri 0:dd89565c6276 2134 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 2135 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 2136 */
apalmieri 0:dd89565c6276 2137 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFDisable_Dyn( ST25DV_EN_STATUS * const pRFDisable, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 2138 {
apalmieri 0:dd89565c6276 2139 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 2140 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 2141
apalmieri 0:dd89565c6276 2142 /* Read actual value of RF_MNGT_DYN register */
apalmieri 0:dd89565c6276 2143 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2144
apalmieri 0:dd89565c6276 2145 /* Extract RFDisable information */
apalmieri 0:dd89565c6276 2146 if( status == NFCTAG_OK )
apalmieri 0:dd89565c6276 2147 {
apalmieri 0:dd89565c6276 2148 if( (reg_value & ST25DV_RF_MNGT_DYN_RFDIS_MASK) == ST25DV_RF_MNGT_DYN_RFDIS_MASK )
apalmieri 0:dd89565c6276 2149 {
apalmieri 0:dd89565c6276 2150 *pRFDisable = ST25DV_ENABLE;
apalmieri 0:dd89565c6276 2151 }
apalmieri 0:dd89565c6276 2152 else
apalmieri 0:dd89565c6276 2153 {
apalmieri 0:dd89565c6276 2154 *pRFDisable = ST25DV_DISABLE;
apalmieri 0:dd89565c6276 2155 }
apalmieri 0:dd89565c6276 2156 return NFCTAG_OK;
apalmieri 0:dd89565c6276 2157 }
apalmieri 0:dd89565c6276 2158
apalmieri 0:dd89565c6276 2159 return status;
apalmieri 0:dd89565c6276 2160 }
apalmieri 0:dd89565c6276 2161
apalmieri 0:dd89565c6276 2162 /**
apalmieri 0:dd89565c6276 2163 * @brief Sets the RF Disable dynamic configuration.
apalmieri 0:dd89565c6276 2164 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 2165 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 2166 */
apalmieri 0:dd89565c6276 2167 NFCTAG_StatusTypeDef ST25DV_i2c_SetRFDisable_Dyn( I2C * mi2cChannel )
apalmieri 0:dd89565c6276 2168 {
apalmieri 0:dd89565c6276 2169 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 2170 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 2171
apalmieri 0:dd89565c6276 2172 /* Read actual value of RF_MNGT_DYN register */
apalmieri 0:dd89565c6276 2173 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2174 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 2175 {
apalmieri 0:dd89565c6276 2176 return status;
apalmieri 0:dd89565c6276 2177 }
apalmieri 0:dd89565c6276 2178
apalmieri 0:dd89565c6276 2179 /* Update dynamic RF Disable field */
apalmieri 0:dd89565c6276 2180 reg_value |= ST25DV_RF_MNGT_DYN_RFDIS_MASK;
apalmieri 0:dd89565c6276 2181
apalmieri 0:dd89565c6276 2182 /* Write RF_MNGT_DYN register */
apalmieri 0:dd89565c6276 2183 return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2184 }
apalmieri 0:dd89565c6276 2185
apalmieri 0:dd89565c6276 2186 /**
apalmieri 0:dd89565c6276 2187 * @brief Unsets the RF Disable dynamic configuration.
apalmieri 0:dd89565c6276 2188 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 2189 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 2190 */
apalmieri 0:dd89565c6276 2191 NFCTAG_StatusTypeDef ST25DV_i2c_ResetRFDisable_Dyn( I2C * mi2cChannel )
apalmieri 0:dd89565c6276 2192 {
apalmieri 0:dd89565c6276 2193 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 2194 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 2195
apalmieri 0:dd89565c6276 2196 /* Read actual value of RF_MNGT_DYN register */
apalmieri 0:dd89565c6276 2197 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2198 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 2199 {
apalmieri 0:dd89565c6276 2200 return status;
apalmieri 0:dd89565c6276 2201 }
apalmieri 0:dd89565c6276 2202
apalmieri 0:dd89565c6276 2203 /* Update dynamic RF Disable field configuration */
apalmieri 0:dd89565c6276 2204 reg_value &= ST25DV_RF_MNGT_DYN_RFDIS_FIELD;
apalmieri 0:dd89565c6276 2205
apalmieri 0:dd89565c6276 2206 /* Write RF_MNGT_DYN register */
apalmieri 0:dd89565c6276 2207 return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2208 }
apalmieri 0:dd89565c6276 2209
apalmieri 0:dd89565c6276 2210 /**
apalmieri 0:dd89565c6276 2211 * @brief Reads the RFSleep dynamic register information.
apalmieri 0:dd89565c6276 2212 * @param pRFSleep Pointer on a ST25DV_EN_STATUS values used to return the RF Sleep state.
apalmieri 0:dd89565c6276 2213 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 2214 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 2215 */
apalmieri 0:dd89565c6276 2216 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFSleep_Dyn( ST25DV_EN_STATUS * const pRFSleep, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 2217 {
apalmieri 0:dd89565c6276 2218 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 2219 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 2220
apalmieri 0:dd89565c6276 2221 /* Read actual value of RF_MNGT_DYN register */
apalmieri 0:dd89565c6276 2222 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2223
apalmieri 0:dd89565c6276 2224 /* Extract RFSleep information */
apalmieri 0:dd89565c6276 2225 if( status == NFCTAG_OK )
apalmieri 0:dd89565c6276 2226 {
apalmieri 0:dd89565c6276 2227 if( (reg_value & ST25DV_RF_MNGT_DYN_RFDIS_MASK) == ST25DV_RF_MNGT_DYN_RFDIS_MASK )
apalmieri 0:dd89565c6276 2228 {
apalmieri 0:dd89565c6276 2229 *pRFSleep = ST25DV_ENABLE;
apalmieri 0:dd89565c6276 2230 }
apalmieri 0:dd89565c6276 2231 else
apalmieri 0:dd89565c6276 2232 {
apalmieri 0:dd89565c6276 2233 *pRFSleep = ST25DV_DISABLE;
apalmieri 0:dd89565c6276 2234 }
apalmieri 0:dd89565c6276 2235 return NFCTAG_OK;
apalmieri 0:dd89565c6276 2236 }
apalmieri 0:dd89565c6276 2237
apalmieri 0:dd89565c6276 2238 return status;
apalmieri 0:dd89565c6276 2239 }
apalmieri 0:dd89565c6276 2240
apalmieri 0:dd89565c6276 2241 /**
apalmieri 0:dd89565c6276 2242 * @brief Sets the RF Sleep dynamic configuration.
apalmieri 0:dd89565c6276 2243 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 2244 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 2245 */
apalmieri 0:dd89565c6276 2246 NFCTAG_StatusTypeDef ST25DV_i2c_SetRFSleep_Dyn( I2C * mi2cChannel )
apalmieri 0:dd89565c6276 2247 {
apalmieri 0:dd89565c6276 2248 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 2249 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 2250
apalmieri 0:dd89565c6276 2251 /* Read actual value of RF_MNGT_DYN register */
apalmieri 0:dd89565c6276 2252 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2253 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 2254 {
apalmieri 0:dd89565c6276 2255 return status;
apalmieri 0:dd89565c6276 2256 }
apalmieri 0:dd89565c6276 2257
apalmieri 0:dd89565c6276 2258 /* Update dynamic RF Disable field configuration */
apalmieri 0:dd89565c6276 2259 reg_value |= ST25DV_RF_MNGT_DYN_RFSLEEP_MASK;
apalmieri 0:dd89565c6276 2260
apalmieri 0:dd89565c6276 2261 /* Write RF_MNGT_DYN register */
apalmieri 0:dd89565c6276 2262 return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2263 }
apalmieri 0:dd89565c6276 2264
apalmieri 0:dd89565c6276 2265 /**
apalmieri 0:dd89565c6276 2266 * @brief Unsets the RF Sleep dynamic configuration.
apalmieri 0:dd89565c6276 2267 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 2268 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 2269 */
apalmieri 0:dd89565c6276 2270 NFCTAG_StatusTypeDef ST25DV_i2c_ResetRFSleep_Dyn( I2C * mi2cChannel )
apalmieri 0:dd89565c6276 2271 {
apalmieri 0:dd89565c6276 2272 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 2273 uint8_t reg_value = 0;
apalmieri 0:dd89565c6276 2274
apalmieri 0:dd89565c6276 2275 /* Read actual value of RF_MNGT_DYN register */
apalmieri 0:dd89565c6276 2276 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2277 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 2278 {
apalmieri 0:dd89565c6276 2279 return status;
apalmieri 0:dd89565c6276 2280 }
apalmieri 0:dd89565c6276 2281
apalmieri 0:dd89565c6276 2282 /* Update dynamic RF Disable field configuration */
apalmieri 0:dd89565c6276 2283 reg_value &= ST25DV_RF_MNGT_DYN_RFSLEEP_FIELD;
apalmieri 0:dd89565c6276 2284
apalmieri 0:dd89565c6276 2285 /* Write RF_MNGT_DYN register */
apalmieri 0:dd89565c6276 2286 return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2287 }
apalmieri 0:dd89565c6276 2288
apalmieri 0:dd89565c6276 2289 /**
apalmieri 0:dd89565c6276 2290 * @brief Reads the Mailbox ctrl dynamic register.
apalmieri 0:dd89565c6276 2291 * @param pCtrlStatus Pointer on a ST25DV_MB_CTRL_DYN_STATUS structure used to return the dynamic Mailbox ctrl information.
apalmieri 0:dd89565c6276 2292 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 2293 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 2294 */
apalmieri 0:dd89565c6276 2295 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMBCtrl_Dyn( ST25DV_MB_CTRL_DYN_STATUS * const pCtrlStatus, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 2296 {
apalmieri 0:dd89565c6276 2297 uint8_t reg_value;
apalmieri 0:dd89565c6276 2298 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 2299
apalmieri 0:dd89565c6276 2300 /* Read MB_CTRL_DYN register */
apalmieri 0:dd89565c6276 2301 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_MB_CTRL_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2302 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 2303 {
apalmieri 0:dd89565c6276 2304 return status;
apalmieri 0:dd89565c6276 2305 }
apalmieri 0:dd89565c6276 2306
apalmieri 0:dd89565c6276 2307 /* Extract Mailbox ctrl information */
apalmieri 0:dd89565c6276 2308 pCtrlStatus->MbEnable = (reg_value & ST25DV_MB_CTRL_DYN_MBEN_MASK) >> ST25DV_MB_CTRL_DYN_MBEN_SHIFT;
apalmieri 0:dd89565c6276 2309 pCtrlStatus->HostPutMsg = (reg_value & ST25DV_MB_CTRL_DYN_HOSTPUTMSG_MASK) >> ST25DV_MB_CTRL_DYN_HOSTPUTMSG_SHIFT;
apalmieri 0:dd89565c6276 2310 pCtrlStatus->RfPutMsg = (reg_value & ST25DV_MB_CTRL_DYN_RFPUTMSG_MASK) >> ST25DV_MB_CTRL_DYN_RFPUTMSG_SHIFT;
apalmieri 0:dd89565c6276 2311 pCtrlStatus->HostMissMsg = (reg_value & ST25DV_MB_CTRL_DYN_HOSTMISSMSG_MASK) >> ST25DV_MB_CTRL_DYN_HOSTMISSMSG_SHIFT;
apalmieri 0:dd89565c6276 2312 pCtrlStatus->RFMissMsg = (reg_value & ST25DV_MB_CTRL_DYN_RFMISSMSG_MASK) >> ST25DV_MB_CTRL_DYN_RFMISSMSG_SHIFT;
apalmieri 0:dd89565c6276 2313 pCtrlStatus->CurrentMsg = (ST25DV_CURRENT_MSG)((reg_value & ST25DV_MB_CTRL_DYN_CURRENTMSG_MASK) >> ST25DV_MB_CTRL_DYN_CURRENTMSG_SHIFT);
apalmieri 0:dd89565c6276 2314
apalmieri 0:dd89565c6276 2315 return NFCTAG_OK;
apalmieri 0:dd89565c6276 2316 }
apalmieri 0:dd89565c6276 2317
apalmieri 0:dd89565c6276 2318 /**
apalmieri 0:dd89565c6276 2319 * @brief Reads the Mailbox Enable dynamic configuration.
apalmieri 0:dd89565c6276 2320 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 2321 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 2322 */
apalmieri 0:dd89565c6276 2323 NFCTAG_StatusTypeDef ST25DV_i2c_GetMBEN_Dyn( ST25DV_EN_STATUS * const pMBEN, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 2324 {
apalmieri 0:dd89565c6276 2325 uint8_t reg_value;
apalmieri 0:dd89565c6276 2326 NFCTAG_StatusTypeDef status;
apalmieri 0:dd89565c6276 2327
apalmieri 0:dd89565c6276 2328 /* Read MB_CTRL_DYN register */
apalmieri 0:dd89565c6276 2329 status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_MB_CTRL_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2330 if( status != NFCTAG_OK )
apalmieri 0:dd89565c6276 2331 {
apalmieri 0:dd89565c6276 2332 return status;
apalmieri 0:dd89565c6276 2333 }
apalmieri 0:dd89565c6276 2334
apalmieri 0:dd89565c6276 2335 if( (reg_value & ST25DV_MB_MODE_RW_MASK ) == ST25DV_MB_MODE_RW_MASK )
apalmieri 0:dd89565c6276 2336 {
apalmieri 0:dd89565c6276 2337 *pMBEN = ST25DV_ENABLE;
apalmieri 0:dd89565c6276 2338 }
apalmieri 0:dd89565c6276 2339 else
apalmieri 0:dd89565c6276 2340 {
apalmieri 0:dd89565c6276 2341 *pMBEN = ST25DV_DISABLE;
apalmieri 0:dd89565c6276 2342 }
apalmieri 0:dd89565c6276 2343
apalmieri 0:dd89565c6276 2344 return NFCTAG_OK;
apalmieri 0:dd89565c6276 2345 }
apalmieri 0:dd89565c6276 2346
apalmieri 0:dd89565c6276 2347 /**
apalmieri 0:dd89565c6276 2348 * @brief Sets the Mailbox Enable dynamic configuration.
apalmieri 0:dd89565c6276 2349 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 2350 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 2351 */
apalmieri 0:dd89565c6276 2352 NFCTAG_StatusTypeDef ST25DV_i2c_SetMBEN_Dyn( I2C * mi2cChannel )
apalmieri 0:dd89565c6276 2353 {
apalmieri 0:dd89565c6276 2354 uint8_t reg_value;
apalmieri 0:dd89565c6276 2355
apalmieri 0:dd89565c6276 2356 /* Set dynamic Mailbox enable */
apalmieri 0:dd89565c6276 2357 reg_value = ST25DV_MB_CTRL_DYN_MBEN_MASK;
apalmieri 0:dd89565c6276 2358
apalmieri 0:dd89565c6276 2359 /* Write MB_CTRL_DYN register */
apalmieri 0:dd89565c6276 2360 return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_MB_CTRL_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2361 }
apalmieri 0:dd89565c6276 2362
apalmieri 0:dd89565c6276 2363 /**
apalmieri 0:dd89565c6276 2364 * @brief Unsets the Mailbox Enable dynamic configuration.
apalmieri 0:dd89565c6276 2365 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 2366 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 2367 */
apalmieri 0:dd89565c6276 2368 NFCTAG_StatusTypeDef ST25DV_i2c_ResetMBEN_Dyn( I2C * mi2cChannel )
apalmieri 0:dd89565c6276 2369 {
apalmieri 0:dd89565c6276 2370 uint8_t reg_value;
apalmieri 0:dd89565c6276 2371
apalmieri 0:dd89565c6276 2372
apalmieri 0:dd89565c6276 2373 /* Set dynamic Mailbox disable */
apalmieri 0:dd89565c6276 2374 reg_value = 0;
apalmieri 0:dd89565c6276 2375
apalmieri 0:dd89565c6276 2376 /* Write MB_CTRL_DYN register */
apalmieri 0:dd89565c6276 2377 ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_MB_CTRL_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2378 return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_MB_CTRL_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2379
apalmieri 0:dd89565c6276 2380 }
apalmieri 0:dd89565c6276 2381
apalmieri 0:dd89565c6276 2382 /**
apalmieri 0:dd89565c6276 2383 * @brief Reads the Mailbox message length dynamic register.
apalmieri 0:dd89565c6276 2384 * @param pMBLength Pointer on a uint8_t used to return the Mailbox message length.
apalmieri 0:dd89565c6276 2385 * @param mi2cChannel I2C channel
apalmieri 0:dd89565c6276 2386 * @return NFCTAG_StatusTypeDef enum status.
apalmieri 0:dd89565c6276 2387 */
apalmieri 0:dd89565c6276 2388 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMBLength_Dyn( uint8_t * const pMBLength, I2C * mi2cChannel )
apalmieri 0:dd89565c6276 2389 {
apalmieri 0:dd89565c6276 2390 /* Read actual value of MBLEN_DYN register */
apalmieri 0:dd89565c6276 2391 return ST25DV_i2c_ReadMailboxRegister( pMBLength, ST25DV_MBLEN_DYN_REG, 1, mi2cChannel );
apalmieri 0:dd89565c6276 2392 }
apalmieri 0:dd89565c6276 2393
apalmieri 0:dd89565c6276 2394 /**
apalmieri 0:dd89565c6276 2395 * @}
apalmieri 0:dd89565c6276 2396 */
apalmieri 0:dd89565c6276 2397
apalmieri 0:dd89565c6276 2398 /**
apalmieri 0:dd89565c6276 2399 * @}
apalmieri 0:dd89565c6276 2400 */
apalmieri 0:dd89565c6276 2401
apalmieri 0:dd89565c6276 2402
apalmieri 0:dd89565c6276 2403 /******************* (C) COPYRIGHT 2016 STMicroelectronics *****END OF FILE****/