1 /**
2   ******************************************************************************
3   * @file    stm32l4xx_ll_dma2d.c
4   * @author  MCD Application Team
5   * @brief   DMA2D LL module driver.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2017 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 #if defined(USE_FULL_LL_DRIVER)
19 
20 /* Includes ------------------------------------------------------------------*/
21 #include "stm32l4xx_ll_dma2d.h"
22 #include "stm32l4xx_ll_bus.h"
23 #ifdef  USE_FULL_ASSERT
24 #include "stm32_assert.h"
25 #else
26 #define assert_param(expr) ((void)0U)
27 #endif  /* USE_FULL_ASSERT */
28 
29 /** @addtogroup STM32L4xx_LL_Driver
30   * @{
31   */
32 
33 #if defined (DMA2D)
34 
35 /** @addtogroup DMA2D_LL
36   * @{
37   */
38 
39 /* Private types -------------------------------------------------------------*/
40 /* Private variables ---------------------------------------------------------*/
41 /* Private constants ---------------------------------------------------------*/
42 /** @addtogroup DMA2D_LL_Private_Constants DMA2D Private Constants
43   * @{
44   */
45 #define LL_DMA2D_COLOR            0xFFU                                      /*!< Maximum output color setting                   */
46 #define LL_DMA2D_NUMBEROFLINES    DMA2D_NLR_NL                               /*!< Maximum number of lines                        */
47 #define LL_DMA2D_NUMBEROFPIXELS   (DMA2D_NLR_PL >> DMA2D_NLR_PL_Pos)         /*!< Maximum number of pixels per lines             */
48 #define LL_DMA2D_OFFSET_MAX       0x3FFFU                                    /*!< Maximum output line offset expressed in pixels */
49 #define LL_DMA2D_CLUTSIZE_MAX     0xFFU                                      /*!< Maximum CLUT size                              */
50 /**
51   * @}
52   */
53 /* Private macros ------------------------------------------------------------*/
54 /** @addtogroup DMA2D_LL_Private_Macros
55   * @{
56   */
57 #if defined(DMA2D_M2M_BLEND_FIXED_COLOR_FG_BG_SUPPORT)
58 #define IS_LL_DMA2D_MODE(MODE)          (((MODE) == LL_DMA2D_MODE_M2M)                      || \
59                                          ((MODE) == LL_DMA2D_MODE_M2M_PFC)                  || \
60                                          ((MODE) == LL_DMA2D_MODE_M2M_BLEND)                || \
61                                          ((MODE) == LL_DMA2D_MODE_M2M_BLEND_FIXED_COLOR_FG) || \
62                                          ((MODE) == LL_DMA2D_MODE_M2M_BLEND_FIXED_COLOR_BG) || \
63                                          ((MODE) == LL_DMA2D_MODE_R2M))
64 #else
65 #define IS_LL_DMA2D_MODE(MODE)          (((MODE) == LL_DMA2D_MODE_M2M)       || \
66                                          ((MODE) == LL_DMA2D_MODE_M2M_PFC)   || \
67                                          ((MODE) == LL_DMA2D_MODE_M2M_BLEND) || \
68                                          ((MODE) == LL_DMA2D_MODE_R2M))
69 #endif /*DMA2D_M2M_BLEND_FIXED_COLOR_FG_BG_SUPPORT*/
70 
71 #define IS_LL_DMA2D_OCMODE(MODE_ARGB)   (((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_ARGB8888) || \
72                                          ((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_RGB888)   || \
73                                          ((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_RGB565)   || \
74                                          ((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_ARGB1555) || \
75                                          ((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_ARGB4444))
76 
77 #define IS_LL_DMA2D_GREEN(GREEN)        ((GREEN) <= LL_DMA2D_COLOR)
78 #define IS_LL_DMA2D_RED(RED)            ((RED)   <= LL_DMA2D_COLOR)
79 #define IS_LL_DMA2D_BLUE(BLUE)          ((BLUE)  <= LL_DMA2D_COLOR)
80 #define IS_LL_DMA2D_ALPHA(ALPHA)        ((ALPHA) <= LL_DMA2D_COLOR)
81 
82 #if defined(DMA2D_LINE_OFFSET_MODE_SUPPORT)
83 #define IS_LL_DMA2D_OFFSET_MODE(MODE)   (((MODE) == LL_DMA2D_LINE_OFFSET_PIXELS) || \
84                                          ((MODE) == LL_DMA2D_LINE_OFFSET_BYTES))
85 #endif /* DMA2D_LINE_OFFSET_MODE_SUPPORT */
86 
87 #define IS_LL_DMA2D_OFFSET(OFFSET)      ((OFFSET) <= LL_DMA2D_OFFSET_MAX)
88 
89 #define IS_LL_DMA2D_LINE(LINES)         ((LINES)  <= LL_DMA2D_NUMBEROFLINES)
90 #define IS_LL_DMA2D_PIXEL(PIXELS)       ((PIXELS) <= LL_DMA2D_NUMBEROFPIXELS)
91 
92 #if defined(DMA2D_OUTPUT_TWO_BY_TWO_SWAP_SUPPORT)
93 #define IS_LL_DMA2D_SWAP_MODE(MODE)     (((MODE) == LL_DMA2D_SWAP_MODE_REGULAR) || \
94                                          ((MODE) == LL_DMA2D_SWAP_MODE_TWO_BY_TWO))
95 #endif /* DMA2D_OUTPUT_TWO_BY_TWO_SWAP_SUPPORT */
96 
97 #define IS_LL_DMA2D_ALPHAINV(ALPHA)     (((ALPHA) == LL_DMA2D_ALPHA_REGULAR) || \
98                                          ((ALPHA) == LL_DMA2D_ALPHA_INVERTED))
99 
100 #define IS_LL_DMA2D_RBSWAP(RBSWAP)      (((RBSWAP) == LL_DMA2D_RB_MODE_REGULAR) || \
101                                          ((RBSWAP) == LL_DMA2D_RB_MODE_SWAP))
102 
103 #define IS_LL_DMA2D_LCMODE(MODE_ARGB)   (((MODE_ARGB) == LL_DMA2D_INPUT_MODE_ARGB8888) || \
104                                          ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_RGB888)   || \
105                                          ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_RGB565)   || \
106                                          ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_ARGB1555) || \
107                                          ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_ARGB4444) || \
108                                          ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_L8)       || \
109                                          ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_AL44)     || \
110                                          ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_AL88)     || \
111                                          ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_L4)       || \
112                                          ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_A8)       || \
113                                          ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_A4))
114 
115 #define IS_LL_DMA2D_CLUTCMODE(CLUTCMODE) (((CLUTCMODE) == LL_DMA2D_CLUT_COLOR_MODE_ARGB8888) || \
116                                           ((CLUTCMODE) == LL_DMA2D_CLUT_COLOR_MODE_RGB888))
117 
118 #define IS_LL_DMA2D_CLUTSIZE(SIZE)      ((SIZE) <= LL_DMA2D_CLUTSIZE_MAX)
119 
120 #define IS_LL_DMA2D_ALPHAMODE(MODE)     (((MODE) == LL_DMA2D_ALPHA_MODE_NO_MODIF) || \
121                                          ((MODE) == LL_DMA2D_ALPHA_MODE_REPLACE)  || \
122                                          ((MODE) == LL_DMA2D_ALPHA_MODE_COMBINE))
123 
124 
125 /**
126   * @}
127   */
128 
129 /* Private function prototypes -----------------------------------------------*/
130 
131 /* Exported functions --------------------------------------------------------*/
132 /** @addtogroup DMA2D_LL_Exported_Functions
133   * @{
134   */
135 
136 /** @addtogroup DMA2D_LL_EF_Init_Functions Initialization and De-initialization Functions
137   * @{
138   */
139 
140 /**
141   * @brief  De-initialize DMA2D registers (registers restored to their default values).
142   * @param  DMA2Dx DMA2D Instance
143   * @retval An ErrorStatus enumeration value:
144   *          - SUCCESS: DMA2D registers are de-initialized
145   *          - ERROR: DMA2D registers are not de-initialized
146   */
LL_DMA2D_DeInit(DMA2D_TypeDef * DMA2Dx)147 ErrorStatus LL_DMA2D_DeInit(DMA2D_TypeDef *DMA2Dx)
148 {
149   ErrorStatus status = SUCCESS;
150 
151   /* Check the parameters */
152   assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
153 
154   if (DMA2Dx == DMA2D)
155   {
156     /* Force reset of DMA2D clock */
157     LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_DMA2D);
158 
159     /* Release reset of DMA2D clock */
160     LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_DMA2D);
161   }
162   else
163   {
164     status = ERROR;
165   }
166 
167   return (status);
168 }
169 
170 /**
171   * @brief  Initialize DMA2D registers according to the specified parameters in DMA2D_InitStruct.
172   * @note   DMA2D transfers must be disabled to set initialization bits in configuration registers,
173   *         otherwise ERROR result is returned.
174   * @param  DMA2Dx DMA2D Instance
175   * @param  DMA2D_InitStruct  pointer to a LL_DMA2D_InitTypeDef structure
176   *         that contains the configuration information for the specified DMA2D peripheral.
177   * @retval An ErrorStatus enumeration value:
178   *          - SUCCESS: DMA2D registers are initialized according to DMA2D_InitStruct content
179   *          - ERROR: Issue occurred during DMA2D registers initialization
180   */
LL_DMA2D_Init(DMA2D_TypeDef * DMA2Dx,LL_DMA2D_InitTypeDef * DMA2D_InitStruct)181 ErrorStatus LL_DMA2D_Init(DMA2D_TypeDef *DMA2Dx, LL_DMA2D_InitTypeDef *DMA2D_InitStruct)
182 {
183   ErrorStatus status = ERROR;
184   LL_DMA2D_ColorTypeDef dma2d_colorstruct;
185   uint32_t tmp;
186   uint32_t tmp1;
187   uint32_t tmp2;
188   uint32_t regMask;
189   uint32_t regValue;
190 
191   /* Check the parameters */
192   assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
193   assert_param(IS_LL_DMA2D_MODE(DMA2D_InitStruct->Mode));
194   assert_param(IS_LL_DMA2D_OCMODE(DMA2D_InitStruct->ColorMode));
195   assert_param(IS_LL_DMA2D_LINE(DMA2D_InitStruct->NbrOfLines));
196   assert_param(IS_LL_DMA2D_PIXEL(DMA2D_InitStruct->NbrOfPixelsPerLines));
197   assert_param(IS_LL_DMA2D_GREEN(DMA2D_InitStruct->OutputGreen));
198   assert_param(IS_LL_DMA2D_RED(DMA2D_InitStruct->OutputRed));
199   assert_param(IS_LL_DMA2D_BLUE(DMA2D_InitStruct->OutputBlue));
200   assert_param(IS_LL_DMA2D_ALPHA(DMA2D_InitStruct->OutputAlpha));
201 #if defined(DMA2D_OUTPUT_TWO_BY_TWO_SWAP_SUPPORT)
202   assert_param(IS_LL_DMA2D_SWAP_MODE(DMA2D_InitStruct->OutputSwapMode));
203 #endif /* DMA2D_OUTPUT_TWO_BY_TWO_SWAP_SUPPORT */
204 #if defined(DMA2D_LINE_OFFSET_MODE_SUPPORT)
205   assert_param(IS_LL_DMA2D_OFFSET_MODE(DMA2D_InitStruct->LineOffsetMode));
206 #endif /* DMA2D_LINE_OFFSET_MODE_SUPPORT */
207   assert_param(IS_LL_DMA2D_OFFSET(DMA2D_InitStruct->LineOffset));
208   assert_param(IS_LL_DMA2D_ALPHAINV(DMA2D_InitStruct->AlphaInversionMode));
209   assert_param(IS_LL_DMA2D_RBSWAP(DMA2D_InitStruct->RBSwapMode));
210 
211   /* DMA2D transfers must be disabled to configure bits in initialization registers */
212   tmp = LL_DMA2D_IsTransferOngoing(DMA2Dx);
213   tmp1 = LL_DMA2D_FGND_IsEnabledCLUTLoad(DMA2Dx);
214   tmp2 = LL_DMA2D_BGND_IsEnabledCLUTLoad(DMA2Dx);
215   if ((tmp == 0U) && (tmp1 == 0U) && (tmp2 == 0U))
216   {
217     /* DMA2D CR register configuration -------------------------------------------*/
218 #if defined(DMA2D_LINE_OFFSET_MODE_SUPPORT)
219     MODIFY_REG(DMA2Dx->CR, (DMA2D_CR_MODE | DMA2D_CR_LOM), \
220                (DMA2D_InitStruct->Mode | DMA2D_InitStruct->LineOffsetMode));
221 #else
222     LL_DMA2D_SetMode(DMA2Dx, DMA2D_InitStruct->Mode);
223 #endif /* DMA2D_LINE_OFFSET_MODE_SUPPORT */
224 
225     /* DMA2D OPFCCR register configuration ---------------------------------------*/
226     regMask = DMA2D_OPFCCR_CM;
227     regValue = DMA2D_InitStruct->ColorMode;
228 
229 #if defined(DMA2D_OUTPUT_TWO_BY_TWO_SWAP_SUPPORT)
230     regMask |= DMA2D_OPFCCR_SB;
231     regValue |= DMA2D_InitStruct->OutputSwapMode;
232 #endif /* DMA2D_OUTPUT_TWO_BY_TWO_SWAP_SUPPORT */
233 
234     regMask |= (DMA2D_OPFCCR_RBS | DMA2D_OPFCCR_AI);
235     regValue |= (DMA2D_InitStruct->AlphaInversionMode | DMA2D_InitStruct->RBSwapMode);
236 
237 
238     MODIFY_REG(DMA2Dx->OPFCCR, regMask, regValue);
239 
240     /* DMA2D OOR register configuration ------------------------------------------*/
241     LL_DMA2D_SetLineOffset(DMA2Dx, DMA2D_InitStruct->LineOffset);
242 
243     /* DMA2D NLR register configuration ------------------------------------------*/
244     LL_DMA2D_ConfigSize(DMA2Dx, DMA2D_InitStruct->NbrOfLines, DMA2D_InitStruct->NbrOfPixelsPerLines);
245 
246     /* DMA2D OMAR register configuration ------------------------------------------*/
247     LL_DMA2D_SetOutputMemAddr(DMA2Dx, DMA2D_InitStruct->OutputMemoryAddress);
248 
249     /* DMA2D OCOLR register configuration ------------------------------------------*/
250     dma2d_colorstruct.ColorMode   = DMA2D_InitStruct->ColorMode;
251     dma2d_colorstruct.OutputBlue  = DMA2D_InitStruct->OutputBlue;
252     dma2d_colorstruct.OutputGreen = DMA2D_InitStruct->OutputGreen;
253     dma2d_colorstruct.OutputRed   = DMA2D_InitStruct->OutputRed;
254     dma2d_colorstruct.OutputAlpha = DMA2D_InitStruct->OutputAlpha;
255     LL_DMA2D_ConfigOutputColor(DMA2Dx, &dma2d_colorstruct);
256 
257     status = SUCCESS;
258   }
259   /* If DMA2D transfers are not disabled, return ERROR */
260 
261   return (status);
262 }
263 
264 /**
265   * @brief Set each @ref LL_DMA2D_InitTypeDef field to default value.
266   * @param DMA2D_InitStruct  pointer to a @ref LL_DMA2D_InitTypeDef structure
267   *                          whose fields will be set to default values.
268   * @retval None
269   */
LL_DMA2D_StructInit(LL_DMA2D_InitTypeDef * DMA2D_InitStruct)270 void LL_DMA2D_StructInit(LL_DMA2D_InitTypeDef *DMA2D_InitStruct)
271 {
272   /* Set DMA2D_InitStruct fields to default values */
273   DMA2D_InitStruct->Mode                = LL_DMA2D_MODE_M2M;
274   DMA2D_InitStruct->ColorMode           = LL_DMA2D_OUTPUT_MODE_ARGB8888;
275   DMA2D_InitStruct->NbrOfLines          = 0x0U;
276   DMA2D_InitStruct->NbrOfPixelsPerLines = 0x0U;
277 #if defined(DMA2D_LINE_OFFSET_MODE_SUPPORT)
278   DMA2D_InitStruct->LineOffsetMode      = LL_DMA2D_LINE_OFFSET_PIXELS;
279 #endif /* DMA2D_LINE_OFFSET_MODE_SUPPORT */
280   DMA2D_InitStruct->LineOffset          = 0x0U;
281   DMA2D_InitStruct->OutputBlue          = 0x0U;
282   DMA2D_InitStruct->OutputGreen         = 0x0U;
283   DMA2D_InitStruct->OutputRed           = 0x0U;
284   DMA2D_InitStruct->OutputAlpha         = 0x0U;
285   DMA2D_InitStruct->OutputMemoryAddress = 0x0U;
286 #if defined(DMA2D_OUTPUT_TWO_BY_TWO_SWAP_SUPPORT)
287   DMA2D_InitStruct->OutputSwapMode      = LL_DMA2D_SWAP_MODE_REGULAR;
288 #endif /* DMA2D_OUTPUT_TWO_BY_TWO_SWAP_SUPPORT */
289   DMA2D_InitStruct->AlphaInversionMode  = LL_DMA2D_ALPHA_REGULAR;
290   DMA2D_InitStruct->RBSwapMode          = LL_DMA2D_RB_MODE_REGULAR;
291 }
292 
293 /**
294   * @brief  Configure the foreground or background according to the specified parameters
295   *         in the LL_DMA2D_LayerCfgTypeDef structure.
296   * @param  DMA2Dx DMA2D Instance
297   * @param  DMA2D_LayerCfg  pointer to a LL_DMA2D_LayerCfgTypeDef structure that contains
298   *         the configuration information for the specified layer.
299   * @param  LayerIdx  DMA2D Layer index.
300   *                   This parameter can be one of the following values:
301   *                   0(background) / 1(foreground)
302   * @retval None
303   */
LL_DMA2D_ConfigLayer(DMA2D_TypeDef * DMA2Dx,LL_DMA2D_LayerCfgTypeDef * DMA2D_LayerCfg,uint32_t LayerIdx)304 void LL_DMA2D_ConfigLayer(DMA2D_TypeDef *DMA2Dx, LL_DMA2D_LayerCfgTypeDef *DMA2D_LayerCfg, uint32_t LayerIdx)
305 {
306   /* Check the parameters */
307   assert_param(IS_LL_DMA2D_OFFSET(DMA2D_LayerCfg->LineOffset));
308   assert_param(IS_LL_DMA2D_LCMODE(DMA2D_LayerCfg->ColorMode));
309   assert_param(IS_LL_DMA2D_CLUTCMODE(DMA2D_LayerCfg->CLUTColorMode));
310   assert_param(IS_LL_DMA2D_CLUTSIZE(DMA2D_LayerCfg->CLUTSize));
311   assert_param(IS_LL_DMA2D_ALPHAMODE(DMA2D_LayerCfg->AlphaMode));
312   assert_param(IS_LL_DMA2D_GREEN(DMA2D_LayerCfg->Green));
313   assert_param(IS_LL_DMA2D_RED(DMA2D_LayerCfg->Red));
314   assert_param(IS_LL_DMA2D_BLUE(DMA2D_LayerCfg->Blue));
315   assert_param(IS_LL_DMA2D_ALPHA(DMA2D_LayerCfg->Alpha));
316   assert_param(IS_LL_DMA2D_ALPHAINV(DMA2D_LayerCfg->AlphaInversionMode));
317   assert_param(IS_LL_DMA2D_RBSWAP(DMA2D_LayerCfg->RBSwapMode));
318 
319 
320   if (LayerIdx == 0U)
321   {
322     /* Configure the background memory address */
323     LL_DMA2D_BGND_SetMemAddr(DMA2Dx, DMA2D_LayerCfg->MemoryAddress);
324 
325     /* Configure the background line offset */
326     LL_DMA2D_BGND_SetLineOffset(DMA2Dx, DMA2D_LayerCfg->LineOffset);
327 
328     /* Configure the background Alpha value, Alpha mode, RB swap, Alpha inversion
329        CLUT size, CLUT Color mode and Color mode */
330     MODIFY_REG(DMA2Dx->BGPFCCR, \
331                (DMA2D_BGPFCCR_ALPHA | DMA2D_BGPFCCR_RBS | DMA2D_BGPFCCR_AI | DMA2D_BGPFCCR_AM | \
332                 DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM | DMA2D_BGPFCCR_CM), \
333                ((DMA2D_LayerCfg->Alpha << DMA2D_BGPFCCR_ALPHA_Pos) | DMA2D_LayerCfg->RBSwapMode | \
334                 DMA2D_LayerCfg->AlphaInversionMode | DMA2D_LayerCfg->AlphaMode | \
335                 (DMA2D_LayerCfg->CLUTSize << DMA2D_BGPFCCR_CS_Pos) | DMA2D_LayerCfg->CLUTColorMode | \
336                 DMA2D_LayerCfg->ColorMode));
337 
338     /* Configure the background color */
339     LL_DMA2D_BGND_SetColor(DMA2Dx, DMA2D_LayerCfg->Red, DMA2D_LayerCfg->Green, DMA2D_LayerCfg->Blue);
340 
341     /* Configure the background CLUT memory address */
342     LL_DMA2D_BGND_SetCLUTMemAddr(DMA2Dx, DMA2D_LayerCfg->CLUTMemoryAddress);
343   }
344   else
345   {
346     /* Configure the foreground memory address */
347     LL_DMA2D_FGND_SetMemAddr(DMA2Dx, DMA2D_LayerCfg->MemoryAddress);
348 
349     /* Configure the foreground line offset */
350     LL_DMA2D_FGND_SetLineOffset(DMA2Dx, DMA2D_LayerCfg->LineOffset);
351 
352     /* Configure the foreground Alpha value, Alpha mode, RB swap, Alpha inversion
353        CLUT size, CLUT Color mode and Color mode */
354     MODIFY_REG(DMA2Dx->FGPFCCR, \
355                (DMA2D_FGPFCCR_ALPHA | DMA2D_FGPFCCR_RBS | DMA2D_FGPFCCR_AI | DMA2D_FGPFCCR_AM | \
356                 DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM | DMA2D_FGPFCCR_CM), \
357                ((DMA2D_LayerCfg->Alpha << DMA2D_FGPFCCR_ALPHA_Pos) | DMA2D_LayerCfg->RBSwapMode | \
358                 DMA2D_LayerCfg->AlphaInversionMode | DMA2D_LayerCfg->AlphaMode | \
359                 (DMA2D_LayerCfg->CLUTSize << DMA2D_FGPFCCR_CS_Pos) | DMA2D_LayerCfg->CLUTColorMode | \
360                 DMA2D_LayerCfg->ColorMode));
361 
362     /* Configure the foreground color */
363     LL_DMA2D_FGND_SetColor(DMA2Dx, DMA2D_LayerCfg->Red, DMA2D_LayerCfg->Green, DMA2D_LayerCfg->Blue);
364 
365     /* Configure the foreground CLUT memory address */
366     LL_DMA2D_FGND_SetCLUTMemAddr(DMA2Dx, DMA2D_LayerCfg->CLUTMemoryAddress);
367   }
368 }
369 
370 /**
371   * @brief Set each @ref LL_DMA2D_LayerCfgTypeDef field to default value.
372   * @param DMA2D_LayerCfg  pointer to a @ref LL_DMA2D_LayerCfgTypeDef structure
373   *                        whose fields will be set to default values.
374   * @retval None
375   */
LL_DMA2D_LayerCfgStructInit(LL_DMA2D_LayerCfgTypeDef * DMA2D_LayerCfg)376 void LL_DMA2D_LayerCfgStructInit(LL_DMA2D_LayerCfgTypeDef *DMA2D_LayerCfg)
377 {
378   /* Set DMA2D_LayerCfg fields to default values */
379   DMA2D_LayerCfg->MemoryAddress      = 0x0U;
380   DMA2D_LayerCfg->ColorMode          = LL_DMA2D_INPUT_MODE_ARGB8888;
381   DMA2D_LayerCfg->LineOffset         = 0x0U;
382   DMA2D_LayerCfg->CLUTColorMode      = LL_DMA2D_CLUT_COLOR_MODE_ARGB8888;
383   DMA2D_LayerCfg->CLUTSize           = 0x0U;
384   DMA2D_LayerCfg->AlphaMode          = LL_DMA2D_ALPHA_MODE_NO_MODIF;
385   DMA2D_LayerCfg->Alpha              = 0x0U;
386   DMA2D_LayerCfg->Blue               = 0x0U;
387   DMA2D_LayerCfg->Green              = 0x0U;
388   DMA2D_LayerCfg->Red                = 0x0U;
389   DMA2D_LayerCfg->CLUTMemoryAddress  = 0x0U;
390   DMA2D_LayerCfg->AlphaInversionMode = LL_DMA2D_ALPHA_REGULAR;
391   DMA2D_LayerCfg->RBSwapMode         = LL_DMA2D_RB_MODE_REGULAR;
392 }
393 
394 /**
395   * @brief  Initialize DMA2D output color register according to the specified parameters
396   *         in DMA2D_ColorStruct.
397   * @param  DMA2Dx DMA2D Instance
398   * @param  DMA2D_ColorStruct  pointer to a LL_DMA2D_ColorTypeDef structure that contains
399   *         the color configuration information for the specified DMA2D peripheral.
400   * @retval None
401   */
LL_DMA2D_ConfigOutputColor(DMA2D_TypeDef * DMA2Dx,LL_DMA2D_ColorTypeDef * DMA2D_ColorStruct)402 void LL_DMA2D_ConfigOutputColor(DMA2D_TypeDef *DMA2Dx, LL_DMA2D_ColorTypeDef *DMA2D_ColorStruct)
403 {
404   uint32_t outgreen;
405   uint32_t outred;
406   uint32_t outalpha;
407 
408   /* Check the parameters */
409   assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
410   assert_param(IS_LL_DMA2D_OCMODE(DMA2D_ColorStruct->ColorMode));
411   assert_param(IS_LL_DMA2D_GREEN(DMA2D_ColorStruct->OutputGreen));
412   assert_param(IS_LL_DMA2D_RED(DMA2D_ColorStruct->OutputRed));
413   assert_param(IS_LL_DMA2D_BLUE(DMA2D_ColorStruct->OutputBlue));
414   assert_param(IS_LL_DMA2D_ALPHA(DMA2D_ColorStruct->OutputAlpha));
415 
416   /* DMA2D OCOLR register configuration ------------------------------------------*/
417   if (DMA2D_ColorStruct->ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
418   {
419     outgreen = DMA2D_ColorStruct->OutputGreen << 8U;
420     outred = DMA2D_ColorStruct->OutputRed << 16U;
421     outalpha = DMA2D_ColorStruct->OutputAlpha << 24U;
422   }
423   else if (DMA2D_ColorStruct->ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888)
424   {
425     outgreen = DMA2D_ColorStruct->OutputGreen << 8U;
426     outred = DMA2D_ColorStruct->OutputRed << 16U;
427     outalpha = 0x00000000U;
428   }
429   else if (DMA2D_ColorStruct->ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565)
430   {
431     outgreen = DMA2D_ColorStruct->OutputGreen << 5U;
432     outred = DMA2D_ColorStruct->OutputRed << 11U;
433     outalpha = 0x00000000U;
434   }
435   else if (DMA2D_ColorStruct->ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
436   {
437     outgreen = DMA2D_ColorStruct->OutputGreen << 5U;
438     outred = DMA2D_ColorStruct->OutputRed << 10U;
439     outalpha = DMA2D_ColorStruct->OutputAlpha << 15U;
440   }
441   else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
442   {
443     outgreen = DMA2D_ColorStruct->OutputGreen << 4U;
444     outred = DMA2D_ColorStruct->OutputRed << 8U;
445     outalpha = DMA2D_ColorStruct->OutputAlpha << 12U;
446   }
447   LL_DMA2D_SetOutputColor(DMA2Dx, (outgreen | outred | DMA2D_ColorStruct->OutputBlue | outalpha));
448 }
449 
450 /**
451   * @brief  Return DMA2D output Blue color.
452   * @param  DMA2Dx DMA2D Instance.
453   * @param  ColorMode This parameter can be one of the following values:
454   *         @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB8888
455   *         @arg @ref LL_DMA2D_OUTPUT_MODE_RGB888
456   *         @arg @ref LL_DMA2D_OUTPUT_MODE_RGB565
457   *         @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB1555
458   *         @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB4444
459   * @retval Output Blue color value between Min_Data=0 and Max_Data=0xFF
460   */
LL_DMA2D_GetOutputBlueColor(DMA2D_TypeDef * DMA2Dx,uint32_t ColorMode)461 uint32_t LL_DMA2D_GetOutputBlueColor(DMA2D_TypeDef *DMA2Dx, uint32_t ColorMode)
462 {
463   uint32_t color;
464 
465   /* Check the parameters */
466   assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
467   assert_param(IS_LL_DMA2D_OCMODE(ColorMode));
468 
469   /* DMA2D OCOLR register reading ------------------------------------------*/
470   if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
471   {
472     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFFU));
473   }
474   else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888)
475   {
476     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFFU));
477   }
478   else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565)
479   {
480     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x1FU));
481   }
482   else if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
483   {
484     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x1FU));
485   }
486   else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
487   {
488     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFU));
489   }
490 
491   return color;
492 }
493 
494 /**
495   * @brief  Return DMA2D output Green color.
496   * @param  DMA2Dx DMA2D Instance.
497   * @param  ColorMode This parameter can be one of the following values:
498   *         @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB8888
499   *         @arg @ref LL_DMA2D_OUTPUT_MODE_RGB888
500   *         @arg @ref LL_DMA2D_OUTPUT_MODE_RGB565
501   *         @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB1555
502   *         @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB4444
503   * @retval Output Green color value between Min_Data=0 and Max_Data=0xFF
504   */
LL_DMA2D_GetOutputGreenColor(DMA2D_TypeDef * DMA2Dx,uint32_t ColorMode)505 uint32_t LL_DMA2D_GetOutputGreenColor(DMA2D_TypeDef *DMA2Dx, uint32_t ColorMode)
506 {
507   uint32_t color;
508 
509   /* Check the parameters */
510   assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
511   assert_param(IS_LL_DMA2D_OCMODE(ColorMode));
512 
513   /* DMA2D OCOLR register reading ------------------------------------------*/
514   if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
515   {
516     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF00U) >> 8U);
517   }
518   else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888)
519   {
520     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF00U) >> 8U);
521   }
522   else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565)
523   {
524     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x7E0U) >> 5U);
525   }
526   else if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
527   {
528     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x3E0U) >> 5U);
529   }
530   else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
531   {
532     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xF0U) >> 4U);
533   }
534 
535   return color;
536 }
537 
538 /**
539   * @brief  Return DMA2D output Red color.
540   * @param  DMA2Dx DMA2D Instance.
541   * @param  ColorMode This parameter can be one of the following values:
542   *         @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB8888
543   *         @arg @ref LL_DMA2D_OUTPUT_MODE_RGB888
544   *         @arg @ref LL_DMA2D_OUTPUT_MODE_RGB565
545   *         @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB1555
546   *         @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB4444
547   * @retval Output Red color value between Min_Data=0 and Max_Data=0xFF
548   */
LL_DMA2D_GetOutputRedColor(DMA2D_TypeDef * DMA2Dx,uint32_t ColorMode)549 uint32_t LL_DMA2D_GetOutputRedColor(DMA2D_TypeDef *DMA2Dx, uint32_t ColorMode)
550 {
551   uint32_t color;
552 
553   /* Check the parameters */
554   assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
555   assert_param(IS_LL_DMA2D_OCMODE(ColorMode));
556 
557   /* DMA2D OCOLR register reading ------------------------------------------*/
558   if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
559   {
560     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF0000U) >> 16U);
561   }
562   else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888)
563   {
564     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF0000U) >> 16U);
565   }
566   else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565)
567   {
568     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xF800U) >> 11U);
569   }
570   else if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
571   {
572     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x7C00U) >> 10U);
573   }
574   else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
575   {
576     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xF00U) >> 8U);
577   }
578 
579   return color;
580 }
581 
582 /**
583   * @brief  Return DMA2D output Alpha color.
584   * @param  DMA2Dx DMA2D Instance.
585   * @param  ColorMode This parameter can be one of the following values:
586   *         @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB8888
587   *         @arg @ref LL_DMA2D_OUTPUT_MODE_RGB888
588   *         @arg @ref LL_DMA2D_OUTPUT_MODE_RGB565
589   *         @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB1555
590   *         @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB4444
591   * @retval Output Alpha color value between Min_Data=0 and Max_Data=0xFF
592   */
LL_DMA2D_GetOutputAlphaColor(DMA2D_TypeDef * DMA2Dx,uint32_t ColorMode)593 uint32_t LL_DMA2D_GetOutputAlphaColor(DMA2D_TypeDef *DMA2Dx, uint32_t ColorMode)
594 {
595   uint32_t color;
596 
597   /* Check the parameters */
598   assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
599   assert_param(IS_LL_DMA2D_OCMODE(ColorMode));
600 
601   /* DMA2D OCOLR register reading ------------------------------------------*/
602   if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
603   {
604     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF000000U) >> 24U);
605   }
606   else if ((ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888) || (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565))
607   {
608     color = 0x0U;
609   }
610   else if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
611   {
612     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x8000U) >> 15U);
613   }
614   else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
615   {
616     color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xF000U) >> 12U);
617   }
618 
619   return color;
620 }
621 
622 /**
623   * @brief  Configure DMA2D transfer size.
624   * @param  DMA2Dx DMA2D Instance
625   * @param  NbrOfLines Value between Min_Data=0 and Max_Data=0xFFFF
626   * @param  NbrOfPixelsPerLines Value between Min_Data=0 and Max_Data=0x3FFF
627   * @retval None
628   */
LL_DMA2D_ConfigSize(DMA2D_TypeDef * DMA2Dx,uint32_t NbrOfLines,uint32_t NbrOfPixelsPerLines)629 void LL_DMA2D_ConfigSize(DMA2D_TypeDef *DMA2Dx, uint32_t NbrOfLines, uint32_t NbrOfPixelsPerLines)
630 {
631   MODIFY_REG(DMA2Dx->NLR, (DMA2D_NLR_PL | DMA2D_NLR_NL), \
632              ((NbrOfPixelsPerLines << DMA2D_NLR_PL_Pos) | NbrOfLines));
633 }
634 
635 /**
636   * @}
637   */
638 
639 /**
640   * @}
641   */
642 
643 /**
644   * @}
645   */
646 
647 #endif /* defined (DMA2D) */
648 
649 /**
650   * @}
651   */
652 
653 #endif /* USE_FULL_LL_DRIVER */
654