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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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. // end X, Y, Z Stepper enable / disable
  128. //
  129. // Extruder Stepper enable / disable
  130. //
  131. // define the individual enables/disables
  132. #if AXIS_DRIVER_TYPE_E0(L6470)
  133. extern L6470 stepperE0;
  134. #define E0_enable NOOP
  135. #define E0_disable do{ stepperE0.free(); CBI(axis_known_position, E_AXIS); }while(0)
  136. #elif HAS_E0_ENABLE
  137. #define E0_enable E0_ENABLE_WRITE( E_ENABLE_ON)
  138. #define E0_disable E0_ENABLE_WRITE(!E_ENABLE_ON)
  139. #else
  140. #define E0_enable NOOP
  141. #define E0_disable NOOP
  142. #endif
  143. #if AXIS_DRIVER_TYPE_E1(L6470)
  144. extern L6470 stepperE1;
  145. #define E1_enable NOOP
  146. #define E1_disable do{ stepperE1.free(); CBI(axis_known_position, E_AXIS); }while(0)
  147. #elif E_STEPPERS > 1 && HAS_E1_ENABLE
  148. #define E1_enable E1_ENABLE_WRITE( E_ENABLE_ON)
  149. #define E1_disable E1_ENABLE_WRITE(!E_ENABLE_ON)
  150. #else
  151. #define E1_enable NOOP
  152. #define E1_disable NOOP
  153. #endif
  154. #if AXIS_DRIVER_TYPE_E2(L6470)
  155. extern L6470 stepperE2;
  156. #define E2_enable NOOP
  157. #define E2_disable do{ stepperE2.free(); CBI(axis_known_position, E_AXIS); }while(0)
  158. #elif E_STEPPERS > 2 && HAS_E2_ENABLE
  159. #define E2_enable E2_ENABLE_WRITE( E_ENABLE_ON)
  160. #define E2_disable E2_ENABLE_WRITE(!E_ENABLE_ON)
  161. #else
  162. #define E2_enable NOOP
  163. #define E2_disable NOOP
  164. #endif
  165. #if AXIS_DRIVER_TYPE_E3(L6470)
  166. extern L6470 stepperE3;
  167. #define E3_enable NOOP
  168. #define E3_disable do{ stepperE3.free(); CBI(axis_known_position, E_AXIS); }while(0)
  169. #elif E_STEPPERS > 3 && HAS_E3_ENABLE
  170. #define E3_enable E3_ENABLE_WRITE( E_ENABLE_ON)
  171. #define E3_disable E3_ENABLE_WRITE(!E_ENABLE_ON)
  172. #else
  173. #define E3_enable NOOP
  174. #define E3_disable NOOP
  175. #endif
  176. #if AXIS_DRIVER_TYPE_E4(L6470)
  177. extern L6470 stepperE4;
  178. #define E4_enable NOOP
  179. #define E4_disable do{ stepperE4.free(); CBI(axis_known_position, E_AXIS); }while(0)
  180. #elif E_STEPPERS > 4 && HAS_E4_ENABLE
  181. #define E4_enable E4_ENABLE_WRITE( E_ENABLE_ON)
  182. #define E4_disable E4_ENABLE_WRITE(!E_ENABLE_ON)
  183. #else
  184. #define E4_enable NOOP
  185. #define E4_disable NOOP
  186. #endif
  187. #if AXIS_DRIVER_TYPE_E5(L6470)
  188. extern L6470 stepperE5;
  189. #define E5_enable NOOP
  190. #define E5_disable do{ stepperE5.free(); CBI(axis_known_position, E_AXIS); }while(0)
  191. #elif E_STEPPERS > 5 && HAS_E5_ENABLE
  192. #define E5_enable E5_ENABLE_WRITE( E_ENABLE_ON)
  193. #define E5_disable E5_ENABLE_WRITE(!E_ENABLE_ON)
  194. #else
  195. #define E5_enable NOOP
  196. #define E5_disable NOOP
  197. #endif
  198. // end individual enables/disables
  199. #if ENABLED(MIXING_EXTRUDER)
  200. /**
  201. * Mixing steppers synchronize their enable (and direction) together
  202. */
  203. #if MIXING_STEPPERS > 5
  204. #define enable_E0() { E0_enable; E1_enable; E2_enable; E3_enable; E4_enable; E5_enable; }
  205. #define disable_E0() { E0_disable; E1_disable; E2_disable; E3_disable; E4_disable; E5_disable; }
  206. #elif MIXING_STEPPERS > 4
  207. #define enable_E0() { E0_enable; E1_enable; E2_enable; E3_enable; E4_enable; }
  208. #define disable_E0() { E0_disable; E1_disable; E2_disable; E3_disable; E4_disable; }
  209. #elif MIXING_STEPPERS > 3
  210. #define enable_E0() { E0_enable; E1_enable; E2_enable; E3_enable; }
  211. #define disable_E0() { E0_disable; E1_disable; E2_disable; E3_disable; }
  212. #elif MIXING_STEPPERS > 2
  213. #define enable_E0() { E0_enable; E1_enable; E2_enable; }
  214. #define disable_E0() { E0_disable; E1_disable; E2_disable; }
  215. #else
  216. #define enable_E0() { E0_enable; E1_enable; }
  217. #define disable_E0() { E0_disable; E1_disable; }
  218. #endif
  219. #define enable_E1() NOOP
  220. #define disable_E1() NOOP
  221. #define enable_E2() NOOP
  222. #define disable_E2() NOOP
  223. #define enable_E3() NOOP
  224. #define disable_E3() NOOP
  225. #define enable_E4() NOOP
  226. #define disable_E4() NOOP
  227. #define enable_E5() NOOP
  228. #define disable_E5() NOOP
  229. #else // !MIXING_EXTRUDER
  230. #if HAS_E0_ENABLE
  231. #define enable_E0() E0_enable
  232. #define disable_E0() E0_disable
  233. #else
  234. #define enable_E0() NOOP
  235. #define disable_E0() NOOP
  236. #endif
  237. #if E_STEPPERS > 1 && HAS_E1_ENABLE
  238. #define enable_E1() E1_enable
  239. #define disable_E1() E1_disable
  240. #else
  241. #define enable_E1() NOOP
  242. #define disable_E1() NOOP
  243. #endif
  244. #if E_STEPPERS > 2 && HAS_E2_ENABLE
  245. #define enable_E2() E2_enable
  246. #define disable_E2() E2_disable
  247. #else
  248. #define enable_E2() NOOP
  249. #define disable_E2() NOOP
  250. #endif
  251. #if E_STEPPERS > 3 && HAS_E3_ENABLE
  252. #define enable_E3() E3_enable
  253. #define disable_E3() E3_disable
  254. #else
  255. #define enable_E3() NOOP
  256. #define disable_E3() NOOP
  257. #endif
  258. #if E_STEPPERS > 4 && HAS_E4_ENABLE
  259. #define enable_E4() E4_enable
  260. #define disable_E4() E4_disable
  261. #else
  262. #define enable_E4() NOOP
  263. #define disable_E4() NOOP
  264. #endif
  265. #if E_STEPPERS > 5 && HAS_E5_ENABLE
  266. #define enable_E5() E5_enable
  267. #define disable_E5() E5_disable
  268. #else
  269. #define enable_E5() NOOP
  270. #define disable_E5() NOOP
  271. #endif
  272. #endif // !MIXING_EXTRUDER
  273. #if ENABLED(EXPERIMENTAL_I2CBUS)
  274. #include "feature/twibus.h"
  275. extern TWIBus i2c;
  276. #endif
  277. #if ENABLED(G38_PROBE_TARGET)
  278. extern bool G38_move, // flag to tell the interrupt handler that a G38 command is being run
  279. G38_endstop_hit; // flag from the interrupt handler to indicate if the endstop went active
  280. #endif
  281. /**
  282. * The axis order in all axis related arrays is X, Y, Z, E
  283. */
  284. void enable_all_steppers();
  285. void disable_e_stepper(const uint8_t e);
  286. void disable_e_steppers();
  287. void disable_all_steppers();
  288. void kill(PGM_P const lcd_msg=NULL);
  289. void minkill();
  290. void quickstop_stepper();
  291. extern bool Running;
  292. inline bool IsRunning() { return Running; }
  293. inline bool IsStopped() { return !Running; }
  294. extern volatile bool wait_for_heatup;
  295. #if HAS_RESUME_CONTINUE
  296. extern volatile bool wait_for_user;
  297. #endif
  298. #if HAS_AUTO_REPORTING || ENABLED(HOST_KEEPALIVE_FEATURE)
  299. extern bool suspend_auto_report;
  300. #endif
  301. // Inactivity shutdown timer
  302. extern millis_t max_inactive_time, stepper_inactive_time;
  303. #if ENABLED(USE_CONTROLLER_FAN)
  304. extern uint8_t controllerfan_speed;
  305. #endif
  306. #if HAS_POWER_SWITCH
  307. extern bool powersupply_on;
  308. #define PSU_PIN_ON() do{ OUT_WRITE(PS_ON_PIN, PS_ON_AWAKE); powersupply_on = true; }while(0)
  309. #define PSU_PIN_OFF() do{ OUT_WRITE(PS_ON_PIN, PS_ON_ASLEEP); powersupply_on = false; }while(0)
  310. #if ENABLED(AUTO_POWER_CONTROL)
  311. #define PSU_ON() powerManager.power_on()
  312. #define PSU_OFF() powerManager.power_off()
  313. #else
  314. #define PSU_ON() PSU_PIN_ON()
  315. #define PSU_OFF() PSU_PIN_OFF()
  316. #endif
  317. #endif
  318. bool pin_is_protected(const pin_t pin);
  319. void protected_pin_err();
  320. #if HAS_SUICIDE
  321. inline void suicide() { OUT_WRITE(SUICIDE_PIN, LOW); }
  322. #endif
  323. #if ENABLED(FILAMENT_RUNOUT_SENSOR)
  324. void event_filament_runout();
  325. #endif
  326. #if ENABLED(G29_RETRY_AND_RECOVER)
  327. void event_probe_recover();
  328. void event_probe_failure();
  329. #endif