BSP driver for DISCO_L496AG
Dependents: DISCO_L496AG-LCD-prova_1 DISCO_L496AG-LCD-prova_2 DISCO_L496AG-LCD-demo DISCO_L496AG-SRAM-demo
Drivers/BSP/STM32L496G-Discovery/stm32l496g_discovery.c@2:106c7b82e064, 2019-11-20 (annotated)
- Committer:
- Jerome Coutant
- Date:
- Wed Nov 20 16:48:24 2019 +0100
- Revision:
- 2:106c7b82e064
- Parent:
- 1:753810620fe9
Update BSP files with CubeL4 V1.14.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:d83f1c8ca282 | 1 | /** |
bcostm | 0:d83f1c8ca282 | 2 | ****************************************************************************** |
bcostm | 0:d83f1c8ca282 | 3 | * @file stm32l496g_discovery.c |
bcostm | 0:d83f1c8ca282 | 4 | * @author MCD Application Team |
bcostm | 0:d83f1c8ca282 | 5 | * @brief This file provides a set of firmware functions to manage Leds, |
bcostm | 0:d83f1c8ca282 | 6 | * push-button and joystick of STM32L496G-Discovery board (MB1261) |
bcostm | 0:d83f1c8ca282 | 7 | ****************************************************************************** |
bcostm | 0:d83f1c8ca282 | 8 | * @attention |
bcostm | 0:d83f1c8ca282 | 9 | * |
Jerome Coutant
2:106c7b82e064
|
10
|
* <h2><center>© Copyright (c) 2017 STMicroelectronics.
|
|
Jerome Coutant
2:106c7b82e064
|
11
|
* All rights reserved.</center></h2>
|
|
bcostm | 0:d83f1c8ca282 | 12 | * |
Jerome Coutant
2:106c7b82e064
|
13
|
* This software component is licensed by ST under BSD 3-Clause license,
|
|
Jerome Coutant
2:106c7b82e064
|
14
|
* the "License"; You may not use this file except in compliance with the
|
|
Jerome Coutant
2:106c7b82e064
|
15
|
* License. You may obtain a copy of the License at:
|
|
Jerome Coutant
2:106c7b82e064
|
16
|
* opensource.org/licenses/BSD-3-Clause
|
|
bcostm | 0:d83f1c8ca282 | 17 | * |
bcostm | 0:d83f1c8ca282 | 18 | ****************************************************************************** |
bcostm | 0:d83f1c8ca282 | 19 | */ |
bcostm | 0:d83f1c8ca282 | 20 | |
bcostm | 0:d83f1c8ca282 | 21 | /* Includes ------------------------------------------------------------------*/ |
bcostm | 0:d83f1c8ca282 | 22 | #include "stm32l496g_discovery.h" |
bcostm | 0:d83f1c8ca282 | 23 | #include "stm32l496g_discovery_io.h" |
bcostm | 0:d83f1c8ca282 | 24 | #include "stm32l496g_discovery_lcd.h" |
bcostm | 0:d83f1c8ca282 | 25 | |
bcostm | 0:d83f1c8ca282 | 26 | /** @addtogroup BSP |
bcostm | 0:d83f1c8ca282 | 27 | * @{ |
bcostm | 0:d83f1c8ca282 | 28 | */ |
bcostm | 0:d83f1c8ca282 | 29 | |
bcostm | 0:d83f1c8ca282 | 30 | /** @defgroup STM32L496G_DISCOVERY STM32L496G-DISCOVERY |
bcostm | 0:d83f1c8ca282 | 31 | * @{ |
bcostm | 0:d83f1c8ca282 | 32 | */ |
bcostm | 0:d83f1c8ca282 | 33 | |
bcostm | 0:d83f1c8ca282 | 34 | /** @defgroup STM32L496G_DISCOVERY_Common STM32L496G-DISCOVERY Common |
bcostm | 0:d83f1c8ca282 | 35 | * @{ |
bcostm | 0:d83f1c8ca282 | 36 | */ |
bcostm | 0:d83f1c8ca282 | 37 | |
bcostm | 0:d83f1c8ca282 | 38 | /** @defgroup STM32L496G_DISCOVERY_Private_TypesDefinitions Private Types Definitions |
bcostm | 0:d83f1c8ca282 | 39 | * @brief This file provides firmware functions to manage Leds, push-buttons, |
bcostm | 0:d83f1c8ca282 | 40 | * COM ports, SD card on SPI and temperature sensor (TS751) available on |
bcostm | 0:d83f1c8ca282 | 41 | * STM32L496G-DISCOVERY discoveryuation board from STMicroelectronics. |
bcostm | 0:d83f1c8ca282 | 42 | * @{ |
bcostm | 0:d83f1c8ca282 | 43 | */ |
bcostm | 0:d83f1c8ca282 | 44 | |
bcostm | 0:d83f1c8ca282 | 45 | /** |
bcostm | 0:d83f1c8ca282 | 46 | * @} |
bcostm | 0:d83f1c8ca282 | 47 | */ |
bcostm | 0:d83f1c8ca282 | 48 | |
bcostm | 0:d83f1c8ca282 | 49 | /** @defgroup STM32L496G_DISCOVERY_Private_Defines Private Defines |
bcostm | 0:d83f1c8ca282 | 50 | * @{ |
bcostm | 0:d83f1c8ca282 | 51 | */ |
bcostm | 0:d83f1c8ca282 | 52 | |
bcostm | 0:d83f1c8ca282 | 53 | /** |
bcostm | 0:d83f1c8ca282 | 54 | * @brief STM32L496G DISCOVERY BSP Driver version number |
bcostm | 0:d83f1c8ca282 | 55 | */ |
bcostm | 0:d83f1c8ca282 | 56 | #define __STM32L496G_DISCOVERY_BSP_VERSION_MAIN (0x01) /*!< [31:24] main version */ |
bcostm | 0:d83f1c8ca282 | 57 | #define __STM32L496G_DISCOVERY_BSP_VERSION_SUB1 (0x01) /*!< [23:16] sub1 version */ |
Jerome Coutant
2:106c7b82e064
|
58
|
#define __STM32L496G_DISCOVERY_BSP_VERSION_SUB2 (0x02) /*!< [15:8] sub2 version */
|
|
bcostm | 0:d83f1c8ca282 | 59 | #define __STM32L496G_DISCOVERY_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */ |
bcostm | 0:d83f1c8ca282 | 60 | #define __STM32L496G_DISCOVERY_BSP_VERSION ((__STM32L496G_DISCOVERY_BSP_VERSION_MAIN << 24)\ |
bcostm | 0:d83f1c8ca282 | 61 | |(__STM32L496G_DISCOVERY_BSP_VERSION_SUB1 << 16)\ |
bcostm | 0:d83f1c8ca282 | 62 | |(__STM32L496G_DISCOVERY_BSP_VERSION_SUB2 << 8 )\ |
bcostm | 0:d83f1c8ca282 | 63 | |(__STM32L496G_DISCOVERY_BSP_VERSION_RC)) |
bcostm | 0:d83f1c8ca282 | 64 | /** |
bcostm | 0:d83f1c8ca282 | 65 | * @} |
bcostm | 0:d83f1c8ca282 | 66 | */ |
bcostm | 0:d83f1c8ca282 | 67 | |
bcostm | 0:d83f1c8ca282 | 68 | |
bcostm | 0:d83f1c8ca282 | 69 | /** @defgroup STM32L496G_DISCOVERY_Private_Macros Private Macros |
bcostm | 0:d83f1c8ca282 | 70 | * @{ |
bcostm | 0:d83f1c8ca282 | 71 | */ |
bcostm | 0:d83f1c8ca282 | 72 | |
bcostm | 0:d83f1c8ca282 | 73 | /** |
bcostm | 0:d83f1c8ca282 | 74 | * @} |
bcostm | 0:d83f1c8ca282 | 75 | */ |
bcostm | 0:d83f1c8ca282 | 76 | |
bcostm | 0:d83f1c8ca282 | 77 | |
bcostm | 0:d83f1c8ca282 | 78 | /** @defgroup STM32L496G_DISCOVERY_Exported_Variables Exported Variables |
bcostm | 0:d83f1c8ca282 | 79 | * @{ |
bcostm | 0:d83f1c8ca282 | 80 | */ |
bcostm | 0:d83f1c8ca282 | 81 | |
bcostm | 0:d83f1c8ca282 | 82 | /** |
bcostm | 0:d83f1c8ca282 | 83 | * @brief LED variables |
bcostm | 0:d83f1c8ca282 | 84 | */ |
bcostm | 0:d83f1c8ca282 | 85 | const uint16_t LED_PIN[LEDn] = {LED1_PIN, |
bcostm | 0:d83f1c8ca282 | 86 | LED2_PIN |
bcostm | 0:d83f1c8ca282 | 87 | }; |
bcostm | 0:d83f1c8ca282 | 88 | |
bcostm | 0:d83f1c8ca282 | 89 | /** |
bcostm | 0:d83f1c8ca282 | 90 | * @brief JOYSTICK variables |
bcostm | 0:d83f1c8ca282 | 91 | */ |
bcostm | 0:d83f1c8ca282 | 92 | GPIO_TypeDef *JOY_PORT[JOYn] = {SEL_JOY_GPIO_PORT, |
bcostm | 0:d83f1c8ca282 | 93 | LEFT_JOY_GPIO_PORT, |
bcostm | 0:d83f1c8ca282 | 94 | RIGHT_JOY_GPIO_PORT, |
bcostm | 0:d83f1c8ca282 | 95 | DOWN_JOY_GPIO_PORT, |
bcostm | 0:d83f1c8ca282 | 96 | UP_JOY_GPIO_PORT |
bcostm | 0:d83f1c8ca282 | 97 | }; |
bcostm | 0:d83f1c8ca282 | 98 | |
bcostm | 0:d83f1c8ca282 | 99 | const uint16_t JOY_PIN[JOYn] = {SEL_JOY_PIN, |
bcostm | 0:d83f1c8ca282 | 100 | LEFT_JOY_PIN, |
bcostm | 0:d83f1c8ca282 | 101 | RIGHT_JOY_PIN, |
bcostm | 0:d83f1c8ca282 | 102 | DOWN_JOY_PIN, |
bcostm | 0:d83f1c8ca282 | 103 | UP_JOY_PIN |
bcostm | 0:d83f1c8ca282 | 104 | }; |
bcostm | 0:d83f1c8ca282 | 105 | |
bcostm | 0:d83f1c8ca282 | 106 | const uint8_t JOY_IRQn[JOYn] = {SEL_JOY_EXTI_IRQn, |
bcostm | 0:d83f1c8ca282 | 107 | LEFT_JOY_EXTI_IRQn, |
bcostm | 0:d83f1c8ca282 | 108 | RIGHT_JOY_EXTI_IRQn, |
bcostm | 0:d83f1c8ca282 | 109 | DOWN_JOY_EXTI_IRQn, |
bcostm | 0:d83f1c8ca282 | 110 | UP_JOY_EXTI_IRQn |
bcostm | 0:d83f1c8ca282 | 111 | }; |
bcostm | 0:d83f1c8ca282 | 112 | |
bcostm | 0:d83f1c8ca282 | 113 | |
bcostm | 0:d83f1c8ca282 | 114 | /** |
bcostm | 0:d83f1c8ca282 | 115 | * @brief COM port variables |
bcostm | 0:d83f1c8ca282 | 116 | */ |
bcostm | 0:d83f1c8ca282 | 117 | #if defined(HAL_UART_MODULE_ENABLED) |
bcostm | 0:d83f1c8ca282 | 118 | USART_TypeDef* COM_USART[COMn] = {DISCOVERY_COM1}; |
bcostm | 0:d83f1c8ca282 | 119 | GPIO_TypeDef* COM_TX_PORT[COMn] = {DISCOVERY_COM1_TX_GPIO_PORT}; |
bcostm | 0:d83f1c8ca282 | 120 | GPIO_TypeDef* COM_RX_PORT[COMn] = {DISCOVERY_COM1_RX_GPIO_PORT}; |
bcostm | 0:d83f1c8ca282 | 121 | const uint16_t COM_TX_PIN[COMn] = {DISCOVERY_COM1_TX_PIN}; |
bcostm | 0:d83f1c8ca282 | 122 | const uint16_t COM_RX_PIN[COMn] = {DISCOVERY_COM1_RX_PIN}; |
bcostm | 0:d83f1c8ca282 | 123 | const uint16_t COM_TX_AF[COMn] = {DISCOVERY_COM1_TX_AF}; |
bcostm | 0:d83f1c8ca282 | 124 | const uint16_t COM_RX_AF[COMn] = {DISCOVERY_COM1_RX_AF}; |
bcostm | 0:d83f1c8ca282 | 125 | #endif /* HAL_UART_MODULE_ENABLED */ |
bcostm | 0:d83f1c8ca282 | 126 | |
bcostm | 0:d83f1c8ca282 | 127 | |
bcostm | 0:d83f1c8ca282 | 128 | /** |
bcostm | 0:d83f1c8ca282 | 129 | * @brief BUS variables |
bcostm | 0:d83f1c8ca282 | 130 | */ |
bcostm | 0:d83f1c8ca282 | 131 | #if defined(HAL_I2C_MODULE_ENABLED) |
bcostm | 0:d83f1c8ca282 | 132 | uint32_t I2c1Timeout = DISCOVERY_I2C2_TIMEOUT_MAX; /*<! Value of Timeout when I2C1 communication fails */ |
bcostm | 0:d83f1c8ca282 | 133 | uint32_t I2c2Timeout = DISCOVERY_I2C2_TIMEOUT_MAX; /*<! Value of Timeout when I2C2 communication fails */ |
bcostm | 0:d83f1c8ca282 | 134 | uint32_t ts_io_init = 0; |
bcostm | 0:d83f1c8ca282 | 135 | static I2C_HandleTypeDef I2c2Handle = {0}; |
bcostm | 0:d83f1c8ca282 | 136 | static I2C_HandleTypeDef hI2cTSHandler = {0}; /* Touch Screen (Capacitive Touch Panel) Handler */ |
bcostm | 0:d83f1c8ca282 | 137 | static I2C_HandleTypeDef hI2cAudioHandler = {0}; |
bcostm | 0:d83f1c8ca282 | 138 | static I2C_HandleTypeDef hI2cCameraHandler = {0} ; |
bcostm | 0:d83f1c8ca282 | 139 | #endif /* HAL_I2C_MODULE_ENABLED */ |
bcostm | 0:d83f1c8ca282 | 140 | |
bcostm | 0:d83f1c8ca282 | 141 | /** |
bcostm | 0:d83f1c8ca282 | 142 | * @} |
bcostm | 0:d83f1c8ca282 | 143 | */ |
bcostm | 0:d83f1c8ca282 | 144 | |
bcostm | 0:d83f1c8ca282 | 145 | /** @defgroup STM32L496G_DISCOVERY_Private_FunctionPrototypes Private Functions |
bcostm | 0:d83f1c8ca282 | 146 | * @{ |
bcostm | 0:d83f1c8ca282 | 147 | */ |
bcostm | 0:d83f1c8ca282 | 148 | /**************************** Bus functions ************************************/ |
bcostm | 0:d83f1c8ca282 | 149 | /* I2C2 bus function */ |
bcostm | 0:d83f1c8ca282 | 150 | #if defined(HAL_I2C_MODULE_ENABLED) |
bcostm | 0:d83f1c8ca282 | 151 | static void I2C2_MspInit(I2C_HandleTypeDef *hi2c); |
bcostm | 0:d83f1c8ca282 | 152 | static void I2C2_MspDeInit(I2C_HandleTypeDef *hi2c); |
bcostm | 0:d83f1c8ca282 | 153 | static void I2C2_WriteData(uint16_t Addr, uint16_t Reg, uint16_t RegSize, uint8_t Value); |
bcostm | 0:d83f1c8ca282 | 154 | static HAL_StatusTypeDef I2C2_WriteBuffer(uint16_t Addr, uint16_t Reg, uint16_t RegSize, uint8_t *pBuffer, uint16_t Length); |
bcostm | 0:d83f1c8ca282 | 155 | static uint8_t I2C2_ReadData(uint16_t Addr, uint16_t Reg, uint16_t RegSize); |
bcostm | 0:d83f1c8ca282 | 156 | static HAL_StatusTypeDef I2C2_ReadBuffer(uint16_t Addr, uint16_t Reg, uint16_t RegSize, uint8_t *pBuffer, uint16_t Length); |
bcostm | 0:d83f1c8ca282 | 157 | static void I2C2_Error(void); |
bcostm | 0:d83f1c8ca282 | 158 | |
bcostm | 0:d83f1c8ca282 | 159 | #endif/* HAL_I2C_MODULE_ENABLED */ |
bcostm | 0:d83f1c8ca282 | 160 | |
bcostm | 0:d83f1c8ca282 | 161 | |
bcostm | 0:d83f1c8ca282 | 162 | /**************************** Link functions ***********************************/ |
bcostm | 0:d83f1c8ca282 | 163 | #if defined(HAL_I2C_MODULE_ENABLED) |
bcostm | 0:d83f1c8ca282 | 164 | |
bcostm | 0:d83f1c8ca282 | 165 | static void FMC_BANK1_WriteData(uint16_t Data); |
bcostm | 0:d83f1c8ca282 | 166 | static void FMC_BANK1_WriteReg(uint8_t Reg); |
bcostm | 0:d83f1c8ca282 | 167 | static uint16_t FMC_BANK1_ReadData(void); |
bcostm | 0:d83f1c8ca282 | 168 | static void FMC_BANK1_Init(void); |
bcostm | 0:d83f1c8ca282 | 169 | |
bcostm | 0:d83f1c8ca282 | 170 | |
bcostm | 0:d83f1c8ca282 | 171 | /* LCD IO functions */ |
bcostm | 0:d83f1c8ca282 | 172 | void LCD_IO_Init(void); |
bcostm | 0:d83f1c8ca282 | 173 | void LCD_IO_WriteData(uint16_t RegValue); |
bcostm | 0:d83f1c8ca282 | 174 | void LCD_IO_WriteReg(uint8_t Reg); |
bcostm | 0:d83f1c8ca282 | 175 | void LCD_IO_WriteMultipleData(uint16_t *pData, uint32_t Size); |
bcostm | 0:d83f1c8ca282 | 176 | uint16_t LCD_IO_ReadData(void); |
bcostm | 0:d83f1c8ca282 | 177 | void LCD_IO_Delay(uint32_t Delay); |
bcostm | 0:d83f1c8ca282 | 178 | |
Jerome Coutant
2:106c7b82e064
|
179
|
/* Link functions for Audio Codec peripheral */
|
|
bcostm | 0:d83f1c8ca282 | 180 | void AUDIO_IO_Init(void); |
bcostm | 0:d83f1c8ca282 | 181 | void AUDIO_IO_DeInit(void); |
bcostm | 0:d83f1c8ca282 | 182 | void AUDIO_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value); |
bcostm | 0:d83f1c8ca282 | 183 | uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg); |
bcostm | 0:d83f1c8ca282 | 184 | void AUDIO_IO_Delay(uint32_t delay); |
bcostm | 0:d83f1c8ca282 | 185 | |
bcostm | 0:d83f1c8ca282 | 186 | /* TouchScreen (TS) IO functions */ |
bcostm | 0:d83f1c8ca282 | 187 | void TS_IO_Init(void); |
bcostm | 0:d83f1c8ca282 | 188 | void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value); |
bcostm | 0:d83f1c8ca282 | 189 | uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg); |
bcostm | 0:d83f1c8ca282 | 190 | uint16_t TS_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length); |
bcostm | 0:d83f1c8ca282 | 191 | void TS_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length); |
bcostm | 0:d83f1c8ca282 | 192 | void TS_IO_Delay(uint32_t Delay); |
bcostm | 0:d83f1c8ca282 | 193 | |
bcostm | 0:d83f1c8ca282 | 194 | /* CAMERA IO functions */ |
bcostm | 0:d83f1c8ca282 | 195 | void CAMERA_IO_Init(void); |
bcostm | 0:d83f1c8ca282 | 196 | void CAMERA_Delay(uint32_t Delay); |
bcostm | 0:d83f1c8ca282 | 197 | void CAMERA_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value); |
bcostm | 0:d83f1c8ca282 | 198 | uint8_t CAMERA_IO_Read(uint8_t Addr, uint8_t Reg); |
bcostm | 0:d83f1c8ca282 | 199 | |
bcostm | 0:d83f1c8ca282 | 200 | #endif/* HAL_I2C_MODULE_ENABLED */ |
bcostm | 0:d83f1c8ca282 | 201 | |
bcostm | 0:d83f1c8ca282 | 202 | |
bcostm | 0:d83f1c8ca282 | 203 | #if defined(HAL_I2C_MODULE_ENABLED) |
bcostm | 0:d83f1c8ca282 | 204 | /* Link functions IOExpander */ |
bcostm | 0:d83f1c8ca282 | 205 | void IOE_Init(void); |
bcostm | 0:d83f1c8ca282 | 206 | void IOE_ITConfig(void); |
bcostm | 0:d83f1c8ca282 | 207 | void IOE_Delay(uint32_t Delay); |
bcostm | 0:d83f1c8ca282 | 208 | void IOE_Write(uint8_t Addr, uint8_t Reg, uint8_t Value); |
bcostm | 0:d83f1c8ca282 | 209 | uint8_t IOE_Read(uint8_t Addr, uint8_t Reg); |
bcostm | 0:d83f1c8ca282 | 210 | uint16_t IOE_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length); |
bcostm | 0:d83f1c8ca282 | 211 | |
bcostm | 0:d83f1c8ca282 | 212 | /* Link functions for IDD measurment */ |
bcostm | 0:d83f1c8ca282 | 213 | void MFX_IO_Init(void); |
bcostm | 0:d83f1c8ca282 | 214 | void MFX_IO_DeInit(void); |
bcostm | 0:d83f1c8ca282 | 215 | void MFX_IO_ITConfig(void); |
bcostm | 0:d83f1c8ca282 | 216 | void MFX_IO_EnableWakeupPin(void); |
bcostm | 0:d83f1c8ca282 | 217 | void MFX_IO_Wakeup(void); |
bcostm | 0:d83f1c8ca282 | 218 | void MFX_IO_Delay(uint32_t delay); |
bcostm | 0:d83f1c8ca282 | 219 | void MFX_IO_Write(uint16_t addr, uint8_t reg, uint8_t value); |
bcostm | 0:d83f1c8ca282 | 220 | uint8_t MFX_IO_Read(uint16_t addr, uint8_t reg); |
bcostm | 0:d83f1c8ca282 | 221 | void MFX_IO_WriteMultiple(uint16_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length); |
bcostm | 0:d83f1c8ca282 | 222 | uint16_t MFX_IO_ReadMultiple(uint16_t addr, uint8_t reg, uint8_t *buffer, uint16_t length); |
bcostm | 0:d83f1c8ca282 | 223 | |
bcostm | 0:d83f1c8ca282 | 224 | static void I2Cx_Init(I2C_HandleTypeDef *i2c_handler); |
bcostm | 0:d83f1c8ca282 | 225 | |
bcostm | 0:d83f1c8ca282 | 226 | static HAL_StatusTypeDef I2Cx_ReadMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length); |
bcostm | 0:d83f1c8ca282 | 227 | static HAL_StatusTypeDef I2Cx_WriteMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length); |
bcostm | 0:d83f1c8ca282 | 228 | static void I2Cx_Error(I2C_HandleTypeDef *i2c_handler, uint8_t Addr); |
bcostm | 0:d83f1c8ca282 | 229 | |
bcostm | 0:d83f1c8ca282 | 230 | static uint8_t I2C2_isDeviceReady(uint16_t Addr, uint32_t trial); |
bcostm | 0:d83f1c8ca282 | 231 | |
bcostm | 0:d83f1c8ca282 | 232 | #endif/* HAL_I2C_MODULE_ENABLED */ |
bcostm | 0:d83f1c8ca282 | 233 | /** |
bcostm | 0:d83f1c8ca282 | 234 | * @} |
bcostm | 0:d83f1c8ca282 | 235 | */ |
bcostm | 0:d83f1c8ca282 | 236 | |
bcostm | 0:d83f1c8ca282 | 237 | __weak void BSP_ErrorHandler(void) |
bcostm | 0:d83f1c8ca282 | 238 | { |
bcostm | 0:d83f1c8ca282 | 239 | while (1); |
bcostm | 0:d83f1c8ca282 | 240 | } |
bcostm | 0:d83f1c8ca282 | 241 | |
bcostm | 0:d83f1c8ca282 | 242 | /** @defgroup STM32L496G_DISCOVERY_Exported_Functions Exported Functions |
bcostm | 0:d83f1c8ca282 | 243 | * @{ |
bcostm | 0:d83f1c8ca282 | 244 | */ |
bcostm | 0:d83f1c8ca282 | 245 | |
bcostm | 0:d83f1c8ca282 | 246 | /** |
bcostm | 0:d83f1c8ca282 | 247 | * @brief This method returns the STM32L496 DISCOVERY BSP Driver revision |
bcostm | 0:d83f1c8ca282 | 248 | * @retval version : 0xXYZR (8bits for each decimal, R for RC) |
bcostm | 0:d83f1c8ca282 | 249 | */ |
bcostm | 0:d83f1c8ca282 | 250 | uint32_t BSP_GetVersion(void) |
bcostm | 0:d83f1c8ca282 | 251 | { |
bcostm | 0:d83f1c8ca282 | 252 | return __STM32L496G_DISCOVERY_BSP_VERSION; |
bcostm | 0:d83f1c8ca282 | 253 | } |
bcostm | 0:d83f1c8ca282 | 254 | |
bcostm | 0:d83f1c8ca282 | 255 | |
bcostm | 0:d83f1c8ca282 | 256 | |
bcostm | 0:d83f1c8ca282 | 257 | /** |
bcostm | 0:d83f1c8ca282 | 258 | * @brief Configures LED GPIOs. |
bcostm | 0:d83f1c8ca282 | 259 | * @param Led: Specifies the Led to be configured. |
bcostm | 0:d83f1c8ca282 | 260 | * This parameter can be one of following parameters: |
bcostm | 1:753810620fe9 | 261 | * @arg DISCO_LED1 |
bcostm | 1:753810620fe9 | 262 | * @arg DISCO_LED2 |
bcostm | 0:d83f1c8ca282 | 263 | * @retval None |
bcostm | 0:d83f1c8ca282 | 264 | */ |
bcostm | 0:d83f1c8ca282 | 265 | void BSP_LED_Init(Led_TypeDef Led) |
bcostm | 0:d83f1c8ca282 | 266 | { |
bcostm | 0:d83f1c8ca282 | 267 | GPIO_InitTypeDef GPIO_InitStructure; |
bcostm | 0:d83f1c8ca282 | 268 | |
bcostm | 1:753810620fe9 | 269 | if (Led == DISCO_LED2) |
bcostm | 0:d83f1c8ca282 | 270 | { |
bcostm | 0:d83f1c8ca282 | 271 | /* Enable the GPIO_LED clock */ |
bcostm | 0:d83f1c8ca282 | 272 | LED2_GPIO_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 273 | |
bcostm | 0:d83f1c8ca282 | 274 | /* Configure the GPIO_LED pin */ |
bcostm | 0:d83f1c8ca282 | 275 | GPIO_InitStructure.Pin = LED_PIN[Led]; |
bcostm | 0:d83f1c8ca282 | 276 | GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; |
bcostm | 0:d83f1c8ca282 | 277 | GPIO_InitStructure.Pull = GPIO_NOPULL; |
bcostm | 0:d83f1c8ca282 | 278 | GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
bcostm | 0:d83f1c8ca282 | 279 | |
bcostm | 0:d83f1c8ca282 | 280 | HAL_GPIO_Init(LED2_GPIO_PORT, &GPIO_InitStructure); |
bcostm | 0:d83f1c8ca282 | 281 | /* By default, turn off LED */ |
bcostm | 0:d83f1c8ca282 | 282 | HAL_GPIO_WritePin(LED2_GPIO_PORT, GPIO_InitStructure.Pin, GPIO_PIN_SET); |
bcostm | 0:d83f1c8ca282 | 283 | } |
bcostm | 0:d83f1c8ca282 | 284 | else |
bcostm | 0:d83f1c8ca282 | 285 | { |
bcostm | 0:d83f1c8ca282 | 286 | /* Initialize the IO functionalities */ |
bcostm | 0:d83f1c8ca282 | 287 | if (BSP_IO_Init() == IO_ERROR) |
bcostm | 0:d83f1c8ca282 | 288 | { |
bcostm | 0:d83f1c8ca282 | 289 | BSP_ErrorHandler(); |
bcostm | 0:d83f1c8ca282 | 290 | } |
bcostm | 0:d83f1c8ca282 | 291 | |
bcostm | 0:d83f1c8ca282 | 292 | BSP_IO_ConfigPin(LED_PIN[Led], IO_MODE_OUTPUT); |
bcostm | 0:d83f1c8ca282 | 293 | |
bcostm | 0:d83f1c8ca282 | 294 | /* By default, turn off LED */ |
bcostm | 0:d83f1c8ca282 | 295 | BSP_IO_WritePin(LED_PIN[Led], GPIO_PIN_SET); |
bcostm | 0:d83f1c8ca282 | 296 | } |
bcostm | 0:d83f1c8ca282 | 297 | |
bcostm | 0:d83f1c8ca282 | 298 | } |
bcostm | 0:d83f1c8ca282 | 299 | |
bcostm | 0:d83f1c8ca282 | 300 | |
bcostm | 0:d83f1c8ca282 | 301 | /** |
bcostm | 0:d83f1c8ca282 | 302 | * @brief Unconfigures LED GPIOs. |
bcostm | 0:d83f1c8ca282 | 303 | * @param Led: Specifies the Led to be unconfigured. |
bcostm | 0:d83f1c8ca282 | 304 | * This parameter can be one of following parameters: |
bcostm | 1:753810620fe9 | 305 | * @arg DISCO_LED1 |
bcostm | 1:753810620fe9 | 306 | * @arg DISCO_LED2 |
bcostm | 0:d83f1c8ca282 | 307 | * @retval None |
bcostm | 0:d83f1c8ca282 | 308 | */ |
bcostm | 0:d83f1c8ca282 | 309 | void BSP_LED_DeInit(Led_TypeDef Led) |
bcostm | 0:d83f1c8ca282 | 310 | { |
bcostm | 1:753810620fe9 | 311 | if (Led == DISCO_LED2) |
bcostm | 0:d83f1c8ca282 | 312 | { |
bcostm | 0:d83f1c8ca282 | 313 | /* Enable the GPIO_LED clock */ |
bcostm | 0:d83f1c8ca282 | 314 | LED2_GPIO_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 315 | |
bcostm | 0:d83f1c8ca282 | 316 | HAL_GPIO_DeInit(LED2_GPIO_PORT, LED_PIN[Led]); |
bcostm | 0:d83f1c8ca282 | 317 | } |
bcostm | 0:d83f1c8ca282 | 318 | } |
bcostm | 0:d83f1c8ca282 | 319 | |
bcostm | 0:d83f1c8ca282 | 320 | |
bcostm | 0:d83f1c8ca282 | 321 | /** |
bcostm | 0:d83f1c8ca282 | 322 | * @brief Turns selected LED On. |
bcostm | 0:d83f1c8ca282 | 323 | * @param Led: Specifies the Led to be set on. |
bcostm | 0:d83f1c8ca282 | 324 | * This parameter can be one of following parameters: |
bcostm | 1:753810620fe9 | 325 | * @arg DISCO_LED1 |
bcostm | 1:753810620fe9 | 326 | * @arg DISCO_LED2 |
bcostm | 0:d83f1c8ca282 | 327 | * @retval None |
bcostm | 0:d83f1c8ca282 | 328 | */ |
bcostm | 0:d83f1c8ca282 | 329 | void BSP_LED_On(Led_TypeDef Led) |
bcostm | 0:d83f1c8ca282 | 330 | { |
bcostm | 1:753810620fe9 | 331 | if (Led == DISCO_LED2) |
bcostm | 0:d83f1c8ca282 | 332 | { |
bcostm | 0:d83f1c8ca282 | 333 | HAL_GPIO_WritePin(LED2_GPIO_PORT, LED_PIN[Led], GPIO_PIN_RESET); |
bcostm | 0:d83f1c8ca282 | 334 | } |
bcostm | 0:d83f1c8ca282 | 335 | else |
bcostm | 0:d83f1c8ca282 | 336 | { |
bcostm | 0:d83f1c8ca282 | 337 | BSP_IO_WritePin(LED_PIN[Led], GPIO_PIN_RESET); |
bcostm | 0:d83f1c8ca282 | 338 | } |
bcostm | 0:d83f1c8ca282 | 339 | } |
bcostm | 0:d83f1c8ca282 | 340 | |
bcostm | 0:d83f1c8ca282 | 341 | |
bcostm | 0:d83f1c8ca282 | 342 | /** |
bcostm | 0:d83f1c8ca282 | 343 | * @brief Turns selected LED Off. |
bcostm | 0:d83f1c8ca282 | 344 | * @param Led: Specifies the Led to be set off. |
bcostm | 0:d83f1c8ca282 | 345 | * This parameter can be one of following parameters: |
bcostm | 1:753810620fe9 | 346 | * @arg DISCO_LED1 |
bcostm | 1:753810620fe9 | 347 | * @arg DISCO_LED2 |
bcostm | 0:d83f1c8ca282 | 348 | * @retval None |
bcostm | 0:d83f1c8ca282 | 349 | */ |
bcostm | 0:d83f1c8ca282 | 350 | void BSP_LED_Off(Led_TypeDef Led) |
bcostm | 0:d83f1c8ca282 | 351 | { |
bcostm | 1:753810620fe9 | 352 | if (Led == DISCO_LED2) |
bcostm | 0:d83f1c8ca282 | 353 | { |
bcostm | 0:d83f1c8ca282 | 354 | HAL_GPIO_WritePin(LED2_GPIO_PORT, LED_PIN[Led], GPIO_PIN_SET); |
bcostm | 0:d83f1c8ca282 | 355 | } |
bcostm | 0:d83f1c8ca282 | 356 | else |
bcostm | 0:d83f1c8ca282 | 357 | { |
bcostm | 0:d83f1c8ca282 | 358 | BSP_IO_WritePin(LED_PIN[Led], GPIO_PIN_SET); |
bcostm | 0:d83f1c8ca282 | 359 | } |
bcostm | 0:d83f1c8ca282 | 360 | } |
bcostm | 0:d83f1c8ca282 | 361 | |
bcostm | 0:d83f1c8ca282 | 362 | |
bcostm | 0:d83f1c8ca282 | 363 | /** |
bcostm | 0:d83f1c8ca282 | 364 | * @brief Toggles the selected LED. |
bcostm | 0:d83f1c8ca282 | 365 | * @param Led: Specifies the Led to be toggled. |
bcostm | 0:d83f1c8ca282 | 366 | * This parameter can be one of following parameters: |
bcostm | 1:753810620fe9 | 367 | * @arg DISCO_LED1 |
bcostm | 1:753810620fe9 | 368 | * @arg DISCO_LED2 |
bcostm | 0:d83f1c8ca282 | 369 | * @retval None |
bcostm | 0:d83f1c8ca282 | 370 | */ |
bcostm | 0:d83f1c8ca282 | 371 | void BSP_LED_Toggle(Led_TypeDef Led) |
bcostm | 0:d83f1c8ca282 | 372 | { |
bcostm | 1:753810620fe9 | 373 | if (Led == DISCO_LED2) |
bcostm | 0:d83f1c8ca282 | 374 | { |
bcostm | 0:d83f1c8ca282 | 375 | HAL_GPIO_TogglePin(LED2_GPIO_PORT, LED_PIN[Led]); |
bcostm | 0:d83f1c8ca282 | 376 | } |
bcostm | 0:d83f1c8ca282 | 377 | else |
bcostm | 0:d83f1c8ca282 | 378 | { |
bcostm | 0:d83f1c8ca282 | 379 | BSP_IO_TogglePin(LED_PIN[Led]); |
bcostm | 0:d83f1c8ca282 | 380 | } |
bcostm | 0:d83f1c8ca282 | 381 | } |
bcostm | 0:d83f1c8ca282 | 382 | |
bcostm | 0:d83f1c8ca282 | 383 | /** |
bcostm | 0:d83f1c8ca282 | 384 | * @brief Configures all buttons of the joystick in GPIO or EXTI modes. |
bcostm | 0:d83f1c8ca282 | 385 | * @param Joy_Mode: Joystick mode. |
bcostm | 0:d83f1c8ca282 | 386 | * This parameter can be one of the following values: |
bcostm | 0:d83f1c8ca282 | 387 | * @arg JOY_MODE_GPIO: Joystick pins will be used as simple IOs |
bcostm | 0:d83f1c8ca282 | 388 | * @arg JOY_MODE_EXTI: Joystick pins will be connected to EXTI line |
bcostm | 0:d83f1c8ca282 | 389 | * with interrupt generation capability |
bcostm | 0:d83f1c8ca282 | 390 | * @retval HAL_OK: if all initializations are OK. Other value if error. |
bcostm | 0:d83f1c8ca282 | 391 | */ |
bcostm | 0:d83f1c8ca282 | 392 | uint8_t BSP_JOY_Init(JOYMode_TypeDef Joy_Mode) |
bcostm | 0:d83f1c8ca282 | 393 | { |
bcostm | 0:d83f1c8ca282 | 394 | JOYState_TypeDef joykey; |
bcostm | 0:d83f1c8ca282 | 395 | GPIO_InitTypeDef GPIO_InitStruct; |
bcostm | 0:d83f1c8ca282 | 396 | |
bcostm | 0:d83f1c8ca282 | 397 | /* Initialized the Joystick. */ |
bcostm | 0:d83f1c8ca282 | 398 | for (joykey = JOY_SEL; joykey < (JOY_SEL + JOYn) ; joykey++) |
bcostm | 0:d83f1c8ca282 | 399 | { |
bcostm | 0:d83f1c8ca282 | 400 | /* Enable the JOY clock */ |
bcostm | 0:d83f1c8ca282 | 401 | JOYx_GPIO_CLK_ENABLE(joykey); |
bcostm | 0:d83f1c8ca282 | 402 | |
bcostm | 0:d83f1c8ca282 | 403 | GPIO_InitStruct.Pin = JOY_PIN[joykey]; |
bcostm | 0:d83f1c8ca282 | 404 | GPIO_InitStruct.Pull = GPIO_PULLDOWN; |
bcostm | 0:d83f1c8ca282 | 405 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
bcostm | 0:d83f1c8ca282 | 406 | |
bcostm | 0:d83f1c8ca282 | 407 | if (Joy_Mode == JOY_MODE_GPIO) |
bcostm | 0:d83f1c8ca282 | 408 | { |
bcostm | 0:d83f1c8ca282 | 409 | /* Configure Joy pin as input */ |
bcostm | 0:d83f1c8ca282 | 410 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
bcostm | 0:d83f1c8ca282 | 411 | HAL_GPIO_Init(JOY_PORT[joykey], &GPIO_InitStruct); |
bcostm | 0:d83f1c8ca282 | 412 | } |
bcostm | 0:d83f1c8ca282 | 413 | else if (Joy_Mode == JOY_MODE_EXTI) |
bcostm | 0:d83f1c8ca282 | 414 | { |
bcostm | 0:d83f1c8ca282 | 415 | /* Configure Joy pin as input with External interrupt */ |
bcostm | 0:d83f1c8ca282 | 416 | GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; |
bcostm | 0:d83f1c8ca282 | 417 | HAL_GPIO_Init(JOY_PORT[joykey], &GPIO_InitStruct); |
bcostm | 0:d83f1c8ca282 | 418 | /* Enable and set Joy EXTI Interrupt to the lowest priority */ |
bcostm | 0:d83f1c8ca282 | 419 | HAL_NVIC_SetPriority((IRQn_Type)(JOY_IRQn[joykey]), 0x0F, 0x00); |
bcostm | 0:d83f1c8ca282 | 420 | HAL_NVIC_EnableIRQ((IRQn_Type)(JOY_IRQn[joykey])); |
bcostm | 0:d83f1c8ca282 | 421 | } |
bcostm | 0:d83f1c8ca282 | 422 | } |
bcostm | 0:d83f1c8ca282 | 423 | |
bcostm | 0:d83f1c8ca282 | 424 | return HAL_OK; |
bcostm | 0:d83f1c8ca282 | 425 | } |
bcostm | 0:d83f1c8ca282 | 426 | |
bcostm | 0:d83f1c8ca282 | 427 | /** |
bcostm | 0:d83f1c8ca282 | 428 | * @brief Unconfigures all GPIOs used as buttons of the joystick. |
bcostm | 0:d83f1c8ca282 | 429 | * @retval None. |
bcostm | 0:d83f1c8ca282 | 430 | */ |
bcostm | 0:d83f1c8ca282 | 431 | void BSP_JOY_DeInit(void) |
bcostm | 0:d83f1c8ca282 | 432 | { |
bcostm | 0:d83f1c8ca282 | 433 | JOYState_TypeDef joykey; |
bcostm | 0:d83f1c8ca282 | 434 | |
bcostm | 0:d83f1c8ca282 | 435 | /* Initialized the Joystick. */ |
bcostm | 0:d83f1c8ca282 | 436 | for (joykey = JOY_SEL; joykey < (JOY_SEL + JOYn) ; joykey++) |
bcostm | 0:d83f1c8ca282 | 437 | { |
bcostm | 0:d83f1c8ca282 | 438 | /* Enable the JOY clock */ |
bcostm | 0:d83f1c8ca282 | 439 | JOYx_GPIO_CLK_ENABLE(joykey); |
bcostm | 0:d83f1c8ca282 | 440 | |
bcostm | 0:d83f1c8ca282 | 441 | HAL_GPIO_DeInit(JOY_PORT[joykey], JOY_PIN[joykey]); |
bcostm | 0:d83f1c8ca282 | 442 | } |
bcostm | 0:d83f1c8ca282 | 443 | } |
bcostm | 0:d83f1c8ca282 | 444 | |
bcostm | 0:d83f1c8ca282 | 445 | /** |
bcostm | 0:d83f1c8ca282 | 446 | * @brief Returns the current joystick status. |
bcostm | 0:d83f1c8ca282 | 447 | * @retval Code of the joystick key pressed |
bcostm | 0:d83f1c8ca282 | 448 | * This code can be one of the following values: |
bcostm | 0:d83f1c8ca282 | 449 | * @arg JOY_NONE |
bcostm | 0:d83f1c8ca282 | 450 | * @arg JOY_SEL |
bcostm | 0:d83f1c8ca282 | 451 | * @arg JOY_DOWN |
bcostm | 0:d83f1c8ca282 | 452 | * @arg JOY_LEFT |
bcostm | 0:d83f1c8ca282 | 453 | * @arg JOY_RIGHT |
bcostm | 0:d83f1c8ca282 | 454 | * @arg JOY_UP |
bcostm | 0:d83f1c8ca282 | 455 | */ |
bcostm | 0:d83f1c8ca282 | 456 | JOYState_TypeDef BSP_JOY_GetState(void) |
bcostm | 0:d83f1c8ca282 | 457 | { |
bcostm | 0:d83f1c8ca282 | 458 | JOYState_TypeDef joykey; |
bcostm | 0:d83f1c8ca282 | 459 | |
bcostm | 0:d83f1c8ca282 | 460 | for (joykey = JOY_SEL; joykey < (JOY_SEL + JOYn) ; joykey++) |
bcostm | 0:d83f1c8ca282 | 461 | { |
bcostm | 0:d83f1c8ca282 | 462 | if (HAL_GPIO_ReadPin(JOY_PORT[joykey], JOY_PIN[joykey]) == GPIO_PIN_SET) |
bcostm | 0:d83f1c8ca282 | 463 | { |
bcostm | 0:d83f1c8ca282 | 464 | /* Return Code Joystick key pressed */ |
bcostm | 0:d83f1c8ca282 | 465 | return joykey; |
bcostm | 0:d83f1c8ca282 | 466 | } |
bcostm | 0:d83f1c8ca282 | 467 | } |
bcostm | 0:d83f1c8ca282 | 468 | |
bcostm | 0:d83f1c8ca282 | 469 | /* No Joystick key pressed */ |
bcostm | 0:d83f1c8ca282 | 470 | return JOY_NONE; |
bcostm | 0:d83f1c8ca282 | 471 | } |
bcostm | 0:d83f1c8ca282 | 472 | |
bcostm | 0:d83f1c8ca282 | 473 | #if defined(HAL_UART_MODULE_ENABLED) |
bcostm | 0:d83f1c8ca282 | 474 | /** |
bcostm | 0:d83f1c8ca282 | 475 | * @brief Configures COM port. |
bcostm | 0:d83f1c8ca282 | 476 | * @param COM: COM port to be configured. |
bcostm | 0:d83f1c8ca282 | 477 | * This parameter can be one of the following values: |
bcostm | 0:d83f1c8ca282 | 478 | * @arg COM1 |
bcostm | 0:d83f1c8ca282 | 479 | * @param huart: Pointer to a UART_HandleTypeDef structure that contains the |
bcostm | 0:d83f1c8ca282 | 480 | * configuration information for the specified USART peripheral. |
bcostm | 0:d83f1c8ca282 | 481 | */ |
bcostm | 0:d83f1c8ca282 | 482 | void BSP_COM_Init(COM_TypeDef COM, UART_HandleTypeDef *huart) |
bcostm | 0:d83f1c8ca282 | 483 | { |
bcostm | 0:d83f1c8ca282 | 484 | GPIO_InitTypeDef gpio_init_structure; |
bcostm | 0:d83f1c8ca282 | 485 | |
bcostm | 0:d83f1c8ca282 | 486 | /* Enable GPIO clock */ |
bcostm | 0:d83f1c8ca282 | 487 | DISCOVERY_COMx_TX_GPIO_CLK_ENABLE(COM); |
bcostm | 0:d83f1c8ca282 | 488 | DISCOVERY_COMx_RX_GPIO_CLK_ENABLE(COM); |
bcostm | 0:d83f1c8ca282 | 489 | |
bcostm | 0:d83f1c8ca282 | 490 | /* Enable USART clock */ |
bcostm | 0:d83f1c8ca282 | 491 | DISCOVERY_COMx_CLK_ENABLE(COM); |
bcostm | 0:d83f1c8ca282 | 492 | |
bcostm | 0:d83f1c8ca282 | 493 | /* Configure USART Tx as alternate function */ |
bcostm | 0:d83f1c8ca282 | 494 | gpio_init_structure.Pin = COM_TX_PIN[COM]; |
bcostm | 0:d83f1c8ca282 | 495 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
bcostm | 0:d83f1c8ca282 | 496 | gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH; |
bcostm | 0:d83f1c8ca282 | 497 | gpio_init_structure.Pull = GPIO_NOPULL; |
bcostm | 0:d83f1c8ca282 | 498 | gpio_init_structure.Alternate = COM_TX_AF[COM]; |
bcostm | 0:d83f1c8ca282 | 499 | HAL_GPIO_Init(COM_TX_PORT[COM], &gpio_init_structure); |
bcostm | 0:d83f1c8ca282 | 500 | |
bcostm | 0:d83f1c8ca282 | 501 | /* Configure USART Rx as alternate function */ |
bcostm | 0:d83f1c8ca282 | 502 | gpio_init_structure.Pin = COM_RX_PIN[COM]; |
bcostm | 0:d83f1c8ca282 | 503 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
bcostm | 0:d83f1c8ca282 | 504 | gpio_init_structure.Alternate = COM_RX_AF[COM]; |
bcostm | 0:d83f1c8ca282 | 505 | HAL_GPIO_Init(COM_RX_PORT[COM], &gpio_init_structure); |
bcostm | 0:d83f1c8ca282 | 506 | |
bcostm | 0:d83f1c8ca282 | 507 | /* USART configuration */ |
bcostm | 0:d83f1c8ca282 | 508 | huart->Instance = COM_USART[COM]; |
bcostm | 0:d83f1c8ca282 | 509 | HAL_UART_Init(huart); |
bcostm | 0:d83f1c8ca282 | 510 | } |
bcostm | 0:d83f1c8ca282 | 511 | |
bcostm | 0:d83f1c8ca282 | 512 | /** |
bcostm | 0:d83f1c8ca282 | 513 | * @brief DeInit COM port. |
bcostm | 0:d83f1c8ca282 | 514 | * @param COM: COM port to be configured. |
bcostm | 0:d83f1c8ca282 | 515 | * This parameter can be one of the following values: |
bcostm | 0:d83f1c8ca282 | 516 | * @arg COM1 |
bcostm | 0:d83f1c8ca282 | 517 | * @param huart: Pointer to a UART_HandleTypeDef structure that contains the |
bcostm | 0:d83f1c8ca282 | 518 | * configuration information for the specified USART peripheral. |
bcostm | 0:d83f1c8ca282 | 519 | */ |
bcostm | 0:d83f1c8ca282 | 520 | void BSP_COM_DeInit(COM_TypeDef COM, UART_HandleTypeDef *huart) |
bcostm | 0:d83f1c8ca282 | 521 | { |
bcostm | 0:d83f1c8ca282 | 522 | /* USART deinitialization */ |
bcostm | 0:d83f1c8ca282 | 523 | huart->Instance = COM_USART[COM]; |
bcostm | 0:d83f1c8ca282 | 524 | HAL_UART_DeInit(huart); |
bcostm | 0:d83f1c8ca282 | 525 | |
bcostm | 0:d83f1c8ca282 | 526 | /* Disable USART clock */ |
bcostm | 0:d83f1c8ca282 | 527 | DISCOVERY_COMx_CLK_DISABLE(COM); |
bcostm | 0:d83f1c8ca282 | 528 | |
bcostm | 0:d83f1c8ca282 | 529 | /* USART TX/RX pins deinitializations */ |
bcostm | 0:d83f1c8ca282 | 530 | HAL_GPIO_DeInit(COM_TX_PORT[COM], COM_TX_PIN[COM]); |
bcostm | 0:d83f1c8ca282 | 531 | HAL_GPIO_DeInit(COM_RX_PORT[COM], COM_RX_PIN[COM]); |
bcostm | 0:d83f1c8ca282 | 532 | |
bcostm | 0:d83f1c8ca282 | 533 | /* Disable GPIOs clock is left for application */ |
bcostm | 0:d83f1c8ca282 | 534 | } |
bcostm | 0:d83f1c8ca282 | 535 | #endif /* HAL_UART_MODULE_ENABLED */ |
bcostm | 0:d83f1c8ca282 | 536 | |
bcostm | 0:d83f1c8ca282 | 537 | /** |
bcostm | 0:d83f1c8ca282 | 538 | * @} |
bcostm | 0:d83f1c8ca282 | 539 | */ |
bcostm | 0:d83f1c8ca282 | 540 | |
bcostm | 0:d83f1c8ca282 | 541 | /** @defgroup STM32L496G_DISCOVERY_BusOperations_Functions Bus Operations Functions |
bcostm | 0:d83f1c8ca282 | 542 | * @{ |
bcostm | 0:d83f1c8ca282 | 543 | */ |
bcostm | 0:d83f1c8ca282 | 544 | |
bcostm | 0:d83f1c8ca282 | 545 | /******************************************************************************* |
bcostm | 0:d83f1c8ca282 | 546 | BUS OPERATIONS |
bcostm | 0:d83f1c8ca282 | 547 | *******************************************************************************/ |
bcostm | 0:d83f1c8ca282 | 548 | |
bcostm | 0:d83f1c8ca282 | 549 | #if defined(HAL_I2C_MODULE_ENABLED) |
bcostm | 0:d83f1c8ca282 | 550 | /******************************* I2C Routines**********************************/ |
bcostm | 0:d83f1c8ca282 | 551 | /** |
bcostm | 0:d83f1c8ca282 | 552 | * @brief Discovery I2C2 Bus initialization |
bcostm | 0:d83f1c8ca282 | 553 | * @retval None |
bcostm | 0:d83f1c8ca282 | 554 | */ |
bcostm | 0:d83f1c8ca282 | 555 | void I2C2_Init(void) |
bcostm | 0:d83f1c8ca282 | 556 | { |
bcostm | 0:d83f1c8ca282 | 557 | if (HAL_I2C_GetState(&I2c2Handle) == HAL_I2C_STATE_RESET) |
bcostm | 0:d83f1c8ca282 | 558 | { |
bcostm | 0:d83f1c8ca282 | 559 | I2c2Handle.Instance = DISCOVERY_I2C2; |
bcostm | 0:d83f1c8ca282 | 560 | I2c2Handle.Init.Timing = DISCOVERY_I2C2_TIMING; |
bcostm | 0:d83f1c8ca282 | 561 | I2c2Handle.Init.OwnAddress1 = 0x70; |
bcostm | 0:d83f1c8ca282 | 562 | I2c2Handle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; |
bcostm | 0:d83f1c8ca282 | 563 | I2c2Handle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; |
bcostm | 0:d83f1c8ca282 | 564 | I2c2Handle.Init.OwnAddress2 = 0xFF; |
bcostm | 0:d83f1c8ca282 | 565 | I2c2Handle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; |
bcostm | 0:d83f1c8ca282 | 566 | I2c2Handle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; |
bcostm | 0:d83f1c8ca282 | 567 | |
bcostm | 0:d83f1c8ca282 | 568 | /* Init the I2C */ |
bcostm | 0:d83f1c8ca282 | 569 | I2C2_MspInit(&I2c2Handle); |
bcostm | 0:d83f1c8ca282 | 570 | HAL_I2C_Init(&I2c2Handle); |
bcostm | 0:d83f1c8ca282 | 571 | } |
bcostm | 0:d83f1c8ca282 | 572 | } |
bcostm | 0:d83f1c8ca282 | 573 | |
bcostm | 0:d83f1c8ca282 | 574 | /** |
bcostm | 0:d83f1c8ca282 | 575 | * @brief Discovery I2C2 MSP Initialization |
bcostm | 0:d83f1c8ca282 | 576 | * @param hi2c: I2C2 handle |
bcostm | 0:d83f1c8ca282 | 577 | * @retval None |
bcostm | 0:d83f1c8ca282 | 578 | */ |
bcostm | 0:d83f1c8ca282 | 579 | static void I2C2_MspInit(I2C_HandleTypeDef *hi2c) |
bcostm | 0:d83f1c8ca282 | 580 | { |
bcostm | 0:d83f1c8ca282 | 581 | GPIO_InitTypeDef GPIO_InitStructure; |
bcostm | 0:d83f1c8ca282 | 582 | RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStruct; |
bcostm | 0:d83f1c8ca282 | 583 | |
bcostm | 0:d83f1c8ca282 | 584 | if (hi2c->Instance == DISCOVERY_I2C2) |
bcostm | 0:d83f1c8ca282 | 585 | { |
bcostm | 0:d83f1c8ca282 | 586 | /*##-1- Configure the Discovery I2C2 clock source. The clock is derived from the SYSCLK #*/ |
bcostm | 0:d83f1c8ca282 | 587 | RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2C2; |
bcostm | 0:d83f1c8ca282 | 588 | RCC_PeriphCLKInitStruct.I2c2ClockSelection = RCC_I2C2CLKSOURCE_SYSCLK; |
bcostm | 0:d83f1c8ca282 | 589 | HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct); |
bcostm | 0:d83f1c8ca282 | 590 | |
bcostm | 0:d83f1c8ca282 | 591 | /*##-2- Configure the GPIOs ################################################*/ |
bcostm | 0:d83f1c8ca282 | 592 | /* Enable GPIO clock */ |
bcostm | 0:d83f1c8ca282 | 593 | DISCOVERY_I2C2_SDA_GPIO_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 594 | DISCOVERY_I2C2_SCL_GPIO_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 595 | |
bcostm | 0:d83f1c8ca282 | 596 | /* Configure I2C Rx/Tx as alternate function */ |
bcostm | 0:d83f1c8ca282 | 597 | GPIO_InitStructure.Pin = DISCOVERY_I2C2_SCL_PIN; |
bcostm | 0:d83f1c8ca282 | 598 | GPIO_InitStructure.Mode = GPIO_MODE_AF_OD; |
bcostm | 0:d83f1c8ca282 | 599 | GPIO_InitStructure.Pull = /*GPIO_NOPULL*/ GPIO_PULLUP; |
bcostm | 0:d83f1c8ca282 | 600 | GPIO_InitStructure.Speed = /*GPIO_SPEED_MEDIUM*/ GPIO_SPEED_FREQ_VERY_HIGH; |
bcostm | 0:d83f1c8ca282 | 601 | GPIO_InitStructure.Alternate = DISCOVERY_I2C2_SCL_SDA_AF; |
bcostm | 0:d83f1c8ca282 | 602 | HAL_GPIO_Init(DISCOVERY_I2C2_SCL_GPIO_PORT, &GPIO_InitStructure); |
bcostm | 0:d83f1c8ca282 | 603 | GPIO_InitStructure.Pin = DISCOVERY_I2C2_SDA_PIN; |
bcostm | 0:d83f1c8ca282 | 604 | HAL_GPIO_Init(DISCOVERY_I2C2_SDA_GPIO_PORT, &GPIO_InitStructure); |
bcostm | 0:d83f1c8ca282 | 605 | |
bcostm | 0:d83f1c8ca282 | 606 | /*##-3- Configure the Discovery I2C2 peripheral #############################*/ |
bcostm | 0:d83f1c8ca282 | 607 | /* Enable Discovery_I2C2 clock */ |
bcostm | 0:d83f1c8ca282 | 608 | DISCOVERY_I2C2_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 609 | |
bcostm | 0:d83f1c8ca282 | 610 | /* Force and release the I2C Peripheral Clock Reset */ |
bcostm | 0:d83f1c8ca282 | 611 | DISCOVERY_I2C2_FORCE_RESET(); |
bcostm | 0:d83f1c8ca282 | 612 | DISCOVERY_I2C2_RELEASE_RESET(); |
bcostm | 0:d83f1c8ca282 | 613 | |
bcostm | 0:d83f1c8ca282 | 614 | /* Enable and set Discovery I2C2 Interrupt to the highest priority */ |
bcostm | 0:d83f1c8ca282 | 615 | HAL_NVIC_SetPriority(DISCOVERY_I2C2_EV_IRQn, 0x00, 0); |
bcostm | 0:d83f1c8ca282 | 616 | HAL_NVIC_EnableIRQ(DISCOVERY_I2C2_EV_IRQn); |
bcostm | 0:d83f1c8ca282 | 617 | |
bcostm | 0:d83f1c8ca282 | 618 | /* Enable and set Discovery I2C2 Interrupt to the highest priority */ |
bcostm | 0:d83f1c8ca282 | 619 | HAL_NVIC_SetPriority(DISCOVERY_I2C2_ER_IRQn, 0x00, 0); |
bcostm | 0:d83f1c8ca282 | 620 | HAL_NVIC_EnableIRQ(DISCOVERY_I2C2_ER_IRQn); |
bcostm | 0:d83f1c8ca282 | 621 | } |
bcostm | 0:d83f1c8ca282 | 622 | } |
bcostm | 0:d83f1c8ca282 | 623 | |
bcostm | 0:d83f1c8ca282 | 624 | /** |
bcostm | 0:d83f1c8ca282 | 625 | * @brief Discovery I2C2 Bus Deinitialization |
bcostm | 0:d83f1c8ca282 | 626 | * @retval None |
bcostm | 0:d83f1c8ca282 | 627 | */ |
bcostm | 0:d83f1c8ca282 | 628 | void I2C2_DeInit(void) |
bcostm | 0:d83f1c8ca282 | 629 | { |
bcostm | 0:d83f1c8ca282 | 630 | if (HAL_I2C_GetState(&I2c2Handle) != HAL_I2C_STATE_RESET) |
bcostm | 0:d83f1c8ca282 | 631 | { |
bcostm | 0:d83f1c8ca282 | 632 | /* DeInit the I2C */ |
bcostm | 0:d83f1c8ca282 | 633 | HAL_I2C_DeInit(&I2c2Handle); |
bcostm | 0:d83f1c8ca282 | 634 | I2C2_MspDeInit(&I2c2Handle); |
bcostm | 0:d83f1c8ca282 | 635 | } |
bcostm | 0:d83f1c8ca282 | 636 | } |
bcostm | 0:d83f1c8ca282 | 637 | |
bcostm | 0:d83f1c8ca282 | 638 | /** |
bcostm | 0:d83f1c8ca282 | 639 | * @brief Discovery I2C2 MSP DeInitialization |
bcostm | 0:d83f1c8ca282 | 640 | * @param hi2c: I2C2 handle |
bcostm | 0:d83f1c8ca282 | 641 | * @retval None |
bcostm | 0:d83f1c8ca282 | 642 | */ |
bcostm | 0:d83f1c8ca282 | 643 | static void I2C2_MspDeInit(I2C_HandleTypeDef *hi2c) |
bcostm | 0:d83f1c8ca282 | 644 | { |
bcostm | 0:d83f1c8ca282 | 645 | if (hi2c->Instance == DISCOVERY_I2C2) |
bcostm | 0:d83f1c8ca282 | 646 | { |
bcostm | 0:d83f1c8ca282 | 647 | /*##-1- Unconfigure the GPIOs ################################################*/ |
bcostm | 0:d83f1c8ca282 | 648 | /* Enable GPIO clock */ |
bcostm | 0:d83f1c8ca282 | 649 | DISCOVERY_I2C2_SDA_GPIO_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 650 | DISCOVERY_I2C2_SCL_GPIO_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 651 | |
bcostm | 0:d83f1c8ca282 | 652 | /* Configure I2C Rx/Tx as alternate function */ |
bcostm | 0:d83f1c8ca282 | 653 | HAL_GPIO_DeInit(DISCOVERY_I2C2_SCL_GPIO_PORT, DISCOVERY_I2C2_SCL_PIN); |
bcostm | 0:d83f1c8ca282 | 654 | HAL_GPIO_DeInit(DISCOVERY_I2C2_SDA_GPIO_PORT, DISCOVERY_I2C2_SDA_PIN); |
bcostm | 0:d83f1c8ca282 | 655 | |
bcostm | 0:d83f1c8ca282 | 656 | /*##-2- Unconfigure the Discovery I2C2 peripheral ############################*/ |
bcostm | 0:d83f1c8ca282 | 657 | /* Force and release I2C Peripheral */ |
bcostm | 0:d83f1c8ca282 | 658 | DISCOVERY_I2C2_FORCE_RESET(); |
bcostm | 0:d83f1c8ca282 | 659 | DISCOVERY_I2C2_RELEASE_RESET(); |
bcostm | 0:d83f1c8ca282 | 660 | |
bcostm | 0:d83f1c8ca282 | 661 | /* Disable Discovery I2C2 clock */ |
bcostm | 0:d83f1c8ca282 | 662 | DISCOVERY_I2C2_CLK_DISABLE(); |
bcostm | 0:d83f1c8ca282 | 663 | |
bcostm | 0:d83f1c8ca282 | 664 | /* Disable Discovery I2C2 interrupts */ |
bcostm | 0:d83f1c8ca282 | 665 | HAL_NVIC_DisableIRQ(DISCOVERY_I2C2_EV_IRQn); |
bcostm | 0:d83f1c8ca282 | 666 | HAL_NVIC_DisableIRQ(DISCOVERY_I2C2_ER_IRQn); |
bcostm | 0:d83f1c8ca282 | 667 | } |
bcostm | 0:d83f1c8ca282 | 668 | } |
bcostm | 0:d83f1c8ca282 | 669 | |
bcostm | 0:d83f1c8ca282 | 670 | /** |
bcostm | 0:d83f1c8ca282 | 671 | * @brief Write a value in a register of the device through BUS. |
bcostm | 0:d83f1c8ca282 | 672 | * @param Addr: Device address on BUS Bus. |
bcostm | 0:d83f1c8ca282 | 673 | * @param Reg: The target register address to write |
bcostm | 0:d83f1c8ca282 | 674 | * @param RegSize: The target register size (can be 8BIT or 16BIT) |
bcostm | 0:d83f1c8ca282 | 675 | * @param Value: The target register value to be written |
bcostm | 0:d83f1c8ca282 | 676 | * @retval None |
bcostm | 0:d83f1c8ca282 | 677 | */ |
bcostm | 0:d83f1c8ca282 | 678 | static void I2C2_WriteData(uint16_t Addr, uint16_t Reg, uint16_t RegSize, uint8_t Value) |
bcostm | 0:d83f1c8ca282 | 679 | { |
bcostm | 0:d83f1c8ca282 | 680 | HAL_StatusTypeDef status = HAL_OK; |
bcostm | 0:d83f1c8ca282 | 681 | |
bcostm | 0:d83f1c8ca282 | 682 | __disable_irq(); |
bcostm | 0:d83f1c8ca282 | 683 | |
bcostm | 0:d83f1c8ca282 | 684 | status = HAL_I2C_Mem_Write(&I2c2Handle, Addr, (uint16_t)Reg, RegSize, &Value, 1, I2c2Timeout); |
bcostm | 0:d83f1c8ca282 | 685 | |
bcostm | 0:d83f1c8ca282 | 686 | __enable_irq(); |
bcostm | 0:d83f1c8ca282 | 687 | |
bcostm | 0:d83f1c8ca282 | 688 | |
bcostm | 0:d83f1c8ca282 | 689 | /* Check the communication status */ |
bcostm | 0:d83f1c8ca282 | 690 | if (status != HAL_OK) |
bcostm | 0:d83f1c8ca282 | 691 | { |
bcostm | 0:d83f1c8ca282 | 692 | /* Re-Initiaize the BUS */ |
bcostm | 0:d83f1c8ca282 | 693 | I2C2_Error(); |
bcostm | 0:d83f1c8ca282 | 694 | } |
bcostm | 0:d83f1c8ca282 | 695 | } |
bcostm | 0:d83f1c8ca282 | 696 | |
bcostm | 0:d83f1c8ca282 | 697 | /** |
bcostm | 0:d83f1c8ca282 | 698 | * @brief Write a value in a register of the device through BUS. |
bcostm | 0:d83f1c8ca282 | 699 | * @param Addr: Device address on BUS Bus. |
bcostm | 0:d83f1c8ca282 | 700 | * @param Reg: The target register address to write |
bcostm | 0:d83f1c8ca282 | 701 | * @param RegSize: The target register size (can be 8BIT or 16BIT) |
bcostm | 0:d83f1c8ca282 | 702 | * @param pBuffer: The target register value to be written |
bcostm | 0:d83f1c8ca282 | 703 | * @param Length: buffer size to be written |
bcostm | 0:d83f1c8ca282 | 704 | * @retval None |
bcostm | 0:d83f1c8ca282 | 705 | */ |
bcostm | 0:d83f1c8ca282 | 706 | static HAL_StatusTypeDef I2C2_WriteBuffer(uint16_t Addr, uint16_t Reg, uint16_t RegSize, uint8_t *pBuffer, uint16_t Length) |
bcostm | 0:d83f1c8ca282 | 707 | { |
bcostm | 0:d83f1c8ca282 | 708 | HAL_StatusTypeDef status = HAL_OK; |
bcostm | 0:d83f1c8ca282 | 709 | |
bcostm | 0:d83f1c8ca282 | 710 | __disable_irq(); |
bcostm | 0:d83f1c8ca282 | 711 | |
bcostm | 0:d83f1c8ca282 | 712 | status = HAL_I2C_Mem_Write(&I2c2Handle, Addr, (uint16_t)Reg, RegSize, pBuffer, Length, I2c2Timeout); |
bcostm | 0:d83f1c8ca282 | 713 | |
bcostm | 0:d83f1c8ca282 | 714 | __enable_irq(); |
bcostm | 0:d83f1c8ca282 | 715 | |
bcostm | 0:d83f1c8ca282 | 716 | |
bcostm | 0:d83f1c8ca282 | 717 | /* Check the communication status */ |
bcostm | 0:d83f1c8ca282 | 718 | if (status != HAL_OK) |
bcostm | 0:d83f1c8ca282 | 719 | { |
bcostm | 0:d83f1c8ca282 | 720 | /* Re-Initiaize the BUS */ |
bcostm | 0:d83f1c8ca282 | 721 | I2C2_Error(); |
bcostm | 0:d83f1c8ca282 | 722 | } |
bcostm | 0:d83f1c8ca282 | 723 | |
bcostm | 0:d83f1c8ca282 | 724 | return status; |
bcostm | 0:d83f1c8ca282 | 725 | } |
bcostm | 0:d83f1c8ca282 | 726 | |
bcostm | 0:d83f1c8ca282 | 727 | /** |
bcostm | 0:d83f1c8ca282 | 728 | * @brief Read a register of the device through BUS |
bcostm | 0:d83f1c8ca282 | 729 | * @param Addr: Device address on BUS |
bcostm | 0:d83f1c8ca282 | 730 | * @param Reg: The target register address to read |
bcostm | 0:d83f1c8ca282 | 731 | * @param RegSize: The target register size (can be 8BIT or 16BIT) |
bcostm | 0:d83f1c8ca282 | 732 | * @retval read register value |
bcostm | 0:d83f1c8ca282 | 733 | */ |
bcostm | 0:d83f1c8ca282 | 734 | static uint8_t I2C2_ReadData(uint16_t Addr, uint16_t Reg, uint16_t RegSize) |
bcostm | 0:d83f1c8ca282 | 735 | { |
bcostm | 0:d83f1c8ca282 | 736 | HAL_StatusTypeDef status = HAL_OK; |
bcostm | 0:d83f1c8ca282 | 737 | uint8_t value = 0x0; |
bcostm | 0:d83f1c8ca282 | 738 | |
bcostm | 0:d83f1c8ca282 | 739 | __disable_irq(); |
bcostm | 0:d83f1c8ca282 | 740 | |
bcostm | 0:d83f1c8ca282 | 741 | status = HAL_I2C_Mem_Read(&I2c2Handle, Addr, Reg, RegSize, &value, 1, I2c2Timeout); |
bcostm | 0:d83f1c8ca282 | 742 | |
bcostm | 0:d83f1c8ca282 | 743 | __enable_irq(); |
bcostm | 0:d83f1c8ca282 | 744 | |
bcostm | 0:d83f1c8ca282 | 745 | /* Check the communication status */ |
bcostm | 0:d83f1c8ca282 | 746 | if (status != HAL_OK) |
bcostm | 0:d83f1c8ca282 | 747 | { |
bcostm | 0:d83f1c8ca282 | 748 | /* Re-Initiaize the BUS */ |
bcostm | 0:d83f1c8ca282 | 749 | I2C2_Error(); |
bcostm | 0:d83f1c8ca282 | 750 | HAL_Delay(200); |
bcostm | 0:d83f1c8ca282 | 751 | } |
bcostm | 0:d83f1c8ca282 | 752 | |
bcostm | 0:d83f1c8ca282 | 753 | return value; |
bcostm | 0:d83f1c8ca282 | 754 | } |
bcostm | 0:d83f1c8ca282 | 755 | |
bcostm | 0:d83f1c8ca282 | 756 | static uint8_t I2C2_isDeviceReady(uint16_t Addr, uint32_t trial) |
bcostm | 0:d83f1c8ca282 | 757 | { |
bcostm | 0:d83f1c8ca282 | 758 | HAL_StatusTypeDef status = HAL_OK; |
bcostm | 0:d83f1c8ca282 | 759 | uint8_t value = 0x0; |
bcostm | 0:d83f1c8ca282 | 760 | |
bcostm | 0:d83f1c8ca282 | 761 | __disable_irq(); |
bcostm | 0:d83f1c8ca282 | 762 | |
bcostm | 0:d83f1c8ca282 | 763 | status = HAL_I2C_IsDeviceReady(&I2c2Handle, Addr, trial, 50); |
bcostm | 0:d83f1c8ca282 | 764 | |
bcostm | 0:d83f1c8ca282 | 765 | __enable_irq(); |
bcostm | 0:d83f1c8ca282 | 766 | |
bcostm | 0:d83f1c8ca282 | 767 | /* Check the communication status */ |
bcostm | 0:d83f1c8ca282 | 768 | if (status != HAL_OK) |
bcostm | 0:d83f1c8ca282 | 769 | { |
bcostm | 0:d83f1c8ca282 | 770 | /* Re-Initiaize the BUS */ |
bcostm | 0:d83f1c8ca282 | 771 | I2C2_Error(); |
bcostm | 0:d83f1c8ca282 | 772 | HAL_Delay(200); |
bcostm | 0:d83f1c8ca282 | 773 | } |
bcostm | 0:d83f1c8ca282 | 774 | |
bcostm | 0:d83f1c8ca282 | 775 | return value; |
bcostm | 0:d83f1c8ca282 | 776 | } |
bcostm | 0:d83f1c8ca282 | 777 | |
bcostm | 0:d83f1c8ca282 | 778 | /** |
bcostm | 0:d83f1c8ca282 | 779 | * @brief Reads multiple data on the BUS. |
bcostm | 0:d83f1c8ca282 | 780 | * @param Addr: I2C Address |
bcostm | 0:d83f1c8ca282 | 781 | * @param Reg: Reg Address |
bcostm | 0:d83f1c8ca282 | 782 | * @param RegSize : The target register size (can be 8BIT or 16BIT) |
bcostm | 0:d83f1c8ca282 | 783 | * @param pBuffer: pointer to read data buffer |
bcostm | 0:d83f1c8ca282 | 784 | * @param Length: length of the data |
bcostm | 0:d83f1c8ca282 | 785 | * @retval 0 if no problems to read multiple data |
bcostm | 0:d83f1c8ca282 | 786 | */ |
bcostm | 0:d83f1c8ca282 | 787 | static HAL_StatusTypeDef I2C2_ReadBuffer(uint16_t Addr, uint16_t Reg, uint16_t RegSize, uint8_t *pBuffer, uint16_t Length) |
bcostm | 0:d83f1c8ca282 | 788 | { |
bcostm | 0:d83f1c8ca282 | 789 | HAL_StatusTypeDef status = HAL_OK; |
bcostm | 0:d83f1c8ca282 | 790 | |
bcostm | 0:d83f1c8ca282 | 791 | __disable_irq(); |
bcostm | 0:d83f1c8ca282 | 792 | |
bcostm | 0:d83f1c8ca282 | 793 | status = HAL_I2C_Mem_Read(&I2c2Handle, Addr, (uint16_t)Reg, RegSize, pBuffer, Length, I2c2Timeout); |
bcostm | 0:d83f1c8ca282 | 794 | |
bcostm | 0:d83f1c8ca282 | 795 | __enable_irq(); |
bcostm | 0:d83f1c8ca282 | 796 | |
bcostm | 0:d83f1c8ca282 | 797 | /* Check the communication status */ |
bcostm | 0:d83f1c8ca282 | 798 | if (status != HAL_OK) |
bcostm | 0:d83f1c8ca282 | 799 | { |
bcostm | 0:d83f1c8ca282 | 800 | /* Re-Initiaize the BUS */ |
bcostm | 0:d83f1c8ca282 | 801 | I2C2_Error(); |
bcostm | 0:d83f1c8ca282 | 802 | } |
bcostm | 0:d83f1c8ca282 | 803 | |
bcostm | 0:d83f1c8ca282 | 804 | return status; |
bcostm | 0:d83f1c8ca282 | 805 | } |
bcostm | 0:d83f1c8ca282 | 806 | |
bcostm | 0:d83f1c8ca282 | 807 | /** |
bcostm | 0:d83f1c8ca282 | 808 | * @brief Discovery I2C2 error treatment function |
bcostm | 0:d83f1c8ca282 | 809 | * @retval None |
bcostm | 0:d83f1c8ca282 | 810 | */ |
bcostm | 0:d83f1c8ca282 | 811 | static void I2C2_Error(void) |
bcostm | 0:d83f1c8ca282 | 812 | { |
bcostm | 0:d83f1c8ca282 | 813 | BSP_ErrorHandler(); |
bcostm | 0:d83f1c8ca282 | 814 | |
bcostm | 0:d83f1c8ca282 | 815 | /* De-initialize the I2C communication BUS */ |
bcostm | 0:d83f1c8ca282 | 816 | HAL_I2C_DeInit(&I2c2Handle); |
bcostm | 0:d83f1c8ca282 | 817 | |
bcostm | 0:d83f1c8ca282 | 818 | /* Re- Initiaize the I2C communication BUS */ |
bcostm | 0:d83f1c8ca282 | 819 | I2C2_Init(); |
bcostm | 0:d83f1c8ca282 | 820 | } |
bcostm | 0:d83f1c8ca282 | 821 | |
bcostm | 0:d83f1c8ca282 | 822 | |
bcostm | 0:d83f1c8ca282 | 823 | |
bcostm | 0:d83f1c8ca282 | 824 | /******************************* I2C Routines *********************************/ |
bcostm | 0:d83f1c8ca282 | 825 | /** |
bcostm | 0:d83f1c8ca282 | 826 | * @brief Initializes I2C HAL. |
bcostm | 0:d83f1c8ca282 | 827 | * @param i2c_handler : I2C handler |
bcostm | 0:d83f1c8ca282 | 828 | * @retval None |
bcostm | 0:d83f1c8ca282 | 829 | */ |
bcostm | 0:d83f1c8ca282 | 830 | static void I2Cx_Init(I2C_HandleTypeDef *i2c_handler) |
bcostm | 0:d83f1c8ca282 | 831 | { |
bcostm | 0:d83f1c8ca282 | 832 | |
bcostm | 0:d83f1c8ca282 | 833 | if (HAL_I2C_GetState(i2c_handler) == HAL_I2C_STATE_RESET) |
bcostm | 0:d83f1c8ca282 | 834 | { |
bcostm | 0:d83f1c8ca282 | 835 | if (i2c_handler == (I2C_HandleTypeDef *)(&hI2cTSHandler)) |
bcostm | 0:d83f1c8ca282 | 836 | { |
bcostm | 0:d83f1c8ca282 | 837 | /* TS (Capacitive Touch Panel) and LCD I2C configuration */ |
bcostm | 0:d83f1c8ca282 | 838 | i2c_handler->Instance = DISCOVERY_TS_I2Cx; |
bcostm | 0:d83f1c8ca282 | 839 | |
bcostm | 0:d83f1c8ca282 | 840 | /* Need to enable MFX, and in doing so, initialize I2C at the same time */ |
bcostm | 0:d83f1c8ca282 | 841 | /* MFX_IO_Init();*/ |
bcostm | 0:d83f1c8ca282 | 842 | |
bcostm | 0:d83f1c8ca282 | 843 | } |
bcostm | 0:d83f1c8ca282 | 844 | else if (i2c_handler == (I2C_HandleTypeDef *)(&hI2cAudioHandler)) |
bcostm | 0:d83f1c8ca282 | 845 | { |
bcostm | 0:d83f1c8ca282 | 846 | /* Audio and LCD I2C configuration */ |
bcostm | 0:d83f1c8ca282 | 847 | i2c_handler->Instance = DISCOVERY_AUDIO_I2Cx; |
bcostm | 0:d83f1c8ca282 | 848 | } |
bcostm | 0:d83f1c8ca282 | 849 | else if (i2c_handler == (I2C_HandleTypeDef *)(&hI2cCameraHandler)) |
bcostm | 0:d83f1c8ca282 | 850 | { |
bcostm | 0:d83f1c8ca282 | 851 | i2c_handler->Instance = DISCOVERY_CAMERA_I2Cx; |
bcostm | 0:d83f1c8ca282 | 852 | } |
bcostm | 0:d83f1c8ca282 | 853 | else |
bcostm | 0:d83f1c8ca282 | 854 | { |
bcostm | 0:d83f1c8ca282 | 855 | /* External, EEPROM and Arduino connector I2C configuration */ |
bcostm | 0:d83f1c8ca282 | 856 | i2c_handler->Instance = DISCOVERY_EXT_I2Cx; |
bcostm | 0:d83f1c8ca282 | 857 | } |
bcostm | 0:d83f1c8ca282 | 858 | |
bcostm | 0:d83f1c8ca282 | 859 | i2c_handler->Init.Timing = DISCOVERY_I2C_TIMING; |
bcostm | 0:d83f1c8ca282 | 860 | i2c_handler->Init.OwnAddress1 = 0x70; |
bcostm | 0:d83f1c8ca282 | 861 | i2c_handler->Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; |
bcostm | 0:d83f1c8ca282 | 862 | i2c_handler->Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; |
bcostm | 0:d83f1c8ca282 | 863 | i2c_handler->Init.OwnAddress2 = 0xFF; |
bcostm | 0:d83f1c8ca282 | 864 | i2c_handler->Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; |
bcostm | 0:d83f1c8ca282 | 865 | i2c_handler->Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; |
bcostm | 0:d83f1c8ca282 | 866 | |
bcostm | 0:d83f1c8ca282 | 867 | |
bcostm | 0:d83f1c8ca282 | 868 | /* Init the I2C */ |
bcostm | 0:d83f1c8ca282 | 869 | HAL_I2C_Init(i2c_handler); |
bcostm | 0:d83f1c8ca282 | 870 | |
bcostm | 0:d83f1c8ca282 | 871 | } |
bcostm | 0:d83f1c8ca282 | 872 | |
bcostm | 0:d83f1c8ca282 | 873 | } |
bcostm | 0:d83f1c8ca282 | 874 | |
bcostm | 0:d83f1c8ca282 | 875 | /** |
bcostm | 0:d83f1c8ca282 | 876 | * @brief Reads multiple data. |
bcostm | 0:d83f1c8ca282 | 877 | * @param i2c_handler : I2C handler |
bcostm | 0:d83f1c8ca282 | 878 | * @param Addr: I2C address |
bcostm | 0:d83f1c8ca282 | 879 | * @param Reg: Reg address |
bcostm | 0:d83f1c8ca282 | 880 | * @param MemAddress: Memory address |
bcostm | 0:d83f1c8ca282 | 881 | * @param Buffer: Pointer to data buffer |
bcostm | 0:d83f1c8ca282 | 882 | * @param Length: Length of the data |
bcostm | 0:d83f1c8ca282 | 883 | * @retval Number of read data |
bcostm | 0:d83f1c8ca282 | 884 | */ |
bcostm | 0:d83f1c8ca282 | 885 | static HAL_StatusTypeDef I2Cx_ReadMultiple(I2C_HandleTypeDef *i2c_handler, |
bcostm | 0:d83f1c8ca282 | 886 | uint8_t Addr, |
bcostm | 0:d83f1c8ca282 | 887 | uint16_t Reg, |
bcostm | 0:d83f1c8ca282 | 888 | uint16_t MemAddress, |
bcostm | 0:d83f1c8ca282 | 889 | uint8_t *Buffer, |
bcostm | 0:d83f1c8ca282 | 890 | uint16_t Length) |
bcostm | 0:d83f1c8ca282 | 891 | { |
bcostm | 0:d83f1c8ca282 | 892 | HAL_StatusTypeDef status = HAL_OK; |
bcostm | 0:d83f1c8ca282 | 893 | |
bcostm | 0:d83f1c8ca282 | 894 | status = HAL_I2C_Mem_Read(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000); |
bcostm | 0:d83f1c8ca282 | 895 | |
bcostm | 0:d83f1c8ca282 | 896 | /* Check the communication status */ |
bcostm | 0:d83f1c8ca282 | 897 | if (status != HAL_OK) |
bcostm | 0:d83f1c8ca282 | 898 | { |
bcostm | 0:d83f1c8ca282 | 899 | /* I2C error occurred */ |
bcostm | 0:d83f1c8ca282 | 900 | I2Cx_Error(i2c_handler, Addr); |
bcostm | 0:d83f1c8ca282 | 901 | } |
bcostm | 0:d83f1c8ca282 | 902 | return status; |
bcostm | 0:d83f1c8ca282 | 903 | } |
bcostm | 0:d83f1c8ca282 | 904 | |
bcostm | 0:d83f1c8ca282 | 905 | /** |
bcostm | 0:d83f1c8ca282 | 906 | * @brief Writes a value in a register of the device through BUS in using DMA mode. |
bcostm | 0:d83f1c8ca282 | 907 | * @param i2c_handler : I2C handler |
bcostm | 0:d83f1c8ca282 | 908 | * @param Addr: Device address on BUS Bus. |
bcostm | 0:d83f1c8ca282 | 909 | * @param Reg: The target register address to write |
bcostm | 0:d83f1c8ca282 | 910 | * @param MemAddress: Memory address |
bcostm | 0:d83f1c8ca282 | 911 | * @param Buffer: The target register value to be written |
bcostm | 0:d83f1c8ca282 | 912 | * @param Length: buffer size to be written |
bcostm | 0:d83f1c8ca282 | 913 | * @retval HAL status |
bcostm | 0:d83f1c8ca282 | 914 | */ |
bcostm | 0:d83f1c8ca282 | 915 | static HAL_StatusTypeDef I2Cx_WriteMultiple(I2C_HandleTypeDef *i2c_handler, |
bcostm | 0:d83f1c8ca282 | 916 | uint8_t Addr, |
bcostm | 0:d83f1c8ca282 | 917 | uint16_t Reg, |
bcostm | 0:d83f1c8ca282 | 918 | uint16_t MemAddress, |
bcostm | 0:d83f1c8ca282 | 919 | uint8_t *Buffer, |
bcostm | 0:d83f1c8ca282 | 920 | uint16_t Length) |
bcostm | 0:d83f1c8ca282 | 921 | { |
bcostm | 0:d83f1c8ca282 | 922 | HAL_StatusTypeDef status = HAL_OK; |
bcostm | 0:d83f1c8ca282 | 923 | |
bcostm | 0:d83f1c8ca282 | 924 | status = HAL_I2C_Mem_Write(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000); |
bcostm | 0:d83f1c8ca282 | 925 | |
bcostm | 0:d83f1c8ca282 | 926 | /* Check the communication status */ |
bcostm | 0:d83f1c8ca282 | 927 | if (status != HAL_OK) |
bcostm | 0:d83f1c8ca282 | 928 | { |
bcostm | 0:d83f1c8ca282 | 929 | /* Re-Initialize the I2C Bus */ |
bcostm | 0:d83f1c8ca282 | 930 | I2Cx_Error(i2c_handler, Addr); |
bcostm | 0:d83f1c8ca282 | 931 | } |
bcostm | 0:d83f1c8ca282 | 932 | return status; |
bcostm | 0:d83f1c8ca282 | 933 | } |
bcostm | 0:d83f1c8ca282 | 934 | |
bcostm | 0:d83f1c8ca282 | 935 | /** |
bcostm | 0:d83f1c8ca282 | 936 | * @brief Manages error callback by re-initializing I2C. |
bcostm | 0:d83f1c8ca282 | 937 | * @param i2c_handler : I2C handler |
bcostm | 0:d83f1c8ca282 | 938 | * @param Addr: I2C Address |
bcostm | 0:d83f1c8ca282 | 939 | * @retval None |
bcostm | 0:d83f1c8ca282 | 940 | */ |
bcostm | 0:d83f1c8ca282 | 941 | static void I2Cx_Error(I2C_HandleTypeDef *i2c_handler, uint8_t Addr) |
bcostm | 0:d83f1c8ca282 | 942 | { |
bcostm | 0:d83f1c8ca282 | 943 | BSP_ErrorHandler(); |
bcostm | 0:d83f1c8ca282 | 944 | |
bcostm | 0:d83f1c8ca282 | 945 | /* De-initialize the I2C communication bus */ |
bcostm | 0:d83f1c8ca282 | 946 | if (i2c_handler == (I2C_HandleTypeDef *)(&hI2cTSHandler)) |
bcostm | 0:d83f1c8ca282 | 947 | { |
bcostm | 0:d83f1c8ca282 | 948 | I2C2_DeInit(); |
bcostm | 0:d83f1c8ca282 | 949 | } |
bcostm | 0:d83f1c8ca282 | 950 | else |
bcostm | 0:d83f1c8ca282 | 951 | { |
bcostm | 0:d83f1c8ca282 | 952 | HAL_I2C_DeInit(i2c_handler); |
bcostm | 0:d83f1c8ca282 | 953 | } |
bcostm | 0:d83f1c8ca282 | 954 | |
bcostm | 0:d83f1c8ca282 | 955 | /* Re-Initialize the I2C communication bus */ |
bcostm | 0:d83f1c8ca282 | 956 | I2Cx_Init(i2c_handler); |
bcostm | 0:d83f1c8ca282 | 957 | } |
bcostm | 0:d83f1c8ca282 | 958 | #endif /*HAL_I2C_MODULE_ENABLED*/ |
bcostm | 0:d83f1c8ca282 | 959 | |
bcostm | 0:d83f1c8ca282 | 960 | |
bcostm | 0:d83f1c8ca282 | 961 | /******************************************************************************* |
bcostm | 0:d83f1c8ca282 | 962 | LINK OPERATIONS |
bcostm | 0:d83f1c8ca282 | 963 | *******************************************************************************/ |
bcostm | 0:d83f1c8ca282 | 964 | |
bcostm | 0:d83f1c8ca282 | 965 | #if defined(HAL_I2C_MODULE_ENABLED) |
bcostm | 0:d83f1c8ca282 | 966 | /********************************* LINK MFX ***********************************/ |
bcostm | 0:d83f1c8ca282 | 967 | /** |
bcostm | 0:d83f1c8ca282 | 968 | * @brief Initializes MFX low level. |
bcostm | 0:d83f1c8ca282 | 969 | * @retval None |
bcostm | 0:d83f1c8ca282 | 970 | */ |
bcostm | 0:d83f1c8ca282 | 971 | void MFX_IO_Init(void) |
bcostm | 0:d83f1c8ca282 | 972 | { |
bcostm | 0:d83f1c8ca282 | 973 | /* I2C2 init */ |
bcostm | 0:d83f1c8ca282 | 974 | I2C2_Init(); |
bcostm | 0:d83f1c8ca282 | 975 | |
bcostm | 0:d83f1c8ca282 | 976 | /* Wait for device ready */ |
bcostm | 0:d83f1c8ca282 | 977 | if (I2C2_isDeviceReady(IO1_I2C_ADDRESS, 4) != HAL_OK) |
bcostm | 0:d83f1c8ca282 | 978 | { |
bcostm | 0:d83f1c8ca282 | 979 | BSP_ErrorHandler(); |
bcostm | 0:d83f1c8ca282 | 980 | } |
bcostm | 0:d83f1c8ca282 | 981 | } |
bcostm | 0:d83f1c8ca282 | 982 | /** |
bcostm | 0:d83f1c8ca282 | 983 | * @brief Deinitializes MFX low level. |
bcostm | 0:d83f1c8ca282 | 984 | * @retval None |
bcostm | 0:d83f1c8ca282 | 985 | */ |
bcostm | 0:d83f1c8ca282 | 986 | void MFX_IO_DeInit(void) |
bcostm | 0:d83f1c8ca282 | 987 | { |
bcostm | 0:d83f1c8ca282 | 988 | GPIO_InitTypeDef GPIO_InitStruct; |
bcostm | 0:d83f1c8ca282 | 989 | |
bcostm | 0:d83f1c8ca282 | 990 | /* Enable wakeup gpio clock */ |
bcostm | 0:d83f1c8ca282 | 991 | MFX_WAKEUP_GPIO_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 992 | |
bcostm | 0:d83f1c8ca282 | 993 | /* MFX wakeup pin configuration */ |
bcostm | 0:d83f1c8ca282 | 994 | GPIO_InitStruct.Pin = MFX_WAKEUP_PIN; |
bcostm | 0:d83f1c8ca282 | 995 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
bcostm | 0:d83f1c8ca282 | 996 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
bcostm | 0:d83f1c8ca282 | 997 | GPIO_InitStruct.Pull = GPIO_PULLDOWN; |
bcostm | 0:d83f1c8ca282 | 998 | HAL_GPIO_Init(MFX_WAKEUP_GPIO_PORT, &GPIO_InitStruct); |
bcostm | 0:d83f1c8ca282 | 999 | |
bcostm | 0:d83f1c8ca282 | 1000 | /* DeInit interrupt pin : disable IRQ before to avoid spurious interrupt */ |
bcostm | 0:d83f1c8ca282 | 1001 | HAL_NVIC_DisableIRQ((IRQn_Type)(MFX_INT_EXTI_IRQn)); |
bcostm | 0:d83f1c8ca282 | 1002 | MFX_INT_GPIO_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 1003 | HAL_GPIO_DeInit(MFX_INT_GPIO_PORT, MFX_INT_PIN); |
bcostm | 0:d83f1c8ca282 | 1004 | |
bcostm | 0:d83f1c8ca282 | 1005 | /* I2C2 Deinit */ |
bcostm | 0:d83f1c8ca282 | 1006 | I2C2_DeInit(); |
bcostm | 0:d83f1c8ca282 | 1007 | } |
bcostm | 0:d83f1c8ca282 | 1008 | |
bcostm | 0:d83f1c8ca282 | 1009 | /** |
bcostm | 0:d83f1c8ca282 | 1010 | * @brief Configures MFX low level interrupt. |
bcostm | 0:d83f1c8ca282 | 1011 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1012 | */ |
bcostm | 0:d83f1c8ca282 | 1013 | void MFX_IO_ITConfig(void) |
bcostm | 0:d83f1c8ca282 | 1014 | { |
bcostm | 0:d83f1c8ca282 | 1015 | GPIO_InitTypeDef GPIO_InitStruct; |
bcostm | 0:d83f1c8ca282 | 1016 | |
bcostm | 0:d83f1c8ca282 | 1017 | /* Enable the GPIO clock */ |
bcostm | 0:d83f1c8ca282 | 1018 | MFX_INT_GPIO_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 1019 | |
bcostm | 0:d83f1c8ca282 | 1020 | /* MFX_OUT_IRQ (normally used for EXTI_WKUP) */ |
bcostm | 0:d83f1c8ca282 | 1021 | GPIO_InitStruct.Pin = MFX_INT_PIN; |
bcostm | 0:d83f1c8ca282 | 1022 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
bcostm | 0:d83f1c8ca282 | 1023 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
bcostm | 0:d83f1c8ca282 | 1024 | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; |
bcostm | 0:d83f1c8ca282 | 1025 | HAL_GPIO_Init(MFX_INT_GPIO_PORT, &GPIO_InitStruct); |
bcostm | 0:d83f1c8ca282 | 1026 | |
bcostm | 0:d83f1c8ca282 | 1027 | /* Enable and set GPIO EXTI Interrupt to the lowest priority */ |
bcostm | 0:d83f1c8ca282 | 1028 | HAL_NVIC_SetPriority((IRQn_Type)(MFX_INT_EXTI_IRQn), 0x0F, 0x0F); |
bcostm | 0:d83f1c8ca282 | 1029 | HAL_NVIC_EnableIRQ((IRQn_Type)(MFX_INT_EXTI_IRQn)); |
bcostm | 0:d83f1c8ca282 | 1030 | } |
bcostm | 0:d83f1c8ca282 | 1031 | |
bcostm | 0:d83f1c8ca282 | 1032 | /** |
bcostm | 0:d83f1c8ca282 | 1033 | * @brief Configures MFX wke up pin. |
bcostm | 0:d83f1c8ca282 | 1034 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1035 | */ |
bcostm | 0:d83f1c8ca282 | 1036 | void MFX_IO_EnableWakeupPin(void) |
bcostm | 0:d83f1c8ca282 | 1037 | { |
bcostm | 0:d83f1c8ca282 | 1038 | GPIO_InitTypeDef GPIO_InitStruct; |
bcostm | 0:d83f1c8ca282 | 1039 | |
bcostm | 0:d83f1c8ca282 | 1040 | /* Enable wakeup gpio clock */ |
bcostm | 0:d83f1c8ca282 | 1041 | MFX_WAKEUP_GPIO_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 1042 | |
bcostm | 0:d83f1c8ca282 | 1043 | /* MFX wakeup pin configuration */ |
bcostm | 0:d83f1c8ca282 | 1044 | GPIO_InitStruct.Pin = MFX_WAKEUP_PIN; |
bcostm | 0:d83f1c8ca282 | 1045 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
bcostm | 0:d83f1c8ca282 | 1046 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; |
bcostm | 0:d83f1c8ca282 | 1047 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
bcostm | 0:d83f1c8ca282 | 1048 | HAL_GPIO_Init(MFX_WAKEUP_GPIO_PORT, &GPIO_InitStruct); |
bcostm | 0:d83f1c8ca282 | 1049 | } |
bcostm | 0:d83f1c8ca282 | 1050 | |
bcostm | 0:d83f1c8ca282 | 1051 | /** |
bcostm | 0:d83f1c8ca282 | 1052 | * @brief Wakeup MFX. |
bcostm | 0:d83f1c8ca282 | 1053 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1054 | */ |
bcostm | 0:d83f1c8ca282 | 1055 | void MFX_IO_Wakeup(void) |
bcostm | 0:d83f1c8ca282 | 1056 | { |
bcostm | 0:d83f1c8ca282 | 1057 | /* Set Wakeup pin to high to wakeup Idd measurement component from standby mode */ |
bcostm | 0:d83f1c8ca282 | 1058 | HAL_GPIO_WritePin(MFX_WAKEUP_GPIO_PORT, MFX_WAKEUP_PIN, GPIO_PIN_SET); |
bcostm | 0:d83f1c8ca282 | 1059 | |
bcostm | 0:d83f1c8ca282 | 1060 | /* Wait */ |
bcostm | 0:d83f1c8ca282 | 1061 | HAL_Delay(1); |
bcostm | 0:d83f1c8ca282 | 1062 | |
bcostm | 0:d83f1c8ca282 | 1063 | /* Set gpio pin basck to low */ |
bcostm | 0:d83f1c8ca282 | 1064 | HAL_GPIO_WritePin(MFX_WAKEUP_GPIO_PORT, MFX_WAKEUP_PIN, GPIO_PIN_RESET); |
bcostm | 0:d83f1c8ca282 | 1065 | } |
bcostm | 0:d83f1c8ca282 | 1066 | |
bcostm | 0:d83f1c8ca282 | 1067 | /** |
bcostm | 0:d83f1c8ca282 | 1068 | * @brief MFX writes single data. |
bcostm | 0:d83f1c8ca282 | 1069 | * @param Addr: I2C address |
bcostm | 0:d83f1c8ca282 | 1070 | * @param Reg: Register address |
bcostm | 0:d83f1c8ca282 | 1071 | * @param Value: Data to be written |
bcostm | 0:d83f1c8ca282 | 1072 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1073 | */ |
bcostm | 0:d83f1c8ca282 | 1074 | void MFX_IO_Write(uint16_t Addr, uint8_t Reg, uint8_t Value) |
bcostm | 0:d83f1c8ca282 | 1075 | { |
bcostm | 0:d83f1c8ca282 | 1076 | I2C2_WriteData(Addr, Reg, I2C_MEMADD_SIZE_8BIT, Value); |
bcostm | 0:d83f1c8ca282 | 1077 | } |
bcostm | 0:d83f1c8ca282 | 1078 | |
bcostm | 0:d83f1c8ca282 | 1079 | /** |
bcostm | 0:d83f1c8ca282 | 1080 | * @brief MFX reads single data. |
bcostm | 0:d83f1c8ca282 | 1081 | * @param Addr: I2C address |
bcostm | 0:d83f1c8ca282 | 1082 | * @param Reg: Register address |
bcostm | 0:d83f1c8ca282 | 1083 | * @retval Read data |
bcostm | 0:d83f1c8ca282 | 1084 | */ |
bcostm | 0:d83f1c8ca282 | 1085 | uint8_t MFX_IO_Read(uint16_t Addr, uint8_t Reg) |
bcostm | 0:d83f1c8ca282 | 1086 | { |
bcostm | 0:d83f1c8ca282 | 1087 | return I2C2_ReadData(Addr, Reg, I2C_MEMADD_SIZE_8BIT); |
bcostm | 0:d83f1c8ca282 | 1088 | } |
bcostm | 0:d83f1c8ca282 | 1089 | |
bcostm | 0:d83f1c8ca282 | 1090 | /** |
bcostm | 0:d83f1c8ca282 | 1091 | * @brief MFX reads multiple data. |
bcostm | 0:d83f1c8ca282 | 1092 | * @param Addr: I2C address |
bcostm | 0:d83f1c8ca282 | 1093 | * @param Reg: Register address |
bcostm | 0:d83f1c8ca282 | 1094 | * @param Buffer: Pointer to data buffer |
bcostm | 0:d83f1c8ca282 | 1095 | * @param Length: Length of the data |
bcostm | 0:d83f1c8ca282 | 1096 | * @retval Number of read data |
bcostm | 0:d83f1c8ca282 | 1097 | */ |
bcostm | 0:d83f1c8ca282 | 1098 | uint16_t MFX_IO_ReadMultiple(uint16_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length) |
bcostm | 0:d83f1c8ca282 | 1099 | { |
bcostm | 0:d83f1c8ca282 | 1100 | return I2C2_ReadBuffer(Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length); |
bcostm | 0:d83f1c8ca282 | 1101 | } |
bcostm | 0:d83f1c8ca282 | 1102 | |
bcostm | 0:d83f1c8ca282 | 1103 | /** |
bcostm | 0:d83f1c8ca282 | 1104 | * @brief MFX writes multiple data. |
bcostm | 0:d83f1c8ca282 | 1105 | * @param Addr: I2C address |
bcostm | 0:d83f1c8ca282 | 1106 | * @param Reg: Register address |
bcostm | 0:d83f1c8ca282 | 1107 | * @param Buffer: Pointer to data buffer |
bcostm | 0:d83f1c8ca282 | 1108 | * @param Length: Length of the data |
bcostm | 0:d83f1c8ca282 | 1109 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1110 | */ |
bcostm | 0:d83f1c8ca282 | 1111 | void MFX_IO_WriteMultiple(uint16_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length) |
bcostm | 0:d83f1c8ca282 | 1112 | { |
bcostm | 0:d83f1c8ca282 | 1113 | I2C2_WriteBuffer(Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length); |
bcostm | 0:d83f1c8ca282 | 1114 | } |
bcostm | 0:d83f1c8ca282 | 1115 | |
bcostm | 0:d83f1c8ca282 | 1116 | /** |
bcostm | 0:d83f1c8ca282 | 1117 | * @brief MFX delay |
bcostm | 0:d83f1c8ca282 | 1118 | * @param Delay: Delay in ms |
bcostm | 0:d83f1c8ca282 | 1119 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1120 | */ |
bcostm | 0:d83f1c8ca282 | 1121 | void MFX_IO_Delay(uint32_t Delay) |
bcostm | 0:d83f1c8ca282 | 1122 | { |
bcostm | 0:d83f1c8ca282 | 1123 | HAL_Delay(Delay); |
bcostm | 0:d83f1c8ca282 | 1124 | } |
bcostm | 0:d83f1c8ca282 | 1125 | |
bcostm | 0:d83f1c8ca282 | 1126 | |
bcostm | 0:d83f1c8ca282 | 1127 | /********************************* LINK AUDIO *********************************/ |
bcostm | 0:d83f1c8ca282 | 1128 | /** |
bcostm | 0:d83f1c8ca282 | 1129 | * @brief Initializes Audio low level. |
bcostm | 0:d83f1c8ca282 | 1130 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1131 | */ |
bcostm | 0:d83f1c8ca282 | 1132 | void AUDIO_IO_Init(void) |
bcostm | 0:d83f1c8ca282 | 1133 | { |
bcostm | 0:d83f1c8ca282 | 1134 | GPIO_InitTypeDef GPIO_InitStruct; |
bcostm | 0:d83f1c8ca282 | 1135 | uint8_t Value; |
bcostm | 0:d83f1c8ca282 | 1136 | |
bcostm | 0:d83f1c8ca282 | 1137 | /* Enable Reset GPIO Clock */ |
bcostm | 0:d83f1c8ca282 | 1138 | AUDIO_RESET_GPIO_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 1139 | |
bcostm | 0:d83f1c8ca282 | 1140 | /* Audio reset pin configuration */ |
bcostm | 0:d83f1c8ca282 | 1141 | GPIO_InitStruct.Pin = AUDIO_RESET_PIN; |
bcostm | 0:d83f1c8ca282 | 1142 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
bcostm | 0:d83f1c8ca282 | 1143 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; |
bcostm | 0:d83f1c8ca282 | 1144 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
bcostm | 0:d83f1c8ca282 | 1145 | HAL_GPIO_Init(AUDIO_RESET_GPIO, &GPIO_InitStruct); |
bcostm | 0:d83f1c8ca282 | 1146 | |
bcostm | 0:d83f1c8ca282 | 1147 | /* I2C bus init */ |
bcostm | 0:d83f1c8ca282 | 1148 | I2C2_Init(); |
bcostm | 0:d83f1c8ca282 | 1149 | |
bcostm | 0:d83f1c8ca282 | 1150 | /* Power off the codec */ |
bcostm | 0:d83f1c8ca282 | 1151 | CODEC_AUDIO_POWER_OFF(); |
bcostm | 0:d83f1c8ca282 | 1152 | |
bcostm | 0:d83f1c8ca282 | 1153 | /* wait until power supplies are stable */ |
bcostm | 0:d83f1c8ca282 | 1154 | HAL_Delay(10); |
bcostm | 0:d83f1c8ca282 | 1155 | |
bcostm | 0:d83f1c8ca282 | 1156 | /* Power on the codec */ |
bcostm | 0:d83f1c8ca282 | 1157 | CODEC_AUDIO_POWER_ON(); |
bcostm | 0:d83f1c8ca282 | 1158 | |
bcostm | 0:d83f1c8ca282 | 1159 | /* Set the device in standby mode */ |
bcostm | 0:d83f1c8ca282 | 1160 | Value = AUDIO_IO_Read(AUDIO_I2C_ADDRESS, 0x02); |
bcostm | 0:d83f1c8ca282 | 1161 | AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x02, (Value | 0x01)); |
bcostm | 0:d83f1c8ca282 | 1162 | |
bcostm | 0:d83f1c8ca282 | 1163 | /* Set all power down bits to 1 */ |
bcostm | 0:d83f1c8ca282 | 1164 | AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x02, 0x7F); |
bcostm | 0:d83f1c8ca282 | 1165 | Value = AUDIO_IO_Read(AUDIO_I2C_ADDRESS, 0x03); |
bcostm | 0:d83f1c8ca282 | 1166 | AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x03, (Value | 0x0E)); |
bcostm | 0:d83f1c8ca282 | 1167 | } |
bcostm | 0:d83f1c8ca282 | 1168 | |
bcostm | 0:d83f1c8ca282 | 1169 | /** |
bcostm | 0:d83f1c8ca282 | 1170 | * @brief Deinitializes Audio low level. |
bcostm | 0:d83f1c8ca282 | 1171 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1172 | */ |
bcostm | 0:d83f1c8ca282 | 1173 | void AUDIO_IO_DeInit(void) |
bcostm | 0:d83f1c8ca282 | 1174 | { |
bcostm | 0:d83f1c8ca282 | 1175 | uint8_t Value; |
bcostm | 0:d83f1c8ca282 | 1176 | |
bcostm | 0:d83f1c8ca282 | 1177 | /* Mute DAC and ADC */ |
bcostm | 0:d83f1c8ca282 | 1178 | Value = AUDIO_IO_Read(AUDIO_I2C_ADDRESS, 0x08); |
bcostm | 0:d83f1c8ca282 | 1179 | AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x08, (Value | 0x03)); |
bcostm | 0:d83f1c8ca282 | 1180 | Value = AUDIO_IO_Read(AUDIO_I2C_ADDRESS, 0x07); |
bcostm | 0:d83f1c8ca282 | 1181 | AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x07, (Value | 0x03)); |
bcostm | 0:d83f1c8ca282 | 1182 | |
bcostm | 0:d83f1c8ca282 | 1183 | /* Disable soft ramp and zero cross */ |
bcostm | 0:d83f1c8ca282 | 1184 | Value = AUDIO_IO_Read(AUDIO_I2C_ADDRESS, 0x06); |
bcostm | 0:d83f1c8ca282 | 1185 | AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x06, (Value & 0xF0)); |
bcostm | 0:d83f1c8ca282 | 1186 | |
bcostm | 0:d83f1c8ca282 | 1187 | /* Set PDN to 1 */ |
bcostm | 0:d83f1c8ca282 | 1188 | Value = AUDIO_IO_Read(AUDIO_I2C_ADDRESS, 0x02); |
bcostm | 0:d83f1c8ca282 | 1189 | AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x02, (Value | 0x01)); |
bcostm | 0:d83f1c8ca282 | 1190 | |
bcostm | 0:d83f1c8ca282 | 1191 | /* Set all power down bits to 1 */ |
bcostm | 0:d83f1c8ca282 | 1192 | AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x02, 0x7F); |
bcostm | 0:d83f1c8ca282 | 1193 | Value = AUDIO_IO_Read(AUDIO_I2C_ADDRESS, 0x03); |
bcostm | 0:d83f1c8ca282 | 1194 | AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x03, (Value | 0x0E)); |
bcostm | 0:d83f1c8ca282 | 1195 | |
bcostm | 0:d83f1c8ca282 | 1196 | /* Power off the codec */ |
bcostm | 0:d83f1c8ca282 | 1197 | CODEC_AUDIO_POWER_OFF(); |
bcostm | 0:d83f1c8ca282 | 1198 | |
bcostm | 0:d83f1c8ca282 | 1199 | } |
bcostm | 0:d83f1c8ca282 | 1200 | |
bcostm | 0:d83f1c8ca282 | 1201 | /** |
bcostm | 0:d83f1c8ca282 | 1202 | * @brief Writes a single data. |
bcostm | 0:d83f1c8ca282 | 1203 | * @param Addr: I2C address |
bcostm | 0:d83f1c8ca282 | 1204 | * @param Reg: Reg address |
bcostm | 0:d83f1c8ca282 | 1205 | * @param Value: Data to be written |
bcostm | 0:d83f1c8ca282 | 1206 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1207 | */ |
bcostm | 0:d83f1c8ca282 | 1208 | void AUDIO_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value) |
bcostm | 0:d83f1c8ca282 | 1209 | { |
bcostm | 0:d83f1c8ca282 | 1210 | I2C2_WriteBuffer(Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1); |
bcostm | 0:d83f1c8ca282 | 1211 | } |
bcostm | 0:d83f1c8ca282 | 1212 | |
bcostm | 0:d83f1c8ca282 | 1213 | /** |
bcostm | 0:d83f1c8ca282 | 1214 | * @brief Reads a single data. |
bcostm | 0:d83f1c8ca282 | 1215 | * @param Addr: I2C address |
bcostm | 0:d83f1c8ca282 | 1216 | * @param Reg: Reg address |
bcostm | 0:d83f1c8ca282 | 1217 | * @retval Data to be read |
bcostm | 0:d83f1c8ca282 | 1218 | */ |
bcostm | 0:d83f1c8ca282 | 1219 | uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg) |
bcostm | 0:d83f1c8ca282 | 1220 | { |
bcostm | 0:d83f1c8ca282 | 1221 | uint8_t Read_Value = 0; |
bcostm | 0:d83f1c8ca282 | 1222 | |
bcostm | 0:d83f1c8ca282 | 1223 | I2C2_ReadBuffer((uint16_t) Addr, (uint16_t) Reg, I2C_MEMADD_SIZE_8BIT, &Read_Value, 1); |
bcostm | 0:d83f1c8ca282 | 1224 | |
bcostm | 0:d83f1c8ca282 | 1225 | return Read_Value; |
bcostm | 0:d83f1c8ca282 | 1226 | } |
bcostm | 0:d83f1c8ca282 | 1227 | |
bcostm | 0:d83f1c8ca282 | 1228 | /** |
bcostm | 0:d83f1c8ca282 | 1229 | * @brief AUDIO Codec delay |
bcostm | 0:d83f1c8ca282 | 1230 | * @param Delay: Delay in ms |
bcostm | 0:d83f1c8ca282 | 1231 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1232 | */ |
bcostm | 0:d83f1c8ca282 | 1233 | void AUDIO_IO_Delay(uint32_t Delay) |
bcostm | 0:d83f1c8ca282 | 1234 | { |
bcostm | 0:d83f1c8ca282 | 1235 | HAL_Delay(Delay); |
bcostm | 0:d83f1c8ca282 | 1236 | } |
bcostm | 0:d83f1c8ca282 | 1237 | |
bcostm | 0:d83f1c8ca282 | 1238 | |
bcostm | 0:d83f1c8ca282 | 1239 | |
bcostm | 0:d83f1c8ca282 | 1240 | |
bcostm | 0:d83f1c8ca282 | 1241 | /*************************** FMC Routines ************************************/ |
bcostm | 0:d83f1c8ca282 | 1242 | /** |
bcostm | 0:d83f1c8ca282 | 1243 | * @brief Initializes FMC_BANK1_LCD_IO MSP. |
bcostm | 0:d83f1c8ca282 | 1244 | * @param None |
bcostm | 0:d83f1c8ca282 | 1245 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1246 | */ |
bcostm | 0:d83f1c8ca282 | 1247 | void FMC_BANK1_MspInit(void) |
bcostm | 0:d83f1c8ca282 | 1248 | { |
bcostm | 0:d83f1c8ca282 | 1249 | |
bcostm | 0:d83f1c8ca282 | 1250 | GPIO_InitTypeDef GPIO_Init_Structure; |
bcostm | 0:d83f1c8ca282 | 1251 | |
bcostm | 0:d83f1c8ca282 | 1252 | /* Enable FMC clock */ |
bcostm | 0:d83f1c8ca282 | 1253 | __HAL_RCC_FMC_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 1254 | |
bcostm | 0:d83f1c8ca282 | 1255 | /* Enable GPIOs clock */ |
bcostm | 0:d83f1c8ca282 | 1256 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 1257 | __HAL_RCC_GPIOE_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 1258 | __HAL_RCC_GPIOF_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 1259 | __HAL_RCC_GPIOG_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 1260 | __HAL_RCC_PWR_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 1261 | HAL_PWREx_EnableVddIO2(); |
bcostm | 0:d83f1c8ca282 | 1262 | |
bcostm | 0:d83f1c8ca282 | 1263 | /* Set PD11 */ |
bcostm | 0:d83f1c8ca282 | 1264 | GPIO_Init_Structure.Pin = GPIO_PIN_11; |
bcostm | 0:d83f1c8ca282 | 1265 | GPIO_Init_Structure.Mode = GPIO_MODE_OUTPUT_PP; |
bcostm | 0:d83f1c8ca282 | 1266 | GPIO_Init_Structure.Pull = GPIO_NOPULL; |
bcostm | 0:d83f1c8ca282 | 1267 | GPIO_Init_Structure.Speed = GPIO_SPEED_FREQ_LOW; |
bcostm | 0:d83f1c8ca282 | 1268 | GPIO_Init_Structure.Alternate = 0; |
bcostm | 0:d83f1c8ca282 | 1269 | |
bcostm | 0:d83f1c8ca282 | 1270 | HAL_GPIO_Init(GPIOD, &GPIO_Init_Structure); |
bcostm | 0:d83f1c8ca282 | 1271 | |
bcostm | 0:d83f1c8ca282 | 1272 | |
bcostm | 0:d83f1c8ca282 | 1273 | GPIO_Init_Structure.Mode = GPIO_MODE_AF_PP; |
bcostm | 0:d83f1c8ca282 | 1274 | GPIO_Init_Structure.Pull = GPIO_PULLUP; |
bcostm | 0:d83f1c8ca282 | 1275 | GPIO_Init_Structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
bcostm | 0:d83f1c8ca282 | 1276 | GPIO_Init_Structure.Alternate = GPIO_AF12_FMC; |
bcostm | 0:d83f1c8ca282 | 1277 | /* GPIOD configuration */ /* GPIO_PIN_7 is FMC_NE1 */ |
bcostm | 0:d83f1c8ca282 | 1278 | GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_8 | \ |
bcostm | 0:d83f1c8ca282 | 1279 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_14 | GPIO_PIN_15 | GPIO_PIN_7; |
bcostm | 0:d83f1c8ca282 | 1280 | |
bcostm | 0:d83f1c8ca282 | 1281 | HAL_GPIO_Init(GPIOD, &GPIO_Init_Structure); |
bcostm | 0:d83f1c8ca282 | 1282 | |
bcostm | 0:d83f1c8ca282 | 1283 | |
bcostm | 0:d83f1c8ca282 | 1284 | |
bcostm | 0:d83f1c8ca282 | 1285 | |
bcostm | 0:d83f1c8ca282 | 1286 | /* GPIOE configuration */ |
bcostm | 0:d83f1c8ca282 | 1287 | GPIO_Init_Structure.Pin = GPIO_PIN_7 | \ |
bcostm | 0:d83f1c8ca282 | 1288 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | \ |
bcostm | 0:d83f1c8ca282 | 1289 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; |
bcostm | 0:d83f1c8ca282 | 1290 | HAL_GPIO_Init(GPIOE, &GPIO_Init_Structure); |
bcostm | 0:d83f1c8ca282 | 1291 | |
bcostm | 0:d83f1c8ca282 | 1292 | /* GPIOF configuration */ |
bcostm | 0:d83f1c8ca282 | 1293 | GPIO_Init_Structure.Pin = GPIO_PIN_13 ; |
bcostm | 0:d83f1c8ca282 | 1294 | HAL_GPIO_Init(GPIOD, &GPIO_Init_Structure); |
bcostm | 0:d83f1c8ca282 | 1295 | |
bcostm | 0:d83f1c8ca282 | 1296 | GPIO_Init_Structure.Pin = GPIO_PIN_0; |
bcostm | 0:d83f1c8ca282 | 1297 | HAL_GPIO_Init(GPIOF, &GPIO_Init_Structure); |
bcostm | 0:d83f1c8ca282 | 1298 | } |
bcostm | 0:d83f1c8ca282 | 1299 | |
bcostm | 0:d83f1c8ca282 | 1300 | |
bcostm | 0:d83f1c8ca282 | 1301 | /** |
bcostm | 0:d83f1c8ca282 | 1302 | * @brief Initializes LCD IO. |
bcostm | 0:d83f1c8ca282 | 1303 | * @param None |
bcostm | 0:d83f1c8ca282 | 1304 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1305 | */ |
bcostm | 0:d83f1c8ca282 | 1306 | void FMC_BANK1_Init(void) |
bcostm | 0:d83f1c8ca282 | 1307 | { |
bcostm | 0:d83f1c8ca282 | 1308 | SRAM_HandleTypeDef hsram; |
bcostm | 0:d83f1c8ca282 | 1309 | FMC_NORSRAM_TimingTypeDef sram_timing; |
bcostm | 0:d83f1c8ca282 | 1310 | FMC_NORSRAM_TimingTypeDef sram_timing_write; |
bcostm | 0:d83f1c8ca282 | 1311 | |
bcostm | 0:d83f1c8ca282 | 1312 | /*** Configure the SRAM Bank 1 ***/ |
bcostm | 0:d83f1c8ca282 | 1313 | /* Configure IPs */ |
bcostm | 0:d83f1c8ca282 | 1314 | hsram.Instance = FMC_NORSRAM_DEVICE; |
bcostm | 0:d83f1c8ca282 | 1315 | hsram.Extended = FMC_NORSRAM_EXTENDED_DEVICE; |
bcostm | 0:d83f1c8ca282 | 1316 | |
bcostm | 0:d83f1c8ca282 | 1317 | |
bcostm | 0:d83f1c8ca282 | 1318 | /* Timing for READING */ |
bcostm | 0:d83f1c8ca282 | 1319 | |
bcostm | 0:d83f1c8ca282 | 1320 | sram_timing.AddressSetupTime = 1; |
bcostm | 0:d83f1c8ca282 | 1321 | sram_timing.AddressHoldTime = 1; |
bcostm | 0:d83f1c8ca282 | 1322 | sram_timing.DataSetupTime = 1; |
bcostm | 0:d83f1c8ca282 | 1323 | sram_timing.BusTurnAroundDuration = 0; |
bcostm | 0:d83f1c8ca282 | 1324 | sram_timing.CLKDivision = 2; |
bcostm | 0:d83f1c8ca282 | 1325 | sram_timing.DataLatency = 2; |
bcostm | 0:d83f1c8ca282 | 1326 | sram_timing.AccessMode = FMC_ACCESS_MODE_A; |
bcostm | 0:d83f1c8ca282 | 1327 | /* Timing for WRITING */ |
bcostm | 0:d83f1c8ca282 | 1328 | sram_timing_write.AddressSetupTime = 5; |
bcostm | 0:d83f1c8ca282 | 1329 | sram_timing_write.AddressHoldTime = 1; |
bcostm | 0:d83f1c8ca282 | 1330 | sram_timing_write.DataSetupTime = 3; |
bcostm | 0:d83f1c8ca282 | 1331 | sram_timing_write.BusTurnAroundDuration = 2; |
bcostm | 0:d83f1c8ca282 | 1332 | sram_timing_write.CLKDivision = 2; |
bcostm | 0:d83f1c8ca282 | 1333 | sram_timing_write.DataLatency = 2; |
bcostm | 0:d83f1c8ca282 | 1334 | sram_timing_write.AccessMode = FMC_ACCESS_MODE_A; |
bcostm | 0:d83f1c8ca282 | 1335 | |
bcostm | 0:d83f1c8ca282 | 1336 | |
bcostm | 0:d83f1c8ca282 | 1337 | hsram.Init.NSBank = FMC_NORSRAM_BANK1; |
bcostm | 0:d83f1c8ca282 | 1338 | hsram.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE; |
bcostm | 0:d83f1c8ca282 | 1339 | hsram.Init.MemoryType = FMC_MEMORY_TYPE_SRAM; |
bcostm | 0:d83f1c8ca282 | 1340 | hsram.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16; |
bcostm | 0:d83f1c8ca282 | 1341 | hsram.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE; |
bcostm | 0:d83f1c8ca282 | 1342 | hsram.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW; |
bcostm | 0:d83f1c8ca282 | 1343 | hsram.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS; |
bcostm | 0:d83f1c8ca282 | 1344 | hsram.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE; |
bcostm | 0:d83f1c8ca282 | 1345 | hsram.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE; |
bcostm | 0:d83f1c8ca282 | 1346 | hsram.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE; |
bcostm | 0:d83f1c8ca282 | 1347 | hsram.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE; |
bcostm | 0:d83f1c8ca282 | 1348 | hsram.Init.WriteBurst = FMC_WRITE_BURST_DISABLE; |
bcostm | 0:d83f1c8ca282 | 1349 | hsram.Init.PageSize = FMC_PAGE_SIZE_NONE; |
bcostm | 0:d83f1c8ca282 | 1350 | hsram.Init.WriteFifo = FMC_WRITE_FIFO_DISABLE; |
bcostm | 0:d83f1c8ca282 | 1351 | hsram.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY; |
bcostm | 0:d83f1c8ca282 | 1352 | /* Initialize the SRAM controller */ |
bcostm | 0:d83f1c8ca282 | 1353 | FMC_BANK1_MspInit(); |
bcostm | 0:d83f1c8ca282 | 1354 | HAL_SRAM_Init(&hsram, &sram_timing, &sram_timing_write); |
bcostm | 0:d83f1c8ca282 | 1355 | |
bcostm | 0:d83f1c8ca282 | 1356 | } |
bcostm | 0:d83f1c8ca282 | 1357 | |
bcostm | 0:d83f1c8ca282 | 1358 | |
bcostm | 0:d83f1c8ca282 | 1359 | /** |
bcostm | 0:d83f1c8ca282 | 1360 | * @brief DeInitializes FMC_BANK1_LCD_IO MSP. |
bcostm | 0:d83f1c8ca282 | 1361 | * @param None |
bcostm | 0:d83f1c8ca282 | 1362 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1363 | */ |
bcostm | 0:d83f1c8ca282 | 1364 | void FMC_BANK1_MspDeInit(void) |
bcostm | 0:d83f1c8ca282 | 1365 | { |
bcostm | 0:d83f1c8ca282 | 1366 | |
bcostm | 0:d83f1c8ca282 | 1367 | /* Enable FMC clock */ |
bcostm | 0:d83f1c8ca282 | 1368 | __HAL_RCC_FMC_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 1369 | |
bcostm | 0:d83f1c8ca282 | 1370 | /* Enable GPIOs clock */ |
bcostm | 0:d83f1c8ca282 | 1371 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 1372 | __HAL_RCC_GPIOE_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 1373 | __HAL_RCC_GPIOF_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 1374 | __HAL_RCC_GPIOG_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 1375 | __HAL_RCC_PWR_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 1376 | |
bcostm | 0:d83f1c8ca282 | 1377 | |
bcostm | 0:d83f1c8ca282 | 1378 | HAL_GPIO_DeInit(GPIOD, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_8 | \ |
bcostm | 0:d83f1c8ca282 | 1379 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_14 | GPIO_PIN_15 | GPIO_PIN_7 | GPIO_PIN_11 | GPIO_PIN_13); |
bcostm | 0:d83f1c8ca282 | 1380 | |
bcostm | 0:d83f1c8ca282 | 1381 | |
bcostm | 0:d83f1c8ca282 | 1382 | |
bcostm | 0:d83f1c8ca282 | 1383 | HAL_GPIO_DeInit(GPIOE, GPIO_PIN_7 | \ |
bcostm | 0:d83f1c8ca282 | 1384 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | \ |
bcostm | 0:d83f1c8ca282 | 1385 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15); |
bcostm | 0:d83f1c8ca282 | 1386 | |
bcostm | 0:d83f1c8ca282 | 1387 | HAL_GPIO_DeInit(GPIOF, GPIO_PIN_0); |
bcostm | 0:d83f1c8ca282 | 1388 | |
bcostm | 0:d83f1c8ca282 | 1389 | |
bcostm | 0:d83f1c8ca282 | 1390 | } |
bcostm | 0:d83f1c8ca282 | 1391 | |
bcostm | 0:d83f1c8ca282 | 1392 | |
bcostm | 0:d83f1c8ca282 | 1393 | /** |
bcostm | 0:d83f1c8ca282 | 1394 | * @brief Writes register value. |
bcostm | 0:d83f1c8ca282 | 1395 | * @param Data: Data to be written |
bcostm | 0:d83f1c8ca282 | 1396 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1397 | */ |
bcostm | 0:d83f1c8ca282 | 1398 | static void FMC_BANK1_WriteData(uint16_t Data) |
bcostm | 0:d83f1c8ca282 | 1399 | { |
bcostm | 0:d83f1c8ca282 | 1400 | /* Write 16-bit Reg */ |
bcostm | 0:d83f1c8ca282 | 1401 | LCD_ADDR->REG = Data; |
bcostm | 0:d83f1c8ca282 | 1402 | } |
bcostm | 0:d83f1c8ca282 | 1403 | |
bcostm | 0:d83f1c8ca282 | 1404 | /** |
bcostm | 0:d83f1c8ca282 | 1405 | * @brief Writes register address. |
bcostm | 0:d83f1c8ca282 | 1406 | * @param Reg: Register to be written |
bcostm | 0:d83f1c8ca282 | 1407 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1408 | */ |
bcostm | 0:d83f1c8ca282 | 1409 | static void FMC_BANK1_WriteReg(uint8_t Reg) |
bcostm | 0:d83f1c8ca282 | 1410 | { |
bcostm | 0:d83f1c8ca282 | 1411 | /* Write 16-bit Index, then write register */ |
bcostm | 0:d83f1c8ca282 | 1412 | FMC_BANK1_ADDR->REG = Reg; |
bcostm | 0:d83f1c8ca282 | 1413 | } |
bcostm | 0:d83f1c8ca282 | 1414 | |
bcostm | 0:d83f1c8ca282 | 1415 | /** |
bcostm | 0:d83f1c8ca282 | 1416 | * @brief Reads register value. |
bcostm | 0:d83f1c8ca282 | 1417 | * @param None |
bcostm | 0:d83f1c8ca282 | 1418 | * @retval Read value |
bcostm | 0:d83f1c8ca282 | 1419 | */ |
bcostm | 0:d83f1c8ca282 | 1420 | static uint16_t FMC_BANK1_ReadData(void) |
bcostm | 0:d83f1c8ca282 | 1421 | { |
bcostm | 0:d83f1c8ca282 | 1422 | return LCD_ADDR->REG; |
bcostm | 0:d83f1c8ca282 | 1423 | } |
bcostm | 0:d83f1c8ca282 | 1424 | |
bcostm | 0:d83f1c8ca282 | 1425 | /******************************************************************************* |
bcostm | 0:d83f1c8ca282 | 1426 | LINK OPERATIONS |
bcostm | 0:d83f1c8ca282 | 1427 | *******************************************************************************/ |
bcostm | 0:d83f1c8ca282 | 1428 | |
bcostm | 0:d83f1c8ca282 | 1429 | /********************************* LINK LCD ***********************************/ |
bcostm | 0:d83f1c8ca282 | 1430 | |
bcostm | 0:d83f1c8ca282 | 1431 | /** |
bcostm | 0:d83f1c8ca282 | 1432 | * @brief Initializes LCD low level. |
bcostm | 0:d83f1c8ca282 | 1433 | * @param None |
bcostm | 0:d83f1c8ca282 | 1434 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1435 | */ |
bcostm | 0:d83f1c8ca282 | 1436 | void LCD_IO_Init(void) |
bcostm | 0:d83f1c8ca282 | 1437 | { |
bcostm | 0:d83f1c8ca282 | 1438 | FMC_BANK1_Init(); |
bcostm | 0:d83f1c8ca282 | 1439 | } |
bcostm | 0:d83f1c8ca282 | 1440 | |
bcostm | 0:d83f1c8ca282 | 1441 | /** |
bcostm | 0:d83f1c8ca282 | 1442 | * @brief Writes data on LCD data register. |
bcostm | 0:d83f1c8ca282 | 1443 | * @param Data: Data to be written |
bcostm | 0:d83f1c8ca282 | 1444 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1445 | */ |
bcostm | 0:d83f1c8ca282 | 1446 | void LCD_IO_WriteData(uint16_t RegValue) |
bcostm | 0:d83f1c8ca282 | 1447 | { |
bcostm | 0:d83f1c8ca282 | 1448 | /* Write 16-bit Reg */ |
bcostm | 0:d83f1c8ca282 | 1449 | FMC_BANK1_WriteData(RegValue); |
bcostm | 0:d83f1c8ca282 | 1450 | } |
bcostm | 0:d83f1c8ca282 | 1451 | |
bcostm | 0:d83f1c8ca282 | 1452 | /** |
bcostm | 0:d83f1c8ca282 | 1453 | * @brief Writes several data on LCD data register. |
bcostm | 0:d83f1c8ca282 | 1454 | * @param Data: pointer on data to be written |
bcostm | 0:d83f1c8ca282 | 1455 | * @param Size: data amount in 16bits short unit |
bcostm | 0:d83f1c8ca282 | 1456 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1457 | */ |
bcostm | 0:d83f1c8ca282 | 1458 | void LCD_IO_WriteMultipleData(uint16_t *pData, uint32_t Size) |
bcostm | 0:d83f1c8ca282 | 1459 | { |
bcostm | 0:d83f1c8ca282 | 1460 | uint32_t i; |
bcostm | 0:d83f1c8ca282 | 1461 | |
bcostm | 0:d83f1c8ca282 | 1462 | for (i = 0; i < Size; i++) |
bcostm | 0:d83f1c8ca282 | 1463 | { |
bcostm | 0:d83f1c8ca282 | 1464 | FMC_BANK1_WriteData(pData[i]); |
bcostm | 0:d83f1c8ca282 | 1465 | } |
bcostm | 0:d83f1c8ca282 | 1466 | } |
bcostm | 0:d83f1c8ca282 | 1467 | |
bcostm | 0:d83f1c8ca282 | 1468 | /** |
bcostm | 0:d83f1c8ca282 | 1469 | * @brief Writes register on LCD register. |
bcostm | 0:d83f1c8ca282 | 1470 | * @param Reg: Register to be written |
bcostm | 0:d83f1c8ca282 | 1471 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1472 | */ |
bcostm | 0:d83f1c8ca282 | 1473 | void LCD_IO_WriteReg(uint8_t Reg) |
bcostm | 0:d83f1c8ca282 | 1474 | { |
bcostm | 0:d83f1c8ca282 | 1475 | /* Write 16-bit Index, then Write Reg */ |
bcostm | 0:d83f1c8ca282 | 1476 | FMC_BANK1_WriteReg(Reg); |
bcostm | 0:d83f1c8ca282 | 1477 | } |
bcostm | 0:d83f1c8ca282 | 1478 | |
bcostm | 0:d83f1c8ca282 | 1479 | /** |
bcostm | 0:d83f1c8ca282 | 1480 | * @brief Reads data from LCD data register. |
bcostm | 0:d83f1c8ca282 | 1481 | * @param None |
bcostm | 0:d83f1c8ca282 | 1482 | * @retval Read data. |
bcostm | 0:d83f1c8ca282 | 1483 | */ |
bcostm | 0:d83f1c8ca282 | 1484 | uint16_t LCD_IO_ReadData(void) |
bcostm | 0:d83f1c8ca282 | 1485 | { |
bcostm | 0:d83f1c8ca282 | 1486 | return FMC_BANK1_ReadData(); |
bcostm | 0:d83f1c8ca282 | 1487 | } |
bcostm | 0:d83f1c8ca282 | 1488 | |
bcostm | 0:d83f1c8ca282 | 1489 | /** |
bcostm | 0:d83f1c8ca282 | 1490 | * @brief LCD delay |
bcostm | 0:d83f1c8ca282 | 1491 | * @param Delay: Delay in ms |
bcostm | 0:d83f1c8ca282 | 1492 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1493 | */ |
bcostm | 0:d83f1c8ca282 | 1494 | void LCD_IO_Delay(uint32_t Delay) |
bcostm | 0:d83f1c8ca282 | 1495 | { |
bcostm | 0:d83f1c8ca282 | 1496 | HAL_Delay(Delay); |
bcostm | 0:d83f1c8ca282 | 1497 | } |
bcostm | 0:d83f1c8ca282 | 1498 | |
bcostm | 0:d83f1c8ca282 | 1499 | |
bcostm | 0:d83f1c8ca282 | 1500 | /************************** LINK TS (TouchScreen) *****************************/ |
bcostm | 0:d83f1c8ca282 | 1501 | /** |
bcostm | 0:d83f1c8ca282 | 1502 | * @brief Initializes Touchscreen low level. |
bcostm | 0:d83f1c8ca282 | 1503 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1504 | */ |
bcostm | 0:d83f1c8ca282 | 1505 | void TS_IO_Init(void) |
bcostm | 0:d83f1c8ca282 | 1506 | { |
bcostm | 0:d83f1c8ca282 | 1507 | I2Cx_Init(&hI2cTSHandler); |
bcostm | 0:d83f1c8ca282 | 1508 | |
bcostm | 0:d83f1c8ca282 | 1509 | if (ts_io_init == 0) |
bcostm | 0:d83f1c8ca282 | 1510 | { |
bcostm | 0:d83f1c8ca282 | 1511 | if (BSP_LCD_Init() == LCD_ERROR) |
bcostm | 0:d83f1c8ca282 | 1512 | { |
bcostm | 0:d83f1c8ca282 | 1513 | BSP_ErrorHandler(); |
bcostm | 0:d83f1c8ca282 | 1514 | } |
bcostm | 0:d83f1c8ca282 | 1515 | |
bcostm | 0:d83f1c8ca282 | 1516 | BSP_IO_ConfigPin(TS_RST_PIN, IO_MODE_OUTPUT); |
bcostm | 0:d83f1c8ca282 | 1517 | |
bcostm | 0:d83f1c8ca282 | 1518 | BSP_IO_WritePin(TS_RST_PIN, GPIO_PIN_RESET); |
bcostm | 0:d83f1c8ca282 | 1519 | HAL_Delay(10); |
bcostm | 0:d83f1c8ca282 | 1520 | BSP_IO_WritePin(TS_RST_PIN, GPIO_PIN_SET); |
bcostm | 0:d83f1c8ca282 | 1521 | HAL_Delay(200); |
bcostm | 0:d83f1c8ca282 | 1522 | |
bcostm | 0:d83f1c8ca282 | 1523 | ts_io_init = 1; |
bcostm | 0:d83f1c8ca282 | 1524 | } |
bcostm | 0:d83f1c8ca282 | 1525 | } |
bcostm | 0:d83f1c8ca282 | 1526 | |
bcostm | 0:d83f1c8ca282 | 1527 | /** |
bcostm | 0:d83f1c8ca282 | 1528 | * @brief Writes a single data. |
bcostm | 0:d83f1c8ca282 | 1529 | * @param Addr: I2C address |
bcostm | 0:d83f1c8ca282 | 1530 | * @param Reg: Reg address |
bcostm | 0:d83f1c8ca282 | 1531 | * @param Value: Data to be written |
bcostm | 0:d83f1c8ca282 | 1532 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1533 | */ |
bcostm | 0:d83f1c8ca282 | 1534 | void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value) |
bcostm | 0:d83f1c8ca282 | 1535 | { |
bcostm | 0:d83f1c8ca282 | 1536 | I2Cx_WriteMultiple(&hI2cTSHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t *)&Value, 1); |
bcostm | 0:d83f1c8ca282 | 1537 | } |
bcostm | 0:d83f1c8ca282 | 1538 | |
bcostm | 0:d83f1c8ca282 | 1539 | /** |
bcostm | 0:d83f1c8ca282 | 1540 | * @brief Reads a single data. |
bcostm | 0:d83f1c8ca282 | 1541 | * @param Addr: I2C address |
bcostm | 0:d83f1c8ca282 | 1542 | * @param Reg: Reg address |
bcostm | 0:d83f1c8ca282 | 1543 | * @retval Data to be read |
bcostm | 0:d83f1c8ca282 | 1544 | */ |
bcostm | 0:d83f1c8ca282 | 1545 | uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg) |
bcostm | 0:d83f1c8ca282 | 1546 | { |
bcostm | 0:d83f1c8ca282 | 1547 | return I2C2_ReadData(Addr, Reg, I2C_MEMADD_SIZE_8BIT); |
bcostm | 0:d83f1c8ca282 | 1548 | } |
bcostm | 0:d83f1c8ca282 | 1549 | |
bcostm | 0:d83f1c8ca282 | 1550 | /** |
bcostm | 0:d83f1c8ca282 | 1551 | * @brief Reads multiple data with I2C communication |
bcostm | 0:d83f1c8ca282 | 1552 | * channel from TouchScreen. |
bcostm | 0:d83f1c8ca282 | 1553 | * @param Addr: I2C address |
bcostm | 0:d83f1c8ca282 | 1554 | * @param Reg: Register address |
bcostm | 0:d83f1c8ca282 | 1555 | * @param Buffer: Pointer to data buffer |
bcostm | 0:d83f1c8ca282 | 1556 | * @param Length: Length of the data |
bcostm | 0:d83f1c8ca282 | 1557 | * @retval Number of read data |
bcostm | 0:d83f1c8ca282 | 1558 | */ |
bcostm | 0:d83f1c8ca282 | 1559 | uint16_t TS_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length) |
bcostm | 0:d83f1c8ca282 | 1560 | { |
bcostm | 0:d83f1c8ca282 | 1561 | return I2Cx_ReadMultiple(&hI2cTSHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length); |
bcostm | 0:d83f1c8ca282 | 1562 | } |
bcostm | 0:d83f1c8ca282 | 1563 | |
bcostm | 0:d83f1c8ca282 | 1564 | /** |
bcostm | 0:d83f1c8ca282 | 1565 | * @brief Writes multiple data with I2C communication |
bcostm | 0:d83f1c8ca282 | 1566 | * channel from MCU to TouchScreen. |
bcostm | 0:d83f1c8ca282 | 1567 | * @param Addr: I2C address |
bcostm | 0:d83f1c8ca282 | 1568 | * @param Reg: Register address |
bcostm | 0:d83f1c8ca282 | 1569 | * @param Buffer: Pointer to data buffer |
bcostm | 0:d83f1c8ca282 | 1570 | * @param Length: Length of the data |
bcostm | 0:d83f1c8ca282 | 1571 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1572 | */ |
bcostm | 0:d83f1c8ca282 | 1573 | void TS_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length) |
bcostm | 0:d83f1c8ca282 | 1574 | { |
bcostm | 0:d83f1c8ca282 | 1575 | I2Cx_WriteMultiple(&hI2cTSHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length); |
bcostm | 0:d83f1c8ca282 | 1576 | } |
bcostm | 0:d83f1c8ca282 | 1577 | |
bcostm | 0:d83f1c8ca282 | 1578 | /** |
bcostm | 0:d83f1c8ca282 | 1579 | * @brief Delay function used in TouchScreen low level driver. |
bcostm | 0:d83f1c8ca282 | 1580 | * @param Delay: Delay in ms |
bcostm | 0:d83f1c8ca282 | 1581 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1582 | */ |
bcostm | 0:d83f1c8ca282 | 1583 | void TS_IO_Delay(uint32_t Delay) |
bcostm | 0:d83f1c8ca282 | 1584 | { |
bcostm | 0:d83f1c8ca282 | 1585 | HAL_Delay(Delay); |
bcostm | 0:d83f1c8ca282 | 1586 | } |
bcostm | 0:d83f1c8ca282 | 1587 | |
bcostm | 0:d83f1c8ca282 | 1588 | |
bcostm | 0:d83f1c8ca282 | 1589 | /************************** Camera *****************************/ |
bcostm | 0:d83f1c8ca282 | 1590 | /** |
bcostm | 0:d83f1c8ca282 | 1591 | * @brief Initializes Camera low level. |
bcostm | 0:d83f1c8ca282 | 1592 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1593 | */ |
bcostm | 0:d83f1c8ca282 | 1594 | void CAMERA_IO_Init(void) |
bcostm | 0:d83f1c8ca282 | 1595 | { |
bcostm | 0:d83f1c8ca282 | 1596 | I2Cx_Init(&hI2cCameraHandler); |
bcostm | 0:d83f1c8ca282 | 1597 | } |
bcostm | 0:d83f1c8ca282 | 1598 | |
bcostm | 0:d83f1c8ca282 | 1599 | /** |
bcostm | 0:d83f1c8ca282 | 1600 | * @brief Camera writes single data. |
bcostm | 0:d83f1c8ca282 | 1601 | * @param Addr: I2C address |
bcostm | 0:d83f1c8ca282 | 1602 | * @param Reg: Register address |
bcostm | 0:d83f1c8ca282 | 1603 | * @param Value: Data to be written |
bcostm | 0:d83f1c8ca282 | 1604 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1605 | */ |
bcostm | 0:d83f1c8ca282 | 1606 | void CAMERA_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value) |
bcostm | 0:d83f1c8ca282 | 1607 | { |
bcostm | 0:d83f1c8ca282 | 1608 | I2Cx_WriteMultiple(&hI2cCameraHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t *)&Value, 1); |
bcostm | 0:d83f1c8ca282 | 1609 | } |
bcostm | 0:d83f1c8ca282 | 1610 | |
bcostm | 0:d83f1c8ca282 | 1611 | /** |
bcostm | 0:d83f1c8ca282 | 1612 | * @brief Camera reads single data. |
bcostm | 0:d83f1c8ca282 | 1613 | * @param Addr: I2C address |
bcostm | 0:d83f1c8ca282 | 1614 | * @param Reg: Register address |
bcostm | 0:d83f1c8ca282 | 1615 | * @retval Read data |
bcostm | 0:d83f1c8ca282 | 1616 | */ |
bcostm | 0:d83f1c8ca282 | 1617 | uint8_t CAMERA_IO_Read(uint8_t Addr, uint8_t Reg) |
bcostm | 0:d83f1c8ca282 | 1618 | { |
bcostm | 0:d83f1c8ca282 | 1619 | uint8_t read_value = 0; |
bcostm | 0:d83f1c8ca282 | 1620 | |
bcostm | 0:d83f1c8ca282 | 1621 | I2Cx_ReadMultiple(&hI2cCameraHandler, Addr, Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t *)&read_value, 1); |
bcostm | 0:d83f1c8ca282 | 1622 | |
bcostm | 0:d83f1c8ca282 | 1623 | return read_value; |
bcostm | 0:d83f1c8ca282 | 1624 | } |
bcostm | 0:d83f1c8ca282 | 1625 | |
bcostm | 0:d83f1c8ca282 | 1626 | /** |
bcostm | 0:d83f1c8ca282 | 1627 | * @brief Camera delay |
bcostm | 0:d83f1c8ca282 | 1628 | * @param Delay: Delay in ms |
bcostm | 0:d83f1c8ca282 | 1629 | * @retval None |
bcostm | 0:d83f1c8ca282 | 1630 | */ |
bcostm | 0:d83f1c8ca282 | 1631 | void CAMERA_Delay(uint32_t Delay) |
bcostm | 0:d83f1c8ca282 | 1632 | { |
bcostm | 0:d83f1c8ca282 | 1633 | HAL_Delay(Delay); |
bcostm | 0:d83f1c8ca282 | 1634 | } |
bcostm | 0:d83f1c8ca282 | 1635 | |
bcostm | 0:d83f1c8ca282 | 1636 | #endif /* HAL_I2C_MODULE_ENABLED */ |
bcostm | 0:d83f1c8ca282 | 1637 | |
bcostm | 0:d83f1c8ca282 | 1638 | |
bcostm | 0:d83f1c8ca282 | 1639 | __weak uint8_t BSP_LCD_Init(void) |
bcostm | 0:d83f1c8ca282 | 1640 | { |
bcostm | 0:d83f1c8ca282 | 1641 | uint8_t ret = 0; |
bcostm | 0:d83f1c8ca282 | 1642 | return ret; |
bcostm | 0:d83f1c8ca282 | 1643 | } |
bcostm | 0:d83f1c8ca282 | 1644 | |
bcostm | 0:d83f1c8ca282 | 1645 | /** |
bcostm | 0:d83f1c8ca282 | 1646 | * @} |
bcostm | 0:d83f1c8ca282 | 1647 | */ |
bcostm | 0:d83f1c8ca282 | 1648 | |
bcostm | 0:d83f1c8ca282 | 1649 | /** |
bcostm | 0:d83f1c8ca282 | 1650 | * @} |
bcostm | 0:d83f1c8ca282 | 1651 | */ |
bcostm | 0:d83f1c8ca282 | 1652 | |
bcostm | 0:d83f1c8ca282 | 1653 | /** |
bcostm | 0:d83f1c8ca282 | 1654 | * @} |
bcostm | 0:d83f1c8ca282 | 1655 | */ |
bcostm | 0:d83f1c8ca282 | 1656 | |
bcostm | 0:d83f1c8ca282 | 1657 | /** |
bcostm | 0:d83f1c8ca282 | 1658 | * @} |
bcostm | 0:d83f1c8ca282 | 1659 | */ |
bcostm | 0:d83f1c8ca282 | 1660 | |
bcostm | 0:d83f1c8ca282 | 1661 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |