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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. #ifndef MARLIN_H
  23. #define MARLIN_H
  24. #include <math.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <inttypes.h>
  29. #include <util/delay.h>
  30. #include <avr/pgmspace.h>
  31. #include <avr/eeprom.h>
  32. #include <avr/interrupt.h>
  33. #include "MarlinConfig.h"
  34. #include "enum.h"
  35. #include "types.h"
  36. #include "fastio.h"
  37. #include "utility.h"
  38. #include "serial.h"
  39. #if ENABLED(PRINTCOUNTER)
  40. #include "printcounter.h"
  41. #else
  42. #include "stopwatch.h"
  43. #endif
  44. void idle(
  45. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  46. bool no_stepper_sleep = false // pass true to keep steppers from disabling on timeout
  47. #endif
  48. );
  49. void manage_inactivity(bool ignore_stepper_queue = false);
  50. #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
  51. extern bool extruder_duplication_enabled;
  52. #endif
  53. #if HAS_X2_ENABLE
  54. #define enable_X() do{ X_ENABLE_WRITE( X_ENABLE_ON); X2_ENABLE_WRITE( X_ENABLE_ON); }while(0)
  55. #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
  56. #elif HAS_X_ENABLE
  57. #define enable_X() X_ENABLE_WRITE( X_ENABLE_ON)
  58. #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
  59. #else
  60. #define enable_X() NOOP
  61. #define disable_X() NOOP
  62. #endif
  63. #if HAS_Y2_ENABLE
  64. #define enable_Y() do{ Y_ENABLE_WRITE( Y_ENABLE_ON); Y2_ENABLE_WRITE(Y_ENABLE_ON); }while(0)
  65. #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
  66. #elif HAS_Y_ENABLE
  67. #define enable_Y() Y_ENABLE_WRITE( Y_ENABLE_ON)
  68. #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
  69. #else
  70. #define enable_Y() NOOP
  71. #define disable_Y() NOOP
  72. #endif
  73. #if HAS_Z2_ENABLE
  74. #define enable_Z() do{ Z_ENABLE_WRITE( Z_ENABLE_ON); Z2_ENABLE_WRITE(Z_ENABLE_ON); }while(0)
  75. #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
  76. #elif HAS_Z_ENABLE
  77. #define enable_Z() Z_ENABLE_WRITE( Z_ENABLE_ON)
  78. #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
  79. #else
  80. #define enable_Z() NOOP
  81. #define disable_Z() NOOP
  82. #endif
  83. #if ENABLED(MIXING_EXTRUDER)
  84. /**
  85. * Mixing steppers synchronize their enable (and direction) together
  86. */
  87. #if MIXING_STEPPERS > 3
  88. #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); }
  89. #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); }
  90. #elif MIXING_STEPPERS > 2
  91. #define enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); }
  92. #define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); }
  93. #else
  94. #define enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); }
  95. #define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); }
  96. #endif
  97. #define enable_E1() NOOP
  98. #define disable_E1() NOOP
  99. #define enable_E2() NOOP
  100. #define disable_E2() NOOP
  101. #define enable_E3() NOOP
  102. #define disable_E3() NOOP
  103. #define enable_E4() NOOP
  104. #define disable_E4() NOOP
  105. #else // !MIXING_EXTRUDER
  106. #if HAS_E0_ENABLE
  107. #define enable_E0() E0_ENABLE_WRITE( E_ENABLE_ON)
  108. #define disable_E0() E0_ENABLE_WRITE(!E_ENABLE_ON)
  109. #else
  110. #define enable_E0() NOOP
  111. #define disable_E0() NOOP
  112. #endif
  113. #if E_STEPPERS > 1 && HAS_E1_ENABLE
  114. #define enable_E1() E1_ENABLE_WRITE( E_ENABLE_ON)
  115. #define disable_E1() E1_ENABLE_WRITE(!E_ENABLE_ON)
  116. #else
  117. #define enable_E1() NOOP
  118. #define disable_E1() NOOP
  119. #endif
  120. #if E_STEPPERS > 2 && HAS_E2_ENABLE
  121. #define enable_E2() E2_ENABLE_WRITE( E_ENABLE_ON)
  122. #define disable_E2() E2_ENABLE_WRITE(!E_ENABLE_ON)
  123. #else
  124. #define enable_E2() NOOP
  125. #define disable_E2() NOOP
  126. #endif
  127. #if E_STEPPERS > 3 && HAS_E3_ENABLE
  128. #define enable_E3() E3_ENABLE_WRITE( E_ENABLE_ON)
  129. #define disable_E3() E3_ENABLE_WRITE(!E_ENABLE_ON)
  130. #else
  131. #define enable_E3() NOOP
  132. #define disable_E3() NOOP
  133. #endif
  134. #if E_STEPPERS > 4 && HAS_E4_ENABLE
  135. #define enable_E4() E4_ENABLE_WRITE( E_ENABLE_ON)
  136. #define disable_E4() E4_ENABLE_WRITE(!E_ENABLE_ON)
  137. #else
  138. #define enable_E4() NOOP
  139. #define disable_E4() NOOP
  140. #endif
  141. #endif // !MIXING_EXTRUDER
  142. #if ENABLED(G38_PROBE_TARGET)
  143. extern bool G38_move, // flag to tell the interrupt handler that a G38 command is being run
  144. G38_endstop_hit; // flag from the interrupt handler to indicate if the endstop went active
  145. #endif
  146. /**
  147. * The axis order in all axis related arrays is X, Y, Z, E
  148. */
  149. #define _AXIS(AXIS) AXIS ##_AXIS
  150. void enable_all_steppers();
  151. void disable_e_steppers();
  152. void disable_all_steppers();
  153. void FlushSerialRequestResend();
  154. void ok_to_send();
  155. void kill(const char*);
  156. void quickstop_stepper();
  157. #if ENABLED(FILAMENT_RUNOUT_SENSOR)
  158. void handle_filament_runout();
  159. #endif
  160. extern uint8_t marlin_debug_flags;
  161. #define DEBUGGING(F) (marlin_debug_flags & (DEBUG_## F))
  162. extern bool Running;
  163. inline bool IsRunning() { return Running; }
  164. inline bool IsStopped() { return !Running; }
  165. bool enqueue_and_echo_command(const char* cmd, bool say_ok=false); // Add a single command to the end of the buffer. Return false on failure.
  166. void enqueue_and_echo_commands_P(const char * const cmd); // Set one or more commands to be prioritized over the next Serial/SD command.
  167. void clear_command_queue();
  168. extern millis_t previous_cmd_ms;
  169. inline void refresh_cmd_timeout() { previous_cmd_ms = millis(); }
  170. #if ENABLED(FAST_PWM_FAN)
  171. void setPwmFrequency(uint8_t pin, int val);
  172. #endif
  173. /**
  174. * Feedrate scaling and conversion
  175. */
  176. extern int feedrate_percentage;
  177. #define MMM_TO_MMS(MM_M) ((MM_M)/60.0)
  178. #define MMS_TO_MMM(MM_S) ((MM_S)*60.0)
  179. #define MMS_SCALED(MM_S) ((MM_S)*feedrate_percentage*0.01)
  180. extern bool axis_relative_modes[];
  181. extern bool volumetric_enabled;
  182. extern int flow_percentage[EXTRUDERS]; // Extrusion factor for each extruder
  183. extern float filament_size[EXTRUDERS]; // cross-sectional area of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder.
  184. extern float volumetric_multiplier[EXTRUDERS]; // reciprocal of cross-sectional area of filament (in square millimeters), stored this way to reduce computational burden in planner
  185. extern bool axis_known_position[XYZ]; // axis[n].is_known
  186. extern bool axis_homed[XYZ]; // axis[n].is_homed
  187. extern volatile bool wait_for_heatup;
  188. #if HAS_RESUME_CONTINUE
  189. extern volatile bool wait_for_user;
  190. #endif
  191. extern float current_position[NUM_AXIS];
  192. // Workspace offsets
  193. #if HAS_WORKSPACE_OFFSET
  194. #if HAS_HOME_OFFSET
  195. extern float home_offset[XYZ];
  196. #endif
  197. #if HAS_POSITION_SHIFT
  198. extern float position_shift[XYZ];
  199. #endif
  200. #endif
  201. #if HAS_HOME_OFFSET && HAS_POSITION_SHIFT
  202. extern float workspace_offset[XYZ];
  203. #define WORKSPACE_OFFSET(AXIS) workspace_offset[AXIS]
  204. #elif HAS_HOME_OFFSET
  205. #define WORKSPACE_OFFSET(AXIS) home_offset[AXIS]
  206. #elif HAS_POSITION_SHIFT
  207. #define WORKSPACE_OFFSET(AXIS) position_shift[AXIS]
  208. #else
  209. #define WORKSPACE_OFFSET(AXIS) 0
  210. #endif
  211. #define LOGICAL_POSITION(POS, AXIS) ((POS) + WORKSPACE_OFFSET(AXIS))
  212. #define RAW_POSITION(POS, AXIS) ((POS) - WORKSPACE_OFFSET(AXIS))
  213. #if HAS_POSITION_SHIFT || DISABLED(DELTA)
  214. #define LOGICAL_X_POSITION(POS) LOGICAL_POSITION(POS, X_AXIS)
  215. #define LOGICAL_Y_POSITION(POS) LOGICAL_POSITION(POS, Y_AXIS)
  216. #define RAW_X_POSITION(POS) RAW_POSITION(POS, X_AXIS)
  217. #define RAW_Y_POSITION(POS) RAW_POSITION(POS, Y_AXIS)
  218. #else
  219. #define LOGICAL_X_POSITION(POS) (POS)
  220. #define LOGICAL_Y_POSITION(POS) (POS)
  221. #define RAW_X_POSITION(POS) (POS)
  222. #define RAW_Y_POSITION(POS) (POS)
  223. #endif
  224. #define LOGICAL_Z_POSITION(POS) LOGICAL_POSITION(POS, Z_AXIS)
  225. #define RAW_Z_POSITION(POS) RAW_POSITION(POS, Z_AXIS)
  226. #define RAW_CURRENT_POSITION(A) RAW_##A##_POSITION(current_position[A##_AXIS])
  227. // Hotend Offsets
  228. #if HOTENDS > 1
  229. extern float hotend_offset[XYZ][HOTENDS];
  230. #endif
  231. // Software Endstops
  232. extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ];
  233. #if HAS_SOFTWARE_ENDSTOPS
  234. extern bool soft_endstops_enabled;
  235. void clamp_to_software_endstops(float target[XYZ]);
  236. #else
  237. #define soft_endstops_enabled false
  238. #define clamp_to_software_endstops(x) NOOP
  239. #endif
  240. #if HAS_WORKSPACE_OFFSET || ENABLED(DUAL_X_CARRIAGE)
  241. void update_software_endstops(const AxisEnum axis);
  242. #endif
  243. // GCode support for external objects
  244. bool code_seen(char);
  245. int code_value_int();
  246. float code_value_temp_abs();
  247. float code_value_temp_diff();
  248. #if IS_KINEMATIC
  249. extern float delta[ABC];
  250. void inverse_kinematics(const float logical[XYZ]);
  251. #endif
  252. #if ENABLED(DELTA)
  253. extern float endstop_adj[ABC],
  254. delta_radius,
  255. delta_diagonal_rod,
  256. delta_segments_per_second,
  257. delta_diagonal_rod_trim[ABC],
  258. delta_tower_angle_trim[ABC],
  259. delta_clip_start_height;
  260. void recalc_delta_settings(float radius, float diagonal_rod);
  261. #elif IS_SCARA
  262. void forward_kinematics_SCARA(const float &a, const float &b);
  263. #endif
  264. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  265. extern int bilinear_grid_spacing[2], bilinear_start[2];
  266. extern float bed_level_grid[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
  267. float bilinear_z_offset(float logical[XYZ]);
  268. void set_bed_leveling_enabled(bool enable=true);
  269. #endif
  270. #if ENABLED(AUTO_BED_LEVELING_UBL)
  271. typedef struct { double A, B, D; } linear_fit;
  272. linear_fit* lsf_linear_fit(double x[], double y[], double z[], const int);
  273. #endif
  274. #if PLANNER_LEVELING
  275. void reset_bed_level();
  276. #endif
  277. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  278. void set_z_fade_height(const float zfh);
  279. #endif
  280. #if ENABLED(Z_DUAL_ENDSTOPS)
  281. extern float z_endstop_adj;
  282. #endif
  283. #if HAS_BED_PROBE
  284. extern float zprobe_zoffset;
  285. void refresh_zprobe_zoffset(const bool no_babystep=false);
  286. #define DEPLOY_PROBE() set_probe_deployed(true)
  287. #define STOW_PROBE() set_probe_deployed(false)
  288. #endif
  289. #if ENABLED(HOST_KEEPALIVE_FEATURE)
  290. extern MarlinBusyState busy_state;
  291. #define KEEPALIVE_STATE(n) do{ busy_state = n; }while(0)
  292. #else
  293. #define KEEPALIVE_STATE(n) NOOP
  294. #endif
  295. #if FAN_COUNT > 0
  296. extern int fanSpeeds[FAN_COUNT];
  297. #endif
  298. #if ENABLED(BARICUDA)
  299. extern int baricuda_valve_pressure;
  300. extern int baricuda_e_to_p_pressure;
  301. #endif
  302. #if ENABLED(FILAMENT_WIDTH_SENSOR)
  303. extern bool filament_sensor; // Flag that filament sensor readings should control extrusion
  304. extern float filament_width_nominal, // Theoretical filament diameter i.e., 3.00 or 1.75
  305. filament_width_meas; // Measured filament diameter
  306. extern int8_t measurement_delay[]; // Ring buffer to delay measurement
  307. extern int filwidth_delay_index[2]; // Ring buffer indexes. Used by planner, temperature, and main code
  308. extern int meas_delay_cm; // Delay distance
  309. #endif
  310. #if ENABLED(FILAMENT_CHANGE_FEATURE)
  311. extern FilamentChangeMenuResponse filament_change_menu_response;
  312. #endif
  313. #if ENABLED(PID_EXTRUSION_SCALING)
  314. extern int lpq_len;
  315. #endif
  316. #if ENABLED(FWRETRACT)
  317. extern bool autoretract_enabled;
  318. extern bool retracted[EXTRUDERS]; // extruder[n].retracted
  319. extern float retract_length, retract_length_swap, retract_feedrate_mm_s, retract_zlift;
  320. extern float retract_recover_length, retract_recover_length_swap, retract_recover_feedrate_mm_s;
  321. #endif
  322. // Print job timer
  323. #if ENABLED(PRINTCOUNTER)
  324. extern PrintCounter print_job_timer;
  325. #else
  326. extern Stopwatch print_job_timer;
  327. #endif
  328. // Handling multiple extruders pins
  329. extern uint8_t active_extruder;
  330. #if HAS_TEMP_HOTEND || HAS_TEMP_BED
  331. void print_heaterstates();
  332. #endif
  333. #if ENABLED(MIXING_EXTRUDER)
  334. extern float mixing_factor[MIXING_STEPPERS];
  335. #endif
  336. void calculate_volumetric_multipliers();
  337. /**
  338. * Blocking movement and shorthand functions
  339. */
  340. void do_blocking_move_to(const float &x, const float &y, const float &z, const float &fr_mm_s=0.0);
  341. void do_blocking_move_to_x(const float &x, const float &fr_mm_s=0.0);
  342. void do_blocking_move_to_z(const float &z, const float &fr_mm_s=0.0);
  343. void do_blocking_move_to_xy(const float &x, const float &y, const float &fr_mm_s=0.0);
  344. #if ENABLED(Z_PROBE_ALLEN_KEY) || ENABLED(Z_PROBE_SLED) || HAS_PROBING_PROCEDURE || HOTENDS > 1 || ENABLED(NOZZLE_CLEAN_FEATURE) || ENABLED(NOZZLE_PARK_FEATURE)
  345. bool axis_unhomed_error(const bool x, const bool y, const bool z);
  346. #endif
  347. #endif //MARLIN_H