Jump to content

Double buffering scheme


Rafael Zingler

Recommended Posts

Hi,

I'm currently using the frame buffer driver in a project with the LPC1788 microcontroller (which has an embedded LCD controller). I've implemented double buffering in the system, to eliminate the undesirable tear effect that appeared on the screen every time the driver put new content in the buffer. Thus, when the driver is pointing to buffer A, buffer B is being shown on the screen, and vice-versa. The operating system (enabled in gfxconf.h) I'm using is FreeRTOS.

Another important thing was the need of a "policy" to decide when system must switch the buffers. For this, the option  GDISP_NEED_AUTOFLUSH was set in the gfxconf.h file. In this way, I've implemented the board_flush() function, which starts a software timer. Thus, a little time after driver finishes writing,  the timer callback function is called, and in the callback function the buffer switching is made (along with the data copy from the front to the back buffer). Basically, the idea is a "driver writing timeout", which makes the callback function be called, and inside it, the buffer switching.

The problem I'm facing now is related to the moment on which the driver writes new data after finishing the last writing. If my callback function is still copying data from one buffer to the other and the driver writes new data, there is a data corruption in the "back buffer". I would like to know if anyone has an idea of how to solve this, or had been facing this same situation.

 

Thanks in advance!!

Link to comment
Share on other sites

Your method of setting a timer is already an implemented option in ugfx. Check the flush options. You just need to implement the board_flush and set the option. Ugfx will then call your flush routine when and if needed.

There are 2 ways to prevent corruption (after sing he inbuilt timer flush)...

1. Make the copy back a synchronous part of the flush routine, or

2. Start the copy back in the flush with a muted lock that is released when the copy back completes. Te driver pixel draw routine then needs to have a test to see if copy back is complete and if not wait until it is.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...