Class Ssd168x
Base class for SSD168X-based ePaper devices.
public abstract class Ssd168x : IEPaperDisplay
- Inheritance
-
Ssd168x
- Implements
- Derived
Constructors
Ssd168x(SpiDevice, int, int, int, int, int, GpioController, bool, bool)
Initializes a new instance of the Ssd168x class.
protected Ssd168x(SpiDevice spiDevice, int resetPin, int busyPin, int dataCommandPin, int width, int height, GpioController gpioController = null, bool enableFramePaging = true, bool shouldDispose = true)
Parameters
spiDeviceSpiDeviceThe communication channel to the SSD1681-based dispay.
resetPinintThe reset GPIO pin. Passing an invalid pin number such as -1 will prevent this driver from opening the pin. Caller should handle hardware resets.
busyPinintThe busy GPIO pin.
dataCommandPinintThe data/command GPIO pin.
widthintThe width of the display.
heightintThe height of the display.
gpioControllerGpioControllerThe GpioController to use when initializing the pins.
enableFramePagingboolPage the frame buffer and all operations to use less memory.
shouldDisposebooltrue to dispose of the GpioController.
Exceptions
- ArgumentNullException
spiDeviceis null.- ArgumentOutOfRangeException
Display width and height can't be less than 0 or greater than 200.
Fields
SpiClockFrequency
The max supported clock frequency for the SSD168x controller. 20MHz.
public const int SpiClockFrequency = 20000000
Field Value
SpiMode
The supported SpiMode by the SSD168x controller.
public const SpiMode SpiMode = Mode0
Field Value
Properties
CurrentFrameBufferPage
Gets or sets the current frame buffer page index.
protected int CurrentFrameBufferPage { get; set; }
Property Value
CurrentFrameBufferPageLowerBound
Gets or sets the current frame buffer page lower bounds.
protected int CurrentFrameBufferPageLowerBound { get; set; }
Property Value
CurrentFrameBufferPageUpperBound
Gets or sets the current frame buffer page upper bounds.
protected int CurrentFrameBufferPageUpperBound { get; set; }
Property Value
CurrentFrameBufferStartXPosition
Gets or sets the current frame buffer start X-Position.
protected int CurrentFrameBufferStartXPosition { get; set; }
Property Value
CurrentFrameBufferStartYPosition
Gets or sets the current frame buffer start Y-Position.
protected int CurrentFrameBufferStartYPosition { get; set; }
Property Value
FirstPageIndex
Gets the index of the first frame page.
protected int FirstPageIndex { get; }
Property Value
FrameBuffer
Gets the frame buffer.
public virtual IFrameBuffer FrameBuffer { get; protected set; }
Property Value
Remarks
This frame buffer instance could be pointing to a portion of the full display frame as a measure to reduce memory footprint. See the ctor documentation for more info.
FrameBuffer2bpp
Gets or sets the FrameBuffer2BitPerPixel used internally by Ssd168x devices to represents the frame.
protected FrameBuffer2BitPerPixel FrameBuffer2bpp { get; set; }
Property Value
Height
Gets the height of the drawable area on the display.
public virtual int Height { get; protected set; }
Property Value
PagedFrameDrawEnabled
Gets a value indicating whether drawing to a frame is paged to save on memory space.
public virtual bool PagedFrameDrawEnabled { get; protected set; }
Property Value
PagesPerFrame
Gets the number of pages in every frame buffer.
protected abstract int PagesPerFrame { get; }
Property Value
PowerState
Gets or sets the current power state of the display panel.
public virtual PowerState PowerState { get; protected set; }
Property Value
Width
Gets the width of the drawable area on the display.
public virtual int Width { get; protected set; }
Property Value
Methods
BeginFrameDraw()
Begins a frame draw operation with frame paging support.
BeginFrameDraw();
do {
// Drawing calls
} while (NextFramePage());
EndFrameDraw();
public virtual void BeginFrameDraw()
CalculateFrameBufferPageBounds()
Calculates the upper and lower bounds of the current frame buffer page.
protected virtual void CalculateFrameBufferPageBounds()
Clear(bool)
Clears the display frame buffer by resetting it to its default state.
public virtual void Clear(bool triggerPageRefresh = false)
Parameters
triggerPageRefreshbooltrue to also flush the buffer to the display and trigger the refresh sequence.
DirectDrawBuffer(int, int, params byte[])
Draws the specified buffer directly to the Black/White RAM on the display. Call PerformFullRefresh() after to update the display.
public void DirectDrawBuffer(int startXPos, int startYPos, params byte[] buffer)
Parameters
startXPosintX start position.
startYPosintY start position.
bufferbyte[]The buffer array to draw.
DirectDrawColorBuffer(int, int, params byte[])
Draws the specified buffer directly to the Red RAM on the display. Call PerformFullRefresh() after to update the display.
public void DirectDrawColorBuffer(int startXPos, int startYPos, params byte[] buffer)
Parameters
startXPosintX start position.
startYPosintY start position.
bufferbyte[]The buffer array to draw.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
DrawPixel(int, int, bool)
Draws a single pixel to the appropriate frame buffer.
public void DrawPixel(int x, int y, bool inverted)
Parameters
xintThe X Position.
yintThe Y Position.
invertedboolTrue to invert the pixel from white to black.
Remarks
The SSD168x comes with 2 RAMs: a Black and White RAM and a Red RAM. Writing to the B/W RAM draws B/W pixels on the panel. While writing to the Red RAM draws red pixels on the panel (if the panel supports red). However, the SSD168x doesn't support specifying the color level (no grayscaling), therefore the way the buffer is selected is by performing a simple binary check: if R >= 128 and G == 0 and B == 0 then write a red pixel to the Red Buffer/RAM if R == 0 and G == 0 and B == 0 then write a black pixel to B/W Buffer/RAM else, assume white pixel and write to B/W Buffer/RAM.
DrawPixel(int, int, Color)
Draws a single pixel to the appropriate frame buffer based on the specified color.
public virtual void DrawPixel(int x, int y, Color color)
Parameters
xintThe X Position.
yintThe Y Position.
colorColorPixel color. See the remarks for how a buffer is selected based on the color value.
Remarks
The SSD168x comes with 2 RAMs: a Black and White RAM and a Red RAM. Writing to the B/W RAM draws B/W pixels on the panel. While writing to the Red RAM draws red pixels on the panel (if the panel supports red). However, the SSD168x doesn't support specifying the color level (no grayscaling), therefore the way the buffer is selected is by performing a simple binary check: if R >= 128 and G == 0 and B == 0 then write a red pixel to the Red Buffer/RAM if R == 0 and G == 0 and B == 0 then write a black pixel to B/W Buffer/RAM else, assume white pixel and write to B/W Buffer/RAM.
EndFrameDraw()
Ends the frame draw and flushes the current page to the device.
public virtual void EndFrameDraw()
EnforceBounds(ref int, ref int)
Snaps the provided coordinates to the lower bounds of the display if out of allowed range.
protected virtual void EnforceBounds(ref int x, ref int y)
Parameters
Flush()
Flushes the content of the internal frame buffer to the display.
public virtual void Flush()
Remarks
You will only need to use this method if you have disabled frame paged draws.
GetFrameBufferIndex(int, int)
Gets the index of the byte containing the pixel specified by the x and y parameters.
protected virtual int GetFrameBufferIndex(int x, int y)
Parameters
Returns
- int
The index of the byte in the frame buffer which contains the specified pixel.
GetXPositionFromFrameBufferIndex(int)
Gets the X position from a buffer index.
protected virtual int GetXPositionFromFrameBufferIndex(int index)
Parameters
indexintThe buffer index.
Returns
- int
The X position of a pixel.
GetYPositionFromFrameBufferIndex(int)
Gets the Y position from a buffer index.
protected virtual int GetYPositionFromFrameBufferIndex(int index)
Parameters
indexintThe buffer index.
Returns
- int
The Y position of a pixel.
HardwareReset()
Performs the hardware reset commands sequence on the display.
protected virtual void HardwareReset()
Initialize()
Perform the required initialization steps to set up the display.
public virtual void Initialize()
Exceptions
- InvalidOperationException
Unable to initialize the display until it has been powered on. Call PowerOn() first.
InitializeFrameBuffer(int, int, bool)
Initializes a new instance of the intenral frame buffer. Supports paging.
protected virtual void InitializeFrameBuffer(int width, int height, bool enableFramePaging)
Parameters
widthintThe width of the frame buffer in pixels.
heightintThe height of the frame buffer in pixels.
enableFramePagingboolIf true, enables paging the frame.
NextFramePage()
Moves the current buffers to the next frame page and returns true if successful.
public virtual bool NextFramePage()
Returns
- bool
True if the next frame page is available and the internal buffers have moved to it, false otherwise.
PerformFullRefresh()
Initiates the full refresh sequence on the display.
public virtual bool PerformFullRefresh()
Returns
- bool
True if the screen sucessfully refresh. False otherwise (still busy after a predefined waiting time).
PerformPartialRefresh()
Initiates the partial refresh sequence on the display if the panel supports it.
public virtual bool PerformPartialRefresh()
Returns
- bool
True if the screen sucessfully refresh. False otherwise (still busy after a predefined waiting time).
PowerDown(SleepMode)
Puts the display to sleep using the specified SleepMode.
public virtual void PowerDown(SleepMode sleepMode = SleepMode.Normal)
Parameters
sleepModeSleepModeThe sleep mode to use when powering down the display.
PowerOn()
Performs the required steps to "power on" the display.
public virtual void PowerOn()
SendCommand(params byte[])
Sends a command byte(s) to the display.
public virtual void SendCommand(params byte[] command)
Parameters
commandbyte[]The command bytes to send. See the command enum within the driver implementation and consult the datasheet.
SendData(params byte[])
Send frame data to the display.
public virtual void SendData(params byte[] data)
Parameters
databyte[]The frame data to send.
SendData(params ushort[])
Send frame data to the display.
public virtual void SendData(params ushort[] data)
Parameters
dataushort[]The frame data to send.
SetFrameBufferPage(int)
Sets the current active frame buffer page to the specified page index. Existing frame buffer is reused by clearing it first and page bounds are recalculated. Make sure to call PerformFullRefresh() or PerformPartialRefresh() to persist the frame to the display's RAM before calling this method.
protected virtual void SetFrameBufferPage(int page)
Parameters
pageintThe frame buffer page index to move to.
SetPosition(int, int)
Sets the drawing position on the display.
public virtual void SetPosition(int x, int y)
Parameters
SoftwareReset()
Performs the software reset commands sequence on the display.
protected virtual void SoftwareReset()
WaitMs(int)
A simple wait method that wraps Sleep(int).
protected virtual void WaitMs(int milliseconds)
Parameters
millisecondsintNumber of milliseconds to sleep.
WaitReady(CancellationToken)
Blocks the current thread until the display is in idle mode again.
public virtual bool WaitReady(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe CancellationToken to be able to cancel the waiting time.
Returns
- bool
True if it returns before the CancellationToken expires, false otherwise.
Remarks
If cancellationToken is null, this method will block until the busy pin is low.