Contains the BSP driver for the B-L475E-IOT01 board.

Dependents:   mbed-os-example-ble-Thermometer DISCO_L475VG_IOT01-Telegram-BOT DISCO_L475VG_IOT01-sche_cheveux DISCO_L475VG_IOT01-QSPI_FLASH_FILE_SYSTEM ... more

https://os.mbed.com/platforms/ST-Discovery-L475E-IOT01A/

Committer:
bcostm
Date:
Tue May 02 16:56:17 2017 +0200
Revision:
5:0c70bc6d2dc0
Parent:
4:137bb367ba50
Child:
6:9dfa42666f03
Update files to BSP driver V1.1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 4:137bb367ba50 1 /**
bcostm 4:137bb367ba50 2 ******************************************************************************
bcostm 4:137bb367ba50 3 * @file stm32l475e_iot01.c
bcostm 4:137bb367ba50 4 * @author MCD Application Team
bcostm 5:0c70bc6d2dc0 5 * @version V1.1.0
bcostm 5:0c70bc6d2dc0 6 * @date 21-April-2017
bcostm 4:137bb367ba50 7 * @brief STM32L475E-IOT01 board support package
bcostm 4:137bb367ba50 8 ******************************************************************************
bcostm 4:137bb367ba50 9 * @attention
bcostm 4:137bb367ba50 10 *
bcostm 4:137bb367ba50 11 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
bcostm 4:137bb367ba50 12 * All rights reserved.</center></h2>
bcostm 4:137bb367ba50 13 *
bcostm 4:137bb367ba50 14 * Redistribution and use in source and binary forms, with or without
bcostm 4:137bb367ba50 15 * modification, are permitted, provided that the following conditions are met:
bcostm 4:137bb367ba50 16 *
bcostm 4:137bb367ba50 17 * 1. Redistribution of source code must retain the above copyright notice,
bcostm 4:137bb367ba50 18 * this list of conditions and the following disclaimer.
bcostm 4:137bb367ba50 19 * 2. Redistributions in binary form must reproduce the above copyright notice,
bcostm 4:137bb367ba50 20 * this list of conditions and the following disclaimer in the documentation
bcostm 4:137bb367ba50 21 * and/or other materials provided with the distribution.
bcostm 4:137bb367ba50 22 * 3. Neither the name of STMicroelectronics nor the names of other
bcostm 4:137bb367ba50 23 * contributors to this software may be used to endorse or promote products
bcostm 4:137bb367ba50 24 * derived from this software without specific written permission.
bcostm 4:137bb367ba50 25 * 4. This software, including modifications and/or derivative works of this
bcostm 4:137bb367ba50 26 * software, must execute solely and exclusively on microcontroller or
bcostm 4:137bb367ba50 27 * microprocessor devices manufactured by or for STMicroelectronics.
bcostm 4:137bb367ba50 28 * 5. Redistribution and use of this software other than as permitted under
bcostm 4:137bb367ba50 29 * this license is void and will automatically terminate your rights under
bcostm 4:137bb367ba50 30 * this license.
bcostm 4:137bb367ba50 31 *
bcostm 4:137bb367ba50 32 * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
bcostm 4:137bb367ba50 33 * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
bcostm 4:137bb367ba50 34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
bcostm 4:137bb367ba50 35 * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
bcostm 4:137bb367ba50 36 * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
bcostm 4:137bb367ba50 37 * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
bcostm 4:137bb367ba50 38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
bcostm 4:137bb367ba50 39 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
bcostm 4:137bb367ba50 40 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
bcostm 4:137bb367ba50 41 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
bcostm 4:137bb367ba50 42 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
bcostm 4:137bb367ba50 43 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bcostm 4:137bb367ba50 44 *
bcostm 4:137bb367ba50 45 ******************************************************************************
bcostm 4:137bb367ba50 46 */
bcostm 4:137bb367ba50 47
bcostm 4:137bb367ba50 48 /* Includes ------------------------------------------------------------------*/
bcostm 4:137bb367ba50 49 #include "stm32l475e_iot01.h"
bcostm 5:0c70bc6d2dc0 50
bcostm 4:137bb367ba50 51 /** @defgroup BSP BSP
bcostm 4:137bb367ba50 52 * @{
bcostm 4:137bb367ba50 53 */
bcostm 4:137bb367ba50 54
bcostm 4:137bb367ba50 55 /** @defgroup STM32L475E_IOT01 STM32L475E_IOT01
bcostm 4:137bb367ba50 56 * @{
bcostm 4:137bb367ba50 57 */
bcostm 4:137bb367ba50 58
bcostm 4:137bb367ba50 59 /** @defgroup STM32L475E_IOT01_LOW_LEVEL LOW LEVEL
bcostm 4:137bb367ba50 60 * @{
bcostm 4:137bb367ba50 61 */
bcostm 4:137bb367ba50 62
bcostm 4:137bb367ba50 63 /** @defgroup STM32L475E_IOT01_LOW_LEVEL_Private_Defines LOW LEVEL Private Def
bcostm 4:137bb367ba50 64 * @{
bcostm 4:137bb367ba50 65 */
bcostm 4:137bb367ba50 66 /**
bcostm 5:0c70bc6d2dc0 67 * @brief STM32L475E IOT01 BSP Driver version number V1.1.0
bcostm 4:137bb367ba50 68 */
bcostm 4:137bb367ba50 69 #define __STM32L475E_IOT01_BSP_VERSION_MAIN (0x01) /*!< [31:24] main version */
bcostm 5:0c70bc6d2dc0 70 #define __STM32L475E_IOT01_BSP_VERSION_SUB1 (0x01) /*!< [23:16] sub1 version */
bcostm 4:137bb367ba50 71 #define __STM32L475E_IOT01_BSP_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */
bcostm 4:137bb367ba50 72 #define __STM32L475E_IOT01_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */
bcostm 4:137bb367ba50 73 #define __STM32L475E_IOT01_BSP_VERSION ((__STM32L475E_IOT01_BSP_VERSION_MAIN << 24)\
bcostm 4:137bb367ba50 74 |(__STM32L475E_IOT01_BSP_VERSION_SUB1 << 16)\
bcostm 4:137bb367ba50 75 |(__STM32L475E_IOT01_BSP_VERSION_SUB2 << 8 )\
bcostm 4:137bb367ba50 76 |(__STM32L475E_IOT01_BSP_VERSION_RC))
bcostm 4:137bb367ba50 77 /**
bcostm 4:137bb367ba50 78 * @}
bcostm 4:137bb367ba50 79 */
bcostm 4:137bb367ba50 80
bcostm 4:137bb367ba50 81 /** @defgroup STM32L475E_IOT01_LOW_LEVEL_Private_Variables LOW LEVEL Variables
bcostm 4:137bb367ba50 82 * @{
bcostm 4:137bb367ba50 83 */
bcostm 4:137bb367ba50 84
bcostm 4:137bb367ba50 85 const uint32_t GPIO_PIN[LEDn] = {LED2_PIN};
bcostm 4:137bb367ba50 86
bcostm 4:137bb367ba50 87
bcostm 4:137bb367ba50 88 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED2_GPIO_PORT};
bcostm 4:137bb367ba50 89
bcostm 4:137bb367ba50 90
bcostm 4:137bb367ba50 91 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {USER_BUTTON_GPIO_PORT};
bcostm 4:137bb367ba50 92
bcostm 4:137bb367ba50 93 const uint16_t BUTTON_PIN[BUTTONn] = {USER_BUTTON_PIN};
bcostm 4:137bb367ba50 94
bcostm 4:137bb367ba50 95 const uint16_t BUTTON_IRQn[BUTTONn] = {USER_BUTTON_EXTI_IRQn};
bcostm 4:137bb367ba50 96
bcostm 4:137bb367ba50 97 USART_TypeDef* COM_USART[COMn] = {DISCOVERY_COM1};
bcostm 4:137bb367ba50 98
bcostm 4:137bb367ba50 99 GPIO_TypeDef* COM_TX_PORT[COMn] = {DISCOVERY_COM1_TX_GPIO_PORT};
bcostm 4:137bb367ba50 100
bcostm 4:137bb367ba50 101 GPIO_TypeDef* COM_RX_PORT[COMn] = {DISCOVERY_COM1_RX_GPIO_PORT};
bcostm 4:137bb367ba50 102
bcostm 4:137bb367ba50 103 const uint16_t COM_TX_PIN[COMn] = {DISCOVERY_COM1_TX_PIN};
bcostm 4:137bb367ba50 104
bcostm 4:137bb367ba50 105 const uint16_t COM_RX_PIN[COMn] = {DISCOVERY_COM1_RX_PIN};
bcostm 4:137bb367ba50 106
bcostm 4:137bb367ba50 107 const uint16_t COM_TX_AF[COMn] = {DISCOVERY_COM1_TX_AF};
bcostm 4:137bb367ba50 108
bcostm 4:137bb367ba50 109 const uint16_t COM_RX_AF[COMn] = {DISCOVERY_COM1_RX_AF};
bcostm 4:137bb367ba50 110
bcostm 4:137bb367ba50 111 I2C_HandleTypeDef hI2cHandler;
bcostm 4:137bb367ba50 112 UART_HandleTypeDef hDiscoUart;
bcostm 5:0c70bc6d2dc0 113
bcostm 4:137bb367ba50 114 /**
bcostm 4:137bb367ba50 115 * @}
bcostm 4:137bb367ba50 116 */
bcostm 4:137bb367ba50 117 /** @defgroup STM32L475E_IOT01_LOW_LEVEL_Private_FunctionPrototypes LOW LEVEL Private Function Prototypes
bcostm 4:137bb367ba50 118 * @{
bcostm 4:137bb367ba50 119 */
bcostm 4:137bb367ba50 120 static void I2Cx_MspInit(I2C_HandleTypeDef *i2c_handler);
bcostm 4:137bb367ba50 121 static void I2Cx_MspDeInit(I2C_HandleTypeDef *i2c_handler);
bcostm 4:137bb367ba50 122 static void I2Cx_Init(I2C_HandleTypeDef *i2c_handler);
bcostm 4:137bb367ba50 123 static void I2Cx_DeInit(I2C_HandleTypeDef *i2c_handler);
bcostm 4:137bb367ba50 124 static HAL_StatusTypeDef I2Cx_ReadMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
bcostm 4:137bb367ba50 125 static HAL_StatusTypeDef I2Cx_WriteMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
bcostm 4:137bb367ba50 126 static HAL_StatusTypeDef I2Cx_IsDeviceReady(I2C_HandleTypeDef *i2c_handler, uint16_t DevAddress, uint32_t Trials);
bcostm 4:137bb367ba50 127 static void I2Cx_Error(I2C_HandleTypeDef *i2c_handler, uint8_t Addr);
bcostm 4:137bb367ba50 128
bcostm 4:137bb367ba50 129 /* Sensors IO functions */
bcostm 4:137bb367ba50 130 void SENSOR_IO_Init(void);
bcostm 4:137bb367ba50 131 void SENSOR_IO_DeInit(void);
bcostm 4:137bb367ba50 132 void SENSOR_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
bcostm 4:137bb367ba50 133 uint8_t SENSOR_IO_Read(uint8_t Addr, uint8_t Reg);
bcostm 4:137bb367ba50 134 uint16_t SENSOR_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
bcostm 4:137bb367ba50 135 void SENSOR_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
bcostm 4:137bb367ba50 136 HAL_StatusTypeDef SENSOR_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);
bcostm 4:137bb367ba50 137 void SENSOR_IO_Delay(uint32_t Delay);
bcostm 4:137bb367ba50 138
bcostm 5:0c70bc6d2dc0 139 void NFC_IO_Init(uint8_t GpoIrqEnable);
bcostm 5:0c70bc6d2dc0 140 void NFC_IO_DeInit(void);
bcostm 5:0c70bc6d2dc0 141 uint16_t NFC_IO_ReadMultiple (uint8_t Addr, uint8_t *pBuffer, uint16_t Length );
bcostm 5:0c70bc6d2dc0 142 uint16_t NFC_IO_WriteMultiple (uint8_t Addr, uint8_t *pBuffer, uint16_t Length);
bcostm 5:0c70bc6d2dc0 143 uint16_t NFC_IO_IsDeviceReady (uint8_t Addr, uint32_t Trials);
bcostm 5:0c70bc6d2dc0 144 void NFC_IO_ReadState(uint8_t * pPinState);
bcostm 5:0c70bc6d2dc0 145 void NFC_IO_RfDisable(uint8_t PinState);
bcostm 5:0c70bc6d2dc0 146 void NFC_IO_Delay(uint32_t Delay);
bcostm 5:0c70bc6d2dc0 147
bcostm 4:137bb367ba50 148 /**
bcostm 4:137bb367ba50 149 * @}
bcostm 4:137bb367ba50 150 */
bcostm 4:137bb367ba50 151
bcostm 4:137bb367ba50 152 /** @defgroup STM32L475E_IOT01_LOW_LEVEL_Private_Functions LOW LEVEL Private Functions
bcostm 4:137bb367ba50 153 * @{
bcostm 4:137bb367ba50 154 */
bcostm 4:137bb367ba50 155
bcostm 4:137bb367ba50 156 /**
bcostm 4:137bb367ba50 157 * @brief This method returns the STM32L475E IOT01 BSP Driver revision
bcostm 4:137bb367ba50 158 * @retval version: 0xXYZR (8bits for each decimal, R for RC)
bcostm 4:137bb367ba50 159 */
bcostm 4:137bb367ba50 160 uint32_t BSP_GetVersion(void)
bcostm 4:137bb367ba50 161 {
bcostm 4:137bb367ba50 162 return __STM32L475E_IOT01_BSP_VERSION;
bcostm 4:137bb367ba50 163 }
bcostm 4:137bb367ba50 164
bcostm 4:137bb367ba50 165 /**
bcostm 4:137bb367ba50 166 * @brief Configures LEDs.
bcostm 4:137bb367ba50 167 * @param Led: LED to be configured.
bcostm 4:137bb367ba50 168 * This parameter can be one of the following values:
bcostm 4:137bb367ba50 169 * @arg LED2
bcostm 4:137bb367ba50 170 */
bcostm 4:137bb367ba50 171 void BSP_LED_Init(Led_TypeDef Led)
bcostm 4:137bb367ba50 172 {
bcostm 4:137bb367ba50 173 GPIO_InitTypeDef gpio_init_structure;
bcostm 4:137bb367ba50 174
bcostm 4:137bb367ba50 175 LEDx_GPIO_CLK_ENABLE(Led);
bcostm 4:137bb367ba50 176 /* Configure the GPIO_LED pin */
bcostm 4:137bb367ba50 177 gpio_init_structure.Pin = GPIO_PIN[Led];
bcostm 4:137bb367ba50 178 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
bcostm 4:137bb367ba50 179 gpio_init_structure.Pull = GPIO_NOPULL;
bcostm 4:137bb367ba50 180 gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
bcostm 4:137bb367ba50 181
bcostm 4:137bb367ba50 182 HAL_GPIO_Init(GPIO_PORT[Led], &gpio_init_structure);
bcostm 4:137bb367ba50 183 }
bcostm 4:137bb367ba50 184
bcostm 4:137bb367ba50 185 /**
bcostm 4:137bb367ba50 186 * @brief DeInit LEDs.
bcostm 4:137bb367ba50 187 * @param Led: LED to be configured.
bcostm 4:137bb367ba50 188 * This parameter can be one of the following values:
bcostm 4:137bb367ba50 189 * @arg LED2
bcostm 4:137bb367ba50 190 */
bcostm 4:137bb367ba50 191 void BSP_LED_DeInit(Led_TypeDef Led)
bcostm 4:137bb367ba50 192 {
bcostm 4:137bb367ba50 193 GPIO_InitTypeDef gpio_init_structure;
bcostm 4:137bb367ba50 194
bcostm 4:137bb367ba50 195 /* DeInit the GPIO_LED pin */
bcostm 4:137bb367ba50 196 gpio_init_structure.Pin = GPIO_PIN[Led];
bcostm 4:137bb367ba50 197
bcostm 4:137bb367ba50 198 /* Turn off LED */
bcostm 4:137bb367ba50 199 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
bcostm 4:137bb367ba50 200 HAL_GPIO_DeInit(GPIO_PORT[Led], gpio_init_structure.Pin);
bcostm 4:137bb367ba50 201 }
bcostm 4:137bb367ba50 202
bcostm 4:137bb367ba50 203 /**
bcostm 4:137bb367ba50 204 * @brief Turns selected LED On.
bcostm 4:137bb367ba50 205 * @param Led: LED to be set on
bcostm 4:137bb367ba50 206 * This parameter can be one of the following values:
bcostm 4:137bb367ba50 207 * @arg LED2
bcostm 4:137bb367ba50 208 */
bcostm 4:137bb367ba50 209 void BSP_LED_On(Led_TypeDef Led)
bcostm 4:137bb367ba50 210 {
bcostm 4:137bb367ba50 211 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
bcostm 4:137bb367ba50 212 }
bcostm 4:137bb367ba50 213
bcostm 4:137bb367ba50 214 /**
bcostm 4:137bb367ba50 215 * @brief Turns selected LED Off.
bcostm 4:137bb367ba50 216 * @param Led: LED to be set off
bcostm 4:137bb367ba50 217 * This parameter can be one of the following values:
bcostm 4:137bb367ba50 218 * @arg LED2
bcostm 4:137bb367ba50 219 */
bcostm 4:137bb367ba50 220 void BSP_LED_Off(Led_TypeDef Led)
bcostm 4:137bb367ba50 221 {
bcostm 4:137bb367ba50 222 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
bcostm 4:137bb367ba50 223 }
bcostm 4:137bb367ba50 224
bcostm 4:137bb367ba50 225 /**
bcostm 4:137bb367ba50 226 * @brief Toggles the selected LED.
bcostm 4:137bb367ba50 227 * @param Led: LED to be toggled
bcostm 4:137bb367ba50 228 * This parameter can be one of the following values:
bcostm 4:137bb367ba50 229 * @arg LED2
bcostm 4:137bb367ba50 230 */
bcostm 4:137bb367ba50 231 void BSP_LED_Toggle(Led_TypeDef Led)
bcostm 4:137bb367ba50 232 {
bcostm 4:137bb367ba50 233 HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]);
bcostm 4:137bb367ba50 234 }
bcostm 4:137bb367ba50 235
bcostm 4:137bb367ba50 236 /**
bcostm 4:137bb367ba50 237 * @brief Configures button GPIO and EXTI Line.
bcostm 4:137bb367ba50 238 * @param Button: Button to be configured
bcostm 4:137bb367ba50 239 * This parameter can be one of the following values:
bcostm 4:137bb367ba50 240 * @arg BUTTON_WAKEUP: Wakeup Push Button
bcostm 4:137bb367ba50 241 * @param ButtonMode: Button mode
bcostm 4:137bb367ba50 242 * This parameter can be one of the following values:
bcostm 4:137bb367ba50 243 * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
bcostm 4:137bb367ba50 244 * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line
bcostm 4:137bb367ba50 245 * with interrupt generation capability
bcostm 4:137bb367ba50 246 */
bcostm 4:137bb367ba50 247 void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
bcostm 4:137bb367ba50 248 {
bcostm 4:137bb367ba50 249 GPIO_InitTypeDef gpio_init_structure;
bcostm 4:137bb367ba50 250
bcostm 4:137bb367ba50 251 /* Enable the BUTTON clock */
bcostm 4:137bb367ba50 252 USER_BUTTON_GPIO_CLK_ENABLE();
bcostm 4:137bb367ba50 253
bcostm 4:137bb367ba50 254 if(ButtonMode == BUTTON_MODE_GPIO)
bcostm 4:137bb367ba50 255 {
bcostm 4:137bb367ba50 256 /* Configure Button pin as input */
bcostm 4:137bb367ba50 257 gpio_init_structure.Pin = BUTTON_PIN[Button];
bcostm 4:137bb367ba50 258 gpio_init_structure.Mode = GPIO_MODE_INPUT;
bcostm 4:137bb367ba50 259 gpio_init_structure.Pull = GPIO_PULLUP;
bcostm 4:137bb367ba50 260 gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
bcostm 4:137bb367ba50 261 HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure);
bcostm 4:137bb367ba50 262 }
bcostm 4:137bb367ba50 263
bcostm 4:137bb367ba50 264 if(ButtonMode == BUTTON_MODE_EXTI)
bcostm 4:137bb367ba50 265 {
bcostm 4:137bb367ba50 266 /* Configure Button pin as input with External interrupt */
bcostm 4:137bb367ba50 267 gpio_init_structure.Pin = BUTTON_PIN[Button];
bcostm 4:137bb367ba50 268 gpio_init_structure.Pull = GPIO_PULLUP;
bcostm 4:137bb367ba50 269 gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
bcostm 4:137bb367ba50 270
bcostm 4:137bb367ba50 271 gpio_init_structure.Mode = GPIO_MODE_IT_RISING;
bcostm 4:137bb367ba50 272
bcostm 4:137bb367ba50 273 HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure);
bcostm 4:137bb367ba50 274
bcostm 4:137bb367ba50 275 /* Enable and set Button EXTI Interrupt to the lowest priority */
bcostm 4:137bb367ba50 276 HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00);
bcostm 4:137bb367ba50 277 HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
bcostm 4:137bb367ba50 278 }
bcostm 4:137bb367ba50 279 }
bcostm 4:137bb367ba50 280
bcostm 4:137bb367ba50 281 /**
bcostm 4:137bb367ba50 282 * @brief Push Button DeInit.
bcostm 4:137bb367ba50 283 * @param Button: Button to be configured
bcostm 4:137bb367ba50 284 * This parameter can be one of the following values:
bcostm 4:137bb367ba50 285 * @arg BUTTON_WAKEUP: Wakeup Push Button
bcostm 4:137bb367ba50 286 * @note PB DeInit does not disable the GPIO clock
bcostm 4:137bb367ba50 287 */
bcostm 4:137bb367ba50 288 void BSP_PB_DeInit(Button_TypeDef Button)
bcostm 4:137bb367ba50 289 {
bcostm 4:137bb367ba50 290 GPIO_InitTypeDef gpio_init_structure;
bcostm 4:137bb367ba50 291
bcostm 4:137bb367ba50 292 gpio_init_structure.Pin = BUTTON_PIN[Button];
bcostm 4:137bb367ba50 293 HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
bcostm 4:137bb367ba50 294 HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin);
bcostm 4:137bb367ba50 295 }
bcostm 4:137bb367ba50 296
bcostm 4:137bb367ba50 297
bcostm 4:137bb367ba50 298 /**
bcostm 4:137bb367ba50 299 * @brief Returns the selected button state.
bcostm 4:137bb367ba50 300 * @param Button: Button to be checked
bcostm 4:137bb367ba50 301 * This parameter can be one of the following values:
bcostm 4:137bb367ba50 302 * @arg BUTTON_WAKEUP: Wakeup Push Button
bcostm 4:137bb367ba50 303 * @retval The Button GPIO pin value (GPIO_PIN_RESET = button pressed)
bcostm 4:137bb367ba50 304 */
bcostm 4:137bb367ba50 305 uint32_t BSP_PB_GetState(Button_TypeDef Button)
bcostm 4:137bb367ba50 306 {
bcostm 4:137bb367ba50 307 return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
bcostm 4:137bb367ba50 308 }
bcostm 4:137bb367ba50 309
bcostm 4:137bb367ba50 310 /**
bcostm 4:137bb367ba50 311 * @brief Configures COM port.
bcostm 4:137bb367ba50 312 * @param COM: COM port to be configured.
bcostm 4:137bb367ba50 313 * This parameter can be one of the following values:
bcostm 4:137bb367ba50 314 * @arg COM1
bcostm 4:137bb367ba50 315 * @param huart: Pointer to a UART_HandleTypeDef structure that contains the
bcostm 4:137bb367ba50 316 * configuration information for the specified USART peripheral.
bcostm 4:137bb367ba50 317 */
bcostm 4:137bb367ba50 318 void BSP_COM_Init(COM_TypeDef COM, UART_HandleTypeDef *huart)
bcostm 4:137bb367ba50 319 {
bcostm 4:137bb367ba50 320 GPIO_InitTypeDef gpio_init_structure;
bcostm 4:137bb367ba50 321
bcostm 4:137bb367ba50 322 /* Enable GPIO clock */
bcostm 4:137bb367ba50 323 DISCOVERY_COMx_TX_GPIO_CLK_ENABLE(COM);
bcostm 4:137bb367ba50 324 DISCOVERY_COMx_RX_GPIO_CLK_ENABLE(COM);
bcostm 4:137bb367ba50 325
bcostm 4:137bb367ba50 326 /* Enable USART clock */
bcostm 4:137bb367ba50 327 DISCOVERY_COMx_CLK_ENABLE(COM);
bcostm 4:137bb367ba50 328
bcostm 4:137bb367ba50 329 /* Configure USART Tx as alternate function */
bcostm 4:137bb367ba50 330 gpio_init_structure.Pin = COM_TX_PIN[COM];
bcostm 4:137bb367ba50 331 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
bcostm 4:137bb367ba50 332 gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
bcostm 4:137bb367ba50 333 gpio_init_structure.Pull = GPIO_NOPULL;
bcostm 4:137bb367ba50 334 gpio_init_structure.Alternate = COM_TX_AF[COM];
bcostm 4:137bb367ba50 335 HAL_GPIO_Init(COM_TX_PORT[COM], &gpio_init_structure);
bcostm 4:137bb367ba50 336
bcostm 4:137bb367ba50 337 /* Configure USART Rx as alternate function */
bcostm 4:137bb367ba50 338 gpio_init_structure.Pin = COM_RX_PIN[COM];
bcostm 4:137bb367ba50 339 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
bcostm 4:137bb367ba50 340 gpio_init_structure.Alternate = COM_RX_AF[COM];
bcostm 4:137bb367ba50 341 HAL_GPIO_Init(COM_RX_PORT[COM], &gpio_init_structure);
bcostm 4:137bb367ba50 342
bcostm 4:137bb367ba50 343 /* USART configuration */
bcostm 4:137bb367ba50 344 huart->Instance = COM_USART[COM];
bcostm 4:137bb367ba50 345 HAL_UART_Init(huart);
bcostm 4:137bb367ba50 346 }
bcostm 4:137bb367ba50 347
bcostm 4:137bb367ba50 348 /**
bcostm 4:137bb367ba50 349 * @brief DeInit COM port.
bcostm 4:137bb367ba50 350 * @param COM: COM port to be configured.
bcostm 4:137bb367ba50 351 * This parameter can be one of the following values:
bcostm 4:137bb367ba50 352 * @arg COM1
bcostm 4:137bb367ba50 353 * @param huart: Pointer to a UART_HandleTypeDef structure that contains the
bcostm 4:137bb367ba50 354 * configuration information for the specified USART peripheral.
bcostm 4:137bb367ba50 355 */
bcostm 4:137bb367ba50 356 void BSP_COM_DeInit(COM_TypeDef COM, UART_HandleTypeDef *huart)
bcostm 4:137bb367ba50 357 {
bcostm 4:137bb367ba50 358 /* USART configuration */
bcostm 4:137bb367ba50 359 huart->Instance = COM_USART[COM];
bcostm 4:137bb367ba50 360 HAL_UART_DeInit(huart);
bcostm 4:137bb367ba50 361
bcostm 4:137bb367ba50 362 /* Enable USART clock */
bcostm 4:137bb367ba50 363 DISCOVERY_COMx_CLK_DISABLE(COM);
bcostm 4:137bb367ba50 364
bcostm 4:137bb367ba50 365 /* DeInit GPIO pins can be done in the application
bcostm 4:137bb367ba50 366 (by surcharging this __weak function) */
bcostm 4:137bb367ba50 367
bcostm 4:137bb367ba50 368 /* GPIO pins clock, FMC clock and DMA clock can be shut down in the application
bcostm 4:137bb367ba50 369 by surcharging this __weak function */
bcostm 4:137bb367ba50 370 }
bcostm 4:137bb367ba50 371
bcostm 4:137bb367ba50 372
bcostm 4:137bb367ba50 373 /*******************************************************************************
bcostm 4:137bb367ba50 374 BUS OPERATIONS
bcostm 4:137bb367ba50 375 *******************************************************************************/
bcostm 4:137bb367ba50 376
bcostm 4:137bb367ba50 377 /******************************* I2C Routines *********************************/
bcostm 4:137bb367ba50 378 /**
bcostm 4:137bb367ba50 379 * @brief Initializes I2C MSP.
bcostm 4:137bb367ba50 380 * @param i2c_handler : I2C handler
bcostm 4:137bb367ba50 381 * @retval None
bcostm 4:137bb367ba50 382 */
bcostm 4:137bb367ba50 383 static void I2Cx_MspInit(I2C_HandleTypeDef *i2c_handler)
bcostm 4:137bb367ba50 384 {
bcostm 4:137bb367ba50 385 GPIO_InitTypeDef gpio_init_structure;
bcostm 4:137bb367ba50 386
bcostm 4:137bb367ba50 387 /*** Configure the GPIOs ***/
bcostm 4:137bb367ba50 388 /* Enable GPIO clock */
bcostm 4:137bb367ba50 389 DISCOVERY_I2Cx_SCL_SDA_GPIO_CLK_ENABLE();
bcostm 4:137bb367ba50 390
bcostm 4:137bb367ba50 391 /* Configure I2C Tx, Rx as alternate function */
bcostm 4:137bb367ba50 392 gpio_init_structure.Pin = DISCOVERY_I2Cx_SCL_PIN | DISCOVERY_I2Cx_SDA_PIN;
bcostm 4:137bb367ba50 393 gpio_init_structure.Mode = GPIO_MODE_AF_OD;
bcostm 4:137bb367ba50 394 gpio_init_structure.Pull = GPIO_PULLUP;
bcostm 4:137bb367ba50 395 gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
bcostm 4:137bb367ba50 396 gpio_init_structure.Alternate = DISCOVERY_I2Cx_SCL_SDA_AF;
bcostm 4:137bb367ba50 397 HAL_GPIO_Init(DISCOVERY_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
bcostm 4:137bb367ba50 398
bcostm 4:137bb367ba50 399 HAL_GPIO_Init(DISCOVERY_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
bcostm 4:137bb367ba50 400
bcostm 4:137bb367ba50 401 /*** Configure the I2C peripheral ***/
bcostm 4:137bb367ba50 402 /* Enable I2C clock */
bcostm 4:137bb367ba50 403 DISCOVERY_I2Cx_CLK_ENABLE();
bcostm 4:137bb367ba50 404
bcostm 4:137bb367ba50 405 /* Force the I2C peripheral clock reset */
bcostm 4:137bb367ba50 406 DISCOVERY_I2Cx_FORCE_RESET();
bcostm 4:137bb367ba50 407
bcostm 4:137bb367ba50 408 /* Release the I2C peripheral clock reset */
bcostm 4:137bb367ba50 409 DISCOVERY_I2Cx_RELEASE_RESET();
bcostm 4:137bb367ba50 410
bcostm 4:137bb367ba50 411 /* Enable and set I2Cx Interrupt to a lower priority */
bcostm 4:137bb367ba50 412 HAL_NVIC_SetPriority(DISCOVERY_I2Cx_EV_IRQn, 0x0F, 0);
bcostm 4:137bb367ba50 413 HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_EV_IRQn);
bcostm 4:137bb367ba50 414
bcostm 4:137bb367ba50 415 /* Enable and set I2Cx Interrupt to a lower priority */
bcostm 4:137bb367ba50 416 HAL_NVIC_SetPriority(DISCOVERY_I2Cx_ER_IRQn, 0x0F, 0);
bcostm 4:137bb367ba50 417 HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_ER_IRQn);
bcostm 4:137bb367ba50 418 }
bcostm 4:137bb367ba50 419
bcostm 4:137bb367ba50 420 /**
bcostm 4:137bb367ba50 421 * @brief DeInitializes I2C MSP.
bcostm 4:137bb367ba50 422 * @param i2c_handler : I2C handler
bcostm 4:137bb367ba50 423 * @retval None
bcostm 4:137bb367ba50 424 */
bcostm 4:137bb367ba50 425 static void I2Cx_MspDeInit(I2C_HandleTypeDef *i2c_handler)
bcostm 4:137bb367ba50 426 {
bcostm 4:137bb367ba50 427 GPIO_InitTypeDef gpio_init_structure;
bcostm 4:137bb367ba50 428
bcostm 4:137bb367ba50 429 /* Configure I2C Tx, Rx as alternate function */
bcostm 4:137bb367ba50 430 gpio_init_structure.Pin = DISCOVERY_I2Cx_SCL_PIN | DISCOVERY_I2Cx_SDA_PIN;
bcostm 4:137bb367ba50 431 HAL_GPIO_DeInit(DISCOVERY_I2Cx_SCL_SDA_GPIO_PORT, gpio_init_structure.Pin);
bcostm 4:137bb367ba50 432 /* Disable GPIO clock */
bcostm 4:137bb367ba50 433 DISCOVERY_I2Cx_SCL_SDA_GPIO_CLK_DISABLE();
bcostm 4:137bb367ba50 434
bcostm 4:137bb367ba50 435 /* Disable I2C clock */
bcostm 4:137bb367ba50 436 DISCOVERY_I2Cx_CLK_DISABLE();
bcostm 4:137bb367ba50 437 }
bcostm 4:137bb367ba50 438
bcostm 4:137bb367ba50 439 /**
bcostm 4:137bb367ba50 440 * @brief Initializes I2C HAL.
bcostm 4:137bb367ba50 441 * @param i2c_handler : I2C handler
bcostm 4:137bb367ba50 442 * @retval None
bcostm 4:137bb367ba50 443 */
bcostm 4:137bb367ba50 444 static void I2Cx_Init(I2C_HandleTypeDef *i2c_handler)
bcostm 4:137bb367ba50 445 {
bcostm 4:137bb367ba50 446 /* I2C configuration */
bcostm 4:137bb367ba50 447 i2c_handler->Instance = DISCOVERY_I2Cx;
bcostm 4:137bb367ba50 448 i2c_handler->Init.Timing = DISCOVERY_I2Cx_TIMING;
bcostm 4:137bb367ba50 449 i2c_handler->Init.OwnAddress1 = 0;
bcostm 4:137bb367ba50 450 i2c_handler->Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
bcostm 4:137bb367ba50 451 i2c_handler->Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
bcostm 4:137bb367ba50 452 i2c_handler->Init.OwnAddress2 = 0;
bcostm 4:137bb367ba50 453 i2c_handler->Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
bcostm 4:137bb367ba50 454 i2c_handler->Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
bcostm 5:0c70bc6d2dc0 455
bcostm 4:137bb367ba50 456 /* Init the I2C */
bcostm 4:137bb367ba50 457 I2Cx_MspInit(i2c_handler);
bcostm 4:137bb367ba50 458 HAL_I2C_Init(i2c_handler);
bcostm 4:137bb367ba50 459
bcostm 4:137bb367ba50 460 /**Configure Analogue filter */
bcostm 4:137bb367ba50 461 HAL_I2CEx_ConfigAnalogFilter(i2c_handler, I2C_ANALOGFILTER_ENABLE);
bcostm 4:137bb367ba50 462 }
bcostm 4:137bb367ba50 463
bcostm 4:137bb367ba50 464 /**
bcostm 4:137bb367ba50 465 * @brief DeInitializes I2C HAL.
bcostm 4:137bb367ba50 466 * @param i2c_handler : I2C handler
bcostm 4:137bb367ba50 467 * @retval None
bcostm 4:137bb367ba50 468 */
bcostm 4:137bb367ba50 469 static void I2Cx_DeInit(I2C_HandleTypeDef *i2c_handler)
bcostm 4:137bb367ba50 470 { /* DeInit the I2C */
bcostm 4:137bb367ba50 471 I2Cx_MspDeInit(i2c_handler);
bcostm 4:137bb367ba50 472 HAL_I2C_DeInit(i2c_handler);
bcostm 4:137bb367ba50 473 }
bcostm 4:137bb367ba50 474
bcostm 4:137bb367ba50 475 /**
bcostm 4:137bb367ba50 476 * @brief Reads multiple data.
bcostm 4:137bb367ba50 477 * @param i2c_handler : I2C handler
bcostm 4:137bb367ba50 478 * @param Addr: I2C address
bcostm 4:137bb367ba50 479 * @param Reg: Reg address
bcostm 4:137bb367ba50 480 * @param MemAddress: memory address
bcostm 4:137bb367ba50 481 * @param Buffer: Pointer to data buffer
bcostm 4:137bb367ba50 482 * @param Length: Length of the data
bcostm 4:137bb367ba50 483 * @retval HAL status
bcostm 4:137bb367ba50 484 */
bcostm 4:137bb367ba50 485 static HAL_StatusTypeDef I2Cx_ReadMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddress, uint8_t *Buffer, uint16_t Length)
bcostm 4:137bb367ba50 486 {
bcostm 4:137bb367ba50 487 HAL_StatusTypeDef status = HAL_OK;
bcostm 4:137bb367ba50 488
bcostm 4:137bb367ba50 489 status = HAL_I2C_Mem_Read(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000);
bcostm 4:137bb367ba50 490
bcostm 4:137bb367ba50 491 /* Check the communication status */
bcostm 4:137bb367ba50 492 if(status != HAL_OK)
bcostm 4:137bb367ba50 493 {
bcostm 4:137bb367ba50 494 /* I2C error occured */
bcostm 4:137bb367ba50 495 I2Cx_Error(i2c_handler, Addr);
bcostm 4:137bb367ba50 496 }
bcostm 4:137bb367ba50 497 return status;
bcostm 4:137bb367ba50 498 }
bcostm 4:137bb367ba50 499
bcostm 4:137bb367ba50 500
bcostm 4:137bb367ba50 501 /**
bcostm 4:137bb367ba50 502 * @brief Writes a value in a register of the device through BUS in using DMA mode.
bcostm 4:137bb367ba50 503 * @param i2c_handler : I2C handler
bcostm 4:137bb367ba50 504 * @param Addr: Device address on BUS Bus.
bcostm 4:137bb367ba50 505 * @param Reg: The target register address to write
bcostm 4:137bb367ba50 506 * @param MemAddress: memory address
bcostm 4:137bb367ba50 507 * @param Buffer: The target register value to be written
bcostm 4:137bb367ba50 508 * @param Length: buffer size to be written
bcostm 4:137bb367ba50 509 * @retval HAL status
bcostm 4:137bb367ba50 510 */
bcostm 4:137bb367ba50 511 static HAL_StatusTypeDef I2Cx_WriteMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddress, uint8_t *Buffer, uint16_t Length)
bcostm 4:137bb367ba50 512 {
bcostm 4:137bb367ba50 513 HAL_StatusTypeDef status = HAL_OK;
bcostm 4:137bb367ba50 514
bcostm 4:137bb367ba50 515 status = HAL_I2C_Mem_Write(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000);
bcostm 4:137bb367ba50 516
bcostm 4:137bb367ba50 517 /* Check the communication status */
bcostm 4:137bb367ba50 518 if(status != HAL_OK)
bcostm 4:137bb367ba50 519 {
bcostm 4:137bb367ba50 520 /* Re-Initiaize the I2C Bus */
bcostm 4:137bb367ba50 521 I2Cx_Error(i2c_handler, Addr);
bcostm 4:137bb367ba50 522 }
bcostm 4:137bb367ba50 523 return status;
bcostm 4:137bb367ba50 524 }
bcostm 4:137bb367ba50 525
bcostm 4:137bb367ba50 526 /**
bcostm 4:137bb367ba50 527 * @brief Checks if target device is ready for communication.
bcostm 4:137bb367ba50 528 * @note This function is used with Memory devices
bcostm 4:137bb367ba50 529 * @param i2c_handler : I2C handler
bcostm 4:137bb367ba50 530 * @param DevAddress: Target device address
bcostm 4:137bb367ba50 531 * @param Trials: Number of trials
bcostm 4:137bb367ba50 532 * @retval HAL status
bcostm 4:137bb367ba50 533 */
bcostm 4:137bb367ba50 534 static HAL_StatusTypeDef I2Cx_IsDeviceReady(I2C_HandleTypeDef *i2c_handler, uint16_t DevAddress, uint32_t Trials)
bcostm 4:137bb367ba50 535 {
bcostm 4:137bb367ba50 536 return (HAL_I2C_IsDeviceReady(i2c_handler, DevAddress, Trials, 1000));
bcostm 4:137bb367ba50 537 }
bcostm 4:137bb367ba50 538
bcostm 4:137bb367ba50 539 /**
bcostm 4:137bb367ba50 540 * @brief Manages error callback by re-initializing I2C.
bcostm 4:137bb367ba50 541 * @param i2c_handler : I2C handler
bcostm 4:137bb367ba50 542 * @param Addr: I2C Address
bcostm 4:137bb367ba50 543 * @retval None
bcostm 4:137bb367ba50 544 */
bcostm 4:137bb367ba50 545 static void I2Cx_Error(I2C_HandleTypeDef *i2c_handler, uint8_t Addr)
bcostm 4:137bb367ba50 546 {
bcostm 4:137bb367ba50 547 /* De-initialize the I2C communication bus */
bcostm 4:137bb367ba50 548 HAL_I2C_DeInit(i2c_handler);
bcostm 4:137bb367ba50 549
bcostm 4:137bb367ba50 550 /* Re-Initialize the I2C communication bus */
bcostm 4:137bb367ba50 551 I2Cx_Init(i2c_handler);
bcostm 4:137bb367ba50 552 }
bcostm 4:137bb367ba50 553
bcostm 4:137bb367ba50 554 /**
bcostm 4:137bb367ba50 555 * @}
bcostm 4:137bb367ba50 556 */
bcostm 4:137bb367ba50 557
bcostm 4:137bb367ba50 558 /*******************************************************************************
bcostm 4:137bb367ba50 559 LINK OPERATIONS
bcostm 4:137bb367ba50 560 *******************************************************************************/
bcostm 4:137bb367ba50 561 /******************************** LINK Sensors ********************************/
bcostm 4:137bb367ba50 562
bcostm 4:137bb367ba50 563 /**
bcostm 4:137bb367ba50 564 * @brief Initializes Sensors low level.
bcostm 4:137bb367ba50 565 * @retval None
bcostm 4:137bb367ba50 566 */
bcostm 4:137bb367ba50 567 void SENSOR_IO_Init(void)
bcostm 4:137bb367ba50 568 {
bcostm 4:137bb367ba50 569 I2Cx_Init(&hI2cHandler);
bcostm 4:137bb367ba50 570 }
bcostm 4:137bb367ba50 571
bcostm 4:137bb367ba50 572 /**
bcostm 4:137bb367ba50 573 * @brief DeInitializes Sensors low level.
bcostm 4:137bb367ba50 574 * @retval None
bcostm 4:137bb367ba50 575 */
bcostm 4:137bb367ba50 576 void SENSOR_IO_DeInit(void)
bcostm 4:137bb367ba50 577 {
bcostm 4:137bb367ba50 578 I2Cx_DeInit(&hI2cHandler);
bcostm 4:137bb367ba50 579 }
bcostm 4:137bb367ba50 580
bcostm 4:137bb367ba50 581 /**
bcostm 4:137bb367ba50 582 * @brief Writes a single data.
bcostm 4:137bb367ba50 583 * @param Addr: I2C address
bcostm 4:137bb367ba50 584 * @param Reg: Reg address
bcostm 4:137bb367ba50 585 * @param Value: Data to be written
bcostm 4:137bb367ba50 586 * @retval None
bcostm 4:137bb367ba50 587 */
bcostm 4:137bb367ba50 588 void SENSOR_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
bcostm 4:137bb367ba50 589 {
bcostm 4:137bb367ba50 590 I2Cx_WriteMultiple(&hI2cHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT,(uint8_t*)&Value, 1);
bcostm 4:137bb367ba50 591 }
bcostm 4:137bb367ba50 592
bcostm 4:137bb367ba50 593 /**
bcostm 4:137bb367ba50 594 * @brief Reads a single data.
bcostm 4:137bb367ba50 595 * @param Addr: I2C address
bcostm 4:137bb367ba50 596 * @param Reg: Reg address
bcostm 4:137bb367ba50 597 * @retval Data to be read
bcostm 4:137bb367ba50 598 */
bcostm 4:137bb367ba50 599 uint8_t SENSOR_IO_Read(uint8_t Addr, uint8_t Reg)
bcostm 4:137bb367ba50 600 {
bcostm 4:137bb367ba50 601 uint8_t read_value = 0;
bcostm 4:137bb367ba50 602
bcostm 4:137bb367ba50 603 I2Cx_ReadMultiple(&hI2cHandler, Addr, Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&read_value, 1);
bcostm 4:137bb367ba50 604
bcostm 4:137bb367ba50 605 return read_value;
bcostm 4:137bb367ba50 606 }
bcostm 4:137bb367ba50 607
bcostm 4:137bb367ba50 608 /**
bcostm 4:137bb367ba50 609 * @brief Reads multiple data with I2C communication
bcostm 4:137bb367ba50 610 * channel from TouchScreen.
bcostm 4:137bb367ba50 611 * @param Addr: I2C address
bcostm 4:137bb367ba50 612 * @param Reg: Register address
bcostm 4:137bb367ba50 613 * @param Buffer: Pointer to data buffer
bcostm 4:137bb367ba50 614 * @param Length: Length of the data
bcostm 4:137bb367ba50 615 * @retval HAL status
bcostm 4:137bb367ba50 616 */
bcostm 4:137bb367ba50 617 uint16_t SENSOR_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
bcostm 4:137bb367ba50 618 {
bcostm 4:137bb367ba50 619 return I2Cx_ReadMultiple(&hI2cHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
bcostm 4:137bb367ba50 620 }
bcostm 4:137bb367ba50 621
bcostm 4:137bb367ba50 622 /**
bcostm 4:137bb367ba50 623 * @brief Writes multiple data with I2C communication
bcostm 4:137bb367ba50 624 * channel from MCU to TouchScreen.
bcostm 4:137bb367ba50 625 * @param Addr: I2C address
bcostm 4:137bb367ba50 626 * @param Reg: Register address
bcostm 4:137bb367ba50 627 * @param Buffer: Pointer to data buffer
bcostm 4:137bb367ba50 628 * @param Length: Length of the data
bcostm 4:137bb367ba50 629 * @retval None
bcostm 4:137bb367ba50 630 */
bcostm 4:137bb367ba50 631 void SENSOR_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
bcostm 4:137bb367ba50 632 {
bcostm 4:137bb367ba50 633 I2Cx_WriteMultiple(&hI2cHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
bcostm 4:137bb367ba50 634 }
bcostm 4:137bb367ba50 635
bcostm 4:137bb367ba50 636 /**
bcostm 4:137bb367ba50 637 * @brief Checks if target device is ready for communication.
bcostm 4:137bb367ba50 638 * @note This function is used with Memory devices
bcostm 4:137bb367ba50 639 * @param DevAddress: Target device address
bcostm 4:137bb367ba50 640 * @param Trials: Number of trials
bcostm 4:137bb367ba50 641 * @retval HAL status
bcostm 4:137bb367ba50 642 */
bcostm 4:137bb367ba50 643 HAL_StatusTypeDef SENSOR_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
bcostm 4:137bb367ba50 644 {
bcostm 4:137bb367ba50 645 return (I2Cx_IsDeviceReady(&hI2cHandler, DevAddress, Trials));
bcostm 4:137bb367ba50 646 }
bcostm 4:137bb367ba50 647
bcostm 4:137bb367ba50 648 /**
bcostm 4:137bb367ba50 649 * @brief Delay function used in TouchScreen low level driver.
bcostm 4:137bb367ba50 650 * @param Delay: Delay in ms
bcostm 4:137bb367ba50 651 * @retval None
bcostm 4:137bb367ba50 652 */
bcostm 4:137bb367ba50 653 void SENSOR_IO_Delay(uint32_t Delay)
bcostm 4:137bb367ba50 654 {
bcostm 4:137bb367ba50 655 HAL_Delay(Delay);
bcostm 4:137bb367ba50 656 }
bcostm 4:137bb367ba50 657
bcostm 5:0c70bc6d2dc0 658 /******************************** LINK NFC ********************************/
bcostm 5:0c70bc6d2dc0 659
bcostm 5:0c70bc6d2dc0 660 /**
bcostm 5:0c70bc6d2dc0 661 * @brief Initializes Sensors low level.
bcostm 5:0c70bc6d2dc0 662 * @param GpoIrqEnable: 0x0 is disable, otherwise enabled
bcostm 5:0c70bc6d2dc0 663 * @retval None
bcostm 5:0c70bc6d2dc0 664 */
bcostm 5:0c70bc6d2dc0 665 void NFC_IO_Init(uint8_t GpoIrqEnable)
bcostm 5:0c70bc6d2dc0 666 {
bcostm 5:0c70bc6d2dc0 667 GPIO_InitTypeDef GPIO_InitStruct;
bcostm 5:0c70bc6d2dc0 668
bcostm 5:0c70bc6d2dc0 669 /* I2C init */
bcostm 5:0c70bc6d2dc0 670 I2Cx_Init(&hI2cHandler);
bcostm 5:0c70bc6d2dc0 671
bcostm 5:0c70bc6d2dc0 672 /* GPIO Ports Clock Enable */
bcostm 5:0c70bc6d2dc0 673 NFC_GPIO_CLK_ENABLE();
bcostm 5:0c70bc6d2dc0 674
bcostm 5:0c70bc6d2dc0 675 /* Configure GPIO pins for GPO (PE4) */
bcostm 5:0c70bc6d2dc0 676 if(GpoIrqEnable == 0)
bcostm 5:0c70bc6d2dc0 677 {
bcostm 5:0c70bc6d2dc0 678 GPIO_InitStruct.Pin = NFC_GPIO_GPO_PIN;
bcostm 5:0c70bc6d2dc0 679 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
bcostm 5:0c70bc6d2dc0 680 GPIO_InitStruct.Pull = GPIO_PULLUP;
bcostm 5:0c70bc6d2dc0 681 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
bcostm 5:0c70bc6d2dc0 682 HAL_GPIO_Init(NFC_GPIO_GPO_PIN_PORT, &GPIO_InitStruct);
bcostm 5:0c70bc6d2dc0 683 }
bcostm 5:0c70bc6d2dc0 684 else
bcostm 5:0c70bc6d2dc0 685 {
bcostm 5:0c70bc6d2dc0 686 GPIO_InitStruct.Pin = NFC_GPIO_GPO_PIN;
bcostm 5:0c70bc6d2dc0 687 GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
bcostm 5:0c70bc6d2dc0 688 GPIO_InitStruct.Pull = GPIO_PULLUP;
bcostm 5:0c70bc6d2dc0 689 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
bcostm 5:0c70bc6d2dc0 690 HAL_GPIO_Init(NFC_GPIO_GPO_PIN_PORT, &GPIO_InitStruct);
bcostm 5:0c70bc6d2dc0 691 /* Enable and set EXTI4_IRQn Interrupt to the lowest priority */
bcostm 5:0c70bc6d2dc0 692 HAL_NVIC_SetPriority(EXTI4_IRQn, 3, 0);
bcostm 5:0c70bc6d2dc0 693 HAL_NVIC_EnableIRQ(EXTI4_IRQn);
bcostm 5:0c70bc6d2dc0 694 }
bcostm 5:0c70bc6d2dc0 695
bcostm 5:0c70bc6d2dc0 696 /* Configure GPIO pins for DISABLE (PE2)*/
bcostm 5:0c70bc6d2dc0 697 GPIO_InitStruct.Pin = NFC_GPIO_RFDISABLE_PIN;
bcostm 5:0c70bc6d2dc0 698 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
bcostm 5:0c70bc6d2dc0 699 GPIO_InitStruct.Pull = GPIO_NOPULL;
bcostm 5:0c70bc6d2dc0 700 HAL_GPIO_Init(NFC_GPIO_RFDISABLE_PIN_PORT, &GPIO_InitStruct);
bcostm 5:0c70bc6d2dc0 701 }
bcostm 5:0c70bc6d2dc0 702
bcostm 5:0c70bc6d2dc0 703 /**
bcostm 5:0c70bc6d2dc0 704 * @brief DeInitializes Sensors low level.
bcostm 5:0c70bc6d2dc0 705 * @retval None
bcostm 5:0c70bc6d2dc0 706 */
bcostm 5:0c70bc6d2dc0 707 void NFC_IO_DeInit(void)
bcostm 5:0c70bc6d2dc0 708 {
bcostm 5:0c70bc6d2dc0 709 I2Cx_DeInit(&hI2cHandler);
bcostm 5:0c70bc6d2dc0 710 }
bcostm 5:0c70bc6d2dc0 711
bcostm 5:0c70bc6d2dc0 712 /**
bcostm 5:0c70bc6d2dc0 713 * @brief This functions reads a response of the M24SR device
bcostm 5:0c70bc6d2dc0 714 * @param Addr: M24SR I2C address (do we really need to add??)
bcostm 5:0c70bc6d2dc0 715 * @param pBuffer : Pointer on the buffer to retrieve M24SR response
bcostm 5:0c70bc6d2dc0 716 * @param Length: Length of the data
bcostm 5:0c70bc6d2dc0 717 * @retval Status: Success or Timeout
bcostm 5:0c70bc6d2dc0 718 */
bcostm 5:0c70bc6d2dc0 719 uint16_t NFC_IO_ReadMultiple (uint8_t Addr, uint8_t *pBuffer, uint16_t Length )
bcostm 5:0c70bc6d2dc0 720 {
bcostm 5:0c70bc6d2dc0 721 uint16_t status ;
bcostm 5:0c70bc6d2dc0 722
bcostm 5:0c70bc6d2dc0 723 /* Before calling this function M24SR must be ready: check to detect potential issues */
bcostm 5:0c70bc6d2dc0 724 status = NFC_IO_IsDeviceReady(Addr, NFC_I2C_TRIALS);
bcostm 5:0c70bc6d2dc0 725 if (status != NFC_I2C_STATUS_SUCCESS)
bcostm 5:0c70bc6d2dc0 726 {
bcostm 5:0c70bc6d2dc0 727 return NFC_I2C_ERROR_TIMEOUT;
bcostm 5:0c70bc6d2dc0 728 }
bcostm 5:0c70bc6d2dc0 729
bcostm 5:0c70bc6d2dc0 730 if( HAL_I2C_Master_Receive(&hI2cHandler, Addr, (uint8_t*)pBuffer, Length, NFC_I2C_TIMEOUT_STD) != HAL_OK)
bcostm 5:0c70bc6d2dc0 731 {
bcostm 5:0c70bc6d2dc0 732 return NFC_I2C_ERROR_TIMEOUT;
bcostm 5:0c70bc6d2dc0 733 }
bcostm 5:0c70bc6d2dc0 734
bcostm 5:0c70bc6d2dc0 735 return NFC_I2C_STATUS_SUCCESS;
bcostm 5:0c70bc6d2dc0 736 }
bcostm 5:0c70bc6d2dc0 737
bcostm 5:0c70bc6d2dc0 738 /**
bcostm 5:0c70bc6d2dc0 739 * @brief This functions sends the command buffer
bcostm 5:0c70bc6d2dc0 740 * @param Addr: M24SR I2C address (do we really need to add??)
bcostm 5:0c70bc6d2dc0 741 * @param pBuffer : pointer to the buffer to send to the M24SR
bcostm 5:0c70bc6d2dc0 742 * @param Length: Length of the data
bcostm 5:0c70bc6d2dc0 743 * @retval Status: Success or Timeout
bcostm 5:0c70bc6d2dc0 744 */
bcostm 5:0c70bc6d2dc0 745 uint16_t NFC_IO_WriteMultiple (uint8_t Addr, uint8_t *pBuffer, uint16_t Length)
bcostm 5:0c70bc6d2dc0 746 {
bcostm 5:0c70bc6d2dc0 747 uint16_t status ;
bcostm 5:0c70bc6d2dc0 748
bcostm 5:0c70bc6d2dc0 749 /* Before calling this function M24SR must be ready: check to detect potential issues */
bcostm 5:0c70bc6d2dc0 750 status = NFC_IO_IsDeviceReady(Addr, NFC_I2C_TRIALS);
bcostm 5:0c70bc6d2dc0 751 if (status != NFC_I2C_STATUS_SUCCESS)
bcostm 5:0c70bc6d2dc0 752 {
bcostm 5:0c70bc6d2dc0 753 return NFC_I2C_ERROR_TIMEOUT;
bcostm 5:0c70bc6d2dc0 754 }
bcostm 5:0c70bc6d2dc0 755
bcostm 5:0c70bc6d2dc0 756 if( HAL_I2C_Master_Transmit(&hI2cHandler, Addr, (uint8_t*)pBuffer, Length, NFC_I2C_TIMEOUT_STD) != HAL_OK)
bcostm 5:0c70bc6d2dc0 757 {
bcostm 5:0c70bc6d2dc0 758 return NFC_I2C_ERROR_TIMEOUT;
bcostm 5:0c70bc6d2dc0 759 }
bcostm 5:0c70bc6d2dc0 760
bcostm 5:0c70bc6d2dc0 761 return NFC_I2C_STATUS_SUCCESS;
bcostm 5:0c70bc6d2dc0 762 }
bcostm 5:0c70bc6d2dc0 763
bcostm 5:0c70bc6d2dc0 764 /**
bcostm 5:0c70bc6d2dc0 765 * @brief Checks if target device is ready for communication.
bcostm 5:0c70bc6d2dc0 766 * @param Addr: M24SR I2C address (do we really need to add??)
bcostm 5:0c70bc6d2dc0 767 * @param Trials: Number of trials (currently not present in M24sr)
bcostm 5:0c70bc6d2dc0 768 * @retval Status: Success or Timeout
bcostm 5:0c70bc6d2dc0 769 */
bcostm 5:0c70bc6d2dc0 770 uint16_t NFC_IO_IsDeviceReady (uint8_t Addr, uint32_t Trials)
bcostm 5:0c70bc6d2dc0 771 {
bcostm 5:0c70bc6d2dc0 772 HAL_StatusTypeDef status;
bcostm 5:0c70bc6d2dc0 773 uint32_t tickstart = 0;
bcostm 5:0c70bc6d2dc0 774 uint32_t currenttick = 0;
bcostm 5:0c70bc6d2dc0 775
bcostm 5:0c70bc6d2dc0 776 /* Get tick */
bcostm 5:0c70bc6d2dc0 777 tickstart = HAL_GetTick();
bcostm 5:0c70bc6d2dc0 778
bcostm 5:0c70bc6d2dc0 779 /* Wait until M24SR is ready or timeout occurs */
bcostm 5:0c70bc6d2dc0 780 do
bcostm 5:0c70bc6d2dc0 781 {
bcostm 5:0c70bc6d2dc0 782 status = HAL_I2C_IsDeviceReady(&hI2cHandler, Addr, Trials, NFC_I2C_TIMEOUT_STD);
bcostm 5:0c70bc6d2dc0 783 currenttick = HAL_GetTick();
bcostm 5:0c70bc6d2dc0 784 } while( ( (currenttick - tickstart) < NFC_I2C_TIMEOUT_MAX) && (status != HAL_OK) );
bcostm 5:0c70bc6d2dc0 785
bcostm 5:0c70bc6d2dc0 786 if (status != HAL_OK)
bcostm 5:0c70bc6d2dc0 787 {
bcostm 5:0c70bc6d2dc0 788 return NFC_I2C_ERROR_TIMEOUT;
bcostm 5:0c70bc6d2dc0 789 }
bcostm 5:0c70bc6d2dc0 790
bcostm 5:0c70bc6d2dc0 791 return NFC_I2C_STATUS_SUCCESS;
bcostm 5:0c70bc6d2dc0 792 }
bcostm 5:0c70bc6d2dc0 793
bcostm 5:0c70bc6d2dc0 794 /**
bcostm 5:0c70bc6d2dc0 795 * @brief This function read the state of the M24SR GPO
bcostm 5:0c70bc6d2dc0 796 * @param none
bcostm 5:0c70bc6d2dc0 797 * @retval GPIO_PinState : state of the M24SR GPO
bcostm 5:0c70bc6d2dc0 798 */
bcostm 5:0c70bc6d2dc0 799 void NFC_IO_ReadState(uint8_t * pPinState)
bcostm 5:0c70bc6d2dc0 800 {
bcostm 5:0c70bc6d2dc0 801 *pPinState = (uint8_t)HAL_GPIO_ReadPin(NFC_GPIO_GPO_PIN_PORT,NFC_GPIO_GPO_PIN);
bcostm 5:0c70bc6d2dc0 802 }
bcostm 5:0c70bc6d2dc0 803
bcostm 5:0c70bc6d2dc0 804 /**
bcostm 5:0c70bc6d2dc0 805 * @brief This function set the state of the M24SR RF disable pin
bcostm 5:0c70bc6d2dc0 806 * @param PinState: put RF disable pin of M24SR in PinState (1 or 0)
bcostm 5:0c70bc6d2dc0 807 */
bcostm 5:0c70bc6d2dc0 808 void NFC_IO_RfDisable(uint8_t PinState)
bcostm 5:0c70bc6d2dc0 809 {
bcostm 5:0c70bc6d2dc0 810 HAL_GPIO_WritePin(NFC_GPIO_RFDISABLE_PIN_PORT,NFC_GPIO_RFDISABLE_PIN,(GPIO_PinState)PinState);
bcostm 5:0c70bc6d2dc0 811 }
bcostm 5:0c70bc6d2dc0 812
bcostm 5:0c70bc6d2dc0 813 /**
bcostm 5:0c70bc6d2dc0 814 * @brief This function wait the time given in param (in milisecond)
bcostm 5:0c70bc6d2dc0 815 * @param Delay: Delay in ms
bcostm 5:0c70bc6d2dc0 816 * @retval None
bcostm 5:0c70bc6d2dc0 817 */
bcostm 5:0c70bc6d2dc0 818 void NFC_IO_Delay(uint32_t Delay)
bcostm 5:0c70bc6d2dc0 819 {
bcostm 5:0c70bc6d2dc0 820 HAL_Delay(Delay);
bcostm 5:0c70bc6d2dc0 821 }
bcostm 5:0c70bc6d2dc0 822
bcostm 4:137bb367ba50 823 /**
bcostm 4:137bb367ba50 824 * @}
bcostm 4:137bb367ba50 825 */
bcostm 4:137bb367ba50 826
bcostm 4:137bb367ba50 827 /**
bcostm 4:137bb367ba50 828 * @}
bcostm 4:137bb367ba50 829 */
bcostm 4:137bb367ba50 830
bcostm 4:137bb367ba50 831 /**
bcostm 4:137bb367ba50 832 * @}
bcostm 4:137bb367ba50 833 */
bcostm 4:137bb367ba50 834
bcostm 4:137bb367ba50 835 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/