图像处理的专门DMA
看一段示例代码
1 /** 2 * @brief Displays a line. 3 * @param Xpos: specifies the X position. 4 * @param Ypos: specifies the Y position. 5 * @param Length: line length. 6 * @param Direction: line direction. 7 * This parameter can be one of the following values: Vertical or Horizontal. 8 * @retval None 9 */ 10 void LCD_DrawLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length, uint8_t Direction) 11 { 12 DMA2D_InitTypeDef DMA2D_InitStruct; 13 14 uint32_t Xaddress = 0; 15 uint16_t Red_Value = 0, Green_Value = 0, Blue_Value = 0; 16 17 Xaddress = CurrentFrameBuffer + 2*(LCD_PIXEL_WIDTH*Ypos + Xpos); 18 19 Red_Value = (0xF800 & CurrentTextColor) >> 11; 20 Blue_Value = 0x001F & CurrentTextColor; 21 Green_Value = (0x07E0 & CurrentTextColor) >> 5; 22 23 /* Configure DMA2D */ 24 DMA2D_DeInit(); 25 DMA2D_InitStruct.DMA2D_Mode = DMA2D_R2M; 26 DMA2D_InitStruct.DMA2D_CMode = DMA2D_RGB565; 27 DMA2D_InitStruct.DMA2D_OutputGreen = Green_Value; 28 DMA2D_InitStruct.DMA2D_OutputBlue = Blue_Value; 29 DMA2D_InitStruct.DMA2D_OutputRed = Red_Value; 30 DMA2D_InitStruct.DMA2D_OutputAlpha = 0x0F; 31 DMA2D_InitStruct.DMA2D_OutputMemoryAdd = Xaddress; 32 33 if(Direction == LCD_DIR_HORIZONTAL) 34 { 35 DMA2D_InitStruct.DMA2D_OutputOffset = 0; 36 DMA2D_InitStruct.DMA2D_NumberOfLine = 1; 37 DMA2D_InitStruct.DMA2D_PixelPerLine = Length; 38 } 39 else 40 { 41 DMA2D_InitStruct.DMA2D_OutputOffset = LCD_PIXEL_WIDTH - 1; 42 DMA2D_InitStruct.DMA2D_NumberOfLine = Length; 43 DMA2D_InitStruct.DMA2D_PixelPerLine = 1; 44 } 45 46 DMA2D_Init(&DMA2D_InitStruct); 47 /* Start Transfer */ 48 DMA2D_StartTransfer(); 49 /* Wait for CTC Flag activation */ 50 while(DMA2D_GetFlagStatus(DMA2D_FLAG_TC) == RESET) 51 { 52 } 53 54 }
LCD_DrawLine
里面不好理解的是offset那块,其他统一模式设置看看手册即可,这个offset设置我们先看寄存器是哪个
/* Configure the line Offset */
DMA2D->OOR &= ~(uint32_t)DMA2D_OOR_LO;
DMA2D->OOR |= (DMA2D_InitStruct->DMA2D_OutputOffset);
寄存器定义:
再看代码那几句:
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_PIXEL_WIDTH - 1;
DMA2D_InitStruct.DMA2D_NumberOfLine = Length;
DMA2D_InitStruct.DMA2D_PixelPerLine = 1;
}
if里很明白,在指定位置没有offset画一条length长的线
else是画的竖线,所以每行只画一个点,画length条线,所以每行只画一个点,offset的值就是:LCD_PIXEL_WIDTH - 1