Skip to content

Commit 1e22445

Browse files
committed
Fix TFTDisplay partial update: align spans to 32-bit boundary for GDMA
The device, such as esp32c6, require 32-bit alignment for the data. The patch aligns start and end of the update pixels buffer.
1 parent 4a534f0 commit 1e22445

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/graphics/TFTDisplay.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,14 +1254,14 @@ void TFTDisplay::display(bool fromBlank)
12541254

12551255
// Did we find a pixel that needs updating on this row?
12561256
if (x_FirstPixelUpdate < displayWidth) {
1257-
1258-
// Quickly write out the first changed pixel (saves another array lookup)
1259-
linePixelBuffer[x_FirstPixelUpdate] = isset ? colorTftMesh : colorTftBlack;
1260-
x_LastPixelUpdate = x_FirstPixelUpdate;
1261-
1262-
// Step 3: copy all remaining pixels in this row into the pixel line buffer,
1263-
// while also recording the last pixel in the row that needs updating
1264-
for (x = x_FirstPixelUpdate + 1; x < displayWidth; x++) {
1257+
// Align the first pixel for update to an even number so the total alignment of
1258+
// the data will be at 32-bit boundary, which is required by GDMA SPI transfers.
1259+
x_FirstPixelUpdate &= ~1;
1260+
1261+
// Step 3a: copy rest of the pixels in this row into the pixel line buffer,
1262+
// while also recording the last pixel in the row that needs updating.
1263+
// Since the first changed pixel will be looked up, the x_LastPixelUpdate will be set.
1264+
for (x = x_FirstPixelUpdate; x < displayWidth; x++) {
12651265
isset = buffer[x + y_byteIndex] & y_byteMask;
12661266
linePixelBuffer[x] = isset ? colorTftMesh : colorTftBlack;
12671267

@@ -1274,6 +1274,10 @@ void TFTDisplay::display(bool fromBlank)
12741274
x_LastPixelUpdate = x;
12751275
}
12761276
}
1277+
// Step 3b: Round up the last pixel to odd number to maintain 32-bit alignment for SPIs.
1278+
// Most of displays will have even number of pixels in a row -- this will be in bounds
1279+
// of the displayWidth. (Hopefully odd displays will just ignore that extra pixel.)
1280+
x_LastPixelUpdate |= 1;
12771281
#if defined(HACKADAY_COMMUNICATOR)
12781282
tft->draw16bitBeRGBBitmap(x_FirstPixelUpdate, y, &linePixelBuffer[x_FirstPixelUpdate],
12791283
(x_LastPixelUpdate - x_FirstPixelUpdate + 1), 1);

0 commit comments

Comments
 (0)