Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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/
Drivers/BSP/B-L475E-IOT01/stm32l475e_iot01.c@4:137bb367ba50, 2017-04-14 (annotated)
- Committer:
- bcostm
- Date:
- Fri Apr 14 13:09:54 2017 +0200
- Revision:
- 4:137bb367ba50
- Child:
- 5:0c70bc6d2dc0
Add remaining Components files
Who changed what in which revision?
| User | Revision | Line number | New 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 | * @version V1.0.0 |
| bcostm | 4:137bb367ba50 | 6 | * @date 17-March-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>© 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 | 4:137bb367ba50 | 50 | /** @defgroup BSP BSP |
| bcostm | 4:137bb367ba50 | 51 | * @{ |
| bcostm | 4:137bb367ba50 | 52 | */ |
| bcostm | 4:137bb367ba50 | 53 | |
| bcostm | 4:137bb367ba50 | 54 | /** @defgroup STM32L475E_IOT01 STM32L475E_IOT01 |
| bcostm | 4:137bb367ba50 | 55 | * @{ |
| bcostm | 4:137bb367ba50 | 56 | */ |
| bcostm | 4:137bb367ba50 | 57 | |
| bcostm | 4:137bb367ba50 | 58 | /** @defgroup STM32L475E_IOT01_LOW_LEVEL LOW LEVEL |
| bcostm | 4:137bb367ba50 | 59 | * @{ |
| bcostm | 4:137bb367ba50 | 60 | */ |
| bcostm | 4:137bb367ba50 | 61 | |
| bcostm | 4:137bb367ba50 | 62 | /** @defgroup STM32L475E_IOT01_LOW_LEVEL_Private_Defines LOW LEVEL Private Def |
| bcostm | 4:137bb367ba50 | 63 | * @{ |
| bcostm | 4:137bb367ba50 | 64 | */ |
| bcostm | 4:137bb367ba50 | 65 | /** |
| bcostm | 4:137bb367ba50 | 66 | * @brief STM32L475E IOT01 BSP Driver version number V1.0.0 |
| bcostm | 4:137bb367ba50 | 67 | */ |
| bcostm | 4:137bb367ba50 | 68 | #define __STM32L475E_IOT01_BSP_VERSION_MAIN (0x01) /*!< [31:24] main version */ |
| bcostm | 4:137bb367ba50 | 69 | #define __STM32L475E_IOT01_BSP_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */ |
| bcostm | 4:137bb367ba50 | 70 | #define __STM32L475E_IOT01_BSP_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */ |
| bcostm | 4:137bb367ba50 | 71 | #define __STM32L475E_IOT01_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */ |
| bcostm | 4:137bb367ba50 | 72 | #define __STM32L475E_IOT01_BSP_VERSION ((__STM32L475E_IOT01_BSP_VERSION_MAIN << 24)\ |
| bcostm | 4:137bb367ba50 | 73 | |(__STM32L475E_IOT01_BSP_VERSION_SUB1 << 16)\ |
| bcostm | 4:137bb367ba50 | 74 | |(__STM32L475E_IOT01_BSP_VERSION_SUB2 << 8 )\ |
| bcostm | 4:137bb367ba50 | 75 | |(__STM32L475E_IOT01_BSP_VERSION_RC)) |
| bcostm | 4:137bb367ba50 | 76 | /** |
| bcostm | 4:137bb367ba50 | 77 | * @} |
| bcostm | 4:137bb367ba50 | 78 | */ |
| bcostm | 4:137bb367ba50 | 79 | |
| bcostm | 4:137bb367ba50 | 80 | /** @defgroup STM32L475E_IOT01_LOW_LEVEL_Private_Variables LOW LEVEL Variables |
| bcostm | 4:137bb367ba50 | 81 | * @{ |
| bcostm | 4:137bb367ba50 | 82 | */ |
| bcostm | 4:137bb367ba50 | 83 | |
| bcostm | 4:137bb367ba50 | 84 | const uint32_t GPIO_PIN[LEDn] = {LED2_PIN}; |
| bcostm | 4:137bb367ba50 | 85 | |
| bcostm | 4:137bb367ba50 | 86 | |
| bcostm | 4:137bb367ba50 | 87 | GPIO_TypeDef* GPIO_PORT[LEDn] = {LED2_GPIO_PORT}; |
| bcostm | 4:137bb367ba50 | 88 | |
| bcostm | 4:137bb367ba50 | 89 | |
| bcostm | 4:137bb367ba50 | 90 | GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {USER_BUTTON_GPIO_PORT}; |
| bcostm | 4:137bb367ba50 | 91 | |
| bcostm | 4:137bb367ba50 | 92 | const uint16_t BUTTON_PIN[BUTTONn] = {USER_BUTTON_PIN}; |
| bcostm | 4:137bb367ba50 | 93 | |
| bcostm | 4:137bb367ba50 | 94 | const uint16_t BUTTON_IRQn[BUTTONn] = {USER_BUTTON_EXTI_IRQn}; |
| bcostm | 4:137bb367ba50 | 95 | |
| bcostm | 4:137bb367ba50 | 96 | USART_TypeDef* COM_USART[COMn] = {DISCOVERY_COM1}; |
| bcostm | 4:137bb367ba50 | 97 | |
| bcostm | 4:137bb367ba50 | 98 | GPIO_TypeDef* COM_TX_PORT[COMn] = {DISCOVERY_COM1_TX_GPIO_PORT}; |
| bcostm | 4:137bb367ba50 | 99 | |
| bcostm | 4:137bb367ba50 | 100 | GPIO_TypeDef* COM_RX_PORT[COMn] = {DISCOVERY_COM1_RX_GPIO_PORT}; |
| bcostm | 4:137bb367ba50 | 101 | |
| bcostm | 4:137bb367ba50 | 102 | const uint16_t COM_TX_PIN[COMn] = {DISCOVERY_COM1_TX_PIN}; |
| bcostm | 4:137bb367ba50 | 103 | |
| bcostm | 4:137bb367ba50 | 104 | const uint16_t COM_RX_PIN[COMn] = {DISCOVERY_COM1_RX_PIN}; |
| bcostm | 4:137bb367ba50 | 105 | |
| bcostm | 4:137bb367ba50 | 106 | const uint16_t COM_TX_AF[COMn] = {DISCOVERY_COM1_TX_AF}; |
| bcostm | 4:137bb367ba50 | 107 | |
| bcostm | 4:137bb367ba50 | 108 | const uint16_t COM_RX_AF[COMn] = {DISCOVERY_COM1_RX_AF}; |
| bcostm | 4:137bb367ba50 | 109 | |
| bcostm | 4:137bb367ba50 | 110 | I2C_HandleTypeDef hI2cHandler; |
| bcostm | 4:137bb367ba50 | 111 | UART_HandleTypeDef hDiscoUart; |
| 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 | 4:137bb367ba50 | 137 | /** |
| bcostm | 4:137bb367ba50 | 138 | * @} |
| bcostm | 4:137bb367ba50 | 139 | */ |
| bcostm | 4:137bb367ba50 | 140 | |
| bcostm | 4:137bb367ba50 | 141 | /** @defgroup STM32L475E_IOT01_LOW_LEVEL_Private_Functions LOW LEVEL Private Functions |
| bcostm | 4:137bb367ba50 | 142 | * @{ |
| bcostm | 4:137bb367ba50 | 143 | */ |
| bcostm | 4:137bb367ba50 | 144 | |
| bcostm | 4:137bb367ba50 | 145 | /** |
| bcostm | 4:137bb367ba50 | 146 | * @brief This method returns the STM32L475E IOT01 BSP Driver revision |
| bcostm | 4:137bb367ba50 | 147 | * @retval version: 0xXYZR (8bits for each decimal, R for RC) |
| bcostm | 4:137bb367ba50 | 148 | */ |
| bcostm | 4:137bb367ba50 | 149 | uint32_t BSP_GetVersion(void) |
| bcostm | 4:137bb367ba50 | 150 | { |
| bcostm | 4:137bb367ba50 | 151 | return __STM32L475E_IOT01_BSP_VERSION; |
| bcostm | 4:137bb367ba50 | 152 | } |
| bcostm | 4:137bb367ba50 | 153 | |
| bcostm | 4:137bb367ba50 | 154 | /** |
| bcostm | 4:137bb367ba50 | 155 | * @brief Configures LEDs. |
| bcostm | 4:137bb367ba50 | 156 | * @param Led: LED to be configured. |
| bcostm | 4:137bb367ba50 | 157 | * This parameter can be one of the following values: |
| bcostm | 4:137bb367ba50 | 158 | * @arg LED2 |
| bcostm | 4:137bb367ba50 | 159 | */ |
| bcostm | 4:137bb367ba50 | 160 | void BSP_LED_Init(Led_TypeDef Led) |
| bcostm | 4:137bb367ba50 | 161 | { |
| bcostm | 4:137bb367ba50 | 162 | GPIO_InitTypeDef gpio_init_structure; |
| bcostm | 4:137bb367ba50 | 163 | |
| bcostm | 4:137bb367ba50 | 164 | LEDx_GPIO_CLK_ENABLE(Led); |
| bcostm | 4:137bb367ba50 | 165 | /* Configure the GPIO_LED pin */ |
| bcostm | 4:137bb367ba50 | 166 | gpio_init_structure.Pin = GPIO_PIN[Led]; |
| bcostm | 4:137bb367ba50 | 167 | gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP; |
| bcostm | 4:137bb367ba50 | 168 | gpio_init_structure.Pull = GPIO_NOPULL; |
| bcostm | 4:137bb367ba50 | 169 | gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH; |
| bcostm | 4:137bb367ba50 | 170 | |
| bcostm | 4:137bb367ba50 | 171 | HAL_GPIO_Init(GPIO_PORT[Led], &gpio_init_structure); |
| bcostm | 4:137bb367ba50 | 172 | } |
| bcostm | 4:137bb367ba50 | 173 | |
| bcostm | 4:137bb367ba50 | 174 | /** |
| bcostm | 4:137bb367ba50 | 175 | * @brief DeInit LEDs. |
| bcostm | 4:137bb367ba50 | 176 | * @param Led: LED to be configured. |
| bcostm | 4:137bb367ba50 | 177 | * This parameter can be one of the following values: |
| bcostm | 4:137bb367ba50 | 178 | * @arg LED2 |
| bcostm | 4:137bb367ba50 | 179 | */ |
| bcostm | 4:137bb367ba50 | 180 | void BSP_LED_DeInit(Led_TypeDef Led) |
| bcostm | 4:137bb367ba50 | 181 | { |
| bcostm | 4:137bb367ba50 | 182 | GPIO_InitTypeDef gpio_init_structure; |
| bcostm | 4:137bb367ba50 | 183 | |
| bcostm | 4:137bb367ba50 | 184 | /* DeInit the GPIO_LED pin */ |
| bcostm | 4:137bb367ba50 | 185 | gpio_init_structure.Pin = GPIO_PIN[Led]; |
| bcostm | 4:137bb367ba50 | 186 | |
| bcostm | 4:137bb367ba50 | 187 | /* Turn off LED */ |
| bcostm | 4:137bb367ba50 | 188 | HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET); |
| bcostm | 4:137bb367ba50 | 189 | HAL_GPIO_DeInit(GPIO_PORT[Led], gpio_init_structure.Pin); |
| bcostm | 4:137bb367ba50 | 190 | } |
| bcostm | 4:137bb367ba50 | 191 | |
| bcostm | 4:137bb367ba50 | 192 | /** |
| bcostm | 4:137bb367ba50 | 193 | * @brief Turns selected LED On. |
| bcostm | 4:137bb367ba50 | 194 | * @param Led: LED to be set on |
| bcostm | 4:137bb367ba50 | 195 | * This parameter can be one of the following values: |
| bcostm | 4:137bb367ba50 | 196 | * @arg LED2 |
| bcostm | 4:137bb367ba50 | 197 | */ |
| bcostm | 4:137bb367ba50 | 198 | void BSP_LED_On(Led_TypeDef Led) |
| bcostm | 4:137bb367ba50 | 199 | { |
| bcostm | 4:137bb367ba50 | 200 | HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET); |
| bcostm | 4:137bb367ba50 | 201 | } |
| bcostm | 4:137bb367ba50 | 202 | |
| bcostm | 4:137bb367ba50 | 203 | /** |
| bcostm | 4:137bb367ba50 | 204 | * @brief Turns selected LED Off. |
| bcostm | 4:137bb367ba50 | 205 | * @param Led: LED to be set off |
| 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_Off(Led_TypeDef Led) |
| bcostm | 4:137bb367ba50 | 210 | { |
| bcostm | 4:137bb367ba50 | 211 | HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET); |
| bcostm | 4:137bb367ba50 | 212 | } |
| bcostm | 4:137bb367ba50 | 213 | |
| bcostm | 4:137bb367ba50 | 214 | /** |
| bcostm | 4:137bb367ba50 | 215 | * @brief Toggles the selected LED. |
| bcostm | 4:137bb367ba50 | 216 | * @param Led: LED to be toggled |
| 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_Toggle(Led_TypeDef Led) |
| bcostm | 4:137bb367ba50 | 221 | { |
| bcostm | 4:137bb367ba50 | 222 | HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]); |
| bcostm | 4:137bb367ba50 | 223 | } |
| bcostm | 4:137bb367ba50 | 224 | |
| bcostm | 4:137bb367ba50 | 225 | /** |
| bcostm | 4:137bb367ba50 | 226 | * @brief Configures button GPIO and EXTI Line. |
| bcostm | 4:137bb367ba50 | 227 | * @param Button: Button to be configured |
| bcostm | 4:137bb367ba50 | 228 | * This parameter can be one of the following values: |
| bcostm | 4:137bb367ba50 | 229 | * @arg BUTTON_WAKEUP: Wakeup Push Button |
| bcostm | 4:137bb367ba50 | 230 | * @param ButtonMode: Button mode |
| bcostm | 4:137bb367ba50 | 231 | * This parameter can be one of the following values: |
| bcostm | 4:137bb367ba50 | 232 | * @arg BUTTON_MODE_GPIO: Button will be used as simple IO |
| bcostm | 4:137bb367ba50 | 233 | * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line |
| bcostm | 4:137bb367ba50 | 234 | * with interrupt generation capability |
| bcostm | 4:137bb367ba50 | 235 | */ |
| bcostm | 4:137bb367ba50 | 236 | void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode) |
| bcostm | 4:137bb367ba50 | 237 | { |
| bcostm | 4:137bb367ba50 | 238 | GPIO_InitTypeDef gpio_init_structure; |
| bcostm | 4:137bb367ba50 | 239 | |
| bcostm | 4:137bb367ba50 | 240 | /* Enable the BUTTON clock */ |
| bcostm | 4:137bb367ba50 | 241 | USER_BUTTON_GPIO_CLK_ENABLE(); |
| bcostm | 4:137bb367ba50 | 242 | |
| bcostm | 4:137bb367ba50 | 243 | if(ButtonMode == BUTTON_MODE_GPIO) |
| bcostm | 4:137bb367ba50 | 244 | { |
| bcostm | 4:137bb367ba50 | 245 | /* Configure Button pin as input */ |
| bcostm | 4:137bb367ba50 | 246 | gpio_init_structure.Pin = BUTTON_PIN[Button]; |
| bcostm | 4:137bb367ba50 | 247 | gpio_init_structure.Mode = GPIO_MODE_INPUT; |
| bcostm | 4:137bb367ba50 | 248 | gpio_init_structure.Pull = GPIO_PULLUP; |
| bcostm | 4:137bb367ba50 | 249 | gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH; |
| bcostm | 4:137bb367ba50 | 250 | HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure); |
| bcostm | 4:137bb367ba50 | 251 | } |
| bcostm | 4:137bb367ba50 | 252 | |
| bcostm | 4:137bb367ba50 | 253 | if(ButtonMode == BUTTON_MODE_EXTI) |
| bcostm | 4:137bb367ba50 | 254 | { |
| bcostm | 4:137bb367ba50 | 255 | /* Configure Button pin as input with External interrupt */ |
| bcostm | 4:137bb367ba50 | 256 | gpio_init_structure.Pin = BUTTON_PIN[Button]; |
| bcostm | 4:137bb367ba50 | 257 | gpio_init_structure.Pull = GPIO_PULLUP; |
| bcostm | 4:137bb367ba50 | 258 | gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
| bcostm | 4:137bb367ba50 | 259 | |
| bcostm | 4:137bb367ba50 | 260 | gpio_init_structure.Mode = GPIO_MODE_IT_RISING; |
| bcostm | 4:137bb367ba50 | 261 | |
| bcostm | 4:137bb367ba50 | 262 | HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure); |
| bcostm | 4:137bb367ba50 | 263 | |
| bcostm | 4:137bb367ba50 | 264 | /* Enable and set Button EXTI Interrupt to the lowest priority */ |
| bcostm | 4:137bb367ba50 | 265 | HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00); |
| bcostm | 4:137bb367ba50 | 266 | HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button])); |
| bcostm | 4:137bb367ba50 | 267 | } |
| bcostm | 4:137bb367ba50 | 268 | } |
| bcostm | 4:137bb367ba50 | 269 | |
| bcostm | 4:137bb367ba50 | 270 | /** |
| bcostm | 4:137bb367ba50 | 271 | * @brief Push Button DeInit. |
| bcostm | 4:137bb367ba50 | 272 | * @param Button: Button to be configured |
| bcostm | 4:137bb367ba50 | 273 | * This parameter can be one of the following values: |
| bcostm | 4:137bb367ba50 | 274 | * @arg BUTTON_WAKEUP: Wakeup Push Button |
| bcostm | 4:137bb367ba50 | 275 | * @note PB DeInit does not disable the GPIO clock |
| bcostm | 4:137bb367ba50 | 276 | */ |
| bcostm | 4:137bb367ba50 | 277 | void BSP_PB_DeInit(Button_TypeDef Button) |
| bcostm | 4:137bb367ba50 | 278 | { |
| bcostm | 4:137bb367ba50 | 279 | GPIO_InitTypeDef gpio_init_structure; |
| bcostm | 4:137bb367ba50 | 280 | |
| bcostm | 4:137bb367ba50 | 281 | gpio_init_structure.Pin = BUTTON_PIN[Button]; |
| bcostm | 4:137bb367ba50 | 282 | HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button])); |
| bcostm | 4:137bb367ba50 | 283 | HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin); |
| bcostm | 4:137bb367ba50 | 284 | } |
| bcostm | 4:137bb367ba50 | 285 | |
| bcostm | 4:137bb367ba50 | 286 | |
| bcostm | 4:137bb367ba50 | 287 | /** |
| bcostm | 4:137bb367ba50 | 288 | * @brief Returns the selected button state. |
| bcostm | 4:137bb367ba50 | 289 | * @param Button: Button to be checked |
| bcostm | 4:137bb367ba50 | 290 | * This parameter can be one of the following values: |
| bcostm | 4:137bb367ba50 | 291 | * @arg BUTTON_WAKEUP: Wakeup Push Button |
| bcostm | 4:137bb367ba50 | 292 | * @retval The Button GPIO pin value (GPIO_PIN_RESET = button pressed) |
| bcostm | 4:137bb367ba50 | 293 | */ |
| bcostm | 4:137bb367ba50 | 294 | uint32_t BSP_PB_GetState(Button_TypeDef Button) |
| bcostm | 4:137bb367ba50 | 295 | { |
| bcostm | 4:137bb367ba50 | 296 | return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]); |
| bcostm | 4:137bb367ba50 | 297 | } |
| bcostm | 4:137bb367ba50 | 298 | |
| bcostm | 4:137bb367ba50 | 299 | /** |
| bcostm | 4:137bb367ba50 | 300 | * @brief Configures COM port. |
| bcostm | 4:137bb367ba50 | 301 | * @param COM: COM port to be configured. |
| bcostm | 4:137bb367ba50 | 302 | * This parameter can be one of the following values: |
| bcostm | 4:137bb367ba50 | 303 | * @arg COM1 |
| bcostm | 4:137bb367ba50 | 304 | * @param huart: Pointer to a UART_HandleTypeDef structure that contains the |
| bcostm | 4:137bb367ba50 | 305 | * configuration information for the specified USART peripheral. |
| bcostm | 4:137bb367ba50 | 306 | */ |
| bcostm | 4:137bb367ba50 | 307 | void BSP_COM_Init(COM_TypeDef COM, UART_HandleTypeDef *huart) |
| bcostm | 4:137bb367ba50 | 308 | { |
| bcostm | 4:137bb367ba50 | 309 | GPIO_InitTypeDef gpio_init_structure; |
| bcostm | 4:137bb367ba50 | 310 | |
| bcostm | 4:137bb367ba50 | 311 | /* Enable GPIO clock */ |
| bcostm | 4:137bb367ba50 | 312 | DISCOVERY_COMx_TX_GPIO_CLK_ENABLE(COM); |
| bcostm | 4:137bb367ba50 | 313 | DISCOVERY_COMx_RX_GPIO_CLK_ENABLE(COM); |
| bcostm | 4:137bb367ba50 | 314 | |
| bcostm | 4:137bb367ba50 | 315 | /* Enable USART clock */ |
| bcostm | 4:137bb367ba50 | 316 | DISCOVERY_COMx_CLK_ENABLE(COM); |
| bcostm | 4:137bb367ba50 | 317 | |
| bcostm | 4:137bb367ba50 | 318 | /* Configure USART Tx as alternate function */ |
| bcostm | 4:137bb367ba50 | 319 | gpio_init_structure.Pin = COM_TX_PIN[COM]; |
| bcostm | 4:137bb367ba50 | 320 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
| bcostm | 4:137bb367ba50 | 321 | gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH; |
| bcostm | 4:137bb367ba50 | 322 | gpio_init_structure.Pull = GPIO_NOPULL; |
| bcostm | 4:137bb367ba50 | 323 | gpio_init_structure.Alternate = COM_TX_AF[COM]; |
| bcostm | 4:137bb367ba50 | 324 | HAL_GPIO_Init(COM_TX_PORT[COM], &gpio_init_structure); |
| bcostm | 4:137bb367ba50 | 325 | |
| bcostm | 4:137bb367ba50 | 326 | /* Configure USART Rx as alternate function */ |
| bcostm | 4:137bb367ba50 | 327 | gpio_init_structure.Pin = COM_RX_PIN[COM]; |
| bcostm | 4:137bb367ba50 | 328 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
| bcostm | 4:137bb367ba50 | 329 | gpio_init_structure.Alternate = COM_RX_AF[COM]; |
| bcostm | 4:137bb367ba50 | 330 | HAL_GPIO_Init(COM_RX_PORT[COM], &gpio_init_structure); |
| bcostm | 4:137bb367ba50 | 331 | |
| bcostm | 4:137bb367ba50 | 332 | /* USART configuration */ |
| bcostm | 4:137bb367ba50 | 333 | huart->Instance = COM_USART[COM]; |
| bcostm | 4:137bb367ba50 | 334 | HAL_UART_Init(huart); |
| bcostm | 4:137bb367ba50 | 335 | } |
| bcostm | 4:137bb367ba50 | 336 | |
| bcostm | 4:137bb367ba50 | 337 | /** |
| bcostm | 4:137bb367ba50 | 338 | * @brief DeInit COM port. |
| bcostm | 4:137bb367ba50 | 339 | * @param COM: COM port to be configured. |
| bcostm | 4:137bb367ba50 | 340 | * This parameter can be one of the following values: |
| bcostm | 4:137bb367ba50 | 341 | * @arg COM1 |
| bcostm | 4:137bb367ba50 | 342 | * @param huart: Pointer to a UART_HandleTypeDef structure that contains the |
| bcostm | 4:137bb367ba50 | 343 | * configuration information for the specified USART peripheral. |
| bcostm | 4:137bb367ba50 | 344 | */ |
| bcostm | 4:137bb367ba50 | 345 | void BSP_COM_DeInit(COM_TypeDef COM, UART_HandleTypeDef *huart) |
| bcostm | 4:137bb367ba50 | 346 | { |
| bcostm | 4:137bb367ba50 | 347 | /* USART configuration */ |
| bcostm | 4:137bb367ba50 | 348 | huart->Instance = COM_USART[COM]; |
| bcostm | 4:137bb367ba50 | 349 | HAL_UART_DeInit(huart); |
| bcostm | 4:137bb367ba50 | 350 | |
| bcostm | 4:137bb367ba50 | 351 | /* Enable USART clock */ |
| bcostm | 4:137bb367ba50 | 352 | DISCOVERY_COMx_CLK_DISABLE(COM); |
| bcostm | 4:137bb367ba50 | 353 | |
| bcostm | 4:137bb367ba50 | 354 | /* DeInit GPIO pins can be done in the application |
| bcostm | 4:137bb367ba50 | 355 | (by surcharging this __weak function) */ |
| bcostm | 4:137bb367ba50 | 356 | |
| bcostm | 4:137bb367ba50 | 357 | /* GPIO pins clock, FMC clock and DMA clock can be shut down in the application |
| bcostm | 4:137bb367ba50 | 358 | by surcharging this __weak function */ |
| bcostm | 4:137bb367ba50 | 359 | } |
| bcostm | 4:137bb367ba50 | 360 | |
| bcostm | 4:137bb367ba50 | 361 | |
| bcostm | 4:137bb367ba50 | 362 | /******************************************************************************* |
| bcostm | 4:137bb367ba50 | 363 | BUS OPERATIONS |
| bcostm | 4:137bb367ba50 | 364 | *******************************************************************************/ |
| bcostm | 4:137bb367ba50 | 365 | |
| bcostm | 4:137bb367ba50 | 366 | /******************************* I2C Routines *********************************/ |
| bcostm | 4:137bb367ba50 | 367 | /** |
| bcostm | 4:137bb367ba50 | 368 | * @brief Initializes I2C MSP. |
| bcostm | 4:137bb367ba50 | 369 | * @param i2c_handler : I2C handler |
| bcostm | 4:137bb367ba50 | 370 | * @retval None |
| bcostm | 4:137bb367ba50 | 371 | */ |
| bcostm | 4:137bb367ba50 | 372 | static void I2Cx_MspInit(I2C_HandleTypeDef *i2c_handler) |
| bcostm | 4:137bb367ba50 | 373 | { |
| bcostm | 4:137bb367ba50 | 374 | GPIO_InitTypeDef gpio_init_structure; |
| bcostm | 4:137bb367ba50 | 375 | |
| bcostm | 4:137bb367ba50 | 376 | /*** Configure the GPIOs ***/ |
| bcostm | 4:137bb367ba50 | 377 | /* Enable GPIO clock */ |
| bcostm | 4:137bb367ba50 | 378 | DISCOVERY_I2Cx_SCL_SDA_GPIO_CLK_ENABLE(); |
| bcostm | 4:137bb367ba50 | 379 | |
| bcostm | 4:137bb367ba50 | 380 | /* Configure I2C Tx, Rx as alternate function */ |
| bcostm | 4:137bb367ba50 | 381 | gpio_init_structure.Pin = DISCOVERY_I2Cx_SCL_PIN | DISCOVERY_I2Cx_SDA_PIN; |
| bcostm | 4:137bb367ba50 | 382 | gpio_init_structure.Mode = GPIO_MODE_AF_OD; |
| bcostm | 4:137bb367ba50 | 383 | gpio_init_structure.Pull = GPIO_PULLUP; |
| bcostm | 4:137bb367ba50 | 384 | gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
| bcostm | 4:137bb367ba50 | 385 | gpio_init_structure.Alternate = DISCOVERY_I2Cx_SCL_SDA_AF; |
| bcostm | 4:137bb367ba50 | 386 | HAL_GPIO_Init(DISCOVERY_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure); |
| bcostm | 4:137bb367ba50 | 387 | |
| bcostm | 4:137bb367ba50 | 388 | HAL_GPIO_Init(DISCOVERY_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure); |
| bcostm | 4:137bb367ba50 | 389 | |
| bcostm | 4:137bb367ba50 | 390 | /*** Configure the I2C peripheral ***/ |
| bcostm | 4:137bb367ba50 | 391 | /* Enable I2C clock */ |
| bcostm | 4:137bb367ba50 | 392 | DISCOVERY_I2Cx_CLK_ENABLE(); |
| bcostm | 4:137bb367ba50 | 393 | |
| bcostm | 4:137bb367ba50 | 394 | /* Force the I2C peripheral clock reset */ |
| bcostm | 4:137bb367ba50 | 395 | DISCOVERY_I2Cx_FORCE_RESET(); |
| bcostm | 4:137bb367ba50 | 396 | |
| bcostm | 4:137bb367ba50 | 397 | /* Release the I2C peripheral clock reset */ |
| bcostm | 4:137bb367ba50 | 398 | DISCOVERY_I2Cx_RELEASE_RESET(); |
| bcostm | 4:137bb367ba50 | 399 | |
| bcostm | 4:137bb367ba50 | 400 | /* Enable and set I2Cx Interrupt to a lower priority */ |
| bcostm | 4:137bb367ba50 | 401 | HAL_NVIC_SetPriority(DISCOVERY_I2Cx_EV_IRQn, 0x0F, 0); |
| bcostm | 4:137bb367ba50 | 402 | HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_EV_IRQn); |
| bcostm | 4:137bb367ba50 | 403 | |
| bcostm | 4:137bb367ba50 | 404 | /* Enable and set I2Cx Interrupt to a lower priority */ |
| bcostm | 4:137bb367ba50 | 405 | HAL_NVIC_SetPriority(DISCOVERY_I2Cx_ER_IRQn, 0x0F, 0); |
| bcostm | 4:137bb367ba50 | 406 | HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_ER_IRQn); |
| bcostm | 4:137bb367ba50 | 407 | } |
| bcostm | 4:137bb367ba50 | 408 | |
| bcostm | 4:137bb367ba50 | 409 | /** |
| bcostm | 4:137bb367ba50 | 410 | * @brief DeInitializes I2C MSP. |
| bcostm | 4:137bb367ba50 | 411 | * @param i2c_handler : I2C handler |
| bcostm | 4:137bb367ba50 | 412 | * @retval None |
| bcostm | 4:137bb367ba50 | 413 | */ |
| bcostm | 4:137bb367ba50 | 414 | static void I2Cx_MspDeInit(I2C_HandleTypeDef *i2c_handler) |
| bcostm | 4:137bb367ba50 | 415 | { |
| bcostm | 4:137bb367ba50 | 416 | GPIO_InitTypeDef gpio_init_structure; |
| bcostm | 4:137bb367ba50 | 417 | |
| bcostm | 4:137bb367ba50 | 418 | /* Configure I2C Tx, Rx as alternate function */ |
| bcostm | 4:137bb367ba50 | 419 | gpio_init_structure.Pin = DISCOVERY_I2Cx_SCL_PIN | DISCOVERY_I2Cx_SDA_PIN; |
| bcostm | 4:137bb367ba50 | 420 | HAL_GPIO_DeInit(DISCOVERY_I2Cx_SCL_SDA_GPIO_PORT, gpio_init_structure.Pin); |
| bcostm | 4:137bb367ba50 | 421 | /* Disable GPIO clock */ |
| bcostm | 4:137bb367ba50 | 422 | DISCOVERY_I2Cx_SCL_SDA_GPIO_CLK_DISABLE(); |
| bcostm | 4:137bb367ba50 | 423 | |
| bcostm | 4:137bb367ba50 | 424 | /* Disable I2C clock */ |
| bcostm | 4:137bb367ba50 | 425 | DISCOVERY_I2Cx_CLK_DISABLE(); |
| bcostm | 4:137bb367ba50 | 426 | } |
| bcostm | 4:137bb367ba50 | 427 | |
| bcostm | 4:137bb367ba50 | 428 | /** |
| bcostm | 4:137bb367ba50 | 429 | * @brief Initializes I2C HAL. |
| bcostm | 4:137bb367ba50 | 430 | * @param i2c_handler : I2C handler |
| bcostm | 4:137bb367ba50 | 431 | * @retval None |
| bcostm | 4:137bb367ba50 | 432 | */ |
| bcostm | 4:137bb367ba50 | 433 | static void I2Cx_Init(I2C_HandleTypeDef *i2c_handler) |
| bcostm | 4:137bb367ba50 | 434 | { |
| bcostm | 4:137bb367ba50 | 435 | /* I2C configuration */ |
| bcostm | 4:137bb367ba50 | 436 | i2c_handler->Instance = DISCOVERY_I2Cx; |
| bcostm | 4:137bb367ba50 | 437 | i2c_handler->Init.Timing = DISCOVERY_I2Cx_TIMING; |
| bcostm | 4:137bb367ba50 | 438 | i2c_handler->Init.OwnAddress1 = 0; |
| bcostm | 4:137bb367ba50 | 439 | i2c_handler->Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; |
| bcostm | 4:137bb367ba50 | 440 | i2c_handler->Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; |
| bcostm | 4:137bb367ba50 | 441 | i2c_handler->Init.OwnAddress2 = 0; |
| bcostm | 4:137bb367ba50 | 442 | i2c_handler->Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; |
| bcostm | 4:137bb367ba50 | 443 | i2c_handler->Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; |
| bcostm | 4:137bb367ba50 | 444 | |
| bcostm | 4:137bb367ba50 | 445 | /* Init the I2C */ |
| bcostm | 4:137bb367ba50 | 446 | I2Cx_MspInit(i2c_handler); |
| bcostm | 4:137bb367ba50 | 447 | HAL_I2C_Init(i2c_handler); |
| bcostm | 4:137bb367ba50 | 448 | |
| bcostm | 4:137bb367ba50 | 449 | /**Configure Analogue filter */ |
| bcostm | 4:137bb367ba50 | 450 | HAL_I2CEx_ConfigAnalogFilter(i2c_handler, I2C_ANALOGFILTER_ENABLE); |
| bcostm | 4:137bb367ba50 | 451 | } |
| bcostm | 4:137bb367ba50 | 452 | |
| bcostm | 4:137bb367ba50 | 453 | /** |
| bcostm | 4:137bb367ba50 | 454 | * @brief DeInitializes I2C HAL. |
| bcostm | 4:137bb367ba50 | 455 | * @param i2c_handler : I2C handler |
| bcostm | 4:137bb367ba50 | 456 | * @retval None |
| bcostm | 4:137bb367ba50 | 457 | */ |
| bcostm | 4:137bb367ba50 | 458 | static void I2Cx_DeInit(I2C_HandleTypeDef *i2c_handler) |
| bcostm | 4:137bb367ba50 | 459 | { /* DeInit the I2C */ |
| bcostm | 4:137bb367ba50 | 460 | I2Cx_MspDeInit(i2c_handler); |
| bcostm | 4:137bb367ba50 | 461 | HAL_I2C_DeInit(i2c_handler); |
| bcostm | 4:137bb367ba50 | 462 | } |
| bcostm | 4:137bb367ba50 | 463 | |
| bcostm | 4:137bb367ba50 | 464 | /** |
| bcostm | 4:137bb367ba50 | 465 | * @brief Reads multiple data. |
| bcostm | 4:137bb367ba50 | 466 | * @param i2c_handler : I2C handler |
| bcostm | 4:137bb367ba50 | 467 | * @param Addr: I2C address |
| bcostm | 4:137bb367ba50 | 468 | * @param Reg: Reg address |
| bcostm | 4:137bb367ba50 | 469 | * @param MemAddress: memory address |
| bcostm | 4:137bb367ba50 | 470 | * @param Buffer: Pointer to data buffer |
| bcostm | 4:137bb367ba50 | 471 | * @param Length: Length of the data |
| bcostm | 4:137bb367ba50 | 472 | * @retval HAL status |
| bcostm | 4:137bb367ba50 | 473 | */ |
| bcostm | 4:137bb367ba50 | 474 | 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 | 475 | { |
| bcostm | 4:137bb367ba50 | 476 | HAL_StatusTypeDef status = HAL_OK; |
| bcostm | 4:137bb367ba50 | 477 | |
| bcostm | 4:137bb367ba50 | 478 | status = HAL_I2C_Mem_Read(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000); |
| bcostm | 4:137bb367ba50 | 479 | |
| bcostm | 4:137bb367ba50 | 480 | /* Check the communication status */ |
| bcostm | 4:137bb367ba50 | 481 | if(status != HAL_OK) |
| bcostm | 4:137bb367ba50 | 482 | { |
| bcostm | 4:137bb367ba50 | 483 | /* I2C error occured */ |
| bcostm | 4:137bb367ba50 | 484 | I2Cx_Error(i2c_handler, Addr); |
| bcostm | 4:137bb367ba50 | 485 | } |
| bcostm | 4:137bb367ba50 | 486 | return status; |
| bcostm | 4:137bb367ba50 | 487 | } |
| bcostm | 4:137bb367ba50 | 488 | |
| bcostm | 4:137bb367ba50 | 489 | |
| bcostm | 4:137bb367ba50 | 490 | /** |
| bcostm | 4:137bb367ba50 | 491 | * @brief Writes a value in a register of the device through BUS in using DMA mode. |
| bcostm | 4:137bb367ba50 | 492 | * @param i2c_handler : I2C handler |
| bcostm | 4:137bb367ba50 | 493 | * @param Addr: Device address on BUS Bus. |
| bcostm | 4:137bb367ba50 | 494 | * @param Reg: The target register address to write |
| bcostm | 4:137bb367ba50 | 495 | * @param MemAddress: memory address |
| bcostm | 4:137bb367ba50 | 496 | * @param Buffer: The target register value to be written |
| bcostm | 4:137bb367ba50 | 497 | * @param Length: buffer size to be written |
| bcostm | 4:137bb367ba50 | 498 | * @retval HAL status |
| bcostm | 4:137bb367ba50 | 499 | */ |
| bcostm | 4:137bb367ba50 | 500 | 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 | 501 | { |
| bcostm | 4:137bb367ba50 | 502 | HAL_StatusTypeDef status = HAL_OK; |
| bcostm | 4:137bb367ba50 | 503 | |
| bcostm | 4:137bb367ba50 | 504 | status = HAL_I2C_Mem_Write(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000); |
| bcostm | 4:137bb367ba50 | 505 | |
| bcostm | 4:137bb367ba50 | 506 | /* Check the communication status */ |
| bcostm | 4:137bb367ba50 | 507 | if(status != HAL_OK) |
| bcostm | 4:137bb367ba50 | 508 | { |
| bcostm | 4:137bb367ba50 | 509 | /* Re-Initiaize the I2C Bus */ |
| bcostm | 4:137bb367ba50 | 510 | I2Cx_Error(i2c_handler, Addr); |
| bcostm | 4:137bb367ba50 | 511 | } |
| bcostm | 4:137bb367ba50 | 512 | return status; |
| bcostm | 4:137bb367ba50 | 513 | } |
| bcostm | 4:137bb367ba50 | 514 | |
| bcostm | 4:137bb367ba50 | 515 | /** |
| bcostm | 4:137bb367ba50 | 516 | * @brief Checks if target device is ready for communication. |
| bcostm | 4:137bb367ba50 | 517 | * @note This function is used with Memory devices |
| bcostm | 4:137bb367ba50 | 518 | * @param i2c_handler : I2C handler |
| bcostm | 4:137bb367ba50 | 519 | * @param DevAddress: Target device address |
| bcostm | 4:137bb367ba50 | 520 | * @param Trials: Number of trials |
| bcostm | 4:137bb367ba50 | 521 | * @retval HAL status |
| bcostm | 4:137bb367ba50 | 522 | */ |
| bcostm | 4:137bb367ba50 | 523 | static HAL_StatusTypeDef I2Cx_IsDeviceReady(I2C_HandleTypeDef *i2c_handler, uint16_t DevAddress, uint32_t Trials) |
| bcostm | 4:137bb367ba50 | 524 | { |
| bcostm | 4:137bb367ba50 | 525 | return (HAL_I2C_IsDeviceReady(i2c_handler, DevAddress, Trials, 1000)); |
| bcostm | 4:137bb367ba50 | 526 | } |
| bcostm | 4:137bb367ba50 | 527 | |
| bcostm | 4:137bb367ba50 | 528 | /** |
| bcostm | 4:137bb367ba50 | 529 | * @brief Manages error callback by re-initializing I2C. |
| bcostm | 4:137bb367ba50 | 530 | * @param i2c_handler : I2C handler |
| bcostm | 4:137bb367ba50 | 531 | * @param Addr: I2C Address |
| bcostm | 4:137bb367ba50 | 532 | * @retval None |
| bcostm | 4:137bb367ba50 | 533 | */ |
| bcostm | 4:137bb367ba50 | 534 | static void I2Cx_Error(I2C_HandleTypeDef *i2c_handler, uint8_t Addr) |
| bcostm | 4:137bb367ba50 | 535 | { |
| bcostm | 4:137bb367ba50 | 536 | /* De-initialize the I2C communication bus */ |
| bcostm | 4:137bb367ba50 | 537 | HAL_I2C_DeInit(i2c_handler); |
| bcostm | 4:137bb367ba50 | 538 | |
| bcostm | 4:137bb367ba50 | 539 | /* Re-Initialize the I2C communication bus */ |
| bcostm | 4:137bb367ba50 | 540 | I2Cx_Init(i2c_handler); |
| bcostm | 4:137bb367ba50 | 541 | } |
| bcostm | 4:137bb367ba50 | 542 | |
| bcostm | 4:137bb367ba50 | 543 | /** |
| bcostm | 4:137bb367ba50 | 544 | * @} |
| bcostm | 4:137bb367ba50 | 545 | */ |
| bcostm | 4:137bb367ba50 | 546 | |
| bcostm | 4:137bb367ba50 | 547 | /******************************************************************************* |
| bcostm | 4:137bb367ba50 | 548 | LINK OPERATIONS |
| bcostm | 4:137bb367ba50 | 549 | *******************************************************************************/ |
| bcostm | 4:137bb367ba50 | 550 | /******************************** LINK Sensors ********************************/ |
| bcostm | 4:137bb367ba50 | 551 | |
| bcostm | 4:137bb367ba50 | 552 | /** |
| bcostm | 4:137bb367ba50 | 553 | * @brief Initializes Sensors low level. |
| bcostm | 4:137bb367ba50 | 554 | * @retval None |
| bcostm | 4:137bb367ba50 | 555 | */ |
| bcostm | 4:137bb367ba50 | 556 | void SENSOR_IO_Init(void) |
| bcostm | 4:137bb367ba50 | 557 | { |
| bcostm | 4:137bb367ba50 | 558 | I2Cx_Init(&hI2cHandler); |
| bcostm | 4:137bb367ba50 | 559 | } |
| bcostm | 4:137bb367ba50 | 560 | |
| bcostm | 4:137bb367ba50 | 561 | /** |
| bcostm | 4:137bb367ba50 | 562 | * @brief DeInitializes Sensors low level. |
| bcostm | 4:137bb367ba50 | 563 | * @retval None |
| bcostm | 4:137bb367ba50 | 564 | */ |
| bcostm | 4:137bb367ba50 | 565 | void SENSOR_IO_DeInit(void) |
| bcostm | 4:137bb367ba50 | 566 | { |
| bcostm | 4:137bb367ba50 | 567 | I2Cx_DeInit(&hI2cHandler); |
| bcostm | 4:137bb367ba50 | 568 | } |
| bcostm | 4:137bb367ba50 | 569 | |
| bcostm | 4:137bb367ba50 | 570 | /** |
| bcostm | 4:137bb367ba50 | 571 | * @brief Writes a single data. |
| bcostm | 4:137bb367ba50 | 572 | * @param Addr: I2C address |
| bcostm | 4:137bb367ba50 | 573 | * @param Reg: Reg address |
| bcostm | 4:137bb367ba50 | 574 | * @param Value: Data to be written |
| bcostm | 4:137bb367ba50 | 575 | * @retval None |
| bcostm | 4:137bb367ba50 | 576 | */ |
| bcostm | 4:137bb367ba50 | 577 | void SENSOR_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value) |
| bcostm | 4:137bb367ba50 | 578 | { |
| bcostm | 4:137bb367ba50 | 579 | I2Cx_WriteMultiple(&hI2cHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT,(uint8_t*)&Value, 1); |
| bcostm | 4:137bb367ba50 | 580 | } |
| bcostm | 4:137bb367ba50 | 581 | |
| bcostm | 4:137bb367ba50 | 582 | /** |
| bcostm | 4:137bb367ba50 | 583 | * @brief Reads a single data. |
| bcostm | 4:137bb367ba50 | 584 | * @param Addr: I2C address |
| bcostm | 4:137bb367ba50 | 585 | * @param Reg: Reg address |
| bcostm | 4:137bb367ba50 | 586 | * @retval Data to be read |
| bcostm | 4:137bb367ba50 | 587 | */ |
| bcostm | 4:137bb367ba50 | 588 | uint8_t SENSOR_IO_Read(uint8_t Addr, uint8_t Reg) |
| bcostm | 4:137bb367ba50 | 589 | { |
| bcostm | 4:137bb367ba50 | 590 | uint8_t read_value = 0; |
| bcostm | 4:137bb367ba50 | 591 | |
| bcostm | 4:137bb367ba50 | 592 | I2Cx_ReadMultiple(&hI2cHandler, Addr, Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&read_value, 1); |
| bcostm | 4:137bb367ba50 | 593 | |
| bcostm | 4:137bb367ba50 | 594 | return read_value; |
| bcostm | 4:137bb367ba50 | 595 | } |
| bcostm | 4:137bb367ba50 | 596 | |
| bcostm | 4:137bb367ba50 | 597 | /** |
| bcostm | 4:137bb367ba50 | 598 | * @brief Reads multiple data with I2C communication |
| bcostm | 4:137bb367ba50 | 599 | * channel from TouchScreen. |
| bcostm | 4:137bb367ba50 | 600 | * @param Addr: I2C address |
| bcostm | 4:137bb367ba50 | 601 | * @param Reg: Register address |
| bcostm | 4:137bb367ba50 | 602 | * @param Buffer: Pointer to data buffer |
| bcostm | 4:137bb367ba50 | 603 | * @param Length: Length of the data |
| bcostm | 4:137bb367ba50 | 604 | * @retval HAL status |
| bcostm | 4:137bb367ba50 | 605 | */ |
| bcostm | 4:137bb367ba50 | 606 | uint16_t SENSOR_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length) |
| bcostm | 4:137bb367ba50 | 607 | { |
| bcostm | 4:137bb367ba50 | 608 | return I2Cx_ReadMultiple(&hI2cHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length); |
| bcostm | 4:137bb367ba50 | 609 | } |
| bcostm | 4:137bb367ba50 | 610 | |
| bcostm | 4:137bb367ba50 | 611 | /** |
| bcostm | 4:137bb367ba50 | 612 | * @brief Writes multiple data with I2C communication |
| bcostm | 4:137bb367ba50 | 613 | * channel from MCU to TouchScreen. |
| bcostm | 4:137bb367ba50 | 614 | * @param Addr: I2C address |
| bcostm | 4:137bb367ba50 | 615 | * @param Reg: Register address |
| bcostm | 4:137bb367ba50 | 616 | * @param Buffer: Pointer to data buffer |
| bcostm | 4:137bb367ba50 | 617 | * @param Length: Length of the data |
| bcostm | 4:137bb367ba50 | 618 | * @retval None |
| bcostm | 4:137bb367ba50 | 619 | */ |
| bcostm | 4:137bb367ba50 | 620 | void SENSOR_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length) |
| bcostm | 4:137bb367ba50 | 621 | { |
| bcostm | 4:137bb367ba50 | 622 | I2Cx_WriteMultiple(&hI2cHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length); |
| bcostm | 4:137bb367ba50 | 623 | } |
| bcostm | 4:137bb367ba50 | 624 | |
| bcostm | 4:137bb367ba50 | 625 | /** |
| bcostm | 4:137bb367ba50 | 626 | * @brief Checks if target device is ready for communication. |
| bcostm | 4:137bb367ba50 | 627 | * @note This function is used with Memory devices |
| bcostm | 4:137bb367ba50 | 628 | * @param DevAddress: Target device address |
| bcostm | 4:137bb367ba50 | 629 | * @param Trials: Number of trials |
| bcostm | 4:137bb367ba50 | 630 | * @retval HAL status |
| bcostm | 4:137bb367ba50 | 631 | */ |
| bcostm | 4:137bb367ba50 | 632 | HAL_StatusTypeDef SENSOR_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials) |
| bcostm | 4:137bb367ba50 | 633 | { |
| bcostm | 4:137bb367ba50 | 634 | return (I2Cx_IsDeviceReady(&hI2cHandler, DevAddress, Trials)); |
| bcostm | 4:137bb367ba50 | 635 | } |
| bcostm | 4:137bb367ba50 | 636 | |
| bcostm | 4:137bb367ba50 | 637 | /** |
| bcostm | 4:137bb367ba50 | 638 | * @brief Delay function used in TouchScreen low level driver. |
| bcostm | 4:137bb367ba50 | 639 | * @param Delay: Delay in ms |
| bcostm | 4:137bb367ba50 | 640 | * @retval None |
| bcostm | 4:137bb367ba50 | 641 | */ |
| bcostm | 4:137bb367ba50 | 642 | void SENSOR_IO_Delay(uint32_t Delay) |
| bcostm | 4:137bb367ba50 | 643 | { |
| bcostm | 4:137bb367ba50 | 644 | HAL_Delay(Delay); |
| bcostm | 4:137bb367ba50 | 645 | } |
| bcostm | 4:137bb367ba50 | 646 | |
| bcostm | 4:137bb367ba50 | 647 | /** |
| bcostm | 4:137bb367ba50 | 648 | * @} |
| bcostm | 4:137bb367ba50 | 649 | */ |
| bcostm | 4:137bb367ba50 | 650 | |
| bcostm | 4:137bb367ba50 | 651 | /** |
| bcostm | 4:137bb367ba50 | 652 | * @} |
| bcostm | 4:137bb367ba50 | 653 | */ |
| bcostm | 4:137bb367ba50 | 654 | |
| bcostm | 4:137bb367ba50 | 655 | /** |
| bcostm | 4:137bb367ba50 | 656 | * @} |
| bcostm | 4:137bb367ba50 | 657 | */ |
| bcostm | 4:137bb367ba50 | 658 | |
| bcostm | 4:137bb367ba50 | 659 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |