/** * @brief Initialize DMA2D registers according to the specified parameters in DMA2D_InitStruct. * @note DMA2D transfers must be disabled to set initialization bits in configuration registers, * otherwise ERROR result is returned. * @param DMA2Dx DMA2D Instance * @param DMA2D_InitStruct: pointer to a LL_DMA2D_InitTypeDef structure * that contains the configuration information for the specified DMA2D peripheral. * @retval An ErrorStatus enumeration value: * - SUCCESS: DMA2D registers are initialized according to DMA2D_InitStruct content * - ERROR: Issue occurred during DMA2D registers initialization */ ErrorStatus LL_DMA2D_Init(DMA2D_TypeDef *DMA2Dx, LL_DMA2D_InitTypeDef *DMA2D_InitStruct) { ErrorStatus status = ERROR; LL_DMA2D_ColorTypeDef DMA2D_ColorStruct; uint32_t tmp = 0U, tmp1 = 0U, tmp2 = 0U; /* Check the parameters */ assert_param(IS_DMA2D_ALL_INSTANCE(DMA2Dx)); assert_param(IS_LL_DMA2D_MODE(DMA2D_InitStruct->Mode)); assert_param(IS_LL_DMA2D_OCMODE(DMA2D_InitStruct->ColorMode)); assert_param(IS_LL_DMA2D_LINE(DMA2D_InitStruct->NbrOfLines)); assert_param(IS_LL_DMA2D_PIXEL(DMA2D_InitStruct->NbrOfPixelsPerLines)); assert_param(IS_LL_DMA2D_GREEN(DMA2D_InitStruct->OutputGreen)); assert_param(IS_LL_DMA2D_RED(DMA2D_InitStruct->OutputRed)); assert_param(IS_LL_DMA2D_BLUE(DMA2D_InitStruct->OutputBlue)); assert_param(IS_LL_DMA2D_ALPHA(DMA2D_InitStruct->OutputAlpha)); assert_param(IS_LL_DMA2D_OFFSET(DMA2D_InitStruct->LineOffset)); assert_param(IS_LL_DMA2D_ALPHAINV(DMA2D_InitStruct->AlphaInversionMode)); assert_param(IS_LL_DMA2D_RBSWAP(DMA2D_InitStruct->RBSwapMode)); /* DMA2D transfers must be disabled to configure bits in initialization registers */ tmp = LL_DMA2D_IsTransferOngoing(DMA2Dx); tmp1 = LL_DMA2D_FGND_IsEnabledCLUTLoad(DMA2Dx); tmp2 = LL_DMA2D_BGND_IsEnabledCLUTLoad(DMA2Dx); if ((tmp == 0U) && (tmp1 == 0U) && (tmp2 == 0U)) { /* DMA2D CR register configuration -------------------------------------------*/ LL_DMA2D_SetMode(DMA2Dx, DMA2D_InitStruct->Mode); /* DMA2D OPFCCR register configuration ---------------------------------------*/ MODIFY_REG(DMA2Dx->OPFCCR, (DMA2D_OPFCCR_CM | DMA2D_OPFCCR_RBS | DMA2D_OPFCCR_AI), \ (DMA2D_InitStruct->ColorMode | DMA2D_InitStruct->AlphaInversionMode | DMA2D_InitStruct->RBSwapMode)); /* DMA2D OOR register configuration ------------------------------------------*/ LL_DMA2D_SetLineOffset(DMA2Dx, DMA2D_InitStruct->LineOffset); /* DMA2D NLR register configuration ------------------------------------------*/ LL_DMA2D_ConfigSize(DMA2Dx, DMA2D_InitStruct->NbrOfLines, DMA2D_InitStruct->NbrOfPixelsPerLines); /* DMA2D OMAR register configuration ------------------------------------------*/ LL_DMA2D_SetOutputMemAddr(DMA2Dx, DMA2D_InitStruct->OutputMemoryAddress); /* DMA2D OCOLR register configuration ------------------------------------------*/ DMA2D_ColorStruct.ColorMode = DMA2D_InitStruct->ColorMode; DMA2D_ColorStruct.OutputBlue = DMA2D_InitStruct->OutputBlue; DMA2D_ColorStruct.OutputGreen = DMA2D_InitStruct->OutputGreen; DMA2D_ColorStruct.OutputRed = DMA2D_InitStruct->OutputRed; DMA2D_ColorStruct.OutputAlpha = DMA2D_InitStruct->OutputAlpha; LL_DMA2D_ConfigOutputColor(DMA2Dx, &DMA2D_ColorStruct); status = SUCCESS; } /* If DMA2D transfers are not disabled, return ERROR */ return (status); }
/** * @brief Configure the foreground or background according to the specified parameters * in the LL_DMA2D_LayerCfgTypeDef structure. * @param DMA2Dx DMA2D Instance * @param DMA2D_LayerCfg: pointer to a LL_DMA2D_LayerCfgTypeDef structure that contains * the configuration information for the specified layer. * @param LayerIdx: DMA2D Layer index. * This parameter can be one of the following values: * 0(background) / 1(foreground) * @retval None */ void LL_DMA2D_ConfigLayer(DMA2D_TypeDef *DMA2Dx, LL_DMA2D_LayerCfgTypeDef *DMA2D_LayerCfg, uint32_t LayerIdx) { /* Check the parameters */ assert_param(IS_LL_DMA2D_OFFSET(DMA2D_LayerCfg->LineOffset)); assert_param(IS_LL_DMA2D_LCMODE(DMA2D_LayerCfg->ColorMode)); assert_param(IS_LL_DMA2D_CLUTCMODE(DMA2D_LayerCfg->CLUTColorMode)); assert_param(IS_LL_DMA2D_CLUTSIZE(DMA2D_LayerCfg->CLUTSize)); assert_param(IS_LL_DMA2D_ALPHAMODE(DMA2D_LayerCfg->AlphaMode)); assert_param(IS_LL_DMA2D_GREEN(DMA2D_LayerCfg->Green)); assert_param(IS_LL_DMA2D_RED(DMA2D_LayerCfg->Red)); assert_param(IS_LL_DMA2D_BLUE(DMA2D_LayerCfg->Blue)); assert_param(IS_LL_DMA2D_ALPHA(DMA2D_LayerCfg->Alpha)); #if defined(DMA2D_ALPHA_INV_RB_SWAP_SUPPORT) assert_param(IS_LL_DMA2D_ALPHAINV(DMA2D_LayerCfg->AlphaInversionMode)); assert_param(IS_LL_DMA2D_RBSWAP(DMA2D_LayerCfg->RBSwapMode)); #endif /* DMA2D_ALPHA_INV_RB_SWAP_SUPPORT */ if (LayerIdx == 0U) { /* Configure the background memory address */ LL_DMA2D_BGND_SetMemAddr(DMA2Dx, DMA2D_LayerCfg->MemoryAddress); /* Configure the background line offset */ LL_DMA2D_BGND_SetLineOffset(DMA2Dx, DMA2D_LayerCfg->LineOffset); #if defined(DMA2D_ALPHA_INV_RB_SWAP_SUPPORT) /* Configure the background Alpha value, Alpha mode, RB swap, Alpha inversion CLUT size, CLUT Color mode and Color mode */ MODIFY_REG(DMA2Dx->BGPFCCR, \ (DMA2D_BGPFCCR_ALPHA | DMA2D_BGPFCCR_RBS | DMA2D_BGPFCCR_AI | DMA2D_BGPFCCR_AM | \ DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM | DMA2D_BGPFCCR_CM), \ ((DMA2D_LayerCfg->Alpha << DMA2D_BGPFCCR_ALPHA_Pos) | DMA2D_LayerCfg->RBSwapMode | \ DMA2D_LayerCfg->AlphaInversionMode | DMA2D_LayerCfg->AlphaMode | \ (DMA2D_LayerCfg->CLUTSize << DMA2D_BGPFCCR_CS_Pos) | DMA2D_LayerCfg->CLUTColorMode | \ DMA2D_LayerCfg->ColorMode)); #else /* Configure the background Alpha value, Alpha mode, CLUT size, CLUT Color mode and Color mode */ MODIFY_REG(DMA2Dx->BGPFCCR, \ (DMA2D_BGPFCCR_ALPHA | DMA2D_BGPFCCR_AM | DMA2D_BGPFCCR_CS | DMA2D_BGPFCCR_CCM | DMA2D_BGPFCCR_CM), \ ((DMA2D_LayerCfg->Alpha << DMA2D_BGPFCCR_ALPHA_Pos) | DMA2D_LayerCfg->AlphaMode | \ (DMA2D_LayerCfg->CLUTSize << DMA2D_BGPFCCR_CS_Pos) | DMA2D_LayerCfg->CLUTColorMode | \ DMA2D_LayerCfg->ColorMode)); #endif /* DMA2D_ALPHA_INV_RB_SWAP_SUPPORT */ /* Configure the background color */ LL_DMA2D_BGND_SetColor(DMA2Dx, DMA2D_LayerCfg->Red, DMA2D_LayerCfg->Green, DMA2D_LayerCfg->Blue); /* Configure the background CLUT memory address */ LL_DMA2D_BGND_SetCLUTMemAddr(DMA2Dx, DMA2D_LayerCfg->CLUTMemoryAddress); } else { /* Configure the foreground memory address */ LL_DMA2D_FGND_SetMemAddr(DMA2Dx, DMA2D_LayerCfg->MemoryAddress); /* Configure the foreground line offset */ LL_DMA2D_FGND_SetLineOffset(DMA2Dx, DMA2D_LayerCfg->LineOffset); #if defined(DMA2D_ALPHA_INV_RB_SWAP_SUPPORT) /* Configure the foreground Alpha value, Alpha mode, RB swap, Alpha inversion CLUT size, CLUT Color mode and Color mode */ MODIFY_REG(DMA2Dx->FGPFCCR, \ (DMA2D_FGPFCCR_ALPHA | DMA2D_FGPFCCR_RBS | DMA2D_FGPFCCR_AI | DMA2D_FGPFCCR_AM | \ DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM | DMA2D_FGPFCCR_CM), \ ((DMA2D_LayerCfg->Alpha << DMA2D_FGPFCCR_ALPHA_Pos) | DMA2D_LayerCfg->RBSwapMode | \ DMA2D_LayerCfg->AlphaInversionMode | DMA2D_LayerCfg->AlphaMode | \ (DMA2D_LayerCfg->CLUTSize << DMA2D_FGPFCCR_CS_Pos) | DMA2D_LayerCfg->CLUTColorMode | \ DMA2D_LayerCfg->ColorMode)); #else /* Configure the foreground Alpha value, Alpha mode, CLUT size, CLUT Color mode and Color mode */ MODIFY_REG(DMA2Dx->FGPFCCR, \ (DMA2D_FGPFCCR_ALPHA | DMA2D_FGPFCCR_AM | DMA2D_FGPFCCR_CS | DMA2D_FGPFCCR_CCM | DMA2D_FGPFCCR_CM), \ ((DMA2D_LayerCfg->Alpha << DMA2D_FGPFCCR_ALPHA_Pos) | DMA2D_LayerCfg->AlphaMode | \ (DMA2D_LayerCfg->CLUTSize << DMA2D_FGPFCCR_CS_Pos) | DMA2D_LayerCfg->CLUTColorMode | \ DMA2D_LayerCfg->ColorMode)); #endif /* DMA2D_ALPHA_INV_RB_SWAP_SUPPORT */ /* Configure the foreground color */ LL_DMA2D_FGND_SetColor(DMA2Dx, DMA2D_LayerCfg->Red, DMA2D_LayerCfg->Green, DMA2D_LayerCfg->Blue); /* Configure the foreground CLUT memory address */ LL_DMA2D_FGND_SetCLUTMemAddr(DMA2Dx, DMA2D_LayerCfg->CLUTMemoryAddress); } }