fsdfsdf

Fork of BSP_DISCO_F469NI by ST

Committer:
bcostm
Date:
Fri Dec 18 07:32:01 2015 +0000
Revision:
0:0002c86c2220
Initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:0002c86c2220 1 /**
bcostm 0:0002c86c2220 2 ******************************************************************************
bcostm 0:0002c86c2220 3 * @file stm32469i_discovery.c
bcostm 0:0002c86c2220 4 * @author MCD Application Team
bcostm 0:0002c86c2220 5 * @version V1.0.1
bcostm 0:0002c86c2220 6 * @date 29-September-2015
bcostm 0:0002c86c2220 7 * @brief This file provides a set of firmware functions to manage LEDs,
bcostm 0:0002c86c2220 8 * push-buttons, external SDRAM, external QSPI Flash, RF EEPROM,
bcostm 0:0002c86c2220 9 * available on STM32469I-Discovery
bcostm 0:0002c86c2220 10 * board (MB1189) RevA/B from STMicroelectronics.
bcostm 0:0002c86c2220 11 ******************************************************************************
bcostm 0:0002c86c2220 12 * @attention
bcostm 0:0002c86c2220 13 *
bcostm 0:0002c86c2220 14 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
bcostm 0:0002c86c2220 15 *
bcostm 0:0002c86c2220 16 * Redistribution and use in source and binary forms, with or without modification,
bcostm 0:0002c86c2220 17 * are permitted provided that the following conditions are met:
bcostm 0:0002c86c2220 18 * 1. Redistributions of source code must retain the above copyright notice,
bcostm 0:0002c86c2220 19 * this list of conditions and the following disclaimer.
bcostm 0:0002c86c2220 20 * 2. Redistributions in binary form must reproduce the above copyright notice,
bcostm 0:0002c86c2220 21 * this list of conditions and the following disclaimer in the documentation
bcostm 0:0002c86c2220 22 * and/or other materials provided with the distribution.
bcostm 0:0002c86c2220 23 * 3. Neither the name of STMicroelectronics nor the names of its contributors
bcostm 0:0002c86c2220 24 * may be used to endorse or promote products derived from this software
bcostm 0:0002c86c2220 25 * without specific prior written permission.
bcostm 0:0002c86c2220 26 *
bcostm 0:0002c86c2220 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
bcostm 0:0002c86c2220 28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
bcostm 0:0002c86c2220 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
bcostm 0:0002c86c2220 30 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
bcostm 0:0002c86c2220 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
bcostm 0:0002c86c2220 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
bcostm 0:0002c86c2220 33 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
bcostm 0:0002c86c2220 34 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
bcostm 0:0002c86c2220 35 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
bcostm 0:0002c86c2220 36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bcostm 0:0002c86c2220 37 *
bcostm 0:0002c86c2220 38 ******************************************************************************
bcostm 0:0002c86c2220 39 */
bcostm 0:0002c86c2220 40
bcostm 0:0002c86c2220 41 /* Includes ------------------------------------------------------------------*/
bcostm 0:0002c86c2220 42 #include "stm32469i_discovery.h"
bcostm 0:0002c86c2220 43
bcostm 0:0002c86c2220 44 /** @addtogroup BSP
bcostm 0:0002c86c2220 45 * @{
bcostm 0:0002c86c2220 46 */
bcostm 0:0002c86c2220 47
bcostm 0:0002c86c2220 48 /** @addtogroup STM32469I_Discovery
bcostm 0:0002c86c2220 49 * @{
bcostm 0:0002c86c2220 50 */
bcostm 0:0002c86c2220 51
bcostm 0:0002c86c2220 52 /** @defgroup STM32469I_Discovery_LOW_LEVEL STM32469I-Discovery LOW LEVEL
bcostm 0:0002c86c2220 53 * @{
bcostm 0:0002c86c2220 54 */
bcostm 0:0002c86c2220 55
bcostm 0:0002c86c2220 56 /** @defgroup STM32469I_Discovery_LOW_LEVEL_Private_TypesDefinitions STM32469I Discovery Low Level Private Typedef
bcostm 0:0002c86c2220 57 * @{
bcostm 0:0002c86c2220 58 */
bcostm 0:0002c86c2220 59 /**
bcostm 0:0002c86c2220 60 * @}
bcostm 0:0002c86c2220 61 */
bcostm 0:0002c86c2220 62
bcostm 0:0002c86c2220 63 /** @defgroup STM32469I_Discovery_LOW_LEVEL_Private_Defines LOW_LEVEL Private Defines
bcostm 0:0002c86c2220 64 * @{
bcostm 0:0002c86c2220 65 */
bcostm 0:0002c86c2220 66 /**
bcostm 0:0002c86c2220 67 * @brief STM32469I Discovery BSP Driver version number V1.0.1
bcostm 0:0002c86c2220 68 */
bcostm 0:0002c86c2220 69 #define __STM32469I_DISCOVERY_BSP_VERSION_MAIN (0x01) /*!< [31:24] main version */
bcostm 0:0002c86c2220 70 #define __STM32469I_DISCOVERY_BSP_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */
bcostm 0:0002c86c2220 71 #define __STM32469I_DISCOVERY_BSP_VERSION_SUB2 (0x01) /*!< [15:8] sub2 version */
bcostm 0:0002c86c2220 72 #define __STM32469I_DISCOVERY_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */
bcostm 0:0002c86c2220 73 #define __STM32469I_DISCOVERY_BSP_VERSION ((__STM32469I_DISCOVERY_BSP_VERSION_MAIN << 24)\
bcostm 0:0002c86c2220 74 |(__STM32469I_DISCOVERY_BSP_VERSION_SUB1 << 16)\
bcostm 0:0002c86c2220 75 |(__STM32469I_DISCOVERY_BSP_VERSION_SUB2 << 8 )\
bcostm 0:0002c86c2220 76 |(__STM32469I_DISCOVERY_BSP_VERSION_RC))
bcostm 0:0002c86c2220 77 /**
bcostm 0:0002c86c2220 78 * @}
bcostm 0:0002c86c2220 79 */
bcostm 0:0002c86c2220 80
bcostm 0:0002c86c2220 81 /** @defgroup STM32469I_Discovery_LOW_LEVEL_Private_Macros LOW_LEVEL Private Macros
bcostm 0:0002c86c2220 82 * @{
bcostm 0:0002c86c2220 83 */
bcostm 0:0002c86c2220 84 /**
bcostm 0:0002c86c2220 85 * @}
bcostm 0:0002c86c2220 86 */
bcostm 0:0002c86c2220 87
bcostm 0:0002c86c2220 88 /** @defgroup STM32469I_Discovery_LOW_LEVEL_Private_Variables LOW_LEVEL Private Variables
bcostm 0:0002c86c2220 89 * @{
bcostm 0:0002c86c2220 90 */
bcostm 0:0002c86c2220 91 uint32_t GPIO_PIN[LEDn] = {LED1_PIN,
bcostm 0:0002c86c2220 92 LED2_PIN,
bcostm 0:0002c86c2220 93 LED3_PIN,
bcostm 0:0002c86c2220 94 LED4_PIN};
bcostm 0:0002c86c2220 95
bcostm 0:0002c86c2220 96 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT,
bcostm 0:0002c86c2220 97 LED2_GPIO_PORT,
bcostm 0:0002c86c2220 98 LED3_GPIO_PORT,
bcostm 0:0002c86c2220 99 LED4_GPIO_PORT};
bcostm 0:0002c86c2220 100
bcostm 0:0002c86c2220 101 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT };
bcostm 0:0002c86c2220 102
bcostm 0:0002c86c2220 103 const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN };
bcostm 0:0002c86c2220 104
bcostm 0:0002c86c2220 105 const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn };
bcostm 0:0002c86c2220 106
bcostm 0:0002c86c2220 107
bcostm 0:0002c86c2220 108 static I2C_HandleTypeDef heval_I2c1;
bcostm 0:0002c86c2220 109 static I2C_HandleTypeDef heval_I2c2;
bcostm 0:0002c86c2220 110
bcostm 0:0002c86c2220 111 /**
bcostm 0:0002c86c2220 112 * @}
bcostm 0:0002c86c2220 113 */
bcostm 0:0002c86c2220 114
bcostm 0:0002c86c2220 115 /** @defgroup STM32469I_Discovery_LOW_LEVEL_Private_FunctionPrototypes LOW_LEVEL Private FunctionPrototypes
bcostm 0:0002c86c2220 116 * @{
bcostm 0:0002c86c2220 117 */
bcostm 0:0002c86c2220 118 static void I2C1_MspInit(void);
bcostm 0:0002c86c2220 119 static void I2C2_MspInit(void);
bcostm 0:0002c86c2220 120 static void I2C1_Init(void);
bcostm 0:0002c86c2220 121 static void I2C2_Init(void);
bcostm 0:0002c86c2220 122
bcostm 0:0002c86c2220 123 #if defined(USE_IOEXPANDER)
bcostm 0:0002c86c2220 124 static void I2C1_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
bcostm 0:0002c86c2220 125 static uint8_t I2C1_Read(uint8_t Addr, uint8_t Reg);
bcostm 0:0002c86c2220 126 #endif /* USE_IOEXPANDER */
bcostm 0:0002c86c2220 127 static HAL_StatusTypeDef I2C1_ReadMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
bcostm 0:0002c86c2220 128 static HAL_StatusTypeDef I2C2_ReadMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
bcostm 0:0002c86c2220 129 static HAL_StatusTypeDef I2C1_WriteMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
bcostm 0:0002c86c2220 130 static HAL_StatusTypeDef I2C2_WriteMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
bcostm 0:0002c86c2220 131 static HAL_StatusTypeDef I2C1_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);
bcostm 0:0002c86c2220 132 static void I2C1_Error(uint8_t Addr);
bcostm 0:0002c86c2220 133 static void I2C2_Error(uint8_t Addr);
bcostm 0:0002c86c2220 134
bcostm 0:0002c86c2220 135 /* AUDIO IO functions */
bcostm 0:0002c86c2220 136 void AUDIO_IO_Init(void);
bcostm 0:0002c86c2220 137 void AUDIO_IO_DeInit(void);
bcostm 0:0002c86c2220 138 void AUDIO_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
bcostm 0:0002c86c2220 139 uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg);
bcostm 0:0002c86c2220 140 void AUDIO_IO_Delay(uint32_t Delay);
bcostm 0:0002c86c2220 141
bcostm 0:0002c86c2220 142
bcostm 0:0002c86c2220 143 /* I2C EEPROM IO function */
bcostm 0:0002c86c2220 144 void EEPROM_IO_Init(void);
bcostm 0:0002c86c2220 145 HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize);
bcostm 0:0002c86c2220 146 HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize);
bcostm 0:0002c86c2220 147 HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);
bcostm 0:0002c86c2220 148
bcostm 0:0002c86c2220 149 /* TouchScreen (TS) IO functions */
bcostm 0:0002c86c2220 150 void TS_IO_Init(void);
bcostm 0:0002c86c2220 151 void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
bcostm 0:0002c86c2220 152 uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg);
bcostm 0:0002c86c2220 153 uint16_t TS_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
bcostm 0:0002c86c2220 154 void TS_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
bcostm 0:0002c86c2220 155 void TS_IO_Delay(uint32_t Delay);
bcostm 0:0002c86c2220 156 void OTM8009A_IO_Delay(uint32_t Delay);
bcostm 0:0002c86c2220 157 /**
bcostm 0:0002c86c2220 158 * @}
bcostm 0:0002c86c2220 159 */
bcostm 0:0002c86c2220 160
bcostm 0:0002c86c2220 161 /** @defgroup STM32469I_Discovery_BSP_Public_Functions BSP Public Functions
bcostm 0:0002c86c2220 162 * @{
bcostm 0:0002c86c2220 163 */
bcostm 0:0002c86c2220 164
bcostm 0:0002c86c2220 165 /**
bcostm 0:0002c86c2220 166 * @brief This method returns the STM32469I Discovery BSP Driver revision
bcostm 0:0002c86c2220 167 * @retval version: 0xXYZR (8bits for each decimal, R for RC)
bcostm 0:0002c86c2220 168 */
bcostm 0:0002c86c2220 169 uint32_t BSP_GetVersion(void)
bcostm 0:0002c86c2220 170 {
bcostm 0:0002c86c2220 171 return __STM32469I_DISCOVERY_BSP_VERSION;
bcostm 0:0002c86c2220 172 }
bcostm 0:0002c86c2220 173
bcostm 0:0002c86c2220 174 /**
bcostm 0:0002c86c2220 175 * @brief Configures LED GPIO.
bcostm 0:0002c86c2220 176 * @param Led: LED to be configured.
bcostm 0:0002c86c2220 177 * This parameter can be one of the following values:
bcostm 0:0002c86c2220 178 * @arg LED1
bcostm 0:0002c86c2220 179 * @arg LED2
bcostm 0:0002c86c2220 180 * @arg LED3
bcostm 0:0002c86c2220 181 * @arg LED4
bcostm 0:0002c86c2220 182 * @retval None
bcostm 0:0002c86c2220 183 */
bcostm 0:0002c86c2220 184 void BSP_LED_Init(Led_TypeDef Led)
bcostm 0:0002c86c2220 185 {
bcostm 0:0002c86c2220 186 GPIO_InitTypeDef gpio_init_structure;
bcostm 0:0002c86c2220 187
bcostm 0:0002c86c2220 188 if (Led <= DISCO_LED4)
bcostm 0:0002c86c2220 189 {
bcostm 0:0002c86c2220 190 /* Configure the GPIO_LED pin */
bcostm 0:0002c86c2220 191 gpio_init_structure.Pin = GPIO_PIN[Led];
bcostm 0:0002c86c2220 192 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
bcostm 0:0002c86c2220 193 gpio_init_structure.Pull = GPIO_PULLUP;
bcostm 0:0002c86c2220 194 gpio_init_structure.Speed = GPIO_SPEED_HIGH;
bcostm 0:0002c86c2220 195
bcostm 0:0002c86c2220 196 switch(Led)
bcostm 0:0002c86c2220 197 {
bcostm 0:0002c86c2220 198 case DISCO_LED1 :
bcostm 0:0002c86c2220 199 LED1_GPIO_CLK_ENABLE();
bcostm 0:0002c86c2220 200 break;
bcostm 0:0002c86c2220 201 case DISCO_LED2 :
bcostm 0:0002c86c2220 202 LED2_GPIO_CLK_ENABLE();
bcostm 0:0002c86c2220 203 break;
bcostm 0:0002c86c2220 204 case DISCO_LED3 :
bcostm 0:0002c86c2220 205 LED3_GPIO_CLK_ENABLE();
bcostm 0:0002c86c2220 206 break;
bcostm 0:0002c86c2220 207 case DISCO_LED4 :
bcostm 0:0002c86c2220 208 LED4_GPIO_CLK_ENABLE();
bcostm 0:0002c86c2220 209 break;
bcostm 0:0002c86c2220 210 default :
bcostm 0:0002c86c2220 211 break;
bcostm 0:0002c86c2220 212
bcostm 0:0002c86c2220 213 } /* end switch */
bcostm 0:0002c86c2220 214
bcostm 0:0002c86c2220 215 HAL_GPIO_Init(GPIO_PORT[Led], &gpio_init_structure);
bcostm 0:0002c86c2220 216
bcostm 0:0002c86c2220 217 /* By default, turn off LED by setting a high level on corresponding GPIO */
bcostm 0:0002c86c2220 218 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
bcostm 0:0002c86c2220 219
bcostm 0:0002c86c2220 220 } /* of if (Led <= LED4) */
bcostm 0:0002c86c2220 221
bcostm 0:0002c86c2220 222 }
bcostm 0:0002c86c2220 223
bcostm 0:0002c86c2220 224
bcostm 0:0002c86c2220 225 /**
bcostm 0:0002c86c2220 226 * @brief DeInit LEDs.
bcostm 0:0002c86c2220 227 * @param Led: LED to be configured.
bcostm 0:0002c86c2220 228 * This parameter can be one of the following values:
bcostm 0:0002c86c2220 229 * @arg LED1
bcostm 0:0002c86c2220 230 * @arg LED2
bcostm 0:0002c86c2220 231 * @arg LED3
bcostm 0:0002c86c2220 232 * @arg LED4
bcostm 0:0002c86c2220 233 * @note Led DeInit does not disable the GPIO clock nor disable the Mfx
bcostm 0:0002c86c2220 234 * @retval None
bcostm 0:0002c86c2220 235 */
bcostm 0:0002c86c2220 236 void BSP_LED_DeInit(Led_TypeDef Led)
bcostm 0:0002c86c2220 237 {
bcostm 0:0002c86c2220 238 GPIO_InitTypeDef gpio_init_structure;
bcostm 0:0002c86c2220 239
bcostm 0:0002c86c2220 240 if (Led <= DISCO_LED4)
bcostm 0:0002c86c2220 241 {
bcostm 0:0002c86c2220 242 /* DeInit the GPIO_LED pin */
bcostm 0:0002c86c2220 243 gpio_init_structure.Pin = GPIO_PIN[Led];
bcostm 0:0002c86c2220 244
bcostm 0:0002c86c2220 245 /* Turn off LED */
bcostm 0:0002c86c2220 246 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
bcostm 0:0002c86c2220 247 HAL_GPIO_DeInit(GPIO_PORT[Led], gpio_init_structure.Pin);
bcostm 0:0002c86c2220 248 }
bcostm 0:0002c86c2220 249
bcostm 0:0002c86c2220 250 }
bcostm 0:0002c86c2220 251
bcostm 0:0002c86c2220 252 /**
bcostm 0:0002c86c2220 253 * @brief Turns selected LED On.
bcostm 0:0002c86c2220 254 * @param Led: LED to be set on
bcostm 0:0002c86c2220 255 * This parameter can be one of the following values:
bcostm 0:0002c86c2220 256 * @arg LED1
bcostm 0:0002c86c2220 257 * @arg LED2
bcostm 0:0002c86c2220 258 * @arg LED3
bcostm 0:0002c86c2220 259 * @arg LED4
bcostm 0:0002c86c2220 260 * @retval None
bcostm 0:0002c86c2220 261 */
bcostm 0:0002c86c2220 262 void BSP_LED_On(Led_TypeDef Led)
bcostm 0:0002c86c2220 263 {
bcostm 0:0002c86c2220 264 if (Led <= DISCO_LED4)
bcostm 0:0002c86c2220 265 {
bcostm 0:0002c86c2220 266 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
bcostm 0:0002c86c2220 267 }
bcostm 0:0002c86c2220 268
bcostm 0:0002c86c2220 269 }
bcostm 0:0002c86c2220 270
bcostm 0:0002c86c2220 271 /**
bcostm 0:0002c86c2220 272 * @brief Turns selected LED Off.
bcostm 0:0002c86c2220 273 * @param Led: LED to be set off
bcostm 0:0002c86c2220 274 * This parameter can be one of the following values:
bcostm 0:0002c86c2220 275 * @arg LED1
bcostm 0:0002c86c2220 276 * @arg LED2
bcostm 0:0002c86c2220 277 * @arg LED3
bcostm 0:0002c86c2220 278 * @arg LED4
bcostm 0:0002c86c2220 279 * @retval None
bcostm 0:0002c86c2220 280 */
bcostm 0:0002c86c2220 281 void BSP_LED_Off(Led_TypeDef Led)
bcostm 0:0002c86c2220 282 {
bcostm 0:0002c86c2220 283 if (Led <= DISCO_LED4)
bcostm 0:0002c86c2220 284 {
bcostm 0:0002c86c2220 285 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
bcostm 0:0002c86c2220 286 }
bcostm 0:0002c86c2220 287 }
bcostm 0:0002c86c2220 288
bcostm 0:0002c86c2220 289 /**
bcostm 0:0002c86c2220 290 * @brief Toggles the selected LED.
bcostm 0:0002c86c2220 291 * @param Led: LED to be toggled
bcostm 0:0002c86c2220 292 * This parameter can be one of the following values:
bcostm 0:0002c86c2220 293 * @arg LED1
bcostm 0:0002c86c2220 294 * @arg LED2
bcostm 0:0002c86c2220 295 * @arg LED3
bcostm 0:0002c86c2220 296 * @arg LED4
bcostm 0:0002c86c2220 297 * @retval None
bcostm 0:0002c86c2220 298 */
bcostm 0:0002c86c2220 299 void BSP_LED_Toggle(Led_TypeDef Led)
bcostm 0:0002c86c2220 300 {
bcostm 0:0002c86c2220 301 if (Led <= DISCO_LED4)
bcostm 0:0002c86c2220 302 {
bcostm 0:0002c86c2220 303 HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]);
bcostm 0:0002c86c2220 304 }
bcostm 0:0002c86c2220 305 }
bcostm 0:0002c86c2220 306
bcostm 0:0002c86c2220 307 /**
bcostm 0:0002c86c2220 308 * @brief Configures button GPIO and EXTI Line.
bcostm 0:0002c86c2220 309 * @param Button: Button to be configured
bcostm 0:0002c86c2220 310 * This parameter can be one of the following values:
bcostm 0:0002c86c2220 311 * @arg BUTTON_WAKEUP: Wakeup Push Button
bcostm 0:0002c86c2220 312 * @arg BUTTON_USER: User Push Button
bcostm 0:0002c86c2220 313 * @param Button_Mode: Button mode
bcostm 0:0002c86c2220 314 * This parameter can be one of the following values:
bcostm 0:0002c86c2220 315 * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
bcostm 0:0002c86c2220 316 * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line
bcostm 0:0002c86c2220 317 * with interrupt generation capability
bcostm 0:0002c86c2220 318 * @retval None
bcostm 0:0002c86c2220 319 */
bcostm 0:0002c86c2220 320 void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
bcostm 0:0002c86c2220 321 {
bcostm 0:0002c86c2220 322 GPIO_InitTypeDef gpio_init_structure;
bcostm 0:0002c86c2220 323
bcostm 0:0002c86c2220 324 /* Enable the BUTTON clock */
bcostm 0:0002c86c2220 325 BUTTON_GPIO_CLK_ENABLE();
bcostm 0:0002c86c2220 326
bcostm 0:0002c86c2220 327 if(Button_Mode == BUTTON_MODE_GPIO)
bcostm 0:0002c86c2220 328 {
bcostm 0:0002c86c2220 329 /* Configure Button pin as input */
bcostm 0:0002c86c2220 330 gpio_init_structure.Pin = BUTTON_PIN[Button];
bcostm 0:0002c86c2220 331 gpio_init_structure.Mode = GPIO_MODE_INPUT;
bcostm 0:0002c86c2220 332 gpio_init_structure.Pull = GPIO_NOPULL;
bcostm 0:0002c86c2220 333 gpio_init_structure.Speed = GPIO_SPEED_FAST;
bcostm 0:0002c86c2220 334 HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure);
bcostm 0:0002c86c2220 335 }
bcostm 0:0002c86c2220 336
bcostm 0:0002c86c2220 337 if(Button_Mode == BUTTON_MODE_EXTI)
bcostm 0:0002c86c2220 338 {
bcostm 0:0002c86c2220 339 /* Configure Button pin as input with External interrupt */
bcostm 0:0002c86c2220 340 gpio_init_structure.Pin = BUTTON_PIN[Button];
bcostm 0:0002c86c2220 341 gpio_init_structure.Pull = GPIO_NOPULL;
bcostm 0:0002c86c2220 342 gpio_init_structure.Speed = GPIO_SPEED_FAST;
bcostm 0:0002c86c2220 343
bcostm 0:0002c86c2220 344 gpio_init_structure.Mode = GPIO_MODE_IT_RISING;
bcostm 0:0002c86c2220 345
bcostm 0:0002c86c2220 346 HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure);
bcostm 0:0002c86c2220 347
bcostm 0:0002c86c2220 348 /* Enable and set Button EXTI Interrupt to the lowest priority */
bcostm 0:0002c86c2220 349 HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00);
bcostm 0:0002c86c2220 350 HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
bcostm 0:0002c86c2220 351 }
bcostm 0:0002c86c2220 352 }
bcostm 0:0002c86c2220 353
bcostm 0:0002c86c2220 354 /**
bcostm 0:0002c86c2220 355 * @brief Push Button DeInit.
bcostm 0:0002c86c2220 356 * @param Button: Button to be configured
bcostm 0:0002c86c2220 357 * This parameter can be one of the following values:
bcostm 0:0002c86c2220 358 * @arg BUTTON_WAKEUP: Wakeup Push Button
bcostm 0:0002c86c2220 359 * @arg BUTTON_USER: User Push Button
bcostm 0:0002c86c2220 360 * @note PB DeInit does not disable the GPIO clock
bcostm 0:0002c86c2220 361 * @retval None
bcostm 0:0002c86c2220 362 */
bcostm 0:0002c86c2220 363 void BSP_PB_DeInit(Button_TypeDef Button)
bcostm 0:0002c86c2220 364 {
bcostm 0:0002c86c2220 365 GPIO_InitTypeDef gpio_init_structure;
bcostm 0:0002c86c2220 366
bcostm 0:0002c86c2220 367 gpio_init_structure.Pin = BUTTON_PIN[Button];
bcostm 0:0002c86c2220 368 HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
bcostm 0:0002c86c2220 369 HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin);
bcostm 0:0002c86c2220 370 }
bcostm 0:0002c86c2220 371
bcostm 0:0002c86c2220 372
bcostm 0:0002c86c2220 373 /**
bcostm 0:0002c86c2220 374 * @brief Returns the selected button state.
bcostm 0:0002c86c2220 375 * @param Button: Button to be checked
bcostm 0:0002c86c2220 376 * This parameter can be one of the following values:
bcostm 0:0002c86c2220 377 * @arg BUTTON_WAKEUP: Wakeup Push Button
bcostm 0:0002c86c2220 378 * @arg BUTTON_USER: User Push Button
bcostm 0:0002c86c2220 379 * @retval The Button GPIO pin value
bcostm 0:0002c86c2220 380 */
bcostm 0:0002c86c2220 381 uint32_t BSP_PB_GetState(Button_TypeDef Button)
bcostm 0:0002c86c2220 382 {
bcostm 0:0002c86c2220 383 return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
bcostm 0:0002c86c2220 384 }
bcostm 0:0002c86c2220 385
bcostm 0:0002c86c2220 386 /**
bcostm 0:0002c86c2220 387 * @}
bcostm 0:0002c86c2220 388 */
bcostm 0:0002c86c2220 389
bcostm 0:0002c86c2220 390 /** @defgroup STM32469I_Discovery_LOW_LEVEL_Private_Functions STM32469I_Discovery_LOW_LEVEL Private Functions
bcostm 0:0002c86c2220 391 * @{
bcostm 0:0002c86c2220 392 */
bcostm 0:0002c86c2220 393
bcostm 0:0002c86c2220 394
bcostm 0:0002c86c2220 395 /*******************************************************************************
bcostm 0:0002c86c2220 396 BUS OPERATIONS
bcostm 0:0002c86c2220 397 *******************************************************************************/
bcostm 0:0002c86c2220 398
bcostm 0:0002c86c2220 399 /******************************* I2C Routines *********************************/
bcostm 0:0002c86c2220 400 /**
bcostm 0:0002c86c2220 401 * @brief Initializes I2C MSP.
bcostm 0:0002c86c2220 402 */
bcostm 0:0002c86c2220 403 static void I2C1_MspInit(void)
bcostm 0:0002c86c2220 404 {
bcostm 0:0002c86c2220 405 GPIO_InitTypeDef gpio_init_structure;
bcostm 0:0002c86c2220 406
bcostm 0:0002c86c2220 407 /*** Configure the GPIOs ***/
bcostm 0:0002c86c2220 408 /* Enable GPIO clock */
bcostm 0:0002c86c2220 409 DISCO_I2C1_SCL_SDA_GPIO_CLK_ENABLE();
bcostm 0:0002c86c2220 410
bcostm 0:0002c86c2220 411 /* Configure I2C Tx as alternate function */
bcostm 0:0002c86c2220 412 gpio_init_structure.Pin = DISCO_I2C1_SCL_PIN;
bcostm 0:0002c86c2220 413 gpio_init_structure.Mode = GPIO_MODE_AF_OD;
bcostm 0:0002c86c2220 414 gpio_init_structure.Pull = GPIO_NOPULL;
bcostm 0:0002c86c2220 415 gpio_init_structure.Speed = GPIO_SPEED_FAST;
bcostm 0:0002c86c2220 416 gpio_init_structure.Alternate = DISCO_I2C1_SCL_SDA_AF;
bcostm 0:0002c86c2220 417 HAL_GPIO_Init(DISCO_I2C1_SCL_SDA_GPIO_PORT, &gpio_init_structure);
bcostm 0:0002c86c2220 418
bcostm 0:0002c86c2220 419 /* Configure I2C Rx as alternate function */
bcostm 0:0002c86c2220 420 gpio_init_structure.Pin = DISCO_I2C1_SDA_PIN;
bcostm 0:0002c86c2220 421 HAL_GPIO_Init(DISCO_I2C1_SCL_SDA_GPIO_PORT, &gpio_init_structure);
bcostm 0:0002c86c2220 422
bcostm 0:0002c86c2220 423 /*** Configure the I2C peripheral ***/
bcostm 0:0002c86c2220 424 /* Enable I2C clock */
bcostm 0:0002c86c2220 425 DISCO_I2C1_CLK_ENABLE();
bcostm 0:0002c86c2220 426
bcostm 0:0002c86c2220 427 /* Force the I2C peripheral clock reset */
bcostm 0:0002c86c2220 428 DISCO_I2C1_FORCE_RESET();
bcostm 0:0002c86c2220 429
bcostm 0:0002c86c2220 430 /* Release the I2C peripheral clock reset */
bcostm 0:0002c86c2220 431 DISCO_I2C1_RELEASE_RESET();
bcostm 0:0002c86c2220 432
bcostm 0:0002c86c2220 433 /* Enable and set I2C1 Interrupt to a lower priority */
bcostm 0:0002c86c2220 434 HAL_NVIC_SetPriority(DISCO_I2C1_EV_IRQn, 0x05, 0);
bcostm 0:0002c86c2220 435 HAL_NVIC_EnableIRQ(DISCO_I2C1_EV_IRQn);
bcostm 0:0002c86c2220 436
bcostm 0:0002c86c2220 437 /* Enable and set I2C1 Interrupt to a lower priority */
bcostm 0:0002c86c2220 438 HAL_NVIC_SetPriority(DISCO_I2C1_ER_IRQn, 0x05, 0);
bcostm 0:0002c86c2220 439 HAL_NVIC_EnableIRQ(DISCO_I2C1_ER_IRQn);
bcostm 0:0002c86c2220 440 }
bcostm 0:0002c86c2220 441
bcostm 0:0002c86c2220 442 /**
bcostm 0:0002c86c2220 443 * @brief Initializes I2C MSP.
bcostm 0:0002c86c2220 444 */
bcostm 0:0002c86c2220 445 static void I2C2_MspInit(void)
bcostm 0:0002c86c2220 446 {
bcostm 0:0002c86c2220 447 GPIO_InitTypeDef gpio_init_structure;
bcostm 0:0002c86c2220 448
bcostm 0:0002c86c2220 449 /*** Configure the GPIOs ***/
bcostm 0:0002c86c2220 450 /* Enable GPIO clock */
bcostm 0:0002c86c2220 451 DISCO_I2C2_SCL_SDA_GPIO_CLK_ENABLE();
bcostm 0:0002c86c2220 452
bcostm 0:0002c86c2220 453 /* Configure I2C Tx as alternate function */
bcostm 0:0002c86c2220 454 gpio_init_structure.Pin = DISCO_I2C2_SCL_PIN;
bcostm 0:0002c86c2220 455 gpio_init_structure.Mode = GPIO_MODE_AF_OD;
bcostm 0:0002c86c2220 456 gpio_init_structure.Pull = GPIO_NOPULL;
bcostm 0:0002c86c2220 457 gpio_init_structure.Speed = GPIO_SPEED_FAST;
bcostm 0:0002c86c2220 458 gpio_init_structure.Alternate = DISCO_I2C2_SCL_SDA_AF;
bcostm 0:0002c86c2220 459 HAL_GPIO_Init(DISCO_I2C2_SCL_SDA_GPIO_PORT, &gpio_init_structure);
bcostm 0:0002c86c2220 460
bcostm 0:0002c86c2220 461 /* Configure I2C Rx as alternate function */
bcostm 0:0002c86c2220 462 gpio_init_structure.Pin = DISCO_I2C2_SDA_PIN;
bcostm 0:0002c86c2220 463 HAL_GPIO_Init(DISCO_I2C2_SCL_SDA_GPIO_PORT, &gpio_init_structure);
bcostm 0:0002c86c2220 464
bcostm 0:0002c86c2220 465 /*** Configure the I2C peripheral ***/
bcostm 0:0002c86c2220 466 /* Enable I2C clock */
bcostm 0:0002c86c2220 467 DISCO_I2C2_CLK_ENABLE();
bcostm 0:0002c86c2220 468
bcostm 0:0002c86c2220 469 /* Force the I2C peripheral clock reset */
bcostm 0:0002c86c2220 470 DISCO_I2C2_FORCE_RESET();
bcostm 0:0002c86c2220 471
bcostm 0:0002c86c2220 472 /* Release the I2C peripheral clock reset */
bcostm 0:0002c86c2220 473 DISCO_I2C2_RELEASE_RESET();
bcostm 0:0002c86c2220 474
bcostm 0:0002c86c2220 475 /* Enable and set I2C1 Interrupt to a lower priority */
bcostm 0:0002c86c2220 476 HAL_NVIC_SetPriority(DISCO_I2C2_EV_IRQn, 0x05, 0);
bcostm 0:0002c86c2220 477 HAL_NVIC_EnableIRQ(DISCO_I2C2_EV_IRQn);
bcostm 0:0002c86c2220 478
bcostm 0:0002c86c2220 479 /* Enable and set I2C1 Interrupt to a lower priority */
bcostm 0:0002c86c2220 480 HAL_NVIC_SetPriority(DISCO_I2C2_ER_IRQn, 0x05, 0);
bcostm 0:0002c86c2220 481 HAL_NVIC_EnableIRQ(DISCO_I2C2_ER_IRQn);
bcostm 0:0002c86c2220 482 }
bcostm 0:0002c86c2220 483
bcostm 0:0002c86c2220 484 /**
bcostm 0:0002c86c2220 485 * @brief Initializes I2C HAL.
bcostm 0:0002c86c2220 486 */
bcostm 0:0002c86c2220 487 static void I2C1_Init(void)
bcostm 0:0002c86c2220 488 {
bcostm 0:0002c86c2220 489 if(HAL_I2C_GetState(&heval_I2c1) == HAL_I2C_STATE_RESET)
bcostm 0:0002c86c2220 490 {
bcostm 0:0002c86c2220 491 heval_I2c1.Instance = I2C1;
bcostm 0:0002c86c2220 492 heval_I2c1.Init.ClockSpeed = I2C1_SCL_FREQ_KHZ;
bcostm 0:0002c86c2220 493 heval_I2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
bcostm 0:0002c86c2220 494 heval_I2c1.Init.OwnAddress1 = 0;
bcostm 0:0002c86c2220 495 heval_I2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
bcostm 0:0002c86c2220 496 heval_I2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
bcostm 0:0002c86c2220 497 heval_I2c1.Init.OwnAddress2 = 0;
bcostm 0:0002c86c2220 498 heval_I2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
bcostm 0:0002c86c2220 499 heval_I2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
bcostm 0:0002c86c2220 500
bcostm 0:0002c86c2220 501 /* Init the I2C */
bcostm 0:0002c86c2220 502 I2C1_MspInit();
bcostm 0:0002c86c2220 503 HAL_I2C_Init(&heval_I2c1);
bcostm 0:0002c86c2220 504 }
bcostm 0:0002c86c2220 505 }
bcostm 0:0002c86c2220 506
bcostm 0:0002c86c2220 507 /**
bcostm 0:0002c86c2220 508 * @brief Initializes I2C HAL.
bcostm 0:0002c86c2220 509 */
bcostm 0:0002c86c2220 510 static void I2C2_Init(void)
bcostm 0:0002c86c2220 511 {
bcostm 0:0002c86c2220 512 if(HAL_I2C_GetState(&heval_I2c2) == HAL_I2C_STATE_RESET)
bcostm 0:0002c86c2220 513 {
bcostm 0:0002c86c2220 514 heval_I2c2.Instance = I2C2;
bcostm 0:0002c86c2220 515 heval_I2c2.Init.ClockSpeed = I2C2_SCL_FREQ_KHZ;
bcostm 0:0002c86c2220 516 heval_I2c2.Init.DutyCycle = I2C_DUTYCYCLE_2;
bcostm 0:0002c86c2220 517 heval_I2c2.Init.OwnAddress1 = 0;
bcostm 0:0002c86c2220 518 heval_I2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
bcostm 0:0002c86c2220 519 heval_I2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
bcostm 0:0002c86c2220 520 heval_I2c2.Init.OwnAddress2 = 0;
bcostm 0:0002c86c2220 521 heval_I2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
bcostm 0:0002c86c2220 522 heval_I2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
bcostm 0:0002c86c2220 523
bcostm 0:0002c86c2220 524 /* Init the I2C */
bcostm 0:0002c86c2220 525 I2C2_MspInit();
bcostm 0:0002c86c2220 526 HAL_I2C_Init(&heval_I2c2);
bcostm 0:0002c86c2220 527 }
bcostm 0:0002c86c2220 528 }
bcostm 0:0002c86c2220 529
bcostm 0:0002c86c2220 530 /**
bcostm 0:0002c86c2220 531 * @brief Writes a single data.
bcostm 0:0002c86c2220 532 * @param Addr: I2C address
bcostm 0:0002c86c2220 533 * @param Reg: Register address
bcostm 0:0002c86c2220 534 * @param Value: Data to be written
bcostm 0:0002c86c2220 535 */
bcostm 0:0002c86c2220 536 static void I2C1_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
bcostm 0:0002c86c2220 537 {
bcostm 0:0002c86c2220 538 HAL_StatusTypeDef status = HAL_OK;
bcostm 0:0002c86c2220 539
bcostm 0:0002c86c2220 540 status = HAL_I2C_Mem_Write(&heval_I2c1,
bcostm 0:0002c86c2220 541 Addr,
bcostm 0:0002c86c2220 542 (uint16_t)Reg,
bcostm 0:0002c86c2220 543 I2C_MEMADD_SIZE_8BIT,
bcostm 0:0002c86c2220 544 &Value,
bcostm 0:0002c86c2220 545 1,
bcostm 0:0002c86c2220 546 100);
bcostm 0:0002c86c2220 547
bcostm 0:0002c86c2220 548 /* Check the communication status */
bcostm 0:0002c86c2220 549 if(status != HAL_OK)
bcostm 0:0002c86c2220 550 {
bcostm 0:0002c86c2220 551 /* Execute user timeout callback */
bcostm 0:0002c86c2220 552 I2C1_Error(Addr);
bcostm 0:0002c86c2220 553 }
bcostm 0:0002c86c2220 554 }
bcostm 0:0002c86c2220 555
bcostm 0:0002c86c2220 556 /**
bcostm 0:0002c86c2220 557 * @brief Reads a single data.
bcostm 0:0002c86c2220 558 * @param Addr: I2C address
bcostm 0:0002c86c2220 559 * @param Reg: Register address
bcostm 0:0002c86c2220 560 * @retval Read data
bcostm 0:0002c86c2220 561 */
bcostm 0:0002c86c2220 562 static uint8_t I2C1_Read(uint8_t Addr, uint8_t Reg)
bcostm 0:0002c86c2220 563 {
bcostm 0:0002c86c2220 564 HAL_StatusTypeDef status = HAL_OK;
bcostm 0:0002c86c2220 565 uint8_t Value = 0;
bcostm 0:0002c86c2220 566
bcostm 0:0002c86c2220 567 status = HAL_I2C_Mem_Read(&heval_I2c1,
bcostm 0:0002c86c2220 568 Addr,
bcostm 0:0002c86c2220 569 Reg,
bcostm 0:0002c86c2220 570 I2C_MEMADD_SIZE_8BIT,
bcostm 0:0002c86c2220 571 &Value,
bcostm 0:0002c86c2220 572 1,
bcostm 0:0002c86c2220 573 1000);
bcostm 0:0002c86c2220 574
bcostm 0:0002c86c2220 575 /* Check the communication status */
bcostm 0:0002c86c2220 576 if(status != HAL_OK)
bcostm 0:0002c86c2220 577 {
bcostm 0:0002c86c2220 578 /* Execute user timeout callback */
bcostm 0:0002c86c2220 579 I2C1_Error(Addr);
bcostm 0:0002c86c2220 580 }
bcostm 0:0002c86c2220 581 return Value;
bcostm 0:0002c86c2220 582 }
bcostm 0:0002c86c2220 583
bcostm 0:0002c86c2220 584 /**
bcostm 0:0002c86c2220 585 * @brief Reads multiple data.
bcostm 0:0002c86c2220 586 * @param Addr: I2C address
bcostm 0:0002c86c2220 587 * @param Reg: Reg address
bcostm 0:0002c86c2220 588 * @param MemAddress: memory address
bcostm 0:0002c86c2220 589 * @param Buffer: Pointer to data buffer
bcostm 0:0002c86c2220 590 * @param Length: Length of the data
bcostm 0:0002c86c2220 591 * @retval HAL status
bcostm 0:0002c86c2220 592 */
bcostm 0:0002c86c2220 593 static HAL_StatusTypeDef I2C1_ReadMultiple(uint8_t Addr,
bcostm 0:0002c86c2220 594 uint16_t Reg,
bcostm 0:0002c86c2220 595 uint16_t MemAddress,
bcostm 0:0002c86c2220 596 uint8_t *Buffer,
bcostm 0:0002c86c2220 597 uint16_t Length)
bcostm 0:0002c86c2220 598 {
bcostm 0:0002c86c2220 599 HAL_StatusTypeDef status = HAL_OK;
bcostm 0:0002c86c2220 600
bcostm 0:0002c86c2220 601 status = HAL_I2C_Mem_Read(&heval_I2c1,
bcostm 0:0002c86c2220 602 Addr,
bcostm 0:0002c86c2220 603 (uint16_t)Reg,
bcostm 0:0002c86c2220 604 MemAddress,
bcostm 0:0002c86c2220 605 Buffer,
bcostm 0:0002c86c2220 606 Length,
bcostm 0:0002c86c2220 607 1000);
bcostm 0:0002c86c2220 608
bcostm 0:0002c86c2220 609 /* Check the communication status */
bcostm 0:0002c86c2220 610 if(status != HAL_OK)
bcostm 0:0002c86c2220 611 {
bcostm 0:0002c86c2220 612 /* I2C error occured */
bcostm 0:0002c86c2220 613 I2C1_Error(Addr);
bcostm 0:0002c86c2220 614 }
bcostm 0:0002c86c2220 615 return status;
bcostm 0:0002c86c2220 616 }
bcostm 0:0002c86c2220 617
bcostm 0:0002c86c2220 618 static HAL_StatusTypeDef I2C2_ReadMultiple(uint8_t Addr,
bcostm 0:0002c86c2220 619 uint16_t Reg,
bcostm 0:0002c86c2220 620 uint16_t MemAddress,
bcostm 0:0002c86c2220 621 uint8_t *Buffer,
bcostm 0:0002c86c2220 622 uint16_t Length)
bcostm 0:0002c86c2220 623 {
bcostm 0:0002c86c2220 624 HAL_StatusTypeDef status = HAL_OK;
bcostm 0:0002c86c2220 625
bcostm 0:0002c86c2220 626 status = HAL_I2C_Mem_Read(&heval_I2c2,
bcostm 0:0002c86c2220 627 Addr,
bcostm 0:0002c86c2220 628 (uint16_t)Reg,
bcostm 0:0002c86c2220 629 MemAddress,
bcostm 0:0002c86c2220 630 Buffer,
bcostm 0:0002c86c2220 631 Length,
bcostm 0:0002c86c2220 632 1000);
bcostm 0:0002c86c2220 633
bcostm 0:0002c86c2220 634 /* Check the communication status */
bcostm 0:0002c86c2220 635 if(status != HAL_OK)
bcostm 0:0002c86c2220 636 {
bcostm 0:0002c86c2220 637 /* I2C2 error occured */
bcostm 0:0002c86c2220 638 I2C2_Error(Addr);
bcostm 0:0002c86c2220 639 }
bcostm 0:0002c86c2220 640 return status;
bcostm 0:0002c86c2220 641 }
bcostm 0:0002c86c2220 642
bcostm 0:0002c86c2220 643 /**
bcostm 0:0002c86c2220 644 * @brief Writes a value in a register of the device through BUS in using DMA mode.
bcostm 0:0002c86c2220 645 * @param Addr: Device address on BUS Bus.
bcostm 0:0002c86c2220 646 * @param Reg: The target register address to write
bcostm 0:0002c86c2220 647 * @param MemAddress: memory address
bcostm 0:0002c86c2220 648 * @param Buffer: The target register value to be written
bcostm 0:0002c86c2220 649 * @param Length: buffer size to be written
bcostm 0:0002c86c2220 650 * @retval HAL status
bcostm 0:0002c86c2220 651 */
bcostm 0:0002c86c2220 652 static HAL_StatusTypeDef I2C1_WriteMultiple(uint8_t Addr,
bcostm 0:0002c86c2220 653 uint16_t Reg,
bcostm 0:0002c86c2220 654 uint16_t MemAddress,
bcostm 0:0002c86c2220 655 uint8_t *Buffer,
bcostm 0:0002c86c2220 656 uint16_t Length)
bcostm 0:0002c86c2220 657 {
bcostm 0:0002c86c2220 658 HAL_StatusTypeDef status = HAL_OK;
bcostm 0:0002c86c2220 659
bcostm 0:0002c86c2220 660 status = HAL_I2C_Mem_Write(&heval_I2c1,
bcostm 0:0002c86c2220 661 Addr,
bcostm 0:0002c86c2220 662 (uint16_t)Reg,
bcostm 0:0002c86c2220 663 MemAddress,
bcostm 0:0002c86c2220 664 Buffer,
bcostm 0:0002c86c2220 665 Length,
bcostm 0:0002c86c2220 666 1000);
bcostm 0:0002c86c2220 667
bcostm 0:0002c86c2220 668 /* Check the communication status */
bcostm 0:0002c86c2220 669 if(status != HAL_OK)
bcostm 0:0002c86c2220 670 {
bcostm 0:0002c86c2220 671 /* Re-Initiaize the I2C Bus */
bcostm 0:0002c86c2220 672 I2C1_Error(Addr);
bcostm 0:0002c86c2220 673 }
bcostm 0:0002c86c2220 674 return status;
bcostm 0:0002c86c2220 675 }
bcostm 0:0002c86c2220 676
bcostm 0:0002c86c2220 677 static HAL_StatusTypeDef I2C2_WriteMultiple(uint8_t Addr,
bcostm 0:0002c86c2220 678 uint16_t Reg,
bcostm 0:0002c86c2220 679 uint16_t MemAddress,
bcostm 0:0002c86c2220 680 uint8_t *Buffer,
bcostm 0:0002c86c2220 681 uint16_t Length)
bcostm 0:0002c86c2220 682 {
bcostm 0:0002c86c2220 683 HAL_StatusTypeDef status = HAL_OK;
bcostm 0:0002c86c2220 684
bcostm 0:0002c86c2220 685 status = HAL_I2C_Mem_Write(&heval_I2c2,
bcostm 0:0002c86c2220 686 Addr,
bcostm 0:0002c86c2220 687 (uint16_t)Reg,
bcostm 0:0002c86c2220 688 MemAddress,
bcostm 0:0002c86c2220 689 Buffer,
bcostm 0:0002c86c2220 690 Length,
bcostm 0:0002c86c2220 691 1000);
bcostm 0:0002c86c2220 692
bcostm 0:0002c86c2220 693 /* Check the communication status */
bcostm 0:0002c86c2220 694 if(status != HAL_OK)
bcostm 0:0002c86c2220 695 {
bcostm 0:0002c86c2220 696 /* Re-Initiaize the I2C2 Bus */
bcostm 0:0002c86c2220 697 I2C2_Error(Addr);
bcostm 0:0002c86c2220 698 }
bcostm 0:0002c86c2220 699 return status;
bcostm 0:0002c86c2220 700 }
bcostm 0:0002c86c2220 701
bcostm 0:0002c86c2220 702 /**
bcostm 0:0002c86c2220 703 * @brief Checks if target device is ready for communication.
bcostm 0:0002c86c2220 704 * @note This function is used with Memory devices
bcostm 0:0002c86c2220 705 * @param DevAddress: Target device address
bcostm 0:0002c86c2220 706 * @param Trials: Number of trials
bcostm 0:0002c86c2220 707 * @retval HAL status
bcostm 0:0002c86c2220 708 */
bcostm 0:0002c86c2220 709 static HAL_StatusTypeDef I2C1_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
bcostm 0:0002c86c2220 710 {
bcostm 0:0002c86c2220 711 return (HAL_I2C_IsDeviceReady(&heval_I2c1, DevAddress, Trials, 1000));
bcostm 0:0002c86c2220 712 }
bcostm 0:0002c86c2220 713
bcostm 0:0002c86c2220 714 /**
bcostm 0:0002c86c2220 715 * @brief Manages error callback by re-initializing I2C.
bcostm 0:0002c86c2220 716 * @param Addr: I2C Address
bcostm 0:0002c86c2220 717 * @retval None
bcostm 0:0002c86c2220 718 */
bcostm 0:0002c86c2220 719 static void I2C1_Error(uint8_t Addr)
bcostm 0:0002c86c2220 720 {
bcostm 0:0002c86c2220 721 /* De-initialize the I2C comunication bus */
bcostm 0:0002c86c2220 722 HAL_I2C_DeInit(&heval_I2c1);
bcostm 0:0002c86c2220 723
bcostm 0:0002c86c2220 724 /* Re-Initiaize the I2C comunication bus */
bcostm 0:0002c86c2220 725 I2C1_Init();
bcostm 0:0002c86c2220 726 }
bcostm 0:0002c86c2220 727
bcostm 0:0002c86c2220 728 static void I2C2_Error(uint8_t Addr)
bcostm 0:0002c86c2220 729 {
bcostm 0:0002c86c2220 730 /* De-initialize the I2C2 comunication bus */
bcostm 0:0002c86c2220 731 HAL_I2C_DeInit(&heval_I2c2);
bcostm 0:0002c86c2220 732
bcostm 0:0002c86c2220 733 /* Re-Initiaize the I2C2 comunication bus */
bcostm 0:0002c86c2220 734 I2C2_Init();
bcostm 0:0002c86c2220 735 }
bcostm 0:0002c86c2220 736
bcostm 0:0002c86c2220 737 /**
bcostm 0:0002c86c2220 738 * @}
bcostm 0:0002c86c2220 739 */
bcostm 0:0002c86c2220 740
bcostm 0:0002c86c2220 741 /*******************************************************************************
bcostm 0:0002c86c2220 742 LINK OPERATIONS
bcostm 0:0002c86c2220 743 *******************************************************************************/
bcostm 0:0002c86c2220 744
bcostm 0:0002c86c2220 745 /********************************* LINK AUDIO *********************************/
bcostm 0:0002c86c2220 746
bcostm 0:0002c86c2220 747 /**
bcostm 0:0002c86c2220 748 * @brief Initializes Audio low level.
bcostm 0:0002c86c2220 749 */
bcostm 0:0002c86c2220 750 void AUDIO_IO_Init(void)
bcostm 0:0002c86c2220 751 {
bcostm 0:0002c86c2220 752 I2C2_Init();
bcostm 0:0002c86c2220 753 }
bcostm 0:0002c86c2220 754
bcostm 0:0002c86c2220 755 /**
bcostm 0:0002c86c2220 756 * @brief DeInitializes Audio low level.
bcostm 0:0002c86c2220 757 */
bcostm 0:0002c86c2220 758 void AUDIO_IO_DeInit(void)
bcostm 0:0002c86c2220 759 {
bcostm 0:0002c86c2220 760
bcostm 0:0002c86c2220 761 }
bcostm 0:0002c86c2220 762
bcostm 0:0002c86c2220 763 /**
bcostm 0:0002c86c2220 764 * @brief Writes a single data.
bcostm 0:0002c86c2220 765 * @param Addr: I2C address
bcostm 0:0002c86c2220 766 * @param Reg: Reg address
bcostm 0:0002c86c2220 767 * @param Value: Data to be written
bcostm 0:0002c86c2220 768 */
bcostm 0:0002c86c2220 769 void AUDIO_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
bcostm 0:0002c86c2220 770 {
bcostm 0:0002c86c2220 771 I2C2_WriteMultiple(Addr, (uint16_t) Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&Value, 1);
bcostm 0:0002c86c2220 772 }
bcostm 0:0002c86c2220 773
bcostm 0:0002c86c2220 774 /**
bcostm 0:0002c86c2220 775 * @brief Reads a single data.
bcostm 0:0002c86c2220 776 * @param Addr: I2C address
bcostm 0:0002c86c2220 777 * @param Reg: Reg address
bcostm 0:0002c86c2220 778 * @retval Data to be read
bcostm 0:0002c86c2220 779 */
bcostm 0:0002c86c2220 780 uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg)
bcostm 0:0002c86c2220 781 {
bcostm 0:0002c86c2220 782 uint8_t read_value = 0;
bcostm 0:0002c86c2220 783
bcostm 0:0002c86c2220 784 I2C2_ReadMultiple(Addr, (uint16_t) Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&read_value, 1);
bcostm 0:0002c86c2220 785
bcostm 0:0002c86c2220 786 return read_value;
bcostm 0:0002c86c2220 787 }
bcostm 0:0002c86c2220 788
bcostm 0:0002c86c2220 789 /**
bcostm 0:0002c86c2220 790 * @brief AUDIO Codec delay
bcostm 0:0002c86c2220 791 * @param Delay: Delay in ms
bcostm 0:0002c86c2220 792 */
bcostm 0:0002c86c2220 793 void AUDIO_IO_Delay(uint32_t Delay)
bcostm 0:0002c86c2220 794 {
bcostm 0:0002c86c2220 795 //HAL_Delay(Delay);
bcostm 0:0002c86c2220 796 wait_ms(Delay);
bcostm 0:0002c86c2220 797 }
bcostm 0:0002c86c2220 798
bcostm 0:0002c86c2220 799 /******************************** LINK I2C EEPROM *****************************/
bcostm 0:0002c86c2220 800
bcostm 0:0002c86c2220 801 /**
bcostm 0:0002c86c2220 802 * @brief Initializes peripherals used by the I2C EEPROM driver.
bcostm 0:0002c86c2220 803 */
bcostm 0:0002c86c2220 804 void EEPROM_IO_Init(void)
bcostm 0:0002c86c2220 805 {
bcostm 0:0002c86c2220 806 I2C1_Init();
bcostm 0:0002c86c2220 807 }
bcostm 0:0002c86c2220 808
bcostm 0:0002c86c2220 809 /**
bcostm 0:0002c86c2220 810 * @brief Write data to I2C EEPROM driver in using DMA channel.
bcostm 0:0002c86c2220 811 * @param DevAddress: Target device address
bcostm 0:0002c86c2220 812 * @param MemAddress: Internal memory address
bcostm 0:0002c86c2220 813 * @param pBuffer: Pointer to data buffer
bcostm 0:0002c86c2220 814 * @param BufferSize: Amount of data to be sent
bcostm 0:0002c86c2220 815 * @retval HAL status
bcostm 0:0002c86c2220 816 */
bcostm 0:0002c86c2220 817 HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize)
bcostm 0:0002c86c2220 818 {
bcostm 0:0002c86c2220 819 return (I2C1_WriteMultiple(DevAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize));
bcostm 0:0002c86c2220 820 }
bcostm 0:0002c86c2220 821
bcostm 0:0002c86c2220 822 /**
bcostm 0:0002c86c2220 823 * @brief Read data from I2C EEPROM driver in using DMA channel.
bcostm 0:0002c86c2220 824 * @param DevAddress: Target device address
bcostm 0:0002c86c2220 825 * @param MemAddress: Internal memory address
bcostm 0:0002c86c2220 826 * @param pBuffer: Pointer to data buffer
bcostm 0:0002c86c2220 827 * @param BufferSize: Amount of data to be read
bcostm 0:0002c86c2220 828 * @retval HAL status
bcostm 0:0002c86c2220 829 */
bcostm 0:0002c86c2220 830 HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize)
bcostm 0:0002c86c2220 831 {
bcostm 0:0002c86c2220 832 return (I2C1_ReadMultiple(DevAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize));
bcostm 0:0002c86c2220 833 }
bcostm 0:0002c86c2220 834
bcostm 0:0002c86c2220 835 /**
bcostm 0:0002c86c2220 836 * @brief Checks if target device is ready for communication.
bcostm 0:0002c86c2220 837 * @note This function is used with Memory devices
bcostm 0:0002c86c2220 838 * @param DevAddress: Target device address
bcostm 0:0002c86c2220 839 * @param Trials: Number of trials
bcostm 0:0002c86c2220 840 * @retval HAL status
bcostm 0:0002c86c2220 841 */
bcostm 0:0002c86c2220 842 HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
bcostm 0:0002c86c2220 843 {
bcostm 0:0002c86c2220 844 return (I2C1_IsDeviceReady(DevAddress, Trials));
bcostm 0:0002c86c2220 845 }
bcostm 0:0002c86c2220 846
bcostm 0:0002c86c2220 847 /******************************** LINK TS (TouchScreen) ***********************/
bcostm 0:0002c86c2220 848
bcostm 0:0002c86c2220 849 /**
bcostm 0:0002c86c2220 850 * @brief Initialize I2C communication
bcostm 0:0002c86c2220 851 * channel from MCU to TouchScreen (TS).
bcostm 0:0002c86c2220 852 */
bcostm 0:0002c86c2220 853 void TS_IO_Init(void)
bcostm 0:0002c86c2220 854 {
bcostm 0:0002c86c2220 855 I2C1_Init();
bcostm 0:0002c86c2220 856 }
bcostm 0:0002c86c2220 857
bcostm 0:0002c86c2220 858 /**
bcostm 0:0002c86c2220 859 * @brief Writes single data with I2C communication
bcostm 0:0002c86c2220 860 * channel from MCU to TouchScreen.
bcostm 0:0002c86c2220 861 * @param Addr: I2C address
bcostm 0:0002c86c2220 862 * @param Reg: Register address
bcostm 0:0002c86c2220 863 * @param Value: Data to be written
bcostm 0:0002c86c2220 864 */
bcostm 0:0002c86c2220 865 void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
bcostm 0:0002c86c2220 866 {
bcostm 0:0002c86c2220 867 I2C1_Write(Addr, Reg, Value);
bcostm 0:0002c86c2220 868 }
bcostm 0:0002c86c2220 869
bcostm 0:0002c86c2220 870 /**
bcostm 0:0002c86c2220 871 * @brief Reads single data with I2C communication
bcostm 0:0002c86c2220 872 * channel from TouchScreen.
bcostm 0:0002c86c2220 873 * @param Addr: I2C address
bcostm 0:0002c86c2220 874 * @param Reg: Register address
bcostm 0:0002c86c2220 875 * @retval Read data
bcostm 0:0002c86c2220 876 */
bcostm 0:0002c86c2220 877 uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg)
bcostm 0:0002c86c2220 878 {
bcostm 0:0002c86c2220 879 return I2C1_Read(Addr, Reg);
bcostm 0:0002c86c2220 880 }
bcostm 0:0002c86c2220 881
bcostm 0:0002c86c2220 882 /**
bcostm 0:0002c86c2220 883 * @brief Reads multiple data with I2C communication
bcostm 0:0002c86c2220 884 * channel from TouchScreen.
bcostm 0:0002c86c2220 885 * @param Addr: I2C address
bcostm 0:0002c86c2220 886 * @param Reg: Register address
bcostm 0:0002c86c2220 887 * @param Buffer: Pointer to data buffer
bcostm 0:0002c86c2220 888 * @param Length: Length of the data
bcostm 0:0002c86c2220 889 * @retval Number of read data
bcostm 0:0002c86c2220 890 */
bcostm 0:0002c86c2220 891 uint16_t TS_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
bcostm 0:0002c86c2220 892 {
bcostm 0:0002c86c2220 893 return I2C1_ReadMultiple(Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
bcostm 0:0002c86c2220 894 }
bcostm 0:0002c86c2220 895
bcostm 0:0002c86c2220 896 /**
bcostm 0:0002c86c2220 897 * @brief Writes multiple data with I2C communication
bcostm 0:0002c86c2220 898 * channel from MCU to TouchScreen.
bcostm 0:0002c86c2220 899 * @param Addr: I2C address
bcostm 0:0002c86c2220 900 * @param Reg: Register address
bcostm 0:0002c86c2220 901 * @param Buffer: Pointer to data buffer
bcostm 0:0002c86c2220 902 * @param Length: Length of the data
bcostm 0:0002c86c2220 903 * @retval None
bcostm 0:0002c86c2220 904 */
bcostm 0:0002c86c2220 905 void TS_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
bcostm 0:0002c86c2220 906 {
bcostm 0:0002c86c2220 907 I2C1_WriteMultiple(Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
bcostm 0:0002c86c2220 908 }
bcostm 0:0002c86c2220 909
bcostm 0:0002c86c2220 910 /**
bcostm 0:0002c86c2220 911 * @brief Delay function used in TouchScreen low level driver.
bcostm 0:0002c86c2220 912 * @param Delay: Delay in ms
bcostm 0:0002c86c2220 913 * @retval None
bcostm 0:0002c86c2220 914 */
bcostm 0:0002c86c2220 915 void TS_IO_Delay(uint32_t Delay)
bcostm 0:0002c86c2220 916 {
bcostm 0:0002c86c2220 917 //HAL_Delay(Delay);
bcostm 0:0002c86c2220 918 wait_ms(Delay);
bcostm 0:0002c86c2220 919 }
bcostm 0:0002c86c2220 920
bcostm 0:0002c86c2220 921 /**************************** LINK OTM8009A (Display driver) ******************/
bcostm 0:0002c86c2220 922 /**
bcostm 0:0002c86c2220 923 * @brief OTM8009A delay
bcostm 0:0002c86c2220 924 * @param Delay: Delay in ms
bcostm 0:0002c86c2220 925 */
bcostm 0:0002c86c2220 926 void OTM8009A_IO_Delay(uint32_t Delay)
bcostm 0:0002c86c2220 927 {
bcostm 0:0002c86c2220 928 //HAL_Delay(Delay);
bcostm 0:0002c86c2220 929 wait_ms(Delay);
bcostm 0:0002c86c2220 930 }
bcostm 0:0002c86c2220 931
bcostm 0:0002c86c2220 932 /**
bcostm 0:0002c86c2220 933 * @}
bcostm 0:0002c86c2220 934 */
bcostm 0:0002c86c2220 935
bcostm 0:0002c86c2220 936 /**
bcostm 0:0002c86c2220 937 * @}
bcostm 0:0002c86c2220 938 */
bcostm 0:0002c86c2220 939
bcostm 0:0002c86c2220 940 /**
bcostm 0:0002c86c2220 941 * @}
bcostm 0:0002c86c2220 942 */
bcostm 0:0002c86c2220 943
bcostm 0:0002c86c2220 944 /**
bcostm 0:0002c86c2220 945 * @}
bcostm 0:0002c86c2220 946 */
bcostm 0:0002c86c2220 947
bcostm 0:0002c86c2220 948 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/