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