stm32f4xx_hal_dma2d.c 59 KB

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