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