#include <AH/Hardware/ExtendedInputOutput/SPIShiftRegisterOut.hpp>
A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bus.
N | The number of bits in total. Usually, shift registers (e.g. the 74HC595) have eight bits per chip, so length = 8 * k where k is the number of cascaded chips. |
SPIDriver | The SPI class to use. Usually, the default is fine. |
Definition at line 28 of file SPIShiftRegisterOut.hpp.
Enabling and disabling updatables | |
void | enable () |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More... | |
void | disable () |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More... | |
bool | isEnabled () const |
Check if this updatable is enabled. More... | |
void | moveDown () |
Move down this element in the list. More... | |
static void | enable (UpdatableCRTP *element) |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More... | |
static void | enable (UpdatableCRTP &element) |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More... | |
static void | enable (U(&array)[N]) |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More... | |
static void | disable (UpdatableCRTP *element) |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More... | |
static void | disable (UpdatableCRTP &element) |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More... | |
static void | disable (U(&array)[N]) |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More... | |
Public Member Functions | |
SPIShiftRegisterOut (SPIDriver spi, pin_t latchPin=SS, BitOrder_t bitOrder=MSBFIRST) | |
Create a new SPIShiftRegisterOut object with a given bit order, and a given number of outputs. More... | |
void | begin () override |
Initialize the shift register. More... | |
void | updateBufferedOutputs () override |
Write the state buffer to the physical outputs. More... | |
void | pinMode (pin_t pin, PinMode_t mode) override __attribute__((deprecated)) |
The pinMode function is not implemented because the mode is OUTPUT by definition. More... | |
void | pinModeBuffered (pin_t pin, PinMode_t mode) override __attribute__((deprecated)) |
The pinMode function is not implemented because the mode is OUTPUT by definition. More... | |
void | digitalWrite (pin_t pin, PinStatus_t val) override |
Set the state of a given output pin. More... | |
void | digitalWriteBuffered (pin_t pin, PinStatus_t val) override |
Set the output of a given pin in the software buffer. More... | |
PinStatus_t | digitalRead (pin_t pin) override |
Get the current state of a given output pin. More... | |
PinStatus_t | digitalReadBuffered (pin_t pin) override |
Get the current state of a given output pin. More... | |
analog_t | analogRead (pin_t pin) override __attribute__((deprecated)) |
The analogRead function is deprecated because a shift is always digital. More... | |
analog_t | analogReadBuffered (pin_t pin) override __attribute__((deprecated)) |
The analogRead function is deprecated because a shift is always digital. More... | |
void | analogWrite (pin_t pin, analog_t val) override __attribute__((deprecated)) |
The analogWrite function is not deprecated because a shift is always digital. More... | |
void | analogWriteBuffered (pin_t pin, analog_t val) override __attribute__((deprecated)) |
The analogWrite function is not deprecated because a shift is always digital. More... | |
void | updateBufferedInputs () override |
Shift registers don't have an input buffer. More... | |
pin_t | red (pin_t id) |
Get the red output pin of the given LED. More... | |
Array< pin_t, N/3 > | redPins () |
Get an array containing all pins with red LEDs. More... | |
pin_t | green (pin_t id) |
Get the green output pin of the given LED. More... | |
Array< pin_t, N/3 > | greenPins () |
Get an array containing all pins with green LEDs. More... | |
pin_t | blue (pin_t id) |
Get the blue output pin of the given LED. More... | |
Array< pin_t, N/3 > | bluePins () |
Get an array containing all pins with blue LEDs. More... | |
Array< pin_t, N > | pins () const |
Get an array containing all pins of the element. More... | |
pin_t | pin (pin_t pin) const |
Get the extended IO pin number of a given physical pin of this extended IO element. More... | |
pin_t | operator[] (pin_t pin) const |
Get the extended IO pin number of a given physical pin of this extended IO element. More... | |
pin_t | getLength () const |
Get the number of pins this IO element has. More... | |
pin_t | getEnd () const |
Get the largest global extended IO pin number that belongs to this extended IO element. More... | |
pin_t | getStart () const |
Get the smallest global extended IO pin number that belongs to this extended IO element. More... | |
Static Public Member Functions | |
static constexpr uint16_t | length () |
static void | beginAll () |
Initialize all extended IO elements. More... | |
static void | updateAllBufferedOutputs () |
Write the internal states to the physical outputs for all extended IO elements. More... | |
static void | updateAllBufferedInputs () |
Read the physical state into the input buffers for all extended IO elements. More... | |
static DoublyLinkedList< ExtendedIOElement > & | getAll () |
Get the list of all Extended IO elements. More... | |
Public Attributes | |
SPISettings | settings {SPI_MAX_SPEED, this->bitOrder, SPI_MODE0} |
Protected Attributes | |
const pin_t | latchPin |
const BitOrder_t | bitOrder |
BitArray< N > | buffer |
bool | dirty = true |
ExtendedIOElement * | next |
ExtendedIOElement * | previous |
Static Protected Attributes | |
static DoublyLinkedList< ExtendedIOElement > | updatables |
Private Attributes | |
SPIDriver | spi |
const pin_t | start |
const pin_t | end |
Static Private Attributes | |
static pin_t | offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS |
SPIShiftRegisterOut | ( | SPIDriver | spi, |
pin_t | latchPin = SS , |
||
BitOrder_t | bitOrder = MSBFIRST |
||
) |
Create a new SPIShiftRegisterOut object with a given bit order, and a given number of outputs.
Multiple shift registers can be cascaded by connecting the serial output of the first one to the input of the second one:
spi | The SPI interface to use. |
latchPin | The digital output pin connected to the latch pin (ST_CP or RCLK) of the shift register. |
bitOrder | Either MSBFIRST (most significant bit first) or LSBFIRST (least significant bit first). |
Definition at line 13 of file SPIShiftRegisterOut.ipp.
|
overridevirtual |
Initialize the shift register.
Setup the SPI interface, set the CS pin to output mode, and set all shift register outputs to LOW
.
Implements ExtendedIOElement.
Definition at line 20 of file SPIShiftRegisterOut.ipp.
|
overridevirtual |
Write the state buffer to the physical outputs.
Implements ExtendedIOElement.
Definition at line 27 of file SPIShiftRegisterOut.ipp.
The pinMode function is not implemented because the mode is OUTPUT
by definition.
Reimplemented from ExtendedIOElement.
Definition at line 43 of file ShiftRegisterOutBase.hpp.
The pinMode function is not implemented because the mode is OUTPUT
by definition.
Implements ExtendedIOElement.
Definition at line 52 of file ShiftRegisterOutBase.hpp.
|
overridevirtualinherited |
Set the state of a given output pin.
pin | The shift register pin to set. |
val | The value to set the pin to. (Either HIGH (1) or LOW (0)) |
Reimplemented from ExtendedIOElement.
Definition at line 13 of file ShiftRegisterOutBase.ipp.
|
overridevirtualinherited |
Set the output of a given pin in the software buffer.
The buffer is written to the ExtIO device when updateBufferedOutputs is called.
pin | The shift register pin to set. |
val | The value to set the pin to. (Either HIGH (1) or LOW (0)) |
Implements ExtendedIOElement.
Definition at line 20 of file ShiftRegisterOutBase.ipp.
|
overridevirtualinherited |
Get the current state of a given output pin.
pin | The shift register pin to read from. |
0 | The state of the pin is LOW . |
1 | The state of the pin is HIGH . |
Reimplemented from ExtendedIOElement.
Definition at line 26 of file ShiftRegisterOutBase.ipp.
|
inlineoverridevirtualinherited |
Get the current state of a given output pin.
pin | The shift register pin to read from. |
0 | The state of the pin is LOW . |
1 | The state of the pin is HIGH . |
Implements ExtendedIOElement.
Definition at line 92 of file ShiftRegisterOutBase.hpp.
The analogRead function is deprecated because a shift is always digital.
pin | The shift register pin to read from. |
0 | The state of the pin is LOW . |
1023 | The state of the pin is HIGH . |
Reimplemented from ExtendedIOElement.
Definition at line 106 of file ShiftRegisterOutBase.hpp.
The analogRead function is deprecated because a shift is always digital.
pin | The shift register pin to read from. |
0 | The state of the pin is LOW . |
1023 | The state of the pin is HIGH . |
Implements ExtendedIOElement.
Definition at line 113 of file ShiftRegisterOutBase.hpp.
The analogWrite function is not deprecated because a shift is always digital.
pin | The shift register pin to set. |
val | The value to set the pin to. A value greater or equal to 0x80 will set the pin to a HIGH state, a value less than 0x80 will set the pin to a LOW state. |
Reimplemented from ExtendedIOElement.
Definition at line 128 of file ShiftRegisterOutBase.hpp.
The analogWrite function is not deprecated because a shift is always digital.
pin | The shift register pin to set. |
val | The value to set the pin to. A value greater or equal to 0x80 will set the pin to a HIGH state, a value less than 0x80 will set the pin to a LOW state. |
Implements ExtendedIOElement.
Definition at line 136 of file ShiftRegisterOutBase.hpp.
|
inlineoverridevirtualinherited |
Shift registers don't have an input buffer.
Implements ExtendedIOElement.
Definition at line 144 of file ShiftRegisterOutBase.hpp.
Get the red output pin of the given LED.
id | The zero-based LED number. |
Definition at line 42 of file ShiftRegisterOutBase.ipp.
Get an array containing all pins with red LEDs.
Definition at line 47 of file ShiftRegisterOutBase.ipp.
Get the green output pin of the given LED.
id | The zero-based LED number. |
Definition at line 31 of file ShiftRegisterOutBase.ipp.
Get an array containing all pins with green LEDs.
Definition at line 36 of file ShiftRegisterOutBase.ipp.
Get the blue output pin of the given LED.
id | The zero-based LED number. |
Definition at line 53 of file ShiftRegisterOutBase.ipp.
Get an array containing all pins with blue LEDs.
Definition at line 58 of file ShiftRegisterOutBase.ipp.
Get an array containing all pins of the element.
Definition at line 24 of file StaticSizeExtendedIOElement.hpp.
|
inlinestaticconstexprinherited |
Definition at line 28 of file StaticSizeExtendedIOElement.hpp.
|
staticinherited |
Initialize all extended IO elements.
Definition at line 17 of file ExtendedIOElement.cpp.
|
staticinherited |
Write the internal states to the physical outputs for all extended IO elements.
Definition at line 21 of file ExtendedIOElement.cpp.
|
staticinherited |
Read the physical state into the input buffers for all extended IO elements.
Definition at line 25 of file ExtendedIOElement.cpp.
Get the extended IO pin number of a given physical pin of this extended IO element.
pin | The zero-based physical pin number of this IO element. |
Definition at line 29 of file ExtendedIOElement.cpp.
Get the extended IO pin number of a given physical pin of this extended IO element.
It is alias for ExtendedIOElement::pin
.
pin | The zero-based physical pin number of this IO element. |
Definition at line 44 of file ExtendedIOElement.cpp.
|
inherited |
Get the number of pins this IO element has.
Definition at line 46 of file ExtendedIOElement.cpp.
|
inherited |
Get the largest global extended IO pin number that belongs to this extended IO element.
Definition at line 48 of file ExtendedIOElement.cpp.
|
inherited |
Get the smallest global extended IO pin number that belongs to this extended IO element.
Definition at line 50 of file ExtendedIOElement.cpp.
|
staticinherited |
Get the list of all Extended IO elements.
Definition at line 52 of file ExtendedIOElement.cpp.
|
inlineinherited |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 96 of file Updatable.hpp.
|
inlinestaticinherited |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 125 of file Updatable.hpp.
|
inlinestaticinherited |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 127 of file Updatable.hpp.
|
inlinestaticinherited |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 130 of file Updatable.hpp.
|
inlineinherited |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 106 of file Updatable.hpp.
|
inlinestaticinherited |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 136 of file Updatable.hpp.
|
inlinestaticinherited |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 138 of file Updatable.hpp.
|
inlinestaticinherited |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 141 of file Updatable.hpp.
|
inlineinherited |
Check if this updatable is enabled.
Definition at line 120 of file Updatable.hpp.
|
inlineinherited |
Move down this element in the list.
Definition at line 147 of file Updatable.hpp.
|
private |
Definition at line 72 of file SPIShiftRegisterOut.hpp.
SPISettings settings {SPI_MAX_SPEED, this->bitOrder, SPI_MODE0} |
Definition at line 75 of file SPIShiftRegisterOut.hpp.
|
protectedinherited |
Definition at line 186 of file ShiftRegisterOutBase.hpp.
|
protectedinherited |
Definition at line 187 of file ShiftRegisterOutBase.hpp.
|
protectedinherited |
Definition at line 189 of file ShiftRegisterOutBase.hpp.
|
protectedinherited |
Definition at line 190 of file ShiftRegisterOutBase.hpp.
|
privateinherited |
Definition at line 267 of file ExtendedIOElement.hpp.
|
privateinherited |
Definition at line 268 of file ExtendedIOElement.hpp.
|
staticprivateinherited |
Definition at line 269 of file ExtendedIOElement.hpp.
|
staticprotectedinherited |
Definition at line 152 of file Updatable.hpp.
|
protectedinherited |
Definition at line 320 of file LinkedList.hpp.
|
protectedinherited |
Definition at line 321 of file LinkedList.hpp.