21template <class SPIDriver = decltype(SPI) &>
35 : spi(
std::forward<SPIDriver>(spi)), loadPin(loadPin),
36 chainlength(chainlength) {}
38 static constexpr uint8_t DECODEMODE = 9;
39 static constexpr uint8_t INTENSITY = 10;
40 static constexpr uint8_t SCANLIMIT = 11;
41 static constexpr uint8_t SHUTDOWN = 12;
42 static constexpr uint8_t DISPLAYTEST = 15;
51 sendRawAll(DISPLAYTEST, 0);
52 sendRawAll(SCANLIMIT, 7);
53 sendRawAll(DECODEMODE, 0);
54 sendRawAll(INTENSITY, 0xF);
56 sendRawAll(SHUTDOWN, 1);
63 for (uint8_t j = 1; j < 8 + 1; j++)
77 void send(uint8_t digit, uint8_t value, uint8_t chip = 0) {
78 sendRaw((digit & 0x7) + 1, value, chip);
113 uint8_t leading_dim = 1) {
114 uint8_t opcode = (digit & 0x7) + 1;
116 spi.beginTransaction(settings);
117 for (uint8_t i = 0; i < chainlength; ++i) {
118 spi.transfer(opcode);
119 spi.transfer(values[uint16_t(i) * leading_dim]);
122 spi.endTransaction();
144 for (uint8_t row = 0; row < 8; ++row)
145 sendRowAll(row, values + row, 8);
158 spi.beginTransaction(settings);
159 for (uint8_t i = 0; i < chainlength; ++i) {
160 spi.transfer(opcode);
164 spi.endTransaction();
177 void sendRaw(uint8_t opcode, uint8_t value, uint8_t chip = 0) {
178 if (chip >= chainlength)
181 spi.beginTransaction(settings);
183 for (; c < chip; c++) {
187 spi.transfer(opcode);
189 for (c++; c < chainlength; c++) {
194 spi.endTransaction();
204 sendRawAll(INTENSITY, intensity & 0xF);
216 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()
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.