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];
105 template <
typename T_SPII, u
int8_t T_DIGITS>
115 const T_SPII& spiInterface,
116 const uint8_t* remapArray =
nullptr
119 mSpiInterface(spiInterface),
120 mRemapArray(remapArray),
129 memset(mPatterns, 0, T_DIGITS);
134 mSpiInterface.send16(kRegisterScanLimit, 7);
136 mSpiInterface.send16(kRegisterDecodeMode, 0);
137 mSpiInterface.send16(kRegisterShutdown, 0x1);
141 mSpiInterface.send16(kRegisterShutdown, 0x0);
152 mPatterns[pos] = pattern;
156 return mPatterns[pos];
160 mBrightness = brightness & 0xF;
176 for (uint8_t chipPos = 0; chipPos < T_DIGITS; ++chipPos) {
181 uint8_t physicalPos = remapLogicalToPhysical(chipPos);
182 uint8_t convertedPattern = internal::convertPatternMax7219(
183 mPatterns[physicalPos]);
184 mSpiInterface.send16(chipPos + 1, convertedPattern);
187 mSpiInterface.send16(kRegisterIntensity, mBrightness);
192 uint8_t remapLogicalToPhysical(uint8_t pos)
const {
193 return mRemapArray ? mRemapArray[pos] : pos;
197 static uint8_t
const kRegisterNoop = 0x00;
198 static uint8_t
const kRegisterDigit0 = 0x01;
199 static uint8_t
const kRegisterDigit1 = 0x02;
200 static uint8_t
const kRegisterDigit2 = 0x03;
201 static uint8_t
const kRegisterDigit3 = 0x04;
202 static uint8_t
const kRegisterDigit4 = 0x05;
203 static uint8_t
const kRegisterDigit5 = 0x06;
204 static uint8_t
const kRegisterDigit6 = 0x07;
205 static uint8_t
const kRegisterDigit7 = 0x08;
206 static uint8_t
const kRegisterDecodeMode = 0x09;
207 static uint8_t
const kRegisterIntensity = 0x0A;
208 static uint8_t
const kRegisterScanLimit = 0x0B;
209 static uint8_t
const kRegisterShutdown = 0x0C;
210 static uint8_t
const kRegisterDisplayTest = 0x0F;
213 const T_SPII& mSpiInterface;
216 const uint8_t*
const mRemapArray;
219 uint8_t mPatterns[T_DIGITS];