]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil/ST_Library/stm32f7xx_hal_ltdc.c
commit 9f316c246baafa15c542a5aea81a94f26e3d6507
[freertos] / FreeRTOS / Demo / CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil / ST_Library / stm32f7xx_hal_ltdc.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32f7xx_hal_ltdc.c\r
4   * @author  MCD Application Team\r
5   * @version V1.0.0\r
6   * @date    12-May-2015\r
7   * @brief   LTDC HAL module driver.\r
8   *          This file provides firmware functions to manage the following \r
9   *          functionalities of the LTDC peripheral:\r
10   *           + Initialization and de-initialization functions\r
11   *           + IO operation functions\r
12   *           + Peripheral Control functions  \r
13   *           + Peripheral State and Errors functions\r
14   *           \r
15   @verbatim      \r
16   ==============================================================================\r
17                         ##### How to use this driver #####\r
18   ==============================================================================\r
19     [..]\r
20      (#) Program the required configuration through the following parameters:   \r
21          the LTDC timing, the horizontal and vertical polarity, \r
22          the pixel clock polarity, Data Enable polarity and the LTDC background color value \r
23          using HAL_LTDC_Init() function\r
24 \r
25      (#) Program the required configuration through the following parameters:   \r
26          the pixel format, the blending factors, input alpha value, the window size \r
27          and the image size using HAL_LTDC_ConfigLayer() function for foreground\r
28          or/and background layer.     \r
29   \r
30      (#) Optionally, configure and enable the CLUT using HAL_LTDC_ConfigCLUT() and \r
31          HAL_LTDC_EnableCLUT functions.\r
32        \r
33      (#) Optionally, enable the Dither using HAL_LTDC_EnableDither().       \r
34 \r
35      (#) Optionally, configure and enable the Color keying using HAL_LTDC_ConfigColorKeying()\r
36          and HAL_LTDC_EnableColorKeying functions.\r
37 \r
38      (#) Optionally, configure LineInterrupt using HAL_LTDC_ProgramLineEvent()\r
39          function\r
40 \r
41      (#) If needed, reconfigure and change the pixel format value, the alpha value\r
42          value, the window size, the window position and the layer start address \r
43          for foreground or/and background layer using respectively the following \r
44          functions: HAL_LTDC_SetPixelFormat(), HAL_LTDC_SetAlpha(), HAL_LTDC_SetWindowSize(),\r
45          HAL_LTDC_SetWindowPosition(), HAL_LTDC_SetAddress.\r
46                      \r
47      (#) To control LTDC state you can use the following function: HAL_LTDC_GetState()               \r
48 \r
49      *** LTDC HAL driver macros list ***\r
50      ============================================= \r
51      [..]\r
52        Below the list of most used macros in LTDC HAL driver.\r
53        \r
54       (+) __HAL_LTDC_ENABLE: Enable the LTDC.\r
55       (+) __HAL_LTDC_DISABLE: Disable the LTDC.\r
56       (+) __HAL_LTDC_LAYER_ENABLE: Enable the LTDC Layer.\r
57       (+) __HAL_LTDC_LAYER_DISABLE: Disable the LTDC Layer.\r
58       (+) __HAL_LTDC_RELOAD_CONFIG: Reload  Layer Configuration.\r
59       (+) __HAL_LTDC_GET_FLAG: Get the LTDC pending flags.\r
60       (+) __HAL_LTDC_CLEAR_FLAG: Clear the LTDC pending flags.\r
61       (+) __HAL_LTDC_ENABLE_IT: Enable the specified LTDC interrupts. \r
62       (+) __HAL_LTDC_DISABLE_IT: Disable the specified LTDC interrupts.\r
63       (+) __HAL_LTDC_GET_IT_SOURCE: Check whether the specified LTDC interrupt has occurred or not.\r
64       \r
65      [..] \r
66        (@) You can refer to the LTDC HAL driver header file for more useful macros\r
67   \r
68   @endverbatim\r
69   ******************************************************************************\r
70   * @attention\r
71   *\r
72   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>\r
73   *\r
74   * Redistribution and use in source and binary forms, with or without modification,\r
75   * are permitted provided that the following conditions are met:\r
76   *   1. Redistributions of source code must retain the above copyright notice,\r
77   *      this list of conditions and the following disclaimer.\r
78   *   2. Redistributions in binary form must reproduce the above copyright notice,\r
79   *      this list of conditions and the following disclaimer in the documentation\r
80   *      and/or other materials provided with the distribution.\r
81   *   3. Neither the name of STMicroelectronics nor the names of its contributors\r
82   *      may be used to endorse or promote products derived from this software\r
83   *      without specific prior written permission.\r
84   *\r
85   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
86   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
87   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
88   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
89   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
90   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
91   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
92   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
93   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
94   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
95   *\r
96   ******************************************************************************\r
97   */ \r
98 \r
99 /* Includes ------------------------------------------------------------------*/\r
100 #include "stm32f7xx_hal.h"\r
101 \r
102 /** @addtogroup STM32F7xx_HAL_Driver\r
103   * @{\r
104   */\r
105 #if defined(STM32F756xx) || defined(STM32F746xx)\r
106 \r
107 /** @defgroup LTDC LTDC\r
108   * @brief LTDC HAL module driver\r
109   * @{\r
110   */\r
111 \r
112 #ifdef HAL_LTDC_MODULE_ENABLED\r
113 \r
114 /* Private typedef -----------------------------------------------------------*/\r
115 /* Private define ------------------------------------------------------------*/\r
116 /* Private macro -------------------------------------------------------------*/\r
117 /* Private variables ---------------------------------------------------------*/    \r
118 /* Private function prototypes -----------------------------------------------*/\r
119 static void LTDC_SetConfig(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx);\r
120 /* Private functions ---------------------------------------------------------*/\r
121 \r
122 /** @defgroup LTDC_Exported_Functions LTDC Exported Functions\r
123   * @{\r
124   */\r
125 \r
126 /** @defgroup LTDC_Exported_Functions_Group1 Initialization and Configuration functions\r
127  *  @brief   Initialization and Configuration functions\r
128  *\r
129 @verbatim   \r
130  ===============================================================================\r
131                 ##### Initialization and Configuration functions #####\r
132  ===============================================================================  \r
133     [..]  This section provides functions allowing to:\r
134       (+) Initialize and configure the LTDC\r
135       (+) De-initialize the LTDC \r
136 \r
137 @endverbatim\r
138   * @{\r
139   */\r
140   \r
141 /**\r
142   * @brief  Initializes the LTDC according to the specified\r
143   *         parameters in the LTDC_InitTypeDef and create the associated handle.\r
144   * @param  hltdc: pointer to a LTDC_HandleTypeDef structure that contains\r
145   *                the configuration information for the LTDC.\r
146   * @retval HAL status\r
147   */\r
148 HAL_StatusTypeDef HAL_LTDC_Init(LTDC_HandleTypeDef *hltdc)\r
149 {\r
150   uint32_t tmp = 0, tmp1 = 0;\r
151 \r
152   /* Check the LTDC peripheral state */\r
153   if(hltdc == NULL)\r
154   {\r
155     return HAL_ERROR;\r
156   }\r
157 \r
158   /* Check function parameters */\r
159   assert_param(IS_LTDC_ALL_INSTANCE(hltdc->Instance));\r
160   assert_param(IS_LTDC_HSYNC(hltdc->Init.HorizontalSync));\r
161   assert_param(IS_LTDC_VSYNC(hltdc->Init.VerticalSync));\r
162   assert_param(IS_LTDC_AHBP(hltdc->Init.AccumulatedHBP));\r
163   assert_param(IS_LTDC_AVBP(hltdc->Init.AccumulatedVBP));\r
164   assert_param(IS_LTDC_AAH(hltdc->Init.AccumulatedActiveH));\r
165   assert_param(IS_LTDC_AAW(hltdc->Init.AccumulatedActiveW));\r
166   assert_param(IS_LTDC_TOTALH(hltdc->Init.TotalHeigh));\r
167   assert_param(IS_LTDC_TOTALW(hltdc->Init.TotalWidth));\r
168   assert_param(IS_LTDC_HSPOL(hltdc->Init.HSPolarity));\r
169   assert_param(IS_LTDC_VSPOL(hltdc->Init.VSPolarity));\r
170   assert_param(IS_LTDC_DEPOL(hltdc->Init.DEPolarity));\r
171   assert_param(IS_LTDC_PCPOL(hltdc->Init.PCPolarity));\r
172 \r
173   if(hltdc->State == HAL_LTDC_STATE_RESET)\r
174   {\r
175     /* Allocate lock resource and initialize it */\r
176     hltdc->Lock = HAL_UNLOCKED;\r
177     /* Init the low level hardware */\r
178     HAL_LTDC_MspInit(hltdc);\r
179   }\r
180   \r
181   /* Change LTDC peripheral state */\r
182   hltdc->State = HAL_LTDC_STATE_BUSY;\r
183 \r
184   /* Configures the HS, VS, DE and PC polarity */\r
185   hltdc->Instance->GCR &= ~(LTDC_GCR_HSPOL | LTDC_GCR_VSPOL | LTDC_GCR_DEPOL | LTDC_GCR_PCPOL);\r
186   hltdc->Instance->GCR |=  (uint32_t)(hltdc->Init.HSPolarity | hltdc->Init.VSPolarity | \\r
187   hltdc->Init.DEPolarity | hltdc->Init.PCPolarity);\r
188 \r
189   /* Sets Synchronization size */\r
190   hltdc->Instance->SSCR &= ~(LTDC_SSCR_VSH | LTDC_SSCR_HSW);\r
191   tmp = (hltdc->Init.HorizontalSync << 16);\r
192   hltdc->Instance->SSCR |= (tmp | hltdc->Init.VerticalSync);\r
193 \r
194   /* Sets Accumulated Back porch */\r
195   hltdc->Instance->BPCR &= ~(LTDC_BPCR_AVBP | LTDC_BPCR_AHBP);\r
196   tmp = (hltdc->Init.AccumulatedHBP << 16);\r
197   hltdc->Instance->BPCR |= (tmp | hltdc->Init.AccumulatedVBP);\r
198 \r
199   /* Sets Accumulated Active Width */\r
200   hltdc->Instance->AWCR &= ~(LTDC_AWCR_AAH | LTDC_AWCR_AAW);\r
201   tmp = (hltdc->Init.AccumulatedActiveW << 16);\r
202   hltdc->Instance->AWCR |= (tmp | hltdc->Init.AccumulatedActiveH);\r
203 \r
204   /* Sets Total Width */\r
205   hltdc->Instance->TWCR &= ~(LTDC_TWCR_TOTALH | LTDC_TWCR_TOTALW);\r
206   tmp = (hltdc->Init.TotalWidth << 16);\r
207   hltdc->Instance->TWCR |= (tmp | hltdc->Init.TotalHeigh);\r
208 \r
209   /* Sets the background color value */\r
210   tmp = ((uint32_t)(hltdc->Init.Backcolor.Green) << 8);\r
211   tmp1 = ((uint32_t)(hltdc->Init.Backcolor.Red) << 16);\r
212   hltdc->Instance->BCCR &= ~(LTDC_BCCR_BCBLUE | LTDC_BCCR_BCGREEN | LTDC_BCCR_BCRED);\r
213   hltdc->Instance->BCCR |= (tmp1 | tmp | hltdc->Init.Backcolor.Blue);\r
214 \r
215   /* Enable the transfer Error interrupt */\r
216   __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_TE);\r
217 \r
218   /* Enable the FIFO underrun interrupt */\r
219   __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_FU);\r
220 \r
221   /* Enable LTDC by setting LTDCEN bit */\r
222   __HAL_LTDC_ENABLE(hltdc);\r
223 \r
224   /* Initialize the error code */\r
225   hltdc->ErrorCode = HAL_LTDC_ERROR_NONE;  \r
226 \r
227   /* Initialize the LTDC state*/\r
228   hltdc->State = HAL_LTDC_STATE_READY;\r
229 \r
230   return HAL_OK;\r
231 }\r
232 \r
233 /**\r
234   * @brief  Deinitializes the LTDC peripheral registers to their default reset\r
235   *         values.\r
236   * @param  hltdc: pointer to a LTDC_HandleTypeDef structure that contains\r
237   *                the configuration information for the LTDC.\r
238   * @retval None\r
239   */\r
240 \r
241 HAL_StatusTypeDef HAL_LTDC_DeInit(LTDC_HandleTypeDef *hltdc)\r
242 {\r
243   /* DeInit the low level hardware */\r
244   HAL_LTDC_MspDeInit(hltdc); \r
245 \r
246   /* Initialize the error code */\r
247   hltdc->ErrorCode = HAL_LTDC_ERROR_NONE;\r
248 \r
249   /* Initialize the LTDC state*/\r
250   hltdc->State = HAL_LTDC_STATE_RESET;\r
251 \r
252   /* Release Lock */\r
253   __HAL_UNLOCK(hltdc);\r
254 \r
255   return HAL_OK;\r
256 }\r
257 \r
258 /**\r
259   * @brief  Initializes the LTDC MSP.\r
260   * @param  hltdc : pointer to a LTDC_HandleTypeDef structure that contains\r
261   *                the configuration information for the LTDC.\r
262   * @retval None\r
263   */\r
264 __weak void HAL_LTDC_MspInit(LTDC_HandleTypeDef* hltdc)\r
265 {\r
266   /* NOTE : This function Should not be modified, when the callback is needed,\r
267             the HAL_LTDC_MspInit could be implemented in the user file\r
268    */ \r
269 }\r
270 \r
271 /**\r
272   * @brief  DeInitializes the LTDC MSP.\r
273   * @param  hltdc : pointer to a LTDC_HandleTypeDef structure that contains\r
274   *                the configuration information for the LTDC.\r
275   * @retval None\r
276   */\r
277 __weak void HAL_LTDC_MspDeInit(LTDC_HandleTypeDef* hltdc)\r
278 {\r
279   /* NOTE : This function Should not be modified, when the callback is needed,\r
280             the HAL_LTDC_MspDeInit could be implemented in the user file\r
281    */\r
282 }\r
283 \r
284 /**\r
285   * @}\r
286   */\r
287   \r
288 /** @defgroup LTDC_Exported_Functions_Group2 IO operation functions \r
289  *  @brief   IO operation functions  \r
290  *\r
291 @verbatim\r
292  ===============================================================================\r
293                       #####  IO operation functions  #####\r
294  ===============================================================================  \r
295     [..]  This section provides function allowing to:\r
296       (+) Handle LTDC interrupt request\r
297 \r
298 @endverbatim\r
299   * @{\r
300   */\r
301 /**\r
302   * @brief  Handles LTDC interrupt request.\r
303   * @param  hltdc: pointer to a LTDC_HandleTypeDef structure that contains\r
304   *                the configuration information for the LTDC.  \r
305   * @retval HAL status\r
306   */\r
307 void HAL_LTDC_IRQHandler(LTDC_HandleTypeDef *hltdc)\r
308 {\r
309   /* Transfer Error Interrupt management ***************************************/\r
310   if(__HAL_LTDC_GET_FLAG(hltdc, LTDC_FLAG_TE) != RESET)\r
311   {\r
312     if(__HAL_LTDC_GET_IT_SOURCE(hltdc, LTDC_IT_TE) != RESET)\r
313     {\r
314       /* Disable the transfer Error interrupt */\r
315       __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_TE);\r
316 \r
317       /* Clear the transfer error flag */\r
318       __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_TE);\r
319 \r
320       /* Update error code */\r
321       hltdc->ErrorCode |= HAL_LTDC_ERROR_TE;\r
322 \r
323       /* Change LTDC state */\r
324       hltdc->State = HAL_LTDC_STATE_ERROR;\r
325 \r
326       /* Process unlocked */\r
327       __HAL_UNLOCK(hltdc);\r
328 \r
329       /* Transfer error Callback */\r
330       HAL_LTDC_ErrorCallback(hltdc);\r
331     }\r
332   }\r
333   /* FIFO underrun Interrupt management ***************************************/\r
334   if(__HAL_LTDC_GET_FLAG(hltdc, LTDC_FLAG_FU) != RESET)\r
335   {\r
336     if(__HAL_LTDC_GET_IT_SOURCE(hltdc, LTDC_IT_FU) != RESET)\r
337     {\r
338       /* Disable the FIFO underrun interrupt */\r
339       __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_FU);\r
340 \r
341       /* Clear the FIFO underrun flag */\r
342       __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_FU);\r
343 \r
344       /* Update error code */\r
345       hltdc->ErrorCode |= HAL_LTDC_ERROR_FU;\r
346 \r
347       /* Change LTDC state */\r
348       hltdc->State = HAL_LTDC_STATE_ERROR;\r
349 \r
350       /* Process unlocked */\r
351       __HAL_UNLOCK(hltdc);\r
352       \r
353       /* Transfer error Callback */\r
354       HAL_LTDC_ErrorCallback(hltdc);\r
355     }\r
356   }\r
357   /* Line Interrupt management ************************************************/\r
358   if(__HAL_LTDC_GET_FLAG(hltdc, LTDC_FLAG_LI) != RESET)\r
359   {\r
360     if(__HAL_LTDC_GET_IT_SOURCE(hltdc, LTDC_IT_LI) != RESET)\r
361     {\r
362       /* Disable the Line interrupt */\r
363       __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_LI);\r
364 \r
365       /* Clear the Line interrupt flag */  \r
366       __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_LI);\r
367 \r
368       /* Change LTDC state */\r
369       hltdc->State = HAL_LTDC_STATE_READY;\r
370 \r
371       /* Process unlocked */\r
372       __HAL_UNLOCK(hltdc);\r
373 \r
374       /* Line interrupt Callback */\r
375       HAL_LTDC_LineEvenCallback(hltdc);\r
376     }\r
377   }\r
378 }\r
379 \r
380 /**\r
381   * @brief  Error LTDC callback.\r
382   * @param  hltdc: pointer to a LTDC_HandleTypeDef structure that contains\r
383   *                the configuration information for the LTDC.\r
384   * @retval None\r
385   */\r
386 __weak void HAL_LTDC_ErrorCallback(LTDC_HandleTypeDef *hltdc)\r
387 {\r
388   /* NOTE : This function Should not be modified, when the callback is needed,\r
389             the HAL_LTDC_ErrorCallback could be implemented in the user file\r
390    */\r
391 }\r
392 \r
393 /**\r
394   * @brief  Line Event callback.\r
395   * @param  hltdc: pointer to a LTDC_HandleTypeDef structure that contains\r
396   *                the configuration information for the LTDC.\r
397   * @retval None\r
398   */\r
399 __weak void HAL_LTDC_LineEvenCallback(LTDC_HandleTypeDef *hltdc)\r
400 {\r
401   /* NOTE : This function Should not be modified, when the callback is needed,\r
402             the HAL_LTDC_LineEvenCallback could be implemented in the user file\r
403    */\r
404 }\r
405 \r
406 /**\r
407   * @}\r
408   */\r
409 \r
410 /** @defgroup LTDC_Exported_Functions_Group3 Peripheral Control functions\r
411  *  @brief    Peripheral Control functions \r
412  *\r
413 @verbatim   \r
414  ===============================================================================\r
415                     ##### Peripheral Control functions #####\r
416  ===============================================================================  \r
417     [..]  This section provides functions allowing to:\r
418       (+) Configure the LTDC foreground or/and background parameters.\r
419       (+) Set the active layer.\r
420       (+) Configure the color keying.\r
421       (+) Configure the C-LUT.\r
422       (+) Enable / Disable the color keying.\r
423       (+) Enable / Disable the C-LUT.\r
424       (+) Update the layer position.\r
425       (+) Update the layer size.\r
426       (+) Update pixel format on the fly. \r
427       (+) Update transparency on the fly.\r
428       (+) Update address on the fly.\r
429 \r
430 @endverbatim\r
431   * @{\r
432   */\r
433 \r
434 /**\r
435   * @brief  Configure the LTDC Layer according to the specified\r
436   *         parameters in the LTDC_InitTypeDef and create the associated handle.\r
437   * @param  hltdc:     pointer to a LTDC_HandleTypeDef structure that contains\r
438   *                    the configuration information for the LTDC.\r
439   * @param  pLayerCfg: pointer to a LTDC_LayerCfgTypeDef structure that contains\r
440   *                    the configuration information for the Layer.\r
441   * @param  LayerIdx:  LTDC Layer index.\r
442   *                    This parameter can be one of the following values:\r
443   *                    0 or 1\r
444   * @retval HAL status\r
445   */\r
446 HAL_StatusTypeDef HAL_LTDC_ConfigLayer(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)\r
447 {   \r
448   /* Process locked */\r
449   __HAL_LOCK(hltdc);\r
450   \r
451   /* Change LTDC peripheral state */\r
452   hltdc->State = HAL_LTDC_STATE_BUSY;\r
453 \r
454   /* Check the parameters */\r
455   assert_param(IS_LTDC_LAYER(LayerIdx));\r
456   assert_param(IS_LTDC_PIXEL_FORMAT(pLayerCfg->PixelFormat));\r
457   assert_param(IS_LTDC_BLENDING_FACTOR1(pLayerCfg->BlendingFactor1));\r
458   assert_param(IS_LTDC_BLENDING_FACTOR2(pLayerCfg->BlendingFactor2));\r
459   assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));\r
460   assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));\r
461   assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));\r
462   assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));\r
463   assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha0));\r
464   assert_param(IS_LTDC_CFBLL(pLayerCfg->ImageWidth));\r
465   assert_param(IS_LTDC_CFBLNBR(pLayerCfg->ImageHeight));\r
466 \r
467   /* Copy new layer configuration into handle structure */\r
468   hltdc->LayerCfg[LayerIdx] = *pLayerCfg;  \r
469 \r
470   /* Configure the LTDC Layer */  \r
471   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);\r
472 \r
473   /* Sets the Reload type */\r
474   hltdc->Instance->SRCR = LTDC_SRCR_IMR;\r
475 \r
476   /* Initialize the LTDC state*/\r
477   hltdc->State  = HAL_LTDC_STATE_READY;\r
478 \r
479   /* Process unlocked */\r
480   __HAL_UNLOCK(hltdc);\r
481 \r
482   return HAL_OK;\r
483 }\r
484 \r
485 /**\r
486   * @brief  Configure the color keying.\r
487   * @param  hltdc:    pointer to a LTDC_HandleTypeDef structure that contains\r
488   *                   the configuration information for the LTDC.\r
489   * @param  RGBValue: the color key value\r
490   * @param  LayerIdx:  LTDC Layer index.\r
491   *                   This parameter can be one of the following values:\r
492   *                   0 or 1\r
493   * @retval HAL status\r
494   */\r
495 HAL_StatusTypeDef HAL_LTDC_ConfigColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t RGBValue, uint32_t LayerIdx)\r
496 {\r
497   /* Process locked */\r
498   __HAL_LOCK(hltdc);\r
499 \r
500   /* Change LTDC peripheral state */\r
501   hltdc->State = HAL_LTDC_STATE_BUSY;\r
502 \r
503   /* Check the parameters */\r
504   assert_param(IS_LTDC_LAYER(LayerIdx));\r
505 \r
506   /* Configures the default color values */\r
507   LTDC_LAYER(hltdc, LayerIdx)->CKCR &=  ~(LTDC_LxCKCR_CKBLUE | LTDC_LxCKCR_CKGREEN | LTDC_LxCKCR_CKRED);\r
508   LTDC_LAYER(hltdc, LayerIdx)->CKCR  = RGBValue;\r
509 \r
510   /* Sets the Reload type */\r
511   hltdc->Instance->SRCR = LTDC_SRCR_IMR;\r
512 \r
513   /* Change the LTDC state*/\r
514   hltdc->State = HAL_LTDC_STATE_READY;\r
515 \r
516   /* Process unlocked */\r
517   __HAL_UNLOCK(hltdc);\r
518 \r
519   return HAL_OK;\r
520 }\r
521 \r
522 /**\r
523   * @brief  Load the color lookup table.\r
524   * @param  hltdc:    pointer to a LTDC_HandleTypeDef structure that contains\r
525   *                   the configuration information for the LTDC.\r
526   * @param  pCLUT:    pointer to the color lookup table address.\r
527   * @param  CLUTSize: the color lookup table size.  \r
528   * @param  LayerIdx:  LTDC Layer index.\r
529   *                   This parameter can be one of the following values:\r
530   *                   0 or 1\r
531   * @retval HAL status\r
532   */\r
533 HAL_StatusTypeDef HAL_LTDC_ConfigCLUT(LTDC_HandleTypeDef *hltdc, uint32_t *pCLUT, uint32_t CLUTSize, uint32_t LayerIdx)\r
534 {\r
535   uint32_t tmp = 0;\r
536   uint32_t counter = 0;\r
537   uint32_t pcounter = 0;\r
538 \r
539   /* Process locked */\r
540   __HAL_LOCK(hltdc);\r
541 \r
542   /* Change LTDC peripheral state */\r
543   hltdc->State = HAL_LTDC_STATE_BUSY;  \r
544 \r
545   /* Check the parameters */\r
546   assert_param(IS_LTDC_LAYER(LayerIdx)); \r
547 \r
548   for(counter = 0; (counter < CLUTSize); counter++)\r
549   {\r
550     if(hltdc->LayerCfg[LayerIdx].PixelFormat == LTDC_PIXEL_FORMAT_AL44)\r
551     {\r
552       tmp  = (((counter + 16*counter) << 24) | ((uint32_t)(*pCLUT) & 0xFF) | ((uint32_t)(*pCLUT) & 0xFF00) | ((uint32_t)(*pCLUT) & 0xFF0000));\r
553     }\r
554     else\r
555     { \r
556       tmp  = ((counter << 24) | ((uint32_t)(*pCLUT) & 0xFF) | ((uint32_t)(*pCLUT) & 0xFF00) | ((uint32_t)(*pCLUT) & 0xFF0000));\r
557     }\r
558     pcounter = (uint32_t)pCLUT + sizeof(*pCLUT);\r
559     pCLUT = (uint32_t *)pcounter;\r
560 \r
561     /* Specifies the C-LUT address and RGB value */\r
562     LTDC_LAYER(hltdc, LayerIdx)->CLUTWR  = tmp;\r
563   }\r
564   \r
565   /* Change the LTDC state*/\r
566   hltdc->State = HAL_LTDC_STATE_READY; \r
567 \r
568   /* Process unlocked */\r
569   __HAL_UNLOCK(hltdc);  \r
570 \r
571   return HAL_OK;\r
572 }\r
573 \r
574 /**\r
575   * @brief  Enable the color keying.\r
576   * @param  hltdc:    pointer to a LTDC_HandleTypeDef structure that contains\r
577   *                   the configuration information for the LTDC.\r
578   * @param  LayerIdx:  LTDC Layer index.\r
579   *                   This parameter can be one of the following values:\r
580   *                   0 or 1\r
581   * @retval  HAL status\r
582   */\r
583 HAL_StatusTypeDef HAL_LTDC_EnableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)\r
584 {  \r
585   /* Process locked */\r
586   __HAL_LOCK(hltdc);\r
587 \r
588   /* Change LTDC peripheral state */\r
589   hltdc->State = HAL_LTDC_STATE_BUSY;\r
590 \r
591   /* Check the parameters */\r
592   assert_param(IS_LTDC_LAYER(LayerIdx));\r
593 \r
594   /* Enable LTDC color keying by setting COLKEN bit */\r
595   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_COLKEN;\r
596 \r
597   /* Sets the Reload type */\r
598   hltdc->Instance->SRCR = LTDC_SRCR_IMR;\r
599 \r
600   /* Change the LTDC state*/\r
601   hltdc->State = HAL_LTDC_STATE_READY; \r
602 \r
603   /* Process unlocked */\r
604   __HAL_UNLOCK(hltdc);\r
605 \r
606   return HAL_OK;  \r
607 }\r
608   \r
609 /**\r
610   * @brief  Disable the color keying.\r
611   * @param  hltdc:    pointer to a LTDC_HandleTypeDef structure that contains\r
612   *                   the configuration information for the LTDC.\r
613   * @param  LayerIdx:  LTDC Layer index.\r
614   *                   This parameter can be one of the following values:\r
615   *                   0 or 1\r
616   * @retval  HAL status\r
617   */\r
618 HAL_StatusTypeDef HAL_LTDC_DisableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)\r
619 {\r
620   /* Process locked */\r
621   __HAL_LOCK(hltdc);\r
622 \r
623   /* Change LTDC peripheral state */\r
624   hltdc->State = HAL_LTDC_STATE_BUSY;\r
625 \r
626   /* Check the parameters */\r
627   assert_param(IS_LTDC_LAYER(LayerIdx));\r
628 \r
629   /* Disable LTDC color keying by setting COLKEN bit */\r
630   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_COLKEN;\r
631 \r
632   /* Sets the Reload type */\r
633   hltdc->Instance->SRCR = LTDC_SRCR_IMR;\r
634 \r
635   /* Change the LTDC state*/\r
636   hltdc->State = HAL_LTDC_STATE_READY; \r
637 \r
638   /* Process unlocked */\r
639   __HAL_UNLOCK(hltdc);\r
640 \r
641   return HAL_OK;\r
642 }\r
643 \r
644 /**\r
645   * @brief  Enable the color lookup table.\r
646   * @param  hltdc:    pointer to a LTDC_HandleTypeDef structure that contains\r
647   *                   the configuration information for the LTDC.\r
648   * @param  LayerIdx:  LTDC Layer index.\r
649   *                   This parameter can be one of the following values:\r
650   *                   0 or 1\r
651   * @retval  HAL status\r
652   */\r
653 HAL_StatusTypeDef HAL_LTDC_EnableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)\r
654 {\r
655 \r
656   /* Process locked */\r
657   __HAL_LOCK(hltdc);\r
658 \r
659   /* Change LTDC peripheral state */\r
660   hltdc->State = HAL_LTDC_STATE_BUSY;\r
661 \r
662   /* Check the parameters */\r
663   assert_param(IS_LTDC_LAYER(LayerIdx));\r
664 \r
665   /* Disable LTDC color lookup table by setting CLUTEN bit */\r
666   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_CLUTEN;\r
667 \r
668   /* Sets the Reload type */\r
669   hltdc->Instance->SRCR = LTDC_SRCR_IMR;\r
670 \r
671   /* Change the LTDC state*/\r
672   hltdc->State = HAL_LTDC_STATE_READY; \r
673 \r
674   /* Process unlocked */\r
675   __HAL_UNLOCK(hltdc);\r
676 \r
677   return HAL_OK;\r
678 }\r
679 \r
680 /**\r
681   * @brief  Disable the color lookup table.\r
682   * @param  hltdc:    pointer to a LTDC_HandleTypeDef structure that contains\r
683   *                   the configuration information for the LTDC.\r
684   * @param  LayerIdx:  LTDC Layer index.\r
685   *                   This parameter can be one of the following values:\r
686   *                   0 or 1   \r
687   * @retval  HAL status\r
688   */\r
689 HAL_StatusTypeDef HAL_LTDC_DisableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)\r
690 {\r
691  \r
692   /* Process locked */\r
693   __HAL_LOCK(hltdc);\r
694 \r
695   /* Change LTDC peripheral state */\r
696   hltdc->State = HAL_LTDC_STATE_BUSY;\r
697 \r
698   /* Check the parameters */\r
699   assert_param(IS_LTDC_LAYER(LayerIdx));\r
700 \r
701   /* Disable LTDC color lookup table by setting CLUTEN bit */\r
702   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_CLUTEN;\r
703 \r
704   /* Sets the Reload type */\r
705   hltdc->Instance->SRCR = LTDC_SRCR_IMR;\r
706 \r
707   /* Change the LTDC state*/\r
708   hltdc->State = HAL_LTDC_STATE_READY; \r
709 \r
710   /* Process unlocked */\r
711   __HAL_UNLOCK(hltdc);\r
712 \r
713   return HAL_OK;\r
714 }\r
715 \r
716 /**\r
717   * @brief  Enables Dither.\r
718   * @param  hltdc: pointer to a LTDC_HandleTypeDef structure that contains\r
719   *                the configuration information for the LTDC.\r
720   * @retval  HAL status\r
721   */\r
722 \r
723 HAL_StatusTypeDef HAL_LTDC_EnableDither(LTDC_HandleTypeDef *hltdc)\r
724 {\r
725   /* Process locked */\r
726   __HAL_LOCK(hltdc);\r
727 \r
728   /* Change LTDC peripheral state */\r
729   hltdc->State = HAL_LTDC_STATE_BUSY;\r
730 \r
731   /* Enable Dither by setting DTEN bit */\r
732   LTDC->GCR |= (uint32_t)LTDC_GCR_DTEN;\r
733 \r
734   /* Change the LTDC state*/\r
735   hltdc->State = HAL_LTDC_STATE_READY; \r
736 \r
737   /* Process unlocked */\r
738   __HAL_UNLOCK(hltdc);\r
739 \r
740   return HAL_OK;\r
741 }\r
742 \r
743 /**\r
744   * @brief  Disables Dither.\r
745   * @param  hltdc: pointer to a LTDC_HandleTypeDef structure that contains\r
746   *                the configuration information for the LTDC.\r
747   * @retval  HAL status\r
748   */\r
749 \r
750 HAL_StatusTypeDef HAL_LTDC_DisableDither(LTDC_HandleTypeDef *hltdc)\r
751 {\r
752   /* Process locked */\r
753   __HAL_LOCK(hltdc);\r
754 \r
755   /* Change LTDC peripheral state */\r
756   hltdc->State = HAL_LTDC_STATE_BUSY;\r
757 \r
758   /* Disable Dither by setting DTEN bit */\r
759   LTDC->GCR &= ~(uint32_t)LTDC_GCR_DTEN;\r
760 \r
761   /* Change the LTDC state*/\r
762   hltdc->State = HAL_LTDC_STATE_READY;\r
763 \r
764   /* Process unlocked */\r
765   __HAL_UNLOCK(hltdc);\r
766 \r
767   return HAL_OK;\r
768 }\r
769 \r
770 /**\r
771   * @brief  Set the LTDC window size.\r
772   * @param  hltdc:    pointer to a LTDC_HandleTypeDef structure that contains\r
773   *                   the configuration information for the LTDC.\r
774   * @param  XSize:    LTDC Pixel per line\r
775   * @param  YSize:    LTDC Line number\r
776   * @param  LayerIdx:  LTDC Layer index.\r
777   *                   This parameter can be one of the following values:\r
778   *                   0 or 1\r
779   * @retval  HAL status\r
780   */\r
781 HAL_StatusTypeDef HAL_LTDC_SetWindowSize(LTDC_HandleTypeDef *hltdc, uint32_t XSize, uint32_t YSize, uint32_t LayerIdx) \r
782 {\r
783   LTDC_LayerCfgTypeDef *pLayerCfg;\r
784 \r
785   /* Process locked */\r
786   __HAL_LOCK(hltdc);\r
787 \r
788   /* Change LTDC peripheral state */\r
789   hltdc->State = HAL_LTDC_STATE_BUSY; \r
790 \r
791   /* Get layer configuration from handle structure */\r
792   pLayerCfg = &hltdc->LayerCfg[LayerIdx];\r
793 \r
794   /* Check the parameters (Layers parameters)*/\r
795   assert_param(IS_LTDC_LAYER(LayerIdx));\r
796   assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));\r
797   assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));\r
798   assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));\r
799   assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));\r
800   assert_param(IS_LTDC_CFBLL(XSize));\r
801   assert_param(IS_LTDC_CFBLNBR(YSize));\r
802 \r
803   /* update horizontal start/stop */\r
804   pLayerCfg->WindowX0 = 0;\r
805   pLayerCfg->WindowX1 = XSize + pLayerCfg->WindowX0;\r
806 \r
807   /* update vertical start/stop */  \r
808   pLayerCfg->WindowY0 = 0;\r
809   pLayerCfg->WindowY1 = YSize + pLayerCfg->WindowY0;\r
810 \r
811   /* Reconfigures the color frame buffer pitch in byte */\r
812   pLayerCfg->ImageWidth = XSize;\r
813 \r
814   /* Reconfigures the frame buffer line number */\r
815   pLayerCfg->ImageHeight = YSize;\r
816 \r
817   /* Set LTDC parameters */\r
818   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);\r
819 \r
820   /* Sets the Reload type */\r
821   hltdc->Instance->SRCR = LTDC_SRCR_IMR;\r
822 \r
823   /* Change the LTDC state*/\r
824   hltdc->State = HAL_LTDC_STATE_READY;\r
825 \r
826   /* Process unlocked */\r
827   __HAL_UNLOCK(hltdc);\r
828 \r
829   return HAL_OK;\r
830 }\r
831 \r
832 /**\r
833   * @brief  Set the LTDC window position.\r
834   * @param  hltdc:    pointer to a LTDC_HandleTypeDef structure that contains\r
835   *                   the configuration information for the LTDC.\r
836   * @param  X0:       LTDC window X offset\r
837   * @param  Y0:       LTDC window Y offset\r
838   * @param  LayerIdx:  LTDC Layer index.\r
839   *                         This parameter can be one of the following values:\r
840   *                         0 or 1\r
841   * @retval  HAL status\r
842   */\r
843 HAL_StatusTypeDef HAL_LTDC_SetWindowPosition(LTDC_HandleTypeDef *hltdc, uint32_t X0, uint32_t Y0, uint32_t LayerIdx)\r
844 {\r
845   LTDC_LayerCfgTypeDef *pLayerCfg;\r
846   \r
847   /* Process locked */\r
848   __HAL_LOCK(hltdc);\r
849 \r
850   /* Change LTDC peripheral state */\r
851   hltdc->State = HAL_LTDC_STATE_BUSY;\r
852 \r
853   /* Get layer configuration from handle structure */\r
854   pLayerCfg = &hltdc->LayerCfg[LayerIdx];\r
855 \r
856   /* Check the parameters */\r
857   assert_param(IS_LTDC_LAYER(LayerIdx));\r
858   assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));\r
859   assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));\r
860   assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));\r
861   assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));\r
862 \r
863   /* update horizontal start/stop */\r
864   pLayerCfg->WindowX0 = X0;\r
865   pLayerCfg->WindowX1 = X0 + pLayerCfg->ImageWidth;\r
866 \r
867   /* update vertical start/stop */\r
868   pLayerCfg->WindowY0 = Y0;\r
869   pLayerCfg->WindowY1 = Y0 + pLayerCfg->ImageHeight;\r
870 \r
871   /* Set LTDC parameters */\r
872   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);\r
873 \r
874   /* Sets the Reload type */\r
875   hltdc->Instance->SRCR = LTDC_SRCR_IMR;\r
876 \r
877   /* Change the LTDC state*/\r
878   hltdc->State = HAL_LTDC_STATE_READY;\r
879 \r
880   /* Process unlocked */\r
881   __HAL_UNLOCK(hltdc);\r
882 \r
883   return HAL_OK;\r
884 }\r
885 \r
886 /**\r
887   * @brief  Reconfigure the pixel format.\r
888   * @param  hltdc:       pointer to a LTDC_HandleTypeDef structure that contains\r
889   *                      the configuration information for the LTDC.\r
890   * @param  Pixelformat: new pixel format value.\r
891   * @param  LayerIdx:    LTDC Layer index.\r
892   *                      This parameter can be one of the following values:\r
893   *                      0 or 1.\r
894   * @retval  HAL status\r
895   */\r
896 HAL_StatusTypeDef HAL_LTDC_SetPixelFormat(LTDC_HandleTypeDef *hltdc, uint32_t Pixelformat, uint32_t LayerIdx)\r
897 {\r
898   LTDC_LayerCfgTypeDef *pLayerCfg;\r
899 \r
900   /* Process locked */\r
901   __HAL_LOCK(hltdc);\r
902 \r
903   /* Change LTDC peripheral state */\r
904   hltdc->State = HAL_LTDC_STATE_BUSY;\r
905 \r
906   /* Check the parameters */\r
907   assert_param(IS_LTDC_LAYER(LayerIdx));\r
908   assert_param(IS_LTDC_PIXEL_FORMAT(Pixelformat));\r
909 \r
910   /* Get layer configuration from handle structure */\r
911   pLayerCfg = &hltdc->LayerCfg[LayerIdx];  \r
912 \r
913   /* Reconfigure the pixel format */\r
914   pLayerCfg->PixelFormat = Pixelformat;\r
915 \r
916   /* Set LTDC parameters */\r
917   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);   \r
918 \r
919   /* Sets the Reload type */\r
920   hltdc->Instance->SRCR = LTDC_SRCR_IMR;\r
921 \r
922   /* Change the LTDC state*/\r
923   hltdc->State = HAL_LTDC_STATE_READY;\r
924 \r
925   /* Process unlocked */\r
926   __HAL_UNLOCK(hltdc);\r
927 \r
928   return HAL_OK;\r
929 }\r
930 \r
931 /**\r
932   * @brief  Reconfigure the layer alpha value.\r
933   * @param  hltdc:    pointer to a LTDC_HandleTypeDef structure that contains\r
934   *                   the configuration information for the LTDC.\r
935   * @param  Alpha:    new alpha value.\r
936   * @param  LayerIdx:  LTDC Layer index.\r
937   *                   This parameter can be one of the following values:\r
938   *                   0 or 1\r
939   * @retval  HAL status\r
940   */\r
941 HAL_StatusTypeDef HAL_LTDC_SetAlpha(LTDC_HandleTypeDef *hltdc, uint32_t Alpha, uint32_t LayerIdx)\r
942 {\r
943   LTDC_LayerCfgTypeDef *pLayerCfg;\r
944 \r
945   /* Process locked */\r
946   __HAL_LOCK(hltdc);\r
947 \r
948   /* Change LTDC peripheral state */\r
949   hltdc->State = HAL_LTDC_STATE_BUSY;\r
950 \r
951   /* Check the parameters */\r
952   assert_param(IS_LTDC_ALPHA(Alpha));\r
953   assert_param(IS_LTDC_LAYER(LayerIdx));\r
954 \r
955   /* Get layer configuration from handle structure */\r
956   pLayerCfg = &hltdc->LayerCfg[LayerIdx];\r
957 \r
958   /* Reconfigure the Alpha value */\r
959   pLayerCfg->Alpha = Alpha;\r
960 \r
961   /* Set LTDC parameters */\r
962   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);\r
963 \r
964   /* Sets the Reload type */\r
965   hltdc->Instance->SRCR = LTDC_SRCR_IMR;\r
966 \r
967   /* Change the LTDC state*/\r
968   hltdc->State = HAL_LTDC_STATE_READY;\r
969 \r
970   /* Process unlocked */\r
971   __HAL_UNLOCK(hltdc);\r
972 \r
973   return HAL_OK;\r
974 }\r
975 /**\r
976   * @brief  Reconfigure the frame buffer Address.\r
977   * @param  hltdc:    pointer to a LTDC_HandleTypeDef structure that contains\r
978   *                   the configuration information for the LTDC.\r
979   * @param  Address:  new address value.\r
980   * @param  LayerIdx: LTDC Layer index.\r
981   *                   This parameter can be one of the following values:\r
982   *                   0 or 1.\r
983   * @retval  HAL status\r
984   */\r
985 HAL_StatusTypeDef HAL_LTDC_SetAddress(LTDC_HandleTypeDef *hltdc, uint32_t Address, uint32_t LayerIdx)\r
986 {\r
987   LTDC_LayerCfgTypeDef *pLayerCfg;\r
988 \r
989   /* Process locked */\r
990   __HAL_LOCK(hltdc);\r
991 \r
992   /* Change LTDC peripheral state */\r
993   hltdc->State = HAL_LTDC_STATE_BUSY;\r
994 \r
995   /* Check the parameters */\r
996   assert_param(IS_LTDC_LAYER(LayerIdx));\r
997 \r
998   /* Get layer configuration from handle structure */\r
999   pLayerCfg = &hltdc->LayerCfg[LayerIdx];\r
1000 \r
1001   /* Reconfigure the Address */\r
1002   pLayerCfg->FBStartAdress = Address;\r
1003 \r
1004   /* Set LTDC parameters */\r
1005   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);\r
1006 \r
1007   /* Sets the Reload type */\r
1008   hltdc->Instance->SRCR = LTDC_SRCR_IMR;\r
1009 \r
1010   /* Change the LTDC state*/\r
1011   hltdc->State = HAL_LTDC_STATE_READY;\r
1012 \r
1013   /* Process unlocked */\r
1014   __HAL_UNLOCK(hltdc);\r
1015 \r
1016   return HAL_OK;\r
1017 }\r
1018 \r
1019 /**\r
1020   * @brief  Define the position of the line interrupt .\r
1021   * @param  hltdc:             pointer to a LTDC_HandleTypeDef structure that contains\r
1022   *                            the configuration information for the LTDC.\r
1023   * @param  Line:   Line Interrupt Position.\r
1024   * @retval  HAL status\r
1025   */\r
1026 HAL_StatusTypeDef HAL_LTDC_ProgramLineEvent(LTDC_HandleTypeDef *hltdc, uint32_t Line)\r
1027 {\r
1028   /* Process locked */\r
1029   __HAL_LOCK(hltdc);\r
1030 \r
1031   /* Change LTDC peripheral state */\r
1032   hltdc->State = HAL_LTDC_STATE_BUSY;\r
1033 \r
1034   /* Check the parameters */\r
1035   assert_param(IS_LTDC_LIPOS(Line));\r
1036 \r
1037   /* Enable the Line interrupt */\r
1038   __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_LI);\r
1039 \r
1040   /* Sets the Line Interrupt position */\r
1041   LTDC->LIPCR = (uint32_t)Line;\r
1042 \r
1043   /* Change the LTDC state*/\r
1044   hltdc->State = HAL_LTDC_STATE_READY;\r
1045 \r
1046   /* Process unlocked */\r
1047   __HAL_UNLOCK(hltdc);\r
1048 \r
1049   return HAL_OK;\r
1050 }\r
1051 \r
1052 /**\r
1053   * @}\r
1054   */\r
1055 \r
1056 /** @defgroup LTDC_Exported_Functions_Group4 Peripheral State and Errors functions\r
1057  *  @brief    Peripheral State and Errors functions \r
1058  *\r
1059 @verbatim   \r
1060  ===============================================================================\r
1061                   ##### Peripheral State and Errors functions #####\r
1062  ===============================================================================  \r
1063     [..]\r
1064     This subsection provides functions allowing to\r
1065       (+) Check the LTDC state.\r
1066       (+) Get error code.  \r
1067 \r
1068 @endverbatim\r
1069   * @{\r
1070   */ \r
1071 \r
1072 /**\r
1073   * @brief  Return the LTDC state\r
1074   * @param  hltdc: pointer to a LTDC_HandleTypeDef structure that contains\r
1075   *                the configuration information for the LTDC.\r
1076   * @retval HAL state\r
1077   */\r
1078 HAL_LTDC_StateTypeDef HAL_LTDC_GetState(LTDC_HandleTypeDef *hltdc)\r
1079 {\r
1080   return hltdc->State;\r
1081 }\r
1082 \r
1083 /**\r
1084 * @brief  Return the LTDC error code\r
1085 * @param  hltdc : pointer to a LTDC_HandleTypeDef structure that contains\r
1086   *               the configuration information for the LTDC.\r
1087 * @retval LTDC Error Code\r
1088 */\r
1089 uint32_t HAL_LTDC_GetError(LTDC_HandleTypeDef *hltdc)\r
1090 {\r
1091   return hltdc->ErrorCode;\r
1092 }\r
1093 \r
1094 /**\r
1095   * @}\r
1096   */\r
1097 \r
1098 /**\r
1099   * @brief  Configures the LTDC peripheral \r
1100   * @param  hltdc   :  Pointer to a LTDC_HandleTypeDef structure that contains\r
1101   *                   the configuration information for the LTDC.\r
1102   * @param  pLayerCfg: Pointer LTDC Layer Configuration structure\r
1103   * @param  LayerIdx:  LTDC Layer index.\r
1104   *                    This parameter can be one of the following values: 0 or 1\r
1105   * @retval None\r
1106   */\r
1107 static void LTDC_SetConfig(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)\r
1108 {\r
1109   uint32_t tmp = 0;\r
1110   uint32_t tmp1 = 0;\r
1111   uint32_t tmp2 = 0;\r
1112 \r
1113   /* Configures the horizontal start and stop position */\r
1114   tmp = ((pLayerCfg->WindowX1 + ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16)) << 16);\r
1115   LTDC_LAYER(hltdc, LayerIdx)->WHPCR &= ~(LTDC_LxWHPCR_WHSTPOS | LTDC_LxWHPCR_WHSPPOS);\r
1116   LTDC_LAYER(hltdc, LayerIdx)->WHPCR = ((pLayerCfg->WindowX0 + ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16) + 1) | tmp);\r
1117 \r
1118   /* Configures the vertical start and stop position */\r
1119   tmp = ((pLayerCfg->WindowY1 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP)) << 16);\r
1120   LTDC_LAYER(hltdc, LayerIdx)->WVPCR &= ~(LTDC_LxWVPCR_WVSTPOS | LTDC_LxWVPCR_WVSPPOS);\r
1121   LTDC_LAYER(hltdc, LayerIdx)->WVPCR  = ((pLayerCfg->WindowY0 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP) + 1) | tmp);  \r
1122 \r
1123   /* Specifies the pixel format */\r
1124   LTDC_LAYER(hltdc, LayerIdx)->PFCR &= ~(LTDC_LxPFCR_PF);\r
1125   LTDC_LAYER(hltdc, LayerIdx)->PFCR = (pLayerCfg->PixelFormat);\r
1126 \r
1127   /* Configures the default color values */\r
1128   tmp = ((uint32_t)(pLayerCfg->Backcolor.Green) << 8);\r
1129   tmp1 = ((uint32_t)(pLayerCfg->Backcolor.Red) << 16);\r
1130   tmp2 = (pLayerCfg->Alpha0 << 24);  \r
1131   LTDC_LAYER(hltdc, LayerIdx)->DCCR &= ~(LTDC_LxDCCR_DCBLUE | LTDC_LxDCCR_DCGREEN | LTDC_LxDCCR_DCRED | LTDC_LxDCCR_DCALPHA);\r
1132   LTDC_LAYER(hltdc, LayerIdx)->DCCR = (pLayerCfg->Backcolor.Blue | tmp | tmp1 | tmp2); \r
1133 \r
1134   /* Specifies the constant alpha value */\r
1135   LTDC_LAYER(hltdc, LayerIdx)->CACR &= ~(LTDC_LxCACR_CONSTA);\r
1136   LTDC_LAYER(hltdc, LayerIdx)->CACR = (pLayerCfg->Alpha);\r
1137 \r
1138   /* Specifies the blending factors */\r
1139   LTDC_LAYER(hltdc, LayerIdx)->BFCR &= ~(LTDC_LxBFCR_BF2 | LTDC_LxBFCR_BF1);\r
1140   LTDC_LAYER(hltdc, LayerIdx)->BFCR = (pLayerCfg->BlendingFactor1 | pLayerCfg->BlendingFactor2);\r
1141 \r
1142   /* Configures the color frame buffer start address */\r
1143   LTDC_LAYER(hltdc, LayerIdx)->CFBAR &= ~(LTDC_LxCFBAR_CFBADD);\r
1144   LTDC_LAYER(hltdc, LayerIdx)->CFBAR = (pLayerCfg->FBStartAdress);\r
1145 \r
1146   if(pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)\r
1147   {\r
1148     tmp = 4;\r
1149   }\r
1150   else if (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB888)\r
1151   {\r
1152     tmp = 3;\r
1153   }\r
1154   else if((pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \\r
1155     (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB565)   || \\r
1156       (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \\r
1157         (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_AL88))\r
1158   {\r
1159     tmp = 2;\r
1160   }\r
1161   else\r
1162   {\r
1163     tmp = 1;\r
1164   }\r
1165 \r
1166   /* Configures the color frame buffer pitch in byte */\r
1167   LTDC_LAYER(hltdc, LayerIdx)->CFBLR  &= ~(LTDC_LxCFBLR_CFBLL | LTDC_LxCFBLR_CFBP);\r
1168   LTDC_LAYER(hltdc, LayerIdx)->CFBLR  = (((pLayerCfg->ImageWidth * tmp) << 16) | (((pLayerCfg->WindowX1 - pLayerCfg->WindowX0) * tmp)  + 3));\r
1169 \r
1170   /* Configures the frame buffer line number */\r
1171   LTDC_LAYER(hltdc, LayerIdx)->CFBLNR  &= ~(LTDC_LxCFBLNR_CFBLNBR);\r
1172   LTDC_LAYER(hltdc, LayerIdx)->CFBLNR  = (pLayerCfg->ImageHeight);\r
1173 \r
1174   /* Enable LTDC_Layer by setting LEN bit */  \r
1175   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_LEN;\r
1176 }\r
1177 \r
1178 /**\r
1179   * @}\r
1180   */\r
1181 \r
1182 #endif /* HAL_LTDC_MODULE_ENABLED */\r
1183 \r
1184 /**\r
1185   * @}\r
1186   */\r
1187 #endif /* STM32F756xx || STM32F746xx */\r
1188 \r
1189 /**\r
1190   * @}\r
1191   */\r
1192 \r
1193 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r