Table of Contents

Class ShiftRegister

Namespace
Iot.Device.Multiplexing
Assembly
Iot.Device.ShiftRegister.dll

Generic shift register implementation. Supports multiple register lengths. Compatible with SN74HC595, MBI5027 and MBI5168, for example. Supports SPI and GPIO control.

public class ShiftRegister : IOutputSegment
Inheritance
ShiftRegister
Implements
Derived

Constructors

ShiftRegister(ShiftRegisterPinMapping, int, GpioController?, bool)

Initializes a new instance of the ShiftRegister class.

public ShiftRegister(ShiftRegisterPinMapping pinMapping, int bitLength, GpioController? gpioController = null, bool shouldDispose = true)

Parameters

pinMapping ShiftRegisterPinMapping

The pin mapping to use by the binding.

bitLength int

Bit length of register, including chained registers.

gpioController GpioController

The GPIO Controller used for interrupt handling.

shouldDispose bool

True (the default) if the GPIO controller shall be disposed when disposing this instance.

ShiftRegister(SpiDevice, int)

Initializes a new instance of the ShiftRegister class. Uses 3 pins (SDI -> SDI, SCLK -> SCLK, CE0 -> LE).

public ShiftRegister(SpiDevice spiDevice, int bitLength)

Parameters

spiDevice SpiDevice

SpiDevice used for serial communication.

bitLength int

Bit length of register, including chained registers.

Properties

BitLength

Bit length across all connected registers.

public int BitLength { get; }

Property Value

int

GpioController

GPIO controller.

protected GpioController? GpioController { get; }

Property Value

GpioController

Length

The length of the segment; the number of GPIO pins it exposes.

public int Length { get; }

Property Value

int

OutputEnable

Sets a value indicating whether output register is high or low-impedance state. Enables or disables register outputs, but does not delete values. Requires use of GPIO controller.

public bool OutputEnable { set; }

Property Value

bool

SpiDevice

SPI device.

protected SpiDevice? SpiDevice { get; }

Property Value

SpiDevice

UsesGpio

Reports if shift register is connected with GPIO.

public bool UsesGpio { get; }

Property Value

bool

UsesSpi

Reports if shift register is connected with SPI.

public bool UsesSpi { get; }

Property Value

bool

Methods

Dispose()

Cleanup. Failing to dispose this class, especially when callbacks are active, may lead to undefined behavior.

public void Dispose()

Latch()

Latches values in data register to output pi. Requires use of GPIO controller.

public void Latch()

ShiftBit(PinValue)

Writes PinValue value to storage register. This will shift existing values to the next storage slot. Does not latch. Requires use of GPIO controller.

public void ShiftBit(PinValue value)

Parameters

value PinValue

Value to write.

ShiftByte(byte, bool)

Shifts a byte -- 8 bits -- to the storage register. Assumes register bit length evenly divisible by 8. Pushes / overwrites any existing values.

public void ShiftByte(byte value, bool latch = true)

Parameters

value byte

Value to write.

latch bool

Should latch, default true.

ShiftClear()

Shifts zeros. Will dim all connected LEDs, for example. Assumes register bit length evenly divisible by 8. Supports GPIO controller or SPI device.

public void ShiftClear()

Write(byte)

Writes discrete underlying bits to a virtual segment. Writes each bit, left to right. Least significant bit will written to index 0. Does not display output.

public void Write(byte value)

Parameters

value byte

Value to write.

Write(SpanByte)

Writes discrete underlying bits to a virtual output. Writes each byte, left to right. Least significant bit will written to index 0. Does not display output.

public void Write(SpanByte value)

Parameters

value SpanByte

Value to write.