My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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