Everything You Should Know About HyperDisplay

Pages
Contributors: Liquid Soulder
Favorited Favorite 5

Buffering

Memory is a touchy subject on microcontrollers and embedded systems. Particularly on the ever-popular AtMega 328p you need to conserve every byte of memory that you can and for that reason HyperDisplay defaults to running in an unbuffered mode (except in some cases where the display hardware demands a buffer). However, operating this way means that you have to watch the drawing operations take place in real time. To avoid this, and also enable other cool features such as (possibly) layer transparency we need to keep record of what is on the screen. This is where the buffered drawing mode comes into play.

Fortunately, running in buffered mode is really easy! All you need to do is allocate memory for your buffer (big enough to hold all the pixels), tell your buffered window where to find that memory, and switch it into buffered mode. Once in buffered mode drawing functions won't appear on the screen until 'show()' is called. In the meantime the data will be rerouted to the buffer you provided. Here's how that process might look in code:

language:c
hwColor_t smallWindowMem[32*64];    // Reserve 32*64 pixels worth of memory

wind_info_t smallWindow;            // Create a window
smallWindow.xMin = 16;              // Set the paramters to match the buffer size
smallWindow.yMin = 72;      
smallWindow.xMax = 16 + 31;         // See, 16+0 would be one pixel, so 16+31 is actually 32 pixels wide
smallWindow.yMax = 72 + 63;         // and this means 64 pixels tall.. so now our small window can be filled with 32*64 pixels


myDisplay.setWindowMemory(&smallWindow, (color_t)smallWindowMem, 32*64);    // Make sure that the window knows about the memory
myDisplay.pCurrentWindow = &smallWindow;    // Switch curent window to small window
myDisplay.buffer();                         // Set the current window to buffer mode
myDisplay.line(0,0, 55,45);                 // Draw a line over the window
...                                         // Continue drawing
myDisplay.show();                           // Show all the changes at conc

Buffered Drawing Output from TFT Examples

Alright, you've nearly made it to the summit of HyperDisplay! One more section to go and you'll be a true master!