123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
-
-
-
-
- #include "MarlinConfig.h"
-
- #if ENABLED(MAX7219_DEBUG)
-
- #include "Max7219_Debug_LEDs.h"
-
- #include "planner.h"
- #include "stepper.h"
- #include "Marlin.h"
-
- static uint8_t LEDs[8] = { 0 };
-
- #ifdef CPU_32_BIT
- #define MS_DELAY() delayMicroseconds(5)
- #else
- #define MS_DELAY() NOOP
- #endif
-
- void Max7219_PutByte(uint8_t data) {
- CRITICAL_SECTION_START
- for (uint8_t i = 8; i--;) {
- MS_DELAY();
- WRITE(MAX7219_CLK_PIN, LOW);
- MS_DELAY();
- WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW);
- MS_DELAY();
- WRITE(MAX7219_CLK_PIN, HIGH);
- MS_DELAY();
- data <<= 1;
- }
- CRITICAL_SECTION_END
- }
-
- void Max7219(const uint8_t reg, const uint8_t data) {
- MS_DELAY();
- CRITICAL_SECTION_START
- WRITE(MAX7219_LOAD_PIN, LOW);
- MS_DELAY();
- Max7219_PutByte(reg);
- MS_DELAY();
- Max7219_PutByte(data);
- MS_DELAY();
- WRITE(MAX7219_LOAD_PIN, LOW);
- MS_DELAY();
- WRITE(MAX7219_LOAD_PIN, HIGH);
- CRITICAL_SECTION_END
- MS_DELAY();
- }
-
- void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on) {
- if (row > 7 || col > 7) {
- SERIAL_ECHOPAIR("??? Max7219_LED_Set(", (int)row);
- SERIAL_ECHOPAIR(",", (int)col);
- SERIAL_ECHOLNPGM(")");
- return;
- }
- if (TEST(LEDs[row], col) == on) return;
- if (on) SBI(LEDs[row], col); else CBI(LEDs[row], col);
- Max7219(8 - row, LEDs[row]);
- }
-
- void Max7219_LED_On(const uint8_t col, const uint8_t row) {
- if (row > 7 || col > 7) {
- SERIAL_ECHOPAIR("??? Max7219_LED_On(", (int)col);
- SERIAL_ECHOPAIR(",", (int)row);
- SERIAL_ECHOLNPGM(")");
- return;
- }
- Max7219_LED_Set(col, row, true);
- }
-
- void Max7219_LED_Off(const uint8_t col, const uint8_t row) {
- if (row > 7 || col > 7) {
- SERIAL_ECHOPAIR("??? Max7219_LED_Off(", (int)row);
- SERIAL_ECHOPAIR(",", (int)col);
- SERIAL_ECHOLNPGM(")");
- return;
- }
- Max7219_LED_Set(col, row, false);
- }
-
- void Max7219_LED_Toggle(const uint8_t col, const uint8_t row) {
- if (row > 7 || col > 7) {
- SERIAL_ECHOPAIR("??? Max7219_LED_Toggle(", (int)row);
- SERIAL_ECHOPAIR(",", (int)col);
- SERIAL_ECHOLNPGM(")");
- return;
- }
- if (TEST(LEDs[row], col))
- Max7219_LED_Off(col, row);
- else
- Max7219_LED_On(col, row);
- }
-
- void Max7219_Clear_Column(const uint8_t col) {
- if (col > 7) {
- SERIAL_ECHOPAIR("??? Max7219_Clear_Column(", (int)col);
- SERIAL_ECHOLNPGM(")");
- return;
- }
- LEDs[col] = 0;
- Max7219(8 - col, LEDs[col]);
- }
-
- void Max7219_Clear_Row(const uint8_t row) {
- if (row > 7) {
- SERIAL_ECHOPAIR("??? Max7219_Clear_Row(", (int)row);
- 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) {
- if (row > 7) {
- SERIAL_ECHOPAIR("??? Max7219_Set_Row(", (int)row);
- 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) {
- if (row > 6) {
- SERIAL_ECHOPAIR("??? Max7219_Set_2_Rows(", (int)row);
- 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) {
- if (row > 4) {
- SERIAL_ECHOPAIR("??? Max7219_Set_4_Rows(", (int)row);
- SERIAL_ECHOPAIR(",", (long)val);
- SERIAL_ECHOLNPGM(")");
- return;
- }
- Max7219_Set_Row(row + 3, (val >> 24) & 0xFF);
- Max7219_Set_Row(row + 2, (val >> 16) & 0xFF);
- Max7219_Set_Row(row + 1, (val >> 8) & 0xFF);
- Max7219_Set_Row(row + 0, (val ) & 0xFF);
- }
-
- void Max7219_Set_Column(const uint8_t col, const uint8_t val) {
- if (col > 7) {
- SERIAL_ECHOPAIR("??? Max7219_Column(", (int)col);
- SERIAL_ECHOPAIR(",", (int)val);
- SERIAL_ECHOLNPGM(")");
- return;
- }
- LEDs[col] = val;
- Max7219(8 - col, LEDs[col]);
- }
-
- void Max7219_init() {
- uint8_t i, x, y;
-
- SET_OUTPUT(MAX7219_DIN_PIN);
- SET_OUTPUT(MAX7219_CLK_PIN);
-
- OUT_WRITE(MAX7219_LOAD_PIN, HIGH);
- delay(1);
-
-
- Max7219(max7219_reg_scanLimit, 0x07);
- Max7219(max7219_reg_decodeMode, 0x00);
- Max7219(max7219_reg_shutdown, 0x01);
- Max7219(max7219_reg_displayTest, 0x00);
- Max7219(max7219_reg_intensity, 0x01 & 0x0F);
-
- for (i = 0; i <= 7; i++) {
- LEDs[i] = 0x00;
- Max7219(i + 1, 0);
- }
-
- for (x = 0; x <= 7; x++)
- for (y = 0; y <= 7; y++) {
- Max7219_LED_On(x, y);
- delay(3);
- }
-
- for (x = 0; x <= 7; x++)
- for (y = 0; y <= 7; y++) {
- Max7219_LED_Off(x, y);
- delay(3);
- }
-
- delay(150);
-
- for (x = 8; x--;)
- for (y = 0; y <= 7; y++) {
- Max7219_LED_On(x, y);
- delay(2);
- }
-
- for (x = 8; x--;)
- for (y = 0; y <= 7; y++) {
- Max7219_LED_Off(x, y);
- delay(2);
- }
- }
-
-
- void Max7219_idle_tasks() {
- #if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
- CRITICAL_SECTION_START
- #if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_QUEUE
- const uint8_t head = planner.block_buffer_head;
- #endif
- #if MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
- const uint8_t tail = planner.block_buffer_tail;
- #endif
- CRITICAL_SECTION_END
- #endif
-
- #if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
- static millis_t next_blink = 0;
- if (ELAPSED(millis(), next_blink)) {
- Max7219_LED_Toggle(7, 7);
- next_blink = millis() + 750;
- }
- #endif
-
- #ifdef MAX7219_DEBUG_STEPPER_HEAD
- static int16_t last_head_cnt = 0;
- if (last_head_cnt != head) {
- if (last_head_cnt < 8)
- Max7219_LED_Off(last_head_cnt, MAX7219_DEBUG_STEPPER_HEAD);
- else
- Max7219_LED_Off(last_head_cnt - 8, MAX7219_DEBUG_STEPPER_HEAD + 1);
-
- last_head_cnt = head;
- if (head < 8)
- Max7219_LED_On(head, MAX7219_DEBUG_STEPPER_HEAD);
- else
- Max7219_LED_On(head - 8, MAX7219_DEBUG_STEPPER_HEAD + 1);
- }
- #endif
-
- #ifdef MAX7219_DEBUG_STEPPER_TAIL
- static int16_t last_tail_cnt = 0;
- if (last_tail_cnt != tail) {
- if (last_tail_cnt < 8)
- Max7219_LED_Off(last_tail_cnt, MAX7219_DEBUG_STEPPER_TAIL);
- else
- Max7219_LED_Off(last_tail_cnt - 8, MAX7219_DEBUG_STEPPER_TAIL + 1);
-
- last_tail_cnt = tail;
- if (tail < 8)
- Max7219_LED_On(tail, MAX7219_DEBUG_STEPPER_TAIL);
- else
- Max7219_LED_On(tail - 8, MAX7219_DEBUG_STEPPER_TAIL + 1);
- }
- #endif
-
- #ifdef MAX7219_DEBUG_STEPPER_QUEUE
- static int16_t last_depth = 0;
- int16_t current_depth = head - tail;
- if (current_depth != last_depth) {
- if (current_depth < 0) current_depth += BLOCK_BUFFER_SIZE;
- NOMORE(current_depth, BLOCK_BUFFER_SIZE);
- NOMORE(current_depth, 16);
-
-
- 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++)
- Max7219_LED_Off(i / 2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
- else
- for (uint8_t i = st; i <= en; i++)
- Max7219_LED_On(i / 2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
-
- last_depth = current_depth;
- }
- #endif
- }
-
- #endif
|