Back to home page

LXR

 
 

    


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

0001 /**
0002   ******************************************************************************
0003   * @file    stm32h7xx_hal_dma2d.c
0004   * @author  MCD Application Team
0005   * @brief   DMA2D HAL module driver.
0006   *          This file provides firmware functions to manage the following
0007   *          functionalities of the DMA2D 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       (#) Program the required configuration through the following parameters:
0030           the transfer mode, the output color mode and the output offset using
0031           HAL_DMA2D_Init() function.
0032 
0033       (#) Program the required configuration through the following parameters:
0034           the input color mode, the input color, the input alpha value, the alpha mode,
0035           the red/blue swap mode, the inverted alpha mode and the input offset using
0036           HAL_DMA2D_ConfigLayer() function for foreground or/and background layer.
0037 
0038      *** Polling mode IO operation ***
0039      =================================
0040     [..]
0041        (#) Configure pdata parameter (explained hereafter), destination and data length
0042            and enable the transfer using HAL_DMA2D_Start().
0043        (#) Wait for end of transfer using HAL_DMA2D_PollForTransfer(), at this stage
0044            user can specify the value of timeout according to his end application.
0045 
0046      *** Interrupt mode IO operation ***
0047      ===================================
0048      [..]
0049        (#) Configure pdata parameter, destination and data length and enable
0050            the transfer using HAL_DMA2D_Start_IT().
0051        (#) Use HAL_DMA2D_IRQHandler() called under DMA2D_IRQHandler() interrupt subroutine.
0052        (#) At the end of data transfer HAL_DMA2D_IRQHandler() function is executed and user can
0053            add his own function by customization of function pointer XferCpltCallback (member
0054            of DMA2D handle structure).
0055        (#) In case of error, the HAL_DMA2D_IRQHandler() function calls the callback
0056            XferErrorCallback.
0057 
0058          -@-   In Register-to-Memory transfer mode, pdata parameter is the register
0059                color, in Memory-to-memory or Memory-to-Memory with pixel format
0060                conversion pdata is the source address.
0061 
0062          -@-   Configure the foreground source address, the background source address,
0063                the destination and data length then Enable the transfer using
0064                HAL_DMA2D_BlendingStart() in polling mode and HAL_DMA2D_BlendingStart_IT()
0065                in interrupt mode.
0066 
0067          -@-   HAL_DMA2D_BlendingStart() and HAL_DMA2D_BlendingStart_IT() functions
0068                are used if the memory to memory with blending transfer mode is selected.
0069 
0070       (#) Optionally, configure and enable the CLUT using HAL_DMA2D_CLUTLoad() in polling
0071           mode or HAL_DMA2D_CLUTLoad_IT() in interrupt mode.
0072 
0073       (#) Optionally, configure the line watermark in using the API HAL_DMA2D_ProgramLineEvent().
0074 
0075       (#) Optionally, configure the dead time value in the AHB clock cycle inserted between two
0076           consecutive accesses on the AHB master port in using the API HAL_DMA2D_ConfigDeadTime()
0077           and enable/disable the functionality  with the APIs HAL_DMA2D_EnableDeadTime() or
0078           HAL_DMA2D_DisableDeadTime().
0079 
0080       (#) The transfer can be suspended, resumed and aborted using the following
0081           functions: HAL_DMA2D_Suspend(), HAL_DMA2D_Resume(), HAL_DMA2D_Abort().
0082 
0083       (#) The CLUT loading can be suspended, resumed and aborted using the following
0084           functions: HAL_DMA2D_CLUTLoading_Suspend(), HAL_DMA2D_CLUTLoading_Resume(),
0085           HAL_DMA2D_CLUTLoading_Abort().
0086 
0087       (#) To control the DMA2D state, use the following function: HAL_DMA2D_GetState().
0088 
0089       (#) To read the DMA2D error code, use the following function: HAL_DMA2D_GetError().
0090 
0091      *** DMA2D HAL driver macros list ***
0092      =============================================
0093      [..]
0094        Below the list of most used macros in DMA2D HAL driver :
0095 
0096       (+) __HAL_DMA2D_ENABLE: Enable the DMA2D peripheral.
0097       (+) __HAL_DMA2D_GET_FLAG: Get the DMA2D pending flags.
0098       (+) __HAL_DMA2D_CLEAR_FLAG: Clear the DMA2D pending flags.
0099       (+) __HAL_DMA2D_ENABLE_IT: Enable the specified DMA2D interrupts.
0100       (+) __HAL_DMA2D_DISABLE_IT: Disable the specified DMA2D interrupts.
0101       (+) __HAL_DMA2D_GET_IT_SOURCE: Check whether the specified DMA2D interrupt is enabled or not.
0102 
0103      *** Callback registration ***
0104      ===================================
0105      [..]
0106       (#) The compilation define  USE_HAL_DMA2D_REGISTER_CALLBACKS when set to 1
0107           allows the user to configure dynamically the driver callbacks.
0108           Use function @ref HAL_DMA2D_RegisterCallback() to register a user callback.
0109 
0110       (#) Function @ref HAL_DMA2D_RegisterCallback() allows to register following callbacks:
0111             (+) XferCpltCallback : callback for transfer complete.
0112             (+) XferErrorCallback : callback for transfer error.
0113             (+) LineEventCallback : callback for line event.
0114             (+) CLUTLoadingCpltCallback : callback for CLUT loading completion.
0115             (+) MspInitCallback    : DMA2D MspInit.
0116             (+) MspDeInitCallback  : DMA2D MspDeInit.
0117           This function takes as parameters the HAL peripheral handle, the Callback ID
0118           and a pointer to the user callback function.
0119 
0120       (#) Use function @ref HAL_DMA2D_UnRegisterCallback() to reset a callback to the default
0121           weak (overridden) function.
0122           @ref HAL_DMA2D_UnRegisterCallback() takes as parameters the HAL peripheral handle,
0123           and the Callback ID.
0124           This function allows to reset following callbacks:
0125             (+) XferCpltCallback : callback for transfer complete.
0126             (+) XferErrorCallback : callback for transfer error.
0127             (+) LineEventCallback : callback for line event.
0128             (+) CLUTLoadingCpltCallback : callback for CLUT loading completion.
0129             (+) MspInitCallback    : DMA2D MspInit.
0130             (+) MspDeInitCallback  : DMA2D MspDeInit.
0131 
0132       (#) By default, after the @ref HAL_DMA2D_Init and if the state is HAL_DMA2D_STATE_RESET
0133           all callbacks are reset to the corresponding legacy weak (overridden) functions:
0134           examples @ref HAL_DMA2D_LineEventCallback(), @ref HAL_DMA2D_CLUTLoadingCpltCallback()
0135           Exception done for MspInit and MspDeInit callbacks that are respectively
0136           reset to the legacy weak (overridden) functions in the @ref HAL_DMA2D_Init
0137           and @ref HAL_DMA2D_DeInit only when these callbacks are null (not registered beforehand)
0138           If not, MspInit or MspDeInit are not null, the @ref HAL_DMA2D_Init and @ref HAL_DMA2D_DeInit
0139           keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
0140 
0141           Exception as well for Transfer Completion and Transfer Error callbacks that are not defined
0142           as weak (overridden) functions. They must be defined by the user to be resorted to.
0143 
0144           Callbacks can be registered/unregistered in READY state only.
0145           Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
0146           in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
0147           during the Init/DeInit.
0148           In that case first register the MspInit/MspDeInit user callbacks
0149           using @ref HAL_DMA2D_RegisterCallback before calling @ref HAL_DMA2D_DeInit
0150           or @ref HAL_DMA2D_Init function.
0151 
0152           When The compilation define USE_HAL_DMA2D_REGISTER_CALLBACKS is set to 0 or
0153           not defined, the callback registering feature is not available
0154           and weak (overridden) callbacks are used.
0155 
0156      [..]
0157       (@) You can refer to the DMA2D HAL driver header file for more useful macros
0158 
0159   @endverbatim
0160   ******************************************************************************
0161   */
0162 
0163 /* Includes ------------------------------------------------------------------*/
0164 #include "stm32h7xx_hal.h"
0165 
0166 #ifdef HAL_DMA2D_MODULE_ENABLED
0167 #if defined (DMA2D)
0168 
0169 /** @addtogroup STM32H7xx_HAL_Driver
0170   * @{
0171   */
0172 
0173 /** @defgroup DMA2D  DMA2D
0174   * @ingroup RTEMSBSPsARMSTM32H7
0175   * @brief DMA2D HAL module driver
0176   * @{
0177   */
0178 
0179 /* Private types -------------------------------------------------------------*/
0180 /* Private define ------------------------------------------------------------*/
0181 /** @defgroup DMA2D_Private_Constants DMA2D Private Constants
0182   * @ingroup RTEMSBSPsARMSTM32H7
0183   * @{
0184   */
0185 
0186 /** @defgroup DMA2D_TimeOut DMA2D Time Out
0187   * @ingroup RTEMSBSPsARMSTM32H7
0188   * @{
0189   */
0190 #define DMA2D_TIMEOUT_ABORT           (1000U)  /*!<  1s  */
0191 #define DMA2D_TIMEOUT_SUSPEND         (1000U)  /*!<  1s  */
0192 /**
0193   * @}
0194   */
0195 
0196 /**
0197   * @}
0198   */
0199 
0200 /* Private variables ---------------------------------------------------------*/
0201 /* Private constants ---------------------------------------------------------*/
0202 /* Private macro -------------------------------------------------------------*/
0203 /* Private function prototypes -----------------------------------------------*/
0204 /** @addtogroup DMA2D_Private_Functions DMA2D Private Functions
0205   * @{
0206   */
0207 static void DMA2D_SetConfig(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width,
0208                             uint32_t Height);
0209 /**
0210   * @}
0211   */
0212 
0213 /* Private functions ---------------------------------------------------------*/
0214 /* Exported functions --------------------------------------------------------*/
0215 /** @defgroup DMA2D_Exported_Functions DMA2D Exported Functions
0216   * @ingroup RTEMSBSPsARMSTM32H7
0217   * @{
0218   */
0219 
0220 /** @defgroup DMA2D_Exported_Functions_Group1 Initialization and de-initialization functions
0221   * @ingroup RTEMSBSPsARMSTM32H7
0222   *  @brief   Initialization and Configuration functions
0223   *
0224 @verbatim
0225  ===============================================================================
0226                 ##### Initialization and Configuration functions #####
0227  ===============================================================================
0228     [..]  This section provides functions allowing to:
0229       (+) Initialize and configure the DMA2D
0230       (+) De-initialize the DMA2D
0231 
0232 @endverbatim
0233   * @{
0234   */
0235 
0236 /**
0237   * @brief  Initialize the DMA2D according to the specified
0238   *         parameters in the DMA2D_InitTypeDef and create the associated handle.
0239   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
0240   *                 the configuration information for the DMA2D.
0241   * @retval HAL status
0242   */
0243 HAL_StatusTypeDef HAL_DMA2D_Init(DMA2D_HandleTypeDef *hdma2d)
0244 {
0245   /* Check the DMA2D peripheral state */
0246   if (hdma2d == NULL)
0247   {
0248     return HAL_ERROR;
0249   }
0250 
0251   /* Check the parameters */
0252   assert_param(IS_DMA2D_ALL_INSTANCE(hdma2d->Instance));
0253   assert_param(IS_DMA2D_MODE(hdma2d->Init.Mode));
0254   assert_param(IS_DMA2D_CMODE(hdma2d->Init.ColorMode));
0255   assert_param(IS_DMA2D_OFFSET(hdma2d->Init.OutputOffset));
0256   assert_param(IS_DMA2D_ALPHA_INVERTED(hdma2d->Init.AlphaInverted));
0257   assert_param(IS_DMA2D_RB_SWAP(hdma2d->Init.RedBlueSwap));
0258   assert_param(IS_DMA2D_LOM_MODE(hdma2d->Init.LineOffsetMode));
0259   assert_param(IS_DMA2D_BYTES_SWAP(hdma2d->Init.BytesSwap));
0260 
0261 #if (USE_HAL_DMA2D_REGISTER_CALLBACKS == 1)
0262   if (hdma2d->State == HAL_DMA2D_STATE_RESET)
0263   {
0264     /* Reset Callback pointers in HAL_DMA2D_STATE_RESET only */
0265     hdma2d->LineEventCallback       = HAL_DMA2D_LineEventCallback;
0266     hdma2d->CLUTLoadingCpltCallback = HAL_DMA2D_CLUTLoadingCpltCallback;
0267     if (hdma2d->MspInitCallback == NULL)
0268     {
0269       hdma2d->MspInitCallback = HAL_DMA2D_MspInit;
0270     }
0271 
0272     /* Init the low level hardware */
0273     hdma2d->MspInitCallback(hdma2d);
0274   }
0275 #else
0276   if (hdma2d->State == HAL_DMA2D_STATE_RESET)
0277   {
0278     /* Allocate lock resource and initialize it */
0279     hdma2d->Lock = HAL_UNLOCKED;
0280     /* Init the low level hardware */
0281     HAL_DMA2D_MspInit(hdma2d);
0282   }
0283 #endif /* (USE_HAL_DMA2D_REGISTER_CALLBACKS) */
0284 
0285   /* Change DMA2D peripheral state */
0286   hdma2d->State = HAL_DMA2D_STATE_BUSY;
0287 
0288   /* DMA2D CR register configuration -------------------------------------------*/
0289   MODIFY_REG(hdma2d->Instance->CR, DMA2D_CR_MODE | DMA2D_CR_LOM, hdma2d->Init.Mode | hdma2d->Init.LineOffsetMode);
0290 
0291   /* DMA2D OPFCCR register configuration ---------------------------------------*/
0292   MODIFY_REG(hdma2d->Instance->OPFCCR, DMA2D_OPFCCR_CM | DMA2D_OPFCCR_SB,
0293              hdma2d->Init.ColorMode | hdma2d->Init.BytesSwap);
0294 
0295   /* DMA2D OOR register configuration ------------------------------------------*/
0296   MODIFY_REG(hdma2d->Instance->OOR, DMA2D_OOR_LO, hdma2d->Init.OutputOffset);
0297   /* DMA2D OPFCCR AI and RBS fields setting (Output Alpha Inversion)*/
0298   MODIFY_REG(hdma2d->Instance->OPFCCR, (DMA2D_OPFCCR_AI | DMA2D_OPFCCR_RBS),
0299              ((hdma2d->Init.AlphaInverted << DMA2D_OPFCCR_AI_Pos) | \
0300               (hdma2d->Init.RedBlueSwap << DMA2D_OPFCCR_RBS_Pos)));
0301 
0302 
0303   /* Update error code */
0304   hdma2d->ErrorCode = HAL_DMA2D_ERROR_NONE;
0305 
0306   /* Initialize the DMA2D state*/
0307   hdma2d->State  = HAL_DMA2D_STATE_READY;
0308 
0309   return HAL_OK;
0310 }
0311 
0312 /**
0313   * @brief  Deinitializes the DMA2D peripheral registers to their default reset
0314   *         values.
0315   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
0316   *                 the configuration information for the DMA2D.
0317   * @retval None
0318   */
0319 
0320 HAL_StatusTypeDef HAL_DMA2D_DeInit(DMA2D_HandleTypeDef *hdma2d)
0321 {
0322 
0323   /* Check the DMA2D peripheral state */
0324   if (hdma2d == NULL)
0325   {
0326     return HAL_ERROR;
0327   }
0328 
0329   /* Before aborting any DMA2D transfer or CLUT loading, check
0330      first whether or not DMA2D clock is enabled */
0331   if (__HAL_RCC_DMA2D_IS_CLK_ENABLED())
0332   {
0333     /* Abort DMA2D transfer if any */
0334     if ((hdma2d->Instance->CR & DMA2D_CR_START) == DMA2D_CR_START)
0335     {
0336       if (HAL_DMA2D_Abort(hdma2d) != HAL_OK)
0337       {
0338         /* Issue when aborting DMA2D transfer */
0339         return HAL_ERROR;
0340       }
0341     }
0342     else
0343     {
0344       /* Abort background CLUT loading if any */
0345       if ((hdma2d->Instance->BGPFCCR & DMA2D_BGPFCCR_START) == DMA2D_BGPFCCR_START)
0346       {
0347         if (HAL_DMA2D_CLUTLoading_Abort(hdma2d, 0U) != HAL_OK)
0348         {
0349           /* Issue when aborting background CLUT loading */
0350           return HAL_ERROR;
0351         }
0352       }
0353       else
0354       {
0355         /* Abort foreground CLUT loading if any */
0356         if ((hdma2d->Instance->FGPFCCR & DMA2D_FGPFCCR_START) == DMA2D_FGPFCCR_START)
0357         {
0358           if (HAL_DMA2D_CLUTLoading_Abort(hdma2d, 1U) != HAL_OK)
0359           {
0360             /* Issue when aborting foreground CLUT loading */
0361             return HAL_ERROR;
0362           }
0363         }
0364       }
0365     }
0366   }
0367 
0368   /* Reset DMA2D control registers*/
0369   hdma2d->Instance->CR       =    0U;
0370   hdma2d->Instance->IFCR     = 0x3FU;
0371   hdma2d->Instance->FGOR     =    0U;
0372   hdma2d->Instance->BGOR     =    0U;
0373   hdma2d->Instance->FGPFCCR  =    0U;
0374   hdma2d->Instance->BGPFCCR  =    0U;
0375   hdma2d->Instance->OPFCCR   =    0U;
0376 
0377 #if (USE_HAL_DMA2D_REGISTER_CALLBACKS == 1)
0378 
0379   if (hdma2d->MspDeInitCallback == NULL)
0380   {
0381     hdma2d->MspDeInitCallback = HAL_DMA2D_MspDeInit;
0382   }
0383 
0384   /* DeInit the low level hardware */
0385   hdma2d->MspDeInitCallback(hdma2d);
0386 
0387 #else
0388   /* Carry on with de-initialization of low level hardware */
0389   HAL_DMA2D_MspDeInit(hdma2d);
0390 #endif /* (USE_HAL_DMA2D_REGISTER_CALLBACKS) */
0391 
0392   /* Update error code */
0393   hdma2d->ErrorCode = HAL_DMA2D_ERROR_NONE;
0394 
0395   /* Initialize the DMA2D state*/
0396   hdma2d->State  = HAL_DMA2D_STATE_RESET;
0397 
0398   /* Release Lock */
0399   __HAL_UNLOCK(hdma2d);
0400 
0401   return HAL_OK;
0402 }
0403 
0404 /**
0405   * @brief  Initializes the DMA2D MSP.
0406   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
0407   *                 the configuration information for the DMA2D.
0408   * @retval None
0409   */
0410 __weak void HAL_DMA2D_MspInit(DMA2D_HandleTypeDef *hdma2d)
0411 {
0412   /* Prevent unused argument(s) compilation warning */
0413   UNUSED(hdma2d);
0414 
0415   /* NOTE : This function should not be modified; when the callback is needed,
0416             the HAL_DMA2D_MspInit can be implemented in the user file.
0417    */
0418 }
0419 
0420 /**
0421   * @brief  DeInitializes the DMA2D MSP.
0422   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
0423   *                 the configuration information for the DMA2D.
0424   * @retval None
0425   */
0426 __weak void HAL_DMA2D_MspDeInit(DMA2D_HandleTypeDef *hdma2d)
0427 {
0428   /* Prevent unused argument(s) compilation warning */
0429   UNUSED(hdma2d);
0430 
0431   /* NOTE : This function should not be modified; when the callback is needed,
0432             the HAL_DMA2D_MspDeInit can be implemented in the user file.
0433    */
0434 }
0435 
0436 #if (USE_HAL_DMA2D_REGISTER_CALLBACKS == 1)
0437 /**
0438   * @brief  Register a User DMA2D Callback
0439   *         To be used instead of the weak (overridden) predefined callback
0440   * @param hdma2d DMA2D handle
0441   * @param CallbackID ID of the callback to be registered
0442   *        This parameter can be one of the following values:
0443   *          @arg @ref HAL_DMA2D_TRANSFERCOMPLETE_CB_ID DMA2D transfer complete Callback ID
0444   *          @arg @ref HAL_DMA2D_TRANSFERERROR_CB_ID DMA2D transfer error Callback ID
0445   *          @arg @ref HAL_DMA2D_LINEEVENT_CB_ID DMA2D line event Callback ID
0446   *          @arg @ref HAL_DMA2D_CLUTLOADINGCPLT_CB_ID DMA2D CLUT loading completion Callback ID
0447   *          @arg @ref HAL_DMA2D_MSPINIT_CB_ID DMA2D MspInit callback ID
0448   *          @arg @ref HAL_DMA2D_MSPDEINIT_CB_ID DMA2D MspDeInit callback ID
0449   * @param pCallback pointer to the Callback function
0450   * @note No weak predefined callbacks are defined for HAL_DMA2D_TRANSFERCOMPLETE_CB_ID or HAL_DMA2D_TRANSFERERROR_CB_ID
0451   * @retval status
0452   */
0453 HAL_StatusTypeDef HAL_DMA2D_RegisterCallback(DMA2D_HandleTypeDef *hdma2d, HAL_DMA2D_CallbackIDTypeDef CallbackID,
0454                                              pDMA2D_CallbackTypeDef pCallback)
0455 {
0456   HAL_StatusTypeDef status = HAL_OK;
0457 
0458   if (pCallback == NULL)
0459   {
0460     /* Update the error code */
0461     hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
0462     return HAL_ERROR;
0463   }
0464   /* Process locked */
0465   __HAL_LOCK(hdma2d);
0466 
0467   if (HAL_DMA2D_STATE_READY == hdma2d->State)
0468   {
0469     switch (CallbackID)
0470     {
0471       case HAL_DMA2D_TRANSFERCOMPLETE_CB_ID :
0472         hdma2d->XferCpltCallback = pCallback;
0473         break;
0474 
0475       case HAL_DMA2D_TRANSFERERROR_CB_ID :
0476         hdma2d->XferErrorCallback = pCallback;
0477         break;
0478 
0479       case HAL_DMA2D_LINEEVENT_CB_ID :
0480         hdma2d->LineEventCallback = pCallback;
0481         break;
0482 
0483       case HAL_DMA2D_CLUTLOADINGCPLT_CB_ID :
0484         hdma2d->CLUTLoadingCpltCallback = pCallback;
0485         break;
0486 
0487       case HAL_DMA2D_MSPINIT_CB_ID :
0488         hdma2d->MspInitCallback = pCallback;
0489         break;
0490 
0491       case HAL_DMA2D_MSPDEINIT_CB_ID :
0492         hdma2d->MspDeInitCallback = pCallback;
0493         break;
0494 
0495       default :
0496         /* Update the error code */
0497         hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
0498         /* update return status */
0499         status =  HAL_ERROR;
0500         break;
0501     }
0502   }
0503   else if (HAL_DMA2D_STATE_RESET == hdma2d->State)
0504   {
0505     switch (CallbackID)
0506     {
0507       case HAL_DMA2D_MSPINIT_CB_ID :
0508         hdma2d->MspInitCallback = pCallback;
0509         break;
0510 
0511       case HAL_DMA2D_MSPDEINIT_CB_ID :
0512         hdma2d->MspDeInitCallback = pCallback;
0513         break;
0514 
0515       default :
0516         /* Update the error code */
0517         hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
0518         /* update return status */
0519         status =  HAL_ERROR;
0520         break;
0521     }
0522   }
0523   else
0524   {
0525     /* Update the error code */
0526     hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
0527     /* update return status */
0528     status =  HAL_ERROR;
0529   }
0530 
0531   /* Release Lock */
0532   __HAL_UNLOCK(hdma2d);
0533   return status;
0534 }
0535 
0536 /**
0537   * @brief  Unregister a DMA2D Callback
0538   *         DMA2D Callback is redirected to the weak (overridden) predefined callback
0539   * @param hdma2d DMA2D handle
0540   * @param CallbackID ID of the callback to be unregistered
0541   *        This parameter can be one of the following values:
0542   *          @arg @ref HAL_DMA2D_TRANSFERCOMPLETE_CB_ID DMA2D transfer complete Callback ID
0543   *          @arg @ref HAL_DMA2D_TRANSFERERROR_CB_ID DMA2D transfer error Callback ID
0544   *          @arg @ref HAL_DMA2D_LINEEVENT_CB_ID DMA2D line event Callback ID
0545   *          @arg @ref HAL_DMA2D_CLUTLOADINGCPLT_CB_ID DMA2D CLUT loading completion Callback ID
0546   *          @arg @ref HAL_DMA2D_MSPINIT_CB_ID DMA2D MspInit callback ID
0547   *          @arg @ref HAL_DMA2D_MSPDEINIT_CB_ID DMA2D MspDeInit callback ID
0548   * @note No weak predefined callbacks are defined for HAL_DMA2D_TRANSFERCOMPLETE_CB_ID or HAL_DMA2D_TRANSFERERROR_CB_ID
0549   * @retval status
0550   */
0551 HAL_StatusTypeDef HAL_DMA2D_UnRegisterCallback(DMA2D_HandleTypeDef *hdma2d, HAL_DMA2D_CallbackIDTypeDef CallbackID)
0552 {
0553   HAL_StatusTypeDef status = HAL_OK;
0554 
0555   /* Process locked */
0556   __HAL_LOCK(hdma2d);
0557 
0558   if (HAL_DMA2D_STATE_READY == hdma2d->State)
0559   {
0560     switch (CallbackID)
0561     {
0562       case HAL_DMA2D_TRANSFERCOMPLETE_CB_ID :
0563         hdma2d->XferCpltCallback = NULL;
0564         break;
0565 
0566       case HAL_DMA2D_TRANSFERERROR_CB_ID :
0567         hdma2d->XferErrorCallback = NULL;
0568         break;
0569 
0570       case HAL_DMA2D_LINEEVENT_CB_ID :
0571         hdma2d->LineEventCallback = HAL_DMA2D_LineEventCallback;
0572         break;
0573 
0574       case HAL_DMA2D_CLUTLOADINGCPLT_CB_ID :
0575         hdma2d->CLUTLoadingCpltCallback = HAL_DMA2D_CLUTLoadingCpltCallback;
0576         break;
0577 
0578       case HAL_DMA2D_MSPINIT_CB_ID :
0579         hdma2d->MspInitCallback = HAL_DMA2D_MspInit; /* Legacy weak (overridden) Msp Init */
0580         break;
0581 
0582       case HAL_DMA2D_MSPDEINIT_CB_ID :
0583         hdma2d->MspDeInitCallback = HAL_DMA2D_MspDeInit; /* Legacy weak (overridden) Msp DeInit */
0584         break;
0585 
0586       default :
0587         /* Update the error code */
0588         hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
0589         /* update return status */
0590         status =  HAL_ERROR;
0591         break;
0592     }
0593   }
0594   else if (HAL_DMA2D_STATE_RESET == hdma2d->State)
0595   {
0596     switch (CallbackID)
0597     {
0598       case HAL_DMA2D_MSPINIT_CB_ID :
0599         hdma2d->MspInitCallback = HAL_DMA2D_MspInit;   /* Legacy weak (overridden) Msp Init */
0600         break;
0601 
0602       case HAL_DMA2D_MSPDEINIT_CB_ID :
0603         hdma2d->MspDeInitCallback = HAL_DMA2D_MspDeInit;  /* Legacy weak (overridden) Msp DeInit */
0604         break;
0605 
0606       default :
0607         /* Update the error code */
0608         hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
0609         /* update return status */
0610         status =  HAL_ERROR;
0611         break;
0612     }
0613   }
0614   else
0615   {
0616     /* Update the error code */
0617     hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
0618     /* update return status */
0619     status =  HAL_ERROR;
0620   }
0621 
0622   /* Release Lock */
0623   __HAL_UNLOCK(hdma2d);
0624   return status;
0625 }
0626 #endif /* USE_HAL_DMA2D_REGISTER_CALLBACKS */
0627 
0628 /**
0629   * @}
0630   */
0631 
0632 
0633 /** @defgroup DMA2D_Exported_Functions_Group2 IO operation functions
0634   * @ingroup RTEMSBSPsARMSTM32H7
0635   *  @brief   IO operation functions
0636   *
0637 @verbatim
0638  ===============================================================================
0639                       #####  IO operation functions  #####
0640  ===============================================================================
0641     [..]  This section provides functions allowing to:
0642       (+) Configure the pdata, destination address and data size then
0643           start the DMA2D transfer.
0644       (+) Configure the source for foreground and background, destination address
0645           and data size then start a MultiBuffer DMA2D transfer.
0646       (+) Configure the pdata, destination address and data size then
0647           start the DMA2D transfer with interrupt.
0648       (+) Configure the source for foreground and background, destination address
0649           and data size then start a MultiBuffer DMA2D transfer with interrupt.
0650       (+) Abort DMA2D transfer.
0651       (+) Suspend DMA2D transfer.
0652       (+) Resume DMA2D transfer.
0653       (+) Enable CLUT transfer.
0654       (+) Configure CLUT loading then start transfer in polling mode.
0655       (+) Configure CLUT loading then start transfer in interrupt mode.
0656       (+) Abort DMA2D CLUT loading.
0657       (+) Suspend DMA2D CLUT loading.
0658       (+) Resume DMA2D CLUT loading.
0659       (+) Poll for transfer complete.
0660       (+) handle DMA2D interrupt request.
0661       (+) Transfer watermark callback.
0662       (+) CLUT Transfer Complete callback.
0663 
0664 
0665 @endverbatim
0666   * @{
0667   */
0668 
0669 /**
0670   * @brief  Start the DMA2D Transfer.
0671   * @param  hdma2d     Pointer to a DMA2D_HandleTypeDef structure that contains
0672   *                     the configuration information for the DMA2D.
0673   * @param  pdata      Configure the source memory Buffer address if
0674   *                     Memory-to-Memory or Memory-to-Memory with pixel format
0675   *                     conversion mode is selected, or configure
0676   *                     the color value if Register-to-Memory mode is selected.
0677   * @param  DstAddress The destination memory Buffer address.
0678   * @param  Width      The width of data to be transferred from source
0679   *                    to destination (expressed in number of pixels per line).
0680   * @param  Height     The height of data to be transferred from source to destination (expressed in number of lines).
0681   * @retval HAL status
0682   */
0683 HAL_StatusTypeDef HAL_DMA2D_Start(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width,
0684                                   uint32_t Height)
0685 {
0686   /* Check the parameters */
0687   assert_param(IS_DMA2D_LINE(Height));
0688   assert_param(IS_DMA2D_PIXEL(Width));
0689 
0690   /* Process locked */
0691   __HAL_LOCK(hdma2d);
0692 
0693   /* Change DMA2D peripheral state */
0694   hdma2d->State = HAL_DMA2D_STATE_BUSY;
0695 
0696   /* Configure the source, destination address and the data size */
0697   DMA2D_SetConfig(hdma2d, pdata, DstAddress, Width, Height);
0698 
0699   /* Enable the Peripheral */
0700   __HAL_DMA2D_ENABLE(hdma2d);
0701 
0702   return HAL_OK;
0703 }
0704 
0705 /**
0706   * @brief  Start the DMA2D Transfer with interrupt enabled.
0707   * @param  hdma2d     Pointer to a DMA2D_HandleTypeDef structure that contains
0708   *                     the configuration information for the DMA2D.
0709   * @param  pdata      Configure the source memory Buffer address if
0710   *                     the Memory-to-Memory or Memory-to-Memory with pixel format
0711   *                     conversion mode is selected, or configure
0712   *                     the color value if Register-to-Memory mode is selected.
0713   * @param  DstAddress The destination memory Buffer address.
0714   * @param  Width      The width of data to be transferred from source
0715   *                    to destination (expressed in number of pixels per line).
0716   * @param  Height     The height of data to be transferred from source to destination (expressed in number of lines).
0717   * @retval HAL status
0718   */
0719 HAL_StatusTypeDef HAL_DMA2D_Start_IT(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width,
0720                                      uint32_t Height)
0721 {
0722   /* Check the parameters */
0723   assert_param(IS_DMA2D_LINE(Height));
0724   assert_param(IS_DMA2D_PIXEL(Width));
0725 
0726   /* Process locked */
0727   __HAL_LOCK(hdma2d);
0728 
0729   /* Change DMA2D peripheral state */
0730   hdma2d->State = HAL_DMA2D_STATE_BUSY;
0731 
0732   /* Configure the source, destination address and the data size */
0733   DMA2D_SetConfig(hdma2d, pdata, DstAddress, Width, Height);
0734 
0735   /* Enable the transfer complete, transfer error and configuration error interrupts */
0736   __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_TC | DMA2D_IT_TE | DMA2D_IT_CE);
0737 
0738   /* Enable the Peripheral */
0739   __HAL_DMA2D_ENABLE(hdma2d);
0740 
0741   return HAL_OK;
0742 }
0743 
0744 /**
0745   * @brief  Start the multi-source DMA2D Transfer.
0746   * @param  hdma2d      Pointer to a DMA2D_HandleTypeDef structure that contains
0747   *                      the configuration information for the DMA2D.
0748   * @param  SrcAddress1 The source memory Buffer address for the foreground layer.
0749   * @param  SrcAddress2 The source memory Buffer address for the background layer.
0750   * @param  DstAddress  The destination memory Buffer address.
0751   * @param  Width       The width of data to be transferred from source
0752   *                     to destination (expressed in number of pixels per line).
0753   * @param  Height      The height of data to be transferred from source to destination (expressed in number of lines).
0754   * @retval HAL status
0755   */
0756 HAL_StatusTypeDef HAL_DMA2D_BlendingStart(DMA2D_HandleTypeDef *hdma2d, uint32_t SrcAddress1, uint32_t  SrcAddress2,
0757                                           uint32_t DstAddress, uint32_t Width,  uint32_t Height)
0758 {
0759   /* Check the parameters */
0760   assert_param(IS_DMA2D_LINE(Height));
0761   assert_param(IS_DMA2D_PIXEL(Width));
0762 
0763   /* Process locked */
0764   __HAL_LOCK(hdma2d);
0765 
0766   /* Change DMA2D peripheral state */
0767   hdma2d->State = HAL_DMA2D_STATE_BUSY;
0768 
0769   if (hdma2d->Init.Mode == DMA2D_M2M_BLEND_FG)
0770   {
0771     /*blending & fixed FG*/
0772     WRITE_REG(hdma2d->Instance->FGCOLR, SrcAddress1);
0773     /* Configure the source, destination address and the data size */
0774     DMA2D_SetConfig(hdma2d, SrcAddress2, DstAddress, Width, Height);
0775   }
0776   else if (hdma2d->Init.Mode == DMA2D_M2M_BLEND_BG)
0777   {
0778     /*blending & fixed BG*/
0779     WRITE_REG(hdma2d->Instance->BGCOLR, SrcAddress2);
0780     /* Configure the source, destination address and the data size */
0781     DMA2D_SetConfig(hdma2d, SrcAddress1, DstAddress, Width, Height);
0782   }
0783   else
0784   {
0785     /* Configure DMA2D Stream source2 address */
0786     WRITE_REG(hdma2d->Instance->BGMAR, SrcAddress2);
0787 
0788     /* Configure the source, destination address and the data size */
0789     DMA2D_SetConfig(hdma2d, SrcAddress1, DstAddress, Width, Height);
0790   }
0791 
0792   /* Enable the Peripheral */
0793   __HAL_DMA2D_ENABLE(hdma2d);
0794 
0795   return HAL_OK;
0796 }
0797 
0798 /**
0799   * @brief  Start the multi-source DMA2D Transfer with interrupt enabled.
0800   * @param  hdma2d     Pointer to a DMA2D_HandleTypeDef structure that contains
0801   *                     the configuration information for the DMA2D.
0802   * @param  SrcAddress1 The source memory Buffer address for the foreground layer.
0803   * @param  SrcAddress2 The source memory Buffer address for the background layer.
0804   * @param  DstAddress  The destination memory Buffer address.
0805   * @param  Width       The width of data to be transferred from source
0806   *                     to destination (expressed in number of pixels per line).
0807   * @param  Height      The height of data to be transferred from source to destination (expressed in number of lines).
0808   * @retval HAL status
0809   */
0810 HAL_StatusTypeDef HAL_DMA2D_BlendingStart_IT(DMA2D_HandleTypeDef *hdma2d, uint32_t SrcAddress1, uint32_t  SrcAddress2,
0811                                              uint32_t DstAddress, uint32_t Width,  uint32_t Height)
0812 {
0813   /* Check the parameters */
0814   assert_param(IS_DMA2D_LINE(Height));
0815   assert_param(IS_DMA2D_PIXEL(Width));
0816 
0817   /* Process locked */
0818   __HAL_LOCK(hdma2d);
0819 
0820   /* Change DMA2D peripheral state */
0821   hdma2d->State = HAL_DMA2D_STATE_BUSY;
0822 
0823   if (hdma2d->Init.Mode == DMA2D_M2M_BLEND_FG)
0824   {
0825     /*blending & fixed FG*/
0826     WRITE_REG(hdma2d->Instance->FGCOLR, SrcAddress1);
0827     /* Configure the source, destination address and the data size */
0828     DMA2D_SetConfig(hdma2d, SrcAddress2, DstAddress, Width, Height);
0829   }
0830   else if (hdma2d->Init.Mode == DMA2D_M2M_BLEND_BG)
0831   {
0832     /*blending & fixed BG*/
0833     WRITE_REG(hdma2d->Instance->BGCOLR, SrcAddress2);
0834     /* Configure the source, destination address and the data size */
0835     DMA2D_SetConfig(hdma2d, SrcAddress1, DstAddress, Width, Height);
0836   }
0837   else
0838   {
0839     WRITE_REG(hdma2d->Instance->BGMAR, SrcAddress2);
0840 
0841     /* Configure the source, destination address and the data size */
0842     DMA2D_SetConfig(hdma2d, SrcAddress1, DstAddress, Width, Height);
0843   }
0844 
0845   /* Enable the transfer complete, transfer error and configuration error interrupts */
0846   __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_TC | DMA2D_IT_TE | DMA2D_IT_CE);
0847 
0848   /* Enable the Peripheral */
0849   __HAL_DMA2D_ENABLE(hdma2d);
0850 
0851   return HAL_OK;
0852 }
0853 
0854 /**
0855   * @brief  Abort the DMA2D Transfer.
0856   * @param  hdma2d  pointer to a DMA2D_HandleTypeDef structure that contains
0857   *                  the configuration information for the DMA2D.
0858   * @retval HAL status
0859   */
0860 HAL_StatusTypeDef HAL_DMA2D_Abort(DMA2D_HandleTypeDef *hdma2d)
0861 {
0862   uint32_t tickstart;
0863 
0864   /* Abort the DMA2D transfer */
0865   /* START bit is reset to make sure not to set it again, in the event the HW clears it
0866      between the register read and the register write by the CPU (writing 0 has no
0867      effect on START bitvalue) */
0868   MODIFY_REG(hdma2d->Instance->CR, DMA2D_CR_ABORT | DMA2D_CR_START, DMA2D_CR_ABORT);
0869 
0870   /* Get tick */
0871   tickstart = HAL_GetTick();
0872 
0873   /* Check if the DMA2D is effectively disabled */
0874   while ((hdma2d->Instance->CR & DMA2D_CR_START) != 0U)
0875   {
0876     if ((HAL_GetTick() - tickstart) > DMA2D_TIMEOUT_ABORT)
0877     {
0878       /* Update error code */
0879       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
0880 
0881       /* Change the DMA2D state */
0882       hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
0883 
0884       /* Process Unlocked */
0885       __HAL_UNLOCK(hdma2d);
0886 
0887       return HAL_TIMEOUT;
0888     }
0889   }
0890 
0891   /* Disable the Transfer Complete, Transfer Error and Configuration Error interrupts */
0892   __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TC | DMA2D_IT_TE | DMA2D_IT_CE);
0893 
0894   /* Change the DMA2D state*/
0895   hdma2d->State = HAL_DMA2D_STATE_READY;
0896 
0897   /* Process Unlocked */
0898   __HAL_UNLOCK(hdma2d);
0899 
0900   return HAL_OK;
0901 }
0902 
0903 /**
0904   * @brief  Suspend the DMA2D Transfer.
0905   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
0906   *                 the configuration information for the DMA2D.
0907   * @retval HAL status
0908   */
0909 HAL_StatusTypeDef HAL_DMA2D_Suspend(DMA2D_HandleTypeDef *hdma2d)
0910 {
0911   uint32_t tickstart;
0912 
0913   /* Suspend the DMA2D transfer */
0914   /* START bit is reset to make sure not to set it again, in the event the HW clears it
0915      between the register read and the register write by the CPU (writing 0 has no
0916      effect on START bitvalue). */
0917   MODIFY_REG(hdma2d->Instance->CR, DMA2D_CR_SUSP | DMA2D_CR_START, DMA2D_CR_SUSP);
0918 
0919   /* Get tick */
0920   tickstart = HAL_GetTick();
0921 
0922   /* Check if the DMA2D is effectively suspended */
0923   while ((hdma2d->Instance->CR & (DMA2D_CR_SUSP | DMA2D_CR_START)) == DMA2D_CR_START)
0924   {
0925     if ((HAL_GetTick() - tickstart) > DMA2D_TIMEOUT_SUSPEND)
0926     {
0927       /* Update error code */
0928       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
0929 
0930       /* Change the DMA2D state */
0931       hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
0932 
0933       return HAL_TIMEOUT;
0934     }
0935   }
0936 
0937   /* Check whether or not a transfer is actually suspended and change the DMA2D state accordingly */
0938   if ((hdma2d->Instance->CR & DMA2D_CR_START) != 0U)
0939   {
0940     hdma2d->State = HAL_DMA2D_STATE_SUSPEND;
0941   }
0942   else
0943   {
0944     /* Make sure SUSP bit is cleared since it is meaningless
0945        when no transfer is on-going */
0946     CLEAR_BIT(hdma2d->Instance->CR, DMA2D_CR_SUSP);
0947   }
0948 
0949   return HAL_OK;
0950 }
0951 
0952 /**
0953   * @brief  Resume the DMA2D Transfer.
0954   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
0955   *                 the configuration information for the DMA2D.
0956   * @retval HAL status
0957   */
0958 HAL_StatusTypeDef HAL_DMA2D_Resume(DMA2D_HandleTypeDef *hdma2d)
0959 {
0960   /* Check the SUSP and START bits */
0961   if ((hdma2d->Instance->CR & (DMA2D_CR_SUSP | DMA2D_CR_START)) == (DMA2D_CR_SUSP | DMA2D_CR_START))
0962   {
0963     /* Ongoing transfer is suspended: change the DMA2D state before resuming */
0964     hdma2d->State = HAL_DMA2D_STATE_BUSY;
0965   }
0966 
0967   /* Resume the DMA2D transfer */
0968   /* START bit is reset to make sure not to set it again, in the event the HW clears it
0969      between the register read and the register write by the CPU (writing 0 has no
0970      effect on START bitvalue). */
0971   CLEAR_BIT(hdma2d->Instance->CR, (DMA2D_CR_SUSP | DMA2D_CR_START));
0972 
0973   return HAL_OK;
0974 }
0975 
0976 
0977 /**
0978   * @brief  Enable the DMA2D CLUT Transfer.
0979   * @param  hdma2d   Pointer to a DMA2D_HandleTypeDef structure that contains
0980   *                   the configuration information for the DMA2D.
0981   * @param  LayerIdx DMA2D Layer index.
0982   *                   This parameter can be one of the following values:
0983   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
0984   * @retval HAL status
0985   */
0986 HAL_StatusTypeDef HAL_DMA2D_EnableCLUT(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
0987 {
0988   /* Check the parameters */
0989   assert_param(IS_DMA2D_LAYER(LayerIdx));
0990 
0991   /* Process locked */
0992   __HAL_LOCK(hdma2d);
0993 
0994   /* Change DMA2D peripheral state */
0995   hdma2d->State = HAL_DMA2D_STATE_BUSY;
0996 
0997   if (LayerIdx == DMA2D_BACKGROUND_LAYER)
0998   {
0999     /* Enable the background CLUT loading */
1000     SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
1001   }
1002   else
1003   {
1004     /* Enable the foreground CLUT loading */
1005     SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
1006   }
1007 
1008   return HAL_OK;
1009 }
1010 
1011 /**
1012   * @brief  Start DMA2D CLUT Loading.
1013   * @param  hdma2d   Pointer to a DMA2D_HandleTypeDef structure that contains
1014   *                   the configuration information for the DMA2D.
1015   * @param  CLUTCfg  Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
1016   *                   the configuration information for the color look up table.
1017   * @param  LayerIdx DMA2D Layer index.
1018   *                   This parameter can be one of the following values:
1019   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
1020   * @retval HAL status
1021   */
1022 HAL_StatusTypeDef HAL_DMA2D_CLUTStartLoad(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef *CLUTCfg, uint32_t LayerIdx)
1023 {
1024   /* Check the parameters */
1025   assert_param(IS_DMA2D_LAYER(LayerIdx));
1026   assert_param(IS_DMA2D_CLUT_CM(CLUTCfg->CLUTColorMode));
1027   assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg->Size));
1028 
1029   /* Process locked */
1030   __HAL_LOCK(hdma2d);
1031 
1032   /* Change DMA2D peripheral state */
1033   hdma2d->State = HAL_DMA2D_STATE_BUSY;
1034 
1035   /* Configure the CLUT of the background DMA2D layer */
1036   if (LayerIdx == DMA2D_BACKGROUND_LAYER)
1037   {
1038     /* Write background CLUT memory address */
1039     WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg->pCLUT);
1040 
1041     /* Write background CLUT size and CLUT color mode */
1042     MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
1043                ((CLUTCfg->Size << DMA2D_BGPFCCR_CS_Pos) | (CLUTCfg->CLUTColorMode << DMA2D_BGPFCCR_CCM_Pos)));
1044 
1045     /* Enable the CLUT loading for the background */
1046     SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
1047   }
1048   /* Configure the CLUT of the foreground DMA2D layer */
1049   else
1050   {
1051     /* Write foreground CLUT memory address */
1052     WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg->pCLUT);
1053 
1054     /* Write foreground CLUT size and CLUT color mode */
1055     MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
1056                ((CLUTCfg->Size << DMA2D_FGPFCCR_CS_Pos) | (CLUTCfg->CLUTColorMode << DMA2D_FGPFCCR_CCM_Pos)));
1057 
1058     /* Enable the CLUT loading for the foreground */
1059     SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
1060   }
1061 
1062   return HAL_OK;
1063 }
1064 
1065 /**
1066   * @brief  Start DMA2D CLUT Loading with interrupt enabled.
1067   * @param  hdma2d   Pointer to a DMA2D_HandleTypeDef structure that contains
1068   *                   the configuration information for the DMA2D.
1069   * @param  CLUTCfg  Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
1070   *                   the configuration information for the color look up table.
1071   * @param  LayerIdx DMA2D Layer index.
1072   *                   This parameter can be one of the following values:
1073   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
1074   * @retval HAL status
1075   */
1076 HAL_StatusTypeDef HAL_DMA2D_CLUTStartLoad_IT(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef *CLUTCfg,
1077                                              uint32_t LayerIdx)
1078 {
1079   /* Check the parameters */
1080   assert_param(IS_DMA2D_LAYER(LayerIdx));
1081   assert_param(IS_DMA2D_CLUT_CM(CLUTCfg->CLUTColorMode));
1082   assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg->Size));
1083 
1084   /* Process locked */
1085   __HAL_LOCK(hdma2d);
1086 
1087   /* Change DMA2D peripheral state */
1088   hdma2d->State = HAL_DMA2D_STATE_BUSY;
1089 
1090   /* Configure the CLUT of the background DMA2D layer */
1091   if (LayerIdx == DMA2D_BACKGROUND_LAYER)
1092   {
1093     /* Write background CLUT memory address */
1094     WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg->pCLUT);
1095 
1096     /* Write background CLUT size and CLUT color mode */
1097     MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
1098                ((CLUTCfg->Size << DMA2D_BGPFCCR_CS_Pos) | (CLUTCfg->CLUTColorMode << DMA2D_BGPFCCR_CCM_Pos)));
1099 
1100     /* Enable the CLUT Transfer Complete, transfer Error, configuration Error and CLUT Access Error interrupts */
1101     __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE | DMA2D_IT_CAE);
1102 
1103     /* Enable the CLUT loading for the background */
1104     SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
1105   }
1106   /* Configure the CLUT of the foreground DMA2D layer */
1107   else
1108   {
1109     /* Write foreground CLUT memory address */
1110     WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg->pCLUT);
1111 
1112     /* Write foreground CLUT size and CLUT color mode */
1113     MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
1114                ((CLUTCfg->Size << DMA2D_FGPFCCR_CS_Pos) | (CLUTCfg->CLUTColorMode << DMA2D_FGPFCCR_CCM_Pos)));
1115 
1116     /* Enable the CLUT Transfer Complete, transfer Error, configuration Error and CLUT Access Error interrupts */
1117     __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE | DMA2D_IT_CAE);
1118 
1119     /* Enable the CLUT loading for the foreground */
1120     SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
1121   }
1122 
1123   return HAL_OK;
1124 }
1125 
1126 /**
1127   * @brief  Start DMA2D CLUT Loading.
1128   * @param  hdma2d   Pointer to a DMA2D_HandleTypeDef structure that contains
1129   *                   the configuration information for the DMA2D.
1130   * @param  CLUTCfg  Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
1131   *                   the configuration information for the color look up table.
1132   * @param  LayerIdx DMA2D Layer index.
1133   *                   This parameter can be one of the following values:
1134   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
1135   * @note API obsolete and maintained for compatibility with legacy. User is
1136   *      invited to resort to HAL_DMA2D_CLUTStartLoad() instead to benefit from
1137   *      code compactness, code size and improved heap usage.
1138   * @retval HAL status
1139   */
1140 HAL_StatusTypeDef HAL_DMA2D_CLUTLoad(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef CLUTCfg, uint32_t LayerIdx)
1141 {
1142   /* Check the parameters */
1143   assert_param(IS_DMA2D_LAYER(LayerIdx));
1144   assert_param(IS_DMA2D_CLUT_CM(CLUTCfg.CLUTColorMode));
1145   assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg.Size));
1146 
1147   /* Process locked */
1148   __HAL_LOCK(hdma2d);
1149 
1150   /* Change DMA2D peripheral state */
1151   hdma2d->State = HAL_DMA2D_STATE_BUSY;
1152 
1153   /* Configure the CLUT of the background DMA2D layer */
1154   if (LayerIdx == DMA2D_BACKGROUND_LAYER)
1155   {
1156     /* Write background CLUT memory address */
1157     WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg.pCLUT);
1158 
1159     /* Write background CLUT size and CLUT color mode */
1160     MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
1161                ((CLUTCfg.Size << DMA2D_BGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_BGPFCCR_CCM_Pos)));
1162 
1163     /* Enable the CLUT loading for the background */
1164     SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
1165   }
1166   /* Configure the CLUT of the foreground DMA2D layer */
1167   else
1168   {
1169     /* Write foreground CLUT memory address */
1170     WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg.pCLUT);
1171 
1172     /* Write foreground CLUT size and CLUT color mode */
1173     MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
1174                ((CLUTCfg.Size << DMA2D_FGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_FGPFCCR_CCM_Pos)));
1175 
1176     /* Enable the CLUT loading for the foreground */
1177     SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
1178   }
1179 
1180   return HAL_OK;
1181 }
1182 
1183 /**
1184   * @brief  Start DMA2D CLUT Loading with interrupt enabled.
1185   * @param  hdma2d   Pointer to a DMA2D_HandleTypeDef structure that contains
1186   *                   the configuration information for the DMA2D.
1187   * @param  CLUTCfg  Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
1188   *                   the configuration information for the color look up table.
1189   * @param  LayerIdx DMA2D Layer index.
1190   *                   This parameter can be one of the following values:
1191   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
1192   * @note API obsolete and maintained for compatibility with legacy. User is
1193   *      invited to resort to HAL_DMA2D_CLUTStartLoad_IT() instead to benefit
1194   *      from code compactness, code size and improved heap usage.
1195   * @retval HAL status
1196   */
1197 HAL_StatusTypeDef HAL_DMA2D_CLUTLoad_IT(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef CLUTCfg, uint32_t LayerIdx)
1198 {
1199   /* Check the parameters */
1200   assert_param(IS_DMA2D_LAYER(LayerIdx));
1201   assert_param(IS_DMA2D_CLUT_CM(CLUTCfg.CLUTColorMode));
1202   assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg.Size));
1203 
1204   /* Process locked */
1205   __HAL_LOCK(hdma2d);
1206 
1207   /* Change DMA2D peripheral state */
1208   hdma2d->State = HAL_DMA2D_STATE_BUSY;
1209 
1210   /* Configure the CLUT of the background DMA2D layer */
1211   if (LayerIdx == DMA2D_BACKGROUND_LAYER)
1212   {
1213     /* Write background CLUT memory address */
1214     WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg.pCLUT);
1215 
1216     /* Write background CLUT size and CLUT color mode */
1217     MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
1218                ((CLUTCfg.Size << DMA2D_BGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_BGPFCCR_CCM_Pos)));
1219 
1220     /* Enable the CLUT Transfer Complete, transfer Error, configuration Error and CLUT Access Error interrupts */
1221     __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE | DMA2D_IT_CAE);
1222 
1223     /* Enable the CLUT loading for the background */
1224     SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
1225   }
1226   /* Configure the CLUT of the foreground DMA2D layer */
1227   else
1228   {
1229     /* Write foreground CLUT memory address */
1230     WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg.pCLUT);
1231 
1232     /* Write foreground CLUT size and CLUT color mode */
1233     MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
1234                ((CLUTCfg.Size << DMA2D_FGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_FGPFCCR_CCM_Pos)));
1235 
1236     /* Enable the CLUT Transfer Complete, transfer Error, configuration Error and CLUT Access Error interrupts */
1237     __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE | DMA2D_IT_CAE);
1238 
1239     /* Enable the CLUT loading for the foreground */
1240     SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
1241   }
1242 
1243   return HAL_OK;
1244 }
1245 
1246 /**
1247   * @brief  Abort the DMA2D CLUT loading.
1248   * @param  hdma2d  Pointer to a DMA2D_HandleTypeDef structure that contains
1249   *                  the configuration information for the DMA2D.
1250   * @param  LayerIdx DMA2D Layer index.
1251   *                   This parameter can be one of the following values:
1252   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
1253   * @retval HAL status
1254   */
1255 HAL_StatusTypeDef HAL_DMA2D_CLUTLoading_Abort(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
1256 {
1257   uint32_t tickstart;
1258   const __IO uint32_t *reg =  &(hdma2d->Instance->BGPFCCR);  /* by default, point at background register */
1259 
1260   /* Abort the CLUT loading */
1261   SET_BIT(hdma2d->Instance->CR, DMA2D_CR_ABORT);
1262 
1263   /* If foreground CLUT loading is considered, update local variables */
1264   if (LayerIdx == DMA2D_FOREGROUND_LAYER)
1265   {
1266     reg  = &(hdma2d->Instance->FGPFCCR);
1267   }
1268 
1269 
1270   /* Get tick */
1271   tickstart = HAL_GetTick();
1272 
1273   /* Check if the CLUT loading is aborted */
1274   while ((*reg & DMA2D_BGPFCCR_START) != 0U)
1275   {
1276     if ((HAL_GetTick() - tickstart) > DMA2D_TIMEOUT_ABORT)
1277     {
1278       /* Update error code */
1279       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
1280 
1281       /* Change the DMA2D state */
1282       hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
1283 
1284       /* Process Unlocked */
1285       __HAL_UNLOCK(hdma2d);
1286 
1287       return HAL_TIMEOUT;
1288     }
1289   }
1290 
1291   /* Disable the CLUT Transfer Complete, Transfer Error, Configuration Error and CLUT Access Error interrupts */
1292   __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE | DMA2D_IT_CAE);
1293 
1294   /* Change the DMA2D state*/
1295   hdma2d->State = HAL_DMA2D_STATE_READY;
1296 
1297   /* Process Unlocked */
1298   __HAL_UNLOCK(hdma2d);
1299 
1300   return HAL_OK;
1301 }
1302 
1303 /**
1304   * @brief  Suspend the DMA2D CLUT loading.
1305   * @param  hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
1306   *                 the configuration information for the DMA2D.
1307   * @param  LayerIdx DMA2D Layer index.
1308   *                   This parameter can be one of the following values:
1309   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
1310   * @retval HAL status
1311   */
1312 HAL_StatusTypeDef HAL_DMA2D_CLUTLoading_Suspend(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
1313 {
1314   uint32_t tickstart;
1315   uint32_t loadsuspended;
1316   const __IO uint32_t *reg =  &(hdma2d->Instance->BGPFCCR);  /* by default, point at background register */
1317 
1318   /* Suspend the CLUT loading */
1319   SET_BIT(hdma2d->Instance->CR, DMA2D_CR_SUSP);
1320 
1321   /* If foreground CLUT loading is considered, update local variables */
1322   if (LayerIdx == DMA2D_FOREGROUND_LAYER)
1323   {
1324     reg  = &(hdma2d->Instance->FGPFCCR);
1325   }
1326 
1327   /* Get tick */
1328   tickstart = HAL_GetTick();
1329 
1330   /* Check if the CLUT loading is suspended */
1331   /* 1st condition: Suspend Check */
1332   loadsuspended = ((hdma2d->Instance->CR & DMA2D_CR_SUSP) == DMA2D_CR_SUSP) ? 1UL : 0UL;
1333   /* 2nd condition: Not Start Check */
1334   loadsuspended |= ((*reg & DMA2D_BGPFCCR_START) != DMA2D_BGPFCCR_START) ? 1UL : 0UL;
1335   while (loadsuspended == 0UL)
1336   {
1337     if ((HAL_GetTick() - tickstart) > DMA2D_TIMEOUT_SUSPEND)
1338     {
1339       /* Update error code */
1340       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
1341 
1342       /* Change the DMA2D state */
1343       hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
1344 
1345       return HAL_TIMEOUT;
1346     }
1347     /* 1st condition: Suspend Check */
1348     loadsuspended = ((hdma2d->Instance->CR & DMA2D_CR_SUSP) == DMA2D_CR_SUSP) ? 1UL : 0UL;
1349     /* 2nd condition: Not Start Check */
1350     loadsuspended |= ((*reg & DMA2D_BGPFCCR_START) != DMA2D_BGPFCCR_START) ? 1UL : 0UL;
1351   }
1352 
1353   /* Check whether or not a transfer is actually suspended and change the DMA2D state accordingly */
1354   if ((*reg & DMA2D_BGPFCCR_START) != 0U)
1355   {
1356     hdma2d->State = HAL_DMA2D_STATE_SUSPEND;
1357   }
1358   else
1359   {
1360     /* Make sure SUSP bit is cleared since it is meaningless
1361        when no transfer is on-going */
1362     CLEAR_BIT(hdma2d->Instance->CR, DMA2D_CR_SUSP);
1363   }
1364 
1365   return HAL_OK;
1366 }
1367 
1368 /**
1369   * @brief  Resume the DMA2D CLUT loading.
1370   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
1371   *                 the configuration information for the DMA2D.
1372   * @param  LayerIdx DMA2D Layer index.
1373   *                   This parameter can be one of the following values:
1374   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
1375   * @retval HAL status
1376   */
1377 HAL_StatusTypeDef HAL_DMA2D_CLUTLoading_Resume(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
1378 {
1379   /* Check the SUSP and START bits for background or foreground CLUT loading */
1380   if (LayerIdx == DMA2D_BACKGROUND_LAYER)
1381   {
1382     /* Background CLUT loading suspension check */
1383     if ((hdma2d->Instance->CR & DMA2D_CR_SUSP) == DMA2D_CR_SUSP)
1384     {
1385       if ((hdma2d->Instance->BGPFCCR & DMA2D_BGPFCCR_START) == DMA2D_BGPFCCR_START)
1386       {
1387         /* Ongoing CLUT loading is suspended: change the DMA2D state before resuming */
1388         hdma2d->State = HAL_DMA2D_STATE_BUSY;
1389       }
1390     }
1391   }
1392   else
1393   {
1394     /* Foreground CLUT loading suspension check */
1395     if ((hdma2d->Instance->CR & DMA2D_CR_SUSP) == DMA2D_CR_SUSP)
1396     {
1397       if ((hdma2d->Instance->FGPFCCR & DMA2D_FGPFCCR_START) == DMA2D_FGPFCCR_START)
1398       {
1399         /* Ongoing CLUT loading is suspended: change the DMA2D state before resuming */
1400         hdma2d->State = HAL_DMA2D_STATE_BUSY;
1401       }
1402     }
1403   }
1404 
1405   /* Resume the CLUT loading */
1406   CLEAR_BIT(hdma2d->Instance->CR, DMA2D_CR_SUSP);
1407 
1408   return HAL_OK;
1409 }
1410 
1411 
1412 /**
1413 
1414   * @brief  Polling for transfer complete or CLUT loading.
1415   * @param  hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
1416   *                 the configuration information for the DMA2D.
1417   * @param  Timeout Timeout duration
1418   * @retval HAL status
1419   */
1420 HAL_StatusTypeDef HAL_DMA2D_PollForTransfer(DMA2D_HandleTypeDef *hdma2d, uint32_t Timeout)
1421 {
1422   uint32_t tickstart;
1423   uint32_t layer_start;
1424   __IO uint32_t isrflags = 0x0U;
1425 
1426   /* Polling for DMA2D transfer */
1427   if ((hdma2d->Instance->CR & DMA2D_CR_START) != 0U)
1428   {
1429     /* Get tick */
1430     tickstart = HAL_GetTick();
1431 
1432     while (__HAL_DMA2D_GET_FLAG(hdma2d, DMA2D_FLAG_TC) == 0U)
1433     {
1434       isrflags = READ_REG(hdma2d->Instance->ISR);
1435       if ((isrflags & (DMA2D_FLAG_CE | DMA2D_FLAG_TE)) != 0U)
1436       {
1437         if ((isrflags & DMA2D_FLAG_CE) != 0U)
1438         {
1439           hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CE;
1440         }
1441         if ((isrflags & DMA2D_FLAG_TE) != 0U)
1442         {
1443           hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TE;
1444         }
1445         /* Clear the transfer and configuration error flags */
1446         __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CE | DMA2D_FLAG_TE);
1447 
1448         /* Change DMA2D state */
1449         hdma2d->State = HAL_DMA2D_STATE_ERROR;
1450 
1451         /* Process unlocked */
1452         __HAL_UNLOCK(hdma2d);
1453 
1454         return HAL_ERROR;
1455       }
1456       /* Check for the Timeout */
1457       if (Timeout != HAL_MAX_DELAY)
1458       {
1459         if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
1460         {
1461           /* Update error code */
1462           hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
1463 
1464           /* Change the DMA2D state */
1465           hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
1466 
1467           /* Process unlocked */
1468           __HAL_UNLOCK(hdma2d);
1469 
1470           return HAL_TIMEOUT;
1471         }
1472       }
1473     }
1474   }
1475   /* Polling for CLUT loading (foreground or background) */
1476   layer_start = hdma2d->Instance->FGPFCCR & DMA2D_FGPFCCR_START;
1477   layer_start |= hdma2d->Instance->BGPFCCR & DMA2D_BGPFCCR_START;
1478   if (layer_start != 0U)
1479   {
1480     /* Get tick */
1481     tickstart = HAL_GetTick();
1482 
1483     while (__HAL_DMA2D_GET_FLAG(hdma2d, DMA2D_FLAG_CTC) == 0U)
1484     {
1485       isrflags = READ_REG(hdma2d->Instance->ISR);
1486       if ((isrflags & (DMA2D_FLAG_CAE | DMA2D_FLAG_CE | DMA2D_FLAG_TE)) != 0U)
1487       {
1488         if ((isrflags & DMA2D_FLAG_CAE) != 0U)
1489         {
1490           hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CAE;
1491         }
1492         if ((isrflags & DMA2D_FLAG_CE) != 0U)
1493         {
1494           hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CE;
1495         }
1496         if ((isrflags & DMA2D_FLAG_TE) != 0U)
1497         {
1498           hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TE;
1499         }
1500         /* Clear the CLUT Access Error, Configuration Error and Transfer Error flags */
1501         __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CAE | DMA2D_FLAG_CE | DMA2D_FLAG_TE);
1502 
1503         /* Change DMA2D state */
1504         hdma2d->State = HAL_DMA2D_STATE_ERROR;
1505 
1506         /* Process unlocked */
1507         __HAL_UNLOCK(hdma2d);
1508 
1509         return HAL_ERROR;
1510       }
1511       /* Check for the Timeout */
1512       if (Timeout != HAL_MAX_DELAY)
1513       {
1514         if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
1515         {
1516           /* Update error code */
1517           hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
1518 
1519           /* Change the DMA2D state */
1520           hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
1521 
1522           /* Process unlocked */
1523           __HAL_UNLOCK(hdma2d);
1524 
1525           return HAL_TIMEOUT;
1526         }
1527       }
1528     }
1529   }
1530 
1531   /* Clear the transfer complete and CLUT loading flags */
1532   __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TC | DMA2D_FLAG_CTC);
1533 
1534   /* Change DMA2D state */
1535   hdma2d->State = HAL_DMA2D_STATE_READY;
1536 
1537   /* Process unlocked */
1538   __HAL_UNLOCK(hdma2d);
1539 
1540   return HAL_OK;
1541 }
1542 /**
1543   * @brief  Handle DMA2D interrupt request.
1544   * @param  hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
1545   *                 the configuration information for the DMA2D.
1546   * @retval HAL status
1547   */
1548 void HAL_DMA2D_IRQHandler(DMA2D_HandleTypeDef *hdma2d)
1549 {
1550   uint32_t isrflags = READ_REG(hdma2d->Instance->ISR);
1551   uint32_t crflags = READ_REG(hdma2d->Instance->CR);
1552 
1553   /* Transfer Error Interrupt management ***************************************/
1554   if ((isrflags & DMA2D_FLAG_TE) != 0U)
1555   {
1556     if ((crflags & DMA2D_IT_TE) != 0U)
1557     {
1558       /* Disable the transfer Error interrupt */
1559       __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TE);
1560 
1561       /* Update error code */
1562       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TE;
1563 
1564       /* Clear the transfer error flag */
1565       __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TE);
1566 
1567       /* Change DMA2D state */
1568       hdma2d->State = HAL_DMA2D_STATE_ERROR;
1569 
1570       /* Process Unlocked */
1571       __HAL_UNLOCK(hdma2d);
1572 
1573       if (hdma2d->XferErrorCallback != NULL)
1574       {
1575         /* Transfer error Callback */
1576         hdma2d->XferErrorCallback(hdma2d);
1577       }
1578     }
1579   }
1580   /* Configuration Error Interrupt management **********************************/
1581   if ((isrflags & DMA2D_FLAG_CE) != 0U)
1582   {
1583     if ((crflags & DMA2D_IT_CE) != 0U)
1584     {
1585       /* Disable the Configuration Error interrupt */
1586       __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CE);
1587 
1588       /* Clear the Configuration error flag */
1589       __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CE);
1590 
1591       /* Update error code */
1592       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CE;
1593 
1594       /* Change DMA2D state */
1595       hdma2d->State = HAL_DMA2D_STATE_ERROR;
1596 
1597       /* Process Unlocked */
1598       __HAL_UNLOCK(hdma2d);
1599 
1600       if (hdma2d->XferErrorCallback != NULL)
1601       {
1602         /* Transfer error Callback */
1603         hdma2d->XferErrorCallback(hdma2d);
1604       }
1605     }
1606   }
1607   /* CLUT access Error Interrupt management ***********************************/
1608   if ((isrflags & DMA2D_FLAG_CAE) != 0U)
1609   {
1610     if ((crflags & DMA2D_IT_CAE) != 0U)
1611     {
1612       /* Disable the CLUT access error interrupt */
1613       __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CAE);
1614 
1615       /* Clear the CLUT access error flag */
1616       __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CAE);
1617 
1618       /* Update error code */
1619       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CAE;
1620 
1621       /* Change DMA2D state */
1622       hdma2d->State = HAL_DMA2D_STATE_ERROR;
1623 
1624       /* Process Unlocked */
1625       __HAL_UNLOCK(hdma2d);
1626 
1627       if (hdma2d->XferErrorCallback != NULL)
1628       {
1629         /* Transfer error Callback */
1630         hdma2d->XferErrorCallback(hdma2d);
1631       }
1632     }
1633   }
1634   /* Transfer watermark Interrupt management **********************************/
1635   if ((isrflags & DMA2D_FLAG_TW) != 0U)
1636   {
1637     if ((crflags & DMA2D_IT_TW) != 0U)
1638     {
1639       /* Disable the transfer watermark interrupt */
1640       __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TW);
1641 
1642       /* Clear the transfer watermark flag */
1643       __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TW);
1644 
1645       /* Transfer watermark Callback */
1646 #if (USE_HAL_DMA2D_REGISTER_CALLBACKS == 1)
1647       hdma2d->LineEventCallback(hdma2d);
1648 #else
1649       HAL_DMA2D_LineEventCallback(hdma2d);
1650 #endif /* USE_HAL_DMA2D_REGISTER_CALLBACKS */
1651 
1652     }
1653   }
1654   /* Transfer Complete Interrupt management ************************************/
1655   if ((isrflags & DMA2D_FLAG_TC) != 0U)
1656   {
1657     if ((crflags & DMA2D_IT_TC) != 0U)
1658     {
1659       /* Disable the transfer complete interrupt */
1660       __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TC);
1661 
1662       /* Clear the transfer complete flag */
1663       __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TC);
1664 
1665       /* Update error code */
1666       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_NONE;
1667 
1668       /* Change DMA2D state */
1669       hdma2d->State = HAL_DMA2D_STATE_READY;
1670 
1671       /* Process Unlocked */
1672       __HAL_UNLOCK(hdma2d);
1673 
1674       if (hdma2d->XferCpltCallback != NULL)
1675       {
1676         /* Transfer complete Callback */
1677         hdma2d->XferCpltCallback(hdma2d);
1678       }
1679     }
1680   }
1681   /* CLUT Transfer Complete Interrupt management ******************************/
1682   if ((isrflags & DMA2D_FLAG_CTC) != 0U)
1683   {
1684     if ((crflags & DMA2D_IT_CTC) != 0U)
1685     {
1686       /* Disable the CLUT transfer complete interrupt */
1687       __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CTC);
1688 
1689       /* Clear the CLUT transfer complete flag */
1690       __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CTC);
1691 
1692       /* Update error code */
1693       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_NONE;
1694 
1695       /* Change DMA2D state */
1696       hdma2d->State = HAL_DMA2D_STATE_READY;
1697 
1698       /* Process Unlocked */
1699       __HAL_UNLOCK(hdma2d);
1700 
1701       /* CLUT Transfer complete Callback */
1702 #if (USE_HAL_DMA2D_REGISTER_CALLBACKS == 1)
1703       hdma2d->CLUTLoadingCpltCallback(hdma2d);
1704 #else
1705       HAL_DMA2D_CLUTLoadingCpltCallback(hdma2d);
1706 #endif /* USE_HAL_DMA2D_REGISTER_CALLBACKS */
1707     }
1708   }
1709 
1710 }
1711 
1712 /**
1713   * @brief  Transfer watermark callback.
1714   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
1715   *                 the configuration information for the DMA2D.
1716   * @retval None
1717   */
1718 __weak void HAL_DMA2D_LineEventCallback(DMA2D_HandleTypeDef *hdma2d)
1719 {
1720   /* Prevent unused argument(s) compilation warning */
1721   UNUSED(hdma2d);
1722 
1723   /* NOTE : This function should not be modified; when the callback is needed,
1724             the HAL_DMA2D_LineEventCallback can be implemented in the user file.
1725    */
1726 }
1727 
1728 /**
1729   * @brief  CLUT Transfer Complete callback.
1730   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
1731   *                 the configuration information for the DMA2D.
1732   * @retval None
1733   */
1734 __weak void HAL_DMA2D_CLUTLoadingCpltCallback(DMA2D_HandleTypeDef *hdma2d)
1735 {
1736   /* Prevent unused argument(s) compilation warning */
1737   UNUSED(hdma2d);
1738 
1739   /* NOTE : This function should not be modified; when the callback is needed,
1740             the HAL_DMA2D_CLUTLoadingCpltCallback can be implemented in the user file.
1741    */
1742 }
1743 
1744 /**
1745   * @}
1746   */
1747 
1748 /** @defgroup DMA2D_Exported_Functions_Group3 Peripheral Control functions
1749   * @ingroup RTEMSBSPsARMSTM32H7
1750   *  @brief    Peripheral Control functions
1751   *
1752 @verbatim
1753  ===============================================================================
1754                     ##### Peripheral Control functions #####
1755  ===============================================================================
1756     [..]  This section provides functions allowing to:
1757       (+) Configure the DMA2D foreground or background layer parameters.
1758       (+) Configure the DMA2D CLUT transfer.
1759       (+) Configure the line watermark
1760       (+) Configure the dead time value.
1761       (+) Enable or disable the dead time value functionality.
1762 
1763 
1764 @endverbatim
1765   * @{
1766   */
1767 
1768 /**
1769   * @brief  Configure the DMA2D Layer according to the specified
1770   *         parameters in the DMA2D_HandleTypeDef.
1771   * @param  hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
1772   *                 the configuration information for the DMA2D.
1773   * @param  LayerIdx DMA2D Layer index.
1774   *                   This parameter can be one of the following values:
1775   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
1776   * @retval HAL status
1777   */
1778 HAL_StatusTypeDef HAL_DMA2D_ConfigLayer(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
1779 {
1780   DMA2D_LayerCfgTypeDef *pLayerCfg;
1781   uint32_t regMask;
1782   uint32_t regValue;
1783 
1784   /* Check the parameters */
1785   assert_param(IS_DMA2D_LAYER(LayerIdx));
1786   assert_param(IS_DMA2D_OFFSET(hdma2d->LayerCfg[LayerIdx].InputOffset));
1787   if (hdma2d->Init.Mode != DMA2D_R2M)
1788   {
1789     assert_param(IS_DMA2D_INPUT_COLOR_MODE(hdma2d->LayerCfg[LayerIdx].InputColorMode));
1790     if (hdma2d->Init.Mode != DMA2D_M2M)
1791     {
1792       assert_param(IS_DMA2D_ALPHA_MODE(hdma2d->LayerCfg[LayerIdx].AlphaMode));
1793     }
1794   }
1795   assert_param(IS_DMA2D_ALPHA_INVERTED(hdma2d->LayerCfg[LayerIdx].AlphaInverted));
1796   assert_param(IS_DMA2D_RB_SWAP(hdma2d->LayerCfg[LayerIdx].RedBlueSwap));
1797 
1798   if ((LayerIdx == DMA2D_FOREGROUND_LAYER) && (hdma2d->LayerCfg[LayerIdx].InputColorMode == DMA2D_INPUT_YCBCR))
1799   {
1800     assert_param(IS_DMA2D_CHROMA_SUB_SAMPLING(hdma2d->LayerCfg[LayerIdx].ChromaSubSampling));
1801   }
1802 
1803   /* Process locked */
1804   __HAL_LOCK(hdma2d);
1805 
1806   /* Change DMA2D peripheral state */
1807   hdma2d->State = HAL_DMA2D_STATE_BUSY;
1808 
1809   pLayerCfg = &hdma2d->LayerCfg[LayerIdx];
1810 
1811   /* Prepare the value to be written to the BGPFCCR or FGPFCCR register */
1812   regValue = pLayerCfg->InputColorMode | (pLayerCfg->AlphaMode << DMA2D_BGPFCCR_AM_Pos) | \
1813              (pLayerCfg->AlphaInverted << DMA2D_BGPFCCR_AI_Pos) | (pLayerCfg->RedBlueSwap << DMA2D_BGPFCCR_RBS_Pos);
1814   regMask  = (DMA2D_BGPFCCR_CM | DMA2D_BGPFCCR_AM | DMA2D_BGPFCCR_ALPHA | DMA2D_BGPFCCR_AI | DMA2D_BGPFCCR_RBS);
1815 
1816 
1817   if ((pLayerCfg->InputColorMode == DMA2D_INPUT_A4) || (pLayerCfg->InputColorMode == DMA2D_INPUT_A8))
1818   {
1819     regValue |= (pLayerCfg->InputAlpha & DMA2D_BGPFCCR_ALPHA);
1820   }
1821   else
1822   {
1823     regValue |= (pLayerCfg->InputAlpha << DMA2D_BGPFCCR_ALPHA_Pos);
1824   }
1825 
1826   /* Configure the background DMA2D layer */
1827   if (LayerIdx == DMA2D_BACKGROUND_LAYER)
1828   {
1829     /* Write DMA2D BGPFCCR register */
1830     MODIFY_REG(hdma2d->Instance->BGPFCCR, regMask, regValue);
1831 
1832     /* DMA2D BGOR register configuration -------------------------------------*/
1833     WRITE_REG(hdma2d->Instance->BGOR, pLayerCfg->InputOffset);
1834 
1835     /* DMA2D BGCOLR register configuration -------------------------------------*/
1836     if ((pLayerCfg->InputColorMode == DMA2D_INPUT_A4) || (pLayerCfg->InputColorMode == DMA2D_INPUT_A8))
1837     {
1838       WRITE_REG(hdma2d->Instance->BGCOLR, pLayerCfg->InputAlpha & (DMA2D_BGCOLR_BLUE | DMA2D_BGCOLR_GREEN | \
1839                                                                    DMA2D_BGCOLR_RED));
1840     }
1841   }
1842   /* Configure the foreground DMA2D layer */
1843   else
1844   {
1845 
1846     if (pLayerCfg->InputColorMode == DMA2D_INPUT_YCBCR)
1847     {
1848       regValue |= (pLayerCfg->ChromaSubSampling << DMA2D_FGPFCCR_CSS_Pos);
1849       regMask  |= DMA2D_FGPFCCR_CSS;
1850     }
1851 
1852     /* Write DMA2D FGPFCCR register */
1853     MODIFY_REG(hdma2d->Instance->FGPFCCR, regMask, regValue);
1854 
1855     /* DMA2D FGOR register configuration -------------------------------------*/
1856     WRITE_REG(hdma2d->Instance->FGOR, pLayerCfg->InputOffset);
1857 
1858     /* DMA2D FGCOLR register configuration -------------------------------------*/
1859     if ((pLayerCfg->InputColorMode == DMA2D_INPUT_A4) || (pLayerCfg->InputColorMode == DMA2D_INPUT_A8))
1860     {
1861       WRITE_REG(hdma2d->Instance->FGCOLR, pLayerCfg->InputAlpha & (DMA2D_FGCOLR_BLUE | DMA2D_FGCOLR_GREEN | \
1862                                                                    DMA2D_FGCOLR_RED));
1863     }
1864   }
1865   /* Initialize the DMA2D state*/
1866   hdma2d->State = HAL_DMA2D_STATE_READY;
1867 
1868   /* Process unlocked */
1869   __HAL_UNLOCK(hdma2d);
1870 
1871   return HAL_OK;
1872 }
1873 
1874 /**
1875   * @brief  Configure the DMA2D CLUT Transfer.
1876   * @param  hdma2d   Pointer to a DMA2D_HandleTypeDef structure that contains
1877   *                   the configuration information for the DMA2D.
1878   * @param  CLUTCfg  Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
1879   *                   the configuration information for the color look up table.
1880   * @param  LayerIdx DMA2D Layer index.
1881   *                   This parameter can be one of the following values:
1882   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
1883   * @note API obsolete and maintained for compatibility with legacy. User is invited
1884   *      to resort to HAL_DMA2D_CLUTStartLoad() instead to benefit from code compactness,
1885   *      code size and improved heap usage.
1886   * @retval HAL status
1887   */
1888 HAL_StatusTypeDef HAL_DMA2D_ConfigCLUT(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef CLUTCfg, uint32_t LayerIdx)
1889 {
1890   /* Check the parameters */
1891   assert_param(IS_DMA2D_LAYER(LayerIdx));
1892   assert_param(IS_DMA2D_CLUT_CM(CLUTCfg.CLUTColorMode));
1893   assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg.Size));
1894 
1895   /* Process locked */
1896   __HAL_LOCK(hdma2d);
1897 
1898   /* Change DMA2D peripheral state */
1899   hdma2d->State = HAL_DMA2D_STATE_BUSY;
1900 
1901   /* Configure the CLUT of the background DMA2D layer */
1902   if (LayerIdx == DMA2D_BACKGROUND_LAYER)
1903   {
1904     /* Write background CLUT memory address */
1905     WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg.pCLUT);
1906 
1907     /* Write background CLUT size and CLUT color mode */
1908     MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
1909                ((CLUTCfg.Size << DMA2D_BGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_BGPFCCR_CCM_Pos)));
1910   }
1911   /* Configure the CLUT of the foreground DMA2D layer */
1912   else
1913   {
1914     /* Write foreground CLUT memory address */
1915     WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg.pCLUT);
1916 
1917     /* Write foreground CLUT size and CLUT color mode */
1918     MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
1919                ((CLUTCfg.Size << DMA2D_FGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_FGPFCCR_CCM_Pos)));
1920   }
1921 
1922   /* Set the DMA2D state to Ready*/
1923   hdma2d->State = HAL_DMA2D_STATE_READY;
1924 
1925   /* Process unlocked */
1926   __HAL_UNLOCK(hdma2d);
1927 
1928   return HAL_OK;
1929 }
1930 
1931 
1932 /**
1933   * @brief  Configure the line watermark.
1934   * @param  hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
1935   *                 the configuration information for the DMA2D.
1936   * @param  Line   Line Watermark configuration (maximum 16-bit long value expected).
1937   * @note   HAL_DMA2D_ProgramLineEvent() API enables the transfer watermark interrupt.
1938   * @note   The transfer watermark interrupt is disabled once it has occurred.
1939   * @retval HAL status
1940   */
1941 
1942 HAL_StatusTypeDef HAL_DMA2D_ProgramLineEvent(DMA2D_HandleTypeDef *hdma2d, uint32_t Line)
1943 {
1944   /* Check the parameters */
1945   if (Line > DMA2D_LWR_LW)
1946   {
1947     return HAL_ERROR;
1948   }
1949   else
1950   {
1951     /* Process locked */
1952     __HAL_LOCK(hdma2d);
1953 
1954     /* Change DMA2D peripheral state */
1955     hdma2d->State = HAL_DMA2D_STATE_BUSY;
1956 
1957     /* Sets the Line watermark configuration */
1958     WRITE_REG(hdma2d->Instance->LWR, Line);
1959 
1960     /* Enable the Line interrupt */
1961     __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_TW);
1962 
1963     /* Initialize the DMA2D state*/
1964     hdma2d->State = HAL_DMA2D_STATE_READY;
1965 
1966     /* Process unlocked */
1967     __HAL_UNLOCK(hdma2d);
1968 
1969     return HAL_OK;
1970   }
1971 }
1972 
1973 /**
1974   * @brief Enable DMA2D dead time feature.
1975   * @param hdma2d DMA2D handle.
1976   * @retval HAL status
1977   */
1978 HAL_StatusTypeDef HAL_DMA2D_EnableDeadTime(DMA2D_HandleTypeDef *hdma2d)
1979 {
1980   /* Process Locked */
1981   __HAL_LOCK(hdma2d);
1982 
1983   hdma2d->State = HAL_DMA2D_STATE_BUSY;
1984 
1985   /* Set DMA2D_AMTCR EN bit */
1986   SET_BIT(hdma2d->Instance->AMTCR, DMA2D_AMTCR_EN);
1987 
1988   hdma2d->State = HAL_DMA2D_STATE_READY;
1989 
1990   /* Process Unlocked */
1991   __HAL_UNLOCK(hdma2d);
1992 
1993   return HAL_OK;
1994 }
1995 
1996 /**
1997   * @brief Disable DMA2D dead time feature.
1998   * @param hdma2d DMA2D handle.
1999   * @retval HAL status
2000   */
2001 HAL_StatusTypeDef HAL_DMA2D_DisableDeadTime(DMA2D_HandleTypeDef *hdma2d)
2002 {
2003   /* Process Locked */
2004   __HAL_LOCK(hdma2d);
2005 
2006   hdma2d->State = HAL_DMA2D_STATE_BUSY;
2007 
2008   /* Clear DMA2D_AMTCR EN bit */
2009   CLEAR_BIT(hdma2d->Instance->AMTCR, DMA2D_AMTCR_EN);
2010 
2011   hdma2d->State = HAL_DMA2D_STATE_READY;
2012 
2013   /* Process Unlocked */
2014   __HAL_UNLOCK(hdma2d);
2015 
2016   return HAL_OK;
2017 }
2018 
2019 /**
2020   * @brief Configure dead time.
2021   * @note The dead time value represents the guaranteed minimum number of cycles between
2022   *       two consecutive transactions on the AHB bus.
2023   * @param hdma2d DMA2D handle.
2024   * @param DeadTime dead time value.
2025   * @retval HAL status
2026   */
2027 HAL_StatusTypeDef HAL_DMA2D_ConfigDeadTime(DMA2D_HandleTypeDef *hdma2d, uint8_t DeadTime)
2028 {
2029   /* Process Locked */
2030   __HAL_LOCK(hdma2d);
2031 
2032   hdma2d->State = HAL_DMA2D_STATE_BUSY;
2033 
2034   /* Set DMA2D_AMTCR DT field */
2035   MODIFY_REG(hdma2d->Instance->AMTCR, DMA2D_AMTCR_DT, (((uint32_t) DeadTime) << DMA2D_AMTCR_DT_Pos));
2036 
2037   hdma2d->State = HAL_DMA2D_STATE_READY;
2038 
2039   /* Process Unlocked */
2040   __HAL_UNLOCK(hdma2d);
2041 
2042   return HAL_OK;
2043 }
2044 
2045 /**
2046   * @}
2047   */
2048 
2049 
2050 /** @defgroup DMA2D_Exported_Functions_Group4 Peripheral State and Error functions
2051   * @ingroup RTEMSBSPsARMSTM32H7
2052   *  @brief    Peripheral State functions
2053   *
2054 @verbatim
2055  ===============================================================================
2056                   ##### Peripheral State and Errors functions #####
2057  ===============================================================================
2058     [..]
2059     This subsection provides functions allowing to:
2060       (+) Get the DMA2D state
2061       (+) Get the DMA2D error code
2062 
2063 @endverbatim
2064   * @{
2065   */
2066 
2067 /**
2068   * @brief  Return the DMA2D state
2069   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
2070   *                 the configuration information for the DMA2D.
2071   * @retval HAL state
2072   */
2073 HAL_DMA2D_StateTypeDef HAL_DMA2D_GetState(DMA2D_HandleTypeDef *hdma2d)
2074 {
2075   return hdma2d->State;
2076 }
2077 
2078 /**
2079   * @brief  Return the DMA2D error code
2080   * @param  hdma2d  pointer to a DMA2D_HandleTypeDef structure that contains
2081   *               the configuration information for DMA2D.
2082   * @retval DMA2D Error Code
2083   */
2084 uint32_t HAL_DMA2D_GetError(DMA2D_HandleTypeDef *hdma2d)
2085 {
2086   return hdma2d->ErrorCode;
2087 }
2088 
2089 /**
2090   * @}
2091   */
2092 
2093 /**
2094   * @}
2095   */
2096 
2097 
2098 /** @defgroup DMA2D_Private_Functions DMA2D Private Functions
2099   * @ingroup RTEMSBSPsARMSTM32H7
2100   * @{
2101   */
2102 
2103 /**
2104   * @brief  Set the DMA2D transfer parameters.
2105   * @param  hdma2d     Pointer to a DMA2D_HandleTypeDef structure that contains
2106   *                     the configuration information for the specified DMA2D.
2107   * @param  pdata      The source memory Buffer address
2108   * @param  DstAddress The destination memory Buffer address
2109   * @param  Width      The width of data to be transferred from source to destination.
2110   * @param  Height     The height of data to be transferred from source to destination.
2111   * @retval HAL status
2112   */
2113 static void DMA2D_SetConfig(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width,
2114                             uint32_t Height)
2115 {
2116   uint32_t tmp;
2117   uint32_t tmp1;
2118   uint32_t tmp2;
2119   uint32_t tmp3;
2120   uint32_t tmp4;
2121 
2122   /* Configure DMA2D data size */
2123   MODIFY_REG(hdma2d->Instance->NLR, (DMA2D_NLR_NL | DMA2D_NLR_PL), (Height | (Width << DMA2D_NLR_PL_Pos)));
2124 
2125   /* Configure DMA2D destination address */
2126   WRITE_REG(hdma2d->Instance->OMAR, DstAddress);
2127 
2128   /* Register to memory DMA2D mode selected */
2129   if (hdma2d->Init.Mode == DMA2D_R2M)
2130   {
2131     tmp1 = pdata & DMA2D_OCOLR_ALPHA_1;
2132     tmp2 = pdata & DMA2D_OCOLR_RED_1;
2133     tmp3 = pdata & DMA2D_OCOLR_GREEN_1;
2134     tmp4 = pdata & DMA2D_OCOLR_BLUE_1;
2135 
2136     /* Prepare the value to be written to the OCOLR register according to the color mode */
2137     if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_ARGB8888)
2138     {
2139       tmp = (tmp3 | tmp2 | tmp1 | tmp4);
2140     }
2141     else if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_RGB888)
2142     {
2143       tmp = (tmp3 | tmp2 | tmp4);
2144     }
2145     else if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_RGB565)
2146     {
2147       tmp2 = (tmp2 >> 19U);
2148       tmp3 = (tmp3 >> 10U);
2149       tmp4 = (tmp4 >> 3U);
2150       tmp  = ((tmp3 << 5U) | (tmp2 << 11U) | tmp4);
2151     }
2152     else if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_ARGB1555)
2153     {
2154       tmp1 = (tmp1 >> 31U);
2155       tmp2 = (tmp2 >> 19U);
2156       tmp3 = (tmp3 >> 11U);
2157       tmp4 = (tmp4 >> 3U);
2158       tmp  = ((tmp3 << 5U) | (tmp2 << 10U) | (tmp1 << 15U) | tmp4);
2159     }
2160     else /* Dhdma2d->Init.ColorMode = DMA2D_OUTPUT_ARGB4444 */
2161     {
2162       tmp1 = (tmp1 >> 28U);
2163       tmp2 = (tmp2 >> 20U);
2164       tmp3 = (tmp3 >> 12U);
2165       tmp4 = (tmp4 >> 4U);
2166       tmp  = ((tmp3 << 4U) | (tmp2 << 8U) | (tmp1 << 12U) | tmp4);
2167     }
2168     /* Write to DMA2D OCOLR register */
2169     WRITE_REG(hdma2d->Instance->OCOLR, tmp);
2170   }
2171   else if (hdma2d->Init.Mode == DMA2D_M2M_BLEND_FG) /*M2M_blending with fixed color FG DMA2D Mode selected*/
2172   {
2173     WRITE_REG(hdma2d->Instance->BGMAR, pdata);
2174   }
2175   else /* M2M, M2M_PFC,M2M_Blending or M2M_blending with fixed color BG DMA2D Mode */
2176   {
2177     /* Configure DMA2D source address */
2178     WRITE_REG(hdma2d->Instance->FGMAR, pdata);
2179   }
2180 }
2181 
2182 /**
2183   * @}
2184   */
2185 
2186 /**
2187   * @}
2188   */
2189 
2190 /**
2191   * @}
2192   */
2193 #endif /* DMA2D */
2194 #endif /* HAL_DMA2D_MODULE_ENABLED */