Skip to content

Fix broken colors and partial flush for ILI9488 display #2976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,37 +289,39 @@ void DisplayDriver::BitBlt(

g_DisplayInterface.SendCommand(1, Memory_Write);

uint32_t numPixels = width * height;
uint32_t count = 0;

CLR_UINT8 *TransferBuffer = Attributes.TransferBuffer;
CLR_UINT32 TransferBufferSize = Attributes.TransferBufferSize;

// only 18/24 bit is supported on SPI
for (uint32_t i = 0; i < numPixels; i++)
{
uint32_t element = data[i / 2]; // Each uint32 stores 2 pixels
uint16_t color = (i % 2 == 0) ? (element & 0xFFFF) : (element >> 16);
for (uint32_t y = srcY; y < srcY + height; y++)
for (uint32_t x = srcX; x < srcX + width; x++)
{
uint32_t i = y * Attributes.Width + x;

uint8_t b = color & 0x1F;
uint8_t g = (color >> 5) & 0x3F;
uint8_t r = (color >> 11) & 0x1F;
uint32_t element = data[i / 2]; // Each uint32 stores 2 pixels
uint16_t color = (i % 2 == 0) ? (element & 0xFFFF) : (element >> 16);

b = (b << 3) | (b >> 2);
g = (g << 2) | (g >> 4);
r = (r << 3) | (r >> 2);
uint8_t b = color & 0x1F;
uint8_t g = (color >> 5) & 0x3F;
uint8_t r = (color >> 11) & 0x1F;

TransferBuffer[count++] = b;
TransferBuffer[count++] = g;
TransferBuffer[count++] = r;
b = (b << 3) | (b >> 2);
g = (g << 2) | (g >> 4);
r = (r << 3) | (r >> 2);

// can't fit another 3 bytes
if (count + 3 > TransferBufferSize - 1)
{
g_DisplayInterface.SendBytes(TransferBuffer, count);
count = 0;
TransferBuffer[count++] = r;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the color scheme is also defined at initialization, what is the current initialization sequence? That maybe the broken part.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Might have found a way to force color order on the display during initialization. I'll give it a try

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted to RGB with a different strategy in #3135
Preferably the color order should come managed code. Haven't looked into that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikmog did you find a way to have it properly set from the managed code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ellerbach Think I have, at least in theory.

One way to do it is to implement the display driver Orientation's native side for the ILI9-drivers. Currently only the generic driver have them implemented in native, it seems.

That would allow us to simply set MADCTL_BGR/MADCTL_RGB on the managed side like below.
https://github.com/nanoframework/nanoFramework.Graphics/blob/c8a8d911e388887a6e65bf2218b59e1d6c196e98/ManagedDrivers/Ili9341/Ili9341.cs#L145

However I would rather have the generic display driver support the ILI9-displays, and extend the managed drivers with a definition for ILI9488. Have ambitions to take a look at it. Just don't know when 😥 🤷

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, when I implemented the generic driver, I reused elements from each drivers, so it basically have more features than the others. And moved the implemented features into the managed drivers, so there was the same features from native to managed. It's then indeed fairly easy to add features on the managed rather than the native side indeed.
Hapy you're still looking at all this :-)

TransferBuffer[count++] = g;
TransferBuffer[count++] = b;

// can't fit another 3 bytes
if (count + 3 > TransferBufferSize - 1)
{
g_DisplayInterface.SendBytes(TransferBuffer, count);
count = 0;
}
}
}
g_DisplayInterface.SendBytes(TransferBuffer, count);
return;
}
Expand Down