Clone
Dependents: SignalProcessLab DigitalSignalAlgorithm_Lab DigitalSignal_Lab
Drivers/BSP/STM32746G-Discovery/stm32746g_discovery.c@0:fc80425b677a, 2019-08-26 (annotated)
- Committer:
- ngtkien
- Date:
- Mon Aug 26 16:33:09 2019 +0000
- Revision:
- 0:fc80425b677a
Library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ngtkien | 0:fc80425b677a | 1 | /** |
ngtkien | 0:fc80425b677a | 2 | ****************************************************************************** |
ngtkien | 0:fc80425b677a | 3 | * @file stm32746g_discovery.c |
ngtkien | 0:fc80425b677a | 4 | * @author MCD Application Team |
ngtkien | 0:fc80425b677a | 5 | * @version V2.0.0 |
ngtkien | 0:fc80425b677a | 6 | * @date 30-December-2016 |
ngtkien | 0:fc80425b677a | 7 | * @brief This file provides a set of firmware functions to manage LEDs, |
ngtkien | 0:fc80425b677a | 8 | * push-buttons and COM ports available on STM32746G-Discovery |
ngtkien | 0:fc80425b677a | 9 | * board(MB1191) from STMicroelectronics. |
ngtkien | 0:fc80425b677a | 10 | ****************************************************************************** |
ngtkien | 0:fc80425b677a | 11 | * @attention |
ngtkien | 0:fc80425b677a | 12 | * |
ngtkien | 0:fc80425b677a | 13 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
ngtkien | 0:fc80425b677a | 14 | * |
ngtkien | 0:fc80425b677a | 15 | * Redistribution and use in source and binary forms, with or without modification, |
ngtkien | 0:fc80425b677a | 16 | * are permitted provided that the following conditions are met: |
ngtkien | 0:fc80425b677a | 17 | * 1. Redistributions of source code must retain the above copyright notice, |
ngtkien | 0:fc80425b677a | 18 | * this list of conditions and the following disclaimer. |
ngtkien | 0:fc80425b677a | 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
ngtkien | 0:fc80425b677a | 20 | * this list of conditions and the following disclaimer in the documentation |
ngtkien | 0:fc80425b677a | 21 | * and/or other materials provided with the distribution. |
ngtkien | 0:fc80425b677a | 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
ngtkien | 0:fc80425b677a | 23 | * may be used to endorse or promote products derived from this software |
ngtkien | 0:fc80425b677a | 24 | * without specific prior written permission. |
ngtkien | 0:fc80425b677a | 25 | * |
ngtkien | 0:fc80425b677a | 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
ngtkien | 0:fc80425b677a | 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
ngtkien | 0:fc80425b677a | 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
ngtkien | 0:fc80425b677a | 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
ngtkien | 0:fc80425b677a | 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
ngtkien | 0:fc80425b677a | 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
ngtkien | 0:fc80425b677a | 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
ngtkien | 0:fc80425b677a | 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
ngtkien | 0:fc80425b677a | 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
ngtkien | 0:fc80425b677a | 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ngtkien | 0:fc80425b677a | 36 | * |
ngtkien | 0:fc80425b677a | 37 | ****************************************************************************** |
ngtkien | 0:fc80425b677a | 38 | */ |
ngtkien | 0:fc80425b677a | 39 | |
ngtkien | 0:fc80425b677a | 40 | /* Includes ------------------------------------------------------------------*/ |
ngtkien | 0:fc80425b677a | 41 | #include "stm32746g_discovery.h" |
ngtkien | 0:fc80425b677a | 42 | |
ngtkien | 0:fc80425b677a | 43 | void wait_ms(int ms); // MBED to replace HAL_Delay function |
ngtkien | 0:fc80425b677a | 44 | |
ngtkien | 0:fc80425b677a | 45 | /** @addtogroup BSP |
ngtkien | 0:fc80425b677a | 46 | * @{ |
ngtkien | 0:fc80425b677a | 47 | */ |
ngtkien | 0:fc80425b677a | 48 | |
ngtkien | 0:fc80425b677a | 49 | /** @addtogroup STM32746G_DISCOVERY |
ngtkien | 0:fc80425b677a | 50 | * @{ |
ngtkien | 0:fc80425b677a | 51 | */ |
ngtkien | 0:fc80425b677a | 52 | |
ngtkien | 0:fc80425b677a | 53 | /** @defgroup STM32746G_DISCOVERY_LOW_LEVEL STM32746G_DISCOVERY_LOW_LEVEL |
ngtkien | 0:fc80425b677a | 54 | * @{ |
ngtkien | 0:fc80425b677a | 55 | */ |
ngtkien | 0:fc80425b677a | 56 | |
ngtkien | 0:fc80425b677a | 57 | /** @defgroup STM32746G_DISCOVERY_LOW_LEVEL_Private_TypesDefinitions STM32746G_DISCOVERY_LOW_LEVEL Private Types Definitions |
ngtkien | 0:fc80425b677a | 58 | * @{ |
ngtkien | 0:fc80425b677a | 59 | */ |
ngtkien | 0:fc80425b677a | 60 | /** |
ngtkien | 0:fc80425b677a | 61 | * @} |
ngtkien | 0:fc80425b677a | 62 | */ |
ngtkien | 0:fc80425b677a | 63 | |
ngtkien | 0:fc80425b677a | 64 | /** @defgroup STM32746G_DISCOVERY_LOW_LEVEL_Private_Defines STM32746G_DISCOVERY_LOW_LEVEL Private Defines |
ngtkien | 0:fc80425b677a | 65 | * @{ |
ngtkien | 0:fc80425b677a | 66 | */ |
ngtkien | 0:fc80425b677a | 67 | /** |
ngtkien | 0:fc80425b677a | 68 | * @brief STM32746G DISCOVERY BSP Driver version number V2.0.0 |
ngtkien | 0:fc80425b677a | 69 | */ |
ngtkien | 0:fc80425b677a | 70 | #define __STM32746G_DISCO_BSP_VERSION_MAIN (0x02) /*!< [31:24] main version */ |
ngtkien | 0:fc80425b677a | 71 | #define __STM32746G_DISCO_BSP_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */ |
ngtkien | 0:fc80425b677a | 72 | #define __STM32746G_DISCO_BSP_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */ |
ngtkien | 0:fc80425b677a | 73 | #define __STM32746G_DISCO_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */ |
ngtkien | 0:fc80425b677a | 74 | #define __STM32746G_DISCO_BSP_VERSION ((__STM32746G_DISCO_BSP_VERSION_MAIN << 24)\ |
ngtkien | 0:fc80425b677a | 75 | |(__STM32746G_DISCO_BSP_VERSION_SUB1 << 16)\ |
ngtkien | 0:fc80425b677a | 76 | |(__STM32746G_DISCO_BSP_VERSION_SUB2 << 8 )\ |
ngtkien | 0:fc80425b677a | 77 | |(__STM32746G_DISCO_BSP_VERSION_RC)) |
ngtkien | 0:fc80425b677a | 78 | /** |
ngtkien | 0:fc80425b677a | 79 | * @} |
ngtkien | 0:fc80425b677a | 80 | */ |
ngtkien | 0:fc80425b677a | 81 | |
ngtkien | 0:fc80425b677a | 82 | /** @defgroup STM32746G_DISCOVERY_LOW_LEVEL_Private_Macros STM32746G_DISCOVERY_LOW_LEVEL Private Macros |
ngtkien | 0:fc80425b677a | 83 | * @{ |
ngtkien | 0:fc80425b677a | 84 | */ |
ngtkien | 0:fc80425b677a | 85 | /** |
ngtkien | 0:fc80425b677a | 86 | * @} |
ngtkien | 0:fc80425b677a | 87 | */ |
ngtkien | 0:fc80425b677a | 88 | |
ngtkien | 0:fc80425b677a | 89 | /** @defgroup STM32746G_DISCOVERY_LOW_LEVEL_Private_Variables STM32746G_DISCOVERY_LOW_LEVEL Private Variables |
ngtkien | 0:fc80425b677a | 90 | * @{ |
ngtkien | 0:fc80425b677a | 91 | */ |
ngtkien | 0:fc80425b677a | 92 | |
ngtkien | 0:fc80425b677a | 93 | const uint32_t GPIO_PIN[LEDn] = {LED1_PIN}; |
ngtkien | 0:fc80425b677a | 94 | |
ngtkien | 0:fc80425b677a | 95 | GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT, |
ngtkien | 0:fc80425b677a | 96 | TAMPER_BUTTON_GPIO_PORT, |
ngtkien | 0:fc80425b677a | 97 | KEY_BUTTON_GPIO_PORT}; |
ngtkien | 0:fc80425b677a | 98 | |
ngtkien | 0:fc80425b677a | 99 | const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN, |
ngtkien | 0:fc80425b677a | 100 | TAMPER_BUTTON_PIN, |
ngtkien | 0:fc80425b677a | 101 | KEY_BUTTON_PIN}; |
ngtkien | 0:fc80425b677a | 102 | |
ngtkien | 0:fc80425b677a | 103 | const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn, |
ngtkien | 0:fc80425b677a | 104 | TAMPER_BUTTON_EXTI_IRQn, |
ngtkien | 0:fc80425b677a | 105 | KEY_BUTTON_EXTI_IRQn}; |
ngtkien | 0:fc80425b677a | 106 | |
ngtkien | 0:fc80425b677a | 107 | USART_TypeDef* COM_USART[COMn] = {DISCOVERY_COM1}; |
ngtkien | 0:fc80425b677a | 108 | |
ngtkien | 0:fc80425b677a | 109 | GPIO_TypeDef* COM_TX_PORT[COMn] = {DISCOVERY_COM1_TX_GPIO_PORT}; |
ngtkien | 0:fc80425b677a | 110 | |
ngtkien | 0:fc80425b677a | 111 | GPIO_TypeDef* COM_RX_PORT[COMn] = {DISCOVERY_COM1_RX_GPIO_PORT}; |
ngtkien | 0:fc80425b677a | 112 | |
ngtkien | 0:fc80425b677a | 113 | const uint16_t COM_TX_PIN[COMn] = {DISCOVERY_COM1_TX_PIN}; |
ngtkien | 0:fc80425b677a | 114 | |
ngtkien | 0:fc80425b677a | 115 | const uint16_t COM_RX_PIN[COMn] = {DISCOVERY_COM1_RX_PIN}; |
ngtkien | 0:fc80425b677a | 116 | |
ngtkien | 0:fc80425b677a | 117 | const uint16_t COM_TX_AF[COMn] = {DISCOVERY_COM1_TX_AF}; |
ngtkien | 0:fc80425b677a | 118 | |
ngtkien | 0:fc80425b677a | 119 | const uint16_t COM_RX_AF[COMn] = {DISCOVERY_COM1_RX_AF}; |
ngtkien | 0:fc80425b677a | 120 | |
ngtkien | 0:fc80425b677a | 121 | static I2C_HandleTypeDef hI2cAudioHandler = {0}; |
ngtkien | 0:fc80425b677a | 122 | static I2C_HandleTypeDef hI2cExtHandler = {0}; |
ngtkien | 0:fc80425b677a | 123 | |
ngtkien | 0:fc80425b677a | 124 | /** |
ngtkien | 0:fc80425b677a | 125 | * @} |
ngtkien | 0:fc80425b677a | 126 | */ |
ngtkien | 0:fc80425b677a | 127 | |
ngtkien | 0:fc80425b677a | 128 | /** @defgroup STM32746G_DISCOVERY_LOW_LEVEL_Private_FunctionPrototypes STM32746G_DISCOVERY_LOW_LEVEL Private Function Prototypes |
ngtkien | 0:fc80425b677a | 129 | * @{ |
ngtkien | 0:fc80425b677a | 130 | */ |
ngtkien | 0:fc80425b677a | 131 | static void I2Cx_MspInit(I2C_HandleTypeDef *i2c_handler); |
ngtkien | 0:fc80425b677a | 132 | static void I2Cx_Init(I2C_HandleTypeDef *i2c_handler); |
ngtkien | 0:fc80425b677a | 133 | |
ngtkien | 0:fc80425b677a | 134 | static HAL_StatusTypeDef I2Cx_ReadMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length); |
ngtkien | 0:fc80425b677a | 135 | static HAL_StatusTypeDef I2Cx_WriteMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length); |
ngtkien | 0:fc80425b677a | 136 | static HAL_StatusTypeDef I2Cx_IsDeviceReady(I2C_HandleTypeDef *i2c_handler, uint16_t DevAddress, uint32_t Trials); |
ngtkien | 0:fc80425b677a | 137 | static void I2Cx_Error(I2C_HandleTypeDef *i2c_handler, uint8_t Addr); |
ngtkien | 0:fc80425b677a | 138 | |
ngtkien | 0:fc80425b677a | 139 | /* AUDIO IO functions */ |
ngtkien | 0:fc80425b677a | 140 | void AUDIO_IO_Init(void); |
ngtkien | 0:fc80425b677a | 141 | void AUDIO_IO_DeInit(void); |
ngtkien | 0:fc80425b677a | 142 | void AUDIO_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value); |
ngtkien | 0:fc80425b677a | 143 | uint16_t AUDIO_IO_Read(uint8_t Addr, uint16_t Reg); |
ngtkien | 0:fc80425b677a | 144 | void AUDIO_IO_Delay(uint32_t Delay); |
ngtkien | 0:fc80425b677a | 145 | |
ngtkien | 0:fc80425b677a | 146 | /* TOUCHSCREEN IO functions */ |
ngtkien | 0:fc80425b677a | 147 | void TS_IO_Init(void); |
ngtkien | 0:fc80425b677a | 148 | void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value); |
ngtkien | 0:fc80425b677a | 149 | uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg); |
ngtkien | 0:fc80425b677a | 150 | void TS_IO_Delay(uint32_t Delay); |
ngtkien | 0:fc80425b677a | 151 | |
ngtkien | 0:fc80425b677a | 152 | /* CAMERA IO functions */ |
ngtkien | 0:fc80425b677a | 153 | void CAMERA_IO_Init(void); |
ngtkien | 0:fc80425b677a | 154 | void CAMERA_Delay(uint32_t Delay); |
ngtkien | 0:fc80425b677a | 155 | void CAMERA_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value); |
ngtkien | 0:fc80425b677a | 156 | uint8_t CAMERA_IO_Read(uint8_t Addr, uint8_t Reg); |
ngtkien | 0:fc80425b677a | 157 | |
ngtkien | 0:fc80425b677a | 158 | /* I2C EEPROM IO function */ |
ngtkien | 0:fc80425b677a | 159 | void EEPROM_IO_Init(void); |
ngtkien | 0:fc80425b677a | 160 | HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize); |
ngtkien | 0:fc80425b677a | 161 | HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize); |
ngtkien | 0:fc80425b677a | 162 | HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials); |
ngtkien | 0:fc80425b677a | 163 | /** |
ngtkien | 0:fc80425b677a | 164 | * @} |
ngtkien | 0:fc80425b677a | 165 | */ |
ngtkien | 0:fc80425b677a | 166 | |
ngtkien | 0:fc80425b677a | 167 | /** @defgroup STM32746G_DISCOVERY_LOW_LEVEL_Exported_Functions STM32746G_DISCOVERY_LOW_LEVELSTM32746G_DISCOVERY_LOW_LEVEL Exported Functions |
ngtkien | 0:fc80425b677a | 168 | * @{ |
ngtkien | 0:fc80425b677a | 169 | */ |
ngtkien | 0:fc80425b677a | 170 | |
ngtkien | 0:fc80425b677a | 171 | /** |
ngtkien | 0:fc80425b677a | 172 | * @brief This method returns the STM32746G DISCOVERY BSP Driver revision |
ngtkien | 0:fc80425b677a | 173 | * @retval version: 0xXYZR (8bits for each decimal, R for RC) |
ngtkien | 0:fc80425b677a | 174 | */ |
ngtkien | 0:fc80425b677a | 175 | uint32_t BSP_GetVersion(void) |
ngtkien | 0:fc80425b677a | 176 | { |
ngtkien | 0:fc80425b677a | 177 | return __STM32746G_DISCO_BSP_VERSION; |
ngtkien | 0:fc80425b677a | 178 | } |
ngtkien | 0:fc80425b677a | 179 | |
ngtkien | 0:fc80425b677a | 180 | /** |
ngtkien | 0:fc80425b677a | 181 | * @brief Configures LED on GPIO. |
ngtkien | 0:fc80425b677a | 182 | * @param Led: LED to be configured. |
ngtkien | 0:fc80425b677a | 183 | * This parameter can be one of the following values: |
ngtkien | 0:fc80425b677a | 184 | * @arg LED1 |
ngtkien | 0:fc80425b677a | 185 | * @retval None |
ngtkien | 0:fc80425b677a | 186 | */ |
ngtkien | 0:fc80425b677a | 187 | void BSP_LED_Init(Led_TypeDef Led) |
ngtkien | 0:fc80425b677a | 188 | { |
ngtkien | 0:fc80425b677a | 189 | GPIO_InitTypeDef gpio_init_structure; |
ngtkien | 0:fc80425b677a | 190 | GPIO_TypeDef* gpio_led; |
ngtkien | 0:fc80425b677a | 191 | |
ngtkien | 0:fc80425b677a | 192 | if (Led == DISCO_LED1) // MBED |
ngtkien | 0:fc80425b677a | 193 | { |
ngtkien | 0:fc80425b677a | 194 | gpio_led = LED1_GPIO_PORT; |
ngtkien | 0:fc80425b677a | 195 | /* Enable the GPIO_LED clock */ |
ngtkien | 0:fc80425b677a | 196 | LED1_GPIO_CLK_ENABLE(); |
ngtkien | 0:fc80425b677a | 197 | |
ngtkien | 0:fc80425b677a | 198 | /* Configure the GPIO_LED pin */ |
ngtkien | 0:fc80425b677a | 199 | gpio_init_structure.Pin = GPIO_PIN[Led]; |
ngtkien | 0:fc80425b677a | 200 | gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP; |
ngtkien | 0:fc80425b677a | 201 | gpio_init_structure.Pull = GPIO_PULLUP; |
ngtkien | 0:fc80425b677a | 202 | gpio_init_structure.Speed = GPIO_SPEED_HIGH; |
ngtkien | 0:fc80425b677a | 203 | |
ngtkien | 0:fc80425b677a | 204 | HAL_GPIO_Init(gpio_led, &gpio_init_structure); |
ngtkien | 0:fc80425b677a | 205 | |
ngtkien | 0:fc80425b677a | 206 | /* By default, turn off LED */ |
ngtkien | 0:fc80425b677a | 207 | HAL_GPIO_WritePin(gpio_led, GPIO_PIN[Led], GPIO_PIN_RESET); |
ngtkien | 0:fc80425b677a | 208 | } |
ngtkien | 0:fc80425b677a | 209 | } |
ngtkien | 0:fc80425b677a | 210 | |
ngtkien | 0:fc80425b677a | 211 | /** |
ngtkien | 0:fc80425b677a | 212 | * @brief DeInit LEDs. |
ngtkien | 0:fc80425b677a | 213 | * @param Led: LED to be configured. |
ngtkien | 0:fc80425b677a | 214 | * This parameter can be one of the following values: |
ngtkien | 0:fc80425b677a | 215 | * @arg LED1 |
ngtkien | 0:fc80425b677a | 216 | * @note Led DeInit does not disable the GPIO clock |
ngtkien | 0:fc80425b677a | 217 | * @retval None |
ngtkien | 0:fc80425b677a | 218 | */ |
ngtkien | 0:fc80425b677a | 219 | void BSP_LED_DeInit(Led_TypeDef Led) |
ngtkien | 0:fc80425b677a | 220 | { |
ngtkien | 0:fc80425b677a | 221 | GPIO_InitTypeDef gpio_init_structure; |
ngtkien | 0:fc80425b677a | 222 | GPIO_TypeDef* gpio_led; |
ngtkien | 0:fc80425b677a | 223 | |
ngtkien | 0:fc80425b677a | 224 | if (Led == DISCO_LED1) // MBED |
ngtkien | 0:fc80425b677a | 225 | { |
ngtkien | 0:fc80425b677a | 226 | gpio_led = LED1_GPIO_PORT; |
ngtkien | 0:fc80425b677a | 227 | /* Turn off LED */ |
ngtkien | 0:fc80425b677a | 228 | HAL_GPIO_WritePin(gpio_led, GPIO_PIN[Led], GPIO_PIN_RESET); |
ngtkien | 0:fc80425b677a | 229 | /* Configure the GPIO_LED pin */ |
ngtkien | 0:fc80425b677a | 230 | gpio_init_structure.Pin = GPIO_PIN[Led]; |
ngtkien | 0:fc80425b677a | 231 | HAL_GPIO_DeInit(gpio_led, gpio_init_structure.Pin); |
ngtkien | 0:fc80425b677a | 232 | } |
ngtkien | 0:fc80425b677a | 233 | } |
ngtkien | 0:fc80425b677a | 234 | |
ngtkien | 0:fc80425b677a | 235 | /** |
ngtkien | 0:fc80425b677a | 236 | * @brief Turns selected LED On. |
ngtkien | 0:fc80425b677a | 237 | * @param Led: LED to be set on |
ngtkien | 0:fc80425b677a | 238 | * This parameter can be one of the following values: |
ngtkien | 0:fc80425b677a | 239 | * @arg LED1 |
ngtkien | 0:fc80425b677a | 240 | * @retval None |
ngtkien | 0:fc80425b677a | 241 | */ |
ngtkien | 0:fc80425b677a | 242 | void BSP_LED_On(Led_TypeDef Led) |
ngtkien | 0:fc80425b677a | 243 | { |
ngtkien | 0:fc80425b677a | 244 | GPIO_TypeDef* gpio_led; |
ngtkien | 0:fc80425b677a | 245 | |
ngtkien | 0:fc80425b677a | 246 | if (Led == DISCO_LED1) /* Switch On LED connected to GPIO */ // MBED |
ngtkien | 0:fc80425b677a | 247 | { |
ngtkien | 0:fc80425b677a | 248 | gpio_led = LED1_GPIO_PORT; |
ngtkien | 0:fc80425b677a | 249 | HAL_GPIO_WritePin(gpio_led, GPIO_PIN[Led], GPIO_PIN_SET); |
ngtkien | 0:fc80425b677a | 250 | } |
ngtkien | 0:fc80425b677a | 251 | } |
ngtkien | 0:fc80425b677a | 252 | |
ngtkien | 0:fc80425b677a | 253 | /** |
ngtkien | 0:fc80425b677a | 254 | * @brief Turns selected LED Off. |
ngtkien | 0:fc80425b677a | 255 | * @param Led: LED to be set off |
ngtkien | 0:fc80425b677a | 256 | * This parameter can be one of the following values: |
ngtkien | 0:fc80425b677a | 257 | * @arg LED1 |
ngtkien | 0:fc80425b677a | 258 | * @retval None |
ngtkien | 0:fc80425b677a | 259 | */ |
ngtkien | 0:fc80425b677a | 260 | void BSP_LED_Off(Led_TypeDef Led) |
ngtkien | 0:fc80425b677a | 261 | { |
ngtkien | 0:fc80425b677a | 262 | GPIO_TypeDef* gpio_led; |
ngtkien | 0:fc80425b677a | 263 | |
ngtkien | 0:fc80425b677a | 264 | if (Led == DISCO_LED1) /* Switch Off LED connected to GPIO */ // MBED |
ngtkien | 0:fc80425b677a | 265 | { |
ngtkien | 0:fc80425b677a | 266 | gpio_led = LED1_GPIO_PORT; |
ngtkien | 0:fc80425b677a | 267 | HAL_GPIO_WritePin(gpio_led, GPIO_PIN[Led], GPIO_PIN_RESET); |
ngtkien | 0:fc80425b677a | 268 | } |
ngtkien | 0:fc80425b677a | 269 | } |
ngtkien | 0:fc80425b677a | 270 | |
ngtkien | 0:fc80425b677a | 271 | /** |
ngtkien | 0:fc80425b677a | 272 | * @brief Toggles the selected LED. |
ngtkien | 0:fc80425b677a | 273 | * @param Led: LED to be toggled |
ngtkien | 0:fc80425b677a | 274 | * This parameter can be one of the following values: |
ngtkien | 0:fc80425b677a | 275 | * @arg LED1 |
ngtkien | 0:fc80425b677a | 276 | * @retval None |
ngtkien | 0:fc80425b677a | 277 | */ |
ngtkien | 0:fc80425b677a | 278 | void BSP_LED_Toggle(Led_TypeDef Led) |
ngtkien | 0:fc80425b677a | 279 | { |
ngtkien | 0:fc80425b677a | 280 | GPIO_TypeDef* gpio_led; |
ngtkien | 0:fc80425b677a | 281 | |
ngtkien | 0:fc80425b677a | 282 | if (Led == DISCO_LED1) /* Toggle LED connected to GPIO */ // MBED |
ngtkien | 0:fc80425b677a | 283 | { |
ngtkien | 0:fc80425b677a | 284 | gpio_led = LED1_GPIO_PORT; |
ngtkien | 0:fc80425b677a | 285 | HAL_GPIO_TogglePin(gpio_led, GPIO_PIN[Led]); |
ngtkien | 0:fc80425b677a | 286 | } |
ngtkien | 0:fc80425b677a | 287 | } |
ngtkien | 0:fc80425b677a | 288 | |
ngtkien | 0:fc80425b677a | 289 | /** |
ngtkien | 0:fc80425b677a | 290 | * @brief Configures button GPIO and EXTI Line. |
ngtkien | 0:fc80425b677a | 291 | * @param Button: Button to be configured |
ngtkien | 0:fc80425b677a | 292 | * This parameter can be one of the following values: |
ngtkien | 0:fc80425b677a | 293 | * @arg BUTTON_WAKEUP: Wakeup Push Button |
ngtkien | 0:fc80425b677a | 294 | * @arg BUTTON_TAMPER: Tamper Push Button |
ngtkien | 0:fc80425b677a | 295 | * @arg BUTTON_KEY: Key Push Button |
ngtkien | 0:fc80425b677a | 296 | * @param ButtonMode: Button mode |
ngtkien | 0:fc80425b677a | 297 | * This parameter can be one of the following values: |
ngtkien | 0:fc80425b677a | 298 | * @arg BUTTON_MODE_GPIO: Button will be used as simple IO |
ngtkien | 0:fc80425b677a | 299 | * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line |
ngtkien | 0:fc80425b677a | 300 | * with interrupt generation capability |
ngtkien | 0:fc80425b677a | 301 | * @note On STM32746G-Discovery board, the three buttons (Wakeup, Tamper and key buttons) |
ngtkien | 0:fc80425b677a | 302 | * are mapped on the same push button named "User" |
ngtkien | 0:fc80425b677a | 303 | * on the board serigraphy. |
ngtkien | 0:fc80425b677a | 304 | * @retval None |
ngtkien | 0:fc80425b677a | 305 | */ |
ngtkien | 0:fc80425b677a | 306 | void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode) |
ngtkien | 0:fc80425b677a | 307 | { |
ngtkien | 0:fc80425b677a | 308 | GPIO_InitTypeDef gpio_init_structure; |
ngtkien | 0:fc80425b677a | 309 | |
ngtkien | 0:fc80425b677a | 310 | /* Enable the BUTTON clock */ |
ngtkien | 0:fc80425b677a | 311 | BUTTONx_GPIO_CLK_ENABLE(Button); |
ngtkien | 0:fc80425b677a | 312 | |
ngtkien | 0:fc80425b677a | 313 | if(ButtonMode == BUTTON_MODE_GPIO) |
ngtkien | 0:fc80425b677a | 314 | { |
ngtkien | 0:fc80425b677a | 315 | /* Configure Button pin as input */ |
ngtkien | 0:fc80425b677a | 316 | gpio_init_structure.Pin = BUTTON_PIN[Button]; |
ngtkien | 0:fc80425b677a | 317 | gpio_init_structure.Mode = GPIO_MODE_INPUT; |
ngtkien | 0:fc80425b677a | 318 | gpio_init_structure.Pull = GPIO_NOPULL; |
ngtkien | 0:fc80425b677a | 319 | gpio_init_structure.Speed = GPIO_SPEED_FAST; |
ngtkien | 0:fc80425b677a | 320 | HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure); |
ngtkien | 0:fc80425b677a | 321 | } |
ngtkien | 0:fc80425b677a | 322 | |
ngtkien | 0:fc80425b677a | 323 | if(ButtonMode == BUTTON_MODE_EXTI) |
ngtkien | 0:fc80425b677a | 324 | { |
ngtkien | 0:fc80425b677a | 325 | /* Configure Button pin as input with External interrupt */ |
ngtkien | 0:fc80425b677a | 326 | gpio_init_structure.Pin = BUTTON_PIN[Button]; |
ngtkien | 0:fc80425b677a | 327 | gpio_init_structure.Pull = GPIO_NOPULL; |
ngtkien | 0:fc80425b677a | 328 | gpio_init_structure.Speed = GPIO_SPEED_FAST; |
ngtkien | 0:fc80425b677a | 329 | |
ngtkien | 0:fc80425b677a | 330 | if(Button != BUTTON_WAKEUP) |
ngtkien | 0:fc80425b677a | 331 | { |
ngtkien | 0:fc80425b677a | 332 | gpio_init_structure.Mode = GPIO_MODE_IT_FALLING; |
ngtkien | 0:fc80425b677a | 333 | } |
ngtkien | 0:fc80425b677a | 334 | else |
ngtkien | 0:fc80425b677a | 335 | { |
ngtkien | 0:fc80425b677a | 336 | gpio_init_structure.Mode = GPIO_MODE_IT_RISING; |
ngtkien | 0:fc80425b677a | 337 | } |
ngtkien | 0:fc80425b677a | 338 | |
ngtkien | 0:fc80425b677a | 339 | HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure); |
ngtkien | 0:fc80425b677a | 340 | |
ngtkien | 0:fc80425b677a | 341 | /* Enable and set Button EXTI Interrupt to the lowest priority */ |
ngtkien | 0:fc80425b677a | 342 | HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00); |
ngtkien | 0:fc80425b677a | 343 | HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button])); |
ngtkien | 0:fc80425b677a | 344 | } |
ngtkien | 0:fc80425b677a | 345 | } |
ngtkien | 0:fc80425b677a | 346 | |
ngtkien | 0:fc80425b677a | 347 | /** |
ngtkien | 0:fc80425b677a | 348 | * @brief Push Button DeInit. |
ngtkien | 0:fc80425b677a | 349 | * @param Button: Button to be configured |
ngtkien | 0:fc80425b677a | 350 | * This parameter can be one of the following values: |
ngtkien | 0:fc80425b677a | 351 | * @arg BUTTON_WAKEUP: Wakeup Push Button |
ngtkien | 0:fc80425b677a | 352 | * @arg BUTTON_TAMPER: Tamper Push Button |
ngtkien | 0:fc80425b677a | 353 | * @arg BUTTON_KEY: Key Push Button |
ngtkien | 0:fc80425b677a | 354 | * @note On STM32746G-Discovery board, the three buttons (Wakeup, Tamper and key buttons) |
ngtkien | 0:fc80425b677a | 355 | * are mapped on the same push button named "User" |
ngtkien | 0:fc80425b677a | 356 | * on the board serigraphy. |
ngtkien | 0:fc80425b677a | 357 | * @note PB DeInit does not disable the GPIO clock |
ngtkien | 0:fc80425b677a | 358 | * @retval None |
ngtkien | 0:fc80425b677a | 359 | */ |
ngtkien | 0:fc80425b677a | 360 | void BSP_PB_DeInit(Button_TypeDef Button) |
ngtkien | 0:fc80425b677a | 361 | { |
ngtkien | 0:fc80425b677a | 362 | GPIO_InitTypeDef gpio_init_structure; |
ngtkien | 0:fc80425b677a | 363 | |
ngtkien | 0:fc80425b677a | 364 | gpio_init_structure.Pin = BUTTON_PIN[Button]; |
ngtkien | 0:fc80425b677a | 365 | HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button])); |
ngtkien | 0:fc80425b677a | 366 | HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin); |
ngtkien | 0:fc80425b677a | 367 | } |
ngtkien | 0:fc80425b677a | 368 | |
ngtkien | 0:fc80425b677a | 369 | |
ngtkien | 0:fc80425b677a | 370 | /** |
ngtkien | 0:fc80425b677a | 371 | * @brief Returns the selected button state. |
ngtkien | 0:fc80425b677a | 372 | * @param Button: Button to be checked |
ngtkien | 0:fc80425b677a | 373 | * This parameter can be one of the following values: |
ngtkien | 0:fc80425b677a | 374 | * @arg BUTTON_WAKEUP: Wakeup Push Button |
ngtkien | 0:fc80425b677a | 375 | * @arg BUTTON_TAMPER: Tamper Push Button |
ngtkien | 0:fc80425b677a | 376 | * @arg BUTTON_KEY: Key Push Button |
ngtkien | 0:fc80425b677a | 377 | * @note On STM32746G-Discovery board, the three buttons (Wakeup, Tamper and key buttons) |
ngtkien | 0:fc80425b677a | 378 | * are mapped on the same push button named "User" |
ngtkien | 0:fc80425b677a | 379 | * on the board serigraphy. |
ngtkien | 0:fc80425b677a | 380 | * @retval The Button GPIO pin value |
ngtkien | 0:fc80425b677a | 381 | */ |
ngtkien | 0:fc80425b677a | 382 | uint32_t BSP_PB_GetState(Button_TypeDef Button) |
ngtkien | 0:fc80425b677a | 383 | { |
ngtkien | 0:fc80425b677a | 384 | return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]); |
ngtkien | 0:fc80425b677a | 385 | } |
ngtkien | 0:fc80425b677a | 386 | |
ngtkien | 0:fc80425b677a | 387 | /** |
ngtkien | 0:fc80425b677a | 388 | * @brief Configures COM port. |
ngtkien | 0:fc80425b677a | 389 | * @param COM: COM port to be configured. |
ngtkien | 0:fc80425b677a | 390 | * This parameter can be one of the following values: |
ngtkien | 0:fc80425b677a | 391 | * @arg COM1 |
ngtkien | 0:fc80425b677a | 392 | * @arg COM2 |
ngtkien | 0:fc80425b677a | 393 | * @param huart: Pointer to a UART_HandleTypeDef structure that contains the |
ngtkien | 0:fc80425b677a | 394 | * configuration information for the specified USART peripheral. |
ngtkien | 0:fc80425b677a | 395 | * @retval None |
ngtkien | 0:fc80425b677a | 396 | */ |
ngtkien | 0:fc80425b677a | 397 | void BSP_COM_Init(COM_TypeDef COM, UART_HandleTypeDef *huart) |
ngtkien | 0:fc80425b677a | 398 | { |
ngtkien | 0:fc80425b677a | 399 | GPIO_InitTypeDef gpio_init_structure; |
ngtkien | 0:fc80425b677a | 400 | |
ngtkien | 0:fc80425b677a | 401 | /* Enable GPIO clock */ |
ngtkien | 0:fc80425b677a | 402 | DISCOVERY_COMx_TX_GPIO_CLK_ENABLE(COM); |
ngtkien | 0:fc80425b677a | 403 | DISCOVERY_COMx_RX_GPIO_CLK_ENABLE(COM); |
ngtkien | 0:fc80425b677a | 404 | |
ngtkien | 0:fc80425b677a | 405 | /* Enable USART clock */ |
ngtkien | 0:fc80425b677a | 406 | DISCOVERY_COMx_CLK_ENABLE(COM); |
ngtkien | 0:fc80425b677a | 407 | |
ngtkien | 0:fc80425b677a | 408 | /* Configure USART Tx as alternate function */ |
ngtkien | 0:fc80425b677a | 409 | gpio_init_structure.Pin = COM_TX_PIN[COM]; |
ngtkien | 0:fc80425b677a | 410 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
ngtkien | 0:fc80425b677a | 411 | gpio_init_structure.Speed = GPIO_SPEED_FAST; |
ngtkien | 0:fc80425b677a | 412 | gpio_init_structure.Pull = GPIO_PULLUP; |
ngtkien | 0:fc80425b677a | 413 | gpio_init_structure.Alternate = COM_TX_AF[COM]; |
ngtkien | 0:fc80425b677a | 414 | HAL_GPIO_Init(COM_TX_PORT[COM], &gpio_init_structure); |
ngtkien | 0:fc80425b677a | 415 | |
ngtkien | 0:fc80425b677a | 416 | /* Configure USART Rx as alternate function */ |
ngtkien | 0:fc80425b677a | 417 | gpio_init_structure.Pin = COM_RX_PIN[COM]; |
ngtkien | 0:fc80425b677a | 418 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
ngtkien | 0:fc80425b677a | 419 | gpio_init_structure.Alternate = COM_RX_AF[COM]; |
ngtkien | 0:fc80425b677a | 420 | HAL_GPIO_Init(COM_RX_PORT[COM], &gpio_init_structure); |
ngtkien | 0:fc80425b677a | 421 | |
ngtkien | 0:fc80425b677a | 422 | /* USART configuration */ |
ngtkien | 0:fc80425b677a | 423 | huart->Instance = COM_USART[COM]; |
ngtkien | 0:fc80425b677a | 424 | HAL_UART_Init(huart); |
ngtkien | 0:fc80425b677a | 425 | } |
ngtkien | 0:fc80425b677a | 426 | |
ngtkien | 0:fc80425b677a | 427 | /** |
ngtkien | 0:fc80425b677a | 428 | * @brief DeInit COM port. |
ngtkien | 0:fc80425b677a | 429 | * @param COM: COM port to be configured. |
ngtkien | 0:fc80425b677a | 430 | * This parameter can be one of the following values: |
ngtkien | 0:fc80425b677a | 431 | * @arg COM1 |
ngtkien | 0:fc80425b677a | 432 | * @arg COM2 |
ngtkien | 0:fc80425b677a | 433 | * @param huart: Pointer to a UART_HandleTypeDef structure that contains the |
ngtkien | 0:fc80425b677a | 434 | * configuration information for the specified USART peripheral. |
ngtkien | 0:fc80425b677a | 435 | * @retval None |
ngtkien | 0:fc80425b677a | 436 | */ |
ngtkien | 0:fc80425b677a | 437 | void BSP_COM_DeInit(COM_TypeDef COM, UART_HandleTypeDef *huart) |
ngtkien | 0:fc80425b677a | 438 | { |
ngtkien | 0:fc80425b677a | 439 | /* USART configuration */ |
ngtkien | 0:fc80425b677a | 440 | huart->Instance = COM_USART[COM]; |
ngtkien | 0:fc80425b677a | 441 | HAL_UART_DeInit(huart); |
ngtkien | 0:fc80425b677a | 442 | |
ngtkien | 0:fc80425b677a | 443 | /* Enable USART clock */ |
ngtkien | 0:fc80425b677a | 444 | DISCOVERY_COMx_CLK_DISABLE(COM); |
ngtkien | 0:fc80425b677a | 445 | |
ngtkien | 0:fc80425b677a | 446 | /* DeInit GPIO pins can be done in the application |
ngtkien | 0:fc80425b677a | 447 | (by surcharging this __weak function) */ |
ngtkien | 0:fc80425b677a | 448 | |
ngtkien | 0:fc80425b677a | 449 | /* GPIO pins clock, DMA clock can be shut down in the application |
ngtkien | 0:fc80425b677a | 450 | by surcharging this __weak function */ |
ngtkien | 0:fc80425b677a | 451 | } |
ngtkien | 0:fc80425b677a | 452 | |
ngtkien | 0:fc80425b677a | 453 | /******************************************************************************* |
ngtkien | 0:fc80425b677a | 454 | BUS OPERATIONS |
ngtkien | 0:fc80425b677a | 455 | *******************************************************************************/ |
ngtkien | 0:fc80425b677a | 456 | |
ngtkien | 0:fc80425b677a | 457 | /******************************* I2C Routines *********************************/ |
ngtkien | 0:fc80425b677a | 458 | /** |
ngtkien | 0:fc80425b677a | 459 | * @brief Initializes I2C MSP. |
ngtkien | 0:fc80425b677a | 460 | * @param i2c_handler : I2C handler |
ngtkien | 0:fc80425b677a | 461 | * @retval None |
ngtkien | 0:fc80425b677a | 462 | */ |
ngtkien | 0:fc80425b677a | 463 | static void I2Cx_MspInit(I2C_HandleTypeDef *i2c_handler) |
ngtkien | 0:fc80425b677a | 464 | { |
ngtkien | 0:fc80425b677a | 465 | GPIO_InitTypeDef gpio_init_structure; |
ngtkien | 0:fc80425b677a | 466 | |
ngtkien | 0:fc80425b677a | 467 | if (i2c_handler == (I2C_HandleTypeDef*)(&hI2cAudioHandler)) |
ngtkien | 0:fc80425b677a | 468 | { |
ngtkien | 0:fc80425b677a | 469 | /* AUDIO and LCD I2C MSP init */ |
ngtkien | 0:fc80425b677a | 470 | |
ngtkien | 0:fc80425b677a | 471 | /*** Configure the GPIOs ***/ |
ngtkien | 0:fc80425b677a | 472 | /* Enable GPIO clock */ |
ngtkien | 0:fc80425b677a | 473 | DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_CLK_ENABLE(); |
ngtkien | 0:fc80425b677a | 474 | |
ngtkien | 0:fc80425b677a | 475 | /* Configure I2C Tx as alternate function */ |
ngtkien | 0:fc80425b677a | 476 | gpio_init_structure.Pin = DISCOVERY_AUDIO_I2Cx_SCL_PIN; |
ngtkien | 0:fc80425b677a | 477 | gpio_init_structure.Mode = GPIO_MODE_AF_OD; |
ngtkien | 0:fc80425b677a | 478 | gpio_init_structure.Pull = GPIO_NOPULL; |
ngtkien | 0:fc80425b677a | 479 | gpio_init_structure.Speed = GPIO_SPEED_FAST; |
ngtkien | 0:fc80425b677a | 480 | gpio_init_structure.Alternate = DISCOVERY_AUDIO_I2Cx_SCL_SDA_AF; |
ngtkien | 0:fc80425b677a | 481 | HAL_GPIO_Init(DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure); |
ngtkien | 0:fc80425b677a | 482 | |
ngtkien | 0:fc80425b677a | 483 | /* Configure I2C Rx as alternate function */ |
ngtkien | 0:fc80425b677a | 484 | gpio_init_structure.Pin = DISCOVERY_AUDIO_I2Cx_SDA_PIN; |
ngtkien | 0:fc80425b677a | 485 | HAL_GPIO_Init(DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure); |
ngtkien | 0:fc80425b677a | 486 | |
ngtkien | 0:fc80425b677a | 487 | /*** Configure the I2C peripheral ***/ |
ngtkien | 0:fc80425b677a | 488 | /* Enable I2C clock */ |
ngtkien | 0:fc80425b677a | 489 | DISCOVERY_AUDIO_I2Cx_CLK_ENABLE(); |
ngtkien | 0:fc80425b677a | 490 | |
ngtkien | 0:fc80425b677a | 491 | /* Force the I2C peripheral clock reset */ |
ngtkien | 0:fc80425b677a | 492 | DISCOVERY_AUDIO_I2Cx_FORCE_RESET(); |
ngtkien | 0:fc80425b677a | 493 | |
ngtkien | 0:fc80425b677a | 494 | /* Release the I2C peripheral clock reset */ |
ngtkien | 0:fc80425b677a | 495 | DISCOVERY_AUDIO_I2Cx_RELEASE_RESET(); |
ngtkien | 0:fc80425b677a | 496 | |
ngtkien | 0:fc80425b677a | 497 | /* Enable and set I2Cx Interrupt to a lower priority */ |
ngtkien | 0:fc80425b677a | 498 | HAL_NVIC_SetPriority(DISCOVERY_AUDIO_I2Cx_EV_IRQn, 0x0F, 0); |
ngtkien | 0:fc80425b677a | 499 | HAL_NVIC_EnableIRQ(DISCOVERY_AUDIO_I2Cx_EV_IRQn); |
ngtkien | 0:fc80425b677a | 500 | |
ngtkien | 0:fc80425b677a | 501 | /* Enable and set I2Cx Interrupt to a lower priority */ |
ngtkien | 0:fc80425b677a | 502 | HAL_NVIC_SetPriority(DISCOVERY_AUDIO_I2Cx_ER_IRQn, 0x0F, 0); |
ngtkien | 0:fc80425b677a | 503 | HAL_NVIC_EnableIRQ(DISCOVERY_AUDIO_I2Cx_ER_IRQn); |
ngtkien | 0:fc80425b677a | 504 | } |
ngtkien | 0:fc80425b677a | 505 | else |
ngtkien | 0:fc80425b677a | 506 | { |
ngtkien | 0:fc80425b677a | 507 | /* External, camera and Arduino connector I2C MSP init */ |
ngtkien | 0:fc80425b677a | 508 | |
ngtkien | 0:fc80425b677a | 509 | /*** Configure the GPIOs ***/ |
ngtkien | 0:fc80425b677a | 510 | /* Enable GPIO clock */ |
ngtkien | 0:fc80425b677a | 511 | DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_CLK_ENABLE(); |
ngtkien | 0:fc80425b677a | 512 | |
ngtkien | 0:fc80425b677a | 513 | /* Configure I2C Tx as alternate function */ |
ngtkien | 0:fc80425b677a | 514 | gpio_init_structure.Pin = DISCOVERY_EXT_I2Cx_SCL_PIN; |
ngtkien | 0:fc80425b677a | 515 | gpio_init_structure.Mode = GPIO_MODE_AF_OD; |
ngtkien | 0:fc80425b677a | 516 | gpio_init_structure.Pull = GPIO_NOPULL; |
ngtkien | 0:fc80425b677a | 517 | gpio_init_structure.Speed = GPIO_SPEED_FAST; |
ngtkien | 0:fc80425b677a | 518 | gpio_init_structure.Alternate = DISCOVERY_EXT_I2Cx_SCL_SDA_AF; |
ngtkien | 0:fc80425b677a | 519 | HAL_GPIO_Init(DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure); |
ngtkien | 0:fc80425b677a | 520 | |
ngtkien | 0:fc80425b677a | 521 | /* Configure I2C Rx as alternate function */ |
ngtkien | 0:fc80425b677a | 522 | gpio_init_structure.Pin = DISCOVERY_EXT_I2Cx_SDA_PIN; |
ngtkien | 0:fc80425b677a | 523 | HAL_GPIO_Init(DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure); |
ngtkien | 0:fc80425b677a | 524 | |
ngtkien | 0:fc80425b677a | 525 | /*** Configure the I2C peripheral ***/ |
ngtkien | 0:fc80425b677a | 526 | /* Enable I2C clock */ |
ngtkien | 0:fc80425b677a | 527 | DISCOVERY_EXT_I2Cx_CLK_ENABLE(); |
ngtkien | 0:fc80425b677a | 528 | |
ngtkien | 0:fc80425b677a | 529 | /* Force the I2C peripheral clock reset */ |
ngtkien | 0:fc80425b677a | 530 | DISCOVERY_EXT_I2Cx_FORCE_RESET(); |
ngtkien | 0:fc80425b677a | 531 | |
ngtkien | 0:fc80425b677a | 532 | /* Release the I2C peripheral clock reset */ |
ngtkien | 0:fc80425b677a | 533 | DISCOVERY_EXT_I2Cx_RELEASE_RESET(); |
ngtkien | 0:fc80425b677a | 534 | |
ngtkien | 0:fc80425b677a | 535 | /* Enable and set I2Cx Interrupt to a lower priority */ |
ngtkien | 0:fc80425b677a | 536 | HAL_NVIC_SetPriority(DISCOVERY_EXT_I2Cx_EV_IRQn, 0x0F, 0); |
ngtkien | 0:fc80425b677a | 537 | HAL_NVIC_EnableIRQ(DISCOVERY_EXT_I2Cx_EV_IRQn); |
ngtkien | 0:fc80425b677a | 538 | |
ngtkien | 0:fc80425b677a | 539 | /* Enable and set I2Cx Interrupt to a lower priority */ |
ngtkien | 0:fc80425b677a | 540 | HAL_NVIC_SetPriority(DISCOVERY_EXT_I2Cx_ER_IRQn, 0x0F, 0); |
ngtkien | 0:fc80425b677a | 541 | HAL_NVIC_EnableIRQ(DISCOVERY_EXT_I2Cx_ER_IRQn); |
ngtkien | 0:fc80425b677a | 542 | } |
ngtkien | 0:fc80425b677a | 543 | } |
ngtkien | 0:fc80425b677a | 544 | |
ngtkien | 0:fc80425b677a | 545 | /** |
ngtkien | 0:fc80425b677a | 546 | * @brief Initializes I2C HAL. |
ngtkien | 0:fc80425b677a | 547 | * @param i2c_handler : I2C handler |
ngtkien | 0:fc80425b677a | 548 | * @retval None |
ngtkien | 0:fc80425b677a | 549 | */ |
ngtkien | 0:fc80425b677a | 550 | static void I2Cx_Init(I2C_HandleTypeDef *i2c_handler) |
ngtkien | 0:fc80425b677a | 551 | { |
ngtkien | 0:fc80425b677a | 552 | if(HAL_I2C_GetState(i2c_handler) == HAL_I2C_STATE_RESET) |
ngtkien | 0:fc80425b677a | 553 | { |
ngtkien | 0:fc80425b677a | 554 | if (i2c_handler == (I2C_HandleTypeDef*)(&hI2cAudioHandler)) |
ngtkien | 0:fc80425b677a | 555 | { |
ngtkien | 0:fc80425b677a | 556 | /* Audio and LCD I2C configuration */ |
ngtkien | 0:fc80425b677a | 557 | i2c_handler->Instance = DISCOVERY_AUDIO_I2Cx; |
ngtkien | 0:fc80425b677a | 558 | } |
ngtkien | 0:fc80425b677a | 559 | else |
ngtkien | 0:fc80425b677a | 560 | { |
ngtkien | 0:fc80425b677a | 561 | /* External, camera and Arduino connector I2C configuration */ |
ngtkien | 0:fc80425b677a | 562 | i2c_handler->Instance = DISCOVERY_EXT_I2Cx; |
ngtkien | 0:fc80425b677a | 563 | } |
ngtkien | 0:fc80425b677a | 564 | i2c_handler->Init.Timing = DISCOVERY_I2Cx_TIMING; |
ngtkien | 0:fc80425b677a | 565 | i2c_handler->Init.OwnAddress1 = 0; |
ngtkien | 0:fc80425b677a | 566 | i2c_handler->Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; |
ngtkien | 0:fc80425b677a | 567 | i2c_handler->Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; |
ngtkien | 0:fc80425b677a | 568 | i2c_handler->Init.OwnAddress2 = 0; |
ngtkien | 0:fc80425b677a | 569 | i2c_handler->Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; |
ngtkien | 0:fc80425b677a | 570 | i2c_handler->Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; |
ngtkien | 0:fc80425b677a | 571 | |
ngtkien | 0:fc80425b677a | 572 | /* Init the I2C */ |
ngtkien | 0:fc80425b677a | 573 | I2Cx_MspInit(i2c_handler); |
ngtkien | 0:fc80425b677a | 574 | HAL_I2C_Init(i2c_handler); |
ngtkien | 0:fc80425b677a | 575 | } |
ngtkien | 0:fc80425b677a | 576 | } |
ngtkien | 0:fc80425b677a | 577 | |
ngtkien | 0:fc80425b677a | 578 | /** |
ngtkien | 0:fc80425b677a | 579 | * @brief Reads multiple data. |
ngtkien | 0:fc80425b677a | 580 | * @param i2c_handler : I2C handler |
ngtkien | 0:fc80425b677a | 581 | * @param Addr: I2C address |
ngtkien | 0:fc80425b677a | 582 | * @param Reg: Reg address |
ngtkien | 0:fc80425b677a | 583 | * @param MemAddress: Memory address |
ngtkien | 0:fc80425b677a | 584 | * @param Buffer: Pointer to data buffer |
ngtkien | 0:fc80425b677a | 585 | * @param Length: Length of the data |
ngtkien | 0:fc80425b677a | 586 | * @retval Number of read data |
ngtkien | 0:fc80425b677a | 587 | */ |
ngtkien | 0:fc80425b677a | 588 | static HAL_StatusTypeDef I2Cx_ReadMultiple(I2C_HandleTypeDef *i2c_handler, |
ngtkien | 0:fc80425b677a | 589 | uint8_t Addr, |
ngtkien | 0:fc80425b677a | 590 | uint16_t Reg, |
ngtkien | 0:fc80425b677a | 591 | uint16_t MemAddress, |
ngtkien | 0:fc80425b677a | 592 | uint8_t *Buffer, |
ngtkien | 0:fc80425b677a | 593 | uint16_t Length) |
ngtkien | 0:fc80425b677a | 594 | { |
ngtkien | 0:fc80425b677a | 595 | HAL_StatusTypeDef status = HAL_OK; |
ngtkien | 0:fc80425b677a | 596 | |
ngtkien | 0:fc80425b677a | 597 | status = HAL_I2C_Mem_Read(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000); |
ngtkien | 0:fc80425b677a | 598 | |
ngtkien | 0:fc80425b677a | 599 | /* Check the communication status */ |
ngtkien | 0:fc80425b677a | 600 | if(status != HAL_OK) |
ngtkien | 0:fc80425b677a | 601 | { |
ngtkien | 0:fc80425b677a | 602 | /* I2C error occurred */ |
ngtkien | 0:fc80425b677a | 603 | I2Cx_Error(i2c_handler, Addr); |
ngtkien | 0:fc80425b677a | 604 | } |
ngtkien | 0:fc80425b677a | 605 | return status; |
ngtkien | 0:fc80425b677a | 606 | } |
ngtkien | 0:fc80425b677a | 607 | |
ngtkien | 0:fc80425b677a | 608 | /** |
ngtkien | 0:fc80425b677a | 609 | * @brief Writes a value in a register of the device through BUS in using DMA mode. |
ngtkien | 0:fc80425b677a | 610 | * @param i2c_handler : I2C handler |
ngtkien | 0:fc80425b677a | 611 | * @param Addr: Device address on BUS Bus. |
ngtkien | 0:fc80425b677a | 612 | * @param Reg: The target register address to write |
ngtkien | 0:fc80425b677a | 613 | * @param MemAddress: Memory address |
ngtkien | 0:fc80425b677a | 614 | * @param Buffer: The target register value to be written |
ngtkien | 0:fc80425b677a | 615 | * @param Length: buffer size to be written |
ngtkien | 0:fc80425b677a | 616 | * @retval HAL status |
ngtkien | 0:fc80425b677a | 617 | */ |
ngtkien | 0:fc80425b677a | 618 | static HAL_StatusTypeDef I2Cx_WriteMultiple(I2C_HandleTypeDef *i2c_handler, |
ngtkien | 0:fc80425b677a | 619 | uint8_t Addr, |
ngtkien | 0:fc80425b677a | 620 | uint16_t Reg, |
ngtkien | 0:fc80425b677a | 621 | uint16_t MemAddress, |
ngtkien | 0:fc80425b677a | 622 | uint8_t *Buffer, |
ngtkien | 0:fc80425b677a | 623 | uint16_t Length) |
ngtkien | 0:fc80425b677a | 624 | { |
ngtkien | 0:fc80425b677a | 625 | HAL_StatusTypeDef status = HAL_OK; |
ngtkien | 0:fc80425b677a | 626 | |
ngtkien | 0:fc80425b677a | 627 | status = HAL_I2C_Mem_Write(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000); |
ngtkien | 0:fc80425b677a | 628 | |
ngtkien | 0:fc80425b677a | 629 | /* Check the communication status */ |
ngtkien | 0:fc80425b677a | 630 | if(status != HAL_OK) |
ngtkien | 0:fc80425b677a | 631 | { |
ngtkien | 0:fc80425b677a | 632 | /* Re-Initiaize the I2C Bus */ |
ngtkien | 0:fc80425b677a | 633 | I2Cx_Error(i2c_handler, Addr); |
ngtkien | 0:fc80425b677a | 634 | } |
ngtkien | 0:fc80425b677a | 635 | return status; |
ngtkien | 0:fc80425b677a | 636 | } |
ngtkien | 0:fc80425b677a | 637 | |
ngtkien | 0:fc80425b677a | 638 | /** |
ngtkien | 0:fc80425b677a | 639 | * @brief Checks if target device is ready for communication. |
ngtkien | 0:fc80425b677a | 640 | * @note This function is used with Memory devices |
ngtkien | 0:fc80425b677a | 641 | * @param i2c_handler : I2C handler |
ngtkien | 0:fc80425b677a | 642 | * @param DevAddress: Target device address |
ngtkien | 0:fc80425b677a | 643 | * @param Trials: Number of trials |
ngtkien | 0:fc80425b677a | 644 | * @retval HAL status |
ngtkien | 0:fc80425b677a | 645 | */ |
ngtkien | 0:fc80425b677a | 646 | static HAL_StatusTypeDef I2Cx_IsDeviceReady(I2C_HandleTypeDef *i2c_handler, uint16_t DevAddress, uint32_t Trials) |
ngtkien | 0:fc80425b677a | 647 | { |
ngtkien | 0:fc80425b677a | 648 | return (HAL_I2C_IsDeviceReady(i2c_handler, DevAddress, Trials, 1000)); |
ngtkien | 0:fc80425b677a | 649 | } |
ngtkien | 0:fc80425b677a | 650 | |
ngtkien | 0:fc80425b677a | 651 | /** |
ngtkien | 0:fc80425b677a | 652 | * @brief Manages error callback by re-initializing I2C. |
ngtkien | 0:fc80425b677a | 653 | * @param i2c_handler : I2C handler |
ngtkien | 0:fc80425b677a | 654 | * @param Addr: I2C Address |
ngtkien | 0:fc80425b677a | 655 | * @retval None |
ngtkien | 0:fc80425b677a | 656 | */ |
ngtkien | 0:fc80425b677a | 657 | static void I2Cx_Error(I2C_HandleTypeDef *i2c_handler, uint8_t Addr) |
ngtkien | 0:fc80425b677a | 658 | { |
ngtkien | 0:fc80425b677a | 659 | /* De-initialize the I2C communication bus */ |
ngtkien | 0:fc80425b677a | 660 | HAL_I2C_DeInit(i2c_handler); |
ngtkien | 0:fc80425b677a | 661 | |
ngtkien | 0:fc80425b677a | 662 | /* Re-Initialize the I2C communication bus */ |
ngtkien | 0:fc80425b677a | 663 | I2Cx_Init(i2c_handler); |
ngtkien | 0:fc80425b677a | 664 | } |
ngtkien | 0:fc80425b677a | 665 | |
ngtkien | 0:fc80425b677a | 666 | /******************************************************************************* |
ngtkien | 0:fc80425b677a | 667 | LINK OPERATIONS |
ngtkien | 0:fc80425b677a | 668 | *******************************************************************************/ |
ngtkien | 0:fc80425b677a | 669 | |
ngtkien | 0:fc80425b677a | 670 | /********************************* LINK AUDIO *********************************/ |
ngtkien | 0:fc80425b677a | 671 | |
ngtkien | 0:fc80425b677a | 672 | /** |
ngtkien | 0:fc80425b677a | 673 | * @brief Initializes Audio low level. |
ngtkien | 0:fc80425b677a | 674 | * @retval None |
ngtkien | 0:fc80425b677a | 675 | */ |
ngtkien | 0:fc80425b677a | 676 | void AUDIO_IO_Init(void) |
ngtkien | 0:fc80425b677a | 677 | { |
ngtkien | 0:fc80425b677a | 678 | I2Cx_Init(&hI2cAudioHandler); |
ngtkien | 0:fc80425b677a | 679 | } |
ngtkien | 0:fc80425b677a | 680 | |
ngtkien | 0:fc80425b677a | 681 | /** |
ngtkien | 0:fc80425b677a | 682 | * @brief Deinitializes Audio low level. |
ngtkien | 0:fc80425b677a | 683 | * @retval None |
ngtkien | 0:fc80425b677a | 684 | */ |
ngtkien | 0:fc80425b677a | 685 | void AUDIO_IO_DeInit(void) |
ngtkien | 0:fc80425b677a | 686 | { |
ngtkien | 0:fc80425b677a | 687 | } |
ngtkien | 0:fc80425b677a | 688 | |
ngtkien | 0:fc80425b677a | 689 | /** |
ngtkien | 0:fc80425b677a | 690 | * @brief Writes a single data. |
ngtkien | 0:fc80425b677a | 691 | * @param Addr: I2C address |
ngtkien | 0:fc80425b677a | 692 | * @param Reg: Reg address |
ngtkien | 0:fc80425b677a | 693 | * @param Value: Data to be written |
ngtkien | 0:fc80425b677a | 694 | * @retval None |
ngtkien | 0:fc80425b677a | 695 | */ |
ngtkien | 0:fc80425b677a | 696 | void AUDIO_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value) |
ngtkien | 0:fc80425b677a | 697 | { |
ngtkien | 0:fc80425b677a | 698 | uint16_t tmp = Value; |
ngtkien | 0:fc80425b677a | 699 | |
ngtkien | 0:fc80425b677a | 700 | Value = ((uint16_t)(tmp >> 8) & 0x00FF); |
ngtkien | 0:fc80425b677a | 701 | |
ngtkien | 0:fc80425b677a | 702 | Value |= ((uint16_t)(tmp << 8)& 0xFF00); |
ngtkien | 0:fc80425b677a | 703 | |
ngtkien | 0:fc80425b677a | 704 | I2Cx_WriteMultiple(&hI2cAudioHandler, Addr, Reg, I2C_MEMADD_SIZE_16BIT,(uint8_t*)&Value, 2); |
ngtkien | 0:fc80425b677a | 705 | } |
ngtkien | 0:fc80425b677a | 706 | |
ngtkien | 0:fc80425b677a | 707 | /** |
ngtkien | 0:fc80425b677a | 708 | * @brief Reads a single data. |
ngtkien | 0:fc80425b677a | 709 | * @param Addr: I2C address |
ngtkien | 0:fc80425b677a | 710 | * @param Reg: Reg address |
ngtkien | 0:fc80425b677a | 711 | * @retval Data to be read |
ngtkien | 0:fc80425b677a | 712 | */ |
ngtkien | 0:fc80425b677a | 713 | uint16_t AUDIO_IO_Read(uint8_t Addr, uint16_t Reg) |
ngtkien | 0:fc80425b677a | 714 | { |
ngtkien | 0:fc80425b677a | 715 | uint16_t read_value = 0, tmp = 0; |
ngtkien | 0:fc80425b677a | 716 | |
ngtkien | 0:fc80425b677a | 717 | I2Cx_ReadMultiple(&hI2cAudioHandler, Addr, Reg, I2C_MEMADD_SIZE_16BIT, (uint8_t*)&read_value, 2); |
ngtkien | 0:fc80425b677a | 718 | |
ngtkien | 0:fc80425b677a | 719 | tmp = ((uint16_t)(read_value >> 8) & 0x00FF); |
ngtkien | 0:fc80425b677a | 720 | |
ngtkien | 0:fc80425b677a | 721 | tmp |= ((uint16_t)(read_value << 8)& 0xFF00); |
ngtkien | 0:fc80425b677a | 722 | |
ngtkien | 0:fc80425b677a | 723 | read_value = tmp; |
ngtkien | 0:fc80425b677a | 724 | |
ngtkien | 0:fc80425b677a | 725 | return read_value; |
ngtkien | 0:fc80425b677a | 726 | } |
ngtkien | 0:fc80425b677a | 727 | |
ngtkien | 0:fc80425b677a | 728 | /** |
ngtkien | 0:fc80425b677a | 729 | * @brief AUDIO Codec delay |
ngtkien | 0:fc80425b677a | 730 | * @param Delay: Delay in ms |
ngtkien | 0:fc80425b677a | 731 | * @retval None |
ngtkien | 0:fc80425b677a | 732 | */ |
ngtkien | 0:fc80425b677a | 733 | void AUDIO_IO_Delay(uint32_t Delay) |
ngtkien | 0:fc80425b677a | 734 | { |
ngtkien | 0:fc80425b677a | 735 | //HAL_Delay(Delay); // MBED |
ngtkien | 0:fc80425b677a | 736 | wait_ms(Delay); // MBED |
ngtkien | 0:fc80425b677a | 737 | } |
ngtkien | 0:fc80425b677a | 738 | |
ngtkien | 0:fc80425b677a | 739 | /********************************* LINK CAMERA ********************************/ |
ngtkien | 0:fc80425b677a | 740 | |
ngtkien | 0:fc80425b677a | 741 | /** |
ngtkien | 0:fc80425b677a | 742 | * @brief Initializes Camera low level. |
ngtkien | 0:fc80425b677a | 743 | * @retval None |
ngtkien | 0:fc80425b677a | 744 | */ |
ngtkien | 0:fc80425b677a | 745 | void CAMERA_IO_Init(void) |
ngtkien | 0:fc80425b677a | 746 | { |
ngtkien | 0:fc80425b677a | 747 | I2Cx_Init(&hI2cExtHandler); |
ngtkien | 0:fc80425b677a | 748 | } |
ngtkien | 0:fc80425b677a | 749 | |
ngtkien | 0:fc80425b677a | 750 | /** |
ngtkien | 0:fc80425b677a | 751 | * @brief Camera writes single data. |
ngtkien | 0:fc80425b677a | 752 | * @param Addr: I2C address |
ngtkien | 0:fc80425b677a | 753 | * @param Reg: Register address |
ngtkien | 0:fc80425b677a | 754 | * @param Value: Data to be written |
ngtkien | 0:fc80425b677a | 755 | * @retval None |
ngtkien | 0:fc80425b677a | 756 | */ |
ngtkien | 0:fc80425b677a | 757 | void CAMERA_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value) |
ngtkien | 0:fc80425b677a | 758 | { |
ngtkien | 0:fc80425b677a | 759 | I2Cx_WriteMultiple(&hI2cExtHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT,(uint8_t*)&Value, 1); |
ngtkien | 0:fc80425b677a | 760 | } |
ngtkien | 0:fc80425b677a | 761 | |
ngtkien | 0:fc80425b677a | 762 | /** |
ngtkien | 0:fc80425b677a | 763 | * @brief Camera reads single data. |
ngtkien | 0:fc80425b677a | 764 | * @param Addr: I2C address |
ngtkien | 0:fc80425b677a | 765 | * @param Reg: Register address |
ngtkien | 0:fc80425b677a | 766 | * @retval Read data |
ngtkien | 0:fc80425b677a | 767 | */ |
ngtkien | 0:fc80425b677a | 768 | uint8_t CAMERA_IO_Read(uint8_t Addr, uint8_t Reg) |
ngtkien | 0:fc80425b677a | 769 | { |
ngtkien | 0:fc80425b677a | 770 | uint8_t read_value = 0; |
ngtkien | 0:fc80425b677a | 771 | |
ngtkien | 0:fc80425b677a | 772 | I2Cx_ReadMultiple(&hI2cExtHandler, Addr, Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&read_value, 1); |
ngtkien | 0:fc80425b677a | 773 | |
ngtkien | 0:fc80425b677a | 774 | return read_value; |
ngtkien | 0:fc80425b677a | 775 | } |
ngtkien | 0:fc80425b677a | 776 | |
ngtkien | 0:fc80425b677a | 777 | /** |
ngtkien | 0:fc80425b677a | 778 | * @brief Camera delay |
ngtkien | 0:fc80425b677a | 779 | * @param Delay: Delay in ms |
ngtkien | 0:fc80425b677a | 780 | * @retval None |
ngtkien | 0:fc80425b677a | 781 | */ |
ngtkien | 0:fc80425b677a | 782 | void CAMERA_Delay(uint32_t Delay) |
ngtkien | 0:fc80425b677a | 783 | { |
ngtkien | 0:fc80425b677a | 784 | //HAL_Delay(Delay); // MBED |
ngtkien | 0:fc80425b677a | 785 | wait_ms(Delay); // MBED |
ngtkien | 0:fc80425b677a | 786 | } |
ngtkien | 0:fc80425b677a | 787 | |
ngtkien | 0:fc80425b677a | 788 | /******************************** LINK I2C EEPROM *****************************/ |
ngtkien | 0:fc80425b677a | 789 | |
ngtkien | 0:fc80425b677a | 790 | /** |
ngtkien | 0:fc80425b677a | 791 | * @brief Initializes peripherals used by the I2C EEPROM driver. |
ngtkien | 0:fc80425b677a | 792 | * @retval None |
ngtkien | 0:fc80425b677a | 793 | */ |
ngtkien | 0:fc80425b677a | 794 | void EEPROM_IO_Init(void) |
ngtkien | 0:fc80425b677a | 795 | { |
ngtkien | 0:fc80425b677a | 796 | I2Cx_Init(&hI2cExtHandler); |
ngtkien | 0:fc80425b677a | 797 | } |
ngtkien | 0:fc80425b677a | 798 | |
ngtkien | 0:fc80425b677a | 799 | /** |
ngtkien | 0:fc80425b677a | 800 | * @brief Write data to I2C EEPROM driver in using DMA channel. |
ngtkien | 0:fc80425b677a | 801 | * @param DevAddress: Target device address |
ngtkien | 0:fc80425b677a | 802 | * @param MemAddress: Internal memory address |
ngtkien | 0:fc80425b677a | 803 | * @param pBuffer: Pointer to data buffer |
ngtkien | 0:fc80425b677a | 804 | * @param BufferSize: Amount of data to be sent |
ngtkien | 0:fc80425b677a | 805 | * @retval HAL status |
ngtkien | 0:fc80425b677a | 806 | */ |
ngtkien | 0:fc80425b677a | 807 | HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize) |
ngtkien | 0:fc80425b677a | 808 | { |
ngtkien | 0:fc80425b677a | 809 | return (I2Cx_WriteMultiple(&hI2cExtHandler, DevAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize)); |
ngtkien | 0:fc80425b677a | 810 | } |
ngtkien | 0:fc80425b677a | 811 | |
ngtkien | 0:fc80425b677a | 812 | /** |
ngtkien | 0:fc80425b677a | 813 | * @brief Read data from I2C EEPROM driver in using DMA channel. |
ngtkien | 0:fc80425b677a | 814 | * @param DevAddress: Target device address |
ngtkien | 0:fc80425b677a | 815 | * @param MemAddress: Internal memory address |
ngtkien | 0:fc80425b677a | 816 | * @param pBuffer: Pointer to data buffer |
ngtkien | 0:fc80425b677a | 817 | * @param BufferSize: Amount of data to be read |
ngtkien | 0:fc80425b677a | 818 | * @retval HAL status |
ngtkien | 0:fc80425b677a | 819 | */ |
ngtkien | 0:fc80425b677a | 820 | HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize) |
ngtkien | 0:fc80425b677a | 821 | { |
ngtkien | 0:fc80425b677a | 822 | return (I2Cx_ReadMultiple(&hI2cExtHandler, DevAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize)); |
ngtkien | 0:fc80425b677a | 823 | } |
ngtkien | 0:fc80425b677a | 824 | |
ngtkien | 0:fc80425b677a | 825 | /** |
ngtkien | 0:fc80425b677a | 826 | * @brief Checks if target device is ready for communication. |
ngtkien | 0:fc80425b677a | 827 | * @note This function is used with Memory devices |
ngtkien | 0:fc80425b677a | 828 | * @param DevAddress: Target device address |
ngtkien | 0:fc80425b677a | 829 | * @param Trials: Number of trials |
ngtkien | 0:fc80425b677a | 830 | * @retval HAL status |
ngtkien | 0:fc80425b677a | 831 | */ |
ngtkien | 0:fc80425b677a | 832 | HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials) |
ngtkien | 0:fc80425b677a | 833 | { |
ngtkien | 0:fc80425b677a | 834 | return (I2Cx_IsDeviceReady(&hI2cExtHandler, DevAddress, Trials)); |
ngtkien | 0:fc80425b677a | 835 | } |
ngtkien | 0:fc80425b677a | 836 | |
ngtkien | 0:fc80425b677a | 837 | /********************************* LINK TOUCHSCREEN *********************************/ |
ngtkien | 0:fc80425b677a | 838 | |
ngtkien | 0:fc80425b677a | 839 | /** |
ngtkien | 0:fc80425b677a | 840 | * @brief Initializes Touchscreen low level. |
ngtkien | 0:fc80425b677a | 841 | * @retval None |
ngtkien | 0:fc80425b677a | 842 | */ |
ngtkien | 0:fc80425b677a | 843 | void TS_IO_Init(void) |
ngtkien | 0:fc80425b677a | 844 | { |
ngtkien | 0:fc80425b677a | 845 | I2Cx_Init(&hI2cAudioHandler); |
ngtkien | 0:fc80425b677a | 846 | } |
ngtkien | 0:fc80425b677a | 847 | |
ngtkien | 0:fc80425b677a | 848 | /** |
ngtkien | 0:fc80425b677a | 849 | * @brief Writes a single data. |
ngtkien | 0:fc80425b677a | 850 | * @param Addr: I2C address |
ngtkien | 0:fc80425b677a | 851 | * @param Reg: Reg address |
ngtkien | 0:fc80425b677a | 852 | * @param Value: Data to be written |
ngtkien | 0:fc80425b677a | 853 | * @retval None |
ngtkien | 0:fc80425b677a | 854 | */ |
ngtkien | 0:fc80425b677a | 855 | void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value) |
ngtkien | 0:fc80425b677a | 856 | { |
ngtkien | 0:fc80425b677a | 857 | I2Cx_WriteMultiple(&hI2cAudioHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT,(uint8_t*)&Value, 1); |
ngtkien | 0:fc80425b677a | 858 | } |
ngtkien | 0:fc80425b677a | 859 | |
ngtkien | 0:fc80425b677a | 860 | /** |
ngtkien | 0:fc80425b677a | 861 | * @brief Reads a single data. |
ngtkien | 0:fc80425b677a | 862 | * @param Addr: I2C address |
ngtkien | 0:fc80425b677a | 863 | * @param Reg: Reg address |
ngtkien | 0:fc80425b677a | 864 | * @retval Data to be read |
ngtkien | 0:fc80425b677a | 865 | */ |
ngtkien | 0:fc80425b677a | 866 | uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg) |
ngtkien | 0:fc80425b677a | 867 | { |
ngtkien | 0:fc80425b677a | 868 | uint8_t read_value = 0; |
ngtkien | 0:fc80425b677a | 869 | |
ngtkien | 0:fc80425b677a | 870 | I2Cx_ReadMultiple(&hI2cAudioHandler, Addr, Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&read_value, 1); |
ngtkien | 0:fc80425b677a | 871 | |
ngtkien | 0:fc80425b677a | 872 | return read_value; |
ngtkien | 0:fc80425b677a | 873 | } |
ngtkien | 0:fc80425b677a | 874 | |
ngtkien | 0:fc80425b677a | 875 | /** |
ngtkien | 0:fc80425b677a | 876 | * @brief TS delay |
ngtkien | 0:fc80425b677a | 877 | * @param Delay: Delay in ms |
ngtkien | 0:fc80425b677a | 878 | * @retval None |
ngtkien | 0:fc80425b677a | 879 | */ |
ngtkien | 0:fc80425b677a | 880 | void TS_IO_Delay(uint32_t Delay) |
ngtkien | 0:fc80425b677a | 881 | { |
ngtkien | 0:fc80425b677a | 882 | //HAL_Delay(Delay); // MBED |
ngtkien | 0:fc80425b677a | 883 | wait_ms(Delay); // MBED |
ngtkien | 0:fc80425b677a | 884 | } |
ngtkien | 0:fc80425b677a | 885 | |
ngtkien | 0:fc80425b677a | 886 | /** |
ngtkien | 0:fc80425b677a | 887 | * @} |
ngtkien | 0:fc80425b677a | 888 | */ |
ngtkien | 0:fc80425b677a | 889 | |
ngtkien | 0:fc80425b677a | 890 | /** |
ngtkien | 0:fc80425b677a | 891 | * @} |
ngtkien | 0:fc80425b677a | 892 | */ |
ngtkien | 0:fc80425b677a | 893 | |
ngtkien | 0:fc80425b677a | 894 | /** |
ngtkien | 0:fc80425b677a | 895 | * @} |
ngtkien | 0:fc80425b677a | 896 | */ |
ngtkien | 0:fc80425b677a | 897 | |
ngtkien | 0:fc80425b677a | 898 | /** |
ngtkien | 0:fc80425b677a | 899 | * @} |
ngtkien | 0:fc80425b677a | 900 | */ |
ngtkien | 0:fc80425b677a | 901 | |
ngtkien | 0:fc80425b677a | 902 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |