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 Member Functions | Private Attributes | Static Private Attributes | List of all members
AnalogMultiplex< N > Class Template Reference

A class for reading multiplexed analog inputs. More...

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

+ Inheritance diagram for AnalogMultiplex< N >:
+ Collaboration diagram for AnalogMultiplex< 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

 AnalogMultiplex (pin_t analogPin, const Array< pin_t, N > &addressPins, pin_t enablePin=NO_PIN)
 Create a new AnalogMultiplex object on the given pins. More...
 
void pinMode (pin_t pin, PinMode_t mode) override
 Set the pin mode of the analog input pin. More...
 
void pinModeBuffered (pin_t pin, PinMode_t mode) override
 Set the pin mode of the analog input pin. More...
 
void digitalWrite (pin_t, PinStatus_t) override __attribute__((deprecated))
 The digitalWrite function is not implemented because writing an output to a multiplexer is not useful. More...
 
void digitalWriteBuffered (pin_t, PinStatus_t) override __attribute__((deprecated))
 The digitalWrite function is not implemented because writing an output to a multiplexer is not useful. More...
 
int digitalRead (pin_t pin) override
 Read the digital state of the given input. More...
 
int digitalReadBuffered (pin_t pin) override
 Read the digital state of the given input. More...
 
analog_t analogRead (pin_t pin) override
 Read the analog value of the given input. More...
 
analog_t analogReadBuffered (pin_t pin) override
 Read the analog value of the given input. More...
 
void analogWrite (pin_t, analog_t) override __attribute__((deprecated))
 The analogWrite function is not implemented because writing an output to a multiplexer is not useful. More...
 
void analogWriteBuffered (pin_t, analog_t) override __attribute__((deprecated))
 The analogWrite function is not implemented because writing an output to a multiplexer is not useful. More...
 
void begin () override
 Initialize the multiplexer: set the pin mode of the address pins and the enable pin to output mode. More...
 
void updateBufferedOutputs () override
 No periodic updating of the state is necessary, all actions are carried out when the user calls analogRead or digitalRead. More...
 
void updateBufferedInputs () override
 No periodic updating of the state is necessary, all actions are carried out when the user calls analogRead or digitalRead. 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

ExtendedIOElementnext
 
ExtendedIOElementprevious
 

Static Protected Attributes

static DoublyLinkedList< ExtendedIOElementupdatables
 
static Mutex mutex
 

Private Member Functions

void setMuxAddress (uint8_t address)
 Write the pin number/address to the address pins of the multiplexer. More...
 
void prepareReading (uint8_t address)
 Select the correct address and enable the multiplexer. More...
 
void afterReading ()
 Disable the multiplexer. More...
 

Private Attributes

const pin_t analogPin
 
const Array< pin_t, N > addressPins
 
const pin_t enablePin
 
const pin_t start
 
const pin_t end
 

Static Private Attributes

constexpr static auto MUX_ENABLED = LOW
 
constexpr static auto MUX_DISABLED = HIGH
 
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::AnalogMultiplex< N >

A class for reading multiplexed analog inputs.

Supports 74HC4067, 74HC4051, etc.

You can use many multiplexers on the same address lines if each of the multiplexers has a different enable line.

Template Parameters
NThe number of address lines.

Definition at line 28 of file AnalogMultiplex.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

◆ AnalogMultiplex()

AnalogMultiplex ( pin_t  analogPin,
const Array< pin_t, N > &  addressPins,
pin_t  enablePin = NO_PIN 
)
inline

Create a new AnalogMultiplex object on the given pins.

Parameters
analogPinThe analog input pin connected to the output of the multiplexer.
addressPinsAn array of the pins connected to the address lines of the multiplexer. (Labeled S0, S1, S2 ... in the datasheet.)
enablePinThe digital output pin connected to the enable pin of the multiplexer. (Labeled Ē in the datasheet.)
If you don't need the enable pin, you can use NO_PIN, which is the default.

Definition at line 44 of file AnalogMultiplex.hpp.

Member Function Documentation

◆ pinMode()

void pinMode ( pin_t  pin,
PinMode_t  mode 
)
overridevirtual

Set the pin mode of the analog input pin.


This allows you to enable the internal pull-up resistor, for use with buttons or open-collector outputs.

Note
This applies to all pins of this multiplexer.
This affects all pins of the multiplexer, because it has only a single common pin.
Parameters
pin(Unused)
modeThe new mode of the input pin: either INPUT or INPUT_PULLUP.

Reimplemented from ExtendedIOElement.

Definition at line 192 of file AnalogMultiplex.hpp.

◆ pinModeBuffered()

void pinModeBuffered ( pin_t  pin,
PinMode_t  mode 
)
overridevirtual

Set the pin mode of the analog input pin.


This allows you to enable the internal pull-up resistor, for use with buttons or open-collector outputs.

Note
This applies to all pins of this multiplexer.
This affects all pins of the multiplexer, because it has only a single common pin.
Parameters
pin(Unused)
modeThe new mode of the input pin: either INPUT or INPUT_PULLUP.

Implements ExtendedIOElement.

Definition at line 197 of file AnalogMultiplex.hpp.

◆ digitalWrite()

void digitalWrite ( pin_t  ,
PinStatus_t   
)
inlineoverridevirtual

The digitalWrite function is not implemented because writing an output to a multiplexer is not useful.

Reimplemented from ExtendedIOElement.

Definition at line 75 of file AnalogMultiplex.hpp.

◆ digitalWriteBuffered()

void digitalWriteBuffered ( pin_t  ,
PinStatus_t   
)
inlineoverridevirtual

The digitalWrite function is not implemented because writing an output to a multiplexer is not useful.

Implements ExtendedIOElement.

Definition at line 81 of file AnalogMultiplex.hpp.

◆ digitalRead()

int digitalRead ( pin_t  pin)
overridevirtual

Read the digital state of the given input.

Parameters
pinThe multiplexer's pin number to read from.

Reimplemented from ExtendedIOElement.

Definition at line 202 of file AnalogMultiplex.hpp.

◆ digitalReadBuffered()

int digitalReadBuffered ( pin_t  pin)
overridevirtual

Read the digital state of the given input.

Parameters
pinThe multiplexer's pin number to read from.

Implements ExtendedIOElement.

Definition at line 210 of file AnalogMultiplex.hpp.

◆ analogRead()

analog_t analogRead ( pin_t  pin)
overridevirtual

Read the analog value of the given input.

Parameters
pinThe multiplexer's pin number to read from.

Reimplemented from ExtendedIOElement.

Definition at line 215 of file AnalogMultiplex.hpp.

◆ analogReadBuffered()

analog_t analogReadBuffered ( pin_t  pin)
overridevirtual

Read the analog value of the given input.

Parameters
pinThe multiplexer's pin number to read from.

Implements ExtendedIOElement.

Definition at line 224 of file AnalogMultiplex.hpp.

◆ analogWrite()

void analogWrite ( pin_t  ,
analog_t   
)
inlineoverridevirtual

The analogWrite function is not implemented because writing an output to a multiplexer is not useful.

Reimplemented from ExtendedIOElement.

Definition at line 114 of file AnalogMultiplex.hpp.

◆ analogWriteBuffered()

void analogWriteBuffered ( pin_t  ,
analog_t   
)
inlineoverridevirtual

The analogWrite function is not implemented because writing an output to a multiplexer is not useful.

Implements ExtendedIOElement.

Definition at line 120 of file AnalogMultiplex.hpp.

◆ begin()

void begin
overridevirtual

Initialize the multiplexer: set the pin mode of the address pins and the enable pin to output mode.

Implements ExtendedIOElement.

Definition at line 229 of file AnalogMultiplex.hpp.

◆ updateBufferedOutputs()

void updateBufferedOutputs ( )
inlineoverridevirtual

No periodic updating of the state is necessary, all actions are carried out when the user calls analogRead or digitalRead.

Implements ExtendedIOElement.

Definition at line 133 of file AnalogMultiplex.hpp.

◆ updateBufferedInputs()

void updateBufferedInputs ( )
inlineoverridevirtual

No periodic updating of the state is necessary, all actions are carried out when the user calls analogRead or digitalRead.

Implements ExtendedIOElement.

Definition at line 139 of file AnalogMultiplex.hpp.

◆ setMuxAddress()

void setMuxAddress ( uint8_t  address)
private

Write the pin number/address to the address pins of the multiplexer.

Parameters
addressThe address to select.

Definition at line 239 of file AnalogMultiplex.hpp.

◆ prepareReading()

void prepareReading ( uint8_t  address)
private

Select the correct address and enable the multiplexer.

Parameters
addressThe address to select.

Definition at line 251 of file AnalogMultiplex.hpp.

◆ afterReading()

void afterReading
private

Disable the multiplexer.

Definition at line 258 of file AnalogMultiplex.hpp.

◆ pins()

Array<pin_t, N> pins
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

◆ analogPin

const pin_t analogPin
private

Definition at line 142 of file AnalogMultiplex.hpp.

◆ addressPins

const Array<pin_t, N> addressPins
private

Definition at line 143 of file AnalogMultiplex.hpp.

◆ enablePin

const pin_t enablePin
private

Definition at line 144 of file AnalogMultiplex.hpp.

◆ MUX_ENABLED

constexpr static auto MUX_ENABLED = LOW
staticconstexprprivate

Definition at line 169 of file AnalogMultiplex.hpp.

◆ MUX_DISABLED

constexpr static auto MUX_DISABLED = HIGH
staticconstexprprivate

Definition at line 170 of file AnalogMultiplex.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 file: