You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

2168 lines
73 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_dma2d.c
  4. * @author MCD Application Team
  5. * @brief DMA2D HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the DMA2D peripheral:
  8. * + Initialization and de-initialization functions
  9. * + IO operation functions
  10. * + Peripheral Control functions
  11. * + Peripheral State and Errors functions
  12. *
  13. @verbatim
  14. ==============================================================================
  15. ##### How to use this driver #####
  16. ==============================================================================
  17. [..]
  18. (#) Program the required configuration through the following parameters:
  19. the transfer mode, the output color mode and the output offset using
  20. HAL_DMA2D_Init() function.
  21. (#) Program the required configuration through the following parameters:
  22. the input color mode, the input color, the input alpha value, the alpha mode,
  23. the red/blue swap mode, the inverted alpha mode and the input offset using
  24. HAL_DMA2D_ConfigLayer() function for foreground or/and background layer.
  25. *** Polling mode IO operation ***
  26. =================================
  27. [..]
  28. (#) Configure pdata parameter (explained hereafter), destination and data length
  29. and enable the transfer using HAL_DMA2D_Start().
  30. (#) Wait for end of transfer using HAL_DMA2D_PollForTransfer(), at this stage
  31. user can specify the value of timeout according to his end application.
  32. *** Interrupt mode IO operation ***
  33. ===================================
  34. [..]
  35. (#) Configure pdata parameter, destination and data length and enable
  36. the transfer using HAL_DMA2D_Start_IT().
  37. (#) Use HAL_DMA2D_IRQHandler() called under DMA2D_IRQHandler() interrupt subroutine.
  38. (#) At the end of data transfer HAL_DMA2D_IRQHandler() function is executed and user can
  39. add his own function by customization of function pointer XferCpltCallback (member
  40. of DMA2D handle structure).
  41. (#) In case of error, the HAL_DMA2D_IRQHandler() function calls the callback
  42. XferErrorCallback.
  43. -@- In Register-to-Memory transfer mode, pdata parameter is the register
  44. color, in Memory-to-memory or Memory-to-Memory with pixel format
  45. conversion pdata is the source address.
  46. -@- Configure the foreground source address, the background source address,
  47. the destination and data length then Enable the transfer using
  48. HAL_DMA2D_BlendingStart() in polling mode and HAL_DMA2D_BlendingStart_IT()
  49. in interrupt mode.
  50. -@- HAL_DMA2D_BlendingStart() and HAL_DMA2D_BlendingStart_IT() functions
  51. are used if the memory to memory with blending transfer mode is selected.
  52. (#) Optionally, configure and enable the CLUT using HAL_DMA2D_CLUTLoad() in polling
  53. mode or HAL_DMA2D_CLUTLoad_IT() in interrupt mode.
  54. (#) Optionally, configure the line watermark in using the API HAL_DMA2D_ProgramLineEvent().
  55. (#) Optionally, configure the dead time value in the AHB clock cycle inserted between two
  56. consecutive accesses on the AHB master port in using the API HAL_DMA2D_ConfigDeadTime()
  57. and enable/disable the functionality with the APIs HAL_DMA2D_EnableDeadTime() or
  58. HAL_DMA2D_DisableDeadTime().
  59. (#) The transfer can be suspended, resumed and aborted using the following
  60. functions: HAL_DMA2D_Suspend(), HAL_DMA2D_Resume(), HAL_DMA2D_Abort().
  61. (#) The CLUT loading can be suspended, resumed and aborted using the following
  62. functions: HAL_DMA2D_CLUTLoading_Suspend(), HAL_DMA2D_CLUTLoading_Resume(),
  63. HAL_DMA2D_CLUTLoading_Abort().
  64. (#) To control the DMA2D state, use the following function: HAL_DMA2D_GetState().
  65. (#) To read the DMA2D error code, use the following function: HAL_DMA2D_GetError().
  66. *** DMA2D HAL driver macros list ***
  67. =============================================
  68. [..]
  69. Below the list of most used macros in DMA2D HAL driver :
  70. (+) __HAL_DMA2D_ENABLE: Enable the DMA2D peripheral.
  71. (+) __HAL_DMA2D_GET_FLAG: Get the DMA2D pending flags.
  72. (+) __HAL_DMA2D_CLEAR_FLAG: Clear the DMA2D pending flags.
  73. (+) __HAL_DMA2D_ENABLE_IT: Enable the specified DMA2D interrupts.
  74. (+) __HAL_DMA2D_DISABLE_IT: Disable the specified DMA2D interrupts.
  75. (+) __HAL_DMA2D_GET_IT_SOURCE: Check whether the specified DMA2D interrupt is enabled or not.
  76. *** Callback registration ***
  77. ===================================
  78. [..]
  79. (#) The compilation define USE_HAL_DMA2D_REGISTER_CALLBACKS when set to 1
  80. allows the user to configure dynamically the driver callbacks.
  81. Use function @ref HAL_DMA2D_RegisterCallback() to register a user callback.
  82. (#) Function @ref HAL_DMA2D_RegisterCallback() allows to register following callbacks:
  83. (+) XferCpltCallback : callback for transfer complete.
  84. (+) XferErrorCallback : callback for transfer error.
  85. (+) LineEventCallback : callback for line event.
  86. (+) CLUTLoadingCpltCallback : callback for CLUT loading completion.
  87. (+) MspInitCallback : DMA2D MspInit.
  88. (+) MspDeInitCallback : DMA2D MspDeInit.
  89. This function takes as parameters the HAL peripheral handle, the Callback ID
  90. and a pointer to the user callback function.
  91. (#) Use function @ref HAL_DMA2D_UnRegisterCallback() to reset a callback to the default
  92. weak (surcharged) function.
  93. @ref HAL_DMA2D_UnRegisterCallback() takes as parameters the HAL peripheral handle,
  94. and the Callback ID.
  95. This function allows to reset following callbacks:
  96. (+) XferCpltCallback : callback for transfer complete.
  97. (+) XferErrorCallback : callback for transfer error.
  98. (+) LineEventCallback : callback for line event.
  99. (+) CLUTLoadingCpltCallback : callback for CLUT loading completion.
  100. (+) MspInitCallback : DMA2D MspInit.
  101. (+) MspDeInitCallback : DMA2D MspDeInit.
  102. (#) By default, after the @ref HAL_DMA2D_Init and if the state is HAL_DMA2D_STATE_RESET
  103. all callbacks are reset to the corresponding legacy weak (surcharged) functions:
  104. examples @ref HAL_DMA2D_LineEventCallback(), @ref HAL_DMA2D_CLUTLoadingCpltCallback()
  105. Exception done for MspInit and MspDeInit callbacks that are respectively
  106. reset to the legacy weak (surcharged) functions in the @ref HAL_DMA2D_Init
  107. and @ref HAL_DMA2D_DeInit only when these callbacks are null (not registered beforehand)
  108. If not, MspInit or MspDeInit are not null, the @ref HAL_DMA2D_Init and @ref HAL_DMA2D_DeInit
  109. keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
  110. Exception as well for Transfer Completion and Transfer Error callbacks that are not defined
  111. as weak (surcharged) functions. They must be defined by the user to be resorted to.
  112. Callbacks can be registered/unregistered in READY state only.
  113. Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
  114. in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
  115. during the Init/DeInit.
  116. In that case first register the MspInit/MspDeInit user callbacks
  117. using @ref HAL_DMA2D_RegisterCallback before calling @ref HAL_DMA2D_DeInit
  118. or @ref HAL_DMA2D_Init function.
  119. When The compilation define USE_HAL_DMA2D_REGISTER_CALLBACKS is set to 0 or
  120. not defined, the callback registering feature is not available
  121. and weak (surcharged) callbacks are used.
  122. [..]
  123. (@) You can refer to the DMA2D HAL driver header file for more useful macros
  124. @endverbatim
  125. ******************************************************************************
  126. * @attention
  127. *
  128. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  129. * All rights reserved.</center></h2>
  130. *
  131. * This software component is licensed by ST under BSD 3-Clause license,
  132. * the "License"; You may not use this file except in compliance with the
  133. * License. You may obtain a copy of the License at:
  134. * opensource.org/licenses/BSD-3-Clause
  135. *
  136. ******************************************************************************
  137. */
  138. /* Includes ------------------------------------------------------------------*/
  139. #include "stm32h7xx_hal.h"
  140. #ifdef HAL_DMA2D_MODULE_ENABLED
  141. #if defined (DMA2D)
  142. /** @addtogroup STM32H7xx_HAL_Driver
  143. * @{
  144. */
  145. /** @defgroup DMA2D DMA2D
  146. * @brief DMA2D HAL module driver
  147. * @{
  148. */
  149. /* Private types -------------------------------------------------------------*/
  150. /* Private define ------------------------------------------------------------*/
  151. /** @defgroup DMA2D_Private_Constants DMA2D Private Constants
  152. * @{
  153. */
  154. /** @defgroup DMA2D_TimeOut DMA2D Time Out
  155. * @{
  156. */
  157. #define DMA2D_TIMEOUT_ABORT (1000U) /*!< 1s */
  158. #define DMA2D_TIMEOUT_SUSPEND (1000U) /*!< 1s */
  159. /**
  160. * @}
  161. */
  162. /**
  163. * @}
  164. */
  165. /* Private variables ---------------------------------------------------------*/
  166. /* Private constants ---------------------------------------------------------*/
  167. /* Private macro -------------------------------------------------------------*/
  168. /* Private function prototypes -----------------------------------------------*/
  169. /** @addtogroup DMA2D_Private_Functions DMA2D Private Functions
  170. * @{
  171. */
  172. static void DMA2D_SetConfig(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width, uint32_t Height);
  173. /**
  174. * @}
  175. */
  176. /* Private functions ---------------------------------------------------------*/
  177. /* Exported functions --------------------------------------------------------*/
  178. /** @defgroup DMA2D_Exported_Functions DMA2D Exported Functions
  179. * @{
  180. */
  181. /** @defgroup DMA2D_Exported_Functions_Group1 Initialization and de-initialization functions
  182. * @brief Initialization and Configuration functions
  183. *
  184. @verbatim
  185. ===============================================================================
  186. ##### Initialization and Configuration functions #####
  187. ===============================================================================
  188. [..] This section provides functions allowing to:
  189. (+) Initialize and configure the DMA2D
  190. (+) De-initialize the DMA2D
  191. @endverbatim
  192. * @{
  193. */
  194. /**
  195. * @brief Initialize the DMA2D according to the specified
  196. * parameters in the DMA2D_InitTypeDef and create the associated handle.
  197. * @param hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
  198. * the configuration information for the DMA2D.
  199. * @retval HAL status
  200. */
  201. HAL_StatusTypeDef HAL_DMA2D_Init(DMA2D_HandleTypeDef *hdma2d)
  202. {
  203. /* Check the DMA2D peripheral state */
  204. if(hdma2d == NULL)
  205. {
  206. return HAL_ERROR;
  207. }
  208. /* Check the parameters */
  209. assert_param(IS_DMA2D_ALL_INSTANCE(hdma2d->Instance));
  210. assert_param(IS_DMA2D_MODE(hdma2d->Init.Mode));
  211. assert_param(IS_DMA2D_CMODE(hdma2d->Init.ColorMode));
  212. assert_param(IS_DMA2D_OFFSET(hdma2d->Init.OutputOffset));
  213. assert_param(IS_DMA2D_ALPHA_INVERTED(hdma2d->Init.AlphaInverted));
  214. assert_param(IS_DMA2D_RB_SWAP(hdma2d->Init.RedBlueSwap));
  215. assert_param(IS_DMA2D_LOM_MODE(hdma2d->Init.LineOffsetMode));
  216. assert_param(IS_DMA2D_BYTES_SWAP(hdma2d->Init.BytesSwap));
  217. #if (USE_HAL_DMA2D_REGISTER_CALLBACKS == 1)
  218. if (hdma2d->State == HAL_DMA2D_STATE_RESET)
  219. {
  220. /* Reset Callback pointers in HAL_DMA2D_STATE_RESET only */
  221. hdma2d->LineEventCallback = HAL_DMA2D_LineEventCallback;
  222. hdma2d->CLUTLoadingCpltCallback = HAL_DMA2D_CLUTLoadingCpltCallback;
  223. if(hdma2d->MspInitCallback == NULL)
  224. {
  225. hdma2d->MspInitCallback = HAL_DMA2D_MspInit;
  226. }
  227. /* Init the low level hardware */
  228. hdma2d->MspInitCallback(hdma2d);
  229. }
  230. #else
  231. if(hdma2d->State == HAL_DMA2D_STATE_RESET)
  232. {
  233. /* Allocate lock resource and initialize it */
  234. hdma2d->Lock = HAL_UNLOCKED;
  235. /* Init the low level hardware */
  236. HAL_DMA2D_MspInit(hdma2d);
  237. }
  238. #endif /* (USE_HAL_DMA2D_REGISTER_CALLBACKS) */
  239. /* Change DMA2D peripheral state */
  240. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  241. /* DMA2D CR register configuration -------------------------------------------*/
  242. MODIFY_REG(hdma2d->Instance->CR, DMA2D_CR_MODE | DMA2D_CR_LOM, hdma2d->Init.Mode | hdma2d->Init.LineOffsetMode);
  243. /* DMA2D OPFCCR register configuration ---------------------------------------*/
  244. MODIFY_REG(hdma2d->Instance->OPFCCR, DMA2D_OPFCCR_CM | DMA2D_OPFCCR_SB, hdma2d->Init.ColorMode | hdma2d->Init.BytesSwap);
  245. /* DMA2D OOR register configuration ------------------------------------------*/
  246. MODIFY_REG(hdma2d->Instance->OOR, DMA2D_OOR_LO, hdma2d->Init.OutputOffset);
  247. /* DMA2D OPFCCR AI and RBS fields setting (Output Alpha Inversion)*/
  248. MODIFY_REG(hdma2d->Instance->OPFCCR,(DMA2D_OPFCCR_AI|DMA2D_OPFCCR_RBS), ((hdma2d->Init.AlphaInverted << DMA2D_OPFCCR_AI_Pos) | (hdma2d->Init.RedBlueSwap << DMA2D_OPFCCR_RBS_Pos)));
  249. /* Update error code */
  250. hdma2d->ErrorCode = HAL_DMA2D_ERROR_NONE;
  251. /* Initialize the DMA2D state*/
  252. hdma2d->State = HAL_DMA2D_STATE_READY;
  253. return HAL_OK;
  254. }
  255. /**
  256. * @brief Deinitializes the DMA2D peripheral registers to their default reset
  257. * values.
  258. * @param hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
  259. * the configuration information for the DMA2D.
  260. * @retval None
  261. */
  262. HAL_StatusTypeDef HAL_DMA2D_DeInit(DMA2D_HandleTypeDef *hdma2d)
  263. {
  264. /* Check the DMA2D peripheral state */
  265. if(hdma2d == NULL)
  266. {
  267. return HAL_ERROR;
  268. }
  269. /* Before aborting any DMA2D transfer or CLUT loading, check
  270. first whether or not DMA2D clock is enabled */
  271. if (__HAL_RCC_DMA2D_IS_CLK_ENABLED())
  272. {
  273. /* Abort DMA2D transfer if any */
  274. if ((hdma2d->Instance->CR & DMA2D_CR_START) == DMA2D_CR_START)
  275. {
  276. if (HAL_DMA2D_Abort(hdma2d) != HAL_OK)
  277. {
  278. /* Issue when aborting DMA2D transfer */
  279. return HAL_ERROR;
  280. }
  281. }
  282. else
  283. {
  284. /* Abort background CLUT loading if any */
  285. if ((hdma2d->Instance->BGPFCCR & DMA2D_BGPFCCR_START) == DMA2D_BGPFCCR_START)
  286. {
  287. if (HAL_DMA2D_CLUTLoading_Abort(hdma2d, 0U) != HAL_OK)
  288. {
  289. /* Issue when aborting background CLUT loading */
  290. return HAL_ERROR;
  291. }
  292. }
  293. else
  294. {
  295. /* Abort foreground CLUT loading if any */
  296. if ((hdma2d->Instance->FGPFCCR & DMA2D_FGPFCCR_START) == DMA2D_FGPFCCR_START)
  297. {
  298. if (HAL_DMA2D_CLUTLoading_Abort(hdma2d, 1U) != HAL_OK)
  299. {
  300. /* Issue when aborting foreground CLUT loading */
  301. return HAL_ERROR;
  302. }
  303. }
  304. }
  305. }
  306. }
  307. /* Reset DMA2D control registers*/
  308. hdma2d->Instance->CR = 0U;
  309. hdma2d->Instance->IFCR = 0x3FU;
  310. hdma2d->Instance->FGOR = 0U;
  311. hdma2d->Instance->BGOR = 0U;
  312. hdma2d->Instance->FGPFCCR = 0U;
  313. hdma2d->Instance->BGPFCCR = 0U;
  314. hdma2d->Instance->OPFCCR = 0U;
  315. #if (USE_HAL_DMA2D_REGISTER_CALLBACKS == 1)
  316. if(hdma2d->MspDeInitCallback == NULL)
  317. {
  318. hdma2d->MspDeInitCallback = HAL_DMA2D_MspDeInit;
  319. }
  320. /* DeInit the low level hardware */
  321. hdma2d->MspDeInitCallback(hdma2d);
  322. #else
  323. /* Carry on with de-initialization of low level hardware */
  324. HAL_DMA2D_MspDeInit(hdma2d);
  325. #endif /* (USE_HAL_DMA2D_REGISTER_CALLBACKS) */
  326. /* Update error code */
  327. hdma2d->ErrorCode = HAL_DMA2D_ERROR_NONE;
  328. /* Initialize the DMA2D state*/
  329. hdma2d->State = HAL_DMA2D_STATE_RESET;
  330. /* Release Lock */
  331. __HAL_UNLOCK(hdma2d);
  332. return HAL_OK;
  333. }
  334. /**
  335. * @brief Initializes the DMA2D MSP.
  336. * @param hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
  337. * the configuration information for the DMA2D.
  338. * @retval None
  339. */
  340. __weak void HAL_DMA2D_MspInit(DMA2D_HandleTypeDef* hdma2d)
  341. {
  342. /* Prevent unused argument(s) compilation warning */
  343. UNUSED(hdma2d);
  344. /* NOTE : This function should not be modified; when the callback is needed,
  345. the HAL_DMA2D_MspInit can be implemented in the user file.
  346. */
  347. }
  348. /**
  349. * @brief DeInitializes the DMA2D MSP.
  350. * @param hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
  351. * the configuration information for the DMA2D.
  352. * @retval None
  353. */
  354. __weak void HAL_DMA2D_MspDeInit(DMA2D_HandleTypeDef* hdma2d)
  355. {
  356. /* Prevent unused argument(s) compilation warning */
  357. UNUSED(hdma2d);
  358. /* NOTE : This function should not be modified; when the callback is needed,
  359. the HAL_DMA2D_MspDeInit can be implemented in the user file.
  360. */
  361. }
  362. #if (USE_HAL_DMA2D_REGISTER_CALLBACKS == 1)
  363. /**
  364. * @brief Register a User DMA2D Callback
  365. * To be used instead of the weak (surcharged) predefined callback
  366. * @param hdma2d DMA2D handle
  367. * @param CallbackID ID of the callback to be registered
  368. * This parameter can be one of the following values:
  369. * @arg @ref HAL_DMA2D_TRANSFERCOMPLETE_CB_ID DMA2D transfer complete Callback ID
  370. * @arg @ref HAL_DMA2D_TRANSFERERROR_CB_ID DMA2D transfer error Callback ID
  371. * @arg @ref HAL_DMA2D_LINEEVENT_CB_ID DMA2D line event Callback ID
  372. * @arg @ref HAL_DMA2D_CLUTLOADINGCPLT_CB_ID DMA2D CLUT loading completion Callback ID
  373. * @arg @ref HAL_DMA2D_MSPINIT_CB_ID DMA2D MspInit callback ID
  374. * @arg @ref HAL_DMA2D_MSPDEINIT_CB_ID DMA2D MspDeInit callback ID
  375. * @param pCallback pointer to the Callback function
  376. * @note No weak predefined callbacks are defined for HAL_DMA2D_TRANSFERCOMPLETE_CB_ID or HAL_DMA2D_TRANSFERERROR_CB_ID
  377. * @retval status
  378. */
  379. HAL_StatusTypeDef HAL_DMA2D_RegisterCallback(DMA2D_HandleTypeDef *hdma2d, HAL_DMA2D_CallbackIDTypeDef CallbackID, pDMA2D_CallbackTypeDef pCallback)
  380. {
  381. HAL_StatusTypeDef status = HAL_OK;
  382. if(pCallback == NULL)
  383. {
  384. /* Update the error code */
  385. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
  386. return HAL_ERROR;
  387. }
  388. /* Process locked */
  389. __HAL_LOCK(hdma2d);
  390. if(HAL_DMA2D_STATE_READY == hdma2d->State)
  391. {
  392. switch (CallbackID)
  393. {
  394. case HAL_DMA2D_TRANSFERCOMPLETE_CB_ID :
  395. hdma2d->XferCpltCallback = pCallback;
  396. break;
  397. case HAL_DMA2D_TRANSFERERROR_CB_ID :
  398. hdma2d->XferErrorCallback = pCallback;
  399. break;
  400. case HAL_DMA2D_LINEEVENT_CB_ID :
  401. hdma2d->LineEventCallback = pCallback;
  402. break;
  403. case HAL_DMA2D_CLUTLOADINGCPLT_CB_ID :
  404. hdma2d->CLUTLoadingCpltCallback = pCallback;
  405. break;
  406. case HAL_DMA2D_MSPINIT_CB_ID :
  407. hdma2d->MspInitCallback = pCallback;
  408. break;
  409. case HAL_DMA2D_MSPDEINIT_CB_ID :
  410. hdma2d->MspDeInitCallback = pCallback;
  411. break;
  412. default :
  413. /* Update the error code */
  414. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
  415. /* update return status */
  416. status = HAL_ERROR;
  417. break;
  418. }
  419. }
  420. else if(HAL_DMA2D_STATE_RESET == hdma2d->State)
  421. {
  422. switch (CallbackID)
  423. {
  424. case HAL_DMA2D_MSPINIT_CB_ID :
  425. hdma2d->MspInitCallback = pCallback;
  426. break;
  427. case HAL_DMA2D_MSPDEINIT_CB_ID :
  428. hdma2d->MspDeInitCallback = pCallback;
  429. break;
  430. default :
  431. /* Update the error code */
  432. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
  433. /* update return status */
  434. status = HAL_ERROR;
  435. break;
  436. }
  437. }
  438. else
  439. {
  440. /* Update the error code */
  441. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
  442. /* update return status */
  443. status = HAL_ERROR;
  444. }
  445. /* Release Lock */
  446. __HAL_UNLOCK(hdma2d);
  447. return status;
  448. }
  449. /**
  450. * @brief Unregister a DMA2D Callback
  451. * DMA2D Callback is redirected to the weak (surcharged) predefined callback
  452. * @param hdma2d DMA2D handle
  453. * @param CallbackID ID of the callback to be unregistered
  454. * This parameter can be one of the following values:
  455. * @arg @ref HAL_DMA2D_TRANSFERCOMPLETE_CB_ID DMA2D transfer complete Callback ID
  456. * @arg @ref HAL_DMA2D_TRANSFERERROR_CB_ID DMA2D transfer error Callback ID
  457. * @arg @ref HAL_DMA2D_LINEEVENT_CB_ID DMA2D line event Callback ID
  458. * @arg @ref HAL_DMA2D_CLUTLOADINGCPLT_CB_ID DMA2D CLUT loading completion Callback ID
  459. * @arg @ref HAL_DMA2D_MSPINIT_CB_ID DMA2D MspInit callback ID
  460. * @arg @ref HAL_DMA2D_MSPDEINIT_CB_ID DMA2D MspDeInit callback ID
  461. * @note No weak predefined callbacks are defined for HAL_DMA2D_TRANSFERCOMPLETE_CB_ID or HAL_DMA2D_TRANSFERERROR_CB_ID
  462. * @retval status
  463. */
  464. HAL_StatusTypeDef HAL_DMA2D_UnRegisterCallback(DMA2D_HandleTypeDef *hdma2d, HAL_DMA2D_CallbackIDTypeDef CallbackID)
  465. {
  466. HAL_StatusTypeDef status = HAL_OK;
  467. /* Process locked */
  468. __HAL_LOCK(hdma2d);
  469. if(HAL_DMA2D_STATE_READY == hdma2d->State)
  470. {
  471. switch (CallbackID)
  472. {
  473. case HAL_DMA2D_TRANSFERCOMPLETE_CB_ID :
  474. hdma2d->XferCpltCallback = NULL;
  475. break;
  476. case HAL_DMA2D_TRANSFERERROR_CB_ID :
  477. hdma2d->XferErrorCallback = NULL;
  478. break;
  479. case HAL_DMA2D_LINEEVENT_CB_ID :
  480. hdma2d->LineEventCallback = HAL_DMA2D_LineEventCallback;
  481. break;
  482. case HAL_DMA2D_CLUTLOADINGCPLT_CB_ID :
  483. hdma2d->CLUTLoadingCpltCallback = HAL_DMA2D_CLUTLoadingCpltCallback;
  484. break;
  485. case HAL_DMA2D_MSPINIT_CB_ID :
  486. hdma2d->MspInitCallback = HAL_DMA2D_MspInit; /* Legacy weak (surcharged) Msp Init */
  487. break;
  488. case HAL_DMA2D_MSPDEINIT_CB_ID :
  489. hdma2d->MspDeInitCallback = HAL_DMA2D_MspDeInit; /* Legacy weak (surcharged) Msp DeInit */
  490. break;
  491. default :
  492. /* Update the error code */
  493. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
  494. /* update return status */
  495. status = HAL_ERROR;
  496. break;
  497. }
  498. }
  499. else if(HAL_DMA2D_STATE_RESET == hdma2d->State)
  500. {
  501. switch (CallbackID)
  502. {
  503. case HAL_DMA2D_MSPINIT_CB_ID :
  504. hdma2d->MspInitCallback = HAL_DMA2D_MspInit; /* Legacy weak (surcharged) Msp Init */
  505. break;
  506. case HAL_DMA2D_MSPDEINIT_CB_ID :
  507. hdma2d->MspDeInitCallback = HAL_DMA2D_MspDeInit; /* Legacy weak (surcharged) Msp DeInit */
  508. break;
  509. default :
  510. /* Update the error code */
  511. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
  512. /* update return status */
  513. status = HAL_ERROR;
  514. break;
  515. }
  516. }
  517. else
  518. {
  519. /* Update the error code */
  520. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_INVALID_CALLBACK;
  521. /* update return status */
  522. status = HAL_ERROR;
  523. }
  524. /* Release Lock */
  525. __HAL_UNLOCK(hdma2d);
  526. return status;
  527. }
  528. #endif /* USE_HAL_DMA2D_REGISTER_CALLBACKS */
  529. /**
  530. * @}
  531. */
  532. /** @defgroup DMA2D_Exported_Functions_Group2 IO operation functions
  533. * @brief IO operation functions
  534. *
  535. @verbatim
  536. ===============================================================================
  537. ##### IO operation functions #####
  538. ===============================================================================
  539. [..] This section provides functions allowing to:
  540. (+) Configure the pdata, destination address and data size then
  541. start the DMA2D transfer.
  542. (+) Configure the source for foreground and background, destination address
  543. and data size then start a MultiBuffer DMA2D transfer.
  544. (+) Configure the pdata, destination address and data size then
  545. start the DMA2D transfer with interrupt.
  546. (+) Configure the source for foreground and background, destination address
  547. and data size then start a MultiBuffer DMA2D transfer with interrupt.
  548. (+) Abort DMA2D transfer.
  549. (+) Suspend DMA2D transfer.
  550. (+) Resume DMA2D transfer.
  551. (+) Enable CLUT transfer.
  552. (+) Configure CLUT loading then start transfer in polling mode.
  553. (+) Configure CLUT loading then start transfer in interrupt mode.
  554. (+) Abort DMA2D CLUT loading.
  555. (+) Suspend DMA2D CLUT loading.
  556. (+) Resume DMA2D CLUT loading.
  557. (+) Poll for transfer complete.
  558. (+) handle DMA2D interrupt request.
  559. (+) Transfer watermark callback.
  560. (+) CLUT Transfer Complete callback.
  561. @endverbatim
  562. * @{
  563. */
  564. /**
  565. * @brief Start the DMA2D Transfer.
  566. * @param hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
  567. * the configuration information for the DMA2D.
  568. * @param pdata Configure the source memory Buffer address if
  569. * Memory-to-Memory or Memory-to-Memory with pixel format
  570. * conversion mode is selected, or configure
  571. * the color value if Register-to-Memory mode is selected.
  572. * @param DstAddress The destination memory Buffer address.
  573. * @param Width The width of data to be transferred from source to destination (expressed in number of pixels per line).
  574. * @param Height The height of data to be transferred from source to destination (expressed in number of lines).
  575. * @retval HAL status
  576. */
  577. HAL_StatusTypeDef HAL_DMA2D_Start(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width, uint32_t Height)
  578. {
  579. /* Check the parameters */
  580. assert_param(IS_DMA2D_LINE(Height));
  581. assert_param(IS_DMA2D_PIXEL(Width));
  582. /* Process locked */
  583. __HAL_LOCK(hdma2d);
  584. /* Change DMA2D peripheral state */
  585. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  586. /* Configure the source, destination address and the data size */
  587. DMA2D_SetConfig(hdma2d, pdata, DstAddress, Width, Height);
  588. /* Enable the Peripheral */
  589. __HAL_DMA2D_ENABLE(hdma2d);
  590. return HAL_OK;
  591. }
  592. /**
  593. * @brief Start the DMA2D Transfer with interrupt enabled.
  594. * @param hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
  595. * the configuration information for the DMA2D.
  596. * @param pdata Configure the source memory Buffer address if
  597. * the Memory-to-Memory or Memory-to-Memory with pixel format
  598. * conversion mode is selected, or configure
  599. * the color value if Register-to-Memory mode is selected.
  600. * @param DstAddress The destination memory Buffer address.
  601. * @param Width The width of data to be transferred from source to destination (expressed in number of pixels per line).
  602. * @param Height The height of data to be transferred from source to destination (expressed in number of lines).
  603. * @retval HAL status
  604. */
  605. HAL_StatusTypeDef HAL_DMA2D_Start_IT(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width, uint32_t Height)
  606. {
  607. /* Check the parameters */
  608. assert_param(IS_DMA2D_LINE(Height));
  609. assert_param(IS_DMA2D_PIXEL(Width));
  610. /* Process locked */
  611. __HAL_LOCK(hdma2d);
  612. /* Change DMA2D peripheral state */
  613. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  614. /* Configure the source, destination address and the data size */
  615. DMA2D_SetConfig(hdma2d, pdata, DstAddress, Width, Height);
  616. /* Enable the transfer complete, transfer error and configuration error interrupts */
  617. __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_TC|DMA2D_IT_TE|DMA2D_IT_CE);
  618. /* Enable the Peripheral */
  619. __HAL_DMA2D_ENABLE(hdma2d);
  620. return HAL_OK;
  621. }
  622. /**
  623. * @brief Start the multi-source DMA2D Transfer.
  624. * @param hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
  625. * the configuration information for the DMA2D.
  626. * @param SrcAddress1 The source memory Buffer address for the foreground layer.
  627. * @param SrcAddress2 The source memory Buffer address for the background layer.
  628. * @param DstAddress The destination memory Buffer address.
  629. * @param Width The width of data to be transferred from source to destination (expressed in number of pixels per line).
  630. * @param Height The height of data to be transferred from source to destination (expressed in number of lines).
  631. * @retval HAL status
  632. */
  633. HAL_StatusTypeDef HAL_DMA2D_BlendingStart(DMA2D_HandleTypeDef *hdma2d, uint32_t SrcAddress1, uint32_t SrcAddress2, uint32_t DstAddress, uint32_t Width, uint32_t Height)
  634. {
  635. /* Check the parameters */
  636. assert_param(IS_DMA2D_LINE(Height));
  637. assert_param(IS_DMA2D_PIXEL(Width));
  638. /* Process locked */
  639. __HAL_LOCK(hdma2d);
  640. /* Change DMA2D peripheral state */
  641. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  642. if(hdma2d->Init.Mode == DMA2D_M2M_BLEND_FG)
  643. {
  644. /*blending & fixed FG*/
  645. WRITE_REG(hdma2d->Instance->FGCOLR, SrcAddress1);
  646. /* Configure the source, destination address and the data size */
  647. DMA2D_SetConfig(hdma2d, SrcAddress2, DstAddress, Width, Height);
  648. }
  649. else if (hdma2d->Init.Mode == DMA2D_M2M_BLEND_BG)
  650. {
  651. /*blending & fixed BG*/
  652. WRITE_REG(hdma2d->Instance->BGCOLR, SrcAddress2);
  653. /* Configure the source, destination address and the data size */
  654. DMA2D_SetConfig(hdma2d, SrcAddress1, DstAddress, Width, Height);
  655. }
  656. else
  657. {
  658. /* Configure DMA2D Stream source2 address */
  659. WRITE_REG(hdma2d->Instance->BGMAR, SrcAddress2);
  660. /* Configure the source, destination address and the data size */
  661. DMA2D_SetConfig(hdma2d, SrcAddress1, DstAddress, Width, Height);
  662. }
  663. /* Enable the Peripheral */
  664. __HAL_DMA2D_ENABLE(hdma2d);
  665. return HAL_OK;
  666. }
  667. /**
  668. * @brief Start the multi-source DMA2D Transfer with interrupt enabled.
  669. * @param hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
  670. * the configuration information for the DMA2D.
  671. * @param SrcAddress1 The source memory Buffer address for the foreground layer.
  672. * @param SrcAddress2 The source memory Buffer address for the background layer.
  673. * @param DstAddress The destination memory Buffer address.
  674. * @param Width The width of data to be transferred from source to destination (expressed in number of pixels per line).
  675. * @param Height The height of data to be transferred from source to destination (expressed in number of lines).
  676. * @retval HAL status
  677. */
  678. HAL_StatusTypeDef HAL_DMA2D_BlendingStart_IT(DMA2D_HandleTypeDef *hdma2d, uint32_t SrcAddress1, uint32_t SrcAddress2, uint32_t DstAddress, uint32_t Width, uint32_t Height)
  679. {
  680. /* Check the parameters */
  681. assert_param(IS_DMA2D_LINE(Height));
  682. assert_param(IS_DMA2D_PIXEL(Width));
  683. /* Process locked */
  684. __HAL_LOCK(hdma2d);
  685. /* Change DMA2D peripheral state */
  686. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  687. if(hdma2d->Init.Mode == DMA2D_M2M_BLEND_FG)
  688. {
  689. /*blending & fixed FG*/
  690. WRITE_REG(hdma2d->Instance->FGCOLR, SrcAddress1);
  691. /* Configure the source, destination address and the data size */
  692. DMA2D_SetConfig(hdma2d, SrcAddress2, DstAddress, Width, Height);
  693. }
  694. else if (hdma2d->Init.Mode == DMA2D_M2M_BLEND_BG)
  695. {
  696. /*blending & fixed BG*/
  697. WRITE_REG(hdma2d->Instance->BGCOLR, SrcAddress2);
  698. /* Configure the source, destination address and the data size */
  699. DMA2D_SetConfig(hdma2d, SrcAddress1, DstAddress, Width, Height);
  700. }
  701. else
  702. {
  703. WRITE_REG(hdma2d->Instance->BGMAR, SrcAddress2);
  704. /* Configure the source, destination address and the data size */
  705. DMA2D_SetConfig(hdma2d, SrcAddress1, DstAddress, Width, Height);
  706. }
  707. /* Enable the transfer complete, transfer error and configuration error interrupts */
  708. __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_TC|DMA2D_IT_TE|DMA2D_IT_CE);
  709. /* Enable the Peripheral */
  710. __HAL_DMA2D_ENABLE(hdma2d);
  711. return HAL_OK;
  712. }
  713. /**
  714. * @brief Abort the DMA2D Transfer.
  715. * @param hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
  716. * the configuration information for the DMA2D.
  717. * @retval HAL status
  718. */
  719. HAL_StatusTypeDef HAL_DMA2D_Abort(DMA2D_HandleTypeDef *hdma2d)
  720. {
  721. uint32_t tickstart;
  722. /* Abort the DMA2D transfer */
  723. /* START bit is reset to make sure not to set it again, in the event the HW clears it
  724. between the register read and the register write by the CPU (writing 0 has no
  725. effect on START bitvalue) */
  726. MODIFY_REG(hdma2d->Instance->CR, DMA2D_CR_ABORT|DMA2D_CR_START, DMA2D_CR_ABORT);
  727. /* Get tick */
  728. tickstart = HAL_GetTick();
  729. /* Check if the DMA2D is effectively disabled */
  730. while((hdma2d->Instance->CR & DMA2D_CR_START) != 0U)
  731. {
  732. if((HAL_GetTick() - tickstart ) > DMA2D_TIMEOUT_ABORT)
  733. {
  734. /* Update error code */
  735. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
  736. /* Change the DMA2D state */
  737. hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
  738. /* Process Unlocked */
  739. __HAL_UNLOCK(hdma2d);
  740. return HAL_TIMEOUT;
  741. }
  742. }
  743. /* Disable the Transfer Complete, Transfer Error and Configuration Error interrupts */
  744. __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TC|DMA2D_IT_TE|DMA2D_IT_CE);
  745. /* Change the DMA2D state*/
  746. hdma2d->State = HAL_DMA2D_STATE_READY;
  747. /* Process Unlocked */
  748. __HAL_UNLOCK(hdma2d);
  749. return HAL_OK;
  750. }
  751. /**
  752. * @brief Suspend the DMA2D Transfer.
  753. * @param hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
  754. * the configuration information for the DMA2D.
  755. * @retval HAL status
  756. */
  757. HAL_StatusTypeDef HAL_DMA2D_Suspend(DMA2D_HandleTypeDef *hdma2d)
  758. {
  759. uint32_t tickstart;
  760. /* Suspend the DMA2D transfer */
  761. /* START bit is reset to make sure not to set it again, in the event the HW clears it
  762. between the register read and the register write by the CPU (writing 0 has no
  763. effect on START bitvalue). */
  764. MODIFY_REG(hdma2d->Instance->CR, DMA2D_CR_SUSP|DMA2D_CR_START, DMA2D_CR_SUSP);
  765. /* Get tick */
  766. tickstart = HAL_GetTick();
  767. /* Check if the DMA2D is effectively suspended */
  768. while ((hdma2d->Instance->CR & (DMA2D_CR_SUSP | DMA2D_CR_START)) == DMA2D_CR_START)
  769. {
  770. if((HAL_GetTick() - tickstart ) > DMA2D_TIMEOUT_SUSPEND)
  771. {
  772. /* Update error code */
  773. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
  774. /* Change the DMA2D state */
  775. hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
  776. return HAL_TIMEOUT;
  777. }
  778. }
  779. /* Check whether or not a transfer is actually suspended and change the DMA2D state accordingly */
  780. if ((hdma2d->Instance->CR & DMA2D_CR_START) != 0U)
  781. {
  782. hdma2d->State = HAL_DMA2D_STATE_SUSPEND;
  783. }
  784. else
  785. {
  786. /* Make sure SUSP bit is cleared since it is meaningless
  787. when no tranfer is on-going */
  788. CLEAR_BIT(hdma2d->Instance->CR, DMA2D_CR_SUSP);
  789. }
  790. return HAL_OK;
  791. }
  792. /**
  793. * @brief Resume the DMA2D Transfer.
  794. * @param hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
  795. * the configuration information for the DMA2D.
  796. * @retval HAL status
  797. */
  798. HAL_StatusTypeDef HAL_DMA2D_Resume(DMA2D_HandleTypeDef *hdma2d)
  799. {
  800. /* Check the SUSP and START bits */
  801. if((hdma2d->Instance->CR & (DMA2D_CR_SUSP | DMA2D_CR_START)) == (DMA2D_CR_SUSP | DMA2D_CR_START))
  802. {
  803. /* Ongoing transfer is suspended: change the DMA2D state before resuming */
  804. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  805. }
  806. /* Resume the DMA2D transfer */
  807. /* START bit is reset to make sure not to set it again, in the event the HW clears it
  808. between the register read and the register write by the CPU (writing 0 has no
  809. effect on START bitvalue). */
  810. CLEAR_BIT(hdma2d->Instance->CR, (DMA2D_CR_SUSP|DMA2D_CR_START));
  811. return HAL_OK;
  812. }
  813. /**
  814. * @brief Enable the DMA2D CLUT Transfer.
  815. * @param hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
  816. * the configuration information for the DMA2D.
  817. * @param LayerIdx DMA2D Layer index.
  818. * This parameter can be one of the following values:
  819. * DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
  820. * @retval HAL status
  821. */
  822. HAL_StatusTypeDef HAL_DMA2D_EnableCLUT(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
  823. {
  824. /* Check the parameters */
  825. assert_param(IS_DMA2D_LAYER(LayerIdx));
  826. /* Process locked */
  827. __HAL_LOCK(hdma2d);
  828. /* Change DMA2D peripheral state */
  829. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  830. if(LayerIdx == DMA2D_BACKGROUND_LAYER)
  831. {
  832. /* Enable the background CLUT loading */
  833. SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
  834. }
  835. else
  836. {
  837. /* Enable the foreground CLUT loading */
  838. SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
  839. }
  840. return HAL_OK;
  841. }
  842. /**
  843. * @brief Start DMA2D CLUT Loading.
  844. * @param hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
  845. * the configuration information for the DMA2D.
  846. * @param CLUTCfg Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
  847. * the configuration information for the color look up table.
  848. * @param LayerIdx DMA2D Layer index.
  849. * This parameter can be one of the following values:
  850. * DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
  851. * @retval HAL status
  852. */
  853. HAL_StatusTypeDef HAL_DMA2D_CLUTStartLoad(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef *CLUTCfg, uint32_t LayerIdx)
  854. {
  855. /* Check the parameters */
  856. assert_param(IS_DMA2D_LAYER(LayerIdx));
  857. assert_param(IS_DMA2D_CLUT_CM(CLUTCfg->CLUTColorMode));
  858. assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg->Size));
  859. /* Process locked */
  860. __HAL_LOCK(hdma2d);
  861. /* Change DMA2D peripheral state */
  862. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  863. /* Configure the CLUT of the background DMA2D layer */
  864. if(LayerIdx == DMA2D_BACKGROUND_LAYER)
  865. {
  866. /* Write background CLUT memory address */
  867. WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg->pCLUT);
  868. /* Write background CLUT size and CLUT color mode */
  869. MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
  870. ((CLUTCfg->Size << DMA2D_BGPFCCR_CS_Pos) | (CLUTCfg->CLUTColorMode << DMA2D_BGPFCCR_CCM_Pos)));
  871. /* Enable the CLUT loading for the background */
  872. SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
  873. }
  874. /* Configure the CLUT of the foreground DMA2D layer */
  875. else
  876. {
  877. /* Write foreground CLUT memory address */
  878. WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg->pCLUT);
  879. /* Write foreground CLUT size and CLUT color mode */
  880. MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
  881. ((CLUTCfg->Size << DMA2D_FGPFCCR_CS_Pos) | (CLUTCfg->CLUTColorMode << DMA2D_FGPFCCR_CCM_Pos)));
  882. /* Enable the CLUT loading for the foreground */
  883. SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
  884. }
  885. return HAL_OK;
  886. }
  887. /**
  888. * @brief Start DMA2D CLUT Loading with interrupt enabled.
  889. * @param hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
  890. * the configuration information for the DMA2D.
  891. * @param CLUTCfg Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
  892. * the configuration information for the color look up table.
  893. * @param LayerIdx DMA2D Layer index.
  894. * This parameter can be one of the following values:
  895. * DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
  896. * @retval HAL status
  897. */
  898. HAL_StatusTypeDef HAL_DMA2D_CLUTStartLoad_IT(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef *CLUTCfg, uint32_t LayerIdx)
  899. {
  900. /* Check the parameters */
  901. assert_param(IS_DMA2D_LAYER(LayerIdx));
  902. assert_param(IS_DMA2D_CLUT_CM(CLUTCfg->CLUTColorMode));
  903. assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg->Size));
  904. /* Process locked */
  905. __HAL_LOCK(hdma2d);
  906. /* Change DMA2D peripheral state */
  907. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  908. /* Configure the CLUT of the background DMA2D layer */
  909. if(LayerIdx == DMA2D_BACKGROUND_LAYER)
  910. {
  911. /* Write background CLUT memory address */
  912. WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg->pCLUT);
  913. /* Write background CLUT size and CLUT color mode */
  914. MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
  915. ((CLUTCfg->Size << DMA2D_BGPFCCR_CS_Pos) | (CLUTCfg->CLUTColorMode << DMA2D_BGPFCCR_CCM_Pos)));
  916. /* Enable the CLUT Transfer Complete, transfer Error, configuration Error and CLUT Access Error interrupts */
  917. __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE |DMA2D_IT_CAE);
  918. /* Enable the CLUT loading for the background */
  919. SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
  920. }
  921. /* Configure the CLUT of the foreground DMA2D layer */
  922. else
  923. {
  924. /* Write foreground CLUT memory address */
  925. WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg->pCLUT);
  926. /* Write foreground CLUT size and CLUT color mode */
  927. MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
  928. ((CLUTCfg->Size << DMA2D_FGPFCCR_CS_Pos) | (CLUTCfg->CLUTColorMode << DMA2D_FGPFCCR_CCM_Pos)));
  929. /* Enable the CLUT Transfer Complete, transfer Error, configuration Error and CLUT Access Error interrupts */
  930. __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE |DMA2D_IT_CAE);
  931. /* Enable the CLUT loading for the foreground */
  932. SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
  933. }
  934. return HAL_OK;
  935. }
  936. /**
  937. * @brief Start DMA2D CLUT Loading.
  938. * @param hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
  939. * the configuration information for the DMA2D.
  940. * @param CLUTCfg Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
  941. * the configuration information for the color look up table.
  942. * @param LayerIdx DMA2D Layer index.
  943. * This parameter can be one of the following values:
  944. * DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
  945. * @note API obsolete and maintained for compatibility with legacy. User is
  946. * invited to resort to HAL_DMA2D_CLUTStartLoad() instead to benefit from
  947. * code compactness, code size and improved heap usage.
  948. * @retval HAL status
  949. */
  950. HAL_StatusTypeDef HAL_DMA2D_CLUTLoad(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef CLUTCfg, uint32_t LayerIdx)
  951. {
  952. /* Check the parameters */
  953. assert_param(IS_DMA2D_LAYER(LayerIdx));
  954. assert_param(IS_DMA2D_CLUT_CM(CLUTCfg.CLUTColorMode));
  955. assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg.Size));
  956. /* Process locked */
  957. __HAL_LOCK(hdma2d);
  958. /* Change DMA2D peripheral state */
  959. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  960. /* Configure the CLUT of the background DMA2D layer */
  961. if(LayerIdx == DMA2D_BACKGROUND_LAYER)
  962. {
  963. /* Write background CLUT memory address */
  964. WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg.pCLUT);
  965. /* Write background CLUT size and CLUT color mode */
  966. MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
  967. ((CLUTCfg.Size << DMA2D_BGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_BGPFCCR_CCM_Pos)));
  968. /* Enable the CLUT loading for the background */
  969. SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
  970. }
  971. /* Configure the CLUT of the foreground DMA2D layer */
  972. else
  973. {
  974. /* Write foreground CLUT memory address */
  975. WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg.pCLUT);
  976. /* Write foreground CLUT size and CLUT color mode */
  977. MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
  978. ((CLUTCfg.Size << DMA2D_FGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_FGPFCCR_CCM_Pos)));
  979. /* Enable the CLUT loading for the foreground */
  980. SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
  981. }
  982. return HAL_OK;
  983. }
  984. /**
  985. * @brief Start DMA2D CLUT Loading with interrupt enabled.
  986. * @param hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
  987. * the configuration information for the DMA2D.
  988. * @param CLUTCfg Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
  989. * the configuration information for the color look up table.
  990. * @param LayerIdx DMA2D Layer index.
  991. * This parameter can be one of the following values:
  992. * DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
  993. * @note API obsolete and maintained for compatibility with legacy. User is
  994. * invited to resort to HAL_DMA2D_CLUTStartLoad_IT() instead to benefit
  995. * from code compactness, code size and improved heap usage.
  996. * @retval HAL status
  997. */
  998. HAL_StatusTypeDef HAL_DMA2D_CLUTLoad_IT(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef CLUTCfg, uint32_t LayerIdx)
  999. {
  1000. /* Check the parameters */
  1001. assert_param(IS_DMA2D_LAYER(LayerIdx));
  1002. assert_param(IS_DMA2D_CLUT_CM(CLUTCfg.CLUTColorMode));
  1003. assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg.Size));
  1004. /* Process locked */
  1005. __HAL_LOCK(hdma2d);
  1006. /* Change DMA2D peripheral state */
  1007. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  1008. /* Configure the CLUT of the background DMA2D layer */
  1009. if(LayerIdx == DMA2D_BACKGROUND_LAYER)
  1010. {
  1011. /* Write background CLUT memory address */
  1012. WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg.pCLUT);
  1013. /* Write background CLUT size and CLUT color mode */
  1014. MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
  1015. ((CLUTCfg.Size << DMA2D_BGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_BGPFCCR_CCM_Pos)));
  1016. /* Enable the CLUT Transfer Complete, transfer Error, configuration Error and CLUT Access Error interrupts */
  1017. __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE |DMA2D_IT_CAE);
  1018. /* Enable the CLUT loading for the background */
  1019. SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
  1020. }
  1021. /* Configure the CLUT of the foreground DMA2D layer */
  1022. else
  1023. {
  1024. /* Write foreground CLUT memory address */
  1025. WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg.pCLUT);
  1026. /* Write foreground CLUT size and CLUT color mode */
  1027. MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
  1028. ((CLUTCfg.Size << DMA2D_FGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_FGPFCCR_CCM_Pos)));
  1029. /* Enable the CLUT Transfer Complete, transfer Error, configuration Error and CLUT Access Error interrupts */
  1030. __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE |DMA2D_IT_CAE);
  1031. /* Enable the CLUT loading for the foreground */
  1032. SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
  1033. }
  1034. return HAL_OK;
  1035. }
  1036. /**
  1037. * @brief Abort the DMA2D CLUT loading.
  1038. * @param hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
  1039. * the configuration information for the DMA2D.
  1040. * @param LayerIdx DMA2D Layer index.
  1041. * This parameter can be one of the following values:
  1042. * DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
  1043. * @retval HAL status
  1044. */
  1045. HAL_StatusTypeDef HAL_DMA2D_CLUTLoading_Abort(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
  1046. {
  1047. uint32_t tickstart;
  1048. const __IO uint32_t * reg = &(hdma2d->Instance->BGPFCCR); /* by default, point at background register */
  1049. /* Abort the CLUT loading */
  1050. SET_BIT(hdma2d->Instance->CR, DMA2D_CR_ABORT);
  1051. /* If foreground CLUT loading is considered, update local variables */
  1052. if(LayerIdx == DMA2D_FOREGROUND_LAYER)
  1053. {
  1054. reg = &(hdma2d->Instance->FGPFCCR);
  1055. }
  1056. /* Get tick */
  1057. tickstart = HAL_GetTick();
  1058. /* Check if the CLUT loading is aborted */
  1059. while((*reg & DMA2D_BGPFCCR_START) != 0U)
  1060. {
  1061. if((HAL_GetTick() - tickstart ) > DMA2D_TIMEOUT_ABORT)
  1062. {
  1063. /* Update error code */
  1064. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
  1065. /* Change the DMA2D state */
  1066. hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
  1067. /* Process Unlocked */
  1068. __HAL_UNLOCK(hdma2d);
  1069. return HAL_TIMEOUT;
  1070. }
  1071. }
  1072. /* Disable the CLUT Transfer Complete, Transfer Error, Configuration Error and CLUT Access Error interrupts */
  1073. __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE |DMA2D_IT_CAE);
  1074. /* Change the DMA2D state*/
  1075. hdma2d->State = HAL_DMA2D_STATE_READY;
  1076. /* Process Unlocked */
  1077. __HAL_UNLOCK(hdma2d);
  1078. return HAL_OK;
  1079. }
  1080. /**
  1081. * @brief Suspend the DMA2D CLUT loading.
  1082. * @param hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
  1083. * the configuration information for the DMA2D.
  1084. * @param LayerIdx DMA2D Layer index.
  1085. * This parameter can be one of the following values:
  1086. * DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
  1087. * @retval HAL status
  1088. */
  1089. HAL_StatusTypeDef HAL_DMA2D_CLUTLoading_Suspend(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
  1090. {
  1091. uint32_t tickstart;
  1092. uint32_t loadsuspended;
  1093. const __IO uint32_t * reg = &(hdma2d->Instance->BGPFCCR); /* by default, point at background register */
  1094. /* Suspend the CLUT loading */
  1095. SET_BIT(hdma2d->Instance->CR, DMA2D_CR_SUSP);
  1096. /* If foreground CLUT loading is considered, update local variables */
  1097. if(LayerIdx == DMA2D_FOREGROUND_LAYER)
  1098. {
  1099. reg = &(hdma2d->Instance->FGPFCCR);
  1100. }
  1101. /* Get tick */
  1102. tickstart = HAL_GetTick();
  1103. /* Check if the CLUT loading is suspended */
  1104. loadsuspended = ((hdma2d->Instance->CR & DMA2D_CR_SUSP) == DMA2D_CR_SUSP)? 1UL: 0UL; /*1st condition: Suspend Check*/
  1105. loadsuspended |= ((*reg & DMA2D_BGPFCCR_START) != DMA2D_BGPFCCR_START)? 1UL: 0UL; /*2nd condition: Not Start Check */
  1106. while (loadsuspended == 0UL)
  1107. {
  1108. if((HAL_GetTick() - tickstart ) > DMA2D_TIMEOUT_SUSPEND)
  1109. {
  1110. /* Update error code */
  1111. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
  1112. /* Change the DMA2D state */
  1113. hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
  1114. return HAL_TIMEOUT;
  1115. }
  1116. loadsuspended = ((hdma2d->Instance->CR & DMA2D_CR_SUSP) == DMA2D_CR_SUSP)? 1UL: 0UL; /*1st condition: Suspend Check*/
  1117. loadsuspended |= ((*reg & DMA2D_BGPFCCR_START) != DMA2D_BGPFCCR_START)? 1UL: 0UL; /*2nd condition: Not Start Check */
  1118. }
  1119. /* Check whether or not a transfer is actually suspended and change the DMA2D state accordingly */
  1120. if ((*reg & DMA2D_BGPFCCR_START) != 0U)
  1121. {
  1122. hdma2d->State = HAL_DMA2D_STATE_SUSPEND;
  1123. }
  1124. else
  1125. {
  1126. /* Make sure SUSP bit is cleared since it is meaningless
  1127. when no tranfer is on-going */
  1128. CLEAR_BIT(hdma2d->Instance->CR, DMA2D_CR_SUSP);
  1129. }
  1130. return HAL_OK;
  1131. }
  1132. /**
  1133. * @brief Resume the DMA2D CLUT loading.
  1134. * @param hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
  1135. * the configuration information for the DMA2D.
  1136. * @param LayerIdx DMA2D Layer index.
  1137. * This parameter can be one of the following values:
  1138. * DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
  1139. * @retval HAL status
  1140. */
  1141. HAL_StatusTypeDef HAL_DMA2D_CLUTLoading_Resume(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
  1142. {
  1143. /* Check the SUSP and START bits for background or foreground CLUT loading */
  1144. if(LayerIdx == DMA2D_BACKGROUND_LAYER)
  1145. {
  1146. /* Background CLUT loading suspension check */
  1147. if ((hdma2d->Instance->CR & DMA2D_CR_SUSP) == DMA2D_CR_SUSP)
  1148. {
  1149. if((hdma2d->Instance->BGPFCCR & DMA2D_BGPFCCR_START) == DMA2D_BGPFCCR_START)
  1150. {
  1151. /* Ongoing CLUT loading is suspended: change the DMA2D state before resuming */
  1152. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  1153. }
  1154. }
  1155. }
  1156. else
  1157. {
  1158. /* Foreground CLUT loading suspension check */
  1159. if ((hdma2d->Instance->CR & DMA2D_CR_SUSP) == DMA2D_CR_SUSP)
  1160. {
  1161. if ((hdma2d->Instance->FGPFCCR & DMA2D_FGPFCCR_START) == DMA2D_FGPFCCR_START)
  1162. {
  1163. /* Ongoing CLUT loading is suspended: change the DMA2D state before resuming */
  1164. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  1165. }
  1166. }
  1167. }
  1168. /* Resume the CLUT loading */
  1169. CLEAR_BIT(hdma2d->Instance->CR, DMA2D_CR_SUSP);
  1170. return HAL_OK;
  1171. }
  1172. /**
  1173. * @brief Polling for transfer complete or CLUT loading.
  1174. * @param hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
  1175. * the configuration information for the DMA2D.
  1176. * @param Timeout Timeout duration
  1177. * @retval HAL status
  1178. */
  1179. HAL_StatusTypeDef HAL_DMA2D_PollForTransfer(DMA2D_HandleTypeDef *hdma2d, uint32_t Timeout)
  1180. {
  1181. uint32_t tickstart;
  1182. uint32_t layer_start;
  1183. __IO uint32_t isrflags = 0x0U;
  1184. /* Polling for DMA2D transfer */
  1185. if((hdma2d->Instance->CR & DMA2D_CR_START) != 0U)
  1186. {
  1187. /* Get tick */
  1188. tickstart = HAL_GetTick();
  1189. while(__HAL_DMA2D_GET_FLAG(hdma2d, DMA2D_FLAG_TC) == 0U)
  1190. {
  1191. isrflags = READ_REG(hdma2d->Instance->ISR);
  1192. if ((isrflags & (DMA2D_FLAG_CE|DMA2D_FLAG_TE)) != 0U)
  1193. {
  1194. if ((isrflags & DMA2D_FLAG_CE) != 0U)
  1195. {
  1196. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CE;
  1197. }
  1198. if ((isrflags & DMA2D_FLAG_TE) != 0U)
  1199. {
  1200. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TE;
  1201. }
  1202. /* Clear the transfer and configuration error flags */
  1203. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CE | DMA2D_FLAG_TE);
  1204. /* Change DMA2D state */
  1205. hdma2d->State = HAL_DMA2D_STATE_ERROR;
  1206. /* Process unlocked */
  1207. __HAL_UNLOCK(hdma2d);
  1208. return HAL_ERROR;
  1209. }
  1210. /* Check for the Timeout */
  1211. if(Timeout != HAL_MAX_DELAY)
  1212. {
  1213. if(((HAL_GetTick() - tickstart ) > Timeout)||(Timeout == 0U))
  1214. {
  1215. /* Update error code */
  1216. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
  1217. /* Change the DMA2D state */
  1218. hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
  1219. /* Process unlocked */
  1220. __HAL_UNLOCK(hdma2d);
  1221. return HAL_TIMEOUT;
  1222. }
  1223. }
  1224. }
  1225. }
  1226. /* Polling for CLUT loading (foreground or background) */
  1227. layer_start = hdma2d->Instance->FGPFCCR & DMA2D_FGPFCCR_START;
  1228. layer_start |= hdma2d->Instance->BGPFCCR & DMA2D_BGPFCCR_START;
  1229. if (layer_start != 0U)
  1230. {
  1231. /* Get tick */
  1232. tickstart = HAL_GetTick();
  1233. while(__HAL_DMA2D_GET_FLAG(hdma2d, DMA2D_FLAG_CTC) == 0U)
  1234. {
  1235. isrflags = READ_REG(hdma2d->Instance->ISR);
  1236. if ((isrflags & (DMA2D_FLAG_CAE|DMA2D_FLAG_CE|DMA2D_FLAG_TE)) != 0U)
  1237. {
  1238. if ((isrflags & DMA2D_FLAG_CAE) != 0U)
  1239. {
  1240. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CAE;
  1241. }
  1242. if ((isrflags & DMA2D_FLAG_CE) != 0U)
  1243. {
  1244. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CE;
  1245. }
  1246. if ((isrflags & DMA2D_FLAG_TE) != 0U)
  1247. {
  1248. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TE;
  1249. }
  1250. /* Clear the CLUT Access Error, Configuration Error and Transfer Error flags */
  1251. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CAE | DMA2D_FLAG_CE | DMA2D_FLAG_TE);
  1252. /* Change DMA2D state */
  1253. hdma2d->State= HAL_DMA2D_STATE_ERROR;
  1254. /* Process unlocked */
  1255. __HAL_UNLOCK(hdma2d);
  1256. return HAL_ERROR;
  1257. }
  1258. /* Check for the Timeout */
  1259. if(Timeout != HAL_MAX_DELAY)
  1260. {
  1261. if(((HAL_GetTick() - tickstart ) > Timeout)||(Timeout == 0U))
  1262. {
  1263. /* Update error code */
  1264. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
  1265. /* Change the DMA2D state */
  1266. hdma2d->State= HAL_DMA2D_STATE_TIMEOUT;
  1267. /* Process unlocked */
  1268. __HAL_UNLOCK(hdma2d);
  1269. return HAL_TIMEOUT;
  1270. }
  1271. }
  1272. }
  1273. }
  1274. /* Clear the transfer complete and CLUT loading flags */
  1275. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TC|DMA2D_FLAG_CTC);
  1276. /* Change DMA2D state */
  1277. hdma2d->State = HAL_DMA2D_STATE_READY;
  1278. /* Process unlocked */
  1279. __HAL_UNLOCK(hdma2d);
  1280. return HAL_OK;
  1281. }
  1282. /**
  1283. * @brief Handle DMA2D interrupt request.
  1284. * @param hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
  1285. * the configuration information for the DMA2D.
  1286. * @retval HAL status
  1287. */
  1288. void HAL_DMA2D_IRQHandler(DMA2D_HandleTypeDef *hdma2d)
  1289. {
  1290. uint32_t isrflags = READ_REG(hdma2d->Instance->ISR);
  1291. uint32_t crflags = READ_REG(hdma2d->Instance->CR);
  1292. /* Transfer Error Interrupt management ***************************************/
  1293. if ((isrflags & DMA2D_FLAG_TE) != 0U)
  1294. {
  1295. if ((crflags & DMA2D_IT_TE) != 0U)
  1296. {
  1297. /* Disable the transfer Error interrupt */
  1298. __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TE);
  1299. /* Update error code */
  1300. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TE;
  1301. /* Clear the transfer error flag */
  1302. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TE);
  1303. /* Change DMA2D state */
  1304. hdma2d->State = HAL_DMA2D_STATE_ERROR;
  1305. /* Process Unlocked */
  1306. __HAL_UNLOCK(hdma2d);
  1307. if(hdma2d->XferErrorCallback != NULL)
  1308. {
  1309. /* Transfer error Callback */
  1310. hdma2d->XferErrorCallback(hdma2d);
  1311. }
  1312. }
  1313. }
  1314. /* Configuration Error Interrupt management **********************************/
  1315. if ((isrflags & DMA2D_FLAG_CE) != 0U)
  1316. {
  1317. if ((crflags & DMA2D_IT_CE) != 0U)
  1318. {
  1319. /* Disable the Configuration Error interrupt */
  1320. __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CE);
  1321. /* Clear the Configuration error flag */
  1322. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CE);
  1323. /* Update error code */
  1324. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CE;
  1325. /* Change DMA2D state */
  1326. hdma2d->State = HAL_DMA2D_STATE_ERROR;
  1327. /* Process Unlocked */
  1328. __HAL_UNLOCK(hdma2d);
  1329. if(hdma2d->XferErrorCallback != NULL)
  1330. {
  1331. /* Transfer error Callback */
  1332. hdma2d->XferErrorCallback(hdma2d);
  1333. }
  1334. }
  1335. }
  1336. /* CLUT access Error Interrupt management ***********************************/
  1337. if ((isrflags & DMA2D_FLAG_CAE) != 0U)
  1338. {
  1339. if ((crflags & DMA2D_IT_CAE) != 0U)
  1340. {
  1341. /* Disable the CLUT access error interrupt */
  1342. __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CAE);
  1343. /* Clear the CLUT access error flag */
  1344. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CAE);
  1345. /* Update error code */
  1346. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CAE;
  1347. /* Change DMA2D state */
  1348. hdma2d->State = HAL_DMA2D_STATE_ERROR;
  1349. /* Process Unlocked */
  1350. __HAL_UNLOCK(hdma2d);
  1351. if(hdma2d->XferErrorCallback != NULL)
  1352. {
  1353. /* Transfer error Callback */
  1354. hdma2d->XferErrorCallback(hdma2d);
  1355. }
  1356. }
  1357. }
  1358. /* Transfer watermark Interrupt management **********************************/
  1359. if ((isrflags & DMA2D_FLAG_TW) != 0U)
  1360. {
  1361. if ((crflags & DMA2D_IT_TW) != 0U)
  1362. {
  1363. /* Disable the transfer watermark interrupt */
  1364. __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TW);
  1365. /* Clear the transfer watermark flag */
  1366. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TW);
  1367. /* Transfer watermark Callback */
  1368. #if (USE_HAL_DMA2D_REGISTER_CALLBACKS == 1)
  1369. hdma2d->LineEventCallback(hdma2d);
  1370. #else
  1371. HAL_DMA2D_LineEventCallback(hdma2d);
  1372. #endif /* USE_HAL_DMA2D_REGISTER_CALLBACKS */
  1373. }
  1374. }
  1375. /* Transfer Complete Interrupt management ************************************/
  1376. if ((isrflags & DMA2D_FLAG_TC) != 0U)
  1377. {
  1378. if ((crflags & DMA2D_IT_TC) != 0U)
  1379. {
  1380. /* Disable the transfer complete interrupt */
  1381. __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TC);
  1382. /* Clear the transfer complete flag */
  1383. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TC);
  1384. /* Update error code */
  1385. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_NONE;
  1386. /* Change DMA2D state */
  1387. hdma2d->State = HAL_DMA2D_STATE_READY;
  1388. /* Process Unlocked */
  1389. __HAL_UNLOCK(hdma2d);
  1390. if(hdma2d->XferCpltCallback != NULL)
  1391. {
  1392. /* Transfer complete Callback */
  1393. hdma2d->XferCpltCallback(hdma2d);
  1394. }
  1395. }
  1396. }
  1397. /* CLUT Transfer Complete Interrupt management ******************************/
  1398. if ((isrflags & DMA2D_FLAG_CTC) != 0U)
  1399. {
  1400. if ((crflags & DMA2D_IT_CTC) != 0U)
  1401. {
  1402. /* Disable the CLUT transfer complete interrupt */
  1403. __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CTC);
  1404. /* Clear the CLUT transfer complete flag */
  1405. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CTC);
  1406. /* Update error code */
  1407. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_NONE;
  1408. /* Change DMA2D state */
  1409. hdma2d->State = HAL_DMA2D_STATE_READY;
  1410. /* Process Unlocked */
  1411. __HAL_UNLOCK(hdma2d);
  1412. /* CLUT Transfer complete Callback */
  1413. #if (USE_HAL_DMA2D_REGISTER_CALLBACKS == 1)
  1414. hdma2d->CLUTLoadingCpltCallback(hdma2d);
  1415. #else
  1416. HAL_DMA2D_CLUTLoadingCpltCallback(hdma2d);
  1417. #endif /* USE_HAL_DMA2D_REGISTER_CALLBACKS */
  1418. }
  1419. }
  1420. }
  1421. /**
  1422. * @brief Transfer watermark callback.
  1423. * @param hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
  1424. * the configuration information for the DMA2D.
  1425. * @retval None
  1426. */
  1427. __weak void HAL_DMA2D_LineEventCallback(DMA2D_HandleTypeDef *hdma2d)
  1428. {
  1429. /* Prevent unused argument(s) compilation warning */
  1430. UNUSED(hdma2d);
  1431. /* NOTE : This function should not be modified; when the callback is needed,
  1432. the HAL_DMA2D_LineEventCallback can be implemented in the user file.
  1433. */
  1434. }
  1435. /**
  1436. * @brief CLUT Transfer Complete callback.
  1437. * @param hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
  1438. * the configuration information for the DMA2D.
  1439. * @retval None
  1440. */
  1441. __weak void HAL_DMA2D_CLUTLoadingCpltCallback(DMA2D_HandleTypeDef *hdma2d)
  1442. {
  1443. /* Prevent unused argument(s) compilation warning */
  1444. UNUSED(hdma2d);
  1445. /* NOTE : This function should not be modified; when the callback is needed,
  1446. the HAL_DMA2D_CLUTLoadingCpltCallback can be implemented in the user file.
  1447. */
  1448. }
  1449. /**
  1450. * @}
  1451. */
  1452. /** @defgroup DMA2D_Exported_Functions_Group3 Peripheral Control functions
  1453. * @brief Peripheral Control functions
  1454. *
  1455. @verbatim
  1456. ===============================================================================
  1457. ##### Peripheral Control functions #####
  1458. ===============================================================================
  1459. [..] This section provides functions allowing to:
  1460. (+) Configure the DMA2D foreground or background layer parameters.
  1461. (+) Configure the DMA2D CLUT transfer.
  1462. (+) Configure the line watermark
  1463. (+) Configure the dead time value.
  1464. (+) Enable or disable the dead time value functionality.
  1465. @endverbatim
  1466. * @{
  1467. */
  1468. /**
  1469. * @brief Configure the DMA2D Layer according to the specified
  1470. * parameters in the DMA2D_HandleTypeDef.
  1471. * @param hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
  1472. * the configuration information for the DMA2D.
  1473. * @param LayerIdx DMA2D Layer index.
  1474. * This parameter can be one of the following values:
  1475. * DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
  1476. * @retval HAL status
  1477. */
  1478. HAL_StatusTypeDef HAL_DMA2D_ConfigLayer(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
  1479. {
  1480. DMA2D_LayerCfgTypeDef *pLayerCfg;
  1481. uint32_t regMask, regValue;
  1482. /* Check the parameters */
  1483. assert_param(IS_DMA2D_LAYER(LayerIdx));
  1484. assert_param(IS_DMA2D_OFFSET(hdma2d->LayerCfg[LayerIdx].InputOffset));
  1485. if(hdma2d->Init.Mode != DMA2D_R2M)
  1486. {
  1487. assert_param(IS_DMA2D_INPUT_COLOR_MODE(hdma2d->LayerCfg[LayerIdx].InputColorMode));
  1488. if(hdma2d->Init.Mode != DMA2D_M2M)
  1489. {
  1490. assert_param(IS_DMA2D_ALPHA_MODE(hdma2d->LayerCfg[LayerIdx].AlphaMode));
  1491. }
  1492. }
  1493. assert_param(IS_DMA2D_ALPHA_INVERTED(hdma2d->LayerCfg[LayerIdx].AlphaInverted));
  1494. assert_param(IS_DMA2D_RB_SWAP(hdma2d->LayerCfg[LayerIdx].RedBlueSwap));
  1495. if((LayerIdx == DMA2D_FOREGROUND_LAYER) && (hdma2d->LayerCfg[LayerIdx].InputColorMode == DMA2D_INPUT_YCBCR))
  1496. {
  1497. assert_param(IS_DMA2D_CHROMA_SUB_SAMPLING(hdma2d->LayerCfg[LayerIdx].ChromaSubSampling));
  1498. }
  1499. /* Process locked */
  1500. __HAL_LOCK(hdma2d);
  1501. /* Change DMA2D peripheral state */
  1502. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  1503. pLayerCfg = &hdma2d->LayerCfg[LayerIdx];
  1504. /* Prepare the value to be written to the BGPFCCR or FGPFCCR register */
  1505. regValue = pLayerCfg->InputColorMode | (pLayerCfg->AlphaMode << DMA2D_BGPFCCR_AM_Pos) |\
  1506. (pLayerCfg->AlphaInverted << DMA2D_BGPFCCR_AI_Pos) | (pLayerCfg->RedBlueSwap << DMA2D_BGPFCCR_RBS_Pos);
  1507. regMask = (DMA2D_BGPFCCR_CM | DMA2D_BGPFCCR_AM | DMA2D_BGPFCCR_ALPHA | DMA2D_BGPFCCR_AI | DMA2D_BGPFCCR_RBS);
  1508. if ((pLayerCfg->InputColorMode == DMA2D_INPUT_A4) || (pLayerCfg->InputColorMode == DMA2D_INPUT_A8))
  1509. {
  1510. regValue |= (pLayerCfg->InputAlpha & DMA2D_BGPFCCR_ALPHA);
  1511. }
  1512. else
  1513. {
  1514. regValue |= (pLayerCfg->InputAlpha << DMA2D_BGPFCCR_ALPHA_Pos);
  1515. }
  1516. /* Configure the background DMA2D layer */
  1517. if(LayerIdx == DMA2D_BACKGROUND_LAYER)
  1518. {
  1519. /* Write DMA2D BGPFCCR register */
  1520. MODIFY_REG(hdma2d->Instance->BGPFCCR, regMask, regValue);
  1521. /* DMA2D BGOR register configuration -------------------------------------*/
  1522. WRITE_REG(hdma2d->Instance->BGOR, pLayerCfg->InputOffset);
  1523. /* DMA2D BGCOLR register configuration -------------------------------------*/
  1524. if ((pLayerCfg->InputColorMode == DMA2D_INPUT_A4) || (pLayerCfg->InputColorMode == DMA2D_INPUT_A8))
  1525. {
  1526. WRITE_REG(hdma2d->Instance->BGCOLR, pLayerCfg->InputAlpha & (DMA2D_BGCOLR_BLUE|DMA2D_BGCOLR_GREEN|DMA2D_BGCOLR_RED));
  1527. }
  1528. }
  1529. /* Configure the foreground DMA2D layer */
  1530. else
  1531. {
  1532. if(pLayerCfg->InputColorMode == DMA2D_INPUT_YCBCR)
  1533. {
  1534. regValue |= (pLayerCfg->ChromaSubSampling << DMA2D_FGPFCCR_CSS_Pos);
  1535. regMask |= DMA2D_FGPFCCR_CSS;
  1536. }
  1537. /* Write DMA2D FGPFCCR register */
  1538. MODIFY_REG(hdma2d->Instance->FGPFCCR, regMask, regValue);
  1539. /* DMA2D FGOR register configuration -------------------------------------*/
  1540. WRITE_REG(hdma2d->Instance->FGOR, pLayerCfg->InputOffset);
  1541. /* DMA2D FGCOLR register configuration -------------------------------------*/
  1542. if ((pLayerCfg->InputColorMode == DMA2D_INPUT_A4) || (pLayerCfg->InputColorMode == DMA2D_INPUT_A8))
  1543. {
  1544. WRITE_REG(hdma2d->Instance->FGCOLR, pLayerCfg->InputAlpha & (DMA2D_FGCOLR_BLUE|DMA2D_FGCOLR_GREEN|DMA2D_FGCOLR_RED));
  1545. }
  1546. }
  1547. /* Initialize the DMA2D state*/
  1548. hdma2d->State = HAL_DMA2D_STATE_READY;
  1549. /* Process unlocked */
  1550. __HAL_UNLOCK(hdma2d);
  1551. return HAL_OK;
  1552. }
  1553. /**
  1554. * @brief Configure the DMA2D CLUT Transfer.
  1555. * @param hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
  1556. * the configuration information for the DMA2D.
  1557. * @param CLUTCfg Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
  1558. * the configuration information for the color look up table.
  1559. * @param LayerIdx DMA2D Layer index.
  1560. * This parameter can be one of the following values:
  1561. * DMA2D_BACKGROUND_LAYER(0) / DMA2D_FOREGROUND_LAYER(1)
  1562. * @note API obsolete and maintained for compatibility with legacy. User is invited
  1563. * to resort to HAL_DMA2D_CLUTStartLoad() instead to benefit from code compactness,
  1564. * code size and improved heap usage.
  1565. * @retval HAL status
  1566. */
  1567. HAL_StatusTypeDef HAL_DMA2D_ConfigCLUT(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef CLUTCfg, uint32_t LayerIdx)
  1568. {
  1569. /* Check the parameters */
  1570. assert_param(IS_DMA2D_LAYER(LayerIdx));
  1571. assert_param(IS_DMA2D_CLUT_CM(CLUTCfg.CLUTColorMode));
  1572. assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg.Size));
  1573. /* Process locked */
  1574. __HAL_LOCK(hdma2d);
  1575. /* Change DMA2D peripheral state */
  1576. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  1577. /* Configure the CLUT of the background DMA2D layer */
  1578. if(LayerIdx == DMA2D_BACKGROUND_LAYER)
  1579. {
  1580. /* Write background CLUT memory address */
  1581. WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg.pCLUT);
  1582. /* Write background CLUT size and CLUT color mode */
  1583. MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
  1584. ((CLUTCfg.Size << DMA2D_BGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_BGPFCCR_CCM_Pos)));
  1585. }
  1586. /* Configure the CLUT of the foreground DMA2D layer */
  1587. else
  1588. {
  1589. /* Write foreground CLUT memory address */
  1590. WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg.pCLUT);
  1591. /* Write foreground CLUT size and CLUT color mode */
  1592. MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
  1593. ((CLUTCfg.Size << DMA2D_FGPFCCR_CS_Pos) | (CLUTCfg.CLUTColorMode << DMA2D_FGPFCCR_CCM_Pos)));
  1594. }
  1595. /* Set the DMA2D state to Ready*/
  1596. hdma2d->State = HAL_DMA2D_STATE_READY;
  1597. /* Process unlocked */
  1598. __HAL_UNLOCK(hdma2d);
  1599. return HAL_OK;
  1600. }
  1601. /**
  1602. * @brief Configure the line watermark.
  1603. * @param hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
  1604. * the configuration information for the DMA2D.
  1605. * @param Line Line Watermark configuration (maximum 16-bit long value expected).
  1606. * @note HAL_DMA2D_ProgramLineEvent() API enables the transfer watermark interrupt.
  1607. * @note The transfer watermark interrupt is disabled once it has occurred.
  1608. * @retval HAL status
  1609. */
  1610. HAL_StatusTypeDef HAL_DMA2D_ProgramLineEvent(DMA2D_HandleTypeDef *hdma2d, uint32_t Line)
  1611. {
  1612. /* Check the parameters */
  1613. assert_param(IS_DMA2D_LINEWATERMARK(Line));
  1614. if (Line > DMA2D_LWR_LW)
  1615. {
  1616. return HAL_ERROR;
  1617. }
  1618. else
  1619. {
  1620. /* Process locked */
  1621. __HAL_LOCK(hdma2d);
  1622. /* Change DMA2D peripheral state */
  1623. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  1624. /* Sets the Line watermark configuration */
  1625. WRITE_REG(hdma2d->Instance->LWR, Line);
  1626. /* Enable the Line interrupt */
  1627. __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_TW);
  1628. /* Initialize the DMA2D state*/
  1629. hdma2d->State = HAL_DMA2D_STATE_READY;
  1630. /* Process unlocked */
  1631. __HAL_UNLOCK(hdma2d);
  1632. return HAL_OK;
  1633. }
  1634. }
  1635. /**
  1636. * @brief Enable DMA2D dead time feature.
  1637. * @param hdma2d DMA2D handle.
  1638. * @retval HAL status
  1639. */
  1640. HAL_StatusTypeDef HAL_DMA2D_EnableDeadTime(DMA2D_HandleTypeDef *hdma2d)
  1641. {
  1642. /* Process Locked */
  1643. __HAL_LOCK(hdma2d);
  1644. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  1645. /* Set DMA2D_AMTCR EN bit */
  1646. SET_BIT(hdma2d->Instance->AMTCR, DMA2D_AMTCR_EN);
  1647. hdma2d->State = HAL_DMA2D_STATE_READY;
  1648. /* Process Unlocked */
  1649. __HAL_UNLOCK(hdma2d);
  1650. return HAL_OK;
  1651. }
  1652. /**
  1653. * @brief Disable DMA2D dead time feature.
  1654. * @param hdma2d DMA2D handle.
  1655. * @retval HAL status
  1656. */
  1657. HAL_StatusTypeDef HAL_DMA2D_DisableDeadTime(DMA2D_HandleTypeDef *hdma2d)
  1658. {
  1659. /* Process Locked */
  1660. __HAL_LOCK(hdma2d);
  1661. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  1662. /* Clear DMA2D_AMTCR EN bit */
  1663. CLEAR_BIT(hdma2d->Instance->AMTCR, DMA2D_AMTCR_EN);
  1664. hdma2d->State = HAL_DMA2D_STATE_READY;
  1665. /* Process Unlocked */
  1666. __HAL_UNLOCK(hdma2d);
  1667. return HAL_OK;
  1668. }
  1669. /**
  1670. * @brief Configure dead time.
  1671. * @note The dead time value represents the guaranteed minimum number of cycles between
  1672. * two consecutive transactions on the AHB bus.
  1673. * @param hdma2d DMA2D handle.
  1674. * @param DeadTime dead time value.
  1675. * @retval HAL status
  1676. */
  1677. HAL_StatusTypeDef HAL_DMA2D_ConfigDeadTime(DMA2D_HandleTypeDef *hdma2d, uint8_t DeadTime)
  1678. {
  1679. /* Process Locked */
  1680. __HAL_LOCK(hdma2d);
  1681. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  1682. /* Set DMA2D_AMTCR DT field */
  1683. MODIFY_REG(hdma2d->Instance->AMTCR, DMA2D_AMTCR_DT, (((uint32_t) DeadTime) << DMA2D_AMTCR_DT_Pos));
  1684. hdma2d->State = HAL_DMA2D_STATE_READY;
  1685. /* Process Unlocked */
  1686. __HAL_UNLOCK(hdma2d);
  1687. return HAL_OK;
  1688. }
  1689. /**
  1690. * @}
  1691. */
  1692. /** @defgroup DMA2D_Exported_Functions_Group4 Peripheral State and Error functions
  1693. * @brief Peripheral State functions
  1694. *
  1695. @verbatim
  1696. ===============================================================================
  1697. ##### Peripheral State and Errors functions #####
  1698. ===============================================================================
  1699. [..]
  1700. This subsection provides functions allowing to:
  1701. (+) Get the DMA2D state
  1702. (+) Get the DMA2D error code
  1703. @endverbatim
  1704. * @{
  1705. */
  1706. /**
  1707. * @brief Return the DMA2D state
  1708. * @param hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
  1709. * the configuration information for the DMA2D.
  1710. * @retval HAL state
  1711. */
  1712. HAL_DMA2D_StateTypeDef HAL_DMA2D_GetState(DMA2D_HandleTypeDef *hdma2d)
  1713. {
  1714. return hdma2d->State;
  1715. }
  1716. /**
  1717. * @brief Return the DMA2D error code
  1718. * @param hdma2d pointer to a DMA2D_HandleTypeDef structure that contains
  1719. * the configuration information for DMA2D.
  1720. * @retval DMA2D Error Code
  1721. */
  1722. uint32_t HAL_DMA2D_GetError(DMA2D_HandleTypeDef *hdma2d)
  1723. {
  1724. return hdma2d->ErrorCode;
  1725. }
  1726. /**
  1727. * @}
  1728. */
  1729. /**
  1730. * @}
  1731. */
  1732. /** @defgroup DMA2D_Private_Functions DMA2D Private Functions
  1733. * @{
  1734. */
  1735. /**
  1736. * @brief Set the DMA2D transfer parameters.
  1737. * @param hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
  1738. * the configuration information for the specified DMA2D.
  1739. * @param pdata The source memory Buffer address
  1740. * @param DstAddress The destination memory Buffer address
  1741. * @param Width The width of data to be transferred from source to destination.
  1742. * @param Height The height of data to be transferred from source to destination.
  1743. * @retval HAL status
  1744. */
  1745. static void DMA2D_SetConfig(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width, uint32_t Height)
  1746. {
  1747. uint32_t tmp;
  1748. uint32_t tmp1;
  1749. uint32_t tmp2;
  1750. uint32_t tmp3;
  1751. uint32_t tmp4;
  1752. /* Configure DMA2D data size */
  1753. MODIFY_REG(hdma2d->Instance->NLR, (DMA2D_NLR_NL|DMA2D_NLR_PL), (Height| (Width << DMA2D_NLR_PL_Pos)));
  1754. /* Configure DMA2D destination address */
  1755. WRITE_REG(hdma2d->Instance->OMAR, DstAddress);
  1756. /* Register to memory DMA2D mode selected */
  1757. if (hdma2d->Init.Mode == DMA2D_R2M)
  1758. {
  1759. tmp1 = pdata & DMA2D_OCOLR_ALPHA_1;
  1760. tmp2 = pdata & DMA2D_OCOLR_RED_1;
  1761. tmp3 = pdata & DMA2D_OCOLR_GREEN_1;
  1762. tmp4 = pdata & DMA2D_OCOLR_BLUE_1;
  1763. /* Prepare the value to be written to the OCOLR register according to the color mode */
  1764. if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_ARGB8888)
  1765. {
  1766. tmp = (tmp3 | tmp2 | tmp1| tmp4);
  1767. }
  1768. else if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_RGB888)
  1769. {
  1770. tmp = (tmp3 | tmp2 | tmp4);
  1771. }
  1772. else if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_RGB565)
  1773. {
  1774. tmp2 = (tmp2 >> 19U);
  1775. tmp3 = (tmp3 >> 10U);
  1776. tmp4 = (tmp4 >> 3U );
  1777. tmp = ((tmp3 << 5U) | (tmp2 << 11U) | tmp4);
  1778. }
  1779. else if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_ARGB1555)
  1780. {
  1781. tmp1 = (tmp1 >> 31U);
  1782. tmp2 = (tmp2 >> 19U);
  1783. tmp3 = (tmp3 >> 11U);
  1784. tmp4 = (tmp4 >> 3U );
  1785. tmp = ((tmp3 << 5U) | (tmp2 << 10U) | (tmp1 << 15U) | tmp4);
  1786. }
  1787. else /* Dhdma2d->Init.ColorMode = DMA2D_OUTPUT_ARGB4444 */
  1788. {
  1789. tmp1 = (tmp1 >> 28U);
  1790. tmp2 = (tmp2 >> 20U);
  1791. tmp3 = (tmp3 >> 12U);
  1792. tmp4 = (tmp4 >> 4U );
  1793. tmp = ((tmp3 << 4U) | (tmp2 << 8U) | (tmp1 << 12U) | tmp4);
  1794. }
  1795. /* Write to DMA2D OCOLR register */
  1796. WRITE_REG(hdma2d->Instance->OCOLR, tmp);
  1797. }
  1798. else if(hdma2d->Init.Mode == DMA2D_M2M_BLEND_FG) /*M2M_blending with fixed color FG DMA2D Mode selected*/
  1799. {
  1800. WRITE_REG(hdma2d->Instance->BGMAR , pdata);
  1801. }
  1802. else /* M2M, M2M_PFC,M2M_Blending or M2M_blending with fixed color BG DMA2D Mode */
  1803. {
  1804. /* Configure DMA2D source address */
  1805. WRITE_REG(hdma2d->Instance->FGMAR, pdata);
  1806. }
  1807. }
  1808. /**
  1809. * @}
  1810. */
  1811. /**
  1812. * @}
  1813. */
  1814. /**
  1815. * @}
  1816. */
  1817. #endif /* DMA2D */
  1818. #endif /* HAL_DMA2D_MODULE_ENABLED */
  1819. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/