display() code cleanup

This commit is contained in:
Manuel
2025-11-01 11:52:09 +01:00
parent 145d2df9b9
commit 7ec233e2e5

View File

@@ -189,8 +189,6 @@ void EInkParallelDisplay::asyncFullUpdateTask(void *pvParameters)
*/ */
void EInkParallelDisplay::display(void) void EInkParallelDisplay::display(void)
{ {
LOG_DEBUG("EInkParallelDisplay::display");
const uint16_t w = this->displayWidth; const uint16_t w = this->displayWidth;
const uint16_t h = this->displayHeight; const uint16_t h = this->displayHeight;
@@ -225,7 +223,7 @@ void EInkParallelDisplay::display(void)
imageHash ^= ((uint32_t)buffer[bi]) << (bi & 31); imageHash ^= ((uint32_t)buffer[bi]) << (bi & 31);
} }
if (imageHash == previousImageHash) { if (imageHash == previousImageHash) {
LOG_DEBUG("image identical to previous, skipping update"); // LOG_DEBUG("image identical to previous, skipping update");
return; return;
} }
@@ -320,37 +318,25 @@ void EInkParallelDisplay::display(void)
#ifdef EINK_LIMIT_GHOSTING_PX #ifdef EINK_LIMIT_GHOSTING_PX
// If ghost pixels exceed limit, force a full update to clear ghosting // If ghost pixels exceed limit, force a full update to clear ghosting
if (ghostPixelCount > ghostPixelLimit) { if (ghostPixelCount > ghostPixelLimit) {
LOG_WARN("ghost pixels %u > limit %u, forcing full refresh", ghostPixelCount, ghostPixelLimit); LOG_DEBUG("ghost pixels %u > limit %u, forcing full refresh", ghostPixelCount, ghostPixelLimit);
forceFull = true; forceFull = true;
} }
#endif #endif
// page-based partial update (pages = rows / 8) // Compute page-aligned pixel bounds from newTop/newBottom (pages are 8 pixel rows)
int topPage = newTop / 8; int startRow = (newTop / 8) * 8;
int bottomPage = newBottom / 8; int endRow = (newBottom / 8) * 8 + 7;
if (topPage < 0) if (startRow < 0)
topPage = 0; startRow = 0;
// clamp bottomPage to valid range if (endRow > (int)h - 1)
int maxPage = ((int)h + 7) / 8 - 1; endRow = (int)h - 1;
if (bottomPage < topPage)
bottomPage = topPage; LOG_DEBUG("EPD update rows=%d..%d alignedRows=%d..%d rowBytes=%u", newTop, newBottom, startRow, endRow, rowBytes);
if (bottomPage > maxPage)
bottomPage = maxPage;
LOG_DEBUG("EPD update rows=%d..%d pages=%d..%d rowBytes=%u", newTop, newBottom, topPage, bottomPage, rowBytes);
if (epaper->getMode() == BB_MODE_1BPP && !forceFull && (newBottom - newTop) <= EPD_PARTIAL_THRESHOLD_ROWS) { if (epaper->getMode() == BB_MODE_1BPP && !forceFull && (newBottom - newTop) <= EPD_PARTIAL_THRESHOLD_ROWS) {
// Prefer partial update path if driver is reliable; otherwise use clipped fullUpdate fallback.
// If we couldn't detect column changes, fall back to page-based pixel bounds
int startRow = topPage * 8;
int endRow = bottomPage * 8 + 7;
if (endRow > (int)h - 1)
endRow = (int)h - 1;
#ifdef FAST_EPD_PARTIAL_UPDATE_BUG #ifdef FAST_EPD_PARTIAL_UPDATE_BUG
// Workaround for FastEPD partial update bug: use clipped fullUpdate instead // LOG_DEBUG("Using clipped fullUpdate workaround for partial update bug");
// Build a pixel rectangle for a clipped fullUpdate using the changed columns
LOG_DEBUG("Using clipped fullUpdate workaround for partial update bug");
int startCol = (newLeftByte <= newRightByte) ? (newLeftByte * 8) : 0; int startCol = (newLeftByte <= newRightByte) ? (newLeftByte * 8) : 0;
int endCol = (newLeftByte <= newRightByte) ? ((newRightByte + 1) * 8 - 1) : (w - 1); int endCol = (newLeftByte <= newRightByte) ? ((newRightByte + 1) * 8 - 1) : (w - 1);
if (startCol < 0) if (startCol < 0)
@@ -358,21 +344,15 @@ void EInkParallelDisplay::display(void)
if (endCol >= (int)w) if (endCol >= (int)w)
endCol = (int)w - 1; endCol = (int)w - 1;
BB_RECT rect; BB_RECT rect{startCol, startRow, endCol - startCol + 1, endRow - startRow + 1};
rect.x = startCol; // LOG_DEBUG("Using clipped fullUpdate rect x=%d y=%d w=%d h=%d", rect.x, rect.y, rect.w, rect.h);
rect.y = startRow;
rect.w = endCol - startCol + 1;
rect.h = endRow - startRow + 1;
LOG_DEBUG("Using clipped fullUpdate rect x=%d y=%d w=%d h=%d", rect.x, rect.y, rect.w, rect.h);
// Use fullUpdate with rect (reliable path) instead of FASTEPD partialUpdate(), then synchronize
{ {
concurrency::LockGuard g(spiLock); concurrency::LockGuard g(spiLock);
// alternate CLEAR_FAST / CLEAR_SLOW handled elsewhere by fastRefreshCount logic
epaper->fullUpdate(CLEAR_FAST, false, &rect); epaper->fullUpdate(CLEAR_FAST, false, &rect);
} }
#else #else
// Use rows for partial update // LOG_DEBUG("calling partialUpdate startRow=%d endRow=%d", startRow, endRow);
LOG_DEBUG("calling partialUpdate startRow=%d endRow=%d", startRow, endRow);
{ {
concurrency::LockGuard g(spiLock); concurrency::LockGuard g(spiLock);
epaper->partialUpdate(true, startRow, endRow); epaper->partialUpdate(true, startRow, endRow);