Contains the BSP driver for the DISCO_F413ZH board.

Dependents:   DISCO_F413ZH-LCD-demo DISCO_F413ZH-touch-screen-demo DISCO_F413ZH-SD-demo DISCO_F413ZH-PSRAM-demo ... more

Committer:
arostm
Date:
Wed May 17 10:23:19 2017 +0200
Revision:
0:4af3ca173992
Child:
3:42b354f5069c
creation of the DISCO_F413ZH BSP library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
arostm 0:4af3ca173992 1 /**
arostm 0:4af3ca173992 2 ******************************************************************************
arostm 0:4af3ca173992 3 * @file stm32f413h_discovery.c
arostm 0:4af3ca173992 4 * @author MCD Application Team
arostm 0:4af3ca173992 5 * @version V1.0.0
arostm 0:4af3ca173992 6 * @date 27-January-2017
arostm 0:4af3ca173992 7 * @brief This file provides a set of firmware functions to manage LEDs,
arostm 0:4af3ca173992 8 * push-buttons and COM ports available on STM32F413H-DISCOVERY board
arostm 0:4af3ca173992 9 * (MB1209) from STMicroelectronics.
arostm 0:4af3ca173992 10 ******************************************************************************
arostm 0:4af3ca173992 11 * @attention
arostm 0:4af3ca173992 12 *
arostm 0:4af3ca173992 13 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
arostm 0:4af3ca173992 14 *
arostm 0:4af3ca173992 15 * Redistribution and use in source and binary forms, with or without modification,
arostm 0:4af3ca173992 16 * are permitted provided that the following conditions are met:
arostm 0:4af3ca173992 17 * 1. Redistributions of source code must retain the above copyright notice,
arostm 0:4af3ca173992 18 * this list of conditions and the following disclaimer.
arostm 0:4af3ca173992 19 * 2. Redistributions in binary form must reproduce the above copyright notice,
arostm 0:4af3ca173992 20 * this list of conditions and the following disclaimer in the documentation
arostm 0:4af3ca173992 21 * and/or other materials provided with the distribution.
arostm 0:4af3ca173992 22 * 3. Neither the name of STMicroelectronics nor the names of its contributors
arostm 0:4af3ca173992 23 * may be used to endorse or promote products derived from this software
arostm 0:4af3ca173992 24 * without specific prior written permission.
arostm 0:4af3ca173992 25 *
arostm 0:4af3ca173992 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
arostm 0:4af3ca173992 27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
arostm 0:4af3ca173992 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
arostm 0:4af3ca173992 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
arostm 0:4af3ca173992 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
arostm 0:4af3ca173992 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
arostm 0:4af3ca173992 32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
arostm 0:4af3ca173992 33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
arostm 0:4af3ca173992 34 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
arostm 0:4af3ca173992 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
arostm 0:4af3ca173992 36 *
arostm 0:4af3ca173992 37 ******************************************************************************
arostm 0:4af3ca173992 38 */
arostm 0:4af3ca173992 39
arostm 0:4af3ca173992 40 /* Includes ------------------------------------------------------------------*/
arostm 0:4af3ca173992 41 #include "stm32f413h_discovery.h"
arostm 0:4af3ca173992 42
arostm 0:4af3ca173992 43
arostm 0:4af3ca173992 44 /** @addtogroup BSP
arostm 0:4af3ca173992 45 * @{
arostm 0:4af3ca173992 46 */
arostm 0:4af3ca173992 47
arostm 0:4af3ca173992 48 /** @defgroup STM32F413H_DISCOVERY STM32F413H_DISCOVERY
arostm 0:4af3ca173992 49 * @{
arostm 0:4af3ca173992 50 */
arostm 0:4af3ca173992 51
arostm 0:4af3ca173992 52 /** @defgroup STM32F413H_DISCOVERY_LOW_LEVEL STM32F413H-DISCOVERY LOW LEVEL
arostm 0:4af3ca173992 53 * @{
arostm 0:4af3ca173992 54 */
arostm 0:4af3ca173992 55
arostm 0:4af3ca173992 56 /** @defgroup STM32F413H_DISCOVERY_LOW_LEVEL_Private_TypesDefinitions STM32F413H Discovery Low Level Private Typedef
arostm 0:4af3ca173992 57 * @{
arostm 0:4af3ca173992 58 */
arostm 0:4af3ca173992 59 typedef struct
arostm 0:4af3ca173992 60 {
arostm 0:4af3ca173992 61 __IO uint16_t REG;
arostm 0:4af3ca173992 62 __IO uint16_t RAM;
arostm 0:4af3ca173992 63 }LCD_CONTROLLER_TypeDef;
arostm 0:4af3ca173992 64 /**
arostm 0:4af3ca173992 65 * @}
arostm 0:4af3ca173992 66 */
arostm 0:4af3ca173992 67
arostm 0:4af3ca173992 68 /** @defgroup STM32F413H_DISCOVERY_LOW_LEVEL_Private_Defines STM32F413H Discovery Low Level Private Def
arostm 0:4af3ca173992 69 * @{
arostm 0:4af3ca173992 70 */
arostm 0:4af3ca173992 71 /**
arostm 0:4af3ca173992 72 * @brief STM32F413H DISCOVERY BSP Driver version number V1.0.0
arostm 0:4af3ca173992 73 */
arostm 0:4af3ca173992 74 #define __STM32F413H_DISCOVERY_BSP_VERSION_MAIN (0x01) /*!< [31:24] main version */
arostm 0:4af3ca173992 75 #define __STM32F413H_DISCOVERY_BSP_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */
arostm 0:4af3ca173992 76 #define __STM32F413H_DISCOVERY_BSP_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */
arostm 0:4af3ca173992 77 #define __STM32F413H_DISCOVERY_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */
arostm 0:4af3ca173992 78 #define __STM32F413H_DISCOVERY_BSP_VERSION ((__STM32F413H_DISCOVERY_BSP_VERSION_MAIN << 24)\
arostm 0:4af3ca173992 79 |(__STM32F413H_DISCOVERY_BSP_VERSION_SUB1 << 16)\
arostm 0:4af3ca173992 80 |(__STM32F413H_DISCOVERY_BSP_VERSION_SUB2 << 8 )\
arostm 0:4af3ca173992 81 |(__STM32F413H_DISCOVERY_BSP_VERSION_RC))
arostm 0:4af3ca173992 82
arostm 0:4af3ca173992 83 /* We use BANK3 as we use FMC_NE3 signal */
arostm 0:4af3ca173992 84 #define FMC_BANK3_BASE ((uint32_t)(0x60000000 | 0x08000000))
arostm 0:4af3ca173992 85 #define FMC_BANK3 ((LCD_CONTROLLER_TypeDef *) FMC_BANK3_BASE)
arostm 0:4af3ca173992 86
arostm 0:4af3ca173992 87 /**
arostm 0:4af3ca173992 88 * @}
arostm 0:4af3ca173992 89 */
arostm 0:4af3ca173992 90
arostm 0:4af3ca173992 91 /** @defgroup STM32F413H_DISCOVERY_LOW_LEVEL_Private_Variables STM32F413H Discovery Low Level Variables
arostm 0:4af3ca173992 92 * @{
arostm 0:4af3ca173992 93 */
arostm 0:4af3ca173992 94
arostm 0:4af3ca173992 95 const uint32_t GPIO_PIN[LEDn] = {LED3_PIN,
arostm 0:4af3ca173992 96 LED4_PIN};
arostm 0:4af3ca173992 97
arostm 0:4af3ca173992 98
arostm 0:4af3ca173992 99 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED3_GPIO_PORT,
arostm 0:4af3ca173992 100 LED4_GPIO_PORT};
arostm 0:4af3ca173992 101
arostm 0:4af3ca173992 102
arostm 0:4af3ca173992 103 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT};
arostm 0:4af3ca173992 104
arostm 0:4af3ca173992 105 const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN};
arostm 0:4af3ca173992 106
arostm 0:4af3ca173992 107 const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn};
arostm 0:4af3ca173992 108
arostm 0:4af3ca173992 109 USART_TypeDef* COM_USART[COMn] = {DISCOVERY_COM1};
arostm 0:4af3ca173992 110
arostm 0:4af3ca173992 111 GPIO_TypeDef* COM_TX_PORT[COMn] = {DISCOVERY_COM1_TX_GPIO_PORT};
arostm 0:4af3ca173992 112
arostm 0:4af3ca173992 113 GPIO_TypeDef* COM_RX_PORT[COMn] = {DISCOVERY_COM1_RX_GPIO_PORT};
arostm 0:4af3ca173992 114
arostm 0:4af3ca173992 115 const uint16_t COM_TX_PIN[COMn] = {DISCOVERY_COM1_TX_PIN};
arostm 0:4af3ca173992 116
arostm 0:4af3ca173992 117 const uint16_t COM_RX_PIN[COMn] = {DISCOVERY_COM1_RX_PIN};
arostm 0:4af3ca173992 118
arostm 0:4af3ca173992 119 const uint16_t COM_TX_AF[COMn] = {DISCOVERY_COM1_TX_AF};
arostm 0:4af3ca173992 120
arostm 0:4af3ca173992 121 const uint16_t COM_RX_AF[COMn] = {DISCOVERY_COM1_RX_AF};
arostm 0:4af3ca173992 122
arostm 0:4af3ca173992 123 static FMPI2C_HandleTypeDef hI2cAudioHandler;
arostm 0:4af3ca173992 124
arostm 0:4af3ca173992 125 /**
arostm 0:4af3ca173992 126 * @}
arostm 0:4af3ca173992 127 */
arostm 0:4af3ca173992 128
arostm 0:4af3ca173992 129 /** @defgroup STM32F413H_DISCOVERY_LOW_LEVEL_Private_FunctionPrototypes STM32F413H Discovery Low Level Private Prototypes
arostm 0:4af3ca173992 130 * @{
arostm 0:4af3ca173992 131 */
arostm 0:4af3ca173992 132 static void FMPI2Cx_Init(FMPI2C_HandleTypeDef *i2c_handler);
arostm 0:4af3ca173992 133 static void FMPI2Cx_DeInit(FMPI2C_HandleTypeDef *i2c_handler);
arostm 0:4af3ca173992 134
arostm 0:4af3ca173992 135 static HAL_StatusTypeDef FMPI2Cx_ReadMultiple(FMPI2C_HandleTypeDef *fmpi2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
arostm 0:4af3ca173992 136 static HAL_StatusTypeDef FMPI2Cx_WriteMultiple(FMPI2C_HandleTypeDef *fmpi2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
arostm 0:4af3ca173992 137 static void FMPI2Cx_Error(FMPI2C_HandleTypeDef *fmpi2c_handler, uint8_t Addr);
arostm 0:4af3ca173992 138
arostm 0:4af3ca173992 139 static void FMC_BANK3_WriteData(uint16_t Data);
arostm 0:4af3ca173992 140 static void FMC_BANK3_WriteReg(uint8_t Reg);
arostm 0:4af3ca173992 141 static uint16_t FMC_BANK3_ReadData(void);
arostm 0:4af3ca173992 142 static void FMC_BANK3_Init(void);
arostm 0:4af3ca173992 143 static void FMC_BANK3_MspInit(void);
arostm 0:4af3ca173992 144
arostm 0:4af3ca173992 145 /* LCD IO functions */
arostm 0:4af3ca173992 146 void LCD_IO_Init(void);
arostm 0:4af3ca173992 147 void LCD_IO_WriteData(uint16_t RegValue);
arostm 0:4af3ca173992 148 void LCD_IO_WriteReg(uint8_t Reg);
arostm 0:4af3ca173992 149 void LCD_IO_WriteMultipleData(uint16_t *pData, uint32_t Size);
arostm 0:4af3ca173992 150 uint16_t LCD_IO_ReadData(void);
arostm 0:4af3ca173992 151 void LCD_IO_Delay(uint32_t Delay);
arostm 0:4af3ca173992 152
arostm 0:4af3ca173992 153 /* AUDIO IO functions */
arostm 0:4af3ca173992 154 void AUDIO_IO_Init(void);
arostm 0:4af3ca173992 155 void AUDIO_IO_DeInit(void);
arostm 0:4af3ca173992 156 void AUDIO_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value);
arostm 0:4af3ca173992 157 uint16_t AUDIO_IO_Read(uint8_t Addr, uint16_t Reg);
arostm 0:4af3ca173992 158 void AUDIO_IO_Delay(uint32_t Delay);
arostm 0:4af3ca173992 159
arostm 0:4af3ca173992 160 /* TouchScreen (TS) IO functions */
arostm 0:4af3ca173992 161 void TS_IO_Init(void);
arostm 0:4af3ca173992 162 void TS_IO_DeInit(void);
arostm 0:4af3ca173992 163 void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
arostm 0:4af3ca173992 164 uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg);
arostm 0:4af3ca173992 165 uint16_t TS_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
arostm 0:4af3ca173992 166 void TS_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
arostm 0:4af3ca173992 167 void TS_IO_Delay(uint32_t Delay);
arostm 0:4af3ca173992 168
arostm 0:4af3ca173992 169 /**
arostm 0:4af3ca173992 170 * @}
arostm 0:4af3ca173992 171 */
arostm 0:4af3ca173992 172
arostm 0:4af3ca173992 173 /** @defgroup STM32F413H_DISCOVERY_LOW_LEVEL_Private_Functions STM32F413H Discovery Low Level Private Functions
arostm 0:4af3ca173992 174 * @{
arostm 0:4af3ca173992 175 */
arostm 0:4af3ca173992 176
arostm 0:4af3ca173992 177 /**
arostm 0:4af3ca173992 178 * @brief This method returns the STM32F413H DISCOVERY BSP Driver revision
arostm 0:4af3ca173992 179 * @retval version: 0xXYZR (8bits for each decimal, R for RC)
arostm 0:4af3ca173992 180 */
arostm 0:4af3ca173992 181 uint32_t BSP_GetVersion(void)
arostm 0:4af3ca173992 182 {
arostm 0:4af3ca173992 183 return __STM32F413H_DISCOVERY_BSP_VERSION;
arostm 0:4af3ca173992 184 }
arostm 0:4af3ca173992 185
arostm 0:4af3ca173992 186 /**
arostm 0:4af3ca173992 187 * @brief Configures LEDs.
arostm 0:4af3ca173992 188 * @param Led: LED to be configured.
arostm 0:4af3ca173992 189 * This parameter can be one of the following values:
arostm 0:4af3ca173992 190 * @arg LED3
arostm 0:4af3ca173992 191 * @arg LED4
arostm 0:4af3ca173992 192 */
arostm 0:4af3ca173992 193 void BSP_LED_Init(Led_TypeDef Led)
arostm 0:4af3ca173992 194 {
arostm 0:4af3ca173992 195 GPIO_InitTypeDef gpio_init_structure;
arostm 0:4af3ca173992 196
arostm 0:4af3ca173992 197 LEDx_GPIO_CLK_ENABLE(Led);
arostm 0:4af3ca173992 198 /* Configure the GPIO_LED pin */
arostm 0:4af3ca173992 199 gpio_init_structure.Pin = GPIO_PIN[Led];
arostm 0:4af3ca173992 200 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
arostm 0:4af3ca173992 201 gpio_init_structure.Pull = GPIO_PULLUP;
arostm 0:4af3ca173992 202 gpio_init_structure.Speed = GPIO_SPEED_HIGH;
arostm 0:4af3ca173992 203
arostm 0:4af3ca173992 204 HAL_GPIO_Init(GPIO_PORT[Led], &gpio_init_structure);
arostm 0:4af3ca173992 205 }
arostm 0:4af3ca173992 206
arostm 0:4af3ca173992 207 /**
arostm 0:4af3ca173992 208 * @brief DeInit LEDs.
arostm 0:4af3ca173992 209 * @param Led: LED to be configured.
arostm 0:4af3ca173992 210 * This parameter can be one of the following values:
arostm 0:4af3ca173992 211 * @arg LED3
arostm 0:4af3ca173992 212 * @arg LED4
arostm 0:4af3ca173992 213 */
arostm 0:4af3ca173992 214 void BSP_LED_DeInit(Led_TypeDef Led)
arostm 0:4af3ca173992 215 {
arostm 0:4af3ca173992 216 GPIO_InitTypeDef gpio_init_structure;
arostm 0:4af3ca173992 217
arostm 0:4af3ca173992 218 /* DeInit the GPIO_LED pin */
arostm 0:4af3ca173992 219 gpio_init_structure.Pin = GPIO_PIN[Led];
arostm 0:4af3ca173992 220
arostm 0:4af3ca173992 221 /* Turn off LED */
arostm 0:4af3ca173992 222 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
arostm 0:4af3ca173992 223 HAL_GPIO_DeInit(GPIO_PORT[Led], gpio_init_structure.Pin);
arostm 0:4af3ca173992 224 }
arostm 0:4af3ca173992 225
arostm 0:4af3ca173992 226 /**
arostm 0:4af3ca173992 227 * @brief Turns selected LED On.
arostm 0:4af3ca173992 228 * @param Led: LED to be set on
arostm 0:4af3ca173992 229 * This parameter can be one of the following values:
arostm 0:4af3ca173992 230 * @arg LED3
arostm 0:4af3ca173992 231 * @arg LED4
arostm 0:4af3ca173992 232 */
arostm 0:4af3ca173992 233 void BSP_LED_On(Led_TypeDef Led)
arostm 0:4af3ca173992 234 {
arostm 0:4af3ca173992 235 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
arostm 0:4af3ca173992 236 }
arostm 0:4af3ca173992 237
arostm 0:4af3ca173992 238 /**
arostm 0:4af3ca173992 239 * @brief Turns selected LED Off.
arostm 0:4af3ca173992 240 * @param Led: LED to be set off
arostm 0:4af3ca173992 241 * This parameter can be one of the following values:
arostm 0:4af3ca173992 242 * @arg LED3
arostm 0:4af3ca173992 243 * @arg LED4
arostm 0:4af3ca173992 244 */
arostm 0:4af3ca173992 245 void BSP_LED_Off(Led_TypeDef Led)
arostm 0:4af3ca173992 246 {
arostm 0:4af3ca173992 247 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
arostm 0:4af3ca173992 248 }
arostm 0:4af3ca173992 249
arostm 0:4af3ca173992 250 /**
arostm 0:4af3ca173992 251 * @brief Toggles the selected LED.
arostm 0:4af3ca173992 252 * @param Led: LED to be toggled
arostm 0:4af3ca173992 253 * This parameter can be one of the following values:
arostm 0:4af3ca173992 254 * @arg LED3
arostm 0:4af3ca173992 255 * @arg LED4
arostm 0:4af3ca173992 256 */
arostm 0:4af3ca173992 257 void BSP_LED_Toggle(Led_TypeDef Led)
arostm 0:4af3ca173992 258 {
arostm 0:4af3ca173992 259 HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]);
arostm 0:4af3ca173992 260 }
arostm 0:4af3ca173992 261
arostm 0:4af3ca173992 262 /**
arostm 0:4af3ca173992 263 * @brief Configures button GPIO and EXTI Line.
arostm 0:4af3ca173992 264 * @param Button: Button to be configured
arostm 0:4af3ca173992 265 * This parameter can be one of the following values:
arostm 0:4af3ca173992 266 * @arg BUTTON_WAKEUP: Wakeup Push Button
arostm 0:4af3ca173992 267 * @param ButtonMode: Button mode
arostm 0:4af3ca173992 268 * This parameter can be one of the following values:
arostm 0:4af3ca173992 269 * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
arostm 0:4af3ca173992 270 * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line
arostm 0:4af3ca173992 271 * with interrupt generation capability
arostm 0:4af3ca173992 272 */
arostm 0:4af3ca173992 273 void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
arostm 0:4af3ca173992 274 {
arostm 0:4af3ca173992 275 GPIO_InitTypeDef gpio_init_structure;
arostm 0:4af3ca173992 276
arostm 0:4af3ca173992 277 /* Enable the BUTTON clock */
arostm 0:4af3ca173992 278 WAKEUP_BUTTON_GPIO_CLK_ENABLE();
arostm 0:4af3ca173992 279
arostm 0:4af3ca173992 280 if(ButtonMode == BUTTON_MODE_GPIO)
arostm 0:4af3ca173992 281 {
arostm 0:4af3ca173992 282 /* Configure Button pin as input */
arostm 0:4af3ca173992 283 gpio_init_structure.Pin = BUTTON_PIN[Button];
arostm 0:4af3ca173992 284 gpio_init_structure.Mode = GPIO_MODE_INPUT;
arostm 0:4af3ca173992 285 gpio_init_structure.Pull = GPIO_PULLDOWN;
arostm 0:4af3ca173992 286 gpio_init_structure.Speed = GPIO_SPEED_FAST;
arostm 0:4af3ca173992 287 HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure);
arostm 0:4af3ca173992 288 }
arostm 0:4af3ca173992 289
arostm 0:4af3ca173992 290 if(ButtonMode == BUTTON_MODE_EXTI)
arostm 0:4af3ca173992 291 {
arostm 0:4af3ca173992 292 /* Configure Button pin as input with External interrupt */
arostm 0:4af3ca173992 293 gpio_init_structure.Pin = BUTTON_PIN[Button];
arostm 0:4af3ca173992 294 gpio_init_structure.Pull = GPIO_PULLDOWN;
arostm 0:4af3ca173992 295 gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
arostm 0:4af3ca173992 296
arostm 0:4af3ca173992 297 gpio_init_structure.Mode = GPIO_MODE_IT_RISING;
arostm 0:4af3ca173992 298
arostm 0:4af3ca173992 299 HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure);
arostm 0:4af3ca173992 300
arostm 0:4af3ca173992 301 /* Enable and set Button EXTI Interrupt to the lowest priority */
arostm 0:4af3ca173992 302 HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00);
arostm 0:4af3ca173992 303 HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
arostm 0:4af3ca173992 304 }
arostm 0:4af3ca173992 305 }
arostm 0:4af3ca173992 306
arostm 0:4af3ca173992 307 /**
arostm 0:4af3ca173992 308 * @brief Push Button DeInit.
arostm 0:4af3ca173992 309 * @param Button: Button to be configured
arostm 0:4af3ca173992 310 * This parameter can be one of the following values:
arostm 0:4af3ca173992 311 * @arg BUTTON_WAKEUP: Wakeup Push Button
arostm 0:4af3ca173992 312 * @note PB DeInit does not disable the GPIO clock
arostm 0:4af3ca173992 313 */
arostm 0:4af3ca173992 314 void BSP_PB_DeInit(Button_TypeDef Button)
arostm 0:4af3ca173992 315 {
arostm 0:4af3ca173992 316 GPIO_InitTypeDef gpio_init_structure;
arostm 0:4af3ca173992 317
arostm 0:4af3ca173992 318 gpio_init_structure.Pin = BUTTON_PIN[Button];
arostm 0:4af3ca173992 319 HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
arostm 0:4af3ca173992 320 HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin);
arostm 0:4af3ca173992 321 }
arostm 0:4af3ca173992 322
arostm 0:4af3ca173992 323
arostm 0:4af3ca173992 324 /**
arostm 0:4af3ca173992 325 * @brief Returns the selected button state.
arostm 0:4af3ca173992 326 * @param Button: Button to be checked
arostm 0:4af3ca173992 327 * This parameter can be one of the following values:
arostm 0:4af3ca173992 328 * @arg BUTTON_WAKEUP: Wakeup Push Button
arostm 0:4af3ca173992 329 * @retval The Button GPIO pin value (GPIO_PIN_RESET = button pressed)
arostm 0:4af3ca173992 330 */
arostm 0:4af3ca173992 331 uint32_t BSP_PB_GetState(Button_TypeDef Button)
arostm 0:4af3ca173992 332 {
arostm 0:4af3ca173992 333 return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
arostm 0:4af3ca173992 334 }
arostm 0:4af3ca173992 335
arostm 0:4af3ca173992 336 /**
arostm 0:4af3ca173992 337 * @brief Configures COM port.
arostm 0:4af3ca173992 338 * @param COM: COM port to be configured.
arostm 0:4af3ca173992 339 * This parameter can be one of the following values:
arostm 0:4af3ca173992 340 * @arg COM1
arostm 0:4af3ca173992 341 * @param huart: Pointer to a UART_HandleTypeDef structure that contains the
arostm 0:4af3ca173992 342 * configuration information for the specified USART peripheral.
arostm 0:4af3ca173992 343 */
arostm 0:4af3ca173992 344 void BSP_COM_Init(COM_TypeDef COM, UART_HandleTypeDef *huart)
arostm 0:4af3ca173992 345 {
arostm 0:4af3ca173992 346 GPIO_InitTypeDef gpio_init_structure;
arostm 0:4af3ca173992 347
arostm 0:4af3ca173992 348 /* Enable GPIO clock */
arostm 0:4af3ca173992 349 DISCOVERY_COMx_TX_GPIO_CLK_ENABLE(COM);
arostm 0:4af3ca173992 350 DISCOVERY_COMx_RX_GPIO_CLK_ENABLE(COM);
arostm 0:4af3ca173992 351
arostm 0:4af3ca173992 352 /* Enable USART clock */
arostm 0:4af3ca173992 353 DISCOVERY_COMx_CLK_ENABLE(COM);
arostm 0:4af3ca173992 354
arostm 0:4af3ca173992 355 /* Configure USART Tx as alternate function */
arostm 0:4af3ca173992 356 gpio_init_structure.Pin = COM_TX_PIN[COM];
arostm 0:4af3ca173992 357 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
arostm 0:4af3ca173992 358 gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
arostm 0:4af3ca173992 359 gpio_init_structure.Pull = GPIO_PULLUP;
arostm 0:4af3ca173992 360 gpio_init_structure.Alternate = COM_TX_AF[COM];
arostm 0:4af3ca173992 361 HAL_GPIO_Init(COM_TX_PORT[COM], &gpio_init_structure);
arostm 0:4af3ca173992 362
arostm 0:4af3ca173992 363 /* Configure USART Rx as alternate function */
arostm 0:4af3ca173992 364 gpio_init_structure.Pin = COM_RX_PIN[COM];
arostm 0:4af3ca173992 365 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
arostm 0:4af3ca173992 366 gpio_init_structure.Alternate = COM_RX_AF[COM];
arostm 0:4af3ca173992 367 HAL_GPIO_Init(COM_RX_PORT[COM], &gpio_init_structure);
arostm 0:4af3ca173992 368
arostm 0:4af3ca173992 369 /* USART configuration */
arostm 0:4af3ca173992 370 huart->Instance = COM_USART[COM];
arostm 0:4af3ca173992 371 HAL_UART_Init(huart);
arostm 0:4af3ca173992 372 }
arostm 0:4af3ca173992 373
arostm 0:4af3ca173992 374 /**
arostm 0:4af3ca173992 375 * @brief DeInit COM port.
arostm 0:4af3ca173992 376 * @param COM: COM port to be configured.
arostm 0:4af3ca173992 377 * This parameter can be one of the following values:
arostm 0:4af3ca173992 378 * @arg COM1
arostm 0:4af3ca173992 379 * @param huart: Pointer to a UART_HandleTypeDef structure that contains the
arostm 0:4af3ca173992 380 * configuration information for the specified USART peripheral.
arostm 0:4af3ca173992 381 */
arostm 0:4af3ca173992 382 void BSP_COM_DeInit(COM_TypeDef COM, UART_HandleTypeDef *huart)
arostm 0:4af3ca173992 383 {
arostm 0:4af3ca173992 384 /* USART configuration */
arostm 0:4af3ca173992 385 huart->Instance = COM_USART[COM];
arostm 0:4af3ca173992 386 HAL_UART_DeInit(huart);
arostm 0:4af3ca173992 387
arostm 0:4af3ca173992 388 /* Enable USART clock */
arostm 0:4af3ca173992 389 DISCOVERY_COMx_CLK_DISABLE(COM);
arostm 0:4af3ca173992 390
arostm 0:4af3ca173992 391 /* DeInit GPIO pins can be done in the application
arostm 0:4af3ca173992 392 (by surcharging this __weak function) */
arostm 0:4af3ca173992 393
arostm 0:4af3ca173992 394 /* GPIO pins clock, FMC clock and DMA clock can be shut down in the application
arostm 0:4af3ca173992 395 by surcharging this __weak function */
arostm 0:4af3ca173992 396 }
arostm 0:4af3ca173992 397
arostm 0:4af3ca173992 398
arostm 0:4af3ca173992 399 /*******************************************************************************
arostm 0:4af3ca173992 400 BUS OPERATIONS
arostm 0:4af3ca173992 401 *******************************************************************************/
arostm 0:4af3ca173992 402
arostm 0:4af3ca173992 403 /******************************* I2C Routines *********************************/
arostm 0:4af3ca173992 404 /**
arostm 0:4af3ca173992 405 * @brief Initializes FMPI2C MSP.
arostm 0:4af3ca173992 406 * @param fmpi2c_handler : FMPI2C handler
arostm 0:4af3ca173992 407 */
arostm 0:4af3ca173992 408 static void FMPI2Cx_MspInit(FMPI2C_HandleTypeDef *fmpi2c_handler)
arostm 0:4af3ca173992 409 {
arostm 0:4af3ca173992 410 GPIO_InitTypeDef gpio_init_structure;
arostm 0:4af3ca173992 411
arostm 0:4af3ca173992 412 /* AUDIO FMPI2C MSP init */
arostm 0:4af3ca173992 413
arostm 0:4af3ca173992 414 /*** Configure the GPIOs ***/
arostm 0:4af3ca173992 415 /* Enable GPIO clock */
arostm 0:4af3ca173992 416 DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_CLK_ENABLE();
arostm 0:4af3ca173992 417
arostm 0:4af3ca173992 418 /* Configure I2C Tx as alternate function */
arostm 0:4af3ca173992 419 gpio_init_structure.Pin = DISCOVERY_AUDIO_I2Cx_SCL_PIN;
arostm 0:4af3ca173992 420 gpio_init_structure.Mode = GPIO_MODE_AF_OD;
arostm 0:4af3ca173992 421 gpio_init_structure.Pull = GPIO_NOPULL;
arostm 0:4af3ca173992 422 gpio_init_structure.Speed = GPIO_SPEED_FAST;
arostm 0:4af3ca173992 423 gpio_init_structure.Alternate = DISCOVERY_AUDIO_I2Cx_SCL_SDA_AF;
arostm 0:4af3ca173992 424 HAL_GPIO_Init(DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
arostm 0:4af3ca173992 425
arostm 0:4af3ca173992 426 /* Configure I2C Rx as alternate function */
arostm 0:4af3ca173992 427 gpio_init_structure.Pin = DISCOVERY_AUDIO_I2Cx_SDA_PIN;
arostm 0:4af3ca173992 428 gpio_init_structure.Alternate = DISCOVERY_AUDIO_I2Cx_SCL_SDA_AF;
arostm 0:4af3ca173992 429 HAL_GPIO_Init(DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
arostm 0:4af3ca173992 430
arostm 0:4af3ca173992 431 /*** Configure the I2C peripheral ***/
arostm 0:4af3ca173992 432 /* Enable I2C clock */
arostm 0:4af3ca173992 433 DISCOVERY_AUDIO_I2Cx_CLK_ENABLE();
arostm 0:4af3ca173992 434
arostm 0:4af3ca173992 435 /* Force the I2C peripheral clock reset */
arostm 0:4af3ca173992 436 DISCOVERY_AUDIO_I2Cx_FORCE_RESET();
arostm 0:4af3ca173992 437
arostm 0:4af3ca173992 438 /* Release the I2C peripheral clock reset */
arostm 0:4af3ca173992 439 DISCOVERY_AUDIO_I2Cx_RELEASE_RESET();
arostm 0:4af3ca173992 440
arostm 0:4af3ca173992 441 /* Enable and set I2Cx Interrupt to a lower priority */
arostm 0:4af3ca173992 442 HAL_NVIC_SetPriority(DISCOVERY_AUDIO_I2Cx_EV_IRQn, 0x0F, 0x00);
arostm 0:4af3ca173992 443 HAL_NVIC_EnableIRQ(DISCOVERY_AUDIO_I2Cx_EV_IRQn);
arostm 0:4af3ca173992 444
arostm 0:4af3ca173992 445 /* Enable and set I2Cx Interrupt to a lower priority */
arostm 0:4af3ca173992 446 HAL_NVIC_SetPriority(DISCOVERY_AUDIO_I2Cx_ER_IRQn, 0x0F, 0x00);
arostm 0:4af3ca173992 447 HAL_NVIC_EnableIRQ(DISCOVERY_AUDIO_I2Cx_ER_IRQn);
arostm 0:4af3ca173992 448 }
arostm 0:4af3ca173992 449
arostm 0:4af3ca173992 450 /**
arostm 0:4af3ca173992 451 * @brief Initializes FMPI2C HAL.
arostm 0:4af3ca173992 452 * @param fmpi2c_handler : FMPI2C handler
arostm 0:4af3ca173992 453 */
arostm 0:4af3ca173992 454 static void FMPI2Cx_Init(FMPI2C_HandleTypeDef *fmpi2c_handler)
arostm 0:4af3ca173992 455 {
arostm 0:4af3ca173992 456 if(HAL_FMPI2C_GetState(fmpi2c_handler) == HAL_FMPI2C_STATE_RESET)
arostm 0:4af3ca173992 457 {
arostm 0:4af3ca173992 458 /* Audio FMPI2C configuration */
arostm 0:4af3ca173992 459 fmpi2c_handler->Instance = DISCOVERY_AUDIO_I2Cx;
arostm 0:4af3ca173992 460 fmpi2c_handler->Init.Timing = DISCOVERY_I2Cx_TIMING;
arostm 0:4af3ca173992 461 fmpi2c_handler->Init.OwnAddress1 = 0;
arostm 0:4af3ca173992 462 fmpi2c_handler->Init.AddressingMode = FMPI2C_ADDRESSINGMODE_7BIT;
arostm 0:4af3ca173992 463 fmpi2c_handler->Init.DualAddressMode = FMPI2C_DUALADDRESS_DISABLE;
arostm 0:4af3ca173992 464 fmpi2c_handler->Init.OwnAddress2 = 0;
arostm 0:4af3ca173992 465 fmpi2c_handler->Init.OwnAddress2Masks = FMPI2C_OA2_NOMASK;
arostm 0:4af3ca173992 466 fmpi2c_handler->Init.GeneralCallMode = FMPI2C_GENERALCALL_DISABLE;
arostm 0:4af3ca173992 467 fmpi2c_handler->Init.NoStretchMode = FMPI2C_NOSTRETCH_DISABLE;
arostm 0:4af3ca173992 468 /* Init the FMPI2C */
arostm 0:4af3ca173992 469 FMPI2Cx_MspInit(fmpi2c_handler);
arostm 0:4af3ca173992 470 HAL_FMPI2C_Init(fmpi2c_handler);
arostm 0:4af3ca173992 471 }
arostm 0:4af3ca173992 472 }
arostm 0:4af3ca173992 473
arostm 0:4af3ca173992 474 /**
arostm 0:4af3ca173992 475 * @brief Reads multiple data.
arostm 0:4af3ca173992 476 * @param fmpi2c_handler : FMPI2C handler
arostm 0:4af3ca173992 477 * @param Addr: I2C address
arostm 0:4af3ca173992 478 * @param Reg: Reg address
arostm 0:4af3ca173992 479 * @param MemAddress: Memory address
arostm 0:4af3ca173992 480 * @param Buffer: Pointer to data buffer
arostm 0:4af3ca173992 481 * @param Length: Length of the data
arostm 0:4af3ca173992 482 * @retval Number of read data
arostm 0:4af3ca173992 483 */
arostm 0:4af3ca173992 484 static HAL_StatusTypeDef FMPI2Cx_ReadMultiple(FMPI2C_HandleTypeDef *fmpi2c_handler,
arostm 0:4af3ca173992 485 uint8_t Addr,
arostm 0:4af3ca173992 486 uint16_t Reg,
arostm 0:4af3ca173992 487 uint16_t MemAddress,
arostm 0:4af3ca173992 488 uint8_t *Buffer,
arostm 0:4af3ca173992 489 uint16_t Length)
arostm 0:4af3ca173992 490 {
arostm 0:4af3ca173992 491 HAL_StatusTypeDef status = HAL_OK;
arostm 0:4af3ca173992 492
arostm 0:4af3ca173992 493 status = HAL_FMPI2C_Mem_Read(fmpi2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000);
arostm 0:4af3ca173992 494
arostm 0:4af3ca173992 495 /* Check the communication status */
arostm 0:4af3ca173992 496 if(status != HAL_OK)
arostm 0:4af3ca173992 497 {
arostm 0:4af3ca173992 498 /* FMPI2C error occurred */
arostm 0:4af3ca173992 499 FMPI2Cx_Error(fmpi2c_handler, Addr);
arostm 0:4af3ca173992 500 }
arostm 0:4af3ca173992 501 return status;
arostm 0:4af3ca173992 502 }
arostm 0:4af3ca173992 503
arostm 0:4af3ca173992 504 /**
arostm 0:4af3ca173992 505 * @brief Writes a value in a register of the device through BUS in using DMA mode.
arostm 0:4af3ca173992 506 * @param fmpi2c_handler : FMPI2C handler
arostm 0:4af3ca173992 507 * @param Addr: Device address on BUS Bus.
arostm 0:4af3ca173992 508 * @param Reg: The target register address to write
arostm 0:4af3ca173992 509 * @param MemAddress: Memory address
arostm 0:4af3ca173992 510 * @param Buffer: The target register value to be written
arostm 0:4af3ca173992 511 * @param Length: buffer size to be written
arostm 0:4af3ca173992 512 * @retval HAL status
arostm 0:4af3ca173992 513 */
arostm 0:4af3ca173992 514 static HAL_StatusTypeDef FMPI2Cx_WriteMultiple(FMPI2C_HandleTypeDef *fmpi2c_handler,
arostm 0:4af3ca173992 515 uint8_t Addr,
arostm 0:4af3ca173992 516 uint16_t Reg,
arostm 0:4af3ca173992 517 uint16_t MemAddress,
arostm 0:4af3ca173992 518 uint8_t *Buffer,
arostm 0:4af3ca173992 519 uint16_t Length)
arostm 0:4af3ca173992 520 {
arostm 0:4af3ca173992 521 HAL_StatusTypeDef status = HAL_OK;
arostm 0:4af3ca173992 522
arostm 0:4af3ca173992 523 status = HAL_FMPI2C_Mem_Write(fmpi2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000);
arostm 0:4af3ca173992 524
arostm 0:4af3ca173992 525 /* Check the communication status */
arostm 0:4af3ca173992 526 if(status != HAL_OK)
arostm 0:4af3ca173992 527 {
arostm 0:4af3ca173992 528 /* Re-Initialize the FMPI2C Bus */
arostm 0:4af3ca173992 529 FMPI2Cx_Error(fmpi2c_handler, Addr);
arostm 0:4af3ca173992 530 }
arostm 0:4af3ca173992 531 return status;
arostm 0:4af3ca173992 532 }
arostm 0:4af3ca173992 533
arostm 0:4af3ca173992 534 /**
arostm 0:4af3ca173992 535 * @brief Manages error callback by re-initializing I2C.
arostm 0:4af3ca173992 536 * @param fmpi2c_handler : FMPI2C handler
arostm 0:4af3ca173992 537 * @param Addr: I2C Address
arostm 0:4af3ca173992 538 * @retval None
arostm 0:4af3ca173992 539 */
arostm 0:4af3ca173992 540 static void FMPI2Cx_Error(FMPI2C_HandleTypeDef *fmpi2c_handler, uint8_t Addr)
arostm 0:4af3ca173992 541 {
arostm 0:4af3ca173992 542 /* De-initialize the FMPI2C communication bus */
arostm 0:4af3ca173992 543 HAL_FMPI2C_DeInit(fmpi2c_handler);
arostm 0:4af3ca173992 544
arostm 0:4af3ca173992 545 /* Re-Initialize the FMPI2C communication bus */
arostm 0:4af3ca173992 546 FMPI2Cx_Init(fmpi2c_handler);
arostm 0:4af3ca173992 547 }
arostm 0:4af3ca173992 548
arostm 0:4af3ca173992 549 /**
arostm 0:4af3ca173992 550 * @brief Deinitializes FMPI2C interface
arostm 0:4af3ca173992 551 * @param fmpi2c_handler : FMPI2C handler
arostm 0:4af3ca173992 552 */
arostm 0:4af3ca173992 553 static void FMPI2Cx_DeInit(FMPI2C_HandleTypeDef *fmpi2c_handler)
arostm 0:4af3ca173992 554 {
arostm 0:4af3ca173992 555 /* Audio and LCD I2C configuration */
arostm 0:4af3ca173992 556 fmpi2c_handler->Instance = DISCOVERY_AUDIO_I2Cx;
arostm 0:4af3ca173992 557 /* Disable FMPI2C block */
arostm 0:4af3ca173992 558 __HAL_FMPI2C_DISABLE(fmpi2c_handler);
arostm 0:4af3ca173992 559
arostm 0:4af3ca173992 560 /* DeInit the FMPI2C */
arostm 0:4af3ca173992 561 HAL_FMPI2C_DeInit(fmpi2c_handler);
arostm 0:4af3ca173992 562 }
arostm 0:4af3ca173992 563 /*************************** FMC Routines ************************************/
arostm 0:4af3ca173992 564 /**
arostm 0:4af3ca173992 565 * @brief Initializes FMC_BANK3 MSP.
arostm 0:4af3ca173992 566 */
arostm 0:4af3ca173992 567 static void FMC_BANK3_MspInit(void)
arostm 0:4af3ca173992 568 {
arostm 0:4af3ca173992 569 GPIO_InitTypeDef gpio_init_structure;
arostm 0:4af3ca173992 570
arostm 0:4af3ca173992 571 /* Enable FSMC clock */
arostm 0:4af3ca173992 572 __HAL_RCC_FSMC_CLK_ENABLE();
arostm 0:4af3ca173992 573
arostm 0:4af3ca173992 574 /* Enable GPIOs clock */
arostm 0:4af3ca173992 575 __HAL_RCC_GPIOD_CLK_ENABLE();
arostm 0:4af3ca173992 576 __HAL_RCC_GPIOE_CLK_ENABLE();
arostm 0:4af3ca173992 577 __HAL_RCC_GPIOF_CLK_ENABLE();
arostm 0:4af3ca173992 578 __HAL_RCC_GPIOG_CLK_ENABLE();
arostm 0:4af3ca173992 579
arostm 0:4af3ca173992 580 /* Common GPIO configuration */
arostm 0:4af3ca173992 581 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
arostm 0:4af3ca173992 582 gpio_init_structure.Pull = GPIO_PULLUP;
arostm 0:4af3ca173992 583 gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
arostm 0:4af3ca173992 584 gpio_init_structure.Alternate = GPIO_AF12_FSMC;
arostm 0:4af3ca173992 585
arostm 0:4af3ca173992 586 /* GPIOD configuration: GPIO_PIN_7 is FMC_NE1 , GPIO_PIN_11 ans GPIO_PIN_12 are PSRAM_A16 and PSRAM_A17 */
arostm 0:4af3ca173992 587 gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_8 |\
arostm 0:4af3ca173992 588 GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_14 | GPIO_PIN_15 | GPIO_PIN_7|\
arostm 0:4af3ca173992 589 GPIO_PIN_11 | GPIO_PIN_12;
arostm 0:4af3ca173992 590
arostm 0:4af3ca173992 591 HAL_GPIO_Init(GPIOD, &gpio_init_structure);
arostm 0:4af3ca173992 592
arostm 0:4af3ca173992 593 /* GPIOE configuration */
arostm 0:4af3ca173992 594 gpio_init_structure.Pin = GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 |\
arostm 0:4af3ca173992 595 GPIO_PIN_12 |GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
arostm 0:4af3ca173992 596 HAL_GPIO_Init(GPIOE, &gpio_init_structure);
arostm 0:4af3ca173992 597
arostm 0:4af3ca173992 598 /* GPIOF configuration */
arostm 0:4af3ca173992 599 gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 |\
arostm 0:4af3ca173992 600 GPIO_PIN_5 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
arostm 0:4af3ca173992 601 HAL_GPIO_Init(GPIOF, &gpio_init_structure);
arostm 0:4af3ca173992 602
arostm 0:4af3ca173992 603 /* GPIOG configuration */
arostm 0:4af3ca173992 604 gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 |\
arostm 0:4af3ca173992 605 GPIO_PIN_5 | GPIO_PIN_10 ;
arostm 0:4af3ca173992 606 HAL_GPIO_Init(GPIOG, &gpio_init_structure);
arostm 0:4af3ca173992 607 }
arostm 0:4af3ca173992 608
arostm 0:4af3ca173992 609 /**
arostm 0:4af3ca173992 610 * @brief Initializes LCD IOs.
arostm 0:4af3ca173992 611 */
arostm 0:4af3ca173992 612 static void FMC_BANK3_Init(void)
arostm 0:4af3ca173992 613 {
arostm 0:4af3ca173992 614 SRAM_HandleTypeDef hsram;
arostm 0:4af3ca173992 615 FSMC_NORSRAM_TimingTypeDef sram_timing;
arostm 0:4af3ca173992 616
arostm 0:4af3ca173992 617 /* Initialize the SRAM controller */
arostm 0:4af3ca173992 618 FMC_BANK3_MspInit();
arostm 0:4af3ca173992 619
arostm 0:4af3ca173992 620 /*** Configure the SRAM Bank 1 ***/
arostm 0:4af3ca173992 621 /* Configure IPs */
arostm 0:4af3ca173992 622 hsram.Instance = FSMC_NORSRAM_DEVICE;
arostm 0:4af3ca173992 623 hsram.Extended = FSMC_NORSRAM_EXTENDED_DEVICE;
arostm 0:4af3ca173992 624
arostm 0:4af3ca173992 625 /* Timing config */
arostm 0:4af3ca173992 626 sram_timing.AddressSetupTime = 3;
arostm 0:4af3ca173992 627 sram_timing.AddressHoldTime = 1;
arostm 0:4af3ca173992 628 sram_timing.DataSetupTime = 4;
arostm 0:4af3ca173992 629 sram_timing.BusTurnAroundDuration = 1;
arostm 0:4af3ca173992 630 sram_timing.CLKDivision = 2;
arostm 0:4af3ca173992 631 sram_timing.DataLatency = 2;
arostm 0:4af3ca173992 632 sram_timing.AccessMode = FSMC_ACCESS_MODE_A;
arostm 0:4af3ca173992 633
arostm 0:4af3ca173992 634 hsram.Init.NSBank = FSMC_NORSRAM_BANK3;
arostm 0:4af3ca173992 635 hsram.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE;
arostm 0:4af3ca173992 636 hsram.Init.MemoryType = FSMC_MEMORY_TYPE_SRAM;
arostm 0:4af3ca173992 637 hsram.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;
arostm 0:4af3ca173992 638 hsram.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;
arostm 0:4af3ca173992 639 hsram.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
arostm 0:4af3ca173992 640 hsram.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;
arostm 0:4af3ca173992 641 hsram.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;
arostm 0:4af3ca173992 642 hsram.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;
arostm 0:4af3ca173992 643 hsram.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;
arostm 0:4af3ca173992 644 hsram.Init.ExtendedMode = FSMC_EXTENDED_MODE_ENABLE;
arostm 0:4af3ca173992 645 hsram.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;
arostm 0:4af3ca173992 646 hsram.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
arostm 0:4af3ca173992 647 hsram.Init.WriteFifo = FSMC_WRITE_FIFO_DISABLE;
arostm 0:4af3ca173992 648 hsram.Init.PageSize = FSMC_PAGE_SIZE_NONE;
arostm 0:4af3ca173992 649 hsram.Init.ContinuousClock = FSMC_CONTINUOUS_CLOCK_SYNC_ONLY;
arostm 0:4af3ca173992 650
arostm 0:4af3ca173992 651 HAL_SRAM_Init(&hsram, &sram_timing, &sram_timing);
arostm 0:4af3ca173992 652 }
arostm 0:4af3ca173992 653
arostm 0:4af3ca173992 654 /**
arostm 0:4af3ca173992 655 * @brief Writes register value.
arostm 0:4af3ca173992 656 * @param Data: Data to be written
arostm 0:4af3ca173992 657 */
arostm 0:4af3ca173992 658 static void FMC_BANK3_WriteData(uint16_t Data)
arostm 0:4af3ca173992 659 {
arostm 0:4af3ca173992 660 /* Write 16-bit Reg */
arostm 0:4af3ca173992 661 FMC_BANK3->RAM = Data;
arostm 0:4af3ca173992 662 __DSB();
arostm 0:4af3ca173992 663 }
arostm 0:4af3ca173992 664
arostm 0:4af3ca173992 665 /**
arostm 0:4af3ca173992 666 * @brief Writes register address.
arostm 0:4af3ca173992 667 * @param Reg: Register to be written
arostm 0:4af3ca173992 668 */
arostm 0:4af3ca173992 669 static void FMC_BANK3_WriteReg(uint8_t Reg)
arostm 0:4af3ca173992 670 {
arostm 0:4af3ca173992 671 /* Write 16-bit Index, then write register */
arostm 0:4af3ca173992 672 FMC_BANK3->REG = Reg;
arostm 0:4af3ca173992 673 __DSB();
arostm 0:4af3ca173992 674 }
arostm 0:4af3ca173992 675
arostm 0:4af3ca173992 676 /**
arostm 0:4af3ca173992 677 * @brief Reads register value.
arostm 0:4af3ca173992 678 * @retval Read value
arostm 0:4af3ca173992 679 */
arostm 0:4af3ca173992 680 static uint16_t FMC_BANK3_ReadData(void)
arostm 0:4af3ca173992 681 {
arostm 0:4af3ca173992 682 return FMC_BANK3->RAM;
arostm 0:4af3ca173992 683 }
arostm 0:4af3ca173992 684
arostm 0:4af3ca173992 685 /*******************************************************************************
arostm 0:4af3ca173992 686 LINK OPERATIONS
arostm 0:4af3ca173992 687 *******************************************************************************/
arostm 0:4af3ca173992 688
arostm 0:4af3ca173992 689 /********************************* LINK LCD ***********************************/
arostm 0:4af3ca173992 690 /**
arostm 0:4af3ca173992 691 * @brief Initializes LCD low level.
arostm 0:4af3ca173992 692 */
arostm 0:4af3ca173992 693 void LCD_IO_Init(void)
arostm 0:4af3ca173992 694 {
arostm 0:4af3ca173992 695 FMC_BANK3_Init();
arostm 0:4af3ca173992 696 }
arostm 0:4af3ca173992 697
arostm 0:4af3ca173992 698 /**
arostm 0:4af3ca173992 699 * @brief Writes data on LCD data register.
arostm 0:4af3ca173992 700 * @param RegValue: Data to be written
arostm 0:4af3ca173992 701 */
arostm 0:4af3ca173992 702 void LCD_IO_WriteData(uint16_t RegValue)
arostm 0:4af3ca173992 703 {
arostm 0:4af3ca173992 704 /* Write 16-bit Reg */
arostm 0:4af3ca173992 705 FMC_BANK3_WriteData(RegValue);
arostm 0:4af3ca173992 706 }
arostm 0:4af3ca173992 707
arostm 0:4af3ca173992 708 /**
arostm 0:4af3ca173992 709 * @brief Writes several data on LCD data register.
arostm 0:4af3ca173992 710 * @param pData: pointer on data to be written
arostm 0:4af3ca173992 711 * @param Size: data amount in 16bits short unit
arostm 0:4af3ca173992 712 */
arostm 0:4af3ca173992 713 void LCD_IO_WriteMultipleData(uint16_t *pData, uint32_t Size)
arostm 0:4af3ca173992 714 {
arostm 0:4af3ca173992 715 uint32_t i;
arostm 0:4af3ca173992 716
arostm 0:4af3ca173992 717 for (i = 0; i < Size; i++)
arostm 0:4af3ca173992 718 {
arostm 0:4af3ca173992 719 FMC_BANK3_WriteData(pData[i]);
arostm 0:4af3ca173992 720 }
arostm 0:4af3ca173992 721 }
arostm 0:4af3ca173992 722
arostm 0:4af3ca173992 723 /**
arostm 0:4af3ca173992 724 * @brief Writes register on LCD register.
arostm 0:4af3ca173992 725 * @param Reg: Register to be written
arostm 0:4af3ca173992 726 */
arostm 0:4af3ca173992 727 void LCD_IO_WriteReg(uint8_t Reg)
arostm 0:4af3ca173992 728 {
arostm 0:4af3ca173992 729 /* Write 16-bit Index, then Write Reg */
arostm 0:4af3ca173992 730 FMC_BANK3_WriteReg(Reg);
arostm 0:4af3ca173992 731 }
arostm 0:4af3ca173992 732
arostm 0:4af3ca173992 733 /**
arostm 0:4af3ca173992 734 * @brief Reads data from LCD data register.
arostm 0:4af3ca173992 735 * @retval Read data.
arostm 0:4af3ca173992 736 */
arostm 0:4af3ca173992 737 uint16_t LCD_IO_ReadData(void)
arostm 0:4af3ca173992 738 {
arostm 0:4af3ca173992 739 return FMC_BANK3_ReadData();
arostm 0:4af3ca173992 740 }
arostm 0:4af3ca173992 741
arostm 0:4af3ca173992 742 /**
arostm 0:4af3ca173992 743 * @brief LCD delay
arostm 0:4af3ca173992 744 * @param Delay: Delay in ms
arostm 0:4af3ca173992 745 */
arostm 0:4af3ca173992 746 void LCD_IO_Delay(uint32_t Delay)
arostm 0:4af3ca173992 747 {
arostm 0:4af3ca173992 748 HAL_Delay(Delay);
arostm 0:4af3ca173992 749 }
arostm 0:4af3ca173992 750
arostm 0:4af3ca173992 751 /********************************* LINK AUDIO *********************************/
arostm 0:4af3ca173992 752
arostm 0:4af3ca173992 753 /**
arostm 0:4af3ca173992 754 * @brief Initializes Audio low level.
arostm 0:4af3ca173992 755 */
arostm 0:4af3ca173992 756 void AUDIO_IO_Init(void)
arostm 0:4af3ca173992 757 {
arostm 0:4af3ca173992 758 FMPI2Cx_Init(&hI2cAudioHandler);
arostm 0:4af3ca173992 759 }
arostm 0:4af3ca173992 760
arostm 0:4af3ca173992 761 /**
arostm 0:4af3ca173992 762 * @brief Deinitializes Audio low level.
arostm 0:4af3ca173992 763 */
arostm 0:4af3ca173992 764 void AUDIO_IO_DeInit(void)
arostm 0:4af3ca173992 765 {
arostm 0:4af3ca173992 766 FMPI2Cx_DeInit(&hI2cAudioHandler);
arostm 0:4af3ca173992 767 }
arostm 0:4af3ca173992 768
arostm 0:4af3ca173992 769 /**
arostm 0:4af3ca173992 770 * @brief Writes a single data.
arostm 0:4af3ca173992 771 * @param Addr: I2C address
arostm 0:4af3ca173992 772 * @param Reg: Reg address
arostm 0:4af3ca173992 773 * @param Value: Data to be written
arostm 0:4af3ca173992 774 */
arostm 0:4af3ca173992 775 void AUDIO_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value)
arostm 0:4af3ca173992 776 {
arostm 0:4af3ca173992 777 uint16_t tmp = Value;
arostm 0:4af3ca173992 778
arostm 0:4af3ca173992 779 Value = ((uint16_t)(tmp >> 8) & 0x00FF);
arostm 0:4af3ca173992 780
arostm 0:4af3ca173992 781 Value |= ((uint16_t)(tmp << 8)& 0xFF00);
arostm 0:4af3ca173992 782
arostm 0:4af3ca173992 783 FMPI2Cx_WriteMultiple(&hI2cAudioHandler, Addr, Reg, FMPI2C_MEMADD_SIZE_16BIT,(uint8_t*)&Value, 2);
arostm 0:4af3ca173992 784 }
arostm 0:4af3ca173992 785
arostm 0:4af3ca173992 786 /**
arostm 0:4af3ca173992 787 * @brief Reads a single data.
arostm 0:4af3ca173992 788 * @param Addr: I2C address
arostm 0:4af3ca173992 789 * @param Reg: Reg address
arostm 0:4af3ca173992 790 * @retval Data to be read
arostm 0:4af3ca173992 791 */
arostm 0:4af3ca173992 792 uint16_t AUDIO_IO_Read(uint8_t Addr, uint16_t Reg)
arostm 0:4af3ca173992 793 {
arostm 0:4af3ca173992 794 uint16_t read_value = 0, tmp = 0;
arostm 0:4af3ca173992 795
arostm 0:4af3ca173992 796 FMPI2Cx_ReadMultiple(&hI2cAudioHandler, Addr, Reg, FMPI2C_MEMADD_SIZE_16BIT, (uint8_t*)&read_value, 2);
arostm 0:4af3ca173992 797
arostm 0:4af3ca173992 798 tmp = ((uint16_t)(read_value >> 8) & 0x00FF);
arostm 0:4af3ca173992 799
arostm 0:4af3ca173992 800 tmp |= ((uint16_t)(read_value << 8)& 0xFF00);
arostm 0:4af3ca173992 801
arostm 0:4af3ca173992 802 read_value = tmp;
arostm 0:4af3ca173992 803
arostm 0:4af3ca173992 804 return read_value;
arostm 0:4af3ca173992 805 }
arostm 0:4af3ca173992 806
arostm 0:4af3ca173992 807 /**
arostm 0:4af3ca173992 808 * @brief Reads multiple data with I2C communication
arostm 0:4af3ca173992 809 * channel from TouchScreen.
arostm 0:4af3ca173992 810 * @param Addr: I2C address
arostm 0:4af3ca173992 811 * @param Reg: Register address
arostm 0:4af3ca173992 812 * @param Buffer: Pointer to data buffer
arostm 0:4af3ca173992 813 * @param Length: Length of the data
arostm 0:4af3ca173992 814 * @retval Number of read data
arostm 0:4af3ca173992 815 */
arostm 0:4af3ca173992 816 uint16_t TS_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
arostm 0:4af3ca173992 817 {
arostm 0:4af3ca173992 818 return FMPI2Cx_ReadMultiple(&hI2cAudioHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
arostm 0:4af3ca173992 819 }
arostm 0:4af3ca173992 820
arostm 0:4af3ca173992 821 /**
arostm 0:4af3ca173992 822 * @brief Writes multiple data with I2C communication
arostm 0:4af3ca173992 823 * channel from MCU to TouchScreen.
arostm 0:4af3ca173992 824 * @param Addr: I2C address
arostm 0:4af3ca173992 825 * @param Reg: Register address
arostm 0:4af3ca173992 826 * @param Buffer: Pointer to data buffer
arostm 0:4af3ca173992 827 * @param Length: Length of the data
arostm 0:4af3ca173992 828 */
arostm 0:4af3ca173992 829 void TS_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
arostm 0:4af3ca173992 830 {
arostm 0:4af3ca173992 831 FMPI2Cx_WriteMultiple(&hI2cAudioHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
arostm 0:4af3ca173992 832 }
arostm 0:4af3ca173992 833
arostm 0:4af3ca173992 834 /**
arostm 0:4af3ca173992 835 * @brief AUDIO Codec delay
arostm 0:4af3ca173992 836 * @param Delay: Delay in ms
arostm 0:4af3ca173992 837 */
arostm 0:4af3ca173992 838 void AUDIO_IO_Delay(uint32_t Delay)
arostm 0:4af3ca173992 839 {
arostm 0:4af3ca173992 840 HAL_Delay(Delay);
arostm 0:4af3ca173992 841 }
arostm 0:4af3ca173992 842
arostm 0:4af3ca173992 843 /******************************** LINK TS (TouchScreen) *****************************/
arostm 0:4af3ca173992 844
arostm 0:4af3ca173992 845 /**
arostm 0:4af3ca173992 846 * @brief Initializes TS low level.
arostm 0:4af3ca173992 847 */
arostm 0:4af3ca173992 848 void TS_IO_Init(void)
arostm 0:4af3ca173992 849 {
arostm 0:4af3ca173992 850 GPIO_InitTypeDef gpio_init_structure;
arostm 0:4af3ca173992 851
arostm 0:4af3ca173992 852 TS_RESET_GPIO_CLK_ENABLE();
arostm 0:4af3ca173992 853
arostm 0:4af3ca173992 854 /* Configure Button pin as input */
arostm 0:4af3ca173992 855 gpio_init_structure.Pin = TS_RESET_PIN;
arostm 0:4af3ca173992 856 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
arostm 0:4af3ca173992 857 gpio_init_structure.Pull = GPIO_NOPULL;
arostm 0:4af3ca173992 858 gpio_init_structure.Speed = GPIO_SPEED_FREQ_LOW;
arostm 0:4af3ca173992 859 HAL_GPIO_Init(TS_RESET_GPIO_PORT, &gpio_init_structure);
arostm 0:4af3ca173992 860
arostm 0:4af3ca173992 861 FMPI2Cx_Init(&hI2cAudioHandler);
arostm 0:4af3ca173992 862 }
arostm 0:4af3ca173992 863
arostm 0:4af3ca173992 864 /**
arostm 0:4af3ca173992 865 * @brief Deinitializes TS low level.
arostm 0:4af3ca173992 866 */
arostm 0:4af3ca173992 867 void TS_IO_DeInit(void)
arostm 0:4af3ca173992 868 {
arostm 0:4af3ca173992 869 FMPI2Cx_DeInit(&hI2cAudioHandler);
arostm 0:4af3ca173992 870 }
arostm 0:4af3ca173992 871
arostm 0:4af3ca173992 872 /**
arostm 0:4af3ca173992 873 * @brief Reads a single data.
arostm 0:4af3ca173992 874 * @param Addr: I2C address
arostm 0:4af3ca173992 875 * @param Reg: Register address
arostm 0:4af3ca173992 876 * @retval Data to be read
arostm 0:4af3ca173992 877 */
arostm 0:4af3ca173992 878 uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg)
arostm 0:4af3ca173992 879 {
arostm 0:4af3ca173992 880 uint8_t read_value = 0;
arostm 0:4af3ca173992 881
arostm 0:4af3ca173992 882 FMPI2Cx_ReadMultiple(&hI2cAudioHandler, Addr, Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&read_value, 1);
arostm 0:4af3ca173992 883
arostm 0:4af3ca173992 884 return read_value;
arostm 0:4af3ca173992 885 }
arostm 0:4af3ca173992 886
arostm 0:4af3ca173992 887 /**
arostm 0:4af3ca173992 888 * @brief Writes a single data.
arostm 0:4af3ca173992 889 * @param Addr: I2C address
arostm 0:4af3ca173992 890 * @param Reg: Reg address
arostm 0:4af3ca173992 891 * @param Value: Data to be written
arostm 0:4af3ca173992 892 */
arostm 0:4af3ca173992 893 void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
arostm 0:4af3ca173992 894 {
arostm 0:4af3ca173992 895 FMPI2Cx_WriteMultiple(&hI2cAudioHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT,(uint8_t*)&Value, 1);
arostm 0:4af3ca173992 896 }
arostm 0:4af3ca173992 897
arostm 0:4af3ca173992 898 /**
arostm 0:4af3ca173992 899 * @brief Delay function used in TouchScreen low level driver.
arostm 0:4af3ca173992 900 * @param Delay: Delay in ms
arostm 0:4af3ca173992 901 */
arostm 0:4af3ca173992 902 void TS_IO_Delay(uint32_t Delay)
arostm 0:4af3ca173992 903 {
arostm 0:4af3ca173992 904 HAL_Delay(Delay);
arostm 0:4af3ca173992 905 }
arostm 0:4af3ca173992 906
arostm 0:4af3ca173992 907 /**
arostm 0:4af3ca173992 908 * @}
arostm 0:4af3ca173992 909 */
arostm 0:4af3ca173992 910
arostm 0:4af3ca173992 911 /**
arostm 0:4af3ca173992 912 * @}
arostm 0:4af3ca173992 913 */
arostm 0:4af3ca173992 914
arostm 0:4af3ca173992 915 /**
arostm 0:4af3ca173992 916 * @}
arostm 0:4af3ca173992 917 */
arostm 0:4af3ca173992 918
arostm 0:4af3ca173992 919 /**
arostm 0:4af3ca173992 920 * @}
arostm 0:4af3ca173992 921 */
arostm 0:4af3ca173992 922
arostm 0:4af3ca173992 923 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/