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