From adac5aa7b18d4252b645dadff3f51e263768d8cb Mon Sep 17 00:00:00 2001 From: Andrei Lukichev Date: Wed, 3 Jul 2024 14:51:09 +0300 Subject: [PATCH 1/2] Fix broken colors and partial flush for ILI9488 display --- .../Graphics/Displays/ILI9488_480x320_SPI.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/nanoFramework.Graphics/Graphics/Displays/ILI9488_480x320_SPI.cpp b/src/nanoFramework.Graphics/Graphics/Displays/ILI9488_480x320_SPI.cpp index c1a93634d0..560fd4d87f 100644 --- a/src/nanoFramework.Graphics/Graphics/Displays/ILI9488_480x320_SPI.cpp +++ b/src/nanoFramework.Graphics/Graphics/Displays/ILI9488_480x320_SPI.cpp @@ -289,15 +289,17 @@ 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++) + 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; + uint32_t element = data[i / 2]; // Each uint32 stores 2 pixels uint16_t color = (i % 2 == 0) ? (element & 0xFFFF) : (element >> 16); @@ -309,9 +311,9 @@ void DisplayDriver::BitBlt( g = (g << 2) | (g >> 4); r = (r << 3) | (r >> 2); - TransferBuffer[count++] = b; - TransferBuffer[count++] = g; TransferBuffer[count++] = r; + TransferBuffer[count++] = g; + TransferBuffer[count++] = b; // can't fit another 3 bytes if (count + 3 > TransferBufferSize - 1) From 0bae92b060ef12c2903bb1ab9576546f799284fe Mon Sep 17 00:00:00 2001 From: nfbot Date: Thu, 4 Jul 2024 03:04:50 +0000 Subject: [PATCH 2/2] Code style fixes Automated fixes for code style. --- .../Graphics/Displays/ILI9488_480x320_SPI.cpp | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/nanoFramework.Graphics/Graphics/Displays/ILI9488_480x320_SPI.cpp b/src/nanoFramework.Graphics/Graphics/Displays/ILI9488_480x320_SPI.cpp index 560fd4d87f..2e2a437211 100644 --- a/src/nanoFramework.Graphics/Graphics/Displays/ILI9488_480x320_SPI.cpp +++ b/src/nanoFramework.Graphics/Graphics/Displays/ILI9488_480x320_SPI.cpp @@ -296,32 +296,32 @@ void DisplayDriver::BitBlt( // only 18/24 bit is supported on SPI 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; - - uint32_t element = data[i / 2]; // Each uint32 stores 2 pixels - uint16_t color = (i % 2 == 0) ? (element & 0xFFFF) : (element >> 16); + 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++] = r; - TransferBuffer[count++] = g; - TransferBuffer[count++] = b; + 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; + 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; }