• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2   ******************************************************************************
3   * @file    stm32mp1xx_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   @verbatim
14   ==============================================================================
15                         ##### How to use this driver #####
16   ==============================================================================
17      [..]
18      The LTDC HAL driver can be used as follows:
19 
20      (#) Declare a LTDC_HandleTypeDef handle structure, for example: LTDC_HandleTypeDef  hltdc;
21 
22      (#) Initialize the LTDC low level resources by implementing the HAL_LTDC_MspInit() API:
23          (##) Enable the LTDC interface clock
24          (##) NVIC configuration if you need to use interrupt process
25              (+++) Configure the LTDC interrupt priority
26              (+++) Enable the NVIC LTDC IRQ Channel
27 
28      (#) Initialize the required configuration through the following parameters:
29          the LTDC timing, the horizontal and vertical polarity, the pixel clock polarity,
30          Data Enable polarity and the LTDC background color value using HAL_LTDC_Init() function
31 
32      *** Configuration ***
33      =========================
34      [..]
35      (#) Program the required configuration through the following parameters:
36          the pixel format, the blending factors, input alpha value, the window size
37          and the image size using HAL_LTDC_ConfigLayer() function for foreground
38          or/and background layer.
39 
40      (#) Optionally, configure and enable the CLUT using HAL_LTDC_ConfigCLUT() and
41          HAL_LTDC_EnableCLUT functions.
42 
43      (#) Optionally, enable the Dither using HAL_LTDC_EnableDither().
44 
45      (#) Optionally, configure and enable the Color keying using HAL_LTDC_ConfigColorKeying()
46          and HAL_LTDC_EnableColorKeying functions.
47 
48      (#) Optionally, configure LineInterrupt using HAL_LTDC_ProgramLineEvent()
49          function
50 
51      (#) If needed, reconfigure and change the pixel format value, the alpha value
52          value, the window size, the window position and the layer start address
53          for foreground or/and background layer using respectively the following
54          functions: HAL_LTDC_SetPixelFormat(), HAL_LTDC_SetAlpha(), HAL_LTDC_SetWindowSize(),
55          HAL_LTDC_SetWindowPosition() and HAL_LTDC_SetAddress().
56 
57      (#) Variant functions with _NoReload suffix allows to set the LTDC configuration/settings without immediate reload.
58          This is useful in case when the program requires to modify serval LTDC settings (on one or both layers)
59          then applying(reload) these settings in one shot by calling the function HAL_LTDC_Reload().
60 
61          After calling the _NoReload functions to set different color/format/layer settings,
62          the program shall call the function HAL_LTDC_Reload() to apply(reload) these settings.
63          Function HAL_LTDC_Reload() can be called with the parameter ReloadType set to LTDC_RELOAD_IMMEDIATE if
64          an immediate reload is required.
65          Function HAL_LTDC_Reload() can be called with the parameter ReloadType set to LTDC_RELOAD_VERTICAL_BLANKING if
66          the reload should be done in the next vertical blanking period,
67          this option allows to avoid display flicker by applying the new settings during the vertical blanking period.
68 
69 
70      (#) To control LTDC state you can use the following function: HAL_LTDC_GetState()
71 
72      *** LTDC HAL driver macros list ***
73      =============================================
74      [..]
75        Below the list of most used macros in LTDC HAL driver.
76 
77       (+) __HAL_LTDC_ENABLE: Enable the LTDC.
78       (+) __HAL_LTDC_DISABLE: Disable the LTDC.
79       (+) __HAL_LTDC_LAYER_ENABLE: Enable an LTDC Layer.
80       (+) __HAL_LTDC_LAYER_DISABLE: Disable an LTDC Layer.
81       (+) __HAL_LTDC_RELOAD_IMMEDIATE_CONFIG: Reload  Layer Configuration.
82       (+) __HAL_LTDC_GET_FLAG: Get the LTDC pending flags.
83       (+) __HAL_LTDC_CLEAR_FLAG: Clear the LTDC pending flags.
84       (+) __HAL_LTDC_ENABLE_IT: Enable the specified LTDC interrupts.
85       (+) __HAL_LTDC_DISABLE_IT: Disable the specified LTDC interrupts.
86       (+) __HAL_LTDC_GET_IT_SOURCE: Check whether the specified LTDC interrupt has occurred or not.
87 
88      [..]
89        (@) You can refer to the LTDC HAL driver header file for more useful macros
90 
91 
92      *** Callback registration ***
93      =============================================
94      [..]
95      The compilation define  USE_HAL_LTDC_REGISTER_CALLBACKS when set to 1
96      allows the user to configure dynamically the driver callbacks.
97      Use function HAL_LTDC_RegisterCallback() to register a callback.
98 
99     [..]
100     Function HAL_LTDC_RegisterCallback() allows to register following callbacks:
101       (+) LineEventCallback   : LTDC Line Event Callback.
102       (+) ReloadEventCallback : LTDC Reload Event Callback.
103       (+) ErrorCallback       : LTDC Error Callback
104       (+) MspInitCallback     : LTDC MspInit.
105       (+) MspDeInitCallback   : LTDC MspDeInit.
106     [..]
107     This function takes as parameters the HAL peripheral handle, the callback ID
108     and a pointer to the user callback function.
109 
110     [..]
111     Use function HAL_LTDC_UnRegisterCallback() to reset a callback to the default
112     weak function.
113     HAL_LTDC_UnRegisterCallback() takes as parameters the HAL peripheral handle
114     and the callback ID.
115     [..]
116     This function allows to reset following callbacks:
117       (+) LineEventCallback   : LTDC Line Event Callback
118       (+) ReloadEventCallback : LTDC Reload Event Callback
119       (+) ErrorCallback       : LTDC Error Callback
120       (+) MspInitCallback     : LTDC MspInit
121       (+) MspDeInitCallback   : LTDC MspDeInit.
122 
123     [..]
124     By default, after the HAL_LTDC_Init and when the state is HAL_LTDC_STATE_RESET
125     all callbacks are set to the corresponding weak functions:
126     examples HAL_LTDC_LineEventCallback(), HAL_LTDC_ErrorCallback().
127     Exception done for MspInit and MspDeInit functions that are
128     reset to the legacy weak (surcharged) functions in the HAL_LTDC_Init() and HAL_LTDC_DeInit()
129     only when these callbacks are null (not registered beforehand).
130     If not, MspInit or MspDeInit are not null, the HAL_LTDC_Init() and HAL_LTDC_DeInit()
131     keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
132 
133     [..]
134     Callbacks can be registered/unregistered in HAL_LTDC_STATE_READY state only.
135     Exception done MspInit/MspDeInit that can be registered/unregistered
136     in HAL_LTDC_STATE_READY or HAL_LTDC_STATE_RESET state,
137     thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
138     In that case first register the MspInit/MspDeInit user callbacks
139     using HAL_LTDC_RegisterCallback() before calling HAL_LTDC_DeInit()
140     or HAL_LTDC_Init() function.
141 
142     [..]
143     When the compilation define USE_HAL_LTDC_REGISTER_CALLBACKS is set to 0 or
144     not defined, the callback registration feature is not available and all callbacks
145     are set to the corresponding weak functions.
146 
147   @endverbatim
148   ******************************************************************************
149   * @attention
150   *
151   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
152   * All rights reserved.</center></h2>
153   *
154   * This software component is licensed by ST under BSD 3-Clause license,
155   * the "License"; You may not use this file except in compliance with the
156   * License. You may obtain a copy of the License at:
157   *                        opensource.org/licenses/BSD-3-Clause
158   *
159   ******************************************************************************
160   */
161 
162 /* Includes ------------------------------------------------------------------*/
163 #include "stm32mp1xx_hal_ltdc.h"
164 
165 /** @addtogroup STM32H7xx_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 /* Private macro -------------------------------------------------------------*/
182 /* Private variables ---------------------------------------------------------*/
183 /* Private function prototypes -----------------------------------------------*/
184 static void LTDC_SetConfig(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx);
185 /* Private functions ---------------------------------------------------------*/
186 
187 /** @defgroup LTDC_Exported_Functions LTDC Exported Functions
188   * @{
189   */
190 
191 /** @defgroup LTDC_Exported_Functions_Group1 Initialization and Configuration functions
192   *  @brief   Initialization and Configuration functions
193   *
194 @verbatim
195  ===============================================================================
196                 ##### Initialization and Configuration functions #####
197  ===============================================================================
198     [..]  This section provides functions allowing to:
199       (+) Initialize and configure the LTDC
200       (+) De-initialize the LTDC
201 
202 @endverbatim
203   * @{
204   */
205 
206 /**
207   * @brief  Initialize the LTDC according to the specified parameters in the LTDC_InitTypeDef.
208   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
209   *                the configuration information for the LTDC.
210   * @retval HAL status
211   */
HAL_LTDC_Init(LTDC_HandleTypeDef * hltdc)212 HAL_StatusTypeDef HAL_LTDC_Init(LTDC_HandleTypeDef *hltdc)
213 {
214   uint32_t tmp, tmp1;
215 
216   /* Check the LTDC peripheral state */
217   if (hltdc == NULL)
218   {
219     return HAL_ERROR;
220   }
221 
222 // #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
223 //   if (hltdc->State == HAL_LTDC_STATE_RESET)
224 //   {
225 //     /* Allocate lock resource and initialize it */
226 //     hltdc->Lock = HAL_UNLOCKED;
227 
228 //     /* Reset the LTDC callback to the legacy weak callbacks */
229 //     hltdc->LineEventCallback   = HAL_LTDC_LineEventCallback;    /* Legacy weak LineEventCallback    */
230 //     hltdc->ReloadEventCallback = HAL_LTDC_ReloadEventCallback;  /* Legacy weak ReloadEventCallback  */
231 //     hltdc->ErrorCallback       = HAL_LTDC_ErrorCallback;        /* Legacy weak ErrorCallback        */
232 
233 //     if (hltdc->MspInitCallback == NULL)
234 //     {
235 //       hltdc->MspInitCallback = HAL_LTDC_MspInit;
236 //     }
237 //     /* Init the low level hardware */
238 //     hltdc->MspInitCallback(hltdc);
239 //   }
240 // #else
241   if (hltdc->State == HAL_LTDC_STATE_RESET)
242   {
243     /* Allocate lock resource and initialize it */
244     // hltdc->Lock = HAL_UNLOCKED;
245     /* Init the low level hardware */
246     // HAL_LTDC_MspInit(hltdc);
247   }
248 // #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
249 
250   /* Change LTDC peripheral state */
251   hltdc->State = HAL_LTDC_STATE_BUSY;
252 
253   /* Configure the HS, VS, DE and PC polarity */
254   hltdc->Instance->GCR &= ~(LTDC_GCR_HSPOL | LTDC_GCR_VSPOL | LTDC_GCR_DEPOL | LTDC_GCR_PCPOL);
255   hltdc->Instance->GCR |= (uint32_t)(hltdc->Init.HSPolarity | hltdc->Init.VSPolarity | \
256                                      hltdc->Init.DEPolarity | hltdc->Init.PCPolarity);
257 
258   /* Set Synchronization size */
259   hltdc->Instance->SSCR &= ~(LTDC_SSCR_VSH | LTDC_SSCR_HSW);
260   tmp = (hltdc->Init.HorizontalSync << 16U);
261   hltdc->Instance->SSCR |= (tmp | hltdc->Init.VerticalSync);
262 
263   /* Set Accumulated Back porch */
264   hltdc->Instance->BPCR &= ~(LTDC_BPCR_AVBP | LTDC_BPCR_AHBP);
265   tmp = (hltdc->Init.AccumulatedHBP << 16U);
266   hltdc->Instance->BPCR |= (tmp | hltdc->Init.AccumulatedVBP);
267 
268   /* Set Accumulated Active Width */
269   hltdc->Instance->AWCR &= ~(LTDC_AWCR_AAH | LTDC_AWCR_AAW);
270   tmp = (hltdc->Init.AccumulatedActiveW << 16U);
271   hltdc->Instance->AWCR |= (tmp | hltdc->Init.AccumulatedActiveH);
272 
273   /* Set Total Width */
274   hltdc->Instance->TWCR &= ~(LTDC_TWCR_TOTALH | LTDC_TWCR_TOTALW);
275   tmp = (hltdc->Init.TotalWidth << 16U);
276   hltdc->Instance->TWCR |= (tmp | hltdc->Init.TotalHeigh);
277 
278   /* Set the background color value */
279   tmp = ((uint32_t)(hltdc->Init.Backcolor.Green) << 8U);
280   tmp1 = ((uint32_t)(hltdc->Init.Backcolor.Red) << 16U);
281   hltdc->Instance->BCCR &= ~(LTDC_BCCR_BCBLUE | LTDC_BCCR_BCGREEN | LTDC_BCCR_BCRED);
282   hltdc->Instance->BCCR |= (tmp1 | tmp | hltdc->Init.Backcolor.Blue);
283 
284   /* Enable the Transfer Error and FIFO underrun interrupts */
285   __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_TE | LTDC_IT_FU);
286 
287   /* Enable LTDC by setting LTDCEN bit */
288   __HAL_LTDC_ENABLE(hltdc);
289 
290   /* Initialize the error code */
291   hltdc->ErrorCode = HAL_LTDC_ERROR_NONE;
292 
293   /* Initialize the LTDC state*/
294   hltdc->State = HAL_LTDC_STATE_READY;
295 
296   return HAL_OK;
297 }
298 
299 /**
300   * @brief  De-initialize the LTDC peripheral.
301   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
302   *                the configuration information for the LTDC.
303   * @retval None
304   */
305 
HAL_LTDC_DeInit(LTDC_HandleTypeDef * hltdc)306 HAL_StatusTypeDef HAL_LTDC_DeInit(LTDC_HandleTypeDef *hltdc)
307 {
308 // #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
309 //   if (hltdc->MspDeInitCallback == NULL)
310 //   {
311 //     hltdc->MspDeInitCallback = HAL_LTDC_MspDeInit;
312 //   }
313 //   /* DeInit the low level hardware */
314 //   hltdc->MspDeInitCallback(hltdc);
315 // #else
316   /* DeInit the low level hardware */
317   // HAL_LTDC_MspDeInit(hltdc);
318 // #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
319 
320   /* Initialize the error code */
321   hltdc->ErrorCode = HAL_LTDC_ERROR_NONE;
322 
323   /* Initialize the LTDC state*/
324   hltdc->State = HAL_LTDC_STATE_RESET;
325 
326   /* Release Lock */
327   // __HAL_UNLOCK(hltdc);
328 
329   return HAL_OK;
330 }
331 
332 
333 
334 #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
335 /**
336   * @brief  Register a User LTDC Callback
337   *         To be used instead of the weak predefined callback
338   * @param hltdc ltdc handle
339   * @param CallbackID ID of the callback to be registered
340   *        This parameter can be one of the following values:
341   *          @arg @ref HAL_LTDC_LINE_EVENT_CB_ID Line Event Callback ID
342   *          @arg @ref HAL_LTDC_RELOAD_EVENT_CB_ID Reload Event Callback ID
343   *          @arg @ref HAL_LTDC_ERROR_CB_ID Error Callback ID
344   *          @arg @ref HAL_LTDC_MSPINIT_CB_ID MspInit callback ID
345   *          @arg @ref HAL_LTDC_MSPDEINIT_CB_ID MspDeInit callback ID
346   * @param pCallback pointer to the Callback function
347   * @retval status
348   */
HAL_LTDC_RegisterCallback(LTDC_HandleTypeDef * hltdc,HAL_LTDC_CallbackIDTypeDef CallbackID,pLTDC_CallbackTypeDef pCallback)349 HAL_StatusTypeDef HAL_LTDC_RegisterCallback(LTDC_HandleTypeDef *hltdc, HAL_LTDC_CallbackIDTypeDef CallbackID, pLTDC_CallbackTypeDef pCallback)
350 {
351   HAL_StatusTypeDef status = HAL_OK;
352 
353   if (pCallback == NULL)
354   {
355     /* Update the error code */
356     hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
357 
358     return HAL_ERROR;
359   }
360   /* Process locked */
361   __HAL_LOCK(hltdc);
362 
363   if (hltdc->State == HAL_LTDC_STATE_READY)
364   {
365     switch (CallbackID)
366     {
367       case HAL_LTDC_LINE_EVENT_CB_ID :
368         hltdc->LineEventCallback = pCallback;
369         break;
370 
371       case HAL_LTDC_RELOAD_EVENT_CB_ID :
372         hltdc->ReloadEventCallback = pCallback;
373         break;
374 
375       case HAL_LTDC_ERROR_CB_ID :
376         hltdc->ErrorCallback = pCallback;
377         break;
378 
379       case HAL_LTDC_MSPINIT_CB_ID :
380         hltdc->MspInitCallback = pCallback;
381         break;
382 
383       case HAL_LTDC_MSPDEINIT_CB_ID :
384         hltdc->MspDeInitCallback = pCallback;
385         break;
386 
387       default :
388         /* Update the error code */
389         hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
390         /* Return error status */
391         status =  HAL_ERROR;
392         break;
393     }
394   }
395   else if (hltdc->State == HAL_LTDC_STATE_RESET)
396   {
397     switch (CallbackID)
398     {
399       case HAL_LTDC_MSPINIT_CB_ID :
400         hltdc->MspInitCallback = pCallback;
401         break;
402 
403       case HAL_LTDC_MSPDEINIT_CB_ID :
404         hltdc->MspDeInitCallback = pCallback;
405         break;
406 
407       default :
408         /* Update the error code */
409         hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
410         /* Return error status */
411         status =  HAL_ERROR;
412         break;
413     }
414   }
415   else
416   {
417     /* Update the error code */
418     hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
419     /* Return error status */
420     status =  HAL_ERROR;
421   }
422 
423   /* Release Lock */
424   __HAL_UNLOCK(hltdc);
425 
426   return status;
427 }
428 
429 /**
430   * @brief  Unregister an LTDC Callback
431   *         LTDC callabck is redirected to the weak predefined callback
432   * @param hltdc ltdc handle
433   * @param CallbackID ID of the callback to be unregistered
434   *        This parameter can be one of the following values:
435   *          @arg @ref HAL_LTDC_LINE_EVENT_CB_ID Line Event Callback ID
436   *          @arg @ref HAL_LTDC_RELOAD_EVENT_CB_ID Reload Event Callback ID
437   *          @arg @ref HAL_LTDC_ERROR_CB_ID Error Callback ID
438   *          @arg @ref HAL_LTDC_MSPINIT_CB_ID MspInit callback ID
439   *          @arg @ref HAL_LTDC_MSPDEINIT_CB_ID MspDeInit callback ID
440   * @retval status
441   */
HAL_LTDC_UnRegisterCallback(LTDC_HandleTypeDef * hltdc,HAL_LTDC_CallbackIDTypeDef CallbackID)442 HAL_StatusTypeDef HAL_LTDC_UnRegisterCallback(LTDC_HandleTypeDef *hltdc, HAL_LTDC_CallbackIDTypeDef CallbackID)
443 {
444   HAL_StatusTypeDef status = HAL_OK;
445 
446   /* Process locked */
447   __HAL_LOCK(hltdc);
448 
449   if (hltdc->State == HAL_LTDC_STATE_READY)
450   {
451     switch (CallbackID)
452     {
453       case HAL_LTDC_LINE_EVENT_CB_ID :
454         hltdc->LineEventCallback = HAL_LTDC_LineEventCallback;      /* Legacy weak LineEventCallback    */
455         break;
456 
457       case HAL_LTDC_RELOAD_EVENT_CB_ID :
458         hltdc->ReloadEventCallback = HAL_LTDC_ReloadEventCallback;  /* Legacy weak ReloadEventCallback  */
459         break;
460 
461       case HAL_LTDC_ERROR_CB_ID :
462         hltdc->ErrorCallback       = HAL_LTDC_ErrorCallback;        /* Legacy weak ErrorCallback        */
463         break;
464 
465       case HAL_LTDC_MSPINIT_CB_ID :
466         hltdc->MspInitCallback = HAL_LTDC_MspInit;                  /* Legcay weak MspInit Callback     */
467         break;
468 
469       case HAL_LTDC_MSPDEINIT_CB_ID :
470         hltdc->MspDeInitCallback = HAL_LTDC_MspDeInit;              /* Legcay weak MspDeInit Callback     */
471         break;
472 
473       default :
474         /* Update the error code */
475         hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
476         /* Return error status */
477         status =  HAL_ERROR;
478         break;
479     }
480   }
481   else if (hltdc->State == HAL_LTDC_STATE_RESET)
482   {
483     switch (CallbackID)
484     {
485       case HAL_LTDC_MSPINIT_CB_ID :
486         hltdc->MspInitCallback = HAL_LTDC_MspInit;                  /* Legcay weak MspInit Callback     */
487         break;
488 
489       case HAL_LTDC_MSPDEINIT_CB_ID :
490         hltdc->MspDeInitCallback = HAL_LTDC_MspDeInit;              /* Legcay weak MspDeInit Callback     */
491         break;
492 
493       default :
494         /* Update the error code */
495         hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
496         /* Return error status */
497         status =  HAL_ERROR;
498         break;
499     }
500   }
501   else
502   {
503     /* Update the error code */
504     hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
505     /* Return error status */
506     status =  HAL_ERROR;
507   }
508 
509   /* Release Lock */
510   __HAL_UNLOCK(hltdc);
511 
512   return status;
513 }
514 #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
515 
516 /**
517   * @}
518   */
519 
520 /** @defgroup LTDC_Exported_Functions_Group2 IO operation functions
521   *  @brief   IO operation functions
522   *
523 @verbatim
524  ===============================================================================
525                       #####  IO operation functions  #####
526  ===============================================================================
527     [..]  This section provides function allowing to:
528       (+) Handle LTDC interrupt request
529 
530 @endverbatim
531   * @{
532   */
533 
534 
535 
536 
537 /**
538   * @}
539   */
540 
541 /** @defgroup LTDC_Exported_Functions_Group3 Peripheral Control functions
542   *  @brief    Peripheral Control functions
543   *
544 @verbatim
545  ===============================================================================
546                     ##### Peripheral Control functions #####
547  ===============================================================================
548     [..]  This section provides functions allowing to:
549       (+) Configure the LTDC foreground or/and background parameters.
550       (+) Set the active layer.
551       (+) Configure the color keying.
552       (+) Configure the C-LUT.
553       (+) Enable / Disable the color keying.
554       (+) Enable / Disable the C-LUT.
555       (+) Update the layer position.
556       (+) Update the layer size.
557       (+) Update pixel format on the fly.
558       (+) Update transparency on the fly.
559       (+) Update address on the fly.
560 
561 @endverbatim
562   * @{
563   */
564 
565 /**
566   * @brief  Configure the LTDC Layer according to the specified
567   *         parameters in the LTDC_InitTypeDef and create the associated handle.
568   * @param  hltdc      pointer to a LTDC_HandleTypeDef structure that contains
569   *                    the configuration information for the LTDC.
570   * @param  pLayerCfg  pointer to a LTDC_LayerCfgTypeDef structure that contains
571   *                    the configuration information for the Layer.
572   * @param  LayerIdx  LTDC Layer index.
573   *                    This parameter can be one of the following values:
574   *                    LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
575   * @retval HAL status
576   */
HAL_LTDC_ConfigLayer(LTDC_HandleTypeDef * hltdc,LTDC_LayerCfgTypeDef * pLayerCfg,uint32_t LayerIdx)577 HAL_StatusTypeDef HAL_LTDC_ConfigLayer(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)
578 {
579   /* Change LTDC peripheral state */
580   hltdc->State = HAL_LTDC_STATE_BUSY;
581 
582   /* Copy new layer configuration into handle structure */
583   hltdc->LayerCfg[LayerIdx] = *pLayerCfg;
584 
585   /* Configure the LTDC Layer */
586   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
587 
588   /* Set the Immediate Reload type */
589   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
590 
591   /* Initialize the LTDC state*/
592   hltdc->State  = HAL_LTDC_STATE_READY;
593 
594   return HAL_OK;
595 }
596 
597 /**
598   * @brief  Configure the color keying.
599   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
600   *                   the configuration information for the LTDC.
601   * @param  RGBValue  the color key value
602   * @param  LayerIdx  LTDC Layer index.
603   *                   This parameter can be one of the following values:
604   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
605   * @retval HAL status
606   */
HAL_LTDC_ConfigColorKeying(LTDC_HandleTypeDef * hltdc,uint32_t RGBValue,uint32_t LayerIdx)607 HAL_StatusTypeDef HAL_LTDC_ConfigColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t RGBValue, uint32_t LayerIdx)
608 {
609   /* Change LTDC peripheral state */
610   hltdc->State = HAL_LTDC_STATE_BUSY;
611 
612   /* Configure the default color values */
613   LTDC_LAYER(hltdc, LayerIdx)->CKCR &=  ~(LTDC_LxCKCR_CKBLUE | LTDC_LxCKCR_CKGREEN | LTDC_LxCKCR_CKRED);
614   LTDC_LAYER(hltdc, LayerIdx)->CKCR  = RGBValue;
615 
616   /* Set the Immediate Reload type */
617   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
618 
619   /* Change the LTDC state*/
620   hltdc->State = HAL_LTDC_STATE_READY;
621 
622   return HAL_OK;
623 }
624 
625 /**
626   * @brief  Load the color lookup table.
627   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
628   *                   the configuration information for the LTDC.
629   * @param  pCLUT     pointer to the color lookup table address.
630   * @param  CLUTSize  the color lookup table size.
631   * @param  LayerIdx  LTDC Layer index.
632   *                   This parameter can be one of the following values:
633   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
634   * @retval HAL status
635   */
HAL_LTDC_ConfigCLUT(LTDC_HandleTypeDef * hltdc,uint32_t * pCLUT,uint32_t CLUTSize,uint32_t LayerIdx)636 HAL_StatusTypeDef HAL_LTDC_ConfigCLUT(LTDC_HandleTypeDef *hltdc, uint32_t *pCLUT, uint32_t CLUTSize, uint32_t LayerIdx)
637 {
638   uint32_t tmp;
639   uint32_t counter;
640   uint32_t *pcolorlut = pCLUT;
641 
642   /* Change LTDC peripheral state */
643   hltdc->State = HAL_LTDC_STATE_BUSY;
644 
645   for (counter = 0U; (counter < CLUTSize); counter++)
646   {
647     if (hltdc->LayerCfg[LayerIdx].PixelFormat == LTDC_PIXEL_FORMAT_AL44)
648     {
649       tmp  = (((counter + (16U*counter)) << 24U) | ((uint32_t)(*pcolorlut) & 0xFFU) | ((uint32_t)(*pcolorlut) & 0xFF00U) | ((uint32_t)(*pcolorlut) & 0xFF0000U));
650     }
651     else
652     {
653       tmp  = ((counter << 24U) | ((uint32_t)(*pcolorlut) & 0xFFU) | ((uint32_t)(*pcolorlut) & 0xFF00U) | ((uint32_t)(*pcolorlut) & 0xFF0000U));
654     }
655 
656     pcolorlut++;
657 
658     /* Specifies the C-LUT address and RGB value */
659     LTDC_LAYER(hltdc, LayerIdx)->CLUTWR  = tmp;
660   }
661 
662   /* Change the LTDC state*/
663   hltdc->State = HAL_LTDC_STATE_READY;
664 
665   return HAL_OK;
666 }
667 
668 /**
669   * @brief  Enable the color keying.
670   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
671   *                   the configuration information for the LTDC.
672   * @param  LayerIdx  LTDC Layer index.
673   *                   This parameter can be one of the following values:
674   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
675   * @retval  HAL status
676   */
HAL_LTDC_EnableColorKeying(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)677 HAL_StatusTypeDef HAL_LTDC_EnableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
678 {
679   /* Change LTDC peripheral state */
680   hltdc->State = HAL_LTDC_STATE_BUSY;
681 
682   /* Enable LTDC color keying by setting COLKEN bit */
683   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_COLKEN;
684 
685   /* Set the Immediate Reload type */
686   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
687 
688   /* Change the LTDC state*/
689   hltdc->State = HAL_LTDC_STATE_READY;
690 
691   return HAL_OK;
692 }
693 
694 /**
695   * @brief  Disable the color keying.
696   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
697   *                   the configuration information for the LTDC.
698   * @param  LayerIdx  LTDC Layer index.
699   *                   This parameter can be one of the following values:
700   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
701   * @retval  HAL status
702   */
HAL_LTDC_DisableColorKeying(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)703 HAL_StatusTypeDef HAL_LTDC_DisableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
704 {
705   /* Change LTDC peripheral state */
706   hltdc->State = HAL_LTDC_STATE_BUSY;
707 
708   /* Disable LTDC color keying by setting COLKEN bit */
709   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_COLKEN;
710 
711   /* Set the Immediate Reload type */
712   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
713 
714   /* Change the LTDC state*/
715   hltdc->State = HAL_LTDC_STATE_READY;
716 
717   return HAL_OK;
718 }
719 
720 /**
721   * @brief  Enable the color lookup table.
722   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
723   *                   the configuration information for the LTDC.
724   * @param  LayerIdx  LTDC Layer index.
725   *                   This parameter can be one of the following values:
726   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
727   * @retval  HAL status
728   */
HAL_LTDC_EnableCLUT(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)729 HAL_StatusTypeDef HAL_LTDC_EnableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
730 {
731   /* Change LTDC peripheral state */
732   hltdc->State = HAL_LTDC_STATE_BUSY;
733 
734   /* Enable LTDC color lookup table by setting CLUTEN bit */
735   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_CLUTEN;
736 
737   /* Set the Immediate Reload type */
738   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
739 
740   /* Change the LTDC state*/
741   hltdc->State = HAL_LTDC_STATE_READY;
742 
743   return HAL_OK;
744 }
745 
746 /**
747   * @brief  Disable the color lookup table.
748   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
749   *                   the configuration information for the LTDC.
750   * @param  LayerIdx  LTDC Layer index.
751   *                   This parameter can be one of the following values:
752   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
753   * @retval  HAL status
754   */
HAL_LTDC_DisableCLUT(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)755 HAL_StatusTypeDef HAL_LTDC_DisableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
756 {
757   /* Change LTDC peripheral state */
758   hltdc->State = HAL_LTDC_STATE_BUSY;
759 
760   /* Disable LTDC color lookup table by setting CLUTEN bit */
761   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_CLUTEN;
762 
763   /* Set the Immediate Reload type */
764   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
765 
766   /* Change the LTDC state*/
767   hltdc->State = HAL_LTDC_STATE_READY;
768 
769   return HAL_OK;
770 }
771 
772 /**
773   * @brief  Enable Dither.
774   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
775   *                the configuration information for the LTDC.
776   * @retval  HAL status
777   */
778 
HAL_LTDC_EnableDither(LTDC_HandleTypeDef * hltdc)779 HAL_StatusTypeDef HAL_LTDC_EnableDither(LTDC_HandleTypeDef *hltdc)
780 {
781   /* Change LTDC peripheral state */
782   hltdc->State = HAL_LTDC_STATE_BUSY;
783 
784   /* Enable Dither by setting DTEN bit */
785   LTDC->GCR |= (uint32_t)LTDC_GCR_DEN;
786 
787   /* Change the LTDC state*/
788   hltdc->State = HAL_LTDC_STATE_READY;
789 
790   return HAL_OK;
791 }
792 
793 /**
794   * @brief  Disable Dither.
795   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
796   *                the configuration information for the LTDC.
797   * @retval  HAL status
798   */
799 
HAL_LTDC_DisableDither(LTDC_HandleTypeDef * hltdc)800 HAL_StatusTypeDef HAL_LTDC_DisableDither(LTDC_HandleTypeDef *hltdc)
801 {
802   /* Change LTDC peripheral state */
803   hltdc->State = HAL_LTDC_STATE_BUSY;
804 
805   /* Disable Dither by setting DTEN bit */
806   LTDC->GCR &= ~(uint32_t)LTDC_GCR_DEN;
807 
808   /* Change the LTDC state*/
809   hltdc->State = HAL_LTDC_STATE_READY;
810 
811   return HAL_OK;
812 }
813 
814 /**
815   * @brief  Set the LTDC window size.
816   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
817   *                   the configuration information for the LTDC.
818   * @param  XSize     LTDC Pixel per line
819   * @param  YSize     LTDC Line number
820   * @param  LayerIdx  LTDC Layer index.
821   *                   This parameter can be one of the following values:
822   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
823   * @retval  HAL status
824   */
HAL_LTDC_SetWindowSize(LTDC_HandleTypeDef * hltdc,uint32_t XSize,uint32_t YSize,uint32_t LayerIdx)825 HAL_StatusTypeDef HAL_LTDC_SetWindowSize(LTDC_HandleTypeDef *hltdc, uint32_t XSize, uint32_t YSize, uint32_t LayerIdx)
826 {
827   LTDC_LayerCfgTypeDef *pLayerCfg;
828 
829   /* Change LTDC peripheral state */
830   hltdc->State = HAL_LTDC_STATE_BUSY;
831 
832   /* Get layer configuration from handle structure */
833   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
834 
835   /* update horizontal stop */
836   pLayerCfg->WindowX1 = XSize + pLayerCfg->WindowX0;
837 
838   /* update vertical stop */
839   pLayerCfg->WindowY1 = YSize + pLayerCfg->WindowY0;
840 
841   /* Reconfigures the color frame buffer pitch in byte */
842   pLayerCfg->ImageWidth = XSize;
843 
844   /* Reconfigures the frame buffer line number */
845   pLayerCfg->ImageHeight = YSize;
846 
847   /* Set LTDC parameters */
848   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
849 
850   /* Set the Immediate Reload type */
851   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
852 
853   /* Change the LTDC state*/
854   hltdc->State = HAL_LTDC_STATE_READY;
855 
856   return HAL_OK;
857 }
858 
859 /**
860   * @brief  Set the LTDC window position.
861   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
862   *                   the configuration information for the LTDC.
863   * @param  X0        LTDC window X offset
864   * @param  Y0        LTDC window Y offset
865   * @param  LayerIdx  LTDC Layer index.
866   *                         This parameter can be one of the following values:
867   *                         LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
868   * @retval  HAL status
869   */
HAL_LTDC_SetWindowPosition(LTDC_HandleTypeDef * hltdc,uint32_t X0,uint32_t Y0,uint32_t LayerIdx)870 HAL_StatusTypeDef HAL_LTDC_SetWindowPosition(LTDC_HandleTypeDef *hltdc, uint32_t X0, uint32_t Y0, uint32_t LayerIdx)
871 {
872   LTDC_LayerCfgTypeDef *pLayerCfg;
873 
874   /* Change LTDC peripheral state */
875   hltdc->State = HAL_LTDC_STATE_BUSY;
876 
877   /* Get layer configuration from handle structure */
878   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
879 
880   /* update horizontal start/stop */
881   pLayerCfg->WindowX0 = X0;
882   pLayerCfg->WindowX1 = X0 + pLayerCfg->ImageWidth;
883 
884   /* update vertical start/stop */
885   pLayerCfg->WindowY0 = Y0;
886   pLayerCfg->WindowY1 = Y0 + pLayerCfg->ImageHeight;
887 
888   /* Set LTDC parameters */
889   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
890 
891   /* Set the Immediate Reload type */
892   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
893 
894   /* Change the LTDC state*/
895   hltdc->State = HAL_LTDC_STATE_READY;
896 
897   return HAL_OK;
898 }
899 
900 /**
901   * @brief  Reconfigure the pixel format.
902   * @param  hltdc        pointer to a LTDC_HandleTypeDef structure that contains
903   *                      the configuration information for the LTDC.
904   * @param  Pixelformat  new pixel format value.
905   * @param  LayerIdx     LTDC Layer index.
906   *                      This parameter can be one of the following values:
907   *                      LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
908   * @retval  HAL status
909   */
HAL_LTDC_SetPixelFormat(LTDC_HandleTypeDef * hltdc,uint32_t Pixelformat,uint32_t LayerIdx)910 HAL_StatusTypeDef HAL_LTDC_SetPixelFormat(LTDC_HandleTypeDef *hltdc, uint32_t Pixelformat, uint32_t LayerIdx)
911 {
912   LTDC_LayerCfgTypeDef *pLayerCfg;
913 
914   /* Change LTDC peripheral state */
915   hltdc->State = HAL_LTDC_STATE_BUSY;
916 
917   /* Get layer configuration from handle structure */
918   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
919 
920   /* Reconfigure the pixel format */
921   pLayerCfg->PixelFormat = Pixelformat;
922 
923   /* Set LTDC parameters */
924   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
925 
926   /* Set the Immediate Reload type */
927   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
928 
929   /* Change the LTDC state*/
930   hltdc->State = HAL_LTDC_STATE_READY;
931 
932   return HAL_OK;
933 }
934 
935 /**
936   * @brief  Reconfigure the layer alpha value.
937   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
938   *                   the configuration information for the LTDC.
939   * @param  Alpha     new alpha value.
940   * @param  LayerIdx  LTDC Layer index.
941   *                   This parameter can be one of the following values:
942   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
943   * @retval  HAL status
944   */
HAL_LTDC_SetAlpha(LTDC_HandleTypeDef * hltdc,uint32_t Alpha,uint32_t LayerIdx)945 HAL_StatusTypeDef HAL_LTDC_SetAlpha(LTDC_HandleTypeDef *hltdc, uint32_t Alpha, uint32_t LayerIdx)
946 {
947   LTDC_LayerCfgTypeDef *pLayerCfg;
948 
949   /* Change LTDC peripheral state */
950   hltdc->State = HAL_LTDC_STATE_BUSY;
951 
952   /* Get layer configuration from handle structure */
953   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
954 
955   /* Reconfigure the Alpha value */
956   pLayerCfg->Alpha = Alpha;
957 
958   /* Set LTDC parameters */
959   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
960 
961   /* Set the Immediate Reload type */
962   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
963 
964   /* Change the LTDC state*/
965   hltdc->State = HAL_LTDC_STATE_READY;
966 
967   return HAL_OK;
968 }
969 /**
970   * @brief  Reconfigure the frame buffer Address.
971   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
972   *                   the configuration information for the LTDC.
973   * @param  Address   new address value.
974   * @param  LayerIdx  LTDC Layer index.
975   *                   This parameter can be one of the following values:
976   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
977   * @retval  HAL status
978   */
HAL_LTDC_SetAddress(LTDC_HandleTypeDef * hltdc,uint32_t Address,uint32_t LayerIdx)979 HAL_StatusTypeDef HAL_LTDC_SetAddress(LTDC_HandleTypeDef *hltdc, uint32_t Address, uint32_t LayerIdx)
980 {
981   LTDC_LayerCfgTypeDef *pLayerCfg;
982 
983   /* Change LTDC peripheral state */
984   hltdc->State = HAL_LTDC_STATE_BUSY;
985 
986   /* Get layer configuration from handle structure */
987   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
988 
989   /* Reconfigure the Address */
990   pLayerCfg->FBStartAdress = Address;
991 
992   /* Set LTDC parameters */
993   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
994 
995   /* Set the Immediate Reload type */
996   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
997 
998   /* Change the LTDC state*/
999   hltdc->State = HAL_LTDC_STATE_READY;
1000 
1001   return HAL_OK;
1002 }
1003 
1004 /**
1005   * @brief  Function used to reconfigure the pitch for specific cases where the attached LayerIdx buffer have a width that is
1006   *         larger than the one intended to be displayed on screen. Example of a buffer 800x480 attached to layer for which we
1007   *         want to read and display on screen only a portion 320x240 taken in the center of the buffer. The pitch in pixels
1008   *         will be in that case 800 pixels and not 320 pixels as initially configured by previous call to HAL_LTDC_ConfigLayer().
1009   * @note   This function should be called only after a previous call to HAL_LTDC_ConfigLayer() to modify the default pitch
1010   *         configured by HAL_LTDC_ConfigLayer() when required (refer to example described just above).
1011   * @param  hltdc              pointer to a LTDC_HandleTypeDef structure that contains
1012   *                            the configuration information for the LTDC.
1013   * @param  LinePitchInPixels  New line pitch in pixels to configure for LTDC layer 'LayerIdx'.
1014   * @param  LayerIdx           LTDC layer index concerned by the modification of line pitch.
1015   * @retval HAL status
1016   */
HAL_LTDC_SetPitch(LTDC_HandleTypeDef * hltdc,uint32_t LinePitchInPixels,uint32_t LayerIdx)1017 HAL_StatusTypeDef HAL_LTDC_SetPitch(LTDC_HandleTypeDef *hltdc, uint32_t LinePitchInPixels, uint32_t LayerIdx)
1018 {
1019   uint32_t tmp;
1020   uint32_t pitchUpdate;
1021   uint32_t pixelFormat;
1022 
1023   /* Change LTDC peripheral state */
1024   hltdc->State = HAL_LTDC_STATE_BUSY;
1025 
1026   /* get LayerIdx used pixel format */
1027   pixelFormat = hltdc->LayerCfg[LayerIdx].PixelFormat;
1028 
1029   if (pixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
1030   {
1031     tmp = 4U;
1032   }
1033   else if (pixelFormat == LTDC_PIXEL_FORMAT_RGB888)
1034   {
1035     tmp = 3U;
1036   }
1037   else if ((pixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
1038            (pixelFormat == LTDC_PIXEL_FORMAT_RGB565)   || \
1039            (pixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
1040            (pixelFormat == LTDC_PIXEL_FORMAT_AL88))
1041   {
1042     tmp = 2U;
1043   }
1044   else
1045   {
1046     tmp = 1U;
1047   }
1048 
1049   pitchUpdate = ((LinePitchInPixels * tmp) << 16U);
1050 
1051   /* Clear previously set standard pitch */
1052   LTDC_LAYER(hltdc, LayerIdx)->CFBLR &= ~LTDC_LxCFBLR_CFBP;
1053 
1054   /* Set the Reload type as immediate update of LTDC pitch configured above */
1055   LTDC->SRCR |= LTDC_SRCR_IMR;
1056 
1057   /* Set new line pitch value */
1058   LTDC_LAYER(hltdc, LayerIdx)->CFBLR |= pitchUpdate;
1059 
1060   /* Set the Reload type as immediate update of LTDC pitch configured above */
1061   LTDC->SRCR |= LTDC_SRCR_IMR;
1062 
1063   /* Change the LTDC state*/
1064   hltdc->State = HAL_LTDC_STATE_READY;
1065 
1066   return HAL_OK;
1067 }
1068 
1069 /**
1070   * @brief  Define the position of the line interrupt.
1071   * @param  hltdc   pointer to a LTDC_HandleTypeDef structure that contains
1072   *                 the configuration information for the LTDC.
1073   * @param  Line    Line Interrupt Position.
1074   * @note   User application may resort to HAL_LTDC_LineEventCallback() at line interrupt generation.
1075   * @retval  HAL status
1076   */
HAL_LTDC_ProgramLineEvent(LTDC_HandleTypeDef * hltdc,uint32_t Line)1077 HAL_StatusTypeDef HAL_LTDC_ProgramLineEvent(LTDC_HandleTypeDef *hltdc, uint32_t Line)
1078 {
1079   /* Change LTDC peripheral state */
1080   hltdc->State = HAL_LTDC_STATE_BUSY;
1081 
1082   /* Disable the Line interrupt */
1083   __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_LI);
1084 
1085   /* Set the Line Interrupt position */
1086   LTDC->LIPCR = (uint32_t)Line;
1087 
1088   /* Enable the Line interrupt */
1089   __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_LI);
1090 
1091   /* Change the LTDC state*/
1092   hltdc->State = HAL_LTDC_STATE_READY;
1093 
1094   return HAL_OK;
1095 }
1096 
1097 /**
1098   * @brief  Reload LTDC Layers configuration.
1099   * @param  hltdc      pointer to a LTDC_HandleTypeDef structure that contains
1100   *                    the configuration information for the LTDC.
1101   * @param  ReloadType This parameter can be one of the following values :
1102   *                      LTDC_RELOAD_IMMEDIATE : Immediate Reload
1103   *                      LTDC_RELOAD_VERTICAL_BLANKING  : Reload in the next Vertical Blanking
1104   * @note   User application may resort to HAL_LTDC_ReloadEventCallback() at reload interrupt generation.
1105   * @retval  HAL status
1106   */
HAL_LTDC_Reload(LTDC_HandleTypeDef * hltdc,uint32_t ReloadType)1107 HAL_StatusTypeDef  HAL_LTDC_Reload(LTDC_HandleTypeDef *hltdc, uint32_t ReloadType)
1108 {
1109   /* Change LTDC peripheral state */
1110   hltdc->State = HAL_LTDC_STATE_BUSY;
1111 
1112   /* Enable the Reload interrupt */
1113   __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_RR);
1114 
1115   /* Apply Reload type */
1116   hltdc->Instance->SRCR = ReloadType;
1117 
1118   /* Change the LTDC state*/
1119   hltdc->State = HAL_LTDC_STATE_READY;
1120 
1121   return HAL_OK;
1122 }
1123 
1124 /**
1125   * @brief  Configure the LTDC Layer according to the specified without reloading
1126   *         parameters in the LTDC_InitTypeDef and create the associated handle.
1127   *         Variant of the function HAL_LTDC_ConfigLayer without immediate reload.
1128   * @param  hltdc      pointer to a LTDC_HandleTypeDef structure that contains
1129   *                    the configuration information for the LTDC.
1130   * @param  pLayerCfg  pointer to a LTDC_LayerCfgTypeDef structure that contains
1131   *                    the configuration information for the Layer.
1132   * @param  LayerIdx   LTDC Layer index.
1133   *                    This parameter can be one of the following values:
1134   *                    LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1135   * @retval HAL status
1136   */
HAL_LTDC_ConfigLayer_NoReload(LTDC_HandleTypeDef * hltdc,LTDC_LayerCfgTypeDef * pLayerCfg,uint32_t LayerIdx)1137 HAL_StatusTypeDef HAL_LTDC_ConfigLayer_NoReload(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)
1138 {
1139   /* Change LTDC peripheral state */
1140   hltdc->State = HAL_LTDC_STATE_BUSY;
1141 
1142   /* Copy new layer configuration into handle structure */
1143   hltdc->LayerCfg[LayerIdx] = *pLayerCfg;
1144 
1145   /* Configure the LTDC Layer */
1146   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1147 
1148   /* Initialize the LTDC state*/
1149   hltdc->State  = HAL_LTDC_STATE_READY;
1150 
1151   return HAL_OK;
1152 }
1153 
1154 /**
1155   * @brief  Set the LTDC window size without reloading.
1156   *         Variant of the function HAL_LTDC_SetWindowSize without immediate reload.
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_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t XSize,uint32_t YSize,uint32_t LayerIdx)1166 HAL_StatusTypeDef HAL_LTDC_SetWindowSize_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t XSize, uint32_t YSize, uint32_t LayerIdx)
1167 {
1168   LTDC_LayerCfgTypeDef *pLayerCfg;
1169 
1170   /* Change LTDC peripheral state */
1171   hltdc->State = HAL_LTDC_STATE_BUSY;
1172 
1173   /* Get layer configuration from handle structure */
1174   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1175 
1176   /* update horizontal stop */
1177   pLayerCfg->WindowX1 = XSize + pLayerCfg->WindowX0;
1178 
1179   /* update vertical stop */
1180   pLayerCfg->WindowY1 = YSize + pLayerCfg->WindowY0;
1181 
1182   /* Reconfigures the color frame buffer pitch in byte */
1183   pLayerCfg->ImageWidth = XSize;
1184 
1185   /* Reconfigures the frame buffer line number */
1186   pLayerCfg->ImageHeight = YSize;
1187 
1188   /* Set LTDC parameters */
1189   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1190 
1191   /* Change the LTDC state*/
1192   hltdc->State = HAL_LTDC_STATE_READY;
1193 
1194   return HAL_OK;
1195 }
1196 
1197 /**
1198   * @brief  Set the LTDC window position without reloading.
1199   *         Variant of the function HAL_LTDC_SetWindowPosition without immediate reload.
1200   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1201   *                   the configuration information for the LTDC.
1202   * @param  X0        LTDC window X offset
1203   * @param  Y0        LTDC window Y offset
1204   * @param  LayerIdx  LTDC Layer index.
1205   *                         This parameter can be one of the following values:
1206   *                         LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1207   * @retval  HAL status
1208   */
HAL_LTDC_SetWindowPosition_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t X0,uint32_t Y0,uint32_t LayerIdx)1209 HAL_StatusTypeDef HAL_LTDC_SetWindowPosition_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t X0, uint32_t Y0, uint32_t LayerIdx)
1210 {
1211   LTDC_LayerCfgTypeDef *pLayerCfg;
1212 
1213   /* Change LTDC peripheral state */
1214   hltdc->State = HAL_LTDC_STATE_BUSY;
1215 
1216   /* Get layer configuration from handle structure */
1217   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1218 
1219   /* update horizontal start/stop */
1220   pLayerCfg->WindowX0 = X0;
1221   pLayerCfg->WindowX1 = X0 + pLayerCfg->ImageWidth;
1222 
1223   /* update vertical start/stop */
1224   pLayerCfg->WindowY0 = Y0;
1225   pLayerCfg->WindowY1 = Y0 + pLayerCfg->ImageHeight;
1226 
1227   /* Set LTDC parameters */
1228   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1229 
1230   /* Change the LTDC state*/
1231   hltdc->State = HAL_LTDC_STATE_READY;
1232 
1233   return HAL_OK;
1234 }
1235 
1236 /**
1237   * @brief  Reconfigure the pixel format without reloading.
1238   *         Variant of the function HAL_LTDC_SetPixelFormat without immediate reload.
1239   * @param  hltdc        pointer to a LTDC_HandleTypeDfef structure that contains
1240   *                      the configuration information for the LTDC.
1241   * @param  Pixelformat  new pixel format value.
1242   * @param  LayerIdx     LTDC Layer index.
1243   *                      This parameter can be one of the following values:
1244   *                      LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
1245   * @retval  HAL status
1246   */
HAL_LTDC_SetPixelFormat_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t Pixelformat,uint32_t LayerIdx)1247 HAL_StatusTypeDef HAL_LTDC_SetPixelFormat_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Pixelformat, uint32_t LayerIdx)
1248 {
1249   LTDC_LayerCfgTypeDef *pLayerCfg;
1250 
1251   /* Change LTDC peripheral state */
1252   hltdc->State = HAL_LTDC_STATE_BUSY;
1253 
1254   /* Get layer configuration from handle structure */
1255   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1256 
1257   /* Reconfigure the pixel format */
1258   pLayerCfg->PixelFormat = Pixelformat;
1259 
1260   /* Set LTDC parameters */
1261   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1262 
1263   /* Change the LTDC state*/
1264   hltdc->State = HAL_LTDC_STATE_READY;
1265 
1266   return HAL_OK;
1267 }
1268 
1269 /**
1270   * @brief  Reconfigure the layer alpha value without reloading.
1271   *         Variant of the function HAL_LTDC_SetAlpha without immediate reload.
1272   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1273   *                   the configuration information for the LTDC.
1274   * @param  Alpha     new alpha value.
1275   * @param  LayerIdx  LTDC Layer index.
1276   *                   This parameter can be one of the following values:
1277   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1278   * @retval  HAL status
1279   */
HAL_LTDC_SetAlpha_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t Alpha,uint32_t LayerIdx)1280 HAL_StatusTypeDef HAL_LTDC_SetAlpha_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Alpha, uint32_t LayerIdx)
1281 {
1282   LTDC_LayerCfgTypeDef *pLayerCfg;
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 Alpha value */
1291   pLayerCfg->Alpha = Alpha;
1292 
1293   /* Set LTDC parameters */
1294   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1295 
1296   /* Change the LTDC state*/
1297   hltdc->State = HAL_LTDC_STATE_READY;
1298 
1299   return HAL_OK;
1300 }
1301 
1302 /**
1303   * @brief  Reconfigure the frame buffer Address without reloading.
1304   *         Variant of the function HAL_LTDC_SetAddress without immediate reload.
1305   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1306   *                   the configuration information for the LTDC.
1307   * @param  Address   new address value.
1308   * @param  LayerIdx  LTDC Layer index.
1309   *                   This parameter can be one of the following values:
1310   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
1311   * @retval  HAL status
1312   */
HAL_LTDC_SetAddress_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t Address,uint32_t LayerIdx)1313 HAL_StatusTypeDef HAL_LTDC_SetAddress_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Address, uint32_t LayerIdx)
1314 {
1315   LTDC_LayerCfgTypeDef *pLayerCfg;
1316 
1317   /* Change LTDC peripheral state */
1318   hltdc->State = HAL_LTDC_STATE_BUSY;
1319 
1320   /* Get layer configuration from handle structure */
1321   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1322 
1323   /* Reconfigure the Address */
1324   pLayerCfg->FBStartAdress = Address;
1325 
1326   /* Set LTDC parameters */
1327   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1328 
1329   /* Change the LTDC state*/
1330   hltdc->State = HAL_LTDC_STATE_READY;
1331 
1332   return HAL_OK;
1333 }
1334 
1335 /**
1336   * @brief  Function used to reconfigure the pitch for specific cases where the attached LayerIdx buffer have a width that is
1337   *         larger than the one intended to be displayed on screen. Example of a buffer 800x480 attached to layer for which we
1338   *         want to read and display on screen only a portion 320x240 taken in the center of the buffer. The pitch in pixels
1339   *         will be in that case 800 pixels and not 320 pixels as initially configured by previous call to HAL_LTDC_ConfigLayer().
1340   * @note   This function should be called only after a previous call to HAL_LTDC_ConfigLayer() to modify the default pitch
1341   *         configured by HAL_LTDC_ConfigLayer() when required (refer to example described just above).
1342   *         Variant of the function HAL_LTDC_SetPitch without immediate reload.
1343   * @param  hltdc              pointer to a LTDC_HandleTypeDef structure that contains
1344   *                            the configuration information for the LTDC.
1345   * @param  LinePitchInPixels  New line pitch in pixels to configure for LTDC layer 'LayerIdx'.
1346   * @param  LayerIdx           LTDC layer index concerned by the modification of line pitch.
1347   * @retval HAL status
1348   */
HAL_LTDC_SetPitch_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t LinePitchInPixels,uint32_t LayerIdx)1349 HAL_StatusTypeDef HAL_LTDC_SetPitch_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LinePitchInPixels, uint32_t LayerIdx)
1350 {
1351   uint32_t tmp;
1352   uint32_t pitchUpdate;
1353   uint32_t pixelFormat;
1354 
1355   /* Change LTDC peripheral state */
1356   hltdc->State = HAL_LTDC_STATE_BUSY;
1357 
1358   /* get LayerIdx used pixel format */
1359   pixelFormat = hltdc->LayerCfg[LayerIdx].PixelFormat;
1360 
1361   if (pixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
1362   {
1363     tmp = 4U;
1364   }
1365   else if (pixelFormat == LTDC_PIXEL_FORMAT_RGB888)
1366   {
1367     tmp = 3U;
1368   }
1369   else if ((pixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
1370            (pixelFormat == LTDC_PIXEL_FORMAT_RGB565)   || \
1371            (pixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
1372            (pixelFormat == LTDC_PIXEL_FORMAT_AL88))
1373   {
1374     tmp = 2U;
1375   }
1376   else
1377   {
1378     tmp = 1U;
1379   }
1380 
1381   pitchUpdate = ((LinePitchInPixels * tmp) << 16U);
1382 
1383   /* Clear previously set standard pitch */
1384   LTDC_LAYER(hltdc, LayerIdx)->CFBLR &= ~LTDC_LxCFBLR_CFBP;
1385 
1386   /* Set new line pitch value */
1387   LTDC_LAYER(hltdc, LayerIdx)->CFBLR |= pitchUpdate;
1388 
1389   /* Change the LTDC state*/
1390   hltdc->State = HAL_LTDC_STATE_READY;
1391 
1392   return HAL_OK;
1393 }
1394 
1395 
1396 /**
1397   * @brief  Configure the color keying without reloading.
1398   *         Variant of the function HAL_LTDC_ConfigColorKeying without immediate reload.
1399   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1400   *                   the configuration information for the LTDC.
1401   * @param  RGBValue the color key value
1402   * @param  LayerIdx  LTDC Layer index.
1403   *                   This parameter can be one of the following values:
1404   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1405   * @retval HAL status
1406   */
HAL_LTDC_ConfigColorKeying_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t RGBValue,uint32_t LayerIdx)1407 HAL_StatusTypeDef HAL_LTDC_ConfigColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t RGBValue, uint32_t LayerIdx)
1408 {
1409   /* Change LTDC peripheral state */
1410   hltdc->State = HAL_LTDC_STATE_BUSY;
1411 
1412   /* Configure the default color values */
1413   LTDC_LAYER(hltdc, LayerIdx)->CKCR &=  ~(LTDC_LxCKCR_CKBLUE | LTDC_LxCKCR_CKGREEN | LTDC_LxCKCR_CKRED);
1414   LTDC_LAYER(hltdc, LayerIdx)->CKCR  = RGBValue;
1415 
1416   /* Change the LTDC state*/
1417   hltdc->State = HAL_LTDC_STATE_READY;
1418 
1419   return HAL_OK;
1420 }
1421 
1422 /**
1423   * @brief  Enable the color keying without reloading.
1424   *         Variant of the function HAL_LTDC_EnableColorKeying without immediate reload.
1425   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1426   *                   the configuration information for the LTDC.
1427   * @param  LayerIdx  LTDC Layer index.
1428   *                   This parameter can be one of the following values:
1429   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1430   * @retval  HAL status
1431   */
HAL_LTDC_EnableColorKeying_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)1432 HAL_StatusTypeDef HAL_LTDC_EnableColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1433 {
1434   /* Change LTDC peripheral state */
1435   hltdc->State = HAL_LTDC_STATE_BUSY;
1436 
1437   /* Enable LTDC color keying by setting COLKEN bit */
1438   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_COLKEN;
1439 
1440   /* Change the LTDC state*/
1441   hltdc->State = HAL_LTDC_STATE_READY;
1442 
1443   return HAL_OK;
1444 }
1445 
1446 /**
1447   * @brief  Disable the color keying without reloading.
1448   *         Variant of the function HAL_LTDC_DisableColorKeying without immediate reload.
1449   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1450   *                   the configuration information for the LTDC.
1451   * @param  LayerIdx  LTDC Layer index.
1452   *                   This parameter can be one of the following values:
1453   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1454   * @retval  HAL status
1455   */
HAL_LTDC_DisableColorKeying_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)1456 HAL_StatusTypeDef HAL_LTDC_DisableColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1457 {
1458   /* Change LTDC peripheral state */
1459   hltdc->State = HAL_LTDC_STATE_BUSY;
1460 
1461   /* Disable LTDC color keying by setting COLKEN bit */
1462   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_COLKEN;
1463 
1464   /* Change the LTDC state*/
1465   hltdc->State = HAL_LTDC_STATE_READY;
1466 
1467   return HAL_OK;
1468 }
1469 
1470 /**
1471   * @brief  Enable the color lookup table without reloading.
1472   *         Variant of the function HAL_LTDC_EnableCLUT without immediate reload.
1473   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1474   *                   the configuration information for the LTDC.
1475   * @param  LayerIdx  LTDC Layer index.
1476   *                   This parameter can be one of the following values:
1477   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1478   * @retval  HAL status
1479   */
HAL_LTDC_EnableCLUT_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)1480 HAL_StatusTypeDef HAL_LTDC_EnableCLUT_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1481 {
1482   /* Change LTDC peripheral state */
1483   hltdc->State = HAL_LTDC_STATE_BUSY;
1484 
1485   /* Disable LTDC color lookup table by setting CLUTEN bit */
1486   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_CLUTEN;
1487 
1488   /* Change the LTDC state*/
1489   hltdc->State = HAL_LTDC_STATE_READY;
1490 
1491   return HAL_OK;
1492 }
1493 
1494 /**
1495   * @brief  Disable the color lookup table without reloading.
1496   *         Variant of the function HAL_LTDC_DisableCLUT without immediate reload.
1497   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1498   *                   the configuration information for the LTDC.
1499   * @param  LayerIdx  LTDC Layer index.
1500   *                   This parameter can be one of the following values:
1501   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1502   * @retval  HAL status
1503   */
HAL_LTDC_DisableCLUT_NoReload(LTDC_HandleTypeDef * hltdc,uint32_t LayerIdx)1504 HAL_StatusTypeDef HAL_LTDC_DisableCLUT_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1505 {
1506   /* Change LTDC peripheral state */
1507   hltdc->State = HAL_LTDC_STATE_BUSY;
1508 
1509   /* Disable LTDC color lookup table by setting CLUTEN bit */
1510   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_CLUTEN;
1511 
1512   /* Change the LTDC state*/
1513   hltdc->State = HAL_LTDC_STATE_READY;
1514 
1515   return HAL_OK;
1516 }
1517 
1518 /**
1519   * @}
1520   */
1521 
1522 /** @defgroup LTDC_Exported_Functions_Group4 Peripheral State and Errors functions
1523   *  @brief    Peripheral State and Errors functions
1524   *
1525 @verbatim
1526  ===============================================================================
1527                   ##### Peripheral State and Errors functions #####
1528  ===============================================================================
1529     [..]
1530     This subsection provides functions allowing to
1531       (+) Check the LTDC handle state.
1532       (+) Get the LTDC handle error code.
1533 
1534 @endverbatim
1535   * @{
1536   */
1537 
1538 /**
1539   * @brief  Return the LTDC handle state.
1540   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
1541   *                the configuration information for the LTDC.
1542   * @retval HAL state
1543   */
HAL_LTDC_GetState(LTDC_HandleTypeDef * hltdc)1544 HAL_LTDC_StateTypeDef HAL_LTDC_GetState(LTDC_HandleTypeDef *hltdc)
1545 {
1546   return hltdc->State;
1547 }
1548 
1549 /**
1550   * @brief  Return the LTDC handle error code.
1551   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
1552   *               the configuration information for the LTDC.
1553   * @retval LTDC Error Code
1554   */
HAL_LTDC_GetError(LTDC_HandleTypeDef * hltdc)1555 uint32_t HAL_LTDC_GetError(LTDC_HandleTypeDef *hltdc)
1556 {
1557   return hltdc->ErrorCode;
1558 }
1559 
1560 /**
1561   * @}
1562   */
1563 
1564 /**
1565   * @}
1566   */
1567 
1568 /** @defgroup LTDC_Private_Functions LTDC Private Functions
1569   * @{
1570   */
1571 
1572 /**
1573   * @brief  Configure the LTDC peripheral
1574   * @param  hltdc     Pointer to a LTDC_HandleTypeDef structure that contains
1575   *                   the configuration information for the LTDC.
1576   * @param  pLayerCfg Pointer LTDC Layer Configuration structure
1577   * @param  LayerIdx  LTDC Layer index.
1578   *                   This parameter can be one of the following values: LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1579   * @retval None
1580   */
LTDC_SetConfig(LTDC_HandleTypeDef * hltdc,LTDC_LayerCfgTypeDef * pLayerCfg,uint32_t LayerIdx)1581 static void LTDC_SetConfig(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)
1582 {
1583   uint32_t tmp;
1584   uint32_t tmp1;
1585   uint32_t tmp2;
1586 
1587   /* Configure the horizontal start and stop position */
1588   tmp = ((pLayerCfg->WindowX1 + ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16U)) << 16U);
1589   LTDC_LAYER(hltdc, LayerIdx)->WHPCR &= ~(LTDC_LxWHPCR_WHSTPOS | LTDC_LxWHPCR_WHSPPOS);
1590   LTDC_LAYER(hltdc, LayerIdx)->WHPCR = ((pLayerCfg->WindowX0 + ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16U) + 1U) | tmp);
1591 
1592   /* Configure the vertical start and stop position */
1593   tmp = ((pLayerCfg->WindowY1 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP)) << 16U);
1594   LTDC_LAYER(hltdc, LayerIdx)->WVPCR &= ~(LTDC_LxWVPCR_WVSTPOS | LTDC_LxWVPCR_WVSPPOS);
1595   LTDC_LAYER(hltdc, LayerIdx)->WVPCR  = ((pLayerCfg->WindowY0 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP) + 1U) | tmp);
1596 
1597   /* Specifies the pixel format */
1598   LTDC_LAYER(hltdc, LayerIdx)->PFCR &= ~(LTDC_LxPFCR_PF);
1599   LTDC_LAYER(hltdc, LayerIdx)->PFCR = (pLayerCfg->PixelFormat);
1600 
1601   /* Configure the default color values */
1602   tmp = ((uint32_t)(pLayerCfg->Backcolor.Green) << 8U);
1603   tmp1 = ((uint32_t)(pLayerCfg->Backcolor.Red) << 16U);
1604   tmp2 = (pLayerCfg->Alpha0 << 24U);
1605   LTDC_LAYER(hltdc, LayerIdx)->DCCR &= ~(LTDC_LxDCCR_DCBLUE | LTDC_LxDCCR_DCGREEN | LTDC_LxDCCR_DCRED | LTDC_LxDCCR_DCALPHA);
1606   LTDC_LAYER(hltdc, LayerIdx)->DCCR = (pLayerCfg->Backcolor.Blue | tmp | tmp1 | tmp2);
1607 
1608   /* Specifies the constant alpha value */
1609   LTDC_LAYER(hltdc, LayerIdx)->CACR &= ~(LTDC_LxCACR_CONSTA);
1610   LTDC_LAYER(hltdc, LayerIdx)->CACR = (pLayerCfg->Alpha);
1611 
1612   /* Specifies the blending factors */
1613   LTDC_LAYER(hltdc, LayerIdx)->BFCR &= ~(LTDC_LxBFCR_BF2 | LTDC_LxBFCR_BF1);
1614   LTDC_LAYER(hltdc, LayerIdx)->BFCR = (pLayerCfg->BlendingFactor1 | pLayerCfg->BlendingFactor2);
1615 
1616   /* Configure the color frame buffer start address */
1617   LTDC_LAYER(hltdc, LayerIdx)->CFBAR &= ~(LTDC_LxCFBAR_CFBADD);
1618   LTDC_LAYER(hltdc, LayerIdx)->CFBAR = (pLayerCfg->FBStartAdress);
1619 
1620   if (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
1621   {
1622     tmp = 4U;
1623   }
1624   else if (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
1625   {
1626     tmp = 3U;
1627   }
1628   else if ((pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
1629            (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB565)   || \
1630            (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
1631            (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_AL88))
1632   {
1633     tmp = 2U;
1634   }
1635   else
1636   {
1637     tmp = 1U;
1638   }
1639 
1640   /* Configure the color frame buffer pitch in byte */
1641   LTDC_LAYER(hltdc, LayerIdx)->CFBLR  &= ~(LTDC_LxCFBLR_CFBLL | LTDC_LxCFBLR_CFBP);
1642   LTDC_LAYER(hltdc, LayerIdx)->CFBLR  = (((pLayerCfg->ImageWidth * tmp) << 16U) | (((pLayerCfg->WindowX1 - pLayerCfg->WindowX0) * tmp)  + 7U));
1643   /* Configure the frame buffer line number */
1644   LTDC_LAYER(hltdc, LayerIdx)->CFBLNR  &= ~(LTDC_LxCFBLNR_CFBLNBR);
1645   LTDC_LAYER(hltdc, LayerIdx)->CFBLNR  = (pLayerCfg->ImageHeight);
1646 
1647   /* Enable LTDC_Layer by setting LEN bit */
1648   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_LEN;
1649 }
1650 
1651 /**
1652   * @}
1653   */
1654 
1655 
1656 /**
1657   * @}
1658   */
1659 
1660 // #endif /* LTDC */
1661 
1662 // #endif /* HAL_LTDC_MODULE_ENABLED */
1663 
1664 /**
1665   * @}
1666   */
1667 
1668 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
1669