25 #ifndef ACE_SEGMENT_MAX7219_MODULE_H
26 #define ACE_SEGMENT_MAX7219_MODULE_H
30 #include "../LedModule.h"
32 namespace ace_segment {
54 inline uint8_t convertPatternMax7219(uint8_t pattern) {
58 uint8_t result = (pattern & 0x80) ? 0x1 : 0x0;
61 for (uint8_t i = 0; i < 7; ++i) {
96 extern const uint8_t kDigitRemapArray8Max7219[8];
106 template <
typename T_SPII, u
int8_t T_DIGITS>
116 const T_SPII& spiInterface,
117 const uint8_t* remapArray =
nullptr
120 mSpiInterface(spiInterface),
121 mRemapArray(remapArray)
131 memset(mPatterns, 0, T_DIGITS);
139 mSpiInterface.send16(kRegisterScanLimit, 7);
141 mSpiInterface.send16(kRegisterDecodeMode, 0);
142 mSpiInterface.send16(kRegisterShutdown, 0x1);
146 mSpiInterface.send16(kRegisterShutdown, 0x0);
172 for (uint8_t chipPos = 0; chipPos < T_DIGITS; ++chipPos) {
177 uint8_t physicalPos = remapLogicalToPhysical(chipPos);
178 uint8_t convertedPattern = internal::convertPatternMax7219(
179 mPatterns[physicalPos]);
180 mSpiInterface.send16(chipPos + 1, convertedPattern);
191 uint8_t remapLogicalToPhysical(uint8_t pos)
const {
192 return mRemapArray ? mRemapArray[pos] : pos;
196 static uint8_t
const kRegisterNoop = 0x00;
197 static uint8_t
const kRegisterDigit0 = 0x01;
198 static uint8_t
const kRegisterDigit1 = 0x02;
199 static uint8_t
const kRegisterDigit2 = 0x03;
200 static uint8_t
const kRegisterDigit3 = 0x04;
201 static uint8_t
const kRegisterDigit4 = 0x05;
202 static uint8_t
const kRegisterDigit5 = 0x06;
203 static uint8_t
const kRegisterDigit6 = 0x07;
204 static uint8_t
const kRegisterDigit7 = 0x08;
205 static uint8_t
const kRegisterDecodeMode = 0x09;
206 static uint8_t
const kRegisterIntensity = 0x0A;
207 static uint8_t
const kRegisterScanLimit = 0x0B;
208 static uint8_t
const kRegisterShutdown = 0x0C;
209 static uint8_t
const kRegisterDisplayTest = 0x0F;
215 const T_SPII mSpiInterface;
218 const uint8_t*
const mRemapArray;
221 uint8_t mPatterns[T_DIGITS];