123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
-
-
-
-
- #include "MarlinConfig.h"
-
- #if ENABLED(MAX7219_DEBUG)
-
- #include "Marlin.h"
- #include "planner.h"
- #include "stepper.h"
- #include "Max7219_Debug_LEDs.h"
-
- static uint8_t LEDs[8] = { 0 };
-
- void Max7219_PutByte(uint8_t data) {
- for (uint8_t i = 8; i--;) {
- WRITE(MAX7219_CLK_PIN, LOW);
- WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW);
- WRITE(MAX7219_CLK_PIN, HIGH);
- data <<= 1;
- }
- }
-
- void Max7219(const uint8_t reg, const uint8_t data) {
- WRITE(MAX7219_LOAD_PIN, LOW);
- Max7219_PutByte(reg);
- Max7219_PutByte(data);
- WRITE(MAX7219_LOAD_PIN, LOW);
- WRITE(MAX7219_LOAD_PIN, HIGH);
- }
-
- void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on) {
- if (row > 7 || col > 7) 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 row, const uint8_t col) {
- Max7219_LED_Set(row, col, true);
- }
-
- void Max7219_LED_Off(const uint8_t row, const uint8_t col) {
- Max7219_LED_Set(row, col, false);
- }
-
- void Max7219_LED_Toggle(const uint8_t row, const uint8_t col) {
- if (row > 7 || col > 7) return;
- if (TEST(LEDs[row], col))
- Max7219_LED_Off(row, col);
- else
- Max7219_LED_On(row, col);
- }
-
- void Max7219_Clear_Column(const uint8_t col) {
- if (col > 7) return;
- LEDs[col] = 0;
- Max7219(8 - col, LEDs[col]);
- }
-
- void Max7219_Clear_Row(const uint8_t row) {
- if (row > 7) 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) 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_Column(const uint8_t col, const uint8_t val) {
- if (col > 7) 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);
-
-
- 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 ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
- static int debug_cnt = 0;
- if (debug_cnt++ > 100) {
- Max7219_LED_Toggle(7, 7);
- debug_cnt = 0;
- }
- #endif
-
- #ifdef MAX7219_DEBUG_STEPPER_HEAD
- Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_HEAD);
- Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_HEAD + 1);
- if ( planner.block_buffer_head < 8)
- Max7219_LED_On( planner.block_buffer_head, MAX7219_DEBUG_STEPPER_HEAD);
- else
- Max7219_LED_On( planner.block_buffer_head-8, MAX7219_DEBUG_STEPPER_HEAD+1);
- #endif
-
- #ifdef MAX7219_DEBUG_STEPPER_TAIL
- Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_TAIL);
- Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_TAIL + 1);
- if ( planner.block_buffer_tail < 8)
- Max7219_LED_On( planner.block_buffer_tail, MAX7219_DEBUG_STEPPER_TAIL );
- else
- Max7219_LED_On( planner.block_buffer_tail-8, MAX7219_DEBUG_STEPPER_TAIL+1 );
- #endif
-
- #ifdef MAX7219_DEBUG_STEPPER_QUEUE
- static int16_t last_depth = 0;
- int16_t current_depth = planner.block_buffer_head - planner.block_buffer_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 >> 1, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
- else
- for (uint8_t i = st; i <= en; i++)
- Max7219_LED_On(i >> 1, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
-
- last_depth = current_depth;
- }
- #endif
- }
-
- #endif
|