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