Skip to main content

SpiDevice Class

Namespace: GHIElectronics.TinyCLR.Devices.Spi · Assembly: GHIElectronics.TinyCLR.Devices.Spi

Represents a single chip on an SPI bus. Each transfer is preceded by a re-apply of ConnectionSettings, so multiple devices on the same controller can coexist without manual reconfiguration between calls.

public class SpiDevice : IDisposable

Properties

ConnectionSettings

public SpiConnectionSettings ConnectionSettings { get; }

The per-device bus settings (clock, mode, chip select, etc.).

Controller

public SpiController Controller { get; }

The SpiController this device transacts over.

Methods

Dispose()

public void Dispose()

Releases device-level resources. Does not close the underlying controller.

Read(byte[] buffer)

public void Read(byte[] buffer)

Reads buffer.Length bytes; transmits zeros while reading.

ParameterTypeDescription
bufferbyte[]Destination buffer.

Write(byte[] buffer)

public void Write(byte[] buffer)

Writes buffer.Length bytes; discards received data.

ParameterTypeDescription
bufferbyte[]Source buffer.

Write(byte[] buffer, int xOffset, int yOffset, int width, int height, int originalWidth)

public void Write(byte[] buffer, int xOffset, int yOffset, int width, int height, int originalWidth)

Writes a rectangular sub-region of a larger framebuffer. Display driver helper.

ParameterTypeDescription
bufferbyte[]Source framebuffer (RGB565 pairs of bytes).
xOffsetintLeft edge of the source rectangle within the framebuffer.
yOffsetintTop edge of the source rectangle within the framebuffer.
widthintWidth of the source rectangle in pixels.
heightintHeight of the source rectangle in pixels.
originalWidthintPixel-width of the full framebuffer.

TransferFullDuplex(byte[] writeBuffer, byte[] readBuffer)

public void TransferFullDuplex(byte[] writeBuffer, byte[] readBuffer)

Writes and reads simultaneously; both buffers must be the same length.

ParameterTypeDescription
writeBufferbyte[]Bytes to transmit.
readBufferbyte[]Receives the bytes shifted in.

TransferSequential(byte[] writeBuffer, byte[] readBuffer)

public void TransferSequential(byte[] writeBuffer, byte[] readBuffer)

Writes all of writeBuffer, then reads all of readBuffer in a single CS-low transaction.

ParameterTypeDescription
writeBufferbyte[]
readBufferbyte[]

Read(byte[] buffer, int offset, int length)

public void Read(byte[] buffer, int offset, int length)

Reads length bytes into buffer starting at offset.

ParameterTypeDescription
bufferbyte[]
offsetint
lengthint

Write(byte[] buffer, int offset, int length)

public void Write(byte[] buffer, int offset, int length)

Writes length bytes from buffer starting at offset.

ParameterTypeDescription
bufferbyte[]
offsetint
lengthint

TransferFullDuplex(byte[] writeBuffer, int writeOffset, int writeLength, byte[] readBuffer, int readOffset, int readLength)

public void TransferFullDuplex(byte[] writeBuffer, int writeOffset, int writeLength, byte[] readBuffer, int readOffset, int readLength)

Full-duplex transfer with explicit slice offsets and lengths.

ParameterTypeDescription
writeBufferbyte[]
writeOffsetint
writeLengthint
readBufferbyte[]
readOffsetint
readLengthint

TransferSequential(byte[] writeBuffer, int writeOffset, int writeLength, byte[] readBuffer, int readOffset, int readLength)

public void TransferSequential(byte[] writeBuffer, int writeOffset, int writeLength, byte[] readBuffer, int readOffset, int readLength)

Sequential write-then-read with explicit slice offsets and lengths; chip select stays asserted between the two phases.

ParameterTypeDescription
writeBufferbyte[]
writeOffsetint
writeLengthint
readBufferbyte[]
readOffsetint
readLengthint

Write(byte[] buffer, int x, int y, int width, int height, int originalWidth, int columnMultiplier, int rowMultiplier)

public void Write(byte[] buffer, int x, int y, int width, int height, int originalWidth, int columnMultiplier, int rowMultiplier)

Writes a rectangular framebuffer region with optional pixel replication. columnMultiplier and rowMultiplier let the display driver scale up small framebuffers without a CPU-side resize.

ParameterTypeDescription
bufferbyte[]
xint
yint
widthint
heightint
originalWidthint
columnMultiplierint
rowMultiplierint