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