My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. // Arduino < 1.0.0 does not define this, so we need to do it ourselves
  47. #ifndef analogInputToDigitalPin
  48. #define analogInputToDigitalPin(p) ((p) + 0xA0)
  49. #endif
  50. #ifdef USBCON
  51. #include "HardwareSerial.h"
  52. #endif
  53. #include "MarlinSerial.h"
  54. #include "WString.h"
  55. #ifdef USBCON
  56. #if ENABLED(BLUETOOTH)
  57. #define MYSERIAL bluetoothSerial
  58. #else
  59. #define MYSERIAL Serial
  60. #endif // BLUETOOTH
  61. #else
  62. #define MYSERIAL customizedSerial
  63. #endif
  64. #define SERIAL_CHAR(x) MYSERIAL.write(x)
  65. #define SERIAL_EOL SERIAL_CHAR('\n')
  66. #define SERIAL_PROTOCOLCHAR(x) SERIAL_CHAR(x)
  67. #define SERIAL_PROTOCOL(x) MYSERIAL.print(x)
  68. #define SERIAL_PROTOCOL_F(x,y) MYSERIAL.print(x,y)
  69. #define SERIAL_PROTOCOLPGM(x) serialprintPGM(PSTR(x))
  70. #define SERIAL_PROTOCOLLN(x) do{ MYSERIAL.print(x); SERIAL_EOL; }while(0)
  71. #define SERIAL_PROTOCOLLNPGM(x) do{ serialprintPGM(PSTR(x)); SERIAL_EOL; }while(0)
  72. extern const char errormagic[] PROGMEM;
  73. extern const char echomagic[] PROGMEM;
  74. #define SERIAL_ERROR_START serialprintPGM(errormagic)
  75. #define SERIAL_ERROR(x) SERIAL_PROTOCOL(x)
  76. #define SERIAL_ERRORPGM(x) SERIAL_PROTOCOLPGM(x)
  77. #define SERIAL_ERRORLN(x) SERIAL_PROTOCOLLN(x)
  78. #define SERIAL_ERRORLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
  79. #define SERIAL_ECHO_START serialprintPGM(echomagic)
  80. #define SERIAL_ECHO(x) SERIAL_PROTOCOL(x)
  81. #define SERIAL_ECHOPGM(x) SERIAL_PROTOCOLPGM(x)
  82. #define SERIAL_ECHOLN(x) SERIAL_PROTOCOLLN(x)
  83. #define SERIAL_ECHOLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
  84. #define SERIAL_ECHOPAIR(name,value) do{ serial_echopair_P(PSTR(name),(value)); }while(0)
  85. void serial_echopair_P(const char* s_P, int v);
  86. void serial_echopair_P(const char* s_P, long v);
  87. void serial_echopair_P(const char* s_P, float v);
  88. void serial_echopair_P(const char* s_P, double v);
  89. void serial_echopair_P(const char* s_P, unsigned long v);
  90. // Things to write to serial from Program memory. Saves 400 to 2k of RAM.
  91. FORCE_INLINE void serialprintPGM(const char* str) {
  92. char ch;
  93. while ((ch = pgm_read_byte(str))) {
  94. MYSERIAL.write(ch);
  95. str++;
  96. }
  97. }
  98. void get_command();
  99. void idle(
  100. #if ENABLED(FILAMENTCHANGEENABLE)
  101. bool no_stepper_sleep=false // pass true to keep steppers from disabling on timeout
  102. #endif
  103. );
  104. void manage_inactivity(bool ignore_stepper_queue = false);
  105. #if ENABLED(DUAL_X_CARRIAGE) && HAS_X_ENABLE && HAS_X2_ENABLE
  106. #define enable_x() do { X_ENABLE_WRITE( X_ENABLE_ON); X2_ENABLE_WRITE( X_ENABLE_ON); } while (0)
  107. #define disable_x() do { X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; } while (0)
  108. #elif HAS_X_ENABLE
  109. #define enable_x() X_ENABLE_WRITE( X_ENABLE_ON)
  110. #define disable_x() { X_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }
  111. #else
  112. #define enable_x() ;
  113. #define disable_x() ;
  114. #endif
  115. #if HAS_Y_ENABLE
  116. #if ENABLED(Y_DUAL_STEPPER_DRIVERS)
  117. #define enable_y() { Y_ENABLE_WRITE( Y_ENABLE_ON); Y2_ENABLE_WRITE(Y_ENABLE_ON); }
  118. #define disable_y() { Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }
  119. #else
  120. #define enable_y() Y_ENABLE_WRITE( Y_ENABLE_ON)
  121. #define disable_y() { Y_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }
  122. #endif
  123. #else
  124. #define enable_y() ;
  125. #define disable_y() ;
  126. #endif
  127. #if HAS_Z_ENABLE
  128. #if ENABLED(Z_DUAL_STEPPER_DRIVERS)
  129. #define enable_z() { Z_ENABLE_WRITE( Z_ENABLE_ON); Z2_ENABLE_WRITE(Z_ENABLE_ON); }
  130. #define disable_z() { Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
  131. #else
  132. #define enable_z() Z_ENABLE_WRITE( Z_ENABLE_ON)
  133. #define disable_z() { Z_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
  134. #endif
  135. #else
  136. #define enable_z() ;
  137. #define disable_z() ;
  138. #endif
  139. #if HAS_E0_ENABLE
  140. #define enable_e0() E0_ENABLE_WRITE( E_ENABLE_ON)
  141. #define disable_e0() E0_ENABLE_WRITE(!E_ENABLE_ON)
  142. #else
  143. #define enable_e0() /* nothing */
  144. #define disable_e0() /* nothing */
  145. #endif
  146. #if (EXTRUDERS > 1) && HAS_E1_ENABLE
  147. #define enable_e1() E1_ENABLE_WRITE( E_ENABLE_ON)
  148. #define disable_e1() E1_ENABLE_WRITE(!E_ENABLE_ON)
  149. #else
  150. #define enable_e1() /* nothing */
  151. #define disable_e1() /* nothing */
  152. #endif
  153. #if (EXTRUDERS > 2) && HAS_E2_ENABLE
  154. #define enable_e2() E2_ENABLE_WRITE( E_ENABLE_ON)
  155. #define disable_e2() E2_ENABLE_WRITE(!E_ENABLE_ON)
  156. #else
  157. #define enable_e2() /* nothing */
  158. #define disable_e2() /* nothing */
  159. #endif
  160. #if (EXTRUDERS > 3) && HAS_E3_ENABLE
  161. #define enable_e3() E3_ENABLE_WRITE( E_ENABLE_ON)
  162. #define disable_e3() E3_ENABLE_WRITE(!E_ENABLE_ON)
  163. #else
  164. #define enable_e3() /* nothing */
  165. #define disable_e3() /* nothing */
  166. #endif
  167. /**
  168. * The axis order in all axis related arrays is X, Y, Z, E
  169. */
  170. #define NUM_AXIS 4
  171. /**
  172. * Axis indices as enumerated constants
  173. *
  174. * A_AXIS and B_AXIS are used by COREXY printers
  175. * 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.
  176. */
  177. enum AxisEnum {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};
  178. enum EndstopEnum {X_MIN = 0, Y_MIN = 1, Z_MIN = 2, Z_MIN_PROBE = 3, X_MAX = 4, Y_MAX = 5, Z_MAX = 6, Z2_MIN = 7, Z2_MAX = 8};
  179. void enable_all_steppers();
  180. void disable_all_steppers();
  181. void FlushSerialRequestResend();
  182. void ok_to_send();
  183. void reset_bed_level();
  184. void prepare_move();
  185. void kill(const char*);
  186. void Stop();
  187. #if ENABLED(FILAMENT_RUNOUT_SENSOR)
  188. void filrunout();
  189. #endif
  190. /**
  191. * Debug flags - not yet widely applied
  192. */
  193. enum DebugFlags {
  194. DEBUG_ECHO = _BV(0),
  195. DEBUG_INFO = _BV(1),
  196. DEBUG_ERRORS = _BV(2),
  197. DEBUG_DRYRUN = _BV(3),
  198. DEBUG_COMMUNICATION = _BV(4),
  199. DEBUG_LEVELING = _BV(5)
  200. };
  201. extern uint8_t marlin_debug_flags;
  202. extern bool Running;
  203. inline bool IsRunning() { return Running; }
  204. inline bool IsStopped() { return !Running; }
  205. 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
  206. void enqueue_and_echo_command_now(const char* cmd); // enqueue now, only return when the command has been enqueued
  207. 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
  208. void prepare_arc_move(char isclockwise);
  209. void clamp_to_software_endstops(float target[3]);
  210. extern millis_t previous_cmd_ms;
  211. inline void refresh_cmd_timeout() { previous_cmd_ms = millis(); }
  212. #if ENABLED(FAST_PWM_FAN)
  213. void setPwmFrequency(uint8_t pin, int val);
  214. #endif
  215. #ifndef CRITICAL_SECTION_START
  216. #define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
  217. #define CRITICAL_SECTION_END SREG = _sreg;
  218. #endif
  219. extern bool axis_relative_modes[];
  220. extern int feedrate_multiplier;
  221. extern bool volumetric_enabled;
  222. extern int extruder_multiplier[EXTRUDERS]; // sets extrude multiply factor (in percent) for each extruder individually
  223. 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.
  224. extern float volumetric_multiplier[EXTRUDERS]; // reciprocal of cross-sectional area of filament (in square millimeters), stored this way to reduce computational burden in planner
  225. extern float current_position[NUM_AXIS];
  226. extern float home_offset[3]; // axis[n].home_offset
  227. extern float min_pos[3]; // axis[n].min_pos
  228. extern float max_pos[3]; // axis[n].max_pos
  229. extern bool axis_known_position[3]; // axis[n].is_known
  230. extern bool axis_homed[3]; // axis[n].is_homed
  231. #if ENABLED(DELTA)
  232. #ifndef DELTA_RADIUS_TRIM_TOWER_1
  233. #define DELTA_RADIUS_TRIM_TOWER_1 0.0
  234. #endif
  235. #ifndef DELTA_RADIUS_TRIM_TOWER_2
  236. #define DELTA_RADIUS_TRIM_TOWER_2 0.0
  237. #endif
  238. #ifndef DELTA_RADIUS_TRIM_TOWER_3
  239. #define DELTA_RADIUS_TRIM_TOWER_3 0.0
  240. #endif
  241. #ifndef DELTA_DIAGONAL_ROD_TRIM_TOWER_1
  242. #define DELTA_DIAGONAL_ROD_TRIM_TOWER_1 0.0
  243. #endif
  244. #ifndef DELTA_DIAGONAL_ROD_TRIM_TOWER_2
  245. #define DELTA_DIAGONAL_ROD_TRIM_TOWER_2 0.0
  246. #endif
  247. #ifndef DELTA_DIAGONAL_ROD_TRIM_TOWER_3
  248. #define DELTA_DIAGONAL_ROD_TRIM_TOWER_3 0.0
  249. #endif
  250. extern float delta[3];
  251. extern float endstop_adj[3]; // axis[n].endstop_adj
  252. extern float delta_radius;
  253. extern float delta_diagonal_rod;
  254. extern float delta_segments_per_second;
  255. extern float delta_diagonal_rod_trim_tower_1;
  256. extern float delta_diagonal_rod_trim_tower_2;
  257. extern float delta_diagonal_rod_trim_tower_3;
  258. void calculate_delta(float cartesian[3]);
  259. void recalc_delta_settings(float radius, float diagonal_rod);
  260. #if ENABLED(AUTO_BED_LEVELING_FEATURE)
  261. extern int delta_grid_spacing[2];
  262. void adjust_delta(float cartesian[3]);
  263. #endif
  264. #elif ENABLED(SCARA)
  265. extern float axis_scaling[3]; // Build size scaling
  266. void calculate_delta(float cartesian[3]);
  267. void calculate_SCARA_forward_Transform(float f_scara[3]);
  268. #endif
  269. #if ENABLED(Z_DUAL_ENDSTOPS)
  270. extern float z_endstop_adj;
  271. #endif
  272. #if ENABLED(AUTO_BED_LEVELING_FEATURE)
  273. extern float zprobe_zoffset;
  274. #endif
  275. #if ENABLED(PREVENT_DANGEROUS_EXTRUDE)
  276. extern float extrude_min_temp;
  277. #endif
  278. #if FAN_COUNT > 0
  279. extern int fanSpeeds[FAN_COUNT];
  280. #endif
  281. #if ENABLED(BARICUDA)
  282. extern int ValvePressure;
  283. extern int EtoPPressure;
  284. #endif
  285. #if ENABLED(FILAMENT_SENSOR)
  286. extern float filament_width_nominal; //holds the theoretical filament diameter i.e., 3.00 or 1.75
  287. extern bool filament_sensor; //indicates that filament sensor readings should control extrusion
  288. extern float filament_width_meas; //holds the filament diameter as accurately measured
  289. extern signed char measurement_delay[]; //ring buffer to delay measurement
  290. extern int delay_index1, delay_index2; //ring buffer index. used by planner, temperature, and main code
  291. extern float delay_dist; //delay distance counter
  292. extern int meas_delay_cm; //delay distance
  293. #endif
  294. #if ENABLED(PID_ADD_EXTRUSION_RATE)
  295. extern int lpq_len;
  296. #endif
  297. #if ENABLED(FWRETRACT)
  298. extern bool autoretract_enabled;
  299. extern bool retracted[EXTRUDERS]; // extruder[n].retracted
  300. extern float retract_length, retract_length_swap, retract_feedrate, retract_zlift;
  301. extern float retract_recover_length, retract_recover_length_swap, retract_recover_feedrate;
  302. #endif
  303. extern millis_t print_job_start_ms;
  304. extern millis_t print_job_stop_ms;
  305. // Handling multiple extruders pins
  306. extern uint8_t active_extruder;
  307. #if ENABLED(DIGIPOT_I2C)
  308. extern void digipot_i2c_set_current(int channel, float current);
  309. extern void digipot_i2c_init();
  310. #endif
  311. #if HAS_TEMP_0 || HAS_TEMP_BED || ENABLED(HEATER_0_USES_MAX6675)
  312. void print_heaterstates();
  313. #endif
  314. extern void calculate_volumetric_multipliers();
  315. // Print job timer related functions
  316. millis_t print_job_timer();
  317. bool print_job_start(millis_t t = 0);
  318. bool print_job_stop(bool force = false);
  319. #endif //MARLIN_H