8#include <AH/Hardware/ExtendedInputOutput/ExtendedInputOutput.hpp>
24template <class SPIDriver = decltype(SPI) &>
38 : spi(
std::forward<SPIDriver>(spi)), loadPin(loadPin),
39 chainlength(chainlength) {}
41 static constexpr uint8_t DECODEMODE = 9;
42 static constexpr uint8_t INTENSITY = 10;
43 static constexpr uint8_t SCANLIMIT = 11;
44 static constexpr uint8_t SHUTDOWN = 12;
45 static constexpr uint8_t DISPLAYTEST = 15;
54 sendRawAll(DISPLAYTEST, 0);
55 sendRawAll(SCANLIMIT, 7);
56 sendRawAll(DECODEMODE, 0);
57 sendRawAll(INTENSITY, 0xF);
59 sendRawAll(SHUTDOWN, 1);
66 for (uint8_t j = 1; j < 8 + 1; j++)
80 void send(uint8_t digit, uint8_t value, uint8_t chip = 0) {
81 sendRaw((digit & 0x7) + 1, value, chip);
116 uint8_t leading_dim = 1) {
117 uint8_t opcode = (digit & 0x7) + 1;
119 spi.beginTransaction(settings);
120 for (uint8_t i = 0; i < chainlength; ++i) {
121 spi.transfer(opcode);
122 spi.transfer(values[uint16_t(i) * leading_dim]);
125 spi.endTransaction();
147 for (uint8_t row = 0; row < 8; ++row)
148 sendRowAll(row, values + row, 8);
161 spi.beginTransaction(settings);
162 for (uint8_t i = 0; i < chainlength; ++i) {
163 spi.transfer(opcode);
167 spi.endTransaction();
180 void sendRaw(uint8_t opcode, uint8_t value, uint8_t chip = 0) {
181 if (chip >= chainlength)
184 spi.beginTransaction(settings);
186 for (; c < chip; c++) {
190 spi.transfer(opcode);
192 for (c++; c < chainlength; c++) {
197 spi.endTransaction();
207 sendRawAll(INTENSITY, intensity & 0xF);
219 sendRaw(INTENSITY, intensity & 0xF, chip);
constexpr PinStatus_t LOW
constexpr PinStatus_t HIGH
constexpr PinMode_t OUTPUT
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
#define BEGIN_AH_NAMESPACE
static constexpr Frequency SPI_MAX_SPEED
#define AH_DIAGNOSTIC_EXTERNAL_HEADER()
#define AH_DIAGNOSTIC_POP()
#define AH_DIAGNOSTIC_WERROR()
A base class for classes that control MAX7219 LED drivers.
void sendRawAll(uint8_t opcode, uint8_t value)
Send the same raw opcode and value to all chips in the chain.
uint8_t getChainLength() const
Get the number of daisy-chained chips.
void sendRaw(uint8_t opcode, uint8_t value, uint8_t chip=0)
Send a raw opcode and value to the given MAX7219.
void sendAll(const uint8_t *values)
Send different values to all digits/rows of all chips.
void begin()
Initialize the Arduino pins, SPI, and the MAX7219.
void clear()
Turn off all LEDs.
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 setIntensity(uint8_t intensity, uint8_t chip)
Set the intensity of the LEDs of a specific chip.
void setIntensity(uint8_t intensity)
Set the intensity of the LEDs of all chips.
void send(uint8_t digit, uint8_t value, uint8_t chip=0)
Send the value to the given digit or row.
MAX7219_Base(SPIDriver spi, pin_t loadPin, uint8_t chainlength=1)
Create a MAX7219_Base object.
void pinMode(pin_t pin, PinMode_t mode)
An ExtIO version of the Arduino function.
void digitalWrite(pin_t pin, PinStatus_t val)
An ExtIO version of the Arduino function.