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.

gcode.h 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * gcode.h - Temporary container for all gcode handlers
  25. */
  26. /**
  27. * -----------------
  28. * G-Codes in Marlin
  29. * -----------------
  30. *
  31. * Helpful G-code references:
  32. * - https://marlinfw.org/meta/gcode
  33. * - https://reprap.org/wiki/G-code
  34. * - https://linuxcnc.org/docs/html/gcode.html
  35. *
  36. * Help to document Marlin's G-codes online:
  37. * - https://github.com/MarlinFirmware/MarlinDocumentation
  38. *
  39. * -----------------
  40. *
  41. * "G" Codes
  42. *
  43. * G0 -> G1
  44. * G1 - Coordinated Movement X Y Z E
  45. * G2 - CW ARC
  46. * G3 - CCW ARC
  47. * G4 - Dwell S<seconds> or P<milliseconds>
  48. * G5 - Cubic B-spline with XYZE destination and IJPQ offsets
  49. * G10 - Retract filament according to settings of M207 (Requires FWRETRACT)
  50. * G11 - Retract recover filament according to settings of M208 (Requires FWRETRACT)
  51. * G12 - Clean tool (Requires NOZZLE_CLEAN_FEATURE)
  52. * G17 - Select Plane XY (Requires CNC_WORKSPACE_PLANES)
  53. * G18 - Select Plane ZX (Requires CNC_WORKSPACE_PLANES)
  54. * G19 - Select Plane YZ (Requires CNC_WORKSPACE_PLANES)
  55. * G20 - Set input units to inches (Requires INCH_MODE_SUPPORT)
  56. * G21 - Set input units to millimeters (Requires INCH_MODE_SUPPORT)
  57. * G26 - Mesh Validation Pattern (Requires G26_MESH_VALIDATION)
  58. * G27 - Park Nozzle (Requires NOZZLE_PARK_FEATURE)
  59. * G28 - Home one or more axes
  60. * G29 - Start or continue the bed leveling probe procedure (Requires bed leveling)
  61. * G30 - Single Z probe, probes bed at X Y location (defaults to current XY location)
  62. * G31 - Dock sled (Z_PROBE_SLED only)
  63. * G32 - Undock sled (Z_PROBE_SLED only)
  64. * G33 - Delta Auto-Calibration (Requires DELTA_AUTO_CALIBRATION)
  65. * G34 - Z Stepper automatic alignment using probe: I<iterations> T<accuracy> A<amplification> (Requires Z_STEPPER_AUTO_ALIGN)
  66. * G35 - Read bed corners to help adjust bed screws: T<screw_thread> (Requires ASSISTED_TRAMMING)
  67. * G38 - Probe in any direction using the Z_MIN_PROBE (Requires G38_PROBE_TARGET)
  68. * G42 - Coordinated move to a mesh point (Requires MESH_BED_LEVELING, AUTO_BED_LEVELING_BLINEAR, or AUTO_BED_LEVELING_UBL)
  69. * G60 - Save current position. (Requires SAVED_POSITIONS)
  70. * G61 - Apply/restore saved coordinates. (Requires SAVED_POSITIONS)
  71. * G76 - Calibrate first layer temperature offsets. (Requires PROBE_TEMP_COMPENSATION)
  72. * G80 - Cancel current motion mode (Requires GCODE_MOTION_MODES)
  73. * G90 - Use Absolute Coordinates
  74. * G91 - Use Relative Coordinates
  75. * G92 - Set current position to coordinates given
  76. *
  77. * "M" Codes
  78. *
  79. * M0 - Unconditional stop - Wait for user to press a button on the LCD (Only if ULTRA_LCD is enabled)
  80. * M1 -> M0
  81. * M3 - Turn ON Laser | Spindle (clockwise), set Power | Speed. (Requires SPINDLE_FEATURE or LASER_FEATURE)
  82. * M4 - Turn ON Laser | Spindle (counter-clockwise), set Power | Speed. (Requires SPINDLE_FEATURE or LASER_FEATURE)
  83. * M5 - Turn OFF Laser | Spindle. (Requires SPINDLE_FEATURE or LASER_FEATURE)
  84. * M7 - Turn mist coolant ON. (Requires COOLANT_CONTROL)
  85. * M8 - Turn flood coolant ON. (Requires COOLANT_CONTROL)
  86. * M9 - Turn coolant OFF. (Requires COOLANT_CONTROL)
  87. * M12 - Set up closed loop control system. (Requires EXTERNAL_CLOSED_LOOP_CONTROLLER)
  88. * M16 - Expected printer check. (Requires EXPECTED_PRINTER_CHECK)
  89. * M17 - Enable/Power all stepper motors
  90. * M18 - Disable all stepper motors; same as M84
  91. * M20 - List SD card. (Requires SDSUPPORT)
  92. * M21 - Init SD card. (Requires SDSUPPORT)
  93. * M22 - Release SD card. (Requires SDSUPPORT)
  94. * M23 - Select SD file: "M23 /path/file.gco". (Requires SDSUPPORT)
  95. * M24 - Start/resume SD print. (Requires SDSUPPORT)
  96. * M25 - Pause SD print. (Requires SDSUPPORT)
  97. * M26 - Set SD position in bytes: "M26 S12345". (Requires SDSUPPORT)
  98. * M27 - Report SD print status. (Requires SDSUPPORT)
  99. * OR, with 'S<seconds>' set the SD status auto-report interval. (Requires AUTO_REPORT_SD_STATUS)
  100. * OR, with 'C' get the current filename.
  101. * M28 - Start SD write: "M28 /path/file.gco". (Requires SDSUPPORT)
  102. * M29 - Stop SD write. (Requires SDSUPPORT)
  103. * M30 - Delete file from SD: "M30 /path/file.gco"
  104. * M31 - Report time since last M109 or SD card start to serial.
  105. * M32 - Select file and start SD print: "M32 [S<bytepos>] !/path/file.gco#". (Requires SDSUPPORT)
  106. * Use P to run other files as sub-programs: "M32 P !filename#"
  107. * The '#' is necessary when calling from within sd files, as it stops buffer prereading
  108. * M33 - Get the longname version of a path. (Requires LONG_FILENAME_HOST_SUPPORT)
  109. * M34 - Set SD Card sorting options. (Requires SDCARD_SORT_ALPHA)
  110. * M42 - Change pin status via gcode: M42 P<pin> S<value>. LED pin assumed if P is omitted. (Requires DIRECT_PIN_CONTROL)
  111. * M43 - Display pin status, watch pins for changes, watch endstops & toggle LED, Z servo probe test, toggle pins
  112. * M48 - Measure Z Probe repeatability: M48 P<points> X<pos> Y<pos> V<level> E<engage> L<legs> S<chizoid>. (Requires Z_MIN_PROBE_REPEATABILITY_TEST)
  113. * M73 - Set the progress percentage. (Requires LCD_SET_PROGRESS_MANUALLY)
  114. * M75 - Start the print job timer.
  115. * M76 - Pause the print job timer.
  116. * M77 - Stop the print job timer.
  117. * M78 - Show statistical information about the print jobs. (Requires PRINTCOUNTER)
  118. * M80 - Turn on Power Supply. (Requires PSU_CONTROL)
  119. * M81 - Turn off Power Supply. (Requires PSU_CONTROL)
  120. * M82 - Set E codes absolute (default).
  121. * M83 - Set E codes relative while in Absolute (G90) mode.
  122. * M84 - Disable steppers until next move, or use S<seconds> to specify an idle
  123. * duration after which steppers should turn off. S0 disables the timeout.
  124. * M85 - Set inactivity shutdown timer with parameter S<seconds>. To disable set zero (default)
  125. * M92 - Set planner.settings.axis_steps_per_mm for one or more axes.
  126. * M100 - Watch Free Memory (for debugging) (Requires M100_FREE_MEMORY_WATCHER)
  127. * M104 - Set extruder target temp.
  128. * M105 - Report current temperatures.
  129. * M106 - Set print fan speed.
  130. * M107 - Print fan off.
  131. * M108 - Break out of heating loops (M109, M190, M303). With no controller, breaks out of M0/M1. (Requires EMERGENCY_PARSER)
  132. * M109 - S<temp> Wait for extruder current temp to reach target temp. ** Wait only when heating! **
  133. * R<temp> Wait for extruder current temp to reach target temp. ** Wait for heating or cooling. **
  134. * If AUTOTEMP is enabled, S<mintemp> B<maxtemp> F<factor>. Exit autotemp by any M109 without F
  135. * M110 - Set the current line number. (Used by host printing)
  136. * M111 - Set debug flags: "M111 S<flagbits>". See flag bits defined in enum.h.
  137. * M112 - Full Shutdown.
  138. * M113 - Get or set the timeout interval for Host Keepalive "busy" messages. (Requires HOST_KEEPALIVE_FEATURE)
  139. * M114 - Report current position.
  140. * M115 - Report capabilities. (Extended capabilities requires EXTENDED_CAPABILITIES_REPORT)
  141. * M117 - Display a message on the controller screen. (Requires an LCD)
  142. * M118 - Display a message in the host console.
  143. * M119 - Report endstops status.
  144. * M120 - Enable endstops detection.
  145. * M121 - Disable endstops detection.
  146. * M122 - Debug stepper (Requires at least one _DRIVER_TYPE defined as TMC2130/2160/5130/5160/2208/2209/2660 or L6470)
  147. * M125 - Save current position and move to filament change position. (Requires PARK_HEAD_ON_PAUSE)
  148. * M126 - Solenoid Air Valve Open. (Requires BARICUDA)
  149. * M127 - Solenoid Air Valve Closed. (Requires BARICUDA)
  150. * M128 - EtoP Open. (Requires BARICUDA)
  151. * M129 - EtoP Closed. (Requires BARICUDA)
  152. * M140 - Set bed target temp. S<temp>
  153. * M141 - Set heated chamber target temp. S<temp> (Requires a chamber heater)
  154. * M145 - Set heatup values for materials on the LCD. H<hotend> B<bed> F<fan speed> for S<material> (0=PLA, 1=ABS)
  155. * M149 - Set temperature units. (Requires TEMPERATURE_UNITS_SUPPORT)
  156. * M150 - Set Status LED Color as R<red> U<green> B<blue> W<white> P<bright>. Values 0-255. (Requires BLINKM, RGB_LED, RGBW_LED, NEOPIXEL_LED, PCA9533, or PCA9632).
  157. * M155 - Auto-report temperatures with interval of S<seconds>. (Requires AUTO_REPORT_TEMPERATURES)
  158. * M163 - Set a single proportion for a mixing extruder. (Requires MIXING_EXTRUDER)
  159. * M164 - Commit the mix and save to a virtual tool (current, or as specified by 'S'). (Requires MIXING_EXTRUDER)
  160. * M165 - Set the mix for the mixing extruder (and current virtual tool) with parameters ABCDHI. (Requires MIXING_EXTRUDER and DIRECT_MIXING_IN_G1)
  161. * M166 - Set the Gradient Mix for the mixing extruder. (Requires GRADIENT_MIX)
  162. * M190 - S<temp> Wait for bed current temp to reach target temp. ** Wait only when heating! **
  163. * R<temp> Wait for bed current temp to reach target temp. ** Wait for heating or cooling. **
  164. * M200 - Set filament diameter, D<diameter>, setting E axis units to cubic. (Use S0 to revert to linear units.)
  165. * M201 - Set max acceleration in units/s^2 for print moves: "M201 X<accel> Y<accel> Z<accel> E<accel>"
  166. * M202 - Set max acceleration in units/s^2 for travel moves: "M202 X<accel> Y<accel> Z<accel> E<accel>" ** UNUSED IN MARLIN! **
  167. * M203 - Set maximum feedrate: "M203 X<fr> Y<fr> Z<fr> E<fr>" in units/sec.
  168. * M204 - Set default acceleration in units/sec^2: P<printing> R<extruder_only> T<travel>
  169. * M205 - Set advanced settings. Current units apply:
  170. S<print> T<travel> minimum speeds
  171. B<minimum segment time>
  172. X<max X jerk>, Y<max Y jerk>, Z<max Z jerk>, E<max E jerk>
  173. * M206 - Set additional homing offset. (Disabled by NO_WORKSPACE_OFFSETS or DELTA)
  174. * M207 - Set Retract Length: S<length>, Feedrate: F<units/min>, and Z lift: Z<distance>. (Requires FWRETRACT)
  175. * M208 - Set Recover (unretract) Additional (!) Length: S<length> and Feedrate: F<units/min>. (Requires FWRETRACT)
  176. * M209 - Turn Automatic Retract Detection on/off: S<0|1> (For slicers that don't support G10/11). (Requires FWRETRACT_AUTORETRACT)
  177. Every normal extrude-only move will be classified as retract depending on the direction.
  178. * M211 - Enable, Disable, and/or Report software endstops: S<0|1> (Requires MIN_SOFTWARE_ENDSTOPS or MAX_SOFTWARE_ENDSTOPS)
  179. * M217 - Set filament swap parameters: "M217 S<length> P<feedrate> R<feedrate>". (Requires SINGLENOZZLE)
  180. * M218 - Set/get a tool offset: "M218 T<index> X<offset> Y<offset>". (Requires 2 or more extruders)
  181. * M220 - Set Feedrate Percentage: "M220 S<percent>" (i.e., "FR" on the LCD)
  182. * Use "M220 B" to back up the Feedrate Percentage and "M220 R" to restore it. (Requires PRUSA_MMU2)
  183. * M221 - Set Flow Percentage: "M221 S<percent>"
  184. * M226 - Wait until a pin is in a given state: "M226 P<pin> S<state>" (Requires DIRECT_PIN_CONTROL)
  185. * M240 - Trigger a camera to take a photograph. (Requires PHOTO_GCODE)
  186. * M250 - Set LCD contrast: "M250 C<contrast>" (0-63). (Requires LCD support)
  187. * M260 - i2c Send Data (Requires EXPERIMENTAL_I2CBUS)
  188. * M261 - i2c Request Data (Requires EXPERIMENTAL_I2CBUS)
  189. * M280 - Set servo position absolute: "M280 P<index> S<angle|µs>". (Requires servos)
  190. * M281 - Set servo min|max position: "M281 P<index> L<min> U<max>". (Requires EDITABLE_SERVO_ANGLES)
  191. * M290 - Babystepping (Requires BABYSTEPPING)
  192. * M300 - Play beep sound S<frequency Hz> P<duration ms>
  193. * M301 - Set PID parameters P I and D. (Requires PIDTEMP)
  194. * M302 - Allow cold extrudes, or set the minimum extrude S<temperature>. (Requires PREVENT_COLD_EXTRUSION)
  195. * M303 - PID relay autotune S<temperature> sets the target temperature. Default 150C. (Requires PIDTEMP)
  196. * M304 - Set bed PID parameters P I and D. (Requires PIDTEMPBED)
  197. * M305 - Set user thermistor parameters R T and P. (Requires TEMP_SENSOR_x 1000)
  198. * M350 - Set microstepping mode. (Requires digital microstepping pins.)
  199. * M351 - Toggle MS1 MS2 pins directly. (Requires digital microstepping pins.)
  200. * M355 - Set Case Light on/off and set brightness. (Requires CASE_LIGHT_PIN)
  201. * M380 - Activate solenoid on active extruder. (Requires EXT_SOLENOID)
  202. * M381 - Disable all solenoids. (Requires EXT_SOLENOID)
  203. * M400 - Finish all moves.
  204. * M401 - Deploy and activate Z probe. (Requires a probe)
  205. * M402 - Deactivate and stow Z probe. (Requires a probe)
  206. * M403 - Set filament type for PRUSA MMU2
  207. * M404 - Display or set the Nominal Filament Width: "W<diameter>". (Requires FILAMENT_WIDTH_SENSOR)
  208. * M405 - Enable Filament Sensor flow control. "M405 D<delay_cm>". (Requires FILAMENT_WIDTH_SENSOR)
  209. * M406 - Disable Filament Sensor flow control. (Requires FILAMENT_WIDTH_SENSOR)
  210. * M407 - Display measured filament diameter in millimeters. (Requires FILAMENT_WIDTH_SENSOR)
  211. * M410 - Quickstop. Abort all planned moves.
  212. * M412 - Enable / Disable Filament Runout Detection. (Requires FILAMENT_RUNOUT_SENSOR)
  213. * M413 - Enable / Disable Power-Loss Recovery. (Requires POWER_LOSS_RECOVERY)
  214. * M420 - Enable/Disable Leveling (with current values) S1=enable S0=disable (Requires MESH_BED_LEVELING or ABL)
  215. * M421 - Set a single Z coordinate in the Mesh Leveling grid. X<units> Y<units> Z<units> (Requires MESH_BED_LEVELING, AUTO_BED_LEVELING_BILINEAR, or AUTO_BED_LEVELING_UBL)
  216. * M422 - Set Z Stepper automatic alignment position using probe. X<units> Y<units> A<axis> (Requires Z_STEPPER_AUTO_ALIGN)
  217. * M425 - Enable/Disable and tune backlash correction. (Requires BACKLASH_COMPENSATION and BACKLASH_GCODE)
  218. * M428 - Set the home_offset based on the current_position. Nearest edge applies. (Disabled by NO_WORKSPACE_OFFSETS or DELTA)
  219. * M430 - Read the system current, voltage, and power (Requires POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE, or POWER_MONITOR_FIXED_VOLTAGE)
  220. * M486 - Identify and cancel objects. (Requires CANCEL_OBJECTS)
  221. * M500 - Store parameters in EEPROM. (Requires EEPROM_SETTINGS)
  222. * M501 - Restore parameters from EEPROM. (Requires EEPROM_SETTINGS)
  223. * M502 - Revert to the default "factory settings". ** Does not write them to EEPROM! **
  224. * M503 - Print the current settings (in memory): "M503 S<verbose>". S0 specifies compact output.
  225. * M504 - Validate EEPROM contents. (Requires EEPROM_SETTINGS)
  226. * M510 - Lock Printer
  227. * M511 - Unlock Printer
  228. * M512 - Set/Change/Remove Password
  229. * M524 - Abort the current SD print job started with M24. (Requires SDSUPPORT)
  230. * M540 - Enable/disable SD card abort on endstop hit: "M540 S<state>". (Requires SD_ABORT_ON_ENDSTOP_HIT)
  231. * M569 - Enable stealthChop on an axis. (Requires at least one _DRIVER_TYPE to be TMC2130/2160/2208/2209/5130/5160)
  232. * M600 - Pause for filament change: "M600 X<pos> Y<pos> Z<raise> E<first_retract> L<later_retract>". (Requires ADVANCED_PAUSE_FEATURE)
  233. * M603 - Configure filament change: "M603 T<tool> U<unload_length> L<load_length>". (Requires ADVANCED_PAUSE_FEATURE)
  234. * M605 - Set Dual X-Carriage movement mode: "M605 S<mode> [X<x_offset>] [R<temp_offset>]". (Requires DUAL_X_CARRIAGE)
  235. * M665 - Set delta configurations: "M665 H<delta height> L<diagonal rod> R<delta radius> S<segments/s> B<calibration radius> X<Alpha angle trim> Y<Beta angle trim> Z<Gamma angle trim> (Requires DELTA)
  236. * M666 - Set/get offsets for delta (Requires DELTA) or dual endstops. (Requires [XYZ]_DUAL_ENDSTOPS)
  237. * M672 - Set/Reset Duet Smart Effector's sensitivity. (Requires DUET_SMART_EFFECTOR and SMART_EFFECTOR_MOD_PIN)
  238. * M701 - Load filament (Requires FILAMENT_LOAD_UNLOAD_GCODES)
  239. * M702 - Unload filament (Requires FILAMENT_LOAD_UNLOAD_GCODES)
  240. * M810-M819 - Define/execute a G-code macro (Requires GCODE_MACROS)
  241. * M851 - Set Z probe's XYZ offsets in current units. (Negative values: X=left, Y=front, Z=below)
  242. * M852 - Set skew factors: "M852 [I<xy>] [J<xz>] [K<yz>]". (Requires SKEW_CORRECTION_GCODE, and SKEW_CORRECTION_FOR_Z for IJ)
  243. * M860 - Report the position of position encoder modules.
  244. * M861 - Report the status of position encoder modules.
  245. * M862 - Perform an axis continuity test for position encoder modules.
  246. * M863 - Perform steps-per-mm calibration for position encoder modules.
  247. * M864 - Change position encoder module I2C address.
  248. * M865 - Check position encoder module firmware version.
  249. * M866 - Report or reset position encoder module error count.
  250. * M867 - Enable/disable or toggle error correction for position encoder modules.
  251. * M868 - Report or set position encoder module error correction threshold.
  252. * M869 - Report position encoder module error.
  253. * M871 - Print/reset/clear first layer temperature offset values. (Requires PROBE_TEMP_COMPENSATION)
  254. * M192 - Wait for probe temp (Requires PROBE_TEMP_COMPENSATION)
  255. * M876 - Handle Prompt Response. (Requires HOST_PROMPT_SUPPORT and not EMERGENCY_PARSER)
  256. * M900 - Get or Set Linear Advance K-factor. (Requires LIN_ADVANCE)
  257. * M906 - Set or get motor current in milliamps using axis codes X, Y, Z, E. Report values if no axis codes given. (Requires at least one _DRIVER_TYPE defined as TMC2130/2160/5130/5160/2208/2209/2660 or L6470)
  258. * M907 - Set digital trimpot motor current using axis codes. (Requires a board with digital trimpots)
  259. * M908 - Control digital trimpot directly. (Requires HAS_MOTOR_CURRENT_DAC or DIGIPOTSS_PIN)
  260. * M909 - Print digipot/DAC current value. (Requires HAS_MOTOR_CURRENT_DAC)
  261. * M910 - Commit digipot/DAC value to external EEPROM via I2C. (Requires HAS_MOTOR_CURRENT_DAC)
  262. * M911 - Report stepper driver overtemperature pre-warn condition. (Requires at least one _DRIVER_TYPE defined as TMC2130/2160/5130/5160/2208/2209/2660)
  263. * M912 - Clear stepper driver overtemperature pre-warn condition flag. (Requires at least one _DRIVER_TYPE defined as TMC2130/2160/5130/5160/2208/2209/2660)
  264. * M913 - Set HYBRID_THRESHOLD speed. (Requires HYBRID_THRESHOLD)
  265. * M914 - Set StallGuard sensitivity. (Requires SENSORLESS_HOMING or SENSORLESS_PROBING)
  266. * M916 - L6470 tuning: Increase KVAL_HOLD until thermal warning. (Requires at least one _DRIVER_TYPE L6470)
  267. * M917 - L6470 tuning: Find minimum current thresholds. (Requires at least one _DRIVER_TYPE L6470)
  268. * M918 - L6470 tuning: Increase speed until max or error. (Requires at least one _DRIVER_TYPE L6470)
  269. * M951 - Set Magnetic Parking Extruder parameters. (Requires MAGNETIC_PARKING_EXTRUDER)
  270. * M7219 - Control Max7219 Matrix LEDs. (Requires MAX7219_GCODE)
  271. *
  272. * M360 - SCARA calibration: Move to cal-position ThetaA (0 deg calibration)
  273. * M361 - SCARA calibration: Move to cal-position ThetaB (90 deg calibration - steps per degree)
  274. * M362 - SCARA calibration: Move to cal-position PsiA (0 deg calibration)
  275. * M363 - SCARA calibration: Move to cal-position PsiB (90 deg calibration - steps per degree)
  276. * M364 - SCARA calibration: Move to cal-position PSIC (90 deg to Theta calibration position)
  277. *
  278. * ************ Custom codes - This can change to suit future G-code regulations
  279. * G425 - Calibrate using a conductive object. (Requires CALIBRATION_GCODE)
  280. * M928 - Start SD logging: "M928 filename.gco". Stop with M29. (Requires SDSUPPORT)
  281. * M993 - Backup SPI Flash to SD
  282. * M994 - Load a Backup from SD to SPI Flash
  283. * M995 - Touch screen calibration for TFT display
  284. * M997 - Perform in-application firmware update
  285. * M999 - Restart after being stopped by error
  286. * D... - Custom Development G-code. Add hooks to 'gcode_D.cpp' for developers to test features. (Requires MARLIN_DEV_MODE)
  287. *
  288. * "T" Codes
  289. *
  290. * T0-T3 - Select an extruder (tool) by index: "T<n> F<units/min>"
  291. */
  292. #include "../inc/MarlinConfig.h"
  293. #include "parser.h"
  294. #if ENABLED(I2C_POSITION_ENCODERS)
  295. #include "../feature/encoder_i2c.h"
  296. #endif
  297. #if IS_SCARA || defined(G0_FEEDRATE)
  298. #define HAS_FAST_MOVES 1
  299. #endif
  300. enum AxisRelative : uint8_t { REL_X, REL_Y, REL_Z, REL_E, E_MODE_ABS, E_MODE_REL };
  301. class GcodeSuite {
  302. public:
  303. static uint8_t axis_relative;
  304. static inline bool axis_is_relative(const AxisEnum a) {
  305. if (a == E_AXIS) {
  306. if (TEST(axis_relative, E_MODE_REL)) return true;
  307. if (TEST(axis_relative, E_MODE_ABS)) return false;
  308. }
  309. return TEST(axis_relative, a);
  310. }
  311. static inline void set_relative_mode(const bool rel) {
  312. axis_relative = rel ? _BV(REL_X) | _BV(REL_Y) | _BV(REL_Z) | _BV(REL_E) : 0;
  313. }
  314. static inline void set_e_relative() {
  315. CBI(axis_relative, E_MODE_ABS);
  316. SBI(axis_relative, E_MODE_REL);
  317. }
  318. static inline void set_e_absolute() {
  319. CBI(axis_relative, E_MODE_REL);
  320. SBI(axis_relative, E_MODE_ABS);
  321. }
  322. #if ENABLED(CNC_WORKSPACE_PLANES)
  323. /**
  324. * Workspace planes only apply to G2/G3 moves
  325. * (and "canned cycles" - not a current feature)
  326. */
  327. enum WorkspacePlane : char { PLANE_XY, PLANE_ZX, PLANE_YZ };
  328. static WorkspacePlane workspace_plane;
  329. #endif
  330. #define MAX_COORDINATE_SYSTEMS 9
  331. #if ENABLED(CNC_COORDINATE_SYSTEMS)
  332. static int8_t active_coordinate_system;
  333. static xyz_pos_t coordinate_system[MAX_COORDINATE_SYSTEMS];
  334. static bool select_coordinate_system(const int8_t _new);
  335. #endif
  336. static millis_t previous_move_ms, max_inactive_time, stepper_inactive_time;
  337. FORCE_INLINE static void reset_stepper_timeout(const millis_t ms=millis()) { previous_move_ms = ms; }
  338. FORCE_INLINE static bool stepper_max_timed_out(const millis_t ms=millis()) {
  339. return max_inactive_time && ELAPSED(ms, previous_move_ms + max_inactive_time);
  340. }
  341. FORCE_INLINE static bool stepper_inactive_timeout(const millis_t ms=millis()) {
  342. return ELAPSED(ms, previous_move_ms + stepper_inactive_time);
  343. }
  344. static int8_t get_target_extruder_from_command();
  345. static int8_t get_target_e_stepper_from_command();
  346. static void get_destination_from_command();
  347. static void process_parsed_command(const bool no_ok=false);
  348. static void process_next_command();
  349. // Execute G-code in-place, preserving current G-code parameters
  350. static void process_subcommands_now_P(PGM_P pgcode);
  351. static void process_subcommands_now(char * gcode);
  352. static inline void home_all_axes() {
  353. extern const char G28_STR[];
  354. process_subcommands_now_P(G28_STR);
  355. }
  356. #if EITHER(HAS_AUTO_REPORTING, HOST_KEEPALIVE_FEATURE)
  357. static bool autoreport_paused;
  358. static inline bool set_autoreport_paused(const bool p) {
  359. const bool was = autoreport_paused;
  360. autoreport_paused = p;
  361. return was;
  362. }
  363. #else
  364. static constexpr bool autoreport_paused = false;
  365. static inline bool set_autoreport_paused(const bool) { return false; }
  366. #endif
  367. #if ENABLED(HOST_KEEPALIVE_FEATURE)
  368. /**
  369. * States for managing Marlin and host communication
  370. * Marlin sends messages if blocked or busy
  371. */
  372. enum MarlinBusyState : char {
  373. NOT_BUSY, // Not in a handler
  374. IN_HANDLER, // Processing a GCode
  375. IN_PROCESS, // Known to be blocking command input (as in G29)
  376. PAUSED_FOR_USER, // Blocking pending any input
  377. PAUSED_FOR_INPUT // Blocking pending text input (concept)
  378. };
  379. static MarlinBusyState busy_state;
  380. static uint8_t host_keepalive_interval;
  381. static void host_keepalive();
  382. #define KEEPALIVE_STATE(N) REMEMBER(_KA_, gcode.busy_state, gcode.N)
  383. #else
  384. #define KEEPALIVE_STATE(N) NOOP
  385. #endif
  386. static void dwell(millis_t time);
  387. private:
  388. TERN_(MARLIN_DEV_MODE, static void D(const int16_t dcode));
  389. static void G0_G1(TERN_(HAS_FAST_MOVES, const bool fast_move=false));
  390. TERN_(ARC_SUPPORT, static void G2_G3(const bool clockwise));
  391. static void G4();
  392. TERN_(BEZIER_CURVE_SUPPORT, static void G5());
  393. TERN_(DIRECT_STEPPING, static void G6());
  394. #if ENABLED(FWRETRACT)
  395. static void G10();
  396. static void G11();
  397. #endif
  398. TERN_(NOZZLE_CLEAN_FEATURE, static void G12());
  399. #if ENABLED(CNC_WORKSPACE_PLANES)
  400. static void G17();
  401. static void G18();
  402. static void G19();
  403. #endif
  404. #if ENABLED(INCH_MODE_SUPPORT)
  405. static void G20();
  406. static void G21();
  407. #endif
  408. TERN_(G26_MESH_VALIDATION, static void G26());
  409. TERN_(NOZZLE_PARK_FEATURE, static void G27());
  410. static void G28();
  411. #if HAS_LEVELING
  412. #if ENABLED(G29_RETRY_AND_RECOVER)
  413. static void G29_with_retry();
  414. #define G29_TYPE bool
  415. #else
  416. #define G29_TYPE void
  417. #endif
  418. static G29_TYPE G29();
  419. #endif
  420. #if HAS_BED_PROBE
  421. static void G30();
  422. #if ENABLED(Z_PROBE_SLED)
  423. static void G31();
  424. static void G32();
  425. #endif
  426. #endif
  427. TERN_(DELTA_AUTO_CALIBRATION, static void G33());
  428. #if EITHER(Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION)
  429. static void G34();
  430. #endif
  431. TERN_(Z_STEPPER_AUTO_ALIGN, static void M422());
  432. TERN_(ASSISTED_TRAMMING, static void G35());
  433. TERN_(G38_PROBE_TARGET, static void G38(const int8_t subcode));
  434. TERN_(HAS_MESH, static void G42());
  435. #if ENABLED(CNC_COORDINATE_SYSTEMS)
  436. static void G53();
  437. static void G54();
  438. static void G55();
  439. static void G56();
  440. static void G57();
  441. static void G58();
  442. static void G59();
  443. #endif
  444. TERN_(PROBE_TEMP_COMPENSATION, static void G76());
  445. #if SAVED_POSITIONS
  446. static void G60();
  447. static void G61();
  448. #endif
  449. TERN_(GCODE_MOTION_MODES, static void G80());
  450. static void G92();
  451. TERN_(CALIBRATION_GCODE, static void G425());
  452. TERN_(HAS_RESUME_CONTINUE, static void M0_M1());
  453. #if HAS_CUTTER
  454. static void M3_M4(const bool is_M4);
  455. static void M5();
  456. #endif
  457. #if ENABLED(COOLANT_CONTROL)
  458. TERN_(COOLANT_MIST, static void M7());
  459. TERN_(COOLANT_FLOOD, static void M8());
  460. static void M9();
  461. #endif
  462. TERN_(EXTERNAL_CLOSED_LOOP_CONTROLLER, static void M12());
  463. TERN_(EXPECTED_PRINTER_CHECK, static void M16());
  464. static void M17();
  465. static void M18_M84();
  466. #if ENABLED(SDSUPPORT)
  467. static void M20();
  468. static void M21();
  469. static void M22();
  470. static void M23();
  471. static void M24();
  472. static void M25();
  473. static void M26();
  474. static void M27();
  475. static void M28();
  476. static void M29();
  477. static void M30();
  478. #endif
  479. static void M31();
  480. #if ENABLED(SDSUPPORT)
  481. static void M32();
  482. TERN_(LONG_FILENAME_HOST_SUPPORT, static void M33());
  483. #if BOTH(SDCARD_SORT_ALPHA, SDSORT_GCODE)
  484. static void M34();
  485. #endif
  486. #endif
  487. TERN_(DIRECT_PIN_CONTROL, static void M42());
  488. TERN_(PINS_DEBUGGING, static void M43());
  489. TERN_(Z_MIN_PROBE_REPEATABILITY_TEST, static void M48());
  490. TERN_(LCD_SET_PROGRESS_MANUALLY, static void M73());
  491. static void M75();
  492. static void M76();
  493. static void M77();
  494. TERN_(PRINTCOUNTER, static void M78());
  495. TERN_(PSU_CONTROL, static void M80());
  496. static void M81();
  497. static void M82();
  498. static void M83();
  499. static void M85();
  500. static void M92();
  501. TERN_(M100_FREE_MEMORY_WATCHER, static void M100());
  502. #if EXTRUDERS
  503. static void M104();
  504. static void M109();
  505. #endif
  506. static void M105();
  507. #if HAS_FAN
  508. static void M106();
  509. static void M107();
  510. #endif
  511. #if DISABLED(EMERGENCY_PARSER)
  512. static void M108();
  513. static void M112();
  514. static void M410();
  515. TERN_(HOST_PROMPT_SUPPORT, static void M876());
  516. #endif
  517. static void M110();
  518. static void M111();
  519. TERN_(HOST_KEEPALIVE_FEATURE, static void M113());
  520. static void M114();
  521. static void M115();
  522. static void M117();
  523. static void M118();
  524. static void M119();
  525. static void M120();
  526. static void M121();
  527. TERN_(PARK_HEAD_ON_PAUSE, static void M125());
  528. #if ENABLED(BARICUDA)
  529. #if HAS_HEATER_1
  530. static void M126();
  531. static void M127();
  532. #endif
  533. #if HAS_HEATER_2
  534. static void M128();
  535. static void M129();
  536. #endif
  537. #endif
  538. #if HAS_HEATED_BED
  539. static void M140();
  540. static void M190();
  541. #endif
  542. #if HAS_HEATED_CHAMBER
  543. static void M141();
  544. static void M191();
  545. #endif
  546. #if PREHEAT_COUNT
  547. static void M145();
  548. #endif
  549. TERN_(TEMPERATURE_UNITS_SUPPORT, static void M149());
  550. TERN_(HAS_COLOR_LEDS, static void M150());
  551. #if BOTH(AUTO_REPORT_TEMPERATURES, HAS_TEMP_SENSOR)
  552. static void M155();
  553. #endif
  554. #if ENABLED(MIXING_EXTRUDER)
  555. static void M163();
  556. static void M164();
  557. TERN_(DIRECT_MIXING_IN_G1, static void M165());
  558. TERN_(GRADIENT_MIX, static void M166());
  559. #endif
  560. static void M200();
  561. static void M201();
  562. #if 0
  563. static void M202(); // Not used for Sprinter/grbl gen6
  564. #endif
  565. static void M203();
  566. static void M204();
  567. static void M205();
  568. TERN_(HAS_M206_COMMAND, static void M206());
  569. #if ENABLED(FWRETRACT)
  570. static void M207();
  571. static void M208();
  572. TERN_(FWRETRACT_AUTORETRACT, static void M209());
  573. #endif
  574. static void M211();
  575. TERN_(HAS_MULTI_EXTRUDER, static void M217());
  576. TERN_(HAS_HOTEND_OFFSET, static void M218());
  577. static void M220();
  578. #if EXTRUDERS
  579. static void M221();
  580. #endif
  581. TERN_(DIRECT_PIN_CONTROL, static void M226());
  582. TERN_(PHOTO_GCODE, static void M240());
  583. TERN_(HAS_LCD_CONTRAST, static void M250());
  584. #if ENABLED(EXPERIMENTAL_I2CBUS)
  585. static void M260();
  586. static void M261();
  587. #endif
  588. #if HAS_SERVOS
  589. static void M280();
  590. TERN_(EDITABLE_SERVO_ANGLES, static void M281());
  591. #endif
  592. TERN_(BABYSTEPPING, static void M290());
  593. TERN_(HAS_BUZZER, static void M300());
  594. TERN_(PIDTEMP, static void M301());
  595. TERN_(PREVENT_COLD_EXTRUSION, static void M302());
  596. TERN_(HAS_PID_HEATING, static void M303());
  597. TERN_(PIDTEMPBED, static void M304());
  598. TERN_(HAS_USER_THERMISTORS, static void M305());
  599. #if HAS_MICROSTEPS
  600. static void M350();
  601. static void M351();
  602. #endif
  603. TERN_(CASE_LIGHT_ENABLE, static void M355());
  604. TERN_(REPETIER_GCODE_M360, static void M360());
  605. #if ENABLED(MORGAN_SCARA)
  606. static bool M360();
  607. static bool M361();
  608. static bool M362();
  609. static bool M363();
  610. static bool M364();
  611. #endif
  612. #if EITHER(EXT_SOLENOID, MANUAL_SOLENOID_CONTROL)
  613. static void M380();
  614. static void M381();
  615. #endif
  616. static void M400();
  617. #if HAS_BED_PROBE
  618. static void M401();
  619. static void M402();
  620. #endif
  621. TERN_(PRUSA_MMU2, static void M403());
  622. #if ENABLED(FILAMENT_WIDTH_SENSOR)
  623. static void M404();
  624. static void M405();
  625. static void M406();
  626. static void M407();
  627. #endif
  628. TERN_(HAS_FILAMENT_SENSOR, static void M412());
  629. #if HAS_LEVELING
  630. static void M420();
  631. static void M421();
  632. #endif
  633. TERN_(BACKLASH_GCODE, static void M425());
  634. TERN_(HAS_M206_COMMAND, static void M428());
  635. TERN_(HAS_POWER_MONITOR, static void M430());
  636. TERN_(CANCEL_OBJECTS, static void M486());
  637. static void M500();
  638. static void M501();
  639. static void M502();
  640. #if DISABLED(DISABLE_M503)
  641. static void M503();
  642. #endif
  643. TERN_(EEPROM_SETTINGS, static void M504());
  644. #if ENABLED(PASSWORD_FEATURE)
  645. static void M510();
  646. #if ENABLED(PASSWORD_UNLOCK_GCODE)
  647. static void M511();
  648. #endif
  649. #if ENABLED(PASSWORD_CHANGE_GCODE)
  650. static void M512();
  651. #endif
  652. #endif
  653. TERN_(SDSUPPORT, static void M524());
  654. TERN_(SD_ABORT_ON_ENDSTOP_HIT, static void M540());
  655. TERN_(BAUD_RATE_GCODE, static void M575());
  656. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  657. static void M600();
  658. static void M603();
  659. #endif
  660. TERN_(HAS_DUPLICATION_MODE, static void M605());
  661. TERN_(IS_KINEMATIC, static void M665());
  662. #if ENABLED(DELTA) || HAS_EXTRA_ENDSTOPS
  663. static void M666();
  664. #endif
  665. #if ENABLED(DUET_SMART_EFFECTOR) && PIN_EXISTS(SMART_EFFECTOR_MOD)
  666. static void M672();
  667. #endif
  668. #if ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
  669. static void M701();
  670. static void M702();
  671. #endif
  672. TERN_(GCODE_MACROS, static void M810_819());
  673. TERN_(HAS_BED_PROBE, static void M851());
  674. TERN_(SKEW_CORRECTION_GCODE, static void M852());
  675. #if ENABLED(I2C_POSITION_ENCODERS)
  676. FORCE_INLINE static void M860() { I2CPEM.M860(); }
  677. FORCE_INLINE static void M861() { I2CPEM.M861(); }
  678. FORCE_INLINE static void M862() { I2CPEM.M862(); }
  679. FORCE_INLINE static void M863() { I2CPEM.M863(); }
  680. FORCE_INLINE static void M864() { I2CPEM.M864(); }
  681. FORCE_INLINE static void M865() { I2CPEM.M865(); }
  682. FORCE_INLINE static void M866() { I2CPEM.M866(); }
  683. FORCE_INLINE static void M867() { I2CPEM.M867(); }
  684. FORCE_INLINE static void M868() { I2CPEM.M868(); }
  685. FORCE_INLINE static void M869() { I2CPEM.M869(); }
  686. #endif
  687. #if ENABLED(PROBE_TEMP_COMPENSATION)
  688. static void M192();
  689. static void M871();
  690. #endif
  691. TERN_(LIN_ADVANCE, static void M900());
  692. #if HAS_TRINAMIC_CONFIG
  693. static void M122();
  694. static void M906();
  695. TERN_(HAS_STEALTHCHOP, static void M569());
  696. #if ENABLED(MONITOR_DRIVER_STATUS)
  697. static void M911();
  698. static void M912();
  699. #endif
  700. TERN_(HYBRID_THRESHOLD, static void M913());
  701. TERN_(USE_SENSORLESS, static void M914());
  702. #endif
  703. #if HAS_L64XX
  704. static void M122();
  705. static void M906();
  706. static void M916();
  707. static void M917();
  708. static void M918();
  709. #endif
  710. #if ANY(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_PWM, HAS_MOTOR_CURRENT_I2C, HAS_MOTOR_CURRENT_DAC)
  711. static void M907();
  712. #if EITHER(HAS_MOTOR_CURRENT_SPI, HAS_MOTOR_CURRENT_DAC)
  713. static void M908();
  714. #if ENABLED(HAS_MOTOR_CURRENT_DAC)
  715. static void M909();
  716. static void M910();
  717. #endif
  718. #endif
  719. #endif
  720. TERN_(SDSUPPORT, static void M928());
  721. TERN_(MAGNETIC_PARKING_EXTRUDER, static void M951());
  722. TERN_(TOUCH_SCREEN_CALIBRATION, static void M995());
  723. #if BOTH(HAS_SPI_FLASH, SDSUPPORT)
  724. static void M993();
  725. static void M994();
  726. #endif
  727. TERN_(PLATFORM_M997_SUPPORT, static void M997());
  728. static void M999();
  729. #if ENABLED(POWER_LOSS_RECOVERY)
  730. static void M413();
  731. static void M1000();
  732. #endif
  733. TERN_(SDSUPPORT, static void M1001());
  734. TERN_(MAX7219_GCODE, static void M7219());
  735. TERN_(CONTROLLER_FAN_EDITABLE, static void M710());
  736. static void T(const int8_t tool_index);
  737. };
  738. extern GcodeSuite gcode;