Arduino Helpers master
Utility library for Arduino
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 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.
Examples
1.MAX7219-Blink.ino.

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. 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...
 

Classes

struct  IndexMask
 

Public Member Functions

 MAX7219 (SPIDriver spi, pin_t loadPin)
 Create a MAX7219 ExtendedIOElement. More...
 
void begin () override
 Initialize. 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 state of a given pin in the software buffer. More...
 
PinStatus_t digitalRead (pin_t pin) override
 Get the current state of a given output. More...
 
PinStatus_t digitalReadBuffered (pin_t pin) override
 Get the current state of a given output. More...
 
analog_t analogRead (pin_t pin) override __attribute__((deprecated))
 The analogRead function is deprecated because a MAX7219 is always digital. More...
 
analog_t analogReadBuffered (pin_t pin) override __attribute__((deprecated))
 The analogRead function is deprecated because a MAX7219 is always digital. More...
 
void analogWrite (pin_t pin, analog_t val) override __attribute__((deprecated))
 The analogWrite function is deprecated because a MAX7219 is always digital. More...
 
void analogWriteBuffered (pin_t pin, analog_t val) override __attribute__((deprecated))
 The analogWrite function is deprecated because a MAX7219 is always digital. More...
 
void updateBufferedOutputRow (IndexMask i)
 
void updateBufferedOutputs () override
 Write the internal state to the physical outputs. More...
 
void updateBufferedInputs () override
 Read the physical state into the input buffers. More...
 
void clear ()
 Turn off all LEDs. More...
 
void send (uint8_t digit, uint8_t value, uint8_t chip=0)
 Send the value to the given digit or row. More...
 
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. More...
 
void sendAll (const uint8_t *values)
 Send different values to all digits/rows of all chips. More...
 
void sendRawAll (uint8_t opcode, uint8_t value)
 Send the same raw opcode and value to all chips in the chain. More...
 
void sendRaw (uint8_t opcode, uint8_t value, uint8_t chip=0)
 Send a raw opcode and value to the given MAX7219. More...
 
void setIntensity (uint8_t intensity)
 Set the intensity of the LEDs of all chips. More...
 
void setIntensity (uint8_t intensity, uint8_t chip)
 Set the intensity of the LEDs of a specific chip. More...
 
uint8_t getChainLength () const
 Get the number of daisy-chained chips. 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
 

Static Public Attributes

static constexpr uint8_t DECODEMODE
 
static constexpr uint8_t INTENSITY
 
static constexpr uint8_t SCANLIMIT
 
static constexpr uint8_t SHUTDOWN
 
static constexpr uint8_t DISPLAYTEST
 

Protected Attributes

ExtendedIOElementnext
 
ExtendedIOElementprevious
 

Static Protected Attributes

static DoublyLinkedList< ExtendedIOElementupdatables
 

Static Private Member Functions

static IndexMask pin2index (pin_t pin)
 

Private Attributes

Array< uint8_t, 8 *NumChips > buffer
 
uint8_t dirty_rows = 0xFF
 
decltype(SPI) & 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()

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

void begin ( )
inlineoverridevirtual

Initialize.

See also
MAX7219::begin

Implements ExtendedIOElement.

Definition at line 47 of file MAX7219.hpp.

◆ pin2index()

static IndexMask pin2index ( pin_t  pin)
inlinestaticprivate

Definition at line 58 of file MAX7219.hpp.

◆ pinMode()

void pinMode ( pin_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()

void pinModeBuffered ( pin_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()

void digitalWrite ( pin_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()

void digitalWriteBuffered ( pin_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()

PinStatus_t digitalRead ( pin_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()

PinStatus_t digitalReadBuffered ( pin_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()

analog_t analogRead ( pin_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()

analog_t analogReadBuffered ( pin_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()

void analogWrite ( pin_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()

void analogWriteBuffered ( pin_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()

void updateBufferedOutputRow ( IndexMask  i)
inline

Definition at line 187 of file MAX7219.hpp.

◆ updateBufferedOutputs()

void updateBufferedOutputs ( )
inlineoverridevirtual

Write the internal state to the physical outputs.

Implements ExtendedIOElement.

Definition at line 192 of file MAX7219.hpp.

◆ updateBufferedInputs()

void updateBufferedInputs ( )
inlineoverridevirtual

Read the physical state into the input buffers.

Implements ExtendedIOElement.

Definition at line 204 of file MAX7219.hpp.

◆ clear()

void clear ( )
inlineinherited

Turn off all LEDs.

Definition at line 62 of file MAX7219_Base.hpp.

◆ send()

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

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

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

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

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]

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]

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

uint8_t getChainLength ( ) const
inlineinherited

Get the number of daisy-chained chips.

Definition at line 222 of file MAX7219_Base.hpp.

◆ pins()

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

static constexpr uint16_t length ( )
inlinestaticconstexprinherited

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_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.
Examples
1.MAX7219-Blink.ino, 1.SPI-Blink.ino, and 2.BitBang-Blink.ino.

Definition at line 29 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 44 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 46 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 48 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 50 of file ExtendedIOElement.cpp.

◆ getAll()

DoublyLinkedList< ExtendedIOElement > & getAll ( )
staticinherited

Get the list of all Extended IO elements.

Definition at line 52 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

Array<uint8_t, 8 * NumChips> buffer
private

Definition at line 207 of file MAX7219.hpp.

◆ dirty_rows

uint8_t dirty_rows = 0xFF
private

Definition at line 208 of file MAX7219.hpp.

◆ DECODEMODE

constexpr uint8_t DECODEMODE
staticconstexprinherited

Definition at line 38 of file MAX7219_Base.hpp.

◆ INTENSITY

constexpr uint8_t INTENSITY
staticconstexprinherited

Definition at line 39 of file MAX7219_Base.hpp.

◆ SCANLIMIT

constexpr uint8_t SCANLIMIT
staticconstexprinherited

Definition at line 40 of file MAX7219_Base.hpp.

◆ SHUTDOWN

constexpr uint8_t SHUTDOWN
staticconstexprinherited

Definition at line 41 of file MAX7219_Base.hpp.

◆ DISPLAYTEST

constexpr uint8_t DISPLAYTEST
staticconstexprinherited

Definition at line 42 of file MAX7219_Base.hpp.

◆ spi

decltype(SPI) & spi
privateinherited

Definition at line 225 of file MAX7219_Base.hpp.

◆ loadPin

pin_t loadPin
privateinherited

Definition at line 226 of file MAX7219_Base.hpp.

◆ chainlength

uint8_t chainlength
privateinherited

Definition at line 227 of file MAX7219_Base.hpp.

◆ settings

SPISettings settings
inherited

Definition at line 230 of file MAX7219_Base.hpp.

◆ start

const pin_t start
privateinherited

Definition at line 267 of file ExtendedIOElement.hpp.

◆ end

const pin_t end
privateinherited

Definition at line 268 of file ExtendedIOElement.hpp.

◆ offset

pin_t offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS
staticprivateinherited

Definition at line 269 of file ExtendedIOElement.hpp.

◆ updatables

DoublyLinkedList< ExtendedIOElement > updatables
staticprotectedinherited

Definition at line 152 of file Updatable.hpp.

◆ next

ExtendedIOElement * next
protectedinherited

Definition at line 320 of file LinkedList.hpp.

◆ previous

ExtendedIOElement * previous
protectedinherited

Definition at line 321 of file LinkedList.hpp.


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