Patched for Audio example - Add status check when DFSDM's filter and channel de-init.

Dependents:   DISCO_F413ZH-AUDIO-demo

The base repository is https://os.mbed.com/teams/ST/code/BSP_DISCO_F413ZH/. I've just added workaround patch for Audio-in demo on DISCO_F413ZH board(Microphone U16, U17)

Committer:
Daniel_Lee
Date:
Fri Jan 31 07:17:05 2020 +0000
Revision:
4:c051317d4051
Parent:
3:42b354f5069c
Patched for Audio example;

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