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