2
\$\begingroup\$

I'm trying to draw a bitmap using 2D DMA, so I have the address of the destination which is the front buffer, and then I read a line from the bitmap, blit it using the 2D DMA.. I get scanlines, and garbage image. Not sure where is the problem

void BSP_LCD_DrawBitmap(uint16_t layer,uint32_t X, uint32_t Y, const uint16_t *pBmp)
{
  uint32_t index = 0, width = 0, height = 0, bitpixel = 0;

  /* Get bitmap data address offset */
  index = 0;

  /* Read bitmap width */
  width = 240;

  /* Read bitmap height */
  height = 320;

    uint16_t address = LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress ;

    for (int i = 0 ; i < height ; i++)
    {
       ConvertLineToRGB565( (uint16_t *)pBmp, (uint16_t *) address ,  width , CM_RGB565) ;
         address += (width*2) ;
         pBmp += (width*2) ;
    }   
}


static void ConvertLineToRGB565(void * pSrc, void * pDst, uint32_t xSize, uint32_t ColorMode)
{    
  /* Configure the DMA2D Mode, Color Mode and output offset */
  Dma2dHandler.Init.Mode         = DMA2D_M2M_PFC;
  Dma2dHandler.Init.ColorMode    = DMA2D_RGB565;
  Dma2dHandler.Init.OutputOffset = 0;     

  /* Foreground Configuration */
  Dma2dHandler.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
  Dma2dHandler.LayerCfg[1].InputAlpha = 0xFF;
  Dma2dHandler.LayerCfg[1].InputColorMode = ColorMode;
  Dma2dHandler.LayerCfg[1].InputOffset = 0;

  Dma2dHandler.Instance = DMA2D; 

  /* DMA2D Initialization */
  if(HAL_DMA2D_Init(&Dma2dHandler) == HAL_OK) 
  {
    if(HAL_DMA2D_ConfigLayer(&Dma2dHandler, 1) == HAL_OK) 
    {
      if (HAL_DMA2D_Start(&Dma2dHandler, (uint16_t)pSrc, (uint16_t)pDst, xSize, 1) == HAL_OK)
      {
        /* Polling For DMA transfer */  
        HAL_DMA2D_PollForTransfer(&Dma2dHandler, 10);
      }
    }
  } 
}
\$\endgroup\$
  • \$\begingroup\$ Does it work if you do it without DMA? \$\endgroup\$ – Jon Jun 8 '18 at 17:32
  • \$\begingroup\$ How it should work with only looping through the height only ? I can do a nested loop with draw pixel and it works.. \$\endgroup\$ – Ahmed Saleh Jun 8 '18 at 17:37
0
\$\begingroup\$

I have figured it out. In case someone wants to do it

void BSP_LCD_DrawBitmap(uint16_t layer,uint32_t X, uint32_t Y, uint8_t *pBmp)
{

  uint32_t index = 0, width = 0, height = 0, bitpixel = 0;
  uint32_t address;
  uint32_t inputcolormode = 0;

  /* Get bitmap data address offset */
  index = 0;
  /* Read bitmap width */
  width = 240;

  /* Read bitmap height */
  height = 340;;

  /* Read bit/pixel */
  bitpixel = 2;

  /* Set Address */
  address = LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Y) + X)*(2));

    inputcolormode = CM_RGB565;

  /* bypass the bitmap header */
  pBmp += width*2;
   for(index=0; index < height; index++)
  {
  /* Pixel format conversion */
  ConvertLineToRGB565((uint32_t *)pBmp, (uint32_t *)address, width, inputcolormode);

  /* Increment the source and destination buffers */
  address+=  ((BSP_LCD_GetXSize())*2);
  pBmp += width*2;
  }
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.