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.

MarlinCore.h 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. #ifdef DEBUG_GCODE_PARSER
  25. #include "gcode/parser.h"
  26. #endif
  27. #include <math.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #if HAS_L64XX
  31. #include "libs/L64XX/L64XX_Marlin.h"
  32. extern uint8_t axis_known_position;
  33. #endif
  34. void stop();
  35. void idle(
  36. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  37. bool no_stepper_sleep = false // pass true to keep steppers from disabling on timeout
  38. #endif
  39. );
  40. void manage_inactivity(const bool ignore_stepper_queue=false);
  41. //
  42. // X, Y, Z Stepper enable / disable
  43. //
  44. #if AXIS_IS_L64XX(X)
  45. #define X_enable() NOOP
  46. #define X_disable() stepperX.free()
  47. #elif HAS_X_ENABLE
  48. #define X_enable() X_ENABLE_WRITE( X_ENABLE_ON)
  49. #define X_disable() X_ENABLE_WRITE(!X_ENABLE_ON)
  50. #else
  51. #define X_enable() NOOP
  52. #define X_disable() NOOP
  53. #endif
  54. #if AXIS_IS_L64XX(X2)
  55. #define X2_enable() NOOP
  56. #define X2_disable() stepperX2.free()
  57. #elif HAS_X2_ENABLE
  58. #define X2_enable() X2_ENABLE_WRITE( X_ENABLE_ON)
  59. #define X2_disable() X2_ENABLE_WRITE(!X_ENABLE_ON)
  60. #else
  61. #define X2_enable() NOOP
  62. #define X2_disable() NOOP
  63. #endif
  64. #define enable_X() do{ X_enable(); X2_enable(); }while(0)
  65. #define disable_X() do{ X_disable(); X2_disable(); CBI(axis_known_position, X_AXIS); }while(0)
  66. #if AXIS_IS_L64XX(Y)
  67. #define Y_enable() NOOP
  68. #define Y_disable() stepperY.free()
  69. #elif HAS_Y_ENABLE
  70. #define Y_enable() Y_ENABLE_WRITE( Y_ENABLE_ON)
  71. #define Y_disable() Y_ENABLE_WRITE(!Y_ENABLE_ON)
  72. #else
  73. #define Y_enable() NOOP
  74. #define Y_disable() NOOP
  75. #endif
  76. #if AXIS_IS_L64XX(Y2)
  77. #define Y2_enable() NOOP
  78. #define Y2_disable() stepperY2.free()
  79. #elif HAS_Y2_ENABLE
  80. #define Y2_enable() Y2_ENABLE_WRITE( Y_ENABLE_ON)
  81. #define Y2_disable() Y2_ENABLE_WRITE(!Y_ENABLE_ON)
  82. #else
  83. #define Y2_enable() NOOP
  84. #define Y2_disable() NOOP
  85. #endif
  86. #define enable_Y() do{ Y_enable(); Y2_enable(); }while(0)
  87. #define disable_Y() do{ Y_disable(); Y2_disable(); CBI(axis_known_position, Y_AXIS); }while(0)
  88. #if AXIS_IS_L64XX(Z)
  89. #define Z_enable() NOOP
  90. #define Z_disable() stepperZ.free()
  91. #elif HAS_Z_ENABLE
  92. #define Z_enable() Z_ENABLE_WRITE( Z_ENABLE_ON)
  93. #define Z_disable() Z_ENABLE_WRITE(!Z_ENABLE_ON)
  94. #else
  95. #define Z_enable() NOOP
  96. #define Z_disable() NOOP
  97. #endif
  98. #if AXIS_IS_L64XX(Z2)
  99. #define Z2_enable() NOOP
  100. #define Z2_disable() stepperZ2.free()
  101. #elif HAS_Z2_ENABLE
  102. #define Z2_enable() Z2_ENABLE_WRITE( Z_ENABLE_ON)
  103. #define Z2_disable() Z2_ENABLE_WRITE(!Z_ENABLE_ON)
  104. #else
  105. #define Z2_enable() NOOP
  106. #define Z2_disable() NOOP
  107. #endif
  108. #if AXIS_IS_L64XX(Z3)
  109. #define Z3_enable() NOOP
  110. #define Z3_disable() stepperZ3.free()
  111. #elif HAS_Z3_ENABLE
  112. #define Z3_enable() Z3_ENABLE_WRITE( Z_ENABLE_ON)
  113. #define Z3_disable() Z3_ENABLE_WRITE(!Z_ENABLE_ON)
  114. #else
  115. #define Z3_enable() NOOP
  116. #define Z3_disable() NOOP
  117. #endif
  118. #define enable_Z() do{ Z_enable(); Z2_enable(); Z3_enable(); }while(0)
  119. #define disable_Z() do{ Z_disable(); Z2_disable(); Z3_disable(); CBI(axis_known_position, Z_AXIS); }while(0)
  120. //
  121. // Extruder Stepper enable / disable
  122. //
  123. // define the individual enables/disables
  124. #if AXIS_IS_L64XX(E0)
  125. #define E0_enable() NOOP
  126. #define E0_disable() do{ stepperE0.free(); CBI(axis_known_position, E_AXIS); }while(0)
  127. #elif HAS_E0_ENABLE
  128. #define E0_enable() E0_ENABLE_WRITE( E_ENABLE_ON)
  129. #define E0_disable() E0_ENABLE_WRITE(!E_ENABLE_ON)
  130. #else
  131. #define E0_enable() NOOP
  132. #define E0_disable() NOOP
  133. #endif
  134. #if AXIS_IS_L64XX(E1)
  135. #define E1_enable() NOOP
  136. #define E1_disable() do{ stepperE1.free(); CBI(axis_known_position, E_AXIS); }while(0)
  137. #elif E_STEPPERS > 1 && HAS_E1_ENABLE
  138. #define E1_enable() E1_ENABLE_WRITE( E_ENABLE_ON)
  139. #define E1_disable() E1_ENABLE_WRITE(!E_ENABLE_ON)
  140. #else
  141. #define E1_enable() NOOP
  142. #define E1_disable() NOOP
  143. #endif
  144. #if AXIS_IS_L64XX(E2)
  145. #define E2_enable() NOOP
  146. #define E2_disable() do{ stepperE2.free(); CBI(axis_known_position, E_AXIS); }while(0)
  147. #elif E_STEPPERS > 2 && HAS_E2_ENABLE
  148. #define E2_enable() E2_ENABLE_WRITE( E_ENABLE_ON)
  149. #define E2_disable() E2_ENABLE_WRITE(!E_ENABLE_ON)
  150. #else
  151. #define E2_enable() NOOP
  152. #define E2_disable() NOOP
  153. #endif
  154. #if AXIS_IS_L64XX(E3)
  155. #define E3_enable() NOOP
  156. #define E3_disable() do{ stepperE3.free(); CBI(axis_known_position, E_AXIS); }while(0)
  157. #elif E_STEPPERS > 3 && HAS_E3_ENABLE
  158. #define E3_enable() E3_ENABLE_WRITE( E_ENABLE_ON)
  159. #define E3_disable() E3_ENABLE_WRITE(!E_ENABLE_ON)
  160. #else
  161. #define E3_enable() NOOP
  162. #define E3_disable() NOOP
  163. #endif
  164. #if AXIS_IS_L64XX(E4)
  165. #define E4_enable() NOOP
  166. #define E4_disable() do{ stepperE4.free(); CBI(axis_known_position, E_AXIS); }while(0)
  167. #elif E_STEPPERS > 4 && HAS_E4_ENABLE
  168. #define E4_enable() E4_ENABLE_WRITE( E_ENABLE_ON)
  169. #define E4_disable() E4_ENABLE_WRITE(!E_ENABLE_ON)
  170. #else
  171. #define E4_enable() NOOP
  172. #define E4_disable() NOOP
  173. #endif
  174. #if AXIS_IS_L64XX(E5)
  175. #define E5_enable() NOOP
  176. #define E5_disable() do{ stepperE5.free(); CBI(axis_known_position, E_AXIS); }while(0)
  177. #elif E_STEPPERS > 5 && HAS_E5_ENABLE
  178. #define E5_enable() E5_ENABLE_WRITE( E_ENABLE_ON)
  179. #define E5_disable() E5_ENABLE_WRITE(!E_ENABLE_ON)
  180. #else
  181. #define E5_enable() NOOP
  182. #define E5_disable() NOOP
  183. #endif
  184. #if ENABLED(MIXING_EXTRUDER)
  185. /**
  186. * Mixing steppers synchronize their enable (and direction) together
  187. */
  188. #if MIXING_STEPPERS > 5
  189. #define enable_E0() { E0_enable(); E1_enable(); E2_enable(); E3_enable(); E4_enable(); E5_enable(); }
  190. #define disable_E0() { E0_disable(); E1_disable(); E2_disable(); E3_disable(); E4_disable(); E5_disable(); }
  191. #elif MIXING_STEPPERS > 4
  192. #define enable_E0() { E0_enable(); E1_enable(); E2_enable(); E3_enable(); E4_enable(); }
  193. #define disable_E0() { E0_disable(); E1_disable(); E2_disable(); E3_disable(); E4_disable(); }
  194. #elif MIXING_STEPPERS > 3
  195. #define enable_E0() { E0_enable(); E1_enable(); E2_enable(); E3_enable(); }
  196. #define disable_E0() { E0_disable(); E1_disable(); E2_disable(); E3_disable(); }
  197. #elif MIXING_STEPPERS > 2
  198. #define enable_E0() { E0_enable(); E1_enable(); E2_enable(); }
  199. #define disable_E0() { E0_disable(); E1_disable(); E2_disable(); }
  200. #else
  201. #define enable_E0() { E0_enable(); E1_enable(); }
  202. #define disable_E0() { E0_disable(); E1_disable(); }
  203. #endif
  204. #define enable_E1() NOOP
  205. #define disable_E1() NOOP
  206. #define enable_E2() NOOP
  207. #define disable_E2() NOOP
  208. #define enable_E3() NOOP
  209. #define disable_E3() NOOP
  210. #define enable_E4() NOOP
  211. #define disable_E4() NOOP
  212. #define enable_E5() NOOP
  213. #define disable_E5() NOOP
  214. #else // !MIXING_EXTRUDER
  215. #if (HAS_E0_ENABLE || AXIS_IS_L64XX(E0))
  216. #define enable_E0() E0_enable()
  217. #define disable_E0() E0_disable()
  218. #else
  219. #define enable_E0() NOOP
  220. #define disable_E0() NOOP
  221. #endif
  222. #if E_STEPPERS > 1 && (HAS_E1_ENABLE || AXIS_IS_L64XX(E1))
  223. #define enable_E1() E1_enable()
  224. #define disable_E1() E1_disable()
  225. #else
  226. #define enable_E1() NOOP
  227. #define disable_E1() NOOP
  228. #endif
  229. #if E_STEPPERS > 2 && (HAS_E2_ENABLE || AXIS_IS_L64XX(E2))
  230. #define enable_E2() E2_enable()
  231. #define disable_E2() E2_disable()
  232. #else
  233. #define enable_E2() NOOP
  234. #define disable_E2() NOOP
  235. #endif
  236. #if E_STEPPERS > 3 && (HAS_E3_ENABLE || AXIS_IS_L64XX(E3))
  237. #define enable_E3() E3_enable()
  238. #define disable_E3() E3_disable()
  239. #else
  240. #define enable_E3() NOOP
  241. #define disable_E3() NOOP
  242. #endif
  243. #if E_STEPPERS > 4 && (HAS_E4_ENABLE || AXIS_IS_L64XX(E4))
  244. #define enable_E4() E4_enable()
  245. #define disable_E4() E4_disable()
  246. #else
  247. #define enable_E4() NOOP
  248. #define disable_E4() NOOP
  249. #endif
  250. #if E_STEPPERS > 5 && (HAS_E5_ENABLE || AXIS_IS_L64XX(E5))
  251. #define enable_E5() E5_enable()
  252. #define disable_E5() E5_disable()
  253. #else
  254. #define enable_E5() NOOP
  255. #define disable_E5() NOOP
  256. #endif
  257. #endif // !MIXING_EXTRUDER
  258. #if ENABLED(EXPERIMENTAL_I2CBUS)
  259. #include "feature/twibus.h"
  260. extern TWIBus i2c;
  261. #endif
  262. #if ENABLED(G38_PROBE_TARGET)
  263. extern uint8_t G38_move; // Flag to tell the ISR that G38 is in progress, and the type
  264. extern bool G38_did_trigger; // Flag from the ISR to indicate the endstop changed
  265. #endif
  266. /**
  267. * The axis order in all axis related arrays is X, Y, Z, E
  268. */
  269. void enable_e_steppers();
  270. void enable_all_steppers();
  271. void disable_e_stepper(const uint8_t e);
  272. void disable_e_steppers();
  273. void disable_all_steppers();
  274. void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
  275. void minkill(const bool steppers_off=false);
  276. void quickstop_stepper();
  277. extern bool Running;
  278. inline bool IsRunning() { return Running; }
  279. inline bool IsStopped() { return !Running; }
  280. bool printingIsActive();
  281. bool printingIsPaused();
  282. void startOrResumeJob();
  283. extern bool wait_for_heatup;
  284. #if HAS_RESUME_CONTINUE
  285. extern bool wait_for_user;
  286. #endif
  287. #if HAS_AUTO_REPORTING || ENABLED(HOST_KEEPALIVE_FEATURE)
  288. extern bool suspend_auto_report;
  289. #endif
  290. // Inactivity shutdown timer
  291. extern millis_t max_inactive_time, stepper_inactive_time;
  292. #if ENABLED(USE_CONTROLLER_FAN)
  293. extern uint8_t controllerfan_speed;
  294. #endif
  295. #if ENABLED(PSU_CONTROL)
  296. extern bool powersupply_on;
  297. #define PSU_PIN_ON() do{ OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_HIGH); powersupply_on = true; }while(0)
  298. #define PSU_PIN_OFF() do{ OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_HIGH); powersupply_on = false; }while(0)
  299. #if ENABLED(AUTO_POWER_CONTROL)
  300. #define PSU_ON() powerManager.power_on()
  301. #define PSU_OFF() powerManager.power_off()
  302. #else
  303. #define PSU_ON() PSU_PIN_ON()
  304. #define PSU_OFF() PSU_PIN_OFF()
  305. #endif
  306. #endif
  307. bool pin_is_protected(const pin_t pin);
  308. void protected_pin_err();
  309. #if HAS_SUICIDE
  310. inline void suicide() { OUT_WRITE(SUICIDE_PIN, SUICIDE_PIN_INVERTING); }
  311. #endif
  312. #if ENABLED(G29_RETRY_AND_RECOVER)
  313. void event_probe_recover();
  314. void event_probe_failure();
  315. #endif
  316. extern const char NUL_STR[], G28_STR[], M21_STR[], M23_STR[], M24_STR[],
  317. SP_X_STR[], SP_Y_STR[], SP_Z_STR[], SP_E_STR[];