|
@@ -63,54 +63,41 @@
|
63
|
63
|
|
64
|
64
|
static uint8_t LEDs[8] = { 0 };
|
65
|
65
|
|
|
66
|
+#ifdef CPU_32_BIT
|
|
67
|
+ #define MS_DELAY() delayMicroseconds(5) // 32-bit processors need a delay to stabilize the signal
|
|
68
|
+#else
|
|
69
|
+ #define MS_DELAY() NOOP
|
|
70
|
+#endif
|
|
71
|
+
|
66
|
72
|
void Max7219_PutByte(uint8_t data) {
|
67
|
73
|
CRITICAL_SECTION_START
|
68
|
74
|
for (uint8_t i = 8; i--;) {
|
69
|
|
- #ifdef CPU_32_BIT // The 32-bit processors are so fast, a small delay in the code is needed
|
70
|
|
- delayMicroseconds(5); // to let the signal wires stabilize.
|
71
|
|
- WRITE(MAX7219_CLK_PIN, LOW); // tick
|
72
|
|
- delayMicroseconds(5);
|
73
|
|
- WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit
|
74
|
|
- delayMicroseconds(5);
|
75
|
|
- WRITE(MAX7219_CLK_PIN, HIGH); // tock
|
76
|
|
- delayMicroseconds(5);
|
77
|
|
- #else
|
78
|
|
- WRITE(MAX7219_CLK_PIN, LOW); // tick
|
79
|
|
- WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit
|
80
|
|
- WRITE(MAX7219_CLK_PIN, HIGH); // tock
|
81
|
|
- #endif
|
82
|
|
-
|
|
75
|
+ MS_DELAY();
|
|
76
|
+ WRITE(MAX7219_CLK_PIN, LOW); // tick
|
|
77
|
+ MS_DELAY();
|
|
78
|
+ WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit
|
|
79
|
+ MS_DELAY();
|
|
80
|
+ WRITE(MAX7219_CLK_PIN, HIGH); // tock
|
|
81
|
+ MS_DELAY();
|
83
|
82
|
data <<= 1;
|
84
|
83
|
}
|
85
|
84
|
CRITICAL_SECTION_END
|
86
|
85
|
}
|
87
|
86
|
|
88
|
87
|
void Max7219(const uint8_t reg, const uint8_t data) {
|
89
|
|
- #ifdef CPU_32_BIT
|
90
|
|
- delayMicroseconds(5);
|
91
|
|
- #endif
|
|
88
|
+ MS_DELAY();
|
92
|
89
|
CRITICAL_SECTION_START
|
93
|
90
|
WRITE(MAX7219_LOAD_PIN, LOW); // begin
|
94
|
|
- #ifdef CPU_32_BIT // The 32-bit processors are so fast, a small delay in the code is needed
|
95
|
|
- delayMicroseconds(5); // to let the signal wires stabilize.
|
96
|
|
- #endif
|
|
91
|
+ MS_DELAY();
|
97
|
92
|
Max7219_PutByte(reg); // specify register
|
98
|
|
- #ifdef CPU_32_BIT
|
99
|
|
- delayMicroseconds(5);
|
100
|
|
- #endif
|
|
93
|
+ MS_DELAY();
|
101
|
94
|
Max7219_PutByte(data); // put data
|
102
|
|
- #ifdef CPU_32_BIT
|
103
|
|
- delayMicroseconds(5);
|
104
|
|
- #endif
|
|
95
|
+ MS_DELAY();
|
105
|
96
|
WRITE(MAX7219_LOAD_PIN, LOW); // and tell the chip to load the data
|
106
|
|
- #ifdef CPU_32_BIT
|
107
|
|
- delayMicroseconds(5);
|
108
|
|
- #endif
|
|
97
|
+ MS_DELAY();
|
109
|
98
|
WRITE(MAX7219_LOAD_PIN, HIGH);
|
110
|
99
|
CRITICAL_SECTION_END
|
111
|
|
- #ifdef CPU_32_BIT
|
112
|
|
- delayMicroseconds(5);
|
113
|
|
- #endif
|
|
100
|
+ MS_DELAY();
|
114
|
101
|
}
|
115
|
102
|
|
116
|
103
|
void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on) {
|
|
@@ -329,23 +316,22 @@ void Max7219_idle_tasks() {
|
329
|
316
|
|
330
|
317
|
#if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
|
331
|
318
|
static millis_t next_blink = 0;
|
332
|
|
-
|
333
|
319
|
if (ELAPSED(millis(), next_blink)) {
|
334
|
|
- Max7219_LED_Toggle(7, 7);
|
335
|
|
- next_blink = millis() + 750;
|
|
320
|
+ Max7219_LED_Toggle(7, 7);
|
|
321
|
+ next_blink = millis() + 750;
|
336
|
322
|
}
|
337
|
323
|
#endif
|
338
|
324
|
|
339
|
325
|
#ifdef MAX7219_DEBUG_STEPPER_HEAD
|
340
|
326
|
static int16_t last_head_cnt=0;
|
341
|
327
|
if (last_head_cnt != head) {
|
342
|
|
- if ( last_head_cnt < 8)
|
|
328
|
+ if (last_head_cnt < 8)
|
343
|
329
|
Max7219_LED_Off( last_head_cnt, MAX7219_DEBUG_STEPPER_HEAD);
|
344
|
330
|
else
|
345
|
331
|
Max7219_LED_Off( last_head_cnt-8, MAX7219_DEBUG_STEPPER_HEAD+1);
|
346
|
332
|
|
347
|
333
|
last_head_cnt = head;
|
348
|
|
- if ( head < 8)
|
|
334
|
+ if (head < 8)
|
349
|
335
|
Max7219_LED_On(head, MAX7219_DEBUG_STEPPER_HEAD);
|
350
|
336
|
else
|
351
|
337
|
Max7219_LED_On(head-8, MAX7219_DEBUG_STEPPER_HEAD+1);
|
|
@@ -355,13 +341,13 @@ void Max7219_idle_tasks() {
|
355
|
341
|
#ifdef MAX7219_DEBUG_STEPPER_TAIL
|
356
|
342
|
static int16_t last_tail_cnt=0;
|
357
|
343
|
if (last_tail_cnt != tail) {
|
358
|
|
- if ( last_tail_cnt < 8)
|
|
344
|
+ if (last_tail_cnt < 8)
|
359
|
345
|
Max7219_LED_Off( last_tail_cnt, MAX7219_DEBUG_STEPPER_TAIL);
|
360
|
346
|
else
|
361
|
347
|
Max7219_LED_Off( last_tail_cnt-8, MAX7219_DEBUG_STEPPER_TAIL+1);
|
362
|
348
|
|
363
|
349
|
last_tail_cnt = tail;
|
364
|
|
- if ( tail < 8)
|
|
350
|
+ if (tail < 8)
|
365
|
351
|
Max7219_LED_On(tail, MAX7219_DEBUG_STEPPER_TAIL);
|
366
|
352
|
else
|
367
|
353
|
Max7219_LED_On(tail-8, MAX7219_DEBUG_STEPPER_TAIL+1);
|
|
@@ -381,10 +367,10 @@ void Max7219_idle_tasks() {
|
381
|
367
|
en = max(current_depth, last_depth);
|
382
|
368
|
if (current_depth < last_depth)
|
383
|
369
|
for (uint8_t i = st; i <= en; i++) // clear the highest order LEDs
|
384
|
|
- Max7219_LED_Off(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
|
|
370
|
+ Max7219_LED_Off(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
|
385
|
371
|
else
|
386
|
|
- for (uint8_t i = st; i <= en; i++) // set the LEDs to current depth
|
387
|
|
- Max7219_LED_On(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
|
|
372
|
+ for (uint8_t i = st; i <= en; i++) // set the LEDs to current depth
|
|
373
|
+ Max7219_LED_On(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
|
388
|
374
|
|
389
|
375
|
last_depth = current_depth;
|
390
|
376
|
}
|