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
pinMappingShiftRegisterPinMappingThe pin mapping to use by the binding.
bitLengthintBit length of register, including chained registers.
gpioControllerGpioControllerThe GPIO Controller used for interrupt handling.
shouldDisposeboolTrue (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
spiDeviceSpiDeviceSpiDevice used for serial communication.
bitLengthintBit length of register, including chained registers.
Properties
BitLength
Bit length across all connected registers.
public int BitLength { get; }
Property Value
GpioController
GPIO controller.
protected GpioController? GpioController { get; }
Property Value
Length
The length of the segment; the number of GPIO pins it exposes.
public int Length { get; }
Property Value
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
SpiDevice
SPI device.
protected SpiDevice? SpiDevice { get; }
Property Value
UsesGpio
Reports if shift register is connected with GPIO.
public bool UsesGpio { get; }
Property Value
UsesSpi
Reports if shift register is connected with SPI.
public bool UsesSpi { get; }
Property Value
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
valuePinValueValue 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
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
valuebyteValue 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
valueSpanByteValue to write.