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.

Marlin.h 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. #pragma once
  23. #include "inc/MarlinConfig.h"
  24. #ifdef DEBUG_GCODE_PARSER
  25. #include "gcode/parser.h"
  26. #endif
  27. #include <math.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. void stop();
  31. void idle(
  32. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  33. bool no_stepper_sleep = false // pass true to keep steppers from disabling on timeout
  34. #endif
  35. );
  36. void manage_inactivity(const bool ignore_stepper_queue=false);
  37. #if HAS_X2_ENABLE
  38. #define enable_X() do{ X_ENABLE_WRITE( X_ENABLE_ON); X2_ENABLE_WRITE( X_ENABLE_ON); }while(0)
  39. #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); CBI(axis_known_position, X_AXIS); }while(0)
  40. #elif HAS_X_ENABLE
  41. #define enable_X() X_ENABLE_WRITE( X_ENABLE_ON)
  42. #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); CBI(axis_known_position, X_AXIS); }while(0)
  43. #else
  44. #define enable_X() NOOP
  45. #define disable_X() NOOP
  46. #endif
  47. #if HAS_Y2_ENABLE
  48. #define enable_Y() do{ Y_ENABLE_WRITE( Y_ENABLE_ON); Y2_ENABLE_WRITE(Y_ENABLE_ON); }while(0)
  49. #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); CBI(axis_known_position, Y_AXIS); }while(0)
  50. #elif HAS_Y_ENABLE
  51. #define enable_Y() Y_ENABLE_WRITE( Y_ENABLE_ON)
  52. #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); CBI(axis_known_position, Y_AXIS); }while(0)
  53. #else
  54. #define enable_Y() NOOP
  55. #define disable_Y() NOOP
  56. #endif
  57. #if HAS_Z3_ENABLE
  58. #define enable_Z() do{ Z_ENABLE_WRITE( Z_ENABLE_ON); Z2_ENABLE_WRITE(Z_ENABLE_ON); Z3_ENABLE_WRITE(Z_ENABLE_ON); }while(0)
  59. #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); Z3_ENABLE_WRITE(!Z_ENABLE_ON); CBI(axis_known_position, Z_AXIS); }while(0)
  60. #elif HAS_Z2_ENABLE
  61. #define enable_Z() do{ Z_ENABLE_WRITE( Z_ENABLE_ON); Z2_ENABLE_WRITE(Z_ENABLE_ON); }while(0)
  62. #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); CBI(axis_known_position, Z_AXIS); }while(0)
  63. #elif HAS_Z_ENABLE
  64. #define enable_Z() Z_ENABLE_WRITE( Z_ENABLE_ON)
  65. #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); CBI(axis_known_position, Z_AXIS); }while(0)
  66. #else
  67. #define enable_Z() NOOP
  68. #define disable_Z() NOOP
  69. #endif
  70. #if ENABLED(MIXING_EXTRUDER)
  71. /**
  72. * Mixing steppers synchronize their enable (and direction) together
  73. */
  74. #if MIXING_STEPPERS > 5
  75. #define enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); E3_ENABLE_WRITE( E_ENABLE_ON); E4_ENABLE_WRITE( E_ENABLE_ON); E5_ENABLE_WRITE( E_ENABLE_ON); }
  76. #define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); E3_ENABLE_WRITE(!E_ENABLE_ON); E4_ENABLE_WRITE(!E_ENABLE_ON); E5_ENABLE_WRITE(!E_ENABLE_ON); }
  77. #elif MIXING_STEPPERS > 4
  78. #define enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); E3_ENABLE_WRITE( E_ENABLE_ON); E4_ENABLE_WRITE( E_ENABLE_ON); }
  79. #define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); E3_ENABLE_WRITE(!E_ENABLE_ON); E4_ENABLE_WRITE(!E_ENABLE_ON); }
  80. #elif MIXING_STEPPERS > 3
  81. #define enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); E3_ENABLE_WRITE( E_ENABLE_ON); }
  82. #define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); E3_ENABLE_WRITE(!E_ENABLE_ON); }
  83. #elif MIXING_STEPPERS > 2
  84. #define enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); }
  85. #define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); }
  86. #else
  87. #define enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); }
  88. #define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); }
  89. #endif
  90. #define enable_E1() NOOP
  91. #define disable_E1() NOOP
  92. #define enable_E2() NOOP
  93. #define disable_E2() NOOP
  94. #define enable_E3() NOOP
  95. #define disable_E3() NOOP
  96. #define enable_E4() NOOP
  97. #define disable_E4() NOOP
  98. #define enable_E5() NOOP
  99. #define disable_E5() NOOP
  100. #else // !MIXING_EXTRUDER
  101. #if HAS_E0_ENABLE
  102. #define enable_E0() E0_ENABLE_WRITE( E_ENABLE_ON)
  103. #define disable_E0() E0_ENABLE_WRITE(!E_ENABLE_ON)
  104. #else
  105. #define enable_E0() NOOP
  106. #define disable_E0() NOOP
  107. #endif
  108. #if E_STEPPERS > 1 && HAS_E1_ENABLE
  109. #define enable_E1() E1_ENABLE_WRITE( E_ENABLE_ON)
  110. #define disable_E1() E1_ENABLE_WRITE(!E_ENABLE_ON)
  111. #else
  112. #define enable_E1() NOOP
  113. #define disable_E1() NOOP
  114. #endif
  115. #if E_STEPPERS > 2 && HAS_E2_ENABLE
  116. #define enable_E2() E2_ENABLE_WRITE( E_ENABLE_ON)
  117. #define disable_E2() E2_ENABLE_WRITE(!E_ENABLE_ON)
  118. #else
  119. #define enable_E2() NOOP
  120. #define disable_E2() NOOP
  121. #endif
  122. #if E_STEPPERS > 3 && HAS_E3_ENABLE
  123. #define enable_E3() E3_ENABLE_WRITE( E_ENABLE_ON)
  124. #define disable_E3() E3_ENABLE_WRITE(!E_ENABLE_ON)
  125. #else
  126. #define enable_E3() NOOP
  127. #define disable_E3() NOOP
  128. #endif
  129. #if E_STEPPERS > 4 && HAS_E4_ENABLE
  130. #define enable_E4() E4_ENABLE_WRITE( E_ENABLE_ON)
  131. #define disable_E4() E4_ENABLE_WRITE(!E_ENABLE_ON)
  132. #else
  133. #define enable_E4() NOOP
  134. #define disable_E4() NOOP
  135. #endif
  136. #if E_STEPPERS > 5 && HAS_E5_ENABLE
  137. #define enable_E5() E5_ENABLE_WRITE( E_ENABLE_ON)
  138. #define disable_E5() E5_ENABLE_WRITE(!E_ENABLE_ON)
  139. #else
  140. #define enable_E5() NOOP
  141. #define disable_E5() NOOP
  142. #endif
  143. #endif // !MIXING_EXTRUDER
  144. #if ENABLED(EXPERIMENTAL_I2CBUS)
  145. #include "feature/twibus.h"
  146. extern TWIBus i2c;
  147. #endif
  148. #if ENABLED(G38_PROBE_TARGET)
  149. extern bool G38_move, // flag to tell the interrupt handler that a G38 command is being run
  150. G38_endstop_hit; // flag from the interrupt handler to indicate if the endstop went active
  151. #endif
  152. /**
  153. * The axis order in all axis related arrays is X, Y, Z, E
  154. */
  155. void enable_all_steppers();
  156. void disable_e_stepper(const uint8_t e);
  157. void disable_e_steppers();
  158. void disable_all_steppers();
  159. void kill(PGM_P const lcd_msg=NULL);
  160. void minkill();
  161. void quickstop_stepper();
  162. extern bool Running;
  163. inline bool IsRunning() { return Running; }
  164. inline bool IsStopped() { return !Running; }
  165. extern volatile bool wait_for_heatup;
  166. #if HAS_RESUME_CONTINUE
  167. extern volatile bool wait_for_user;
  168. #endif
  169. #if HAS_AUTO_REPORTING || ENABLED(HOST_KEEPALIVE_FEATURE)
  170. extern bool suspend_auto_report;
  171. #endif
  172. // Inactivity shutdown timer
  173. extern millis_t max_inactive_time, stepper_inactive_time;
  174. #if FAN_COUNT > 0
  175. extern uint8_t fan_speed[FAN_COUNT];
  176. #if ENABLED(EXTRA_FAN_SPEED)
  177. extern uint8_t old_fan_speed[FAN_COUNT], new_fan_speed[FAN_COUNT];
  178. #endif
  179. #if ENABLED(PROBING_FANS_OFF)
  180. extern bool fans_paused;
  181. extern uint8_t paused_fan_speed[FAN_COUNT];
  182. #endif
  183. #endif
  184. inline void zero_fan_speeds() {
  185. #if FAN_COUNT > 0
  186. LOOP_L_N(i, FAN_COUNT) fan_speed[i] = 0;
  187. #endif
  188. }
  189. #if ENABLED(USE_CONTROLLER_FAN)
  190. extern uint8_t controllerfan_speed;
  191. #endif
  192. #if HAS_POWER_SWITCH
  193. extern bool powersupply_on;
  194. #define PSU_PIN_ON() do{ OUT_WRITE(PS_ON_PIN, PS_ON_AWAKE); powersupply_on = true; }while(0)
  195. #define PSU_PIN_OFF() do{ OUT_WRITE(PS_ON_PIN, PS_ON_ASLEEP); powersupply_on = false; }while(0)
  196. #if ENABLED(AUTO_POWER_CONTROL)
  197. #define PSU_ON() powerManager.power_on()
  198. #define PSU_OFF() powerManager.power_off()
  199. #else
  200. #define PSU_ON() PSU_PIN_ON()
  201. #define PSU_OFF() PSU_PIN_OFF()
  202. #endif
  203. #endif
  204. bool pin_is_protected(const pin_t pin);
  205. void protected_pin_err();
  206. #if HAS_SUICIDE
  207. inline void suicide() { OUT_WRITE(SUICIDE_PIN, LOW); }
  208. #endif