stm32f4xx_hal_dma2d.c 71 KB

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