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 
36 /* Includes ------------------------------------------------------------------*/
37 #include "stm32l4xx_hal.h"
38 
39 /** @addtogroup STM32L4xx_HAL_Driver
40   * @{
41   */
42 
43 #if defined (LTDC) && defined (DSI)
44 
45 /** @defgroup LTDCEx LTDCEx
46   * @brief LTDC HAL module driver
47   * @{
48   */
49 
50 #if defined(HAL_LTDC_MODULE_ENABLED) && defined(HAL_DSI_MODULE_ENABLED)
51 
52 /* Private typedef -----------------------------------------------------------*/
53 /* Private define ------------------------------------------------------------*/
54 /* Private macro -------------------------------------------------------------*/
55 /* Private variables ---------------------------------------------------------*/
56 /* Private function prototypes -----------------------------------------------*/
57 /* Exported functions --------------------------------------------------------*/
58 
59 /** @defgroup LTDCEx_Exported_Functions LTDC Extended Exported Functions
60   * @{
61   */
62 
63 /** @defgroup LTDCEx_Exported_Functions_Group1 Initialization and Configuration functions
64  *  @brief   Initialization and Configuration functions
65  *
66 @verbatim
67  ===============================================================================
68                 ##### Initialization and Configuration functions #####
69  ===============================================================================
70     [..]  This section provides functions allowing to:
71       (+) Initialize and configure the LTDC
72 
73 @endverbatim
74   * @{
75   */
76 
77 /**
78   * @brief  Retrieve common parameters from DSI Video mode configuration structure
79   * @param  hltdc   pointer to a LTDC_HandleTypeDef structure that contains
80   *                 the configuration information for the LTDC.
81   * @param  VidCfg  pointer to a DSI_VidCfgTypeDef structure that contains
82   *                 the DSI video mode configuration parameters
83   * @note   The implementation of this function is taking into account the LTDC
84   *         polarities inversion as described in the current LTDC specification
85   * @retval HAL status
86   */
HAL_LTDCEx_StructInitFromVideoConfig(LTDC_HandleTypeDef * hltdc,DSI_VidCfgTypeDef * VidCfg)87 HAL_StatusTypeDef HAL_LTDCEx_StructInitFromVideoConfig(LTDC_HandleTypeDef* hltdc, DSI_VidCfgTypeDef *VidCfg)
88 {
89   /* Retrieve signal polarities from DSI */
90 
91   /* The following polarity is inverted:
92                      LTDC_DEPOLARITY_AL <-> LTDC_DEPOLARITY_AH */
93 
94   /* Note 1 : Code in line w/ Current LTDC specification */
95   hltdc->Init.DEPolarity = (VidCfg->DEPolarity == DSI_DATA_ENABLE_ACTIVE_HIGH) ? LTDC_DEPOLARITY_AL : LTDC_DEPOLARITY_AH;
96   hltdc->Init.VSPolarity = (VidCfg->VSPolarity == DSI_VSYNC_ACTIVE_HIGH) ? LTDC_VSPOLARITY_AH : LTDC_VSPOLARITY_AL;
97   hltdc->Init.HSPolarity = (VidCfg->HSPolarity == DSI_HSYNC_ACTIVE_HIGH) ? LTDC_HSPOLARITY_AH : LTDC_HSPOLARITY_AL;
98 
99   /* Note 2: Code to be used in case LTDC polarities inversion updated in the specification */
100   /* hltdc->Init.DEPolarity = VidCfg->DEPolarity << 29;
101      hltdc->Init.VSPolarity = VidCfg->VSPolarity << 29;
102      hltdc->Init.HSPolarity = VidCfg->HSPolarity << 29; */
103 
104   /* Retrieve vertical timing parameters from DSI */
105   hltdc->Init.VerticalSync       = VidCfg->VerticalSyncActive - 1U;
106   hltdc->Init.AccumulatedVBP     = VidCfg->VerticalSyncActive + VidCfg->VerticalBackPorch - 1U;
107   hltdc->Init.AccumulatedActiveH = VidCfg->VerticalSyncActive + VidCfg->VerticalBackPorch + VidCfg->VerticalActive - 1U;
108   hltdc->Init.TotalHeigh         = VidCfg->VerticalSyncActive + VidCfg->VerticalBackPorch + VidCfg->VerticalActive + VidCfg->VerticalFrontPorch - 1U;
109 
110   return HAL_OK;
111 }
112 
113 /**
114   * @brief  Retrieve common parameters from DSI Adapted command mode configuration structure
115   * @param  hltdc   pointer to a LTDC_HandleTypeDef structure that contains
116   *                 the configuration information for the LTDC.
117   * @param  CmdCfg  pointer to a DSI_CmdCfgTypeDef structure that contains
118   *                 the DSI command mode configuration parameters
119   * @note   The implementation of this function is taking into account the LTDC
120   *         polarities inversion as described in the current LTDC specification
121   * @retval HAL status
122   */
HAL_LTDCEx_StructInitFromAdaptedCommandConfig(LTDC_HandleTypeDef * hltdc,DSI_CmdCfgTypeDef * CmdCfg)123 HAL_StatusTypeDef HAL_LTDCEx_StructInitFromAdaptedCommandConfig(LTDC_HandleTypeDef* hltdc, DSI_CmdCfgTypeDef *CmdCfg)
124 {
125   /* Retrieve signal polarities from DSI */
126 
127   /* The following polarities are inverted:
128                      LTDC_DEPOLARITY_AL <-> LTDC_DEPOLARITY_AH
129                      LTDC_VSPOLARITY_AL <-> LTDC_VSPOLARITY_AH
130                      LTDC_HSPOLARITY_AL <-> LTDC_HSPOLARITY_AH)*/
131 
132   /* Note 1 : Code in line w/ Current LTDC specification */
133   hltdc->Init.DEPolarity = (CmdCfg->DEPolarity == DSI_DATA_ENABLE_ACTIVE_HIGH) ? LTDC_DEPOLARITY_AL : LTDC_DEPOLARITY_AH;
134   hltdc->Init.VSPolarity = (CmdCfg->VSPolarity == DSI_VSYNC_ACTIVE_HIGH) ? LTDC_VSPOLARITY_AL : LTDC_VSPOLARITY_AH;
135   hltdc->Init.HSPolarity = (CmdCfg->HSPolarity == DSI_HSYNC_ACTIVE_HIGH) ? LTDC_HSPOLARITY_AL : LTDC_HSPOLARITY_AH;
136 
137   /* Note 2: Code to be used in case LTDC polarities inversion updated in the specification */
138   /* hltdc->Init.DEPolarity = CmdCfg->DEPolarity << 29;
139      hltdc->Init.VSPolarity = CmdCfg->VSPolarity << 29;
140      hltdc->Init.HSPolarity = CmdCfg->HSPolarity << 29; */
141 
142   return HAL_OK;
143 }
144 
145 /**
146   * @}
147   */
148 
149 /**
150   * @}
151   */
152 
153 #endif /* HAL_LTCD_MODULE_ENABLED && HAL_DSI_MODULE_ENABLED */
154 
155 /**
156   * @}
157   */
158 
159 #endif /* LTDC && DSI */
160 
161 /**
162   * @}
163   */
164 
165 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
166