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.9KB

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