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

Only call SetAddressWindow if the update window changes #652

Merged
merged 2 commits into from
May 2, 2023
Merged
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 @@ -13,7 +13,7 @@ public abstract partial class TftSpiBase : IGraphicsDisplay, ISpiPeripheral
/// Temporary buffer that can be used to batch set address window buffer commands
/// </summary>
protected byte[] SetAddressBuffer { get; } = new byte[4];

//these displays typically support 16 & 18 bit, some also include 8, 9, 12 and/or 24 bit color

/// <summary>
Expand Down Expand Up @@ -134,6 +134,30 @@ public SpiClockConfiguration.Mode SpiBusMode
/// </summary>
protected int nativeWidth;

/// <summary>
/// Previous x0 value passed to SetAddressWindow
/// Used for optimization to avoid unnecessary SPI commands
/// </summary>
protected int setAddressLastX0 = -1;

/// <summary>
/// Previous x1 value passed to SetAddressWindow
/// Used for optimization to avoid unnecessary SPI commands
/// </summary>
protected int setAddressLastX1 = -1;

/// <summary>
/// Previous y0 value passed to SetAddressWindow
/// Used for optimization to avoid unnecessary SPI commands
/// </summary>
protected int setAddressLastY0 = -1;

/// <summary>
/// Previous y1 value passed to SetAddressWindow
/// Used for optimization to avoid unnecessary SPI commands
/// </summary>
protected int setAddressLastY1 = -1;

/// <summary>
/// Represents an abstract TftSpiBase object
/// </summary>
Expand Down Expand Up @@ -231,22 +255,31 @@ protected void CreateBuffer(ColorMode colorMode, int width, int height)
/// <param name="y1">Y end in pixels</param>
protected virtual void SetAddressWindow(int x0, int y0, int x1, int y1)
{
SendCommand(LcdCommand.CASET); // column addr set
dataCommandPort.State = Data;
SetAddressBuffer[0] = (byte)(x0 >> 8);
SetAddressBuffer[1] = (byte)(x0 & 0xff); // XSTART
SetAddressBuffer[2] = (byte)(x1 >> 8);
SetAddressBuffer[3] = (byte)(x1 & 0xff); // XEND
Write(SetAddressBuffer);

SendCommand(LcdCommand.RASET); // row addr set
dataCommandPort.State = Data;
SetAddressBuffer[0] = (byte)(y0 >> 8);
SetAddressBuffer[0] = (byte)(y0 & 0xff); // XEND
SetAddressBuffer[0] = (byte)(y1 >> 8);
SetAddressBuffer[0] = (byte)(y1 & 0xff); // YEND

SendCommand(LcdCommand.RAMWR); // write to RAM
if (x0 != setAddressLastX0 || x1 != setAddressLastX1 || y0 != setAddressLastY0 || y1 != setAddressLastY1)
{
setAddressLastX0 = x0;
setAddressLastX1 = x1;
setAddressLastY0 = y0;
setAddressLastY1 = y1;

SendCommand(LcdCommand.CASET); // column addr set
dataCommandPort.State = Data;
SetAddressBuffer[0] = (byte)(x0 >> 8);
SetAddressBuffer[1] = (byte)(x0 & 0xff); // XSTART
SetAddressBuffer[2] = (byte)(x1 >> 8);
SetAddressBuffer[3] = (byte)(x1 & 0xff); // XEND
Write(SetAddressBuffer);

SendCommand(LcdCommand.RASET); // row addr set
dataCommandPort.State = Data;
SetAddressBuffer[0] = (byte)(y0 >> 8);
SetAddressBuffer[1] = (byte)(y0 & 0xff); // XEND
SetAddressBuffer[2] = (byte)(y1 >> 8);
SetAddressBuffer[3] = (byte)(y1 & 0xff); // YEND
Write(SetAddressBuffer);

SendCommand(LcdCommand.RAMWR); // write to RAM
}
}

/// <summary>
Expand Down Expand Up @@ -447,7 +480,7 @@ protected void SendCommand(byte command)
dataCommandPort.State = Command;
Write(command);
}

/// <summary>
/// Send a single byte to the display (convenience method)
/// </summary>
Expand Down