STM32Cube BSP FW for STM32F769I-Discovery

Dependents:   mbed-os-example-blinky-5 DISCO-F769NI_TOUCHSCREEN_demo_custom_1 Datarecorder2 DISCO-F769NI_TOUCHSCREEN_demo ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32f769i_discovery.c Source File

stm32f769i_discovery.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f769i_discovery.c
00004   * @author  MCD Application Team
00005   * @brief   This file provides a set of firmware functions to manage LEDs,
00006   *          push-buttons, external SDRAM, external QSPI Flash, RF EEPROM,
00007   *          available on STM32F769I-Discovery board (MB1225) from 
00008   *          STMicroelectronics.
00009   ******************************************************************************
00010   * @attention
00011   *
00012   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00013   *
00014   * Redistribution and use in source and binary forms, with or without modification,
00015   * are permitted provided that the following conditions are met:
00016   *   1. Redistributions of source code must retain the above copyright notice,
00017   *      this list of conditions and the following disclaimer.
00018   *   2. Redistributions in binary form must reproduce the above copyright notice,
00019   *      this list of conditions and the following disclaimer in the documentation
00020   *      and/or other materials provided with the distribution.
00021   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00022   *      may be used to endorse or promote products derived from this software
00023   *      without specific prior written permission.
00024   *
00025   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00026   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00028   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00029   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00030   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00031   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00033   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035   *
00036   ******************************************************************************
00037   */
00038 
00039 /* Dependencies
00040 - stm32f7xx_hal_cortex.c
00041 - stm32f7xx_hal_gpio.c
00042 - stm32f7xx_hal_uart.c
00043 - stm32f7xx_hal_i2c.c
00044 EndDependencies */
00045 
00046 /* Includes ------------------------------------------------------------------*/
00047 #include "stm32f769i_discovery.h"
00048 
00049 /** @addtogroup BSP
00050   * @{
00051   */
00052 
00053 /** @addtogroup STM32F769I_DISCOVERY
00054   * @{
00055   */
00056 
00057 /** @defgroup STM32F769I_DISCOVERY_LOW_LEVEL STM32F769I_DISCOVERY LOW LEVEL
00058   * @{
00059   */
00060 
00061 /** @defgroup STM32F769I_DISCOVERY_LOW_LEVEL_Private_TypesDefinitions STM32F769I Discovery Low Level Private Typedef
00062   * @{
00063   */
00064 /**
00065   * @}
00066   */
00067 
00068 /** @defgroup STM32F769I_DISCOVERY_LOW_LEVEL_Private_Defines LOW_LEVEL Private Defines
00069   * @{
00070   */
00071 /**
00072  * @brief STM32F769I Discovery BSP Driver version number V2.0.1
00073    */
00074 #define __STM32F769I_DISCOVERY_BSP_VERSION_MAIN   (0x02) /*!< [31:24] main version */
00075 #define __STM32F769I_DISCOVERY_BSP_VERSION_SUB1   (0x00) /*!< [23:16] sub1 version */
00076 #define __STM32F769I_DISCOVERY_BSP_VERSION_SUB2   (0x01) /*!< [15:8]  sub2 version */
00077 #define __STM32F769I_DISCOVERY_BSP_VERSION_RC     (0x00) /*!< [7:0]  release candidate */
00078 #define __STM32F769I_DISCOVERY_BSP_VERSION        ((__STM32F769I_DISCOVERY_BSP_VERSION_MAIN << 24)\
00079                                                  |(__STM32F769I_DISCOVERY_BSP_VERSION_SUB1 << 16)\
00080                                                  |(__STM32F769I_DISCOVERY_BSP_VERSION_SUB2 << 8 )\
00081                                                  |(__STM32F769I_DISCOVERY_BSP_VERSION_RC))
00082 /**
00083   * @}
00084   */
00085 
00086 /** @defgroup STM32F769I_DISCOVERY_LOW_LEVEL_Private_Macros  LOW_LEVEL Private Macros
00087   * @{
00088   */
00089 /**
00090   * @}
00091   */
00092 
00093 /** @defgroup STM32F769I_DISCOVERY_LOW_LEVEL_Private_Variables LOW_LEVEL Private Variables
00094   * @{
00095   */
00096 uint32_t GPIO_PIN[LEDn] = {LED1_PIN,
00097                            LED2_PIN};
00098 
00099 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED1_GPIO_PORT,
00100                                  LED2_GPIO_PORT};
00101 
00102 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT };
00103 
00104 const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN };
00105 
00106 const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn };
00107 
00108 
00109 static I2C_HandleTypeDef hI2cAudioHandler = {0};
00110 static I2C_HandleTypeDef hI2cExtHandler = {0};
00111 
00112 /**
00113   * @}
00114   */
00115 
00116 /** @defgroup STM32F769I_DISCOVERY_LOW_LEVEL_Private_FunctionPrototypes LOW_LEVEL Private FunctionPrototypes
00117   * @{
00118   */
00119 static void     I2Cx_MspInit(I2C_HandleTypeDef *i2c_handler);
00120 static void     I2Cx_Init(I2C_HandleTypeDef *i2c_handler);
00121 
00122 static HAL_StatusTypeDef I2Cx_ReadMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
00123 static HAL_StatusTypeDef I2Cx_WriteMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
00124 static HAL_StatusTypeDef I2Cx_IsDeviceReady(I2C_HandleTypeDef *i2c_handler, uint16_t DevAddress, uint32_t Trials);
00125 static void              I2Cx_Error(I2C_HandleTypeDef *i2c_handler, uint8_t Addr);
00126 
00127 /* AUDIO IO functions */
00128 void            AUDIO_IO_Init(void);
00129 void            AUDIO_IO_DeInit(void);
00130 void            AUDIO_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value);
00131 uint16_t        AUDIO_IO_Read(uint8_t Addr, uint16_t Reg);
00132 void            AUDIO_IO_Delay(uint32_t Delay);
00133 
00134 /* HDMI IO functions */
00135 void            HDMI_IO_Init(void);
00136 void            HDMI_IO_Delay(uint32_t Delay);
00137 void            HDMI_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
00138 uint8_t         HDMI_IO_Read(uint8_t Addr, uint8_t Reg);
00139 
00140 /* I2C EEPROM IO function */
00141 void                EEPROM_IO_Init(void);
00142 HAL_StatusTypeDef   EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize);
00143 HAL_StatusTypeDef   EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize);
00144 HAL_StatusTypeDef   EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);
00145 
00146 /* TouchScreen (TS) IO functions */
00147 void     TS_IO_Init(void);
00148 void     TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
00149 uint8_t  TS_IO_Read(uint8_t Addr, uint8_t Reg);
00150 uint16_t TS_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
00151 void     TS_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
00152 void     TS_IO_Delay(uint32_t Delay);
00153 
00154 /* LCD Display IO functions */
00155 void     OTM8009A_IO_Delay(uint32_t Delay);
00156 /**
00157   * @}
00158   */
00159 
00160 /** @defgroup STM32F769I_DISCOVERY_BSP_Public_Functions BSP Public Functions
00161   * @{
00162   */
00163 
00164   /**
00165   * @brief  This method returns the STM32F769I Discovery BSP Driver revision
00166   * @retval version: 0xXYZR (8bits for each decimal, R for RC)
00167   */
00168 uint32_t BSP_GetVersion(void)
00169 {
00170   return __STM32F769I_DISCOVERY_BSP_VERSION;
00171 }
00172 
00173 /**
00174   * @brief  Configures LED GPIO.
00175   * @param  Led: LED to be configured.
00176   *          This parameter can be one of the following values:
00177   *            @arg  DISCO_LED1
00178   *            @arg  DISCO_LED2
00179   * @retval None
00180   */
00181 void BSP_LED_Init(Led_TypeDef Led)
00182 {
00183   GPIO_InitTypeDef  gpio_init_structure;
00184   
00185   LEDx_GPIO_CLK_ENABLE();
00186   /* Configure the GPIO_LED pin */
00187   gpio_init_structure.Pin   = GPIO_PIN[Led];
00188   gpio_init_structure.Mode  = GPIO_MODE_OUTPUT_PP;
00189   gpio_init_structure.Pull  = GPIO_PULLUP;
00190   gpio_init_structure.Speed = GPIO_SPEED_HIGH;
00191   
00192   HAL_GPIO_Init(GPIO_PORT[Led], &gpio_init_structure);
00193 
00194 }
00195 
00196 
00197 /**
00198   * @brief  DeInit LEDs.
00199   * @param  Led: LED to be configured.
00200   *          This parameter can be one of the following values:
00201   *            @arg  DISCO_LED1
00202   *            @arg  DISCO_LED2
00203   * @note Led DeInit does not disable the GPIO clock
00204   * @retval None
00205   */
00206 void BSP_LED_DeInit(Led_TypeDef Led)
00207 {
00208   GPIO_InitTypeDef  gpio_init_structure;
00209   
00210   /* DeInit the GPIO_LED pin */
00211   gpio_init_structure.Pin = GPIO_PIN[Led];
00212   
00213   /* Turn off LED */
00214   HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
00215   HAL_GPIO_DeInit(GPIO_PORT[Led], gpio_init_structure.Pin);
00216 }
00217 
00218 /**
00219   * @brief  Turns selected LED On.
00220   * @param  Led: LED to be set on
00221   *          This parameter can be one of the following values:
00222   *            @arg  DISCO_LED1
00223   *            @arg  DISCO_LED2
00224   * @retval None
00225   */
00226 void BSP_LED_On(Led_TypeDef Led)
00227 {
00228   HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
00229 }
00230 
00231 /**
00232   * @brief  Turns selected LED Off.
00233   * @param  Led: LED to be set off
00234   *          This parameter can be one of the following values:
00235   *            @arg  DISCO_LED1
00236   *            @arg  DISCO_LED2
00237   * @retval None
00238   */
00239 void BSP_LED_Off(Led_TypeDef Led)
00240 {
00241   HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
00242 }
00243 
00244 /**
00245   * @brief  Toggles the selected LED.
00246   * @param  Led: LED to be toggled
00247   *          This parameter can be one of the following values:
00248   *            @arg  DISCO_LED1
00249   *            @arg  DISCO_LED2
00250   * @retval None
00251   */
00252 void BSP_LED_Toggle(Led_TypeDef Led)
00253 {
00254   HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]);
00255 }
00256 
00257 /**
00258   * @brief  Configures button GPIO and EXTI Line.
00259   * @param  Button: Button to be configured
00260   *          This parameter can be one of the following values:
00261   *            @arg  BUTTON_WAKEUP: Wakeup Push Button
00262   *            @arg  BUTTON_USER: User Push Button
00263   * @param  Button_Mode: Button mode
00264   *          This parameter can be one of the following values:
00265   *            @arg  BUTTON_MODE_GPIO: Button will be used as simple IO
00266   *            @arg  BUTTON_MODE_EXTI: Button will be connected to EXTI line
00267   *                                    with interrupt generation capability
00268   * @retval None
00269   */
00270 void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
00271 {
00272   GPIO_InitTypeDef gpio_init_structure;
00273 
00274   /* Enable the BUTTON clock */
00275   BUTTON_GPIO_CLK_ENABLE();
00276 
00277   if(Button_Mode == BUTTON_MODE_GPIO)
00278   {
00279     /* Configure Button pin as input */
00280     gpio_init_structure.Pin = BUTTON_PIN[Button];
00281     gpio_init_structure.Mode = GPIO_MODE_INPUT;
00282     gpio_init_structure.Pull = GPIO_NOPULL;
00283     gpio_init_structure.Speed = GPIO_SPEED_FAST;
00284     HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure);
00285   }
00286 
00287   if(Button_Mode == BUTTON_MODE_EXTI)
00288   {
00289     /* Configure Button pin as input with External interrupt */
00290     gpio_init_structure.Pin = BUTTON_PIN[Button];
00291     gpio_init_structure.Pull = GPIO_NOPULL;
00292     gpio_init_structure.Speed = GPIO_SPEED_FAST;
00293 
00294     gpio_init_structure.Mode = GPIO_MODE_IT_RISING;
00295 
00296     HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure);
00297 
00298     /* Enable and set Button EXTI Interrupt to the lowest priority */
00299     HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00);
00300     HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
00301   }
00302 }
00303 
00304 /**
00305   * @brief  Push Button DeInit.
00306   * @param  Button: Button to be configured
00307   *          This parameter can be one of the following values:
00308   *            @arg  BUTTON_WAKEUP: Wakeup Push Button
00309   *            @arg  BUTTON_USER: User Push Button
00310   * @note PB DeInit does not disable the GPIO clock
00311   * @retval None
00312   */
00313 void BSP_PB_DeInit(Button_TypeDef Button)
00314 {
00315     GPIO_InitTypeDef gpio_init_structure;
00316 
00317     gpio_init_structure.Pin = BUTTON_PIN[Button];
00318     HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
00319     HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin);
00320 }
00321 
00322 
00323 /**
00324   * @brief  Returns the selected button state.
00325   * @param  Button: Button to be checked
00326   *          This parameter can be one of the following values:
00327   *            @arg  BUTTON_WAKEUP: Wakeup Push Button
00328   *            @arg  BUTTON_USER: User Push Button
00329   * @retval The Button GPIO pin value
00330   */
00331 uint32_t BSP_PB_GetState(Button_TypeDef Button)
00332 {
00333   return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
00334 }
00335 
00336 /**
00337   * @}
00338   */
00339 
00340 /** @defgroup STM32F769I_DISCOVERY_LOW_LEVEL_Private_Functions STM32F769I_DISCOVERY_LOW_LEVEL Private Functions
00341   * @{
00342   */
00343 
00344 
00345 /*******************************************************************************
00346                             BUS OPERATIONS
00347 *******************************************************************************/
00348 
00349 /******************************* I2C Routines *********************************/
00350 /**
00351   * @brief  Initializes I2C MSP.
00352   * @param  i2c_handler : I2C handler
00353   * @retval None
00354   */
00355 static void I2Cx_MspInit(I2C_HandleTypeDef *i2c_handler)
00356 {
00357   GPIO_InitTypeDef  gpio_init_structure;
00358 
00359   if (i2c_handler == (I2C_HandleTypeDef*)(&hI2cAudioHandler))
00360   {
00361   /*** Configure the GPIOs ***/
00362   /* Enable GPIO clock */
00363   DISCOVERY_AUDIO_I2Cx_SCL_GPIO_CLK_ENABLE();
00364   DISCOVERY_AUDIO_I2Cx_SDA_GPIO_CLK_ENABLE();
00365   /* Configure I2C Tx as alternate function */
00366   gpio_init_structure.Pin = DISCOVERY_AUDIO_I2Cx_SCL_PIN;
00367   gpio_init_structure.Mode = GPIO_MODE_AF_OD;
00368   gpio_init_structure.Pull = GPIO_NOPULL;
00369   gpio_init_structure.Speed = GPIO_SPEED_FAST;
00370   gpio_init_structure.Alternate = DISCOVERY_AUDIO_I2Cx_SCL_AF;
00371   HAL_GPIO_Init(DISCOVERY_AUDIO_I2Cx_SCL_GPIO_PORT, &gpio_init_structure);
00372 
00373   /* Configure I2C Rx as alternate function */
00374   gpio_init_structure.Pin = DISCOVERY_AUDIO_I2Cx_SDA_PIN;
00375   gpio_init_structure.Alternate = DISCOVERY_AUDIO_I2Cx_SDA_AF;
00376   HAL_GPIO_Init(DISCOVERY_AUDIO_I2Cx_SDA_GPIO_PORT, &gpio_init_structure);
00377 
00378   /*** Configure the I2C peripheral ***/
00379   /* Enable I2C clock */
00380   DISCOVERY_AUDIO_I2Cx_CLK_ENABLE();
00381 
00382   /* Force the I2C peripheral clock reset */
00383   DISCOVERY_AUDIO_I2Cx_FORCE_RESET();
00384 
00385   /* Release the I2C peripheral clock reset */
00386   DISCOVERY_AUDIO_I2Cx_RELEASE_RESET();
00387 
00388   /* Enable and set I2C1 Interrupt to a lower priority */
00389   HAL_NVIC_SetPriority(DISCOVERY_AUDIO_I2Cx_EV_IRQn, 0x0F, 0);
00390   HAL_NVIC_EnableIRQ(DISCOVERY_AUDIO_I2Cx_EV_IRQn);
00391 
00392   /* Enable and set I2C1 Interrupt to a lower priority */
00393   HAL_NVIC_SetPriority(DISCOVERY_AUDIO_I2Cx_ER_IRQn, 0x0F, 0);
00394   HAL_NVIC_EnableIRQ(DISCOVERY_AUDIO_I2Cx_ER_IRQn);    
00395     
00396   }
00397   else
00398   {
00399   /*** Configure the GPIOs ***/
00400   /* Enable GPIO clock */
00401   DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_CLK_ENABLE();
00402 
00403   /* Configure I2C Tx as alternate function */
00404   gpio_init_structure.Pin = DISCOVERY_EXT_I2Cx_SCL_PIN;
00405   gpio_init_structure.Mode = GPIO_MODE_AF_OD;
00406   gpio_init_structure.Pull = GPIO_NOPULL;
00407   gpio_init_structure.Speed = GPIO_SPEED_FAST;
00408   gpio_init_structure.Alternate = DISCOVERY_EXT_I2Cx_SCL_SDA_AF;
00409   HAL_GPIO_Init(DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
00410 
00411   /* Configure I2C Rx as alternate function */
00412   gpio_init_structure.Pin = DISCOVERY_EXT_I2Cx_SDA_PIN;
00413   HAL_GPIO_Init(DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
00414 
00415   /*** Configure the I2C peripheral ***/
00416   /* Enable I2C clock */
00417   DISCOVERY_EXT_I2Cx_CLK_ENABLE();
00418 
00419   /* Force the I2C peripheral clock reset */
00420   DISCOVERY_EXT_I2Cx_FORCE_RESET();
00421 
00422   /* Release the I2C peripheral clock reset */
00423   DISCOVERY_EXT_I2Cx_RELEASE_RESET();
00424 
00425   /* Enable and set I2C1 Interrupt to a lower priority */
00426   HAL_NVIC_SetPriority(DISCOVERY_EXT_I2Cx_EV_IRQn, 0x0F, 0);
00427   HAL_NVIC_EnableIRQ(DISCOVERY_EXT_I2Cx_EV_IRQn);
00428 
00429   /* Enable and set I2C1 Interrupt to a lower priority */
00430   HAL_NVIC_SetPriority(DISCOVERY_EXT_I2Cx_ER_IRQn, 0x0F, 0);
00431   HAL_NVIC_EnableIRQ(DISCOVERY_EXT_I2Cx_ER_IRQn);
00432   }
00433 }
00434 
00435 /**
00436   * @brief  Initializes I2C HAL.
00437   * @param  i2c_handler : I2C handler
00438   * @retval None
00439   */
00440 static void I2Cx_Init(I2C_HandleTypeDef *i2c_handler)
00441 {
00442   if(HAL_I2C_GetState(i2c_handler) == HAL_I2C_STATE_RESET)
00443   {
00444     if (i2c_handler == (I2C_HandleTypeDef*)(&hI2cAudioHandler))
00445     {
00446       /* Audio and LCD I2C configuration */
00447       i2c_handler->Instance = DISCOVERY_AUDIO_I2Cx;
00448     }
00449     else
00450     {
00451       /* External, camera and Arduino connector  I2C configuration */
00452       i2c_handler->Instance = DISCOVERY_EXT_I2Cx;
00453     }
00454     i2c_handler->Init.Timing           = DISCOVERY_I2Cx_TIMING;
00455     i2c_handler->Init.OwnAddress1      = 0;
00456     i2c_handler->Init.AddressingMode   = I2C_ADDRESSINGMODE_7BIT;
00457     i2c_handler->Init.DualAddressMode  = I2C_DUALADDRESS_DISABLE;
00458     i2c_handler->Init.OwnAddress2      = 0;
00459     i2c_handler->Init.GeneralCallMode  = I2C_GENERALCALL_DISABLE;
00460     i2c_handler->Init.NoStretchMode    = I2C_NOSTRETCH_DISABLE;
00461 
00462     /* Init the I2C */
00463     I2Cx_MspInit(i2c_handler);
00464     HAL_I2C_Init(i2c_handler);
00465   }
00466 }
00467 
00468 /**
00469   * @brief  Reads multiple data.
00470   * @param  i2c_handler : I2C handler
00471   * @param  Addr: I2C address
00472   * @param  Reg: Reg address
00473   * @param  MemAddress: memory address
00474   * @param  Buffer: Pointer to data buffer
00475   * @param  Length: Length of the data
00476   * @retval HAL status
00477   */
00478 static HAL_StatusTypeDef I2Cx_ReadMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddress, uint8_t *Buffer, uint16_t Length)
00479 {
00480   HAL_StatusTypeDef status = HAL_OK;
00481 
00482   status = HAL_I2C_Mem_Read(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000);
00483 
00484   /* Check the communication status */
00485   if(status != HAL_OK)
00486   {
00487     /* I2C error occured */
00488     I2Cx_Error(i2c_handler, Addr);
00489   }
00490   return status;
00491 }
00492 
00493 
00494 /**
00495   * @brief  Writes a value in a register of the device through BUS in using DMA mode.
00496   * @param  i2c_handler : I2C handler
00497   * @param  Addr: Device address on BUS Bus.
00498   * @param  Reg: The target register address to write
00499   * @param  MemAddress: memory address
00500   * @param  Buffer: The target register value to be written
00501   * @param  Length: buffer size to be written
00502   * @retval HAL status
00503   */
00504 static HAL_StatusTypeDef I2Cx_WriteMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddress, uint8_t *Buffer, uint16_t Length)
00505 {
00506   HAL_StatusTypeDef status = HAL_OK;
00507 
00508   status = HAL_I2C_Mem_Write(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000);
00509 
00510   /* Check the communication status */
00511   if(status != HAL_OK)
00512   {
00513     /* Re-Initiaize the I2C Bus */
00514     I2Cx_Error(i2c_handler, Addr);
00515   }
00516   return status;
00517 }
00518 
00519 /**
00520   * @brief  Checks if target device is ready for communication. 
00521   * @note   This function is used with Memory devices
00522   * @param  i2c_handler : I2C handler
00523   * @param  DevAddress: Target device address
00524   * @param  Trials: Number of trials
00525   * @retval HAL status
00526   */
00527 static HAL_StatusTypeDef I2Cx_IsDeviceReady(I2C_HandleTypeDef *i2c_handler, uint16_t DevAddress, uint32_t Trials)
00528 { 
00529   return (HAL_I2C_IsDeviceReady(i2c_handler, DevAddress, Trials, 1000));
00530 }
00531 
00532 /**
00533   * @brief  Manages error callback by re-initializing I2C.
00534   * @param  i2c_handler : I2C handler
00535   * @param  Addr: I2C Address
00536   * @retval None
00537   */
00538 static void I2Cx_Error(I2C_HandleTypeDef *i2c_handler, uint8_t Addr)
00539 {
00540   /* De-initialize the I2C communication bus */
00541   HAL_I2C_DeInit(i2c_handler);
00542   
00543   /* Re-Initialize the I2C communication bus */
00544   I2Cx_Init(i2c_handler);
00545 }
00546 
00547 /**
00548   * @}
00549   */
00550 
00551 /*******************************************************************************
00552                             LINK OPERATIONS
00553 *******************************************************************************/
00554 
00555 /********************************* LINK AUDIO *********************************/
00556 
00557 /**
00558   * @brief  Initializes Audio low level.
00559   */
00560 void AUDIO_IO_Init(void)
00561 {
00562   I2Cx_Init(&hI2cAudioHandler);
00563 }
00564 
00565 /**
00566   * @brief  DeInitializes Audio low level.
00567   */
00568 void AUDIO_IO_DeInit(void)
00569 {
00570 
00571 }
00572 
00573 /**
00574   * @brief  Writes a single data.
00575   * @param  Addr: I2C address
00576   * @param  Reg: Reg address 
00577   * @param  Value: Data to be written
00578   * @retval None
00579   */
00580 void AUDIO_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value)
00581 {
00582   uint16_t tmp = Value;
00583   
00584   Value = ((uint16_t)(tmp >> 8) & 0x00FF);
00585   
00586   Value |= ((uint16_t)(tmp << 8)& 0xFF00);
00587   
00588   I2Cx_WriteMultiple(&hI2cAudioHandler, Addr, Reg, I2C_MEMADD_SIZE_16BIT,(uint8_t*)&Value, 2);
00589 }
00590 
00591 /**
00592   * @brief  Reads a single data.
00593   * @param  Addr: I2C address
00594   * @param  Reg: Reg address 
00595   * @retval Data to be read
00596   */
00597 uint16_t AUDIO_IO_Read(uint8_t Addr, uint16_t Reg)
00598 {
00599   uint16_t read_value = 0, tmp = 0;
00600   
00601   I2Cx_ReadMultiple(&hI2cAudioHandler, Addr, Reg, I2C_MEMADD_SIZE_16BIT, (uint8_t*)&read_value, 2);
00602   
00603   tmp = ((uint16_t)(read_value >> 8) & 0x00FF);
00604   
00605   tmp |= ((uint16_t)(read_value << 8)& 0xFF00);
00606   
00607   read_value = tmp;
00608   
00609   return read_value;
00610 }
00611 
00612 /**
00613   * @brief  AUDIO Codec delay
00614   * @param  Delay: Delay in ms
00615   */
00616 void AUDIO_IO_Delay(uint32_t Delay)
00617 {
00618   HAL_Delay(Delay);
00619 }
00620 
00621 /******************************** LINK I2C EEPROM *****************************/
00622 
00623 /**
00624   * @brief  Initializes peripherals used by the I2C EEPROM driver.
00625   */
00626 void EEPROM_IO_Init(void)
00627 {
00628   I2Cx_Init(&hI2cExtHandler);
00629 }
00630 
00631 /**
00632   * @brief  Write data to I2C EEPROM driver in using DMA channel.
00633   * @param  DevAddress: Target device address
00634   * @param  MemAddress: Internal memory address
00635   * @param  pBuffer: Pointer to data buffer
00636   * @param  BufferSize: Amount of data to be sent
00637   * @retval HAL status
00638   */
00639 HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize)
00640 {
00641   return (I2Cx_WriteMultiple(&hI2cExtHandler, DevAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize));
00642 }
00643 
00644 /**
00645   * @brief  Read data from I2C EEPROM driver in using DMA channel.
00646   * @param  DevAddress: Target device address
00647   * @param  MemAddress: Internal memory address
00648   * @param  pBuffer: Pointer to data buffer
00649   * @param  BufferSize: Amount of data to be read
00650   * @retval HAL status
00651   */
00652 HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize)
00653 {
00654   return (I2Cx_ReadMultiple(&hI2cExtHandler, DevAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize));
00655 }
00656 
00657 /**
00658   * @brief  Checks if target device is ready for communication. 
00659   * @note   This function is used with Memory devices
00660   * @param  DevAddress: Target device address
00661   * @param  Trials: Number of trials
00662   * @retval HAL status
00663   */
00664 HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
00665 { 
00666   return (I2Cx_IsDeviceReady(&hI2cExtHandler, DevAddress, Trials));
00667 }
00668 
00669 /******************************** LINK TS (TouchScreen) ***********************/
00670 
00671 /**
00672   * @brief  Initializes Touchscreen low level.
00673   * @retval None
00674   */
00675 void TS_IO_Init(void)
00676 {
00677   I2Cx_Init(&hI2cAudioHandler);
00678 }
00679 
00680 /**
00681   * @brief  Writes a single data.
00682   * @param  Addr: I2C address
00683   * @param  Reg: Reg address
00684   * @param  Value: Data to be written
00685   * @retval None
00686   */
00687 void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
00688 {
00689   I2Cx_WriteMultiple(&hI2cAudioHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT,(uint8_t*)&Value, 1);
00690 }
00691 
00692 /**
00693   * @brief  Reads a single data.
00694   * @param  Addr: I2C address
00695   * @param  Reg: Reg address
00696   * @retval Data to be read
00697   */
00698 uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg)
00699 {
00700   uint8_t read_value = 0;
00701 
00702   I2Cx_ReadMultiple(&hI2cAudioHandler, Addr, Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&read_value, 1);
00703 
00704   return read_value;
00705 }
00706 
00707 /**
00708   * @brief  Reads multiple data with I2C communication
00709   *         channel from TouchScreen.
00710   * @param  Addr: I2C address
00711   * @param  Reg: Register address
00712   * @param  Buffer: Pointer to data buffer
00713   * @param  Length: Length of the data
00714   * @retval Number of read data
00715   */
00716 uint16_t TS_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
00717 {
00718  return I2Cx_ReadMultiple(&hI2cAudioHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
00719 }
00720 
00721 /**
00722   * @brief  Writes multiple data with I2C communication
00723   *         channel from MCU to TouchScreen.
00724   * @param  Addr: I2C address
00725   * @param  Reg: Register address
00726   * @param  Buffer: Pointer to data buffer
00727   * @param  Length: Length of the data
00728   * @retval None
00729   */
00730 void TS_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
00731 {
00732   I2Cx_WriteMultiple(&hI2cAudioHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
00733 }
00734 
00735 /**
00736   * @brief  Delay function used in TouchScreen low level driver.
00737   * @param  Delay: Delay in ms
00738   * @retval None
00739   */
00740 void TS_IO_Delay(uint32_t Delay)
00741 {
00742   HAL_Delay(Delay);
00743 }
00744 
00745 /**************************** LINK OTM8009A (Display driver) ******************/
00746 /**
00747   * @brief  OTM8009A delay
00748   * @param  Delay: Delay in ms
00749   */
00750 void OTM8009A_IO_Delay(uint32_t Delay)
00751 {
00752   HAL_Delay(Delay);
00753 }
00754 
00755 /**************************** LINK ADV7533 DSI-HDMI (Display driver) **********/
00756 /**
00757   * @brief  Initializes HDMI IO low level.
00758   * @retval None
00759   */
00760 void HDMI_IO_Init(void)
00761 {
00762   I2Cx_Init(&hI2cAudioHandler);
00763 }
00764 
00765 /**
00766   * @brief  HDMI writes single data.
00767   * @param  Addr: I2C address
00768   * @param  Reg: Register address 
00769   * @param  Value: Data to be written
00770   * @retval None
00771   */
00772 void HDMI_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
00773 {
00774   I2Cx_WriteMultiple(&hI2cAudioHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1);  
00775 }
00776 
00777 /**
00778   * @brief  Reads single data with I2C communication
00779   *         channel from HDMI bridge.
00780   * @param  Addr: I2C address
00781   * @param  Reg: Register address
00782   * @retval Read data
00783   */
00784 uint8_t HDMI_IO_Read(uint8_t Addr, uint8_t Reg)
00785 {
00786   uint8_t value = 0x00;
00787 
00788   I2Cx_ReadMultiple(&hI2cAudioHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &value, 1);
00789 
00790   return value;   
00791 }
00792 
00793 /**
00794   * @brief  HDMI delay 
00795   * @param  Delay: Delay in ms
00796   * @retval None
00797   */
00798 void HDMI_IO_Delay(uint32_t Delay)
00799 {
00800   HAL_Delay(Delay);
00801 }
00802 /**
00803   * @}
00804   */
00805 
00806 /**
00807   * @}
00808   */
00809 
00810 /**
00811   * @}
00812   */
00813 
00814 /**
00815   * @}
00816   */
00817 
00818 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/