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