Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:08

0001 /**
0002   ******************************************************************************
0003   * @file    stm32h7xx_hal_ltdc.c
0004   * @author  MCD Application Team
0005   * @brief   LTDC HAL module driver.
0006   *          This file provides firmware functions to manage the following
0007   *          functionalities of the LTDC peripheral:
0008   *           + Initialization and de-initialization functions
0009   *           + IO operation functions
0010   *           + Peripheral Control functions
0011   *           + Peripheral State and Errors functions
0012   *
0013   ******************************************************************************
0014   * @attention
0015   *
0016   * Copyright (c) 2017 STMicroelectronics.
0017   * All rights reserved.
0018   *
0019   * This software is licensed under terms that can be found in the LICENSE file
0020   * in the root directory of this software component.
0021   * If no LICENSE file comes with this software, it is provided AS-IS.
0022   *
0023   ******************************************************************************
0024   @verbatim
0025   ==============================================================================
0026                         ##### How to use this driver #####
0027   ==============================================================================
0028      [..]
0029      The LTDC HAL driver can be used as follows:
0030 
0031      (#) Declare a LTDC_HandleTypeDef handle structure, for example: LTDC_HandleTypeDef  hltdc;
0032 
0033      (#) Initialize the LTDC low level resources by implementing the HAL_LTDC_MspInit() API:
0034          (##) Enable the LTDC interface clock
0035          (##) NVIC configuration if you need to use interrupt process
0036              (+++) Configure the LTDC interrupt priority
0037              (+++) Enable the NVIC LTDC IRQ Channel
0038 
0039      (#) Initialize the required configuration through the following parameters:
0040          the LTDC timing, the horizontal and vertical polarity, the pixel clock polarity,
0041          Data Enable polarity and the LTDC background color value using HAL_LTDC_Init() function
0042 
0043      *** Configuration ***
0044      =========================
0045      [..]
0046      (#) Program the required configuration through the following parameters:
0047          the pixel format, the blending factors, input alpha value, the window size
0048          and the image size using HAL_LTDC_ConfigLayer() function for foreground
0049          or/and background layer.
0050 
0051      (#) Optionally, configure and enable the CLUT using HAL_LTDC_ConfigCLUT() and
0052          HAL_LTDC_EnableCLUT functions.
0053 
0054      (#) Optionally, enable the Dither using HAL_LTDC_EnableDither().
0055 
0056      (#) Optionally, configure and enable the Color keying using HAL_LTDC_ConfigColorKeying()
0057          and HAL_LTDC_EnableColorKeying functions.
0058 
0059      (#) Optionally, configure LineInterrupt using HAL_LTDC_ProgramLineEvent()
0060          function
0061 
0062      (#) If needed, reconfigure and change the pixel format value, the alpha value
0063          value, the window size, the window position and the layer start address
0064          for foreground or/and background layer using respectively the following
0065          functions: HAL_LTDC_SetPixelFormat(), HAL_LTDC_SetAlpha(), HAL_LTDC_SetWindowSize(),
0066          HAL_LTDC_SetWindowPosition() and HAL_LTDC_SetAddress().
0067 
0068      (#) Variant functions with _NoReload suffix allows to set the LTDC configuration/settings without immediate reload.
0069          This is useful in case when the program requires to modify serval LTDC settings (on one or both layers)
0070          then applying(reload) these settings in one shot by calling the function HAL_LTDC_Reload().
0071 
0072          After calling the _NoReload functions to set different color/format/layer settings,
0073          the program shall call the function HAL_LTDC_Reload() to apply(reload) these settings.
0074          Function HAL_LTDC_Reload() can be called with the parameter ReloadType set to LTDC_RELOAD_IMMEDIATE if
0075          an immediate reload is required.
0076          Function HAL_LTDC_Reload() can be called with the parameter ReloadType set to LTDC_RELOAD_VERTICAL_BLANKING if
0077          the reload should be done in the next vertical blanking period,
0078          this option allows to avoid display flicker by applying the new settings during the vertical blanking period.
0079 
0080 
0081      (#) To control LTDC state you can use the following function: HAL_LTDC_GetState()
0082 
0083      *** LTDC HAL driver macros list ***
0084      =============================================
0085      [..]
0086        Below the list of most used macros in LTDC HAL driver.
0087 
0088       (+) __HAL_LTDC_ENABLE: Enable the LTDC.
0089       (+) __HAL_LTDC_DISABLE: Disable the LTDC.
0090       (+) __HAL_LTDC_LAYER_ENABLE: Enable an LTDC Layer.
0091       (+) __HAL_LTDC_LAYER_DISABLE: Disable an LTDC Layer.
0092       (+) __HAL_LTDC_RELOAD_IMMEDIATE_CONFIG: Reload  Layer Configuration.
0093       (+) __HAL_LTDC_GET_FLAG: Get the LTDC pending flags.
0094       (+) __HAL_LTDC_CLEAR_FLAG: Clear the LTDC pending flags.
0095       (+) __HAL_LTDC_ENABLE_IT: Enable the specified LTDC interrupts.
0096       (+) __HAL_LTDC_DISABLE_IT: Disable the specified LTDC interrupts.
0097       (+) __HAL_LTDC_GET_IT_SOURCE: Check whether the specified LTDC interrupt has occurred or not.
0098 
0099      [..]
0100        (@) You can refer to the LTDC HAL driver header file for more useful macros
0101 
0102 
0103      *** Callback registration ***
0104      =============================================
0105      [..]
0106      The compilation define  USE_HAL_LTDC_REGISTER_CALLBACKS when set to 1
0107      allows the user to configure dynamically the driver callbacks.
0108      Use function HAL_LTDC_RegisterCallback() to register a callback.
0109 
0110     [..]
0111     Function HAL_LTDC_RegisterCallback() allows to register following callbacks:
0112       (+) LineEventCallback   : LTDC Line Event Callback.
0113       (+) ReloadEventCallback : LTDC Reload Event Callback.
0114       (+) ErrorCallback       : LTDC Error Callback
0115       (+) MspInitCallback     : LTDC MspInit.
0116       (+) MspDeInitCallback   : LTDC MspDeInit.
0117     [..]
0118     This function takes as parameters the HAL peripheral handle, the callback ID
0119     and a pointer to the user callback function.
0120 
0121     [..]
0122     Use function HAL_LTDC_UnRegisterCallback() to reset a callback to the default
0123     weak function.
0124     HAL_LTDC_UnRegisterCallback() takes as parameters the HAL peripheral handle
0125     and the callback ID.
0126     [..]
0127     This function allows to reset following callbacks:
0128       (+) LineEventCallback   : LTDC Line Event Callback
0129       (+) ReloadEventCallback : LTDC Reload Event Callback
0130       (+) ErrorCallback       : LTDC Error Callback
0131       (+) MspInitCallback     : LTDC MspInit
0132       (+) MspDeInitCallback   : LTDC MspDeInit.
0133 
0134     [..]
0135     By default, after the HAL_LTDC_Init and when the state is HAL_LTDC_STATE_RESET
0136     all callbacks are set to the corresponding weak functions:
0137     examples HAL_LTDC_LineEventCallback(), HAL_LTDC_ErrorCallback().
0138     Exception done for MspInit and MspDeInit functions that are
0139     reset to the legacy weak (surcharged) functions in the HAL_LTDC_Init() and HAL_LTDC_DeInit()
0140     only when these callbacks are null (not registered beforehand).
0141     If not, MspInit or MspDeInit are not null, the HAL_LTDC_Init() and HAL_LTDC_DeInit()
0142     keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
0143 
0144     [..]
0145     Callbacks can be registered/unregistered in HAL_LTDC_STATE_READY state only.
0146     Exception done MspInit/MspDeInit that can be registered/unregistered
0147     in HAL_LTDC_STATE_READY or HAL_LTDC_STATE_RESET state,
0148     thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
0149     In that case first register the MspInit/MspDeInit user callbacks
0150     using HAL_LTDC_RegisterCallback() before calling HAL_LTDC_DeInit()
0151     or HAL_LTDC_Init() function.
0152 
0153     [..]
0154     When the compilation define USE_HAL_LTDC_REGISTER_CALLBACKS is set to 0 or
0155     not defined, the callback registration feature is not available and all callbacks
0156     are set to the corresponding weak functions.
0157 
0158   @endverbatim
0159   ******************************************************************************
0160   */
0161 
0162 /* Includes ------------------------------------------------------------------*/
0163 #include "stm32h7xx_hal.h"
0164 
0165 /** @addtogroup STM32H7xx_HAL_Driver
0166   * @{
0167   */
0168 
0169 #ifdef HAL_LTDC_MODULE_ENABLED
0170 
0171 #if defined (LTDC)
0172 
0173 /** @defgroup LTDC LTDC
0174   * @ingroup RTEMSBSPsARMSTM32H7
0175   * @brief LTDC HAL module driver
0176   * @{
0177   */
0178 
0179 
0180 /* Private typedef -----------------------------------------------------------*/
0181 /* Private define ------------------------------------------------------------*/
0182 /** @defgroup LTDC_Private_Define LTDC Private Define
0183   * @ingroup RTEMSBSPsARMSTM32H7
0184   * @{
0185   */
0186 #define LTDC_TIMEOUT_VALUE ((uint32_t)100U)  /* 100ms */
0187 /**
0188   * @}
0189   */
0190 /* Private macro -------------------------------------------------------------*/
0191 /* Private variables ---------------------------------------------------------*/
0192 /* Private function prototypes -----------------------------------------------*/
0193 static void LTDC_SetConfig(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx);
0194 /* Private functions ---------------------------------------------------------*/
0195 
0196 /** @defgroup LTDC_Exported_Functions LTDC Exported Functions
0197   * @ingroup RTEMSBSPsARMSTM32H7
0198   * @{
0199   */
0200 
0201 /** @defgroup LTDC_Exported_Functions_Group1 Initialization and Configuration functions
0202   * @ingroup RTEMSBSPsARMSTM32H7
0203   *  @brief   Initialization and Configuration functions
0204   *
0205 @verbatim
0206  ===============================================================================
0207                 ##### Initialization and Configuration functions #####
0208  ===============================================================================
0209     [..]  This section provides functions allowing to:
0210       (+) Initialize and configure the LTDC
0211       (+) De-initialize the LTDC
0212 
0213 @endverbatim
0214   * @{
0215   */
0216 
0217 /**
0218   * @brief  Initialize the LTDC according to the specified parameters in the LTDC_InitTypeDef.
0219   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
0220   *                the configuration information for the LTDC.
0221   * @retval HAL status
0222   */
0223 HAL_StatusTypeDef HAL_LTDC_Init(LTDC_HandleTypeDef *hltdc)
0224 {
0225   uint32_t tmp;
0226   uint32_t tmp1;
0227 
0228   /* Check the LTDC peripheral state */
0229   if (hltdc == NULL)
0230   {
0231     return HAL_ERROR;
0232   }
0233 
0234   /* Check function parameters */
0235   assert_param(IS_LTDC_ALL_INSTANCE(hltdc->Instance));
0236   assert_param(IS_LTDC_HSYNC(hltdc->Init.HorizontalSync));
0237   assert_param(IS_LTDC_VSYNC(hltdc->Init.VerticalSync));
0238   assert_param(IS_LTDC_AHBP(hltdc->Init.AccumulatedHBP));
0239   assert_param(IS_LTDC_AVBP(hltdc->Init.AccumulatedVBP));
0240   assert_param(IS_LTDC_AAH(hltdc->Init.AccumulatedActiveH));
0241   assert_param(IS_LTDC_AAW(hltdc->Init.AccumulatedActiveW));
0242   assert_param(IS_LTDC_TOTALH(hltdc->Init.TotalHeigh));
0243   assert_param(IS_LTDC_TOTALW(hltdc->Init.TotalWidth));
0244   assert_param(IS_LTDC_HSPOL(hltdc->Init.HSPolarity));
0245   assert_param(IS_LTDC_VSPOL(hltdc->Init.VSPolarity));
0246   assert_param(IS_LTDC_DEPOL(hltdc->Init.DEPolarity));
0247   assert_param(IS_LTDC_PCPOL(hltdc->Init.PCPolarity));
0248 
0249 #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
0250   if (hltdc->State == HAL_LTDC_STATE_RESET)
0251   {
0252     /* Allocate lock resource and initialize it */
0253     hltdc->Lock = HAL_UNLOCKED;
0254 
0255     /* Reset the LTDC callback to the legacy weak callbacks */
0256     hltdc->LineEventCallback   = HAL_LTDC_LineEventCallback;    /* Legacy weak LineEventCallback    */
0257     hltdc->ReloadEventCallback = HAL_LTDC_ReloadEventCallback;  /* Legacy weak ReloadEventCallback  */
0258     hltdc->ErrorCallback       = HAL_LTDC_ErrorCallback;        /* Legacy weak ErrorCallback        */
0259 
0260     if (hltdc->MspInitCallback == NULL)
0261     {
0262       hltdc->MspInitCallback = HAL_LTDC_MspInit;
0263     }
0264     /* Init the low level hardware */
0265     hltdc->MspInitCallback(hltdc);
0266   }
0267 #else
0268   if (hltdc->State == HAL_LTDC_STATE_RESET)
0269   {
0270     /* Allocate lock resource and initialize it */
0271     hltdc->Lock = HAL_UNLOCKED;
0272     /* Init the low level hardware */
0273     HAL_LTDC_MspInit(hltdc);
0274   }
0275 #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
0276 
0277   /* Change LTDC peripheral state */
0278   hltdc->State = HAL_LTDC_STATE_BUSY;
0279 
0280   /* Configure the HS, VS, DE and PC polarity */
0281   hltdc->Instance->GCR &= ~(LTDC_GCR_HSPOL | LTDC_GCR_VSPOL | LTDC_GCR_DEPOL | LTDC_GCR_PCPOL);
0282   hltdc->Instance->GCR |= (uint32_t)(hltdc->Init.HSPolarity | hltdc->Init.VSPolarity | \
0283                                      hltdc->Init.DEPolarity | hltdc->Init.PCPolarity);
0284 
0285   /* Set Synchronization size */
0286   hltdc->Instance->SSCR &= ~(LTDC_SSCR_VSH | LTDC_SSCR_HSW);
0287   tmp = (hltdc->Init.HorizontalSync << 16U);
0288   hltdc->Instance->SSCR |= (tmp | hltdc->Init.VerticalSync);
0289 
0290   /* Set Accumulated Back porch */
0291   hltdc->Instance->BPCR &= ~(LTDC_BPCR_AVBP | LTDC_BPCR_AHBP);
0292   tmp = (hltdc->Init.AccumulatedHBP << 16U);
0293   hltdc->Instance->BPCR |= (tmp | hltdc->Init.AccumulatedVBP);
0294 
0295   /* Set Accumulated Active Width */
0296   hltdc->Instance->AWCR &= ~(LTDC_AWCR_AAH | LTDC_AWCR_AAW);
0297   tmp = (hltdc->Init.AccumulatedActiveW << 16U);
0298   hltdc->Instance->AWCR |= (tmp | hltdc->Init.AccumulatedActiveH);
0299 
0300   /* Set Total Width */
0301   hltdc->Instance->TWCR &= ~(LTDC_TWCR_TOTALH | LTDC_TWCR_TOTALW);
0302   tmp = (hltdc->Init.TotalWidth << 16U);
0303   hltdc->Instance->TWCR |= (tmp | hltdc->Init.TotalHeigh);
0304 
0305   /* Set the background color value */
0306   tmp = ((uint32_t)(hltdc->Init.Backcolor.Green) << 8U);
0307   tmp1 = ((uint32_t)(hltdc->Init.Backcolor.Red) << 16U);
0308   hltdc->Instance->BCCR &= ~(LTDC_BCCR_BCBLUE | LTDC_BCCR_BCGREEN | LTDC_BCCR_BCRED);
0309   hltdc->Instance->BCCR |= (tmp1 | tmp | hltdc->Init.Backcolor.Blue);
0310 
0311   /* Enable the Transfer Error and FIFO underrun interrupts */
0312   __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_TE | LTDC_IT_FU);
0313 
0314   /* Enable LTDC by setting LTDCEN bit */
0315   __HAL_LTDC_ENABLE(hltdc);
0316 
0317   /* Initialize the error code */
0318   hltdc->ErrorCode = HAL_LTDC_ERROR_NONE;
0319 
0320   /* Initialize the LTDC state*/
0321   hltdc->State = HAL_LTDC_STATE_READY;
0322 
0323   return HAL_OK;
0324 }
0325 
0326 /**
0327   * @brief  De-initialize the LTDC peripheral.
0328   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
0329   *                the configuration information for the LTDC.
0330   * @retval None
0331   */
0332 
0333 HAL_StatusTypeDef HAL_LTDC_DeInit(LTDC_HandleTypeDef *hltdc)
0334 {
0335   uint32_t tickstart;
0336 
0337   /* Check the LTDC peripheral state */
0338   if (hltdc == NULL)
0339   {
0340     return HAL_ERROR;
0341   }
0342 
0343   /* Check function parameters */
0344   assert_param(IS_LTDC_ALL_INSTANCE(hltdc->Instance));
0345 
0346   /* Disable LTDC Layer 1 */
0347   __HAL_LTDC_LAYER_DISABLE(hltdc, LTDC_LAYER_1);
0348 
0349 #if defined(LTDC_Layer2_BASE)
0350   /* Disable LTDC Layer 2 */
0351   __HAL_LTDC_LAYER_DISABLE(hltdc, LTDC_LAYER_2);
0352 #endif /* LTDC_Layer2_BASE */
0353 
0354   /* Reload during vertical blanking period */
0355   __HAL_LTDC_VERTICAL_BLANKING_RELOAD_CONFIG(hltdc);
0356 
0357   /* Get tick */
0358   tickstart = HAL_GetTick();
0359 
0360   /* Wait for VSYNC Interrupt */
0361   while (READ_BIT(hltdc->Instance->CDSR, LTDC_CDSR_VSYNCS) == 0U)
0362   {
0363     /* Check for the Timeout */
0364     if ((HAL_GetTick() - tickstart) > LTDC_TIMEOUT_VALUE)
0365     {
0366       break;
0367     }
0368   }
0369 
0370   /* Disable LTDC  */
0371   __HAL_LTDC_DISABLE(hltdc);
0372 
0373 #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
0374   if (hltdc->MspDeInitCallback == NULL)
0375   {
0376     hltdc->MspDeInitCallback = HAL_LTDC_MspDeInit;
0377   }
0378   /* DeInit the low level hardware */
0379   hltdc->MspDeInitCallback(hltdc);
0380 #else
0381   /* DeInit the low level hardware */
0382   HAL_LTDC_MspDeInit(hltdc);
0383 #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
0384 
0385   /* Initialize the error code */
0386   hltdc->ErrorCode = HAL_LTDC_ERROR_NONE;
0387 
0388   /* Initialize the LTDC state*/
0389   hltdc->State = HAL_LTDC_STATE_RESET;
0390 
0391   /* Release Lock */
0392   __HAL_UNLOCK(hltdc);
0393 
0394   return HAL_OK;
0395 }
0396 
0397 /**
0398   * @brief  Initialize the LTDC MSP.
0399   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
0400   *                the configuration information for the LTDC.
0401   * @retval None
0402   */
0403 __weak void HAL_LTDC_MspInit(LTDC_HandleTypeDef *hltdc)
0404 {
0405   /* Prevent unused argument(s) compilation warning */
0406   UNUSED(hltdc);
0407 
0408   /* NOTE : This function should not be modified, when the callback is needed,
0409             the HAL_LTDC_MspInit could be implemented in the user file
0410    */
0411 }
0412 
0413 /**
0414   * @brief  De-initialize the LTDC MSP.
0415   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
0416   *                the configuration information for the LTDC.
0417   * @retval None
0418   */
0419 __weak void HAL_LTDC_MspDeInit(LTDC_HandleTypeDef *hltdc)
0420 {
0421   /* Prevent unused argument(s) compilation warning */
0422   UNUSED(hltdc);
0423 
0424   /* NOTE : This function should not be modified, when the callback is needed,
0425             the HAL_LTDC_MspDeInit could be implemented in the user file
0426    */
0427 }
0428 
0429 #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
0430 /**
0431   * @brief  Register a User LTDC Callback
0432   *         To be used instead of the weak predefined callback
0433   * @param hltdc ltdc handle
0434   * @param CallbackID ID of the callback to be registered
0435   *        This parameter can be one of the following values:
0436   *          @arg @ref HAL_LTDC_LINE_EVENT_CB_ID Line Event Callback ID
0437   *          @arg @ref HAL_LTDC_RELOAD_EVENT_CB_ID Reload Event Callback ID
0438   *          @arg @ref HAL_LTDC_ERROR_CB_ID Error Callback ID
0439   *          @arg @ref HAL_LTDC_MSPINIT_CB_ID MspInit callback ID
0440   *          @arg @ref HAL_LTDC_MSPDEINIT_CB_ID MspDeInit callback ID
0441   * @param pCallback pointer to the Callback function
0442   * @retval status
0443   */
0444 HAL_StatusTypeDef HAL_LTDC_RegisterCallback(LTDC_HandleTypeDef *hltdc, HAL_LTDC_CallbackIDTypeDef CallbackID,
0445                                             pLTDC_CallbackTypeDef pCallback)
0446 {
0447   HAL_StatusTypeDef status = HAL_OK;
0448 
0449   if (pCallback == NULL)
0450   {
0451     /* Update the error code */
0452     hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
0453 
0454     return HAL_ERROR;
0455   }
0456   /* Process locked */
0457   __HAL_LOCK(hltdc);
0458 
0459   if (hltdc->State == HAL_LTDC_STATE_READY)
0460   {
0461     switch (CallbackID)
0462     {
0463       case HAL_LTDC_LINE_EVENT_CB_ID :
0464         hltdc->LineEventCallback = pCallback;
0465         break;
0466 
0467       case HAL_LTDC_RELOAD_EVENT_CB_ID :
0468         hltdc->ReloadEventCallback = pCallback;
0469         break;
0470 
0471       case HAL_LTDC_ERROR_CB_ID :
0472         hltdc->ErrorCallback = pCallback;
0473         break;
0474 
0475       case HAL_LTDC_MSPINIT_CB_ID :
0476         hltdc->MspInitCallback = pCallback;
0477         break;
0478 
0479       case HAL_LTDC_MSPDEINIT_CB_ID :
0480         hltdc->MspDeInitCallback = pCallback;
0481         break;
0482 
0483       default :
0484         /* Update the error code */
0485         hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
0486         /* Return error status */
0487         status =  HAL_ERROR;
0488         break;
0489     }
0490   }
0491   else if (hltdc->State == HAL_LTDC_STATE_RESET)
0492   {
0493     switch (CallbackID)
0494     {
0495       case HAL_LTDC_MSPINIT_CB_ID :
0496         hltdc->MspInitCallback = pCallback;
0497         break;
0498 
0499       case HAL_LTDC_MSPDEINIT_CB_ID :
0500         hltdc->MspDeInitCallback = pCallback;
0501         break;
0502 
0503       default :
0504         /* Update the error code */
0505         hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
0506         /* Return error status */
0507         status =  HAL_ERROR;
0508         break;
0509     }
0510   }
0511   else
0512   {
0513     /* Update the error code */
0514     hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
0515     /* Return error status */
0516     status =  HAL_ERROR;
0517   }
0518 
0519   /* Release Lock */
0520   __HAL_UNLOCK(hltdc);
0521 
0522   return status;
0523 }
0524 
0525 /**
0526   * @brief  Unregister an LTDC Callback
0527   *         LTDC callback is redirected to the weak predefined callback
0528   * @param hltdc ltdc handle
0529   * @param CallbackID ID of the callback to be unregistered
0530   *        This parameter can be one of the following values:
0531   *          @arg @ref HAL_LTDC_LINE_EVENT_CB_ID Line Event Callback ID
0532   *          @arg @ref HAL_LTDC_RELOAD_EVENT_CB_ID Reload Event Callback ID
0533   *          @arg @ref HAL_LTDC_ERROR_CB_ID Error Callback ID
0534   *          @arg @ref HAL_LTDC_MSPINIT_CB_ID MspInit callback ID
0535   *          @arg @ref HAL_LTDC_MSPDEINIT_CB_ID MspDeInit callback ID
0536   * @retval status
0537   */
0538 HAL_StatusTypeDef HAL_LTDC_UnRegisterCallback(LTDC_HandleTypeDef *hltdc, HAL_LTDC_CallbackIDTypeDef CallbackID)
0539 {
0540   HAL_StatusTypeDef status = HAL_OK;
0541 
0542   /* Process locked */
0543   __HAL_LOCK(hltdc);
0544 
0545   if (hltdc->State == HAL_LTDC_STATE_READY)
0546   {
0547     switch (CallbackID)
0548     {
0549       case HAL_LTDC_LINE_EVENT_CB_ID :
0550         hltdc->LineEventCallback = HAL_LTDC_LineEventCallback;      /* Legacy weak LineEventCallback    */
0551         break;
0552 
0553       case HAL_LTDC_RELOAD_EVENT_CB_ID :
0554         hltdc->ReloadEventCallback = HAL_LTDC_ReloadEventCallback;  /* Legacy weak ReloadEventCallback  */
0555         break;
0556 
0557       case HAL_LTDC_ERROR_CB_ID :
0558         hltdc->ErrorCallback       = HAL_LTDC_ErrorCallback;        /* Legacy weak ErrorCallback        */
0559         break;
0560 
0561       case HAL_LTDC_MSPINIT_CB_ID :
0562         hltdc->MspInitCallback = HAL_LTDC_MspInit;                  /* Legcay weak MspInit Callback  */
0563         break;
0564 
0565       case HAL_LTDC_MSPDEINIT_CB_ID :
0566         hltdc->MspDeInitCallback = HAL_LTDC_MspDeInit;              /* Legcay weak MspDeInit Callback     */
0567         break;
0568 
0569       default :
0570         /* Update the error code */
0571         hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
0572         /* Return error status */
0573         status =  HAL_ERROR;
0574         break;
0575     }
0576   }
0577   else if (hltdc->State == HAL_LTDC_STATE_RESET)
0578   {
0579     switch (CallbackID)
0580     {
0581       case HAL_LTDC_MSPINIT_CB_ID :
0582         hltdc->MspInitCallback = HAL_LTDC_MspInit;                  /* Legcay weak MspInit Callback     */
0583         break;
0584 
0585       case HAL_LTDC_MSPDEINIT_CB_ID :
0586         hltdc->MspDeInitCallback = HAL_LTDC_MspDeInit;              /* Legcay weak MspDeInit Callback     */
0587         break;
0588 
0589       default :
0590         /* Update the error code */
0591         hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
0592         /* Return error status */
0593         status =  HAL_ERROR;
0594         break;
0595     }
0596   }
0597   else
0598   {
0599     /* Update the error code */
0600     hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
0601     /* Return error status */
0602     status =  HAL_ERROR;
0603   }
0604 
0605   /* Release Lock */
0606   __HAL_UNLOCK(hltdc);
0607 
0608   return status;
0609 }
0610 #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
0611 
0612 /**
0613   * @}
0614   */
0615 
0616 /** @defgroup LTDC_Exported_Functions_Group2 IO operation functions
0617   * @ingroup RTEMSBSPsARMSTM32H7
0618   *  @brief   IO operation functions
0619   *
0620 @verbatim
0621  ===============================================================================
0622                       #####  IO operation functions  #####
0623  ===============================================================================
0624     [..]  This section provides function allowing to:
0625       (+) Handle LTDC interrupt request
0626 
0627 @endverbatim
0628   * @{
0629   */
0630 /**
0631   * @brief  Handle LTDC interrupt request.
0632   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
0633   *                the configuration information for the LTDC.
0634   * @retval HAL status
0635   */
0636 void HAL_LTDC_IRQHandler(LTDC_HandleTypeDef *hltdc)
0637 {
0638   uint32_t isrflags  = READ_REG(hltdc->Instance->ISR);
0639   uint32_t itsources = READ_REG(hltdc->Instance->IER);
0640 
0641   /* Transfer Error Interrupt management ***************************************/
0642   if (((isrflags & LTDC_ISR_TERRIF) != 0U) && ((itsources & LTDC_IER_TERRIE) != 0U))
0643   {
0644     /* Disable the transfer Error interrupt */
0645     __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_TE);
0646 
0647     /* Clear the transfer error flag */
0648     __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_TE);
0649 
0650     /* Update error code */
0651     hltdc->ErrorCode |= HAL_LTDC_ERROR_TE;
0652 
0653     /* Change LTDC state */
0654     hltdc->State = HAL_LTDC_STATE_ERROR;
0655 
0656     /* Process unlocked */
0657     __HAL_UNLOCK(hltdc);
0658 
0659     /* Transfer error Callback */
0660 #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
0661     /*Call registered error callback*/
0662     hltdc->ErrorCallback(hltdc);
0663 #else
0664     /* Call legacy error callback*/
0665     HAL_LTDC_ErrorCallback(hltdc);
0666 #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
0667   }
0668 
0669   /* FIFO underrun Interrupt management ***************************************/
0670   if (((isrflags & LTDC_ISR_FUIF) != 0U) && ((itsources & LTDC_IER_FUIE) != 0U))
0671   {
0672     /* Disable the FIFO underrun interrupt */
0673     __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_FU);
0674 
0675     /* Clear the FIFO underrun flag */
0676     __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_FU);
0677 
0678     /* Update error code */
0679     hltdc->ErrorCode |= HAL_LTDC_ERROR_FU;
0680 
0681     /* Change LTDC state */
0682     hltdc->State = HAL_LTDC_STATE_ERROR;
0683 
0684     /* Process unlocked */
0685     __HAL_UNLOCK(hltdc);
0686 
0687     /* Transfer error Callback */
0688 #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
0689     /*Call registered error callback*/
0690     hltdc->ErrorCallback(hltdc);
0691 #else
0692     /* Call legacy error callback*/
0693     HAL_LTDC_ErrorCallback(hltdc);
0694 #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
0695   }
0696 
0697   /* Line Interrupt management ************************************************/
0698   if (((isrflags & LTDC_ISR_LIF) != 0U) && ((itsources & LTDC_IER_LIE) != 0U))
0699   {
0700     /* Disable the Line interrupt */
0701     __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_LI);
0702 
0703     /* Clear the Line interrupt flag */
0704     __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_LI);
0705 
0706     /* Change LTDC state */
0707     hltdc->State = HAL_LTDC_STATE_READY;
0708 
0709     /* Process unlocked */
0710     __HAL_UNLOCK(hltdc);
0711 
0712     /* Line interrupt Callback */
0713 #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
0714     /*Call registered Line Event callback */
0715     hltdc->LineEventCallback(hltdc);
0716 #else
0717     /*Call Legacy Line Event callback */
0718     HAL_LTDC_LineEventCallback(hltdc);
0719 #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
0720   }
0721 
0722   /* Register reload Interrupt management ***************************************/
0723   if (((isrflags & LTDC_ISR_RRIF) != 0U) && ((itsources & LTDC_IER_RRIE) != 0U))
0724   {
0725     /* Disable the register reload interrupt */
0726     __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_RR);
0727 
0728     /* Clear the register reload flag */
0729     __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_RR);
0730 
0731     /* Change LTDC state */
0732     hltdc->State = HAL_LTDC_STATE_READY;
0733 
0734     /* Process unlocked */
0735     __HAL_UNLOCK(hltdc);
0736 
0737     /* Reload interrupt Callback */
0738 #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
0739     /*Call registered reload Event callback */
0740     hltdc->ReloadEventCallback(hltdc);
0741 #else
0742     /*Call Legacy Reload Event callback */
0743     HAL_LTDC_ReloadEventCallback(hltdc);
0744 #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
0745   }
0746 }
0747 
0748 /**
0749   * @brief  Error LTDC callback.
0750   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
0751   *                the configuration information for the LTDC.
0752   * @retval None
0753   */
0754 __weak void HAL_LTDC_ErrorCallback(LTDC_HandleTypeDef *hltdc)
0755 {
0756   /* Prevent unused argument(s) compilation warning */
0757   UNUSED(hltdc);
0758 
0759   /* NOTE : This function should not be modified, when the callback is needed,
0760             the HAL_LTDC_ErrorCallback could be implemented in the user file
0761    */
0762 }
0763 
0764 /**
0765   * @brief  Line Event callback.
0766   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
0767   *                the configuration information for the LTDC.
0768   * @retval None
0769   */
0770 __weak void HAL_LTDC_LineEventCallback(LTDC_HandleTypeDef *hltdc)
0771 {
0772   /* Prevent unused argument(s) compilation warning */
0773   UNUSED(hltdc);
0774 
0775   /* NOTE : This function should not be modified, when the callback is needed,
0776             the HAL_LTDC_LineEventCallback could be implemented in the user file
0777    */
0778 }
0779 
0780 /**
0781   * @brief  Reload Event callback.
0782   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
0783   *                the configuration information for the LTDC.
0784   * @retval None
0785   */
0786 __weak void HAL_LTDC_ReloadEventCallback(LTDC_HandleTypeDef *hltdc)
0787 {
0788   /* Prevent unused argument(s) compilation warning */
0789   UNUSED(hltdc);
0790 
0791   /* NOTE : This function should not be modified, when the callback is needed,
0792             the HAL_LTDC_ReloadEvenCallback could be implemented in the user file
0793    */
0794 }
0795 
0796 /**
0797   * @}
0798   */
0799 
0800 /** @defgroup LTDC_Exported_Functions_Group3 Peripheral Control functions
0801   * @ingroup RTEMSBSPsARMSTM32H7
0802   *  @brief    Peripheral Control functions
0803   *
0804 @verbatim
0805  ===============================================================================
0806                     ##### Peripheral Control functions #####
0807  ===============================================================================
0808     [..]  This section provides functions allowing to:
0809       (+) Configure the LTDC foreground or/and background parameters.
0810       (+) Set the active layer.
0811       (+) Configure the color keying.
0812       (+) Configure the C-LUT.
0813       (+) Enable / Disable the color keying.
0814       (+) Enable / Disable the C-LUT.
0815       (+) Update the layer position.
0816       (+) Update the layer size.
0817       (+) Update pixel format on the fly.
0818       (+) Update transparency on the fly.
0819       (+) Update address on the fly.
0820 
0821 @endverbatim
0822   * @{
0823   */
0824 
0825 /**
0826   * @brief  Configure the LTDC Layer according to the specified
0827   *         parameters in the LTDC_InitTypeDef and create the associated handle.
0828   * @param  hltdc      pointer to a LTDC_HandleTypeDef structure that contains
0829   *                    the configuration information for the LTDC.
0830   * @param  pLayerCfg  pointer to a LTDC_LayerCfgTypeDef structure that contains
0831   *                    the configuration information for the Layer.
0832   * @param  LayerIdx  LTDC Layer index.
0833   *                    This parameter can be one of the following values:
0834   *                    LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
0835   * @retval HAL status
0836   */
0837 HAL_StatusTypeDef HAL_LTDC_ConfigLayer(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)
0838 {
0839   /* Check the parameters */
0840   assert_param(IS_LTDC_LAYER(LayerIdx));
0841   assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));
0842   assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));
0843   assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));
0844   assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));
0845   assert_param(IS_LTDC_PIXEL_FORMAT(pLayerCfg->PixelFormat));
0846   assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha));
0847   assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha0));
0848   assert_param(IS_LTDC_BLENDING_FACTOR1(pLayerCfg->BlendingFactor1));
0849   assert_param(IS_LTDC_BLENDING_FACTOR2(pLayerCfg->BlendingFactor2));
0850   assert_param(IS_LTDC_CFBLL(pLayerCfg->ImageWidth));
0851   assert_param(IS_LTDC_CFBLNBR(pLayerCfg->ImageHeight));
0852 
0853   /* Process locked */
0854   __HAL_LOCK(hltdc);
0855 
0856   /* Change LTDC peripheral state */
0857   hltdc->State = HAL_LTDC_STATE_BUSY;
0858 
0859   /* Copy new layer configuration into handle structure */
0860   hltdc->LayerCfg[LayerIdx] = *pLayerCfg;
0861 
0862   /* Configure the LTDC Layer */
0863   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
0864 
0865   /* Set the Immediate Reload type */
0866   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
0867 
0868   /* Initialize the LTDC state*/
0869   hltdc->State  = HAL_LTDC_STATE_READY;
0870 
0871   /* Process unlocked */
0872   __HAL_UNLOCK(hltdc);
0873 
0874   return HAL_OK;
0875 }
0876 
0877 /**
0878   * @brief  Configure the color keying.
0879   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
0880   *                   the configuration information for the LTDC.
0881   * @param  RGBValue  the color key value
0882   * @param  LayerIdx  LTDC Layer index.
0883   *                   This parameter can be one of the following values:
0884   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
0885   * @retval HAL status
0886   */
0887 HAL_StatusTypeDef HAL_LTDC_ConfigColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t RGBValue, uint32_t LayerIdx)
0888 {
0889   /* Check the parameters */
0890   assert_param(IS_LTDC_LAYER(LayerIdx));
0891 
0892   /* Process locked */
0893   __HAL_LOCK(hltdc);
0894 
0895   /* Change LTDC peripheral state */
0896   hltdc->State = HAL_LTDC_STATE_BUSY;
0897 
0898   /* Configure the default color values */
0899   LTDC_LAYER(hltdc, LayerIdx)->CKCR &=  ~(LTDC_LxCKCR_CKBLUE | LTDC_LxCKCR_CKGREEN | LTDC_LxCKCR_CKRED);
0900   LTDC_LAYER(hltdc, LayerIdx)->CKCR  = RGBValue;
0901 
0902   /* Set the Immediate Reload type */
0903   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
0904 
0905   /* Change the LTDC state*/
0906   hltdc->State = HAL_LTDC_STATE_READY;
0907 
0908   /* Process unlocked */
0909   __HAL_UNLOCK(hltdc);
0910 
0911   return HAL_OK;
0912 }
0913 
0914 /**
0915   * @brief  Load the color lookup table.
0916   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
0917   *                   the configuration information for the LTDC.
0918   * @param  pCLUT     pointer to the color lookup table address.
0919   * @param  CLUTSize  the color lookup table size.
0920   * @param  LayerIdx  LTDC Layer index.
0921   *                   This parameter can be one of the following values:
0922   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
0923   * @retval HAL status
0924   */
0925 HAL_StatusTypeDef HAL_LTDC_ConfigCLUT(LTDC_HandleTypeDef *hltdc, uint32_t *pCLUT, uint32_t CLUTSize, uint32_t LayerIdx)
0926 {
0927   uint32_t tmp;
0928   uint32_t counter;
0929   uint32_t *pcolorlut = pCLUT;
0930   /* Check the parameters */
0931   assert_param(IS_LTDC_LAYER(LayerIdx));
0932 
0933   /* Process locked */
0934   __HAL_LOCK(hltdc);
0935 
0936   /* Change LTDC peripheral state */
0937   hltdc->State = HAL_LTDC_STATE_BUSY;
0938 
0939   for (counter = 0U; (counter < CLUTSize); counter++)
0940   {
0941     if (hltdc->LayerCfg[LayerIdx].PixelFormat == LTDC_PIXEL_FORMAT_AL44)
0942     {
0943       tmp  = (((counter + (16U * counter)) << 24U) | ((uint32_t)(*pcolorlut) & 0xFFU) | \
0944               ((uint32_t)(*pcolorlut) & 0xFF00U) | ((uint32_t)(*pcolorlut) & 0xFF0000U));
0945     }
0946     else
0947     {
0948       tmp  = ((counter << 24U) | ((uint32_t)(*pcolorlut) & 0xFFU) | \
0949               ((uint32_t)(*pcolorlut) & 0xFF00U) | ((uint32_t)(*pcolorlut) & 0xFF0000U));
0950     }
0951 
0952     pcolorlut++;
0953 
0954     /* Specifies the C-LUT address and RGB value */
0955     LTDC_LAYER(hltdc, LayerIdx)->CLUTWR  = tmp;
0956   }
0957 
0958   /* Change the LTDC state*/
0959   hltdc->State = HAL_LTDC_STATE_READY;
0960 
0961   /* Process unlocked */
0962   __HAL_UNLOCK(hltdc);
0963 
0964   return HAL_OK;
0965 }
0966 
0967 /**
0968   * @brief  Enable the color keying.
0969   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
0970   *                   the configuration information for the LTDC.
0971   * @param  LayerIdx  LTDC Layer index.
0972   *                   This parameter can be one of the following values:
0973   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
0974   * @retval  HAL status
0975   */
0976 HAL_StatusTypeDef HAL_LTDC_EnableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
0977 {
0978   /* Check the parameters */
0979   assert_param(IS_LTDC_LAYER(LayerIdx));
0980 
0981   /* Process locked */
0982   __HAL_LOCK(hltdc);
0983 
0984   /* Change LTDC peripheral state */
0985   hltdc->State = HAL_LTDC_STATE_BUSY;
0986 
0987   /* Enable LTDC color keying by setting COLKEN bit */
0988   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_COLKEN;
0989 
0990   /* Set the Immediate Reload type */
0991   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
0992 
0993   /* Change the LTDC state*/
0994   hltdc->State = HAL_LTDC_STATE_READY;
0995 
0996   /* Process unlocked */
0997   __HAL_UNLOCK(hltdc);
0998 
0999   return HAL_OK;
1000 }
1001 
1002 /**
1003   * @brief  Disable the color keying.
1004   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1005   *                   the configuration information for the LTDC.
1006   * @param  LayerIdx  LTDC Layer index.
1007   *                   This parameter can be one of the following values:
1008   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1009   * @retval  HAL status
1010   */
1011 HAL_StatusTypeDef HAL_LTDC_DisableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1012 {
1013   /* Check the parameters */
1014   assert_param(IS_LTDC_LAYER(LayerIdx));
1015 
1016   /* Process locked */
1017   __HAL_LOCK(hltdc);
1018 
1019   /* Change LTDC peripheral state */
1020   hltdc->State = HAL_LTDC_STATE_BUSY;
1021 
1022   /* Disable LTDC color keying by setting COLKEN bit */
1023   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_COLKEN;
1024 
1025   /* Set the Immediate Reload type */
1026   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1027 
1028   /* Change the LTDC state*/
1029   hltdc->State = HAL_LTDC_STATE_READY;
1030 
1031   /* Process unlocked */
1032   __HAL_UNLOCK(hltdc);
1033 
1034   return HAL_OK;
1035 }
1036 
1037 /**
1038   * @brief  Enable the color lookup table.
1039   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1040   *                   the configuration information for the LTDC.
1041   * @param  LayerIdx  LTDC Layer index.
1042   *                   This parameter can be one of the following values:
1043   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1044   * @retval  HAL status
1045   */
1046 HAL_StatusTypeDef HAL_LTDC_EnableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1047 {
1048   /* Check the parameters */
1049   assert_param(IS_LTDC_LAYER(LayerIdx));
1050 
1051   /* Process locked */
1052   __HAL_LOCK(hltdc);
1053 
1054   /* Change LTDC peripheral state */
1055   hltdc->State = HAL_LTDC_STATE_BUSY;
1056 
1057   /* Enable LTDC color lookup table by setting CLUTEN bit */
1058   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_CLUTEN;
1059 
1060   /* Set the Immediate Reload type */
1061   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1062 
1063   /* Change the LTDC state*/
1064   hltdc->State = HAL_LTDC_STATE_READY;
1065 
1066   /* Process unlocked */
1067   __HAL_UNLOCK(hltdc);
1068 
1069   return HAL_OK;
1070 }
1071 
1072 /**
1073   * @brief  Disable the color lookup table.
1074   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1075   *                   the configuration information for the LTDC.
1076   * @param  LayerIdx  LTDC Layer index.
1077   *                   This parameter can be one of the following values:
1078   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1079   * @retval  HAL status
1080   */
1081 HAL_StatusTypeDef HAL_LTDC_DisableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1082 {
1083   /* Check the parameters */
1084   assert_param(IS_LTDC_LAYER(LayerIdx));
1085 
1086   /* Process locked */
1087   __HAL_LOCK(hltdc);
1088 
1089   /* Change LTDC peripheral state */
1090   hltdc->State = HAL_LTDC_STATE_BUSY;
1091 
1092   /* Disable LTDC color lookup table by setting CLUTEN bit */
1093   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_CLUTEN;
1094 
1095   /* Set the Immediate Reload type */
1096   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1097 
1098   /* Change the LTDC state*/
1099   hltdc->State = HAL_LTDC_STATE_READY;
1100 
1101   /* Process unlocked */
1102   __HAL_UNLOCK(hltdc);
1103 
1104   return HAL_OK;
1105 }
1106 
1107 /**
1108   * @brief  Enable Dither.
1109   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
1110   *                the configuration information for the LTDC.
1111   * @retval  HAL status
1112   */
1113 
1114 HAL_StatusTypeDef HAL_LTDC_EnableDither(LTDC_HandleTypeDef *hltdc)
1115 {
1116   /* Process locked */
1117   __HAL_LOCK(hltdc);
1118 
1119   /* Change LTDC peripheral state */
1120   hltdc->State = HAL_LTDC_STATE_BUSY;
1121 
1122   /* Enable Dither by setting DTEN bit */
1123   LTDC->GCR |= (uint32_t)LTDC_GCR_DEN;
1124 
1125   /* Change the LTDC state*/
1126   hltdc->State = HAL_LTDC_STATE_READY;
1127 
1128   /* Process unlocked */
1129   __HAL_UNLOCK(hltdc);
1130 
1131   return HAL_OK;
1132 }
1133 
1134 /**
1135   * @brief  Disable Dither.
1136   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
1137   *                the configuration information for the LTDC.
1138   * @retval  HAL status
1139   */
1140 
1141 HAL_StatusTypeDef HAL_LTDC_DisableDither(LTDC_HandleTypeDef *hltdc)
1142 {
1143   /* Process locked */
1144   __HAL_LOCK(hltdc);
1145 
1146   /* Change LTDC peripheral state */
1147   hltdc->State = HAL_LTDC_STATE_BUSY;
1148 
1149   /* Disable Dither by setting DTEN bit */
1150   LTDC->GCR &= ~(uint32_t)LTDC_GCR_DEN;
1151 
1152   /* Change the LTDC state*/
1153   hltdc->State = HAL_LTDC_STATE_READY;
1154 
1155   /* Process unlocked */
1156   __HAL_UNLOCK(hltdc);
1157 
1158   return HAL_OK;
1159 }
1160 
1161 /**
1162   * @brief  Set the LTDC window size.
1163   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1164   *                   the configuration information for the LTDC.
1165   * @param  XSize     LTDC Pixel per line
1166   * @param  YSize     LTDC Line number
1167   * @param  LayerIdx  LTDC Layer index.
1168   *                   This parameter can be one of the following values:
1169   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1170   * @retval  HAL status
1171   */
1172 HAL_StatusTypeDef HAL_LTDC_SetWindowSize(LTDC_HandleTypeDef *hltdc, uint32_t XSize, uint32_t YSize, uint32_t LayerIdx)
1173 {
1174   LTDC_LayerCfgTypeDef *pLayerCfg;
1175 
1176   /* Check the parameters (Layers parameters)*/
1177   assert_param(IS_LTDC_LAYER(LayerIdx));
1178   assert_param(IS_LTDC_CFBLL(XSize));
1179   assert_param(IS_LTDC_CFBLNBR(YSize));
1180 
1181   /* Process locked */
1182   __HAL_LOCK(hltdc);
1183 
1184   /* Change LTDC peripheral state */
1185   hltdc->State = HAL_LTDC_STATE_BUSY;
1186 
1187   /* Get layer configuration from handle structure */
1188   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1189 
1190   /* update horizontal stop */
1191   pLayerCfg->WindowX1 = XSize + pLayerCfg->WindowX0;
1192 
1193   /* update vertical stop */
1194   pLayerCfg->WindowY1 = YSize + pLayerCfg->WindowY0;
1195 
1196   /* Reconfigures the color frame buffer pitch in byte */
1197   pLayerCfg->ImageWidth = XSize;
1198 
1199   /* Reconfigures the frame buffer line number */
1200   pLayerCfg->ImageHeight = YSize;
1201 
1202   /* Set LTDC parameters */
1203   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1204 
1205   /* Set the Immediate Reload type */
1206   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1207 
1208   /* Change the LTDC state*/
1209   hltdc->State = HAL_LTDC_STATE_READY;
1210 
1211   /* Process unlocked */
1212   __HAL_UNLOCK(hltdc);
1213 
1214   return HAL_OK;
1215 }
1216 
1217 /**
1218   * @brief  Set the LTDC window position.
1219   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1220   *                   the configuration information for the LTDC.
1221   * @param  X0        LTDC window X offset
1222   * @param  Y0        LTDC window Y offset
1223   * @param  LayerIdx  LTDC Layer index.
1224   *                         This parameter can be one of the following values:
1225   *                         LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1226   * @retval  HAL status
1227   */
1228 HAL_StatusTypeDef HAL_LTDC_SetWindowPosition(LTDC_HandleTypeDef *hltdc, uint32_t X0, uint32_t Y0, uint32_t LayerIdx)
1229 {
1230   LTDC_LayerCfgTypeDef *pLayerCfg;
1231 
1232   /* Check the parameters */
1233   assert_param(IS_LTDC_LAYER(LayerIdx));
1234   assert_param(IS_LTDC_CFBLL(X0));
1235   assert_param(IS_LTDC_CFBLNBR(Y0));
1236 
1237   /* Process locked */
1238   __HAL_LOCK(hltdc);
1239 
1240   /* Change LTDC peripheral state */
1241   hltdc->State = HAL_LTDC_STATE_BUSY;
1242 
1243   /* Get layer configuration from handle structure */
1244   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1245 
1246   /* update horizontal start/stop */
1247   pLayerCfg->WindowX0 = X0;
1248   pLayerCfg->WindowX1 = X0 + pLayerCfg->ImageWidth;
1249 
1250   /* update vertical start/stop */
1251   pLayerCfg->WindowY0 = Y0;
1252   pLayerCfg->WindowY1 = Y0 + pLayerCfg->ImageHeight;
1253 
1254   /* Set LTDC parameters */
1255   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1256 
1257   /* Set the Immediate Reload type */
1258   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1259 
1260   /* Change the LTDC state*/
1261   hltdc->State = HAL_LTDC_STATE_READY;
1262 
1263   /* Process unlocked */
1264   __HAL_UNLOCK(hltdc);
1265 
1266   return HAL_OK;
1267 }
1268 
1269 /**
1270   * @brief  Reconfigure the pixel format.
1271   * @param  hltdc        pointer to a LTDC_HandleTypeDef structure that contains
1272   *                      the configuration information for the LTDC.
1273   * @param  Pixelformat  new pixel format value.
1274   * @param  LayerIdx     LTDC Layer index.
1275   *                      This parameter can be one of the following values:
1276   *                      LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
1277   * @retval  HAL status
1278   */
1279 HAL_StatusTypeDef HAL_LTDC_SetPixelFormat(LTDC_HandleTypeDef *hltdc, uint32_t Pixelformat, uint32_t LayerIdx)
1280 {
1281   LTDC_LayerCfgTypeDef *pLayerCfg;
1282 
1283   /* Check the parameters */
1284   assert_param(IS_LTDC_PIXEL_FORMAT(Pixelformat));
1285   assert_param(IS_LTDC_LAYER(LayerIdx));
1286 
1287   /* Process locked */
1288   __HAL_LOCK(hltdc);
1289 
1290   /* Change LTDC peripheral state */
1291   hltdc->State = HAL_LTDC_STATE_BUSY;
1292 
1293   /* Get layer configuration from handle structure */
1294   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1295 
1296   /* Reconfigure the pixel format */
1297   pLayerCfg->PixelFormat = Pixelformat;
1298 
1299   /* Set LTDC parameters */
1300   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1301 
1302   /* Set the Immediate Reload type */
1303   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1304 
1305   /* Change the LTDC state*/
1306   hltdc->State = HAL_LTDC_STATE_READY;
1307 
1308   /* Process unlocked */
1309   __HAL_UNLOCK(hltdc);
1310 
1311   return HAL_OK;
1312 }
1313 
1314 /**
1315   * @brief  Reconfigure the layer alpha value.
1316   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1317   *                   the configuration information for the LTDC.
1318   * @param  Alpha     new alpha value.
1319   * @param  LayerIdx  LTDC Layer index.
1320   *                   This parameter can be one of the following values:
1321   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1322   * @retval  HAL status
1323   */
1324 HAL_StatusTypeDef HAL_LTDC_SetAlpha(LTDC_HandleTypeDef *hltdc, uint32_t Alpha, uint32_t LayerIdx)
1325 {
1326   LTDC_LayerCfgTypeDef *pLayerCfg;
1327 
1328   /* Check the parameters */
1329   assert_param(IS_LTDC_ALPHA(Alpha));
1330   assert_param(IS_LTDC_LAYER(LayerIdx));
1331 
1332   /* Process locked */
1333   __HAL_LOCK(hltdc);
1334 
1335   /* Change LTDC peripheral state */
1336   hltdc->State = HAL_LTDC_STATE_BUSY;
1337 
1338   /* Get layer configuration from handle structure */
1339   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1340 
1341   /* Reconfigure the Alpha value */
1342   pLayerCfg->Alpha = Alpha;
1343 
1344   /* Set LTDC parameters */
1345   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1346 
1347   /* Set the Immediate Reload type */
1348   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1349 
1350   /* Change the LTDC state*/
1351   hltdc->State = HAL_LTDC_STATE_READY;
1352 
1353   /* Process unlocked */
1354   __HAL_UNLOCK(hltdc);
1355 
1356   return HAL_OK;
1357 }
1358 /**
1359   * @brief  Reconfigure the frame buffer Address.
1360   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1361   *                   the configuration information for the LTDC.
1362   * @param  Address   new address value.
1363   * @param  LayerIdx  LTDC Layer index.
1364   *                   This parameter can be one of the following values:
1365   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
1366   * @retval  HAL status
1367   */
1368 HAL_StatusTypeDef HAL_LTDC_SetAddress(LTDC_HandleTypeDef *hltdc, uint32_t Address, uint32_t LayerIdx)
1369 {
1370   LTDC_LayerCfgTypeDef *pLayerCfg;
1371 
1372   /* Check the parameters */
1373   assert_param(IS_LTDC_LAYER(LayerIdx));
1374 
1375   /* Process locked */
1376   __HAL_LOCK(hltdc);
1377 
1378   /* Change LTDC peripheral state */
1379   hltdc->State = HAL_LTDC_STATE_BUSY;
1380 
1381   /* Get layer configuration from handle structure */
1382   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1383 
1384   /* Reconfigure the Address */
1385   pLayerCfg->FBStartAdress = Address;
1386 
1387   /* Set LTDC parameters */
1388   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1389 
1390   /* Set the Immediate Reload type */
1391   hltdc->Instance->SRCR = LTDC_SRCR_IMR;
1392 
1393   /* Change the LTDC state*/
1394   hltdc->State = HAL_LTDC_STATE_READY;
1395 
1396   /* Process unlocked */
1397   __HAL_UNLOCK(hltdc);
1398 
1399   return HAL_OK;
1400 }
1401 
1402 /**
1403   * @brief  Function used to reconfigure the pitch for specific cases where the attached LayerIdx buffer have a width
1404   *         that is larger than the one intended to be displayed on screen. Example of a buffer 800x480 attached to
1405   *         layer for which we want to read and display on screen only a portion 320x240 taken in the center
1406   *         of the buffer.
1407   *         The pitch in pixels will be in that case 800 pixels and not 320 pixels as initially configured by previous
1408   *         call to HAL_LTDC_ConfigLayer().
1409   * @note   This function should be called only after a previous call to HAL_LTDC_ConfigLayer() to modify the default
1410   *         pitch configured by HAL_LTDC_ConfigLayer() when required (refer to example described just above).
1411   * @param  hltdc              pointer to a LTDC_HandleTypeDef structure that contains
1412   *                            the configuration information for the LTDC.
1413   * @param  LinePitchInPixels  New line pitch in pixels to configure for LTDC layer 'LayerIdx'.
1414   * @param  LayerIdx           LTDC layer index concerned by the modification of line pitch.
1415   * @retval HAL status
1416   */
1417 HAL_StatusTypeDef HAL_LTDC_SetPitch(LTDC_HandleTypeDef *hltdc, uint32_t LinePitchInPixels, uint32_t LayerIdx)
1418 {
1419   uint32_t tmp;
1420   uint32_t pitchUpdate;
1421   uint32_t pixelFormat;
1422 
1423   /* Check the parameters */
1424   assert_param(IS_LTDC_LAYER(LayerIdx));
1425 
1426   /* Process locked */
1427   __HAL_LOCK(hltdc);
1428 
1429   /* Change LTDC peripheral state */
1430   hltdc->State = HAL_LTDC_STATE_BUSY;
1431 
1432   /* get LayerIdx used pixel format */
1433   pixelFormat = hltdc->LayerCfg[LayerIdx].PixelFormat;
1434 
1435   if (pixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
1436   {
1437     tmp = 4U;
1438   }
1439   else if (pixelFormat == LTDC_PIXEL_FORMAT_RGB888)
1440   {
1441     tmp = 3U;
1442   }
1443   else if ((pixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
1444            (pixelFormat == LTDC_PIXEL_FORMAT_RGB565)   || \
1445            (pixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
1446            (pixelFormat == LTDC_PIXEL_FORMAT_AL88))
1447   {
1448     tmp = 2U;
1449   }
1450   else
1451   {
1452     tmp = 1U;
1453   }
1454 
1455   pitchUpdate = ((LinePitchInPixels * tmp) << 16U);
1456 
1457   /* Clear previously set standard pitch */
1458   LTDC_LAYER(hltdc, LayerIdx)->CFBLR &= ~LTDC_LxCFBLR_CFBP;
1459 
1460   /* Set the Reload type as immediate update of LTDC pitch configured above */
1461   LTDC->SRCR |= LTDC_SRCR_IMR;
1462 
1463   /* Set new line pitch value */
1464   LTDC_LAYER(hltdc, LayerIdx)->CFBLR |= pitchUpdate;
1465 
1466   /* Set the Reload type as immediate update of LTDC pitch configured above */
1467   LTDC->SRCR |= LTDC_SRCR_IMR;
1468 
1469   /* Change the LTDC state*/
1470   hltdc->State = HAL_LTDC_STATE_READY;
1471 
1472   /* Process unlocked */
1473   __HAL_UNLOCK(hltdc);
1474 
1475   return HAL_OK;
1476 }
1477 
1478 /**
1479   * @brief  Define the position of the line interrupt.
1480   * @param  hltdc   pointer to a LTDC_HandleTypeDef structure that contains
1481   *                 the configuration information for the LTDC.
1482   * @param  Line    Line Interrupt Position.
1483   * @note   User application may resort to HAL_LTDC_LineEventCallback() at line interrupt generation.
1484   * @retval  HAL status
1485   */
1486 HAL_StatusTypeDef HAL_LTDC_ProgramLineEvent(LTDC_HandleTypeDef *hltdc, uint32_t Line)
1487 {
1488   /* Check the parameters */
1489   assert_param(IS_LTDC_LIPOS(Line));
1490 
1491   /* Process locked */
1492   __HAL_LOCK(hltdc);
1493 
1494   /* Change LTDC peripheral state */
1495   hltdc->State = HAL_LTDC_STATE_BUSY;
1496 
1497   /* Disable the Line interrupt */
1498   __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_LI);
1499 
1500   /* Set the Line Interrupt position */
1501   LTDC->LIPCR = (uint32_t)Line;
1502 
1503   /* Enable the Line interrupt */
1504   __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_LI);
1505 
1506   /* Change the LTDC state*/
1507   hltdc->State = HAL_LTDC_STATE_READY;
1508 
1509   /* Process unlocked */
1510   __HAL_UNLOCK(hltdc);
1511 
1512   return HAL_OK;
1513 }
1514 
1515 /**
1516   * @brief  Reload LTDC Layers configuration.
1517   * @param  hltdc      pointer to a LTDC_HandleTypeDef structure that contains
1518   *                    the configuration information for the LTDC.
1519   * @param  ReloadType This parameter can be one of the following values :
1520   *                      LTDC_RELOAD_IMMEDIATE : Immediate Reload
1521   *                      LTDC_RELOAD_VERTICAL_BLANKING  : Reload in the next Vertical Blanking
1522   * @note   User application may resort to HAL_LTDC_ReloadEventCallback() at reload interrupt generation.
1523   * @retval  HAL status
1524   */
1525 HAL_StatusTypeDef  HAL_LTDC_Reload(LTDC_HandleTypeDef *hltdc, uint32_t ReloadType)
1526 {
1527   /* Check the parameters */
1528   assert_param(IS_LTDC_RELOAD(ReloadType));
1529 
1530   /* Process locked */
1531   __HAL_LOCK(hltdc);
1532 
1533   /* Change LTDC peripheral state */
1534   hltdc->State = HAL_LTDC_STATE_BUSY;
1535 
1536   /* Enable the Reload interrupt */
1537   __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_RR);
1538 
1539   /* Apply Reload type */
1540   hltdc->Instance->SRCR = ReloadType;
1541 
1542   /* Change the LTDC state*/
1543   hltdc->State = HAL_LTDC_STATE_READY;
1544 
1545   /* Process unlocked */
1546   __HAL_UNLOCK(hltdc);
1547 
1548   return HAL_OK;
1549 }
1550 
1551 /**
1552   * @brief  Configure the LTDC Layer according to the specified without reloading
1553   *         parameters in the LTDC_InitTypeDef and create the associated handle.
1554   *         Variant of the function HAL_LTDC_ConfigLayer without immediate reload.
1555   * @param  hltdc      pointer to a LTDC_HandleTypeDef structure that contains
1556   *                    the configuration information for the LTDC.
1557   * @param  pLayerCfg  pointer to a LTDC_LayerCfgTypeDef structure that contains
1558   *                    the configuration information for the Layer.
1559   * @param  LayerIdx   LTDC Layer index.
1560   *                    This parameter can be one of the following values:
1561   *                    LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1562   * @retval HAL status
1563   */
1564 HAL_StatusTypeDef HAL_LTDC_ConfigLayer_NoReload(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg,
1565                                                 uint32_t LayerIdx)
1566 {
1567   /* Check the parameters */
1568   assert_param(IS_LTDC_LAYER(LayerIdx));
1569   assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));
1570   assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));
1571   assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));
1572   assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));
1573   assert_param(IS_LTDC_PIXEL_FORMAT(pLayerCfg->PixelFormat));
1574   assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha));
1575   assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha0));
1576   assert_param(IS_LTDC_BLENDING_FACTOR1(pLayerCfg->BlendingFactor1));
1577   assert_param(IS_LTDC_BLENDING_FACTOR2(pLayerCfg->BlendingFactor2));
1578   assert_param(IS_LTDC_CFBLL(pLayerCfg->ImageWidth));
1579   assert_param(IS_LTDC_CFBLNBR(pLayerCfg->ImageHeight));
1580 
1581   /* Process locked */
1582   __HAL_LOCK(hltdc);
1583 
1584   /* Change LTDC peripheral state */
1585   hltdc->State = HAL_LTDC_STATE_BUSY;
1586 
1587   /* Copy new layer configuration into handle structure */
1588   hltdc->LayerCfg[LayerIdx] = *pLayerCfg;
1589 
1590   /* Configure the LTDC Layer */
1591   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1592 
1593   /* Initialize the LTDC state*/
1594   hltdc->State  = HAL_LTDC_STATE_READY;
1595 
1596   /* Process unlocked */
1597   __HAL_UNLOCK(hltdc);
1598 
1599   return HAL_OK;
1600 }
1601 
1602 /**
1603   * @brief  Set the LTDC window size without reloading.
1604   *         Variant of the function HAL_LTDC_SetWindowSize without immediate reload.
1605   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1606   *                   the configuration information for the LTDC.
1607   * @param  XSize     LTDC Pixel per line
1608   * @param  YSize     LTDC Line number
1609   * @param  LayerIdx  LTDC Layer index.
1610   *                   This parameter can be one of the following values:
1611   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1612   * @retval  HAL status
1613   */
1614 HAL_StatusTypeDef HAL_LTDC_SetWindowSize_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t XSize, uint32_t YSize,
1615                                                   uint32_t LayerIdx)
1616 {
1617   LTDC_LayerCfgTypeDef *pLayerCfg;
1618 
1619   /* Check the parameters (Layers parameters)*/
1620   assert_param(IS_LTDC_LAYER(LayerIdx));
1621   assert_param(IS_LTDC_CFBLL(XSize));
1622   assert_param(IS_LTDC_CFBLNBR(YSize));
1623 
1624   /* Process locked */
1625   __HAL_LOCK(hltdc);
1626 
1627   /* Change LTDC peripheral state */
1628   hltdc->State = HAL_LTDC_STATE_BUSY;
1629 
1630   /* Get layer configuration from handle structure */
1631   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1632 
1633   /* update horizontal stop */
1634   pLayerCfg->WindowX1 = XSize + pLayerCfg->WindowX0;
1635 
1636   /* update vertical stop */
1637   pLayerCfg->WindowY1 = YSize + pLayerCfg->WindowY0;
1638 
1639   /* Reconfigures the color frame buffer pitch in byte */
1640   pLayerCfg->ImageWidth = XSize;
1641 
1642   /* Reconfigures the frame buffer line number */
1643   pLayerCfg->ImageHeight = YSize;
1644 
1645   /* Set LTDC parameters */
1646   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1647 
1648   /* Change the LTDC state*/
1649   hltdc->State = HAL_LTDC_STATE_READY;
1650 
1651   /* Process unlocked */
1652   __HAL_UNLOCK(hltdc);
1653 
1654   return HAL_OK;
1655 }
1656 
1657 /**
1658   * @brief  Set the LTDC window position without reloading.
1659   *         Variant of the function HAL_LTDC_SetWindowPosition without immediate reload.
1660   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1661   *                   the configuration information for the LTDC.
1662   * @param  X0        LTDC window X offset
1663   * @param  Y0        LTDC window Y offset
1664   * @param  LayerIdx  LTDC Layer index.
1665   *                         This parameter can be one of the following values:
1666   *                         LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1667   * @retval  HAL status
1668   */
1669 HAL_StatusTypeDef HAL_LTDC_SetWindowPosition_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t X0, uint32_t Y0,
1670                                                       uint32_t LayerIdx)
1671 {
1672   LTDC_LayerCfgTypeDef *pLayerCfg;
1673 
1674   /* Check the parameters */
1675   assert_param(IS_LTDC_LAYER(LayerIdx));
1676   assert_param(IS_LTDC_CFBLL(X0));
1677   assert_param(IS_LTDC_CFBLNBR(Y0));
1678 
1679   /* Process locked */
1680   __HAL_LOCK(hltdc);
1681 
1682   /* Change LTDC peripheral state */
1683   hltdc->State = HAL_LTDC_STATE_BUSY;
1684 
1685   /* Get layer configuration from handle structure */
1686   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1687 
1688   /* update horizontal start/stop */
1689   pLayerCfg->WindowX0 = X0;
1690   pLayerCfg->WindowX1 = X0 + pLayerCfg->ImageWidth;
1691 
1692   /* update vertical start/stop */
1693   pLayerCfg->WindowY0 = Y0;
1694   pLayerCfg->WindowY1 = Y0 + pLayerCfg->ImageHeight;
1695 
1696   /* Set LTDC parameters */
1697   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1698 
1699   /* Change the LTDC state*/
1700   hltdc->State = HAL_LTDC_STATE_READY;
1701 
1702   /* Process unlocked */
1703   __HAL_UNLOCK(hltdc);
1704 
1705   return HAL_OK;
1706 }
1707 
1708 /**
1709   * @brief  Reconfigure the pixel format without reloading.
1710   *         Variant of the function HAL_LTDC_SetPixelFormat without immediate reload.
1711   * @param  hltdc        pointer to a LTDC_HandleTypeDfef structure that contains
1712   *                      the configuration information for the LTDC.
1713   * @param  Pixelformat  new pixel format value.
1714   * @param  LayerIdx     LTDC Layer index.
1715   *                      This parameter can be one of the following values:
1716   *                      LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
1717   * @retval  HAL status
1718   */
1719 HAL_StatusTypeDef HAL_LTDC_SetPixelFormat_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Pixelformat, uint32_t LayerIdx)
1720 {
1721   LTDC_LayerCfgTypeDef *pLayerCfg;
1722 
1723   /* Check the parameters */
1724   assert_param(IS_LTDC_PIXEL_FORMAT(Pixelformat));
1725   assert_param(IS_LTDC_LAYER(LayerIdx));
1726 
1727   /* Process locked */
1728   __HAL_LOCK(hltdc);
1729 
1730   /* Change LTDC peripheral state */
1731   hltdc->State = HAL_LTDC_STATE_BUSY;
1732 
1733   /* Get layer configuration from handle structure */
1734   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1735 
1736   /* Reconfigure the pixel format */
1737   pLayerCfg->PixelFormat = Pixelformat;
1738 
1739   /* Set LTDC parameters */
1740   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1741 
1742   /* Change the LTDC state*/
1743   hltdc->State = HAL_LTDC_STATE_READY;
1744 
1745   /* Process unlocked */
1746   __HAL_UNLOCK(hltdc);
1747 
1748   return HAL_OK;
1749 }
1750 
1751 /**
1752   * @brief  Reconfigure the layer alpha value without reloading.
1753   *         Variant of the function HAL_LTDC_SetAlpha without immediate reload.
1754   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1755   *                   the configuration information for the LTDC.
1756   * @param  Alpha     new alpha value.
1757   * @param  LayerIdx  LTDC Layer index.
1758   *                   This parameter can be one of the following values:
1759   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1760   * @retval  HAL status
1761   */
1762 HAL_StatusTypeDef HAL_LTDC_SetAlpha_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Alpha, uint32_t LayerIdx)
1763 {
1764   LTDC_LayerCfgTypeDef *pLayerCfg;
1765 
1766   /* Check the parameters */
1767   assert_param(IS_LTDC_ALPHA(Alpha));
1768   assert_param(IS_LTDC_LAYER(LayerIdx));
1769 
1770   /* Process locked */
1771   __HAL_LOCK(hltdc);
1772 
1773   /* Change LTDC peripheral state */
1774   hltdc->State = HAL_LTDC_STATE_BUSY;
1775 
1776   /* Get layer configuration from handle structure */
1777   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1778 
1779   /* Reconfigure the Alpha value */
1780   pLayerCfg->Alpha = Alpha;
1781 
1782   /* Set LTDC parameters */
1783   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1784 
1785   /* Change the LTDC state*/
1786   hltdc->State = HAL_LTDC_STATE_READY;
1787 
1788   /* Process unlocked */
1789   __HAL_UNLOCK(hltdc);
1790 
1791   return HAL_OK;
1792 }
1793 
1794 /**
1795   * @brief  Reconfigure the frame buffer Address without reloading.
1796   *         Variant of the function HAL_LTDC_SetAddress without immediate reload.
1797   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1798   *                   the configuration information for the LTDC.
1799   * @param  Address   new address value.
1800   * @param  LayerIdx  LTDC Layer index.
1801   *                   This parameter can be one of the following values:
1802   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
1803   * @retval  HAL status
1804   */
1805 HAL_StatusTypeDef HAL_LTDC_SetAddress_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Address, uint32_t LayerIdx)
1806 {
1807   LTDC_LayerCfgTypeDef *pLayerCfg;
1808 
1809   /* Check the parameters */
1810   assert_param(IS_LTDC_LAYER(LayerIdx));
1811 
1812   /* Process locked */
1813   __HAL_LOCK(hltdc);
1814 
1815   /* Change LTDC peripheral state */
1816   hltdc->State = HAL_LTDC_STATE_BUSY;
1817 
1818   /* Get layer configuration from handle structure */
1819   pLayerCfg = &hltdc->LayerCfg[LayerIdx];
1820 
1821   /* Reconfigure the Address */
1822   pLayerCfg->FBStartAdress = Address;
1823 
1824   /* Set LTDC parameters */
1825   LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
1826 
1827   /* Change the LTDC state*/
1828   hltdc->State = HAL_LTDC_STATE_READY;
1829 
1830   /* Process unlocked */
1831   __HAL_UNLOCK(hltdc);
1832 
1833   return HAL_OK;
1834 }
1835 
1836 /**
1837   * @brief  Function used to reconfigure the pitch for specific cases where the attached LayerIdx buffer have a width
1838   *         that is larger than the one intended to be displayed on screen. Example of a buffer 800x480 attached to
1839   *         layer for which we want to read and display on screen only a portion 320x240 taken in the center
1840   *         of the buffer.
1841   *         The pitch in pixels will be in that case 800 pixels and not 320 pixels as initially configured by
1842   *         previous call to HAL_LTDC_ConfigLayer().
1843   * @note   This function should be called only after a previous call to HAL_LTDC_ConfigLayer() to modify the default
1844   *         pitch configured by HAL_LTDC_ConfigLayer() when required (refer to example described just above).
1845   *         Variant of the function HAL_LTDC_SetPitch without immediate reload.
1846   * @param  hltdc              pointer to a LTDC_HandleTypeDef structure that contains
1847   *                            the configuration information for the LTDC.
1848   * @param  LinePitchInPixels  New line pitch in pixels to configure for LTDC layer 'LayerIdx'.
1849   * @param  LayerIdx           LTDC layer index concerned by the modification of line pitch.
1850   * @retval HAL status
1851   */
1852 HAL_StatusTypeDef HAL_LTDC_SetPitch_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LinePitchInPixels, uint32_t LayerIdx)
1853 {
1854   uint32_t tmp;
1855   uint32_t pitchUpdate;
1856   uint32_t pixelFormat;
1857 
1858   /* Check the parameters */
1859   assert_param(IS_LTDC_LAYER(LayerIdx));
1860 
1861   /* Process locked */
1862   __HAL_LOCK(hltdc);
1863 
1864   /* Change LTDC peripheral state */
1865   hltdc->State = HAL_LTDC_STATE_BUSY;
1866 
1867   /* get LayerIdx used pixel format */
1868   pixelFormat = hltdc->LayerCfg[LayerIdx].PixelFormat;
1869 
1870   if (pixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
1871   {
1872     tmp = 4U;
1873   }
1874   else if (pixelFormat == LTDC_PIXEL_FORMAT_RGB888)
1875   {
1876     tmp = 3U;
1877   }
1878   else if ((pixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
1879            (pixelFormat == LTDC_PIXEL_FORMAT_RGB565)   || \
1880            (pixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
1881            (pixelFormat == LTDC_PIXEL_FORMAT_AL88))
1882   {
1883     tmp = 2U;
1884   }
1885   else
1886   {
1887     tmp = 1U;
1888   }
1889 
1890   pitchUpdate = ((LinePitchInPixels * tmp) << 16U);
1891 
1892   /* Clear previously set standard pitch */
1893   LTDC_LAYER(hltdc, LayerIdx)->CFBLR &= ~LTDC_LxCFBLR_CFBP;
1894 
1895   /* Set new line pitch value */
1896   LTDC_LAYER(hltdc, LayerIdx)->CFBLR |= pitchUpdate;
1897 
1898   /* Change the LTDC state*/
1899   hltdc->State = HAL_LTDC_STATE_READY;
1900 
1901   /* Process unlocked */
1902   __HAL_UNLOCK(hltdc);
1903 
1904   return HAL_OK;
1905 }
1906 
1907 
1908 /**
1909   * @brief  Configure the color keying without reloading.
1910   *         Variant of the function HAL_LTDC_ConfigColorKeying without immediate reload.
1911   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1912   *                   the configuration information for the LTDC.
1913   * @param  RGBValue the color key value
1914   * @param  LayerIdx  LTDC Layer index.
1915   *                   This parameter can be one of the following values:
1916   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1917   * @retval HAL status
1918   */
1919 HAL_StatusTypeDef HAL_LTDC_ConfigColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t RGBValue, uint32_t LayerIdx)
1920 {
1921   /* Check the parameters */
1922   assert_param(IS_LTDC_LAYER(LayerIdx));
1923 
1924   /* Process locked */
1925   __HAL_LOCK(hltdc);
1926 
1927   /* Change LTDC peripheral state */
1928   hltdc->State = HAL_LTDC_STATE_BUSY;
1929 
1930   /* Configure the default color values */
1931   LTDC_LAYER(hltdc, LayerIdx)->CKCR &=  ~(LTDC_LxCKCR_CKBLUE | LTDC_LxCKCR_CKGREEN | LTDC_LxCKCR_CKRED);
1932   LTDC_LAYER(hltdc, LayerIdx)->CKCR  = RGBValue;
1933 
1934   /* Change the LTDC state*/
1935   hltdc->State = HAL_LTDC_STATE_READY;
1936 
1937   /* Process unlocked */
1938   __HAL_UNLOCK(hltdc);
1939 
1940   return HAL_OK;
1941 }
1942 
1943 /**
1944   * @brief  Enable the color keying without reloading.
1945   *         Variant of the function HAL_LTDC_EnableColorKeying without immediate reload.
1946   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1947   *                   the configuration information for the LTDC.
1948   * @param  LayerIdx  LTDC Layer index.
1949   *                   This parameter can be one of the following values:
1950   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1951   * @retval  HAL status
1952   */
1953 HAL_StatusTypeDef HAL_LTDC_EnableColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1954 {
1955   /* Check the parameters */
1956   assert_param(IS_LTDC_LAYER(LayerIdx));
1957 
1958   /* Process locked */
1959   __HAL_LOCK(hltdc);
1960 
1961   /* Change LTDC peripheral state */
1962   hltdc->State = HAL_LTDC_STATE_BUSY;
1963 
1964   /* Enable LTDC color keying by setting COLKEN bit */
1965   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_COLKEN;
1966 
1967   /* Change the LTDC state*/
1968   hltdc->State = HAL_LTDC_STATE_READY;
1969 
1970   /* Process unlocked */
1971   __HAL_UNLOCK(hltdc);
1972 
1973   return HAL_OK;
1974 }
1975 
1976 /**
1977   * @brief  Disable the color keying without reloading.
1978   *         Variant of the function HAL_LTDC_DisableColorKeying without immediate reload.
1979   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
1980   *                   the configuration information for the LTDC.
1981   * @param  LayerIdx  LTDC Layer index.
1982   *                   This parameter can be one of the following values:
1983   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
1984   * @retval  HAL status
1985   */
1986 HAL_StatusTypeDef HAL_LTDC_DisableColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
1987 {
1988   /* Check the parameters */
1989   assert_param(IS_LTDC_LAYER(LayerIdx));
1990 
1991   /* Process locked */
1992   __HAL_LOCK(hltdc);
1993 
1994   /* Change LTDC peripheral state */
1995   hltdc->State = HAL_LTDC_STATE_BUSY;
1996 
1997   /* Disable LTDC color keying by setting COLKEN bit */
1998   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_COLKEN;
1999 
2000   /* Change the LTDC state*/
2001   hltdc->State = HAL_LTDC_STATE_READY;
2002 
2003   /* Process unlocked */
2004   __HAL_UNLOCK(hltdc);
2005 
2006   return HAL_OK;
2007 }
2008 
2009 /**
2010   * @brief  Enable the color lookup table without reloading.
2011   *         Variant of the function HAL_LTDC_EnableCLUT without immediate reload.
2012   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
2013   *                   the configuration information for the LTDC.
2014   * @param  LayerIdx  LTDC Layer index.
2015   *                   This parameter can be one of the following values:
2016   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
2017   * @retval  HAL status
2018   */
2019 HAL_StatusTypeDef HAL_LTDC_EnableCLUT_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
2020 {
2021   /* Check the parameters */
2022   assert_param(IS_LTDC_LAYER(LayerIdx));
2023 
2024   /* Process locked */
2025   __HAL_LOCK(hltdc);
2026 
2027   /* Change LTDC peripheral state */
2028   hltdc->State = HAL_LTDC_STATE_BUSY;
2029 
2030   /* Disable LTDC color lookup table by setting CLUTEN bit */
2031   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_CLUTEN;
2032 
2033   /* Change the LTDC state*/
2034   hltdc->State = HAL_LTDC_STATE_READY;
2035 
2036   /* Process unlocked */
2037   __HAL_UNLOCK(hltdc);
2038 
2039   return HAL_OK;
2040 }
2041 
2042 /**
2043   * @brief  Disable the color lookup table without reloading.
2044   *         Variant of the function HAL_LTDC_DisableCLUT without immediate reload.
2045   * @param  hltdc     pointer to a LTDC_HandleTypeDef structure that contains
2046   *                   the configuration information for the LTDC.
2047   * @param  LayerIdx  LTDC Layer index.
2048   *                   This parameter can be one of the following values:
2049   *                   LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
2050   * @retval  HAL status
2051   */
2052 HAL_StatusTypeDef HAL_LTDC_DisableCLUT_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
2053 {
2054   /* Check the parameters */
2055   assert_param(IS_LTDC_LAYER(LayerIdx));
2056 
2057   /* Process locked */
2058   __HAL_LOCK(hltdc);
2059 
2060   /* Change LTDC peripheral state */
2061   hltdc->State = HAL_LTDC_STATE_BUSY;
2062 
2063   /* Disable LTDC color lookup table by setting CLUTEN bit */
2064   LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_CLUTEN;
2065 
2066   /* Change the LTDC state*/
2067   hltdc->State = HAL_LTDC_STATE_READY;
2068 
2069   /* Process unlocked */
2070   __HAL_UNLOCK(hltdc);
2071 
2072   return HAL_OK;
2073 }
2074 
2075 /**
2076   * @}
2077   */
2078 
2079 /** @defgroup LTDC_Exported_Functions_Group4 Peripheral State and Errors functions
2080   * @ingroup RTEMSBSPsARMSTM32H7
2081   *  @brief    Peripheral State and Errors functions
2082   *
2083 @verbatim
2084  ===============================================================================
2085                   ##### Peripheral State and Errors functions #####
2086  ===============================================================================
2087     [..]
2088     This subsection provides functions allowing to
2089       (+) Check the LTDC handle state.
2090       (+) Get the LTDC handle error code.
2091 
2092 @endverbatim
2093   * @{
2094   */
2095 
2096 /**
2097   * @brief  Return the LTDC handle state.
2098   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
2099   *                the configuration information for the LTDC.
2100   * @retval HAL state
2101   */
2102 HAL_LTDC_StateTypeDef HAL_LTDC_GetState(LTDC_HandleTypeDef *hltdc)
2103 {
2104   return hltdc->State;
2105 }
2106 
2107 /**
2108   * @brief  Return the LTDC handle error code.
2109   * @param  hltdc  pointer to a LTDC_HandleTypeDef structure that contains
2110   *               the configuration information for the LTDC.
2111   * @retval LTDC Error Code
2112   */
2113 uint32_t HAL_LTDC_GetError(LTDC_HandleTypeDef *hltdc)
2114 {
2115   return hltdc->ErrorCode;
2116 }
2117 
2118 /**
2119   * @}
2120   */
2121 
2122 /**
2123   * @}
2124   */
2125 
2126 /** @defgroup LTDC_Private_Functions LTDC Private Functions
2127   * @ingroup RTEMSBSPsARMSTM32H7
2128   * @{
2129   */
2130 
2131 /**
2132   * @brief  Configure the LTDC peripheral
2133   * @param  hltdc     Pointer to a LTDC_HandleTypeDef structure that contains
2134   *                   the configuration information for the LTDC.
2135   * @param  pLayerCfg Pointer LTDC Layer Configuration structure
2136   * @param  LayerIdx  LTDC Layer index.
2137   *                   This parameter can be one of the following values: LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
2138   * @retval None
2139   */
2140 static void LTDC_SetConfig(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)
2141 {
2142   uint32_t tmp;
2143   uint32_t tmp1;
2144   uint32_t tmp2;
2145 
2146   /* Configure the horizontal start and stop position */
2147   tmp = ((pLayerCfg->WindowX1 + ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16U)) << 16U);
2148   LTDC_LAYER(hltdc, LayerIdx)->WHPCR &= ~(LTDC_LxWHPCR_WHSTPOS | LTDC_LxWHPCR_WHSPPOS);
2149   LTDC_LAYER(hltdc, LayerIdx)->WHPCR = ((pLayerCfg->WindowX0 + \
2150                                          ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16U) + 1U) | tmp);
2151 
2152   /* Configure the vertical start and stop position */
2153   tmp = ((pLayerCfg->WindowY1 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP)) << 16U);
2154   LTDC_LAYER(hltdc, LayerIdx)->WVPCR &= ~(LTDC_LxWVPCR_WVSTPOS | LTDC_LxWVPCR_WVSPPOS);
2155   LTDC_LAYER(hltdc, LayerIdx)->WVPCR  = ((pLayerCfg->WindowY0 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP) + 1U) | tmp);
2156 
2157   /* Specifies the pixel format */
2158   LTDC_LAYER(hltdc, LayerIdx)->PFCR &= ~(LTDC_LxPFCR_PF);
2159   LTDC_LAYER(hltdc, LayerIdx)->PFCR = (pLayerCfg->PixelFormat);
2160 
2161   /* Configure the default color values */
2162   tmp = ((uint32_t)(pLayerCfg->Backcolor.Green) << 8U);
2163   tmp1 = ((uint32_t)(pLayerCfg->Backcolor.Red) << 16U);
2164   tmp2 = (pLayerCfg->Alpha0 << 24U);
2165   LTDC_LAYER(hltdc, LayerIdx)->DCCR &= ~(LTDC_LxDCCR_DCBLUE | LTDC_LxDCCR_DCGREEN | LTDC_LxDCCR_DCRED |
2166                                          LTDC_LxDCCR_DCALPHA);
2167   LTDC_LAYER(hltdc, LayerIdx)->DCCR = (pLayerCfg->Backcolor.Blue | tmp | tmp1 | tmp2);
2168 
2169   /* Specifies the constant alpha value */
2170   LTDC_LAYER(hltdc, LayerIdx)->CACR &= ~(LTDC_LxCACR_CONSTA);
2171   LTDC_LAYER(hltdc, LayerIdx)->CACR = (pLayerCfg->Alpha);
2172 
2173   /* Specifies the blending factors */
2174   LTDC_LAYER(hltdc, LayerIdx)->BFCR &= ~(LTDC_LxBFCR_BF2 | LTDC_LxBFCR_BF1);
2175   LTDC_LAYER(hltdc, LayerIdx)->BFCR = (pLayerCfg->BlendingFactor1 | pLayerCfg->BlendingFactor2);
2176 
2177   /* Configure the color frame buffer start address */
2178   LTDC_LAYER(hltdc, LayerIdx)->CFBAR &= ~(LTDC_LxCFBAR_CFBADD);
2179   LTDC_LAYER(hltdc, LayerIdx)->CFBAR = (pLayerCfg->FBStartAdress);
2180 
2181   if (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
2182   {
2183     tmp = 4U;
2184   }
2185   else if (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
2186   {
2187     tmp = 3U;
2188   }
2189   else if ((pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
2190            (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB565)   || \
2191            (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
2192            (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_AL88))
2193   {
2194     tmp = 2U;
2195   }
2196   else
2197   {
2198     tmp = 1U;
2199   }
2200 
2201   /* Configure the color frame buffer pitch in byte */
2202   LTDC_LAYER(hltdc, LayerIdx)->CFBLR  &= ~(LTDC_LxCFBLR_CFBLL | LTDC_LxCFBLR_CFBP);
2203   LTDC_LAYER(hltdc, LayerIdx)->CFBLR  = (((pLayerCfg->ImageWidth * tmp) << 16U) |
2204                                          (((pLayerCfg->WindowX1 - pLayerCfg->WindowX0) * tmp)  + 7U));
2205   /* Configure the frame buffer line number */
2206   LTDC_LAYER(hltdc, LayerIdx)->CFBLNR  &= ~(LTDC_LxCFBLNR_CFBLNBR);
2207   LTDC_LAYER(hltdc, LayerIdx)->CFBLNR  = (pLayerCfg->ImageHeight);
2208 
2209   /* Enable LTDC_Layer by setting LEN bit */
2210   LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_LEN;
2211 }
2212 
2213 /**
2214   * @}
2215   */
2216 
2217 
2218 /**
2219   * @}
2220   */
2221 
2222 #endif /* LTDC */
2223 
2224 #endif /* HAL_LTDC_MODULE_ENABLED */
2225 
2226 /**
2227   * @}
2228   */
2229