stm32h7xx_hal_dma2d.c 61 KB

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