stm32f4xx_hal_dma2d.c 58 KB

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