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.
 
 
 

1765 lines
59 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_dma2d.c
  4. * @author MCD Application Team
  5. * @version V1.2.2
  6. * @date 14-April-2017
  7. * @brief DMA2D HAL module driver.
  8. * This file provides firmware functions to manage the following
  9. * functionalities of the DMA2D peripheral:
  10. * + Initialization and de-initialization functions
  11. * + IO operation functions
  12. * + Peripheral Control functions
  13. * + Peripheral State and Errors functions
  14. *
  15. @verbatim
  16. ==============================================================================
  17. ##### How to use this driver #####
  18. ==============================================================================
  19. [..]
  20. (#) Program the required configuration through the following parameters:
  21. the transfer mode, the output color mode and the output offset using
  22. HAL_DMA2D_Init() function.
  23. (#) Program the required configuration through the following parameters:
  24. the input color mode, the input color, the input alpha value, the alpha mode,
  25. the red/blue swap mode, the inverted alpha mode and the input offset using
  26. HAL_DMA2D_ConfigLayer() function for foreground or/and background layer.
  27. *** Polling mode IO operation ***
  28. =================================
  29. [..]
  30. (#) Configure pdata parameter (explained hereafter), destination and data length
  31. and enable the transfer using HAL_DMA2D_Start().
  32. (#) Wait for end of transfer using HAL_DMA2D_PollForTransfer(), at this stage
  33. user can specify the value of timeout according to his end application.
  34. *** Interrupt mode IO operation ***
  35. ===================================
  36. [..]
  37. (#) Configure pdata parameter, destination and data length and enable
  38. the transfer using HAL_DMA2D_Start_IT().
  39. (#) Use HAL_DMA2D_IRQHandler() called under DMA2D_IRQHandler() interrupt subroutine.
  40. (#) At the end of data transfer HAL_DMA2D_IRQHandler() function is executed and user can
  41. add his own function by customization of function pointer XferCpltCallback (member
  42. of DMA2D handle structure).
  43. (#) In case of error, the HAL_DMA2D_IRQHandler() function will call the callback
  44. XferErrorCallback.
  45. -@- In Register-to-Memory transfer mode, pdata parameter is the register
  46. color, in Memory-to-memory or Memory-to-Memory with pixel format
  47. conversion pdata is the source address.
  48. -@- Configure the foreground source address, the background source address,
  49. the destination and data length then Enable the transfer using
  50. HAL_DMA2D_BlendingStart() in polling mode and HAL_DMA2D_BlendingStart_IT()
  51. in interrupt mode.
  52. -@- HAL_DMA2D_BlendingStart() and HAL_DMA2D_BlendingStart_IT() functions
  53. are used if the memory to memory with blending transfer mode is selected.
  54. (#) Optionally, configure and enable the CLUT using HAL_DMA2D_CLUTLoad() in polling
  55. mode or HAL_DMA2D_CLUTLoad_IT() in interrupt mode.
  56. (#) Optionally, configure the line watermark in using the API HAL_DMA2D_ProgramLineEvent()
  57. (#) Optionally, configure the dead time value in the AHB clock cycle inserted between two
  58. consecutive accesses on the AHB master port in using the API HAL_DMA2D_ConfigDeadTime()
  59. and enable/disable the functionality with the APIs HAL_DMA2D_EnableDeadTime() or
  60. HAL_DMA2D_DisableDeadTime().
  61. (#) The transfer can be suspended, resumed and aborted using the following
  62. functions: HAL_DMA2D_Suspend(), HAL_DMA2D_Resume(), HAL_DMA2D_Abort().
  63. (#) The CLUT loading can be suspended, resumed and aborted using the following
  64. functions: HAL_DMA2D_CLUTLoading_Suspend(), HAL_DMA2D_CLUTLoading_Resume(),
  65. HAL_DMA2D_CLUTLoading_Abort().
  66. (#) To control the DMA2D state, use the following function: HAL_DMA2D_GetState().
  67. (#) To read the DMA2D error code, use the following function: HAL_DMA2D_GetError().
  68. *** DMA2D HAL driver macros list ***
  69. =============================================
  70. [..]
  71. Below the list of most used macros in DMA2D HAL driver :
  72. (+) __HAL_DMA2D_ENABLE: Enable the DMA2D peripheral.
  73. (+) __HAL_DMA2D_GET_FLAG: Get the DMA2D pending flags.
  74. (+) __HAL_DMA2D_CLEAR_FLAG: Clear the DMA2D pending flags.
  75. (+) __HAL_DMA2D_ENABLE_IT: Enable the specified DMA2D interrupts.
  76. (+) __HAL_DMA2D_DISABLE_IT: Disable the specified DMA2D interrupts.
  77. (+) __HAL_DMA2D_GET_IT_SOURCE: Check whether the specified DMA2D interrupt is enabled or not.
  78. [..]
  79. (@) You can refer to the DMA2D HAL driver header file for more useful macros
  80. @endverbatim
  81. ******************************************************************************
  82. * @attention
  83. *
  84. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  85. *
  86. * Redistribution and use in source and binary forms, with or without modification,
  87. * are permitted provided that the following conditions are met:
  88. * 1. Redistributions of source code must retain the above copyright notice,
  89. * this list of conditions and the following disclaimer.
  90. * 2. Redistributions in binary form must reproduce the above copyright notice,
  91. * this list of conditions and the following disclaimer in the documentation
  92. * and/or other materials provided with the distribution.
  93. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  94. * may be used to endorse or promote products derived from this software
  95. * without specific prior written permission.
  96. *
  97. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  98. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  99. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  100. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  101. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  102. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  103. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  104. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  105. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  106. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  107. *
  108. ******************************************************************************
  109. */
  110. /* Includes ------------------------------------------------------------------*/
  111. #include "stm32f7xx_hal.h"
  112. /** @addtogroup STM32F7xx_HAL_Driver
  113. * @{
  114. */
  115. /** @defgroup DMA2D DMA2D
  116. * @brief DMA2D HAL module driver
  117. * @{
  118. */
  119. #ifdef HAL_DMA2D_MODULE_ENABLED
  120. #if defined (DMA2D)
  121. /* Private types -------------------------------------------------------------*/
  122. /* Private define ------------------------------------------------------------*/
  123. /** @defgroup DMA2D_Private_Constants DMA2D Private Constants
  124. * @{
  125. */
  126. /** @defgroup DMA2D_TimeOut DMA2D Time Out
  127. * @{
  128. */
  129. #define DMA2D_TIMEOUT_ABORT ((uint32_t)1000) /*!< 1s */
  130. #define DMA2D_TIMEOUT_SUSPEND ((uint32_t)1000) /*!< 1s */
  131. /**
  132. * @}
  133. */
  134. /** @defgroup DMA2D_Shifts DMA2D Shifts
  135. * @{
  136. */
  137. #define DMA2D_POSITION_FGPFCCR_CS (uint32_t)POSITION_VAL(DMA2D_FGPFCCR_CS) /*!< Required left shift to set foreground CLUT size */
  138. #define DMA2D_POSITION_BGPFCCR_CS (uint32_t)POSITION_VAL(DMA2D_BGPFCCR_CS) /*!< Required left shift to set background CLUT size */
  139. #define DMA2D_POSITION_FGPFCCR_CCM (uint32_t)POSITION_VAL(DMA2D_FGPFCCR_CCM) /*!< Required left shift to set foreground CLUT color mode */
  140. #define DMA2D_POSITION_BGPFCCR_CCM (uint32_t)POSITION_VAL(DMA2D_BGPFCCR_CCM) /*!< Required left shift to set background CLUT color mode */
  141. #define DMA2D_POSITION_OPFCCR_AI (uint32_t)POSITION_VAL(DMA2D_OPFCCR_AI) /*!< Required left shift to set output alpha inversion */
  142. #define DMA2D_POSITION_FGPFCCR_AI (uint32_t)POSITION_VAL(DMA2D_FGPFCCR_AI) /*!< Required left shift to set foreground alpha inversion */
  143. #define DMA2D_POSITION_BGPFCCR_AI (uint32_t)POSITION_VAL(DMA2D_BGPFCCR_AI) /*!< Required left shift to set background alpha inversion */
  144. #define DMA2D_POSITION_OPFCCR_RBS (uint32_t)POSITION_VAL(DMA2D_OPFCCR_RBS) /*!< Required left shift to set output Red/Blue swap */
  145. #define DMA2D_POSITION_FGPFCCR_RBS (uint32_t)POSITION_VAL(DMA2D_FGPFCCR_RBS) /*!< Required left shift to set foreground Red/Blue swap */
  146. #define DMA2D_POSITION_BGPFCCR_RBS (uint32_t)POSITION_VAL(DMA2D_BGPFCCR_RBS) /*!< Required left shift to set background Red/Blue swap */
  147. #define DMA2D_POSITION_AMTCR_DT (uint32_t)POSITION_VAL(DMA2D_AMTCR_DT) /*!< Required left shift to set deadtime value */
  148. #define DMA2D_POSITION_FGPFCCR_AM (uint32_t)POSITION_VAL(DMA2D_FGPFCCR_AM) /*!< Required left shift to set foreground alpha mode */
  149. #define DMA2D_POSITION_BGPFCCR_AM (uint32_t)POSITION_VAL(DMA2D_BGPFCCR_AM) /*!< Required left shift to set background alpha mode */
  150. #define DMA2D_POSITION_FGPFCCR_ALPHA (uint32_t)POSITION_VAL(DMA2D_FGPFCCR_ALPHA) /*!< Required left shift to set foreground alpha value */
  151. #define DMA2D_POSITION_BGPFCCR_ALPHA (uint32_t)POSITION_VAL(DMA2D_BGPFCCR_ALPHA) /*!< Required left shift to set background alpha value */
  152. #define DMA2D_POSITION_NLR_PL (uint32_t)POSITION_VAL(DMA2D_NLR_PL) /*!< Required left shift to set pixels per lines value */
  153. /**
  154. * @}
  155. */
  156. /**
  157. * @}
  158. */
  159. /* Private variables ---------------------------------------------------------*/
  160. /* Private constants ---------------------------------------------------------*/
  161. /* Private macro -------------------------------------------------------------*/
  162. /* Private function prototypes -----------------------------------------------*/
  163. /** @addtogroup DMA2D_Private_Functions_Prototypes
  164. * @{
  165. */
  166. static void DMA2D_SetConfig(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width, uint32_t Height);
  167. /**
  168. * @}
  169. */
  170. /* Private functions ---------------------------------------------------------*/
  171. /* Exported functions --------------------------------------------------------*/
  172. /** @defgroup DMA2D_Exported_Functions DMA2D Exported Functions
  173. * @{
  174. */
  175. /** @defgroup DMA2D_Exported_Functions_Group1 Initialization and de-initialization functions
  176. * @brief Initialization and Configuration functions
  177. *
  178. @verbatim
  179. ===============================================================================
  180. ##### Initialization and Configuration functions #####
  181. ===============================================================================
  182. [..] This section provides functions allowing to:
  183. (+) Initialize and configure the DMA2D
  184. (+) De-initialize the DMA2D
  185. @endverbatim
  186. * @{
  187. */
  188. /**
  189. * @brief Initialize the DMA2D according to the specified
  190. * parameters in the DMA2D_InitTypeDef and create the associated handle.
  191. * @param hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains
  192. * the configuration information for the DMA2D.
  193. * @retval HAL status
  194. */
  195. HAL_StatusTypeDef HAL_DMA2D_Init(DMA2D_HandleTypeDef *hdma2d)
  196. {
  197. /* Check the DMA2D peripheral state */
  198. if(hdma2d == NULL)
  199. {
  200. return HAL_ERROR;
  201. }
  202. /* Check the parameters */
  203. assert_param(IS_DMA2D_ALL_INSTANCE(hdma2d->Instance));
  204. assert_param(IS_DMA2D_MODE(hdma2d->Init.Mode));
  205. assert_param(IS_DMA2D_CMODE(hdma2d->Init.ColorMode));
  206. assert_param(IS_DMA2D_OFFSET(hdma2d->Init.OutputOffset));
  207. if(hdma2d->State == HAL_DMA2D_STATE_RESET)
  208. {
  209. /* Allocate lock resource and initialize it */
  210. hdma2d->Lock = HAL_UNLOCKED;
  211. /* Init the low level hardware */
  212. HAL_DMA2D_MspInit(hdma2d);
  213. }
  214. /* Change DMA2D peripheral state */
  215. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  216. /* DMA2D CR register configuration -------------------------------------------*/
  217. MODIFY_REG(hdma2d->Instance->CR, DMA2D_CR_MODE, hdma2d->Init.Mode);
  218. /* DMA2D OPFCCR register configuration ---------------------------------------*/
  219. MODIFY_REG(hdma2d->Instance->OPFCCR, DMA2D_OPFCCR_CM, hdma2d->Init.ColorMode);
  220. /* DMA2D OOR register configuration ------------------------------------------*/
  221. MODIFY_REG(hdma2d->Instance->OOR, DMA2D_OOR_LO, hdma2d->Init.OutputOffset);
  222. #if defined (DMA2D_OPFCCR_AI)
  223. /* DMA2D OPFCCR AI fields setting (Output Alpha Inversion)*/
  224. MODIFY_REG(hdma2d->Instance->OPFCCR, DMA2D_OPFCCR_AI, (hdma2d->Init.AlphaInverted << DMA2D_POSITION_OPFCCR_AI));
  225. #endif /* DMA2D_OPFCCR_AI */
  226. #if defined (DMA2D_OPFCCR_RBS)
  227. MODIFY_REG(hdma2d->Instance->OPFCCR, DMA2D_OPFCCR_RBS,(hdma2d->Init.RedBlueSwap << DMA2D_POSITION_OPFCCR_RBS));
  228. #endif /* DMA2D_OPFCCR_RBS */
  229. /* Update error code */
  230. hdma2d->ErrorCode = HAL_DMA2D_ERROR_NONE;
  231. /* Initialize the DMA2D state*/
  232. hdma2d->State = HAL_DMA2D_STATE_READY;
  233. return HAL_OK;
  234. }
  235. /**
  236. * @brief Deinitializes the DMA2D peripheral registers to their default reset
  237. * values.
  238. * @param hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains
  239. * the configuration information for the DMA2D.
  240. * @retval None
  241. */
  242. HAL_StatusTypeDef HAL_DMA2D_DeInit(DMA2D_HandleTypeDef *hdma2d)
  243. {
  244. /* Check the DMA2D peripheral state */
  245. if(hdma2d == NULL)
  246. {
  247. return HAL_ERROR;
  248. }
  249. /* Before aborting any DMA2D transfer or CLUT loading, check
  250. first whether or not DMA2D clock is enabled */
  251. if (__HAL_RCC_DMA2D_IS_CLK_ENABLED())
  252. {
  253. /* Abort DMA2D transfer if any */
  254. if ((hdma2d->Instance->CR & DMA2D_CR_START) == DMA2D_CR_START)
  255. {
  256. if (HAL_DMA2D_Abort(hdma2d) != HAL_OK)
  257. {
  258. /* Issue when aborting DMA2D transfer */
  259. return HAL_ERROR;
  260. }
  261. }
  262. else
  263. {
  264. /* Abort background CLUT loading if any */
  265. if ((hdma2d->Instance->BGPFCCR & DMA2D_BGPFCCR_START) == DMA2D_BGPFCCR_START)
  266. {
  267. if (HAL_DMA2D_CLUTLoading_Abort(hdma2d, 0) != HAL_OK)
  268. {
  269. /* Issue when aborting background CLUT loading */
  270. return HAL_ERROR;
  271. }
  272. }
  273. else
  274. {
  275. /* Abort foreground CLUT loading if any */
  276. if ((hdma2d->Instance->FGPFCCR & DMA2D_FGPFCCR_START) == DMA2D_FGPFCCR_START)
  277. {
  278. if (HAL_DMA2D_CLUTLoading_Abort(hdma2d, 1) != HAL_OK)
  279. {
  280. /* Issue when aborting foreground CLUT loading */
  281. return HAL_ERROR;
  282. }
  283. }
  284. }
  285. }
  286. }
  287. /* Carry on with de-initialization of low level hardware */
  288. HAL_DMA2D_MspDeInit(hdma2d);
  289. /* Reset DMA2D control registers*/
  290. hdma2d->Instance->CR = 0;
  291. hdma2d->Instance->FGOR = 0;
  292. hdma2d->Instance->BGOR = 0;
  293. hdma2d->Instance->FGPFCCR = 0;
  294. hdma2d->Instance->BGPFCCR = 0;
  295. hdma2d->Instance->OPFCCR = 0;
  296. /* Update error code */
  297. hdma2d->ErrorCode = HAL_DMA2D_ERROR_NONE;
  298. /* Initialize the DMA2D state*/
  299. hdma2d->State = HAL_DMA2D_STATE_RESET;
  300. /* Release Lock */
  301. __HAL_UNLOCK(hdma2d);
  302. return HAL_OK;
  303. }
  304. /**
  305. * @brief Initializes the DMA2D MSP.
  306. * @param hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains
  307. * the configuration information for the DMA2D.
  308. * @retval None
  309. */
  310. __weak void HAL_DMA2D_MspInit(DMA2D_HandleTypeDef* hdma2d)
  311. {
  312. /* Prevent unused argument(s) compilation warning */
  313. UNUSED(hdma2d);
  314. /* NOTE : This function should not be modified; when the callback is needed,
  315. the HAL_DMA2D_MspInit can be implemented in the user file.
  316. */
  317. }
  318. /**
  319. * @brief DeInitializes the DMA2D MSP.
  320. * @param hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains
  321. * the configuration information for the DMA2D.
  322. * @retval None
  323. */
  324. __weak void HAL_DMA2D_MspDeInit(DMA2D_HandleTypeDef* hdma2d)
  325. {
  326. /* Prevent unused argument(s) compilation warning */
  327. UNUSED(hdma2d);
  328. /* NOTE : This function should not be modified; when the callback is needed,
  329. the HAL_DMA2D_MspDeInit can be implemented in the user file.
  330. */
  331. }
  332. /**
  333. * @}
  334. */
  335. /** @defgroup DMA2D_Exported_Functions_Group2 IO operation functions
  336. * @brief IO operation functions
  337. *
  338. @verbatim
  339. ===============================================================================
  340. ##### IO operation functions #####
  341. ===============================================================================
  342. [..] This section provides functions allowing to:
  343. (+) Configure the pdata, destination address and data size then
  344. start the DMA2D transfer.
  345. (+) Configure the source for foreground and background, destination address
  346. and data size then start a MultiBuffer DMA2D transfer.
  347. (+) Configure the pdata, destination address and data size then
  348. start the DMA2D transfer with interrupt.
  349. (+) Configure the source for foreground and background, destination address
  350. and data size then start a MultiBuffer DMA2D transfer with interrupt.
  351. (+) Abort DMA2D transfer.
  352. (+) Suspend DMA2D transfer.
  353. (+) Resume DMA2D transfer.
  354. (+) Enable CLUT transfer.
  355. (+) Configure CLUT loading then start transfer in polling mode.
  356. (+) Configure CLUT loading then start transfer in interrupt mode.
  357. (+) Abort DMA2D CLUT loading.
  358. (+) Suspend DMA2D CLUT loading.
  359. (+) Resume DMA2D CLUT loading.
  360. (+) Poll for transfer complete.
  361. (+) handle DMA2D interrupt request.
  362. (+) Transfer watermark callback.
  363. (+) CLUT Transfer Complete callback.
  364. @endverbatim
  365. * @{
  366. */
  367. /**
  368. * @brief Start the DMA2D Transfer.
  369. * @param hdma2d: Pointer to a DMA2D_HandleTypeDef structure that contains
  370. * the configuration information for the DMA2D.
  371. * @param pdata: Configure the source memory Buffer address if
  372. * Memory-to-Memory or Memory-to-Memory with pixel format
  373. * conversion mode is selected, or configure
  374. * the color value if Register-to-Memory mode is selected.
  375. * @param DstAddress: The destination memory Buffer address.
  376. * @param Width: The width of data to be transferred from source to destination (expressed in number of pixels per line).
  377. * @param Height: The height of data to be transferred from source to destination (expressed in number of lines).
  378. * @retval HAL status
  379. */
  380. HAL_StatusTypeDef HAL_DMA2D_Start(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width, uint32_t Height)
  381. {
  382. /* Check the parameters */
  383. assert_param(IS_DMA2D_LINE(Height));
  384. assert_param(IS_DMA2D_PIXEL(Width));
  385. /* Process locked */
  386. __HAL_LOCK(hdma2d);
  387. /* Change DMA2D peripheral state */
  388. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  389. /* Configure the source, destination address and the data size */
  390. DMA2D_SetConfig(hdma2d, pdata, DstAddress, Width, Height);
  391. /* Enable the Peripheral */
  392. __HAL_DMA2D_ENABLE(hdma2d);
  393. return HAL_OK;
  394. }
  395. /**
  396. * @brief Start the DMA2D Transfer with interrupt enabled.
  397. * @param hdma2d: Pointer to a DMA2D_HandleTypeDef structure that contains
  398. * the configuration information for the DMA2D.
  399. * @param pdata: Configure the source memory Buffer address if
  400. * the Memory-to-Memory or Memory-to-Memory with pixel format
  401. * conversion mode is selected, or configure
  402. * the color value if Register-to-Memory mode is selected.
  403. * @param DstAddress: The destination memory Buffer address.
  404. * @param Width: The width of data to be transferred from source to destination (expressed in number of pixels per line).
  405. * @param Height: The height of data to be transferred from source to destination (expressed in number of lines).
  406. * @retval HAL status
  407. */
  408. HAL_StatusTypeDef HAL_DMA2D_Start_IT(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width, uint32_t Height)
  409. {
  410. /* Check the parameters */
  411. assert_param(IS_DMA2D_LINE(Height));
  412. assert_param(IS_DMA2D_PIXEL(Width));
  413. /* Process locked */
  414. __HAL_LOCK(hdma2d);
  415. /* Change DMA2D peripheral state */
  416. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  417. /* Configure the source, destination address and the data size */
  418. DMA2D_SetConfig(hdma2d, pdata, DstAddress, Width, Height);
  419. /* Enable the transfer complete, transfer error and configuration error interrupts */
  420. __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_TC|DMA2D_IT_TE|DMA2D_IT_CE);
  421. /* Enable the Peripheral */
  422. __HAL_DMA2D_ENABLE(hdma2d);
  423. return HAL_OK;
  424. }
  425. /**
  426. * @brief Start the multi-source DMA2D Transfer.
  427. * @param hdma2d: Pointer to a DMA2D_HandleTypeDef structure that contains
  428. * the configuration information for the DMA2D.
  429. * @param SrcAddress1: The source memory Buffer address for the foreground layer.
  430. * @param SrcAddress2: The source memory Buffer address for the background layer.
  431. * @param DstAddress: The destination memory Buffer address.
  432. * @param Width: The width of data to be transferred from source to destination (expressed in number of pixels per line).
  433. * @param Height: The height of data to be transferred from source to destination (expressed in number of lines).
  434. * @retval HAL status
  435. */
  436. HAL_StatusTypeDef HAL_DMA2D_BlendingStart(DMA2D_HandleTypeDef *hdma2d, uint32_t SrcAddress1, uint32_t SrcAddress2, uint32_t DstAddress, uint32_t Width, uint32_t Height)
  437. {
  438. /* Check the parameters */
  439. assert_param(IS_DMA2D_LINE(Height));
  440. assert_param(IS_DMA2D_PIXEL(Width));
  441. /* Process locked */
  442. __HAL_LOCK(hdma2d);
  443. /* Change DMA2D peripheral state */
  444. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  445. /* Configure DMA2D Stream source2 address */
  446. WRITE_REG(hdma2d->Instance->BGMAR, SrcAddress2);
  447. /* Configure the source, destination address and the data size */
  448. DMA2D_SetConfig(hdma2d, SrcAddress1, DstAddress, Width, Height);
  449. /* Enable the Peripheral */
  450. __HAL_DMA2D_ENABLE(hdma2d);
  451. return HAL_OK;
  452. }
  453. /**
  454. * @brief Start the multi-source DMA2D Transfer with interrupt enabled.
  455. * @param hdma2d: Pointer to a DMA2D_HandleTypeDef structure that contains
  456. * the configuration information for the DMA2D.
  457. * @param SrcAddress1: The source memory Buffer address for the foreground layer.
  458. * @param SrcAddress2: The source memory Buffer address for the background layer.
  459. * @param DstAddress: The destination memory Buffer address.
  460. * @param Width: The width of data to be transferred from source to destination (expressed in number of pixels per line).
  461. * @param Height: The height of data to be transferred from source to destination (expressed in number of lines).
  462. * @retval HAL status
  463. */
  464. HAL_StatusTypeDef HAL_DMA2D_BlendingStart_IT(DMA2D_HandleTypeDef *hdma2d, uint32_t SrcAddress1, uint32_t SrcAddress2, uint32_t DstAddress, uint32_t Width, uint32_t Height)
  465. {
  466. /* Check the parameters */
  467. assert_param(IS_DMA2D_LINE(Height));
  468. assert_param(IS_DMA2D_PIXEL(Width));
  469. /* Process locked */
  470. __HAL_LOCK(hdma2d);
  471. /* Change DMA2D peripheral state */
  472. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  473. /* Configure DMA2D Stream source2 address */
  474. WRITE_REG(hdma2d->Instance->BGMAR, SrcAddress2);
  475. /* Configure the source, destination address and the data size */
  476. DMA2D_SetConfig(hdma2d, SrcAddress1, DstAddress, Width, Height);
  477. /* Enable the transfer complete, transfer error and configuration error interrupts */
  478. __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_TC|DMA2D_IT_TE|DMA2D_IT_CE);
  479. /* Enable the Peripheral */
  480. __HAL_DMA2D_ENABLE(hdma2d);
  481. return HAL_OK;
  482. }
  483. /**
  484. * @brief Abort the DMA2D Transfer.
  485. * @param hdma2d : pointer to a DMA2D_HandleTypeDef structure that contains
  486. * the configuration information for the DMA2D.
  487. * @retval HAL status
  488. */
  489. HAL_StatusTypeDef HAL_DMA2D_Abort(DMA2D_HandleTypeDef *hdma2d)
  490. {
  491. uint32_t tickstart = 0;
  492. /* Abort the DMA2D transfer */
  493. /* START bit is reset to make sure not to set it again, in the event the HW clears it
  494. between the register read and the register write by the CPU (writing 0 has no
  495. effect on START bitvalue) */
  496. MODIFY_REG(hdma2d->Instance->CR, DMA2D_CR_ABORT|DMA2D_CR_START, DMA2D_CR_ABORT);
  497. /* Get tick */
  498. tickstart = HAL_GetTick();
  499. /* Check if the DMA2D is effectively disabled */
  500. while((hdma2d->Instance->CR & DMA2D_CR_START) != RESET)
  501. {
  502. if((HAL_GetTick() - tickstart ) > DMA2D_TIMEOUT_ABORT)
  503. {
  504. /* Update error code */
  505. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
  506. /* Change the DMA2D state */
  507. hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
  508. /* Process Unlocked */
  509. __HAL_UNLOCK(hdma2d);
  510. return HAL_TIMEOUT;
  511. }
  512. }
  513. /* Disable the Transfer Complete, Transfer Error and Configuration Error interrupts */
  514. __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TC|DMA2D_IT_TE|DMA2D_IT_CE);
  515. /* Change the DMA2D state*/
  516. hdma2d->State = HAL_DMA2D_STATE_READY;
  517. /* Process Unlocked */
  518. __HAL_UNLOCK(hdma2d);
  519. return HAL_OK;
  520. }
  521. /**
  522. * @brief Suspend the DMA2D Transfer.
  523. * @param hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains
  524. * the configuration information for the DMA2D.
  525. * @retval HAL status
  526. */
  527. HAL_StatusTypeDef HAL_DMA2D_Suspend(DMA2D_HandleTypeDef *hdma2d)
  528. {
  529. uint32_t tickstart = 0;
  530. /* Suspend the DMA2D transfer */
  531. /* START bit is reset to make sure not to set it again, in the event the HW clears it
  532. between the register read and the register write by the CPU (writing 0 has no
  533. effect on START bitvalue). */
  534. MODIFY_REG(hdma2d->Instance->CR, DMA2D_CR_SUSP|DMA2D_CR_START, DMA2D_CR_SUSP);
  535. /* Get tick */
  536. tickstart = HAL_GetTick();
  537. /* Check if the DMA2D is effectively suspended */
  538. while (((hdma2d->Instance->CR & DMA2D_CR_SUSP) != DMA2D_CR_SUSP) \
  539. && ((hdma2d->Instance->CR & DMA2D_CR_START) == DMA2D_CR_START))
  540. {
  541. if((HAL_GetTick() - tickstart ) > DMA2D_TIMEOUT_SUSPEND)
  542. {
  543. /* Update error code */
  544. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
  545. /* Change the DMA2D state */
  546. hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
  547. return HAL_TIMEOUT;
  548. }
  549. }
  550. /* Check whether or not a transfer is actually suspended and change the DMA2D state accordingly */
  551. if ((hdma2d->Instance->CR & DMA2D_CR_START) != RESET)
  552. {
  553. hdma2d->State = HAL_DMA2D_STATE_SUSPEND;
  554. }
  555. else
  556. {
  557. /* Make sure SUSP bit is cleared since it is meaningless
  558. when no tranfer is on-going */
  559. CLEAR_BIT(hdma2d->Instance->CR, DMA2D_CR_SUSP);
  560. }
  561. return HAL_OK;
  562. }
  563. /**
  564. * @brief Resume the DMA2D Transfer.
  565. * @param hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains
  566. * the configuration information for the DMA2D.
  567. * @retval HAL status
  568. */
  569. HAL_StatusTypeDef HAL_DMA2D_Resume(DMA2D_HandleTypeDef *hdma2d)
  570. {
  571. /* Check the SUSP and START bits */
  572. if((hdma2d->Instance->CR & (DMA2D_CR_SUSP | DMA2D_CR_START)) == (DMA2D_CR_SUSP | DMA2D_CR_START))
  573. {
  574. /* Ongoing transfer is suspended: change the DMA2D state before resuming */
  575. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  576. }
  577. /* Resume the DMA2D transfer */
  578. /* START bit is reset to make sure not to set it again, in the event the HW clears it
  579. between the register read and the register write by the CPU (writing 0 has no
  580. effect on START bitvalue). */
  581. CLEAR_BIT(hdma2d->Instance->CR, (DMA2D_CR_SUSP|DMA2D_CR_START));
  582. return HAL_OK;
  583. }
  584. /**
  585. * @brief Enable the DMA2D CLUT Transfer.
  586. * @param hdma2d: Pointer to a DMA2D_HandleTypeDef structure that contains
  587. * the configuration information for the DMA2D.
  588. * @param LayerIdx: DMA2D Layer index.
  589. * This parameter can be one of the following values:
  590. * 0(background) / 1(foreground)
  591. * @retval HAL status
  592. */
  593. HAL_StatusTypeDef HAL_DMA2D_EnableCLUT(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
  594. {
  595. /* Check the parameters */
  596. assert_param(IS_DMA2D_LAYER(LayerIdx));
  597. /* Process locked */
  598. __HAL_LOCK(hdma2d);
  599. /* Change DMA2D peripheral state */
  600. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  601. if(LayerIdx == 0)
  602. {
  603. /* Enable the background CLUT loading */
  604. SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
  605. }
  606. else
  607. {
  608. /* Enable the foreground CLUT loading */
  609. SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
  610. }
  611. return HAL_OK;
  612. }
  613. /**
  614. * @brief Start DMA2D CLUT Loading.
  615. * @param hdma2d: Pointer to a DMA2D_HandleTypeDef structure that contains
  616. * the configuration information for the DMA2D.
  617. * @param CLUTCfg: Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
  618. * the configuration information for the color look up table.
  619. * @param LayerIdx: DMA2D Layer index.
  620. * This parameter can be one of the following values:
  621. * 0(background) / 1(foreground)
  622. * @note Invoking this API is similar to calling HAL_DMA2D_ConfigCLUT() then HAL_DMA2D_EnableCLUT().
  623. * @retval HAL status
  624. */
  625. HAL_StatusTypeDef HAL_DMA2D_CLUTLoad(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef CLUTCfg, uint32_t LayerIdx)
  626. {
  627. /* Check the parameters */
  628. assert_param(IS_DMA2D_LAYER(LayerIdx));
  629. assert_param(IS_DMA2D_CLUT_CM(CLUTCfg.CLUTColorMode));
  630. assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg.Size));
  631. /* Process locked */
  632. __HAL_LOCK(hdma2d);
  633. /* Change DMA2D peripheral state */
  634. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  635. /* Configure the CLUT of the background DMA2D layer */
  636. if(LayerIdx == 0)
  637. {
  638. /* Write background CLUT memory address */
  639. WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg.pCLUT);
  640. /* Write background CLUT size and CLUT color mode */
  641. MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
  642. ((CLUTCfg.Size << DMA2D_POSITION_BGPFCCR_CS) | (CLUTCfg.CLUTColorMode << DMA2D_POSITION_BGPFCCR_CCM)));
  643. /* Enable the CLUT loading for the background */
  644. SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
  645. }
  646. /* Configure the CLUT of the foreground DMA2D layer */
  647. else
  648. {
  649. /* Write foreground CLUT memory address */
  650. WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg.pCLUT);
  651. /* Write foreground CLUT size and CLUT color mode */
  652. MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
  653. ((CLUTCfg.Size << DMA2D_POSITION_BGPFCCR_CS) | (CLUTCfg.CLUTColorMode << DMA2D_POSITION_FGPFCCR_CCM)));
  654. /* Enable the CLUT loading for the foreground */
  655. SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
  656. }
  657. return HAL_OK;
  658. }
  659. /**
  660. * @brief Start DMA2D CLUT Loading with interrupt enabled.
  661. * @param hdma2d: Pointer to a DMA2D_HandleTypeDef structure that contains
  662. * the configuration information for the DMA2D.
  663. * @param CLUTCfg: Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
  664. * the configuration information for the color look up table.
  665. * @param LayerIdx: DMA2D Layer index.
  666. * This parameter can be one of the following values:
  667. * 0(background) / 1(foreground)
  668. * @retval HAL status
  669. */
  670. HAL_StatusTypeDef HAL_DMA2D_CLUTLoad_IT(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef CLUTCfg, uint32_t LayerIdx)
  671. {
  672. /* Check the parameters */
  673. assert_param(IS_DMA2D_LAYER(LayerIdx));
  674. assert_param(IS_DMA2D_CLUT_CM(CLUTCfg.CLUTColorMode));
  675. assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg.Size));
  676. /* Process locked */
  677. __HAL_LOCK(hdma2d);
  678. /* Change DMA2D peripheral state */
  679. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  680. /* Configure the CLUT of the background DMA2D layer */
  681. if(LayerIdx == 0)
  682. {
  683. /* Write background CLUT memory address */
  684. WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg.pCLUT);
  685. /* Write background CLUT size and CLUT color mode */
  686. MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
  687. ((CLUTCfg.Size << DMA2D_POSITION_BGPFCCR_CS) | (CLUTCfg.CLUTColorMode << DMA2D_POSITION_BGPFCCR_CCM)));
  688. /* Enable the CLUT Transfer Complete, transfer Error, configuration Error and CLUT Access Error interrupts */
  689. __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE |DMA2D_IT_CAE);
  690. /* Enable the CLUT loading for the background */
  691. SET_BIT(hdma2d->Instance->BGPFCCR, DMA2D_BGPFCCR_START);
  692. }
  693. /* Configure the CLUT of the foreground DMA2D layer */
  694. else
  695. {
  696. /* Write foreground CLUT memory address */
  697. WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg.pCLUT);
  698. /* Write foreground CLUT size and CLUT color mode */
  699. MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
  700. ((CLUTCfg.Size << DMA2D_POSITION_BGPFCCR_CS) | (CLUTCfg.CLUTColorMode << DMA2D_POSITION_FGPFCCR_CCM)));
  701. /* Enable the CLUT Transfer Complete, transfer Error, configuration Error and CLUT Access Error interrupts */
  702. __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE |DMA2D_IT_CAE);
  703. /* Enable the CLUT loading for the foreground */
  704. SET_BIT(hdma2d->Instance->FGPFCCR, DMA2D_FGPFCCR_START);
  705. }
  706. return HAL_OK;
  707. }
  708. /**
  709. * @brief Abort the DMA2D CLUT loading.
  710. * @param hdma2d : Pointer to a DMA2D_HandleTypeDef structure that contains
  711. * the configuration information for the DMA2D.
  712. * @param LayerIdx: DMA2D Layer index.
  713. * This parameter can be one of the following values:
  714. * 0(background) / 1(foreground)
  715. * @retval HAL status
  716. */
  717. HAL_StatusTypeDef HAL_DMA2D_CLUTLoading_Abort(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
  718. {
  719. uint32_t tickstart = 0;
  720. __IO uint32_t * reg = &(hdma2d->Instance->BGPFCCR); /* by default, point at background register */
  721. /* Abort the CLUT loading */
  722. SET_BIT(hdma2d->Instance->CR, DMA2D_CR_ABORT);
  723. /* If foreground CLUT loading is considered, update local variables */
  724. if(LayerIdx == 1)
  725. {
  726. reg = &(hdma2d->Instance->FGPFCCR);
  727. }
  728. /* Get tick */
  729. tickstart = HAL_GetTick();
  730. /* Check if the CLUT loading is aborted */
  731. while((*reg & DMA2D_BGPFCCR_START) != RESET)
  732. {
  733. if((HAL_GetTick() - tickstart ) > DMA2D_TIMEOUT_ABORT)
  734. {
  735. /* Update error code */
  736. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
  737. /* Change the DMA2D state */
  738. hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
  739. /* Process Unlocked */
  740. __HAL_UNLOCK(hdma2d);
  741. return HAL_TIMEOUT;
  742. }
  743. }
  744. /* Disable the CLUT Transfer Complete, Transfer Error, Configuration Error and CLUT Access Error interrupts */
  745. __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CTC | DMA2D_IT_TE | DMA2D_IT_CE |DMA2D_IT_CAE);
  746. /* Change the DMA2D state*/
  747. hdma2d->State = HAL_DMA2D_STATE_READY;
  748. /* Process Unlocked */
  749. __HAL_UNLOCK(hdma2d);
  750. return HAL_OK;
  751. }
  752. /**
  753. * @brief Suspend the DMA2D CLUT loading.
  754. * @param hdma2d: Pointer to a DMA2D_HandleTypeDef structure that contains
  755. * the configuration information for the DMA2D.
  756. * @param LayerIdx: DMA2D Layer index.
  757. * This parameter can be one of the following values:
  758. * 0(background) / 1(foreground)
  759. * @retval HAL status
  760. */
  761. HAL_StatusTypeDef HAL_DMA2D_CLUTLoading_Suspend(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
  762. {
  763. uint32_t tickstart = 0;
  764. __IO uint32_t * reg = &(hdma2d->Instance->BGPFCCR); /* by default, point at background register */
  765. /* Suspend the CLUT loading */
  766. SET_BIT(hdma2d->Instance->CR, DMA2D_CR_SUSP);
  767. /* If foreground CLUT loading is considered, update local variables */
  768. if(LayerIdx == 1)
  769. {
  770. reg = &(hdma2d->Instance->FGPFCCR);
  771. }
  772. /* Get tick */
  773. tickstart = HAL_GetTick();
  774. /* Check if the CLUT loading is suspended */
  775. while (((hdma2d->Instance->CR & DMA2D_CR_SUSP) != DMA2D_CR_SUSP) \
  776. && ((*reg & DMA2D_BGPFCCR_START) == DMA2D_BGPFCCR_START))
  777. {
  778. if((HAL_GetTick() - tickstart ) > DMA2D_TIMEOUT_SUSPEND)
  779. {
  780. /* Update error code */
  781. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
  782. /* Change the DMA2D state */
  783. hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
  784. return HAL_TIMEOUT;
  785. }
  786. }
  787. /* Check whether or not a transfer is actually suspended and change the DMA2D state accordingly */
  788. if ((*reg & DMA2D_BGPFCCR_START) != RESET)
  789. {
  790. hdma2d->State = HAL_DMA2D_STATE_SUSPEND;
  791. }
  792. else
  793. {
  794. /* Make sure SUSP bit is cleared since it is meaningless
  795. when no tranfer is on-going */
  796. CLEAR_BIT(hdma2d->Instance->CR, DMA2D_CR_SUSP);
  797. }
  798. return HAL_OK;
  799. }
  800. /**
  801. * @brief Resume the DMA2D CLUT loading.
  802. * @param hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains
  803. * the configuration information for the DMA2D.
  804. * @param LayerIdx: DMA2D Layer index.
  805. * This parameter can be one of the following values:
  806. * 0(background) / 1(foreground)
  807. * @retval HAL status
  808. */
  809. HAL_StatusTypeDef HAL_DMA2D_CLUTLoading_Resume(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
  810. {
  811. /* Check the SUSP and START bits for background or foreground CLUT loading */
  812. if(LayerIdx == 0)
  813. {
  814. /* Background CLUT loading suspension check */
  815. if (((hdma2d->Instance->CR & DMA2D_CR_SUSP) == DMA2D_CR_SUSP)
  816. && ((hdma2d->Instance->BGPFCCR & DMA2D_BGPFCCR_START) == DMA2D_BGPFCCR_START))
  817. {
  818. /* Ongoing CLUT loading is suspended: change the DMA2D state before resuming */
  819. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  820. }
  821. }
  822. else
  823. {
  824. /* Foreground CLUT loading suspension check */
  825. if (((hdma2d->Instance->CR & DMA2D_CR_SUSP) == DMA2D_CR_SUSP)
  826. && ((hdma2d->Instance->FGPFCCR & DMA2D_FGPFCCR_START) == DMA2D_FGPFCCR_START))
  827. {
  828. /* Ongoing CLUT loading is suspended: change the DMA2D state before resuming */
  829. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  830. }
  831. }
  832. /* Resume the CLUT loading */
  833. CLEAR_BIT(hdma2d->Instance->CR, DMA2D_CR_SUSP);
  834. return HAL_OK;
  835. }
  836. /**
  837. * @brief Polling for transfer complete or CLUT loading.
  838. * @param hdma2d: Pointer to a DMA2D_HandleTypeDef structure that contains
  839. * the configuration information for the DMA2D.
  840. * @param Timeout: Timeout duration
  841. * @retval HAL status
  842. */
  843. HAL_StatusTypeDef HAL_DMA2D_PollForTransfer(DMA2D_HandleTypeDef *hdma2d, uint32_t Timeout)
  844. {
  845. uint32_t tickstart = 0;
  846. __IO uint32_t isrflags = 0x0;
  847. /* Polling for DMA2D transfer */
  848. if((hdma2d->Instance->CR & DMA2D_CR_START) != RESET)
  849. {
  850. /* Get tick */
  851. tickstart = HAL_GetTick();
  852. while(__HAL_DMA2D_GET_FLAG(hdma2d, DMA2D_FLAG_TC) == RESET)
  853. {
  854. isrflags = READ_REG(hdma2d->Instance->ISR);
  855. if ((isrflags & (DMA2D_FLAG_CE|DMA2D_FLAG_TE)) != RESET)
  856. {
  857. if ((isrflags & DMA2D_FLAG_CE) != RESET)
  858. {
  859. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CE;
  860. }
  861. if ((isrflags & DMA2D_FLAG_TE) != RESET)
  862. {
  863. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TE;
  864. }
  865. /* Clear the transfer and configuration error flags */
  866. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CE | DMA2D_FLAG_TE);
  867. /* Change DMA2D state */
  868. hdma2d->State = HAL_DMA2D_STATE_ERROR;
  869. /* Process unlocked */
  870. __HAL_UNLOCK(hdma2d);
  871. return HAL_ERROR;
  872. }
  873. /* Check for the Timeout */
  874. if(Timeout != HAL_MAX_DELAY)
  875. {
  876. if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
  877. {
  878. /* Update error code */
  879. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
  880. /* Change the DMA2D state */
  881. hdma2d->State = HAL_DMA2D_STATE_TIMEOUT;
  882. /* Process unlocked */
  883. __HAL_UNLOCK(hdma2d);
  884. return HAL_TIMEOUT;
  885. }
  886. }
  887. }
  888. }
  889. /* Polling for CLUT loading (foreground or background) */
  890. if (((hdma2d->Instance->FGPFCCR & DMA2D_FGPFCCR_START) != RESET) ||
  891. ((hdma2d->Instance->BGPFCCR & DMA2D_BGPFCCR_START) != RESET))
  892. {
  893. /* Get tick */
  894. tickstart = HAL_GetTick();
  895. while(__HAL_DMA2D_GET_FLAG(hdma2d, DMA2D_FLAG_CTC) == RESET)
  896. {
  897. isrflags = READ_REG(hdma2d->Instance->ISR);
  898. if ((isrflags & (DMA2D_FLAG_CAE|DMA2D_FLAG_CE|DMA2D_FLAG_TE)) != RESET)
  899. {
  900. if ((isrflags & DMA2D_FLAG_CAE) != RESET)
  901. {
  902. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CAE;
  903. }
  904. if ((isrflags & DMA2D_FLAG_CE) != RESET)
  905. {
  906. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CE;
  907. }
  908. if ((isrflags & DMA2D_FLAG_TE) != RESET)
  909. {
  910. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TE;
  911. }
  912. /* Clear the CLUT Access Error, Configuration Error and Transfer Error flags */
  913. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CAE | DMA2D_FLAG_CE | DMA2D_FLAG_TE);
  914. /* Change DMA2D state */
  915. hdma2d->State= HAL_DMA2D_STATE_ERROR;
  916. /* Process unlocked */
  917. __HAL_UNLOCK(hdma2d);
  918. return HAL_ERROR;
  919. }
  920. /* Check for the Timeout */
  921. if(Timeout != HAL_MAX_DELAY)
  922. {
  923. if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
  924. {
  925. /* Update error code */
  926. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;
  927. /* Change the DMA2D state */
  928. hdma2d->State= HAL_DMA2D_STATE_TIMEOUT;
  929. /* Process unlocked */
  930. __HAL_UNLOCK(hdma2d);
  931. return HAL_TIMEOUT;
  932. }
  933. }
  934. }
  935. }
  936. /* Clear the transfer complete and CLUT loading flags */
  937. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TC|DMA2D_FLAG_CTC);
  938. /* Change DMA2D state */
  939. hdma2d->State = HAL_DMA2D_STATE_READY;
  940. /* Process unlocked */
  941. __HAL_UNLOCK(hdma2d);
  942. return HAL_OK;
  943. }
  944. /**
  945. * @brief Handle DMA2D interrupt request.
  946. * @param hdma2d: Pointer to a DMA2D_HandleTypeDef structure that contains
  947. * the configuration information for the DMA2D.
  948. * @retval HAL status
  949. */
  950. void HAL_DMA2D_IRQHandler(DMA2D_HandleTypeDef *hdma2d)
  951. {
  952. uint32_t isrflags = READ_REG(hdma2d->Instance->ISR);
  953. uint32_t crflags = READ_REG(hdma2d->Instance->CR);
  954. /* Transfer Error Interrupt management ***************************************/
  955. if ((isrflags & DMA2D_FLAG_TE) != RESET)
  956. {
  957. if ((crflags & DMA2D_IT_TE) != RESET)
  958. {
  959. /* Disable the transfer Error interrupt */
  960. __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TE);
  961. /* Update error code */
  962. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TE;
  963. /* Clear the transfer error flag */
  964. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TE);
  965. /* Change DMA2D state */
  966. hdma2d->State = HAL_DMA2D_STATE_ERROR;
  967. /* Process Unlocked */
  968. __HAL_UNLOCK(hdma2d);
  969. if(hdma2d->XferErrorCallback != NULL)
  970. {
  971. /* Transfer error Callback */
  972. hdma2d->XferErrorCallback(hdma2d);
  973. }
  974. }
  975. }
  976. /* Configuration Error Interrupt management **********************************/
  977. if ((isrflags & DMA2D_FLAG_CE) != RESET)
  978. {
  979. if ((crflags & DMA2D_IT_CE) != RESET)
  980. {
  981. /* Disable the Configuration Error interrupt */
  982. __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CE);
  983. /* Clear the Configuration error flag */
  984. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CE);
  985. /* Update error code */
  986. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CE;
  987. /* Change DMA2D state */
  988. hdma2d->State = HAL_DMA2D_STATE_ERROR;
  989. /* Process Unlocked */
  990. __HAL_UNLOCK(hdma2d);
  991. if(hdma2d->XferErrorCallback != NULL)
  992. {
  993. /* Transfer error Callback */
  994. hdma2d->XferErrorCallback(hdma2d);
  995. }
  996. }
  997. }
  998. /* CLUT access Error Interrupt management ***********************************/
  999. if ((isrflags & DMA2D_FLAG_CAE) != RESET)
  1000. {
  1001. if ((crflags & DMA2D_IT_CAE) != RESET)
  1002. {
  1003. /* Disable the CLUT access error interrupt */
  1004. __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CAE);
  1005. /* Clear the CLUT access error flag */
  1006. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CAE);
  1007. /* Update error code */
  1008. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CAE;
  1009. /* Change DMA2D state */
  1010. hdma2d->State = HAL_DMA2D_STATE_ERROR;
  1011. /* Process Unlocked */
  1012. __HAL_UNLOCK(hdma2d);
  1013. if(hdma2d->XferErrorCallback != NULL)
  1014. {
  1015. /* Transfer error Callback */
  1016. hdma2d->XferErrorCallback(hdma2d);
  1017. }
  1018. }
  1019. }
  1020. /* Transfer watermark Interrupt management **********************************/
  1021. if ((isrflags & DMA2D_FLAG_TW) != RESET)
  1022. {
  1023. if ((crflags & DMA2D_IT_TW) != RESET)
  1024. {
  1025. /* Disable the transfer watermark interrupt */
  1026. __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TW);
  1027. /* Clear the transfer watermark flag */
  1028. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TW);
  1029. /* Transfer watermark Callback */
  1030. HAL_DMA2D_LineEventCallback(hdma2d);
  1031. }
  1032. }
  1033. /* Transfer Complete Interrupt management ************************************/
  1034. if ((isrflags & DMA2D_FLAG_TC) != RESET)
  1035. {
  1036. if ((crflags & DMA2D_IT_TC) != RESET)
  1037. {
  1038. /* Disable the transfer complete interrupt */
  1039. __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TC);
  1040. /* Clear the transfer complete flag */
  1041. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TC);
  1042. /* Update error code */
  1043. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_NONE;
  1044. /* Change DMA2D state */
  1045. hdma2d->State = HAL_DMA2D_STATE_READY;
  1046. /* Process Unlocked */
  1047. __HAL_UNLOCK(hdma2d);
  1048. if(hdma2d->XferCpltCallback != NULL)
  1049. {
  1050. /* Transfer complete Callback */
  1051. hdma2d->XferCpltCallback(hdma2d);
  1052. }
  1053. }
  1054. }
  1055. /* CLUT Transfer Complete Interrupt management ******************************/
  1056. if ((isrflags & DMA2D_FLAG_CTC) != RESET)
  1057. {
  1058. if ((crflags & DMA2D_IT_CTC) != RESET)
  1059. {
  1060. /* Disable the CLUT transfer complete interrupt */
  1061. __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CTC);
  1062. /* Clear the CLUT transfer complete flag */
  1063. __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CTC);
  1064. /* Update error code */
  1065. hdma2d->ErrorCode |= HAL_DMA2D_ERROR_NONE;
  1066. /* Change DMA2D state */
  1067. hdma2d->State = HAL_DMA2D_STATE_READY;
  1068. /* Process Unlocked */
  1069. __HAL_UNLOCK(hdma2d);
  1070. /* CLUT Transfer complete Callback */
  1071. HAL_DMA2D_CLUTLoadingCpltCallback(hdma2d);
  1072. }
  1073. }
  1074. }
  1075. /**
  1076. * @brief Transfer watermark callback.
  1077. * @param hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains
  1078. * the configuration information for the DMA2D.
  1079. * @retval None
  1080. */
  1081. __weak void HAL_DMA2D_LineEventCallback(DMA2D_HandleTypeDef *hdma2d)
  1082. {
  1083. /* Prevent unused argument(s) compilation warning */
  1084. UNUSED(hdma2d);
  1085. /* NOTE : This function should not be modified; when the callback is needed,
  1086. the HAL_DMA2D_LineEventCallback can be implemented in the user file.
  1087. */
  1088. }
  1089. /**
  1090. * @brief CLUT Transfer Complete callback.
  1091. * @param hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains
  1092. * the configuration information for the DMA2D.
  1093. * @retval None
  1094. */
  1095. __weak void HAL_DMA2D_CLUTLoadingCpltCallback(DMA2D_HandleTypeDef *hdma2d)
  1096. {
  1097. /* Prevent unused argument(s) compilation warning */
  1098. UNUSED(hdma2d);
  1099. /* NOTE : This function should not be modified; when the callback is needed,
  1100. the HAL_DMA2D_CLUTLoadingCpltCallback can be implemented in the user file.
  1101. */
  1102. }
  1103. /**
  1104. * @}
  1105. */
  1106. /** @defgroup DMA2D_Exported_Functions_Group3 Peripheral Control functions
  1107. * @brief Peripheral Control functions
  1108. *
  1109. @verbatim
  1110. ===============================================================================
  1111. ##### Peripheral Control functions #####
  1112. ===============================================================================
  1113. [..] This section provides functions allowing to:
  1114. (+) Configure the DMA2D foreground or background layer parameters.
  1115. (+) Configure the DMA2D CLUT transfer.
  1116. (+) Configure the line watermark
  1117. (+) Configure the dead time value.
  1118. (+) Enable or disable the dead time value functionality.
  1119. @endverbatim
  1120. * @{
  1121. */
  1122. /**
  1123. * @brief Configure the DMA2D Layer according to the specified
  1124. * parameters in the DMA2D_InitTypeDef and create the associated handle.
  1125. * @param hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains
  1126. * the configuration information for the DMA2D.
  1127. * @param LayerIdx: DMA2D Layer index.
  1128. * This parameter can be one of the following values:
  1129. * 0(background) / 1(foreground)
  1130. * @retval HAL status
  1131. */
  1132. HAL_StatusTypeDef HAL_DMA2D_ConfigLayer(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)
  1133. {
  1134. DMA2D_LayerCfgTypeDef *pLayerCfg = &hdma2d->LayerCfg[LayerIdx];
  1135. uint32_t regMask = 0, regValue = 0;
  1136. /* Check the parameters */
  1137. assert_param(IS_DMA2D_LAYER(LayerIdx));
  1138. assert_param(IS_DMA2D_OFFSET(pLayerCfg->InputOffset));
  1139. if(hdma2d->Init.Mode != DMA2D_R2M)
  1140. {
  1141. assert_param(IS_DMA2D_INPUT_COLOR_MODE(pLayerCfg->InputColorMode));
  1142. if(hdma2d->Init.Mode != DMA2D_M2M)
  1143. {
  1144. assert_param(IS_DMA2D_ALPHA_MODE(pLayerCfg->AlphaMode));
  1145. }
  1146. }
  1147. /* Process locked */
  1148. __HAL_LOCK(hdma2d);
  1149. /* Change DMA2D peripheral state */
  1150. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  1151. /* DMA2D BGPFCR register configuration -----------------------------------*/
  1152. /* Prepare the value to be written to the BGPFCCR register */
  1153. regValue = pLayerCfg->InputColorMode | (pLayerCfg->AlphaMode << DMA2D_POSITION_BGPFCCR_AM);
  1154. regMask = DMA2D_BGPFCCR_CM | DMA2D_BGPFCCR_AM | DMA2D_BGPFCCR_ALPHA;
  1155. #if defined (DMA2D_FGPFCCR_AI) && defined (DMA2D_BGPFCCR_AI)
  1156. regValue |= (pLayerCfg->AlphaInverted << DMA2D_POSITION_BGPFCCR_AI);
  1157. regMask |= DMA2D_BGPFCCR_AI;
  1158. #endif /* (DMA2D_FGPFCCR_AI) && (DMA2D_BGPFCCR_AI) */
  1159. #if defined (DMA2D_FGPFCCR_RBS) && defined (DMA2D_BGPFCCR_RBS)
  1160. regValue |= (pLayerCfg->RedBlueSwap << DMA2D_POSITION_BGPFCCR_RBS);
  1161. regMask |= DMA2D_BGPFCCR_RBS;
  1162. #endif
  1163. if ((pLayerCfg->InputColorMode == DMA2D_INPUT_A4) || (pLayerCfg->InputColorMode == DMA2D_INPUT_A8))
  1164. {
  1165. regValue |= (pLayerCfg->InputAlpha & DMA2D_BGPFCCR_ALPHA);
  1166. }
  1167. else
  1168. {
  1169. regValue |= (pLayerCfg->InputAlpha << DMA2D_POSITION_BGPFCCR_ALPHA);
  1170. }
  1171. /* Configure the background DMA2D layer */
  1172. if(LayerIdx == 0)
  1173. {
  1174. /* Write DMA2D BGPFCCR register */
  1175. MODIFY_REG(hdma2d->Instance->BGPFCCR, regMask, regValue);
  1176. /* DMA2D BGOR register configuration -------------------------------------*/
  1177. WRITE_REG(hdma2d->Instance->BGOR, pLayerCfg->InputOffset);
  1178. /* DMA2D BGCOLR register configuration -------------------------------------*/
  1179. if ((pLayerCfg->InputColorMode == DMA2D_INPUT_A4) || (pLayerCfg->InputColorMode == DMA2D_INPUT_A8))
  1180. {
  1181. WRITE_REG(hdma2d->Instance->BGCOLR, pLayerCfg->InputAlpha & (DMA2D_BGCOLR_BLUE|DMA2D_BGCOLR_GREEN|DMA2D_BGCOLR_RED));
  1182. }
  1183. }
  1184. /* Configure the foreground DMA2D layer */
  1185. else
  1186. {
  1187. /* Write DMA2D FGPFCCR register */
  1188. MODIFY_REG(hdma2d->Instance->FGPFCCR, regMask, regValue);
  1189. /* DMA2D FGOR register configuration -------------------------------------*/
  1190. WRITE_REG(hdma2d->Instance->FGOR, pLayerCfg->InputOffset);
  1191. /* DMA2D FGCOLR register configuration -------------------------------------*/
  1192. if ((pLayerCfg->InputColorMode == DMA2D_INPUT_A4) || (pLayerCfg->InputColorMode == DMA2D_INPUT_A8))
  1193. {
  1194. WRITE_REG(hdma2d->Instance->FGCOLR, pLayerCfg->InputAlpha & (DMA2D_FGCOLR_BLUE|DMA2D_FGCOLR_GREEN|DMA2D_FGCOLR_RED));
  1195. }
  1196. }
  1197. /* Initialize the DMA2D state*/
  1198. hdma2d->State = HAL_DMA2D_STATE_READY;
  1199. /* Process unlocked */
  1200. __HAL_UNLOCK(hdma2d);
  1201. return HAL_OK;
  1202. }
  1203. /**
  1204. * @brief Configure the DMA2D CLUT Transfer.
  1205. * @param hdma2d: Pointer to a DMA2D_HandleTypeDef structure that contains
  1206. * the configuration information for the DMA2D.
  1207. * @param CLUTCfg: Pointer to a DMA2D_CLUTCfgTypeDef structure that contains
  1208. * the configuration information for the color look up table.
  1209. * @param LayerIdx: DMA2D Layer index.
  1210. * This parameter can be one of the following values:
  1211. * 0(background) / 1(foreground)
  1212. * @retval HAL status
  1213. */
  1214. HAL_StatusTypeDef HAL_DMA2D_ConfigCLUT(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef CLUTCfg, uint32_t LayerIdx)
  1215. {
  1216. /* Check the parameters */
  1217. assert_param(IS_DMA2D_LAYER(LayerIdx));
  1218. assert_param(IS_DMA2D_CLUT_CM(CLUTCfg.CLUTColorMode));
  1219. assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg.Size));
  1220. /* Process locked */
  1221. __HAL_LOCK(hdma2d);
  1222. /* Change DMA2D peripheral state */
  1223. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  1224. /* Configure the CLUT of the background DMA2D layer */
  1225. if(LayerIdx == 0)
  1226. {
  1227. /* Write background CLUT memory address */
  1228. WRITE_REG(hdma2d->Instance->BGCMAR, (uint32_t)CLUTCfg.pCLUT);
  1229. /* Write background CLUT size and CLUT color mode */
  1230. MODIFY_REG(hdma2d->Instance->BGPFCCR, (DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM),
  1231. ((CLUTCfg.Size << DMA2D_POSITION_BGPFCCR_CS) | (CLUTCfg.CLUTColorMode << DMA2D_POSITION_BGPFCCR_CCM)));
  1232. }
  1233. /* Configure the CLUT of the foreground DMA2D layer */
  1234. else
  1235. {
  1236. /* Write foreground CLUT memory address */
  1237. WRITE_REG(hdma2d->Instance->FGCMAR, (uint32_t)CLUTCfg.pCLUT);
  1238. /* Write foreground CLUT size and CLUT color mode */
  1239. MODIFY_REG(hdma2d->Instance->FGPFCCR, (DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM),
  1240. ((CLUTCfg.Size << DMA2D_POSITION_BGPFCCR_CS) | (CLUTCfg.CLUTColorMode << DMA2D_POSITION_FGPFCCR_CCM)));
  1241. }
  1242. /* Set the DMA2D state to Ready*/
  1243. hdma2d->State = HAL_DMA2D_STATE_READY;
  1244. /* Process unlocked */
  1245. __HAL_UNLOCK(hdma2d);
  1246. return HAL_OK;
  1247. }
  1248. /**
  1249. * @brief Configure the line watermark.
  1250. * @param hdma2d: Pointer to a DMA2D_HandleTypeDef structure that contains
  1251. * the configuration information for the DMA2D.
  1252. * @param Line: Line Watermark configuration (maximum 16-bit long value expected).
  1253. * @note HAL_DMA2D_ProgramLineEvent() API enables the transfer watermark interrupt.
  1254. * @note The transfer watermark interrupt is disabled once it has occurred.
  1255. * @retval HAL status
  1256. */
  1257. HAL_StatusTypeDef HAL_DMA2D_ProgramLineEvent(DMA2D_HandleTypeDef *hdma2d, uint32_t Line)
  1258. {
  1259. /* Check the parameters */
  1260. assert_param(IS_DMA2D_LINEWATERMARK(Line));
  1261. if (Line > DMA2D_LWR_LW)
  1262. {
  1263. return HAL_ERROR;
  1264. }
  1265. else
  1266. {
  1267. /* Process locked */
  1268. __HAL_LOCK(hdma2d);
  1269. /* Change DMA2D peripheral state */
  1270. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  1271. /* Sets the Line watermark configuration */
  1272. WRITE_REG(hdma2d->Instance->LWR, Line);
  1273. /* Enable the Line interrupt */
  1274. __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_TW);
  1275. /* Initialize the DMA2D state*/
  1276. hdma2d->State = HAL_DMA2D_STATE_READY;
  1277. /* Process unlocked */
  1278. __HAL_UNLOCK(hdma2d);
  1279. return HAL_OK;
  1280. }
  1281. }
  1282. /**
  1283. * @brief Enable DMA2D dead time feature.
  1284. * @param hdma2d: DMA2D handle.
  1285. * @retval HAL status
  1286. */
  1287. HAL_StatusTypeDef HAL_DMA2D_EnableDeadTime(DMA2D_HandleTypeDef *hdma2d)
  1288. {
  1289. /* Process Locked */
  1290. __HAL_LOCK(hdma2d);
  1291. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  1292. /* Set DMA2D_AMTCR EN bit */
  1293. SET_BIT(hdma2d->Instance->AMTCR, DMA2D_AMTCR_EN);
  1294. hdma2d->State = HAL_DMA2D_STATE_READY;
  1295. /* Process Unlocked */
  1296. __HAL_UNLOCK(hdma2d);
  1297. return HAL_OK;
  1298. }
  1299. /**
  1300. * @brief Disable DMA2D dead time feature.
  1301. * @param hdma2d: DMA2D handle.
  1302. * @retval HAL status
  1303. */
  1304. HAL_StatusTypeDef HAL_DMA2D_DisableDeadTime(DMA2D_HandleTypeDef *hdma2d)
  1305. {
  1306. /* Process Locked */
  1307. __HAL_LOCK(hdma2d);
  1308. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  1309. /* Clear DMA2D_AMTCR EN bit */
  1310. CLEAR_BIT(hdma2d->Instance->AMTCR, DMA2D_AMTCR_EN);
  1311. hdma2d->State = HAL_DMA2D_STATE_READY;
  1312. /* Process Unlocked */
  1313. __HAL_UNLOCK(hdma2d);
  1314. return HAL_OK;
  1315. }
  1316. /**
  1317. * @brief Configure dead time.
  1318. * @note The dead time value represents the guaranteed minimum number of cycles between
  1319. * two consecutive transactions on the AHB bus.
  1320. * @param hdma2d: DMA2D handle.
  1321. * @param DeadTime: dead time value.
  1322. * @retval HAL status
  1323. */
  1324. HAL_StatusTypeDef HAL_DMA2D_ConfigDeadTime(DMA2D_HandleTypeDef *hdma2d, uint8_t DeadTime)
  1325. {
  1326. /* Process Locked */
  1327. __HAL_LOCK(hdma2d);
  1328. hdma2d->State = HAL_DMA2D_STATE_BUSY;
  1329. /* Set DMA2D_AMTCR DT field */
  1330. MODIFY_REG(hdma2d->Instance->AMTCR, DMA2D_AMTCR_DT, (((uint32_t) DeadTime) << DMA2D_POSITION_AMTCR_DT));
  1331. hdma2d->State = HAL_DMA2D_STATE_READY;
  1332. /* Process Unlocked */
  1333. __HAL_UNLOCK(hdma2d);
  1334. return HAL_OK;
  1335. }
  1336. /**
  1337. * @}
  1338. */
  1339. /** @defgroup DMA2D_Exported_Functions_Group4 Peripheral State and Error functions
  1340. * @brief Peripheral State functions
  1341. *
  1342. @verbatim
  1343. ===============================================================================
  1344. ##### Peripheral State and Errors functions #####
  1345. ===============================================================================
  1346. [..]
  1347. This subsection provides functions allowing to :
  1348. (+) Get the DMA2D state
  1349. (+) Get the DMA2D error code
  1350. @endverbatim
  1351. * @{
  1352. */
  1353. /**
  1354. * @brief Return the DMA2D state
  1355. * @param hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains
  1356. * the configuration information for the DMA2D.
  1357. * @retval HAL state
  1358. */
  1359. HAL_DMA2D_StateTypeDef HAL_DMA2D_GetState(DMA2D_HandleTypeDef *hdma2d)
  1360. {
  1361. return hdma2d->State;
  1362. }
  1363. /**
  1364. * @brief Return the DMA2D error code
  1365. * @param hdma2d : pointer to a DMA2D_HandleTypeDef structure that contains
  1366. * the configuration information for DMA2D.
  1367. * @retval DMA2D Error Code
  1368. */
  1369. uint32_t HAL_DMA2D_GetError(DMA2D_HandleTypeDef *hdma2d)
  1370. {
  1371. return hdma2d->ErrorCode;
  1372. }
  1373. /**
  1374. * @}
  1375. */
  1376. /**
  1377. * @}
  1378. */
  1379. /** @defgroup DMA2D_Private_Functions DMA2D Private Functions
  1380. * @{
  1381. */
  1382. /**
  1383. * @brief Set the DMA2D transfer parameters.
  1384. * @param hdma2d: Pointer to a DMA2D_HandleTypeDef structure that contains
  1385. * the configuration information for the specified DMA2D.
  1386. * @param pdata: The source memory Buffer address
  1387. * @param DstAddress: The destination memory Buffer address
  1388. * @param Width: The width of data to be transferred from source to destination.
  1389. * @param Height: The height of data to be transferred from source to destination.
  1390. * @retval HAL status
  1391. */
  1392. static void DMA2D_SetConfig(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width, uint32_t Height)
  1393. {
  1394. uint32_t tmp = 0;
  1395. uint32_t tmp1 = 0;
  1396. uint32_t tmp2 = 0;
  1397. uint32_t tmp3 = 0;
  1398. uint32_t tmp4 = 0;
  1399. /* Configure DMA2D data size */
  1400. MODIFY_REG(hdma2d->Instance->NLR, (DMA2D_NLR_NL|DMA2D_NLR_PL), (Height| (Width << DMA2D_POSITION_NLR_PL)));
  1401. /* Configure DMA2D destination address */
  1402. WRITE_REG(hdma2d->Instance->OMAR, DstAddress);
  1403. /* Register to memory DMA2D mode selected */
  1404. if (hdma2d->Init.Mode == DMA2D_R2M)
  1405. {
  1406. tmp1 = pdata & DMA2D_OCOLR_ALPHA_1;
  1407. tmp2 = pdata & DMA2D_OCOLR_RED_1;
  1408. tmp3 = pdata & DMA2D_OCOLR_GREEN_1;
  1409. tmp4 = pdata & DMA2D_OCOLR_BLUE_1;
  1410. /* Prepare the value to be written to the OCOLR register according to the color mode */
  1411. if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_ARGB8888)
  1412. {
  1413. tmp = (tmp3 | tmp2 | tmp1| tmp4);
  1414. }
  1415. else if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_RGB888)
  1416. {
  1417. tmp = (tmp3 | tmp2 | tmp4);
  1418. }
  1419. else if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_RGB565)
  1420. {
  1421. tmp2 = (tmp2 >> 19);
  1422. tmp3 = (tmp3 >> 10);
  1423. tmp4 = (tmp4 >> 3 );
  1424. tmp = ((tmp3 << 5) | (tmp2 << 11) | tmp4);
  1425. }
  1426. else if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_ARGB1555)
  1427. {
  1428. tmp1 = (tmp1 >> 31);
  1429. tmp2 = (tmp2 >> 19);
  1430. tmp3 = (tmp3 >> 11);
  1431. tmp4 = (tmp4 >> 3 );
  1432. tmp = ((tmp3 << 5) | (tmp2 << 10) | (tmp1 << 15) | tmp4);
  1433. }
  1434. else /* Dhdma2d->Init.ColorMode = DMA2D_OUTPUT_ARGB4444 */
  1435. {
  1436. tmp1 = (tmp1 >> 28);
  1437. tmp2 = (tmp2 >> 20);
  1438. tmp3 = (tmp3 >> 12);
  1439. tmp4 = (tmp4 >> 4 );
  1440. tmp = ((tmp3 << 4) | (tmp2 << 8) | (tmp1 << 12) | tmp4);
  1441. }
  1442. /* Write to DMA2D OCOLR register */
  1443. WRITE_REG(hdma2d->Instance->OCOLR, tmp);
  1444. }
  1445. else /* M2M, M2M_PFC or M2M_Blending DMA2D Mode */
  1446. {
  1447. /* Configure DMA2D source address */
  1448. WRITE_REG(hdma2d->Instance->FGMAR, pdata);
  1449. }
  1450. }
  1451. /**
  1452. * @}
  1453. */
  1454. #endif /* DMA2D */
  1455. #endif /* HAL_DMA2D_MODULE_ENABLED */
  1456. /**
  1457. * @}
  1458. */
  1459. /**
  1460. * @}
  1461. */
  1462. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/