stm32h750 用DMA2D对YCBCR转RGB

stm32h750 用DMA2D对YCBCR转RGB

H750 的DMA2D对YCBCR转RGB 接收的是8x8色块的数据输入
并不是一行一行的YCBCR输入 新手肯定会遇到这个问题
因为H750是针对解码JPEG开发的YCBCR转RGB 这一点很坑


/*

    函 数 名: DMA2D_Copy_YCbCr_To_RGB
    功能说明: YCbCr转RGB输出
    形 参: pSrc: 数据源地址
    pDst: 数据目的地址
    x: X轴首地址
    y: Y轴首地址
    xsize: 目的区域的X轴大小,即每行像素数
    ysize: 目的区域的Y轴大小,即行数
    PixelFormat: 目标区颜色格式
    ChromaSampling : YCbCr Chroma sampling : 4:2:0, 4:2:2 or 4:4:4
    返 回 值: 无
    //注意g_LcdWidth是显示屏的宽度
    */
    void DMA2D_Copy_YCbCr_To_RGB_v(uint32_t pSrc,uint32_t *pDst,
    uint16_t x, uint16_t y,uint16_t xsize, uint16_t ysize,
    uint32_t PixelFormat, uint32_t ChromaSampling)
    {
    uint32_t cssMode = DMA2D_CSS_420;
    uint32_t inputLineOffset = 0;
    uint32_t destination = 0;


    if(ChromaSampling == JPEG_420_SUBSAMPLING)
    {
            cssMode = DMA2D_CSS_420;

            inputLineOffset = xsize % 16;
            if(inputLineOffset != 0)
            {
                    inputLineOffset = 16 - inputLineOffset;
            }   
    }
    else if(ChromaSampling == JPEG_444_SUBSAMPLING)
    {
            cssMode = DMA2D_NO_CSS;

            inputLineOffset = xsize % 8;
            if(inputLineOffset != 0)
            {
                    inputLineOffset = 8 - inputLineOffset;
            }   
    }
    else if(ChromaSampling == JPEG_422_SUBSAMPLING)
    {
            cssMode = DMA2D_CSS_422;

            inputLineOffset = xsize % 16;
            if(inputLineOffset != 0)
            {
                    inputLineOffset = 16 - inputLineOffset;
            }      
    }  

    // 输出地址,乘以2的对RGB565,如果输出格式是ARGB8888,需要乘以4 
    destination = (uint32_t)pDst + ((y * g_LcdWidth) + x) * 2;

    DMA2D->CR      = 0x00010000UL | (1 << 9);
    DMA2D->OOR     = g_LcdWidth - xsize;


    DMA2D->OPFCCR  = PixelFormat
                     | (DMA2D_REGULAR_ALPHA << 20)
                     | (DMA2D_RB_REGULAR << 21);  

     
    DMA2D->FGPFCCR = DMA2D_INPUT_YCBCR
                     | (DMA2D_REPLACE_ALPHA << 16)
                     | (DMA2D_REGULAR_ALPHA << 20)
                     | (DMA2D_RB_REGULAR << 21)   
                     | (0xFFU << 24)              
                     | (cssMode << 18);               

    DMA2D->FGOR    = inputLineOffset;
    DMA2D->NLR     = (uint32_t)(xsize << 16) | (uint16_t)ysize;      
    DMA2D->OMAR    = (uint32_t)destination;
    DMA2D->FGMAR   = (uint32_t)pSrc;  


    DMA2D->CR   |= DMA2D_CR_START;   


    while (DMA2D->CR & DMA2D_CR_START) {}

    }

你可能感兴趣的:(技术分享)