My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

serial.h 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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. #pragma once
  23. #include "../inc/MarlinConfig.h"
  24. /**
  25. * Define debug bit-masks
  26. */
  27. enum MarlinDebugFlags : uint8_t {
  28. MARLIN_DEBUG_NONE = 0,
  29. MARLIN_DEBUG_ECHO = _BV(0), ///< Echo commands in order as they are processed
  30. MARLIN_DEBUG_INFO = _BV(1), ///< Print messages for code that has debug output
  31. MARLIN_DEBUG_ERRORS = _BV(2), ///< Not implemented
  32. MARLIN_DEBUG_DRYRUN = _BV(3), ///< Ignore temperature setting and E movement commands
  33. MARLIN_DEBUG_COMMUNICATION = _BV(4), ///< Not implemented
  34. #if ENABLED(DEBUG_LEVELING_FEATURE)
  35. MARLIN_DEBUG_LEVELING = _BV(5), ///< Print detailed output for homing and leveling
  36. MARLIN_DEBUG_MESH_ADJUST = _BV(6), ///< UBL bed leveling
  37. #else
  38. MARLIN_DEBUG_LEVELING = 0,
  39. MARLIN_DEBUG_MESH_ADJUST = 0,
  40. #endif
  41. MARLIN_DEBUG_ALL = 0xFF
  42. };
  43. extern uint8_t marlin_debug_flags;
  44. #define DEBUGGING(F) (marlin_debug_flags & (MARLIN_DEBUG_## F))
  45. #define SERIAL_BOTH 0x7F
  46. #if NUM_SERIAL > 1
  47. extern int8_t serial_port_index;
  48. #define _PORT_REDIRECT(n,p) REMEMBER(n,serial_port_index,p)
  49. #define _PORT_RESTORE(n) RESTORE(n)
  50. #define SERIAL_OUT(WHAT, V...) do{ \
  51. if (!serial_port_index || serial_port_index == SERIAL_BOTH) (void)MYSERIAL0.WHAT(V); \
  52. if ( serial_port_index) (void)MYSERIAL1.WHAT(V); \
  53. }while(0)
  54. #define SERIAL_ASSERT(P) if(serial_port_index!=(P)){ debugger(); }
  55. #else
  56. #define _PORT_REDIRECT(n,p) NOOP
  57. #define _PORT_RESTORE(n) NOOP
  58. #define SERIAL_OUT(WHAT, V...) (void)MYSERIAL0.WHAT(V)
  59. #define SERIAL_ASSERT(P) NOOP
  60. #endif
  61. #define PORT_REDIRECT(p) _PORT_REDIRECT(1,p)
  62. #define PORT_RESTORE() _PORT_RESTORE(1)
  63. #define SERIAL_CHAR(x) SERIAL_OUT(write, x)
  64. #define SERIAL_ECHO(x) SERIAL_OUT(print, x)
  65. #define SERIAL_ECHO_F(V...) SERIAL_OUT(print, V)
  66. #define SERIAL_ECHOLN(x) SERIAL_OUT(println, x)
  67. #define SERIAL_PRINT(x,b) SERIAL_OUT(print, x, b)
  68. #define SERIAL_PRINTLN(x,b) SERIAL_OUT(println, x, b)
  69. #define SERIAL_PRINTF(V...) SERIAL_OUT(printf, V)
  70. #define SERIAL_FLUSH() SERIAL_OUT(flush)
  71. #if TX_BUFFER_SIZE > 0
  72. #define SERIAL_FLUSHTX() SERIAL_OUT(flushTX)
  73. #else
  74. #define SERIAL_FLUSHTX()
  75. #endif
  76. // Print up to 12 pairs of values
  77. #define __SEP_N(N,V...) _SEP_##N(V)
  78. #define _SEP_N(N,V...) __SEP_N(N,V)
  79. #define _SEP_1(PRE) SERIAL_ECHOPGM(PRE)
  80. #define _SEP_2(PRE,V) serial_echopair_PGM(PSTR(PRE),V)
  81. #define _SEP_3(a,b,c) do{ _SEP_2(a,b); SERIAL_ECHOPGM(c); }while(0)
  82. #define _SEP_4(a,b,V...) do{ _SEP_2(a,b); _SEP_2(V); }while(0)
  83. #define _SEP_5(a,b,V...) do{ _SEP_2(a,b); _SEP_3(V); }while(0)
  84. #define _SEP_6(a,b,V...) do{ _SEP_2(a,b); _SEP_4(V); }while(0)
  85. #define _SEP_7(a,b,V...) do{ _SEP_2(a,b); _SEP_5(V); }while(0)
  86. #define _SEP_8(a,b,V...) do{ _SEP_2(a,b); _SEP_6(V); }while(0)
  87. #define _SEP_9(a,b,V...) do{ _SEP_2(a,b); _SEP_7(V); }while(0)
  88. #define _SEP_10(a,b,V...) do{ _SEP_2(a,b); _SEP_8(V); }while(0)
  89. #define _SEP_11(a,b,V...) do{ _SEP_2(a,b); _SEP_9(V); }while(0)
  90. #define _SEP_12(a,b,V...) do{ _SEP_2(a,b); _SEP_10(V); }while(0)
  91. #define _SEP_13(a,b,V...) do{ _SEP_2(a,b); _SEP_11(V); }while(0)
  92. #define _SEP_14(a,b,V...) do{ _SEP_2(a,b); _SEP_12(V); }while(0)
  93. #define _SEP_15(a,b,V...) do{ _SEP_2(a,b); _SEP_13(V); }while(0)
  94. #define _SEP_16(a,b,V...) do{ _SEP_2(a,b); _SEP_14(V); }while(0)
  95. #define _SEP_17(a,b,V...) do{ _SEP_2(a,b); _SEP_15(V); }while(0)
  96. #define _SEP_18(a,b,V...) do{ _SEP_2(a,b); _SEP_16(V); }while(0)
  97. #define _SEP_19(a,b,V...) do{ _SEP_2(a,b); _SEP_17(V); }while(0)
  98. #define _SEP_20(a,b,V...) do{ _SEP_2(a,b); _SEP_18(V); }while(0)
  99. #define _SEP_21(a,b,V...) do{ _SEP_2(a,b); _SEP_19(V); }while(0)
  100. #define _SEP_22(a,b,V...) do{ _SEP_2(a,b); _SEP_20(V); }while(0)
  101. #define _SEP_23(a,b,V...) do{ _SEP_2(a,b); _SEP_21(V); }while(0)
  102. #define _SEP_24(a,b,V...) do{ _SEP_2(a,b); _SEP_22(V); }while(0)
  103. #define SERIAL_ECHOPAIR(V...) _SEP_N(NUM_ARGS(V),V)
  104. // Print up to 12 pairs of values followed by newline
  105. #define __SELP_N(N,V...) _SELP_##N(V)
  106. #define _SELP_N(N,V...) __SELP_N(N,V)
  107. #define _SELP_1(PRE) SERIAL_ECHOLNPGM(PRE)
  108. #define _SELP_2(PRE,V) do{ serial_echopair_PGM(PSTR(PRE),V); SERIAL_EOL(); }while(0)
  109. #define _SELP_3(a,b,c) do{ _SEP_2(a,b); SERIAL_ECHOLNPGM(c); }while(0)
  110. #define _SELP_4(a,b,V...) do{ _SEP_2(a,b); _SELP_2(V); }while(0)
  111. #define _SELP_5(a,b,V...) do{ _SEP_2(a,b); _SELP_3(V); }while(0)
  112. #define _SELP_6(a,b,V...) do{ _SEP_2(a,b); _SELP_4(V); }while(0)
  113. #define _SELP_7(a,b,V...) do{ _SEP_2(a,b); _SELP_5(V); }while(0)
  114. #define _SELP_8(a,b,V...) do{ _SEP_2(a,b); _SELP_6(V); }while(0)
  115. #define _SELP_9(a,b,V...) do{ _SEP_2(a,b); _SELP_7(V); }while(0)
  116. #define _SELP_10(a,b,V...) do{ _SEP_2(a,b); _SELP_8(V); }while(0)
  117. #define _SELP_11(a,b,V...) do{ _SEP_2(a,b); _SELP_9(V); }while(0)
  118. #define _SELP_12(a,b,V...) do{ _SEP_2(a,b); _SELP_10(V); }while(0)
  119. #define _SELP_13(a,b,V...) do{ _SEP_2(a,b); _SELP_11(V); }while(0)
  120. #define _SELP_14(a,b,V...) do{ _SEP_2(a,b); _SELP_12(V); }while(0)
  121. #define _SELP_15(a,b,V...) do{ _SEP_2(a,b); _SELP_13(V); }while(0)
  122. #define _SELP_16(a,b,V...) do{ _SEP_2(a,b); _SELP_14(V); }while(0)
  123. #define _SELP_17(a,b,V...) do{ _SEP_2(a,b); _SELP_15(V); }while(0)
  124. #define _SELP_18(a,b,V...) do{ _SEP_2(a,b); _SELP_16(V); }while(0)
  125. #define _SELP_19(a,b,V...) do{ _SEP_2(a,b); _SELP_17(V); }while(0)
  126. #define _SELP_20(a,b,V...) do{ _SEP_2(a,b); _SELP_18(V); }while(0)
  127. #define _SELP_21(a,b,V...) do{ _SEP_2(a,b); _SELP_19(V); }while(0)
  128. #define _SELP_22(a,b,V...) do{ _SEP_2(a,b); _SELP_20(V); }while(0)
  129. #define _SELP_23(a,b,V...) do{ _SEP_2(a,b); _SELP_21(V); }while(0)
  130. #define _SELP_24(a,b,V...) do{ _SEP_2(a,b); _SELP_22(V); }while(0)
  131. #define SERIAL_ECHOLNPAIR(V...) _SELP_N(NUM_ARGS(V),V)
  132. #define SERIAL_ECHOPGM(S) (serialprintPGM(PSTR(S)))
  133. #define SERIAL_ECHOLNPGM(S) (serialprintPGM(PSTR(S "\n")))
  134. #define SERIAL_ECHOPAIR_F(pre, V...) do{ SERIAL_ECHO(pre); SERIAL_ECHO_F(V); }while(0)
  135. #define SERIAL_ECHOLNPAIR_F(V...) do{ SERIAL_ECHOPAIR_F(V); SERIAL_EOL(); }while(0)
  136. #define SERIAL_ECHO_START() serial_echo_start()
  137. #define SERIAL_ERROR_START() serial_error_start()
  138. #define SERIAL_EOL() SERIAL_CHAR('\n')
  139. #define SERIAL_ECHO_MSG(S) do{ SERIAL_ECHO_START(); SERIAL_ECHOLNPGM(S); }while(0)
  140. #define SERIAL_ERROR_MSG(S) do{ SERIAL_ERROR_START(); SERIAL_ECHOLNPGM(S); }while(0)
  141. #define SERIAL_ECHO_SP(C) serial_spaces(C)
  142. //
  143. // Functions for serial printing from PROGMEM. (Saves loads of SRAM.)
  144. //
  145. void serial_echopair_PGM(PGM_P const s_P, const char *v);
  146. void serial_echopair_PGM(PGM_P const s_P, char v);
  147. void serial_echopair_PGM(PGM_P const s_P, int v);
  148. void serial_echopair_PGM(PGM_P const s_P, long v);
  149. void serial_echopair_PGM(PGM_P const s_P, float v);
  150. void serial_echopair_PGM(PGM_P const s_P, double v);
  151. void serial_echopair_PGM(PGM_P const s_P, unsigned int v);
  152. void serial_echopair_PGM(PGM_P const s_P, unsigned long v);
  153. inline void serial_echopair_PGM(PGM_P const s_P, uint8_t v) { serial_echopair_PGM(s_P, (int)v); }
  154. inline void serial_echopair_PGM(PGM_P const s_P, bool v) { serial_echopair_PGM(s_P, (int)v); }
  155. inline void serial_echopair_PGM(PGM_P const s_P, void *v) { serial_echopair_PGM(s_P, (unsigned long)v); }
  156. void serialprintPGM(PGM_P str);
  157. void serial_echo_start();
  158. void serial_error_start();
  159. void serial_ternary(const bool onoff, PGM_P const pre, PGM_P const on, PGM_P const off, PGM_P const post=nullptr);
  160. void serialprint_onoff(const bool onoff);
  161. void serialprintln_onoff(const bool onoff);
  162. void serialprint_truefalse(const bool tf);
  163. void serial_spaces(uint8_t count);
  164. void print_bin(const uint16_t val);
  165. void print_xyz(PGM_P const prefix, PGM_P const suffix, const float x, const float y, const float z);
  166. void print_xyz(PGM_P const prefix, PGM_P const suffix, const float xyz[]);
  167. #define SERIAL_POS(SUFFIX,VAR) do { print_xyz(PSTR(" " STRINGIFY(VAR) "="), PSTR(" : " SUFFIX "\n"), VAR); }while(0)
  168. #define SERIAL_XYZ(PREFIX,V...) do { print_xyz(PSTR(PREFIX), nullptr, V); }while(0)