DMA2D配置与显示图形
1.DMA2D参数配置:
void BSP_DMA2D_Init(void)
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2D,ENABLE);
}
void BSP_DMA2D_Line_Layer1(uint32_t BSP_Position_X,uint32_t BSP_Position_Y,uint32_t BSP_Line_Width,uint32_t BSP_Line_Height,uint32_t BSP_Line_K,uint32_t BSP_Line_Color)
{
DMA2D_DeInit();
DMA2D_InitTypeDef DMA2D_InitStruct;
DMA2D_InitStruct.DMA2D_Mode = DMA2D_R2M;//寄存器到显存模式
DMA2D_InitStruct.DMA2D_CMode = DMA2D_ARGB8888;
DMA2D_InitStruct.DMA2D_OutputBlue = (BSP_Line_Color>>0)&0x000000FF;
DMA2D_InitStruct.DMA2D_OutputGreen = (BSP_Line_Color>>8)&0x000000FF;
DMA2D_InitStruct.DMA2D_OutputRed = (BSP_Line_Color>>16)&0x000000FF;
DMA2D_InitStruct.DMA2D_OutputAlpha = (BSP_Line_Color>>24)&0x000000FF;
DMA2D_InitStruct.DMA2D_OutputMemoryAdd = LCD_LAYER1_Buffer_Adderess + (LCD_PIXEL_WIDTH * 4 * BSP_Position_Y) + (BSP_Position_X*4); //layer2 显存地址
DMA2D_InitStruct.DMA2D_OutputOffset = LCD_PIXEL_WIDTH - BSP_Line_Width + BSP_Line_K; //偏移量 本行末尾 到 下一行开始 的像素数量
DMA2D_InitStruct.DMA2D_NumberOfLine = BSP_Line_Height;
DMA2D_InitStruct.DMA2D_PixelPerLine = BSP_Line_Width;
DMA2D_Init(&DMA2D_InitStruct);
DMA2D_StartTransfer();
while(DMA2D_GetFlagStatus(DMA2D_FLAG_TC) != SET);
}
void BSP_DMA2D_Line_Layer2(uint32_t BSP_Position_X,uint32_t BSP_Position_Y,uint32_t BSP_Line_Width,uint32_t BSP_Line_Height,uint32_t BSP_Line_K,uint32_t BSP_Line_Color)
{
DMA2D_DeInit();
DMA2D_InitTypeDef DMA2D_InitStruct;
DMA2D_InitStruct.DMA2D_Mode = DMA2D_R2M;//寄存器到显存模式
DMA2D_InitStruct.DMA2D_CMode = DMA2D_ARGB8888;
DMA2D_InitStruct.DMA2D_OutputBlue = (BSP_Line_Color>>0)&0x000000FF;
DMA2D_InitStruct.DMA2D_OutputGreen = (BSP_Line_Color>>8)&0x000000FF;
DMA2D_InitStruct.DMA2D_OutputRed = (BSP_Line_Color>>16)&0x000000FF;
DMA2D_InitStruct.DMA2D_OutputAlpha = (BSP_Line_Color>>24)&0x000000FF;
DMA2D_InitStruct.DMA2D_OutputMemoryAdd = LCD_LAYER2_Buffer_Adderess + (LCD_PIXEL_WIDTH * 4 * BSP_Position_Y) + (BSP_Position_X*4); //layer2 显存地址
DMA2D_InitStruct.DMA2D_OutputOffset = LCD_PIXEL_WIDTH - BSP_Line_Width + BSP_Line_K; //偏移量 本行末尾 到 下一行开始 的像素数量
DMA2D_InitStruct.DMA2D_NumberOfLine = BSP_Line_Height;
DMA2D_InitStruct.DMA2D_PixelPerLine = BSP_Line_Width;
DMA2D_Init(&DMA2D_InitStruct);
DMA2D_StartTransfer();
while(DMA2D_GetFlagStatus(DMA2D_FLAG_TC) != SET);
}
2.清屏函数:
void BSP_Clear_Layer1(void)
{
uint16_t i,j;
uint32_t *p = (uint32_t *)LCD_LAYER1_Buffer_Adderess;
for(j=0;j<480;j++)
{
for(i=0;i<800;i++)
{
*p = BLACK;
p++;
}
}
}
void BSP_Clear_Layer2(void)
{
uint16_t i,j;
uint32_t *p = (uint32_t *)LCD_LAYER2_Buffer_Adderess;
for(j=0;j<480;j++)
for(i=0;i<800;i++)
{
*p = 0xFF000000;
p++;
}
}
3.测试函数
void BSP_LCD_DisplayTest(void)
{
BSP_Clear_Layer1();
BSP_Clear_Layer2();
BSP_DMA2D_Line_Layer2(200,200,20,50,0,YELLOW);
BSP_DMA2D_Line_Layer2(0,0,50,50,0,WHITE);
BSP_DMA2D_Line_Layer2(50,50,5,200,0,BLUE);
BSP_DMA2D_Line_Layer2(200,100,200,5,0,RED);
}
4.测试结果
?改变参数多次调用DMA2D_Init()出现错误
* 初始化前调用DMA2D_DeInit()
? 传递#define的地址出错
* #define的地址是两数相加,应带上括号避免出错