Skip to content

Optimise update modes

The different update modes are detailed at the screen library page.

While global update ensures the optimal quality, other modes may provoke ghosting: fast update on the whole screen and especially partial update outside the modified window.

The solution presented below forces the use of a slower update mode to limit ghosting.

Configure

The function below counts the number of refreshes (variable updateFastCount) for the fast update mode.

If the selected mode (parameter mode) is fast update (parameter UPDATE_FAST) and the counter (variable updateFastCount) has not reached the threshold (constant updateFastMax), the function performs a fast update.

Otherwise, it performs a global update.

uint8_t updateFastCount = 0;
const uint8_t updateFastMax = 4;

void flushMode(updateMode_e mode)
{
    if (mode == UPDATE_FAST)
    {
        updateFastCount += 1;
        updateFastCount %= updateFastMax;
    }

    if ((updateFastCount != 0) and (mode == UPDATE_FAST)) 
    {
        myScreen.flushFast();
    }
    else
    {
        myScreen.flush();
    }
}
Legacy version 6

Legacy version 6 features partial update.

The function below counts the number of refreshes (table updateCount[]) for every update mode. When the counter of the selected mode (parameter mode) reaches a threshold (constant table updateMax[]) , the function automatically performs a slower update (with mode - 1).

enum updateMode_e
{
    updateGlobal = 0,
    updateFast,
    updatePartial
};

uint8_t updateCount[3] = { 0 };
const uint8_t updateMax[3] = {4, 4, 4};

void flushMode(updateMode_e mode)
{
    updateCount[mode] += 1;
    updateCount[mode] %= updateMax[mode];

    if ((updateCount[mode] == 0) and (mode > updateGlobal))
    {
        flushMode(mode - 1);
    }
    else
    {
        switch (mode)
        {
            case updatePartial:
                myScreen.flushPartial();
                break;

            case updateFast:
                myScreen.flushFast();
                break;

            default:
                myScreen.flush();
                break;
        }
    }
}

The procedure is non-destructive, as it keeps the frame-buffer unchanged and only modifies the way the panel is updated.

Use

Instead of calling the flush functions of the screen, the main loop calls the flushMode() function previously defined.

myScreen.setFontSolid(true);

for (uint8_t i = 0; i < 36; i++)
{
    myScreen.gText(0, 0, formatString("Loop %3i", i));
    flushMode(updatePartial);
}

Example

// SDK
#include "hV_HAL_Peripherals.h"

// Configuration
#include "hV_Configuration.h"

// Libraries
#include "PDLS_EXT3_Advanced_Fast_Small.h"

// Variables
Screen_EPD_EXT3_Fast myScreen(eScreen_EPD_271_PS_09, boardRaspberryPiPico_RP2040);

// Utilities
enum updateMode_e
{
    updateGlobal,
    updateFast,
    updatePartial
};

uint8_t updateCount[3] = { 0 };
const uint8_t updateMax = 6;

void flushMode(updateMode_e mode)
{
    updateCount[mode] += 1;
    updateCount[mode] %= updateMax;

    if ((updateCount[mode] == 0) and (mode > 0))
    {
        flushMode((updateMode_e)(mode - 1));
    }
    else
    {
        switch (mode)
        {
            case updatePartial:

                myScreen.flushFast();
                break;

            case updateFast:

                myScreen.flushFast();
                break;

            default:

                myScreen.flush();
                break;
        }
    }
}

void setup()
{
    hV_HAL_begin();

    myScreen.begin();
    myScreen.setOrientation(ORIENTATION_LANDSCAPE);

    myScreen.setFontSolid(true);

    for (uint8_t i = 0; i < 36; i++)
    {
        myScreen.beginPartial();
        myScreen.gText(0, 0, formatString("Loop %3i", i));
        flushMode(updatePartial);
    }

    hV_HAL_end();
}

void loop()
{
    hV_HAL_delayMilliseconds(1000);
}