BSP files for STM32H747I-Discovery Copy from ST Cube delivery

Dependents:   DISCO_H747I_LCD_demo DISCO_H747I_AUDIO_demo

Committer:
Jerome Coutant
Date:
Wed Nov 06 11:32:01 2019 +0100
Revision:
3:bc403474b366
Parent:
0:146cf26a9bbb
Add PDM lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jerome Coutant 0:146cf26a9bbb 1 /**
Jerome Coutant 0:146cf26a9bbb 2 ******************************************************************************
Jerome Coutant 0:146cf26a9bbb 3 * @file stm32h747i_discovery.c
Jerome Coutant 0:146cf26a9bbb 4 * @author MCD Application Team
Jerome Coutant 0:146cf26a9bbb 5 * @brief This file provides a set of firmware functions to manage LEDs,
Jerome Coutant 0:146cf26a9bbb 6 * push-buttons, external SDRAM, external QSPI Flash,
Jerome Coutant 0:146cf26a9bbb 7 * available on STM32H747I-Discovery board (MB1248) from
Jerome Coutant 0:146cf26a9bbb 8 * STMicroelectronics.
Jerome Coutant 0:146cf26a9bbb 9 ******************************************************************************
Jerome Coutant 0:146cf26a9bbb 10 * @attention
Jerome Coutant 0:146cf26a9bbb 11 *
Jerome Coutant 0:146cf26a9bbb 12 * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
Jerome Coutant 0:146cf26a9bbb 13 * All rights reserved.</center></h2>
Jerome Coutant 0:146cf26a9bbb 14 *
Jerome Coutant 0:146cf26a9bbb 15 * This software component is licensed by ST under BSD 3-Clause license,
Jerome Coutant 0:146cf26a9bbb 16 * the "License"; You may not use this file except in compliance with the
Jerome Coutant 0:146cf26a9bbb 17 * License. You may obtain a copy of the License at:
Jerome Coutant 0:146cf26a9bbb 18 * opensource.org/licenses/BSD-3-Clause
Jerome Coutant 0:146cf26a9bbb 19 *
Jerome Coutant 0:146cf26a9bbb 20 ******************************************************************************
Jerome Coutant 0:146cf26a9bbb 21 */
Jerome Coutant 0:146cf26a9bbb 22
Jerome Coutant 0:146cf26a9bbb 23 /* Includes ------------------------------------------------------------------*/
Jerome Coutant 0:146cf26a9bbb 24 #include "stm32h747i_discovery.h"
Jerome Coutant 0:146cf26a9bbb 25
Jerome Coutant 0:146cf26a9bbb 26 /** @defgroup BSP BSP
Jerome Coutant 0:146cf26a9bbb 27 * @{
Jerome Coutant 0:146cf26a9bbb 28 */
Jerome Coutant 0:146cf26a9bbb 29
Jerome Coutant 0:146cf26a9bbb 30 /** @defgroup STM32H747I_DISCOVERY STM32H747I_DISCOVERY
Jerome Coutant 0:146cf26a9bbb 31 * @{
Jerome Coutant 0:146cf26a9bbb 32 */
Jerome Coutant 0:146cf26a9bbb 33
Jerome Coutant 0:146cf26a9bbb 34 /** @defgroup STM32H747I_DISCOVERY_LOW_LEVEL STM32H747I_DISCOVERY_LOW_LEVEL
Jerome Coutant 0:146cf26a9bbb 35 * @{
Jerome Coutant 0:146cf26a9bbb 36 */
Jerome Coutant 0:146cf26a9bbb 37
Jerome Coutant 0:146cf26a9bbb 38 /** @defgroup STM32H747I_DISCOVERY_LOW_LEVEL_Private_Defines Private Defines
Jerome Coutant 0:146cf26a9bbb 39 * @{
Jerome Coutant 0:146cf26a9bbb 40 */
Jerome Coutant 0:146cf26a9bbb 41 /**
Jerome Coutant 0:146cf26a9bbb 42 * @brief STM32H747I Discovery BSP Driver version number V1.0.0
Jerome Coutant 0:146cf26a9bbb 43 */
Jerome Coutant 0:146cf26a9bbb 44 #define __STM32H747I_DISCOVERY_BSP_VERSION_MAIN (0x01) /*!< [31:24] main version */
Jerome Coutant 0:146cf26a9bbb 45 #define __STM32H747I_DISCOVERY_BSP_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */
Jerome Coutant 0:146cf26a9bbb 46 #define __STM32H747I_DISCOVERY_BSP_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */
Jerome Coutant 0:146cf26a9bbb 47 #define __STM32H747I_DISCOVERY_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */
Jerome Coutant 0:146cf26a9bbb 48 #define __STM32H747I_DISCOVERY_BSP_VERSION ((__STM32H747I_DISCOVERY_BSP_VERSION_MAIN << 24)\
Jerome Coutant 0:146cf26a9bbb 49 |(__STM32H747I_DISCOVERY_BSP_VERSION_SUB1 << 16)\
Jerome Coutant 0:146cf26a9bbb 50 |(__STM32H747I_DISCOVERY_BSP_VERSION_SUB2 << 8 )\
Jerome Coutant 0:146cf26a9bbb 51 |(__STM32H747I_DISCOVERY_BSP_VERSION_RC))
Jerome Coutant 0:146cf26a9bbb 52 /**
Jerome Coutant 0:146cf26a9bbb 53 * @}
Jerome Coutant 0:146cf26a9bbb 54 */
Jerome Coutant 0:146cf26a9bbb 55
Jerome Coutant 0:146cf26a9bbb 56
Jerome Coutant 0:146cf26a9bbb 57 /** @defgroup STM32H747I_DISCOVERY_LOW_LEVEL_Private_Variables Private Variables
Jerome Coutant 0:146cf26a9bbb 58 * @{
Jerome Coutant 0:146cf26a9bbb 59 */
Jerome Coutant 0:146cf26a9bbb 60
Jerome Coutant 0:146cf26a9bbb 61 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT,
Jerome Coutant 0:146cf26a9bbb 62 LED2_GPIO_PORT,
Jerome Coutant 0:146cf26a9bbb 63 LED3_GPIO_PORT,
Jerome Coutant 0:146cf26a9bbb 64 LED4_GPIO_PORT};
Jerome Coutant 0:146cf26a9bbb 65
Jerome Coutant 0:146cf26a9bbb 66 const uint32_t GPIO_PIN[LEDn] = {LED1_PIN,
Jerome Coutant 0:146cf26a9bbb 67 LED2_PIN,
Jerome Coutant 0:146cf26a9bbb 68 LED3_PIN,
Jerome Coutant 0:146cf26a9bbb 69 LED4_PIN};
Jerome Coutant 0:146cf26a9bbb 70
Jerome Coutant 0:146cf26a9bbb 71 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT };
Jerome Coutant 0:146cf26a9bbb 72
Jerome Coutant 0:146cf26a9bbb 73 const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN };
Jerome Coutant 0:146cf26a9bbb 74
Jerome Coutant 0:146cf26a9bbb 75 const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn };
Jerome Coutant 0:146cf26a9bbb 76
Jerome Coutant 0:146cf26a9bbb 77 GPIO_TypeDef* JOY_PORT[JOYn] = {SEL_JOY_GPIO_PORT,
Jerome Coutant 0:146cf26a9bbb 78 DOWN_JOY_GPIO_PORT,
Jerome Coutant 0:146cf26a9bbb 79 LEFT_JOY_GPIO_PORT,
Jerome Coutant 0:146cf26a9bbb 80 RIGHT_JOY_GPIO_PORT,
Jerome Coutant 0:146cf26a9bbb 81 UP_JOY_GPIO_PORT};
Jerome Coutant 0:146cf26a9bbb 82
Jerome Coutant 0:146cf26a9bbb 83 const uint16_t JOY_PIN[JOYn] = {SEL_JOY_PIN,
Jerome Coutant 0:146cf26a9bbb 84 DOWN_JOY_PIN,
Jerome Coutant 0:146cf26a9bbb 85 LEFT_JOY_PIN,
Jerome Coutant 0:146cf26a9bbb 86 RIGHT_JOY_PIN,
Jerome Coutant 0:146cf26a9bbb 87 UP_JOY_PIN};
Jerome Coutant 0:146cf26a9bbb 88
Jerome Coutant 0:146cf26a9bbb 89 const uint8_t JOY_IRQn[JOYn] = {SEL_JOY_EXTI_IRQn,
Jerome Coutant 0:146cf26a9bbb 90 DOWN_JOY_EXTI_IRQn,
Jerome Coutant 0:146cf26a9bbb 91 LEFT_JOY_EXTI_IRQn,
Jerome Coutant 0:146cf26a9bbb 92 RIGHT_JOY_EXTI_IRQn,
Jerome Coutant 0:146cf26a9bbb 93 UP_JOY_EXTI_IRQn};
Jerome Coutant 0:146cf26a9bbb 94
Jerome Coutant 0:146cf26a9bbb 95 static I2C_HandleTypeDef heval_I2c = {0};
Jerome Coutant 0:146cf26a9bbb 96
Jerome Coutant 0:146cf26a9bbb 97 #if defined(BSP_USE_CMSIS_OS)
Jerome Coutant 0:146cf26a9bbb 98 static osSemaphoreId BspI2cSemaphore = 0;
Jerome Coutant 0:146cf26a9bbb 99 #endif
Jerome Coutant 0:146cf26a9bbb 100
Jerome Coutant 0:146cf26a9bbb 101 /**
Jerome Coutant 0:146cf26a9bbb 102 * @}
Jerome Coutant 0:146cf26a9bbb 103 */
Jerome Coutant 0:146cf26a9bbb 104
Jerome Coutant 0:146cf26a9bbb 105 /** @defgroup STM32H747I_DISCOVERY_LOW_LEVEL_Private_FunctionPrototypes Private FunctionPrototypes
Jerome Coutant 0:146cf26a9bbb 106 * @{
Jerome Coutant 0:146cf26a9bbb 107 */
Jerome Coutant 0:146cf26a9bbb 108 static void I2Cx_MspInit(void);
Jerome Coutant 0:146cf26a9bbb 109 static void I2Cx_Init(void);
Jerome Coutant 0:146cf26a9bbb 110 static void I2Cx_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
Jerome Coutant 0:146cf26a9bbb 111 static uint8_t I2Cx_Read(uint8_t Addr, uint8_t Reg);
Jerome Coutant 0:146cf26a9bbb 112 static HAL_StatusTypeDef I2Cx_ReadMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
Jerome Coutant 0:146cf26a9bbb 113 static HAL_StatusTypeDef I2Cx_WriteMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
Jerome Coutant 0:146cf26a9bbb 114 static HAL_StatusTypeDef I2Cx_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);
Jerome Coutant 0:146cf26a9bbb 115 static void I2Cx_Error(uint8_t Addr);
Jerome Coutant 0:146cf26a9bbb 116
Jerome Coutant 0:146cf26a9bbb 117 /* HDMI IO functions */
Jerome Coutant 0:146cf26a9bbb 118 void HDMI_IO_Init(void);
Jerome Coutant 0:146cf26a9bbb 119 void HDMI_IO_Delay(uint32_t Delay);
Jerome Coutant 0:146cf26a9bbb 120 void HDMI_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
Jerome Coutant 0:146cf26a9bbb 121 uint8_t HDMI_IO_Read(uint8_t Addr, uint8_t Reg);
Jerome Coutant 0:146cf26a9bbb 122
Jerome Coutant 0:146cf26a9bbb 123 /* AUDIO IO functions */
Jerome Coutant 0:146cf26a9bbb 124 void AUDIO_IO_Init(void);
Jerome Coutant 0:146cf26a9bbb 125 void AUDIO_IO_DeInit(void);
Jerome Coutant 0:146cf26a9bbb 126 void AUDIO_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value);
Jerome Coutant 0:146cf26a9bbb 127 uint16_t AUDIO_IO_Read(uint8_t Addr, uint16_t Reg);
Jerome Coutant 0:146cf26a9bbb 128 void AUDIO_IO_Delay(uint32_t Delay);
Jerome Coutant 0:146cf26a9bbb 129
Jerome Coutant 0:146cf26a9bbb 130 /* CAMERA IO functions */
Jerome Coutant 0:146cf26a9bbb 131 void CAMERA_IO_Init(void);
Jerome Coutant 0:146cf26a9bbb 132 void CAMERA_Delay(uint32_t Delay);
Jerome Coutant 0:146cf26a9bbb 133 void CAMERA_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value);
Jerome Coutant 0:146cf26a9bbb 134 uint16_t CAMERA_IO_Read(uint8_t Addr, uint16_t Reg);
Jerome Coutant 0:146cf26a9bbb 135
Jerome Coutant 0:146cf26a9bbb 136 /* I2C EEPROM IO function */
Jerome Coutant 0:146cf26a9bbb 137 void EEPROM_IO_Init(void);
Jerome Coutant 0:146cf26a9bbb 138 HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize);
Jerome Coutant 0:146cf26a9bbb 139 HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize);
Jerome Coutant 0:146cf26a9bbb 140 HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);
Jerome Coutant 0:146cf26a9bbb 141
Jerome Coutant 0:146cf26a9bbb 142 /* TouchScreen (TS) IO functions */
Jerome Coutant 0:146cf26a9bbb 143 void TS_IO_Init(void);
Jerome Coutant 0:146cf26a9bbb 144 void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
Jerome Coutant 0:146cf26a9bbb 145 uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg);
Jerome Coutant 0:146cf26a9bbb 146 uint16_t TS_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
Jerome Coutant 0:146cf26a9bbb 147 void TS_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
Jerome Coutant 0:146cf26a9bbb 148 void TS_IO_Delay(uint32_t Delay);
Jerome Coutant 0:146cf26a9bbb 149
Jerome Coutant 0:146cf26a9bbb 150 /* LCD Display IO functions */
Jerome Coutant 0:146cf26a9bbb 151 void OTM8009A_IO_Delay(uint32_t Delay);
Jerome Coutant 0:146cf26a9bbb 152 /**
Jerome Coutant 0:146cf26a9bbb 153 * @}
Jerome Coutant 0:146cf26a9bbb 154 */
Jerome Coutant 0:146cf26a9bbb 155
Jerome Coutant 0:146cf26a9bbb 156 /** @defgroup STM32H747I_DISCOVERY_BSP_Exported_Functions BSP Exported Functions
Jerome Coutant 0:146cf26a9bbb 157 * @{
Jerome Coutant 0:146cf26a9bbb 158 */
Jerome Coutant 0:146cf26a9bbb 159
Jerome Coutant 0:146cf26a9bbb 160 /**
Jerome Coutant 0:146cf26a9bbb 161 * @brief BSP Error Notification
Jerome Coutant 0:146cf26a9bbb 162 * @note Defined as a weak function to be overwritten by the application.
Jerome Coutant 0:146cf26a9bbb 163 * @retval None
Jerome Coutant 0:146cf26a9bbb 164 */
Jerome Coutant 0:146cf26a9bbb 165 __weak void BSP_ErrorNotify(void)
Jerome Coutant 0:146cf26a9bbb 166 {
Jerome Coutant 0:146cf26a9bbb 167 }
Jerome Coutant 0:146cf26a9bbb 168
Jerome Coutant 0:146cf26a9bbb 169 /**
Jerome Coutant 0:146cf26a9bbb 170 * @brief This method returns the STM32H747I Discovery BSP Driver revision
Jerome Coutant 0:146cf26a9bbb 171 * @retval version: 0xXYZR (8bits for each decimal, R for RC)
Jerome Coutant 0:146cf26a9bbb 172 */
Jerome Coutant 0:146cf26a9bbb 173 uint32_t BSP_GetVersion(void)
Jerome Coutant 0:146cf26a9bbb 174 {
Jerome Coutant 0:146cf26a9bbb 175 return __STM32H747I_DISCOVERY_BSP_VERSION;
Jerome Coutant 0:146cf26a9bbb 176 }
Jerome Coutant 0:146cf26a9bbb 177
Jerome Coutant 0:146cf26a9bbb 178 /**
Jerome Coutant 0:146cf26a9bbb 179 * @brief Configures LED GPIO.
Jerome Coutant 0:146cf26a9bbb 180 * @param Led: LED to be configured.
Jerome Coutant 0:146cf26a9bbb 181 * This parameter can be one of the following values:
Jerome Coutant 0:146cf26a9bbb 182 * @arg DISCO_LED1
Jerome Coutant 0:146cf26a9bbb 183 * @arg DISCO_LED2
Jerome Coutant 0:146cf26a9bbb 184 * @arg DISCO_LED3
Jerome Coutant 0:146cf26a9bbb 185 * @arg DISCO_LED4
Jerome Coutant 0:146cf26a9bbb 186 * @retval None
Jerome Coutant 0:146cf26a9bbb 187 */
Jerome Coutant 0:146cf26a9bbb 188 void BSP_LED_Init(Led_TypeDef Led)
Jerome Coutant 0:146cf26a9bbb 189 {
Jerome Coutant 0:146cf26a9bbb 190 GPIO_InitTypeDef GPIO_InitStruct;
Jerome Coutant 0:146cf26a9bbb 191
Jerome Coutant 0:146cf26a9bbb 192 /* Enable the GPIO_LED clock */
Jerome Coutant 0:146cf26a9bbb 193 LEDx_GPIO_CLK_ENABLE();
Jerome Coutant 0:146cf26a9bbb 194
Jerome Coutant 0:146cf26a9bbb 195 /* Configure the GPIO_LED pin */
Jerome Coutant 0:146cf26a9bbb 196 GPIO_InitStruct.Pin = GPIO_PIN[Led];
Jerome Coutant 0:146cf26a9bbb 197 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
Jerome Coutant 0:146cf26a9bbb 198 GPIO_InitStruct.Pull = GPIO_PULLUP;
Jerome Coutant 0:146cf26a9bbb 199 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
Jerome Coutant 0:146cf26a9bbb 200
Jerome Coutant 0:146cf26a9bbb 201 HAL_GPIO_Init(GPIO_PORT[Led], &GPIO_InitStruct);
Jerome Coutant 0:146cf26a9bbb 202
Jerome Coutant 0:146cf26a9bbb 203 /* By default, turn off LED */
Jerome Coutant 0:146cf26a9bbb 204 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
Jerome Coutant 0:146cf26a9bbb 205 }
Jerome Coutant 0:146cf26a9bbb 206
Jerome Coutant 0:146cf26a9bbb 207
Jerome Coutant 0:146cf26a9bbb 208 /**
Jerome Coutant 0:146cf26a9bbb 209 * @brief DeInit LEDs.
Jerome Coutant 0:146cf26a9bbb 210 * @param Led: LED to be configured.
Jerome Coutant 0:146cf26a9bbb 211 * This parameter can be one of the following values:
Jerome Coutant 0:146cf26a9bbb 212 * @arg DISCO_LED1
Jerome Coutant 0:146cf26a9bbb 213 * @arg DISCO_LED2
Jerome Coutant 0:146cf26a9bbb 214 * @arg DISCO_LED3
Jerome Coutant 0:146cf26a9bbb 215 * @arg DISCO_LED4
Jerome Coutant 0:146cf26a9bbb 216 * @note Led DeInit does not disable the GPIO clock
Jerome Coutant 0:146cf26a9bbb 217 * @retval None
Jerome Coutant 0:146cf26a9bbb 218 */
Jerome Coutant 0:146cf26a9bbb 219 void BSP_LED_DeInit(Led_TypeDef Led)
Jerome Coutant 0:146cf26a9bbb 220 {
Jerome Coutant 0:146cf26a9bbb 221 /* Turn off LED */
Jerome Coutant 0:146cf26a9bbb 222 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
Jerome Coutant 0:146cf26a9bbb 223 /* Configure the GPIO_LED pin */
Jerome Coutant 0:146cf26a9bbb 224 HAL_GPIO_DeInit(GPIO_PORT[Led], GPIO_PIN[Led]);
Jerome Coutant 0:146cf26a9bbb 225 }
Jerome Coutant 0:146cf26a9bbb 226
Jerome Coutant 0:146cf26a9bbb 227 /**
Jerome Coutant 0:146cf26a9bbb 228 * @brief Turns selected LED On.
Jerome Coutant 0:146cf26a9bbb 229 * @param Led: LED to be set on
Jerome Coutant 0:146cf26a9bbb 230 * This parameter can be one of the following values:
Jerome Coutant 0:146cf26a9bbb 231 * @arg DISCO_LED1
Jerome Coutant 0:146cf26a9bbb 232 * @arg DISCO_LED2
Jerome Coutant 0:146cf26a9bbb 233 * @arg DISCO_LED3
Jerome Coutant 0:146cf26a9bbb 234 * @arg DISCO_LED4
Jerome Coutant 0:146cf26a9bbb 235 * @retval None
Jerome Coutant 0:146cf26a9bbb 236 */
Jerome Coutant 0:146cf26a9bbb 237 void BSP_LED_On(Led_TypeDef Led)
Jerome Coutant 0:146cf26a9bbb 238 {
Jerome Coutant 0:146cf26a9bbb 239 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
Jerome Coutant 0:146cf26a9bbb 240 }
Jerome Coutant 0:146cf26a9bbb 241
Jerome Coutant 0:146cf26a9bbb 242 /**
Jerome Coutant 0:146cf26a9bbb 243 * @brief Turns selected LED Off.
Jerome Coutant 0:146cf26a9bbb 244 * @param Led: LED to be set off
Jerome Coutant 0:146cf26a9bbb 245 * This parameter can be one of the following values:
Jerome Coutant 0:146cf26a9bbb 246 * @arg DISCO_LED1
Jerome Coutant 0:146cf26a9bbb 247 * @arg DISCO_LED2
Jerome Coutant 0:146cf26a9bbb 248 * @arg DISCO_LED3
Jerome Coutant 0:146cf26a9bbb 249 * @arg DISCO_LED4
Jerome Coutant 0:146cf26a9bbb 250 * @retval None
Jerome Coutant 0:146cf26a9bbb 251 */
Jerome Coutant 0:146cf26a9bbb 252 void BSP_LED_Off(Led_TypeDef Led)
Jerome Coutant 0:146cf26a9bbb 253 {
Jerome Coutant 0:146cf26a9bbb 254 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
Jerome Coutant 0:146cf26a9bbb 255 }
Jerome Coutant 0:146cf26a9bbb 256
Jerome Coutant 0:146cf26a9bbb 257 /**
Jerome Coutant 0:146cf26a9bbb 258 * @brief Toggles the selected LED.
Jerome Coutant 0:146cf26a9bbb 259 * @param Led: LED to be toggled
Jerome Coutant 0:146cf26a9bbb 260 * This parameter can be one of the following values:
Jerome Coutant 0:146cf26a9bbb 261 * @arg DISCO_LED1
Jerome Coutant 0:146cf26a9bbb 262 * @arg DISCO_LED2
Jerome Coutant 0:146cf26a9bbb 263 * @arg DISCO_LED3
Jerome Coutant 0:146cf26a9bbb 264 * @arg DISCO_LED4
Jerome Coutant 0:146cf26a9bbb 265 * @retval None
Jerome Coutant 0:146cf26a9bbb 266 */
Jerome Coutant 0:146cf26a9bbb 267 void BSP_LED_Toggle(Led_TypeDef Led)
Jerome Coutant 0:146cf26a9bbb 268 {
Jerome Coutant 0:146cf26a9bbb 269 HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]);
Jerome Coutant 0:146cf26a9bbb 270 }
Jerome Coutant 0:146cf26a9bbb 271
Jerome Coutant 0:146cf26a9bbb 272 /**
Jerome Coutant 0:146cf26a9bbb 273 * @brief Configures button GPIO and EXTI Line.
Jerome Coutant 0:146cf26a9bbb 274 * @param Button: Button to be configured
Jerome Coutant 0:146cf26a9bbb 275 * This parameter can be one of the following values:
Jerome Coutant 0:146cf26a9bbb 276 * @arg BUTTON_WAKEUP: Wakeup Push Button
Jerome Coutant 0:146cf26a9bbb 277 * @arg BUTTON_USER: User Push Button
Jerome Coutant 0:146cf26a9bbb 278 * @param Button_Mode: Button mode
Jerome Coutant 0:146cf26a9bbb 279 * This parameter can be one of the following values:
Jerome Coutant 0:146cf26a9bbb 280 * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
Jerome Coutant 0:146cf26a9bbb 281 * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line
Jerome Coutant 0:146cf26a9bbb 282 * with interrupt generation capability
Jerome Coutant 0:146cf26a9bbb 283 * @retval None
Jerome Coutant 0:146cf26a9bbb 284 */
Jerome Coutant 0:146cf26a9bbb 285 void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
Jerome Coutant 0:146cf26a9bbb 286 {
Jerome Coutant 0:146cf26a9bbb 287 GPIO_InitTypeDef GPIO_InitStruct;
Jerome Coutant 0:146cf26a9bbb 288
Jerome Coutant 0:146cf26a9bbb 289 /* Enable the BUTTON clock */
Jerome Coutant 0:146cf26a9bbb 290 BUTTON_GPIO_CLK_ENABLE();
Jerome Coutant 0:146cf26a9bbb 291
Jerome Coutant 0:146cf26a9bbb 292 if(Button_Mode == BUTTON_MODE_GPIO)
Jerome Coutant 0:146cf26a9bbb 293 {
Jerome Coutant 0:146cf26a9bbb 294 /* Configure Button pin as input */
Jerome Coutant 0:146cf26a9bbb 295 GPIO_InitStruct.Pin = BUTTON_PIN[Button];
Jerome Coutant 0:146cf26a9bbb 296 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
Jerome Coutant 0:146cf26a9bbb 297 GPIO_InitStruct.Pull = GPIO_NOPULL;
Jerome Coutant 0:146cf26a9bbb 298 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
Jerome Coutant 0:146cf26a9bbb 299 HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
Jerome Coutant 0:146cf26a9bbb 300 }
Jerome Coutant 0:146cf26a9bbb 301
Jerome Coutant 0:146cf26a9bbb 302 if(Button_Mode == BUTTON_MODE_EXTI)
Jerome Coutant 0:146cf26a9bbb 303 {
Jerome Coutant 0:146cf26a9bbb 304 /* Configure Button pin as input with External interrupt */
Jerome Coutant 0:146cf26a9bbb 305 GPIO_InitStruct.Pin = BUTTON_PIN[Button];
Jerome Coutant 0:146cf26a9bbb 306 GPIO_InitStruct.Pull = GPIO_NOPULL;
Jerome Coutant 0:146cf26a9bbb 307 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
Jerome Coutant 0:146cf26a9bbb 308
Jerome Coutant 0:146cf26a9bbb 309 GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
Jerome Coutant 0:146cf26a9bbb 310
Jerome Coutant 0:146cf26a9bbb 311 HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
Jerome Coutant 0:146cf26a9bbb 312
Jerome Coutant 0:146cf26a9bbb 313 /* Enable and set Button EXTI Interrupt to the lowest priority */
Jerome Coutant 0:146cf26a9bbb 314 HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00);
Jerome Coutant 0:146cf26a9bbb 315 HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
Jerome Coutant 0:146cf26a9bbb 316 }
Jerome Coutant 0:146cf26a9bbb 317 }
Jerome Coutant 0:146cf26a9bbb 318
Jerome Coutant 0:146cf26a9bbb 319 /**
Jerome Coutant 0:146cf26a9bbb 320 * @brief Push Button DeInit.
Jerome Coutant 0:146cf26a9bbb 321 * @param Button: Button to be configured
Jerome Coutant 0:146cf26a9bbb 322 * This parameter can be one of the following values:
Jerome Coutant 0:146cf26a9bbb 323 * @arg BUTTON_WAKEUP: Wakeup Push Button
Jerome Coutant 0:146cf26a9bbb 324 * @arg BUTTON_USER: User Push Button
Jerome Coutant 0:146cf26a9bbb 325 * @note PB DeInit does not disable the GPIO clock
Jerome Coutant 0:146cf26a9bbb 326 * @retval None
Jerome Coutant 0:146cf26a9bbb 327 */
Jerome Coutant 0:146cf26a9bbb 328 void BSP_PB_DeInit(Button_TypeDef Button)
Jerome Coutant 0:146cf26a9bbb 329 {
Jerome Coutant 0:146cf26a9bbb 330 GPIO_InitTypeDef gpio_init_structure;
Jerome Coutant 0:146cf26a9bbb 331
Jerome Coutant 0:146cf26a9bbb 332 gpio_init_structure.Pin = BUTTON_PIN[Button];
Jerome Coutant 0:146cf26a9bbb 333 HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
Jerome Coutant 0:146cf26a9bbb 334 HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin);
Jerome Coutant 0:146cf26a9bbb 335 }
Jerome Coutant 0:146cf26a9bbb 336
Jerome Coutant 0:146cf26a9bbb 337
Jerome Coutant 0:146cf26a9bbb 338 /**
Jerome Coutant 0:146cf26a9bbb 339 * @brief Returns the selected button state.
Jerome Coutant 0:146cf26a9bbb 340 * @param Button: Button to be checked
Jerome Coutant 0:146cf26a9bbb 341 * This parameter can be one of the following values:
Jerome Coutant 0:146cf26a9bbb 342 * @arg BUTTON_WAKEUP: Wakeup Push Button
Jerome Coutant 0:146cf26a9bbb 343 * @arg BUTTON_USER: User Push Button
Jerome Coutant 0:146cf26a9bbb 344 * @retval The Button GPIO pin value
Jerome Coutant 0:146cf26a9bbb 345 */
Jerome Coutant 0:146cf26a9bbb 346 uint32_t BSP_PB_GetState(Button_TypeDef Button)
Jerome Coutant 0:146cf26a9bbb 347 {
Jerome Coutant 0:146cf26a9bbb 348 return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
Jerome Coutant 0:146cf26a9bbb 349 }
Jerome Coutant 0:146cf26a9bbb 350
Jerome Coutant 0:146cf26a9bbb 351 /**
Jerome Coutant 0:146cf26a9bbb 352 * @brief Configures all joystick's buttons in GPIO or EXTI modes.
Jerome Coutant 0:146cf26a9bbb 353 * @param Joy_Mode: Joystick mode.
Jerome Coutant 0:146cf26a9bbb 354 * This parameter can be one of the following values:
Jerome Coutant 0:146cf26a9bbb 355 * @arg JOY_MODE_GPIO: Joystick pins will be used as simple IOs
Jerome Coutant 0:146cf26a9bbb 356 * @arg JOY_MODE_EXTI: Joystick pins will be connected to EXTI line
Jerome Coutant 0:146cf26a9bbb 357 * with interrupt generation capability
Jerome Coutant 0:146cf26a9bbb 358 * @retval HAL_OK: if all initializations are OK. Other value if error.
Jerome Coutant 0:146cf26a9bbb 359 */
Jerome Coutant 0:146cf26a9bbb 360 uint8_t BSP_JOY_Init(JOYMode_TypeDef Joy_Mode)
Jerome Coutant 0:146cf26a9bbb 361 {
Jerome Coutant 0:146cf26a9bbb 362 JOYState_TypeDef joykey;
Jerome Coutant 0:146cf26a9bbb 363 GPIO_InitTypeDef GPIO_InitStruct;
Jerome Coutant 0:146cf26a9bbb 364
Jerome Coutant 0:146cf26a9bbb 365 /* Initialized the Joystick. */
Jerome Coutant 0:146cf26a9bbb 366 for(joykey = JOY_SEL; joykey < (JOY_SEL + JOYn) ; joykey++)
Jerome Coutant 0:146cf26a9bbb 367 {
Jerome Coutant 0:146cf26a9bbb 368 /* Enable the JOY clock */
Jerome Coutant 0:146cf26a9bbb 369 JOYx_GPIO_CLK_ENABLE(joykey);
Jerome Coutant 0:146cf26a9bbb 370
Jerome Coutant 0:146cf26a9bbb 371 GPIO_InitStruct.Pin = JOY_PIN[joykey];
Jerome Coutant 0:146cf26a9bbb 372 GPIO_InitStruct.Pull = GPIO_PULLUP;
Jerome Coutant 0:146cf26a9bbb 373 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
Jerome Coutant 0:146cf26a9bbb 374
Jerome Coutant 0:146cf26a9bbb 375 if (Joy_Mode == JOY_MODE_GPIO)
Jerome Coutant 0:146cf26a9bbb 376 {
Jerome Coutant 0:146cf26a9bbb 377 /* Configure Joy pin as input */
Jerome Coutant 0:146cf26a9bbb 378 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
Jerome Coutant 0:146cf26a9bbb 379 HAL_GPIO_Init(JOY_PORT[joykey], &GPIO_InitStruct);
Jerome Coutant 0:146cf26a9bbb 380 }
Jerome Coutant 0:146cf26a9bbb 381 else if (Joy_Mode == JOY_MODE_EXTI)
Jerome Coutant 0:146cf26a9bbb 382 {
Jerome Coutant 0:146cf26a9bbb 383 /* Configure Joy pin as input with External interrupt */
Jerome Coutant 0:146cf26a9bbb 384 GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
Jerome Coutant 0:146cf26a9bbb 385 HAL_GPIO_Init(JOY_PORT[joykey], &GPIO_InitStruct);
Jerome Coutant 0:146cf26a9bbb 386
Jerome Coutant 0:146cf26a9bbb 387 /* Enable and set Joy EXTI Interrupt to the lowest priority */
Jerome Coutant 0:146cf26a9bbb 388 HAL_NVIC_SetPriority((IRQn_Type)(JOY_IRQn[joykey]), 0x0F, 0x00);
Jerome Coutant 0:146cf26a9bbb 389 HAL_NVIC_EnableIRQ((IRQn_Type)(JOY_IRQn[joykey]));
Jerome Coutant 0:146cf26a9bbb 390 }
Jerome Coutant 0:146cf26a9bbb 391 }
Jerome Coutant 0:146cf26a9bbb 392
Jerome Coutant 0:146cf26a9bbb 393 return HAL_OK;
Jerome Coutant 0:146cf26a9bbb 394 }
Jerome Coutant 0:146cf26a9bbb 395
Jerome Coutant 0:146cf26a9bbb 396 /**
Jerome Coutant 0:146cf26a9bbb 397 * @brief Un-configures all GPIOs used as joystick's buttons.
Jerome Coutant 0:146cf26a9bbb 398 * @retval None.
Jerome Coutant 0:146cf26a9bbb 399 */
Jerome Coutant 0:146cf26a9bbb 400 void BSP_JOY_DeInit(void)
Jerome Coutant 0:146cf26a9bbb 401 {
Jerome Coutant 0:146cf26a9bbb 402 JOYState_TypeDef joykey;
Jerome Coutant 0:146cf26a9bbb 403
Jerome Coutant 0:146cf26a9bbb 404 /* Initialized the Joystick. */
Jerome Coutant 0:146cf26a9bbb 405 for(joykey = JOY_SEL; joykey < (JOY_SEL + JOYn) ; joykey++)
Jerome Coutant 0:146cf26a9bbb 406 {
Jerome Coutant 0:146cf26a9bbb 407 /* Enable the JOY clock */
Jerome Coutant 0:146cf26a9bbb 408 JOYx_GPIO_CLK_ENABLE(joykey);
Jerome Coutant 0:146cf26a9bbb 409
Jerome Coutant 0:146cf26a9bbb 410 HAL_GPIO_DeInit(JOY_PORT[joykey], JOY_PIN[joykey]);
Jerome Coutant 0:146cf26a9bbb 411 }
Jerome Coutant 0:146cf26a9bbb 412 }
Jerome Coutant 0:146cf26a9bbb 413
Jerome Coutant 0:146cf26a9bbb 414 /**
Jerome Coutant 0:146cf26a9bbb 415 * @brief Returns the current joystick status.
Jerome Coutant 0:146cf26a9bbb 416 * @retval Code of the joystick key pressed
Jerome Coutant 0:146cf26a9bbb 417 * This code can be one of the following values:
Jerome Coutant 0:146cf26a9bbb 418 * @arg JOY_NONE
Jerome Coutant 0:146cf26a9bbb 419 * @arg JOY_SEL
Jerome Coutant 0:146cf26a9bbb 420 * @arg JOY_DOWN
Jerome Coutant 0:146cf26a9bbb 421 * @arg JOY_LEFT
Jerome Coutant 0:146cf26a9bbb 422 * @arg JOY_RIGHT
Jerome Coutant 0:146cf26a9bbb 423 * @arg JOY_UP
Jerome Coutant 0:146cf26a9bbb 424 */
Jerome Coutant 0:146cf26a9bbb 425 JOYState_TypeDef BSP_JOY_GetState(void)
Jerome Coutant 0:146cf26a9bbb 426 {
Jerome Coutant 0:146cf26a9bbb 427 JOYState_TypeDef joykey;
Jerome Coutant 0:146cf26a9bbb 428
Jerome Coutant 0:146cf26a9bbb 429 for (joykey = JOY_SEL; joykey < (JOY_SEL + JOYn) ; joykey++)
Jerome Coutant 0:146cf26a9bbb 430 {
Jerome Coutant 0:146cf26a9bbb 431 if (HAL_GPIO_ReadPin(JOY_PORT[joykey], JOY_PIN[joykey]) == GPIO_PIN_RESET)
Jerome Coutant 0:146cf26a9bbb 432 {
Jerome Coutant 0:146cf26a9bbb 433 /* Return Code Joystick key pressed */
Jerome Coutant 0:146cf26a9bbb 434 return joykey;
Jerome Coutant 0:146cf26a9bbb 435 }
Jerome Coutant 0:146cf26a9bbb 436 }
Jerome Coutant 0:146cf26a9bbb 437
Jerome Coutant 0:146cf26a9bbb 438 /* No Joystick key pressed */
Jerome Coutant 0:146cf26a9bbb 439 return JOY_NONE;
Jerome Coutant 0:146cf26a9bbb 440 }
Jerome Coutant 0:146cf26a9bbb 441
Jerome Coutant 0:146cf26a9bbb 442 /**
Jerome Coutant 0:146cf26a9bbb 443 * @}
Jerome Coutant 0:146cf26a9bbb 444 */
Jerome Coutant 0:146cf26a9bbb 445
Jerome Coutant 0:146cf26a9bbb 446 /** @defgroup STM32H747I_DISCOVERY_LOW_LEVEL_Private_Functions Private Functions
Jerome Coutant 0:146cf26a9bbb 447 * @{
Jerome Coutant 0:146cf26a9bbb 448 */
Jerome Coutant 0:146cf26a9bbb 449 /*******************************************************************************
Jerome Coutant 0:146cf26a9bbb 450 BUS OPERATIONS
Jerome Coutant 0:146cf26a9bbb 451 *******************************************************************************/
Jerome Coutant 0:146cf26a9bbb 452
Jerome Coutant 0:146cf26a9bbb 453 /******************************* I2C Routines *********************************/
Jerome Coutant 0:146cf26a9bbb 454 /**
Jerome Coutant 0:146cf26a9bbb 455 * @brief Initializes I2C MSP.
Jerome Coutant 0:146cf26a9bbb 456 * @retval None
Jerome Coutant 0:146cf26a9bbb 457 */
Jerome Coutant 0:146cf26a9bbb 458 static void I2Cx_MspInit(void)
Jerome Coutant 0:146cf26a9bbb 459 {
Jerome Coutant 0:146cf26a9bbb 460 GPIO_InitTypeDef gpio_init_structure;
Jerome Coutant 0:146cf26a9bbb 461 RCC_PeriphCLKInitTypeDef RCC_PeriphClkInit;
Jerome Coutant 0:146cf26a9bbb 462
Jerome Coutant 0:146cf26a9bbb 463 /* Configure the I2C clock source */
Jerome Coutant 0:146cf26a9bbb 464 RCC_PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C123;
Jerome Coutant 0:146cf26a9bbb 465 RCC_PeriphClkInit.I2c123ClockSelection = RCC_I2C123CLKSOURCE_D2PCLK1;
Jerome Coutant 0:146cf26a9bbb 466 HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInit);
Jerome Coutant 0:146cf26a9bbb 467
Jerome Coutant 0:146cf26a9bbb 468 /* set STOPWUCK in RCC_CFGR */
Jerome Coutant 0:146cf26a9bbb 469 __HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI);
Jerome Coutant 0:146cf26a9bbb 470
Jerome Coutant 0:146cf26a9bbb 471 /*** Configure the GPIOs ***/
Jerome Coutant 0:146cf26a9bbb 472 /* Enable GPIO clock */
Jerome Coutant 0:146cf26a9bbb 473 DISCOVERY_I2Cx_SCL_SDA_GPIO_CLK_ENABLE();
Jerome Coutant 0:146cf26a9bbb 474
Jerome Coutant 0:146cf26a9bbb 475 /* Configure I2C Tx as alternate function */
Jerome Coutant 0:146cf26a9bbb 476 gpio_init_structure.Pin = DISCOVERY_I2Cx_SCL_PIN;
Jerome Coutant 0:146cf26a9bbb 477 gpio_init_structure.Mode = GPIO_MODE_AF_OD;
Jerome Coutant 0:146cf26a9bbb 478 gpio_init_structure.Pull = GPIO_NOPULL;
Jerome Coutant 0:146cf26a9bbb 479 gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
Jerome Coutant 0:146cf26a9bbb 480 gpio_init_structure.Alternate = DISCOVERY_I2Cx_SCL_SDA_AF;
Jerome Coutant 0:146cf26a9bbb 481 HAL_GPIO_Init(DISCOVERY_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
Jerome Coutant 0:146cf26a9bbb 482
Jerome Coutant 0:146cf26a9bbb 483 /* Configure I2C Rx as alternate function */
Jerome Coutant 0:146cf26a9bbb 484 gpio_init_structure.Pin = DISCOVERY_I2Cx_SDA_PIN;
Jerome Coutant 0:146cf26a9bbb 485 HAL_GPIO_Init(DISCOVERY_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
Jerome Coutant 0:146cf26a9bbb 486
Jerome Coutant 0:146cf26a9bbb 487 /*** Configure the I2C peripheral ***/
Jerome Coutant 0:146cf26a9bbb 488 /* Enable I2C clock */
Jerome Coutant 0:146cf26a9bbb 489 DISCOVERY_I2Cx_CLK_ENABLE();
Jerome Coutant 0:146cf26a9bbb 490
Jerome Coutant 0:146cf26a9bbb 491 /* Force the I2C peripheral clock reset */
Jerome Coutant 0:146cf26a9bbb 492 DISCOVERY_I2Cx_FORCE_RESET();
Jerome Coutant 0:146cf26a9bbb 493
Jerome Coutant 0:146cf26a9bbb 494 /* Release the I2C peripheral clock reset */
Jerome Coutant 0:146cf26a9bbb 495 DISCOVERY_I2Cx_RELEASE_RESET();
Jerome Coutant 0:146cf26a9bbb 496
Jerome Coutant 0:146cf26a9bbb 497 /* Enable and set I2Cx Interrupt to a lower priority */
Jerome Coutant 0:146cf26a9bbb 498 HAL_NVIC_SetPriority(DISCOVERY_I2Cx_EV_IRQn, 0x0F, 0);
Jerome Coutant 0:146cf26a9bbb 499 HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_EV_IRQn);
Jerome Coutant 0:146cf26a9bbb 500
Jerome Coutant 0:146cf26a9bbb 501 /* Enable and set I2Cx Interrupt to a lower priority */
Jerome Coutant 0:146cf26a9bbb 502 HAL_NVIC_SetPriority(DISCOVERY_I2Cx_ER_IRQn, 0x0F, 0);
Jerome Coutant 0:146cf26a9bbb 503 HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_ER_IRQn);
Jerome Coutant 0:146cf26a9bbb 504 }
Jerome Coutant 0:146cf26a9bbb 505
Jerome Coutant 0:146cf26a9bbb 506 /**
Jerome Coutant 0:146cf26a9bbb 507 * @brief Initializes I2C HAL.
Jerome Coutant 0:146cf26a9bbb 508 * @retval None
Jerome Coutant 0:146cf26a9bbb 509 */
Jerome Coutant 0:146cf26a9bbb 510 static void I2Cx_Init(void)
Jerome Coutant 0:146cf26a9bbb 511 {
Jerome Coutant 0:146cf26a9bbb 512 if(HAL_I2C_GetState(&heval_I2c) == HAL_I2C_STATE_RESET)
Jerome Coutant 0:146cf26a9bbb 513 {
Jerome Coutant 0:146cf26a9bbb 514 #if defined(BSP_USE_CMSIS_OS)
Jerome Coutant 0:146cf26a9bbb 515 if(BspI2cSemaphore == NULL)
Jerome Coutant 0:146cf26a9bbb 516 {
Jerome Coutant 0:146cf26a9bbb 517 /* Create semaphore to prevent multiple I2C access */
Jerome Coutant 0:146cf26a9bbb 518 osSemaphoreDef(BSP_I2C_SEM);
Jerome Coutant 0:146cf26a9bbb 519 BspI2cSemaphore = osSemaphoreCreate(osSemaphore(BSP_I2C_SEM), 1);
Jerome Coutant 0:146cf26a9bbb 520 }
Jerome Coutant 0:146cf26a9bbb 521 #endif
Jerome Coutant 0:146cf26a9bbb 522
Jerome Coutant 0:146cf26a9bbb 523 heval_I2c.Instance = DISCOVERY_I2Cx;
Jerome Coutant 0:146cf26a9bbb 524 heval_I2c.Init.Timing = DISCOVERY_I2Cx_TIMING;
Jerome Coutant 0:146cf26a9bbb 525 heval_I2c.Init.OwnAddress1 = 0x72;
Jerome Coutant 0:146cf26a9bbb 526 heval_I2c.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
Jerome Coutant 0:146cf26a9bbb 527 heval_I2c.Init.DualAddressMode = I2C_DUALADDRESS_ENABLE;
Jerome Coutant 0:146cf26a9bbb 528 heval_I2c.Init.OwnAddress2 = 0;
Jerome Coutant 0:146cf26a9bbb 529 heval_I2c.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
Jerome Coutant 0:146cf26a9bbb 530 heval_I2c.Init.GeneralCallMode = I2C_GENERALCALL_ENABLE;
Jerome Coutant 0:146cf26a9bbb 531 heval_I2c.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
Jerome Coutant 0:146cf26a9bbb 532
Jerome Coutant 0:146cf26a9bbb 533 /* Init the I2C */
Jerome Coutant 0:146cf26a9bbb 534 I2Cx_MspInit();
Jerome Coutant 0:146cf26a9bbb 535 HAL_I2C_Init(&heval_I2c);
Jerome Coutant 0:146cf26a9bbb 536 }
Jerome Coutant 0:146cf26a9bbb 537 }
Jerome Coutant 0:146cf26a9bbb 538
Jerome Coutant 0:146cf26a9bbb 539 /**
Jerome Coutant 0:146cf26a9bbb 540 * @brief Writes a single data.
Jerome Coutant 0:146cf26a9bbb 541 * @param Addr: I2C address
Jerome Coutant 0:146cf26a9bbb 542 * @param Reg: Register address
Jerome Coutant 0:146cf26a9bbb 543 * @param Value: Data to be written
Jerome Coutant 0:146cf26a9bbb 544 * @retval None
Jerome Coutant 0:146cf26a9bbb 545 */
Jerome Coutant 0:146cf26a9bbb 546 static void I2Cx_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
Jerome Coutant 0:146cf26a9bbb 547 {
Jerome Coutant 0:146cf26a9bbb 548 HAL_StatusTypeDef status = HAL_OK;
Jerome Coutant 0:146cf26a9bbb 549
Jerome Coutant 0:146cf26a9bbb 550 #if defined(BSP_USE_CMSIS_OS)
Jerome Coutant 0:146cf26a9bbb 551 /* Get semaphore to prevent multiple I2C access */
Jerome Coutant 0:146cf26a9bbb 552 osSemaphoreWait(BspI2cSemaphore, osWaitForever);
Jerome Coutant 0:146cf26a9bbb 553 #endif
Jerome Coutant 0:146cf26a9bbb 554
Jerome Coutant 0:146cf26a9bbb 555 status = HAL_I2C_Mem_Write(&heval_I2c, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1, 100);
Jerome Coutant 0:146cf26a9bbb 556
Jerome Coutant 0:146cf26a9bbb 557 #if defined(BSP_USE_CMSIS_OS)
Jerome Coutant 0:146cf26a9bbb 558 /* Release semaphore to prevent multiple I2C access */
Jerome Coutant 0:146cf26a9bbb 559 osSemaphoreRelease(BspI2cSemaphore);
Jerome Coutant 0:146cf26a9bbb 560 #endif
Jerome Coutant 0:146cf26a9bbb 561
Jerome Coutant 0:146cf26a9bbb 562 /* Check the communication status */
Jerome Coutant 0:146cf26a9bbb 563 if(status != HAL_OK)
Jerome Coutant 0:146cf26a9bbb 564 {
Jerome Coutant 0:146cf26a9bbb 565 /* Execute user timeout callback */
Jerome Coutant 0:146cf26a9bbb 566 I2Cx_Error(Addr);
Jerome Coutant 0:146cf26a9bbb 567 }
Jerome Coutant 0:146cf26a9bbb 568 }
Jerome Coutant 0:146cf26a9bbb 569
Jerome Coutant 0:146cf26a9bbb 570 /**
Jerome Coutant 0:146cf26a9bbb 571 * @brief Reads a single data.
Jerome Coutant 0:146cf26a9bbb 572 * @param Addr: I2C address
Jerome Coutant 0:146cf26a9bbb 573 * @param Reg: Register address
Jerome Coutant 0:146cf26a9bbb 574 * @retval Read data
Jerome Coutant 0:146cf26a9bbb 575 */
Jerome Coutant 0:146cf26a9bbb 576 static uint8_t I2Cx_Read(uint8_t Addr, uint8_t Reg)
Jerome Coutant 0:146cf26a9bbb 577 {
Jerome Coutant 0:146cf26a9bbb 578 HAL_StatusTypeDef status = HAL_OK;
Jerome Coutant 0:146cf26a9bbb 579 uint8_t Value = 0;
Jerome Coutant 0:146cf26a9bbb 580
Jerome Coutant 0:146cf26a9bbb 581 #if defined(BSP_USE_CMSIS_OS)
Jerome Coutant 0:146cf26a9bbb 582 /* Get semaphore to prevent multiple I2C access */
Jerome Coutant 0:146cf26a9bbb 583 osSemaphoreWait(BspI2cSemaphore, osWaitForever);
Jerome Coutant 0:146cf26a9bbb 584 #endif
Jerome Coutant 0:146cf26a9bbb 585
Jerome Coutant 0:146cf26a9bbb 586 status = HAL_I2C_Mem_Read(&heval_I2c, Addr, Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1, 1000);
Jerome Coutant 0:146cf26a9bbb 587
Jerome Coutant 0:146cf26a9bbb 588 #if defined(BSP_USE_CMSIS_OS)
Jerome Coutant 0:146cf26a9bbb 589 /* Release semaphore to prevent multiple I2C access */
Jerome Coutant 0:146cf26a9bbb 590 osSemaphoreRelease(BspI2cSemaphore);
Jerome Coutant 0:146cf26a9bbb 591 #endif
Jerome Coutant 0:146cf26a9bbb 592
Jerome Coutant 0:146cf26a9bbb 593 /* Check the communication status */
Jerome Coutant 0:146cf26a9bbb 594 if(status != HAL_OK)
Jerome Coutant 0:146cf26a9bbb 595 {
Jerome Coutant 0:146cf26a9bbb 596 /* Execute user timeout callback */
Jerome Coutant 0:146cf26a9bbb 597 I2Cx_Error(Addr);
Jerome Coutant 0:146cf26a9bbb 598 }
Jerome Coutant 0:146cf26a9bbb 599 return Value;
Jerome Coutant 0:146cf26a9bbb 600 }
Jerome Coutant 0:146cf26a9bbb 601
Jerome Coutant 0:146cf26a9bbb 602 /**
Jerome Coutant 0:146cf26a9bbb 603 * @brief Reads multiple data.
Jerome Coutant 0:146cf26a9bbb 604 * @param Addr: I2C address
Jerome Coutant 0:146cf26a9bbb 605 * @param Reg: Reg address
Jerome Coutant 0:146cf26a9bbb 606 * @param MemAddress: memory address
Jerome Coutant 0:146cf26a9bbb 607 * @param Buffer: Pointer to data buffer
Jerome Coutant 0:146cf26a9bbb 608 * @param Length: Length of the data
Jerome Coutant 0:146cf26a9bbb 609 * @retval HAL status
Jerome Coutant 0:146cf26a9bbb 610 */
Jerome Coutant 0:146cf26a9bbb 611 static HAL_StatusTypeDef I2Cx_ReadMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddress, uint8_t *Buffer, uint16_t Length)
Jerome Coutant 0:146cf26a9bbb 612 {
Jerome Coutant 0:146cf26a9bbb 613 HAL_StatusTypeDef status = HAL_OK;
Jerome Coutant 0:146cf26a9bbb 614
Jerome Coutant 0:146cf26a9bbb 615 #if defined(BSP_USE_CMSIS_OS)
Jerome Coutant 0:146cf26a9bbb 616 /* Get semaphore to prevent multiple I2C access */
Jerome Coutant 0:146cf26a9bbb 617 osSemaphoreWait(BspI2cSemaphore, osWaitForever);
Jerome Coutant 0:146cf26a9bbb 618 #endif
Jerome Coutant 0:146cf26a9bbb 619
Jerome Coutant 0:146cf26a9bbb 620 status = HAL_I2C_Mem_Read(&heval_I2c, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000);
Jerome Coutant 0:146cf26a9bbb 621
Jerome Coutant 0:146cf26a9bbb 622 #if defined(BSP_USE_CMSIS_OS)
Jerome Coutant 0:146cf26a9bbb 623 /* Release semaphore to prevent multiple I2C access */
Jerome Coutant 0:146cf26a9bbb 624 osSemaphoreRelease(BspI2cSemaphore);
Jerome Coutant 0:146cf26a9bbb 625 #endif
Jerome Coutant 0:146cf26a9bbb 626
Jerome Coutant 0:146cf26a9bbb 627 /* Check the communication status */
Jerome Coutant 0:146cf26a9bbb 628 if(status != HAL_OK)
Jerome Coutant 0:146cf26a9bbb 629 {
Jerome Coutant 0:146cf26a9bbb 630 /* I2C error occurred */
Jerome Coutant 0:146cf26a9bbb 631 I2Cx_Error(Addr);
Jerome Coutant 0:146cf26a9bbb 632 }
Jerome Coutant 0:146cf26a9bbb 633 return status;
Jerome Coutant 0:146cf26a9bbb 634 }
Jerome Coutant 0:146cf26a9bbb 635
Jerome Coutant 0:146cf26a9bbb 636 /**
Jerome Coutant 0:146cf26a9bbb 637 * @brief Writes a value in a register of the device through BUS in using DMA mode.
Jerome Coutant 0:146cf26a9bbb 638 * @param Addr: Device address on BUS Bus.
Jerome Coutant 0:146cf26a9bbb 639 * @param Reg: The target register address to write
Jerome Coutant 0:146cf26a9bbb 640 * @param MemAddress: memory address
Jerome Coutant 0:146cf26a9bbb 641 * @param Buffer: The target register value to be written
Jerome Coutant 0:146cf26a9bbb 642 * @param Length: buffer size to be written
Jerome Coutant 0:146cf26a9bbb 643 * @retval HAL status
Jerome Coutant 0:146cf26a9bbb 644 */
Jerome Coutant 0:146cf26a9bbb 645 static HAL_StatusTypeDef I2Cx_WriteMultiple(uint8_t Addr, uint16_t Reg, uint16_t MemAddress, uint8_t *Buffer, uint16_t Length)
Jerome Coutant 0:146cf26a9bbb 646 {
Jerome Coutant 0:146cf26a9bbb 647 HAL_StatusTypeDef status = HAL_OK;
Jerome Coutant 0:146cf26a9bbb 648
Jerome Coutant 0:146cf26a9bbb 649 #if defined(BSP_USE_CMSIS_OS)
Jerome Coutant 0:146cf26a9bbb 650 /* Get semaphore to prevent multiple I2C access */
Jerome Coutant 0:146cf26a9bbb 651 osSemaphoreWait(BspI2cSemaphore, osWaitForever);
Jerome Coutant 0:146cf26a9bbb 652 #endif
Jerome Coutant 0:146cf26a9bbb 653
Jerome Coutant 0:146cf26a9bbb 654 status = HAL_I2C_Mem_Write(&heval_I2c, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000);
Jerome Coutant 0:146cf26a9bbb 655
Jerome Coutant 0:146cf26a9bbb 656 #if defined(BSP_USE_CMSIS_OS)
Jerome Coutant 0:146cf26a9bbb 657 /* Release semaphore to prevent multiple I2C access */
Jerome Coutant 0:146cf26a9bbb 658 osSemaphoreRelease(BspI2cSemaphore);
Jerome Coutant 0:146cf26a9bbb 659 #endif
Jerome Coutant 0:146cf26a9bbb 660
Jerome Coutant 0:146cf26a9bbb 661 /* Check the communication status */
Jerome Coutant 0:146cf26a9bbb 662 if(status != HAL_OK)
Jerome Coutant 0:146cf26a9bbb 663 {
Jerome Coutant 0:146cf26a9bbb 664 /* Re-Initiaize the I2C Bus */
Jerome Coutant 0:146cf26a9bbb 665 I2Cx_Error(Addr);
Jerome Coutant 0:146cf26a9bbb 666 }
Jerome Coutant 0:146cf26a9bbb 667 return status;
Jerome Coutant 0:146cf26a9bbb 668 }
Jerome Coutant 0:146cf26a9bbb 669
Jerome Coutant 0:146cf26a9bbb 670 /**
Jerome Coutant 0:146cf26a9bbb 671 * @brief Checks if target device is ready for communication.
Jerome Coutant 0:146cf26a9bbb 672 * @note This function is used with Memory devices
Jerome Coutant 0:146cf26a9bbb 673 * @param DevAddress: Target device address
Jerome Coutant 0:146cf26a9bbb 674 * @param Trials: Number of trials
Jerome Coutant 0:146cf26a9bbb 675 * @retval HAL status
Jerome Coutant 0:146cf26a9bbb 676 */
Jerome Coutant 0:146cf26a9bbb 677 static HAL_StatusTypeDef I2Cx_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
Jerome Coutant 0:146cf26a9bbb 678 {
Jerome Coutant 0:146cf26a9bbb 679 HAL_StatusTypeDef status = HAL_OK;
Jerome Coutant 0:146cf26a9bbb 680
Jerome Coutant 0:146cf26a9bbb 681 #if defined(BSP_USE_CMSIS_OS)
Jerome Coutant 0:146cf26a9bbb 682 /* Get semaphore to prevent multiple I2C access */
Jerome Coutant 0:146cf26a9bbb 683 osSemaphoreWait(BspI2cSemaphore, osWaitForever);
Jerome Coutant 0:146cf26a9bbb 684 #endif
Jerome Coutant 0:146cf26a9bbb 685
Jerome Coutant 0:146cf26a9bbb 686 status = HAL_I2C_IsDeviceReady(&heval_I2c, DevAddress, Trials, 1000);
Jerome Coutant 0:146cf26a9bbb 687
Jerome Coutant 0:146cf26a9bbb 688 #if defined(BSP_USE_CMSIS_OS)
Jerome Coutant 0:146cf26a9bbb 689 /* Release semaphore to prevent multiple I2C access */
Jerome Coutant 0:146cf26a9bbb 690 osSemaphoreRelease(BspI2cSemaphore);
Jerome Coutant 0:146cf26a9bbb 691 #endif
Jerome Coutant 0:146cf26a9bbb 692
Jerome Coutant 0:146cf26a9bbb 693 return status;
Jerome Coutant 0:146cf26a9bbb 694 }
Jerome Coutant 0:146cf26a9bbb 695
Jerome Coutant 0:146cf26a9bbb 696 /**
Jerome Coutant 0:146cf26a9bbb 697 * @brief Manages error callback by re-initializing I2C.
Jerome Coutant 0:146cf26a9bbb 698 * @param Addr: I2C Address
Jerome Coutant 0:146cf26a9bbb 699 * @retval None
Jerome Coutant 0:146cf26a9bbb 700 */
Jerome Coutant 0:146cf26a9bbb 701 static void I2Cx_Error(uint8_t Addr)
Jerome Coutant 0:146cf26a9bbb 702 {
Jerome Coutant 0:146cf26a9bbb 703 BSP_ErrorNotify();
Jerome Coutant 0:146cf26a9bbb 704
Jerome Coutant 0:146cf26a9bbb 705 /* De-initialize the I2C comunication bus */
Jerome Coutant 0:146cf26a9bbb 706 HAL_I2C_DeInit(&heval_I2c);
Jerome Coutant 0:146cf26a9bbb 707
Jerome Coutant 0:146cf26a9bbb 708 /* Re-Initialize the I2C communication bus */
Jerome Coutant 0:146cf26a9bbb 709 I2Cx_Init();
Jerome Coutant 0:146cf26a9bbb 710
Jerome Coutant 0:146cf26a9bbb 711 #if defined(BSP_USE_CMSIS_OS)
Jerome Coutant 0:146cf26a9bbb 712 /* Release semaphore to prevent multiple I2C access */
Jerome Coutant 0:146cf26a9bbb 713 osSemaphoreRelease(BspI2cSemaphore);
Jerome Coutant 0:146cf26a9bbb 714 #endif
Jerome Coutant 0:146cf26a9bbb 715 }
Jerome Coutant 0:146cf26a9bbb 716
Jerome Coutant 0:146cf26a9bbb 717 /*******************************************************************************
Jerome Coutant 0:146cf26a9bbb 718 LINK OPERATIONS
Jerome Coutant 0:146cf26a9bbb 719 *******************************************************************************/
Jerome Coutant 0:146cf26a9bbb 720
Jerome Coutant 0:146cf26a9bbb 721 /********************************* LINK AUDIO *********************************/
Jerome Coutant 0:146cf26a9bbb 722
Jerome Coutant 0:146cf26a9bbb 723 /**
Jerome Coutant 0:146cf26a9bbb 724 * @brief Initializes Audio low level.
Jerome Coutant 0:146cf26a9bbb 725 * @retval None
Jerome Coutant 0:146cf26a9bbb 726 */
Jerome Coutant 0:146cf26a9bbb 727 void AUDIO_IO_Init(void)
Jerome Coutant 0:146cf26a9bbb 728 {
Jerome Coutant 0:146cf26a9bbb 729 I2Cx_Init();
Jerome Coutant 0:146cf26a9bbb 730 }
Jerome Coutant 0:146cf26a9bbb 731
Jerome Coutant 0:146cf26a9bbb 732 /**
Jerome Coutant 0:146cf26a9bbb 733 * @brief De-Initializes Audio low level.
Jerome Coutant 0:146cf26a9bbb 734 * @retval None
Jerome Coutant 0:146cf26a9bbb 735 */
Jerome Coutant 0:146cf26a9bbb 736 void AUDIO_IO_DeInit(void)
Jerome Coutant 0:146cf26a9bbb 737 {
Jerome Coutant 0:146cf26a9bbb 738 }
Jerome Coutant 0:146cf26a9bbb 739
Jerome Coutant 0:146cf26a9bbb 740 /**
Jerome Coutant 0:146cf26a9bbb 741 * @brief Writes a single data.
Jerome Coutant 0:146cf26a9bbb 742 * @param Addr: I2C address
Jerome Coutant 0:146cf26a9bbb 743 * @param Reg: Reg address
Jerome Coutant 0:146cf26a9bbb 744 * @param Value: Data to be written
Jerome Coutant 0:146cf26a9bbb 745 * @retval None
Jerome Coutant 0:146cf26a9bbb 746 */
Jerome Coutant 0:146cf26a9bbb 747 void AUDIO_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value)
Jerome Coutant 0:146cf26a9bbb 748 {
Jerome Coutant 0:146cf26a9bbb 749 uint16_t tmp = Value;
Jerome Coutant 0:146cf26a9bbb 750
Jerome Coutant 0:146cf26a9bbb 751 Value = ((uint16_t)(tmp >> 8) & 0x00FF);
Jerome Coutant 0:146cf26a9bbb 752
Jerome Coutant 0:146cf26a9bbb 753 Value |= ((uint16_t)(tmp << 8)& 0xFF00);
Jerome Coutant 0:146cf26a9bbb 754
Jerome Coutant 0:146cf26a9bbb 755 I2Cx_WriteMultiple(Addr, Reg, I2C_MEMADD_SIZE_16BIT,(uint8_t*)&Value, 2);
Jerome Coutant 0:146cf26a9bbb 756 }
Jerome Coutant 0:146cf26a9bbb 757
Jerome Coutant 0:146cf26a9bbb 758 /**
Jerome Coutant 0:146cf26a9bbb 759 * @brief Reads a single data.
Jerome Coutant 0:146cf26a9bbb 760 * @param Addr: I2C address
Jerome Coutant 0:146cf26a9bbb 761 * @param Reg: Reg address
Jerome Coutant 0:146cf26a9bbb 762 * @retval Data to be read
Jerome Coutant 0:146cf26a9bbb 763 */
Jerome Coutant 0:146cf26a9bbb 764 uint16_t AUDIO_IO_Read(uint8_t Addr, uint16_t Reg)
Jerome Coutant 0:146cf26a9bbb 765 {
Jerome Coutant 0:146cf26a9bbb 766 uint16_t read_value = 0, tmp = 0;
Jerome Coutant 0:146cf26a9bbb 767
Jerome Coutant 0:146cf26a9bbb 768 I2Cx_ReadMultiple(Addr, Reg, I2C_MEMADD_SIZE_16BIT, (uint8_t*)&read_value, 2);
Jerome Coutant 0:146cf26a9bbb 769
Jerome Coutant 0:146cf26a9bbb 770 tmp = ((uint16_t)(read_value >> 8) & 0x00FF);
Jerome Coutant 0:146cf26a9bbb 771
Jerome Coutant 0:146cf26a9bbb 772 tmp |= ((uint16_t)(read_value << 8)& 0xFF00);
Jerome Coutant 0:146cf26a9bbb 773
Jerome Coutant 0:146cf26a9bbb 774 read_value = tmp;
Jerome Coutant 0:146cf26a9bbb 775
Jerome Coutant 0:146cf26a9bbb 776 return read_value;
Jerome Coutant 0:146cf26a9bbb 777 }
Jerome Coutant 0:146cf26a9bbb 778
Jerome Coutant 0:146cf26a9bbb 779 /**
Jerome Coutant 0:146cf26a9bbb 780 * @brief AUDIO Codec delay
Jerome Coutant 0:146cf26a9bbb 781 * @param Delay: Delay in ms
Jerome Coutant 0:146cf26a9bbb 782 * @retval None
Jerome Coutant 0:146cf26a9bbb 783 */
Jerome Coutant 0:146cf26a9bbb 784 void AUDIO_IO_Delay(uint32_t Delay)
Jerome Coutant 0:146cf26a9bbb 785 {
Jerome Coutant 0:146cf26a9bbb 786 HAL_Delay(Delay);
Jerome Coutant 0:146cf26a9bbb 787 }
Jerome Coutant 0:146cf26a9bbb 788
Jerome Coutant 0:146cf26a9bbb 789 /********************************* LINK CAMERA ********************************/
Jerome Coutant 0:146cf26a9bbb 790
Jerome Coutant 0:146cf26a9bbb 791 /**
Jerome Coutant 0:146cf26a9bbb 792 * @brief Initializes Camera low level.
Jerome Coutant 0:146cf26a9bbb 793 * @retval None
Jerome Coutant 0:146cf26a9bbb 794 */
Jerome Coutant 0:146cf26a9bbb 795 void CAMERA_IO_Init(void)
Jerome Coutant 0:146cf26a9bbb 796 {
Jerome Coutant 0:146cf26a9bbb 797 I2Cx_Init();
Jerome Coutant 0:146cf26a9bbb 798 }
Jerome Coutant 0:146cf26a9bbb 799
Jerome Coutant 0:146cf26a9bbb 800 /**
Jerome Coutant 0:146cf26a9bbb 801 * @brief Camera writes single data.
Jerome Coutant 0:146cf26a9bbb 802 * @param Addr: I2C address
Jerome Coutant 0:146cf26a9bbb 803 * @param Reg: Register address
Jerome Coutant 0:146cf26a9bbb 804 * @param Value: Data to be written
Jerome Coutant 0:146cf26a9bbb 805 * @retval None
Jerome Coutant 0:146cf26a9bbb 806 */
Jerome Coutant 0:146cf26a9bbb 807 void CAMERA_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value)
Jerome Coutant 0:146cf26a9bbb 808 {
Jerome Coutant 0:146cf26a9bbb 809
Jerome Coutant 0:146cf26a9bbb 810 I2Cx_WriteMultiple(Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT,(uint8_t*)&Value, 1);
Jerome Coutant 0:146cf26a9bbb 811
Jerome Coutant 0:146cf26a9bbb 812 }
Jerome Coutant 0:146cf26a9bbb 813
Jerome Coutant 0:146cf26a9bbb 814 /**
Jerome Coutant 0:146cf26a9bbb 815 * @brief Camera reads single data.
Jerome Coutant 0:146cf26a9bbb 816 * @param Addr: I2C address
Jerome Coutant 0:146cf26a9bbb 817 * @param Reg: Register address
Jerome Coutant 0:146cf26a9bbb 818 * @retval Read data
Jerome Coutant 0:146cf26a9bbb 819 */
Jerome Coutant 0:146cf26a9bbb 820 uint16_t CAMERA_IO_Read(uint8_t Addr, uint16_t Reg)
Jerome Coutant 0:146cf26a9bbb 821 {
Jerome Coutant 0:146cf26a9bbb 822
Jerome Coutant 0:146cf26a9bbb 823 uint16_t Read_Value = 0;
Jerome Coutant 0:146cf26a9bbb 824
Jerome Coutant 0:146cf26a9bbb 825 I2Cx_ReadMultiple(Addr, Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&Read_Value, 1);
Jerome Coutant 0:146cf26a9bbb 826
Jerome Coutant 0:146cf26a9bbb 827 return Read_Value;
Jerome Coutant 0:146cf26a9bbb 828
Jerome Coutant 0:146cf26a9bbb 829 }
Jerome Coutant 0:146cf26a9bbb 830
Jerome Coutant 0:146cf26a9bbb 831 /**
Jerome Coutant 0:146cf26a9bbb 832 * @brief Camera delay
Jerome Coutant 0:146cf26a9bbb 833 * @param Delay: Delay in ms
Jerome Coutant 0:146cf26a9bbb 834 * @retval None
Jerome Coutant 0:146cf26a9bbb 835 */
Jerome Coutant 0:146cf26a9bbb 836 void CAMERA_Delay(uint32_t Delay)
Jerome Coutant 0:146cf26a9bbb 837 {
Jerome Coutant 0:146cf26a9bbb 838 HAL_Delay(Delay);
Jerome Coutant 0:146cf26a9bbb 839 }
Jerome Coutant 0:146cf26a9bbb 840
Jerome Coutant 0:146cf26a9bbb 841 /******************************** LINK I2C EEPROM *****************************/
Jerome Coutant 0:146cf26a9bbb 842
Jerome Coutant 0:146cf26a9bbb 843 /**
Jerome Coutant 0:146cf26a9bbb 844 * @brief Initializes peripherals used by the I2C EEPROM driver.
Jerome Coutant 0:146cf26a9bbb 845 * @retval None
Jerome Coutant 0:146cf26a9bbb 846 */
Jerome Coutant 0:146cf26a9bbb 847 void EEPROM_IO_Init(void)
Jerome Coutant 0:146cf26a9bbb 848 {
Jerome Coutant 0:146cf26a9bbb 849 I2Cx_Init();
Jerome Coutant 0:146cf26a9bbb 850 }
Jerome Coutant 0:146cf26a9bbb 851
Jerome Coutant 0:146cf26a9bbb 852 /**
Jerome Coutant 0:146cf26a9bbb 853 * @brief Write data to I2C EEPROM driver in using DMA channel.
Jerome Coutant 0:146cf26a9bbb 854 * @param DevAddress: Target device address
Jerome Coutant 0:146cf26a9bbb 855 * @param MemAddress: Internal memory address
Jerome Coutant 0:146cf26a9bbb 856 * @param pBuffer: Pointer to data buffer
Jerome Coutant 0:146cf26a9bbb 857 * @param BufferSize: Amount of data to be sent
Jerome Coutant 0:146cf26a9bbb 858 * @retval HAL status
Jerome Coutant 0:146cf26a9bbb 859 */
Jerome Coutant 0:146cf26a9bbb 860 HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize)
Jerome Coutant 0:146cf26a9bbb 861 {
Jerome Coutant 0:146cf26a9bbb 862 return (I2Cx_WriteMultiple(DevAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize));
Jerome Coutant 0:146cf26a9bbb 863 }
Jerome Coutant 0:146cf26a9bbb 864
Jerome Coutant 0:146cf26a9bbb 865 /**
Jerome Coutant 0:146cf26a9bbb 866 * @brief Read data from I2C EEPROM driver in using DMA channel.
Jerome Coutant 0:146cf26a9bbb 867 * @param DevAddress: Target device address
Jerome Coutant 0:146cf26a9bbb 868 * @param MemAddress: Internal memory address
Jerome Coutant 0:146cf26a9bbb 869 * @param pBuffer: Pointer to data buffer
Jerome Coutant 0:146cf26a9bbb 870 * @param BufferSize: Amount of data to be read
Jerome Coutant 0:146cf26a9bbb 871 * @retval HAL status
Jerome Coutant 0:146cf26a9bbb 872 */
Jerome Coutant 0:146cf26a9bbb 873 HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize)
Jerome Coutant 0:146cf26a9bbb 874 {
Jerome Coutant 0:146cf26a9bbb 875 return (I2Cx_ReadMultiple(DevAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize));
Jerome Coutant 0:146cf26a9bbb 876 }
Jerome Coutant 0:146cf26a9bbb 877
Jerome Coutant 0:146cf26a9bbb 878 /**
Jerome Coutant 0:146cf26a9bbb 879 * @brief Checks if target device is ready for communication.
Jerome Coutant 0:146cf26a9bbb 880 * @note This function is used with Memory devices
Jerome Coutant 0:146cf26a9bbb 881 * @param DevAddress: Target device address
Jerome Coutant 0:146cf26a9bbb 882 * @param Trials: Number of trials
Jerome Coutant 0:146cf26a9bbb 883 * @retval HAL status
Jerome Coutant 0:146cf26a9bbb 884 */
Jerome Coutant 0:146cf26a9bbb 885 HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
Jerome Coutant 0:146cf26a9bbb 886 {
Jerome Coutant 0:146cf26a9bbb 887 return (I2Cx_IsDeviceReady(DevAddress, Trials));
Jerome Coutant 0:146cf26a9bbb 888 }
Jerome Coutant 0:146cf26a9bbb 889
Jerome Coutant 0:146cf26a9bbb 890 /******************************** LINK TS (TouchScreen) *****************************/
Jerome Coutant 0:146cf26a9bbb 891
Jerome Coutant 0:146cf26a9bbb 892 /**
Jerome Coutant 0:146cf26a9bbb 893 * @brief Initialize I2C communication
Jerome Coutant 0:146cf26a9bbb 894 * channel from MCU to TouchScreen (TS).
Jerome Coutant 0:146cf26a9bbb 895 */
Jerome Coutant 0:146cf26a9bbb 896 void TS_IO_Init(void)
Jerome Coutant 0:146cf26a9bbb 897 {
Jerome Coutant 0:146cf26a9bbb 898 I2Cx_Init();
Jerome Coutant 0:146cf26a9bbb 899 }
Jerome Coutant 0:146cf26a9bbb 900
Jerome Coutant 0:146cf26a9bbb 901 /**
Jerome Coutant 0:146cf26a9bbb 902 * @brief Writes single data with I2C communication
Jerome Coutant 0:146cf26a9bbb 903 * channel from MCU to TouchScreen.
Jerome Coutant 0:146cf26a9bbb 904 * @param Addr: I2C address
Jerome Coutant 0:146cf26a9bbb 905 * @param Reg: Register address
Jerome Coutant 0:146cf26a9bbb 906 * @param Value: Data to be written
Jerome Coutant 0:146cf26a9bbb 907 */
Jerome Coutant 0:146cf26a9bbb 908 void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
Jerome Coutant 0:146cf26a9bbb 909 {
Jerome Coutant 0:146cf26a9bbb 910 I2Cx_Write(Addr, Reg, Value);
Jerome Coutant 0:146cf26a9bbb 911 }
Jerome Coutant 0:146cf26a9bbb 912
Jerome Coutant 0:146cf26a9bbb 913 /**
Jerome Coutant 0:146cf26a9bbb 914 * @brief Reads single data with I2C communication
Jerome Coutant 0:146cf26a9bbb 915 * channel from TouchScreen.
Jerome Coutant 0:146cf26a9bbb 916 * @param Addr: I2C address
Jerome Coutant 0:146cf26a9bbb 917 * @param Reg: Register address
Jerome Coutant 0:146cf26a9bbb 918 * @retval Read data
Jerome Coutant 0:146cf26a9bbb 919 */
Jerome Coutant 0:146cf26a9bbb 920 uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg)
Jerome Coutant 0:146cf26a9bbb 921 {
Jerome Coutant 0:146cf26a9bbb 922 return I2Cx_Read(Addr, Reg);
Jerome Coutant 0:146cf26a9bbb 923 }
Jerome Coutant 0:146cf26a9bbb 924
Jerome Coutant 0:146cf26a9bbb 925 /**
Jerome Coutant 0:146cf26a9bbb 926 * @brief Reads multiple data with I2C communication
Jerome Coutant 0:146cf26a9bbb 927 * channel from TouchScreen.
Jerome Coutant 0:146cf26a9bbb 928 * @param Addr: I2C address
Jerome Coutant 0:146cf26a9bbb 929 * @param Reg: Register address
Jerome Coutant 0:146cf26a9bbb 930 * @param Buffer: Pointer to data buffer
Jerome Coutant 0:146cf26a9bbb 931 * @param Length: Length of the data
Jerome Coutant 0:146cf26a9bbb 932 * @retval Number of read data
Jerome Coutant 0:146cf26a9bbb 933 */
Jerome Coutant 0:146cf26a9bbb 934 uint16_t TS_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
Jerome Coutant 0:146cf26a9bbb 935 {
Jerome Coutant 0:146cf26a9bbb 936 return I2Cx_ReadMultiple(Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
Jerome Coutant 0:146cf26a9bbb 937 }
Jerome Coutant 0:146cf26a9bbb 938
Jerome Coutant 0:146cf26a9bbb 939 /**
Jerome Coutant 0:146cf26a9bbb 940 * @brief Writes multiple data with I2C communication
Jerome Coutant 0:146cf26a9bbb 941 * channel from MCU to TouchScreen.
Jerome Coutant 0:146cf26a9bbb 942 * @param Addr: I2C address
Jerome Coutant 0:146cf26a9bbb 943 * @param Reg: Register address
Jerome Coutant 0:146cf26a9bbb 944 * @param Buffer: Pointer to data buffer
Jerome Coutant 0:146cf26a9bbb 945 * @param Length: Length of the data
Jerome Coutant 0:146cf26a9bbb 946 * @retval None
Jerome Coutant 0:146cf26a9bbb 947 */
Jerome Coutant 0:146cf26a9bbb 948 void TS_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
Jerome Coutant 0:146cf26a9bbb 949 {
Jerome Coutant 0:146cf26a9bbb 950 I2Cx_WriteMultiple(Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
Jerome Coutant 0:146cf26a9bbb 951 }
Jerome Coutant 0:146cf26a9bbb 952
Jerome Coutant 0:146cf26a9bbb 953 /**
Jerome Coutant 0:146cf26a9bbb 954 * @brief Delay function used in TouchScreen low level driver.
Jerome Coutant 0:146cf26a9bbb 955 * @param Delay: Delay in ms
Jerome Coutant 0:146cf26a9bbb 956 * @retval None
Jerome Coutant 0:146cf26a9bbb 957 */
Jerome Coutant 0:146cf26a9bbb 958 void TS_IO_Delay(uint32_t Delay)
Jerome Coutant 0:146cf26a9bbb 959 {
Jerome Coutant 0:146cf26a9bbb 960 HAL_Delay(Delay);
Jerome Coutant 0:146cf26a9bbb 961 }
Jerome Coutant 0:146cf26a9bbb 962
Jerome Coutant 0:146cf26a9bbb 963 /**************************** LINK OTM8009A (Display driver) ******************/
Jerome Coutant 0:146cf26a9bbb 964 /**
Jerome Coutant 0:146cf26a9bbb 965 * @brief OTM8009A delay
Jerome Coutant 0:146cf26a9bbb 966 * @param Delay: Delay in ms
Jerome Coutant 0:146cf26a9bbb 967 */
Jerome Coutant 0:146cf26a9bbb 968 void OTM8009A_IO_Delay(uint32_t Delay)
Jerome Coutant 0:146cf26a9bbb 969 {
Jerome Coutant 0:146cf26a9bbb 970 HAL_Delay(Delay);
Jerome Coutant 0:146cf26a9bbb 971 }
Jerome Coutant 0:146cf26a9bbb 972
Jerome Coutant 0:146cf26a9bbb 973 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:146cf26a9bbb 974 /**************************** LINK ADV7533 DSI-HDMI (Display driver) **********/
Jerome Coutant 0:146cf26a9bbb 975 /**
Jerome Coutant 0:146cf26a9bbb 976 * @brief Initializes HDMI IO low level.
Jerome Coutant 0:146cf26a9bbb 977 * @retval None
Jerome Coutant 0:146cf26a9bbb 978 */
Jerome Coutant 0:146cf26a9bbb 979 void HDMI_IO_Init(void)
Jerome Coutant 0:146cf26a9bbb 980 {
Jerome Coutant 0:146cf26a9bbb 981 I2Cx_Init();
Jerome Coutant 0:146cf26a9bbb 982 }
Jerome Coutant 0:146cf26a9bbb 983
Jerome Coutant 0:146cf26a9bbb 984 /**
Jerome Coutant 0:146cf26a9bbb 985 * @brief HDMI writes single data.
Jerome Coutant 0:146cf26a9bbb 986 * @param Addr: I2C address
Jerome Coutant 0:146cf26a9bbb 987 * @param Reg: Register address
Jerome Coutant 0:146cf26a9bbb 988 * @param Value: Data to be written
Jerome Coutant 0:146cf26a9bbb 989 * @retval None
Jerome Coutant 0:146cf26a9bbb 990 */
Jerome Coutant 0:146cf26a9bbb 991 void HDMI_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
Jerome Coutant 0:146cf26a9bbb 992 {
Jerome Coutant 0:146cf26a9bbb 993 I2Cx_Write(Addr, Reg, Value);
Jerome Coutant 0:146cf26a9bbb 994 }
Jerome Coutant 0:146cf26a9bbb 995
Jerome Coutant 0:146cf26a9bbb 996 /**
Jerome Coutant 0:146cf26a9bbb 997 * @brief Reads single data with I2C communication
Jerome Coutant 0:146cf26a9bbb 998 * channel from HDMI bridge.
Jerome Coutant 0:146cf26a9bbb 999 * @param Addr: I2C address
Jerome Coutant 0:146cf26a9bbb 1000 * @param Reg: Register address
Jerome Coutant 0:146cf26a9bbb 1001 * @retval Read data
Jerome Coutant 0:146cf26a9bbb 1002 */
Jerome Coutant 0:146cf26a9bbb 1003 uint8_t HDMI_IO_Read(uint8_t Addr, uint8_t Reg)
Jerome Coutant 0:146cf26a9bbb 1004 {
Jerome Coutant 0:146cf26a9bbb 1005 return I2Cx_Read(Addr, Reg);
Jerome Coutant 0:146cf26a9bbb 1006 }
Jerome Coutant 0:146cf26a9bbb 1007
Jerome Coutant 0:146cf26a9bbb 1008 /**
Jerome Coutant 0:146cf26a9bbb 1009 * @brief HDMI delay
Jerome Coutant 0:146cf26a9bbb 1010 * @param Delay: Delay in ms
Jerome Coutant 0:146cf26a9bbb 1011 * @retval None
Jerome Coutant 0:146cf26a9bbb 1012 */
Jerome Coutant 0:146cf26a9bbb 1013 void HDMI_IO_Delay(uint32_t Delay)
Jerome Coutant 0:146cf26a9bbb 1014 {
Jerome Coutant 0:146cf26a9bbb 1015 HAL_Delay(Delay);
Jerome Coutant 0:146cf26a9bbb 1016 }
Jerome Coutant 0:146cf26a9bbb 1017 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:146cf26a9bbb 1018
Jerome Coutant 0:146cf26a9bbb 1019 /**
Jerome Coutant 0:146cf26a9bbb 1020 * @}
Jerome Coutant 0:146cf26a9bbb 1021 */
Jerome Coutant 0:146cf26a9bbb 1022
Jerome Coutant 0:146cf26a9bbb 1023 /**
Jerome Coutant 0:146cf26a9bbb 1024 * @}
Jerome Coutant 0:146cf26a9bbb 1025 */
Jerome Coutant 0:146cf26a9bbb 1026 /**
Jerome Coutant 0:146cf26a9bbb 1027 * @}
Jerome Coutant 0:146cf26a9bbb 1028 */
Jerome Coutant 0:146cf26a9bbb 1029
Jerome Coutant 0:146cf26a9bbb 1030 /**
Jerome Coutant 0:146cf26a9bbb 1031 * @}
Jerome Coutant 0:146cf26a9bbb 1032 */
Jerome Coutant 0:146cf26a9bbb 1033
Jerome Coutant 0:146cf26a9bbb 1034 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/