请教下 ,使用dma2d的透明功能改如何设置 ?
配置函数如下
static void BMP_DMA2D_ConverBuffer(uint32_t *pSrc, uint32_t *pDst,
uint16_t _usX, uint16_t _usY,
uint16_t _usWidth, uint16_t _usHeight,
uint32_t InputColorMode, uint32_t OutputColorMode)
{
uint32_t source ;
uint32_t destination = 0;
uint16_t OutputOffset = 0; // 行偏移
uint16_t NumberOfLine = 0; // 行数,表示我们显示的数据需要的行数
uint16_t PixelPerLine = 0; // 每行像素数, 每行需要显示多少个像素点
__IO uint32_t XaddrPutPixel = 0;
source = (uint32_t)pSrc;
destination = (uint32_t)pDst;
XaddrPutPixel = (BYTES_PER_PIXEL * (uint32_t)((_usY * LCD_PIXEL_WIDTH) + (_usX)));
OutputOffset = LCD_PIXEL_WIDTH - _usWidth;
NumberOfLine = _usHeight ;
PixelPerLine = _usWidth ;
__HAL_RCC_DMA2D_FORCE_RESET(); // 强制复位
__HAL_RCC_DMA2D_RELEASE_RESET(); // 释放复位
DMA2D->CR &= ~DMA2D_CR_START; // 停止dma2d
DMA2D_Handle.Init.Mode = DMA2D_M2M_PFC;
DMA2D_Handle.Init.OutputOffset = OutputOffset; //OutputOffset;
DMA2D_Handle.Init.AlphaInverted = DMA2D_REGULAR_ALPHA; // No Output Alpha Inversion
DMA2D_Handle.LayerCfg[1].AlphaMode = DMA2D_REPLACE_ALPHA;
DMA2D_Handle.LayerCfg[1].InputAlpha = 0xFF;
DMA2D_Handle.Init.RedBlueSwap = DMA2D_RB_REGULAR;
DMA2D_Handle.XferCpltCallback = NULL;
DMA2D_Handle.LayerCfg[1].InputColorMode = InputColorMode; // 输入颜色模式
DMA2D_Handle.Init.ColorMode = OutputColorMode; // 输出颜色模式
DMA2D_Handle.LayerCfg[1].InputOffset = 0;
DMA2D_Handle.LayerCfg[1].RedBlueSwap = DMA2D_RB_REGULAR; /* No ForeGround Red a Blue swap */
DMA2D_Handle.LayerCfg[1].AlphaInverted = DMA2D_REGULAR_ALPHA; /* No ForeGround Alpha inversion */
DMA2D_Handle.Instance = DMA2D;
if(HAL_DMA2D_Init(&DMA2D_Handle) == HAL_OK)
{
if(HAL_DMA2D_ConfigLayer(&DMA2D_Handle, 1) == HAL_OK)
{
uint32_t timeout = 0;
if (HAL_DMA2D_Start(&DMA2D_Handle, source, destination + XaddrPutPixel, PixelPerLine, NumberOfLine ) == HAL_OK)
{
while((DMA2D->ISR & (DMA2D_FLAG_TC)) == 0) //等待传输完成
{
timeout++;
if(timeout > 0X1FFFFF) break; //超时退出
}
__HAL_DMA2D_CLEAR_FLAG(&DMA2D_Handle, DMA2D_FLAG_TC | DMA2D_FLAG_CTC);
DMA2D_Handle.State = HAL_DMA2D_STATE_READY;
__HAL_UNLOCK(&DMA2D_Handle);
}
}
}
} |