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