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