Merge pull request #10558 from iNavFlight/MrD_Correct-comments-on-OSD-symbols
[inav.git] / lib / main / STM32F7 / Drivers / STM32F7xx_HAL_Driver / Src / stm32f7xx_ll_dma2d.c
blob4ac3bcf4d31130cfff7eab148621e58ecc9a6271
1 /**
2 ******************************************************************************
3 * @file stm32f7xx_ll_dma2d.c
4 * @author MCD Application Team
5 * @version V1.2.2
6 * @date 14-April-2017
7 * @brief DMA2D LL module driver.
8 ******************************************************************************
9 * @attention
11 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ******************************************************************************
37 #if defined(USE_FULL_LL_DRIVER)
39 /* Includes ------------------------------------------------------------------*/
40 #include "stm32f7xx_ll_dma2d.h"
41 #include "stm32f7xx_ll_bus.h"
42 #ifdef USE_FULL_ASSERT
43 #include "stm32_assert.h"
44 #else
45 #define assert_param(expr) ((void)0U)
46 #endif
48 /** @addtogroup STM32F7xx_LL_Driver
49 * @{
52 #if defined (DMA2D)
54 /** @addtogroup DMA2D_LL
55 * @{
58 /* Private types -------------------------------------------------------------*/
59 /* Private variables ---------------------------------------------------------*/
60 /* Private constants ---------------------------------------------------------*/
61 /** @addtogroup DMA2D_LL_Private_Constants DMA2D Private Constants
62 * @{
64 #define LL_DMA2D_COLOR 0xFFU /*!< Maximum output color setting */
65 #define LL_DMA2D_NUMBEROFLINES DMA2D_NLR_NL /*!< Maximum number of lines */
66 #define LL_DMA2D_NUMBEROFPIXELS (DMA2D_NLR_PL >> DMA2D_NLR_PL_Pos) /*!< Maximum number of pixels per lines */
67 #define LL_DMA2D_OFFSET_MAX 0x3FFFU /*!< Maximum output line offset expressed in pixels */
68 #define LL_DMA2D_CLUTSIZE_MAX 0xFFU /*!< Maximum CLUT size */
69 /**
70 * @}
72 /* Private macros ------------------------------------------------------------*/
73 /** @addtogroup DMA2D_LL_Private_Macros
74 * @{
76 #define IS_LL_DMA2D_MODE(MODE) (((MODE) == LL_DMA2D_MODE_M2M) || \
77 ((MODE) == LL_DMA2D_MODE_M2M_PFC) || \
78 ((MODE) == LL_DMA2D_MODE_M2M_BLEND) || \
79 ((MODE) == LL_DMA2D_MODE_R2M))
81 #define IS_LL_DMA2D_OCMODE(MODE_ARGB) (((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_ARGB8888) || \
82 ((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_RGB888) || \
83 ((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_RGB565) || \
84 ((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_ARGB1555) || \
85 ((MODE_ARGB) == LL_DMA2D_OUTPUT_MODE_ARGB4444))
87 #define IS_LL_DMA2D_GREEN(GREEN) ((GREEN) <= LL_DMA2D_COLOR)
88 #define IS_LL_DMA2D_RED(RED) ((RED) <= LL_DMA2D_COLOR)
89 #define IS_LL_DMA2D_BLUE(BLUE) ((BLUE) <= LL_DMA2D_COLOR)
90 #define IS_LL_DMA2D_ALPHA(ALPHA) ((ALPHA) <= LL_DMA2D_COLOR)
92 #define IS_LL_DMA2D_OFFSET(OOFFSET) ((OOFFSET) <= LL_DMA2D_OFFSET_MAX)
94 #define IS_LL_DMA2D_LINE(LINES) ((LINES) <= LL_DMA2D_NUMBEROFLINES)
95 #define IS_LL_DMA2D_PIXEL(PIXELS) ((PIXELS) <= LL_DMA2D_NUMBEROFPIXELS)
97 #if defined(DMA2D_ALPHA_INV_RB_SWAP_SUPPORT)
98 #define IS_LL_DMA2D_ALPHAINV(ALPHA) (((ALPHA) == LL_DMA2D_ALPHA_REGULAR) || \
99 ((ALPHA) == LL_DMA2D_ALPHA_INVERTED))
101 #define IS_LL_DMA2D_RBSWAP(RBSWAP) (((RBSWAP) == LL_DMA2D_RB_MODE_REGULAR) || \
102 ((RBSWAP) == LL_DMA2D_RB_MODE_SWAP))
104 #endif /* DMA2D_ALPHA_INV_RB_SWAP_SUPPORT */
105 #define IS_LL_DMA2D_LCMODE(MODE_ARGB) (((MODE_ARGB) == LL_DMA2D_INPUT_MODE_ARGB8888) || \
106 ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_RGB888) || \
107 ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_RGB565) || \
108 ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_ARGB1555) || \
109 ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_ARGB4444) || \
110 ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_L8) || \
111 ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_AL44) || \
112 ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_AL88) || \
113 ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_L4) || \
114 ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_A8) || \
115 ((MODE_ARGB) == LL_DMA2D_INPUT_MODE_A4))
117 #define IS_LL_DMA2D_CLUTCMODE(CLUTCMODE) (((CLUTCMODE) == LL_DMA2D_CLUT_COLOR_MODE_ARGB8888) || \
118 ((CLUTCMODE) == LL_DMA2D_CLUT_COLOR_MODE_RGB888))
120 #define IS_LL_DMA2D_CLUTSIZE(SIZE) ((SIZE) <= LL_DMA2D_CLUTSIZE_MAX)
122 #define IS_LL_DMA2D_ALPHAMODE(MODE) (((MODE) == LL_DMA2D_ALPHA_MODE_NO_MODIF) || \
123 ((MODE) == LL_DMA2D_ALPHA_MODE_REPLACE) || \
124 ((MODE) == LL_DMA2D_ALPHA_MODE_COMBINE))
126 * @}
129 /* Private function prototypes -----------------------------------------------*/
131 /* Exported functions --------------------------------------------------------*/
132 /** @addtogroup DMA2D_LL_Exported_Functions
133 * @{
136 /** @addtogroup DMA2D_LL_EF_Init_Functions Initialization and De-initialization Functions
137 * @{
141 * @brief De-initialize DMA2D registers (registers restored to their default values).
142 * @param DMA2Dx DMA2D Instance
143 * @retval An ErrorStatus enumeration value:
144 * - SUCCESS: DMA2D registers are de-initialized
145 * - ERROR: DMA2D registers are not de-initialized
147 ErrorStatus LL_DMA2D_DeInit(DMA2D_TypeDef *DMA2Dx)
149 ErrorStatus status = SUCCESS;
151 /* Check the parameters */
152 assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
154 if (DMA2Dx == DMA2D)
156 /* Force reset of DMA2D clock */
157 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_DMA2D);
159 /* Release reset of DMA2D clock */
160 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_DMA2D);
162 else
164 status = ERROR;
167 return (status);
171 * @brief Initialize DMA2D registers according to the specified parameters in DMA2D_InitStruct.
172 * @note DMA2D transfers must be disabled to set initialization bits in configuration registers,
173 * otherwise ERROR result is returned.
174 * @param DMA2Dx DMA2D Instance
175 * @param DMA2D_InitStruct: pointer to a LL_DMA2D_InitTypeDef structure
176 * that contains the configuration information for the specified DMA2D peripheral.
177 * @retval An ErrorStatus enumeration value:
178 * - SUCCESS: DMA2D registers are initialized according to DMA2D_InitStruct content
179 * - ERROR: Issue occurred during DMA2D registers initialization
181 ErrorStatus LL_DMA2D_Init(DMA2D_TypeDef *DMA2Dx, LL_DMA2D_InitTypeDef *DMA2D_InitStruct)
183 ErrorStatus status = ERROR;
184 LL_DMA2D_ColorTypeDef DMA2D_ColorStruct;
185 uint32_t tmp = 0U, tmp1 = 0U, tmp2 = 0U;
187 /* Check the parameters */
188 assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
189 assert_param(IS_LL_DMA2D_MODE(DMA2D_InitStruct->Mode));
190 assert_param(IS_LL_DMA2D_OCMODE(DMA2D_InitStruct->ColorMode));
191 assert_param(IS_LL_DMA2D_GREEN(DMA2D_InitStruct->OutputGreen));
192 assert_param(IS_LL_DMA2D_RED(DMA2D_InitStruct->OutputRed));
193 assert_param(IS_LL_DMA2D_BLUE(DMA2D_InitStruct->OutputBlue));
194 assert_param(IS_LL_DMA2D_ALPHA(DMA2D_InitStruct->OutputAlpha));
195 assert_param(IS_LL_DMA2D_OFFSET(DMA2D_InitStruct->LineOffset));
196 assert_param(IS_LL_DMA2D_LINE(DMA2D_InitStruct->NbrOfLines));
197 assert_param(IS_LL_DMA2D_PIXEL(DMA2D_InitStruct->NbrOfPixelsPerLines));
198 #if defined(DMA2D_ALPHA_INV_RB_SWAP_SUPPORT)
199 assert_param(IS_LL_DMA2D_ALPHAINV(DMA2D_InitStruct->AlphaInversionMode));
200 assert_param(IS_LL_DMA2D_RBSWAP(DMA2D_InitStruct->RBSwapMode));
201 #endif /* DMA2D_ALPHA_INV_RB_SWAP_SUPPORT */
203 /* DMA2D transfers must be disabled to configure bits in initialization registers */
204 tmp = LL_DMA2D_IsTransferOngoing(DMA2Dx);
205 tmp1 = LL_DMA2D_FGND_IsEnabledCLUTLoad(DMA2Dx);
206 tmp2 = LL_DMA2D_BGND_IsEnabledCLUTLoad(DMA2Dx);
207 if ((tmp == 0U) && (tmp1 == 0U) && (tmp2 == 0U))
209 /* DMA2D CR register configuration -------------------------------------------*/
210 LL_DMA2D_SetMode(DMA2Dx, DMA2D_InitStruct->Mode);
212 /* DMA2D OPFCCR register configuration ---------------------------------------*/
213 #if defined(DMA2D_ALPHA_INV_RB_SWAP_SUPPORT)
214 MODIFY_REG(DMA2Dx->OPFCCR, (DMA2D_OPFCCR_CM | DMA2D_OPFCCR_RBS | DMA2D_OPFCCR_AI), \
215 (DMA2D_InitStruct->ColorMode | DMA2D_InitStruct->AlphaInversionMode | DMA2D_InitStruct->RBSwapMode));
216 #else
217 MODIFY_REG(DMA2Dx->OPFCCR, DMA2D_OPFCCR_CM, DMA2D_InitStruct->ColorMode);
218 #endif /* DMA2D_ALPHA_INV_RB_SWAP_SUPPORT */
220 /* DMA2D OOR register configuration ------------------------------------------*/
221 LL_DMA2D_SetLineOffset(DMA2Dx, DMA2D_InitStruct->LineOffset);
223 /* DMA2D NLR register configuration ------------------------------------------*/
224 LL_DMA2D_ConfigSize(DMA2Dx, DMA2D_InitStruct->NbrOfLines, DMA2D_InitStruct->NbrOfPixelsPerLines);
226 /* DMA2D OMAR register configuration ------------------------------------------*/
227 LL_DMA2D_SetOutputMemAddr(DMA2Dx, DMA2D_InitStruct->OutputMemoryAddress);
229 /* DMA2D OCOLR register configuration ------------------------------------------*/
230 DMA2D_ColorStruct.ColorMode = DMA2D_InitStruct->ColorMode;
231 DMA2D_ColorStruct.OutputBlue = DMA2D_InitStruct->OutputBlue;
232 DMA2D_ColorStruct.OutputGreen = DMA2D_InitStruct->OutputGreen;
233 DMA2D_ColorStruct.OutputRed = DMA2D_InitStruct->OutputRed;
234 DMA2D_ColorStruct.OutputAlpha = DMA2D_InitStruct->OutputAlpha;
235 LL_DMA2D_ConfigOutputColor(DMA2Dx, &DMA2D_ColorStruct);
237 status = SUCCESS;
239 /* If DMA2D transfers are not disabled, return ERROR */
241 return (status);
245 * @brief Set each @ref LL_DMA2D_InitTypeDef field to default value.
246 * @param DMA2D_InitStruct: pointer to a @ref LL_DMA2D_InitTypeDef structure
247 * whose fields will be set to default values.
248 * @retval None
250 void LL_DMA2D_StructInit(LL_DMA2D_InitTypeDef *DMA2D_InitStruct)
252 /* Set DMA2D_InitStruct fields to default values */
253 DMA2D_InitStruct->Mode = LL_DMA2D_MODE_M2M;
254 DMA2D_InitStruct->ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB8888;
255 DMA2D_InitStruct->LineOffset = 0x0U;
256 DMA2D_InitStruct->OutputBlue = 0x0U;
257 DMA2D_InitStruct->OutputGreen = 0x0U;
258 DMA2D_InitStruct->OutputRed = 0x0U;
259 DMA2D_InitStruct->OutputAlpha = 0x0U;
260 DMA2D_InitStruct->OutputMemoryAddress = 0x0U;
261 DMA2D_InitStruct->NbrOfLines = 0x0U;
262 DMA2D_InitStruct->NbrOfPixelsPerLines = 0x0U;
263 #if defined(DMA2D_ALPHA_INV_RB_SWAP_SUPPORT)
264 DMA2D_InitStruct->AlphaInversionMode = LL_DMA2D_ALPHA_REGULAR;
265 DMA2D_InitStruct->RBSwapMode = LL_DMA2D_RB_MODE_REGULAR;
266 #endif /* DMA2D_ALPHA_INV_RB_SWAP_SUPPORT */
270 * @brief Configure the foreground or background according to the specified parameters
271 * in the LL_DMA2D_LayerCfgTypeDef structure.
272 * @param DMA2Dx DMA2D Instance
273 * @param DMA2D_LayerCfg: pointer to a LL_DMA2D_LayerCfgTypeDef structure that contains
274 * the configuration information for the specified layer.
275 * @param LayerIdx: DMA2D Layer index.
276 * This parameter can be one of the following values:
277 * 0(background) / 1(foreground)
278 * @retval None
280 void LL_DMA2D_ConfigLayer(DMA2D_TypeDef *DMA2Dx, LL_DMA2D_LayerCfgTypeDef *DMA2D_LayerCfg, uint32_t LayerIdx)
282 /* Check the parameters */
283 assert_param(IS_LL_DMA2D_OFFSET(DMA2D_LayerCfg->LineOffset));
284 assert_param(IS_LL_DMA2D_LCMODE(DMA2D_LayerCfg->ColorMode));
285 assert_param(IS_LL_DMA2D_CLUTCMODE(DMA2D_LayerCfg->CLUTColorMode));
286 assert_param(IS_LL_DMA2D_CLUTSIZE(DMA2D_LayerCfg->CLUTSize));
287 assert_param(IS_LL_DMA2D_ALPHAMODE(DMA2D_LayerCfg->AlphaMode));
288 assert_param(IS_LL_DMA2D_GREEN(DMA2D_LayerCfg->Green));
289 assert_param(IS_LL_DMA2D_RED(DMA2D_LayerCfg->Red));
290 assert_param(IS_LL_DMA2D_BLUE(DMA2D_LayerCfg->Blue));
291 assert_param(IS_LL_DMA2D_ALPHA(DMA2D_LayerCfg->Alpha));
292 #if defined(DMA2D_ALPHA_INV_RB_SWAP_SUPPORT)
293 assert_param(IS_LL_DMA2D_ALPHAINV(DMA2D_LayerCfg->AlphaInversionMode));
294 assert_param(IS_LL_DMA2D_RBSWAP(DMA2D_LayerCfg->RBSwapMode));
295 #endif /* DMA2D_ALPHA_INV_RB_SWAP_SUPPORT */
297 if (LayerIdx == 0U)
299 /* Configure the background memory address */
300 LL_DMA2D_BGND_SetMemAddr(DMA2Dx, DMA2D_LayerCfg->MemoryAddress);
302 /* Configure the background line offset */
303 LL_DMA2D_BGND_SetLineOffset(DMA2Dx, DMA2D_LayerCfg->LineOffset);
305 #if defined(DMA2D_ALPHA_INV_RB_SWAP_SUPPORT)
306 /* Configure the background Alpha value, Alpha mode, RB swap, Alpha inversion
307 CLUT size, CLUT Color mode and Color mode */
308 MODIFY_REG(DMA2Dx->BGPFCCR, \
309 (DMA2D_BGPFCCR_ALPHA | DMA2D_BGPFCCR_RBS | DMA2D_BGPFCCR_AI | DMA2D_BGPFCCR_AM | \
310 DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM | DMA2D_BGPFCCR_CM), \
311 ((DMA2D_LayerCfg->Alpha << DMA2D_BGPFCCR_ALPHA_Pos) | DMA2D_LayerCfg->RBSwapMode | \
312 DMA2D_LayerCfg->AlphaInversionMode | DMA2D_LayerCfg->AlphaMode | \
313 (DMA2D_LayerCfg->CLUTSize << DMA2D_BGPFCCR_CS_Pos) | DMA2D_LayerCfg->CLUTColorMode | \
314 DMA2D_LayerCfg->ColorMode));
315 #else
316 /* Configure the background Alpha value, Alpha mode, CLUT size, CLUT Color mode and Color mode */
317 MODIFY_REG(DMA2Dx->BGPFCCR, \
318 (DMA2D_BGPFCCR_ALPHA | DMA2D_BGPFCCR_AM | DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM | DMA2D_BGPFCCR_CM), \
319 ((DMA2D_LayerCfg->Alpha << DMA2D_BGPFCCR_ALPHA_Pos) | DMA2D_LayerCfg->AlphaMode | \
320 (DMA2D_LayerCfg->CLUTSize << DMA2D_BGPFCCR_CS_Pos) | DMA2D_LayerCfg->CLUTColorMode | \
321 DMA2D_LayerCfg->ColorMode));
322 #endif /* DMA2D_ALPHA_INV_RB_SWAP_SUPPORT */
324 /* Configure the background color */
325 LL_DMA2D_BGND_SetColor(DMA2Dx, DMA2D_LayerCfg->Red, DMA2D_LayerCfg->Green, DMA2D_LayerCfg->Blue);
327 /* Configure the background CLUT memory address */
328 LL_DMA2D_BGND_SetCLUTMemAddr(DMA2Dx, DMA2D_LayerCfg->CLUTMemoryAddress);
330 else
332 /* Configure the foreground memory address */
333 LL_DMA2D_FGND_SetMemAddr(DMA2Dx, DMA2D_LayerCfg->MemoryAddress);
335 /* Configure the foreground line offset */
336 LL_DMA2D_FGND_SetLineOffset(DMA2Dx, DMA2D_LayerCfg->LineOffset);
338 #if defined(DMA2D_ALPHA_INV_RB_SWAP_SUPPORT)
339 /* Configure the foreground Alpha value, Alpha mode, RB swap, Alpha inversion
340 CLUT size, CLUT Color mode and Color mode */
341 MODIFY_REG(DMA2Dx->FGPFCCR, \
342 (DMA2D_FGPFCCR_ALPHA | DMA2D_FGPFCCR_RBS | DMA2D_FGPFCCR_AI | DMA2D_FGPFCCR_AM | \
343 DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM | DMA2D_FGPFCCR_CM), \
344 ((DMA2D_LayerCfg->Alpha << DMA2D_FGPFCCR_ALPHA_Pos) | DMA2D_LayerCfg->RBSwapMode | \
345 DMA2D_LayerCfg->AlphaInversionMode | DMA2D_LayerCfg->AlphaMode | \
346 (DMA2D_LayerCfg->CLUTSize << DMA2D_FGPFCCR_CS_Pos) | DMA2D_LayerCfg->CLUTColorMode | \
347 DMA2D_LayerCfg->ColorMode));
348 #else
349 /* Configure the foreground Alpha value, Alpha mode, CLUT size, CLUT Color mode and Color mode */
350 MODIFY_REG(DMA2Dx->FGPFCCR, \
351 (DMA2D_FGPFCCR_ALPHA | DMA2D_FGPFCCR_AM | DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM | DMA2D_FGPFCCR_CM), \
352 ((DMA2D_LayerCfg->Alpha << DMA2D_FGPFCCR_ALPHA_Pos) | DMA2D_LayerCfg->AlphaMode | \
353 (DMA2D_LayerCfg->CLUTSize << DMA2D_FGPFCCR_CS_Pos) | DMA2D_LayerCfg->CLUTColorMode | \
354 DMA2D_LayerCfg->ColorMode));
355 #endif /* DMA2D_ALPHA_INV_RB_SWAP_SUPPORT */
357 /* Configure the foreground color */
358 LL_DMA2D_FGND_SetColor(DMA2Dx, DMA2D_LayerCfg->Red, DMA2D_LayerCfg->Green, DMA2D_LayerCfg->Blue);
360 /* Configure the foreground CLUT memory address */
361 LL_DMA2D_FGND_SetCLUTMemAddr(DMA2Dx, DMA2D_LayerCfg->CLUTMemoryAddress);
366 * @brief Set each @ref LL_DMA2D_LayerCfgTypeDef field to default value.
367 * @param DMA2D_LayerCfg: pointer to a @ref LL_DMA2D_LayerCfgTypeDef structure
368 * whose fields will be set to default values.
369 * @retval None
371 void LL_DMA2D_LayerCfgStructInit(LL_DMA2D_LayerCfgTypeDef *DMA2D_LayerCfg)
373 /* Set DMA2D_LayerCfg fields to default values */
374 DMA2D_LayerCfg->MemoryAddress = 0x0U;
375 DMA2D_LayerCfg->ColorMode = LL_DMA2D_INPUT_MODE_ARGB8888;
376 DMA2D_LayerCfg->LineOffset = 0x0U;
377 DMA2D_LayerCfg->CLUTColorMode = LL_DMA2D_CLUT_COLOR_MODE_ARGB8888;
378 DMA2D_LayerCfg->CLUTSize = 0x0U;
379 DMA2D_LayerCfg->AlphaMode = LL_DMA2D_ALPHA_MODE_NO_MODIF;
380 DMA2D_LayerCfg->Alpha = 0x0U;
381 DMA2D_LayerCfg->Blue = 0x0U;
382 DMA2D_LayerCfg->Green = 0x0U;
383 DMA2D_LayerCfg->Red = 0x0U;
384 DMA2D_LayerCfg->CLUTMemoryAddress = 0x0U;
385 #if defined(DMA2D_ALPHA_INV_RB_SWAP_SUPPORT)
386 DMA2D_LayerCfg->AlphaInversionMode = LL_DMA2D_ALPHA_REGULAR;
387 DMA2D_LayerCfg->RBSwapMode = LL_DMA2D_RB_MODE_REGULAR;
388 #endif /* DMA2D_ALPHA_INV_RB_SWAP_SUPPORT */
392 * @brief Initialize DMA2D output color register according to the specified parameters
393 * in DMA2D_ColorStruct.
394 * @param DMA2Dx DMA2D Instance
395 * @param DMA2D_ColorStruct: pointer to a LL_DMA2D_ColorTypeDef structure that contains
396 * the color configuration information for the specified DMA2D peripheral.
397 * @retval None
399 void LL_DMA2D_ConfigOutputColor(DMA2D_TypeDef *DMA2Dx, LL_DMA2D_ColorTypeDef *DMA2D_ColorStruct)
401 uint32_t outgreen = 0U;
402 uint32_t outred = 0U;
403 uint32_t outalpha = 0U;
405 /* Check the parameters */
406 assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
407 assert_param(IS_LL_DMA2D_OCMODE(DMA2D_ColorStruct->ColorMode));
408 assert_param(IS_LL_DMA2D_GREEN(DMA2D_ColorStruct->OutputGreen));
409 assert_param(IS_LL_DMA2D_RED(DMA2D_ColorStruct->OutputRed));
410 assert_param(IS_LL_DMA2D_BLUE(DMA2D_ColorStruct->OutputBlue));
411 assert_param(IS_LL_DMA2D_ALPHA(DMA2D_ColorStruct->OutputAlpha));
413 /* DMA2D OCOLR register configuration ------------------------------------------*/
414 if (DMA2D_ColorStruct->ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
416 outgreen = DMA2D_ColorStruct->OutputGreen << 8U;
417 outred = DMA2D_ColorStruct->OutputRed << 16U;
418 outalpha = DMA2D_ColorStruct->OutputAlpha << 24U;
420 else if (DMA2D_ColorStruct->ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888)
422 outgreen = DMA2D_ColorStruct->OutputGreen << 8U;
423 outred = DMA2D_ColorStruct->OutputRed << 16U;
424 outalpha = 0x00000000U;
426 else if (DMA2D_ColorStruct->ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565)
428 outgreen = DMA2D_ColorStruct->OutputGreen << 5U;
429 outred = DMA2D_ColorStruct->OutputRed << 11U;
430 outalpha = 0x00000000U;
432 else if (DMA2D_ColorStruct->ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
434 outgreen = DMA2D_ColorStruct->OutputGreen << 5U;
435 outred = DMA2D_ColorStruct->OutputRed << 10U;
436 outalpha = DMA2D_ColorStruct->OutputAlpha << 15U;
438 else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
440 outgreen = DMA2D_ColorStruct->OutputGreen << 4U;
441 outred = DMA2D_ColorStruct->OutputRed << 8U;
442 outalpha = DMA2D_ColorStruct->OutputAlpha << 12U;
444 LL_DMA2D_SetOutputColor(DMA2Dx, (outgreen | outred | DMA2D_ColorStruct->OutputBlue | outalpha));
448 * @brief Return DMA2D output Blue color.
449 * @param DMA2Dx DMA2D Instance.
450 * @param ColorMode This parameter can be one of the following values:
451 * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB8888
452 * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB888
453 * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB565
454 * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB1555
455 * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB4444
456 * @retval Output Blue color value between Min_Data=0 and Max_Data=0xFF
458 uint32_t LL_DMA2D_GetOutputBlueColor(DMA2D_TypeDef *DMA2Dx, uint32_t ColorMode)
460 uint32_t color = 0U;
462 /* Check the parameters */
463 assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
464 assert_param(IS_LL_DMA2D_OCMODE(ColorMode));
466 /* DMA2D OCOLR register reading ------------------------------------------*/
467 if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
469 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFFU));
471 else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888)
473 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFFU));
475 else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565)
477 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x1FU));
479 else if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
481 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x1FU));
483 else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
485 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFU));
488 return color;
492 * @brief Return DMA2D output Green color.
493 * @param DMA2Dx DMA2D Instance.
494 * @param ColorMode This parameter can be one of the following values:
495 * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB8888
496 * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB888
497 * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB565
498 * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB1555
499 * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB4444
500 * @retval Output Green color value between Min_Data=0 and Max_Data=0xFF
502 uint32_t LL_DMA2D_GetOutputGreenColor(DMA2D_TypeDef *DMA2Dx, uint32_t ColorMode)
504 uint32_t color = 0U;
506 /* Check the parameters */
507 assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
508 assert_param(IS_LL_DMA2D_OCMODE(ColorMode));
510 /* DMA2D OCOLR register reading ------------------------------------------*/
511 if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
513 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF00U) >> 8U);
515 else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888)
517 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF00U) >> 8U);
519 else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565)
521 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x7E0U) >> 5U);
523 else if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
525 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x3E0U) >> 5U);
527 else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
529 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xF0U) >> 4U);
532 return color;
536 * @brief Return DMA2D output Red color.
537 * @param DMA2Dx DMA2D Instance.
538 * @param ColorMode This parameter can be one of the following values:
539 * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB8888
540 * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB888
541 * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB565
542 * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB1555
543 * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB4444
544 * @retval Output Red color value between Min_Data=0 and Max_Data=0xFF
546 uint32_t LL_DMA2D_GetOutputRedColor(DMA2D_TypeDef *DMA2Dx, uint32_t ColorMode)
548 uint32_t color = 0U;
550 /* Check the parameters */
551 assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
552 assert_param(IS_LL_DMA2D_OCMODE(ColorMode));
554 /* DMA2D OCOLR register reading ------------------------------------------*/
555 if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
557 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF0000U) >> 16U);
559 else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888)
561 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF0000U) >> 16U);
563 else if (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565)
565 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xF800U) >> 11U);
567 else if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
569 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x7C00U) >> 10U);
571 else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
573 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xF00U) >> 8U);
576 return color;
580 * @brief Return DMA2D output Alpha color.
581 * @param DMA2Dx DMA2D Instance.
582 * @param ColorMode This parameter can be one of the following values:
583 * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB8888
584 * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB888
585 * @arg @ref LL_DMA2D_OUTPUT_MODE_RGB565
586 * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB1555
587 * @arg @ref LL_DMA2D_OUTPUT_MODE_ARGB4444
588 * @retval Output Alpha color value between Min_Data=0 and Max_Data=0xFF
590 uint32_t LL_DMA2D_GetOutputAlphaColor(DMA2D_TypeDef *DMA2Dx, uint32_t ColorMode)
592 uint32_t color = 0U;
594 /* Check the parameters */
595 assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx));
596 assert_param(IS_LL_DMA2D_OCMODE(ColorMode));
598 /* DMA2D OCOLR register reading ------------------------------------------*/
599 if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB8888)
601 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xFF000000U) >> 24U);
603 else if ((ColorMode == LL_DMA2D_OUTPUT_MODE_RGB888) || (ColorMode == LL_DMA2D_OUTPUT_MODE_RGB565))
605 color = 0x0U;
607 else if (ColorMode == LL_DMA2D_OUTPUT_MODE_ARGB1555)
609 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0x8000U) >> 15U);
611 else /* ColorMode = LL_DMA2D_OUTPUT_MODE_ARGB4444 */
613 color = (uint32_t)(READ_BIT(DMA2Dx->OCOLR, 0xF000U) >> 12U);
616 return color;
620 * @brief Configure DMA2D transfer size.
621 * @param DMA2Dx DMA2D Instance
622 * @param NbrOfLines Value between Min_Data=0 and Max_Data=0xFFFF
623 * @param NbrOfPixelsPerLines Value between Min_Data=0 and Max_Data=0x3FFF
624 * @retval None
626 void LL_DMA2D_ConfigSize(DMA2D_TypeDef *DMA2Dx, uint32_t NbrOfLines, uint32_t NbrOfPixelsPerLines)
628 MODIFY_REG(DMA2Dx->NLR, (DMA2D_NLR_PL | DMA2D_NLR_NL), \
629 ((NbrOfPixelsPerLines << DMA2D_NLR_PL_Pos) | NbrOfLines));
633 * @}
637 * @}
641 * @}
644 #endif /* defined (DMA2D) */
647 * @}
650 #endif /* USE_FULL_LL_DRIVER */
652 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/