My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Max7219_Debug_LEDs.cpp 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * This module is off by default, but can be enabled to facilitate the display of
  24. * extra debug information during code development. It assumes the existence of a
  25. * Max7219 LED Matrix. A suitable device can be obtained on eBay similar to this:
  26. * http://www.ebay.com/itm/191781645249 for under $2.00 including shipping.
  27. *
  28. * Just connect up +5v and GND to give it power, then connect up the pins assigned
  29. * in Configuration_adv.h. For example, on the Re-ARM you could use:
  30. *
  31. * #define MAX7219_CLK_PIN 77
  32. * #define MAX7219_DIN_PIN 78
  33. * #define MAX7219_LOAD_PIN 79
  34. *
  35. * Max7219_init() is called automatically at startup, and then there are a number of
  36. * support functions available to control the LEDs in the 8x8 grid.
  37. *
  38. * void Max7219_init();
  39. * void Max7219_PutByte(uint8_t data);
  40. * void Max7219(uint8_t reg, uint8_t data);
  41. * void Max7219_LED_On(uint8_t row, uint8_t col);
  42. * void Max7219_LED_Off(uint8_t row, uint8_t col);
  43. * void Max7219_LED_Toggle(uint8_t row, uint8_t col);
  44. * void Max7219_Clear_Row(uint8_t row);
  45. * void Max7219_Clear_Column(uint8_t col);
  46. * void Max7219_Set_Row(uint8_t row, uint8_t val);
  47. * void Max7219_Set_Column(uint8_t col, uint8_t val);
  48. * void Max7219_idle_tasks();
  49. */
  50. #include "MarlinConfig.h"
  51. #if ENABLED(MAX7219_DEBUG)
  52. #include "Marlin.h"
  53. #include "planner.h"
  54. #include "stepper.h"
  55. #include "Max7219_Debug_LEDs.h"
  56. static uint8_t LEDs[8] = { 0 };
  57. void Max7219_PutByte(uint8_t data) {
  58. for (uint8_t i = 8; i--;) {
  59. WRITE(MAX7219_CLK_PIN, LOW); // tick
  60. WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit
  61. WRITE(MAX7219_CLK_PIN, HIGH); // tock
  62. data <<= 1;
  63. }
  64. }
  65. void Max7219(const uint8_t reg, const uint8_t data) {
  66. WRITE(MAX7219_LOAD_PIN, LOW); // begin
  67. Max7219_PutByte(reg); // specify register
  68. Max7219_PutByte(data); // put data
  69. WRITE(MAX7219_LOAD_PIN, LOW); // and tell the chip to load the data
  70. WRITE(MAX7219_LOAD_PIN, HIGH);
  71. }
  72. void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on) {
  73. if (row > 7 || col > 7) return;
  74. if (TEST(LEDs[row], col) == on) return; // if LED is already on/off, leave alone
  75. if (on) SBI(LEDs[row], col); else CBI(LEDs[row], col);
  76. Max7219(8 - row, LEDs[row]);
  77. }
  78. void Max7219_LED_On(const uint8_t row, const uint8_t col) {
  79. Max7219_LED_Set(row, col, true);
  80. }
  81. void Max7219_LED_Off(const uint8_t row, const uint8_t col) {
  82. Max7219_LED_Set(row, col, false);
  83. }
  84. void Max7219_LED_Toggle(const uint8_t row, const uint8_t col) {
  85. if (row > 7 || col > 7) return;
  86. if (TEST(LEDs[row], col))
  87. Max7219_LED_Off(row, col);
  88. else
  89. Max7219_LED_On(row, col);
  90. }
  91. void Max7219_Clear_Column(const uint8_t col) {
  92. if (col > 7) return;
  93. LEDs[col] = 0;
  94. Max7219(8 - col, LEDs[col]);
  95. }
  96. void Max7219_Clear_Row(const uint8_t row) {
  97. if (row > 7) return;
  98. for (uint8_t c = 0; c <= 7; c++)
  99. Max7219_LED_Off(c, row);
  100. }
  101. void Max7219_Set_Row(const uint8_t row, const uint8_t val) {
  102. if (row > 7) return;
  103. for (uint8_t b = 0; b <= 7; b++)
  104. if (TEST(val, b))
  105. Max7219_LED_On(7 - b, row);
  106. else
  107. Max7219_LED_Off(7 - b, row);
  108. }
  109. void Max7219_Set_Column(const uint8_t col, const uint8_t val) {
  110. if (col > 7) return;
  111. LEDs[col] = val;
  112. Max7219(8 - col, LEDs[col]);
  113. }
  114. void Max7219_init() {
  115. uint8_t i, x, y;
  116. SET_OUTPUT(MAX7219_DIN_PIN);
  117. SET_OUTPUT(MAX7219_CLK_PIN);
  118. OUT_WRITE(MAX7219_LOAD_PIN, HIGH);
  119. //initiation of the max 7219
  120. Max7219(max7219_reg_scanLimit, 0x07);
  121. Max7219(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits)
  122. Max7219(max7219_reg_shutdown, 0x01); // not in shutdown mode
  123. Max7219(max7219_reg_displayTest, 0x00); // no display test
  124. Max7219(max7219_reg_intensity, 0x01 & 0x0F); // the first 0x0F is the value you can set
  125. // range: 0x00 to 0x0F
  126. for (i = 0; i <= 7; i++) { // empty registers, turn all LEDs off
  127. LEDs[i] = 0x00;
  128. Max7219(i + 1, 0);
  129. }
  130. for (x = 0; x <= 7; x++) // Do an aesthetically pleasing pattern to fully test
  131. for (y = 0; y <= 7; y++) { // the Max7219 module and LEDs. First, turn them
  132. Max7219_LED_On(x, y); // all on.
  133. delay(3);
  134. }
  135. for (x = 0; x <= 7; x++) // Now, turn them all off.
  136. for (y = 0; y <= 7; y++) {
  137. Max7219_LED_Off(x, y);
  138. delay(3); // delay() is OK here. Max7219_init() is only called from
  139. } // setup() and nothing is running yet.
  140. delay(150);
  141. for (x = 8; x--;) // Now, do the same thing from the opposite direction
  142. for (y = 0; y <= 7; y++) {
  143. Max7219_LED_On(x, y);
  144. delay(2);
  145. }
  146. for (x = 8; x--;)
  147. for (y = 0; y <= 7; y++) {
  148. Max7219_LED_Off(x, y);
  149. delay(2);
  150. }
  151. }
  152. /**
  153. * These are sample debug features to demonstrate the usage of the 8x8 LED Matrix for debug purposes.
  154. * There is very little CPU burden added to the system by displaying information within the idle()
  155. * task.
  156. *
  157. * But with that said, if your debugging can be facilitated by making calls into the library from
  158. * other places in the code, feel free to do it. The CPU burden for a few calls to toggle an LED
  159. * or clear a row is not very significant.
  160. */
  161. void Max7219_idle_tasks() {
  162. #if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
  163. static int debug_cnt = 0;
  164. if (debug_cnt++ > 100) {
  165. Max7219_LED_Toggle(7, 7);
  166. debug_cnt = 0;
  167. }
  168. #endif
  169. #ifdef MAX7219_DEBUG_STEPPER_HEAD
  170. Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_HEAD);
  171. Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_HEAD + 1);
  172. if ( planner.block_buffer_head < 8)
  173. Max7219_LED_On( planner.block_buffer_head, MAX7219_DEBUG_STEPPER_HEAD);
  174. else
  175. Max7219_LED_On( planner.block_buffer_head-8, MAX7219_DEBUG_STEPPER_HEAD+1);
  176. #endif
  177. #ifdef MAX7219_DEBUG_STEPPER_TAIL
  178. Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_TAIL);
  179. Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_TAIL + 1);
  180. if ( planner.block_buffer_tail < 8)
  181. Max7219_LED_On( planner.block_buffer_tail, MAX7219_DEBUG_STEPPER_TAIL );
  182. else
  183. Max7219_LED_On( planner.block_buffer_tail-8, MAX7219_DEBUG_STEPPER_TAIL+1 );
  184. #endif
  185. #ifdef MAX7219_DEBUG_STEPPER_QUEUE
  186. static int16_t last_depth = 0;
  187. int16_t current_depth = planner.block_buffer_head - planner.block_buffer_tail;
  188. if (current_depth != last_depth) { // usually, no update will be needed.
  189. if (current_depth < 0) current_depth += BLOCK_BUFFER_SIZE;
  190. NOMORE(current_depth, BLOCK_BUFFER_SIZE);
  191. NOMORE(current_depth, 16); // if the BLOCK_BUFFER_SIZE is greater than 16, two lines
  192. // of LEDs is enough to see if the buffer is draining
  193. const uint8_t st = min(current_depth, last_depth),
  194. en = max(current_depth, last_depth);
  195. if (current_depth < last_depth)
  196. for (uint8_t i = st; i <= en; i++) // clear the highest order LEDs
  197. Max7219_LED_Off(i >> 1, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
  198. else
  199. for (uint8_t i = st; i <= en; i++) // set the highest order LEDs
  200. Max7219_LED_On(i >> 1, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
  201. last_depth = current_depth;
  202. }
  203. #endif
  204. }
  205. #endif // MAX7219_DEBUG