|
|
@ -22,11 +22,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* This module is off by default, but can be enabled to facilitate the display of
|
|
|
|
* This module is off by default, but can be enabled to facilitate the display of
|
|
|
|
* extra debug information during code development. It assumes the existence of a
|
|
|
|
* extra debug information during code development.
|
|
|
|
* Max7219 LED Matrix. A suitable device can be obtained on eBay similar to this:
|
|
|
|
|
|
|
|
* http://www.ebay.com/itm/191781645249 for under $2.00 including shipping.
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Just connect up +5v and GND to give it power, then connect up the pins assigned
|
|
|
|
* Just connect up 5V and GND to give it power, then connect up the pins assigned
|
|
|
|
* in Configuration_adv.h. For example, on the Re-ARM you could use:
|
|
|
|
* in Configuration_adv.h. For example, on the Re-ARM you could use:
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* #define MAX7219_CLK_PIN 77
|
|
|
|
* #define MAX7219_CLK_PIN 77
|
|
|
@ -35,26 +33,14 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Max7219_init() is called automatically at startup, and then there are a number of
|
|
|
|
* Max7219_init() is called automatically at startup, and then there are a number of
|
|
|
|
* support functions available to control the LEDs in the 8x8 grid.
|
|
|
|
* support functions available to control the LEDs in the 8x8 grid.
|
|
|
|
*
|
|
|
|
|
|
|
|
* void Max7219_init();
|
|
|
|
|
|
|
|
* void Max7219_PutByte(uint8_t data);
|
|
|
|
|
|
|
|
* void Max7219(uint8_t reg, uint8_t data);
|
|
|
|
|
|
|
|
* void Max7219_LED_On(uint8_t col, uint8_t row);
|
|
|
|
|
|
|
|
* void Max7219_LED_Off(uint8_t col, uint8_t row);
|
|
|
|
|
|
|
|
* void Max7219_LED_Toggle(uint8_t col, uint8_t row);
|
|
|
|
|
|
|
|
* void Max7219_Clear_Row(uint8_t row);
|
|
|
|
|
|
|
|
* void Max7219_Clear_Column(uint8_t col);
|
|
|
|
|
|
|
|
* void Max7219_Set_Row(uint8_t row, uint8_t val);
|
|
|
|
|
|
|
|
* void Max7219_Set_2_Rows(uint8_t row, uint16_t val);
|
|
|
|
|
|
|
|
* void Max7219_Set_4_Rows(uint8_t row, uint32_t val);
|
|
|
|
|
|
|
|
* void Max7219_Set_Column(uint8_t col, uint8_t val);
|
|
|
|
|
|
|
|
* void Max7219_idle_tasks();
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
#include "../inc/MarlinConfigPre.h"
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(MAX7219_DEBUG)
|
|
|
|
#if ENABLED(MAX7219_DEBUG)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MAX7219_ERRORS // Disable to save 406 bytes of Program Memory
|
|
|
|
|
|
|
|
|
|
|
|
#include "Max7219_Debug_LEDs.h"
|
|
|
|
#include "Max7219_Debug_LEDs.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "../module/planner.h"
|
|
|
|
#include "../module/planner.h"
|
|
|
@ -64,6 +50,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
static uint8_t LEDs[8] = { 0 };
|
|
|
|
static uint8_t LEDs[8] = { 0 };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef MAX7219_ROTATE
|
|
|
|
|
|
|
|
#define MAX7219_ROTATE 0
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define _ROT ((MAX7219_ROTATE + 360) % 360)
|
|
|
|
|
|
|
|
#if _ROT == 0
|
|
|
|
|
|
|
|
#define _ROW_ y
|
|
|
|
|
|
|
|
#define _COL_ x
|
|
|
|
|
|
|
|
#define XOR_7219(x, y) LEDs[y] ^= _BV(7 - x)
|
|
|
|
|
|
|
|
#define BIT_7219(x, y) TEST(LEDs[y], 7 - x)
|
|
|
|
|
|
|
|
#define SEND_7219(R,V) Max7219(max7219_reg_digit0 + R, V)
|
|
|
|
|
|
|
|
#elif _ROT == 90
|
|
|
|
|
|
|
|
#define _ROW_ x
|
|
|
|
|
|
|
|
#define _COL_ y
|
|
|
|
|
|
|
|
#define XOR_7219(x, y) LEDs[x] ^= _BV(y)
|
|
|
|
|
|
|
|
#define BIT_7219(x, y) TEST(LEDs[x], y)
|
|
|
|
|
|
|
|
#define SEND_7219(R,V) Max7219(max7219_reg_digit0 + R, V)
|
|
|
|
|
|
|
|
#elif _ROT == 180
|
|
|
|
|
|
|
|
#define _ROW_ y
|
|
|
|
|
|
|
|
#define _COL_ x
|
|
|
|
|
|
|
|
#define XOR_7219(x, y) LEDs[y] ^= _BV(x)
|
|
|
|
|
|
|
|
#define BIT_7219(x, y) TEST(LEDs[y], x)
|
|
|
|
|
|
|
|
#define SEND_7219(R,V) Max7219(max7219_reg_digit7 - R, V)
|
|
|
|
|
|
|
|
#elif _ROT == 270
|
|
|
|
|
|
|
|
#define _ROW_ x
|
|
|
|
|
|
|
|
#define _COL_ y
|
|
|
|
|
|
|
|
#define XOR_7219(x, y) LEDs[x] ^= _BV(7 - y)
|
|
|
|
|
|
|
|
#define BIT_7219(x, y) TEST(LEDs[x], 7 - y)
|
|
|
|
|
|
|
|
#define SEND_7219(R,V) Max7219(max7219_reg_digit7 - R, V)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#error "MAX7219_ROTATE must be a multiple of +/- 90°."
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CPU_32_BIT
|
|
|
|
#ifdef CPU_32_BIT
|
|
|
|
// Approximate a 1µs delay on 32-bit ARM
|
|
|
|
// Approximate a 1µs delay on 32-bit ARM
|
|
|
|
#define SIG_DELAY() DELAY_US(1)
|
|
|
|
#define SIG_DELAY() DELAY_US(1)
|
|
|
@ -73,6 +91,9 @@ static uint8_t LEDs[8] = { 0 };
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_PutByte(uint8_t data) {
|
|
|
|
void Max7219_PutByte(uint8_t data) {
|
|
|
|
|
|
|
|
#ifndef CPU_32_BIT
|
|
|
|
|
|
|
|
CRITICAL_SECTION_START;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
for (uint8_t i = 8; i--;) {
|
|
|
|
for (uint8_t i = 8; i--;) {
|
|
|
|
SIG_DELAY();
|
|
|
|
SIG_DELAY();
|
|
|
|
WRITE(MAX7219_CLK_PIN, LOW); // tick
|
|
|
|
WRITE(MAX7219_CLK_PIN, LOW); // tick
|
|
|
@ -83,10 +104,16 @@ void Max7219_PutByte(uint8_t data) {
|
|
|
|
SIG_DELAY();
|
|
|
|
SIG_DELAY();
|
|
|
|
data <<= 1;
|
|
|
|
data <<= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef CPU_32_BIT
|
|
|
|
|
|
|
|
CRITICAL_SECTION_END;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219(const uint8_t reg, const uint8_t data) {
|
|
|
|
void Max7219(const uint8_t reg, const uint8_t data) {
|
|
|
|
SIG_DELAY();
|
|
|
|
SIG_DELAY();
|
|
|
|
|
|
|
|
#ifndef CPU_32_BIT
|
|
|
|
|
|
|
|
CRITICAL_SECTION_START;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
WRITE(MAX7219_LOAD_PIN, LOW); // begin
|
|
|
|
WRITE(MAX7219_LOAD_PIN, LOW); // begin
|
|
|
|
SIG_DELAY();
|
|
|
|
SIG_DELAY();
|
|
|
|
Max7219_PutByte(reg); // specify register
|
|
|
|
Max7219_PutByte(reg); // specify register
|
|
|
@ -96,125 +123,168 @@ void Max7219(const uint8_t reg, const uint8_t data) {
|
|
|
|
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
|
|
|
|
SIG_DELAY();
|
|
|
|
SIG_DELAY();
|
|
|
|
WRITE(MAX7219_LOAD_PIN, HIGH);
|
|
|
|
WRITE(MAX7219_LOAD_PIN, HIGH);
|
|
|
|
|
|
|
|
#ifndef CPU_32_BIT
|
|
|
|
|
|
|
|
CRITICAL_SECTION_END;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
SIG_DELAY();
|
|
|
|
SIG_DELAY();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_LED_Set(const uint8_t col, const uint8_t row, const bool on) {
|
|
|
|
#if ENABLED(MAX7219_NUMERIC)
|
|
|
|
if (row > 7 || col > 7) {
|
|
|
|
|
|
|
|
SERIAL_ECHOPAIR("??? Max7219_LED_Set(", (int)row);
|
|
|
|
// Draw an integer with optional leading zeros and optional decimal point
|
|
|
|
SERIAL_ECHOPAIR(",", (int)col);
|
|
|
|
void Max7219_Print(const uint8_t start, int16_t value, uint8_t size, const bool leadzero=false, bool dec=false) {
|
|
|
|
SERIAL_ECHOLNPGM(")");
|
|
|
|
constexpr uint8_t led_numeral[10] = { 0x7E, 0x60, 0x6D, 0x79, 0x63, 0x5B, 0x5F, 0x70, 0x7F, 0x7A },
|
|
|
|
return;
|
|
|
|
led_decimal = 0x80, led_minus = 0x01;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool blank = false, neg = value < 0;
|
|
|
|
|
|
|
|
if (neg) value *= -1;
|
|
|
|
|
|
|
|
while (size--) {
|
|
|
|
|
|
|
|
const bool minus = neg && blank;
|
|
|
|
|
|
|
|
if (minus) neg = false;
|
|
|
|
|
|
|
|
Max7219(
|
|
|
|
|
|
|
|
max7219_reg_digit0 + start + size,
|
|
|
|
|
|
|
|
minus ? led_minus : blank ? 0x00 : led_numeral[value % 10] | (dec ? led_decimal : 0x00)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
value /= 10;
|
|
|
|
|
|
|
|
if (!value && !leadzero) blank = true;
|
|
|
|
|
|
|
|
dec = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (TEST(LEDs[col], row) == on) return; // if LED is already on/off, leave alone
|
|
|
|
|
|
|
|
if (on) SBI(LEDs[col], row); else CBI(LEDs[col], row);
|
|
|
|
|
|
|
|
Max7219(8 - col, LEDs[col]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_LED_On(const uint8_t col, const uint8_t row) {
|
|
|
|
// Draw a float with a decimal point and optional digits
|
|
|
|
if (row > 7 || col > 7) {
|
|
|
|
void Max7219_Print(const uint8_t start, const float value, const uint8_t pre_size, const uint8_t post_size, const bool leadzero=false) {
|
|
|
|
SERIAL_ECHOPAIR("??? Max7219_LED_On(", (int)col);
|
|
|
|
if (pre_size) Max7219_Print(start, value, pre_size, leadzero, !!post_size);
|
|
|
|
SERIAL_ECHOPAIR(",", (int)row);
|
|
|
|
if (post_size) {
|
|
|
|
SERIAL_ECHOLNPGM(")");
|
|
|
|
const int16_t after = ABS(value) * (10 ^ post_size);
|
|
|
|
return;
|
|
|
|
Max7219_Print(start + pre_size, after, post_size, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Max7219_LED_Set(col, row, true);
|
|
|
|
|
|
|
|
|
|
|
|
#endif // MAX7219_NUMERIC
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline void Max7219_Error(const char * const func, const int32_t v1, const int32_t v2=-1) {
|
|
|
|
|
|
|
|
#if ENABLED(MAX7219_ERRORS)
|
|
|
|
|
|
|
|
SERIAL_ECHOPGM("??? ");
|
|
|
|
|
|
|
|
serialprintPGM(func);
|
|
|
|
|
|
|
|
SERIAL_CHAR('(');
|
|
|
|
|
|
|
|
SERIAL_ECHO(v1);
|
|
|
|
|
|
|
|
if (v2 > 0) SERIAL_ECHOPAIR(", ", v2);
|
|
|
|
|
|
|
|
SERIAL_CHAR(')');
|
|
|
|
|
|
|
|
SERIAL_EOL();
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
UNUSED(func); UNUSED(v1); UNUSED(v2);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_LED_Off(const uint8_t col, const uint8_t row) {
|
|
|
|
inline uint8_t flipped(const uint8_t bits) {
|
|
|
|
if (row > 7 || col > 7) {
|
|
|
|
uint8_t outbits = 0;
|
|
|
|
SERIAL_ECHOPAIR("??? Max7219_LED_Off(", (int)row);
|
|
|
|
for (uint8_t b = 0; b < 8; b++)
|
|
|
|
SERIAL_ECHOPAIR(",", (int)col);
|
|
|
|
if (bits & _BV(b)) outbits |= _BV(7 - b);
|
|
|
|
SERIAL_ECHOLNPGM(")");
|
|
|
|
return outbits;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Max7219_LED_Set(col, row, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_LED_Toggle(const uint8_t col, const uint8_t row) {
|
|
|
|
// Modify a single LED bit and send the changed line
|
|
|
|
if (row > 7 || col > 7) {
|
|
|
|
void Max7219_LED_Set(const uint8_t x, const uint8_t y, const bool on) {
|
|
|
|
SERIAL_ECHOPAIR("??? Max7219_LED_Toggle(", (int)row);
|
|
|
|
if (x > 7 || y > 7) return Max7219_Error(PSTR("Max7219_LED_Set"), x, y);
|
|
|
|
SERIAL_ECHOPAIR(",", (int)col);
|
|
|
|
if (BIT_7219(x, y) == on) return;
|
|
|
|
SERIAL_ECHOLNPGM(")");
|
|
|
|
XOR_7219(x, y);
|
|
|
|
return;
|
|
|
|
SEND_7219(_ROW_, LEDs[_ROW_]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TEST(LEDs[row], col))
|
|
|
|
|
|
|
|
Max7219_LED_Off(col, row);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
Max7219_LED_On(col, row);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_Clear_Column(const uint8_t col) {
|
|
|
|
void Max7219_LED_On(const uint8_t x, const uint8_t y) {
|
|
|
|
if (col > 7) {
|
|
|
|
if (x > 7 || y > 7) return Max7219_Error(PSTR("Max7219_LED_On"), x, y);
|
|
|
|
SERIAL_ECHOPAIR("??? Max7219_Clear_Column(", (int)col);
|
|
|
|
Max7219_LED_Set(x, y, true);
|
|
|
|
SERIAL_ECHOLNPGM(")");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
LEDs[col] = 0;
|
|
|
|
|
|
|
|
Max7219(8 - col, LEDs[col]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_Clear_Row(const uint8_t row) {
|
|
|
|
void Max7219_LED_Off(const uint8_t x, const uint8_t y) {
|
|
|
|
if (row > 7) {
|
|
|
|
if (x > 7 || y > 7) return Max7219_Error(PSTR("Max7219_LED_Off"), x, y);
|
|
|
|
SERIAL_ECHOPAIR("??? Max7219_Clear_Row(", (int)row);
|
|
|
|
Max7219_LED_Set(x, y, false);
|
|
|
|
SERIAL_ECHOLNPGM(")");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint8_t c = 0; c <= 7; c++)
|
|
|
|
|
|
|
|
Max7219_LED_Off(c, row);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_Set_Row(const uint8_t row, const uint8_t val) {
|
|
|
|
void Max7219_LED_Toggle(const uint8_t x, const uint8_t y) {
|
|
|
|
if (row > 7) {
|
|
|
|
if (x > 7 || y > 7) return Max7219_Error(PSTR("Max7219_LED_Toggle"), x, y);
|
|
|
|
SERIAL_ECHOPAIR("??? Max7219_Set_Row(", (int)row);
|
|
|
|
Max7219_LED_Set(x, y, !BIT_7219(x, y));
|
|
|
|
SERIAL_ECHOPAIR(",", (int)val);
|
|
|
|
|
|
|
|
SERIAL_ECHOLNPGM(")");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint8_t b = 0; b <= 7; b++)
|
|
|
|
|
|
|
|
if (TEST(val, b))
|
|
|
|
|
|
|
|
Max7219_LED_On(7 - b, row);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
Max7219_LED_Off(7 - b, row);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_Set_2_Rows(const uint8_t row, const uint16_t val) {
|
|
|
|
inline void _Max7219_Set_Reg(const uint8_t reg, const uint8_t val) {
|
|
|
|
if (row > 6) {
|
|
|
|
LEDs[reg] = val;
|
|
|
|
SERIAL_ECHOPAIR("??? Max7219_Set_2_Rows(", (int)row);
|
|
|
|
SEND_7219(reg, val);
|
|
|
|
SERIAL_ECHOPAIR(",", (int)val);
|
|
|
|
|
|
|
|
SERIAL_ECHOLNPGM(")");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Max7219_Set_Row(row + 1, (val >> 8) & 0xFF);
|
|
|
|
|
|
|
|
Max7219_Set_Row(row + 0, (val ) & 0xFF);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_Set_4_Rows(const uint8_t row, const uint32_t val) {
|
|
|
|
void Max7219_Set_Row(const uint8_t _ROW_, const uint8_t val) {
|
|
|
|
if (row > 4) {
|
|
|
|
if (_ROW_ > 7) return Max7219_Error(PSTR("Max7219_Set_Row"), _ROW_);
|
|
|
|
SERIAL_ECHOPAIR("??? Max7219_Set_4_Rows(", (int)row);
|
|
|
|
#if _ROT == 90
|
|
|
|
SERIAL_ECHOPAIR(",", (long)val);
|
|
|
|
for (uint8_t _COL_ = 0; _COL_ <= 7; _COL_++) Max7219_LED_Set(7 - _COL_, _ROW_, TEST(val, _COL_));
|
|
|
|
SERIAL_ECHOLNPGM(")");
|
|
|
|
#elif _ROT == 180
|
|
|
|
return;
|
|
|
|
_Max7219_Set_Reg(_ROW_, flipped(val));
|
|
|
|
}
|
|
|
|
#elif _ROT == 270
|
|
|
|
Max7219_Set_Row(row + 3, (val >> 24) & 0xFF);
|
|
|
|
for (uint8_t _COL_ = 0; _COL_ <= 7; _COL_++) Max7219_LED_Set(_COL_, _ROW_, TEST(val, _COL_));
|
|
|
|
Max7219_Set_Row(row + 2, (val >> 16) & 0xFF);
|
|
|
|
#else
|
|
|
|
Max7219_Set_Row(row + 1, (val >> 8) & 0xFF);
|
|
|
|
_Max7219_Set_Reg(_ROW_, val);
|
|
|
|
Max7219_Set_Row(row + 0, (val ) & 0xFF);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_Set_Column(const uint8_t col, const uint8_t val) {
|
|
|
|
void Max7219_Clear_Row(const uint8_t _ROW_) {
|
|
|
|
if (col > 7) {
|
|
|
|
if (_ROW_ > 7) return Max7219_Error(PSTR("Max7219_Clear_Row"), _ROW_);
|
|
|
|
SERIAL_ECHOPAIR("??? Max7219_Column(", (int)col);
|
|
|
|
#if _ROT == 90 || _ROT == 270
|
|
|
|
SERIAL_ECHOPAIR(",", (int)val);
|
|
|
|
for (uint8_t _COL_ = 0; _COL_ <= 7; _COL_++) Max7219_LED_Off(_COL_, _ROW_);
|
|
|
|
SERIAL_ECHOLNPGM(")");
|
|
|
|
#else
|
|
|
|
return;
|
|
|
|
_Max7219_Set_Reg(_ROW_, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
LEDs[col] = val;
|
|
|
|
}
|
|
|
|
Max7219(8 - col, LEDs[col]);
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_Set_Column(const uint8_t _COL_, const uint8_t val) {
|
|
|
|
|
|
|
|
if (_COL_ > 7) return Max7219_Error(PSTR("Max7219_Set_Column"), _COL_);
|
|
|
|
|
|
|
|
#if _ROT == 90
|
|
|
|
|
|
|
|
_Max7219_Set_Reg(_COL_, val);
|
|
|
|
|
|
|
|
#elif _ROT == 180
|
|
|
|
|
|
|
|
for (uint8_t _ROW_ = 0; _ROW_ <= 7; _ROW_++) Max7219_LED_Set(_COL_, _ROW_, TEST(val, _ROW_));
|
|
|
|
|
|
|
|
#elif _ROT == 270
|
|
|
|
|
|
|
|
_Max7219_Set_Reg(_COL_, flipped(val));
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
for (uint8_t _ROW_ = 0; _ROW_ <= 7; _ROW_++) Max7219_LED_Set(_COL_, _ROW_, TEST(val, _ROW_));
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_Clear_Column(const uint8_t _COL_) {
|
|
|
|
|
|
|
|
if (_COL_ > 7) return Max7219_Error(PSTR("Max7219_Clear_Column"), _COL_);
|
|
|
|
|
|
|
|
#if _ROT == 90 || _ROT == 270
|
|
|
|
|
|
|
|
_Max7219_Set_Reg(_COL_, 0);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
for (uint8_t _ROW_ = 0; _ROW_ <= 7; _ROW_++) Max7219_LED_Off(_COL_, _ROW_);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_Set_2_Rows(const uint8_t y, uint16_t val) {
|
|
|
|
|
|
|
|
if (y > 6) return Max7219_Error(PSTR("Max7219_Set_2_Rows"), y, val);
|
|
|
|
|
|
|
|
Max7219_Set_Row(y + 0, val & 0xFF); val >>= 8;
|
|
|
|
|
|
|
|
Max7219_Set_Row(y + 1, val & 0xFF);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_Set_4_Rows(const uint8_t y, uint32_t val) {
|
|
|
|
|
|
|
|
if (y > 4) return Max7219_Error(PSTR("Max7219_Set_4_Rows"), y, val);
|
|
|
|
|
|
|
|
Max7219_Set_Row(y + 0, val & 0xFF); val >>= 8;
|
|
|
|
|
|
|
|
Max7219_Set_Row(y + 1, val & 0xFF); val >>= 8;
|
|
|
|
|
|
|
|
Max7219_Set_Row(y + 2, val & 0xFF); val >>= 8;
|
|
|
|
|
|
|
|
Max7219_Set_Row(y + 3, val & 0xFF);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_Set_2_Columns(const uint8_t x, uint16_t val) {
|
|
|
|
|
|
|
|
if (x > 6) return Max7219_Error(PSTR("Max7219_Set_2_Columns"), x, val);
|
|
|
|
|
|
|
|
Max7219_Set_Column(x + 0, val & 0xFF); val >>= 8;
|
|
|
|
|
|
|
|
Max7219_Set_Column(x + 1, val & 0xFF);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_Set_4_Columns(const uint8_t x, uint32_t val) {
|
|
|
|
|
|
|
|
if (x > 4) return Max7219_Error(PSTR("Max7219_Set_4_Columns"), x, val);
|
|
|
|
|
|
|
|
Max7219_Set_Column(x + 0, val & 0xFF); val >>= 8;
|
|
|
|
|
|
|
|
Max7219_Set_Column(x + 1, val & 0xFF); val >>= 8;
|
|
|
|
|
|
|
|
Max7219_Set_Column(x + 2, val & 0xFF); val >>= 8;
|
|
|
|
|
|
|
|
Max7219_Set_Column(x + 3, val & 0xFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_register_setup() {
|
|
|
|
void Max7219_register_setup() {
|
|
|
|
//initiation of the max 7219
|
|
|
|
// Initialize the Max7219
|
|
|
|
Max7219(max7219_reg_scanLimit, 0x07);
|
|
|
|
Max7219(max7219_reg_scanLimit, 0x07);
|
|
|
|
Max7219(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits)
|
|
|
|
Max7219(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits)
|
|
|
|
Max7219(max7219_reg_shutdown, 0x01); // not in shutdown mode
|
|
|
|
Max7219(max7219_reg_shutdown, 0x01); // not in shutdown mode
|
|
|
@ -223,135 +293,173 @@ void Max7219_register_setup() {
|
|
|
|
// range: 0x00 to 0x0F
|
|
|
|
// range: 0x00 to 0x0F
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_init() {
|
|
|
|
#ifdef MAX7219_INIT_TEST
|
|
|
|
uint8_t i, x, y;
|
|
|
|
#if (MAX7219_INIT_TEST + 0) == 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline void Max7219_spiral(const bool on, const uint16_t del) {
|
|
|
|
|
|
|
|
constexpr int8_t way[] = { 1, 0, 0, 1, -1, 0, 0, -1 };
|
|
|
|
|
|
|
|
int8_t px = 0, py = 0, dir = 0;
|
|
|
|
|
|
|
|
for (uint8_t i = 64; i--;) {
|
|
|
|
|
|
|
|
Max7219_LED_Set(px, py, on);
|
|
|
|
|
|
|
|
delay(del);
|
|
|
|
|
|
|
|
const int8_t x = px + way[dir], y = py + way[dir + 1];
|
|
|
|
|
|
|
|
if (!WITHIN(x, 0, 7) || !WITHIN(y, 0, 7) || BIT_7219(x, y) == on) dir = (dir + 2) & 0x7;
|
|
|
|
|
|
|
|
px += way[dir]; py += way[dir + 1];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline void Max7219_colset(const uint8_t x, const bool on) {
|
|
|
|
|
|
|
|
for (uint8_t y = 0; y <= 7; y++) Max7219_LED_Set(x, y, on);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Max7219_sweep(const int8_t dir, const uint16_t ms, const bool on) {
|
|
|
|
|
|
|
|
uint8_t x = dir > 0 ? 0 : 7;
|
|
|
|
|
|
|
|
for (uint8_t i = 8; i--; x += dir) {
|
|
|
|
|
|
|
|
Max7219_Set_Column(x, on ? 0xFF : 0x00);
|
|
|
|
|
|
|
|
delay(ms);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // MAX7219_INIT_TEST
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Max7219_init() {
|
|
|
|
SET_OUTPUT(MAX7219_DIN_PIN);
|
|
|
|
SET_OUTPUT(MAX7219_DIN_PIN);
|
|
|
|
SET_OUTPUT(MAX7219_CLK_PIN);
|
|
|
|
SET_OUTPUT(MAX7219_CLK_PIN);
|
|
|
|
|
|
|
|
|
|
|
|
OUT_WRITE(MAX7219_LOAD_PIN, HIGH);
|
|
|
|
OUT_WRITE(MAX7219_LOAD_PIN, HIGH);
|
|
|
|
delay(1);
|
|
|
|
delay(1);
|
|
|
|
|
|
|
|
|
|
|
|
Max7219_register_setup();
|
|
|
|
Max7219_register_setup();
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i <= 7; i++) { // empty registers, turn all LEDs off
|
|
|
|
for (uint8_t i = 0; i <= 7; i++) { // Empty registers to turn all LEDs off
|
|
|
|
LEDs[i] = 0x00;
|
|
|
|
LEDs[i] = 0x00;
|
|
|
|
Max7219(i + 1, 0);
|
|
|
|
Max7219(max7219_reg_digit0 + i, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (x = 0; x <= 7; x++) // Do an aesthetically pleasing pattern to fully test
|
|
|
|
#ifdef MAX7219_INIT_TEST
|
|
|
|
for (y = 0; y <= 7; y++) { // the Max7219 module and LEDs. First, turn them
|
|
|
|
#if (MAX7219_INIT_TEST + 0) == 2
|
|
|
|
Max7219_LED_On(y, x); // all on.
|
|
|
|
Max7219_spiral(true, 8);
|
|
|
|
delay(3);
|
|
|
|
delay(150);
|
|
|
|
}
|
|
|
|
Max7219_spiral(false, 8);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
// Do an aesthetically-pleasing pattern to fully test the Max7219 module and LEDs.
|
|
|
|
|
|
|
|
// Light up and turn off columns, both forward and backward.
|
|
|
|
|
|
|
|
Max7219_sweep(1, 20, true);
|
|
|
|
|
|
|
|
Max7219_sweep(1, 20, false);
|
|
|
|
|
|
|
|
delay(150);
|
|
|
|
|
|
|
|
Max7219_sweep(-1, 20, true);
|
|
|
|
|
|
|
|
Max7219_sweep(-1, 20, false);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (x = 0; x <= 7; x++) // Now, turn them all off.
|
|
|
|
/**
|
|
|
|
for (y = 0; y <= 7; y++) {
|
|
|
|
* This code demonstrates some simple debugging using a single 8x8 LED Matrix. If your feature could
|
|
|
|
Max7219_LED_Off(y, x);
|
|
|
|
* benefit from matrix display, add its code here. Very little processing is required, so the 7219 is
|
|
|
|
delay(3); // delay() is OK here. Max7219_init() is only called from
|
|
|
|
* ideal for debugging when realtime feedback is important but serial output can't be used.
|
|
|
|
} // setup() and nothing is running yet.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
delay(150);
|
|
|
|
// Apply changes to update a marker
|
|
|
|
|
|
|
|
inline void Max7219_Mark16(const uint8_t y, const uint8_t v1, const uint8_t v2) {
|
|
|
|
|
|
|
|
Max7219_LED_Off(v1 & 0x7, y + (v1 >= 8));
|
|
|
|
|
|
|
|
Max7219_LED_On(v2 & 0x7, y + (v2 >= 8));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (x = 8; x--;) // Now, do the same thing from the opposite direction
|
|
|
|
// Apply changes to update a tail-to-head range
|
|
|
|
for (y = 0; y <= 7; y++) {
|
|
|
|
inline void Max7219_Range16(const uint8_t y, const uint8_t ot, const uint8_t nt, const uint8_t oh, const uint8_t nh) {
|
|
|
|
Max7219_LED_On(y, x);
|
|
|
|
if (ot != nt) for (uint8_t n = ot & 0xF; n != (nt & 0xF) && n != (nh & 0xF); n = (n + 1) & 0xF)
|
|
|
|
delay(2);
|
|
|
|
Max7219_LED_Off(n & 0x7, y + (n >= 8));
|
|
|
|
}
|
|
|
|
if (oh != nh) for (uint8_t n = (oh + 1) & 0xF; n != ((nh + 1) & 0xF); n = (n + 1) & 0xF)
|
|
|
|
|
|
|
|
Max7219_LED_On(n & 0x7, y + (n >= 8));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (x = 8; x--;)
|
|
|
|
// Apply changes to update a quantity
|
|
|
|
for (y = 0; y <= 7; y++) {
|
|
|
|
inline void Max7219_Quantity16(const uint8_t y, const uint8_t ov, const uint8_t nv) {
|
|
|
|
Max7219_LED_Off(y, x);
|
|
|
|
for (uint8_t i = MIN(nv, ov); i < MAX(nv, ov); i++)
|
|
|
|
delay(2);
|
|
|
|
Max7219_LED_Set(i >> 1, y + (i & 1), nv >= ov);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* These are sample debug features to demonstrate the usage of the 8x8 LED Matrix for debug purposes.
|
|
|
|
|
|
|
|
* There is very little CPU burden added to the system by displaying information within the idle()
|
|
|
|
|
|
|
|
* task.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* But with that said, if your debugging can be facilitated by making calls into the library from
|
|
|
|
|
|
|
|
* other places in the code, feel free to do it. The CPU burden for a few calls to toggle an LED
|
|
|
|
|
|
|
|
* or clear a row is not very significant.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Max7219_idle_tasks() {
|
|
|
|
void Max7219_idle_tasks() {
|
|
|
|
#if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
|
|
|
|
#define MAX7219_USE_HEAD (defined(MAX7219_DEBUG_PLANNER_HEAD) || defined(MAX7219_DEBUG_PLANNER_QUEUE))
|
|
|
|
CRITICAL_SECTION_START;
|
|
|
|
#define MAX7219_USE_TAIL (defined(MAX7219_DEBUG_PLANNER_TAIL) || defined(MAX7219_DEBUG_PLANNER_QUEUE))
|
|
|
|
#if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_QUEUE
|
|
|
|
#if MAX7219_USE_HEAD || MAX7219_USE_TAIL
|
|
|
|
|
|
|
|
#ifndef CPU_32_BIT
|
|
|
|
|
|
|
|
CRITICAL_SECTION_START;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MAX7219_USE_HEAD
|
|
|
|
const uint8_t head = planner.block_buffer_head;
|
|
|
|
const uint8_t head = planner.block_buffer_head;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
|
|
|
|
#if MAX7219_USE_TAIL
|
|
|
|
const uint8_t tail = planner.block_buffer_tail;
|
|
|
|
const uint8_t tail = planner.block_buffer_tail;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
CRITICAL_SECTION_END;
|
|
|
|
#ifndef CPU_32_BIT
|
|
|
|
|
|
|
|
CRITICAL_SECTION_END;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
|
|
|
|
|
|
|
|
static uint8_t refresh_cnt; // = 0
|
|
|
|
|
|
|
|
constexpr uint16_t refresh_limit = 5;
|
|
|
|
|
|
|
|
static millis_t next_blink = 0;
|
|
|
|
|
|
|
|
const millis_t ms = millis();
|
|
|
|
|
|
|
|
const bool do_blink = ELAPSED(ms, next_blink);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static uint16_t refresh_cnt; // = 0
|
|
|
|
|
|
|
|
constexpr bool do_blink = true;
|
|
|
|
|
|
|
|
constexpr uint16_t refresh_limit = 50000;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
static uint16_t refresh_cnt = 0; // The Max7219 circuit boards available for several dollars on eBay
|
|
|
|
// Some Max7219 units are vulnerable to electrical noise, especially
|
|
|
|
if (refresh_cnt++ > 50000) { // are vulnerable to electrical noise, especially with long wires
|
|
|
|
// with long wires next to high current wires. If the display becomes
|
|
|
|
Max7219_register_setup(); // next to high current wires. If the display becomes corrupted due
|
|
|
|
// corrupted, this will fix it within a couple seconds.
|
|
|
|
Max7219_LED_Toggle(7, 0); // to electrical noise, this will fix it within a couple of seconds.
|
|
|
|
if (do_blink && ++refresh_cnt >= refresh_limit) {
|
|
|
|
refresh_cnt = 0;
|
|
|
|
refresh_cnt = 0;
|
|
|
|
|
|
|
|
Max7219_register_setup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
|
|
|
|
#if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
|
|
|
|
static millis_t next_blink = 0;
|
|
|
|
if (do_blink) {
|
|
|
|
if (ELAPSED(millis(), next_blink)) {
|
|
|
|
|
|
|
|
Max7219_LED_Toggle(7, 7);
|
|
|
|
Max7219_LED_Toggle(7, 7);
|
|
|
|
next_blink = millis() + 750;
|
|
|
|
next_blink = ms + 1000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef MAX7219_DEBUG_STEPPER_HEAD
|
|
|
|
#if defined(MAX7219_DEBUG_PLANNER_HEAD) && defined(MAX7219_DEBUG_PLANNER_TAIL) && MAX7219_DEBUG_PLANNER_HEAD == MAX7219_DEBUG_PLANNER_TAIL
|
|
|
|
static int16_t last_head_cnt = 0;
|
|
|
|
|
|
|
|
if (last_head_cnt != head) {
|
|
|
|
static int16_t last_head_cnt = 0xF, last_tail_cnt = 0xF;
|
|
|
|
if (last_head_cnt < 8)
|
|
|
|
|
|
|
|
Max7219_LED_Off(MAX7219_DEBUG_STEPPER_HEAD, last_head_cnt);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
Max7219_LED_Off(MAX7219_DEBUG_STEPPER_HEAD + 1, last_head_cnt - 8);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (last_head_cnt != head || last_tail_cnt != tail) {
|
|
|
|
|
|
|
|
Max7219_Range16(MAX7219_DEBUG_PLANNER_HEAD, last_tail_cnt, tail, last_head_cnt, head);
|
|
|
|
last_head_cnt = head;
|
|
|
|
last_head_cnt = head;
|
|
|
|
if (head < 8)
|
|
|
|
last_tail_cnt = tail;
|
|
|
|
Max7219_LED_On(MAX7219_DEBUG_STEPPER_HEAD, head);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
Max7219_LED_On(MAX7219_DEBUG_STEPPER_HEAD + 1, head - 8);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef MAX7219_DEBUG_STEPPER_TAIL
|
|
|
|
#else
|
|
|
|
static int16_t last_tail_cnt = 0;
|
|
|
|
|
|
|
|
if (last_tail_cnt != tail) {
|
|
|
|
#ifdef MAX7219_DEBUG_PLANNER_HEAD
|
|
|
|
if (last_tail_cnt < 8)
|
|
|
|
static int16_t last_head_cnt = 0x1;
|
|
|
|
Max7219_LED_Off(MAX7219_DEBUG_STEPPER_TAIL, last_tail_cnt);
|
|
|
|
if (last_head_cnt != head) {
|
|
|
|
else
|
|
|
|
Max7219_Mark16(MAX7219_DEBUG_PLANNER_HEAD, last_head_cnt, head);
|
|
|
|
Max7219_LED_Off(MAX7219_DEBUG_STEPPER_TAIL + 1, last_tail_cnt - 8);
|
|
|
|
last_head_cnt = head;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef MAX7219_DEBUG_PLANNER_TAIL
|
|
|
|
|
|
|
|
static int16_t last_tail_cnt = 0x1;
|
|
|
|
|
|
|
|
if (last_tail_cnt != tail) {
|
|
|
|
|
|
|
|
Max7219_Mark16(MAX7219_DEBUG_PLANNER_TAIL, last_tail_cnt, tail);
|
|
|
|
|
|
|
|
last_tail_cnt = tail;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
last_tail_cnt = tail;
|
|
|
|
|
|
|
|
if (tail < 8)
|
|
|
|
|
|
|
|
Max7219_LED_On(MAX7219_DEBUG_STEPPER_TAIL, tail);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
Max7219_LED_On(MAX7219_DEBUG_STEPPER_TAIL + 1, tail - 8);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef MAX7219_DEBUG_STEPPER_QUEUE
|
|
|
|
#ifdef MAX7219_DEBUG_PLANNER_QUEUE
|
|
|
|
static int16_t last_depth = 0;
|
|
|
|
static int16_t last_depth = 0;
|
|
|
|
int16_t current_depth = head - tail;
|
|
|
|
const int16_t current_depth = (head - tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1) & 0xF;
|
|
|
|
if (current_depth != last_depth) { // usually, no update will be needed.
|
|
|
|
if (current_depth != last_depth) {
|
|
|
|
if (current_depth < 0) current_depth += BLOCK_BUFFER_SIZE;
|
|
|
|
Max7219_Quantity16(MAX7219_DEBUG_PLANNER_QUEUE, last_depth, current_depth);
|
|
|
|
NOMORE(current_depth, BLOCK_BUFFER_SIZE);
|
|
|
|
|
|
|
|
NOMORE(current_depth, 16); // if the BLOCK_BUFFER_SIZE is greater than 16, two lines
|
|
|
|
|
|
|
|
// of LEDs is enough to see if the buffer is draining
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const uint8_t st = MIN(current_depth, last_depth),
|
|
|
|
|
|
|
|
en = MAX(current_depth, last_depth);
|
|
|
|
|
|
|
|
if (current_depth < last_depth)
|
|
|
|
|
|
|
|
for (uint8_t i = st; i <= en; i++) // clear the highest order LEDs
|
|
|
|
|
|
|
|
Max7219_LED_Off(MAX7219_DEBUG_STEPPER_QUEUE + (i & 1), i / 2);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
for (uint8_t i = st; i <= en; i++) // set the LEDs to current depth
|
|
|
|
|
|
|
|
Max7219_LED_On(MAX7219_DEBUG_STEPPER_QUEUE + (i & 1), i / 2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
last_depth = current_depth;
|
|
|
|
last_depth = current_depth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|