圖像處理的專門DMAide
看一段示例代碼函數
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 }
裏面很差理解的是offset那塊,其餘統一模式設置看看手冊便可,這個offset設置咱們先看寄存器是哪一個ui
/* Configure the line Offset */
DMA2D->OOR &= ~(uint32_t)DMA2D_OOR_LO;
DMA2D->OOR |= (DMA2D_InitStruct->DMA2D_OutputOffset);spa
寄存器定義:3d
再看代碼那幾句:code
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;
}orm
if裏很明白,在指定位置沒有offset畫一條length長的線blog
else是畫的豎線,因此每行只畫一個點,畫length條線,因此每行只畫一個點,offset的值就是:LCD_PIXEL_WIDTH - 1ip
發現不一樣MODE有不少不一樣理解故深化一下看看初始化函數內部操做的哪些寄存器進一步理解ci
1 /** 2 * @brief Initializes the DMA2D peripheral according to the specified parameters 3 * in the DMA2D_InitStruct. 4 * @note This function can be used only when the DMA2D is disabled. 5 * @param DMA2D_InitStruct: pointer to a DMA2D_InitTypeDef structure that contains 6 * the configuration information for the specified DMA2D peripheral. 7 * @retval None 8 */ 9 void DMA2D_Init(DMA2D_InitTypeDef* DMA2D_InitStruct) 10 { 11 12 uint32_t outgreen = 0; 13 uint32_t outred = 0; 14 uint32_t outalpha = 0; 15 uint32_t pixline = 0; 16 17 /* Check the parameters */ 18 assert_param(IS_DMA2D_MODE(DMA2D_InitStruct->DMA2D_Mode)); 19 assert_param(IS_DMA2D_CMODE(DMA2D_InitStruct->DMA2D_CMode)); 20 assert_param(IS_DMA2D_OGREEN(DMA2D_InitStruct->DMA2D_OutputGreen)); 21 assert_param(IS_DMA2D_ORED(DMA2D_InitStruct->DMA2D_OutputRed)); 22 assert_param(IS_DMA2D_OBLUE(DMA2D_InitStruct->DMA2D_OutputBlue)); 23 assert_param(IS_DMA2D_OALPHA(DMA2D_InitStruct->DMA2D_OutputAlpha)); 24 assert_param(IS_DMA2D_OUTPUT_OFFSET(DMA2D_InitStruct->DMA2D_OutputOffset)); 25 assert_param(IS_DMA2D_LINE(DMA2D_InitStruct->DMA2D_NumberOfLine)); 26 assert_param(IS_DMA2D_PIXEL(DMA2D_InitStruct->DMA2D_PixelPerLine)); 27 28 /* Configures the DMA2D operation mode */ 29 DMA2D->CR &= (uint32_t)CR_MASK; 30 DMA2D->CR |= (DMA2D_InitStruct->DMA2D_Mode); 31 32 /* Configures the color mode of the output image */ 33 DMA2D->OPFCCR &= ~(uint32_t)DMA2D_OPFCCR_CM; 34 DMA2D->OPFCCR |= (DMA2D_InitStruct->DMA2D_CMode); 35 36 /* Configures the output color */ 37 38 if (DMA2D_InitStruct->DMA2D_CMode == DMA2D_ARGB8888) 39 { 40 outgreen = DMA2D_InitStruct->DMA2D_OutputGreen << 8; 41 outred = DMA2D_InitStruct->DMA2D_OutputRed << 16; 42 outalpha = DMA2D_InitStruct->DMA2D_OutputAlpha << 24; 43 } 44 else 45 46 if (DMA2D_InitStruct->DMA2D_CMode == DMA2D_RGB888) 47 { 48 outgreen = DMA2D_InitStruct->DMA2D_OutputGreen << 8; 49 outred = DMA2D_InitStruct->DMA2D_OutputRed << 16; 50 outalpha = (uint32_t)0x00000000; 51 } 52 53 else 54 55 if (DMA2D_InitStruct->DMA2D_CMode == DMA2D_RGB565) 56 { 57 outgreen = DMA2D_InitStruct->DMA2D_OutputGreen << 5; 58 outred = DMA2D_InitStruct->DMA2D_OutputRed << 11; 59 outalpha = (uint32_t)0x00000000; 60 } 61 62 else 63 64 if (DMA2D_InitStruct->DMA2D_CMode == DMA2D_ARGB1555) 65 { 66 outgreen = DMA2D_InitStruct->DMA2D_OutputGreen << 5; 67 outred = DMA2D_InitStruct->DMA2D_OutputRed << 10; 68 outalpha = DMA2D_InitStruct->DMA2D_OutputAlpha << 15; 69 } 70 71 else /* DMA2D_CMode = DMA2D_ARGB4444 */ 72 { 73 outgreen = DMA2D_InitStruct->DMA2D_OutputGreen << 4; 74 outred = DMA2D_InitStruct->DMA2D_OutputRed << 8; 75 outalpha = DMA2D_InitStruct->DMA2D_OutputAlpha << 12; 76 } 77 DMA2D->OCOLR |= ((outgreen) | (outred) | (DMA2D_InitStruct->DMA2D_OutputBlue) | (outalpha)); 78 79 /* Configures the output memory address */ 80 DMA2D->OMAR = (DMA2D_InitStruct->DMA2D_OutputMemoryAdd); 81 82 /* Configure the line Offset */ 83 DMA2D->OOR &= ~(uint32_t)DMA2D_OOR_LO; 84 DMA2D->OOR |= (DMA2D_InitStruct->DMA2D_OutputOffset); 85 86 /* Configure the number of line and pixel per line */ 87 pixline = DMA2D_InitStruct->DMA2D_PixelPerLine << 16; 88 DMA2D->NLR &= ~(DMA2D_NLR_NL | DMA2D_NLR_PL); 89 DMA2D->NLR |= ((DMA2D_InitStruct->DMA2D_NumberOfLine) | (pixline));
DMA2D_InitStruct.DMA2D_Mode = DMA2D_R2M; // DMA2D->CR
DMA2D_InitStruct.DMA2D_CMode = DMA2D_RGB565; // DMA2D->OPFCCR
DMA2D_InitStruct.DMA2D_OutputGreen = Green_Value; // DMA2D->OCOLR
DMA2D_InitStruct.DMA2D_OutputBlue = Blue_Value; // DMA2D->OCOLR
DMA2D_InitStruct.DMA2D_OutputRed = Red_Value; // DMA2D->OCOLR
DMA2D_InitStruct.DMA2D_OutputAlpha = 0x0F; // DMA2D->OCOLR
DMA2D_InitStruct.DMA2D_OutputMemoryAdd = Xaddress; // DMA2D->OMAR
DMA2D_InitStruct.DMA2D_OutputOffset = 0; // DMA2D->OOR
DMA2D_InitStruct.DMA2D_NumberOfLine = 1; // DMA2D->NLR
DMA2D_InitStruct.DMA2D_PixelPerLine = Length; // DMA2D->NLR
Register to Memory比較簡單,設置模式與輸出color format,而後就是輸出的顏色值,輸出的地址(此例子直接給LCD),輸出的offset已經解釋過
沒有FG(foreground)和 BG(background) 直接輸出image到Memory