Showing results for 
Search instead for 
Did you mean: 

TouchGFX custom widget with partial framebuffer - how to?

Associate II

I am developing a TouchGFX-based firmware and have a trouble with my custom widget when I try to use partial framebuffer strategy.

Currently I am using TouchGFX 4.13 on STM32H743 MCU with LTDC.

The code of my custom widget class is based on this "QRCode widget" example from TouchGFX documentation:

touchgfx::Rect absolute = getAbsoluteRect();
uint16_t* framebuffer = touchgfx::HAL::getInstance()->lockFrameBuffer();
for (int y = invalidatedArea.y; y < invalidatedArea.bottom(); y++)
	for (int x = invalidatedArea.x; x < invalidatedArea.right(); x++)
		framebuffer[absolute.x + x + (absolute.y + y) * touchgfx::HAL::DISPLAY_WIDTH]
		data->at(x / scale, y / scale) ? 0x0000 : 0xffff;

When I use single or double framebuffer everything works fine.

When I use partial framebuffer without custom widgets everything works fine.

But where I use partial framebuffer with custom widget it is unclear how to determine in draw() method

a) where is current partial framebuffer located in RAM, and

b) which region of screen does it contain.

The lockFrameBuffer() method returns seeming random addressess, sometimes not in RAM section (0x1fff....).

And I did not found in documentation, how to determine the coordinates of the rectangle that is mapped to partial framebuffer.

Is there any working example of using TouchGFX with partial framebuffer and custom widgets?

ST Employee

Hello @hdmi87​ ,

Your equation for determining the position of the your widget in the partial framebuffer isn't completely correct.

Because this framebuffer doesn't have the same dimensions as your display, you should use touchgfx::HAL::FRAME_BUFFER_WIDTH instead of touchgfx::HAL::DISPLAY_WIDTH.

Then, you should be able to locate your widget inside the framebuffer.

To find where the partial framebuffer is located in the RAM, you could check the TouchGFXGeneratedHAL.cpp file, and more especially the line :

// Block Allocator for Partial Framebuffer strategy
static ManyBlockAllocator<1920, /* block size */
                   3, /* number of blocks */
                   2  /* bytes per pixel */
                   > blockAllocator;

That points the class FrameBufferAllocator.cpp, located at Middlewares\ST\touchgfx\framework\include\touchgfx\hal.

There you will find all the details about how and where the memory is allocated.

Unfortunately, there is no example or documentation about using custom widgets and partial framebuffer for the moment, we will work on it.

Hope that this helped,


ST Software Developer | TouchGFX