NUCLEO-NFC01A1 board drivers.

Dependents:   Nucleo_NFC_Example I2C_NFC_Master Print_Entire_Nucleo_NFC01A1_Memory

Fork of X-NUCLEO-NFC01A1 by Enrico Gregoratto

Warning: Deprecated!

Official and up-to-date drivers can be found at this link.

Committer:
EnricoG
Date:
Sun Jan 04 18:21:34 2015 +0000
Revision:
4:1814ea3853a7
Parent:
3:0528e68eac4a
Updated poll delay

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EnricoG 3:0528e68eac4a 1 /**
EnricoG 3:0528e68eac4a 2 ******************************************************************************
EnricoG 3:0528e68eac4a 3 * @file drv_I2C_M24SR.h
EnricoG 3:0528e68eac4a 4 * @author MMY Application Team
EnricoG 3:0528e68eac4a 5 * @version V1.1.0
EnricoG 3:0528e68eac4a 6 * @date 20-October-2014
EnricoG 3:0528e68eac4a 7 * @brief This file provides a set of functions needed to manage the I2C of
EnricoG 3:0528e68eac4a 8 the M24SR device.
EnricoG 3:0528e68eac4a 9 ******************************************************************************
EnricoG 3:0528e68eac4a 10 * @attention
EnricoG 3:0528e68eac4a 11 *
EnricoG 3:0528e68eac4a 12 * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
EnricoG 3:0528e68eac4a 13 *
EnricoG 3:0528e68eac4a 14 * Licensed under MMY-ST Liberty SW License Agreement V2, (the "License");
EnricoG 3:0528e68eac4a 15 * You may not use this file except in compliance with the License.
EnricoG 3:0528e68eac4a 16 * You may obtain a copy of the License at:
EnricoG 3:0528e68eac4a 17 *
EnricoG 3:0528e68eac4a 18 * http://www.st.com/software_license_agreement_liberty_v2
EnricoG 3:0528e68eac4a 19 *
EnricoG 3:0528e68eac4a 20 * Unless required by applicable law or agreed to in writing, software
EnricoG 3:0528e68eac4a 21 * distributed under the License is distributed on an "AS IS" BASIS,
EnricoG 3:0528e68eac4a 22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
EnricoG 3:0528e68eac4a 23 * See the License for the specific language governing permissions and
EnricoG 3:0528e68eac4a 24 * limitations under the License.
EnricoG 3:0528e68eac4a 25 *
EnricoG 3:0528e68eac4a 26 ******************************************************************************
EnricoG 3:0528e68eac4a 27 */
EnricoG 3:0528e68eac4a 28
EnricoG 3:0528e68eac4a 29 /* Define to prevent recursive inclusion -------------------------------------*/
EnricoG 3:0528e68eac4a 30 #ifndef __DRV_I2CM24SR_H
EnricoG 3:0528e68eac4a 31 #define __DRV_I2CM24SR_H
EnricoG 3:0528e68eac4a 32
EnricoG 3:0528e68eac4a 33
EnricoG 3:0528e68eac4a 34 #ifdef __MBED__ /* UNDEFINED types with mbed */
EnricoG 3:0528e68eac4a 35 #ifdef TARGET_NUCLEO_F411RE
EnricoG 3:0528e68eac4a 36 #include "stm32f4xx.h"
EnricoG 3:0528e68eac4a 37 #elif TARGET_NUCLEO_F401RE
EnricoG 3:0528e68eac4a 38 #include "stm32f4xx.h"
EnricoG 3:0528e68eac4a 39 #elif defined TARGET_NUCLEO_L053R8
EnricoG 3:0528e68eac4a 40 #include "stm32l0xx.h"
EnricoG 3:0528e68eac4a 41 #elif defined TARGET_NUCLEO_F030R8
EnricoG 3:0528e68eac4a 42 #include "stm32F0xx.h"
EnricoG 3:0528e68eac4a 43 #elif defined TARGET_NUCLEO_F302R8
EnricoG 3:0528e68eac4a 44 #include "stm32F3xx.h"
EnricoG 3:0528e68eac4a 45 #elif defined TARGET_NUCLEO_L152RE
EnricoG 3:0528e68eac4a 46 #include "stm32l1xx.h"
EnricoG 3:0528e68eac4a 47 #else
EnricoG 3:0528e68eac4a 48 #error "You need to update your code to this new microcontroller"
EnricoG 3:0528e68eac4a 49 #endif
EnricoG 3:0528e68eac4a 50 #else
EnricoG 3:0528e68eac4a 51 #ifdef STM32F401xE
EnricoG 3:0528e68eac4a 52 #include "stm32f4xx_hal.h"
EnricoG 3:0528e68eac4a 53 #elif defined STM32F030x8
EnricoG 3:0528e68eac4a 54 #include "stm32f0xx_hal.h"
EnricoG 3:0528e68eac4a 55 #elif defined STM32F302x8
EnricoG 3:0528e68eac4a 56 #include "stm32f3xx_hal.h"
EnricoG 3:0528e68eac4a 57 #elif defined STM32L053xx
EnricoG 3:0528e68eac4a 58 #include "stm32l0xx_hal.h"
EnricoG 3:0528e68eac4a 59 #elif defined STM32L152xE
EnricoG 3:0528e68eac4a 60 #include "stm32l1xx_hal.h"
EnricoG 3:0528e68eac4a 61 #else
EnricoG 3:0528e68eac4a 62 #error "You need to update your code to this new microcontroller"
EnricoG 3:0528e68eac4a 63 #endif
EnricoG 3:0528e68eac4a 64 #endif
EnricoG 3:0528e68eac4a 65
EnricoG 3:0528e68eac4a 66
EnricoG 3:0528e68eac4a 67 #ifdef __cplusplus
EnricoG 3:0528e68eac4a 68 extern "C" {
EnricoG 3:0528e68eac4a 69 #endif
EnricoG 3:0528e68eac4a 70
EnricoG 3:0528e68eac4a 71 /* Includes ------------------------------------------------------------------*/
EnricoG 3:0528e68eac4a 72 #include "string.h"
EnricoG 3:0528e68eac4a 73 #include "stdio.h"
EnricoG 3:0528e68eac4a 74 #include "stdbool.h"
EnricoG 3:0528e68eac4a 75
EnricoG 3:0528e68eac4a 76 /* Flags ---------------------------------------------------------------------*/
EnricoG 3:0528e68eac4a 77 /* If both of this two flags are disabled, then the I2C polling will be used */
EnricoG 3:0528e68eac4a 78 //#define I2C_GPO_SYNCHRO_ALLOWED /* allow tu use GPO polling as I2C synchronization */
EnricoG 3:0528e68eac4a 79 //#define I2C_GPO_INTERRUPT_ALLOWED /* allow tu use GPO interrupt as I2C synchronization ! NOT SUPPORTED BY MBED ! */
EnricoG 3:0528e68eac4a 80
EnricoG 3:0528e68eac4a 81 #define EXTERNAL_PULLUP /* If SCL is already pulled up using an external resistor */
EnricoG 3:0528e68eac4a 82
EnricoG 4:1814ea3853a7 83 #define M24SR_POLL_DELAY 50 /* Delay (in ms) before starting to poll the device for command completion */
EnricoG 3:0528e68eac4a 84
EnricoG 3:0528e68eac4a 85 /* macro function ------------------------------------------------------------*/
EnricoG 3:0528e68eac4a 86
EnricoG 3:0528e68eac4a 87 #ifndef errchk
EnricoG 3:0528e68eac4a 88 #define errchk(fCall) if (status = (fCall), status != M24SR_STATUS_SUCCESS) \
EnricoG 3:0528e68eac4a 89 {goto Error;} else
EnricoG 3:0528e68eac4a 90 #endif
EnricoG 3:0528e68eac4a 91
EnricoG 3:0528e68eac4a 92 /*!< constant Unsigned integer types */
EnricoG 3:0528e68eac4a 93 typedef const unsigned char uc8;
EnricoG 3:0528e68eac4a 94 typedef const unsigned short uc16;
EnricoG 3:0528e68eac4a 95 //typedef const unsigned long uc32;
EnricoG 3:0528e68eac4a 96
EnricoG 3:0528e68eac4a 97 #define M24SR_I2C_TIMEOUT 200 /* I2C Time out (ms), this is the maximum time needed by M24SR to complete any command */
EnricoG 3:0528e68eac4a 98 #define M24SR_I2C_POLLING 1 /* In case M24SR will reply ACK failed allow to perform retry before returning error (HAL option not used) */
EnricoG 3:0528e68eac4a 99 #define M24SR_ADDR 0xAC /*!< M24SR address */
EnricoG 3:0528e68eac4a 100
EnricoG 3:0528e68eac4a 101
EnricoG 3:0528e68eac4a 102 /* error code ---------------------------------------------------------------------------------*/
EnricoG 3:0528e68eac4a 103 #define M24SR_ERRORCODE_FILEOVERFLOW 0x6280
EnricoG 3:0528e68eac4a 104 #define M24SR_ERRORCODE_ENDOFFILE 0x6282
EnricoG 3:0528e68eac4a 105 #define M24SR_ERRORCODE_PASSWORDREQUIRED 0x63C0
EnricoG 3:0528e68eac4a 106 #define M24SR_ERRORCODE_PASSWORDINCORRECT2RETRY 0x63C2
EnricoG 3:0528e68eac4a 107 #define M24SR_ERRORCODE_PASSWORDINCORRECT1RETRY 0x63C1
EnricoG 3:0528e68eac4a 108 #define M24SR_ERRORCODE_RFSESSIONKILLED 0x6500
EnricoG 3:0528e68eac4a 109 #define M24SR_ERRORCODE_UNSUCCESSFULUPDATING 0x6581
EnricoG 3:0528e68eac4a 110 #define M24SR_ERRORCODE_WRONGHLENGTH 0x6700
EnricoG 3:0528e68eac4a 111 #define M24SR_ERRORCODE_COMMANDINCORRECT 0x6981
EnricoG 3:0528e68eac4a 112 #define M24SR_ERRORCODE_SECURITYSTATUS 0x6982
EnricoG 3:0528e68eac4a 113 #define M24SR_ERRORCODE_REFERENCEDATANOTUSABLE 0x6984
EnricoG 3:0528e68eac4a 114 #define M24SR_ERRORCODE_INCORRECTPARAMETER 0x6A80
EnricoG 3:0528e68eac4a 115 #define M24SR_ERRORCODE_FILENOTFOUND 0x6A82
EnricoG 3:0528e68eac4a 116 #define M24SR_ERRORCODE_FILEOVERFLOWLC 0x6A84
EnricoG 3:0528e68eac4a 117 #define M24SR_ERRORCODE_INCORRECTP1P2 0x6A86
EnricoG 3:0528e68eac4a 118 #define M24SR_ERRORCODE_INSNOTSUPPORTED 0x6D00
EnricoG 3:0528e68eac4a 119 #define M24SR_ERRORCODE_CLASSNOTSUPPORTED 0x6E00
EnricoG 3:0528e68eac4a 120 #define M24SR_ERRORCODE_DAFAULT 0x6F00
EnricoG 3:0528e68eac4a 121
EnricoG 3:0528e68eac4a 122 /* Status and error code -----------------------------------------------------*/
EnricoG 3:0528e68eac4a 123 #define M24SR_STATUS_SUCCESS 0x0000
EnricoG 3:0528e68eac4a 124 #define M24SR_ERROR_DEFAULT 0x0010
EnricoG 3:0528e68eac4a 125 #define M24SR_ERROR_I2CTIMEOUT 0x0011
EnricoG 3:0528e68eac4a 126 #define M24SR_ERROR_CRC 0x0012
EnricoG 3:0528e68eac4a 127 #define M24SR_ERROR_NACK 0x0013
EnricoG 3:0528e68eac4a 128 #define M24SR_ERROR_PARAMETER 0x0014
EnricoG 3:0528e68eac4a 129 #define M24SR_ERROR_NBATEMPT 0x0015
EnricoG 3:0528e68eac4a 130 #define M24SR_ERROR_NOACKNOWLEDGE 0x0016
EnricoG 3:0528e68eac4a 131
EnricoG 3:0528e68eac4a 132 /* mask ------------------------------------------------------------------------------------*/
EnricoG 3:0528e68eac4a 133 typedef enum{
EnricoG 3:0528e68eac4a 134 M24SR_WAITINGTIME_UNKNOWN= 0,
EnricoG 3:0528e68eac4a 135 M24SR_WAITINGTIME_POLLING,
EnricoG 3:0528e68eac4a 136 M24SR_WAITINGTIME_TIMEOUT,
EnricoG 3:0528e68eac4a 137 M24SR_WAITINGTIME_GPO,
EnricoG 3:0528e68eac4a 138 M24SR_INTERRUPT_GPO
EnricoG 3:0528e68eac4a 139 }M24SR_WAITINGTIME_MGMT;
EnricoG 3:0528e68eac4a 140
EnricoG 3:0528e68eac4a 141 /* public function --------------------------------------------------------------------------*/
EnricoG 3:0528e68eac4a 142
EnricoG 3:0528e68eac4a 143 void M24SR_I2CInit ( void );
EnricoG 3:0528e68eac4a 144 void M24SR_GPOInit ( void );
EnricoG 3:0528e68eac4a 145 void M24SR_WaitMs ( uint32_t time_ms );
EnricoG 3:0528e68eac4a 146 void M24SR_GetTick ( uint32_t *ptickstart );
EnricoG 3:0528e68eac4a 147 void M24SR_GPO_ReadPin ( GPIO_PinState *pPinState);
EnricoG 3:0528e68eac4a 148 void M24SR_RFDIS_WritePin ( GPIO_PinState PinState);
EnricoG 3:0528e68eac4a 149 void M24SR_SetI2CSynchroMode ( uint8_t mode );
EnricoG 3:0528e68eac4a 150 int8_t M24SR_SendI2Ccommand ( uint8_t NbByte , uint8_t *pBuffer );
EnricoG 3:0528e68eac4a 151 int8_t M24SR_IsAnswerReady ( void );
EnricoG 3:0528e68eac4a 152 int8_t M24SR_PollI2C ( void );
EnricoG 3:0528e68eac4a 153 int8_t M24SR_ReceiveI2Cresponse ( uint8_t NbByte , uint8_t *pBuffer );
EnricoG 3:0528e68eac4a 154 void M24SR_RFConfig_Hard ( uint8_t OnOffChoice);
EnricoG 3:0528e68eac4a 155
EnricoG 3:0528e68eac4a 156 #endif
EnricoG 3:0528e68eac4a 157
EnricoG 3:0528e68eac4a 158 #ifdef __cplusplus
EnricoG 3:0528e68eac4a 159 }
EnricoG 3:0528e68eac4a 160 #endif
EnricoG 3:0528e68eac4a 161
EnricoG 3:0528e68eac4a 162 /******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/