STM32F479xx HAL User Manual
stm32f4xx_hal_dma2d.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_hal_dma2d.c
00004   * @author  MCD Application Team
00005   * @brief   DMA2D HAL module driver.
00006   *          This file provides firmware functions to manage the following
00007   *          functionalities of the DMA2D peripheral:
00008   *           + Initialization and de-initialization functions
00009   *           + IO operation functions
00010   *           + Peripheral Control functions
00011   *           + Peripheral State and Errors functions
00012   *
00013   @verbatim
00014   ==============================================================================
00015                         ##### How to use this driver #####
00016   ==============================================================================
00017     [..]
00018       (#) Program the required configuration through the following parameters:
00019           the transfer mode, the output color mode and the output offset using
00020           HAL_DMA2D_Init() function.
00021 
00022       (#) Program the required configuration through the following parameters:
00023           the input color mode, the input color, the input alpha value, the alpha mode,
00024           the red/blue swap mode, the inverted alpha mode and the input offset using
00025           HAL_DMA2D_ConfigLayer() function for foreground or/and background layer.
00026 
00027      *** Polling mode IO operation ***
00028      =================================
00029     [..]
00030        (#) Configure pdata parameter (explained hereafter), destination and data length
00031            and enable the transfer using HAL_DMA2D_Start().
00032        (#) Wait for end of transfer using HAL_DMA2D_PollForTransfer(), at this stage
00033            user can specify the value of timeout according to his end application.
00034 
00035      *** Interrupt mode IO operation ***
00036      ===================================
00037      [..]
00038        (#) Configure pdata parameter, destination and data length and enable
00039            the transfer using HAL_DMA2D_Start_IT().
00040        (#) Use HAL_DMA2D_IRQHandler() called under DMA2D_IRQHandler() interrupt subroutine.
00041        (#) At the end of data transfer HAL_DMA2D_IRQHandler() function is executed and user can
00042            add his own function by customization of function pointer XferCpltCallback (member
00043            of DMA2D handle structure).
00044        (#) In case of error, the HAL_DMA2D_IRQHandler() function calls the callback
00045            XferErrorCallback.
00046 
00047          -@-   In Register-to-Memory transfer mode, pdata parameter is the register
00048                color, in Memory-to-memory or Memory-to-Memory with pixel format
00049                conversion pdata is the source address.
00050 
00051          -@-   Configure the foreground source address, the background source address,
00052                the destination and data length then Enable the transfer using
00053                HAL_DMA2D_BlendingStart() in polling mode and HAL_DMA2D_BlendingStart_IT()
00054                in interrupt mode.
00055 
00056          -@-   HAL_DMA2D_BlendingStart() and HAL_DMA2D_BlendingStart_IT() functions
00057                are used if the memory to memory with blending transfer mode is selected.
00058 
00059       (#) Optionally, configure and enable the CLUT using HAL_DMA2D_CLUTLoad() in polling
00060           mode or HAL_DMA2D_CLUTLoad_IT() in interrupt mode.
00061 
00062       (#) Optionally, configure the line watermark in using the API HAL_DMA2D_ProgramLineEvent().
00063 
00064       (#) Optionally, configure the dead time value in the AHB clock cycle inserted between two
00065           consecutive accesses on the AHB master port in using the API HAL_DMA2D_ConfigDeadTime()
00066           and enable/disable the functionality  with the APIs HAL_DMA2D_EnableDeadTime() or
00067           HAL_DMA2D_DisableDeadTime().
00068 
00069       (#) The transfer can be suspended, resumed and aborted using the following
00070           functions: HAL_DMA2D_Suspend(), HAL_DMA2D_Resume(), HAL_DMA2D_Abort().
00071 
00072       (#) The CLUT loading can be suspended, resumed and aborted using the following
00073           functions: HAL_DMA2D_CLUTLoading_Suspend(), HAL_DMA2D_CLUTLoading_Resume(),
00074           HAL_DMA2D_CLUTLoading_Abort().
00075 
00076       (#) To control the DMA2D state, use the following function: HAL_DMA2D_GetState().
00077 
00078       (#) To read the DMA2D error code, use the following function: HAL_DMA2D_GetError().
00079 
00080      *** DMA2D HAL driver macros list ***
00081      =============================================
00082      [..]
00083        Below the list of most used macros in DMA2D HAL driver :
00084 
00085       (+) __HAL_DMA2D_ENABLE: Enable the DMA2D peripheral.
00086       (+) __HAL_DMA2D_GET_FLAG: Get the DMA2D pending flags.
00087       (+) __HAL_DMA2D_CLEAR_FLAG: Clear the DMA2D pending flags.
00088       (+) __HAL_DMA2D_ENABLE_IT: Enable the specified DMA2D interrupts.
00089       (+) __HAL_DMA2D_DISABLE_IT: Disable the specified DMA2D interrupts.
00090       (+) __HAL_DMA2D_GET_IT_SOURCE: Check whether the specified DMA2D interrupt is enabled or not.
00091 
00092      *** Callback registration ***
00093      ===================================
00094      [..]
00095       (#) The compilation define  USE_HAL_DMA2D_REGISTER_CALLBACKS when set to 1
00096           allows the user to configure dynamically the driver callbacks.
00097           Use function HAL_DMA2D_RegisterCallback() to register a user callback.
00098 
00099       (#) Function HAL_DMA2D_RegisterCallback() allows to register following callbacks:
00100             (+) XferCpltCallback : callback for transfer complete.
00101             (+) XferErrorCallback : callback for transfer error.
00102             (+) LineEventCallback : callback for line event.
00103             (+) CLUTLoadingCpltCallback : callback for CLUT loading completion.
00104             (+) MspInitCallback    : DMA2D MspInit.
00105             (+) MspDeInitCallback  : DMA2D MspDeInit.
00106           This function takes as parameters the HAL peripheral handle, the Callback ID
00107           and a pointer to the user callback function.
00108 
00109       (#) Use function HAL_DMA2D_UnRegisterCallback() to reset a callback to the default
00110           weak (surcharged) function.
00111           HAL_DMA2D_UnRegisterCallback() takes as parameters the HAL peripheral handle,
00112           and the Callback ID.
00113           This function allows to reset following callbacks:
00114             (+) XferCpltCallback : callback for transfer complete.
00115             (+) XferErrorCallback : callback for transfer error.
00116             (+) LineEventCallback : callback for line event.
00117             (+) CLUTLoadingCpltCallback : callback for CLUT loading completion.
00118             (+) MspInitCallback    : DMA2D MspInit.
00119             (+) MspDeInitCallback  : DMA2D MspDeInit.
00120 
00121       (#) By default, after the HAL_DMA2D_Init and if the state is HAL_DMA2D_STATE_RESET
00122           all callbacks are reset to the corresponding legacy weak (surcharged) functions:
00123           examples HAL_DMA2D_LineEventCallback(), HAL_DMA2D_CLUTLoadingCpltCallback()
00124           Exception done for MspInit and MspDeInit callbacks that are respectively
00125           reset to the legacy weak (surcharged) functions in the HAL_DMA2D_Init
00126           and HAL_DMA2D_DeInit only when these callbacks are null (not registered beforehand)
00127           If not, MspInit or MspDeInit are not null, the HAL_DMA2D_Init and HAL_DMA2D_DeInit
00128           keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
00129 
00130           Exception as well for Transfer Completion and Transfer Error callbacks that are not defined
00131           as weak (surcharged) functions. They must be defined by the user to be resorted to.
00132 
00133           Callbacks can be registered/unregistered in READY state only.
00134           Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
00135           in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
00136           during the Init/DeInit.
00137           In that case first register the MspInit/MspDeInit user callbacks
00138           using HAL_DMA2D_RegisterCallback before calling HAL_DMA2D_DeInit
00139           or HAL_DMA2D_Init function.
00140 
00141           When The compilation define USE_HAL_DMA2D_REGISTER_CALLBACKS is set to 0 or
00142           not defined, the callback registering feature is not available
00143           and weak (surcharged) callbacks are used.
00144 
00145      [..]
00146       (@) You can refer to the DMA2D HAL driver header file for more useful macros
00147 
00148   @endverbatim
00149   ******************************************************************************
00150   * @attention
00151   *
00152   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
00153   * All rights reserved.</center></h2>
00154   *
00155   * This software component is licensed by ST under BSD 3-Clause license,
00156   * the "License"; You may not use this file except in compliance with the
00157   * License. You may obtain a copy of the License at:
00158   *                        opensource.org/licenses/BSD-3-Clause
00159   *
00160   ******************************************************************************
00161   */
00162 
00163 /* Includes ------------------------------------------------------------------*/
00164 #include "stm32f4xx_hal.h"
00165 
00166 #ifdef HAL_DMA2D_MODULE_ENABLED
00167 #if defined (DMA2D)
00168 
00169 /** @addtogroup STM32F4xx_HAL_Driver
00170   * @{
00171   */
00172 
00173 /** @defgroup DMA2D  DMA2D
00174   * @brief DMA2D HAL module driver
00175   * @{
00176   */
00177 
00178 /* Private types -------------------------------------------------------------*/
00179 /* Private define ------------------------------------------------------------*/
00180 /** @defgroup DMA2D_Private_Constants DMA2D Private Constants
00181   * @{
00182   */
00183 
00184 /** @defgroup DMA2D_TimeOut DMA2D Time Out
00185   * @{
00186   */
00187 #define DMA2D_TIMEOUT_ABORT           (1000U)  /*!<  1s  */
00188 #define DMA2D_TIMEOUT_SUSPEND         (1000U)  /*!<  1s  */
00189 /**
00190   * @}
00191   */
00192 
00193 /**
00194   * @}
00195   */
00196 
00197 /* Private variables ---------------------------------------------------------*/
00198 /* Private constants ---------------------------------------------------------*/
00199 /* Private macro -------------------------------------------------------------*/
00200 /* Private function prototypes -----------------------------------------------*/
00201 /** @addtogroup DMA2D_Private_Functions DMA2D Private Functions
00202   * @{
00203   */
00204 static void DMA2D_SetConfig(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width,
00205                             uint32_t Height);
00206 /**
00207   * @}
00208   */
00209 
00210 /* Private functions ---------------------------------------------------------*/
00211 /* Exported functions --------------------------------------------------------*/
00212 /** @defgroup DMA2D_Exported_Functions DMA2D Exported Functions
00213   * @{
00214   */
00215 
00216 /** @defgroup DMA2D_Exported_Functions_Group1 Initialization and de-initialization functions
00217   *  @brief   Initialization and Configuration functions
00218   *
00219 @verbatim
00220  ===============================================================================
00221                 ##### Initialization and Configuration functions #####
00222  ===============================================================================
00223     [..]  This section provides functions allowing to:
00224       (+) Initialize and configure the DMA2D
00225       (+) De-initialize the DMA2D
00226 
00227 @endverbatim
00228   * @{
00229   */
00230 
00231 /**
00232   * @brief  Initialize the DMA2D according to the specified
00233   *         parameters in the DMA2D_InitTypeDef and create the associated handle.
00234   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
00235   *                 the configuration information for the DMA2D.
00236   * @retval HAL status
00237   */
00238 HAL_StatusTypeDef HAL_DMA2D_Init(DMA2D_HandleTypeDef *hdma2d)
00239 {
00240   /* Check the DMA2D peripheral state */
00241   if (hdma2d == NULL)
00242   {
00243     return HAL_ERROR;
00244   }
00245 
00246   /* Check the parameters */
00247   assert_param(IS_DMA2D_ALL_INSTANCE(hdma2d->Instance));
00248   assert_param(IS_DMA2D_MODE(hdma2d->Init.Mode));
00249   assert_param(IS_DMA2D_CMODE(hdma2d->Init.ColorMode));
00250   assert_param(IS_DMA2D_OFFSET(hdma2d->Init.OutputOffset));
00251 
00252 #if (USE_HAL_DMA2D_REGISTER_CALLBACKS == 1)
00253   if (hdma2d->State == HAL_DMA2D_STATE_RESET)
00254   {
00255     /* Reset Callback pointers in HAL_DMA2D_STATE_RESET only */
00256     hdma2d->LineEventCallback       = HAL_DMA2D_LineEventCallback;
00257     hdma2d->CLUTLoadingCpltCallback = HAL_DMA2D_CLUTLoadingCpltCallback;
00258     if (hdma2d->MspInitCallback == NULL)
00259     {
00260       hdma2d->MspInitCallback = HAL_DMA2D_MspInit;
00261     }
00262 
00263     /* Init the low level hardware */
00264     hdma2d->MspInitCallback(hdma2d);
00265   }
00266 #else
00267   if (hdma2d->State == HAL_DMA2D_STATE_RESET)
00268   {
00269     /* Allocate lock resource and initialize it */
00270     hdma2d->Lock = HAL_UNLOCKED;
00271     /* Init the low level hardware */
00272     HAL_DMA2D_MspInit(hdma2d);
00273   }
00274 #endif /* (USE_HAL_DMA2D_REGISTER_CALLBACKS) */
00275 
00276   /* Change DMA2D peripheral state */
00277   hdma2d->State = HAL_DMA2D_STATE_BUSY;
00278 
00279   /* DMA2D CR register configuration -------------------------------------------*/
00280   MODIFY_REG(hdma2d->Instance->CR, DMA2D_CR_MODE, hdma2d->Init.Mode);
00281 
00282   /* DMA2D OPFCCR register configuration ---------------------------------------*/
00283   MODIFY_REG(hdma2d->Instance->OPFCCR, DMA2D_OPFCCR_CM, hdma2d->Init.ColorMode);
00284 
00285   /* DMA2D OOR register configuration ------------------------------------------*/
00286   MODIFY_REG(hdma2d->Instance->OOR, DMA2D_OOR_LO, hdma2d->Init.OutputOffset);
00287 
00288 
00289   /* Update error code */
00290   hdma2d->ErrorCode = HAL_DMA2D_ERROR_NONE;
00291 
00292   /* Initialize the DMA2D state*/
00293   hdma2d->State  = HAL_DMA2D_STATE_READY;
00294 
00295   return HAL_OK;
00296 }
00297 
00298 /**
00299   * @brief  Deinitializes the DMA2D peripheral registers to their default reset
00300   *         values.
00301   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
00302   *                 the configuration information for the DMA2D.
00303   * @retval None
00304   */
00305 
00306 HAL_StatusTypeDef HAL_DMA2D_DeInit(DMA2D_HandleTypeDef *hdma2d)
00307 {
00308 
00309   /* Check the DMA2D peripheral state */
00310   if (hdma2d == NULL)
00311   {
00312     return HAL_ERROR;
00313   }
00314 
00315   /* Before aborting any DMA2D transfer or CLUT loading, check
00316      first whether or not DMA2D clock is enabled */
00317   if (__HAL_RCC_DMA2D_IS_CLK_ENABLED())
00318   {
00319     /* Abort DMA2D transfer if any */
00320     if ((hdma2d->Instance->CR & DMA2D_CR_START) == DMA2D_CR_START)
00321     {
00322       if (HAL_DMA2D_Abort(hdma2d) != HAL_OK)
00323       {
00324         /* Issue when aborting DMA2D transfer */
00325         return HAL_ERROR;
00326       }
00327     }
00328     else
00329     {
00330       /* Abort background CLUT loading if any */
00331       if ((hdma2d->Instance->BGPFCCR & DMA2D_BGPFCCR_START) == DMA2D_BGPFCCR_START)
00332       {
00333         if (HAL_DMA2D_CLUTLoading_Abort(hdma2d, 0U) != HAL_OK)
00334         {
00335           /* Issue when aborting background CLUT loading */
00336           return HAL_ERROR;
00337         }
00338       }
00339       else
00340       {
00341         /* Abort foreground CLUT loading if any */
00342         if ((hdma2d->Instance->FGPFCCR & DMA2D_FGPFCCR_START) == DMA2D_FGPFCCR_START)
00343         {
00344           if (HAL_DMA2D_CLUTLoading_Abort(hdma2d, 1U) != HAL_OK)
00345           {
00346             /* Issue when aborting foreground CLUT loading */
00347             return HAL_ERROR;
00348           }
00349         }
00350       }
00351     }
00352   }
00353 
00354   /* Reset DMA2D control registers*/
00355   hdma2d->Instance->CR       =    0U;
00356   hdma2d->Instance->IFCR     = 0x3FU;
00357   hdma2d->Instance->FGOR     =    0U;
00358   hdma2d->Instance->BGOR     =    0U;
00359   hdma2d->Instance->FGPFCCR  =    0U;
00360   hdma2d->Instance->BGPFCCR  =    0U;
00361   hdma2d->Instance->OPFCCR   =    0U;
00362 
00363 #if (USE_HAL_DMA2D_REGISTER_CALLBACKS == 1)
00364 
00365   if (hdma2d->MspDeInitCallback == NULL)
00366   {
00367     hdma2d->MspDeInitCallback = HAL_DMA2D_MspDeInit;
00368   }
00369 
00370   /* DeInit the low level hardware */
00371   hdma2d->MspDeInitCallback(hdma2d);
00372 
00373 #else
00374   /* Carry on with de-initialization of low level hardware */
00375   HAL_DMA2D_MspDeInit(hdma2d);
00376 #endif /* (USE_HAL_DMA2D_REGISTER_CALLBACKS) */
00377 
00378   /* Update error code */
00379   hdma2d->ErrorCode = HAL_DMA2D_ERROR_NONE;
00380 
00381   /* Initialize the DMA2D state*/
00382   hdma2d->State  = HAL_DMA2D_STATE_RESET;
00383 
00384   /* Release Lock */
00385   __HAL_UNLOCK(hdma2d);
00386 
00387   return HAL_OK;
00388 }
00389 
00390 /**
00391   * @brief  Initializes the DMA2D MSP.
00392   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
00393   *                 the configuration information for the DMA2D.
00394   * @retval None
00395   */
00396 __weak void HAL_DMA2D_MspInit(DMA2D_HandleTypeDef *hdma2d)
00397 {
00398   /* Prevent unused argument(s) compilation warning */
00399   UNUSED(hdma2d);
00400 
00401   /* NOTE : This function should not be modified; when the callback is needed,
00402             the HAL_DMA2D_MspInit can be implemented in the user file.
00403    */
00404 }
00405 
00406 /**
00407   * @brief  DeInitializes the DMA2D MSP.
00408   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
00409   *                 the configuration information for the DMA2D.
00410   * @retval None
00411   */
00412 __weak void HAL_DMA2D_MspDeInit(DMA2D_HandleTypeDef *hdma2d)
00413 {
00414   /* Prevent unused argument(s) compilation warning */
00415   UNUSED(hdma2d);
00416 
00417   /* NOTE : This function should not be modified; when the callback is needed,
00418             the HAL_DMA2D_MspDeInit can be implemented in the user file.
00419    */
00420 }
00421 
00422 #if (USE_HAL_DMA2D_REGISTER_CALLBACKS == 1)
00423 /**
00424   * @brief  Register a User DMA2D Callback
00425   *         To be used instead of the weak (surcharged) predefined callback
00426   * @param hdma2d DMA2D handle
00427   * @param CallbackID ID of the callback to be registered
00428   *        This parameter can be one of the following values:
00429   *          @arg @ref HAL_DMA2D_TRANSFERCOMPLETE_CB_ID DMA2D transfer complete Callback ID
00430   *          @arg @ref HAL_DMA2D_TRANSFERERROR_CB_ID DMA2D transfer error Callback ID
00431   *          @arg @ref HAL_DMA2D_LINEEVENT_CB_ID DMA2D line event Callback ID
00432   *          @arg @ref HAL_DMA2D_CLUTLOADINGCPLT_CB_ID DMA2D CLUT loading completion Callback ID
00433   *          @arg @ref HAL_DMA2D_MSPINIT_CB_ID DMA2D MspInit callback ID
00434   *          @arg @ref HAL_DMA2D_MSPDEINIT_CB_ID DMA2D MspDeInit callback ID
00435   * @param pCallback pointer to the Callback function
00436   * @note No weak predefined callbacks are defined for HAL_DMA2D_TRANSFERCOMPLETE_CB_ID or HAL_DMA2D_TRANSFERERROR_CB_ID
00437   * @retval status
00438   */
00439 HAL_StatusTypeDef HAL_DMA2D_RegisterCallback(DMA2D_HandleTypeDef *hdma2d, HAL_DMA2D_CallbackIDTypeDef CallbackID,
00440                                              pDMA2D_CallbackTypeDef pCallback)
00441 {
00442   HAL_StatusTypeDef status = HAL_OK;
00443 
00444   if (pCallback == NULL)
00445   {
00446     /* Update the error code */
00447     hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
00448     return HAL_ERROR;
00449   }
00450   /* Process locked */
00451   __HAL_LOCK(hdma2d);
00452 
00453   if (HAL_DMA2D_STATE_READY == hdma2d->State)
00454   {
00455     switch (CallbackID)
00456     {
00457       case HAL_DMA2D_TRANSFERCOMPLETE_CB_ID :
00458         hdma2d->XferCpltCallback = pCallback;
00459         break;
00460 
00461       case HAL_DMA2D_TRANSFERERROR_CB_ID :
00462         hdma2d->XferErrorCallback = pCallback;
00463         break;
00464 
00465       case HAL_DMA2D_LINEEVENT_CB_ID :
00466         hdma2d->LineEventCallback = pCallback;
00467         break;
00468 
00469       case HAL_DMA2D_CLUTLOADINGCPLT_CB_ID :
00470         hdma2d->CLUTLoadingCpltCallback = pCallback;
00471         break;
00472 
00473       case HAL_DMA2D_MSPINIT_CB_ID :
00474         hdma2d->MspInitCallback = pCallback;
00475         break;
00476 
00477       case HAL_DMA2D_MSPDEINIT_CB_ID :
00478         hdma2d->MspDeInitCallback = pCallback;
00479         break;
00480 
00481       default :
00482         /* Update the error code */
00483         hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
00484         /* update return status */
00485         status =  HAL_ERROR;
00486         break;
00487     }
00488   }
00489   else if (HAL_DMA2D_STATE_RESET == hdma2d->State)
00490   {
00491     switch (CallbackID)
00492     {
00493       case HAL_DMA2D_MSPINIT_CB_ID :
00494         hdma2d->MspInitCallback = pCallback;
00495         break;
00496 
00497       case HAL_DMA2D_MSPDEINIT_CB_ID :
00498         hdma2d->MspDeInitCallback = pCallback;
00499         break;
00500 
00501       default :
00502         /* Update the error code */
00503         hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
00504         /* update return status */
00505         status =  HAL_ERROR;
00506         break;
00507     }
00508   }
00509   else
00510   {
00511     /* Update the error code */
00512     hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
00513     /* update return status */
00514     status =  HAL_ERROR;
00515   }
00516 
00517   /* Release Lock */
00518   __HAL_UNLOCK(hdma2d);
00519   return status;
00520 }
00521 
00522 /**
00523   * @brief  Unregister a DMA2D Callback
00524   *         DMA2D Callback is redirected to the weak (surcharged) predefined callback
00525   * @param hdma2d DMA2D handle
00526   * @param CallbackID ID of the callback to be unregistered
00527   *        This parameter can be one of the following values:
00528   *          @arg @ref HAL_DMA2D_TRANSFERCOMPLETE_CB_ID DMA2D transfer complete Callback ID
00529   *          @arg @ref HAL_DMA2D_TRANSFERERROR_CB_ID DMA2D transfer error Callback ID
00530   *          @arg @ref HAL_DMA2D_LINEEVENT_CB_ID DMA2D line event Callback ID
00531   *          @arg @ref HAL_DMA2D_CLUTLOADINGCPLT_CB_ID DMA2D CLUT loading completion Callback ID
00532   *          @arg @ref HAL_DMA2D_MSPINIT_CB_ID DMA2D MspInit callback ID
00533   *          @arg @ref HAL_DMA2D_MSPDEINIT_CB_ID DMA2D MspDeInit callback ID
00534   * @note No weak predefined callbacks are defined for HAL_DMA2D_TRANSFERCOMPLETE_CB_ID or HAL_DMA2D_TRANSFERERROR_CB_ID
00535   * @retval status
00536   */
00537 HAL_StatusTypeDef HAL_DMA2D_UnRegisterCallback(DMA2D_HandleTypeDef *hdma2d, HAL_DMA2D_CallbackIDTypeDef CallbackID)
00538 {
00539   HAL_StatusTypeDef status = HAL_OK;
00540 
00541   /* Process locked */
00542   __HAL_LOCK(hdma2d);
00543 
00544   if (HAL_DMA2D_STATE_READY == hdma2d->State)
00545   {
00546     switch (CallbackID)
00547     {
00548       case HAL_DMA2D_TRANSFERCOMPLETE_CB_ID :
00549         hdma2d->XferCpltCallback = NULL;
00550         break;
00551 
00552       case HAL_DMA2D_TRANSFERERROR_CB_ID :
00553         hdma2d->XferErrorCallback = NULL;
00554         break;
00555 
00556       case HAL_DMA2D_LINEEVENT_CB_ID :
00557         hdma2d->LineEventCallback = HAL_DMA2D_LineEventCallback;
00558         break;
00559 
00560       case HAL_DMA2D_CLUTLOADINGCPLT_CB_ID :
00561         hdma2d->CLUTLoadingCpltCallback = HAL_DMA2D_CLUTLoadingCpltCallback;
00562         break;
00563 
00564       case HAL_DMA2D_MSPINIT_CB_ID :
00565         hdma2d->MspInitCallback = HAL_DMA2D_MspInit; /* Legacy weak (surcharged) Msp Init */
00566         break;
00567 
00568       case HAL_DMA2D_MSPDEINIT_CB_ID :
00569         hdma2d->MspDeInitCallback = HAL_DMA2D_MspDeInit; /* Legacy weak (surcharged) Msp DeInit */
00570         break;
00571 
00572       default :
00573         /* Update the error code */
00574         hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
00575         /* update return status */
00576         status =  HAL_ERROR;
00577         break;
00578     }
00579   }
00580   else if (HAL_DMA2D_STATE_RESET == hdma2d->State)
00581   {
00582     switch (CallbackID)
00583     {
00584       case HAL_DMA2D_MSPINIT_CB_ID :
00585         hdma2d->MspInitCallback = HAL_DMA2D_MspInit;   /* Legacy weak (surcharged) Msp Init */
00586         break;
00587 
00588       case HAL_DMA2D_MSPDEINIT_CB_ID :
00589         hdma2d->MspDeInitCallback = HAL_DMA2D_MspDeInit;  /* Legacy weak (surcharged) Msp DeInit */
00590         break;
00591 
00592       default :
00593         /* Update the error code */
00594         hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
00595         /* update return status */
00596         status =  HAL_ERROR;
00597         break;
00598     }
00599   }
00600   else
00601   {
00602     /* Update the error code */
00603     hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
00604     /* update return status */
00605     status =  HAL_ERROR;
00606   }
00607 
00608   /* Release Lock */
00609   __HAL_UNLOCK(hdma2d);
00610   return status;
00611 }
00612 #endif /* USE_HAL_DMA2D_REGISTER_CALLBACKS */
00613 
00614 /**
00615   * @}
00616   */
00617 
00618 
00619 /** @defgroup DMA2D_Exported_Functions_Group2 IO operation functions
00620   *  @brief   IO operation functions
00621   *
00622 @verbatim
00623  ===============================================================================
00624                       #####  IO operation functions  #####
00625  ===============================================================================
00626     [..]  This section provides functions allowing to:
00627       (+) Configure the pdata, destination address and data size then
00628           start the DMA2D transfer.
00629       (+) Configure the source for foreground and background, destination address
00630           and data size then start a MultiBuffer DMA2D transfer.
00631       (+) Configure the pdata, destination address and data size then
00632           start the DMA2D transfer with interrupt.
00633       (+) Configure the source for foreground and background, destination address
00634           and data size then start a MultiBuffer DMA2D transfer with interrupt.
00635       (+) Abort DMA2D transfer.
00636       (+) Suspend DMA2D transfer.
00637       (+) Resume DMA2D transfer.
00638       (+) Enable CLUT transfer.
00639       (+) Configure CLUT loading then start transfer in polling mode.
00640       (+) Configure CLUT loading then start transfer in interrupt mode.
00641       (+) Abort DMA2D CLUT loading.
00642       (+) Suspend DMA2D CLUT loading.
00643       (+) Resume DMA2D CLUT loading.
00644       (+) Poll for transfer complete.
00645       (+) handle DMA2D interrupt request.
00646       (+) Transfer watermark callback.
00647       (+) CLUT Transfer Complete callback.
00648 
00649 
00650 @endverbatim
00651   * @{
00652   */
00653 
00654 /**
00655   * @brief  Start the DMA2D Transfer.
00656   * @param  hdma2d     Pointer to a DMA2D_HandleTypeDef structure that contains
00657   *                     the configuration information for the DMA2D.
00658   * @param  pdata      Configure the source memory Buffer address if
00659   *                     Memory-to-Memory or Memory-to-Memory with pixel format
00660   *                     conversion mode is selected, or configure
00661   *                     the color value if Register-to-Memory mode is selected.
00662   * @param  DstAddress The destination memory Buffer address.
00663   * @param  Width      The width of data to be transferred from source
00664   *                    to destination (expressed in number of pixels per line).
00665   * @param  Height     The height of data to be transferred from source to destination (expressed in number of lines).
00666   * @retval HAL status
00667   */
00668 HAL_StatusTypeDef HAL_DMA2D_Start(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width,
00669                                   uint32_t Height)
00670 {
00671   /* Check the parameters */
00672   assert_param(IS_DMA2D_LINE(Height));
00673   assert_param(IS_DMA2D_PIXEL(Width));
00674 
00675   /* Process locked */
00676   __HAL_LOCK(hdma2d);
00677 
00678   /* Change DMA2D peripheral state */
00679   hdma2d->State = HAL_DMA2D_STATE_BUSY;
00680 
00681   /* Configure the source, destination address and the data size */
00682   DMA2D_SetConfig(hdma2d, pdata, DstAddress, Width, Height);
00683 
00684   /* Enable the Peripheral */
00685   __HAL_DMA2D_ENABLE(hdma2d);
00686 
00687   return HAL_OK;
00688 }
00689 
00690 /**
00691   * @brief  Start the DMA2D Transfer with interrupt enabled.
00692   * @param  hdma2d     Pointer to a DMA2D_HandleTypeDef structure that contains
00693   *                     the configuration information for the DMA2D.
00694   * @param  pdata      Configure the source memory Buffer address if
00695   *                     the Memory-to-Memory or Memory-to-Memory with pixel format
00696   *                     conversion mode is selected, or configure
00697   *                     the color value if Register-to-Memory mode is selected.
00698   * @param  DstAddress The destination memory Buffer address.
00699   * @param  Width      The width of data to be transferred from source
00700   *                    to destination (expressed in number of pixels per line).
00701   * @param  Height     The height of data to be transferred from source to destination (expressed in number of lines).
00702   * @retval HAL status
00703   */
00704 HAL_StatusTypeDef HAL_DMA2D_Start_IT(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width,
00705                                      uint32_t Height)
00706 {
00707   /* Check the parameters */
00708   assert_param(IS_DMA2D_LINE(Height));
00709   assert_param(IS_DMA2D_PIXEL(Width));
00710 
00711   /* Process locked */
00712   __HAL_LOCK(hdma2d);
00713 
00714   /* Change DMA2D peripheral state */
00715   hdma2d->State = HAL_DMA2D_STATE_BUSY;
00716 
00717   /* Configure the source, destination address and the data size */
00718   DMA2D_SetConfig(hdma2d, pdata, DstAddress, Width, Height);
00719 
00720   /* Enable the transfer complete, transfer error and configuration error interrupts */
00721   __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_TC | DMA2D_IT_TE | DMA2D_IT_CE);
00722 
00723   /* Enable the Peripheral */
00724   __HAL_DMA2D_ENABLE(hdma2d);
00725 
00726   return HAL_OK;
00727 }
00728 
00729 /**
00730   * @brief  Start the multi-source DMA2D Transfer.
00731   * @param  hdma2d      Pointer to a DMA2D_HandleTypeDef structure that contains
00732   *                      the configuration information for the DMA2D.
00733   * @param  SrcAddress1 The source memory Buffer address for the foreground layer.
00734   * @param  SrcAddress2 The source memory Buffer address for the background layer.
00735   * @param  DstAddress  The destination memory Buffer address.
00736   * @param  Width       The width of data to be transferred from source
00737   *                     to destination (expressed in number of pixels per line).
00738   * @param  Height      The height of data to be transferred from source to destination (expressed in number of lines).
00739   * @retval HAL status
00740   */
00741 HAL_StatusTypeDef HAL_DMA2D_BlendingStart(DMA2D_HandleTypeDef *hdma2d, uint32_t SrcAddress1, uint32_t  SrcAddress2,
00742                                           uint32_t DstAddress, uint32_t Width,  uint32_t Height)
00743 {
00744   /* Check the parameters */
00745   assert_param(IS_DMA2D_LINE(Height));
00746   assert_param(IS_DMA2D_PIXEL(Width));
00747 
00748   /* Process locked */
00749   __HAL_LOCK(hdma2d);
00750 
00751   /* Change DMA2D peripheral state */
00752   hdma2d->State = HAL_DMA2D_STATE_BUSY;
00753 
00754   /* Configure DMA2D Stream source2 address */
00755   WRITE_REG(hdma2d->Instance->BGMAR, SrcAddress2);
00756 
00757   /* Configure the source, destination address and the data size */
00758   DMA2D_SetConfig(hdma2d, SrcAddress1, DstAddress, Width, Height);
00759 
00760   /* Enable the Peripheral */
00761   __HAL_DMA2D_ENABLE(hdma2d);
00762 
00763   return HAL_OK;
00764 }
00765 
00766 /**
00767   * @brief  Start the multi-source DMA2D Transfer with interrupt enabled.
00768   * @param  hdma2d     Pointer to a DMA2D_HandleTypeDef structure that contains
00769   *                     the configuration information for the DMA2D.
00770   * @param  SrcAddress1 The source memory Buffer address for the foreground layer.
00771   * @param  SrcAddress2 The source memory Buffer address for the background layer.
00772   * @param  DstAddress  The destination memory Buffer address.
00773   * @param  Width       The width of data to be transferred from source
00774   *                     to destination (expressed in number of pixels per line).
00775   * @param  Height      The height of data to be transferred from source to destination (expressed in number of lines).
00776   * @retval HAL status
00777   */
00778 HAL_StatusTypeDef HAL_DMA2D_BlendingStart_IT(DMA2D_HandleTypeDef *hdma2d, uint32_t SrcAddress1, uint32_t  SrcAddress2,
00779                                              uint32_t DstAddress, uint32_t Width,  uint32_t Height)
00780 {
00781   /* Check the parameters */
00782   assert_param(IS_DMA2D_LINE(Height));
00783   assert_param(IS_DMA2D_PIXEL(Width));
00784 
00785   /* Process locked */
00786   __HAL_LOCK(hdma2d);
00787 
00788   /* Change DMA2D peripheral state */
00789   hdma2d->State = HAL_DMA2D_STATE_BUSY;
00790 
00791   /* Configure DMA2D Stream source2 address */
00792   WRITE_REG(hdma2d->Instance->BGMAR, SrcAddress2);
00793 
00794   /* Configure the source, destination address and the data size */
00795   DMA2D_SetConfig(hdma2d, SrcAddress1, DstAddress, Width, Height);
00796 
00797   /* Enable the transfer complete, transfer error and configuration error interrupts */
00798   __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_TC | DMA2D_IT_TE | DMA2D_IT_CE);
00799 
00800   /* Enable the Peripheral */
00801   __HAL_DMA2D_ENABLE(hdma2d);
00802 
00803   return HAL_OK;
00804 }
00805 
00806 /**
00807   * @brief  Abort the DMA2D Transfer.
00808   * @param  hdma2d  pointer to a DMA2D_HandleTypeDef structure that contains
00809   *                  the configuration information for the DMA2D.
00810   * @retval HAL status
00811   */
00812 HAL_StatusTypeDef HAL_DMA2D_Abort(DMA2D_HandleTypeDef *hdma2d)
00813 {
00814   uint32_t tickstart;
00815 
00816   /* Abort the DMA2D transfer */
00817   /* START bit is reset to make sure not to set it again, in the event the HW clears it
00818      between the register read and the register write by the CPU (writing 0 has no
00819      effect on START bitvalue) */
00820   MODIFY_REG(hdma2d->Instance->CR, DMA2D_CR_ABORT | DMA2D_CR_START, DMA2D_CR_ABORT);
00821 
00822   /* Get tick */
00823   tickstart = HAL_GetTick();
00824 
00825   /* Check if the DMA2D is effectively disabled */
00826   while ((hdma2d->Instance->CR & DMA2D_CR_START) != 0U)
00827   {
00828     if ((HAL_GetTick() - tickstart) > DMA2D_TIMEOUT_ABORT)
00829     {
00830       /* Update error code */
00831       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
00832 
00833       /* Change the DMA2D state */
00834       hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
00835 
00836       /* Process Unlocked */
00837       __HAL_UNLOCK(hdma2d);
00838 
00839       return HAL_TIMEOUT;
00840     }
00841   }
00842 
00843   /* Disable the Transfer Complete, Transfer Error and Configuration Error interrupts */
00844   __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TC | DMA2D_IT_TE | DMA2D_IT_CE);
00845 
00846   /* Change the DMA2D state*/
00847   hdma2d->State = HAL_DMA2D_STATE_READY;
00848 
00849   /* Process Unlocked */
00850   __HAL_UNLOCK(hdma2d);
00851 
00852   return HAL_OK;
00853 }
00854 
00855 /**
00856   * @brief  Suspend the DMA2D Transfer.
00857   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
00858   *                 the configuration information for the DMA2D.
00859   * @retval HAL status
00860   */
00861 HAL_StatusTypeDef HAL_DMA2D_Suspend(DMA2D_HandleTypeDef *hdma2d)
00862 {
00863   uint32_t tickstart;
00864 
00865   /* Suspend the DMA2D transfer */
00866   /* START bit is reset to make sure not to set it again, in the event the HW clears it
00867      between the register read and the register write by the CPU (writing 0 has no
00868      effect on START bitvalue). */
00869   MODIFY_REG(hdma2d->Instance->CR, DMA2D_CR_SUSP | DMA2D_CR_START, DMA2D_CR_SUSP);
00870 
00871   /* Get tick */
00872   tickstart = HAL_GetTick();
00873 
00874   /* Check if the DMA2D is effectively suspended */
00875   while ((hdma2d->Instance->CR & (DMA2D_CR_SUSP | DMA2D_CR_START)) == DMA2D_CR_START)
00876   {
00877     if ((HAL_GetTick() - tickstart) > DMA2D_TIMEOUT_SUSPEND)
00878     {
00879       /* Update error code */
00880       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
00881 
00882       /* Change the DMA2D state */
00883       hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
00884 
00885       return HAL_TIMEOUT;
00886     }
00887   }
00888 
00889   /* Check whether or not a transfer is actually suspended and change the DMA2D state accordingly */
00890   if ((hdma2d->Instance->CR & DMA2D_CR_START) != 0U)
00891   {
00892     hdma2d->State = HAL_DMA2D_STATE_SUSPEND;
00893   }
00894   else
00895   {
00896     /* Make sure SUSP bit is cleared since it is meaningless
00897        when no transfer is on-going */
00898     CLEAR_BIT(hdma2d->Instance->CR, DMA2D_CR_SUSP);
00899   }
00900 
00901   return HAL_OK;
00902 }
00903 
00904 /**
00905   * @brief  Resume the DMA2D Transfer.
00906   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
00907   *                 the configuration information for the DMA2D.
00908   * @retval HAL status
00909   */
00910 HAL_StatusTypeDef HAL_DMA2D_Resume(DMA2D_HandleTypeDef *hdma2d)
00911 {
00912   /* Check the SUSP and START bits */
00913   if ((hdma2d->Instance->CR & (DMA2D_CR_SUSP | DMA2D_CR_START)) == (DMA2D_CR_SUSP | DMA2D_CR_START))
00914   {
00915     /* Ongoing transfer is suspended: change the DMA2D state before resuming */
00916     hdma2d->State = HAL_DMA2D_STATE_BUSY;
00917   }
00918 
00919   /* Resume the DMA2D transfer */
00920   /* START bit is reset to make sure not to set it again, in the event the HW clears it
00921      between the register read and the register write by the CPU (writing 0 has no
00922      effect on START bitvalue). */
00923   CLEAR_BIT(hdma2d->Instance->CR, (DMA2D_CR_SUSP | DMA2D_CR_START));
00924 
00925   return HAL_OK;
00926 }
00927 
00928 
00929 /**
00930   * @brief  Enable the DMA2D CLUT Transfer.
00931   * @param  hdma2d   Pointer to a DMA2D_HandleTypeDef structure that contains
00932   *                   the configuration information for the DMA2D.
00933   * @param  LayerIdx DMA2D Layer index.
00934   *                   This parameter can be one of the following values:
00935   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
00936   * @retval HAL status
00937   */
00938 HAL_StatusTypeDef HAL_DMA2D_EnableCLUT(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
00939 {
00940   /* Check the parameters */
00941   assert_param(IS_DMA2D_LAYER(LayerIdx));
00942 
00943   /* Process locked */
00944   __HAL_LOCK(hdma2d);
00945 
00946   /* Change DMA2D peripheral state */
00947   hdma2d->State = HAL_DMA2D_STATE_BUSY;
00948 
00949   if (LayerIdx == DMA2D_BACKGROUND_LAYER)
00950   {
00951     /* Enable the background CLUT loading */
00952     SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
00953   }
00954   else
00955   {
00956     /* Enable the foreground CLUT loading */
00957     SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
00958   }
00959 
00960   return HAL_OK;
00961 }
00962 
00963 /**
00964   * @brief  Start DMA2D CLUT Loading.
00965   * @param  hdma2d   Pointer to a DMA2D_HandleTypeDef structure that contains
00966   *                   the configuration information for the DMA2D.
00967   * @param  CLUTCfg  Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
00968   *                   the configuration information for the color look up table.
00969   * @param  LayerIdx DMA2D Layer index.
00970   *                   This parameter can be one of the following values:
00971   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
00972   * @retval HAL status
00973   */
00974 HAL_StatusTypeDef HAL_DMA2D_CLUTStartLoad(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef *CLUTCfg, uint32_t LayerIdx)
00975 {
00976   /* Check the parameters */
00977   assert_param(IS_DMA2D_LAYER(LayerIdx));
00978   assert_param(IS_DMA2D_CLUT_CM(CLUTCfg->CLUTColorMode));
00979   assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg->Size));
00980 
00981   /* Process locked */
00982   __HAL_LOCK(hdma2d);
00983 
00984   /* Change DMA2D peripheral state */
00985   hdma2d->State = HAL_DMA2D_STATE_BUSY;
00986 
00987   /* Configure the CLUT of the background DMA2D layer */
00988   if (LayerIdx == DMA2D_BACKGROUND_LAYER)
00989   {
00990     /* Write background CLUT memory address */
00991     WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg->pCLUT);
00992 
00993     /* Write background CLUT size and CLUT color mode */
00994     MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
00995                ((CLUTCfg->Size << DMA2D_BGPFCCR_CS_Pos) | (CLUTCfg->CLUTColorMode << DMA2D_BGPFCCR_CCM_Pos)));
00996 
00997     /* Enable the CLUT loading for the background */
00998     SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
00999   }
01000   /* Configure the CLUT of the foreground DMA2D layer */
01001   else
01002   {
01003     /* Write foreground CLUT memory address */
01004     WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg->pCLUT);
01005 
01006     /* Write foreground CLUT size and CLUT color mode */
01007     MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
01008                ((CLUTCfg->Size << DMA2D_FGPFCCR_CS_Pos) | (CLUTCfg->CLUTColorMode << DMA2D_FGPFCCR_CCM_Pos)));
01009 
01010     /* Enable the CLUT loading for the foreground */
01011     SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
01012   }
01013 
01014   return HAL_OK;
01015 }
01016 
01017 /**
01018   * @brief  Start DMA2D CLUT Loading with interrupt enabled.
01019   * @param  hdma2d   Pointer to a DMA2D_HandleTypeDef structure that contains
01020   *                   the configuration information for the DMA2D.
01021   * @param  CLUTCfg  Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
01022   *                   the configuration information for the color look up table.
01023   * @param  LayerIdx DMA2D Layer index.
01024   *                   This parameter can be one of the following values:
01025   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
01026   * @retval HAL status
01027   */
01028 HAL_StatusTypeDef HAL_DMA2D_CLUTStartLoad_IT(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef *CLUTCfg,
01029                                              uint32_t LayerIdx)
01030 {
01031   /* Check the parameters */
01032   assert_param(IS_DMA2D_LAYER(LayerIdx));
01033   assert_param(IS_DMA2D_CLUT_CM(CLUTCfg->CLUTColorMode));
01034   assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg->Size));
01035 
01036   /* Process locked */
01037   __HAL_LOCK(hdma2d);
01038 
01039   /* Change DMA2D peripheral state */
01040   hdma2d->State = HAL_DMA2D_STATE_BUSY;
01041 
01042   /* Configure the CLUT of the background DMA2D layer */
01043   if (LayerIdx == DMA2D_BACKGROUND_LAYER)
01044   {
01045     /* Write background CLUT memory address */
01046     WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg->pCLUT);
01047 
01048     /* Write background CLUT size and CLUT color mode */
01049     MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
01050                ((CLUTCfg->Size << DMA2D_BGPFCCR_CS_Pos) | (CLUTCfg->CLUTColorMode << DMA2D_BGPFCCR_CCM_Pos)));
01051 
01052     /* Enable the CLUT Transfer Complete, transfer Error, configuration Error and CLUT Access Error interrupts */
01053     __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE | DMA2D_IT_CAE);
01054 
01055     /* Enable the CLUT loading for the background */
01056     SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
01057   }
01058   /* Configure the CLUT of the foreground DMA2D layer */
01059   else
01060   {
01061     /* Write foreground CLUT memory address */
01062     WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg->pCLUT);
01063 
01064     /* Write foreground CLUT size and CLUT color mode */
01065     MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
01066                ((CLUTCfg->Size << DMA2D_FGPFCCR_CS_Pos) | (CLUTCfg->CLUTColorMode << DMA2D_FGPFCCR_CCM_Pos)));
01067 
01068     /* Enable the CLUT Transfer Complete, transfer Error, configuration Error and CLUT Access Error interrupts */
01069     __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE | DMA2D_IT_CAE);
01070 
01071     /* Enable the CLUT loading for the foreground */
01072     SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
01073   }
01074 
01075   return HAL_OK;
01076 }
01077 
01078 /**
01079   * @brief  Start DMA2D CLUT Loading.
01080   * @param  hdma2d   Pointer to a DMA2D_HandleTypeDef structure that contains
01081   *                   the configuration information for the DMA2D.
01082   * @param  CLUTCfg  Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
01083   *                   the configuration information for the color look up table.
01084   * @param  LayerIdx DMA2D Layer index.
01085   *                   This parameter can be one of the following values:
01086   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
01087   * @note API obsolete and maintained for compatibility with legacy. User is
01088   *      invited to resort to HAL_DMA2D_CLUTStartLoad() instead to benefit from
01089   *      code compactness, code size and improved heap usage.
01090   * @retval HAL status
01091   */
01092 HAL_StatusTypeDef HAL_DMA2D_CLUTLoad(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef CLUTCfg, uint32_t LayerIdx)
01093 {
01094   /* Check the parameters */
01095   assert_param(IS_DMA2D_LAYER(LayerIdx));
01096   assert_param(IS_DMA2D_CLUT_CM(CLUTCfg.CLUTColorMode));
01097   assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg.Size));
01098 
01099   /* Process locked */
01100   __HAL_LOCK(hdma2d);
01101 
01102   /* Change DMA2D peripheral state */
01103   hdma2d->State = HAL_DMA2D_STATE_BUSY;
01104 
01105   /* Configure the CLUT of the background DMA2D layer */
01106   if (LayerIdx == DMA2D_BACKGROUND_LAYER)
01107   {
01108     /* Write background CLUT memory address */
01109     WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg.pCLUT);
01110 
01111     /* Write background CLUT size and CLUT color mode */
01112     MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
01113                ((CLUTCfg.Size << DMA2D_BGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_BGPFCCR_CCM_Pos)));
01114 
01115     /* Enable the CLUT loading for the background */
01116     SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
01117   }
01118   /* Configure the CLUT of the foreground DMA2D layer */
01119   else
01120   {
01121     /* Write foreground CLUT memory address */
01122     WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg.pCLUT);
01123 
01124     /* Write foreground CLUT size and CLUT color mode */
01125     MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
01126                ((CLUTCfg.Size << DMA2D_FGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_FGPFCCR_CCM_Pos)));
01127 
01128     /* Enable the CLUT loading for the foreground */
01129     SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
01130   }
01131 
01132   return HAL_OK;
01133 }
01134 
01135 /**
01136   * @brief  Start DMA2D CLUT Loading with interrupt enabled.
01137   * @param  hdma2d   Pointer to a DMA2D_HandleTypeDef structure that contains
01138   *                   the configuration information for the DMA2D.
01139   * @param  CLUTCfg  Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
01140   *                   the configuration information for the color look up table.
01141   * @param  LayerIdx DMA2D Layer index.
01142   *                   This parameter can be one of the following values:
01143   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
01144   * @note API obsolete and maintained for compatibility with legacy. User is
01145   *      invited to resort to HAL_DMA2D_CLUTStartLoad_IT() instead to benefit
01146   *      from code compactness, code size and improved heap usage.
01147   * @retval HAL status
01148   */
01149 HAL_StatusTypeDef HAL_DMA2D_CLUTLoad_IT(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef CLUTCfg, uint32_t LayerIdx)
01150 {
01151   /* Check the parameters */
01152   assert_param(IS_DMA2D_LAYER(LayerIdx));
01153   assert_param(IS_DMA2D_CLUT_CM(CLUTCfg.CLUTColorMode));
01154   assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg.Size));
01155 
01156   /* Process locked */
01157   __HAL_LOCK(hdma2d);
01158 
01159   /* Change DMA2D peripheral state */
01160   hdma2d->State = HAL_DMA2D_STATE_BUSY;
01161 
01162   /* Configure the CLUT of the background DMA2D layer */
01163   if (LayerIdx == DMA2D_BACKGROUND_LAYER)
01164   {
01165     /* Write background CLUT memory address */
01166     WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg.pCLUT);
01167 
01168     /* Write background CLUT size and CLUT color mode */
01169     MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
01170                ((CLUTCfg.Size << DMA2D_BGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_BGPFCCR_CCM_Pos)));
01171 
01172     /* Enable the CLUT Transfer Complete, transfer Error, configuration Error and CLUT Access Error interrupts */
01173     __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE | DMA2D_IT_CAE);
01174 
01175     /* Enable the CLUT loading for the background */
01176     SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
01177   }
01178   /* Configure the CLUT of the foreground DMA2D layer */
01179   else
01180   {
01181     /* Write foreground CLUT memory address */
01182     WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg.pCLUT);
01183 
01184     /* Write foreground CLUT size and CLUT color mode */
01185     MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
01186                ((CLUTCfg.Size << DMA2D_FGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_FGPFCCR_CCM_Pos)));
01187 
01188     /* Enable the CLUT Transfer Complete, transfer Error, configuration Error and CLUT Access Error interrupts */
01189     __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE | DMA2D_IT_CAE);
01190 
01191     /* Enable the CLUT loading for the foreground */
01192     SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
01193   }
01194 
01195   return HAL_OK;
01196 }
01197 
01198 /**
01199   * @brief  Abort the DMA2D CLUT loading.
01200   * @param  hdma2d  Pointer to a DMA2D_HandleTypeDef structure that contains
01201   *                  the configuration information for the DMA2D.
01202   * @param  LayerIdx DMA2D Layer index.
01203   *                   This parameter can be one of the following values:
01204   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
01205   * @retval HAL status
01206   */
01207 HAL_StatusTypeDef HAL_DMA2D_CLUTLoading_Abort(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
01208 {
01209   uint32_t tickstart;
01210   const __IO uint32_t *reg =  &(hdma2d->Instance->BGPFCCR);  /* by default, point at background register */
01211 
01212   /* Abort the CLUT loading */
01213   SET_BIT(hdma2d->Instance->CR, DMA2D_CR_ABORT);
01214 
01215   /* If foreground CLUT loading is considered, update local variables */
01216   if (LayerIdx == DMA2D_FOREGROUND_LAYER)
01217   {
01218     reg  = &(hdma2d->Instance->FGPFCCR);
01219   }
01220 
01221 
01222   /* Get tick */
01223   tickstart = HAL_GetTick();
01224 
01225   /* Check if the CLUT loading is aborted */
01226   while ((*reg & DMA2D_BGPFCCR_START) != 0U)
01227   {
01228     if ((HAL_GetTick() - tickstart) > DMA2D_TIMEOUT_ABORT)
01229     {
01230       /* Update error code */
01231       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
01232 
01233       /* Change the DMA2D state */
01234       hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
01235 
01236       /* Process Unlocked */
01237       __HAL_UNLOCK(hdma2d);
01238 
01239       return HAL_TIMEOUT;
01240     }
01241   }
01242 
01243   /* Disable the CLUT Transfer Complete, Transfer Error, Configuration Error and CLUT Access Error interrupts */
01244   __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE | DMA2D_IT_CAE);
01245 
01246   /* Change the DMA2D state*/
01247   hdma2d->State = HAL_DMA2D_STATE_READY;
01248 
01249   /* Process Unlocked */
01250   __HAL_UNLOCK(hdma2d);
01251 
01252   return HAL_OK;
01253 }
01254 
01255 /**
01256   * @brief  Suspend the DMA2D CLUT loading.
01257   * @param  hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
01258   *                 the configuration information for the DMA2D.
01259   * @param  LayerIdx DMA2D Layer index.
01260   *                   This parameter can be one of the following values:
01261   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
01262   * @retval HAL status
01263   */
01264 HAL_StatusTypeDef HAL_DMA2D_CLUTLoading_Suspend(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
01265 {
01266   uint32_t tickstart;
01267   uint32_t loadsuspended;
01268   const __IO uint32_t *reg =  &(hdma2d->Instance->BGPFCCR);  /* by default, point at background register */
01269 
01270   /* Suspend the CLUT loading */
01271   SET_BIT(hdma2d->Instance->CR, DMA2D_CR_SUSP);
01272 
01273   /* If foreground CLUT loading is considered, update local variables */
01274   if (LayerIdx == DMA2D_FOREGROUND_LAYER)
01275   {
01276     reg  = &(hdma2d->Instance->FGPFCCR);
01277   }
01278 
01279   /* Get tick */
01280   tickstart = HAL_GetTick();
01281 
01282   /* Check if the CLUT loading is suspended */
01283   /* 1st condition: Suspend Check */
01284   loadsuspended = ((hdma2d->Instance->CR & DMA2D_CR_SUSP) == DMA2D_CR_SUSP) ? 1UL : 0UL;
01285   /* 2nd condition: Not Start Check */
01286   loadsuspended |= ((*reg & DMA2D_BGPFCCR_START) != DMA2D_BGPFCCR_START) ? 1UL : 0UL;
01287   while (loadsuspended == 0UL)
01288   {
01289     if ((HAL_GetTick() - tickstart) > DMA2D_TIMEOUT_SUSPEND)
01290     {
01291       /* Update error code */
01292       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
01293 
01294       /* Change the DMA2D state */
01295       hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
01296 
01297       return HAL_TIMEOUT;
01298     }
01299     /* 1st condition: Suspend Check */
01300     loadsuspended = ((hdma2d->Instance->CR & DMA2D_CR_SUSP) == DMA2D_CR_SUSP) ? 1UL : 0UL;
01301     /* 2nd condition: Not Start Check */
01302     loadsuspended |= ((*reg & DMA2D_BGPFCCR_START) != DMA2D_BGPFCCR_START) ? 1UL : 0UL;
01303   }
01304 
01305   /* Check whether or not a transfer is actually suspended and change the DMA2D state accordingly */
01306   if ((*reg & DMA2D_BGPFCCR_START) != 0U)
01307   {
01308     hdma2d->State = HAL_DMA2D_STATE_SUSPEND;
01309   }
01310   else
01311   {
01312     /* Make sure SUSP bit is cleared since it is meaningless
01313        when no transfer is on-going */
01314     CLEAR_BIT(hdma2d->Instance->CR, DMA2D_CR_SUSP);
01315   }
01316 
01317   return HAL_OK;
01318 }
01319 
01320 /**
01321   * @brief  Resume the DMA2D CLUT loading.
01322   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
01323   *                 the configuration information for the DMA2D.
01324   * @param  LayerIdx DMA2D Layer index.
01325   *                   This parameter can be one of the following values:
01326   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
01327   * @retval HAL status
01328   */
01329 HAL_StatusTypeDef HAL_DMA2D_CLUTLoading_Resume(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
01330 {
01331   /* Check the SUSP and START bits for background or foreground CLUT loading */
01332   if (LayerIdx == DMA2D_BACKGROUND_LAYER)
01333   {
01334     /* Background CLUT loading suspension check */
01335     if ((hdma2d->Instance->CR & DMA2D_CR_SUSP) == DMA2D_CR_SUSP)
01336     {
01337       if ((hdma2d->Instance->BGPFCCR & DMA2D_BGPFCCR_START) == DMA2D_BGPFCCR_START)
01338       {
01339         /* Ongoing CLUT loading is suspended: change the DMA2D state before resuming */
01340         hdma2d->State = HAL_DMA2D_STATE_BUSY;
01341       }
01342     }
01343   }
01344   else
01345   {
01346     /* Foreground CLUT loading suspension check */
01347     if ((hdma2d->Instance->CR & DMA2D_CR_SUSP) == DMA2D_CR_SUSP)
01348     {
01349       if ((hdma2d->Instance->FGPFCCR & DMA2D_FGPFCCR_START) == DMA2D_FGPFCCR_START)
01350       {
01351         /* Ongoing CLUT loading is suspended: change the DMA2D state before resuming */
01352         hdma2d->State = HAL_DMA2D_STATE_BUSY;
01353       }
01354     }
01355   }
01356 
01357   /* Resume the CLUT loading */
01358   CLEAR_BIT(hdma2d->Instance->CR, DMA2D_CR_SUSP);
01359 
01360   return HAL_OK;
01361 }
01362 
01363 
01364 /**
01365 
01366   * @brief  Polling for transfer complete or CLUT loading.
01367   * @param  hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
01368   *                 the configuration information for the DMA2D.
01369   * @param  Timeout Timeout duration
01370   * @retval HAL status
01371   */
01372 HAL_StatusTypeDef HAL_DMA2D_PollForTransfer(DMA2D_HandleTypeDef *hdma2d, uint32_t Timeout)
01373 {
01374   uint32_t tickstart;
01375   uint32_t layer_start;
01376   __IO uint32_t isrflags = 0x0U;
01377 
01378   /* Polling for DMA2D transfer */
01379   if ((hdma2d->Instance->CR & DMA2D_CR_START) != 0U)
01380   {
01381     /* Get tick */
01382     tickstart = HAL_GetTick();
01383 
01384     while (__HAL_DMA2D_GET_FLAG(hdma2d, DMA2D_FLAG_TC) == 0U)
01385     {
01386       isrflags = READ_REG(hdma2d->Instance->ISR);
01387       if ((isrflags & (DMA2D_FLAG_CE | DMA2D_FLAG_TE)) != 0U)
01388       {
01389         if ((isrflags & DMA2D_FLAG_CE) != 0U)
01390         {
01391           hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CE;
01392         }
01393         if ((isrflags & DMA2D_FLAG_TE) != 0U)
01394         {
01395           hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TE;
01396         }
01397         /* Clear the transfer and configuration error flags */
01398         __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CE | DMA2D_FLAG_TE);
01399 
01400         /* Change DMA2D state */
01401         hdma2d->State = HAL_DMA2D_STATE_ERROR;
01402 
01403         /* Process unlocked */
01404         __HAL_UNLOCK(hdma2d);
01405 
01406         return HAL_ERROR;
01407       }
01408       /* Check for the Timeout */
01409       if (Timeout != HAL_MAX_DELAY)
01410       {
01411         if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
01412         {
01413           /* Update error code */
01414           hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
01415 
01416           /* Change the DMA2D state */
01417           hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
01418 
01419           /* Process unlocked */
01420           __HAL_UNLOCK(hdma2d);
01421 
01422           return HAL_TIMEOUT;
01423         }
01424       }
01425     }
01426   }
01427   /* Polling for CLUT loading (foreground or background) */
01428   layer_start = hdma2d->Instance->FGPFCCR & DMA2D_FGPFCCR_START;
01429   layer_start |= hdma2d->Instance->BGPFCCR & DMA2D_BGPFCCR_START;
01430   if (layer_start != 0U)
01431   {
01432     /* Get tick */
01433     tickstart = HAL_GetTick();
01434 
01435     while (__HAL_DMA2D_GET_FLAG(hdma2d, DMA2D_FLAG_CTC) == 0U)
01436     {
01437       isrflags = READ_REG(hdma2d->Instance->ISR);
01438       if ((isrflags & (DMA2D_FLAG_CAE | DMA2D_FLAG_CE | DMA2D_FLAG_TE)) != 0U)
01439       {
01440         if ((isrflags & DMA2D_FLAG_CAE) != 0U)
01441         {
01442           hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CAE;
01443         }
01444         if ((isrflags & DMA2D_FLAG_CE) != 0U)
01445         {
01446           hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CE;
01447         }
01448         if ((isrflags & DMA2D_FLAG_TE) != 0U)
01449         {
01450           hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TE;
01451         }
01452         /* Clear the CLUT Access Error, Configuration Error and Transfer Error flags */
01453         __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CAE | DMA2D_FLAG_CE | DMA2D_FLAG_TE);
01454 
01455         /* Change DMA2D state */
01456         hdma2d->State = HAL_DMA2D_STATE_ERROR;
01457 
01458         /* Process unlocked */
01459         __HAL_UNLOCK(hdma2d);
01460 
01461         return HAL_ERROR;
01462       }
01463       /* Check for the Timeout */
01464       if (Timeout != HAL_MAX_DELAY)
01465       {
01466         if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
01467         {
01468           /* Update error code */
01469           hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
01470 
01471           /* Change the DMA2D state */
01472           hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
01473 
01474           /* Process unlocked */
01475           __HAL_UNLOCK(hdma2d);
01476 
01477           return HAL_TIMEOUT;
01478         }
01479       }
01480     }
01481   }
01482 
01483   /* Clear the transfer complete and CLUT loading flags */
01484   __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TC | DMA2D_FLAG_CTC);
01485 
01486   /* Change DMA2D state */
01487   hdma2d->State = HAL_DMA2D_STATE_READY;
01488 
01489   /* Process unlocked */
01490   __HAL_UNLOCK(hdma2d);
01491 
01492   return HAL_OK;
01493 }
01494 /**
01495   * @brief  Handle DMA2D interrupt request.
01496   * @param  hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
01497   *                 the configuration information for the DMA2D.
01498   * @retval HAL status
01499   */
01500 void HAL_DMA2D_IRQHandler(DMA2D_HandleTypeDef *hdma2d)
01501 {
01502   uint32_t isrflags = READ_REG(hdma2d->Instance->ISR);
01503   uint32_t crflags = READ_REG(hdma2d->Instance->CR);
01504 
01505   /* Transfer Error Interrupt management ***************************************/
01506   if ((isrflags & DMA2D_FLAG_TE) != 0U)
01507   {
01508     if ((crflags & DMA2D_IT_TE) != 0U)
01509     {
01510       /* Disable the transfer Error interrupt */
01511       __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TE);
01512 
01513       /* Update error code */
01514       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TE;
01515 
01516       /* Clear the transfer error flag */
01517       __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TE);
01518 
01519       /* Change DMA2D state */
01520       hdma2d->State = HAL_DMA2D_STATE_ERROR;
01521 
01522       /* Process Unlocked */
01523       __HAL_UNLOCK(hdma2d);
01524 
01525       if (hdma2d->XferErrorCallback != NULL)
01526       {
01527         /* Transfer error Callback */
01528         hdma2d->XferErrorCallback(hdma2d);
01529       }
01530     }
01531   }
01532   /* Configuration Error Interrupt management **********************************/
01533   if ((isrflags & DMA2D_FLAG_CE) != 0U)
01534   {
01535     if ((crflags & DMA2D_IT_CE) != 0U)
01536     {
01537       /* Disable the Configuration Error interrupt */
01538       __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CE);
01539 
01540       /* Clear the Configuration error flag */
01541       __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CE);
01542 
01543       /* Update error code */
01544       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CE;
01545 
01546       /* Change DMA2D state */
01547       hdma2d->State = HAL_DMA2D_STATE_ERROR;
01548 
01549       /* Process Unlocked */
01550       __HAL_UNLOCK(hdma2d);
01551 
01552       if (hdma2d->XferErrorCallback != NULL)
01553       {
01554         /* Transfer error Callback */
01555         hdma2d->XferErrorCallback(hdma2d);
01556       }
01557     }
01558   }
01559   /* CLUT access Error Interrupt management ***********************************/
01560   if ((isrflags & DMA2D_FLAG_CAE) != 0U)
01561   {
01562     if ((crflags & DMA2D_IT_CAE) != 0U)
01563     {
01564       /* Disable the CLUT access error interrupt */
01565       __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CAE);
01566 
01567       /* Clear the CLUT access error flag */
01568       __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CAE);
01569 
01570       /* Update error code */
01571       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CAE;
01572 
01573       /* Change DMA2D state */
01574       hdma2d->State = HAL_DMA2D_STATE_ERROR;
01575 
01576       /* Process Unlocked */
01577       __HAL_UNLOCK(hdma2d);
01578 
01579       if (hdma2d->XferErrorCallback != NULL)
01580       {
01581         /* Transfer error Callback */
01582         hdma2d->XferErrorCallback(hdma2d);
01583       }
01584     }
01585   }
01586   /* Transfer watermark Interrupt management **********************************/
01587   if ((isrflags & DMA2D_FLAG_TW) != 0U)
01588   {
01589     if ((crflags & DMA2D_IT_TW) != 0U)
01590     {
01591       /* Disable the transfer watermark interrupt */
01592       __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TW);
01593 
01594       /* Clear the transfer watermark flag */
01595       __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TW);
01596 
01597       /* Transfer watermark Callback */
01598 #if (USE_HAL_DMA2D_REGISTER_CALLBACKS == 1)
01599       hdma2d->LineEventCallback(hdma2d);
01600 #else
01601       HAL_DMA2D_LineEventCallback(hdma2d);
01602 #endif /* USE_HAL_DMA2D_REGISTER_CALLBACKS */
01603 
01604     }
01605   }
01606   /* Transfer Complete Interrupt management ************************************/
01607   if ((isrflags & DMA2D_FLAG_TC) != 0U)
01608   {
01609     if ((crflags & DMA2D_IT_TC) != 0U)
01610     {
01611       /* Disable the transfer complete interrupt */
01612       __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TC);
01613 
01614       /* Clear the transfer complete flag */
01615       __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TC);
01616 
01617       /* Update error code */
01618       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_NONE;
01619 
01620       /* Change DMA2D state */
01621       hdma2d->State = HAL_DMA2D_STATE_READY;
01622 
01623       /* Process Unlocked */
01624       __HAL_UNLOCK(hdma2d);
01625 
01626       if (hdma2d->XferCpltCallback != NULL)
01627       {
01628         /* Transfer complete Callback */
01629         hdma2d->XferCpltCallback(hdma2d);
01630       }
01631     }
01632   }
01633   /* CLUT Transfer Complete Interrupt management ******************************/
01634   if ((isrflags & DMA2D_FLAG_CTC) != 0U)
01635   {
01636     if ((crflags & DMA2D_IT_CTC) != 0U)
01637     {
01638       /* Disable the CLUT transfer complete interrupt */
01639       __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CTC);
01640 
01641       /* Clear the CLUT transfer complete flag */
01642       __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CTC);
01643 
01644       /* Update error code */
01645       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_NONE;
01646 
01647       /* Change DMA2D state */
01648       hdma2d->State = HAL_DMA2D_STATE_READY;
01649 
01650       /* Process Unlocked */
01651       __HAL_UNLOCK(hdma2d);
01652 
01653       /* CLUT Transfer complete Callback */
01654 #if (USE_HAL_DMA2D_REGISTER_CALLBACKS == 1)
01655       hdma2d->CLUTLoadingCpltCallback(hdma2d);
01656 #else
01657       HAL_DMA2D_CLUTLoadingCpltCallback(hdma2d);
01658 #endif /* USE_HAL_DMA2D_REGISTER_CALLBACKS */
01659     }
01660   }
01661 
01662 }
01663 
01664 /**
01665   * @brief  Transfer watermark callback.
01666   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
01667   *                 the configuration information for the DMA2D.
01668   * @retval None
01669   */
01670 __weak void HAL_DMA2D_LineEventCallback(DMA2D_HandleTypeDef *hdma2d)
01671 {
01672   /* Prevent unused argument(s) compilation warning */
01673   UNUSED(hdma2d);
01674 
01675   /* NOTE : This function should not be modified; when the callback is needed,
01676             the HAL_DMA2D_LineEventCallback can be implemented in the user file.
01677    */
01678 }
01679 
01680 /**
01681   * @brief  CLUT Transfer Complete callback.
01682   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
01683   *                 the configuration information for the DMA2D.
01684   * @retval None
01685   */
01686 __weak void HAL_DMA2D_CLUTLoadingCpltCallback(DMA2D_HandleTypeDef *hdma2d)
01687 {
01688   /* Prevent unused argument(s) compilation warning */
01689   UNUSED(hdma2d);
01690 
01691   /* NOTE : This function should not be modified; when the callback is needed,
01692             the HAL_DMA2D_CLUTLoadingCpltCallback can be implemented in the user file.
01693    */
01694 }
01695 
01696 /**
01697   * @}
01698   */
01699 
01700 /** @defgroup DMA2D_Exported_Functions_Group3 Peripheral Control functions
01701   *  @brief    Peripheral Control functions
01702   *
01703 @verbatim
01704  ===============================================================================
01705                     ##### Peripheral Control functions #####
01706  ===============================================================================
01707     [..]  This section provides functions allowing to:
01708       (+) Configure the DMA2D foreground or background layer parameters.
01709       (+) Configure the DMA2D CLUT transfer.
01710       (+) Configure the line watermark
01711       (+) Configure the dead time value.
01712       (+) Enable or disable the dead time value functionality.
01713 
01714 
01715 @endverbatim
01716   * @{
01717   */
01718 
01719 /**
01720   * @brief  Configure the DMA2D Layer according to the specified
01721   *         parameters in the DMA2D_HandleTypeDef.
01722   * @param  hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
01723   *                 the configuration information for the DMA2D.
01724   * @param  LayerIdx DMA2D Layer index.
01725   *                   This parameter can be one of the following values:
01726   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
01727   * @retval HAL status
01728   */
01729 HAL_StatusTypeDef HAL_DMA2D_ConfigLayer(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
01730 {
01731   DMA2D_LayerCfgTypeDef *pLayerCfg;
01732   uint32_t regMask;
01733   uint32_t regValue;
01734 
01735   /* Check the parameters */
01736   assert_param(IS_DMA2D_LAYER(LayerIdx));
01737   assert_param(IS_DMA2D_OFFSET(hdma2d->LayerCfg[LayerIdx].InputOffset));
01738   if (hdma2d->Init.Mode != DMA2D_R2M)
01739   {
01740     assert_param(IS_DMA2D_INPUT_COLOR_MODE(hdma2d->LayerCfg[LayerIdx].InputColorMode));
01741     if (hdma2d->Init.Mode != DMA2D_M2M)
01742     {
01743       assert_param(IS_DMA2D_ALPHA_MODE(hdma2d->LayerCfg[LayerIdx].AlphaMode));
01744     }
01745   }
01746 
01747   /* Process locked */
01748   __HAL_LOCK(hdma2d);
01749 
01750   /* Change DMA2D peripheral state */
01751   hdma2d->State = HAL_DMA2D_STATE_BUSY;
01752 
01753   pLayerCfg = &hdma2d->LayerCfg[LayerIdx];
01754 
01755   /* Prepare the value to be written to the BGPFCCR or FGPFCCR register */
01756   regValue = pLayerCfg->InputColorMode | (pLayerCfg->AlphaMode << DMA2D_BGPFCCR_AM_Pos);
01757   regMask  = DMA2D_BGPFCCR_CM | DMA2D_BGPFCCR_AM | DMA2D_BGPFCCR_ALPHA;
01758 
01759 
01760   if ((pLayerCfg->InputColorMode == DMA2D_INPUT_A4) || (pLayerCfg->InputColorMode == DMA2D_INPUT_A8))
01761   {
01762     regValue |= (pLayerCfg->InputAlpha & DMA2D_BGPFCCR_ALPHA);
01763   }
01764   else
01765   {
01766     regValue |= (pLayerCfg->InputAlpha << DMA2D_BGPFCCR_ALPHA_Pos);
01767   }
01768 
01769   /* Configure the background DMA2D layer */
01770   if (LayerIdx == DMA2D_BACKGROUND_LAYER)
01771   {
01772     /* Write DMA2D BGPFCCR register */
01773     MODIFY_REG(hdma2d->Instance->BGPFCCR, regMask, regValue);
01774 
01775     /* DMA2D BGOR register configuration -------------------------------------*/
01776     WRITE_REG(hdma2d->Instance->BGOR, pLayerCfg->InputOffset);
01777 
01778     /* DMA2D BGCOLR register configuration -------------------------------------*/
01779     if ((pLayerCfg->InputColorMode == DMA2D_INPUT_A4) || (pLayerCfg->InputColorMode == DMA2D_INPUT_A8))
01780     {
01781       WRITE_REG(hdma2d->Instance->BGCOLR, pLayerCfg->InputAlpha & (DMA2D_BGCOLR_BLUE | DMA2D_BGCOLR_GREEN | \
01782                                                                    DMA2D_BGCOLR_RED));
01783     }
01784   }
01785   /* Configure the foreground DMA2D layer */
01786   else
01787   {
01788 
01789 
01790     /* Write DMA2D FGPFCCR register */
01791     MODIFY_REG(hdma2d->Instance->FGPFCCR, regMask, regValue);
01792 
01793     /* DMA2D FGOR register configuration -------------------------------------*/
01794     WRITE_REG(hdma2d->Instance->FGOR, pLayerCfg->InputOffset);
01795 
01796     /* DMA2D FGCOLR register configuration -------------------------------------*/
01797     if ((pLayerCfg->InputColorMode == DMA2D_INPUT_A4) || (pLayerCfg->InputColorMode == DMA2D_INPUT_A8))
01798     {
01799       WRITE_REG(hdma2d->Instance->FGCOLR, pLayerCfg->InputAlpha & (DMA2D_FGCOLR_BLUE | DMA2D_FGCOLR_GREEN | \
01800                                                                    DMA2D_FGCOLR_RED));
01801     }
01802   }
01803   /* Initialize the DMA2D state*/
01804   hdma2d->State = HAL_DMA2D_STATE_READY;
01805 
01806   /* Process unlocked */
01807   __HAL_UNLOCK(hdma2d);
01808 
01809   return HAL_OK;
01810 }
01811 
01812 /**
01813   * @brief  Configure the DMA2D CLUT Transfer.
01814   * @param  hdma2d   Pointer to a DMA2D_HandleTypeDef structure that contains
01815   *                   the configuration information for the DMA2D.
01816   * @param  CLUTCfg  Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
01817   *                   the configuration information for the color look up table.
01818   * @param  LayerIdx DMA2D Layer index.
01819   *                   This parameter can be one of the following values:
01820   *                   DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
01821   * @note API obsolete and maintained for compatibility with legacy. User is invited
01822   *      to resort to HAL_DMA2D_CLUTStartLoad() instead to benefit from code compactness,
01823   *      code size and improved heap usage.
01824   * @retval HAL status
01825   */
01826 HAL_StatusTypeDef HAL_DMA2D_ConfigCLUT(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef CLUTCfg, uint32_t LayerIdx)
01827 {
01828   /* Check the parameters */
01829   assert_param(IS_DMA2D_LAYER(LayerIdx));
01830   assert_param(IS_DMA2D_CLUT_CM(CLUTCfg.CLUTColorMode));
01831   assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg.Size));
01832 
01833   /* Process locked */
01834   __HAL_LOCK(hdma2d);
01835 
01836   /* Change DMA2D peripheral state */
01837   hdma2d->State = HAL_DMA2D_STATE_BUSY;
01838 
01839   /* Configure the CLUT of the background DMA2D layer */
01840   if (LayerIdx == DMA2D_BACKGROUND_LAYER)
01841   {
01842     /* Write background CLUT memory address */
01843     WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg.pCLUT);
01844 
01845     /* Write background CLUT size and CLUT color mode */
01846     MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
01847                ((CLUTCfg.Size << DMA2D_BGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_BGPFCCR_CCM_Pos)));
01848   }
01849   /* Configure the CLUT of the foreground DMA2D layer */
01850   else
01851   {
01852     /* Write foreground CLUT memory address */
01853     WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg.pCLUT);
01854 
01855     /* Write foreground CLUT size and CLUT color mode */
01856     MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
01857                ((CLUTCfg.Size << DMA2D_FGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_FGPFCCR_CCM_Pos)));
01858   }
01859 
01860   /* Set the DMA2D state to Ready*/
01861   hdma2d->State = HAL_DMA2D_STATE_READY;
01862 
01863   /* Process unlocked */
01864   __HAL_UNLOCK(hdma2d);
01865 
01866   return HAL_OK;
01867 }
01868 
01869 
01870 /**
01871   * @brief  Configure the line watermark.
01872   * @param  hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
01873   *                 the configuration information for the DMA2D.
01874   * @param  Line   Line Watermark configuration (maximum 16-bit long value expected).
01875   * @note   HAL_DMA2D_ProgramLineEvent() API enables the transfer watermark interrupt.
01876   * @note   The transfer watermark interrupt is disabled once it has occurred.
01877   * @retval HAL status
01878   */
01879 
01880 HAL_StatusTypeDef HAL_DMA2D_ProgramLineEvent(DMA2D_HandleTypeDef *hdma2d, uint32_t Line)
01881 {
01882   /* Check the parameters */
01883   if (Line > DMA2D_LWR_LW)
01884   {
01885     return HAL_ERROR;
01886   }
01887   else
01888   {
01889     /* Process locked */
01890     __HAL_LOCK(hdma2d);
01891 
01892     /* Change DMA2D peripheral state */
01893     hdma2d->State = HAL_DMA2D_STATE_BUSY;
01894 
01895     /* Sets the Line watermark configuration */
01896     WRITE_REG(hdma2d->Instance->LWR, Line);
01897 
01898     /* Enable the Line interrupt */
01899     __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_TW);
01900 
01901     /* Initialize the DMA2D state*/
01902     hdma2d->State = HAL_DMA2D_STATE_READY;
01903 
01904     /* Process unlocked */
01905     __HAL_UNLOCK(hdma2d);
01906 
01907     return HAL_OK;
01908   }
01909 }
01910 
01911 /**
01912   * @brief Enable DMA2D dead time feature.
01913   * @param hdma2d DMA2D handle.
01914   * @retval HAL status
01915   */
01916 HAL_StatusTypeDef HAL_DMA2D_EnableDeadTime(DMA2D_HandleTypeDef *hdma2d)
01917 {
01918   /* Process Locked */
01919   __HAL_LOCK(hdma2d);
01920 
01921   hdma2d->State = HAL_DMA2D_STATE_BUSY;
01922 
01923   /* Set DMA2D_AMTCR EN bit */
01924   SET_BIT(hdma2d->Instance->AMTCR, DMA2D_AMTCR_EN);
01925 
01926   hdma2d->State = HAL_DMA2D_STATE_READY;
01927 
01928   /* Process Unlocked */
01929   __HAL_UNLOCK(hdma2d);
01930 
01931   return HAL_OK;
01932 }
01933 
01934 /**
01935   * @brief Disable DMA2D dead time feature.
01936   * @param hdma2d DMA2D handle.
01937   * @retval HAL status
01938   */
01939 HAL_StatusTypeDef HAL_DMA2D_DisableDeadTime(DMA2D_HandleTypeDef *hdma2d)
01940 {
01941   /* Process Locked */
01942   __HAL_LOCK(hdma2d);
01943 
01944   hdma2d->State = HAL_DMA2D_STATE_BUSY;
01945 
01946   /* Clear DMA2D_AMTCR EN bit */
01947   CLEAR_BIT(hdma2d->Instance->AMTCR, DMA2D_AMTCR_EN);
01948 
01949   hdma2d->State = HAL_DMA2D_STATE_READY;
01950 
01951   /* Process Unlocked */
01952   __HAL_UNLOCK(hdma2d);
01953 
01954   return HAL_OK;
01955 }
01956 
01957 /**
01958   * @brief Configure dead time.
01959   * @note The dead time value represents the guaranteed minimum number of cycles between
01960   *       two consecutive transactions on the AHB bus.
01961   * @param hdma2d DMA2D handle.
01962   * @param DeadTime dead time value.
01963   * @retval HAL status
01964   */
01965 HAL_StatusTypeDef HAL_DMA2D_ConfigDeadTime(DMA2D_HandleTypeDef *hdma2d, uint8_t DeadTime)
01966 {
01967   /* Process Locked */
01968   __HAL_LOCK(hdma2d);
01969 
01970   hdma2d->State = HAL_DMA2D_STATE_BUSY;
01971 
01972   /* Set DMA2D_AMTCR DT field */
01973   MODIFY_REG(hdma2d->Instance->AMTCR, DMA2D_AMTCR_DT, (((uint32_t) DeadTime) << DMA2D_AMTCR_DT_Pos));
01974 
01975   hdma2d->State = HAL_DMA2D_STATE_READY;
01976 
01977   /* Process Unlocked */
01978   __HAL_UNLOCK(hdma2d);
01979 
01980   return HAL_OK;
01981 }
01982 
01983 /**
01984   * @}
01985   */
01986 
01987 
01988 /** @defgroup DMA2D_Exported_Functions_Group4 Peripheral State and Error functions
01989   *  @brief    Peripheral State functions
01990   *
01991 @verbatim
01992  ===============================================================================
01993                   ##### Peripheral State and Errors functions #####
01994  ===============================================================================
01995     [..]
01996     This subsection provides functions allowing to:
01997       (+) Get the DMA2D state
01998       (+) Get the DMA2D error code
01999 
02000 @endverbatim
02001   * @{
02002   */
02003 
02004 /**
02005   * @brief  Return the DMA2D state
02006   * @param  hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
02007   *                 the configuration information for the DMA2D.
02008   * @retval HAL state
02009   */
02010 HAL_DMA2D_StateTypeDef HAL_DMA2D_GetState(DMA2D_HandleTypeDef *hdma2d)
02011 {
02012   return hdma2d->State;
02013 }
02014 
02015 /**
02016   * @brief  Return the DMA2D error code
02017   * @param  hdma2d  pointer to a DMA2D_HandleTypeDef structure that contains
02018   *               the configuration information for DMA2D.
02019   * @retval DMA2D Error Code
02020   */
02021 uint32_t HAL_DMA2D_GetError(DMA2D_HandleTypeDef *hdma2d)
02022 {
02023   return hdma2d->ErrorCode;
02024 }
02025 
02026 /**
02027   * @}
02028   */
02029 
02030 /**
02031   * @}
02032   */
02033 
02034 
02035 /** @defgroup DMA2D_Private_Functions DMA2D Private Functions
02036   * @{
02037   */
02038 
02039 /**
02040   * @brief  Set the DMA2D transfer parameters.
02041   * @param  hdma2d     Pointer to a DMA2D_HandleTypeDef structure that contains
02042   *                     the configuration information for the specified DMA2D.
02043   * @param  pdata      The source memory Buffer address
02044   * @param  DstAddress The destination memory Buffer address
02045   * @param  Width      The width of data to be transferred from source to destination.
02046   * @param  Height     The height of data to be transferred from source to destination.
02047   * @retval HAL status
02048   */
02049 static void DMA2D_SetConfig(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width,
02050                             uint32_t Height)
02051 {
02052   uint32_t tmp;
02053   uint32_t tmp1;
02054   uint32_t tmp2;
02055   uint32_t tmp3;
02056   uint32_t tmp4;
02057 
02058   /* Configure DMA2D data size */
02059   MODIFY_REG(hdma2d->Instance->NLR, (DMA2D_NLR_NL | DMA2D_NLR_PL), (Height | (Width << DMA2D_NLR_PL_Pos)));
02060 
02061   /* Configure DMA2D destination address */
02062   WRITE_REG(hdma2d->Instance->OMAR, DstAddress);
02063 
02064   /* Register to memory DMA2D mode selected */
02065   if (hdma2d->Init.Mode == DMA2D_R2M)
02066   {
02067     tmp1 = pdata & DMA2D_OCOLR_ALPHA_1;
02068     tmp2 = pdata & DMA2D_OCOLR_RED_1;
02069     tmp3 = pdata & DMA2D_OCOLR_GREEN_1;
02070     tmp4 = pdata & DMA2D_OCOLR_BLUE_1;
02071 
02072     /* Prepare the value to be written to the OCOLR register according to the color mode */
02073     if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_ARGB8888)
02074     {
02075       tmp = (tmp3 | tmp2 | tmp1 | tmp4);
02076     }
02077     else if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_RGB888)
02078     {
02079       tmp = (tmp3 | tmp2 | tmp4);
02080     }
02081     else if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_RGB565)
02082     {
02083       tmp2 = (tmp2 >> 19U);
02084       tmp3 = (tmp3 >> 10U);
02085       tmp4 = (tmp4 >> 3U);
02086       tmp  = ((tmp3 << 5U) | (tmp2 << 11U) | tmp4);
02087     }
02088     else if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_ARGB1555)
02089     {
02090       tmp1 = (tmp1 >> 31U);
02091       tmp2 = (tmp2 >> 19U);
02092       tmp3 = (tmp3 >> 11U);
02093       tmp4 = (tmp4 >> 3U);
02094       tmp  = ((tmp3 << 5U) | (tmp2 << 10U) | (tmp1 << 15U) | tmp4);
02095     }
02096     else /* Dhdma2d->Init.ColorMode = DMA2D_OUTPUT_ARGB4444 */
02097     {
02098       tmp1 = (tmp1 >> 28U);
02099       tmp2 = (tmp2 >> 20U);
02100       tmp3 = (tmp3 >> 12U);
02101       tmp4 = (tmp4 >> 4U);
02102       tmp  = ((tmp3 << 4U) | (tmp2 << 8U) | (tmp1 << 12U) | tmp4);
02103     }
02104     /* Write to DMA2D OCOLR register */
02105     WRITE_REG(hdma2d->Instance->OCOLR, tmp);
02106   }
02107   else /* M2M, M2M_PFC or M2M_Blending DMA2D Mode */
02108   {
02109     /* Configure DMA2D source address */
02110     WRITE_REG(hdma2d->Instance->FGMAR, pdata);
02111   }
02112 }
02113 
02114 /**
02115   * @}
02116   */
02117 
02118 /**
02119   * @}
02120   */
02121 
02122 /**
02123   * @}
02124   */
02125 #endif /* DMA2D */
02126 #endif /* HAL_DMA2D_MODULE_ENABLED */
02127 
02128 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/