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