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,const uint32_t * pCLUT,uint32_t CLUTSize,uint32_t LayerIdx)919 HAL_StatusTypeDef HAL_LTDC_ConfigCLUT(LTDC_HandleTypeDef *hltdc, const uint32_t *pCLUT, uint32_t CLUTSize,
920                                       uint32_t LayerIdx)
921 {
922   uint32_t tmp;
923   uint32_t counter;
924   const uint32_t *pcolorlut = pCLUT;
925   /* Check the parameters */
926   assert_param(IS_LTDC_LAYER(LayerIdx));
927 
928   /* Process locked */
929   __HAL_LOCK(hltdc);
930 
931   /* Change LTDC peripheral state */
932   hltdc->State = HAL_LTDC_STATE_BUSY;
933 
934   for (counter = 0U; (counter < CLUTSize); counter++)
935   {
936     if (hltdc->LayerCfg[LayerIdx].PixelFormat == LTDC_PIXEL_FORMAT_AL44)
937     {
938       tmp  = (((counter + (16U * counter)) << 24U) | ((uint32_t)(*pcolorlut) & 0xFFU) | \
939               ((uint32_t)(*pcolorlut) & 0xFF00U) | ((uint32_t)(*pcolorlut) & 0xFF0000U));
940     }
941     else
942     {
943       tmp  = ((counter << 24U) | ((uint32_t)(*pcolorlut) & 0xFFU) | \
944               ((uint32_t)(*pcolorlut) & 0xFF00U) | ((uint32_t)(*pcolorlut) & 0xFF0000U));
945     }
946 
947     pcolorlut++;
948 
949     /* Specifies the C-LUT address and RGB value */
950     LTDC_LAYER(hltdc, LayerIdx)->CLUTWR  = tmp;
951   }
952 
953   /* Change the LTDC state*/
954   hltdc->State = HAL_LTDC_STATE_READY;
955 
956   /* Process unlocked */
957   __HAL_UNLOCK(hltdc);
958 
959   return HAL_OK;
960 }
961 
962 /**
963   * @brief  Enable the color keying.
964   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
965   *                   the configuration information for the LTDC.
966   * @param  LayerIdx  LTDC Layer index.
967   *                   This parameter can be one of the following values:
968   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
969   * @retval  HAL status
970   */
HAL_LTDC_EnableColorKeying(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)971 HAL_StatusTypeDef HAL_LTDC_EnableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
972 {
973   /* Check the parameters */
974   assert_param(IS_LTDC_LAYER(LayerIdx));
975 
976   /* Process locked */
977   __HAL_LOCK(hltdc);
978 
979   /* Change LTDC peripheral state */
980   hltdc->State = HAL_LTDC_STATE_BUSY;
981 
982   /* Enable LTDC color keying by setting COLKEN bit */
983   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_COLKEN;
984 
985   /* Set the Immediate Reload type */
986   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
987 
988   /* Change the LTDC state*/
989   hltdc->State = HAL_LTDC_STATE_READY;
990 
991   /* Process unlocked */
992   __HAL_UNLOCK(hltdc);
993 
994   return HAL_OK;
995 }
996 
997 /**
998   * @brief  Disable the color keying.
999   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1000   *                   the configuration information for the LTDC.
1001   * @param  LayerIdx  LTDC Layer index.
1002   *                   This parameter can be one of the following values:
1003   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1004   * @retval  HAL status
1005   */
HAL_LTDC_DisableColorKeying(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)1006 HAL_StatusTypeDef HAL_LTDC_DisableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1007 {
1008   /* Check the parameters */
1009   assert_param(IS_LTDC_LAYER(LayerIdx));
1010 
1011   /* Process locked */
1012   __HAL_LOCK(hltdc);
1013 
1014   /* Change LTDC peripheral state */
1015   hltdc->State = HAL_LTDC_STATE_BUSY;
1016 
1017   /* Disable LTDC color keying by setting COLKEN bit */
1018   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_COLKEN;
1019 
1020   /* Set the Immediate Reload type */
1021   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1022 
1023   /* Change the LTDC state*/
1024   hltdc->State = HAL_LTDC_STATE_READY;
1025 
1026   /* Process unlocked */
1027   __HAL_UNLOCK(hltdc);
1028 
1029   return HAL_OK;
1030 }
1031 
1032 /**
1033   * @brief  Enable the color lookup table.
1034   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1035   *                   the configuration information for the LTDC.
1036   * @param  LayerIdx  LTDC Layer index.
1037   *                   This parameter can be one of the following values:
1038   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1039   * @retval  HAL status
1040   */
HAL_LTDC_EnableCLUT(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)1041 HAL_StatusTypeDef HAL_LTDC_EnableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1042 {
1043   /* Check the parameters */
1044   assert_param(IS_LTDC_LAYER(LayerIdx));
1045 
1046   /* Process locked */
1047   __HAL_LOCK(hltdc);
1048 
1049   /* Change LTDC peripheral state */
1050   hltdc->State = HAL_LTDC_STATE_BUSY;
1051 
1052   /* Enable LTDC color lookup table by setting CLUTEN bit */
1053   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_CLUTEN;
1054 
1055   /* Set the Immediate Reload type */
1056   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1057 
1058   /* Change the LTDC state*/
1059   hltdc->State = HAL_LTDC_STATE_READY;
1060 
1061   /* Process unlocked */
1062   __HAL_UNLOCK(hltdc);
1063 
1064   return HAL_OK;
1065 }
1066 
1067 /**
1068   * @brief  Disable the color lookup table.
1069   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1070   *                   the configuration information for the LTDC.
1071   * @param  LayerIdx  LTDC Layer index.
1072   *                   This parameter can be one of the following values:
1073   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1074   * @retval  HAL status
1075   */
HAL_LTDC_DisableCLUT(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)1076 HAL_StatusTypeDef HAL_LTDC_DisableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1077 {
1078   /* Check the parameters */
1079   assert_param(IS_LTDC_LAYER(LayerIdx));
1080 
1081   /* Process locked */
1082   __HAL_LOCK(hltdc);
1083 
1084   /* Change LTDC peripheral state */
1085   hltdc->State = HAL_LTDC_STATE_BUSY;
1086 
1087   /* Disable LTDC color lookup table by setting CLUTEN bit */
1088   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_CLUTEN;
1089 
1090   /* Set the Immediate Reload type */
1091   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1092 
1093   /* Change the LTDC state*/
1094   hltdc->State = HAL_LTDC_STATE_READY;
1095 
1096   /* Process unlocked */
1097   __HAL_UNLOCK(hltdc);
1098 
1099   return HAL_OK;
1100 }
1101 
1102 /**
1103   * @brief  Enable Dither.
1104   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
1105   *                the configuration information for the LTDC.
1106   * @retval  HAL status
1107   */
1108 
HAL_LTDC_EnableDither(LTDC_HandleTypeDef * hltdc)1109 HAL_StatusTypeDef HAL_LTDC_EnableDither(LTDC_HandleTypeDef *hltdc)
1110 {
1111   /* Process locked */
1112   __HAL_LOCK(hltdc);
1113 
1114   /* Change LTDC peripheral state */
1115   hltdc->State = HAL_LTDC_STATE_BUSY;
1116 
1117   /* Enable Dither by setting DTEN bit */
1118   LTDC->GCR |= (uint32_t)LTDC_GCR_DEN;
1119 
1120   /* Change the LTDC state*/
1121   hltdc->State = HAL_LTDC_STATE_READY;
1122 
1123   /* Process unlocked */
1124   __HAL_UNLOCK(hltdc);
1125 
1126   return HAL_OK;
1127 }
1128 
1129 /**
1130   * @brief  Disable Dither.
1131   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
1132   *                the configuration information for the LTDC.
1133   * @retval  HAL status
1134   */
1135 
HAL_LTDC_DisableDither(LTDC_HandleTypeDef * hltdc)1136 HAL_StatusTypeDef HAL_LTDC_DisableDither(LTDC_HandleTypeDef *hltdc)
1137 {
1138   /* Process locked */
1139   __HAL_LOCK(hltdc);
1140 
1141   /* Change LTDC peripheral state */
1142   hltdc->State = HAL_LTDC_STATE_BUSY;
1143 
1144   /* Disable Dither by setting DTEN bit */
1145   LTDC->GCR &= ~(uint32_t)LTDC_GCR_DEN;
1146 
1147   /* Change the LTDC state*/
1148   hltdc->State = HAL_LTDC_STATE_READY;
1149 
1150   /* Process unlocked */
1151   __HAL_UNLOCK(hltdc);
1152 
1153   return HAL_OK;
1154 }
1155 
1156 /**
1157   * @brief  Set the LTDC window size.
1158   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1159   *                   the configuration information for the LTDC.
1160   * @param  XSize     LTDC Pixel per line
1161   * @param  YSize     LTDC Line number
1162   * @param  LayerIdx  LTDC Layer index.
1163   *                   This parameter can be one of the following values:
1164   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1165   * @retval  HAL status
1166   */
HAL_LTDC_SetWindowSize(LTDC_HandleTypeDef * hltdc,uint32_t XSize,uint32_t YSize,uint32_t LayerIdx)1167 HAL_StatusTypeDef HAL_LTDC_SetWindowSize(LTDC_HandleTypeDef *hltdc, uint32_t XSize, uint32_t YSize, uint32_t LayerIdx)
1168 {
1169   LTDC_LayerCfgTypeDef *pLayerCfg;
1170 
1171   /* Check the parameters (Layers parameters)*/
1172   assert_param(IS_LTDC_LAYER(LayerIdx));
1173   assert_param(IS_LTDC_CFBLL(XSize));
1174   assert_param(IS_LTDC_CFBLNBR(YSize));
1175 
1176   /* Process locked */
1177   __HAL_LOCK(hltdc);
1178 
1179   /* Change LTDC peripheral state */
1180   hltdc->State = HAL_LTDC_STATE_BUSY;
1181 
1182   /* Get layer configuration from handle structure */
1183   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1184 
1185   /* update horizontal stop */
1186   pLayerCfg->WindowX1 = XSize + pLayerCfg->WindowX0;
1187 
1188   /* update vertical stop */
1189   pLayerCfg->WindowY1 = YSize + pLayerCfg->WindowY0;
1190 
1191   /* Reconfigures the color frame buffer pitch in byte */
1192   pLayerCfg->ImageWidth = XSize;
1193 
1194   /* Reconfigures the frame buffer line number */
1195   pLayerCfg->ImageHeight = YSize;
1196 
1197   /* Set LTDC parameters */
1198   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1199 
1200   /* Set the Immediate Reload type */
1201   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1202 
1203   /* Change the LTDC state*/
1204   hltdc->State = HAL_LTDC_STATE_READY;
1205 
1206   /* Process unlocked */
1207   __HAL_UNLOCK(hltdc);
1208 
1209   return HAL_OK;
1210 }
1211 
1212 /**
1213   * @brief  Set the LTDC window position.
1214   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1215   *                   the configuration information for the LTDC.
1216   * @param  X0        LTDC window X offset
1217   * @param  Y0        LTDC window Y offset
1218   * @param  LayerIdx  LTDC Layer index.
1219   *                         This parameter can be one of the following values:
1220   *                         LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1221   * @retval  HAL status
1222   */
HAL_LTDC_SetWindowPosition(LTDC_HandleTypeDef * hltdc,uint32_t X0,uint32_t Y0,uint32_t LayerIdx)1223 HAL_StatusTypeDef HAL_LTDC_SetWindowPosition(LTDC_HandleTypeDef *hltdc, uint32_t X0, uint32_t Y0, uint32_t LayerIdx)
1224 {
1225   LTDC_LayerCfgTypeDef *pLayerCfg;
1226 
1227   /* Check the parameters */
1228   assert_param(IS_LTDC_LAYER(LayerIdx));
1229   assert_param(IS_LTDC_CFBLL(X0));
1230   assert_param(IS_LTDC_CFBLNBR(Y0));
1231 
1232   /* Process locked */
1233   __HAL_LOCK(hltdc);
1234 
1235   /* Change LTDC peripheral state */
1236   hltdc->State = HAL_LTDC_STATE_BUSY;
1237 
1238   /* Get layer configuration from handle structure */
1239   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1240 
1241   /* update horizontal start/stop */
1242   pLayerCfg->WindowX0 = X0;
1243   pLayerCfg->WindowX1 = X0 + pLayerCfg->ImageWidth;
1244 
1245   /* update vertical start/stop */
1246   pLayerCfg->WindowY0 = Y0;
1247   pLayerCfg->WindowY1 = Y0 + pLayerCfg->ImageHeight;
1248 
1249   /* Set LTDC parameters */
1250   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1251 
1252   /* Set the Immediate Reload type */
1253   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1254 
1255   /* Change the LTDC state*/
1256   hltdc->State = HAL_LTDC_STATE_READY;
1257 
1258   /* Process unlocked */
1259   __HAL_UNLOCK(hltdc);
1260 
1261   return HAL_OK;
1262 }
1263 
1264 /**
1265   * @brief  Reconfigure the pixel format.
1266   * @param  hltdc        pointer to a LTDC_HandleTypeDef structure that contains
1267   *                      the configuration information for the LTDC.
1268   * @param  Pixelformat  new pixel format value.
1269   * @param  LayerIdx     LTDC Layer index.
1270   *                      This parameter can be one of the following values:
1271   *                      LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
1272   * @retval  HAL status
1273   */
HAL_LTDC_SetPixelFormat(LTDC_HandleTypeDef * hltdc,uint32_t Pixelformat,uint32_t LayerIdx)1274 HAL_StatusTypeDef HAL_LTDC_SetPixelFormat(LTDC_HandleTypeDef *hltdc, uint32_t Pixelformat, uint32_t LayerIdx)
1275 {
1276   LTDC_LayerCfgTypeDef *pLayerCfg;
1277 
1278   /* Check the parameters */
1279   assert_param(IS_LTDC_PIXEL_FORMAT(Pixelformat));
1280   assert_param(IS_LTDC_LAYER(LayerIdx));
1281 
1282   /* Process locked */
1283   __HAL_LOCK(hltdc);
1284 
1285   /* Change LTDC peripheral state */
1286   hltdc->State = HAL_LTDC_STATE_BUSY;
1287 
1288   /* Get layer configuration from handle structure */
1289   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1290 
1291   /* Reconfigure the pixel format */
1292   pLayerCfg->PixelFormat = Pixelformat;
1293 
1294   /* Set LTDC parameters */
1295   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1296 
1297   /* Set the Immediate Reload type */
1298   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1299 
1300   /* Change the LTDC state*/
1301   hltdc->State = HAL_LTDC_STATE_READY;
1302 
1303   /* Process unlocked */
1304   __HAL_UNLOCK(hltdc);
1305 
1306   return HAL_OK;
1307 }
1308 
1309 /**
1310   * @brief  Reconfigure the layer alpha value.
1311   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1312   *                   the configuration information for the LTDC.
1313   * @param  Alpha     new alpha value.
1314   * @param  LayerIdx  LTDC Layer index.
1315   *                   This parameter can be one of the following values:
1316   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1317   * @retval  HAL status
1318   */
HAL_LTDC_SetAlpha(LTDC_HandleTypeDef * hltdc,uint32_t Alpha,uint32_t LayerIdx)1319 HAL_StatusTypeDef HAL_LTDC_SetAlpha(LTDC_HandleTypeDef *hltdc, uint32_t Alpha, uint32_t LayerIdx)
1320 {
1321   LTDC_LayerCfgTypeDef *pLayerCfg;
1322 
1323   /* Check the parameters */
1324   assert_param(IS_LTDC_ALPHA(Alpha));
1325   assert_param(IS_LTDC_LAYER(LayerIdx));
1326 
1327   /* Process locked */
1328   __HAL_LOCK(hltdc);
1329 
1330   /* Change LTDC peripheral state */
1331   hltdc->State = HAL_LTDC_STATE_BUSY;
1332 
1333   /* Get layer configuration from handle structure */
1334   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1335 
1336   /* Reconfigure the Alpha value */
1337   pLayerCfg->Alpha = Alpha;
1338 
1339   /* Set LTDC parameters */
1340   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1341 
1342   /* Set the Immediate Reload type */
1343   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1344 
1345   /* Change the LTDC state*/
1346   hltdc->State = HAL_LTDC_STATE_READY;
1347 
1348   /* Process unlocked */
1349   __HAL_UNLOCK(hltdc);
1350 
1351   return HAL_OK;
1352 }
1353 /**
1354   * @brief  Reconfigure the frame buffer Address.
1355   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1356   *                   the configuration information for the LTDC.
1357   * @param  Address   new address value.
1358   * @param  LayerIdx  LTDC Layer index.
1359   *                   This parameter can be one of the following values:
1360   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
1361   * @retval  HAL status
1362   */
HAL_LTDC_SetAddress(LTDC_HandleTypeDef * hltdc,uint32_t Address,uint32_t LayerIdx)1363 HAL_StatusTypeDef HAL_LTDC_SetAddress(LTDC_HandleTypeDef *hltdc, uint32_t Address, uint32_t LayerIdx)
1364 {
1365   LTDC_LayerCfgTypeDef *pLayerCfg;
1366 
1367   /* Check the parameters */
1368   assert_param(IS_LTDC_LAYER(LayerIdx));
1369 
1370   /* Process locked */
1371   __HAL_LOCK(hltdc);
1372 
1373   /* Change LTDC peripheral state */
1374   hltdc->State = HAL_LTDC_STATE_BUSY;
1375 
1376   /* Get layer configuration from handle structure */
1377   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1378 
1379   /* Reconfigure the Address */
1380   pLayerCfg->FBStartAdress = Address;
1381 
1382   /* Set LTDC parameters */
1383   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1384 
1385   /* Set the Immediate Reload type */
1386   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1387 
1388   /* Change the LTDC state*/
1389   hltdc->State = HAL_LTDC_STATE_READY;
1390 
1391   /* Process unlocked */
1392   __HAL_UNLOCK(hltdc);
1393 
1394   return HAL_OK;
1395 }
1396 
1397 /**
1398   * @brief  Function used to reconfigure the pitch for specific cases where the attached LayerIdx buffer have a width
1399   *         that is larger than the one intended to be displayed on screen. Example of a buffer 800x480 attached to
1400   *         layer for which we want to read and display on screen only a portion 320x240 taken in the center
1401   *         of the buffer.
1402   *         The pitch in pixels will be in that case 800 pixels and not 320 pixels as initially configured by previous
1403   *         call to HAL_LTDC_ConfigLayer().
1404   * @note   This function should be called only after a previous call to HAL_LTDC_ConfigLayer() to modify the default
1405   *         pitch configured by HAL_LTDC_ConfigLayer() when required (refer to example described just above).
1406   * @param  hltdc              pointer to a LTDC_HandleTypeDef structure that contains
1407   *                            the configuration information for the LTDC.
1408   * @param  LinePitchInPixels  New line pitch in pixels to configure for LTDC layer 'LayerIdx'.
1409   * @param  LayerIdx           LTDC layer index concerned by the modification of line pitch.
1410   * @retval HAL status
1411   */
HAL_LTDC_SetPitch(LTDC_HandleTypeDef * hltdc,uint32_t LinePitchInPixels,uint32_t LayerIdx)1412 HAL_StatusTypeDef HAL_LTDC_SetPitch(LTDC_HandleTypeDef *hltdc, uint32_t LinePitchInPixels, uint32_t LayerIdx)
1413 {
1414   uint32_t tmp;
1415   uint32_t pitchUpdate;
1416   uint32_t pixelFormat;
1417 
1418   /* Check the parameters */
1419   assert_param(IS_LTDC_LAYER(LayerIdx));
1420 
1421   /* Process locked */
1422   __HAL_LOCK(hltdc);
1423 
1424   /* Change LTDC peripheral state */
1425   hltdc->State = HAL_LTDC_STATE_BUSY;
1426 
1427   /* get LayerIdx used pixel format */
1428   pixelFormat = hltdc->LayerCfg[LayerIdx].PixelFormat;
1429 
1430   if (pixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
1431   {
1432     tmp = 4U;
1433   }
1434   else if (pixelFormat == LTDC_PIXEL_FORMAT_RGB888)
1435   {
1436     tmp = 3U;
1437   }
1438   else if ((pixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
1439            (pixelFormat == LTDC_PIXEL_FORMAT_RGB565)   || \
1440            (pixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
1441            (pixelFormat == LTDC_PIXEL_FORMAT_AL88))
1442   {
1443     tmp = 2U;
1444   }
1445   else
1446   {
1447     tmp = 1U;
1448   }
1449 
1450   pitchUpdate = ((LinePitchInPixels * tmp) << 16U);
1451 
1452   /* Clear previously set standard pitch */
1453   LTDC_LAYER(hltdc, LayerIdx)->CFBLR &= ~LTDC_LxCFBLR_CFBP;
1454 
1455   /* Set the Reload type as immediate update of LTDC pitch configured above */
1456   LTDC->SRCR |= LTDC_SRCR_IMR;
1457 
1458   /* Set new line pitch value */
1459   LTDC_LAYER(hltdc, LayerIdx)->CFBLR |= pitchUpdate;
1460 
1461   /* Set the Reload type as immediate update of LTDC pitch configured above */
1462   LTDC->SRCR |= LTDC_SRCR_IMR;
1463 
1464   /* Change the LTDC state*/
1465   hltdc->State = HAL_LTDC_STATE_READY;
1466 
1467   /* Process unlocked */
1468   __HAL_UNLOCK(hltdc);
1469 
1470   return HAL_OK;
1471 }
1472 
1473 /**
1474   * @brief  Define the position of the line interrupt.
1475   * @param  hltdc   pointer to a LTDC_HandleTypeDef structure that contains
1476   *                 the configuration information for the LTDC.
1477   * @param  Line    Line Interrupt Position.
1478   * @note   User application may resort to HAL_LTDC_LineEventCallback() at line interrupt generation.
1479   * @retval  HAL status
1480   */
HAL_LTDC_ProgramLineEvent(LTDC_HandleTypeDef * hltdc,uint32_t Line)1481 HAL_StatusTypeDef HAL_LTDC_ProgramLineEvent(LTDC_HandleTypeDef *hltdc, uint32_t Line)
1482 {
1483   /* Check the parameters */
1484   assert_param(IS_LTDC_LIPOS(Line));
1485 
1486   /* Process locked */
1487   __HAL_LOCK(hltdc);
1488 
1489   /* Change LTDC peripheral state */
1490   hltdc->State = HAL_LTDC_STATE_BUSY;
1491 
1492   /* Disable the Line interrupt */
1493   __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_LI);
1494 
1495   /* Set the Line Interrupt position */
1496   LTDC->LIPCR = (uint32_t)Line;
1497 
1498   /* Enable the Line interrupt */
1499   __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_LI);
1500 
1501   /* Change the LTDC state*/
1502   hltdc->State = HAL_LTDC_STATE_READY;
1503 
1504   /* Process unlocked */
1505   __HAL_UNLOCK(hltdc);
1506 
1507   return HAL_OK;
1508 }
1509 
1510 /**
1511   * @brief  Reload LTDC Layers configuration.
1512   * @param  hltdc      pointer to a LTDC_HandleTypeDef structure that contains
1513   *                    the configuration information for the LTDC.
1514   * @param  ReloadType This parameter can be one of the following values :
1515   *                      LTDC_RELOAD_IMMEDIATE : Immediate Reload
1516   *                      LTDC_RELOAD_VERTICAL_BLANKING  : Reload in the next Vertical Blanking
1517   * @note   User application may resort to HAL_LTDC_ReloadEventCallback() at reload interrupt generation.
1518   * @retval  HAL status
1519   */
HAL_LTDC_Reload(LTDC_HandleTypeDef * hltdc,uint32_t ReloadType)1520 HAL_StatusTypeDef  HAL_LTDC_Reload(LTDC_HandleTypeDef *hltdc, uint32_t ReloadType)
1521 {
1522   /* Check the parameters */
1523   assert_param(IS_LTDC_RELOAD(ReloadType));
1524 
1525   /* Process locked */
1526   __HAL_LOCK(hltdc);
1527 
1528   /* Change LTDC peripheral state */
1529   hltdc->State = HAL_LTDC_STATE_BUSY;
1530 
1531   /* Enable the Reload interrupt */
1532   __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_RR);
1533 
1534   /* Apply Reload type */
1535   hltdc->Instance->SRCR = ReloadType;
1536 
1537   /* Change the LTDC state*/
1538   hltdc->State = HAL_LTDC_STATE_READY;
1539 
1540   /* Process unlocked */
1541   __HAL_UNLOCK(hltdc);
1542 
1543   return HAL_OK;
1544 }
1545 
1546 /**
1547   * @brief  Configure the LTDC Layer according to the specified without reloading
1548   *         parameters in the LTDC_InitTypeDef and create the associated handle.
1549   *         Variant of the function HAL_LTDC_ConfigLayer without immediate reload.
1550   * @param  hltdc      pointer to a LTDC_HandleTypeDef structure that contains
1551   *                    the configuration information for the LTDC.
1552   * @param  pLayerCfg  pointer to a LTDC_LayerCfgTypeDef structure that contains
1553   *                    the configuration information for the Layer.
1554   * @param  LayerIdx   LTDC Layer index.
1555   *                    This parameter can be one of the following values:
1556   *                    LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1557   * @retval HAL status
1558   */
HAL_LTDC_ConfigLayer_NoReload(LTDC_HandleTypeDef * hltdc,LTDC_LayerCfgTypeDef * pLayerCfg,uint32_t LayerIdx)1559 HAL_StatusTypeDef HAL_LTDC_ConfigLayer_NoReload(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg,
1560                                                 uint32_t LayerIdx)
1561 {
1562   /* Check the parameters */
1563   assert_param(IS_LTDC_LAYER(LayerIdx));
1564   assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));
1565   assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));
1566   assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));
1567   assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));
1568   assert_param(IS_LTDC_PIXEL_FORMAT(pLayerCfg->PixelFormat));
1569   assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha));
1570   assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha0));
1571   assert_param(IS_LTDC_BLENDING_FACTOR1(pLayerCfg->BlendingFactor1));
1572   assert_param(IS_LTDC_BLENDING_FACTOR2(pLayerCfg->BlendingFactor2));
1573   assert_param(IS_LTDC_CFBLL(pLayerCfg->ImageWidth));
1574   assert_param(IS_LTDC_CFBLNBR(pLayerCfg->ImageHeight));
1575 
1576   /* Process locked */
1577   __HAL_LOCK(hltdc);
1578 
1579   /* Change LTDC peripheral state */
1580   hltdc->State = HAL_LTDC_STATE_BUSY;
1581 
1582   /* Copy new layer configuration into handle structure */
1583   hltdc->LayerCfg[LayerIdx] = *pLayerCfg;
1584 
1585   /* Configure the LTDC Layer */
1586   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1587 
1588   /* Initialize the LTDC state*/
1589   hltdc->State  = HAL_LTDC_STATE_READY;
1590 
1591   /* Process unlocked */
1592   __HAL_UNLOCK(hltdc);
1593 
1594   return HAL_OK;
1595 }
1596 
1597 /**
1598   * @brief  Set the LTDC window size without reloading.
1599   *         Variant of the function HAL_LTDC_SetWindowSize without immediate reload.
1600   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1601   *                   the configuration information for the LTDC.
1602   * @param  XSize     LTDC Pixel per line
1603   * @param  YSize     LTDC Line number
1604   * @param  LayerIdx  LTDC Layer index.
1605   *                   This parameter can be one of the following values:
1606   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1607   * @retval  HAL status
1608   */
HAL_LTDC_SetWindowSize_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t XSize,uint32_t YSize,uint32_t LayerIdx)1609 HAL_StatusTypeDef HAL_LTDC_SetWindowSize_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t XSize, uint32_t YSize,
1610                                                   uint32_t LayerIdx)
1611 {
1612   LTDC_LayerCfgTypeDef *pLayerCfg;
1613 
1614   /* Check the parameters (Layers parameters)*/
1615   assert_param(IS_LTDC_LAYER(LayerIdx));
1616   assert_param(IS_LTDC_CFBLL(XSize));
1617   assert_param(IS_LTDC_CFBLNBR(YSize));
1618 
1619   /* Process locked */
1620   __HAL_LOCK(hltdc);
1621 
1622   /* Change LTDC peripheral state */
1623   hltdc->State = HAL_LTDC_STATE_BUSY;
1624 
1625   /* Get layer configuration from handle structure */
1626   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1627 
1628   /* update horizontal stop */
1629   pLayerCfg->WindowX1 = XSize + pLayerCfg->WindowX0;
1630 
1631   /* update vertical stop */
1632   pLayerCfg->WindowY1 = YSize + pLayerCfg->WindowY0;
1633 
1634   /* Reconfigures the color frame buffer pitch in byte */
1635   pLayerCfg->ImageWidth = XSize;
1636 
1637   /* Reconfigures the frame buffer line number */
1638   pLayerCfg->ImageHeight = YSize;
1639 
1640   /* Set LTDC parameters */
1641   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1642 
1643   /* Change the LTDC state*/
1644   hltdc->State = HAL_LTDC_STATE_READY;
1645 
1646   /* Process unlocked */
1647   __HAL_UNLOCK(hltdc);
1648 
1649   return HAL_OK;
1650 }
1651 
1652 /**
1653   * @brief  Set the LTDC window position without reloading.
1654   *         Variant of the function HAL_LTDC_SetWindowPosition without immediate reload.
1655   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1656   *                   the configuration information for the LTDC.
1657   * @param  X0        LTDC window X offset
1658   * @param  Y0        LTDC window Y offset
1659   * @param  LayerIdx  LTDC Layer index.
1660   *                         This parameter can be one of the following values:
1661   *                         LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1662   * @retval  HAL status
1663   */
HAL_LTDC_SetWindowPosition_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t X0,uint32_t Y0,uint32_t LayerIdx)1664 HAL_StatusTypeDef HAL_LTDC_SetWindowPosition_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t X0, uint32_t Y0,
1665                                                       uint32_t LayerIdx)
1666 {
1667   LTDC_LayerCfgTypeDef *pLayerCfg;
1668 
1669   /* Check the parameters */
1670   assert_param(IS_LTDC_LAYER(LayerIdx));
1671   assert_param(IS_LTDC_CFBLL(X0));
1672   assert_param(IS_LTDC_CFBLNBR(Y0));
1673 
1674   /* Process locked */
1675   __HAL_LOCK(hltdc);
1676 
1677   /* Change LTDC peripheral state */
1678   hltdc->State = HAL_LTDC_STATE_BUSY;
1679 
1680   /* Get layer configuration from handle structure */
1681   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1682 
1683   /* update horizontal start/stop */
1684   pLayerCfg->WindowX0 = X0;
1685   pLayerCfg->WindowX1 = X0 + pLayerCfg->ImageWidth;
1686 
1687   /* update vertical start/stop */
1688   pLayerCfg->WindowY0 = Y0;
1689   pLayerCfg->WindowY1 = Y0 + pLayerCfg->ImageHeight;
1690 
1691   /* Set LTDC parameters */
1692   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1693 
1694   /* Change the LTDC state*/
1695   hltdc->State = HAL_LTDC_STATE_READY;
1696 
1697   /* Process unlocked */
1698   __HAL_UNLOCK(hltdc);
1699 
1700   return HAL_OK;
1701 }
1702 
1703 /**
1704   * @brief  Reconfigure the pixel format without reloading.
1705   *         Variant of the function HAL_LTDC_SetPixelFormat without immediate reload.
1706   * @param  hltdc        pointer to a LTDC_HandleTypeDfef structure that contains
1707   *                      the configuration information for the LTDC.
1708   * @param  Pixelformat  new pixel format value.
1709   * @param  LayerIdx     LTDC Layer index.
1710   *                      This parameter can be one of the following values:
1711   *                      LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
1712   * @retval  HAL status
1713   */
HAL_LTDC_SetPixelFormat_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t Pixelformat,uint32_t LayerIdx)1714 HAL_StatusTypeDef HAL_LTDC_SetPixelFormat_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Pixelformat, uint32_t LayerIdx)
1715 {
1716   LTDC_LayerCfgTypeDef *pLayerCfg;
1717 
1718   /* Check the parameters */
1719   assert_param(IS_LTDC_PIXEL_FORMAT(Pixelformat));
1720   assert_param(IS_LTDC_LAYER(LayerIdx));
1721 
1722   /* Process locked */
1723   __HAL_LOCK(hltdc);
1724 
1725   /* Change LTDC peripheral state */
1726   hltdc->State = HAL_LTDC_STATE_BUSY;
1727 
1728   /* Get layer configuration from handle structure */
1729   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1730 
1731   /* Reconfigure the pixel format */
1732   pLayerCfg->PixelFormat = Pixelformat;
1733 
1734   /* Set LTDC parameters */
1735   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1736 
1737   /* Change the LTDC state*/
1738   hltdc->State = HAL_LTDC_STATE_READY;
1739 
1740   /* Process unlocked */
1741   __HAL_UNLOCK(hltdc);
1742 
1743   return HAL_OK;
1744 }
1745 
1746 /**
1747   * @brief  Reconfigure the layer alpha value without reloading.
1748   *         Variant of the function HAL_LTDC_SetAlpha without immediate reload.
1749   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1750   *                   the configuration information for the LTDC.
1751   * @param  Alpha     new alpha value.
1752   * @param  LayerIdx  LTDC Layer index.
1753   *                   This parameter can be one of the following values:
1754   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1755   * @retval  HAL status
1756   */
HAL_LTDC_SetAlpha_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t Alpha,uint32_t LayerIdx)1757 HAL_StatusTypeDef HAL_LTDC_SetAlpha_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Alpha, uint32_t LayerIdx)
1758 {
1759   LTDC_LayerCfgTypeDef *pLayerCfg;
1760 
1761   /* Check the parameters */
1762   assert_param(IS_LTDC_ALPHA(Alpha));
1763   assert_param(IS_LTDC_LAYER(LayerIdx));
1764 
1765   /* Process locked */
1766   __HAL_LOCK(hltdc);
1767 
1768   /* Change LTDC peripheral state */
1769   hltdc->State = HAL_LTDC_STATE_BUSY;
1770 
1771   /* Get layer configuration from handle structure */
1772   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1773 
1774   /* Reconfigure the Alpha value */
1775   pLayerCfg->Alpha = Alpha;
1776 
1777   /* Set LTDC parameters */
1778   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1779 
1780   /* Change the LTDC state*/
1781   hltdc->State = HAL_LTDC_STATE_READY;
1782 
1783   /* Process unlocked */
1784   __HAL_UNLOCK(hltdc);
1785 
1786   return HAL_OK;
1787 }
1788 
1789 /**
1790   * @brief  Reconfigure the frame buffer Address without reloading.
1791   *         Variant of the function HAL_LTDC_SetAddress without immediate reload.
1792   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1793   *                   the configuration information for the LTDC.
1794   * @param  Address   new address value.
1795   * @param  LayerIdx  LTDC Layer index.
1796   *                   This parameter can be one of the following values:
1797   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
1798   * @retval  HAL status
1799   */
HAL_LTDC_SetAddress_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t Address,uint32_t LayerIdx)1800 HAL_StatusTypeDef HAL_LTDC_SetAddress_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Address, uint32_t LayerIdx)
1801 {
1802   LTDC_LayerCfgTypeDef *pLayerCfg;
1803 
1804   /* Check the parameters */
1805   assert_param(IS_LTDC_LAYER(LayerIdx));
1806 
1807   /* Process locked */
1808   __HAL_LOCK(hltdc);
1809 
1810   /* Change LTDC peripheral state */
1811   hltdc->State = HAL_LTDC_STATE_BUSY;
1812 
1813   /* Get layer configuration from handle structure */
1814   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1815 
1816   /* Reconfigure the Address */
1817   pLayerCfg->FBStartAdress = Address;
1818 
1819   /* Set LTDC parameters */
1820   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1821 
1822   /* Change the LTDC state*/
1823   hltdc->State = HAL_LTDC_STATE_READY;
1824 
1825   /* Process unlocked */
1826   __HAL_UNLOCK(hltdc);
1827 
1828   return HAL_OK;
1829 }
1830 
1831 /**
1832   * @brief  Function used to reconfigure the pitch for specific cases where the attached LayerIdx buffer have a width
1833   *         that is larger than the one intended to be displayed on screen. Example of a buffer 800x480 attached to
1834   *         layer for which we want to read and display on screen only a portion 320x240 taken in the center
1835   *         of the buffer.
1836   *         The pitch in pixels will be in that case 800 pixels and not 320 pixels as initially configured by
1837   *         previous call to HAL_LTDC_ConfigLayer().
1838   * @note   This function should be called only after a previous call to HAL_LTDC_ConfigLayer() to modify the default
1839   *         pitch configured by HAL_LTDC_ConfigLayer() when required (refer to example described just above).
1840   *         Variant of the function HAL_LTDC_SetPitch without immediate reload.
1841   * @param  hltdc              pointer to a LTDC_HandleTypeDef structure that contains
1842   *                            the configuration information for the LTDC.
1843   * @param  LinePitchInPixels  New line pitch in pixels to configure for LTDC layer 'LayerIdx'.
1844   * @param  LayerIdx           LTDC layer index concerned by the modification of line pitch.
1845   * @retval HAL status
1846   */
HAL_LTDC_SetPitch_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t LinePitchInPixels,uint32_t LayerIdx)1847 HAL_StatusTypeDef HAL_LTDC_SetPitch_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LinePitchInPixels, uint32_t LayerIdx)
1848 {
1849   uint32_t tmp;
1850   uint32_t pitchUpdate;
1851   uint32_t pixelFormat;
1852 
1853   /* Check the parameters */
1854   assert_param(IS_LTDC_LAYER(LayerIdx));
1855 
1856   /* Process locked */
1857   __HAL_LOCK(hltdc);
1858 
1859   /* Change LTDC peripheral state */
1860   hltdc->State = HAL_LTDC_STATE_BUSY;
1861 
1862   /* get LayerIdx used pixel format */
1863   pixelFormat = hltdc->LayerCfg[LayerIdx].PixelFormat;
1864 
1865   if (pixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
1866   {
1867     tmp = 4U;
1868   }
1869   else if (pixelFormat == LTDC_PIXEL_FORMAT_RGB888)
1870   {
1871     tmp = 3U;
1872   }
1873   else if ((pixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
1874            (pixelFormat == LTDC_PIXEL_FORMAT_RGB565)   || \
1875            (pixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
1876            (pixelFormat == LTDC_PIXEL_FORMAT_AL88))
1877   {
1878     tmp = 2U;
1879   }
1880   else
1881   {
1882     tmp = 1U;
1883   }
1884 
1885   pitchUpdate = ((LinePitchInPixels * tmp) << 16U);
1886 
1887   /* Clear previously set standard pitch */
1888   LTDC_LAYER(hltdc, LayerIdx)->CFBLR &= ~LTDC_LxCFBLR_CFBP;
1889 
1890   /* Set new line pitch value */
1891   LTDC_LAYER(hltdc, LayerIdx)->CFBLR |= pitchUpdate;
1892 
1893   /* Change the LTDC state*/
1894   hltdc->State = HAL_LTDC_STATE_READY;
1895 
1896   /* Process unlocked */
1897   __HAL_UNLOCK(hltdc);
1898 
1899   return HAL_OK;
1900 }
1901 
1902 
1903 /**
1904   * @brief  Configure the color keying without reloading.
1905   *         Variant of the function HAL_LTDC_ConfigColorKeying without immediate reload.
1906   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1907   *                   the configuration information for the LTDC.
1908   * @param  RGBValue the color key value
1909   * @param  LayerIdx  LTDC Layer index.
1910   *                   This parameter can be one of the following values:
1911   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1912   * @retval HAL status
1913   */
HAL_LTDC_ConfigColorKeying_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t RGBValue,uint32_t LayerIdx)1914 HAL_StatusTypeDef HAL_LTDC_ConfigColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t RGBValue, uint32_t LayerIdx)
1915 {
1916   /* Check the parameters */
1917   assert_param(IS_LTDC_LAYER(LayerIdx));
1918 
1919   /* Process locked */
1920   __HAL_LOCK(hltdc);
1921 
1922   /* Change LTDC peripheral state */
1923   hltdc->State = HAL_LTDC_STATE_BUSY;
1924 
1925   /* Configure the default color values */
1926   LTDC_LAYER(hltdc, LayerIdx)->CKCR &=  ~(LTDC_LxCKCR_CKBLUE | LTDC_LxCKCR_CKGREEN | LTDC_LxCKCR_CKRED);
1927   LTDC_LAYER(hltdc, LayerIdx)->CKCR  = RGBValue;
1928 
1929   /* Change the LTDC state*/
1930   hltdc->State = HAL_LTDC_STATE_READY;
1931 
1932   /* Process unlocked */
1933   __HAL_UNLOCK(hltdc);
1934 
1935   return HAL_OK;
1936 }
1937 
1938 /**
1939   * @brief  Enable the color keying without reloading.
1940   *         Variant of the function HAL_LTDC_EnableColorKeying without immediate reload.
1941   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1942   *                   the configuration information for the LTDC.
1943   * @param  LayerIdx  LTDC Layer index.
1944   *                   This parameter can be one of the following values:
1945   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1946   * @retval  HAL status
1947   */
HAL_LTDC_EnableColorKeying_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)1948 HAL_StatusTypeDef HAL_LTDC_EnableColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1949 {
1950   /* Check the parameters */
1951   assert_param(IS_LTDC_LAYER(LayerIdx));
1952 
1953   /* Process locked */
1954   __HAL_LOCK(hltdc);
1955 
1956   /* Change LTDC peripheral state */
1957   hltdc->State = HAL_LTDC_STATE_BUSY;
1958 
1959   /* Enable LTDC color keying by setting COLKEN bit */
1960   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_COLKEN;
1961 
1962   /* Change the LTDC state*/
1963   hltdc->State = HAL_LTDC_STATE_READY;
1964 
1965   /* Process unlocked */
1966   __HAL_UNLOCK(hltdc);
1967 
1968   return HAL_OK;
1969 }
1970 
1971 /**
1972   * @brief  Disable the color keying without reloading.
1973   *         Variant of the function HAL_LTDC_DisableColorKeying without immediate reload.
1974   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1975   *                   the configuration information for the LTDC.
1976   * @param  LayerIdx  LTDC Layer index.
1977   *                   This parameter can be one of the following values:
1978   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1979   * @retval  HAL status
1980   */
HAL_LTDC_DisableColorKeying_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)1981 HAL_StatusTypeDef HAL_LTDC_DisableColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1982 {
1983   /* Check the parameters */
1984   assert_param(IS_LTDC_LAYER(LayerIdx));
1985 
1986   /* Process locked */
1987   __HAL_LOCK(hltdc);
1988 
1989   /* Change LTDC peripheral state */
1990   hltdc->State = HAL_LTDC_STATE_BUSY;
1991 
1992   /* Disable LTDC color keying by setting COLKEN bit */
1993   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_COLKEN;
1994 
1995   /* Change the LTDC state*/
1996   hltdc->State = HAL_LTDC_STATE_READY;
1997 
1998   /* Process unlocked */
1999   __HAL_UNLOCK(hltdc);
2000 
2001   return HAL_OK;
2002 }
2003 
2004 /**
2005   * @brief  Enable the color lookup table without reloading.
2006   *         Variant of the function HAL_LTDC_EnableCLUT without immediate reload.
2007   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
2008   *                   the configuration information for the LTDC.
2009   * @param  LayerIdx  LTDC Layer index.
2010   *                   This parameter can be one of the following values:
2011   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
2012   * @retval  HAL status
2013   */
HAL_LTDC_EnableCLUT_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)2014 HAL_StatusTypeDef HAL_LTDC_EnableCLUT_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
2015 {
2016   /* Check the parameters */
2017   assert_param(IS_LTDC_LAYER(LayerIdx));
2018 
2019   /* Process locked */
2020   __HAL_LOCK(hltdc);
2021 
2022   /* Change LTDC peripheral state */
2023   hltdc->State = HAL_LTDC_STATE_BUSY;
2024 
2025   /* Disable LTDC color lookup table by setting CLUTEN bit */
2026   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_CLUTEN;
2027 
2028   /* Change the LTDC state*/
2029   hltdc->State = HAL_LTDC_STATE_READY;
2030 
2031   /* Process unlocked */
2032   __HAL_UNLOCK(hltdc);
2033 
2034   return HAL_OK;
2035 }
2036 
2037 /**
2038   * @brief  Disable the color lookup table without reloading.
2039   *         Variant of the function HAL_LTDC_DisableCLUT without immediate reload.
2040   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
2041   *                   the configuration information for the LTDC.
2042   * @param  LayerIdx  LTDC Layer index.
2043   *                   This parameter can be one of the following values:
2044   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
2045   * @retval  HAL status
2046   */
HAL_LTDC_DisableCLUT_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)2047 HAL_StatusTypeDef HAL_LTDC_DisableCLUT_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
2048 {
2049   /* Check the parameters */
2050   assert_param(IS_LTDC_LAYER(LayerIdx));
2051 
2052   /* Process locked */
2053   __HAL_LOCK(hltdc);
2054 
2055   /* Change LTDC peripheral state */
2056   hltdc->State = HAL_LTDC_STATE_BUSY;
2057 
2058   /* Disable LTDC color lookup table by setting CLUTEN bit */
2059   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_CLUTEN;
2060 
2061   /* Change the LTDC state*/
2062   hltdc->State = HAL_LTDC_STATE_READY;
2063 
2064   /* Process unlocked */
2065   __HAL_UNLOCK(hltdc);
2066 
2067   return HAL_OK;
2068 }
2069 
2070 /**
2071   * @}
2072   */
2073 
2074 /** @defgroup LTDC_Exported_Functions_Group4 Peripheral State and Errors functions
2075   *  @brief    Peripheral State and Errors functions
2076   *
2077 @verbatim
2078  ===============================================================================
2079                   ##### Peripheral State and Errors functions #####
2080  ===============================================================================
2081     [..]
2082     This subsection provides functions allowing to
2083       (+) Check the LTDC handle state.
2084       (+) Get the LTDC handle error code.
2085 
2086 @endverbatim
2087   * @{
2088   */
2089 
2090 /**
2091   * @brief  Return the LTDC handle state.
2092   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
2093   *                the configuration information for the LTDC.
2094   * @retval HAL state
2095   */
HAL_LTDC_GetState(const LTDC_HandleTypeDef * hltdc)2096 HAL_LTDC_StateTypeDef HAL_LTDC_GetState(const LTDC_HandleTypeDef *hltdc)
2097 {
2098   return hltdc->State;
2099 }
2100 
2101 /**
2102   * @brief  Return the LTDC handle error code.
2103   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
2104   *               the configuration information for the LTDC.
2105   * @retval LTDC Error Code
2106   */
HAL_LTDC_GetError(const LTDC_HandleTypeDef * hltdc)2107 uint32_t HAL_LTDC_GetError(const LTDC_HandleTypeDef *hltdc)
2108 {
2109   return hltdc->ErrorCode;
2110 }
2111 
2112 /**
2113   * @}
2114   */
2115 
2116 /**
2117   * @}
2118   */
2119 
2120 /** @defgroup LTDC_Private_Functions LTDC Private Functions
2121   * @{
2122   */
2123 
2124 /**
2125   * @brief  Configure the LTDC peripheral
2126   * @param  hltdc     Pointer to a LTDC_HandleTypeDef structure that contains
2127   *                   the configuration information for the LTDC.
2128   * @param  pLayerCfg Pointer LTDC Layer Configuration structure
2129   * @param  LayerIdx  LTDC Layer index.
2130   *                   This parameter can be one of the following values: LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
2131   * @retval None
2132   */
LTDC_SetConfig(LTDC_HandleTypeDef * hltdc,LTDC_LayerCfgTypeDef * pLayerCfg,uint32_t LayerIdx)2133 static void LTDC_SetConfig(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)
2134 {
2135   uint32_t tmp;
2136   uint32_t tmp1;
2137   uint32_t tmp2;
2138 
2139   /* Configure the horizontal start and stop position */
2140   tmp = ((pLayerCfg->WindowX1 + ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16U)) << 16U);
2141   LTDC_LAYER(hltdc, LayerIdx)->WHPCR &= ~(LTDC_LxWHPCR_WHSTPOS | LTDC_LxWHPCR_WHSPPOS);
2142   LTDC_LAYER(hltdc, LayerIdx)->WHPCR = ((pLayerCfg->WindowX0 + \
2143                                          ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16U) + 1U) | tmp);
2144 
2145   /* Configure the vertical start and stop position */
2146   tmp = ((pLayerCfg->WindowY1 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP)) << 16U);
2147   LTDC_LAYER(hltdc, LayerIdx)->WVPCR &= ~(LTDC_LxWVPCR_WVSTPOS | LTDC_LxWVPCR_WVSPPOS);
2148   LTDC_LAYER(hltdc, LayerIdx)->WVPCR  = ((pLayerCfg->WindowY0 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP) + 1U) | tmp);
2149 
2150   /* Specifies the pixel format */
2151   LTDC_LAYER(hltdc, LayerIdx)->PFCR &= ~(LTDC_LxPFCR_PF);
2152   LTDC_LAYER(hltdc, LayerIdx)->PFCR = (pLayerCfg->PixelFormat);
2153 
2154   /* Configure the default color values */
2155   tmp = ((uint32_t)(pLayerCfg->Backcolor.Green) << 8U);
2156   tmp1 = ((uint32_t)(pLayerCfg->Backcolor.Red) << 16U);
2157   tmp2 = (pLayerCfg->Alpha0 << 24U);
2158   WRITE_REG(LTDC_LAYER(hltdc, LayerIdx)->DCCR, (pLayerCfg->Backcolor.Blue | tmp | tmp1 | tmp2));
2159 
2160   /* Specifies the constant alpha value */
2161   LTDC_LAYER(hltdc, LayerIdx)->CACR &= ~(LTDC_LxCACR_CONSTA);
2162   LTDC_LAYER(hltdc, LayerIdx)->CACR = (pLayerCfg->Alpha);
2163 
2164   /* Specifies the blending factors */
2165   LTDC_LAYER(hltdc, LayerIdx)->BFCR &= ~(LTDC_LxBFCR_BF2 | LTDC_LxBFCR_BF1);
2166   LTDC_LAYER(hltdc, LayerIdx)->BFCR = (pLayerCfg->BlendingFactor1 | pLayerCfg->BlendingFactor2);
2167 
2168   /* Configure the color frame buffer start address */
2169   WRITE_REG(LTDC_LAYER(hltdc, LayerIdx)->CFBAR, pLayerCfg->FBStartAdress);
2170 
2171   if (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
2172   {
2173     tmp = 4U;
2174   }
2175   else if (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
2176   {
2177     tmp = 3U;
2178   }
2179   else if ((pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
2180            (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB565)   || \
2181            (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
2182            (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_AL88))
2183   {
2184     tmp = 2U;
2185   }
2186   else
2187   {
2188     tmp = 1U;
2189   }
2190 
2191   /* Configure the color frame buffer pitch in byte */
2192   LTDC_LAYER(hltdc, LayerIdx)->CFBLR  &= ~(LTDC_LxCFBLR_CFBLL | LTDC_LxCFBLR_CFBP);
2193   LTDC_LAYER(hltdc, LayerIdx)->CFBLR  = (((pLayerCfg->ImageWidth * tmp) << 16U) | \
2194                                          (((pLayerCfg->WindowX1 - pLayerCfg->WindowX0) * tmp)  + 3U));
2195   /* Configure the frame buffer line number */
2196   LTDC_LAYER(hltdc, LayerIdx)->CFBLNR  &= ~(LTDC_LxCFBLNR_CFBLNBR);
2197   LTDC_LAYER(hltdc, LayerIdx)->CFBLNR  = (pLayerCfg->ImageHeight);
2198 
2199   /* Enable LTDC_Layer by setting LEN bit */
2200   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_LEN;
2201 }
2202 
2203 /**
2204   * @}
2205   */
2206 
2207 
2208 /**
2209   * @}
2210   */
2211 
2212 #endif /* LTDC */
2213 
2214 #endif /* HAL_LTDC_MODULE_ENABLED */
2215 
2216 /**
2217   * @}
2218   */
2219