From 060740205de0987de4177abd125711483e4f20d2 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Mon, 8 Aug 2022 16:52:08 -0700 Subject: [PATCH 1/4] Fix ILI9488 display driver and set to 24bpp --- .../Displays.TftSpi/Driver/Drivers/Ili9488.cs | 49 +++++++++++++------ .../Displays.TftSpi/Driver/TftSpiBase.cs | 12 ++++- .../Samples/Ili9488_Sample/MeadowApp.cs | 7 +-- 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Drivers/Ili9488.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Drivers/Ili9488.cs index 636fecca7f..e52eb3646c 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Drivers/Ili9488.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/Drivers/Ili9488.cs @@ -1,5 +1,4 @@ using System.Threading; -using Meadow.Devices; using Meadow.Foundation.Graphics; using Meadow.Hardware; @@ -7,10 +6,21 @@ namespace Meadow.Foundation.Displays.TftSpi { public class Ili9488 : TftSpiBase { - public override ColorType DefautColorMode => ColorType.Format12bppRgb444; - + public override ColorType DefautColorMode => ColorType.Format24bppRgb888; + + /// + /// Create a new Ili9488 display instance + /// + /// + /// + /// + /// + /// + /// + /// + /// public Ili9488(IMeadowDevice device, ISpiBus spiBus, IPin chipSelectPin, IPin dcPin, IPin resetPin, - int width = 320, int height = 480, ColorType displayColorMode = ColorType.Format12bppRgb444) + int width = 320, int height = 480, ColorType displayColorMode = ColorType.Format24bppRgb888) : base(device, spiBus, chipSelectPin, dcPin, resetPin, width, height, displayColorMode) { Initialize(); @@ -18,8 +28,20 @@ public Ili9488(IMeadowDevice device, ISpiBus spiBus, IPin chipSelectPin, IPin dc SetRotation(Rotation.Normal); } + public override bool IsColorModeSupported(ColorType mode) + { + return mode == ColorType.Format24bppRgb888; + } + protected override void Initialize() { + resetPort.State = true; + DelayMs(5); + resetPort.State = false; + DelayMs(120); + resetPort.State = true; + DelayMs(150); + SendCommand(0xE0); // Positive Gamma Control SendData(0x00); SendData(0x03); @@ -70,40 +92,39 @@ protected override void Initialize() SendData(0x48); // MX, BGR SendCommand((byte)Register.COLOR_MODE); // Pixel Interface Format - if (ColorMode == ColorType.Format16bppRgb565) - SendData(0x55); // 16 bit colour for SPI - else - SendData(0x53); //12 bit RGB444 + SendData(0x66); //24bpp SendCommand(0xB0); // Interface Mode Control SendData(0x00); SendCommand(0xB1); // Frame Rate Control - SendData(0xA0); + SendData(0xA0); //60hz SendCommand(0xB4); // Display Inversion Control - SendData(0x02); + SendData(0x02); //2-dot SendCommand(0xB6); // Display Function Control SendData(0x02); SendData(0x02); SendData(0x3B); - SendCommand(0xB7); // Entry Mode Set - SendData(0xC6); + SendCommand(0xE9); //set image funcion + SendData(0x00); //disable 24 bit data SendCommand(0xF7); // Adjust Control 3 SendData(0xA9); SendData(0x51); SendData(0x2C); - SendData(0x82); + SendData(0x82);// D7 stream, loose + + SendCommand(0xB7); // Entry Mode Set + SendData(0xC6); SendCommand(TFT_SLPOUT); //Exit Sleep Thread.Sleep(120); SendCommand(TFT_DISPON); //Display on Thread.Sleep(25); - } protected override void SetAddressWindow(int x0, int y0, int x1, int y1) diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/TftSpiBase.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/TftSpiBase.cs index 8febf4ce6c..12915365ae 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/TftSpiBase.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Driver/TftSpiBase.cs @@ -47,6 +47,11 @@ public TftSpiBase(IMeadowDevice device, ISpiBus spiBus, IPin chipSelectPin, IPin CreateBuffer(mode, width, height); } + /// + /// Is the color mode supported on this display + /// + /// The color mode + /// true if supported public virtual bool IsColorModeSupported(ColorType mode) { if (mode == ColorType.Format12bppRgb444 || @@ -64,7 +69,12 @@ protected void CreateBuffer(ColorType mode, int width, int height) throw new ArgumentException($"Mode {mode} not supported"); } - if (mode == ColorType.Format16bppRgb565) + if (mode == ColorType.Format24bppRgb888) + { + imageBuffer = new BufferRgb888(width, height); + } + + else if (mode == ColorType.Format16bppRgb565) { imageBuffer = new BufferRgb565(width, height); } diff --git a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9488_Sample/MeadowApp.cs b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9488_Sample/MeadowApp.cs index d1157a20a8..ca25a850a1 100644 --- a/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9488_Sample/MeadowApp.cs +++ b/Source/Meadow.Foundation.Peripherals/Displays.TftSpi/Samples/Ili9488_Sample/MeadowApp.cs @@ -29,9 +29,8 @@ public override Task Initialize() device: Device, spiBus: spiBus, chipSelectPin: Device.Pins.D02, - dcPin: Device.Pins.D01, - resetPin: Device.Pins.D00, - width: 320, height: 480 + dcPin: Device.Pins.D00, + resetPin: Device.Pins.D01 ); graphics = new MicroGraphics(display) @@ -45,6 +44,8 @@ public override Task Initialize() public override Task Run() { + Console.WriteLine("Run"); + graphics.Clear(); graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Meadow.Foundation.Color.Red); From 546b4a764c9429c59c2824375f3f5db5b5557885 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Mon, 8 Aug 2022 17:08:40 -0700 Subject: [PATCH 2/4] Add InvertPixel to BufferRgb888 --- .../Driver/Buffers/BufferRgb888.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferRgb888.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferRgb888.cs index 0ed01e9725..48d23e1ddd 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferRgb888.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferRgb888.cs @@ -102,7 +102,14 @@ public override void Fill(int x, int y, int width, int height, Color color) /// y position of pixel public override void InvertPixel(int x, int y) { - throw new NotImplementedException(); + var color = GetPixel(x, y); + + //split into R,G,B & invert + byte r = (byte)~color.R; + byte g = (byte)~color.G; + byte b = (byte)~color.B; + + SetPixel(x, y, new Color(r, g, b)); } /// From 5e0378c5fb71333266f3a692de5b0ed093fc8891 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Mon, 8 Aug 2022 17:12:49 -0700 Subject: [PATCH 3/4] Fix Fill method in BufferRgb888 --- .../Graphics.MicroGraphics/Driver/Buffers/BufferRgb888.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferRgb888.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferRgb888.cs index 48d23e1ddd..6abc9723fd 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferRgb888.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferRgb888.cs @@ -74,7 +74,7 @@ public override void Fill(int x, int y, int width, int height, Color color) } byte[] value = { color.R, color.G, color.B }; - int index = y * Width * 3 + x * 3 - 1; + int index = (y * Width + x) * 3 - 1; //fill the first line for (int i = 0; i < width; i++) @@ -91,7 +91,7 @@ public override void Fill(int x, int y, int width, int height, Color color) (y + j) * Width * 3 + x * 3, Buffer, (y + j + 1) * Width * 3 + x * 3, - width); + width * 3); } } From 618e2e1fbae2fc0e022711a166385beba36d0697 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Mon, 8 Aug 2022 17:19:12 -0700 Subject: [PATCH 4/4] Fix fill and invert pixel methods for BufferRgb8888 --- .../Driver/Buffers/BufferRgb8888.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferRgb8888.cs b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferRgb8888.cs index 76e38230e9..dab9ccb90d 100644 --- a/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferRgb8888.cs +++ b/Source/Meadow.Foundation.Libraries_and_Frameworks/Graphics.MicroGraphics/Driver/Buffers/BufferRgb8888.cs @@ -77,7 +77,7 @@ public override void Fill(int x, int y, int width, int height, Color color) } byte[] value = { color.R, color.G, color.B, color.A }; - int index = y * Width * 4 + x * 4 - 1; + int index = (y * Width + x) * 4 - 1; //fill the first line for (int i = 0; i < width; i++) @@ -95,7 +95,7 @@ public override void Fill(int x, int y, int width, int height, Color color) (y + j) * Width * 4 + x * 4, Buffer, (y + j + 1) * Width * 4 + x * 4, - width); + width * 4); } } @@ -106,7 +106,14 @@ public override void Fill(int x, int y, int width, int height, Color color) /// y position of pixel public override void InvertPixel(int x, int y) { - throw new NotImplementedException(); + var color = GetPixel(x, y); + + //split into R,G,B & invert + byte r = (byte)~color.R; + byte g = (byte)~color.G; + byte b = (byte)~color.B; + + SetPixel(x, y, new Color(r, g, b, color.A)); } ///