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