图像处理的专门DMA
看一段示例代码
/**
* @brief Displays a line.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Length: line length.
* @param Direction: line direction.
* This parameter can be one of the following values: Vertical or Horizontal.
* @retval None
*/
void LCD_DrawLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length, uint8_t Direction)
{
DMA2D_InitTypeDef DMA2D_InitStruct;
uint32_t Xaddress = ;
uint16_t Red_Value = , Green_Value = , Blue_Value = ;
Xaddress = CurrentFrameBuffer + *(LCD_PIXEL_WIDTH*Ypos + Xpos);
Red_Value = (0xF800 & CurrentTextColor) >> ;
Blue_Value = 0x001F & CurrentTextColor;
Green_Value = (0x07E0 & CurrentTextColor) >> ;
/* 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 = ;
DMA2D_InitStruct.DMA2D_NumberOfLine = ;
DMA2D_InitStruct.DMA2D_PixelPerLine = Length;
}
else
{
DMA2D_InitStruct.DMA2D_OutputOffset = LCD_PIXEL_WIDTH - ;
DMA2D_InitStruct.DMA2D_NumberOfLine = Length;
DMA2D_InitStruct.DMA2D_PixelPerLine = ;
}
DMA2D_Init(&DMA2D_InitStruct);
/* Start Transfer */
DMA2D_StartTransfer();
/* Wait for CTC Flag activation */
while(DMA2D_GetFlagStatus(DMA2D_FLAG_TC) == RESET)
{
}
}
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
发现不同MODE有很多不同理解故深化一下看看初始化函数内部操作的哪些寄存器进一步理解
/**
* @brief Initializes the DMA2D peripheral according to the specified parameters
* in the DMA2D_InitStruct.
* @note This function can be used only when the DMA2D is disabled.
* @param DMA2D_InitStruct: pointer to a DMA2D_InitTypeDef structure that contains
* the configuration information for the specified DMA2D peripheral.
* @retval None
*/
void DMA2D_Init(DMA2D_InitTypeDef* DMA2D_InitStruct)
{
uint32_t outgreen = ;
uint32_t outred = ;
uint32_t outalpha = ;
uint32_t pixline = ;
/* Check the parameters */
assert_param(IS_DMA2D_MODE(DMA2D_InitStruct->DMA2D_Mode));
assert_param(IS_DMA2D_CMODE(DMA2D_InitStruct->DMA2D_CMode));
assert_param(IS_DMA2D_OGREEN(DMA2D_InitStruct->DMA2D_OutputGreen));
assert_param(IS_DMA2D_ORED(DMA2D_InitStruct->DMA2D_OutputRed));
assert_param(IS_DMA2D_OBLUE(DMA2D_InitStruct->DMA2D_OutputBlue));
assert_param(IS_DMA2D_OALPHA(DMA2D_InitStruct->DMA2D_OutputAlpha));
assert_param(IS_DMA2D_OUTPUT_OFFSET(DMA2D_InitStruct->DMA2D_OutputOffset));
assert_param(IS_DMA2D_LINE(DMA2D_InitStruct->DMA2D_NumberOfLine));
assert_param(IS_DMA2D_PIXEL(DMA2D_InitStruct->DMA2D_PixelPerLine));
/* Configures the DMA2D operation mode */
DMA2D->CR &= (uint32_t)CR_MASK;
DMA2D->CR |= (DMA2D_InitStruct->DMA2D_Mode);
/* Configures the color mode of the output image */
DMA2D->OPFCCR &= ~(uint32_t)DMA2D_OPFCCR_CM;
DMA2D->OPFCCR |= (DMA2D_InitStruct->DMA2D_CMode);
/* Configures the output color */
if (DMA2D_InitStruct->DMA2D_CMode == DMA2D_ARGB8888)
{
outgreen = DMA2D_InitStruct->DMA2D_OutputGreen << ;
outred = DMA2D_InitStruct->DMA2D_OutputRed << ;
outalpha = DMA2D_InitStruct->DMA2D_OutputAlpha << ;
}
else
if (DMA2D\_InitStruct->DMA2D\_CMode == DMA2D\_RGB888)
{
outgreen = DMA2D\_InitStruct->DMA2D\_OutputGreen << ;
outred = DMA2D\_InitStruct->DMA2D\_OutputRed << ;
outalpha = (uint32\_t)0x00000000;
}
else
if (DMA2D\_InitStruct->DMA2D\_CMode == DMA2D\_RGB565)
{
outgreen = DMA2D\_InitStruct->DMA2D\_OutputGreen << ;
outred = DMA2D\_InitStruct->DMA2D\_OutputRed << ;
outalpha = (uint32\_t)0x00000000;
}
else
if (DMA2D\_InitStruct->DMA2D\_CMode == DMA2D\_ARGB1555)
{
outgreen = DMA2D\_InitStruct->DMA2D\_OutputGreen << ;
outred = DMA2D\_InitStruct->DMA2D\_OutputRed << ;
outalpha = DMA2D\_InitStruct->DMA2D\_OutputAlpha << ;
}
else /* DMA2D_CMode = DMA2D_ARGB4444 */
{
outgreen = DMA2D_InitStruct->DMA2D_OutputGreen << ;
outred = DMA2D_InitStruct->DMA2D_OutputRed << ;
outalpha = DMA2D_InitStruct->DMA2D_OutputAlpha << ;
}
DMA2D->OCOLR |= ((outgreen) | (outred) | (DMA2D_InitStruct->DMA2D_OutputBlue) | (outalpha));
/* Configures the output memory address */
DMA2D->OMAR = (DMA2D_InitStruct->DMA2D_OutputMemoryAdd);
/* Configure the line Offset */
DMA2D->OOR &= ~(uint32_t)DMA2D_OOR_LO;
DMA2D->OOR |= (DMA2D_InitStruct->DMA2D_OutputOffset);
/* Configure the number of line and pixel per line */
pixline = DMA2D_InitStruct->DMA2D_PixelPerLine << ;
DMA2D->NLR &= ~(DMA2D_NLR_NL | DMA2D_NLR_PL);
DMA2D->NLR |= ((DMA2D_InitStruct->DMA2D_NumberOfLine) | (pixline));
DMA2D_Init
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
手机扫一扫
移动阅读更方便
你可能感兴趣的文章