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