|
|
@ -63,54 +63,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
static uint8_t LEDs[8] = { 0 };
|
|
|
|
static uint8_t LEDs[8] = { 0 };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CPU_32_BIT
|
|
|
|
|
|
|
|
#define MS_DELAY() delayMicroseconds(5) // 32-bit processors need a delay to stabilize the signal
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define MS_DELAY() NOOP
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_PutByte(uint8_t data) {
|
|
|
|
void Max7219_PutByte(uint8_t data) {
|
|
|
|
CRITICAL_SECTION_START
|
|
|
|
CRITICAL_SECTION_START
|
|
|
|
for (uint8_t i = 8; i--;) {
|
|
|
|
for (uint8_t i = 8; i--;) {
|
|
|
|
#ifdef CPU_32_BIT // The 32-bit processors are so fast, a small delay in the code is needed
|
|
|
|
MS_DELAY();
|
|
|
|
delayMicroseconds(5); // to let the signal wires stabilize.
|
|
|
|
WRITE(MAX7219_CLK_PIN, LOW); // tick
|
|
|
|
WRITE(MAX7219_CLK_PIN, LOW); // tick
|
|
|
|
MS_DELAY();
|
|
|
|
delayMicroseconds(5);
|
|
|
|
WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit
|
|
|
|
WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit
|
|
|
|
MS_DELAY();
|
|
|
|
delayMicroseconds(5);
|
|
|
|
WRITE(MAX7219_CLK_PIN, HIGH); // tock
|
|
|
|
WRITE(MAX7219_CLK_PIN, HIGH); // tock
|
|
|
|
MS_DELAY();
|
|
|
|
delayMicroseconds(5);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
WRITE(MAX7219_CLK_PIN, LOW); // tick
|
|
|
|
|
|
|
|
WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit
|
|
|
|
|
|
|
|
WRITE(MAX7219_CLK_PIN, HIGH); // tock
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data <<= 1;
|
|
|
|
data <<= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CRITICAL_SECTION_END
|
|
|
|
CRITICAL_SECTION_END
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219(const uint8_t reg, const uint8_t data) {
|
|
|
|
void Max7219(const uint8_t reg, const uint8_t data) {
|
|
|
|
#ifdef CPU_32_BIT
|
|
|
|
MS_DELAY();
|
|
|
|
delayMicroseconds(5);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CRITICAL_SECTION_START
|
|
|
|
CRITICAL_SECTION_START
|
|
|
|
WRITE(MAX7219_LOAD_PIN, LOW); // begin
|
|
|
|
WRITE(MAX7219_LOAD_PIN, LOW); // begin
|
|
|
|
#ifdef CPU_32_BIT // The 32-bit processors are so fast, a small delay in the code is needed
|
|
|
|
MS_DELAY();
|
|
|
|
delayMicroseconds(5); // to let the signal wires stabilize.
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Max7219_PutByte(reg); // specify register
|
|
|
|
Max7219_PutByte(reg); // specify register
|
|
|
|
#ifdef CPU_32_BIT
|
|
|
|
MS_DELAY();
|
|
|
|
delayMicroseconds(5);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Max7219_PutByte(data); // put data
|
|
|
|
Max7219_PutByte(data); // put data
|
|
|
|
#ifdef CPU_32_BIT
|
|
|
|
MS_DELAY();
|
|
|
|
delayMicroseconds(5);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
WRITE(MAX7219_LOAD_PIN, LOW); // and tell the chip to load the data
|
|
|
|
WRITE(MAX7219_LOAD_PIN, LOW); // and tell the chip to load the data
|
|
|
|
#ifdef CPU_32_BIT
|
|
|
|
MS_DELAY();
|
|
|
|
delayMicroseconds(5);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
WRITE(MAX7219_LOAD_PIN, HIGH);
|
|
|
|
WRITE(MAX7219_LOAD_PIN, HIGH);
|
|
|
|
CRITICAL_SECTION_END
|
|
|
|
CRITICAL_SECTION_END
|
|
|
|
#ifdef CPU_32_BIT
|
|
|
|
MS_DELAY();
|
|
|
|
delayMicroseconds(5);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on) {
|
|
|
|
void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on) {
|
|
|
@ -329,23 +316,22 @@ void Max7219_idle_tasks() {
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
|
|
|
|
#if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
|
|
|
|
static millis_t next_blink = 0;
|
|
|
|
static millis_t next_blink = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (ELAPSED(millis(), next_blink)) {
|
|
|
|
if (ELAPSED(millis(), next_blink)) {
|
|
|
|
Max7219_LED_Toggle(7, 7);
|
|
|
|
Max7219_LED_Toggle(7, 7);
|
|
|
|
next_blink = millis() + 750;
|
|
|
|
next_blink = millis() + 750;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef MAX7219_DEBUG_STEPPER_HEAD
|
|
|
|
#ifdef MAX7219_DEBUG_STEPPER_HEAD
|
|
|
|
static int16_t last_head_cnt=0;
|
|
|
|
static int16_t last_head_cnt=0;
|
|
|
|
if (last_head_cnt != head) {
|
|
|
|
if (last_head_cnt != head) {
|
|
|
|
if ( last_head_cnt < 8)
|
|
|
|
if (last_head_cnt < 8)
|
|
|
|
Max7219_LED_Off( last_head_cnt, MAX7219_DEBUG_STEPPER_HEAD);
|
|
|
|
Max7219_LED_Off( last_head_cnt, MAX7219_DEBUG_STEPPER_HEAD);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
Max7219_LED_Off( last_head_cnt-8, MAX7219_DEBUG_STEPPER_HEAD+1);
|
|
|
|
Max7219_LED_Off( last_head_cnt-8, MAX7219_DEBUG_STEPPER_HEAD+1);
|
|
|
|
|
|
|
|
|
|
|
|
last_head_cnt = head;
|
|
|
|
last_head_cnt = head;
|
|
|
|
if ( head < 8)
|
|
|
|
if (head < 8)
|
|
|
|
Max7219_LED_On(head, MAX7219_DEBUG_STEPPER_HEAD);
|
|
|
|
Max7219_LED_On(head, MAX7219_DEBUG_STEPPER_HEAD);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
Max7219_LED_On(head-8, MAX7219_DEBUG_STEPPER_HEAD+1);
|
|
|
|
Max7219_LED_On(head-8, MAX7219_DEBUG_STEPPER_HEAD+1);
|
|
|
@ -355,13 +341,13 @@ void Max7219_idle_tasks() {
|
|
|
|
#ifdef MAX7219_DEBUG_STEPPER_TAIL
|
|
|
|
#ifdef MAX7219_DEBUG_STEPPER_TAIL
|
|
|
|
static int16_t last_tail_cnt=0;
|
|
|
|
static int16_t last_tail_cnt=0;
|
|
|
|
if (last_tail_cnt != tail) {
|
|
|
|
if (last_tail_cnt != tail) {
|
|
|
|
if ( last_tail_cnt < 8)
|
|
|
|
if (last_tail_cnt < 8)
|
|
|
|
Max7219_LED_Off( last_tail_cnt, MAX7219_DEBUG_STEPPER_TAIL);
|
|
|
|
Max7219_LED_Off( last_tail_cnt, MAX7219_DEBUG_STEPPER_TAIL);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
Max7219_LED_Off( last_tail_cnt-8, MAX7219_DEBUG_STEPPER_TAIL+1);
|
|
|
|
Max7219_LED_Off( last_tail_cnt-8, MAX7219_DEBUG_STEPPER_TAIL+1);
|
|
|
|
|
|
|
|
|
|
|
|
last_tail_cnt = tail;
|
|
|
|
last_tail_cnt = tail;
|
|
|
|
if ( tail < 8)
|
|
|
|
if (tail < 8)
|
|
|
|
Max7219_LED_On(tail, MAX7219_DEBUG_STEPPER_TAIL);
|
|
|
|
Max7219_LED_On(tail, MAX7219_DEBUG_STEPPER_TAIL);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
Max7219_LED_On(tail-8, MAX7219_DEBUG_STEPPER_TAIL+1);
|
|
|
|
Max7219_LED_On(tail-8, MAX7219_DEBUG_STEPPER_TAIL+1);
|
|
|
@ -381,10 +367,10 @@ void Max7219_idle_tasks() {
|
|
|
|
en = max(current_depth, last_depth);
|
|
|
|
en = max(current_depth, last_depth);
|
|
|
|
if (current_depth < last_depth)
|
|
|
|
if (current_depth < last_depth)
|
|
|
|
for (uint8_t i = st; i <= en; i++) // clear the highest order LEDs
|
|
|
|
for (uint8_t i = st; i <= en; i++) // clear the highest order LEDs
|
|
|
|
Max7219_LED_Off(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
|
|
|
|
Max7219_LED_Off(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
|
|
|
|
else
|
|
|
|
else
|
|
|
|
for (uint8_t i = st; i <= en; i++) // set the LEDs to current depth
|
|
|
|
for (uint8_t i = st; i <= en; i++) // set the LEDs to current depth
|
|
|
|
Max7219_LED_On(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
|
|
|
|
Max7219_LED_On(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
|
|
|
|
|
|
|
|
|
|
|
|
last_depth = current_depth;
|
|
|
|
last_depth = current_depth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|