Skip to content

Commit

Permalink
Merge pull request #388 from WildernessLabs/adrian-ILI9488-fix
Browse files Browse the repository at this point in the history
Fix ILI9488 display driver and set to 24bpp
  • Loading branch information
profexorgeek authored Aug 9, 2022
2 parents 19ef7f3 + 618e2e1 commit 6a89359
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand All @@ -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);
}
}

Expand All @@ -102,7 +102,14 @@ public override void Fill(int x, int y, int width, int height, Color color)
/// <param name="y">y position of pixel</param>
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));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand All @@ -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);
}
}

Expand All @@ -106,7 +106,14 @@ public override void Fill(int x, int y, int width, int height, Color color)
/// <param name="y">y position of pixel</param>
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));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
using System.Threading;
using Meadow.Devices;
using Meadow.Foundation.Graphics;
using Meadow.Hardware;

namespace Meadow.Foundation.Displays.TftSpi
{
public class Ili9488 : TftSpiBase
{
public override ColorType DefautColorMode => ColorType.Format12bppRgb444;

public override ColorType DefautColorMode => ColorType.Format24bppRgb888;

/// <summary>
/// Create a new Ili9488 display instance
/// </summary>
/// <param name="device"></param>
/// <param name="spiBus"></param>
/// <param name="chipSelectPin"></param>
/// <param name="dcPin"></param>
/// <param name="resetPin"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="displayColorMode"></param>
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();

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);
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public TftSpiBase(IMeadowDevice device, ISpiBus spiBus, IPin chipSelectPin, IPin
CreateBuffer(mode, width, height);
}

/// <summary>
/// Is the color mode supported on this display
/// </summary>
/// <param name="mode">The color mode</param>
/// <returns>true if supported</returns>
public virtual bool IsColorModeSupported(ColorType mode)
{
if (mode == ColorType.Format12bppRgb444 ||
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit 6a89359

Please sign in to comment.