From e232e3462c58bd67711a1706351f3d5a4adb61d6 Mon Sep 17 00:00:00 2001 From: Todd Herbert Date: Sun, 10 Mar 2024 03:48:59 +1300 Subject: [PATCH] add BLOCKING modifier to frameFlagTypes --- src/graphics/EInkDynamicDisplay.cpp | 21 +++++++++++++++++++-- src/graphics/EInkDynamicDisplay.h | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/graphics/EInkDynamicDisplay.cpp b/src/graphics/EInkDynamicDisplay.cpp index 8ff8dc4af..2b3659099 100644 --- a/src/graphics/EInkDynamicDisplay.cpp +++ b/src/graphics/EInkDynamicDisplay.cpp @@ -458,15 +458,32 @@ void EInkDynamicDisplay::checkAsyncFullRefresh() // Figure out who runs the post-update code void EInkDynamicDisplay::endOrDetach() { - if (previousRefresh == FULL) { // Note: previousRefresh is the refresh from this loop. + if (refresh == FULL) { asyncRefreshRunning = true; // Set the flag - picked up at start of determineMode(), next loop. - LOG_DEBUG("Async full-refresh begins\n"); + + if (frameFlags & BLOCKING) + awaitRefresh(); + else + LOG_DEBUG("Async full-refresh begins\n"); } // Fast Refresh else EInkDisplay::endUpdate(); // Still block while updating, but EInkDisplay needs us to call endUpdate() ourselves. } + +// Hold control while an async refresh runs +void EInkDynamicDisplay::awaitRefresh() +{ + // Continually poll the BUSY pin + while (adafruitDisplay->epd2.isBusy()) + yield(); + + // End the full-refresh process + adafruitDisplay->endAsyncFull(); // Run the end of nextPage() code + EInkDisplay::endUpdate(); // Run base-class code to finish off update (NOT our derived class override) + asyncRefreshRunning = false; // Unset the flag +} #endif // HAS_EINK_ASYNCFULL #endif // USE_EINK_DYNAMICDISPLAY \ No newline at end of file diff --git a/src/graphics/EInkDynamicDisplay.h b/src/graphics/EInkDynamicDisplay.h index 48540a132..ed5be70cd 100644 --- a/src/graphics/EInkDynamicDisplay.h +++ b/src/graphics/EInkDynamicDisplay.h @@ -28,6 +28,7 @@ class EInkDynamicDisplay : public EInkDisplay RESPONSIVE = (1 << 1), // For frames via forceDisplay() COSMETIC = (1 << 2), // For splashes DEMAND_FAST = (1 << 3), // Special case only + BLOCKING = (1 << 4), // Modifier - block while refresh runs }; void addFrameFlag(frameFlagTypes flag); @@ -112,6 +113,7 @@ class EInkDynamicDisplay : public EInkDisplay #if defined(HAS_EINK_ASYNCFULL) void checkAsyncFullRefresh(); // Check the status of "async full-refresh"; run the post-update code if the hardware is ready void endOrDetach(); // Run the post-update code, or delegate it off to checkAsyncFullRefresh() + void awaitRefresh(); // Hold control while an async refresh runs void endUpdate() override {} // Disable base-class behavior of running post-update immediately after forceDisplay() bool asyncRefreshRunning = false; // Flag, checked by checkAsyncFullRefresh() #endif