Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change TftSpiBase displays to use SpiBus.Write instead of Exchange #1122

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading