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