Control Surface  1.2.0
MIDI Control Surface library for Arduino
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes | Static Private Attributes | List of all members
ShiftRegisterOut< N > Class Template Reference

A class for serial-in/parallel-out shift registers, like the 74HC595. More...

#include <AH/Hardware/ExtendedInputOutput/ShiftRegisterOut.hpp>

+ Inheritance diagram for ShiftRegisterOut< N >:
+ Collaboration diagram for ShiftRegisterOut< N >:

Public Types

using Mutex = typename std::conditional< false, DefaultMutEx, EmptyMutex >::type
 
using LockGuard = typename std::conditional< false, DefaultLockGuard< Mutex >, EmptyLockGuard< Mutex > >::type
 

Public Member Functions

 ShiftRegisterOut (pin_t dataPin, pin_t clockPin, pin_t latchPin, BitOrder_t bitOrder=MSBFIRST)
 Create a new ShiftRegisterOut object with a shift register connected to the given pins, 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...
 
int digitalRead (pin_t pin) override
 Get the current state of a given output pin. More...
 
int 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...
 
static MutexgetMutex ()
 

Protected Attributes

const pin_t latchPin
 
const BitOrder_t bitOrder
 
BitArray< N > buffer
 
bool dirty = true
 
ExtendedIOElementnext
 
ExtendedIOElementprevious
 

Static Protected Attributes

static DoublyLinkedList< ExtendedIOElementupdatables
 
static Mutex mutex
 

Private Attributes

const pin_t dataPin
 
const pin_t clockPin
 
const pin_t start
 
const pin_t end
 

Static Private Attributes

static pin_t offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS
 

Main initialization and updating methods

static void applyToAll (const LockGuard &, void(Derived::*method)(Args &&...), Args &&... args)
 
static void applyToAll (void(Derived::*method)(Args &&...), Args &&... args)
 

Enabling and disabling updatables

void enable (const LockGuard &lock)
 Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More...
 
void enable ()
 Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More...
 
void disable (const LockGuard &lock)
 Disable this updatable: remove it from the linked list of instances, so it no longer 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 LockGuard &) const
 Check if this updatable is enabled. More...
 
bool isEnabled ()
 Check if this updatable is enabled. More...
 
void moveDown (const LockGuard &)
 Move down this element in the list. 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...
 

Detailed Description

template<uint8_t N>
class AH::ShiftRegisterOut< N >

A class for serial-in/parallel-out shift registers, like the 74HC595.

Definition at line 23 of file ShiftRegisterOut.hpp.

Member Typedef Documentation

◆ Mutex

using Mutex = typename std::conditional<false , DefaultMutEx, EmptyMutex>::type
inherited

Definition at line 36 of file Updatable.hpp.

◆ LockGuard

using LockGuard = typename std::conditional<false , DefaultLockGuard<Mutex>, EmptyLockGuard<Mutex> >::type
inherited

Definition at line 38 of file Updatable.hpp.

Constructor & Destructor Documentation

◆ ShiftRegisterOut()

ShiftRegisterOut ( pin_t  dataPin,
pin_t  clockPin,
pin_t  latchPin,
BitOrder_t  bitOrder = MSBFIRST 
)

Create a new ShiftRegisterOut object with a shift register connected to the given pins, 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:

clockPin >───────────┬──────────────────────┬───────── ⋯
┏━━━━━━━┷━━━━━━━┓ ┏━━━━━━━┷━━━━━━━┓
┃ SH_CP ┃ ┃ SH_CP ┃
dataPin >───┨ DS Q7S ┠──────┨ DS Q7S ┠─ ⋯
┃ ST_CP ┃ ┃ ST_CP ┃
┗━━━━━━━┯━━━━━━━┛ ┗━━━━━━━┯━━━━━━━┛
latchPin >───────────┴──────────────────────┴───────── ⋯
Parameters
dataPinThe digital output pin connected to the serial data input (DS or SER) of the shift register.
clockPinThe digital output pin connected to the clock input (SH_CP or SRCLK) of the shift register.
latchPinThe digital output pin connected to the latch pin (ST_CP or RCLK) of the shift register.
bitOrderEither MSBFIRST (most significant bit first) or LSBFIRST (least significant bit first).

Definition at line 7 of file ShiftRegisterOut.ipp.

Member Function Documentation

◆ begin()

void begin
overridevirtual

Initialize the shift register.


Set the data and clock pins to output mode, and set all shift register outputs to LOW.

Implements ExtendedIOElement.

Definition at line 13 of file ShiftRegisterOut.ipp.

◆ updateBufferedOutputs()

void updateBufferedOutputs
overridevirtual

Write the state buffer to the physical outputs.

Implements ExtendedIOElement.

Definition at line 21 of file ShiftRegisterOut.ipp.

◆ pinMode()

void pinMode ( pin_t  pin,
PinMode_t  mode 
)
inlineoverridevirtualinherited

The pinMode function is not implemented because the mode is OUTPUT by definition.

Reimplemented from ExtendedIOElement.

Definition at line 46 of file ShiftRegisterOutBase.hpp.

◆ pinModeBuffered()

void pinModeBuffered ( pin_t  pin,
PinMode_t  mode 
)
inlineoverridevirtualinherited

The pinMode function is not implemented because the mode is OUTPUT by definition.

Implements ExtendedIOElement.

Definition at line 55 of file ShiftRegisterOutBase.hpp.

◆ digitalWrite()

void digitalWrite ( pin_t  pin,
PinStatus_t  val 
)
overridevirtualinherited

Set the state of a given output pin.

Parameters
pinThe shift register pin to set.
valThe value to set the pin to. (Either HIGH (1) or LOW (0))

Reimplemented from ExtendedIOElement.

Definition at line 13 of file ShiftRegisterOutBase.ipp.

◆ digitalWriteBuffered()

void digitalWriteBuffered ( pin_t  pin,
PinStatus_t  val 
)
overridevirtualinherited

Set the output of a given pin in the software buffer.

The buffer is written to the ExtIO device when updateBufferedOutputs is called.

Parameters
pinThe shift register pin to set.
valThe value to set the pin to. (Either HIGH (1) or LOW (0))

Implements ExtendedIOElement.

Definition at line 20 of file ShiftRegisterOutBase.ipp.

◆ digitalRead()

int digitalRead ( pin_t  pin)
overridevirtualinherited

Get the current state of a given output pin.

Parameters
pinThe shift register pin to read from.
Return values
0The state of the pin is LOW.
1The state of the pin is HIGH.

Reimplemented from ExtendedIOElement.

Definition at line 26 of file ShiftRegisterOutBase.ipp.

◆ digitalReadBuffered()

int digitalReadBuffered ( pin_t  pin)
inlineoverridevirtualinherited

Get the current state of a given output pin.

Parameters
pinThe shift register pin to read from.
Return values
0The state of the pin is LOW.
1The state of the pin is HIGH.

Implements ExtendedIOElement.

Definition at line 95 of file ShiftRegisterOutBase.hpp.

◆ analogRead()

analog_t analogRead ( pin_t  pin)
inlineoverridevirtualinherited

The analogRead function is deprecated because a shift is always digital.

Parameters
pinThe shift register pin to read from.
Return values
0The state of the pin is LOW.
1023The state of the pin is HIGH.

Reimplemented from ExtendedIOElement.

Definition at line 109 of file ShiftRegisterOutBase.hpp.

◆ analogReadBuffered()

analog_t analogReadBuffered ( pin_t  pin)
inlineoverridevirtualinherited

The analogRead function is deprecated because a shift is always digital.

Parameters
pinThe shift register pin to read from.
Return values
0The state of the pin is LOW.
1023The state of the pin is HIGH.

Implements ExtendedIOElement.

Definition at line 116 of file ShiftRegisterOutBase.hpp.

◆ analogWrite()

void analogWrite ( pin_t  pin,
analog_t  val 
)
inlineoverridevirtualinherited

The analogWrite function is not deprecated because a shift is always digital.

Parameters
pinThe shift register pin to set.
valThe 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 131 of file ShiftRegisterOutBase.hpp.

◆ analogWriteBuffered()

void analogWriteBuffered ( pin_t  pin,
analog_t  val 
)
inlineoverridevirtualinherited

The analogWrite function is not deprecated because a shift is always digital.

Parameters
pinThe shift register pin to set.
valThe 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 139 of file ShiftRegisterOutBase.hpp.

◆ updateBufferedInputs()

void updateBufferedInputs ( )
inlineoverridevirtualinherited

Shift registers don't have an input buffer.

Implements ExtendedIOElement.

Definition at line 147 of file ShiftRegisterOutBase.hpp.

◆ red()

pin_t red ( pin_t  id)
inherited

Get the red output pin of the given LED.

Parameters
idThe zero-based LED number.

Definition at line 42 of file ShiftRegisterOutBase.ipp.

◆ redPins()

Array< pin_t, N/3 > redPins
inherited

Get an array containing all pins with red LEDs.

Definition at line 47 of file ShiftRegisterOutBase.ipp.

◆ green()

pin_t green ( pin_t  id)
inherited

Get the green output pin of the given LED.

Parameters
idThe zero-based LED number.

Definition at line 31 of file ShiftRegisterOutBase.ipp.

◆ greenPins()

Array< pin_t, N/3 > greenPins
inherited

Get an array containing all pins with green LEDs.

Definition at line 36 of file ShiftRegisterOutBase.ipp.

◆ blue()

pin_t blue ( pin_t  id)
inherited

Get the blue output pin of the given LED.

Parameters
idThe zero-based LED number.

Definition at line 53 of file ShiftRegisterOutBase.ipp.

◆ bluePins()

Array< pin_t, N/3 > bluePins
inherited

Get an array containing all pins with blue LEDs.

Definition at line 58 of file ShiftRegisterOutBase.ipp.

◆ pins()

Array<pin_t, N> pins ( ) const
inlineinherited

Get an array containing all pins of the element.

Definition at line 27 of file StaticSizeExtendedIOElement.hpp.

◆ length()

static constexpr uint16_t length ( )
inlinestaticconstexprinherited

Definition at line 31 of file StaticSizeExtendedIOElement.hpp.

◆ beginAll()

void beginAll ( )
staticinherited

Initialize all extended IO elements.

Definition at line 20 of file ExtendedIOElement.cpp.

◆ updateAllBufferedOutputs()

void updateAllBufferedOutputs ( )
staticinherited

Write the internal states to the physical outputs for all extended IO elements.

Definition at line 24 of file ExtendedIOElement.cpp.

◆ updateAllBufferedInputs()

void updateAllBufferedInputs ( )
staticinherited

Read the physical state into the input buffers for all extended IO elements.

Definition at line 28 of file ExtendedIOElement.cpp.

◆ pin()

pin_t pin ( pin_t  pin) const
inherited

Get the extended IO pin number of a given physical pin of this extended IO element.

Parameters
pinThe zero-based physical pin number of this IO element.
Returns
The global, unique extended IO pin number for the given pin.

Definition at line 32 of file ExtendedIOElement.cpp.

◆ operator[]()

pin_t operator[] ( pin_t  pin) const
inherited

Get the extended IO pin number of a given physical pin of this extended IO element.


It is alias for ExtendedIOElement::pin.

Parameters
pinThe zero-based physical pin number of this IO element.
Returns
The global, unique extended IO pin number for the given pin.

Definition at line 47 of file ExtendedIOElement.cpp.

◆ getLength()

pin_t getLength ( ) const
inherited

Get the number of pins this IO element has.

Returns
The number of pins this IO element has.

Definition at line 49 of file ExtendedIOElement.cpp.

◆ getEnd()

pin_t getEnd ( ) const
inherited

Get the largest global extended IO pin number that belongs to this extended IO element.

Definition at line 51 of file ExtendedIOElement.cpp.

◆ getStart()

pin_t getStart ( ) const
inherited

Get the smallest global extended IO pin number that belongs to this extended IO element.

Definition at line 53 of file ExtendedIOElement.cpp.

◆ getAll()

DoublyLinkedList< ExtendedIOElement > & getAll ( )
staticinherited

Get the list of all Extended IO elements.

Definition at line 55 of file ExtendedIOElement.cpp.

◆ getMutex()

static Mutex& getMutex ( )
inlinestaticinherited

Definition at line 79 of file Updatable.hpp.

◆ applyToAll() [1/2]

static void applyToAll ( const LockGuard ,
void(Derived::*)(Args &&...)  method,
Args &&...  args 
)
inlinestaticinherited

Definition at line 85 of file Updatable.hpp.

◆ applyToAll() [2/2]

static void applyToAll ( void(Derived::*)(Args &&...)  method,
Args &&...  args 
)
inlinestaticinherited

Definition at line 93 of file Updatable.hpp.

◆ enable() [1/5]

void enable ( const LockGuard lock)
inlineinherited

Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.

Definition at line 106 of file Updatable.hpp.

◆ enable() [2/5]

void enable ( )
inlineinherited

Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.

Definition at line 115 of file Updatable.hpp.

◆ enable() [3/5]

static void enable ( UpdatableCRTP< ExtendedIOElement > *  element)
inlinestaticinherited

Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.

Definition at line 144 of file Updatable.hpp.

◆ enable() [4/5]

static void enable ( UpdatableCRTP< ExtendedIOElement > &  element)
inlinestaticinherited

Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.

Definition at line 146 of file Updatable.hpp.

◆ enable() [5/5]

static void enable ( U(&)  array[N])
inlinestaticinherited

Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.

Definition at line 149 of file Updatable.hpp.

◆ disable() [1/5]

void disable ( const LockGuard lock)
inlineinherited

Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.

Definition at line 119 of file Updatable.hpp.

◆ disable() [2/5]

void disable ( )
inlineinherited

Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.

Definition at line 128 of file Updatable.hpp.

◆ disable() [3/5]

static void disable ( UpdatableCRTP< ExtendedIOElement > *  element)
inlinestaticinherited

Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.

Definition at line 155 of file Updatable.hpp.

◆ disable() [4/5]

static void disable ( UpdatableCRTP< ExtendedIOElement > &  element)
inlinestaticinherited

Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.

Definition at line 157 of file Updatable.hpp.

◆ disable() [5/5]

static void disable ( U(&)  array[N])
inlinestaticinherited

Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.

Definition at line 160 of file Updatable.hpp.

◆ isEnabled() [1/2]

bool isEnabled ( const LockGuard ) const
inlineinherited

Check if this updatable is enabled.

Note
Assumes that the updatable is not added to a different linked list by the user.

Definition at line 136 of file Updatable.hpp.

◆ isEnabled() [2/2]

bool isEnabled ( )
inlineinherited

Check if this updatable is enabled.

Note
Assumes that the updatable is not added to a different linked list by the user.

Definition at line 141 of file Updatable.hpp.

◆ moveDown() [1/2]

void moveDown ( const LockGuard )
inlineinherited

Move down this element in the list.

Definition at line 166 of file Updatable.hpp.

◆ moveDown() [2/2]

void moveDown ( )
inlineinherited

Move down this element in the list.

Definition at line 168 of file Updatable.hpp.

Member Data Documentation

◆ dataPin

const pin_t dataPin
private

Definition at line 71 of file ShiftRegisterOut.hpp.

◆ clockPin

const pin_t clockPin
private

Definition at line 72 of file ShiftRegisterOut.hpp.

◆ latchPin

const pin_t latchPin
protectedinherited

Definition at line 189 of file ShiftRegisterOutBase.hpp.

◆ bitOrder

const BitOrder_t bitOrder
protectedinherited

Definition at line 190 of file ShiftRegisterOutBase.hpp.

◆ buffer

BitArray<N> buffer
protectedinherited

Definition at line 192 of file ShiftRegisterOutBase.hpp.

◆ dirty

bool dirty = true
protectedinherited

Definition at line 193 of file ShiftRegisterOutBase.hpp.

◆ start

const pin_t start
privateinherited

Definition at line 260 of file ExtendedIOElement.hpp.

◆ end

const pin_t end
privateinherited

Definition at line 261 of file ExtendedIOElement.hpp.

◆ offset

pin_t offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS
staticprivateinherited

Definition at line 262 of file ExtendedIOElement.hpp.

◆ updatables

DoublyLinkedList< ExtendedIOElement > updatables
staticprotectedinherited

Definition at line 173 of file Updatable.hpp.

◆ mutex

UpdatableCRTP< ExtendedIOElement , false >::Mutex mutex
staticprotectedinherited

Definition at line 174 of file Updatable.hpp.

◆ next

ExtendedIOElement * next
protectedinherited

Definition at line 323 of file LinkedList.hpp.

◆ previous

ExtendedIOElement * previous
protectedinherited

Definition at line 324 of file LinkedList.hpp.


The documentation for this class was generated from the following files:
AH::ShiftRegisterOut::clockPin
const pin_t clockPin
Definition: ShiftRegisterOut.hpp:72
AH::ShiftRegisterOut::dataPin
const pin_t dataPin
Definition: ShiftRegisterOut.hpp:71
AH::ShiftRegisterOutBase::latchPin
const pin_t latchPin
Definition: ShiftRegisterOutBase.hpp:189