static void DMA2D_Config(void) { DMA2D_InitTypeDef DMA2D_InitStruct; /* Enable the DMA2D Clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2D, ENABLE); DMA2D_DeInit(); /* Configure transfer mode */ DMA2D_InitStruct.DMA2D_Mode = DMA2D_R2M; /* Configure color mode */ DMA2D_InitStruct.DMA2D_CMode = DMA2D_ARGB4444; /* Configure A,R,G,B value : color to be used to fill user defined area */ DMA2D_InitStruct.DMA2D_OutputGreen = 0; DMA2D_InitStruct.DMA2D_OutputBlue = 15; DMA2D_InitStruct.DMA2D_OutputRed = 15; DMA2D_InitStruct.DMA2D_OutputAlpha = 15; /* Configure output Address */ DMA2D_InitStruct.DMA2D_OutputMemoryAdd = (uint32_t)&aBufferResult; /* Configure output offset */ DMA2D_InitStruct.DMA2D_OutputOffset = 0; /* Configure number of lines : height */ DMA2D_InitStruct.DMA2D_NumberOfLine = 100; /* Configure number of pixel per line : width */ DMA2D_InitStruct.DMA2D_PixelPerLine = 100; DMA2D_Init(&DMA2D_InitStruct); }
/** * @brief Está rotina é chamada para imprimir um retângulo preenchido * @param Posição X, Posição Y, largura, altura , cor * @retval Nenhum */ void LCD_DrawFullRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height, uint16_t color) { DMA2D_InitTypeDef DMA2D_InitStruct; uint32_t Xaddress = 0; uint16_t Red_Value = 0, Green_Value = 0, Blue_Value = 0; Red_Value = (0xF800 & color) >> 11; Blue_Value = 0x001F & color; Green_Value = (0x07E0 & color) >> 5; Xaddress = CurrentFrameBuffer + 2*(LCD_MAXX*Ypos + Xpos); /* configure DMA2D */ DMA2D_DeInit(); DMA2D_InitStruct.DMA2D_Mode = DMA2D_R2M; DMA2D_InitStruct.DMA2D_CMode = DMA2D_RGB565; DMA2D_InitStruct.DMA2D_OutputGreen = Green_Value; DMA2D_InitStruct.DMA2D_OutputBlue = Blue_Value; DMA2D_InitStruct.DMA2D_OutputRed = Red_Value; DMA2D_InitStruct.DMA2D_OutputAlpha = 0x0F; DMA2D_InitStruct.DMA2D_OutputMemoryAdd = Xaddress; DMA2D_InitStruct.DMA2D_OutputOffset = (LCD_MAXX - Width); DMA2D_InitStruct.DMA2D_NumberOfLine = Height; DMA2D_InitStruct.DMA2D_PixelPerLine = Width; DMA2D_Init(&DMA2D_InitStruct); /* Start Transfer */ DMA2D_StartTransfer(); /* Wait for CTC Flag activation */ while(DMA2D_GetFlagStatus(DMA2D_FLAG_TC) == RESET) { } }
static void DMA2D_Config(void) { DMA2D_InitTypeDef DMA2D_InitStruct; DMA2D_FG_InitTypeDef DMA2D_FG_InitStruct; /* Enable the DMA2D Clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2D, ENABLE); /* DMA2D configuration */ DMA2D_DeInit(); /* Transfer mode */ DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M; /* Color mode */ DMA2D_InitStruct.DMA2D_CMode = DMA2D_ARGB4444; /* Output Address */ DMA2D_InitStruct.DMA2D_OutputMemoryAdd = (uint32_t)&aBufferResult; /* Output Offset */ DMA2D_InitStruct.DMA2D_OutputOffset = 0; /* Number of lines : height */ DMA2D_InitStruct.DMA2D_NumberOfLine = 150; /* Number of pixel per line : width */ DMA2D_InitStruct.DMA2D_PixelPerLine = 150; /* Initialize the alpha and RGB values */ DMA2D_InitStruct.DMA2D_OutputGreen = 0; DMA2D_InitStruct.DMA2D_OutputBlue = 0; DMA2D_InitStruct.DMA2D_OutputRed = 0; DMA2D_InitStruct.DMA2D_OutputAlpha = 0; /* Initialize the output offset */ DMA2D_InitStruct.DMA2D_OutputOffset = 0; /* Initialize DMA2D */ DMA2D_Init(&DMA2D_InitStruct); /* Configure default values for foreground */ DMA2D_FG_StructInit(&DMA2D_FG_InitStruct); /* Configure DMA2D foreground color mode */ DMA2D_FG_InitStruct.DMA2D_FGCM = CM_ARGB4444; /* Configure Input Address */ DMA2D_FG_InitStruct.DMA2D_FGMA = (uint32_t)&ARGB4444_150x150; /* Initialize foreground */ DMA2D_FGConfig(&DMA2D_FG_InitStruct); }
//-------------------------------------------------------------- void LCD_DrawLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length, uint8_t Direction, uint16_t color) { DMA2D_InitTypeDef DMA2D_InitStruct; uint32_t Xaddress = 0; uint16_t Red_Value = 0, Green_Value = 0, Blue_Value = 0; Xaddress = CurrentFrameBuffer + 2*(LCD_MAXX*Ypos + Xpos); Red_Value = (0xF800 & color) >> 11; Blue_Value = 0x001F & color; Green_Value = (0x07E0 & color) >> 5; /* Configure DMA2D */ DMA2D_DeInit(); DMA2D_InitStruct.DMA2D_Mode = DMA2D_R2M; DMA2D_InitStruct.DMA2D_CMode = DMA2D_RGB565; DMA2D_InitStruct.DMA2D_OutputGreen = Green_Value; DMA2D_InitStruct.DMA2D_OutputBlue = Blue_Value; DMA2D_InitStruct.DMA2D_OutputRed = Red_Value; DMA2D_InitStruct.DMA2D_OutputAlpha = 0x0F; DMA2D_InitStruct.DMA2D_OutputMemoryAdd = Xaddress; if(Direction == LCD_DIR_HORIZONTAL) { DMA2D_InitStruct.DMA2D_OutputOffset = 0; DMA2D_InitStruct.DMA2D_NumberOfLine = 1; DMA2D_InitStruct.DMA2D_PixelPerLine = Length; } else { DMA2D_InitStruct.DMA2D_OutputOffset = LCD_MAXX - 1; DMA2D_InitStruct.DMA2D_NumberOfLine = Length; DMA2D_InitStruct.DMA2D_PixelPerLine = 1; } DMA2D_Init(&DMA2D_InitStruct); /* Start Transfer */ DMA2D_StartTransfer(); /* Wait for CTC Flag activation */ while(DMA2D_GetFlagStatus(DMA2D_FLAG_TC) == RESET) { } }
static void DMA2D_Config(void) { DMA2D_InitTypeDef DMA2D_InitStruct; DMA2D_FG_InitTypeDef DMA2D_FG_InitStruct; DMA2D_BG_InitTypeDef DMA2D_BG_InitStruct; /* Enable the DMA2D Clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2D, ENABLE); /* DMA2D DeInitialization */ DMA2D_DeInit(); /* Configure transfer mode : memory to memory with blending */ DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M_BLEND; /* Configure color mode : RGB565 pixel format */ DMA2D_InitStruct.DMA2D_CMode = DMA2D_RGB565; /* Configure output Address : output frame buffer is located at SRAM */ DMA2D_InitStruct.DMA2D_OutputMemoryAdd = (uint32_t)&aBlendedImage; /* Configure the alpha and RGB values */ DMA2D_InitStruct.DMA2D_OutputGreen = 0; DMA2D_InitStruct.DMA2D_OutputBlue = 0; DMA2D_InitStruct.DMA2D_OutputRed = 0; DMA2D_InitStruct.DMA2D_OutputAlpha = 0; /* Configure the output offset */ DMA2D_InitStruct.DMA2D_OutputOffset = 0; /* Configure number of lines : height */ DMA2D_InitStruct.DMA2D_NumberOfLine = 130; /* Configure number of pixel per line : width */ DMA2D_InitStruct.DMA2D_PixelPerLine = 240; /* DMA2D Initialization */ DMA2D_Init(&DMA2D_InitStruct); /* Configure default values for foreground */ DMA2D_FG_StructInit(&DMA2D_FG_InitStruct); /* Configure foreground memory address : first input memory address at FLASH memory */ DMA2D_FG_InitStruct.DMA2D_FGMA = (uint32_t)&RGB565_240x130_1; /* Configure foreground color mode */ DMA2D_FG_InitStruct.DMA2D_FGCM = CM_RGB565; /* Configure foreground alpha value */ DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = REPLACE_ALPHA_VALUE; /* Configure foreground alpha mode : The constant alpha for foreground is decreased to see the background */ DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_VALUE = 0x75; /* Foreground Initialization */ DMA2D_FGConfig(&DMA2D_FG_InitStruct); /* Configure default values for background */ DMA2D_BG_StructInit(&DMA2D_BG_InitStruct); /* Configure background memory address : second input memory address at FLASH memory */ DMA2D_BG_InitStruct.DMA2D_BGMA = (uint32_t)&RGB565_240x130_2; /* Configure background color mode */ DMA2D_BG_InitStruct.DMA2D_BGCM = CM_RGB565; /* Configure background alpha mode */ DMA2D_BG_InitStruct.DMA2D_BGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE; /* Configure background alpha value */ DMA2D_BG_InitStruct.DMA2D_BGPFC_ALPHA_VALUE = 255; /* Background Initialization */ DMA2D_BGConfig(&DMA2D_BG_InitStruct); }