STM32F429I-Discovery & BSP: problem with LCD and transparency
Hi,
I'm struggling with the BSP LCD functions. The goal is to display an image which has transparent background. I'm working on STM32F429I-Discovery board, using BSP LCD drivers.
Since the BSP_LCD_DrawBitmap() function seems to expect a real BMP file, which doesn't contain alpha channel information, I want to create my own function for drawing the picture.
Currently I'm only displaying a text to verify that the LCD functions are working in general which seems to be fine.
For the transparency check, I made a small test loop. Here, a vertical line is displayed pixel by pixel with black color and the alpha channel is incremented for each pixel:
for(int y = 0; y < 256; y++)
BSP_LCD_DrawPixel(10, y, y << 24);Now, what I expect is that the line will be transparent at the beginning and becoming opaque at the end. But it is drawn fully opaque. I don't know what I'm doing wrong.
My main code (without the above mentioned loop):
/* Initialize the LCD Layers */
BSP_LCD_LayerDefaultInit(0, LCD_FRAME_BUFFER);
BSP_LCD_LayerDefaultInit(1, LCD_FRAME_BUFFER + BUFFER_OFFSET);
//TEST
BSP_LCD_SelectLayer(0);
BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
/* Clear the LCD */
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
BSP_LCD_Clear(LCD_COLOR_BLUE);
/* Set the LCD Text Color */
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
/* Display LCD messages */
BSP_LCD_DisplayStringAt(0, 10, (uint8_t*)"Welcome", CENTER_MODE);This works, the text is displayed on blue background with white color.
Here's my setup for the LTDC layers:
pLayerCfg.WindowX0 = 0;
pLayerCfg.WindowX1 = 239;
pLayerCfg.WindowY0 = 0;
pLayerCfg.WindowY1 = 319;
pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
pLayerCfg.Alpha = 255;
pLayerCfg.Alpha0 = 0;
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
pLayerCfg.FBStartAdress = 0xD0000000;
pLayerCfg.ImageWidth = 240;
pLayerCfg.ImageHeight = 320;
pLayerCfg.Backcolor.Blue = 0;
pLayerCfg.Backcolor.Green = 0;
pLayerCfg.Backcolor.Red = 0;
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
{
Error_Handler();
}
pLayerCfg1.WindowX0 = 0;
pLayerCfg1.WindowX1 = 239;
pLayerCfg1.WindowY0 = 0;
pLayerCfg1.WindowY1 = 319;
pLayerCfg1.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
pLayerCfg1.Alpha = 255;
pLayerCfg1.Alpha0 = 0;
pLayerCfg1.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
pLayerCfg1.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
pLayerCfg1.FBStartAdress = 0xD0050000;
pLayerCfg1.ImageWidth = 240;
pLayerCfg1.ImageHeight = 320;
pLayerCfg1.Backcolor.Blue = 0;
pLayerCfg1.Backcolor.Green = 0;
pLayerCfg1.Backcolor.Red = 0;
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg1, 1) != HAL_OK)
{
Error_Handler();
}And the DMA2D setup:
hdma2d.Instance = DMA2D;
hdma2d.Init.Mode = DMA2D_M2M;
hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
hdma2d.Init.OutputOffset = 0;
hdma2d.LayerCfg[1].InputOffset = 0;
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
hdma2d.LayerCfg[1].InputAlpha = 0;From what I can see in the BSP LCD drivers, the DMA2D is dynamically configured at run-time.
I played around with the alpha values for the layers as well as inserting a call to BSP_LCD_SetTransparency() function with different values before drawing the line. But it affected either the whole layer (obviously) or nothing.
So, here are my questions:
1) Is my layer setup correct?
2) do I have to setup something else to enable alpha channel handling?
3) do I have to draw the line/image on layer 2 (with different setup)?
4) not directly related to the problem: which graphic solution would you recommend, e.g. EmWin, TouchGFX, etc.
Regards
