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..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);
}
}
@@ -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));
}
///
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));
}
///
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);