Arduino Filters master
Filter library for Arduino
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes | Static Private Attributes | List of all members
ExtendedIOElement Class Referenceabstract

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

Detailed Description

An abstract base class for Extended Input/Output elements.

The limited number of IO pins of the Arduino can be extended by adding multiplexers, shift registers, IO expanders, etc.
ExtendedIOElement serves as a base class for all these expanders.

The pins of each extended IO element are mapped to a pin number greater than the greatest Arduino pin number.
You can supply this pin number to the IO functions in the ExtIO namespace.
If the pin number corresponds to an actual Arduino pin, the default Arduino IO function (digitalRead, digitalWrite, ...) will be called.
If the pin is not an Arduino pin, it is an extended IO pin number, so the extended IO element that this pin belongs to is looked up, and the IO function for this element is executed with the correct pin number.

For example: Imagine an Arduino with 20 pins (e.g. the Arduino UNO). Pins 0 - 19 will correspond to the Arduino pins, and ExtIO::digitalRead(pin) will have the exact same effect as the standard digitalRead(pin) function (albeit a little slower).
Now, we'll add two 8-channel analog multiplexers, let's call them mux1 and mux2.
The first pin (pin 0) of mux1 will be extended IO pin number 20, the last pin (pin 7) of mux1 will be extended IO pin number 27, etc. The first pin of mux2 will be extended IO pin number 28, you get the idea. If you now call ExtIO::digitalRead(mux1.#pin (7)) or ExtIO::digitalRead(27), both will be translated to mux1.digitalRead(7).

The number of extended IO elements is limited only by the size of pin_t. However, looking up the extended IO element for a given extended IO pin number uses linear search, so that might add some noticable overhead for large pin numbers.

The design here is a compromise: saving a pointer to each extended IO element to find it directly would be much faster than having to search all elements each time. On the other hand, it would require each pin_t variable to be at least one byte larger. Since almost all other classes in this library store pin variables, the memory penalty would be too large, especially on AVR microcontrollers.
Another reason to do it this way, is that this approach is still fast enough to make sure it is not noticable to human users.

Definition at line 63 of file ExtendedIOElement.hpp.

+ Inheritance diagram for ExtendedIOElement:
+ Collaboration diagram for ExtendedIOElement:

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

virtual void pinMode (pin_t pin, PinMode_t mode)
 Set the mode of a given pin. More...
 
virtual void pinModeBuffered (pin_t pin, PinMode_t mode)=0
 Set the mode of a given pin in the software buffer. More...
 
virtual void digitalWrite (pin_t pin, PinStatus_t state)
 Set the output of the given pin to the given state. More...
 
virtual void digitalWriteBuffered (pin_t pin, PinStatus_t state)=0
 Set the output of a given pin in the software buffer. More...
 
virtual PinStatus_t digitalRead (pin_t pin)
 Read the state of the given pin. More...
 
virtual PinStatus_t digitalReadBuffered (pin_t pin)=0
 Read the state of the given pin from the software buffer. More...
 
virtual void analogWrite (pin_t pin, analog_t val)
 Write an analog (or PWM) value to the given pin. More...
 
virtual void analogWriteBuffered (pin_t pin, analog_t val)=0
 Write an analog (or PWM) value to the software buffer given pin. More...
 
virtual analog_t analogRead (pin_t pin)
 Read the analog value of the given pin. More...
 
virtual analog_t analogReadBuffered (pin_t pin)=0
 Read the analog value of the given pin from the software buffer. More...
 
virtual void begin ()=0
 Initialize the extended IO element. More...
 
virtual void updateBufferedOutputs ()=0
 Write the internal state to the physical outputs. More...
 
virtual void updateBufferedInputs ()=0
 Read the physical state into the input buffers. 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 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...
 

Protected Member Functions

 ExtendedIOElement (pin_t length)
 Create an ExtendedIOElement with the given number of pins. More...
 
 ExtendedIOElement (const ExtendedIOElement &)=delete
 Copying not allowed. More...
 
ExtendedIOElementoperator= (const ExtendedIOElement &)=delete
 Copying not allowed. More...
 
 ExtendedIOElement (ExtendedIOElement &&)=default
 Move constructor. More...
 
ExtendedIOElementoperator= (ExtendedIOElement &&)=delete
 Move assignment. More...
 

Protected Attributes

ExtendedIOElementnext
 
ExtendedIOElementprevious
 

Static Protected Attributes

static DoublyLinkedList< ExtendedIOElementupdatables
 

Private Attributes

const pin_t length
 
const pin_t start
 
const pin_t end
 

Static Private Attributes

static pin_t offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS
 

Constructor & Destructor Documentation

◆ ExtendedIOElement() [1/3]

ExtendedIOElement ( pin_t  length)
protected

Create an ExtendedIOElement with the given number of pins.

Parameters
lengthThe number of pins this element has.

Definition at line 10 of file ExtendedIOElement.cpp.

◆ ExtendedIOElement() [2/3]

ExtendedIOElement ( const ExtendedIOElement )
protecteddelete

Copying not allowed.

◆ ExtendedIOElement() [3/3]

ExtendedIOElement ( ExtendedIOElement &&  )
protecteddefault

Move constructor.

Member Function Documentation

◆ operator=() [1/2]

ExtendedIOElement & operator= ( const ExtendedIOElement )
protecteddelete

Copying not allowed.

◆ operator=() [2/2]

ExtendedIOElement & operator= ( ExtendedIOElement &&  )
protecteddelete

Move assignment.

◆ pinMode()

virtual void pinMode ( pin_t  pin,
PinMode_t  mode 
)
inlinevirtual

Set the mode of a given pin.

Note
This function might not be implemented by all subclasses.
Some extended IO types, such as shift registers, can only be used as outputs.
On others, it might be implemented, but it could impact all pins of the IO element. For example, enabling the internal pull-up resistor on an analog multiplexer affects all pins of the mux.
Parameters
pinThe (zero-based) pin of this IO element.
modeThe mode to set the pin to (e.g. INPUT, OUTPUT or INPUT_PULLUP).

Reimplemented in MAX7219< NumChips, SPIDriver >, and ShiftRegisterOutBase< N >.

Definition at line 100 of file ExtendedIOElement.hpp.

◆ pinModeBuffered()

virtual void pinModeBuffered ( pin_t  pin,
PinMode_t  mode 
)
pure virtual

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

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

Note
This function might not be implemented by all subclasses.
Some extended IO types, such as shift registers, can only be used as outputs.
On others, it might be implemented, but it could impact all pins of the IO element. For example, enabling the internal pull-up resistor on an analog multiplexer affects all pins of the mux.
Parameters
pinThe (zero-based) pin of this IO element.
modeThe mode to set the pin to (e.g. INPUT, OUTPUT or INPUT_PULLUP).

Implemented in MCP23017< WireType >, MAX7219< NumChips, SPIDriver >, and ShiftRegisterOutBase< N >.

◆ digitalWrite()

virtual void digitalWrite ( pin_t  pin,
PinStatus_t  state 
)
inlinevirtual

Set the output of the given pin to the given state.

Parameters
pinThe (zero-based) pin of this IO element.
stateThe new state to set the pin to.

Reimplemented in MAX7219< NumChips, SPIDriver >, and ShiftRegisterOutBase< N >.

Definition at line 121 of file ExtendedIOElement.hpp.

◆ digitalWriteBuffered()

virtual void digitalWriteBuffered ( pin_t  pin,
PinStatus_t  state 
)
pure virtual

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 (zero-based) pin of this IO element.
stateThe new state to set the pin to.

Implemented in MCP23017< WireType >, MAX7219< NumChips, SPIDriver >, and ShiftRegisterOutBase< N >.

◆ digitalRead()

virtual PinStatus_t digitalRead ( pin_t  pin)
inlinevirtual

Read the state of the given pin.

Parameters
pinThe (zero-based) pin of this IO element.
Returns
The state of the given pin.

Reimplemented in MAX7219< NumChips, SPIDriver >, and ShiftRegisterOutBase< N >.

Definition at line 141 of file ExtendedIOElement.hpp.

◆ digitalReadBuffered()

virtual PinStatus_t digitalReadBuffered ( pin_t  pin)
pure virtual

Read the state of the given pin from the software buffer.

To update the buffer, you have to call updateBufferedInputs first.

Parameters
pinThe (zero-based) pin of this IO element.
Returns
The state of the given pin.

Implemented in MAX7219< NumChips, SPIDriver >, MCP23017< WireType >, and ShiftRegisterOutBase< N >.

◆ analogWrite()

virtual void analogWrite ( pin_t  pin,
analog_t  val 
)
inlinevirtual

Write an analog (or PWM) value to the given pin.

Parameters
pinThe (zero-based) pin of this IO element.
valThe new analog value to set the pin to.

Reimplemented in MAX7219< NumChips, SPIDriver >, and ShiftRegisterOutBase< N >.

Definition at line 161 of file ExtendedIOElement.hpp.

◆ analogWriteBuffered()

virtual void analogWriteBuffered ( pin_t  pin,
analog_t  val 
)
pure virtual

Write an analog (or PWM) value to the software buffer given pin.

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

Parameters
pinThe (zero-based) pin of this IO element.
valThe new analog value to set the pin to.

Implemented in MAX7219< NumChips, SPIDriver >, ShiftRegisterOutBase< N >, and MCP23017< WireType >.

◆ analogRead()

virtual analog_t analogRead ( pin_t  pin)
inlinevirtual

Read the analog value of the given pin.

Parameters
pinThe (zero-based) pin of this IO element.
Returns
The new analog value of pin.

Reimplemented in MAX7219< NumChips, SPIDriver >, and ShiftRegisterOutBase< N >.

Definition at line 181 of file ExtendedIOElement.hpp.

◆ analogReadBuffered()

virtual analog_t analogReadBuffered ( pin_t  pin)
pure virtual

Read the analog value of the given pin from the software buffer.

To update the buffer, you have to call updateBufferedInputs first.

Parameters
pinThe (zero-based) pin of this IO element.
Returns
The new analog value of pin.

Implemented in MCP23017< WireType >, MAX7219< NumChips, SPIDriver >, and ShiftRegisterOutBase< N >.

◆ begin()

virtual void begin ( )
pure virtual

◆ beginAll()

void beginAll ( )
static

Initialize all extended IO elements.

Definition at line 20 of file ExtendedIOElement.cpp.

◆ updateBufferedOutputs()

virtual void updateBufferedOutputs ( )
pure virtual

Write the internal state to the physical outputs.

Implemented in MAX7219< NumChips, SPIDriver >, MCP23017< WireType >, ShiftRegisterOut< N >, and SPIShiftRegisterOut< N, SPIDriver >.

◆ updateAllBufferedOutputs()

void updateAllBufferedOutputs ( )
static

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

Definition at line 24 of file ExtendedIOElement.cpp.

◆ updateBufferedInputs()

virtual void updateBufferedInputs ( )
pure virtual

Read the physical state into the input buffers.

Implemented in MAX7219< NumChips, SPIDriver >, MCP23017< WireType >, and ShiftRegisterOutBase< N >.

◆ updateAllBufferedInputs()

void updateAllBufferedInputs ( )
static

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

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

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

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

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

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 ( )
static

Get the list of all Extended IO elements.

Definition at line 55 of file ExtendedIOElement.cpp.

◆ enable() [1/4]

void enable ( )
inlineinherited

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

Definition at line 100 of file Updatable.hpp.

◆ enable() [2/4]

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 129 of file Updatable.hpp.

◆ enable() [3/4]

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 131 of file Updatable.hpp.

◆ enable() [4/4]

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 134 of file Updatable.hpp.

◆ disable() [1/4]

void disable ( )
inlineinherited

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

Definition at line 110 of file Updatable.hpp.

◆ disable() [2/4]

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 140 of file Updatable.hpp.

◆ disable() [3/4]

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 142 of file Updatable.hpp.

◆ disable() [4/4]

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 145 of file Updatable.hpp.

◆ isEnabled()

bool isEnabled ( ) 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 124 of file Updatable.hpp.

◆ moveDown()

void moveDown ( )
inlineinherited

Move down this element in the list.

Definition at line 151 of file Updatable.hpp.

Member Data Documentation

◆ length

const pin_t length
private

Definition at line 269 of file ExtendedIOElement.hpp.

◆ start

const pin_t start
private

Definition at line 270 of file ExtendedIOElement.hpp.

◆ end

const pin_t end
private

Definition at line 271 of file ExtendedIOElement.hpp.

◆ offset

pin_t offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS
staticprivate

Definition at line 272 of file ExtendedIOElement.hpp.

◆ updatables

DoublyLinkedList< ExtendedIOElement > updatables
staticprotectedinherited

Definition at line 156 of file Updatable.hpp.

◆ next

ExtendedIOElement * next
protectedinherited

Definition at line 324 of file LinkedList.hpp.

◆ previous

ExtendedIOElement * previous
protectedinherited

Definition at line 325 of file LinkedList.hpp.


The documentation for this class was generated from the following files: