#include <AH/Hardware/ExtendedInputOutput/MAX7219.hpp>
A class for LED outputs using the MAX7219 LED display driver.
The SPI interface is used.
Wiring
NumChips | The number of daisy-chained MAX7219 chips. |
SPIDriver | The SPI class to use. Usually, the default is fine. |
Definition at line 30 of file MAX7219.hpp.
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 | |
Node * | next = nullptr |
Node * | previous = nullptr |
Static Protected Attributes | |
static DoublyLinkedList< ExtendedIOElement > | updatables |
Static Private Member Functions | |
static IndexMask | pin2index (pin_t pin) |
Private Attributes | |
Array< uint8_t, 8 *NumChips > | buffer |
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 |
Create a MAX7219 ExtendedIOElement.
spi | The SPI interface to use. |
loadPin | The pin connected to the load pin (C̄S̄) of the MAX7219. |
Definition at line 41 of file MAX7219.hpp.
|
inlineoverridevirtual |
Initialize.
Implements ExtendedIOElement.
Definition at line 47 of file MAX7219.hpp.
Definition at line 58 of file MAX7219.hpp.
The pinMode function is not implemented because the mode is OUTPUT
by definition.
Reimplemented from ExtendedIOElement.
Definition at line 72 of file MAX7219.hpp.
The pinMode function is not implemented because the mode is OUTPUT
by definition.
Implements ExtendedIOElement.
Definition at line 81 of file MAX7219.hpp.
|
inlineoverridevirtual |
Set the state of a given output pin.
pin | The output pin to set. |
val | The value to set the output to. (Either HIGH (1) or LOW (0)) |
Reimplemented from ExtendedIOElement.
Definition at line 96 of file MAX7219.hpp.
|
inlineoverridevirtual |
Set the state of a given pin in the software buffer.
The buffer is written to the MAX7219 when updateBufferedOutputs is called.
pin | The output pin to set. |
val | The value to set the output to. (Either HIGH (1) or LOW (0)) |
Implements ExtendedIOElement.
Definition at line 109 of file MAX7219.hpp.
|
inlineoverridevirtual |
Get the current state of a given output.
pin | The output to read the state from. |
0 | The state of the output is LOW . |
1 | The state of the output is HIGH . |
Reimplemented from ExtendedIOElement.
Definition at line 126 of file MAX7219.hpp.
|
inlineoverridevirtual |
Get the current state of a given output.
pin | The output to read the state from. |
0 | The state of the output is LOW . |
1 | The state of the output is HIGH . |
Implements ExtendedIOElement.
Definition at line 134 of file MAX7219.hpp.
The analogRead function is deprecated because a MAX7219 is always digital.
pin | The output to read the state from. |
0 | The state of the output is LOW . |
1023 | The state of the output is HIGH . |
Reimplemented from ExtendedIOElement.
Definition at line 149 of file MAX7219.hpp.
The analogRead function is deprecated because a MAX7219 is always digital.
pin | The output to read the state from. |
0 | The state of the output is LOW . |
1023 | The state of the output is HIGH . |
Implements ExtendedIOElement.
Definition at line 156 of file MAX7219.hpp.
The analogWrite function is deprecated because a MAX7219 is always digital.
pin | The output to set. |
val | The 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. |
Reimplemented from ExtendedIOElement.
Definition at line 174 of file MAX7219.hpp.
The analogWrite function is deprecated because a MAX7219 is always digital.
pin | The output to set. |
val | The 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. |
Implements ExtendedIOElement.
Definition at line 182 of file MAX7219.hpp.
Definition at line 187 of file MAX7219.hpp.
|
inlineoverridevirtual |
Write the internal state to the physical outputs.
Implements ExtendedIOElement.
Definition at line 192 of file MAX7219.hpp.
|
inlineoverridevirtual |
Read the physical state into the input buffers.
Implements ExtendedIOElement.
Definition at line 204 of file MAX7219.hpp.
Turn off all LEDs.
Definition at line 62 of file MAX7219_Base.hpp.
Send the value to the given digit or row.
digit | The digit or row to set [0, 7]. |
value | The value to set the row to. |
chip | The chip to send the digit to. |
Definition at line 77 of file MAX7219_Base.hpp.
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 [ ] ...
digit | The digit or row to set [0, 7]. |
values | The array of values to send. |
leading_dim | The leading dimension of the array of values. |
Definition at line 112 of file MAX7219_Base.hpp.
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.
values | The array of values to send. |
Definition at line 143 of file MAX7219_Base.hpp.
Send the same raw opcode and value to all chips in the chain.
opcode | The opcode to send. |
value | The value to send. |
Definition at line 156 of file MAX7219_Base.hpp.
Send a raw opcode and value to the given MAX7219.
opcode | The opcode to send. |
value | The value to send. |
chip | The chip to send the command to. |
Definition at line 177 of file MAX7219_Base.hpp.
Set the intensity of the LEDs of all chips.
intensity | The intensity [0, 15]. |
Definition at line 203 of file MAX7219_Base.hpp.
Set the intensity of the LEDs of a specific chip.
intensity | The intensity [0, 15]. |
chip | The chip to set the intensity of. |
Definition at line 215 of file MAX7219_Base.hpp.
Get the number of daisy-chained chips.
Definition at line 222 of file MAX7219_Base.hpp.
Get an array containing all pins of the element.
Definition at line 24 of file StaticSizeExtendedIOElement.hpp.
Definition at line 28 of file StaticSizeExtendedIOElement.hpp.
|
staticinherited |
Initialize all extended IO elements.
Definition at line 17 of file ExtendedIOElement.cpp.
|
staticinherited |
Write the internal states to the physical outputs for all extended IO elements.
Definition at line 21 of file ExtendedIOElement.cpp.
|
staticinherited |
Read the physical state into the input buffers for all extended IO elements.
Definition at line 25 of file ExtendedIOElement.cpp.
Get the extended IO pin number of a given physical pin of this extended IO element.
pin | The zero-based physical pin number of this IO element. |
Definition at line 29 of file ExtendedIOElement.cpp.
Get the extended IO pin number of a given physical pin of this extended IO element.
It is alias for ExtendedIOElement::pin
.
pin | The zero-based physical pin number of this IO element. |
Definition at line 45 of file ExtendedIOElement.cpp.
|
inherited |
Get the number of pins this IO element has.
Definition at line 47 of file ExtendedIOElement.cpp.
|
inherited |
Get the largest global extended IO pin number that belongs to this extended IO element.
Definition at line 49 of file ExtendedIOElement.cpp.
|
inherited |
Get the smallest global extended IO pin number that belongs to this extended IO element.
Definition at line 51 of file ExtendedIOElement.cpp.
|
staticinherited |
Get the list of all Extended IO elements.
Definition at line 53 of file ExtendedIOElement.cpp.
|
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.
|
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.
|
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 this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 130 of file Updatable.hpp.
|
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.
|
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.
|
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 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.
|
inlineinherited |
Check if this updatable is enabled.
Definition at line 120 of file Updatable.hpp.
|
inlineinherited |
Move down this element in the list.
Definition at line 147 of file Updatable.hpp.
Definition at line 207 of file MAX7219.hpp.
Definition at line 208 of file MAX7219.hpp.
Definition at line 38 of file MAX7219_Base.hpp.
Definition at line 39 of file MAX7219_Base.hpp.
Definition at line 40 of file MAX7219_Base.hpp.
Definition at line 41 of file MAX7219_Base.hpp.
Definition at line 42 of file MAX7219_Base.hpp.
Definition at line 225 of file MAX7219_Base.hpp.
Definition at line 226 of file MAX7219_Base.hpp.
Definition at line 227 of file MAX7219_Base.hpp.
|
inherited |
Definition at line 230 of file MAX7219_Base.hpp.
Definition at line 265 of file ExtendedIOElement.hpp.
Definition at line 266 of file ExtendedIOElement.hpp.
|
staticprivateinherited |
Definition at line 267 of file ExtendedIOElement.hpp.
|
staticprotectedinherited |
Definition at line 152 of file Updatable.hpp.
Definition at line 320 of file LinkedList.hpp.
Definition at line 321 of file LinkedList.hpp.