stm32l4xx_hal_ltdc_ex.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_ltdc_ex.c
  4. * @author MCD Application Team
  5. * @brief LTDC Extension HAL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Includes ------------------------------------------------------------------*/
  36. #include "stm32l4xx_hal.h"
  37. /** @addtogroup STM32L4xx_HAL_Driver
  38. * @{
  39. */
  40. #if defined (STM32L4R9xx) || defined (STM32L4S9xx)
  41. /** @defgroup LTDCEx LTDCEx
  42. * @brief LTDC HAL module driver
  43. * @{
  44. */
  45. #if defined(HAL_LTDC_MODULE_ENABLED) && defined(HAL_DSI_MODULE_ENABLED)
  46. /* Private typedef -----------------------------------------------------------*/
  47. /* Private define ------------------------------------------------------------*/
  48. /* Private macro -------------------------------------------------------------*/
  49. /* Private variables ---------------------------------------------------------*/
  50. /* Private function prototypes -----------------------------------------------*/
  51. /* Exported functions --------------------------------------------------------*/
  52. /** @defgroup LTDCEx_Exported_Functions LTDC Extended Exported Functions
  53. * @{
  54. */
  55. /** @defgroup LTDCEx_Exported_Functions_Group1 Initialization and Configuration functions
  56. * @brief Initialization and Configuration functions
  57. *
  58. @verbatim
  59. ===============================================================================
  60. ##### Initialization and Configuration functions #####
  61. ===============================================================================
  62. [..] This section provides functions allowing to:
  63. (+) Initialize and configure the LTDC
  64. @endverbatim
  65. * @{
  66. */
  67. /**
  68. * @brief Retrieve common parameters from DSI Video mode configuration structure
  69. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  70. * the configuration information for the LTDC.
  71. * @param VidCfg pointer to a DSI_VidCfgTypeDef structure that contains
  72. * the DSI video mode configuration parameters
  73. * @note The implementation of this function is taking into account the LTDC
  74. * polarities inversion as described in the current LTDC specification
  75. * @retval HAL status
  76. */
  77. HAL_StatusTypeDef HAL_LTDCEx_StructInitFromVideoConfig(LTDC_HandleTypeDef* hltdc, DSI_VidCfgTypeDef *VidCfg)
  78. {
  79. /* Retrieve signal polarities from DSI */
  80. /* The following polarities are inverted:
  81. LTDC_DEPOLARITY_AL <-> LTDC_DEPOLARITY_AH
  82. LTDC_VSPOLARITY_AL <-> LTDC_VSPOLARITY_AH
  83. LTDC_HSPOLARITY_AL <-> LTDC_HSPOLARITY_AH)*/
  84. /* Note 1 : Code in line w/ Current LTDC specification */
  85. hltdc->Init.DEPolarity = (VidCfg->DEPolarity == DSI_DATA_ENABLE_ACTIVE_HIGH) ? LTDC_DEPOLARITY_AL : LTDC_DEPOLARITY_AH;
  86. hltdc->Init.VSPolarity = (VidCfg->VSPolarity == DSI_VSYNC_ACTIVE_HIGH) ? LTDC_VSPOLARITY_AL : LTDC_VSPOLARITY_AH;
  87. hltdc->Init.HSPolarity = (VidCfg->HSPolarity == DSI_HSYNC_ACTIVE_HIGH) ? LTDC_HSPOLARITY_AL : LTDC_HSPOLARITY_AH;
  88. /* Note 2: Code to be used in case LTDC polarities inversion updated in the specification */
  89. /* hltdc->Init.DEPolarity = VidCfg->DEPolarity << 29;
  90. hltdc->Init.VSPolarity = VidCfg->VSPolarity << 29;
  91. hltdc->Init.HSPolarity = VidCfg->HSPolarity << 29; */
  92. /* Retrieve vertical timing parameters from DSI */
  93. hltdc->Init.VerticalSync = VidCfg->VerticalSyncActive - 1;
  94. hltdc->Init.AccumulatedVBP = VidCfg->VerticalSyncActive + VidCfg->VerticalBackPorch - 1;
  95. hltdc->Init.AccumulatedActiveH = VidCfg->VerticalSyncActive + VidCfg->VerticalBackPorch + VidCfg->VerticalActive - 1;
  96. hltdc->Init.TotalHeigh = VidCfg->VerticalSyncActive + VidCfg->VerticalBackPorch + VidCfg->VerticalActive + VidCfg->VerticalFrontPorch - 1;
  97. return HAL_OK;
  98. }
  99. /**
  100. * @brief Retrieve common parameters from DSI Adapted command mode configuration structure
  101. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  102. * the configuration information for the LTDC.
  103. * @param CmdCfg pointer to a DSI_CmdCfgTypeDef structure that contains
  104. * the DSI command mode configuration parameters
  105. * @note The implementation of this function is taking into account the LTDC
  106. * polarities inversion as described in the current LTDC specification
  107. * @retval HAL status
  108. */
  109. HAL_StatusTypeDef HAL_LTDCEx_StructInitFromAdaptedCommandConfig(LTDC_HandleTypeDef* hltdc, DSI_CmdCfgTypeDef *CmdCfg)
  110. {
  111. /* Retrieve signal polarities from DSI */
  112. /* The following polarities are inverted:
  113. LTDC_DEPOLARITY_AL <-> LTDC_DEPOLARITY_AH
  114. LTDC_VSPOLARITY_AL <-> LTDC_VSPOLARITY_AH
  115. LTDC_HSPOLARITY_AL <-> LTDC_HSPOLARITY_AH)*/
  116. /* Note 1 : Code in line w/ Current LTDC specification */
  117. hltdc->Init.DEPolarity = (CmdCfg->DEPolarity == DSI_DATA_ENABLE_ACTIVE_HIGH) ? LTDC_DEPOLARITY_AL : LTDC_DEPOLARITY_AH;
  118. hltdc->Init.VSPolarity = (CmdCfg->VSPolarity == DSI_VSYNC_ACTIVE_HIGH) ? LTDC_VSPOLARITY_AL : LTDC_VSPOLARITY_AH;
  119. hltdc->Init.HSPolarity = (CmdCfg->HSPolarity == DSI_HSYNC_ACTIVE_HIGH) ? LTDC_HSPOLARITY_AL : LTDC_HSPOLARITY_AH;
  120. /* Note 2: Code to be used in case LTDC polarities inversion updated in the specification */
  121. /* hltdc->Init.DEPolarity = CmdCfg->DEPolarity << 29;
  122. hltdc->Init.VSPolarity = CmdCfg->VSPolarity << 29;
  123. hltdc->Init.HSPolarity = CmdCfg->HSPolarity << 29; */
  124. return HAL_OK;
  125. }
  126. /**
  127. * @}
  128. */
  129. /**
  130. * @}
  131. */
  132. #endif /* HAL_LTCD_MODULE_ENABLED && HAL_DSI_MODULE_ENABLED */
  133. /**
  134. * @}
  135. */
  136. #endif /* STM32L4R9xx || STM32L4S9xx */
  137. /**
  138. * @}
  139. */
  140. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/