Best refresh strategy with external display controller

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Best refresh strategy with external display controller

    I'm using a TFT display with integrated ILI9341 controller. The connection between MCU and TFT is 16-bits parallel.

    I'm confused about the best strategy to refresh the display when some parts change.

    Suppose I have a black background with one image at the center. Every 1 second, a variable is checked and depending on its value the image at the center changes accordingly. The variable is updated in another task.

    I can use the background window and call GUI_DrawBitmap() in WM_PAINT message. Every 1 second, I call WM_Invalidate() to force the refresh (maybe in a WM_TIMER message).
    This works, but I suspect the GUI library is forced to redraw (i.e., re-write) every pixel of the display, not only the pixels of the image that could change. If the display is big and the image small, this approach wastes a lot of time.

    So what is a better approach? I'm thinking to create an IMAGE widget in WM_CREATE and change the image with IMAGE_SetBitmap() directly in WM_TIMER (raised every second) and not in WM_PAINT.

    I can't use a data cache, because I don't have so much memory space.
  • "I would recommend you to invalidate just the rectangle which might change according to the variable. Also I would recommend to invalidate the rectangle only if the variable changed."

    Suppose I have an image in the rect (0,0)-(10,10). The image depends on the value of variable names status.

    Source Code

    1. enum {IMAGE_A, IMAGE_B} status, old_status;
    2. ...
    3. GUI_RECT r;r.x0 = 0; rx.y0 = 0; r.x1 = 10; r.y1 = 10;
    4. if (old_status != status) {
    5. WM_InvalidateRect(hWin, &r);
    6. old_status = status;
    7. }


    Now, in the WM_PAINT event, what should I write? Should I have to redraw the entire window or only the image in the rect (0,0)-(10,10)?
    In the first case, will the GUI library avoid the real redraw of the full window and changes only the invalid rectangle?
    In the second case, how could I understand in WM_PAINT event which part of the window to redraw?

    The post was edited 1 time, last by giusloq ().

  • Hello,

    Now, in the WM_PAINT event, what should I write? Should I have to redraw the entire window or only the image in the rect (0,0)-(10,10)?
    In the first case, will the GUI library avoid the real redraw of the full window and changes only the invalid rectangle?


    Yes, exactly. You do not have to change anything in the paint event.

    Best regards,
    Adrian