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 11KB

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