1 /**
2   ******************************************************************************
3   * @file    stm32l4xx_hal_ltdc.c
4   * @author  MCD Application Team
5   * @brief   LTDC HAL module driver.
6   *          This file provides firmware functions to manage the following
7   *          functionalities of the LTDC peripheral:
8   *           + Initialization and de-initialization functions
9   *           + IO operation functions
10   *           + Peripheral Control functions
11   *           + Peripheral State and Errors functions
12   *
13   ******************************************************************************
14   * @attention
15   *
16   * Copyright (c) 2017 STMicroelectronics.
17   * All rights reserved.
18   *
19   * This software is licensed under terms that can be found in the LICENSE file
20   * in the root directory of this software component.
21   * If no LICENSE file comes with this software, it is provided AS-IS.
22   *
23   ******************************************************************************
24   @verbatim
25   ==============================================================================
26                         ##### How to use this driver #####
27   ==============================================================================
28      [..]
29      The LTDC HAL driver can be used as follows:
30 
31      (#) Declare a LTDC_HandleTypeDef handle structure, for example: LTDC_HandleTypeDef  hltdc;
32 
33      (#) Initialize the LTDC low level resources by implementing the HAL_LTDC_MspInit() API:
34          (##) Enable the LTDC interface clock
35          (##) NVIC configuration if you need to use interrupt process
36              (+++) Configure the LTDC interrupt priority
37              (+++) Enable the NVIC LTDC IRQ Channel
38 
39      (#) Initialize the required configuration through the following parameters:
40          the LTDC timing, the horizontal and vertical polarity, the pixel clock polarity,
41          Data Enable polarity and the LTDC background color value using HAL_LTDC_Init() function
42 
43      *** Configuration ***
44      =========================
45      [..]
46      (#) Program the required configuration through the following parameters:
47          the pixel format, the blending factors, input alpha value, the window size
48          and the image size using HAL_LTDC_ConfigLayer() function for foreground
49          or/and background layer.
50 
51      (#) Optionally, configure and enable the CLUT using HAL_LTDC_ConfigCLUT() and
52          HAL_LTDC_EnableCLUT functions.
53 
54      (#) Optionally, enable the Dither using HAL_LTDC_EnableDither().
55 
56      (#) Optionally, configure and enable the Color keying using HAL_LTDC_ConfigColorKeying()
57          and HAL_LTDC_EnableColorKeying functions.
58 
59      (#) Optionally, configure LineInterrupt using HAL_LTDC_ProgramLineEvent()
60          function
61 
62      (#) If needed, reconfigure and change the pixel format value, the alpha value
63          value, the window size, the window position and the layer start address
64          for foreground or/and background layer using respectively the following
65          functions: HAL_LTDC_SetPixelFormat(), HAL_LTDC_SetAlpha(), HAL_LTDC_SetWindowSize(),
66          HAL_LTDC_SetWindowPosition() and HAL_LTDC_SetAddress().
67 
68      (#) Variant functions with _NoReload suffix allows to set the LTDC configuration/settings without immediate reload.
69          This is useful in case when the program requires to modify serval LTDC settings (on one or both layers)
70          then applying(reload) these settings in one shot by calling the function HAL_LTDC_Reload().
71 
72          After calling the _NoReload functions to set different color/format/layer settings,
73          the program shall call the function HAL_LTDC_Reload() to apply(reload) these settings.
74          Function HAL_LTDC_Reload() can be called with the parameter ReloadType set to LTDC_RELOAD_IMMEDIATE if
75          an immediate reload is required.
76          Function HAL_LTDC_Reload() can be called with the parameter ReloadType set to LTDC_RELOAD_VERTICAL_BLANKING if
77          the reload should be done in the next vertical blanking period,
78          this option allows to avoid display flicker by applying the new settings during the vertical blanking period.
79 
80 
81      (#) To control LTDC state you can use the following function: HAL_LTDC_GetState()
82 
83      *** LTDC HAL driver macros list ***
84      =============================================
85      [..]
86        Below the list of most used macros in LTDC HAL driver.
87 
88       (+) __HAL_LTDC_ENABLE: Enable the LTDC.
89       (+) __HAL_LTDC_DISABLE: Disable the LTDC.
90       (+) __HAL_LTDC_LAYER_ENABLE: Enable an LTDC Layer.
91       (+) __HAL_LTDC_LAYER_DISABLE: Disable an LTDC Layer.
92       (+) __HAL_LTDC_RELOAD_IMMEDIATE_CONFIG: Reload  Layer Configuration.
93       (+) __HAL_LTDC_GET_FLAG: Get the LTDC pending flags.
94       (+) __HAL_LTDC_CLEAR_FLAG: Clear the LTDC pending flags.
95       (+) __HAL_LTDC_ENABLE_IT: Enable the specified LTDC interrupts.
96       (+) __HAL_LTDC_DISABLE_IT: Disable the specified LTDC interrupts.
97       (+) __HAL_LTDC_GET_IT_SOURCE: Check whether the specified LTDC interrupt has occurred or not.
98 
99      [..]
100        (@) You can refer to the LTDC HAL driver header file for more useful macros
101 
102 
103      *** Callback registration ***
104      =============================================
105      [..]
106      The compilation define  USE_HAL_LTDC_REGISTER_CALLBACKS when set to 1
107      allows the user to configure dynamically the driver callbacks.
108      Use function HAL_LTDC_RegisterCallback() to register a callback.
109 
110     [..]
111     Function HAL_LTDC_RegisterCallback() allows to register following callbacks:
112       (+) LineEventCallback   : LTDC Line Event Callback.
113       (+) ReloadEventCallback : LTDC Reload Event Callback.
114       (+) ErrorCallback       : LTDC Error Callback
115       (+) MspInitCallback     : LTDC MspInit.
116       (+) MspDeInitCallback   : LTDC MspDeInit.
117     [..]
118     This function takes as parameters the HAL peripheral handle, the callback ID
119     and a pointer to the user callback function.
120 
121     [..]
122     Use function HAL_LTDC_UnRegisterCallback() to reset a callback to the default
123     weak function.
124     HAL_LTDC_UnRegisterCallback() takes as parameters the HAL peripheral handle
125     and the callback ID.
126     [..]
127     This function allows to reset following callbacks:
128       (+) LineEventCallback   : LTDC Line Event Callback
129       (+) ReloadEventCallback : LTDC Reload Event Callback
130       (+) ErrorCallback       : LTDC Error Callback
131       (+) MspInitCallback     : LTDC MspInit
132       (+) MspDeInitCallback   : LTDC MspDeInit.
133 
134     [..]
135     By default, after the HAL_LTDC_Init and when the state is HAL_LTDC_STATE_RESET
136     all callbacks are set to the corresponding weak functions:
137     examples HAL_LTDC_LineEventCallback(), HAL_LTDC_ErrorCallback().
138     Exception done for MspInit and MspDeInit functions that are
139     reset to the legacy weak (surcharged) functions in the HAL_LTDC_Init() and HAL_LTDC_DeInit()
140     only when these callbacks are null (not registered beforehand).
141     If not, MspInit or MspDeInit are not null, the HAL_LTDC_Init() and HAL_LTDC_DeInit()
142     keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
143 
144     [..]
145     Callbacks can be registered/unregistered in HAL_LTDC_STATE_READY state only.
146     Exception done MspInit/MspDeInit that can be registered/unregistered
147     in HAL_LTDC_STATE_READY or HAL_LTDC_STATE_RESET state,
148     thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
149     In that case first register the MspInit/MspDeInit user callbacks
150     using HAL_LTDC_RegisterCallback() before calling HAL_LTDC_DeInit()
151     or HAL_LTDC_Init() function.
152 
153     [..]
154     When the compilation define USE_HAL_LTDC_REGISTER_CALLBACKS is set to 0 or
155     not defined, the callback registration feature is not available and all callbacks
156     are set to the corresponding weak functions.
157 
158   @endverbatim
159   ******************************************************************************
160   */
161 
162 /* Includes ------------------------------------------------------------------*/
163 #include "stm32l4xx_hal.h"
164 
165 /** @addtogroup STM32L4xx_HAL_Driver
166   * @{
167   */
168 
169 #ifdef HAL_LTDC_MODULE_ENABLED
170 
171 #if defined (LTDC)
172 
173 /** @defgroup LTDC LTDC
174   * @brief LTDC HAL module driver
175   * @{
176   */
177 
178 
179 /* Private typedef -----------------------------------------------------------*/
180 /* Private define ------------------------------------------------------------*/
181 #define LTDC_TIMEOUT_VALUE ((uint32_t)100U)  /* 100ms */
182 /* Private macro -------------------------------------------------------------*/
183 /* Private variables ---------------------------------------------------------*/
184 /* Private function prototypes -----------------------------------------------*/
185 static void LTDC_SetConfig(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx);
186 /* Private functions ---------------------------------------------------------*/
187 
188 /** @defgroup LTDC_Exported_Functions LTDC Exported Functions
189   * @{
190   */
191 
192 /** @defgroup LTDC_Exported_Functions_Group1 Initialization and Configuration functions
193   *  @brief   Initialization and Configuration functions
194   *
195 @verbatim
196  ===============================================================================
197                 ##### Initialization and Configuration functions #####
198  ===============================================================================
199     [..]  This section provides functions allowing to:
200       (+) Initialize and configure the LTDC
201       (+) De-initialize the LTDC
202 
203 @endverbatim
204   * @{
205   */
206 
207 /**
208   * @brief  Initialize the LTDC according to the specified parameters in the LTDC_InitTypeDef.
209   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
210   *                the configuration information for the LTDC.
211   * @retval HAL status
212   */
HAL_LTDC_Init(LTDC_HandleTypeDef * hltdc)213 HAL_StatusTypeDef HAL_LTDC_Init(LTDC_HandleTypeDef *hltdc)
214 {
215   uint32_t tmp;
216   uint32_t tmp1;
217 
218   /* Check the LTDC peripheral state */
219   if (hltdc == NULL)
220   {
221     return HAL_ERROR;
222   }
223 
224   /* Check function parameters */
225   assert_param(IS_LTDC_ALL_INSTANCE(hltdc->Instance));
226   assert_param(IS_LTDC_HSYNC(hltdc->Init.HorizontalSync));
227   assert_param(IS_LTDC_VSYNC(hltdc->Init.VerticalSync));
228   assert_param(IS_LTDC_AHBP(hltdc->Init.AccumulatedHBP));
229   assert_param(IS_LTDC_AVBP(hltdc->Init.AccumulatedVBP));
230   assert_param(IS_LTDC_AAH(hltdc->Init.AccumulatedActiveH));
231   assert_param(IS_LTDC_AAW(hltdc->Init.AccumulatedActiveW));
232   assert_param(IS_LTDC_TOTALH(hltdc->Init.TotalHeigh));
233   assert_param(IS_LTDC_TOTALW(hltdc->Init.TotalWidth));
234   assert_param(IS_LTDC_HSPOL(hltdc->Init.HSPolarity));
235   assert_param(IS_LTDC_VSPOL(hltdc->Init.VSPolarity));
236   assert_param(IS_LTDC_DEPOL(hltdc->Init.DEPolarity));
237   assert_param(IS_LTDC_PCPOL(hltdc->Init.PCPolarity));
238 
239 #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
240   if (hltdc->State == HAL_LTDC_STATE_RESET)
241   {
242     /* Allocate lock resource and initialize it */
243     hltdc->Lock = HAL_UNLOCKED;
244 
245     /* Reset the LTDC callback to the legacy weak callbacks */
246     hltdc->LineEventCallback   = HAL_LTDC_LineEventCallback;    /* Legacy weak LineEventCallback    */
247     hltdc->ReloadEventCallback = HAL_LTDC_ReloadEventCallback;  /* Legacy weak ReloadEventCallback  */
248     hltdc->ErrorCallback       = HAL_LTDC_ErrorCallback;        /* Legacy weak ErrorCallback        */
249 
250     if (hltdc->MspInitCallback == NULL)
251     {
252       hltdc->MspInitCallback = HAL_LTDC_MspInit;
253     }
254     /* Init the low level hardware */
255     hltdc->MspInitCallback(hltdc);
256   }
257 #else
258   if (hltdc->State == HAL_LTDC_STATE_RESET)
259   {
260     /* Allocate lock resource and initialize it */
261     hltdc->Lock = HAL_UNLOCKED;
262     /* Init the low level hardware */
263     HAL_LTDC_MspInit(hltdc);
264   }
265 #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
266 
267   /* Change LTDC peripheral state */
268   hltdc->State = HAL_LTDC_STATE_BUSY;
269 
270   /* Configure the HS, VS, DE and PC polarity */
271   hltdc->Instance->GCR &= ~(LTDC_GCR_HSPOL | LTDC_GCR_VSPOL | LTDC_GCR_DEPOL | LTDC_GCR_PCPOL);
272   hltdc->Instance->GCR |= (uint32_t)(hltdc->Init.HSPolarity | hltdc->Init.VSPolarity | \
273                                      hltdc->Init.DEPolarity | hltdc->Init.PCPolarity);
274 
275   /* Set Synchronization size */
276   hltdc->Instance->SSCR &= ~(LTDC_SSCR_VSH | LTDC_SSCR_HSW);
277   tmp = (hltdc->Init.HorizontalSync << 16U);
278   hltdc->Instance->SSCR |= (tmp | hltdc->Init.VerticalSync);
279 
280   /* Set Accumulated Back porch */
281   hltdc->Instance->BPCR &= ~(LTDC_BPCR_AVBP | LTDC_BPCR_AHBP);
282   tmp = (hltdc->Init.AccumulatedHBP << 16U);
283   hltdc->Instance->BPCR |= (tmp | hltdc->Init.AccumulatedVBP);
284 
285   /* Set Accumulated Active Width */
286   hltdc->Instance->AWCR &= ~(LTDC_AWCR_AAH | LTDC_AWCR_AAW);
287   tmp = (hltdc->Init.AccumulatedActiveW << 16U);
288   hltdc->Instance->AWCR |= (tmp | hltdc->Init.AccumulatedActiveH);
289 
290   /* Set Total Width */
291   hltdc->Instance->TWCR &= ~(LTDC_TWCR_TOTALH | LTDC_TWCR_TOTALW);
292   tmp = (hltdc->Init.TotalWidth << 16U);
293   hltdc->Instance->TWCR |= (tmp | hltdc->Init.TotalHeigh);
294 
295   /* Set the background color value */
296   tmp = ((uint32_t)(hltdc->Init.Backcolor.Green) << 8U);
297   tmp1 = ((uint32_t)(hltdc->Init.Backcolor.Red) << 16U);
298   hltdc->Instance->BCCR &= ~(LTDC_BCCR_BCBLUE | LTDC_BCCR_BCGREEN | LTDC_BCCR_BCRED);
299   hltdc->Instance->BCCR |= (tmp1 | tmp | hltdc->Init.Backcolor.Blue);
300 
301   /* Enable the Transfer Error and FIFO underrun interrupts */
302   __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_TE | LTDC_IT_FU);
303 
304   /* Enable LTDC by setting LTDCEN bit */
305   __HAL_LTDC_ENABLE(hltdc);
306 
307   /* Initialize the error code */
308   hltdc->ErrorCode = HAL_LTDC_ERROR_NONE;
309 
310   /* Initialize the LTDC state*/
311   hltdc->State = HAL_LTDC_STATE_READY;
312 
313   return HAL_OK;
314 }
315 
316 /**
317   * @brief  De-initialize the LTDC peripheral.
318   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
319   *                the configuration information for the LTDC.
320   * @retval None
321   */
322 
HAL_LTDC_DeInit(LTDC_HandleTypeDef * hltdc)323 HAL_StatusTypeDef HAL_LTDC_DeInit(LTDC_HandleTypeDef *hltdc)
324 {
325   uint32_t tickstart;
326 
327   /* Check the LTDC peripheral state */
328   if (hltdc == NULL)
329   {
330     return HAL_ERROR;
331   }
332 
333   /* Check function parameters */
334   assert_param(IS_LTDC_ALL_INSTANCE(hltdc->Instance));
335 
336   /* Disable LTDC Layer 1 */
337   __HAL_LTDC_LAYER_DISABLE(hltdc, LTDC_LAYER_1);
338 
339 #if defined(LTDC_Layer2_BASE)
340   /* Disable LTDC Layer 2 */
341   __HAL_LTDC_LAYER_DISABLE(hltdc, LTDC_LAYER_2);
342 #endif /* LTDC_Layer2_BASE */
343 
344   /* Reload during vertical blanking period */
345   __HAL_LTDC_VERTICAL_BLANKING_RELOAD_CONFIG(hltdc);
346 
347   /* Get tick */
348   tickstart = HAL_GetTick();
349 
350   /* Wait for VSYNC Interrupt */
351   while (READ_BIT(hltdc->Instance->CDSR, LTDC_CDSR_VSYNCS) == 0U)
352   {
353     /* Check for the Timeout */
354     if ((HAL_GetTick() - tickstart) > LTDC_TIMEOUT_VALUE)
355     {
356       break;
357     }
358   }
359 
360   /* Disable LTDC  */
361   __HAL_LTDC_DISABLE(hltdc);
362 
363 #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
364   if (hltdc->MspDeInitCallback == NULL)
365   {
366     hltdc->MspDeInitCallback = HAL_LTDC_MspDeInit;
367   }
368   /* DeInit the low level hardware */
369   hltdc->MspDeInitCallback(hltdc);
370 #else
371   /* DeInit the low level hardware */
372   HAL_LTDC_MspDeInit(hltdc);
373 #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
374 
375   /* Initialize the error code */
376   hltdc->ErrorCode = HAL_LTDC_ERROR_NONE;
377 
378   /* Initialize the LTDC state*/
379   hltdc->State = HAL_LTDC_STATE_RESET;
380 
381   /* Release Lock */
382   __HAL_UNLOCK(hltdc);
383 
384   return HAL_OK;
385 }
386 
387 /**
388   * @brief  Initialize the LTDC MSP.
389   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
390   *                the configuration information for the LTDC.
391   * @retval None
392   */
HAL_LTDC_MspInit(LTDC_HandleTypeDef * hltdc)393 __weak void HAL_LTDC_MspInit(LTDC_HandleTypeDef *hltdc)
394 {
395   /* Prevent unused argument(s) compilation warning */
396   UNUSED(hltdc);
397 
398   /* NOTE : This function should not be modified, when the callback is needed,
399             the HAL_LTDC_MspInit could be implemented in the user file
400    */
401 }
402 
403 /**
404   * @brief  De-initialize the LTDC MSP.
405   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
406   *                the configuration information for the LTDC.
407   * @retval None
408   */
HAL_LTDC_MspDeInit(LTDC_HandleTypeDef * hltdc)409 __weak void HAL_LTDC_MspDeInit(LTDC_HandleTypeDef *hltdc)
410 {
411   /* Prevent unused argument(s) compilation warning */
412   UNUSED(hltdc);
413 
414   /* NOTE : This function should not be modified, when the callback is needed,
415             the HAL_LTDC_MspDeInit could be implemented in the user file
416    */
417 }
418 
419 #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
420 /**
421   * @brief  Register a User LTDC Callback
422   *         To be used instead of the weak predefined callback
423   * @param hltdc ltdc handle
424   * @param CallbackID ID of the callback to be registered
425   *        This parameter can be one of the following values:
426   *          @arg @ref HAL_LTDC_LINE_EVENT_CB_ID Line Event Callback ID
427   *          @arg @ref HAL_LTDC_RELOAD_EVENT_CB_ID Reload Event Callback ID
428   *          @arg @ref HAL_LTDC_ERROR_CB_ID Error Callback ID
429   *          @arg @ref HAL_LTDC_MSPINIT_CB_ID MspInit callback ID
430   *          @arg @ref HAL_LTDC_MSPDEINIT_CB_ID MspDeInit callback ID
431   * @param pCallback pointer to the Callback function
432   * @retval status
433   */
HAL_LTDC_RegisterCallback(LTDC_HandleTypeDef * hltdc,HAL_LTDC_CallbackIDTypeDef CallbackID,pLTDC_CallbackTypeDef pCallback)434 HAL_StatusTypeDef HAL_LTDC_RegisterCallback(LTDC_HandleTypeDef *hltdc, HAL_LTDC_CallbackIDTypeDef CallbackID,
435                                             pLTDC_CallbackTypeDef pCallback)
436 {
437   HAL_StatusTypeDef status = HAL_OK;
438 
439   if (pCallback == NULL)
440   {
441     /* Update the error code */
442     hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
443 
444     return HAL_ERROR;
445   }
446   /* Process locked */
447   __HAL_LOCK(hltdc);
448 
449   if (hltdc->State == HAL_LTDC_STATE_READY)
450   {
451     switch (CallbackID)
452     {
453       case HAL_LTDC_LINE_EVENT_CB_ID :
454         hltdc->LineEventCallback = pCallback;
455         break;
456 
457       case HAL_LTDC_RELOAD_EVENT_CB_ID :
458         hltdc->ReloadEventCallback = pCallback;
459         break;
460 
461       case HAL_LTDC_ERROR_CB_ID :
462         hltdc->ErrorCallback = pCallback;
463         break;
464 
465       case HAL_LTDC_MSPINIT_CB_ID :
466         hltdc->MspInitCallback = pCallback;
467         break;
468 
469       case HAL_LTDC_MSPDEINIT_CB_ID :
470         hltdc->MspDeInitCallback = pCallback;
471         break;
472 
473       default :
474         /* Update the error code */
475         hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
476         /* Return error status */
477         status =  HAL_ERROR;
478         break;
479     }
480   }
481   else if (hltdc->State == HAL_LTDC_STATE_RESET)
482   {
483     switch (CallbackID)
484     {
485       case HAL_LTDC_MSPINIT_CB_ID :
486         hltdc->MspInitCallback = pCallback;
487         break;
488 
489       case HAL_LTDC_MSPDEINIT_CB_ID :
490         hltdc->MspDeInitCallback = pCallback;
491         break;
492 
493       default :
494         /* Update the error code */
495         hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
496         /* Return error status */
497         status =  HAL_ERROR;
498         break;
499     }
500   }
501   else
502   {
503     /* Update the error code */
504     hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
505     /* Return error status */
506     status =  HAL_ERROR;
507   }
508 
509   /* Release Lock */
510   __HAL_UNLOCK(hltdc);
511 
512   return status;
513 }
514 
515 /**
516   * @brief  Unregister an LTDC Callback
517   *         LTDC callback is redirected to the weak predefined callback
518   * @param hltdc ltdc handle
519   * @param CallbackID ID of the callback to be unregistered
520   *        This parameter can be one of the following values:
521   *          @arg @ref HAL_LTDC_LINE_EVENT_CB_ID Line Event Callback ID
522   *          @arg @ref HAL_LTDC_RELOAD_EVENT_CB_ID Reload Event Callback ID
523   *          @arg @ref HAL_LTDC_ERROR_CB_ID Error Callback ID
524   *          @arg @ref HAL_LTDC_MSPINIT_CB_ID MspInit callback ID
525   *          @arg @ref HAL_LTDC_MSPDEINIT_CB_ID MspDeInit callback ID
526   * @retval status
527   */
HAL_LTDC_UnRegisterCallback(LTDC_HandleTypeDef * hltdc,HAL_LTDC_CallbackIDTypeDef CallbackID)528 HAL_StatusTypeDef HAL_LTDC_UnRegisterCallback(LTDC_HandleTypeDef *hltdc, HAL_LTDC_CallbackIDTypeDef CallbackID)
529 {
530   HAL_StatusTypeDef status = HAL_OK;
531 
532   /* Process locked */
533   __HAL_LOCK(hltdc);
534 
535   if (hltdc->State == HAL_LTDC_STATE_READY)
536   {
537     switch (CallbackID)
538     {
539       case HAL_LTDC_LINE_EVENT_CB_ID :
540         hltdc->LineEventCallback = HAL_LTDC_LineEventCallback;      /* Legacy weak LineEventCallback    */
541         break;
542 
543       case HAL_LTDC_RELOAD_EVENT_CB_ID :
544         hltdc->ReloadEventCallback = HAL_LTDC_ReloadEventCallback;  /* Legacy weak ReloadEventCallback  */
545         break;
546 
547       case HAL_LTDC_ERROR_CB_ID :
548         hltdc->ErrorCallback       = HAL_LTDC_ErrorCallback;        /* Legacy weak ErrorCallback        */
549         break;
550 
551       case HAL_LTDC_MSPINIT_CB_ID :
552         hltdc->MspInitCallback = HAL_LTDC_MspInit;                  /* Legcay weak MspInit Callback     */
553         break;
554 
555       case HAL_LTDC_MSPDEINIT_CB_ID :
556         hltdc->MspDeInitCallback = HAL_LTDC_MspDeInit;              /* Legcay weak MspDeInit Callback     */
557         break;
558 
559       default :
560         /* Update the error code */
561         hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
562         /* Return error status */
563         status =  HAL_ERROR;
564         break;
565     }
566   }
567   else if (hltdc->State == HAL_LTDC_STATE_RESET)
568   {
569     switch (CallbackID)
570     {
571       case HAL_LTDC_MSPINIT_CB_ID :
572         hltdc->MspInitCallback = HAL_LTDC_MspInit;                  /* Legcay weak MspInit Callback     */
573         break;
574 
575       case HAL_LTDC_MSPDEINIT_CB_ID :
576         hltdc->MspDeInitCallback = HAL_LTDC_MspDeInit;              /* Legcay weak MspDeInit Callback     */
577         break;
578 
579       default :
580         /* Update the error code */
581         hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
582         /* Return error status */
583         status =  HAL_ERROR;
584         break;
585     }
586   }
587   else
588   {
589     /* Update the error code */
590     hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
591     /* Return error status */
592     status =  HAL_ERROR;
593   }
594 
595   /* Release Lock */
596   __HAL_UNLOCK(hltdc);
597 
598   return status;
599 }
600 #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
601 
602 /**
603   * @}
604   */
605 
606 /** @defgroup LTDC_Exported_Functions_Group2 IO operation functions
607   *  @brief   IO operation functions
608   *
609 @verbatim
610  ===============================================================================
611                       #####  IO operation functions  #####
612  ===============================================================================
613     [..]  This section provides function allowing to:
614       (+) Handle LTDC interrupt request
615 
616 @endverbatim
617   * @{
618   */
619 /**
620   * @brief  Handle LTDC interrupt request.
621   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
622   *                the configuration information for the LTDC.
623   * @retval HAL status
624   */
HAL_LTDC_IRQHandler(LTDC_HandleTypeDef * hltdc)625 void HAL_LTDC_IRQHandler(LTDC_HandleTypeDef *hltdc)
626 {
627   uint32_t isrflags  = READ_REG(hltdc->Instance->ISR);
628   uint32_t itsources = READ_REG(hltdc->Instance->IER);
629 
630   /* Transfer Error Interrupt management ***************************************/
631   if (((isrflags & LTDC_ISR_TERRIF) != 0U) && ((itsources & LTDC_IER_TERRIE) != 0U))
632   {
633     /* Disable the transfer Error interrupt */
634     __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_TE);
635 
636     /* Clear the transfer error flag */
637     __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_TE);
638 
639     /* Update error code */
640     hltdc->ErrorCode |= HAL_LTDC_ERROR_TE;
641 
642     /* Change LTDC state */
643     hltdc->State = HAL_LTDC_STATE_ERROR;
644 
645     /* Process unlocked */
646     __HAL_UNLOCK(hltdc);
647 
648     /* Transfer error Callback */
649 #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
650     /*Call registered error callback*/
651     hltdc->ErrorCallback(hltdc);
652 #else
653     /* Call legacy error callback*/
654     HAL_LTDC_ErrorCallback(hltdc);
655 #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
656   }
657 
658   /* FIFO underrun Interrupt management ***************************************/
659   if (((isrflags & LTDC_ISR_FUIF) != 0U) && ((itsources & LTDC_IER_FUIE) != 0U))
660   {
661     /* Disable the FIFO underrun interrupt */
662     __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_FU);
663 
664     /* Clear the FIFO underrun flag */
665     __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_FU);
666 
667     /* Update error code */
668     hltdc->ErrorCode |= HAL_LTDC_ERROR_FU;
669 
670     /* Change LTDC state */
671     hltdc->State = HAL_LTDC_STATE_ERROR;
672 
673     /* Process unlocked */
674     __HAL_UNLOCK(hltdc);
675 
676     /* Transfer error Callback */
677 #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
678     /*Call registered error callback*/
679     hltdc->ErrorCallback(hltdc);
680 #else
681     /* Call legacy error callback*/
682     HAL_LTDC_ErrorCallback(hltdc);
683 #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
684   }
685 
686   /* Line Interrupt management ************************************************/
687   if (((isrflags & LTDC_ISR_LIF) != 0U) && ((itsources & LTDC_IER_LIE) != 0U))
688   {
689     /* Disable the Line interrupt */
690     __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_LI);
691 
692     /* Clear the Line interrupt flag */
693     __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_LI);
694 
695     /* Change LTDC state */
696     hltdc->State = HAL_LTDC_STATE_READY;
697 
698     /* Process unlocked */
699     __HAL_UNLOCK(hltdc);
700 
701     /* Line interrupt Callback */
702 #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
703     /*Call registered Line Event callback */
704     hltdc->LineEventCallback(hltdc);
705 #else
706     /*Call Legacy Line Event callback */
707     HAL_LTDC_LineEventCallback(hltdc);
708 #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
709   }
710 
711   /* Register reload Interrupt management ***************************************/
712   if (((isrflags & LTDC_ISR_RRIF) != 0U) && ((itsources & LTDC_IER_RRIE) != 0U))
713   {
714     /* Disable the register reload interrupt */
715     __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_RR);
716 
717     /* Clear the register reload flag */
718     __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_RR);
719 
720     /* Change LTDC state */
721     hltdc->State = HAL_LTDC_STATE_READY;
722 
723     /* Process unlocked */
724     __HAL_UNLOCK(hltdc);
725 
726     /* Reload interrupt Callback */
727 #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
728     /*Call registered reload Event callback */
729     hltdc->ReloadEventCallback(hltdc);
730 #else
731     /*Call Legacy Reload Event callback */
732     HAL_LTDC_ReloadEventCallback(hltdc);
733 #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
734   }
735 }
736 
737 /**
738   * @brief  Error LTDC callback.
739   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
740   *                the configuration information for the LTDC.
741   * @retval None
742   */
HAL_LTDC_ErrorCallback(LTDC_HandleTypeDef * hltdc)743 __weak void HAL_LTDC_ErrorCallback(LTDC_HandleTypeDef *hltdc)
744 {
745   /* Prevent unused argument(s) compilation warning */
746   UNUSED(hltdc);
747 
748   /* NOTE : This function should not be modified, when the callback is needed,
749             the HAL_LTDC_ErrorCallback could be implemented in the user file
750    */
751 }
752 
753 /**
754   * @brief  Line Event callback.
755   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
756   *                the configuration information for the LTDC.
757   * @retval None
758   */
HAL_LTDC_LineEventCallback(LTDC_HandleTypeDef * hltdc)759 __weak void HAL_LTDC_LineEventCallback(LTDC_HandleTypeDef *hltdc)
760 {
761   /* Prevent unused argument(s) compilation warning */
762   UNUSED(hltdc);
763 
764   /* NOTE : This function should not be modified, when the callback is needed,
765             the HAL_LTDC_LineEventCallback could be implemented in the user file
766    */
767 }
768 
769 /**
770   * @brief  Reload Event callback.
771   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
772   *                the configuration information for the LTDC.
773   * @retval None
774   */
HAL_LTDC_ReloadEventCallback(LTDC_HandleTypeDef * hltdc)775 __weak void HAL_LTDC_ReloadEventCallback(LTDC_HandleTypeDef *hltdc)
776 {
777   /* Prevent unused argument(s) compilation warning */
778   UNUSED(hltdc);
779 
780   /* NOTE : This function should not be modified, when the callback is needed,
781             the HAL_LTDC_ReloadEvenCallback could be implemented in the user file
782    */
783 }
784 
785 /**
786   * @}
787   */
788 
789 /** @defgroup LTDC_Exported_Functions_Group3 Peripheral Control functions
790   *  @brief    Peripheral Control functions
791   *
792 @verbatim
793  ===============================================================================
794                     ##### Peripheral Control functions #####
795  ===============================================================================
796     [..]  This section provides functions allowing to:
797       (+) Configure the LTDC foreground or/and background parameters.
798       (+) Set the active layer.
799       (+) Configure the color keying.
800       (+) Configure the C-LUT.
801       (+) Enable / Disable the color keying.
802       (+) Enable / Disable the C-LUT.
803       (+) Update the layer position.
804       (+) Update the layer size.
805       (+) Update pixel format on the fly.
806       (+) Update transparency on the fly.
807       (+) Update address on the fly.
808 
809 @endverbatim
810   * @{
811   */
812 
813 /**
814   * @brief  Configure the LTDC Layer according to the specified
815   *         parameters in the LTDC_InitTypeDef and create the associated handle.
816   * @param  hltdc      pointer to a LTDC_HandleTypeDef structure that contains
817   *                    the configuration information for the LTDC.
818   * @param  pLayerCfg  pointer to a LTDC_LayerCfgTypeDef structure that contains
819   *                    the configuration information for the Layer.
820   * @param  LayerIdx  LTDC Layer index.
821   *                    This parameter can be one of the following values:
822   *                    LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
823   * @retval HAL status
824   */
HAL_LTDC_ConfigLayer(LTDC_HandleTypeDef * hltdc,LTDC_LayerCfgTypeDef * pLayerCfg,uint32_t LayerIdx)825 HAL_StatusTypeDef HAL_LTDC_ConfigLayer(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)
826 {
827   /* Check the parameters */
828   assert_param(IS_LTDC_LAYER(LayerIdx));
829   assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));
830   assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));
831   assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));
832   assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));
833   assert_param(IS_LTDC_PIXEL_FORMAT(pLayerCfg->PixelFormat));
834   assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha));
835   assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha0));
836   assert_param(IS_LTDC_BLENDING_FACTOR1(pLayerCfg->BlendingFactor1));
837   assert_param(IS_LTDC_BLENDING_FACTOR2(pLayerCfg->BlendingFactor2));
838   assert_param(IS_LTDC_CFBLL(pLayerCfg->ImageWidth));
839   assert_param(IS_LTDC_CFBLNBR(pLayerCfg->ImageHeight));
840 
841   /* Process locked */
842   __HAL_LOCK(hltdc);
843 
844   /* Change LTDC peripheral state */
845   hltdc->State = HAL_LTDC_STATE_BUSY;
846 
847   /* Copy new layer configuration into handle structure */
848   hltdc->LayerCfg[LayerIdx] = *pLayerCfg;
849 
850   /* Configure the LTDC Layer */
851   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
852 
853   /* Set the Immediate Reload type */
854   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
855 
856   /* Initialize the LTDC state*/
857   hltdc->State  = HAL_LTDC_STATE_READY;
858 
859   /* Process unlocked */
860   __HAL_UNLOCK(hltdc);
861 
862   return HAL_OK;
863 }
864 
865 /**
866   * @brief  Configure the color keying.
867   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
868   *                   the configuration information for the LTDC.
869   * @param  RGBValue  the color key value
870   * @param  LayerIdx  LTDC Layer index.
871   *                   This parameter can be one of the following values:
872   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
873   * @retval HAL status
874   */
HAL_LTDC_ConfigColorKeying(LTDC_HandleTypeDef * hltdc,uint32_t RGBValue,uint32_t LayerIdx)875 HAL_StatusTypeDef HAL_LTDC_ConfigColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t RGBValue, uint32_t LayerIdx)
876 {
877   /* Check the parameters */
878   assert_param(IS_LTDC_LAYER(LayerIdx));
879 
880   /* Process locked */
881   __HAL_LOCK(hltdc);
882 
883   /* Change LTDC peripheral state */
884   hltdc->State = HAL_LTDC_STATE_BUSY;
885 
886   /* Configure the default color values */
887   LTDC_LAYER(hltdc, LayerIdx)->CKCR &=  ~(LTDC_LxCKCR_CKBLUE | LTDC_LxCKCR_CKGREEN | LTDC_LxCKCR_CKRED);
888   LTDC_LAYER(hltdc, LayerIdx)->CKCR  = RGBValue;
889 
890   /* Set the Immediate Reload type */
891   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
892 
893   /* Change the LTDC state*/
894   hltdc->State = HAL_LTDC_STATE_READY;
895 
896   /* Process unlocked */
897   __HAL_UNLOCK(hltdc);
898 
899   return HAL_OK;
900 }
901 
902 /**
903   * @brief  Load the color lookup table.
904   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
905   *                   the configuration information for the LTDC.
906   * @param  pCLUT     pointer to the color lookup table address.
907   * @param  CLUTSize  the color lookup table size.
908   * @param  LayerIdx  LTDC Layer index.
909   *                   This parameter can be one of the following values:
910   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
911   * @retval HAL status
912   */
HAL_LTDC_ConfigCLUT(LTDC_HandleTypeDef * hltdc,uint32_t * pCLUT,uint32_t CLUTSize,uint32_t LayerIdx)913 HAL_StatusTypeDef HAL_LTDC_ConfigCLUT(LTDC_HandleTypeDef *hltdc, uint32_t *pCLUT, uint32_t CLUTSize, uint32_t LayerIdx)
914 {
915   uint32_t tmp;
916   uint32_t counter;
917   uint32_t *pcolorlut = pCLUT;
918   /* Check the parameters */
919   assert_param(IS_LTDC_LAYER(LayerIdx));
920 
921   /* Process locked */
922   __HAL_LOCK(hltdc);
923 
924   /* Change LTDC peripheral state */
925   hltdc->State = HAL_LTDC_STATE_BUSY;
926 
927   for (counter = 0U; (counter < CLUTSize); counter++)
928   {
929     if (hltdc->LayerCfg[LayerIdx].PixelFormat == LTDC_PIXEL_FORMAT_AL44)
930     {
931       tmp  = (((counter + (16U * counter)) << 24U) | ((uint32_t)(*pcolorlut) & 0xFFU) | \
932               ((uint32_t)(*pcolorlut) & 0xFF00U) | ((uint32_t)(*pcolorlut) & 0xFF0000U));
933     }
934     else
935     {
936       tmp  = ((counter << 24U) | ((uint32_t)(*pcolorlut) & 0xFFU) | \
937               ((uint32_t)(*pcolorlut) & 0xFF00U) | ((uint32_t)(*pcolorlut) & 0xFF0000U));
938     }
939 
940     pcolorlut++;
941 
942     /* Specifies the C-LUT address and RGB value */
943     LTDC_LAYER(hltdc, LayerIdx)->CLUTWR  = tmp;
944   }
945 
946   /* Change the LTDC state*/
947   hltdc->State = HAL_LTDC_STATE_READY;
948 
949   /* Process unlocked */
950   __HAL_UNLOCK(hltdc);
951 
952   return HAL_OK;
953 }
954 
955 /**
956   * @brief  Enable the color keying.
957   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
958   *                   the configuration information for the LTDC.
959   * @param  LayerIdx  LTDC Layer index.
960   *                   This parameter can be one of the following values:
961   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
962   * @retval  HAL status
963   */
HAL_LTDC_EnableColorKeying(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)964 HAL_StatusTypeDef HAL_LTDC_EnableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
965 {
966   /* Check the parameters */
967   assert_param(IS_LTDC_LAYER(LayerIdx));
968 
969   /* Process locked */
970   __HAL_LOCK(hltdc);
971 
972   /* Change LTDC peripheral state */
973   hltdc->State = HAL_LTDC_STATE_BUSY;
974 
975   /* Enable LTDC color keying by setting COLKEN bit */
976   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_COLKEN;
977 
978   /* Set the Immediate Reload type */
979   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
980 
981   /* Change the LTDC state*/
982   hltdc->State = HAL_LTDC_STATE_READY;
983 
984   /* Process unlocked */
985   __HAL_UNLOCK(hltdc);
986 
987   return HAL_OK;
988 }
989 
990 /**
991   * @brief  Disable the color keying.
992   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
993   *                   the configuration information for the LTDC.
994   * @param  LayerIdx  LTDC Layer index.
995   *                   This parameter can be one of the following values:
996   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
997   * @retval  HAL status
998   */
HAL_LTDC_DisableColorKeying(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)999 HAL_StatusTypeDef HAL_LTDC_DisableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1000 {
1001   /* Check the parameters */
1002   assert_param(IS_LTDC_LAYER(LayerIdx));
1003 
1004   /* Process locked */
1005   __HAL_LOCK(hltdc);
1006 
1007   /* Change LTDC peripheral state */
1008   hltdc->State = HAL_LTDC_STATE_BUSY;
1009 
1010   /* Disable LTDC color keying by setting COLKEN bit */
1011   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_COLKEN;
1012 
1013   /* Set the Immediate Reload type */
1014   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1015 
1016   /* Change the LTDC state*/
1017   hltdc->State = HAL_LTDC_STATE_READY;
1018 
1019   /* Process unlocked */
1020   __HAL_UNLOCK(hltdc);
1021 
1022   return HAL_OK;
1023 }
1024 
1025 /**
1026   * @brief  Enable the color lookup table.
1027   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1028   *                   the configuration information for the LTDC.
1029   * @param  LayerIdx  LTDC Layer index.
1030   *                   This parameter can be one of the following values:
1031   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1032   * @retval  HAL status
1033   */
HAL_LTDC_EnableCLUT(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)1034 HAL_StatusTypeDef HAL_LTDC_EnableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1035 {
1036   /* Check the parameters */
1037   assert_param(IS_LTDC_LAYER(LayerIdx));
1038 
1039   /* Process locked */
1040   __HAL_LOCK(hltdc);
1041 
1042   /* Change LTDC peripheral state */
1043   hltdc->State = HAL_LTDC_STATE_BUSY;
1044 
1045   /* Enable LTDC color lookup table by setting CLUTEN bit */
1046   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_CLUTEN;
1047 
1048   /* Set the Immediate Reload type */
1049   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1050 
1051   /* Change the LTDC state*/
1052   hltdc->State = HAL_LTDC_STATE_READY;
1053 
1054   /* Process unlocked */
1055   __HAL_UNLOCK(hltdc);
1056 
1057   return HAL_OK;
1058 }
1059 
1060 /**
1061   * @brief  Disable the color lookup table.
1062   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1063   *                   the configuration information for the LTDC.
1064   * @param  LayerIdx  LTDC Layer index.
1065   *                   This parameter can be one of the following values:
1066   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1067   * @retval  HAL status
1068   */
HAL_LTDC_DisableCLUT(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)1069 HAL_StatusTypeDef HAL_LTDC_DisableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1070 {
1071   /* Check the parameters */
1072   assert_param(IS_LTDC_LAYER(LayerIdx));
1073 
1074   /* Process locked */
1075   __HAL_LOCK(hltdc);
1076 
1077   /* Change LTDC peripheral state */
1078   hltdc->State = HAL_LTDC_STATE_BUSY;
1079 
1080   /* Disable LTDC color lookup table by setting CLUTEN bit */
1081   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_CLUTEN;
1082 
1083   /* Set the Immediate Reload type */
1084   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1085 
1086   /* Change the LTDC state*/
1087   hltdc->State = HAL_LTDC_STATE_READY;
1088 
1089   /* Process unlocked */
1090   __HAL_UNLOCK(hltdc);
1091 
1092   return HAL_OK;
1093 }
1094 
1095 /**
1096   * @brief  Enable Dither.
1097   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
1098   *                the configuration information for the LTDC.
1099   * @retval  HAL status
1100   */
1101 
HAL_LTDC_EnableDither(LTDC_HandleTypeDef * hltdc)1102 HAL_StatusTypeDef HAL_LTDC_EnableDither(LTDC_HandleTypeDef *hltdc)
1103 {
1104   /* Process locked */
1105   __HAL_LOCK(hltdc);
1106 
1107   /* Change LTDC peripheral state */
1108   hltdc->State = HAL_LTDC_STATE_BUSY;
1109 
1110   /* Enable Dither by setting DTEN bit */
1111   LTDC->GCR |= (uint32_t)LTDC_GCR_DEN;
1112 
1113   /* Change the LTDC state*/
1114   hltdc->State = HAL_LTDC_STATE_READY;
1115 
1116   /* Process unlocked */
1117   __HAL_UNLOCK(hltdc);
1118 
1119   return HAL_OK;
1120 }
1121 
1122 /**
1123   * @brief  Disable Dither.
1124   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
1125   *                the configuration information for the LTDC.
1126   * @retval  HAL status
1127   */
1128 
HAL_LTDC_DisableDither(LTDC_HandleTypeDef * hltdc)1129 HAL_StatusTypeDef HAL_LTDC_DisableDither(LTDC_HandleTypeDef *hltdc)
1130 {
1131   /* Process locked */
1132   __HAL_LOCK(hltdc);
1133 
1134   /* Change LTDC peripheral state */
1135   hltdc->State = HAL_LTDC_STATE_BUSY;
1136 
1137   /* Disable Dither by setting DTEN bit */
1138   LTDC->GCR &= ~(uint32_t)LTDC_GCR_DEN;
1139 
1140   /* Change the LTDC state*/
1141   hltdc->State = HAL_LTDC_STATE_READY;
1142 
1143   /* Process unlocked */
1144   __HAL_UNLOCK(hltdc);
1145 
1146   return HAL_OK;
1147 }
1148 
1149 /**
1150   * @brief  Set the LTDC window size.
1151   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1152   *                   the configuration information for the LTDC.
1153   * @param  XSize     LTDC Pixel per line
1154   * @param  YSize     LTDC Line number
1155   * @param  LayerIdx  LTDC Layer index.
1156   *                   This parameter can be one of the following values:
1157   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1158   * @retval  HAL status
1159   */
HAL_LTDC_SetWindowSize(LTDC_HandleTypeDef * hltdc,uint32_t XSize,uint32_t YSize,uint32_t LayerIdx)1160 HAL_StatusTypeDef HAL_LTDC_SetWindowSize(LTDC_HandleTypeDef *hltdc, uint32_t XSize, uint32_t YSize, uint32_t LayerIdx)
1161 {
1162   LTDC_LayerCfgTypeDef *pLayerCfg;
1163 
1164   /* Check the parameters (Layers parameters)*/
1165   assert_param(IS_LTDC_LAYER(LayerIdx));
1166   assert_param(IS_LTDC_CFBLL(XSize));
1167   assert_param(IS_LTDC_CFBLNBR(YSize));
1168 
1169   /* Process locked */
1170   __HAL_LOCK(hltdc);
1171 
1172   /* Change LTDC peripheral state */
1173   hltdc->State = HAL_LTDC_STATE_BUSY;
1174 
1175   /* Get layer configuration from handle structure */
1176   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1177 
1178   /* update horizontal stop */
1179   pLayerCfg->WindowX1 = XSize + pLayerCfg->WindowX0;
1180 
1181   /* update vertical stop */
1182   pLayerCfg->WindowY1 = YSize + pLayerCfg->WindowY0;
1183 
1184   /* Reconfigures the color frame buffer pitch in byte */
1185   pLayerCfg->ImageWidth = XSize;
1186 
1187   /* Reconfigures the frame buffer line number */
1188   pLayerCfg->ImageHeight = YSize;
1189 
1190   /* Set LTDC parameters */
1191   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1192 
1193   /* Set the Immediate Reload type */
1194   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1195 
1196   /* Change the LTDC state*/
1197   hltdc->State = HAL_LTDC_STATE_READY;
1198 
1199   /* Process unlocked */
1200   __HAL_UNLOCK(hltdc);
1201 
1202   return HAL_OK;
1203 }
1204 
1205 /**
1206   * @brief  Set the LTDC window position.
1207   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1208   *                   the configuration information for the LTDC.
1209   * @param  X0        LTDC window X offset
1210   * @param  Y0        LTDC window Y offset
1211   * @param  LayerIdx  LTDC Layer index.
1212   *                         This parameter can be one of the following values:
1213   *                         LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1214   * @retval  HAL status
1215   */
HAL_LTDC_SetWindowPosition(LTDC_HandleTypeDef * hltdc,uint32_t X0,uint32_t Y0,uint32_t LayerIdx)1216 HAL_StatusTypeDef HAL_LTDC_SetWindowPosition(LTDC_HandleTypeDef *hltdc, uint32_t X0, uint32_t Y0, uint32_t LayerIdx)
1217 {
1218   LTDC_LayerCfgTypeDef *pLayerCfg;
1219 
1220   /* Check the parameters */
1221   assert_param(IS_LTDC_LAYER(LayerIdx));
1222   assert_param(IS_LTDC_CFBLL(X0));
1223   assert_param(IS_LTDC_CFBLNBR(Y0));
1224 
1225   /* Process locked */
1226   __HAL_LOCK(hltdc);
1227 
1228   /* Change LTDC peripheral state */
1229   hltdc->State = HAL_LTDC_STATE_BUSY;
1230 
1231   /* Get layer configuration from handle structure */
1232   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1233 
1234   /* update horizontal start/stop */
1235   pLayerCfg->WindowX0 = X0;
1236   pLayerCfg->WindowX1 = X0 + pLayerCfg->ImageWidth;
1237 
1238   /* update vertical start/stop */
1239   pLayerCfg->WindowY0 = Y0;
1240   pLayerCfg->WindowY1 = Y0 + pLayerCfg->ImageHeight;
1241 
1242   /* Set LTDC parameters */
1243   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1244 
1245   /* Set the Immediate Reload type */
1246   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1247 
1248   /* Change the LTDC state*/
1249   hltdc->State = HAL_LTDC_STATE_READY;
1250 
1251   /* Process unlocked */
1252   __HAL_UNLOCK(hltdc);
1253 
1254   return HAL_OK;
1255 }
1256 
1257 /**
1258   * @brief  Reconfigure the pixel format.
1259   * @param  hltdc        pointer to a LTDC_HandleTypeDef structure that contains
1260   *                      the configuration information for the LTDC.
1261   * @param  Pixelformat  new pixel format value.
1262   * @param  LayerIdx     LTDC Layer index.
1263   *                      This parameter can be one of the following values:
1264   *                      LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
1265   * @retval  HAL status
1266   */
HAL_LTDC_SetPixelFormat(LTDC_HandleTypeDef * hltdc,uint32_t Pixelformat,uint32_t LayerIdx)1267 HAL_StatusTypeDef HAL_LTDC_SetPixelFormat(LTDC_HandleTypeDef *hltdc, uint32_t Pixelformat, uint32_t LayerIdx)
1268 {
1269   LTDC_LayerCfgTypeDef *pLayerCfg;
1270 
1271   /* Check the parameters */
1272   assert_param(IS_LTDC_PIXEL_FORMAT(Pixelformat));
1273   assert_param(IS_LTDC_LAYER(LayerIdx));
1274 
1275   /* Process locked */
1276   __HAL_LOCK(hltdc);
1277 
1278   /* Change LTDC peripheral state */
1279   hltdc->State = HAL_LTDC_STATE_BUSY;
1280 
1281   /* Get layer configuration from handle structure */
1282   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1283 
1284   /* Reconfigure the pixel format */
1285   pLayerCfg->PixelFormat = Pixelformat;
1286 
1287   /* Set LTDC parameters */
1288   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1289 
1290   /* Set the Immediate Reload type */
1291   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1292 
1293   /* Change the LTDC state*/
1294   hltdc->State = HAL_LTDC_STATE_READY;
1295 
1296   /* Process unlocked */
1297   __HAL_UNLOCK(hltdc);
1298 
1299   return HAL_OK;
1300 }
1301 
1302 /**
1303   * @brief  Reconfigure the layer alpha value.
1304   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1305   *                   the configuration information for the LTDC.
1306   * @param  Alpha     new alpha value.
1307   * @param  LayerIdx  LTDC Layer index.
1308   *                   This parameter can be one of the following values:
1309   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1310   * @retval  HAL status
1311   */
HAL_LTDC_SetAlpha(LTDC_HandleTypeDef * hltdc,uint32_t Alpha,uint32_t LayerIdx)1312 HAL_StatusTypeDef HAL_LTDC_SetAlpha(LTDC_HandleTypeDef *hltdc, uint32_t Alpha, uint32_t LayerIdx)
1313 {
1314   LTDC_LayerCfgTypeDef *pLayerCfg;
1315 
1316   /* Check the parameters */
1317   assert_param(IS_LTDC_ALPHA(Alpha));
1318   assert_param(IS_LTDC_LAYER(LayerIdx));
1319 
1320   /* Process locked */
1321   __HAL_LOCK(hltdc);
1322 
1323   /* Change LTDC peripheral state */
1324   hltdc->State = HAL_LTDC_STATE_BUSY;
1325 
1326   /* Get layer configuration from handle structure */
1327   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1328 
1329   /* Reconfigure the Alpha value */
1330   pLayerCfg->Alpha = Alpha;
1331 
1332   /* Set LTDC parameters */
1333   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1334 
1335   /* Set the Immediate Reload type */
1336   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1337 
1338   /* Change the LTDC state*/
1339   hltdc->State = HAL_LTDC_STATE_READY;
1340 
1341   /* Process unlocked */
1342   __HAL_UNLOCK(hltdc);
1343 
1344   return HAL_OK;
1345 }
1346 /**
1347   * @brief  Reconfigure the frame buffer Address.
1348   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1349   *                   the configuration information for the LTDC.
1350   * @param  Address   new address value.
1351   * @param  LayerIdx  LTDC Layer index.
1352   *                   This parameter can be one of the following values:
1353   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
1354   * @retval  HAL status
1355   */
HAL_LTDC_SetAddress(LTDC_HandleTypeDef * hltdc,uint32_t Address,uint32_t LayerIdx)1356 HAL_StatusTypeDef HAL_LTDC_SetAddress(LTDC_HandleTypeDef *hltdc, uint32_t Address, uint32_t LayerIdx)
1357 {
1358   LTDC_LayerCfgTypeDef *pLayerCfg;
1359 
1360   /* Check the parameters */
1361   assert_param(IS_LTDC_LAYER(LayerIdx));
1362 
1363   /* Process locked */
1364   __HAL_LOCK(hltdc);
1365 
1366   /* Change LTDC peripheral state */
1367   hltdc->State = HAL_LTDC_STATE_BUSY;
1368 
1369   /* Get layer configuration from handle structure */
1370   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1371 
1372   /* Reconfigure the Address */
1373   pLayerCfg->FBStartAdress = Address;
1374 
1375   /* Set LTDC parameters */
1376   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1377 
1378   /* Set the Immediate Reload type */
1379   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1380 
1381   /* Change the LTDC state*/
1382   hltdc->State = HAL_LTDC_STATE_READY;
1383 
1384   /* Process unlocked */
1385   __HAL_UNLOCK(hltdc);
1386 
1387   return HAL_OK;
1388 }
1389 
1390 /**
1391   * @brief  Function used to reconfigure the pitch for specific cases where the attached LayerIdx buffer have a width
1392   *         that is larger than the one intended to be displayed on screen. Example of a buffer 800x480 attached to
1393   *         layer for which we want to read and display on screen only a portion 320x240 taken in the center
1394   *         of the buffer.
1395   *         The pitch in pixels will be in that case 800 pixels and not 320 pixels as initially configured by previous
1396   *         call to HAL_LTDC_ConfigLayer().
1397   * @note   This function should be called only after a previous call to HAL_LTDC_ConfigLayer() to modify the default
1398   *         pitch configured by HAL_LTDC_ConfigLayer() when required (refer to example described just above).
1399   * @param  hltdc              pointer to a LTDC_HandleTypeDef structure that contains
1400   *                            the configuration information for the LTDC.
1401   * @param  LinePitchInPixels  New line pitch in pixels to configure for LTDC layer 'LayerIdx'.
1402   * @param  LayerIdx           LTDC layer index concerned by the modification of line pitch.
1403   * @retval HAL status
1404   */
HAL_LTDC_SetPitch(LTDC_HandleTypeDef * hltdc,uint32_t LinePitchInPixels,uint32_t LayerIdx)1405 HAL_StatusTypeDef HAL_LTDC_SetPitch(LTDC_HandleTypeDef *hltdc, uint32_t LinePitchInPixels, uint32_t LayerIdx)
1406 {
1407   uint32_t tmp;
1408   uint32_t pitchUpdate;
1409   uint32_t pixelFormat;
1410 
1411   /* Check the parameters */
1412   assert_param(IS_LTDC_LAYER(LayerIdx));
1413 
1414   /* Process locked */
1415   __HAL_LOCK(hltdc);
1416 
1417   /* Change LTDC peripheral state */
1418   hltdc->State = HAL_LTDC_STATE_BUSY;
1419 
1420   /* get LayerIdx used pixel format */
1421   pixelFormat = hltdc->LayerCfg[LayerIdx].PixelFormat;
1422 
1423   if (pixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
1424   {
1425     tmp = 4U;
1426   }
1427   else if (pixelFormat == LTDC_PIXEL_FORMAT_RGB888)
1428   {
1429     tmp = 3U;
1430   }
1431   else if ((pixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
1432            (pixelFormat == LTDC_PIXEL_FORMAT_RGB565)   || \
1433            (pixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
1434            (pixelFormat == LTDC_PIXEL_FORMAT_AL88))
1435   {
1436     tmp = 2U;
1437   }
1438   else
1439   {
1440     tmp = 1U;
1441   }
1442 
1443   pitchUpdate = ((LinePitchInPixels * tmp) << 16U);
1444 
1445   /* Clear previously set standard pitch */
1446   LTDC_LAYER(hltdc, LayerIdx)->CFBLR &= ~LTDC_LxCFBLR_CFBP;
1447 
1448   /* Set the Reload type as immediate update of LTDC pitch configured above */
1449   LTDC->SRCR |= LTDC_SRCR_IMR;
1450 
1451   /* Set new line pitch value */
1452   LTDC_LAYER(hltdc, LayerIdx)->CFBLR |= pitchUpdate;
1453 
1454   /* Set the Reload type as immediate update of LTDC pitch configured above */
1455   LTDC->SRCR |= LTDC_SRCR_IMR;
1456 
1457   /* Change the LTDC state*/
1458   hltdc->State = HAL_LTDC_STATE_READY;
1459 
1460   /* Process unlocked */
1461   __HAL_UNLOCK(hltdc);
1462 
1463   return HAL_OK;
1464 }
1465 
1466 /**
1467   * @brief  Define the position of the line interrupt.
1468   * @param  hltdc   pointer to a LTDC_HandleTypeDef structure that contains
1469   *                 the configuration information for the LTDC.
1470   * @param  Line    Line Interrupt Position.
1471   * @note   User application may resort to HAL_LTDC_LineEventCallback() at line interrupt generation.
1472   * @retval  HAL status
1473   */
HAL_LTDC_ProgramLineEvent(LTDC_HandleTypeDef * hltdc,uint32_t Line)1474 HAL_StatusTypeDef HAL_LTDC_ProgramLineEvent(LTDC_HandleTypeDef *hltdc, uint32_t Line)
1475 {
1476   /* Check the parameters */
1477   assert_param(IS_LTDC_LIPOS(Line));
1478 
1479   /* Process locked */
1480   __HAL_LOCK(hltdc);
1481 
1482   /* Change LTDC peripheral state */
1483   hltdc->State = HAL_LTDC_STATE_BUSY;
1484 
1485   /* Disable the Line interrupt */
1486   __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_LI);
1487 
1488   /* Set the Line Interrupt position */
1489   LTDC->LIPCR = (uint32_t)Line;
1490 
1491   /* Enable the Line interrupt */
1492   __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_LI);
1493 
1494   /* Change the LTDC state*/
1495   hltdc->State = HAL_LTDC_STATE_READY;
1496 
1497   /* Process unlocked */
1498   __HAL_UNLOCK(hltdc);
1499 
1500   return HAL_OK;
1501 }
1502 
1503 /**
1504   * @brief  Reload LTDC Layers configuration.
1505   * @param  hltdc      pointer to a LTDC_HandleTypeDef structure that contains
1506   *                    the configuration information for the LTDC.
1507   * @param  ReloadType This parameter can be one of the following values :
1508   *                      LTDC_RELOAD_IMMEDIATE : Immediate Reload
1509   *                      LTDC_RELOAD_VERTICAL_BLANKING  : Reload in the next Vertical Blanking
1510   * @note   User application may resort to HAL_LTDC_ReloadEventCallback() at reload interrupt generation.
1511   * @retval  HAL status
1512   */
HAL_LTDC_Reload(LTDC_HandleTypeDef * hltdc,uint32_t ReloadType)1513 HAL_StatusTypeDef  HAL_LTDC_Reload(LTDC_HandleTypeDef *hltdc, uint32_t ReloadType)
1514 {
1515   /* Check the parameters */
1516   assert_param(IS_LTDC_RELOAD(ReloadType));
1517 
1518   /* Process locked */
1519   __HAL_LOCK(hltdc);
1520 
1521   /* Change LTDC peripheral state */
1522   hltdc->State = HAL_LTDC_STATE_BUSY;
1523 
1524   /* Enable the Reload interrupt */
1525   __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_RR);
1526 
1527   /* Apply Reload type */
1528   hltdc->Instance->SRCR = ReloadType;
1529 
1530   /* Change the LTDC state*/
1531   hltdc->State = HAL_LTDC_STATE_READY;
1532 
1533   /* Process unlocked */
1534   __HAL_UNLOCK(hltdc);
1535 
1536   return HAL_OK;
1537 }
1538 
1539 /**
1540   * @brief  Configure the LTDC Layer according to the specified without reloading
1541   *         parameters in the LTDC_InitTypeDef and create the associated handle.
1542   *         Variant of the function HAL_LTDC_ConfigLayer without immediate reload.
1543   * @param  hltdc      pointer to a LTDC_HandleTypeDef structure that contains
1544   *                    the configuration information for the LTDC.
1545   * @param  pLayerCfg  pointer to a LTDC_LayerCfgTypeDef structure that contains
1546   *                    the configuration information for the Layer.
1547   * @param  LayerIdx   LTDC Layer index.
1548   *                    This parameter can be one of the following values:
1549   *                    LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1550   * @retval HAL status
1551   */
HAL_LTDC_ConfigLayer_NoReload(LTDC_HandleTypeDef * hltdc,LTDC_LayerCfgTypeDef * pLayerCfg,uint32_t LayerIdx)1552 HAL_StatusTypeDef HAL_LTDC_ConfigLayer_NoReload(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg,
1553                                                 uint32_t LayerIdx)
1554 {
1555   /* Check the parameters */
1556   assert_param(IS_LTDC_LAYER(LayerIdx));
1557   assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));
1558   assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));
1559   assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));
1560   assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));
1561   assert_param(IS_LTDC_PIXEL_FORMAT(pLayerCfg->PixelFormat));
1562   assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha));
1563   assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha0));
1564   assert_param(IS_LTDC_BLENDING_FACTOR1(pLayerCfg->BlendingFactor1));
1565   assert_param(IS_LTDC_BLENDING_FACTOR2(pLayerCfg->BlendingFactor2));
1566   assert_param(IS_LTDC_CFBLL(pLayerCfg->ImageWidth));
1567   assert_param(IS_LTDC_CFBLNBR(pLayerCfg->ImageHeight));
1568 
1569   /* Process locked */
1570   __HAL_LOCK(hltdc);
1571 
1572   /* Change LTDC peripheral state */
1573   hltdc->State = HAL_LTDC_STATE_BUSY;
1574 
1575   /* Copy new layer configuration into handle structure */
1576   hltdc->LayerCfg[LayerIdx] = *pLayerCfg;
1577 
1578   /* Configure the LTDC Layer */
1579   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1580 
1581   /* Initialize the LTDC state*/
1582   hltdc->State  = HAL_LTDC_STATE_READY;
1583 
1584   /* Process unlocked */
1585   __HAL_UNLOCK(hltdc);
1586 
1587   return HAL_OK;
1588 }
1589 
1590 /**
1591   * @brief  Set the LTDC window size without reloading.
1592   *         Variant of the function HAL_LTDC_SetWindowSize without immediate reload.
1593   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1594   *                   the configuration information for the LTDC.
1595   * @param  XSize     LTDC Pixel per line
1596   * @param  YSize     LTDC Line number
1597   * @param  LayerIdx  LTDC Layer index.
1598   *                   This parameter can be one of the following values:
1599   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1600   * @retval  HAL status
1601   */
HAL_LTDC_SetWindowSize_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t XSize,uint32_t YSize,uint32_t LayerIdx)1602 HAL_StatusTypeDef HAL_LTDC_SetWindowSize_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t XSize, uint32_t YSize,
1603                                                   uint32_t LayerIdx)
1604 {
1605   LTDC_LayerCfgTypeDef *pLayerCfg;
1606 
1607   /* Check the parameters (Layers parameters)*/
1608   assert_param(IS_LTDC_LAYER(LayerIdx));
1609   assert_param(IS_LTDC_CFBLL(XSize));
1610   assert_param(IS_LTDC_CFBLNBR(YSize));
1611 
1612   /* Process locked */
1613   __HAL_LOCK(hltdc);
1614 
1615   /* Change LTDC peripheral state */
1616   hltdc->State = HAL_LTDC_STATE_BUSY;
1617 
1618   /* Get layer configuration from handle structure */
1619   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1620 
1621   /* update horizontal stop */
1622   pLayerCfg->WindowX1 = XSize + pLayerCfg->WindowX0;
1623 
1624   /* update vertical stop */
1625   pLayerCfg->WindowY1 = YSize + pLayerCfg->WindowY0;
1626 
1627   /* Reconfigures the color frame buffer pitch in byte */
1628   pLayerCfg->ImageWidth = XSize;
1629 
1630   /* Reconfigures the frame buffer line number */
1631   pLayerCfg->ImageHeight = YSize;
1632 
1633   /* Set LTDC parameters */
1634   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1635 
1636   /* Change the LTDC state*/
1637   hltdc->State = HAL_LTDC_STATE_READY;
1638 
1639   /* Process unlocked */
1640   __HAL_UNLOCK(hltdc);
1641 
1642   return HAL_OK;
1643 }
1644 
1645 /**
1646   * @brief  Set the LTDC window position without reloading.
1647   *         Variant of the function HAL_LTDC_SetWindowPosition without immediate reload.
1648   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1649   *                   the configuration information for the LTDC.
1650   * @param  X0        LTDC window X offset
1651   * @param  Y0        LTDC window Y offset
1652   * @param  LayerIdx  LTDC Layer index.
1653   *                         This parameter can be one of the following values:
1654   *                         LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1655   * @retval  HAL status
1656   */
HAL_LTDC_SetWindowPosition_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t X0,uint32_t Y0,uint32_t LayerIdx)1657 HAL_StatusTypeDef HAL_LTDC_SetWindowPosition_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t X0, uint32_t Y0,
1658                                                       uint32_t LayerIdx)
1659 {
1660   LTDC_LayerCfgTypeDef *pLayerCfg;
1661 
1662   /* Check the parameters */
1663   assert_param(IS_LTDC_LAYER(LayerIdx));
1664   assert_param(IS_LTDC_CFBLL(X0));
1665   assert_param(IS_LTDC_CFBLNBR(Y0));
1666 
1667   /* Process locked */
1668   __HAL_LOCK(hltdc);
1669 
1670   /* Change LTDC peripheral state */
1671   hltdc->State = HAL_LTDC_STATE_BUSY;
1672 
1673   /* Get layer configuration from handle structure */
1674   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1675 
1676   /* update horizontal start/stop */
1677   pLayerCfg->WindowX0 = X0;
1678   pLayerCfg->WindowX1 = X0 + pLayerCfg->ImageWidth;
1679 
1680   /* update vertical start/stop */
1681   pLayerCfg->WindowY0 = Y0;
1682   pLayerCfg->WindowY1 = Y0 + pLayerCfg->ImageHeight;
1683 
1684   /* Set LTDC parameters */
1685   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1686 
1687   /* Change the LTDC state*/
1688   hltdc->State = HAL_LTDC_STATE_READY;
1689 
1690   /* Process unlocked */
1691   __HAL_UNLOCK(hltdc);
1692 
1693   return HAL_OK;
1694 }
1695 
1696 /**
1697   * @brief  Reconfigure the pixel format without reloading.
1698   *         Variant of the function HAL_LTDC_SetPixelFormat without immediate reload.
1699   * @param  hltdc        pointer to a LTDC_HandleTypeDfef structure that contains
1700   *                      the configuration information for the LTDC.
1701   * @param  Pixelformat  new pixel format value.
1702   * @param  LayerIdx     LTDC Layer index.
1703   *                      This parameter can be one of the following values:
1704   *                      LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
1705   * @retval  HAL status
1706   */
HAL_LTDC_SetPixelFormat_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t Pixelformat,uint32_t LayerIdx)1707 HAL_StatusTypeDef HAL_LTDC_SetPixelFormat_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Pixelformat, uint32_t LayerIdx)
1708 {
1709   LTDC_LayerCfgTypeDef *pLayerCfg;
1710 
1711   /* Check the parameters */
1712   assert_param(IS_LTDC_PIXEL_FORMAT(Pixelformat));
1713   assert_param(IS_LTDC_LAYER(LayerIdx));
1714 
1715   /* Process locked */
1716   __HAL_LOCK(hltdc);
1717 
1718   /* Change LTDC peripheral state */
1719   hltdc->State = HAL_LTDC_STATE_BUSY;
1720 
1721   /* Get layer configuration from handle structure */
1722   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1723 
1724   /* Reconfigure the pixel format */
1725   pLayerCfg->PixelFormat = Pixelformat;
1726 
1727   /* Set LTDC parameters */
1728   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1729 
1730   /* Change the LTDC state*/
1731   hltdc->State = HAL_LTDC_STATE_READY;
1732 
1733   /* Process unlocked */
1734   __HAL_UNLOCK(hltdc);
1735 
1736   return HAL_OK;
1737 }
1738 
1739 /**
1740   * @brief  Reconfigure the layer alpha value without reloading.
1741   *         Variant of the function HAL_LTDC_SetAlpha without immediate reload.
1742   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1743   *                   the configuration information for the LTDC.
1744   * @param  Alpha     new alpha value.
1745   * @param  LayerIdx  LTDC Layer index.
1746   *                   This parameter can be one of the following values:
1747   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1748   * @retval  HAL status
1749   */
HAL_LTDC_SetAlpha_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t Alpha,uint32_t LayerIdx)1750 HAL_StatusTypeDef HAL_LTDC_SetAlpha_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Alpha, uint32_t LayerIdx)
1751 {
1752   LTDC_LayerCfgTypeDef *pLayerCfg;
1753 
1754   /* Check the parameters */
1755   assert_param(IS_LTDC_ALPHA(Alpha));
1756   assert_param(IS_LTDC_LAYER(LayerIdx));
1757 
1758   /* Process locked */
1759   __HAL_LOCK(hltdc);
1760 
1761   /* Change LTDC peripheral state */
1762   hltdc->State = HAL_LTDC_STATE_BUSY;
1763 
1764   /* Get layer configuration from handle structure */
1765   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1766 
1767   /* Reconfigure the Alpha value */
1768   pLayerCfg->Alpha = Alpha;
1769 
1770   /* Set LTDC parameters */
1771   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1772 
1773   /* Change the LTDC state*/
1774   hltdc->State = HAL_LTDC_STATE_READY;
1775 
1776   /* Process unlocked */
1777   __HAL_UNLOCK(hltdc);
1778 
1779   return HAL_OK;
1780 }
1781 
1782 /**
1783   * @brief  Reconfigure the frame buffer Address without reloading.
1784   *         Variant of the function HAL_LTDC_SetAddress without immediate reload.
1785   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1786   *                   the configuration information for the LTDC.
1787   * @param  Address   new address value.
1788   * @param  LayerIdx  LTDC Layer index.
1789   *                   This parameter can be one of the following values:
1790   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
1791   * @retval  HAL status
1792   */
HAL_LTDC_SetAddress_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t Address,uint32_t LayerIdx)1793 HAL_StatusTypeDef HAL_LTDC_SetAddress_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Address, uint32_t LayerIdx)
1794 {
1795   LTDC_LayerCfgTypeDef *pLayerCfg;
1796 
1797   /* Check the parameters */
1798   assert_param(IS_LTDC_LAYER(LayerIdx));
1799 
1800   /* Process locked */
1801   __HAL_LOCK(hltdc);
1802 
1803   /* Change LTDC peripheral state */
1804   hltdc->State = HAL_LTDC_STATE_BUSY;
1805 
1806   /* Get layer configuration from handle structure */
1807   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1808 
1809   /* Reconfigure the Address */
1810   pLayerCfg->FBStartAdress = Address;
1811 
1812   /* Set LTDC parameters */
1813   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1814 
1815   /* Change the LTDC state*/
1816   hltdc->State = HAL_LTDC_STATE_READY;
1817 
1818   /* Process unlocked */
1819   __HAL_UNLOCK(hltdc);
1820 
1821   return HAL_OK;
1822 }
1823 
1824 /**
1825   * @brief  Function used to reconfigure the pitch for specific cases where the attached LayerIdx buffer have a width
1826   *         that is larger than the one intended to be displayed on screen. Example of a buffer 800x480 attached to
1827   *         layer for which we want to read and display on screen only a portion 320x240 taken in the center
1828   *         of the buffer.
1829   *         The pitch in pixels will be in that case 800 pixels and not 320 pixels as initially configured by
1830   *         previous call to HAL_LTDC_ConfigLayer().
1831   * @note   This function should be called only after a previous call to HAL_LTDC_ConfigLayer() to modify the default
1832   *         pitch configured by HAL_LTDC_ConfigLayer() when required (refer to example described just above).
1833   *         Variant of the function HAL_LTDC_SetPitch without immediate reload.
1834   * @param  hltdc              pointer to a LTDC_HandleTypeDef structure that contains
1835   *                            the configuration information for the LTDC.
1836   * @param  LinePitchInPixels  New line pitch in pixels to configure for LTDC layer 'LayerIdx'.
1837   * @param  LayerIdx           LTDC layer index concerned by the modification of line pitch.
1838   * @retval HAL status
1839   */
HAL_LTDC_SetPitch_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t LinePitchInPixels,uint32_t LayerIdx)1840 HAL_StatusTypeDef HAL_LTDC_SetPitch_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LinePitchInPixels, uint32_t LayerIdx)
1841 {
1842   uint32_t tmp;
1843   uint32_t pitchUpdate;
1844   uint32_t pixelFormat;
1845 
1846   /* Check the parameters */
1847   assert_param(IS_LTDC_LAYER(LayerIdx));
1848 
1849   /* Process locked */
1850   __HAL_LOCK(hltdc);
1851 
1852   /* Change LTDC peripheral state */
1853   hltdc->State = HAL_LTDC_STATE_BUSY;
1854 
1855   /* get LayerIdx used pixel format */
1856   pixelFormat = hltdc->LayerCfg[LayerIdx].PixelFormat;
1857 
1858   if (pixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
1859   {
1860     tmp = 4U;
1861   }
1862   else if (pixelFormat == LTDC_PIXEL_FORMAT_RGB888)
1863   {
1864     tmp = 3U;
1865   }
1866   else if ((pixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
1867            (pixelFormat == LTDC_PIXEL_FORMAT_RGB565)   || \
1868            (pixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
1869            (pixelFormat == LTDC_PIXEL_FORMAT_AL88))
1870   {
1871     tmp = 2U;
1872   }
1873   else
1874   {
1875     tmp = 1U;
1876   }
1877 
1878   pitchUpdate = ((LinePitchInPixels * tmp) << 16U);
1879 
1880   /* Clear previously set standard pitch */
1881   LTDC_LAYER(hltdc, LayerIdx)->CFBLR &= ~LTDC_LxCFBLR_CFBP;
1882 
1883   /* Set new line pitch value */
1884   LTDC_LAYER(hltdc, LayerIdx)->CFBLR |= pitchUpdate;
1885 
1886   /* Change the LTDC state*/
1887   hltdc->State = HAL_LTDC_STATE_READY;
1888 
1889   /* Process unlocked */
1890   __HAL_UNLOCK(hltdc);
1891 
1892   return HAL_OK;
1893 }
1894 
1895 
1896 /**
1897   * @brief  Configure the color keying without reloading.
1898   *         Variant of the function HAL_LTDC_ConfigColorKeying without immediate reload.
1899   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1900   *                   the configuration information for the LTDC.
1901   * @param  RGBValue the color key value
1902   * @param  LayerIdx  LTDC Layer index.
1903   *                   This parameter can be one of the following values:
1904   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1905   * @retval HAL status
1906   */
HAL_LTDC_ConfigColorKeying_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t RGBValue,uint32_t LayerIdx)1907 HAL_StatusTypeDef HAL_LTDC_ConfigColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t RGBValue, uint32_t LayerIdx)
1908 {
1909   /* Check the parameters */
1910   assert_param(IS_LTDC_LAYER(LayerIdx));
1911 
1912   /* Process locked */
1913   __HAL_LOCK(hltdc);
1914 
1915   /* Change LTDC peripheral state */
1916   hltdc->State = HAL_LTDC_STATE_BUSY;
1917 
1918   /* Configure the default color values */
1919   LTDC_LAYER(hltdc, LayerIdx)->CKCR &=  ~(LTDC_LxCKCR_CKBLUE | LTDC_LxCKCR_CKGREEN | LTDC_LxCKCR_CKRED);
1920   LTDC_LAYER(hltdc, LayerIdx)->CKCR  = RGBValue;
1921 
1922   /* Change the LTDC state*/
1923   hltdc->State = HAL_LTDC_STATE_READY;
1924 
1925   /* Process unlocked */
1926   __HAL_UNLOCK(hltdc);
1927 
1928   return HAL_OK;
1929 }
1930 
1931 /**
1932   * @brief  Enable the color keying without reloading.
1933   *         Variant of the function HAL_LTDC_EnableColorKeying without immediate reload.
1934   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1935   *                   the configuration information for the LTDC.
1936   * @param  LayerIdx  LTDC Layer index.
1937   *                   This parameter can be one of the following values:
1938   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1939   * @retval  HAL status
1940   */
HAL_LTDC_EnableColorKeying_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)1941 HAL_StatusTypeDef HAL_LTDC_EnableColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1942 {
1943   /* Check the parameters */
1944   assert_param(IS_LTDC_LAYER(LayerIdx));
1945 
1946   /* Process locked */
1947   __HAL_LOCK(hltdc);
1948 
1949   /* Change LTDC peripheral state */
1950   hltdc->State = HAL_LTDC_STATE_BUSY;
1951 
1952   /* Enable LTDC color keying by setting COLKEN bit */
1953   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_COLKEN;
1954 
1955   /* Change the LTDC state*/
1956   hltdc->State = HAL_LTDC_STATE_READY;
1957 
1958   /* Process unlocked */
1959   __HAL_UNLOCK(hltdc);
1960 
1961   return HAL_OK;
1962 }
1963 
1964 /**
1965   * @brief  Disable the color keying without reloading.
1966   *         Variant of the function HAL_LTDC_DisableColorKeying without immediate reload.
1967   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1968   *                   the configuration information for the LTDC.
1969   * @param  LayerIdx  LTDC Layer index.
1970   *                   This parameter can be one of the following values:
1971   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1972   * @retval  HAL status
1973   */
HAL_LTDC_DisableColorKeying_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)1974 HAL_StatusTypeDef HAL_LTDC_DisableColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1975 {
1976   /* Check the parameters */
1977   assert_param(IS_LTDC_LAYER(LayerIdx));
1978 
1979   /* Process locked */
1980   __HAL_LOCK(hltdc);
1981 
1982   /* Change LTDC peripheral state */
1983   hltdc->State = HAL_LTDC_STATE_BUSY;
1984 
1985   /* Disable LTDC color keying by setting COLKEN bit */
1986   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_COLKEN;
1987 
1988   /* Change the LTDC state*/
1989   hltdc->State = HAL_LTDC_STATE_READY;
1990 
1991   /* Process unlocked */
1992   __HAL_UNLOCK(hltdc);
1993 
1994   return HAL_OK;
1995 }
1996 
1997 /**
1998   * @brief  Enable the color lookup table without reloading.
1999   *         Variant of the function HAL_LTDC_EnableCLUT without immediate reload.
2000   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
2001   *                   the configuration information for the LTDC.
2002   * @param  LayerIdx  LTDC Layer index.
2003   *                   This parameter can be one of the following values:
2004   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
2005   * @retval  HAL status
2006   */
HAL_LTDC_EnableCLUT_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)2007 HAL_StatusTypeDef HAL_LTDC_EnableCLUT_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
2008 {
2009   /* Check the parameters */
2010   assert_param(IS_LTDC_LAYER(LayerIdx));
2011 
2012   /* Process locked */
2013   __HAL_LOCK(hltdc);
2014 
2015   /* Change LTDC peripheral state */
2016   hltdc->State = HAL_LTDC_STATE_BUSY;
2017 
2018   /* Disable LTDC color lookup table by setting CLUTEN bit */
2019   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_CLUTEN;
2020 
2021   /* Change the LTDC state*/
2022   hltdc->State = HAL_LTDC_STATE_READY;
2023 
2024   /* Process unlocked */
2025   __HAL_UNLOCK(hltdc);
2026 
2027   return HAL_OK;
2028 }
2029 
2030 /**
2031   * @brief  Disable the color lookup table without reloading.
2032   *         Variant of the function HAL_LTDC_DisableCLUT without immediate reload.
2033   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
2034   *                   the configuration information for the LTDC.
2035   * @param  LayerIdx  LTDC Layer index.
2036   *                   This parameter can be one of the following values:
2037   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
2038   * @retval  HAL status
2039   */
HAL_LTDC_DisableCLUT_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)2040 HAL_StatusTypeDef HAL_LTDC_DisableCLUT_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
2041 {
2042   /* Check the parameters */
2043   assert_param(IS_LTDC_LAYER(LayerIdx));
2044 
2045   /* Process locked */
2046   __HAL_LOCK(hltdc);
2047 
2048   /* Change LTDC peripheral state */
2049   hltdc->State = HAL_LTDC_STATE_BUSY;
2050 
2051   /* Disable LTDC color lookup table by setting CLUTEN bit */
2052   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_CLUTEN;
2053 
2054   /* Change the LTDC state*/
2055   hltdc->State = HAL_LTDC_STATE_READY;
2056 
2057   /* Process unlocked */
2058   __HAL_UNLOCK(hltdc);
2059 
2060   return HAL_OK;
2061 }
2062 
2063 /**
2064   * @}
2065   */
2066 
2067 /** @defgroup LTDC_Exported_Functions_Group4 Peripheral State and Errors functions
2068   *  @brief    Peripheral State and Errors functions
2069   *
2070 @verbatim
2071  ===============================================================================
2072                   ##### Peripheral State and Errors functions #####
2073  ===============================================================================
2074     [..]
2075     This subsection provides functions allowing to
2076       (+) Check the LTDC handle state.
2077       (+) Get the LTDC handle error code.
2078 
2079 @endverbatim
2080   * @{
2081   */
2082 
2083 /**
2084   * @brief  Return the LTDC handle state.
2085   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
2086   *                the configuration information for the LTDC.
2087   * @retval HAL state
2088   */
HAL_LTDC_GetState(LTDC_HandleTypeDef * hltdc)2089 HAL_LTDC_StateTypeDef HAL_LTDC_GetState(LTDC_HandleTypeDef *hltdc)
2090 {
2091   return hltdc->State;
2092 }
2093 
2094 /**
2095   * @brief  Return the LTDC handle error code.
2096   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
2097   *               the configuration information for the LTDC.
2098   * @retval LTDC Error Code
2099   */
HAL_LTDC_GetError(LTDC_HandleTypeDef * hltdc)2100 uint32_t HAL_LTDC_GetError(LTDC_HandleTypeDef *hltdc)
2101 {
2102   return hltdc->ErrorCode;
2103 }
2104 
2105 /**
2106   * @}
2107   */
2108 
2109 /**
2110   * @}
2111   */
2112 
2113 /** @defgroup LTDC_Private_Functions LTDC Private Functions
2114   * @{
2115   */
2116 
2117 /**
2118   * @brief  Configure the LTDC peripheral
2119   * @param  hltdc     Pointer to a LTDC_HandleTypeDef structure that contains
2120   *                   the configuration information for the LTDC.
2121   * @param  pLayerCfg Pointer LTDC Layer Configuration structure
2122   * @param  LayerIdx  LTDC Layer index.
2123   *                   This parameter can be one of the following values: LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
2124   * @retval None
2125   */
LTDC_SetConfig(LTDC_HandleTypeDef * hltdc,LTDC_LayerCfgTypeDef * pLayerCfg,uint32_t LayerIdx)2126 static void LTDC_SetConfig(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)
2127 {
2128   uint32_t tmp;
2129   uint32_t tmp1;
2130   uint32_t tmp2;
2131 
2132   /* Configure the horizontal start and stop position */
2133   tmp = ((pLayerCfg->WindowX1 + ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16U)) << 16U);
2134   LTDC_LAYER(hltdc, LayerIdx)->WHPCR &= ~(LTDC_LxWHPCR_WHSTPOS | LTDC_LxWHPCR_WHSPPOS);
2135   LTDC_LAYER(hltdc, LayerIdx)->WHPCR = ((pLayerCfg->WindowX0 + \
2136                                          ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16U) + 1U) | tmp);
2137 
2138   /* Configure the vertical start and stop position */
2139   tmp = ((pLayerCfg->WindowY1 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP)) << 16U);
2140   LTDC_LAYER(hltdc, LayerIdx)->WVPCR &= ~(LTDC_LxWVPCR_WVSTPOS | LTDC_LxWVPCR_WVSPPOS);
2141   LTDC_LAYER(hltdc, LayerIdx)->WVPCR  = ((pLayerCfg->WindowY0 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP) + 1U) | tmp);
2142 
2143   /* Specifies the pixel format */
2144   LTDC_LAYER(hltdc, LayerIdx)->PFCR &= ~(LTDC_LxPFCR_PF);
2145   LTDC_LAYER(hltdc, LayerIdx)->PFCR = (pLayerCfg->PixelFormat);
2146 
2147   /* Configure the default color values */
2148   tmp = ((uint32_t)(pLayerCfg->Backcolor.Green) << 8U);
2149   tmp1 = ((uint32_t)(pLayerCfg->Backcolor.Red) << 16U);
2150   tmp2 = (pLayerCfg->Alpha0 << 24U);
2151   LTDC_LAYER(hltdc, LayerIdx)->DCCR &= ~(LTDC_LxDCCR_DCBLUE | LTDC_LxDCCR_DCGREEN | LTDC_LxDCCR_DCRED |
2152                                          LTDC_LxDCCR_DCALPHA);
2153   LTDC_LAYER(hltdc, LayerIdx)->DCCR = (pLayerCfg->Backcolor.Blue | tmp | tmp1 | tmp2);
2154 
2155   /* Specifies the constant alpha value */
2156   LTDC_LAYER(hltdc, LayerIdx)->CACR &= ~(LTDC_LxCACR_CONSTA);
2157   LTDC_LAYER(hltdc, LayerIdx)->CACR = (pLayerCfg->Alpha);
2158 
2159   /* Specifies the blending factors */
2160   LTDC_LAYER(hltdc, LayerIdx)->BFCR &= ~(LTDC_LxBFCR_BF2 | LTDC_LxBFCR_BF1);
2161   LTDC_LAYER(hltdc, LayerIdx)->BFCR = (pLayerCfg->BlendingFactor1 | pLayerCfg->BlendingFactor2);
2162 
2163   /* Configure the color frame buffer start address */
2164   LTDC_LAYER(hltdc, LayerIdx)->CFBAR &= ~(LTDC_LxCFBAR_CFBADD);
2165   LTDC_LAYER(hltdc, LayerIdx)->CFBAR = (pLayerCfg->FBStartAdress);
2166 
2167   if (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
2168   {
2169     tmp = 4U;
2170   }
2171   else if (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
2172   {
2173     tmp = 3U;
2174   }
2175   else if ((pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
2176            (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB565)   || \
2177            (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
2178            (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_AL88))
2179   {
2180     tmp = 2U;
2181   }
2182   else
2183   {
2184     tmp = 1U;
2185   }
2186 
2187   /* Configure the color frame buffer pitch in byte */
2188   LTDC_LAYER(hltdc, LayerIdx)->CFBLR  &= ~(LTDC_LxCFBLR_CFBLL | LTDC_LxCFBLR_CFBP);
2189   LTDC_LAYER(hltdc, LayerIdx)->CFBLR  = (((pLayerCfg->ImageWidth * tmp) << 16U) | \
2190                                          (((pLayerCfg->WindowX1 - pLayerCfg->WindowX0) * tmp)  + 3U));
2191   /* Configure the frame buffer line number */
2192   LTDC_LAYER(hltdc, LayerIdx)->CFBLNR  &= ~(LTDC_LxCFBLNR_CFBLNBR);
2193   LTDC_LAYER(hltdc, LayerIdx)->CFBLNR  = (pLayerCfg->ImageHeight);
2194 
2195   /* Enable LTDC_Layer by setting LEN bit */
2196   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_LEN;
2197 }
2198 
2199 /**
2200   * @}
2201   */
2202 
2203 
2204 /**
2205   * @}
2206   */
2207 
2208 #endif /* LTDC */
2209 
2210 #endif /* HAL_LTDC_MODULE_ENABLED */
2211 
2212 /**
2213   * @}
2214   */
2215