图像处理的专门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

相关文章: