Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Attributes | Static Protected Attributes | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
MAX7219< NumChips, SPIDriver > Class Template Reference

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

Detailed Description

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
class AH::MAX7219< NumChips, SPIDriver >

A class for LED outputs using the MAX7219 LED display driver.

The SPI interface is used.

Wiring

Template Parameters
NumChipsThe number of daisy-chained MAX7219 chips.
SPIDriverThe SPI class to use. Usually, the default is fine.

Definition at line 30 of file MAX7219.hpp.

+ Inheritance diagram for MAX7219< NumChips, SPIDriver >:
+ Collaboration diagram for MAX7219< NumChips, SPIDriver >:

Enabling and disabling updatables

void enable ()
 Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
 
void disable ()
 Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
 
bool isEnabled () const
 Check if this updatable is enabled.
 
void moveDown ()
 Move down this element in the list.
 
static void enable (UpdatableCRTP *element)
 Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
 
static void enable (UpdatableCRTP &element)
 Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
 
static void enable (U(&array)[N])
 Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
 
static void disable (UpdatableCRTP *element)
 Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
 
static void disable (UpdatableCRTP &element)
 Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
 
static void disable (U(&array)[N])
 Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
 

Classes

struct  IndexMask
 

Public Member Functions

 MAX7219 (SPIDriver spi, pin_t loadPin)
 Create a MAX7219 ExtendedIOElement.
 
void begin () override
 Initialize.
 
void pinMode (pin_int_t pin, PinMode_t mode) override __attribute__((deprecated))
 The pinMode function is not implemented because the mode is OUTPUT by definition.
 
void pinModeBuffered (pin_int_t pin, PinMode_t mode) override __attribute__((deprecated))
 The pinMode function is not implemented because the mode is OUTPUT by definition.
 
void digitalWrite (pin_int_t pin, PinStatus_t val) override
 Set the state of a given output pin.
 
void digitalWriteBuffered (pin_int_t pin, PinStatus_t val) override
 Set the state of a given pin in the software buffer.
 
PinStatus_t digitalRead (pin_int_t pin) override
 Get the current state of a given output.
 
PinStatus_t digitalReadBuffered (pin_int_t pin) override
 Get the current state of a given output.
 
analog_t analogRead (pin_int_t pin) override __attribute__((deprecated))
 The analogRead function is deprecated because a MAX7219 is always digital.
 
analog_t analogReadBuffered (pin_int_t pin) override __attribute__((deprecated))
 The analogRead function is deprecated because a MAX7219 is always digital.
 
void analogWrite (pin_int_t pin, analog_t val) override __attribute__((deprecated))
 The analogWrite function is deprecated because a MAX7219 is always digital.
 
void analogWriteBuffered (pin_int_t pin, analog_t val) override __attribute__((deprecated))
 The analogWrite function is deprecated because a MAX7219 is always digital.
 
void updateBufferedOutputRow (IndexMask i)
 
void updateBufferedOutputs () override
 Write the internal state to the physical outputs.
 
void updateBufferedInputs () override
 Read the physical state into the input buffers.
 
void clear ()
 Turn off all LEDs.
 
void send (uint8_t digit, uint8_t value, uint8_t chip=0)
 Send the value to the given digit or row.
 
void sendRowAll (uint8_t digit, const uint8_t *values, uint8_t leading_dim=1)
 Send values to the given digit or row, sending a different value for each chip.
 
void sendAll (const uint8_t *values)
 Send different values to all digits/rows of all chips.
 
void sendRawAll (uint8_t opcode, uint8_t value)
 Send the same raw opcode and value to all chips in the chain.
 
void sendRaw (uint8_t opcode, uint8_t value, uint8_t chip=0)
 Send a raw opcode and value to the given MAX7219.
 
void setIntensity (uint8_t intensity)
 Set the intensity of the LEDs of all chips.
 
void setIntensity (uint8_t intensity, uint8_t chip)
 Set the intensity of the LEDs of a specific chip.
 
uint8_t getChainLength () const
 Get the number of daisy-chained chips.
 
Array< pin_t, N > pins () const
 Get an array containing all pins of the element.
 
pin_t pin (pin_int_t pin) const
 Get the extended IO pin number of a given physical pin of this extended IO element.
 
pin_t operator[] (pin_int_t pin) const
 Get the extended IO pin number of a given physical pin of this extended IO element.
 
pin_int_t getLength () const
 Get the number of pins this IO element has.
 
pin_t getEnd () const
 Get the largest global extended IO pin number that belongs to this extended IO element.
 
pin_t getStart () const
 Get the smallest global extended IO pin number that belongs to this extended IO element.
 

Static Public Member Functions

static constexpr uint16_t length ()
 
static void beginAll ()
 Initialize all extended IO elements.
 
static void updateAllBufferedOutputs ()
 Write the internal states to the physical outputs for all extended IO elements.
 
static void updateAllBufferedInputs ()
 Read the physical state into the input buffers for all extended IO elements.
 
static DoublyLinkedList< ExtendedIOElement > & getAll ()
 Get the list of all Extended IO elements.
 

Public Attributes

SPISettings settings {SPI_MAX_SPEED, MSBFIRST, SPI_MODE0}
 

Static Public Attributes

static constexpr uint8_t DECODEMODE = 9
 
static constexpr uint8_t INTENSITY = 10
 
static constexpr uint8_t SCANLIMIT = 11
 
static constexpr uint8_t SHUTDOWN = 12
 
static constexpr uint8_t DISPLAYTEST = 15
 

Protected Attributes

Nodenext = nullptr
 
Nodeprevious = nullptr
 

Static Protected Attributes

static DoublyLinkedList< ExtendedIOElementupdatables
 

Static Private Member Functions

static IndexMask pin2index (pin_t pin)
 

Private Attributes

Array< uint8_t, 8 *NumChipsbuffer
 
uint8_t dirty_rows = 0xFF
 
SPIDriver spi
 
pin_t loadPin
 
uint8_t chainlength
 
const pin_t start
 
const pin_t end
 

Static Private Attributes

static pin_t offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS
 

Constructor & Destructor Documentation

◆ MAX7219()

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
MAX7219 ( SPIDriver spi,
pin_t loadPin )
inline

Create a MAX7219 ExtendedIOElement.

Parameters
spiThe SPI interface to use.
loadPinThe pin connected to the load pin (C̄S̄) of the MAX7219.

Definition at line 41 of file MAX7219.hpp.

Member Function Documentation

◆ begin()

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
void begin ( )
inlineoverridevirtual

Initialize.

See also
MAX7219::begin

Implements ExtendedIOElement.

Definition at line 47 of file MAX7219.hpp.

◆ pin2index()

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
static IndexMask pin2index ( pin_t pin)
inlinestaticprivate

Definition at line 58 of file MAX7219.hpp.

◆ pinMode()

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
void pinMode ( pin_int_t pin,
PinMode_t mode )
inlineoverridevirtual

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

Reimplemented from ExtendedIOElement.

Definition at line 72 of file MAX7219.hpp.

◆ pinModeBuffered()

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
void pinModeBuffered ( pin_int_t pin,
PinMode_t mode )
inlineoverridevirtual

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

Implements ExtendedIOElement.

Definition at line 81 of file MAX7219.hpp.

◆ digitalWrite()

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
void digitalWrite ( pin_int_t pin,
PinStatus_t val )
inlineoverridevirtual

Set the state of a given output pin.

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

Reimplemented from ExtendedIOElement.

Definition at line 96 of file MAX7219.hpp.

◆ digitalWriteBuffered()

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
void digitalWriteBuffered ( pin_int_t pin,
PinStatus_t val )
inlineoverridevirtual

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

The buffer is written to the MAX7219 when updateBufferedOutputs is called.

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

Implements ExtendedIOElement.

Definition at line 109 of file MAX7219.hpp.

◆ digitalRead()

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
PinStatus_t digitalRead ( pin_int_t pin)
inlineoverridevirtual

Get the current state of a given output.

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

Reimplemented from ExtendedIOElement.

Definition at line 126 of file MAX7219.hpp.

◆ digitalReadBuffered()

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
PinStatus_t digitalReadBuffered ( pin_int_t pin)
inlineoverridevirtual

Get the current state of a given output.

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

Implements ExtendedIOElement.

Definition at line 134 of file MAX7219.hpp.

◆ analogRead()

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
analog_t analogRead ( pin_int_t pin)
inlineoverridevirtual

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

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

Reimplemented from ExtendedIOElement.

Definition at line 149 of file MAX7219.hpp.

◆ analogReadBuffered()

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
analog_t analogReadBuffered ( pin_int_t pin)
inlineoverridevirtual

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

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

Implements ExtendedIOElement.

Definition at line 156 of file MAX7219.hpp.

◆ analogWrite()

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
void analogWrite ( pin_int_t pin,
analog_t val )
inlineoverridevirtual

The analogWrite function is deprecated because a MAX7219 is always digital.

Parameters
pinThe output to set.
valThe value to set the output to. A value greater or equal to 0x80 will set the output to a HIGH state, a value less than 0x80 will set the output to a LOW state.
Note
This function is just implemented for compatibility. Don't use it in new code.

Reimplemented from ExtendedIOElement.

Definition at line 174 of file MAX7219.hpp.

◆ analogWriteBuffered()

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
void analogWriteBuffered ( pin_int_t pin,
analog_t val )
inlineoverridevirtual

The analogWrite function is deprecated because a MAX7219 is always digital.

Parameters
pinThe output to set.
valThe value to set the output to. A value greater or equal to 0x80 will set the output to a HIGH state, a value less than 0x80 will set the output to a LOW state.
Note
This function is just implemented for compatibility. Don't use it in new code.

Implements ExtendedIOElement.

Definition at line 182 of file MAX7219.hpp.

◆ updateBufferedOutputRow()

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
void updateBufferedOutputRow ( IndexMask i)
inline

Definition at line 187 of file MAX7219.hpp.

◆ updateBufferedOutputs()

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
void updateBufferedOutputs ( )
inlineoverridevirtual

Write the internal state to the physical outputs.

Implements ExtendedIOElement.

Definition at line 192 of file MAX7219.hpp.

◆ updateBufferedInputs()

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
void updateBufferedInputs ( )
inlineoverridevirtual

Read the physical state into the input buffers.

Implements ExtendedIOElement.

Definition at line 204 of file MAX7219.hpp.

◆ clear()

template<class SPIDriver = decltype(SPI) &>
void clear ( )
inlineinherited

Turn off all LEDs.

Definition at line 62 of file MAX7219_Base.hpp.

◆ send()

template<class SPIDriver = decltype(SPI) &>
void send ( uint8_t digit,
uint8_t value,
uint8_t chip = 0 )
inlineinherited

Send the value to the given digit or row.

Parameters
digitThe digit or row to set [0, 7].
valueThe value to set the row to.
chipThe chip to send the digit to.

Definition at line 77 of file MAX7219_Base.hpp.

◆ sendRowAll()

template<class SPIDriver = decltype(SPI) &>
void sendRowAll ( uint8_t digit,
const uint8_t * values,
uint8_t leading_dim = 1 )
inlineinherited

Send values to the given digit or row, sending a different value for each chip.

The array is often a matrix containing the values for all rows of all chips in this chain. In that case, the leading dimension is 8, because each chip has 8 rows.

[0] chip 0, row 0  ┐
[1] chip 0, row 1  │
[ ] ...            │ 8 elements between two chips
[7] chip 0, row 7  │
[8] chip 1, row 0  ┘
[9] chip 1, row 1
[ ] ...

If you just want to specify a single row for all chips, the leading dimension of the array is 1.

[0] chip 0, row 0  ┐
[1] chip 1, row 0  ┘ 1 element between two chips
[2] chip 2, row 0
[ ] ...
Parameters
digitThe digit or row to set [0, 7].
valuesThe array of values to send.
leading_dimThe leading dimension of the array of values.

Definition at line 112 of file MAX7219_Base.hpp.

◆ sendAll()

template<class SPIDriver = decltype(SPI) &>
void sendAll ( const uint8_t * values)
inlineinherited

Send different values to all digits/rows of all chips.

The array layout should be as follows:

[0] chip 0, row 0  ┐
[1] chip 0, row 1  │
[ ] ...            │ 8 elements between two chips
[7] chip 0, row 7  │
[8] chip 1, row 0  ┘
[9] chip 1, row 1
[ ] ...

The array has 8 * chainlength elements in total.

Parameters
valuesThe array of values to send.

Definition at line 143 of file MAX7219_Base.hpp.

◆ sendRawAll()

template<class SPIDriver = decltype(SPI) &>
void sendRawAll ( uint8_t opcode,
uint8_t value )
inlineinherited

Send the same raw opcode and value to all chips in the chain.

Parameters
opcodeThe opcode to send.
valueThe value to send.

Definition at line 156 of file MAX7219_Base.hpp.

◆ sendRaw()

template<class SPIDriver = decltype(SPI) &>
void sendRaw ( uint8_t opcode,
uint8_t value,
uint8_t chip = 0 )
inlineinherited

Send a raw opcode and value to the given MAX7219.

Parameters
opcodeThe opcode to send.
valueThe value to send.
chipThe chip to send the command to.

Definition at line 177 of file MAX7219_Base.hpp.

◆ setIntensity() [1/2]

template<class SPIDriver = decltype(SPI) &>
void setIntensity ( uint8_t intensity)
inlineinherited

Set the intensity of the LEDs of all chips.

Parameters
intensityThe intensity [0, 15].

Definition at line 203 of file MAX7219_Base.hpp.

◆ setIntensity() [2/2]

template<class SPIDriver = decltype(SPI) &>
void setIntensity ( uint8_t intensity,
uint8_t chip )
inlineinherited

Set the intensity of the LEDs of a specific chip.

Parameters
intensityThe intensity [0, 15].
chipThe chip to set the intensity of.

Definition at line 215 of file MAX7219_Base.hpp.

◆ getChainLength()

template<class SPIDriver = decltype(SPI) &>
uint8_t getChainLength ( ) const
inlineinherited

Get the number of daisy-chained chips.

Definition at line 222 of file MAX7219_Base.hpp.

◆ pins()

template<uint16_t N>
Array< pin_t, N > pins ( ) const
inlineinherited

Get an array containing all pins of the element.

Definition at line 24 of file StaticSizeExtendedIOElement.hpp.

◆ length()

template<uint16_t N>
static constexpr uint16_t length ( )
inlinestaticconstexprinherited
Examples
Toggle-LEDs.ino.

Definition at line 28 of file StaticSizeExtendedIOElement.hpp.

◆ beginAll()

void beginAll ( )
staticinherited

Initialize all extended IO elements.

Definition at line 17 of file ExtendedIOElement.cpp.

◆ updateAllBufferedOutputs()

void updateAllBufferedOutputs ( )
staticinherited

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

Definition at line 21 of file ExtendedIOElement.cpp.

◆ updateAllBufferedInputs()

void updateAllBufferedInputs ( )
staticinherited

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

Definition at line 25 of file ExtendedIOElement.cpp.

◆ pin()

pin_t pin ( pin_int_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 29 of file ExtendedIOElement.cpp.

◆ operator[]()

pin_t operator[] ( pin_int_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 45 of file ExtendedIOElement.cpp.

◆ getLength()

pin_int_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 47 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 49 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 51 of file ExtendedIOElement.cpp.

◆ getAll()

DoublyLinkedList< ExtendedIOElement > & getAll ( )
staticinherited

Get the list of all Extended IO elements.

Definition at line 53 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 96 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 125 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 127 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 130 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 106 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 136 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 138 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 141 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 120 of file Updatable.hpp.

◆ moveDown()

void moveDown ( )
inlineinherited

Move down this element in the list.

Definition at line 147 of file Updatable.hpp.

Member Data Documentation

◆ buffer

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
Array<uint8_t, 8 * NumChips> buffer
private

Definition at line 207 of file MAX7219.hpp.

◆ dirty_rows

template<uint8_t NumChips = 1, class SPIDriver = decltype(SPI) &>
uint8_t dirty_rows = 0xFF
private

Definition at line 208 of file MAX7219.hpp.

◆ DECODEMODE

template<class SPIDriver = decltype(SPI) &>
constexpr uint8_t DECODEMODE = 9
staticconstexprinherited

Definition at line 38 of file MAX7219_Base.hpp.

◆ INTENSITY

template<class SPIDriver = decltype(SPI) &>
constexpr uint8_t INTENSITY = 10
staticconstexprinherited

Definition at line 39 of file MAX7219_Base.hpp.

◆ SCANLIMIT

template<class SPIDriver = decltype(SPI) &>
constexpr uint8_t SCANLIMIT = 11
staticconstexprinherited

Definition at line 40 of file MAX7219_Base.hpp.

◆ SHUTDOWN

template<class SPIDriver = decltype(SPI) &>
constexpr uint8_t SHUTDOWN = 12
staticconstexprinherited

Definition at line 41 of file MAX7219_Base.hpp.

◆ DISPLAYTEST

template<class SPIDriver = decltype(SPI) &>
constexpr uint8_t DISPLAYTEST = 15
staticconstexprinherited

Definition at line 42 of file MAX7219_Base.hpp.

◆ spi

template<class SPIDriver = decltype(SPI) &>
SPIDriver spi
privateinherited

Definition at line 225 of file MAX7219_Base.hpp.

◆ loadPin

template<class SPIDriver = decltype(SPI) &>
pin_t loadPin
privateinherited

Definition at line 226 of file MAX7219_Base.hpp.

◆ chainlength

template<class SPIDriver = decltype(SPI) &>
uint8_t chainlength
privateinherited

Definition at line 227 of file MAX7219_Base.hpp.

◆ settings

template<class SPIDriver = decltype(SPI) &>
SPISettings settings {SPI_MAX_SPEED, MSBFIRST, SPI_MODE0}
inherited

Definition at line 230 of file MAX7219_Base.hpp.

◆ start

const pin_t start
privateinherited

Definition at line 265 of file ExtendedIOElement.hpp.

◆ end

const pin_t end
privateinherited

Definition at line 266 of file ExtendedIOElement.hpp.

◆ offset

pin_t offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS
staticprivateinherited

Definition at line 267 of file ExtendedIOElement.hpp.

◆ updatables

DoublyLinkedList< ExtendedIOElement > updatables
staticprotectedinherited

Definition at line 152 of file Updatable.hpp.

◆ next

template<class Node >
Node* next = nullptr
protectedinherited

Definition at line 320 of file LinkedList.hpp.

◆ previous

template<class Node >
Node* previous = nullptr
protectedinherited

Definition at line 321 of file LinkedList.hpp.


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