Skip to content

Commit

Permalink
Merge pull request #1122 from HakanL/develop
Browse files Browse the repository at this point in the history
Change TftSpiBase displays to use SpiBus.Write instead of Exchange
  • Loading branch information
adrianstevens authored Feb 17, 2025
2 parents 42a8b64 + e6b2949 commit 2ebf06c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class St7789 : TftSpiBase, IRotatableDisplay
/// <param name="width">Width of display in pixels</param>
/// <param name="height">Height of display in pixels</param>
/// <param name="colorMode">The color mode to use for the display buffer</param>
public St7789(ISpiBus spiBus, IPin chipSelectPin, IPin dcPin, IPin resetPin,
public St7789(ISpiBus spiBus, IPin chipSelectPin, IPin dcPin, IPin? resetPin,
int width, int height, ColorMode colorMode = ColorMode.Format12bppRgb444)
: base(spiBus, chipSelectPin, dcPin, resetPin, width, height, colorMode)
{
Expand All @@ -63,7 +63,7 @@ public St7789(ISpiBus spiBus, IPin chipSelectPin, IPin dcPin, IPin resetPin,
/// <param name="height">Height of display in pixels</param>
/// <param name="colorMode">The color mode to use for the display buffer</param>
public St7789(ISpiBus spiBus, IDigitalOutputPort chipSelectPort,
IDigitalOutputPort dataCommandPort, IDigitalOutputPort resetPort,
IDigitalOutputPort dataCommandPort, IDigitalOutputPort? resetPort,
int width, int height, ColorMode colorMode = ColorMode.Format12bppRgb444) :
base(spiBus, chipSelectPort, dataCommandPort, resetPort, width, height, colorMode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ public SpiClockConfiguration.Mode SpiBusMode
/// </summary>
protected IPixelBuffer imageBuffer = default!;

/// <summary>
/// The read buffer
/// </summary>
protected Memory<byte> readBuffer;

/// <summary>
/// Data convenience bool
/// </summary>
Expand Down Expand Up @@ -271,7 +266,6 @@ protected void CreateBuffer(ColorMode colorMode, int width, int height)
{
imageBuffer = new BufferRgb444(width, height);
}
readBuffer = new byte[imageBuffer.ByteCount];
}

/// <summary>
Expand Down Expand Up @@ -415,7 +409,7 @@ public void Show()

dataCommandPort.State = Data;

spiDisplay.Bus.Exchange(chipSelectPort, imageBuffer.Buffer, readBuffer.Span);
spiDisplay.Bus.Write(chipSelectPort, imageBuffer.Buffer);
}

/// <summary>
Expand Down Expand Up @@ -467,10 +461,9 @@ public void Show(int left, int top, int right, int bottom)
{
int sourceIndex = (int)((y * Width + left) * bytesPerPixel);

spiDisplay.Bus.Exchange(
spiDisplay.Bus.Write(
chipSelectPort,
imageBuffer.Buffer[sourceIndex..(sourceIndex + len)],
readBuffer.Span[0..len]);
imageBuffer.Buffer[sourceIndex..(sourceIndex + len)]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Displays.TftSpi\Driver\Displays.TftSpi.csproj" />
<ProjectReference Include="..\..\..\ICs.ADCs.Mcp3xxx\Driver\ICs.ADC.Mcp3xxx.csproj" />
<ProjectReference Include="..\..\..\Sensors.Light.Veml7700\Driver\Sensors.Light.Veml7700.csproj" />
<ProjectReference Include="..\..\Driver\ICs.IOExpanders.Ftxxxx.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// See https://aka.ms/new-console-template for more information
using Meadow;
using Meadow.Foundation.Displays;
using Meadow.Foundation.Graphics;
using Meadow.Foundation.ICs.IOExpanders;
using Meadow.Foundation.Sensors.Light;
using Meadow.Hardware;
using Meadow.Peripherals.Displays;
using System.Diagnostics;

Console.WriteLine("HELLO FROM THE WILDERNESS FT232H DRIVER!");
Expand All @@ -12,7 +15,37 @@

//await TestGpio(FtdiExpanderCollection.Devices);
//await TestI2C(FtdiExpanderCollection.Devices[0]);
await TestSPI(FtdiExpanderCollection.Devices[0]);
//await TestSPI(FtdiExpanderCollection.Devices[0]);
await TestSPIDisplay(FtdiExpanderCollection.Devices[0]);

async Task TestSPIDisplay(FtdiExpander expander)
{
var display = new St7789
(
spiBus: expander.CreateSpiBus(),
chipSelectPin: expander.Pins.D0,
dcPin: expander.Pins.D1,
resetPin: null,
135, 240
);

var microGraphics = new MicroGraphics(display)
{
CurrentFont = new Font12x16(),
Rotation = RotationType._270Degrees
};

microGraphics.Clear();
microGraphics.DrawText(0, 0, "Loading Menu");
microGraphics.Show();

while (true)
{
Debug.WriteLine("Sleeping...");

await Task.Delay(1000);
}
}

async Task TestSPI(FtdiExpander expander)
{
Expand Down

0 comments on commit 2ebf06c

Please sign in to comment.