]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil/ST_Library/stm32f7xx_hal_dma2d.c
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil / ST_Library / stm32f7xx_hal_dma2d.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32f7xx_hal_dma2d.c\r
4   * @author  MCD Application Team\r
5   * @version V1.0.0RC1\r
6   * @date    24-March-2015\r
7   * @brief   DMA2D HAL module driver.\r
8   *          This file provides firmware functions to manage the following \r
9   *          functionalities of the DMA2D peripheral:\r
10   *           + Initialization and de-initialization functions\r
11   *           + IO operation functions\r
12   *           + Peripheral Control functions \r
13   *           + Peripheral State and Errors functions\r
14   *\r
15   @verbatim\r
16   ==============================================================================\r
17                         ##### How to use this driver #####\r
18   ==============================================================================\r
19     [..]\r
20       (#) Program the required configuration through following parameters:   \r
21           the Transfer Mode, the output color mode and the output offset using \r
22           HAL_DMA2D_Init() function.\r
23 \r
24       (#) Program the required configuration through following parameters:   \r
25           the input color mode, the input color, input alpha value, alpha mode \r
26           and the input offset using HAL_DMA2D_ConfigLayer() function for foreground\r
27           or/and background layer.\r
28           \r
29      *** Polling mode IO operation ***\r
30      =================================   \r
31     [..]        \r
32        (+) Configure the pdata, Destination and data length and Enable \r
33            the transfer using HAL_DMA2D_Start() \r
34        (+) Wait for end of transfer using HAL_DMA2D_PollForTransfer(), at this stage\r
35            user can specify the value of timeout according to his end application.\r
36                \r
37      *** Interrupt mode IO operation ***    \r
38      ===================================\r
39      [..] \r
40        (#) Configure the pdata, Destination and data length and Enable \r
41            the transfer using HAL_DMA2D_Start_IT() \r
42        (#) Use HAL_DMA2D_IRQHandler() called under DMA2D_IRQHandler() Interrupt subroutine\r
43        (#) At the end of data transfer HAL_DMA2D_IRQHandler() function is executed and user can \r
44            add his own function by customization of function pointer XferCpltCallback and \r
45            XferErrorCallback (i.e a member of DMA2D handle structure). \r
46 \r
47          -@-   In Register-to-Memory transfer mode, the pdata parameter is the register\r
48                color, in Memory-to-memory or memory-to-memory with pixel format\r
49                conversion the pdata is the source address.\r
50 \r
51          -@-   Configure the foreground source address, the background source address, \r
52                the Destination and data length and Enable the transfer using \r
53                HAL_DMA2D_BlendingStart() in polling mode and HAL_DMA2D_BlendingStart_IT()\r
54                in interrupt mode.\r
55                \r
56          -@-   HAL_DMA2D_BlendingStart() and HAL_DMA2D_BlendingStart_IT() functions\r
57                are used if the memory to memory with blending transfer mode is selected.\r
58                    \r
59       (#) Optionally, configure and enable the CLUT using HAL_DMA2D_ConfigCLUT()\r
60           HAL_DMA2D_EnableCLUT() functions.\r
61 \r
62       (#) Optionally, configure and enable LineInterrupt using the following function:\r
63           HAL_DMA2D_ProgramLineEvent().\r
64    \r
65       (#) The transfer can be suspended, continued and aborted using the following\r
66           functions: HAL_DMA2D_Suspend(), HAL_DMA2D_Resume(), HAL_DMA2D_Abort().\r
67                      \r
68       (#) To control DMA2D state you can use the following function: HAL_DMA2D_GetState()                   \r
69 \r
70      *** DMA2D HAL driver macros list ***\r
71      ============================================= \r
72      [..]\r
73        Below the list of most used macros in DMA2D HAL driver :\r
74        \r
75       (+) __HAL_DMA2D_ENABLE: Enable the DMA2D peripheral.\r
76       (+) __HAL_DMA2D_DISABLE: Disable the DMA2D peripheral.\r
77       (+) __HAL_DMA2D_GET_FLAG: Get the DMA2D pending flags.\r
78       (+) __HAL_DMA2D_CLEAR_FLAG: Clear the DMA2D pending flags.\r
79       (+) __HAL_DMA2D_ENABLE_IT: Enable the specified DMA2D interrupts.\r
80       (+) __HAL_DMA2D_DISABLE_IT: Disable the specified DMA2D interrupts.\r
81       (+) __HAL_DMA2D_GET_IT_SOURCE: Check whether the specified DMA2D interrupt has occurred or not.\r
82      \r
83      [..] \r
84       (@) You can refer to the DMA2D HAL driver header file for more useful macros\r
85                                   \r
86   @endverbatim\r
87   ******************************************************************************\r
88   * @attention\r
89   *\r
90   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>\r
91   *\r
92   * Redistribution and use in source and binary forms, with or without modification,\r
93   * are permitted provided that the following conditions are met:\r
94   *   1. Redistributions of source code must retain the above copyright notice,\r
95   *      this list of conditions and the following disclaimer.\r
96   *   2. Redistributions in binary form must reproduce the above copyright notice,\r
97   *      this list of conditions and the following disclaimer in the documentation\r
98   *      and/or other materials provided with the distribution.\r
99   *   3. Neither the name of STMicroelectronics nor the names of its contributors\r
100   *      may be used to endorse or promote products derived from this software\r
101   *      without specific prior written permission.\r
102   *\r
103   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
104   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
105   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
106   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
107   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
108   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
109   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
110   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
111   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
112   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
113   *\r
114   ******************************************************************************\r
115   */ \r
116 \r
117 /* Includes ------------------------------------------------------------------*/\r
118 #include "stm32f7xx_hal.h"\r
119 \r
120 /** @addtogroup STM32F7xx_HAL_Driver\r
121   * @{\r
122   */\r
123 /** @addtogroup DMA2D\r
124   * @brief DMA2D HAL module driver\r
125   * @{\r
126   */\r
127 \r
128 #ifdef HAL_DMA2D_MODULE_ENABLED\r
129 \r
130 /* Private types -------------------------------------------------------------*/\r
131 /* Private define ------------------------------------------------------------*/\r
132 /** @addtogroup DMA2D_Private_Defines\r
133   * @{\r
134   */\r
135 #define HAL_TIMEOUT_DMA2D_ABORT      ((uint32_t)1000)  /* 1s  */\r
136 #define HAL_TIMEOUT_DMA2D_SUSPEND    ((uint32_t)1000)  /* 1s  */\r
137 /**\r
138   * @}\r
139   */\r
140 \r
141 /* Private variables ---------------------------------------------------------*/\r
142 /* Private constants ---------------------------------------------------------*/\r
143 /* Private macro -------------------------------------------------------------*/\r
144 /* Private function prototypes -----------------------------------------------*/\r
145 /** @addtogroup DMA2D_Private_Functions_Prototypes\r
146   * @{\r
147   */\r
148 static void DMA2D_SetConfig(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width, uint32_t Height);\r
149 /**\r
150   * @}\r
151   */\r
152 \r
153 /* Private functions ---------------------------------------------------------*/\r
154 /* Exported functions --------------------------------------------------------*/\r
155 /** @addtogroup DMA2D_Exported_Functions\r
156   * @{\r
157   */\r
158 \r
159 /** @defgroup DMA2D_Group1 Initialization and Configuration functions\r
160  *  @brief   Initialization and Configuration functions\r
161  *\r
162 @verbatim   \r
163  ===============================================================================\r
164                 ##### Initialization and Configuration functions #####\r
165  ===============================================================================  \r
166     [..]  This section provides functions allowing to:\r
167       (+) Initialize and configure the DMA2D\r
168       (+) De-initialize the DMA2D \r
169 \r
170 @endverbatim\r
171   * @{\r
172   */\r
173     \r
174 /**\r
175   * @brief  Initializes the DMA2D according to the specified\r
176   *         parameters in the DMA2D_InitTypeDef and create the associated handle.\r
177   * @param  hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains\r
178   *                 the configuration information for the DMA2D.\r
179   * @retval HAL status\r
180   */\r
181 HAL_StatusTypeDef HAL_DMA2D_Init(DMA2D_HandleTypeDef *hdma2d)\r
182\r
183   uint32_t tmp = 0;\r
184 \r
185   /* Check the DMA2D peripheral state */\r
186   if(hdma2d == NULL)\r
187   {\r
188      return HAL_ERROR;\r
189   }\r
190 \r
191   /* Check the parameters */\r
192   assert_param(IS_DMA2D_ALL_INSTANCE(hdma2d->Instance));\r
193   assert_param(IS_DMA2D_MODE(hdma2d->Init.Mode));\r
194   assert_param(IS_DMA2D_CMODE(hdma2d->Init.ColorMode));\r
195   assert_param(IS_DMA2D_OFFSET(hdma2d->Init.OutputOffset));\r
196 \r
197   if(hdma2d->State == HAL_DMA2D_STATE_RESET)\r
198   {\r
199     /* Init the low level hardware */\r
200     HAL_DMA2D_MspInit(hdma2d);\r
201   }\r
202   \r
203   /* Change DMA2D peripheral state */\r
204   hdma2d->State = HAL_DMA2D_STATE_BUSY;  \r
205 \r
206 /* DMA2D CR register configuration -------------------------------------------*/\r
207   /* Get the CR register value */\r
208   tmp = hdma2d->Instance->CR;\r
209 \r
210   /* Clear Mode bits */\r
211   tmp &= (uint32_t)~DMA2D_CR_MODE;\r
212 \r
213   /* Prepare the value to be wrote to the CR register */\r
214   tmp |= hdma2d->Init.Mode;\r
215 \r
216   /* Write to DMA2D CR register */\r
217   hdma2d->Instance->CR = tmp;\r
218 \r
219 /* DMA2D OPFCCR register configuration ---------------------------------------*/\r
220   /* Get the OPFCCR register value */\r
221   tmp = hdma2d->Instance->OPFCCR;\r
222 \r
223   /* Clear Color Mode bits */\r
224   tmp &= (uint32_t)~DMA2D_OPFCCR_CM;\r
225 \r
226   /* Prepare the value to be wrote to the OPFCCR register */\r
227   tmp |= hdma2d->Init.ColorMode;\r
228 \r
229   /* Write to DMA2D OPFCCR register */\r
230   hdma2d->Instance->OPFCCR = tmp;\r
231 \r
232 /* DMA2D OOR register configuration ------------------------------------------*/  \r
233   /* Get the OOR register value */\r
234   tmp = hdma2d->Instance->OOR;\r
235 \r
236   /* Clear Offset bits */\r
237   tmp &= (uint32_t)~DMA2D_OOR_LO;\r
238 \r
239   /* Prepare the value to be wrote to the OOR register */\r
240   tmp |= hdma2d->Init.OutputOffset;\r
241 \r
242   /* Write to DMA2D OOR register */\r
243   hdma2d->Instance->OOR = tmp;\r
244 \r
245   /* Update error code */\r
246   hdma2d->ErrorCode = HAL_DMA2D_ERROR_NONE;\r
247 \r
248   /* Initialize the DMA2D state*/\r
249   hdma2d->State  = HAL_DMA2D_STATE_READY;\r
250 \r
251   return HAL_OK;\r
252 }\r
253 \r
254 /**\r
255   * @brief  Deinitializes the DMA2D peripheral registers to their default reset\r
256   *         values.\r
257   * @param  hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains\r
258   *                 the configuration information for the DMA2D.\r
259   * @retval None\r
260   */\r
261 \r
262 HAL_StatusTypeDef HAL_DMA2D_DeInit(DMA2D_HandleTypeDef *hdma2d)\r
263 {\r
264   /* Check the DMA2D peripheral state */\r
265   if(hdma2d == NULL)\r
266   {\r
267      return HAL_ERROR;\r
268   }\r
269 \r
270   /* DeInit the low level hardware */\r
271   HAL_DMA2D_MspDeInit(hdma2d);\r
272 \r
273   /* Update error code */\r
274   hdma2d->ErrorCode = HAL_DMA2D_ERROR_NONE;\r
275 \r
276   /* Initialize the DMA2D state*/\r
277   hdma2d->State  = HAL_DMA2D_STATE_RESET;\r
278 \r
279   /* Release Lock */\r
280   __HAL_UNLOCK(hdma2d);\r
281 \r
282   return HAL_OK;\r
283 }\r
284 \r
285 /**\r
286   * @brief  Initializes the DMA2D MSP.\r
287   * @param  hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains\r
288   *                 the configuration information for the DMA2D.\r
289   * @retval None\r
290   */\r
291 __weak void HAL_DMA2D_MspInit(DMA2D_HandleTypeDef* hdma2d)\r
292 {\r
293   /* NOTE : This function Should not be modified, when the callback is needed,\r
294             the HAL_DMA2D_MspInit could be implemented in the user file\r
295    */ \r
296 }\r
297 \r
298 /**\r
299   * @brief  DeInitializes the DMA2D MSP.\r
300   * @param  hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains\r
301   *                 the configuration information for the DMA2D.\r
302   * @retval None\r
303   */\r
304 __weak void HAL_DMA2D_MspDeInit(DMA2D_HandleTypeDef* hdma2d)\r
305 {\r
306   /* NOTE : This function Should not be modified, when the callback is needed,\r
307             the HAL_DMA2D_MspDeInit could be implemented in the user file\r
308    */ \r
309 }\r
310 \r
311 /**\r
312   * @}\r
313   */\r
314 \r
315 /** @defgroup DMA2D_Group2 IO operation functions \r
316  *  @brief   IO operation functions  \r
317  *\r
318 @verbatim   \r
319  ===============================================================================\r
320                       #####  IO operation functions  #####\r
321  ===============================================================================  \r
322     [..]  This section provides functions allowing to:\r
323       (+) Configure the pdata, destination address and data size and \r
324           Start DMA2D transfer.\r
325       (+) Configure the source for foreground and background, destination address \r
326           and data size and Start MultiBuffer DMA2D transfer.\r
327       (+) Configure the pdata, destination address and data size and \r
328           Start DMA2D transfer with interrupt.\r
329       (+) Configure the source for foreground and background, destination address \r
330           and data size and Start MultiBuffer DMA2D transfer with interrupt.\r
331       (+) Abort DMA2D transfer.\r
332       (+) Suspend DMA2D transfer.\r
333       (+) Continue DMA2D transfer. \r
334       (+) Poll for transfer complete.\r
335       (+) handle DMA2D interrupt request.\r
336         \r
337 @endverbatim\r
338   * @{\r
339   */\r
340 \r
341 /**\r
342   * @brief  Start the DMA2D Transfer.\r
343   * @param  hdma2d:     pointer to a DMA2D_HandleTypeDef structure that contains\r
344   *                     the configuration information for the DMA2D.  \r
345   * @param  pdata:      Configure the source memory Buffer address if \r
346   *                     the memory to memory or memory to memory with pixel format \r
347   *                     conversion DMA2D mode is selected, and configure \r
348   *                     the color value if register to memory DMA2D mode is selected.\r
349   * @param  DstAddress: The destination memory Buffer address.\r
350   * @param  Width:      The width of data to be transferred from source to destination.\r
351   * @param  Height:      The height of data to be transferred from source to destination.\r
352   * @retval HAL status\r
353   */\r
354 HAL_StatusTypeDef HAL_DMA2D_Start(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width,  uint32_t Height)\r
355 {\r
356   /* Process locked */\r
357   __HAL_LOCK(hdma2d);\r
358 \r
359   /* Change DMA2D peripheral state */\r
360   hdma2d->State = HAL_DMA2D_STATE_BUSY;\r
361 \r
362   /* Check the parameters */\r
363   assert_param(IS_DMA2D_LINE(Height));\r
364   assert_param(IS_DMA2D_PIXEL(Width));\r
365 \r
366   /* Disable the Peripheral */\r
367   __HAL_DMA2D_DISABLE(hdma2d);\r
368 \r
369   /* Configure the source, destination address and the data size */\r
370   DMA2D_SetConfig(hdma2d, pdata, DstAddress, Width, Height);\r
371 \r
372   /* Enable the Peripheral */\r
373   __HAL_DMA2D_ENABLE(hdma2d);\r
374 \r
375   return HAL_OK;\r
376 }\r
377 \r
378 /**\r
379   * @brief  Start the DMA2D Transfer with interrupt enabled.\r
380   * @param  hdma2d:     pointer to a DMA2D_HandleTypeDef structure that contains\r
381   *                     the configuration information for the DMA2D.  \r
382   * @param  pdata:      Configure the source memory Buffer address if \r
383   *                     the memory to memory or memory to memory with pixel format \r
384   *                     conversion DMA2D mode is selected, and configure \r
385   *                     the color value if register to memory DMA2D mode is selected.\r
386   * @param  DstAddress: The destination memory Buffer address.\r
387   * @param  Width:      The width of data to be transferred from source to destination.\r
388   * @param  Height:     The height of data to be transferred from source to destination.\r
389   * @retval HAL status\r
390   */\r
391 HAL_StatusTypeDef HAL_DMA2D_Start_IT(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width,  uint32_t Height)\r
392 {\r
393   /* Process locked */\r
394   __HAL_LOCK(hdma2d);\r
395 \r
396   /* Change DMA2D peripheral state */\r
397   hdma2d->State = HAL_DMA2D_STATE_BUSY;\r
398 \r
399   /* Check the parameters */\r
400   assert_param(IS_DMA2D_LINE(Height));\r
401   assert_param(IS_DMA2D_PIXEL(Width));\r
402 \r
403   /* Disable the Peripheral */\r
404   __HAL_DMA2D_DISABLE(hdma2d);\r
405 \r
406   /* Configure the source, destination address and the data size */\r
407   DMA2D_SetConfig(hdma2d, pdata, DstAddress, Width, Height);\r
408 \r
409   /* Enable the transfer complete interrupt */\r
410   __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_TC);\r
411 \r
412   /* Enable the transfer Error interrupt */\r
413   __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_TE);\r
414 \r
415   /* Enable the Peripheral */\r
416   __HAL_DMA2D_ENABLE(hdma2d);\r
417 \r
418   /* Enable the configuration error interrupt */\r
419   __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_CE);\r
420 \r
421   return HAL_OK;\r
422 }\r
423 \r
424 /**\r
425   * @brief  Start the multi-source DMA2D Transfer.\r
426   * @param  hdma2d:      pointer to a DMA2D_HandleTypeDef structure that contains\r
427   *                      the configuration information for the DMA2D.  \r
428   * @param  SrcAddress1: The source memory Buffer address of the foreground layer.\r
429   * @param  SrcAddress2: The source memory Buffer address of the background layer.\r
430   * @param  DstAddress:  The destination memory Buffer address\r
431   * @param  Width:       The width of data to be transferred from source to destination.\r
432   * @param  Height:      The height of data to be transferred from source to destination.\r
433   * @retval HAL status\r
434   */\r
435 HAL_StatusTypeDef HAL_DMA2D_BlendingStart(DMA2D_HandleTypeDef *hdma2d, uint32_t SrcAddress1, uint32_t  SrcAddress2, uint32_t DstAddress, uint32_t Width,  uint32_t Height)\r
436 {\r
437   /* Process locked */\r
438   __HAL_LOCK(hdma2d);\r
439 \r
440   /* Change DMA2D peripheral state */\r
441   hdma2d->State = HAL_DMA2D_STATE_BUSY; \r
442 \r
443   /* Check the parameters */\r
444   assert_param(IS_DMA2D_LINE(Height));\r
445   assert_param(IS_DMA2D_PIXEL(Width));\r
446 \r
447   /* Disable the Peripheral */\r
448   __HAL_DMA2D_DISABLE(hdma2d);\r
449 \r
450   /* Configure DMA2D Stream source2 address */\r
451   hdma2d->Instance->BGMAR = SrcAddress2;\r
452 \r
453   /* Configure the source, destination address and the data size */\r
454   DMA2D_SetConfig(hdma2d, SrcAddress1, DstAddress, Width, Height);\r
455 \r
456   /* Enable the Peripheral */\r
457   __HAL_DMA2D_ENABLE(hdma2d);\r
458 \r
459   return HAL_OK;\r
460 }\r
461 \r
462 /**\r
463   * @brief  Start the multi-source DMA2D Transfer with interrupt enabled.\r
464   * @param  hdma2d:     pointer to a DMA2D_HandleTypeDef structure that contains\r
465   *                     the configuration information for the DMA2D.  \r
466   * @param  SrcAddress1: The source memory Buffer address of the foreground layer.\r
467   * @param  SrcAddress2: The source memory Buffer address of the background layer.\r
468   * @param  DstAddress:  The destination memory Buffer address.\r
469   * @param  Width:       The width of data to be transferred from source to destination.\r
470   * @param  Height:      The height of data to be transferred from source to destination.\r
471   * @retval HAL status\r
472   */\r
473 HAL_StatusTypeDef HAL_DMA2D_BlendingStart_IT(DMA2D_HandleTypeDef *hdma2d, uint32_t SrcAddress1, uint32_t  SrcAddress2, uint32_t DstAddress, uint32_t Width,  uint32_t Height)\r
474 {\r
475   /* Process locked */\r
476   __HAL_LOCK(hdma2d);\r
477 \r
478   /* Change DMA2D peripheral state */\r
479   hdma2d->State = HAL_DMA2D_STATE_BUSY;\r
480 \r
481   /* Check the parameters */\r
482   assert_param(IS_DMA2D_LINE(Height));\r
483   assert_param(IS_DMA2D_PIXEL(Width));\r
484 \r
485   /* Disable the Peripheral */\r
486   __HAL_DMA2D_DISABLE(hdma2d);\r
487  \r
488   /* Configure DMA2D Stream source2 address */\r
489   hdma2d->Instance->BGMAR = SrcAddress2;\r
490 \r
491   /* Configure the source, destination address and the data size */\r
492   DMA2D_SetConfig(hdma2d, SrcAddress1, DstAddress, Width, Height);\r
493 \r
494   /* Enable the configuration error interrupt */\r
495   __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_CE);\r
496 \r
497   /* Enable the transfer complete interrupt */\r
498   __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_TC);\r
499 \r
500   /* Enable the transfer Error interrupt */\r
501   __HAL_DMA2D_ENABLE_IT(hdma2d, DMA2D_IT_TE);\r
502 \r
503   /* Enable the Peripheral */\r
504   __HAL_DMA2D_ENABLE(hdma2d);\r
505 \r
506   return HAL_OK;\r
507 }\r
508 \r
509 /**\r
510   * @brief  Abort the DMA2D Transfer.\r
511   * @param  hdma2d : pointer to a DMA2D_HandleTypeDef structure that contains\r
512   *                  the configuration information for the DMA2D.\r
513   * @retval HAL status\r
514   */\r
515 HAL_StatusTypeDef HAL_DMA2D_Abort(DMA2D_HandleTypeDef *hdma2d)\r
516 {\r
517   uint32_t tickstart = 0;\r
518 \r
519   /* Disable the DMA2D */\r
520   __HAL_DMA2D_DISABLE(hdma2d);\r
521 \r
522   /* Get tick */\r
523   tickstart = HAL_GetTick();\r
524 \r
525   /* Check if the DMA2D is effectively disabled */\r
526   while((hdma2d->Instance->CR & DMA2D_CR_START) != 0)\r
527   {\r
528     if((HAL_GetTick() - tickstart ) > HAL_TIMEOUT_DMA2D_ABORT)\r
529     {\r
530       /* Update error code */\r
531       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;\r
532       \r
533       /* Change the DMA2D state */\r
534       hdma2d->State= HAL_DMA2D_STATE_TIMEOUT;\r
535       \r
536       /* Process Unlocked */\r
537       __HAL_UNLOCK(hdma2d);\r
538       \r
539       return HAL_TIMEOUT;\r
540     }\r
541   }\r
542   /* Process Unlocked */\r
543   __HAL_UNLOCK(hdma2d);\r
544 \r
545   /* Change the DMA2D state*/\r
546   hdma2d->State = HAL_DMA2D_STATE_READY;\r
547 \r
548   return HAL_OK;\r
549 }\r
550 \r
551 /**\r
552   * @brief  Suspend the DMA2D Transfer.\r
553   * @param  hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains\r
554   *                 the configuration information for the DMA2D. \r
555   * @retval HAL status\r
556   */\r
557 HAL_StatusTypeDef HAL_DMA2D_Suspend(DMA2D_HandleTypeDef *hdma2d)\r
558 {\r
559   uint32_t tickstart = 0;\r
560 \r
561   /* Suspend the DMA2D transfer */\r
562   hdma2d->Instance->CR |= DMA2D_CR_SUSP;\r
563 \r
564   /* Get tick */\r
565   tickstart = HAL_GetTick();\r
566 \r
567   /* Check if the DMA2D is effectively suspended */\r
568   while((hdma2d->Instance->CR & DMA2D_CR_SUSP) != DMA2D_CR_SUSP)\r
569   {\r
570     if((HAL_GetTick() - tickstart ) > HAL_TIMEOUT_DMA2D_SUSPEND)\r
571     {\r
572       /* Update error code */\r
573       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;\r
574       \r
575       /* Change the DMA2D state */\r
576       hdma2d->State= HAL_DMA2D_STATE_TIMEOUT;\r
577       \r
578       return HAL_TIMEOUT;\r
579     }\r
580   }\r
581   /* Change the DMA2D state*/\r
582   hdma2d->State = HAL_DMA2D_STATE_SUSPEND;\r
583 \r
584   return HAL_OK;\r
585 }\r
586 \r
587 /**\r
588   * @brief  Resume the DMA2D Transfer.\r
589   * @param  hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains\r
590   *                 the configuration information for the DMA2D.  \r
591   * @retval HAL status\r
592   */\r
593 HAL_StatusTypeDef HAL_DMA2D_Resume(DMA2D_HandleTypeDef *hdma2d)\r
594 {\r
595   /* Resume the DMA2D transfer */\r
596   hdma2d->Instance->CR &= ~DMA2D_CR_SUSP;\r
597 \r
598   /* Change the DMA2D state*/\r
599   hdma2d->State = HAL_DMA2D_STATE_BUSY;\r
600 \r
601   return HAL_OK;\r
602 }\r
603 \r
604 /**\r
605   * @brief  Polling for transfer complete or CLUT loading.\r
606   * @param  hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains\r
607   *                 the configuration information for the DMA2D. \r
608   * @param  Timeout: Timeout duration\r
609   * @retval HAL status\r
610   */\r
611 HAL_StatusTypeDef HAL_DMA2D_PollForTransfer(DMA2D_HandleTypeDef *hdma2d, uint32_t Timeout)\r
612 {\r
613   uint32_t tmp, tmp1;\r
614   uint32_t tickstart = 0;\r
615 \r
616   /* Polling for DMA2D transfer */\r
617   if((hdma2d->Instance->CR & DMA2D_CR_START) != 0)\r
618   {\r
619    /* Get tick */\r
620    tickstart = HAL_GetTick();\r
621 \r
622     while(__HAL_DMA2D_GET_FLAG(hdma2d, DMA2D_FLAG_TC) == RESET)\r
623     {\r
624       tmp  = __HAL_DMA2D_GET_FLAG(hdma2d, DMA2D_FLAG_CE);\r
625       tmp1 = __HAL_DMA2D_GET_FLAG(hdma2d, DMA2D_FLAG_TE);\r
626 \r
627       if((tmp != RESET) || (tmp1 != RESET))\r
628       {\r
629         /* Clear the transfer and configuration error flags */\r
630         __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CE);\r
631         __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TE);\r
632 \r
633         /* Change DMA2D state */\r
634         hdma2d->State= HAL_DMA2D_STATE_ERROR;\r
635 \r
636         /* Process unlocked */\r
637         __HAL_UNLOCK(hdma2d);\r
638         \r
639         return HAL_ERROR;\r
640       }\r
641       /* Check for the Timeout */\r
642       if(Timeout != HAL_MAX_DELAY)\r
643       {\r
644         if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))\r
645         {\r
646           /* Process unlocked */\r
647           __HAL_UNLOCK(hdma2d);\r
648         \r
649           /* Update error code */\r
650           hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;\r
651 \r
652           /* Change the DMA2D state */\r
653           hdma2d->State= HAL_DMA2D_STATE_TIMEOUT;\r
654           \r
655           return HAL_TIMEOUT;\r
656         }\r
657       }        \r
658     }\r
659   }\r
660   /* Polling for CLUT loading */\r
661   if((hdma2d->Instance->FGPFCCR & DMA2D_FGPFCCR_START) != 0)\r
662   {\r
663     /* Get tick */\r
664     tickstart = HAL_GetTick();\r
665    \r
666     while(__HAL_DMA2D_GET_FLAG(hdma2d, DMA2D_FLAG_CTC) == RESET)\r
667     {\r
668       if((__HAL_DMA2D_GET_FLAG(hdma2d, DMA2D_FLAG_CAE) != RESET))\r
669       {      \r
670         /* Clear the transfer and configuration error flags */\r
671         __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CAE);\r
672         \r
673         /* Change DMA2D state */\r
674         hdma2d->State= HAL_DMA2D_STATE_ERROR;\r
675         \r
676         return HAL_ERROR;      \r
677       }      \r
678       /* Check for the Timeout */\r
679       if(Timeout != HAL_MAX_DELAY)\r
680       {\r
681         if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))\r
682         {\r
683           /* Update error code */\r
684           hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TIMEOUT;\r
685     \r
686           /* Change the DMA2D state */\r
687           hdma2d->State= HAL_DMA2D_STATE_TIMEOUT;\r
688           \r
689           return HAL_TIMEOUT;\r
690         }\r
691       }      \r
692     }\r
693   }\r
694   /* Clear the transfer complete flag */\r
695   __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TC);\r
696   \r
697   /* Clear the CLUT loading flag */\r
698   __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CTC);  \r
699   \r
700   /* Change DMA2D state */\r
701   hdma2d->State = HAL_DMA2D_STATE_READY;\r
702   \r
703   /* Process unlocked */\r
704   __HAL_UNLOCK(hdma2d);\r
705   \r
706   return HAL_OK;\r
707 }\r
708 /**\r
709   * @brief  Handles DMA2D interrupt request.\r
710   * @param  hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains\r
711   *                 the configuration information for the DMA2D.  \r
712   * @retval HAL status\r
713   */\r
714 void HAL_DMA2D_IRQHandler(DMA2D_HandleTypeDef *hdma2d)\r
715 {    \r
716   /* Transfer Error Interrupt management ***************************************/\r
717   if(__HAL_DMA2D_GET_FLAG(hdma2d, DMA2D_FLAG_TE) != RESET)\r
718   {\r
719     if(__HAL_DMA2D_GET_IT_SOURCE(hdma2d, DMA2D_IT_TE) != RESET)\r
720     {\r
721       /* Disable the transfer Error interrupt */\r
722       __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TE);  \r
723 \r
724       /* Update error code */\r
725       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_TE;\r
726     \r
727       /* Clear the transfer error flag */\r
728       __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TE);\r
729 \r
730       /* Change DMA2D state */\r
731       hdma2d->State = HAL_DMA2D_STATE_ERROR;\r
732 \r
733       /* Process Unlocked */\r
734       __HAL_UNLOCK(hdma2d);       \r
735       \r
736       if(hdma2d->XferErrorCallback != NULL)\r
737       {\r
738         /* Transfer error Callback */\r
739         hdma2d->XferErrorCallback(hdma2d);\r
740       }\r
741     }\r
742   }\r
743   /* Configuration Error Interrupt management **********************************/\r
744   if(__HAL_DMA2D_GET_FLAG(hdma2d, DMA2D_FLAG_CE) != RESET)\r
745   {\r
746     if(__HAL_DMA2D_GET_IT_SOURCE(hdma2d, DMA2D_IT_CE) != RESET)\r
747     {\r
748       /* Disable the Configuration Error interrupt */\r
749       __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_CE);\r
750   \r
751       /* Clear the Configuration error flag */\r
752       __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_CE);\r
753 \r
754       /* Update error code */\r
755       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_CE;    \r
756     \r
757       /* Change DMA2D state */\r
758       hdma2d->State = HAL_DMA2D_STATE_ERROR;\r
759 \r
760       /* Process Unlocked */\r
761       __HAL_UNLOCK(hdma2d);       \r
762       \r
763       if(hdma2d->XferErrorCallback != NULL)\r
764       {\r
765         /* Transfer error Callback */\r
766         hdma2d->XferErrorCallback(hdma2d);\r
767       }\r
768     }\r
769   }\r
770   /* Transfer Complete Interrupt management ************************************/\r
771   if(__HAL_DMA2D_GET_FLAG(hdma2d, DMA2D_FLAG_TC) != RESET)\r
772   {\r
773     if(__HAL_DMA2D_GET_IT_SOURCE(hdma2d, DMA2D_IT_TC) != RESET)\r
774     { \r
775       /* Disable the transfer complete interrupt */\r
776       __HAL_DMA2D_DISABLE_IT(hdma2d, DMA2D_IT_TC);\r
777   \r
778       /* Clear the transfer complete flag */  \r
779       __HAL_DMA2D_CLEAR_FLAG(hdma2d, DMA2D_FLAG_TC);\r
780 \r
781       /* Update error code */\r
782       hdma2d->ErrorCode |= HAL_DMA2D_ERROR_NONE;    \r
783     \r
784       /* Change DMA2D state */\r
785       hdma2d->State = HAL_DMA2D_STATE_READY;\r
786     \r
787       /* Process Unlocked */\r
788       __HAL_UNLOCK(hdma2d);       \r
789       \r
790       if(hdma2d->XferCpltCallback != NULL)\r
791       {\r
792         /* Transfer complete Callback */\r
793         hdma2d->XferCpltCallback(hdma2d);\r
794       }         \r
795     }\r
796   }\r
797\r
798 \r
799 /**\r
800   * @}\r
801   */\r
802 \r
803 /** @defgroup DMA2D_Group3 Peripheral Control functions\r
804  *  @brief    Peripheral Control functions \r
805  *\r
806 @verbatim   \r
807  ===============================================================================\r
808                     ##### Peripheral Control functions #####\r
809  ===============================================================================  \r
810     [..]  This section provides functions allowing to:\r
811       (+) Configure the DMA2D foreground or/and background parameters.\r
812       (+) Configure the DMA2D CLUT transfer.\r
813       (+) Enable DMA2D CLUT.\r
814       (+) Disable DMA2D CLUT.\r
815       (+) Configure the line watermark\r
816 \r
817 @endverbatim\r
818   * @{\r
819   */\r
820 /**\r
821   * @brief  Configure the DMA2D Layer according to the specified\r
822   *         parameters in the DMA2D_InitTypeDef and create the associated handle.\r
823   * @param  hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains\r
824   *                 the configuration information for the DMA2D.\r
825   * @param  LayerIdx: DMA2D Layer index.\r
826   *                   This parameter can be one of the following values:\r
827   *                   0(background) / 1(foreground)\r
828   * @retval HAL status\r
829   */\r
830 HAL_StatusTypeDef HAL_DMA2D_ConfigLayer(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)\r
831\r
832   DMA2D_LayerCfgTypeDef *pLayerCfg = &hdma2d->LayerCfg[LayerIdx];\r
833   \r
834   uint32_t tmp = 0;\r
835   \r
836   /* Process locked */\r
837   __HAL_LOCK(hdma2d);\r
838   \r
839   /* Change DMA2D peripheral state */\r
840   hdma2d->State = HAL_DMA2D_STATE_BUSY; \r
841   \r
842   /* Check the parameters */\r
843   assert_param(IS_DMA2D_LAYER(LayerIdx));  \r
844   assert_param(IS_DMA2D_OFFSET(pLayerCfg->InputOffset));  \r
845   if(hdma2d->Init.Mode != DMA2D_R2M)\r
846   {  \r
847     assert_param(IS_DMA2D_INPUT_COLOR_MODE(pLayerCfg->InputColorMode));\r
848     if(hdma2d->Init.Mode != DMA2D_M2M)\r
849     {\r
850       assert_param(IS_DMA2D_ALPHA_MODE(pLayerCfg->AlphaMode));\r
851     }\r
852   }\r
853   \r
854   /* Configure the background DMA2D layer */\r
855   if(LayerIdx == 0)\r
856   {\r
857     /* DMA2D BGPFCR register configuration -----------------------------------*/\r
858     /* Get the BGPFCCR register value */\r
859     tmp = hdma2d->Instance->BGPFCCR;\r
860     \r
861     /* Clear Input color mode, alpha value and alpha mode bits */\r
862     tmp &= (uint32_t)~(DMA2D_BGPFCCR_CM | DMA2D_BGPFCCR_AM | DMA2D_BGPFCCR_ALPHA); \r
863     \r
864     if ((pLayerCfg->InputColorMode == CM_A4) || (pLayerCfg->InputColorMode == CM_A8))\r
865     {\r
866       /* Prepare the value to be wrote to the BGPFCCR register */\r
867       tmp |= (pLayerCfg->InputColorMode | (pLayerCfg->AlphaMode << 16) | ((pLayerCfg->InputAlpha) & 0xFF000000));\r
868     }\r
869     else\r
870     {\r
871       /* Prepare the value to be wrote to the BGPFCCR register */\r
872       tmp |= (pLayerCfg->InputColorMode | (pLayerCfg->AlphaMode << 16) | (pLayerCfg->InputAlpha << 24));\r
873     }\r
874     \r
875     /* Write to DMA2D BGPFCCR register */\r
876     hdma2d->Instance->BGPFCCR = tmp; \r
877     \r
878     /* DMA2D BGOR register configuration -------------------------------------*/  \r
879     /* Get the BGOR register value */\r
880     tmp = hdma2d->Instance->BGOR;\r
881     \r
882     /* Clear colors bits */\r
883     tmp &= (uint32_t)~DMA2D_BGOR_LO; \r
884     \r
885     /* Prepare the value to be wrote to the BGOR register */\r
886     tmp |= pLayerCfg->InputOffset;\r
887     \r
888     /* Write to DMA2D BGOR register */\r
889     hdma2d->Instance->BGOR = tmp;\r
890     \r
891     if ((pLayerCfg->InputColorMode == CM_A4) || (pLayerCfg->InputColorMode == CM_A8))\r
892     {\r
893       /* Prepare the value to be wrote to the BGCOLR register */\r
894       tmp |= ((pLayerCfg->InputAlpha) & 0x00FFFFFF);\r
895     \r
896       /* Write to DMA2D BGCOLR register */\r
897       hdma2d->Instance->BGCOLR = tmp;\r
898     }    \r
899   }\r
900   /* Configure the foreground DMA2D layer */\r
901   else\r
902   {\r
903     /* DMA2D FGPFCR register configuration -----------------------------------*/\r
904     /* Get the FGPFCCR register value */\r
905     tmp = hdma2d->Instance->FGPFCCR;\r
906     \r
907     /* Clear Input color mode, alpha value and alpha mode bits */\r
908     tmp &= (uint32_t)~(DMA2D_FGPFCCR_CM | DMA2D_FGPFCCR_AM | DMA2D_FGPFCCR_ALPHA); \r
909     \r
910     if ((pLayerCfg->InputColorMode == CM_A4) || (pLayerCfg->InputColorMode == CM_A8))\r
911     {\r
912       /* Prepare the value to be wrote to the FGPFCCR register */\r
913       tmp |= (pLayerCfg->InputColorMode | (pLayerCfg->AlphaMode << 16) | ((pLayerCfg->InputAlpha) & 0xFF000000));\r
914     }\r
915     else\r
916     {\r
917       /* Prepare the value to be wrote to the FGPFCCR register */\r
918       tmp |= (pLayerCfg->InputColorMode | (pLayerCfg->AlphaMode << 16) | (pLayerCfg->InputAlpha << 24));\r
919     }\r
920     \r
921     /* Write to DMA2D FGPFCCR register */\r
922     hdma2d->Instance->FGPFCCR = tmp; \r
923     \r
924     /* DMA2D FGOR register configuration -------------------------------------*/  \r
925     /* Get the FGOR register value */\r
926     tmp = hdma2d->Instance->FGOR;\r
927     \r
928     /* Clear colors bits */\r
929     tmp &= (uint32_t)~DMA2D_FGOR_LO; \r
930     \r
931     /* Prepare the value to be wrote to the FGOR register */\r
932     tmp |= pLayerCfg->InputOffset;\r
933     \r
934     /* Write to DMA2D FGOR register */\r
935     hdma2d->Instance->FGOR = tmp;\r
936    \r
937     if ((pLayerCfg->InputColorMode == CM_A4) || (pLayerCfg->InputColorMode == CM_A8))\r
938     {\r
939       /* Prepare the value to be wrote to the FGCOLR register */\r
940       tmp |= ((pLayerCfg->InputAlpha) & 0x00FFFFFF);\r
941     \r
942       /* Write to DMA2D FGCOLR register */\r
943       hdma2d->Instance->FGCOLR = tmp;\r
944     }   \r
945   }    \r
946   /* Initialize the DMA2D state*/\r
947   hdma2d->State  = HAL_DMA2D_STATE_READY;\r
948   \r
949   /* Process unlocked */\r
950   __HAL_UNLOCK(hdma2d);  \r
951   \r
952   return HAL_OK;\r
953 }\r
954 \r
955 /**\r
956   * @brief  Configure the DMA2D CLUT Transfer.\r
957   * @param  hdma2d:   pointer to a DMA2D_HandleTypeDef structure that contains\r
958   *                   the configuration information for the DMA2D.\r
959   * @param  CLUTCfg:  pointer to a DMA2D_CLUTCfgTypeDef structure that contains\r
960   *                   the configuration information for the color look up table.\r
961   * @param  LayerIdx: DMA2D Layer index.\r
962   *                   This parameter can be one of the following values:\r
963   *                   0(background) / 1(foreground)\r
964   * @retval HAL status\r
965   */\r
966 HAL_StatusTypeDef HAL_DMA2D_ConfigCLUT(DMA2D_HandleTypeDef *hdma2d, DMA2D_CLUTCfgTypeDef CLUTCfg, uint32_t LayerIdx)\r
967 {\r
968   uint32_t tmp = 0, tmp1 = 0;\r
969 \r
970   /* Check the parameters */\r
971   assert_param(IS_DMA2D_LAYER(LayerIdx));   \r
972   assert_param(IS_DMA2D_CLUT_CM(CLUTCfg.CLUTColorMode));\r
973   assert_param(IS_DMA2D_CLUT_SIZE(CLUTCfg.Size));\r
974   \r
975   /* Configure the CLUT of the background DMA2D layer */\r
976   if(LayerIdx == 0)\r
977   {\r
978     /* Get the BGCMAR register value */\r
979     tmp = hdma2d->Instance->BGCMAR;\r
980 \r
981     /* Clear CLUT address bits */\r
982     tmp &= (uint32_t)~DMA2D_BGCMAR_MA; \r
983   \r
984     /* Prepare the value to be wrote to the BGCMAR register */\r
985     tmp |= (uint32_t)CLUTCfg.pCLUT;\r
986   \r
987     /* Write to DMA2D BGCMAR register */\r
988     hdma2d->Instance->BGCMAR = tmp;\r
989     \r
990     /* Get the BGPFCCR register value */\r
991     tmp = hdma2d->Instance->BGPFCCR;\r
992 \r
993     /* Clear CLUT size and CLUT address bits */\r
994     tmp &= (uint32_t)~(DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM); \r
995 \r
996     /* Get the CLUT size */\r
997     tmp1 = CLUTCfg.Size << 16;\r
998     \r
999     /* Prepare the value to be wrote to the BGPFCCR register */\r
1000     tmp |= (CLUTCfg.CLUTColorMode | tmp1);\r
1001   \r
1002     /* Write to DMA2D BGPFCCR register */\r
1003     hdma2d->Instance->BGPFCCR = tmp;       \r
1004   }\r
1005   /* Configure the CLUT of the foreground DMA2D layer */\r
1006   else\r
1007   {\r
1008     /* Get the FGCMAR register value */\r
1009     tmp = hdma2d->Instance->FGCMAR;\r
1010 \r
1011     /* Clear CLUT address bits */\r
1012     tmp &= (uint32_t)~DMA2D_FGCMAR_MA; \r
1013   \r
1014     /* Prepare the value to be wrote to the FGCMAR register */\r
1015     tmp |= (uint32_t)CLUTCfg.pCLUT;\r
1016   \r
1017     /* Write to DMA2D FGCMAR register */\r
1018     hdma2d->Instance->FGCMAR = tmp;\r
1019     \r
1020     /* Get the FGPFCCR register value */\r
1021     tmp = hdma2d->Instance->FGPFCCR;\r
1022 \r
1023     /* Clear CLUT size and CLUT address bits */\r
1024     tmp &= (uint32_t)~(DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM); \r
1025 \r
1026     /* Get the CLUT size */\r
1027     tmp1 = CLUTCfg.Size << 8;\r
1028     \r
1029     /* Prepare the value to be wrote to the FGPFCCR register */\r
1030     tmp |= (CLUTCfg.CLUTColorMode | tmp1);\r
1031   \r
1032     /* Write to DMA2D FGPFCCR register */\r
1033     hdma2d->Instance->FGPFCCR = tmp;    \r
1034   }\r
1035   \r
1036   return HAL_OK;\r
1037 }\r
1038 \r
1039 /**\r
1040   * @brief  Enable the DMA2D CLUT Transfer.\r
1041   * @param  hdma2d:   pointer to a DMA2D_HandleTypeDef structure that contains\r
1042   *                   the configuration information for the DMA2D.\r
1043   * @param  LayerIdx: DMA2D Layer index.\r
1044   *                   This parameter can be one of the following values:\r
1045   *                   0(background) / 1(foreground)\r
1046   * @retval HAL status\r
1047   */\r
1048 HAL_StatusTypeDef HAL_DMA2D_EnableCLUT(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)\r
1049 {  \r
1050   /* Check the parameters */\r
1051   assert_param(IS_DMA2D_LAYER(LayerIdx));\r
1052   \r
1053   if(LayerIdx == 0)\r
1054   {\r
1055     /* Enable the CLUT loading for the background */\r
1056     hdma2d->Instance->BGPFCCR |= DMA2D_BGPFCCR_START;\r
1057   }\r
1058   else\r
1059   {\r
1060     /* Enable the CLUT loading for the foreground */\r
1061     hdma2d->Instance->FGPFCCR |= DMA2D_FGPFCCR_START;\r
1062   }\r
1063   \r
1064   return HAL_OK;\r
1065 }\r
1066 \r
1067 /**\r
1068   * @brief  Disable the DMA2D CLUT Transfer.\r
1069   * @param  hdma2d:   pointer to a DMA2D_HandleTypeDef structure that contains\r
1070   *                   the configuration information for the DMA2D.\r
1071   * @param  LayerIdx: DMA2D Layer index.\r
1072   *                   This parameter can be one of the following values:\r
1073   *                   0(background) / 1(foreground)\r
1074   * @retval HAL status\r
1075   */\r
1076 HAL_StatusTypeDef HAL_DMA2D_DisableCLUT(DMA2D_HandleTypeDef *hdma2d, uint32_t LayerIdx)\r
1077 {\r
1078   /* Check the parameters */\r
1079   assert_param(IS_DMA2D_LAYER(LayerIdx));\r
1080   \r
1081   if(LayerIdx == 0)\r
1082   {\r
1083     /* Disable the CLUT loading for the background */\r
1084     hdma2d->Instance->BGPFCCR &= ~DMA2D_BGPFCCR_START;\r
1085   }\r
1086   else\r
1087   {\r
1088     /* Disable the CLUT loading for the foreground */\r
1089     hdma2d->Instance->FGPFCCR &= ~DMA2D_FGPFCCR_START;\r
1090   } \r
1091   \r
1092   return HAL_OK;\r
1093 }\r
1094 \r
1095 /**\r
1096   * @brief  Define the configuration of the line watermark .\r
1097   * @param  hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains\r
1098   *                 the configuration information for the DMA2D.\r
1099   * @param  Line:   Line Watermark configuration.\r
1100   * @retval HAL status\r
1101   */\r
1102 \r
1103 HAL_StatusTypeDef HAL_DMA2D_ProgramLineEvent(DMA2D_HandleTypeDef *hdma2d, uint32_t Line)\r
1104 {\r
1105   /* Process locked */\r
1106   __HAL_LOCK(hdma2d);\r
1107   \r
1108   /* Change DMA2D peripheral state */\r
1109   hdma2d->State = HAL_DMA2D_STATE_BUSY;\r
1110   \r
1111   /* Check the parameters */\r
1112   assert_param(IS_DMA2D_LineWatermark(Line));\r
1113 \r
1114   /* Sets the Line watermark configuration */\r
1115   DMA2D->LWR = (uint32_t)Line;\r
1116   \r
1117   /* Initialize the DMA2D state*/\r
1118   hdma2d->State = HAL_DMA2D_STATE_READY;\r
1119   \r
1120   /* Process unlocked */\r
1121   __HAL_UNLOCK(hdma2d);  \r
1122   \r
1123   return HAL_OK;  \r
1124 }\r
1125 \r
1126 /**\r
1127   * @}\r
1128   */\r
1129 \r
1130 /** @defgroup DMA2D_Group4 Peripheral State functions\r
1131  *  @brief    Peripheral State functions \r
1132  *\r
1133 @verbatim   \r
1134  ===============================================================================\r
1135                   ##### Peripheral State and Errors functions #####\r
1136  ===============================================================================  \r
1137     [..]\r
1138     This subsection provides functions allowing to :\r
1139       (+) Check the DMA2D state\r
1140       (+) Get error code  \r
1141 \r
1142 @endverbatim\r
1143   * @{\r
1144   */ \r
1145 \r
1146 /**\r
1147   * @brief  Return the DMA2D state\r
1148   * @param  hdma2d: pointer to a DMA2D_HandleTypeDef structure that contains\r
1149   *                 the configuration information for the DMA2D.  \r
1150   * @retval HAL state\r
1151   */\r
1152 HAL_DMA2D_StateTypeDef HAL_DMA2D_GetState(DMA2D_HandleTypeDef *hdma2d)\r
1153 {  \r
1154   return hdma2d->State;\r
1155 }\r
1156 \r
1157 /**\r
1158   * @brief  Return the DMA2D error code\r
1159   * @param  hdma2d : pointer to a DMA2D_HandleTypeDef structure that contains\r
1160   *               the configuration information for DMA2D.\r
1161   * @retval DMA2D Error Code\r
1162   */\r
1163 uint32_t HAL_DMA2D_GetError(DMA2D_HandleTypeDef *hdma2d)\r
1164 {\r
1165   return hdma2d->ErrorCode;\r
1166 }\r
1167 \r
1168 /**\r
1169   * @}\r
1170   */\r
1171 \r
1172 \r
1173 /**\r
1174   * @brief  Set the DMA2D Transfer parameter.\r
1175   * @param  hdma2d:     pointer to a DMA2D_HandleTypeDef structure that contains\r
1176   *                     the configuration information for the specified DMA2D.  \r
1177   * @param  pdata:      The source memory Buffer address\r
1178   * @param  DstAddress: The destination memory Buffer address\r
1179   * @param  Width:      The width of data to be transferred from source to destination.\r
1180   * @param  Height:     The height of data to be transferred from source to destination.\r
1181   * @retval HAL status\r
1182   */\r
1183 static void DMA2D_SetConfig(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width, uint32_t Height)\r
1184 {  \r
1185   uint32_t tmp = 0;\r
1186   uint32_t tmp1 = 0;\r
1187   uint32_t tmp2 = 0;\r
1188   uint32_t tmp3 = 0;\r
1189   uint32_t tmp4 = 0;\r
1190   \r
1191   tmp = Width << 16;\r
1192   \r
1193   /* Configure DMA2D data size */\r
1194   hdma2d->Instance->NLR = (Height | tmp);\r
1195   \r
1196   /* Configure DMA2D destination address */\r
1197   hdma2d->Instance->OMAR = DstAddress;\r
1198  \r
1199   /* Register to memory DMA2D mode selected */\r
1200   if (hdma2d->Init.Mode == DMA2D_R2M)\r
1201   {    \r
1202     tmp1 = pdata & DMA2D_OCOLR_ALPHA_1;\r
1203     tmp2 = pdata & DMA2D_OCOLR_RED_1;\r
1204     tmp3 = pdata & DMA2D_OCOLR_GREEN_1;\r
1205     tmp4 = pdata & DMA2D_OCOLR_BLUE_1;\r
1206     \r
1207     /* Prepare the value to be wrote to the OCOLR register according to the color mode */\r
1208     if (hdma2d->Init.ColorMode == DMA2D_ARGB8888)\r
1209     {\r
1210       tmp = (tmp3 | tmp2 | tmp1| tmp4);\r
1211     }\r
1212     else if (hdma2d->Init.ColorMode == DMA2D_RGB888)\r
1213     {\r
1214       tmp = (tmp3 | tmp2 | tmp4);  \r
1215     }\r
1216     else if (hdma2d->Init.ColorMode == DMA2D_RGB565)\r
1217     {\r
1218       tmp2 = (tmp2 >> 19);\r
1219       tmp3 = (tmp3 >> 10);\r
1220       tmp4 = (tmp4 >> 3 );\r
1221       tmp  = ((tmp3 << 5) | (tmp2 << 11) | tmp4); \r
1222     }\r
1223     else if (hdma2d->Init.ColorMode == DMA2D_ARGB1555)\r
1224     { \r
1225       tmp1 = (tmp1 >> 31);\r
1226       tmp2 = (tmp2 >> 19);\r
1227       tmp3 = (tmp3 >> 11);\r
1228       tmp4 = (tmp4 >> 3 );      \r
1229       tmp  = ((tmp3 << 5) | (tmp2 << 10) | (tmp1 << 15) | tmp4);    \r
1230     } \r
1231     else /* DMA2D_CMode = DMA2D_ARGB4444 */\r
1232     {\r
1233       tmp1 = (tmp1 >> 28);\r
1234       tmp2 = (tmp2 >> 20);\r
1235       tmp3 = (tmp3 >> 12);\r
1236       tmp4 = (tmp4 >> 4 );\r
1237       tmp  = ((tmp3 << 4) | (tmp2 << 8) | (tmp1 << 12) | tmp4);\r
1238     }    \r
1239     /* Write to DMA2D OCOLR register */\r
1240     hdma2d->Instance->OCOLR = tmp;\r
1241   } \r
1242   else /* M2M, M2M_PFC or M2M_Blending DMA2D Mode */\r
1243   {\r
1244     /* Configure DMA2D source address */\r
1245     hdma2d->Instance->FGMAR = pdata;\r
1246   }\r
1247 }\r
1248 \r
1249 /**\r
1250   * @}\r
1251   */\r
1252 #endif /* HAL_DMA2D_MODULE_ENABLED */\r
1253 /**\r
1254   * @}\r
1255   */\r
1256 \r
1257 /**\r
1258   * @}\r
1259   */\r
1260 \r
1261 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r