stm32f4xx_hal_dma2d.c 71 KB

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