stm32l4xx_hal_dma2d.c 65 KB

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