|
@@ -48,39 +48,11 @@
|
48
|
48
|
#include "../Marlin.h"
|
49
|
49
|
#include "../HAL/Delay.h"
|
50
|
50
|
|
51
|
|
-static uint8_t LEDs[8] = { 0 };
|
|
51
|
+uint8_t LEDs[8 * (MAX7219_NUMBER_UNITS)] = { 0 };
|
52
|
52
|
|
53
|
53
|
#ifndef MAX7219_ROTATE
|
54
|
54
|
#define MAX7219_ROTATE 0
|
55
|
55
|
#endif
|
56
|
|
-#define _ROT ((MAX7219_ROTATE + 360) % 360)
|
57
|
|
-#if _ROT == 0
|
58
|
|
- #define _ROW_ y
|
59
|
|
- #define _COL_ x
|
60
|
|
- #define XOR_7219(x, y) LEDs[y] ^= _BV(7 - x)
|
61
|
|
- #define BIT_7219(x, y) TEST(LEDs[y], 7 - x)
|
62
|
|
- #define SEND_7219(R,V) Max7219(max7219_reg_digit0 + R, V)
|
63
|
|
-#elif _ROT == 90
|
64
|
|
- #define _ROW_ x
|
65
|
|
- #define _COL_ y
|
66
|
|
- #define XOR_7219(x, y) LEDs[x] ^= _BV(y)
|
67
|
|
- #define BIT_7219(x, y) TEST(LEDs[x], y)
|
68
|
|
- #define SEND_7219(R,V) Max7219(max7219_reg_digit0 + R, V)
|
69
|
|
-#elif _ROT == 180
|
70
|
|
- #define _ROW_ y
|
71
|
|
- #define _COL_ x
|
72
|
|
- #define XOR_7219(x, y) LEDs[y] ^= _BV(x)
|
73
|
|
- #define BIT_7219(x, y) TEST(LEDs[y], x)
|
74
|
|
- #define SEND_7219(R,V) Max7219(max7219_reg_digit7 - R, V)
|
75
|
|
-#elif _ROT == 270
|
76
|
|
- #define _ROW_ x
|
77
|
|
- #define _COL_ y
|
78
|
|
- #define XOR_7219(x, y) LEDs[x] ^= _BV(7 - y)
|
79
|
|
- #define BIT_7219(x, y) TEST(LEDs[x], 7 - y)
|
80
|
|
- #define SEND_7219(R,V) Max7219(max7219_reg_digit7 - R, V)
|
81
|
|
-#else
|
82
|
|
- #error "MAX7219_ROTATE must be a multiple of +/- 90°."
|
83
|
|
-#endif
|
84
|
56
|
|
85
|
57
|
#ifdef CPU_32_BIT
|
86
|
58
|
// Approximate a 1µs delay on 32-bit ARM
|
|
@@ -108,25 +80,24 @@ void Max7219_PutByte(uint8_t data) {
|
108
|
80
|
CRITICAL_SECTION_END;
|
109
|
81
|
#endif
|
110
|
82
|
}
|
|
83
|
+void Max7219_pulse_load() {
|
|
84
|
+ SIG_DELAY();
|
|
85
|
+ WRITE(MAX7219_LOAD_PIN, LOW); // tell the chip to load the data
|
|
86
|
+ SIG_DELAY();
|
|
87
|
+ WRITE(MAX7219_LOAD_PIN, HIGH);
|
|
88
|
+ SIG_DELAY();
|
|
89
|
+}
|
111
|
90
|
|
112
|
91
|
void Max7219(const uint8_t reg, const uint8_t data) {
|
113
|
92
|
SIG_DELAY();
|
114
|
93
|
#ifndef CPU_32_BIT
|
115
|
94
|
CRITICAL_SECTION_START;
|
116
|
95
|
#endif
|
117
|
|
- WRITE(MAX7219_LOAD_PIN, LOW); // begin
|
118
|
96
|
SIG_DELAY();
|
119
|
97
|
Max7219_PutByte(reg); // specify register
|
120
|
98
|
SIG_DELAY();
|
121
|
99
|
Max7219_PutByte(data); // put data
|
122
|
|
- SIG_DELAY();
|
123
|
|
- WRITE(MAX7219_LOAD_PIN, LOW); // and tell the chip to load the data
|
124
|
|
- SIG_DELAY();
|
125
|
|
- WRITE(MAX7219_LOAD_PIN, HIGH);
|
126
|
|
- #ifndef CPU_32_BIT
|
127
|
100
|
CRITICAL_SECTION_END;
|
128
|
|
- #endif
|
129
|
|
- SIG_DELAY();
|
130
|
101
|
}
|
131
|
102
|
|
132
|
103
|
#if ENABLED(MAX7219_NUMERIC)
|
|
@@ -145,6 +116,7 @@ void Max7219(const uint8_t reg, const uint8_t data) {
|
145
|
116
|
max7219_reg_digit0 + start + size,
|
146
|
117
|
minus ? led_minus : blank ? 0x00 : led_numeral[value % 10] | (dec ? led_decimal : 0x00)
|
147
|
118
|
);
|
|
119
|
+ Max7219_pulse_load(); // tell the chips to load the clocked out data
|
148
|
120
|
value /= 10;
|
149
|
121
|
if (!value && !leadzero) blank = true;
|
150
|
122
|
dec = false;
|
|
@@ -176,125 +148,213 @@ inline void Max7219_Error(const char * const func, const int32_t v1, const int32
|
176
|
148
|
#endif
|
177
|
149
|
}
|
178
|
150
|
|
179
|
|
-inline uint8_t flipped(const uint8_t bits) {
|
180
|
|
- uint8_t outbits = 0;
|
181
|
|
- for (uint8_t b = 0; b < 8; b++)
|
182
|
|
- if (bits & _BV(b)) outbits |= _BV(7 - b);
|
|
151
|
+/**
|
|
152
|
+ * uint32_t flipped(const uint32_t bits, const uint8_t n_bytes) operates on the number
|
|
153
|
+ * of bytes specified in n_bytes. The lower order bits of the supplied bits are flipped.
|
|
154
|
+ * flipped( x, 1) flips the low 8 bits of x.
|
|
155
|
+ * flipped( x, 2) flips the low 16 bits of x.
|
|
156
|
+ * flipped( x, 3) flips the low 24 bits of x.
|
|
157
|
+ * flipped( x, 4) flips the low 32 bits of x.
|
|
158
|
+ */
|
|
159
|
+
|
|
160
|
+inline uint32_t flipped(const uint32_t bits, const uint8_t n_bytes) {
|
|
161
|
+ uint32_t mask = 1, outbits = 0;
|
|
162
|
+ for (uint8_t b = 0; b < n_bytes * 8; b++) {
|
|
163
|
+ outbits = (outbits << 1);
|
|
164
|
+ if (bits & mask)
|
|
165
|
+ outbits |= 1;
|
|
166
|
+ mask = mask << 1;
|
|
167
|
+ }
|
183
|
168
|
return outbits;
|
184
|
169
|
}
|
185
|
170
|
|
186
|
171
|
// Modify a single LED bit and send the changed line
|
187
|
172
|
void Max7219_LED_Set(const uint8_t x, const uint8_t y, const bool on) {
|
188
|
|
- if (x > 7 || y > 7) return Max7219_Error(PSTR("Max7219_LED_Set"), x, y);
|
|
173
|
+ if (x > (MAX7219_X_LEDS - 1) || y > (MAX7219_Y_LEDS - 1)) return Max7219_Error(PSTR("Max7219_LED_Set"), x, y);
|
189
|
174
|
if (BIT_7219(x, y) == on) return;
|
190
|
175
|
XOR_7219(x, y);
|
191
|
|
- SEND_7219(_ROW_, LEDs[_ROW_]);
|
|
176
|
+ SEND_7219(MAX7219_UPDATE_AXIS);
|
192
|
177
|
}
|
193
|
178
|
|
194
|
179
|
void Max7219_LED_On(const uint8_t x, const uint8_t y) {
|
195
|
|
- if (x > 7 || y > 7) return Max7219_Error(PSTR("Max7219_LED_On"), x, y);
|
|
180
|
+ if (x > (MAX7219_X_LEDS - 1) || y > (MAX7219_Y_LEDS - 1)) return Max7219_Error(PSTR("Max7219_LED_On"), x, y);
|
196
|
181
|
Max7219_LED_Set(x, y, true);
|
197
|
182
|
}
|
198
|
183
|
|
199
|
184
|
void Max7219_LED_Off(const uint8_t x, const uint8_t y) {
|
200
|
|
- if (x > 7 || y > 7) return Max7219_Error(PSTR("Max7219_LED_Off"), x, y);
|
|
185
|
+ if (x > (MAX7219_X_LEDS - 1) || y > (MAX7219_Y_LEDS - 1)) return Max7219_Error(PSTR("Max7219_LED_Off"), x, y);
|
201
|
186
|
Max7219_LED_Set(x, y, false);
|
202
|
187
|
}
|
203
|
188
|
|
204
|
189
|
void Max7219_LED_Toggle(const uint8_t x, const uint8_t y) {
|
205
|
|
- if (x > 7 || y > 7) return Max7219_Error(PSTR("Max7219_LED_Toggle"), x, y);
|
|
190
|
+ if (x > (MAX7219_X_LEDS - 1) || y > (MAX7219_Y_LEDS - 1)) return Max7219_Error(PSTR("Max7219_LED_Toggle"), x, y);
|
206
|
191
|
Max7219_LED_Set(x, y, !BIT_7219(x, y));
|
207
|
192
|
}
|
208
|
193
|
|
209
|
|
-inline void _Max7219_Set_Reg(const uint8_t reg, const uint8_t val) {
|
210
|
|
- LEDs[reg] = val;
|
211
|
|
- SEND_7219(reg, val);
|
|
194
|
+inline void _Max7219_Set_Digit_Segments(const uint8_t digit, const uint8_t val) {
|
|
195
|
+ LEDs[digit] = val;
|
|
196
|
+ SEND_7219(digit);
|
212
|
197
|
}
|
213
|
198
|
|
214
|
|
-void Max7219_Set_Row(const uint8_t _ROW_, const uint8_t val) {
|
215
|
|
- if (_ROW_ > 7) return Max7219_Error(PSTR("Max7219_Set_Row"), _ROW_);
|
216
|
|
- #if _ROT == 90
|
217
|
|
- for (uint8_t _COL_ = 0; _COL_ <= 7; _COL_++) Max7219_LED_Set(7 - _COL_, _ROW_, TEST(val, _COL_));
|
218
|
|
- #elif _ROT == 180
|
219
|
|
- _Max7219_Set_Reg(_ROW_, flipped(val));
|
220
|
|
- #elif _ROT == 270
|
221
|
|
- for (uint8_t _COL_ = 0; _COL_ <= 7; _COL_++) Max7219_LED_Set(_COL_, _ROW_, TEST(val, _COL_));
|
|
199
|
+/**
|
|
200
|
+ * void Max7219_Set_Row( const uint8_t col, const uint32_t val) plots the low order bits of
|
|
201
|
+ * val to the specified row of the Max7219 matrix. With 4 Max7219 units in the chain, it
|
|
202
|
+ * is possible to display an entire 32-bit number with one call to the function (if appropriately
|
|
203
|
+ * orientated).
|
|
204
|
+ */
|
|
205
|
+void Max7219_Set_Row(const uint8_t row, const uint32_t val) {
|
|
206
|
+ if (row >= MAX7219_Y_LEDS) return Max7219_Error(PSTR("Max7219_Set_Row"), row);
|
|
207
|
+ uint32_t mask = 0x0000001;
|
|
208
|
+ for (uint8_t x = 0; x < MAX7219_X_LEDS; x++) {
|
|
209
|
+ if (val & mask)
|
|
210
|
+ SET_PIXEL_7219((MAX7219_X_LEDS-1-x), row);
|
|
211
|
+ else
|
|
212
|
+ CLEAR_PIXEL_7219((MAX7219_X_LEDS-1-x), row);
|
|
213
|
+ mask = mask << 1;
|
|
214
|
+ }
|
|
215
|
+
|
|
216
|
+ #if _ROT == 90 || _ROT == 270
|
|
217
|
+ for (uint8_t x = 0; x < 8; x++)
|
|
218
|
+ SEND_7219(x); // force all columns out to the Max7219 chips and strobe them
|
222
|
219
|
#else
|
223
|
|
- _Max7219_Set_Reg(_ROW_, val);
|
|
220
|
+ SEND_7219(row); // force the single column out to the Max7219 chips and strobe them
|
224
|
221
|
#endif
|
225
|
222
|
}
|
226
|
223
|
|
227
|
|
-void Max7219_Clear_Row(const uint8_t _ROW_) {
|
228
|
|
- if (_ROW_ > 7) return Max7219_Error(PSTR("Max7219_Clear_Row"), _ROW_);
|
|
224
|
+void Max7219_Clear_Row(const uint8_t row) {
|
|
225
|
+ if (row > 7) return Max7219_Error(PSTR("Max7219_Clear_Row"), row);
|
229
|
226
|
#if _ROT == 90 || _ROT == 270
|
230
|
|
- for (uint8_t _COL_ = 0; _COL_ <= 7; _COL_++) Max7219_LED_Off(_COL_, _ROW_);
|
|
227
|
+ for (uint8_t col = 0; col < 8; col++) Max7219_LED_Off(col, row);
|
231
|
228
|
#else
|
232
|
|
- _Max7219_Set_Reg(_ROW_, 0);
|
|
229
|
+ _Max7219_Set_Digit_Segments(row, 0);
|
233
|
230
|
#endif
|
234
|
231
|
}
|
235
|
232
|
|
236
|
|
-void Max7219_Set_Column(const uint8_t _COL_, const uint8_t val) {
|
237
|
|
- if (_COL_ > 7) return Max7219_Error(PSTR("Max7219_Set_Column"), _COL_);
|
238
|
|
- #if _ROT == 90
|
239
|
|
- _Max7219_Set_Reg(_COL_, val);
|
240
|
|
- #elif _ROT == 180
|
241
|
|
- for (uint8_t _ROW_ = 0; _ROW_ <= 7; _ROW_++) Max7219_LED_Set(_COL_, _ROW_, TEST(val, _ROW_));
|
242
|
|
- #elif _ROT == 270
|
243
|
|
- _Max7219_Set_Reg(_COL_, flipped(val));
|
|
233
|
+/**
|
|
234
|
+ * void Max7219_Set_Column( const uint8_t col, const uint32_t val) plots the low order bits of
|
|
235
|
+ * val to the specified column of the Max7219 matrix. With 4 Max7219 units in the chain, it
|
|
236
|
+ * is possible to display an entire 32-bit number with one call to the function (if appropriately
|
|
237
|
+ * orientated).
|
|
238
|
+ */
|
|
239
|
+void Max7219_Set_Column(const uint8_t col, const uint32_t val) {
|
|
240
|
+ if (col >= MAX7219_X_LEDS) return Max7219_Error(PSTR("Max7219_Set_Column"), col);
|
|
241
|
+ uint32_t mask = 0x0000001;
|
|
242
|
+ for (uint8_t y = 0; y < MAX7219_Y_LEDS; y++) {
|
|
243
|
+ if (val & mask)
|
|
244
|
+ SET_PIXEL_7219(col, MAX7219_Y_LEDS-1-y);
|
|
245
|
+ else
|
|
246
|
+ CLEAR_PIXEL_7219(col, MAX7219_Y_LEDS-1-y);
|
|
247
|
+ mask = mask << 1;
|
|
248
|
+ }
|
|
249
|
+ #if _ROT == 90 || _ROT == 270
|
|
250
|
+ SEND_7219(col); // force the column out to the Max7219 chips and strobe them
|
244
|
251
|
#else
|
245
|
|
- for (uint8_t _ROW_ = 0; _ROW_ <= 7; _ROW_++) Max7219_LED_Set(_COL_, _ROW_, TEST(val, _ROW_));
|
|
252
|
+ for (uint8_t yy = 0; yy < 8; yy++)
|
|
253
|
+ SEND_7219(yy); // force all columns out to the Max7219 chips and strobe them
|
246
|
254
|
#endif
|
247
|
255
|
}
|
248
|
256
|
|
249
|
|
-void Max7219_Clear_Column(const uint8_t _COL_) {
|
250
|
|
- if (_COL_ > 7) return Max7219_Error(PSTR("Max7219_Clear_Column"), _COL_);
|
|
257
|
+void Max7219_Clear_Column(const uint8_t col) {
|
|
258
|
+ if (col >= MAX7219_X_LEDS) return Max7219_Error(PSTR("Max7219_Clear_Column"), col);
|
|
259
|
+
|
|
260
|
+ for (uint8_t yy = 0; yy < MAX7219_Y_LEDS; yy++)
|
|
261
|
+ CLEAR_PIXEL_7219(col, yy);
|
|
262
|
+
|
251
|
263
|
#if _ROT == 90 || _ROT == 270
|
252
|
|
- _Max7219_Set_Reg(_COL_, 0);
|
|
264
|
+ SEND_7219(col); // force the column out to the Max7219 chips and strobe them
|
253
|
265
|
#else
|
254
|
|
- for (uint8_t _ROW_ = 0; _ROW_ <= 7; _ROW_++) Max7219_LED_Off(_COL_, _ROW_);
|
|
266
|
+ for (uint8_t y = 0; y < 8; y++)
|
|
267
|
+ SEND_7219(y); // force all columns out to the Max7219 chips and strobe them
|
255
|
268
|
#endif
|
256
|
269
|
}
|
257
|
270
|
|
258
|
271
|
void Max7219_Clear() {
|
259
|
|
- for (uint8_t r = 0; r < 8; r++) _Max7219_Set_Reg(r, 0);
|
|
272
|
+ for (uint8_t i = 0; i <= 7; i++) { // Clear LED bitmap
|
|
273
|
+ for (uint8_t j = 0; j < MAX7219_NUMBER_UNITS; j++)
|
|
274
|
+ LEDs[i + j * 8] = 0x00;
|
|
275
|
+ SEND_7219(i);
|
|
276
|
+ }
|
|
277
|
+
|
260
|
278
|
}
|
261
|
279
|
|
262
|
|
-void Max7219_Set_2_Rows(const uint8_t y, uint16_t val) {
|
263
|
|
- if (y > 6) return Max7219_Error(PSTR("Max7219_Set_2_Rows"), y, val);
|
264
|
|
- Max7219_Set_Row(y + 0, val & 0xFF); val >>= 8;
|
265
|
|
- Max7219_Set_Row(y + 1, val & 0xFF);
|
|
280
|
+void Max7219_Set_Rows_16bits(const uint8_t y, uint32_t val) {
|
|
281
|
+ #if MAX7219_X_LEDS == 8
|
|
282
|
+ if (y > MAX7219_Y_LEDS - 2) return Max7219_Error(PSTR("Max7219_Set_Rows_16bits"), y, val);
|
|
283
|
+ Max7219_Set_Row(y + 1, val); val >>= 8;
|
|
284
|
+ Max7219_Set_Row(y + 0, val);
|
|
285
|
+ #else // at least 16 bits on each row
|
|
286
|
+ if (y > MAX7219_Y_LEDS - 1) return Max7219_Error(PSTR("Max7219_Set_Rows_16bits"), y, val);
|
|
287
|
+ Max7219_Set_Row(y, val);
|
|
288
|
+ #endif
|
266
|
289
|
}
|
267
|
290
|
|
268
|
|
-void Max7219_Set_4_Rows(const uint8_t y, uint32_t val) {
|
269
|
|
- if (y > 4) return Max7219_Error(PSTR("Max7219_Set_4_Rows"), y, val);
|
270
|
|
- Max7219_Set_Row(y + 0, val & 0xFF); val >>= 8;
|
271
|
|
- Max7219_Set_Row(y + 1, val & 0xFF); val >>= 8;
|
272
|
|
- Max7219_Set_Row(y + 2, val & 0xFF); val >>= 8;
|
273
|
|
- Max7219_Set_Row(y + 3, val & 0xFF);
|
|
291
|
+void Max7219_Set_Rows_32bits(const uint8_t y, uint32_t val) {
|
|
292
|
+ #if MAX7219_X_LEDS == 8
|
|
293
|
+ if (y > MAX7219_Y_LEDS - 4) return Max7219_Error(PSTR("Max7219_Set_Rows_32bits"), y, val);
|
|
294
|
+ Max7219_Set_Row(y + 3, val); val >>= 8;
|
|
295
|
+ Max7219_Set_Row(y + 2, val); val >>= 8;
|
|
296
|
+ Max7219_Set_Row(y + 1, val); val >>= 8;
|
|
297
|
+ Max7219_Set_Row(y + 0, val);
|
|
298
|
+ #elif MAX7219_X_LEDS == 16
|
|
299
|
+ if (y > MAX7219_Y_LEDS - 2) return Max7219_Error(PSTR("Max7219_Set_Rows_32bits"), y, val);
|
|
300
|
+ Max7219_Set_Row(y + 1, val); val >>= 16;
|
|
301
|
+ Max7219_Set_Row(y + 0, val);
|
|
302
|
+ #else // at least 24 bits on each row. In the 3 matrix case, just display the low 24 bits
|
|
303
|
+ if (y > MAX7219_Y_LEDS - 1) return Max7219_Error(PSTR("Max7219_Set_Rows_32bits"), y, val);
|
|
304
|
+ Max7219_Set_Row(y, val);
|
|
305
|
+ #endif
|
274
|
306
|
}
|
275
|
307
|
|
276
|
|
-void Max7219_Set_2_Columns(const uint8_t x, uint16_t val) {
|
277
|
|
- if (x > 6) return Max7219_Error(PSTR("Max7219_Set_2_Columns"), x, val);
|
278
|
|
- Max7219_Set_Column(x + 0, val & 0xFF); val >>= 8;
|
279
|
|
- Max7219_Set_Column(x + 1, val & 0xFF);
|
|
308
|
+void Max7219_Set_Columns_16bits(const uint8_t x, uint32_t val) {
|
|
309
|
+ #if MAX7219_Y_LEDS == 8
|
|
310
|
+ if (x > MAX7219_X_LEDS - 2) return Max7219_Error(PSTR("Max7219_Set_Columns_16bits"), x, val);
|
|
311
|
+ Max7219_Set_Column(x + 0, val); val >>= 8;
|
|
312
|
+ Max7219_Set_Column(x + 1, val);
|
|
313
|
+ #else // at least 16 bits in each column
|
|
314
|
+ if (x > MAX7219_X_LEDS - 1) return Max7219_Error(PSTR("Max7219_Set_Columns_16bits"), x, val);
|
|
315
|
+ Max7219_Set_Column(x, val);
|
|
316
|
+ #endif
|
280
|
317
|
}
|
281
|
318
|
|
282
|
|
-void Max7219_Set_4_Columns(const uint8_t x, uint32_t val) {
|
283
|
|
- if (x > 4) return Max7219_Error(PSTR("Max7219_Set_4_Columns"), x, val);
|
284
|
|
- Max7219_Set_Column(x + 0, val & 0xFF); val >>= 8;
|
285
|
|
- Max7219_Set_Column(x + 1, val & 0xFF); val >>= 8;
|
286
|
|
- Max7219_Set_Column(x + 2, val & 0xFF); val >>= 8;
|
287
|
|
- Max7219_Set_Column(x + 3, val & 0xFF);
|
|
319
|
+void Max7219_Set_Columns_32bits(const uint8_t x, uint32_t val) {
|
|
320
|
+ #if MAX7219_Y_LEDS == 8
|
|
321
|
+ if (x > MAX7219_X_LEDS - 4) return Max7219_Error(PSTR("Max7219_Set_Rows_32bits"), x, val);
|
|
322
|
+ Max7219_Set_Column(x + 3, val); val >>= 8;
|
|
323
|
+ Max7219_Set_Column(x + 2, val); val >>= 8;
|
|
324
|
+ Max7219_Set_Column(x + 1, val); val >>= 8;
|
|
325
|
+ Max7219_Set_Column(x + 0, val);
|
|
326
|
+ #elif MAX7219_Y_LEDS == 16
|
|
327
|
+ if (x > MAX7219_X_LEDS - 2) return Max7219_Error(PSTR("Max7219_Set_Rows_32bits"), x, val);
|
|
328
|
+ Max7219_Set_Column(x + 1, val); val >>= 16;
|
|
329
|
+ Max7219_Set_Column(x + 0, val);
|
|
330
|
+ #else // at least 24 bits on each row. In the 3 matrix case, just display the low 24 bits
|
|
331
|
+ if (x > MAX7219_X_LEDS - 1) return Max7219_Error(PSTR("Max7219_Set_Rows_32bits"), x, val);
|
|
332
|
+ Max7219_Set_Column(x, val);
|
|
333
|
+ #endif
|
288
|
334
|
}
|
289
|
335
|
|
290
|
336
|
void Max7219_register_setup() {
|
291
|
337
|
// Initialize the Max7219
|
292
|
|
- Max7219(max7219_reg_scanLimit, 0x07);
|
293
|
|
- Max7219(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits)
|
294
|
|
- Max7219(max7219_reg_shutdown, 0x01); // not in shutdown mode
|
295
|
|
- Max7219(max7219_reg_displayTest, 0x00); // no display test
|
296
|
|
- Max7219(max7219_reg_intensity, 0x01 & 0x0F); // the first 0x0F is the value you can set
|
|
338
|
+ for (uint8_t i = 0; i < MAX7219_NUMBER_UNITS; i++)
|
|
339
|
+ Max7219(max7219_reg_scanLimit, 0x07);
|
|
340
|
+ Max7219_pulse_load(); // tell the chips to load the clocked out data
|
|
341
|
+
|
|
342
|
+ for (uint8_t i = 0; i < MAX7219_NUMBER_UNITS; i++)
|
|
343
|
+ Max7219(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits)
|
|
344
|
+ Max7219_pulse_load(); // tell the chips to load the clocked out data
|
|
345
|
+
|
|
346
|
+ for (uint8_t i = 0; i < MAX7219_NUMBER_UNITS; i++)
|
|
347
|
+ Max7219(max7219_reg_shutdown, 0x01); // not in shutdown mode
|
|
348
|
+ Max7219_pulse_load(); // tell the chips to load the clocked out data
|
|
349
|
+
|
|
350
|
+ for (uint8_t i = 0; i < MAX7219_NUMBER_UNITS; i++)
|
|
351
|
+ Max7219(max7219_reg_displayTest, 0x00); // no display test
|
|
352
|
+ Max7219_pulse_load(); // tell the chips to load the clocked out data
|
|
353
|
+
|
|
354
|
+ for (uint8_t i = 0; i < MAX7219_NUMBER_UNITS; i++)
|
|
355
|
+ Max7219(max7219_reg_intensity, 0x01 & 0x0F); // the first 0x0F is the value you can set
|
297
|
356
|
// range: 0x00 to 0x0F
|
|
357
|
+ Max7219_pulse_load(); // tell the chips to load the clocked out data
|
298
|
358
|
}
|
299
|
359
|
|
300
|
360
|
#ifdef MAX7219_INIT_TEST
|
|
@@ -303,24 +363,21 @@ void Max7219_register_setup() {
|
303
|
363
|
inline void Max7219_spiral(const bool on, const uint16_t del) {
|
304
|
364
|
constexpr int8_t way[] = { 1, 0, 0, 1, -1, 0, 0, -1 };
|
305
|
365
|
int8_t px = 0, py = 0, dir = 0;
|
306
|
|
- for (uint8_t i = 64; i--;) {
|
|
366
|
+ for (uint8_t i = MAX7219_X_LEDS * MAX7219_Y_LEDS; i--;) {
|
307
|
367
|
Max7219_LED_Set(px, py, on);
|
308
|
368
|
delay(del);
|
309
|
369
|
const int8_t x = px + way[dir], y = py + way[dir + 1];
|
310
|
|
- if (!WITHIN(x, 0, 7) || !WITHIN(y, 0, 7) || BIT_7219(x, y) == on) dir = (dir + 2) & 0x7;
|
|
370
|
+ if (!WITHIN(x, 0, MAX7219_X_LEDS-1) || !WITHIN(y, 0, MAX7219_Y_LEDS-1) || BIT_7219(x, y) == on) dir = (dir + 2) & 0x7;
|
311
|
371
|
px += way[dir]; py += way[dir + 1];
|
312
|
372
|
}
|
313
|
373
|
}
|
314
|
374
|
|
315
|
375
|
#else
|
316
|
376
|
|
317
|
|
- inline void Max7219_colset(const uint8_t x, const bool on) {
|
318
|
|
- for (uint8_t y = 0; y <= 7; y++) Max7219_LED_Set(x, y, on);
|
319
|
|
- }
|
320
|
377
|
inline void Max7219_sweep(const int8_t dir, const uint16_t ms, const bool on) {
|
321
|
|
- uint8_t x = dir > 0 ? 0 : 7;
|
322
|
|
- for (uint8_t i = 8; i--; x += dir) {
|
323
|
|
- Max7219_Set_Column(x, on ? 0xFF : 0x00);
|
|
378
|
+ uint8_t x = dir > 0 ? 0 : MAX7219_X_LEDS-1;
|
|
379
|
+ for (uint8_t i = MAX7219_X_LEDS; i--; x += dir) {
|
|
380
|
+ Max7219_Set_Column(x, on ? 0xFFFFFFFF : 0x00000000);
|
324
|
381
|
delay(ms);
|
325
|
382
|
}
|
326
|
383
|
}
|
|
@@ -339,6 +396,7 @@ void Max7219_init() {
|
339
|
396
|
for (uint8_t i = 0; i <= 7; i++) { // Empty registers to turn all LEDs off
|
340
|
397
|
LEDs[i] = 0x00;
|
341
|
398
|
Max7219(max7219_reg_digit0 + i, 0);
|
|
399
|
+ Max7219_pulse_load(); // tell the chips to load the clocked out data
|
342
|
400
|
}
|
343
|
401
|
|
344
|
402
|
#ifdef MAX7219_INIT_TEST
|
|
@@ -366,22 +424,38 @@ void Max7219_init() {
|
366
|
424
|
|
367
|
425
|
// Apply changes to update a marker
|
368
|
426
|
inline void Max7219_Mark16(const uint8_t y, const uint8_t v1, const uint8_t v2) {
|
369
|
|
- Max7219_LED_Off(v1 & 0x7, y + (v1 >= 8));
|
370
|
|
- Max7219_LED_On(v2 & 0x7, y + (v2 >= 8));
|
|
427
|
+ #if MAX7219_X_LEDS == 8
|
|
428
|
+ Max7219_LED_Off(v1 & 0x7, y + (v1 >= 8));
|
|
429
|
+ Max7219_LED_On(v2 & 0x7, y + (v2 >= 8));
|
|
430
|
+ #else // LED matrix has at least 16 LED's on the X-Axis. Use single line of LED's
|
|
431
|
+ Max7219_LED_Off(v1 & 0xF, y);
|
|
432
|
+ Max7219_LED_On(v2 & 0xF, y);
|
|
433
|
+ #endif
|
371
|
434
|
}
|
372
|
435
|
|
373
|
436
|
// Apply changes to update a tail-to-head range
|
374
|
437
|
inline void Max7219_Range16(const uint8_t y, const uint8_t ot, const uint8_t nt, const uint8_t oh, const uint8_t nh) {
|
375
|
|
- if (ot != nt) for (uint8_t n = ot & 0xF; n != (nt & 0xF) && n != (nh & 0xF); n = (n + 1) & 0xF)
|
376
|
|
- Max7219_LED_Off(n & 0x7, y + (n >= 8));
|
377
|
|
- if (oh != nh) for (uint8_t n = (oh + 1) & 0xF; n != ((nh + 1) & 0xF); n = (n + 1) & 0xF)
|
378
|
|
- Max7219_LED_On(n & 0x7, y + (n >= 8));
|
|
438
|
+ #if MAX7219_X_LEDS == 8
|
|
439
|
+ if (ot != nt) for (uint8_t n = ot & 0xF; n != (nt & 0xF) && n != (nh & 0xF); n = (n + 1) & 0xF)
|
|
440
|
+ Max7219_LED_Off(n & 0x7, y + (n >= 8));
|
|
441
|
+ if (oh != nh) for (uint8_t n = (oh + 1) & 0xF; n != ((nh + 1) & 0xF); n = (n + 1) & 0xF)
|
|
442
|
+ Max7219_LED_On(n & 0x7, y + (n >= 8));
|
|
443
|
+ #else // LED matrix has at least 16 LED's on the X-Axis. Use single line of LED's
|
|
444
|
+ if (ot != nt) for (uint8_t n = ot & 0xF; n != (nt & 0xF) && n != (nh & 0xF); n = (n + 1) & 0xF)
|
|
445
|
+ Max7219_LED_Off(n & 0xF, y);
|
|
446
|
+ if (oh != nh) for (uint8_t n = (oh + 1) & 0xF; n != ((nh + 1) & 0xF); n = (n + 1) & 0xF)
|
|
447
|
+ Max7219_LED_On(n & 0xF, y);
|
|
448
|
+ #endif
|
379
|
449
|
}
|
380
|
450
|
|
381
|
451
|
// Apply changes to update a quantity
|
382
|
452
|
inline void Max7219_Quantity16(const uint8_t y, const uint8_t ov, const uint8_t nv) {
|
383
|
453
|
for (uint8_t i = MIN(nv, ov); i < MAX(nv, ov); i++)
|
384
|
|
- Max7219_LED_Set(i >> 1, y + (i & 1), nv >= ov);
|
|
454
|
+ #if MAX7219_X_LEDS == 8
|
|
455
|
+ Max7219_LED_Set(i >> 1, y + (i & 1), nv >= ov); // single 8x8 LED matrix. Use two lines to get 16 LED's
|
|
456
|
+ #else
|
|
457
|
+ Max7219_LED_Set(i, y, nv >= ov); // LED matrix has at least 16 LED's on the X-Axis. Use single line of LED's
|
|
458
|
+ #endif
|
385
|
459
|
}
|
386
|
460
|
|
387
|
461
|
void Max7219_idle_tasks() {
|
|
@@ -424,7 +498,7 @@ void Max7219_idle_tasks() {
|
424
|
498
|
|
425
|
499
|
#if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
|
426
|
500
|
if (do_blink) {
|
427
|
|
- Max7219_LED_Toggle(7, 7);
|
|
501
|
+ Max7219_LED_Toggle(MAX7219_X_LEDS - 1, MAX7219_Y_LEDS - 1);
|
428
|
502
|
next_blink = ms + 1000;
|
429
|
503
|
}
|
430
|
504
|
#endif
|