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),
130 memset(mPatterns, 0, T_DIGITS);
135 mSpiInterface.send16(kRegisterScanLimit, 7);
137 mSpiInterface.send16(kRegisterDecodeMode, 0);
138 mSpiInterface.send16(kRegisterShutdown, 0x1);
142 mSpiInterface.send16(kRegisterShutdown, 0x0);
153 mPatterns[pos] = pattern;
157 return mPatterns[pos];
161 mBrightness = brightness & 0xF;
177 for (uint8_t chipPos = 0; chipPos < T_DIGITS; ++chipPos) {
182 uint8_t physicalPos = remapLogicalToPhysical(chipPos);
183 uint8_t convertedPattern = internal::convertPatternMax7219(
184 mPatterns[physicalPos]);
185 mSpiInterface.send16(chipPos + 1, convertedPattern);
188 mSpiInterface.send16(kRegisterIntensity, mBrightness);
193 uint8_t remapLogicalToPhysical(uint8_t pos)
const {
194 return mRemapArray ? mRemapArray[pos] : pos;
198 static uint8_t
const kRegisterNoop = 0x00;
199 static uint8_t
const kRegisterDigit0 = 0x01;
200 static uint8_t
const kRegisterDigit1 = 0x02;
201 static uint8_t
const kRegisterDigit2 = 0x03;
202 static uint8_t
const kRegisterDigit3 = 0x04;
203 static uint8_t
const kRegisterDigit4 = 0x05;
204 static uint8_t
const kRegisterDigit5 = 0x06;
205 static uint8_t
const kRegisterDigit6 = 0x07;
206 static uint8_t
const kRegisterDigit7 = 0x08;
207 static uint8_t
const kRegisterDecodeMode = 0x09;
208 static uint8_t
const kRegisterIntensity = 0x0A;
209 static uint8_t
const kRegisterScanLimit = 0x0B;
210 static uint8_t
const kRegisterShutdown = 0x0C;
211 static uint8_t
const kRegisterDisplayTest = 0x0F;
217 const T_SPII mSpiInterface;
220 const uint8_t*
const mRemapArray;
223 uint8_t mPatterns[T_DIGITS];