My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Marlin.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. #define FORCE_INLINE __attribute__((always_inline)) inline
  25. /**
  26. * Compiler warning on unused variable.
  27. */
  28. #define UNUSED(x) (void) (x)
  29. #include <math.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <inttypes.h>
  34. #include <util/delay.h>
  35. #include <avr/pgmspace.h>
  36. #include <avr/eeprom.h>
  37. #include <avr/interrupt.h>
  38. #include "fastio.h"
  39. #include "Configuration.h"
  40. #include "pins.h"
  41. #ifndef SANITYCHECK_H
  42. #error "Your Configuration.h and Configuration_adv.h files are outdated!"
  43. #endif
  44. #include "Arduino.h"
  45. typedef unsigned long millis_t;
  46. #ifdef USBCON
  47. #include "HardwareSerial.h"
  48. #endif
  49. #include "MarlinSerial.h"
  50. #include "WString.h"
  51. #if ENABLED(PRINTCOUNTER)
  52. #include "printcounter.h"
  53. #else
  54. #include "stopwatch.h"
  55. #endif
  56. #ifdef USBCON
  57. #if ENABLED(BLUETOOTH)
  58. #define MYSERIAL bluetoothSerial
  59. #else
  60. #define MYSERIAL Serial
  61. #endif // BLUETOOTH
  62. #else
  63. #define MYSERIAL customizedSerial
  64. #endif
  65. #define SERIAL_CHAR(x) MYSERIAL.write(x)
  66. #define SERIAL_EOL SERIAL_CHAR('\n')
  67. #define SERIAL_PROTOCOLCHAR(x) SERIAL_CHAR(x)
  68. #define SERIAL_PROTOCOL(x) MYSERIAL.print(x)
  69. #define SERIAL_PROTOCOL_F(x,y) MYSERIAL.print(x,y)
  70. #define SERIAL_PROTOCOLPGM(x) serialprintPGM(PSTR(x))
  71. #define SERIAL_PROTOCOLLN(x) do{ MYSERIAL.print(x); SERIAL_EOL; }while(0)
  72. #define SERIAL_PROTOCOLLNPGM(x) do{ serialprintPGM(PSTR(x)); SERIAL_EOL; }while(0)
  73. extern const char errormagic[] PROGMEM;
  74. extern const char echomagic[] PROGMEM;
  75. #define SERIAL_ERROR_START serialprintPGM(errormagic)
  76. #define SERIAL_ERROR(x) SERIAL_PROTOCOL(x)
  77. #define SERIAL_ERRORPGM(x) SERIAL_PROTOCOLPGM(x)
  78. #define SERIAL_ERRORLN(x) SERIAL_PROTOCOLLN(x)
  79. #define SERIAL_ERRORLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
  80. #define SERIAL_ECHO_START serialprintPGM(echomagic)
  81. #define SERIAL_ECHO(x) SERIAL_PROTOCOL(x)
  82. #define SERIAL_ECHOPGM(x) SERIAL_PROTOCOLPGM(x)
  83. #define SERIAL_ECHOLN(x) SERIAL_PROTOCOLLN(x)
  84. #define SERIAL_ECHOLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
  85. #define SERIAL_ECHOPAIR(name,value) (serial_echopair_P(PSTR(name),(value)))
  86. void serial_echopair_P(const char* s_P, int v);
  87. void serial_echopair_P(const char* s_P, long v);
  88. void serial_echopair_P(const char* s_P, float v);
  89. void serial_echopair_P(const char* s_P, double v);
  90. void serial_echopair_P(const char* s_P, unsigned long v);
  91. FORCE_INLINE void serial_echopair_P(const char* s_P, bool v) { serial_echopair_P(s_P, (int)v); }
  92. FORCE_INLINE void serial_echopair_P(const char* s_P, void *v) { serial_echopair_P(s_P, (unsigned long)v); }
  93. // Things to write to serial from Program memory. Saves 400 to 2k of RAM.
  94. FORCE_INLINE void serialprintPGM(const char* str) {
  95. char ch;
  96. while ((ch = pgm_read_byte(str))) {
  97. MYSERIAL.write(ch);
  98. str++;
  99. }
  100. }
  101. void idle(
  102. #if ENABLED(FILAMENTCHANGEENABLE)
  103. bool no_stepper_sleep=false // pass true to keep steppers from disabling on timeout
  104. #endif
  105. );
  106. void manage_inactivity(bool ignore_stepper_queue = false);
  107. #if ENABLED(DUAL_X_CARRIAGE)
  108. extern bool extruder_duplication_enabled;
  109. #endif
  110. #if ENABLED(DUAL_X_CARRIAGE) && HAS_X_ENABLE && HAS_X2_ENABLE
  111. #define enable_x() do { X_ENABLE_WRITE( X_ENABLE_ON); X2_ENABLE_WRITE( X_ENABLE_ON); } while (0)
  112. #define disable_x() do { X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; } while (0)
  113. #elif HAS_X_ENABLE
  114. #define enable_x() X_ENABLE_WRITE( X_ENABLE_ON)
  115. #define disable_x() { X_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }
  116. #else
  117. #define enable_x() ;
  118. #define disable_x() ;
  119. #endif
  120. #if HAS_Y_ENABLE
  121. #if ENABLED(Y_DUAL_STEPPER_DRIVERS)
  122. #define enable_y() { Y_ENABLE_WRITE( Y_ENABLE_ON); Y2_ENABLE_WRITE(Y_ENABLE_ON); }
  123. #define disable_y() { Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }
  124. #else
  125. #define enable_y() Y_ENABLE_WRITE( Y_ENABLE_ON)
  126. #define disable_y() { Y_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }
  127. #endif
  128. #else
  129. #define enable_y() ;
  130. #define disable_y() ;
  131. #endif
  132. #if HAS_Z_ENABLE
  133. #if ENABLED(Z_DUAL_STEPPER_DRIVERS)
  134. #define enable_z() { Z_ENABLE_WRITE( Z_ENABLE_ON); Z2_ENABLE_WRITE(Z_ENABLE_ON); }
  135. #define disable_z() { Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
  136. #else
  137. #define enable_z() Z_ENABLE_WRITE( Z_ENABLE_ON)
  138. #define disable_z() { Z_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
  139. #endif
  140. #else
  141. #define enable_z() ;
  142. #define disable_z() ;
  143. #endif
  144. #if HAS_E0_ENABLE
  145. #define enable_e0() E0_ENABLE_WRITE( E_ENABLE_ON)
  146. #define disable_e0() E0_ENABLE_WRITE(!E_ENABLE_ON)
  147. #else
  148. #define enable_e0() /* nothing */
  149. #define disable_e0() /* nothing */
  150. #endif
  151. #if (EXTRUDERS > 1) && HAS_E1_ENABLE
  152. #define enable_e1() E1_ENABLE_WRITE( E_ENABLE_ON)
  153. #define disable_e1() E1_ENABLE_WRITE(!E_ENABLE_ON)
  154. #else
  155. #define enable_e1() /* nothing */
  156. #define disable_e1() /* nothing */
  157. #endif
  158. #if (EXTRUDERS > 2) && HAS_E2_ENABLE
  159. #define enable_e2() E2_ENABLE_WRITE( E_ENABLE_ON)
  160. #define disable_e2() E2_ENABLE_WRITE(!E_ENABLE_ON)
  161. #else
  162. #define enable_e2() /* nothing */
  163. #define disable_e2() /* nothing */
  164. #endif
  165. #if (EXTRUDERS > 3) && HAS_E3_ENABLE
  166. #define enable_e3() E3_ENABLE_WRITE( E_ENABLE_ON)
  167. #define disable_e3() E3_ENABLE_WRITE(!E_ENABLE_ON)
  168. #else
  169. #define enable_e3() /* nothing */
  170. #define disable_e3() /* nothing */
  171. #endif
  172. /**
  173. * The axis order in all axis related arrays is X, Y, Z, E
  174. */
  175. #define NUM_AXIS 4
  176. /**
  177. * Axis indices as enumerated constants
  178. *
  179. * A_AXIS and B_AXIS are used by COREXY printers
  180. * X_HEAD and Y_HEAD is used for systems that don't have a 1:1 relationship between X_AXIS and X Head movement, like CoreXY bots.
  181. */
  182. enum AxisEnum {NO_AXIS = -1, X_AXIS = 0, A_AXIS = 0, Y_AXIS = 1, B_AXIS = 1, Z_AXIS = 2, C_AXIS = 2, E_AXIS = 3, X_HEAD = 4, Y_HEAD = 5, Z_HEAD = 5};
  183. #define _AXIS(AXIS) AXIS ##_AXIS
  184. typedef enum { LINEARUNIT_MM = 0, LINEARUNIT_INCH = 1 } LinearUnit;
  185. typedef enum { TEMPUNIT_C = 0, TEMPUNIT_K = 1, TEMPUNIT_F = 2 } TempUnit;
  186. void enable_all_steppers();
  187. void disable_all_steppers();
  188. void FlushSerialRequestResend();
  189. void ok_to_send();
  190. void reset_bed_level();
  191. void prepare_move();
  192. void kill(const char*);
  193. #if DISABLED(DELTA) && DISABLED(SCARA)
  194. void set_current_position_from_planner();
  195. #endif
  196. #if ENABLED(FILAMENT_RUNOUT_SENSOR)
  197. void handle_filament_runout();
  198. #endif
  199. /**
  200. * Debug flags - not yet widely applied
  201. */
  202. enum DebugFlags {
  203. DEBUG_NONE = 0,
  204. DEBUG_ECHO = _BV(0), ///< Echo commands in order as they are processed
  205. DEBUG_INFO = _BV(1), ///< Print messages for code that has debug output
  206. DEBUG_ERRORS = _BV(2), ///< Not implemented
  207. DEBUG_DRYRUN = _BV(3), ///< Ignore temperature setting and E movement commands
  208. DEBUG_COMMUNICATION = _BV(4), ///< Not implemented
  209. DEBUG_LEVELING = _BV(5) ///< Print detailed output for homing and leveling
  210. };
  211. extern uint8_t marlin_debug_flags;
  212. #define DEBUGGING(F) (marlin_debug_flags & (DEBUG_## F))
  213. extern bool Running;
  214. inline bool IsRunning() { return Running; }
  215. inline bool IsStopped() { return !Running; }
  216. bool enqueue_and_echo_command(const char* cmd, bool say_ok=false); //put a single ASCII command at the end of the current buffer or return false when it is full
  217. void enqueue_and_echo_command_now(const char* cmd); // enqueue now, only return when the command has been enqueued
  218. void enqueue_and_echo_commands_P(const char* cmd); //put one or many ASCII commands at the end of the current buffer, read from flash
  219. void clear_command_queue();
  220. void clamp_to_software_endstops(float target[3]);
  221. extern millis_t previous_cmd_ms;
  222. inline void refresh_cmd_timeout() { previous_cmd_ms = millis(); }
  223. #if ENABLED(FAST_PWM_FAN)
  224. void setPwmFrequency(uint8_t pin, int val);
  225. #endif
  226. #ifndef CRITICAL_SECTION_START
  227. #define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
  228. #define CRITICAL_SECTION_END SREG = _sreg;
  229. #endif
  230. extern bool axis_relative_modes[];
  231. extern int feedrate_multiplier;
  232. extern bool volumetric_enabled;
  233. extern int extruder_multiplier[EXTRUDERS]; // sets extrude multiply factor (in percent) for each extruder individually
  234. 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.
  235. extern float volumetric_multiplier[EXTRUDERS]; // reciprocal of cross-sectional area of filament (in square millimeters), stored this way to reduce computational burden in planner
  236. extern float current_position[NUM_AXIS];
  237. extern float home_offset[3]; // axis[n].home_offset
  238. extern float sw_endstop_min[3]; // axis[n].sw_endstop_min
  239. extern float sw_endstop_max[3]; // axis[n].sw_endstop_max
  240. extern bool axis_known_position[3]; // axis[n].is_known
  241. extern bool axis_homed[3]; // axis[n].is_homed
  242. // GCode support for external objects
  243. bool code_seen(char);
  244. int code_value_int();
  245. float code_value_temp_abs();
  246. float code_value_temp_diff();
  247. #if ENABLED(DELTA)
  248. extern float delta[3];
  249. extern float endstop_adj[3]; // axis[n].endstop_adj
  250. extern float delta_radius;
  251. extern float delta_diagonal_rod;
  252. extern float delta_segments_per_second;
  253. extern float delta_diagonal_rod_trim_tower_1;
  254. extern float delta_diagonal_rod_trim_tower_2;
  255. extern float delta_diagonal_rod_trim_tower_3;
  256. void calculate_delta(float cartesian[3]);
  257. void recalc_delta_settings(float radius, float diagonal_rod);
  258. #if ENABLED(AUTO_BED_LEVELING_FEATURE)
  259. extern int delta_grid_spacing[2];
  260. void adjust_delta(float cartesian[3]);
  261. #endif
  262. #elif ENABLED(SCARA)
  263. extern float axis_scaling[3]; // Build size scaling
  264. void calculate_delta(float cartesian[3]);
  265. void calculate_SCARA_forward_Transform(float f_scara[3]);
  266. #endif
  267. #if ENABLED(Z_DUAL_ENDSTOPS)
  268. extern float z_endstop_adj;
  269. #endif
  270. #if ENABLED(AUTO_BED_LEVELING_FEATURE)
  271. extern float zprobe_zoffset;
  272. #endif
  273. #if ENABLED(HOST_KEEPALIVE_FEATURE)
  274. extern uint8_t host_keepalive_interval;
  275. #endif
  276. #if FAN_COUNT > 0
  277. extern int fanSpeeds[FAN_COUNT];
  278. #endif
  279. #if ENABLED(BARICUDA)
  280. extern int baricuda_valve_pressure;
  281. extern int baricuda_e_to_p_pressure;
  282. #endif
  283. #if ENABLED(FILAMENT_WIDTH_SENSOR)
  284. extern float filament_width_nominal; //holds the theoretical filament diameter i.e., 3.00 or 1.75
  285. extern bool filament_sensor; //indicates that filament sensor readings should control extrusion
  286. extern float filament_width_meas; //holds the filament diameter as accurately measured
  287. extern int8_t measurement_delay[]; //ring buffer to delay measurement
  288. extern int filwidth_delay_index1, filwidth_delay_index2; //ring buffer index. used by planner, temperature, and main code
  289. extern int meas_delay_cm; //delay distance
  290. #endif
  291. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  292. extern int lpq_len;
  293. #endif
  294. #if ENABLED(FWRETRACT)
  295. extern bool autoretract_enabled;
  296. extern bool retracted[EXTRUDERS]; // extruder[n].retracted
  297. extern float retract_length, retract_length_swap, retract_feedrate, retract_zlift;
  298. extern float retract_recover_length, retract_recover_length_swap, retract_recover_feedrate;
  299. #endif
  300. // Print job timer
  301. #if ENABLED(PRINTCOUNTER)
  302. extern PrintCounter print_job_timer;
  303. #else
  304. extern Stopwatch print_job_timer;
  305. #endif
  306. // Handling multiple extruders pins
  307. extern uint8_t active_extruder;
  308. #if HAS_TEMP_HOTEND || HAS_TEMP_BED
  309. void print_heaterstates();
  310. #endif
  311. void calculate_volumetric_multipliers();
  312. // Buzzer
  313. #if HAS_BUZZER
  314. #if ENABLED(SPEAKER)
  315. #include "speaker.h"
  316. extern Speaker buzzer;
  317. #else
  318. #include "buzzer.h"
  319. extern Buzzer buzzer;
  320. #endif
  321. #endif
  322. #endif //MARLIN_H