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.

settings.cpp 97KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414
  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. /**
  23. * settings.cpp
  24. *
  25. * Settings and EEPROM storage
  26. *
  27. * IMPORTANT: Whenever there are changes made to the variables stored in EEPROM
  28. * in the functions below, also increment the version number. This makes sure that
  29. * the default values are used whenever there is a change to the data, to prevent
  30. * wrong data being written to the variables.
  31. *
  32. * ALSO: Variables in the Store and Retrieve sections must be in the same order.
  33. * If a feature is disabled, some data must still be written that, when read,
  34. * either sets a Sane Default, or results in No Change to the existing value.
  35. */
  36. // Change EEPROM version if the structure changes
  37. #define EEPROM_VERSION "V86"
  38. #define EEPROM_OFFSET 100
  39. // Check the integrity of data offsets.
  40. // Can be disabled for production build.
  41. //#define DEBUG_EEPROM_READWRITE
  42. #include "settings.h"
  43. #include "endstops.h"
  44. #include "planner.h"
  45. #include "stepper.h"
  46. #include "temperature.h"
  47. #include "../lcd/marlinui.h"
  48. #include "../libs/vector_3.h" // for matrix_3x3
  49. #include "../gcode/gcode.h"
  50. #include "../MarlinCore.h"
  51. #if EITHER(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE)
  52. #include "../HAL/shared/eeprom_api.h"
  53. #endif
  54. #include "probe.h"
  55. #if HAS_LEVELING
  56. #include "../feature/bedlevel/bedlevel.h"
  57. #if ENABLED(X_AXIS_TWIST_COMPENSATION)
  58. #include "../feature/bedlevel/abl/x_twist.h"
  59. #endif
  60. #endif
  61. #if ENABLED(Z_STEPPER_AUTO_ALIGN)
  62. #include "../feature/z_stepper_align.h"
  63. #endif
  64. #if ENABLED(EXTENSIBLE_UI)
  65. #include "../lcd/extui/ui_api.h"
  66. #elif ENABLED(DWIN_CREALITY_LCD_ENHANCED)
  67. #include "../lcd/e3v2/enhanced/dwin.h"
  68. #elif ENABLED(DWIN_CREALITY_LCD_JYERSUI)
  69. #include "../lcd/e3v2/jyersui/dwin.h"
  70. #endif
  71. #if HAS_SERVOS
  72. #include "servo.h"
  73. #endif
  74. #if HAS_SERVOS && HAS_SERVO_ANGLES
  75. #define EEPROM_NUM_SERVOS NUM_SERVOS
  76. #else
  77. #define EEPROM_NUM_SERVOS NUM_SERVO_PLUGS
  78. #endif
  79. #include "../feature/fwretract.h"
  80. #if ENABLED(POWER_LOSS_RECOVERY)
  81. #include "../feature/powerloss.h"
  82. #endif
  83. #if HAS_POWER_MONITOR
  84. #include "../feature/power_monitor.h"
  85. #endif
  86. #include "../feature/pause.h"
  87. #if ENABLED(BACKLASH_COMPENSATION)
  88. #include "../feature/backlash.h"
  89. #endif
  90. #if HAS_FILAMENT_SENSOR
  91. #include "../feature/runout.h"
  92. #ifndef FIL_RUNOUT_ENABLED_DEFAULT
  93. #define FIL_RUNOUT_ENABLED_DEFAULT true
  94. #endif
  95. #endif
  96. #if ENABLED(EXTRA_LIN_ADVANCE_K)
  97. extern float other_extruder_advance_K[EXTRUDERS];
  98. #endif
  99. #if HAS_MULTI_EXTRUDER
  100. #include "tool_change.h"
  101. void M217_report(const bool eeprom);
  102. #endif
  103. #if ENABLED(BLTOUCH)
  104. #include "../feature/bltouch.h"
  105. #endif
  106. #if HAS_TRINAMIC_CONFIG
  107. #include "stepper/indirection.h"
  108. #include "../feature/tmc_util.h"
  109. #endif
  110. #if HAS_PTC
  111. #include "../feature/probe_temp_comp.h"
  112. #endif
  113. #include "../feature/controllerfan.h"
  114. #if ENABLED(CASE_LIGHT_ENABLE)
  115. #include "../feature/caselight.h"
  116. #endif
  117. #if ENABLED(PASSWORD_FEATURE)
  118. #include "../feature/password/password.h"
  119. #endif
  120. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  121. #include "../lcd/tft_io/touch_calibration.h"
  122. #endif
  123. #if HAS_ETHERNET
  124. #include "../feature/ethernet.h"
  125. #endif
  126. #if ENABLED(SOUND_MENU_ITEM)
  127. #include "../libs/buzzer.h"
  128. #endif
  129. #if HAS_FANCHECK
  130. #include "../feature/fancheck.h"
  131. #endif
  132. #if ENABLED(DGUS_LCD_UI_MKS)
  133. #include "../lcd/extui/dgus/DGUSScreenHandler.h"
  134. #include "../lcd/extui/dgus/DGUSDisplayDef.h"
  135. #endif
  136. #pragma pack(push, 1) // No padding between variables
  137. #if HAS_ETHERNET
  138. void ETH0_report();
  139. void MAC_report();
  140. #endif
  141. #define _EN_ITEM(N) , E##N
  142. typedef struct { uint16_t LINEAR_AXIS_LIST(X, Y, Z, I, J, K), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } tmc_stepper_current_t;
  143. typedef struct { uint32_t LINEAR_AXIS_LIST(X, Y, Z, I, J, K), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } tmc_hybrid_threshold_t;
  144. typedef struct { int16_t LINEAR_AXIS_LIST(X, Y, Z, I, J, K), X2, Y2, Z2, Z3, Z4; } tmc_sgt_t;
  145. typedef struct { bool LINEAR_AXIS_LIST(X, Y, Z, I, J, K), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } tmc_stealth_enabled_t;
  146. #undef _EN_ITEM
  147. // Limit an index to an array size
  148. #define ALIM(I,ARR) _MIN(I, (signed)COUNT(ARR) - 1)
  149. // Defaults for reset / fill in on load
  150. static const uint32_t _DMA[] PROGMEM = DEFAULT_MAX_ACCELERATION;
  151. static const float _DASU[] PROGMEM = DEFAULT_AXIS_STEPS_PER_UNIT;
  152. static const feedRate_t _DMF[] PROGMEM = DEFAULT_MAX_FEEDRATE;
  153. /**
  154. * Current EEPROM Layout
  155. *
  156. * Keep this data structure up to date so
  157. * EEPROM size is known at compile time!
  158. */
  159. typedef struct SettingsDataStruct {
  160. char version[4]; // Vnn\0
  161. #if ENABLED(EEPROM_INIT_NOW)
  162. uint32_t build_hash; // Unique build hash
  163. #endif
  164. uint16_t crc; // Data Checksum
  165. //
  166. // DISTINCT_E_FACTORS
  167. //
  168. uint8_t e_factors; // DISTINCT_AXES - LINEAR_AXES
  169. //
  170. // Planner settings
  171. //
  172. planner_settings_t planner_settings;
  173. xyze_float_t planner_max_jerk; // M205 XYZE planner.max_jerk
  174. float planner_junction_deviation_mm; // M205 J planner.junction_deviation_mm
  175. //
  176. // Home Offset
  177. //
  178. xyz_pos_t home_offset; // M206 XYZ / M665 TPZ
  179. //
  180. // Hotend Offset
  181. //
  182. #if HAS_HOTEND_OFFSET
  183. xyz_pos_t hotend_offset[HOTENDS - 1]; // M218 XYZ
  184. #endif
  185. //
  186. // FILAMENT_RUNOUT_SENSOR
  187. //
  188. bool runout_sensor_enabled; // M412 S
  189. float runout_distance_mm; // M412 D
  190. //
  191. // ENABLE_LEVELING_FADE_HEIGHT
  192. //
  193. float planner_z_fade_height; // M420 Zn planner.z_fade_height
  194. //
  195. // MESH_BED_LEVELING
  196. //
  197. float mbl_z_offset; // mbl.z_offset
  198. uint8_t mesh_num_x, mesh_num_y; // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y
  199. float mbl_z_values[TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3)] // mbl.z_values
  200. [TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_Y, 3)];
  201. //
  202. // HAS_BED_PROBE
  203. //
  204. xyz_pos_t probe_offset;
  205. //
  206. // ABL_PLANAR
  207. //
  208. matrix_3x3 planner_bed_level_matrix; // planner.bed_level_matrix
  209. //
  210. // AUTO_BED_LEVELING_BILINEAR
  211. //
  212. uint8_t grid_max_x, grid_max_y; // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y
  213. xy_pos_t bilinear_grid_spacing, bilinear_start; // G29 L F
  214. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  215. bed_mesh_t z_values; // G29
  216. #if ENABLED(X_AXIS_TWIST_COMPENSATION)
  217. XATC xatc; // TBD
  218. #endif
  219. #else
  220. float z_values[3][3];
  221. #endif
  222. //
  223. // AUTO_BED_LEVELING_UBL
  224. //
  225. bool planner_leveling_active; // M420 S planner.leveling_active
  226. int8_t ubl_storage_slot; // ubl.storage_slot
  227. //
  228. // SERVO_ANGLES
  229. //
  230. uint16_t servo_angles[EEPROM_NUM_SERVOS][2]; // M281 P L U
  231. //
  232. // Temperature first layer compensation values
  233. //
  234. #if HAS_PTC
  235. #if ENABLED(PTC_PROBE)
  236. int16_t z_offsets_probe[COUNT(ptc.z_offsets_probe)]; // M871 P I V
  237. #endif
  238. #if ENABLED(PTC_BED)
  239. int16_t z_offsets_bed[COUNT(ptc.z_offsets_bed)]; // M871 B I V
  240. #endif
  241. #if ENABLED(PTC_HOTEND)
  242. int16_t z_offsets_hotend[COUNT(ptc.z_offsets_hotend)]; // M871 E I V
  243. #endif
  244. #endif
  245. //
  246. // BLTOUCH
  247. //
  248. bool bltouch_last_written_mode;
  249. //
  250. // Kinematic Settings
  251. //
  252. #if IS_KINEMATIC
  253. float segments_per_second; // M665 S
  254. #if ENABLED(DELTA)
  255. float delta_height; // M666 H
  256. abc_float_t delta_endstop_adj; // M666 X Y Z
  257. float delta_radius, // M665 R
  258. delta_diagonal_rod; // M665 L
  259. abc_float_t delta_tower_angle_trim, // M665 X Y Z
  260. delta_diagonal_rod_trim; // M665 A B C
  261. #endif
  262. #endif
  263. //
  264. // Extra Endstops offsets
  265. //
  266. #if HAS_EXTRA_ENDSTOPS
  267. float x2_endstop_adj, // M666 X
  268. y2_endstop_adj, // M666 Y
  269. z2_endstop_adj, // M666 (S2) Z
  270. z3_endstop_adj, // M666 (S3) Z
  271. z4_endstop_adj; // M666 (S4) Z
  272. #endif
  273. //
  274. // Z_STEPPER_AUTO_ALIGN, Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS
  275. //
  276. #if ENABLED(Z_STEPPER_AUTO_ALIGN)
  277. xy_pos_t z_stepper_align_xy[NUM_Z_STEPPER_DRIVERS]; // M422 S X Y
  278. #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
  279. xy_pos_t z_stepper_align_stepper_xy[NUM_Z_STEPPER_DRIVERS]; // M422 W X Y
  280. #endif
  281. #endif
  282. //
  283. // Material Presets
  284. //
  285. #if HAS_PREHEAT
  286. preheat_t ui_material_preset[PREHEAT_COUNT]; // M145 S0 H B F
  287. #endif
  288. //
  289. // PIDTEMP
  290. //
  291. PIDCF_t hotendPID[HOTENDS]; // M301 En PIDCF / M303 En U
  292. int16_t lpq_len; // M301 L
  293. //
  294. // PIDTEMPBED
  295. //
  296. PID_t bedPID; // M304 PID / M303 E-1 U
  297. //
  298. // PIDTEMPCHAMBER
  299. //
  300. PID_t chamberPID; // M309 PID / M303 E-2 U
  301. //
  302. // User-defined Thermistors
  303. //
  304. #if HAS_USER_THERMISTORS
  305. user_thermistor_t user_thermistor[USER_THERMISTORS]; // M305 P0 R4700 T100000 B3950
  306. #endif
  307. //
  308. // Power monitor
  309. //
  310. uint8_t power_monitor_flags; // M430 I V W
  311. //
  312. // HAS_LCD_CONTRAST
  313. //
  314. uint8_t lcd_contrast; // M250 C
  315. //
  316. // HAS_LCD_BRIGHTNESS
  317. //
  318. uint8_t lcd_brightness; // M256 B
  319. //
  320. // Controller fan settings
  321. //
  322. controllerFan_settings_t controllerFan_settings; // M710
  323. //
  324. // POWER_LOSS_RECOVERY
  325. //
  326. bool recovery_enabled; // M413 S
  327. //
  328. // FWRETRACT
  329. //
  330. fwretract_settings_t fwretract_settings; // M207 S F Z W, M208 S F W R
  331. bool autoretract_enabled; // M209 S
  332. //
  333. // !NO_VOLUMETRIC
  334. //
  335. bool parser_volumetric_enabled; // M200 S parser.volumetric_enabled
  336. float planner_filament_size[EXTRUDERS]; // M200 T D planner.filament_size[]
  337. float planner_volumetric_extruder_limit[EXTRUDERS]; // M200 T L planner.volumetric_extruder_limit[]
  338. //
  339. // HAS_TRINAMIC_CONFIG
  340. //
  341. tmc_stepper_current_t tmc_stepper_current; // M906 X Y Z X2 Y2 Z2 Z3 Z4 E0 E1 E2 E3 E4 E5
  342. tmc_hybrid_threshold_t tmc_hybrid_threshold; // M913 X Y Z X2 Y2 Z2 Z3 Z4 E0 E1 E2 E3 E4 E5
  343. tmc_sgt_t tmc_sgt; // M914 X Y Z X2 Y2 Z2 Z3 Z4
  344. tmc_stealth_enabled_t tmc_stealth_enabled; // M569 X Y Z X2 Y2 Z2 Z3 Z4 E0 E1 E2 E3 E4 E5
  345. //
  346. // LIN_ADVANCE
  347. //
  348. float planner_extruder_advance_K[_MAX(EXTRUDERS, 1)]; // M900 K planner.extruder_advance_K
  349. //
  350. // HAS_MOTOR_CURRENT_PWM
  351. //
  352. #ifndef MOTOR_CURRENT_COUNT
  353. #define MOTOR_CURRENT_COUNT LINEAR_AXES
  354. #endif
  355. uint32_t motor_current_setting[MOTOR_CURRENT_COUNT]; // M907 X Z E ...
  356. //
  357. // CNC_COORDINATE_SYSTEMS
  358. //
  359. xyz_pos_t coordinate_system[MAX_COORDINATE_SYSTEMS]; // G54-G59.3
  360. //
  361. // SKEW_CORRECTION
  362. //
  363. skew_factor_t planner_skew_factor; // M852 I J K planner.skew_factor
  364. //
  365. // ADVANCED_PAUSE_FEATURE
  366. //
  367. #if HAS_EXTRUDERS
  368. fil_change_settings_t fc_settings[EXTRUDERS]; // M603 T U L
  369. #endif
  370. //
  371. // Tool-change settings
  372. //
  373. #if HAS_MULTI_EXTRUDER
  374. toolchange_settings_t toolchange_settings; // M217 S P R
  375. #endif
  376. //
  377. // BACKLASH_COMPENSATION
  378. //
  379. xyz_float_t backlash_distance_mm; // M425 X Y Z
  380. uint8_t backlash_correction; // M425 F
  381. float backlash_smoothing_mm; // M425 S
  382. //
  383. // EXTENSIBLE_UI
  384. //
  385. #if ENABLED(EXTENSIBLE_UI)
  386. uint8_t extui_data[ExtUI::eeprom_data_size];
  387. #endif
  388. //
  389. // Ender-3 V2 DWIN
  390. //
  391. #if ENABLED(DWIN_CREALITY_LCD_ENHANCED)
  392. uint8_t dwin_data[eeprom_data_size];
  393. #elif ENABLED(DWIN_CREALITY_LCD_JYERSUI)
  394. uint8_t dwin_settings[CrealityDWIN.eeprom_data_size];
  395. #endif
  396. //
  397. // CASELIGHT_USES_BRIGHTNESS
  398. //
  399. #if CASELIGHT_USES_BRIGHTNESS
  400. uint8_t caselight_brightness; // M355 P
  401. #endif
  402. //
  403. // PASSWORD_FEATURE
  404. //
  405. #if ENABLED(PASSWORD_FEATURE)
  406. bool password_is_set;
  407. uint32_t password_value;
  408. #endif
  409. //
  410. // TOUCH_SCREEN_CALIBRATION
  411. //
  412. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  413. touch_calibration_t touch_calibration_data;
  414. #endif
  415. // Ethernet settings
  416. #if HAS_ETHERNET
  417. bool ethernet_hardware_enabled; // M552 S
  418. uint32_t ethernet_ip, // M552 P
  419. ethernet_dns,
  420. ethernet_gateway, // M553 P
  421. ethernet_subnet; // M554 P
  422. #endif
  423. //
  424. // Buzzer enable/disable
  425. //
  426. #if ENABLED(SOUND_MENU_ITEM)
  427. bool buzzer_enabled;
  428. #endif
  429. //
  430. // Fan tachometer check
  431. //
  432. #if HAS_FANCHECK
  433. bool fan_check_enabled;
  434. #endif
  435. //
  436. // MKS UI controller
  437. //
  438. #if ENABLED(DGUS_LCD_UI_MKS)
  439. uint8_t mks_language_index; // Display Language
  440. xy_int_t mks_corner_offsets[5]; // Bed Tramming
  441. xyz_int_t mks_park_pos; // Custom Parking (without NOZZLE_PARK)
  442. celsius_t mks_min_extrusion_temp; // Min E Temp (shadow M302 value)
  443. #endif
  444. #if HAS_MULTI_LANGUAGE
  445. uint8_t ui_language; // M414 S
  446. #endif
  447. } SettingsData;
  448. //static_assert(sizeof(SettingsData) <= MARLIN_EEPROM_SIZE, "EEPROM too small to contain SettingsData!");
  449. MarlinSettings settings;
  450. uint16_t MarlinSettings::datasize() { return sizeof(SettingsData); }
  451. /**
  452. * Post-process after Retrieve or Reset
  453. */
  454. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  455. float new_z_fade_height;
  456. #endif
  457. void MarlinSettings::postprocess() {
  458. xyze_pos_t oldpos = current_position;
  459. // steps per s2 needs to be updated to agree with units per s2
  460. planner.reset_acceleration_rates();
  461. // Make sure delta kinematics are updated before refreshing the
  462. // planner position so the stepper counts will be set correctly.
  463. TERN_(DELTA, recalc_delta_settings());
  464. TERN_(PIDTEMP, thermalManager.updatePID());
  465. #if DISABLED(NO_VOLUMETRICS)
  466. planner.calculate_volumetric_multipliers();
  467. #elif EXTRUDERS
  468. for (uint8_t i = COUNT(planner.e_factor); i--;)
  469. planner.refresh_e_factor(i);
  470. #endif
  471. // Software endstops depend on home_offset
  472. LOOP_LINEAR_AXES(i) {
  473. update_workspace_offset((AxisEnum)i);
  474. update_software_endstops((AxisEnum)i);
  475. }
  476. TERN_(ENABLE_LEVELING_FADE_HEIGHT, set_z_fade_height(new_z_fade_height, false)); // false = no report
  477. TERN_(AUTO_BED_LEVELING_BILINEAR, refresh_bed_level());
  478. TERN_(HAS_MOTOR_CURRENT_PWM, stepper.refresh_motor_power());
  479. TERN_(FWRETRACT, fwretract.refresh_autoretract());
  480. TERN_(HAS_LINEAR_E_JERK, planner.recalculate_max_e_jerk());
  481. TERN_(CASELIGHT_USES_BRIGHTNESS, caselight.update_brightness());
  482. TERN_(EXTENSIBLE_UI, ExtUI::onPostprocessSettings());
  483. // Refresh mm_per_step with the reciprocal of axis_steps_per_mm
  484. // and init stepper.count[], planner.position[] with current_position
  485. planner.refresh_positioning();
  486. // Various factors can change the current position
  487. if (oldpos != current_position)
  488. report_current_position();
  489. }
  490. #if BOTH(PRINTCOUNTER, EEPROM_SETTINGS)
  491. #include "printcounter.h"
  492. static_assert(
  493. !WITHIN(STATS_EEPROM_ADDRESS, EEPROM_OFFSET, EEPROM_OFFSET + sizeof(SettingsData)) &&
  494. !WITHIN(STATS_EEPROM_ADDRESS + sizeof(printStatistics), EEPROM_OFFSET, EEPROM_OFFSET + sizeof(SettingsData)),
  495. "STATS_EEPROM_ADDRESS collides with EEPROM settings storage."
  496. );
  497. #endif
  498. #if ENABLED(SD_FIRMWARE_UPDATE)
  499. #if ENABLED(EEPROM_SETTINGS)
  500. static_assert(
  501. !WITHIN(SD_FIRMWARE_UPDATE_EEPROM_ADDR, EEPROM_OFFSET, EEPROM_OFFSET + sizeof(SettingsData)),
  502. "SD_FIRMWARE_UPDATE_EEPROM_ADDR collides with EEPROM settings storage."
  503. );
  504. #endif
  505. bool MarlinSettings::sd_update_status() {
  506. uint8_t val;
  507. persistentStore.read_data(SD_FIRMWARE_UPDATE_EEPROM_ADDR, &val);
  508. return (val == SD_FIRMWARE_UPDATE_ACTIVE_VALUE);
  509. }
  510. bool MarlinSettings::set_sd_update_status(const bool enable) {
  511. if (enable != sd_update_status())
  512. persistentStore.write_data(
  513. SD_FIRMWARE_UPDATE_EEPROM_ADDR,
  514. enable ? SD_FIRMWARE_UPDATE_ACTIVE_VALUE : SD_FIRMWARE_UPDATE_INACTIVE_VALUE
  515. );
  516. return true;
  517. }
  518. #endif // SD_FIRMWARE_UPDATE
  519. #ifdef ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE
  520. static_assert(EEPROM_OFFSET + sizeof(SettingsData) < ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE,
  521. "ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE is insufficient to capture all EEPROM data.");
  522. #endif
  523. //
  524. // This file simply uses the DEBUG_ECHO macros to implement EEPROM_CHITCHAT.
  525. // For deeper debugging of EEPROM issues enable DEBUG_EEPROM_READWRITE.
  526. //
  527. #define DEBUG_OUT EITHER(EEPROM_CHITCHAT, DEBUG_LEVELING_FEATURE)
  528. #include "../core/debug_out.h"
  529. #if ENABLED(EEPROM_SETTINGS)
  530. #define EEPROM_ASSERT(TST,ERR) do{ if (!(TST)) { SERIAL_ERROR_MSG(ERR); eeprom_error = true; } }while(0)
  531. #if ENABLED(DEBUG_EEPROM_READWRITE)
  532. #define _FIELD_TEST(FIELD) \
  533. EEPROM_ASSERT( \
  534. eeprom_error || eeprom_index == offsetof(SettingsData, FIELD) + EEPROM_OFFSET, \
  535. "Field " STRINGIFY(FIELD) " mismatch." \
  536. )
  537. #else
  538. #define _FIELD_TEST(FIELD) NOOP
  539. #endif
  540. const char version[4] = EEPROM_VERSION;
  541. #if ENABLED(EEPROM_INIT_NOW)
  542. constexpr uint32_t strhash32(const char *s, const uint32_t h=0) {
  543. return *s ? strhash32(s + 1, ((h + *s) << (*s & 3)) ^ *s) : h;
  544. }
  545. constexpr uint32_t build_hash = strhash32(__DATE__ __TIME__);
  546. #endif
  547. bool MarlinSettings::eeprom_error, MarlinSettings::validating;
  548. int MarlinSettings::eeprom_index;
  549. uint16_t MarlinSettings::working_crc;
  550. bool MarlinSettings::size_error(const uint16_t size) {
  551. if (size != datasize()) {
  552. DEBUG_ERROR_MSG("EEPROM datasize error."
  553. #if ENABLED(MARLIN_DEV_MODE)
  554. " (Actual:", size, " Expected:", datasize(), ")"
  555. #endif
  556. );
  557. return true;
  558. }
  559. return false;
  560. }
  561. /**
  562. * M500 - Store Configuration
  563. */
  564. bool MarlinSettings::save() {
  565. float dummyf = 0;
  566. char ver[4] = "ERR";
  567. if (!EEPROM_START(EEPROM_OFFSET)) return false;
  568. eeprom_error = false;
  569. // Write or Skip version. (Flash doesn't allow rewrite without erase.)
  570. TERN(FLASH_EEPROM_EMULATION, EEPROM_SKIP, EEPROM_WRITE)(ver);
  571. #if ENABLED(EEPROM_INIT_NOW)
  572. EEPROM_SKIP(build_hash); // Skip the hash slot
  573. #endif
  574. EEPROM_SKIP(working_crc); // Skip the checksum slot
  575. working_crc = 0; // clear before first "real data"
  576. const uint8_t e_factors = DISTINCT_AXES - (LINEAR_AXES);
  577. _FIELD_TEST(e_factors);
  578. EEPROM_WRITE(e_factors);
  579. //
  580. // Planner Motion
  581. //
  582. {
  583. EEPROM_WRITE(planner.settings);
  584. #if HAS_CLASSIC_JERK
  585. EEPROM_WRITE(planner.max_jerk);
  586. #if HAS_LINEAR_E_JERK
  587. dummyf = float(DEFAULT_EJERK);
  588. EEPROM_WRITE(dummyf);
  589. #endif
  590. #else
  591. const xyze_pos_t planner_max_jerk = LOGICAL_AXIS_ARRAY(float(DEFAULT_EJERK), 10, 10, 0.4, 0.4, 0.4, 0.4);
  592. EEPROM_WRITE(planner_max_jerk);
  593. #endif
  594. TERN_(CLASSIC_JERK, dummyf = 0.02f);
  595. EEPROM_WRITE(TERN(CLASSIC_JERK, dummyf, planner.junction_deviation_mm));
  596. }
  597. //
  598. // Home Offset
  599. //
  600. {
  601. _FIELD_TEST(home_offset);
  602. #if HAS_SCARA_OFFSET
  603. EEPROM_WRITE(scara_home_offset);
  604. #else
  605. #if !HAS_HOME_OFFSET
  606. const xyz_pos_t home_offset{0};
  607. #endif
  608. EEPROM_WRITE(home_offset);
  609. #endif
  610. }
  611. //
  612. // Hotend Offsets, if any
  613. //
  614. {
  615. #if HAS_HOTEND_OFFSET
  616. // Skip hotend 0 which must be 0
  617. LOOP_S_L_N(e, 1, HOTENDS)
  618. EEPROM_WRITE(hotend_offset[e]);
  619. #endif
  620. }
  621. //
  622. // Filament Runout Sensor
  623. //
  624. {
  625. #if HAS_FILAMENT_SENSOR
  626. const bool &runout_sensor_enabled = runout.enabled;
  627. #else
  628. constexpr int8_t runout_sensor_enabled = -1;
  629. #endif
  630. _FIELD_TEST(runout_sensor_enabled);
  631. EEPROM_WRITE(runout_sensor_enabled);
  632. #if HAS_FILAMENT_RUNOUT_DISTANCE
  633. const float &runout_distance_mm = runout.runout_distance();
  634. #else
  635. constexpr float runout_distance_mm = 0;
  636. #endif
  637. EEPROM_WRITE(runout_distance_mm);
  638. }
  639. //
  640. // Global Leveling
  641. //
  642. {
  643. const float zfh = TERN(ENABLE_LEVELING_FADE_HEIGHT, planner.z_fade_height, (DEFAULT_LEVELING_FADE_HEIGHT));
  644. EEPROM_WRITE(zfh);
  645. }
  646. //
  647. // Mesh Bed Leveling
  648. //
  649. {
  650. #if ENABLED(MESH_BED_LEVELING)
  651. static_assert(
  652. sizeof(mbl.z_values) == (GRID_MAX_POINTS) * sizeof(mbl.z_values[0][0]),
  653. "MBL Z array is the wrong size."
  654. );
  655. #else
  656. dummyf = 0;
  657. #endif
  658. const uint8_t mesh_num_x = TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3),
  659. mesh_num_y = TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_Y, 3);
  660. EEPROM_WRITE(TERN(MESH_BED_LEVELING, mbl.z_offset, dummyf));
  661. EEPROM_WRITE(mesh_num_x);
  662. EEPROM_WRITE(mesh_num_y);
  663. #if ENABLED(MESH_BED_LEVELING)
  664. EEPROM_WRITE(mbl.z_values);
  665. #else
  666. for (uint8_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_WRITE(dummyf);
  667. #endif
  668. }
  669. //
  670. // Probe XYZ Offsets
  671. //
  672. {
  673. _FIELD_TEST(probe_offset);
  674. #if HAS_BED_PROBE
  675. const xyz_pos_t &zpo = probe.offset;
  676. #else
  677. constexpr xyz_pos_t zpo{0};
  678. #endif
  679. EEPROM_WRITE(zpo);
  680. }
  681. //
  682. // Planar Bed Leveling matrix
  683. //
  684. {
  685. #if ABL_PLANAR
  686. EEPROM_WRITE(planner.bed_level_matrix);
  687. #else
  688. dummyf = 0;
  689. for (uint8_t q = 9; q--;) EEPROM_WRITE(dummyf);
  690. #endif
  691. }
  692. //
  693. // Bilinear Auto Bed Leveling
  694. //
  695. {
  696. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  697. static_assert(
  698. sizeof(z_values) == (GRID_MAX_POINTS) * sizeof(z_values[0][0]),
  699. "Bilinear Z array is the wrong size."
  700. );
  701. #if ENABLED(X_AXIS_TWIST_COMPENSATION)
  702. static_assert(
  703. sizeof(xatc.z_values) == (XATC_MAX_POINTS) * sizeof(xatc.z_values[0]),
  704. "Z-offset mesh is the wrong size."
  705. );
  706. #endif
  707. #else
  708. const xy_pos_t bilinear_start{0}, bilinear_grid_spacing{0};
  709. #endif
  710. const uint8_t grid_max_x = TERN(AUTO_BED_LEVELING_BILINEAR, GRID_MAX_POINTS_X, 3),
  711. grid_max_y = TERN(AUTO_BED_LEVELING_BILINEAR, GRID_MAX_POINTS_Y, 3);
  712. EEPROM_WRITE(grid_max_x);
  713. EEPROM_WRITE(grid_max_y);
  714. EEPROM_WRITE(bilinear_grid_spacing);
  715. EEPROM_WRITE(bilinear_start);
  716. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  717. EEPROM_WRITE(z_values); // 9-256 floats
  718. #if ENABLED(X_AXIS_TWIST_COMPENSATION)
  719. EEPROM_WRITE(xatc);
  720. #endif
  721. #else
  722. dummyf = 0;
  723. for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummyf);
  724. #endif
  725. }
  726. //
  727. // Unified Bed Leveling
  728. //
  729. {
  730. _FIELD_TEST(planner_leveling_active);
  731. const bool ubl_active = TERN(AUTO_BED_LEVELING_UBL, planner.leveling_active, false);
  732. const int8_t storage_slot = TERN(AUTO_BED_LEVELING_UBL, ubl.storage_slot, -1);
  733. EEPROM_WRITE(ubl_active);
  734. EEPROM_WRITE(storage_slot);
  735. }
  736. //
  737. // Servo Angles
  738. //
  739. {
  740. _FIELD_TEST(servo_angles);
  741. #if !HAS_SERVO_ANGLES
  742. uint16_t servo_angles[EEPROM_NUM_SERVOS][2] = { { 0, 0 } };
  743. #endif
  744. EEPROM_WRITE(servo_angles);
  745. }
  746. //
  747. // Thermal first layer compensation values
  748. //
  749. #if HAS_PTC
  750. #if ENABLED(PTC_PROBE)
  751. EEPROM_WRITE(ptc.z_offsets_probe);
  752. #endif
  753. #if ENABLED(PTC_BED)
  754. EEPROM_WRITE(ptc.z_offsets_bed);
  755. #endif
  756. #if ENABLED(PTC_HOTEND)
  757. EEPROM_WRITE(ptc.z_offsets_hotend);
  758. #endif
  759. #else
  760. // No placeholder data for this feature
  761. #endif
  762. //
  763. // BLTOUCH
  764. //
  765. {
  766. _FIELD_TEST(bltouch_last_written_mode);
  767. const bool bltouch_last_written_mode = TERN(BLTOUCH, bltouch.last_written_mode, false);
  768. EEPROM_WRITE(bltouch_last_written_mode);
  769. }
  770. //
  771. // Kinematic Settings
  772. //
  773. #if IS_KINEMATIC
  774. {
  775. EEPROM_WRITE(segments_per_second);
  776. #if ENABLED(DELTA)
  777. _FIELD_TEST(delta_height);
  778. EEPROM_WRITE(delta_height); // 1 float
  779. EEPROM_WRITE(delta_endstop_adj); // 3 floats
  780. EEPROM_WRITE(delta_radius); // 1 float
  781. EEPROM_WRITE(delta_diagonal_rod); // 1 float
  782. EEPROM_WRITE(delta_tower_angle_trim); // 3 floats
  783. EEPROM_WRITE(delta_diagonal_rod_trim); // 3 floats
  784. #endif
  785. }
  786. #endif
  787. //
  788. // Extra Endstops offsets
  789. //
  790. #if HAS_EXTRA_ENDSTOPS
  791. {
  792. _FIELD_TEST(x2_endstop_adj);
  793. // Write dual endstops in X, Y, Z order. Unused = 0.0
  794. dummyf = 0;
  795. EEPROM_WRITE(TERN(X_DUAL_ENDSTOPS, endstops.x2_endstop_adj, dummyf)); // 1 float
  796. EEPROM_WRITE(TERN(Y_DUAL_ENDSTOPS, endstops.y2_endstop_adj, dummyf)); // 1 float
  797. EEPROM_WRITE(TERN(Z_MULTI_ENDSTOPS, endstops.z2_endstop_adj, dummyf)); // 1 float
  798. #if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 3
  799. EEPROM_WRITE(endstops.z3_endstop_adj); // 1 float
  800. #else
  801. EEPROM_WRITE(dummyf);
  802. #endif
  803. #if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 4
  804. EEPROM_WRITE(endstops.z4_endstop_adj); // 1 float
  805. #else
  806. EEPROM_WRITE(dummyf);
  807. #endif
  808. }
  809. #endif
  810. #if ENABLED(Z_STEPPER_AUTO_ALIGN)
  811. EEPROM_WRITE(z_stepper_align.xy);
  812. #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
  813. EEPROM_WRITE(z_stepper_align.stepper_xy);
  814. #endif
  815. #endif
  816. //
  817. // LCD Preheat settings
  818. //
  819. #if HAS_PREHEAT
  820. _FIELD_TEST(ui_material_preset);
  821. EEPROM_WRITE(ui.material_preset);
  822. #endif
  823. //
  824. // PIDTEMP
  825. //
  826. {
  827. _FIELD_TEST(hotendPID);
  828. HOTEND_LOOP() {
  829. PIDCF_t pidcf = {
  830. #if DISABLED(PIDTEMP)
  831. NAN, NAN, NAN,
  832. NAN, NAN
  833. #else
  834. PID_PARAM(Kp, e),
  835. unscalePID_i(PID_PARAM(Ki, e)),
  836. unscalePID_d(PID_PARAM(Kd, e)),
  837. PID_PARAM(Kc, e),
  838. PID_PARAM(Kf, e)
  839. #endif
  840. };
  841. EEPROM_WRITE(pidcf);
  842. }
  843. _FIELD_TEST(lpq_len);
  844. #if DISABLED(PID_EXTRUSION_SCALING)
  845. const int16_t lpq_len = 20;
  846. #endif
  847. EEPROM_WRITE(TERN(PID_EXTRUSION_SCALING, thermalManager.lpq_len, lpq_len));
  848. }
  849. //
  850. // PIDTEMPBED
  851. //
  852. {
  853. _FIELD_TEST(bedPID);
  854. const PID_t bed_pid = {
  855. #if DISABLED(PIDTEMPBED)
  856. NAN, NAN, NAN
  857. #else
  858. // Store the unscaled PID values
  859. thermalManager.temp_bed.pid.Kp,
  860. unscalePID_i(thermalManager.temp_bed.pid.Ki),
  861. unscalePID_d(thermalManager.temp_bed.pid.Kd)
  862. #endif
  863. };
  864. EEPROM_WRITE(bed_pid);
  865. }
  866. //
  867. // PIDTEMPCHAMBER
  868. //
  869. {
  870. _FIELD_TEST(chamberPID);
  871. const PID_t chamber_pid = {
  872. #if DISABLED(PIDTEMPCHAMBER)
  873. NAN, NAN, NAN
  874. #else
  875. // Store the unscaled PID values
  876. thermalManager.temp_chamber.pid.Kp,
  877. unscalePID_i(thermalManager.temp_chamber.pid.Ki),
  878. unscalePID_d(thermalManager.temp_chamber.pid.Kd)
  879. #endif
  880. };
  881. EEPROM_WRITE(chamber_pid);
  882. }
  883. //
  884. // User-defined Thermistors
  885. //
  886. #if HAS_USER_THERMISTORS
  887. {
  888. _FIELD_TEST(user_thermistor);
  889. EEPROM_WRITE(thermalManager.user_thermistor);
  890. }
  891. #endif
  892. //
  893. // Power monitor
  894. //
  895. {
  896. #if HAS_POWER_MONITOR
  897. const uint8_t &power_monitor_flags = power_monitor.flags;
  898. #else
  899. constexpr uint8_t power_monitor_flags = 0x00;
  900. #endif
  901. _FIELD_TEST(power_monitor_flags);
  902. EEPROM_WRITE(power_monitor_flags);
  903. }
  904. //
  905. // LCD Contrast
  906. //
  907. {
  908. _FIELD_TEST(lcd_contrast);
  909. const uint8_t lcd_contrast = TERN(HAS_LCD_CONTRAST, ui.contrast, 127);
  910. EEPROM_WRITE(lcd_contrast);
  911. }
  912. //
  913. // LCD Brightness
  914. //
  915. {
  916. _FIELD_TEST(lcd_brightness);
  917. const uint8_t lcd_brightness = TERN(HAS_LCD_BRIGHTNESS, ui.brightness, 255);
  918. EEPROM_WRITE(lcd_brightness);
  919. }
  920. //
  921. // Controller Fan
  922. //
  923. {
  924. _FIELD_TEST(controllerFan_settings);
  925. #if ENABLED(USE_CONTROLLER_FAN)
  926. const controllerFan_settings_t &cfs = controllerFan.settings;
  927. #else
  928. controllerFan_settings_t cfs = controllerFan_defaults;
  929. #endif
  930. EEPROM_WRITE(cfs);
  931. }
  932. //
  933. // Power-Loss Recovery
  934. //
  935. {
  936. _FIELD_TEST(recovery_enabled);
  937. const bool recovery_enabled = TERN(POWER_LOSS_RECOVERY, recovery.enabled, ENABLED(PLR_ENABLED_DEFAULT));
  938. EEPROM_WRITE(recovery_enabled);
  939. }
  940. //
  941. // Firmware Retraction
  942. //
  943. {
  944. _FIELD_TEST(fwretract_settings);
  945. #if DISABLED(FWRETRACT)
  946. const fwretract_settings_t autoretract_defaults = { 3, 45, 0, 0, 0, 13, 0, 8 };
  947. #endif
  948. EEPROM_WRITE(TERN(FWRETRACT, fwretract.settings, autoretract_defaults));
  949. #if DISABLED(FWRETRACT_AUTORETRACT)
  950. const bool autoretract_enabled = false;
  951. #endif
  952. EEPROM_WRITE(TERN(FWRETRACT_AUTORETRACT, fwretract.autoretract_enabled, autoretract_enabled));
  953. }
  954. //
  955. // Volumetric & Filament Size
  956. //
  957. {
  958. _FIELD_TEST(parser_volumetric_enabled);
  959. #if DISABLED(NO_VOLUMETRICS)
  960. EEPROM_WRITE(parser.volumetric_enabled);
  961. EEPROM_WRITE(planner.filament_size);
  962. #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
  963. EEPROM_WRITE(planner.volumetric_extruder_limit);
  964. #else
  965. dummyf = DEFAULT_VOLUMETRIC_EXTRUDER_LIMIT;
  966. for (uint8_t q = EXTRUDERS; q--;) EEPROM_WRITE(dummyf);
  967. #endif
  968. #else
  969. const bool volumetric_enabled = false;
  970. EEPROM_WRITE(volumetric_enabled);
  971. dummyf = DEFAULT_NOMINAL_FILAMENT_DIA;
  972. for (uint8_t q = EXTRUDERS; q--;) EEPROM_WRITE(dummyf);
  973. dummyf = DEFAULT_VOLUMETRIC_EXTRUDER_LIMIT;
  974. for (uint8_t q = EXTRUDERS; q--;) EEPROM_WRITE(dummyf);
  975. #endif
  976. }
  977. //
  978. // TMC Configuration
  979. //
  980. {
  981. _FIELD_TEST(tmc_stepper_current);
  982. tmc_stepper_current_t tmc_stepper_current{0};
  983. #if HAS_TRINAMIC_CONFIG
  984. #if AXIS_IS_TMC(X)
  985. tmc_stepper_current.X = stepperX.getMilliamps();
  986. #endif
  987. #if AXIS_IS_TMC(Y)
  988. tmc_stepper_current.Y = stepperY.getMilliamps();
  989. #endif
  990. #if AXIS_IS_TMC(Z)
  991. tmc_stepper_current.Z = stepperZ.getMilliamps();
  992. #endif
  993. #if AXIS_IS_TMC(I)
  994. tmc_stepper_current.I = stepperI.getMilliamps();
  995. #endif
  996. #if AXIS_IS_TMC(J)
  997. tmc_stepper_current.J = stepperJ.getMilliamps();
  998. #endif
  999. #if AXIS_IS_TMC(K)
  1000. tmc_stepper_current.K = stepperK.getMilliamps();
  1001. #endif
  1002. #if AXIS_IS_TMC(X2)
  1003. tmc_stepper_current.X2 = stepperX2.getMilliamps();
  1004. #endif
  1005. #if AXIS_IS_TMC(Y2)
  1006. tmc_stepper_current.Y2 = stepperY2.getMilliamps();
  1007. #endif
  1008. #if AXIS_IS_TMC(Z2)
  1009. tmc_stepper_current.Z2 = stepperZ2.getMilliamps();
  1010. #endif
  1011. #if AXIS_IS_TMC(Z3)
  1012. tmc_stepper_current.Z3 = stepperZ3.getMilliamps();
  1013. #endif
  1014. #if AXIS_IS_TMC(Z4)
  1015. tmc_stepper_current.Z4 = stepperZ4.getMilliamps();
  1016. #endif
  1017. #if AXIS_IS_TMC(E0)
  1018. tmc_stepper_current.E0 = stepperE0.getMilliamps();
  1019. #endif
  1020. #if AXIS_IS_TMC(E1)
  1021. tmc_stepper_current.E1 = stepperE1.getMilliamps();
  1022. #endif
  1023. #if AXIS_IS_TMC(E2)
  1024. tmc_stepper_current.E2 = stepperE2.getMilliamps();
  1025. #endif
  1026. #if AXIS_IS_TMC(E3)
  1027. tmc_stepper_current.E3 = stepperE3.getMilliamps();
  1028. #endif
  1029. #if AXIS_IS_TMC(E4)
  1030. tmc_stepper_current.E4 = stepperE4.getMilliamps();
  1031. #endif
  1032. #if AXIS_IS_TMC(E5)
  1033. tmc_stepper_current.E5 = stepperE5.getMilliamps();
  1034. #endif
  1035. #if AXIS_IS_TMC(E6)
  1036. tmc_stepper_current.E6 = stepperE6.getMilliamps();
  1037. #endif
  1038. #if AXIS_IS_TMC(E7)
  1039. tmc_stepper_current.E7 = stepperE7.getMilliamps();
  1040. #endif
  1041. #endif
  1042. EEPROM_WRITE(tmc_stepper_current);
  1043. }
  1044. //
  1045. // TMC Hybrid Threshold, and placeholder values
  1046. //
  1047. {
  1048. _FIELD_TEST(tmc_hybrid_threshold);
  1049. #if ENABLED(HYBRID_THRESHOLD)
  1050. tmc_hybrid_threshold_t tmc_hybrid_threshold{0};
  1051. TERN_(X_HAS_STEALTHCHOP, tmc_hybrid_threshold.X = stepperX.get_pwm_thrs());
  1052. TERN_(Y_HAS_STEALTHCHOP, tmc_hybrid_threshold.Y = stepperY.get_pwm_thrs());
  1053. TERN_(Z_HAS_STEALTHCHOP, tmc_hybrid_threshold.Z = stepperZ.get_pwm_thrs());
  1054. TERN_(I_HAS_STEALTHCHOP, tmc_hybrid_threshold.I = stepperI.get_pwm_thrs());
  1055. TERN_(J_HAS_STEALTHCHOP, tmc_hybrid_threshold.J = stepperJ.get_pwm_thrs());
  1056. TERN_(K_HAS_STEALTHCHOP, tmc_hybrid_threshold.K = stepperK.get_pwm_thrs());
  1057. TERN_(X2_HAS_STEALTHCHOP, tmc_hybrid_threshold.X2 = stepperX2.get_pwm_thrs());
  1058. TERN_(Y2_HAS_STEALTHCHOP, tmc_hybrid_threshold.Y2 = stepperY2.get_pwm_thrs());
  1059. TERN_(Z2_HAS_STEALTHCHOP, tmc_hybrid_threshold.Z2 = stepperZ2.get_pwm_thrs());
  1060. TERN_(Z3_HAS_STEALTHCHOP, tmc_hybrid_threshold.Z3 = stepperZ3.get_pwm_thrs());
  1061. TERN_(Z4_HAS_STEALTHCHOP, tmc_hybrid_threshold.Z4 = stepperZ4.get_pwm_thrs());
  1062. TERN_(E0_HAS_STEALTHCHOP, tmc_hybrid_threshold.E0 = stepperE0.get_pwm_thrs());
  1063. TERN_(E1_HAS_STEALTHCHOP, tmc_hybrid_threshold.E1 = stepperE1.get_pwm_thrs());
  1064. TERN_(E2_HAS_STEALTHCHOP, tmc_hybrid_threshold.E2 = stepperE2.get_pwm_thrs());
  1065. TERN_(E3_HAS_STEALTHCHOP, tmc_hybrid_threshold.E3 = stepperE3.get_pwm_thrs());
  1066. TERN_(E4_HAS_STEALTHCHOP, tmc_hybrid_threshold.E4 = stepperE4.get_pwm_thrs());
  1067. TERN_(E5_HAS_STEALTHCHOP, tmc_hybrid_threshold.E5 = stepperE5.get_pwm_thrs());
  1068. TERN_(E6_HAS_STEALTHCHOP, tmc_hybrid_threshold.E6 = stepperE6.get_pwm_thrs());
  1069. TERN_(E7_HAS_STEALTHCHOP, tmc_hybrid_threshold.E7 = stepperE7.get_pwm_thrs());
  1070. #else
  1071. #define _EN_ITEM(N) , .E##N = 30
  1072. const tmc_hybrid_threshold_t tmc_hybrid_threshold = {
  1073. LINEAR_AXIS_LIST(.X = 100, .Y = 100, .Z = 3, .I = 3, .J = 3, .K = 3),
  1074. .X2 = 100, .Y2 = 100, .Z2 = 3, .Z3 = 3, .Z4 = 3
  1075. REPEAT(E_STEPPERS, _EN_ITEM)
  1076. };
  1077. #undef _EN_ITEM
  1078. #endif
  1079. EEPROM_WRITE(tmc_hybrid_threshold);
  1080. }
  1081. //
  1082. // TMC StallGuard threshold
  1083. //
  1084. {
  1085. tmc_sgt_t tmc_sgt{0};
  1086. #if USE_SENSORLESS
  1087. LINEAR_AXIS_CODE(
  1088. TERN_(X_SENSORLESS, tmc_sgt.X = stepperX.homing_threshold()),
  1089. TERN_(Y_SENSORLESS, tmc_sgt.Y = stepperY.homing_threshold()),
  1090. TERN_(Z_SENSORLESS, tmc_sgt.Z = stepperZ.homing_threshold()),
  1091. TERN_(I_SENSORLESS, tmc_sgt.I = stepperI.homing_threshold()),
  1092. TERN_(J_SENSORLESS, tmc_sgt.J = stepperJ.homing_threshold()),
  1093. TERN_(K_SENSORLESS, tmc_sgt.K = stepperK.homing_threshold())
  1094. );
  1095. TERN_(X2_SENSORLESS, tmc_sgt.X2 = stepperX2.homing_threshold());
  1096. TERN_(Y2_SENSORLESS, tmc_sgt.Y2 = stepperY2.homing_threshold());
  1097. TERN_(Z2_SENSORLESS, tmc_sgt.Z2 = stepperZ2.homing_threshold());
  1098. TERN_(Z3_SENSORLESS, tmc_sgt.Z3 = stepperZ3.homing_threshold());
  1099. TERN_(Z4_SENSORLESS, tmc_sgt.Z4 = stepperZ4.homing_threshold());
  1100. #endif
  1101. EEPROM_WRITE(tmc_sgt);
  1102. }
  1103. //
  1104. // TMC stepping mode
  1105. //
  1106. {
  1107. _FIELD_TEST(tmc_stealth_enabled);
  1108. tmc_stealth_enabled_t tmc_stealth_enabled = { false };
  1109. TERN_(X_HAS_STEALTHCHOP, tmc_stealth_enabled.X = stepperX.get_stored_stealthChop());
  1110. TERN_(Y_HAS_STEALTHCHOP, tmc_stealth_enabled.Y = stepperY.get_stored_stealthChop());
  1111. TERN_(Z_HAS_STEALTHCHOP, tmc_stealth_enabled.Z = stepperZ.get_stored_stealthChop());
  1112. TERN_(I_HAS_STEALTHCHOP, tmc_stealth_enabled.I = stepperI.get_stored_stealthChop());
  1113. TERN_(J_HAS_STEALTHCHOP, tmc_stealth_enabled.J = stepperJ.get_stored_stealthChop());
  1114. TERN_(K_HAS_STEALTHCHOP, tmc_stealth_enabled.K = stepperK.get_stored_stealthChop());
  1115. TERN_(X2_HAS_STEALTHCHOP, tmc_stealth_enabled.X2 = stepperX2.get_stored_stealthChop());
  1116. TERN_(Y2_HAS_STEALTHCHOP, tmc_stealth_enabled.Y2 = stepperY2.get_stored_stealthChop());
  1117. TERN_(Z2_HAS_STEALTHCHOP, tmc_stealth_enabled.Z2 = stepperZ2.get_stored_stealthChop());
  1118. TERN_(Z3_HAS_STEALTHCHOP, tmc_stealth_enabled.Z3 = stepperZ3.get_stored_stealthChop());
  1119. TERN_(Z4_HAS_STEALTHCHOP, tmc_stealth_enabled.Z4 = stepperZ4.get_stored_stealthChop());
  1120. TERN_(E0_HAS_STEALTHCHOP, tmc_stealth_enabled.E0 = stepperE0.get_stored_stealthChop());
  1121. TERN_(E1_HAS_STEALTHCHOP, tmc_stealth_enabled.E1 = stepperE1.get_stored_stealthChop());
  1122. TERN_(E2_HAS_STEALTHCHOP, tmc_stealth_enabled.E2 = stepperE2.get_stored_stealthChop());
  1123. TERN_(E3_HAS_STEALTHCHOP, tmc_stealth_enabled.E3 = stepperE3.get_stored_stealthChop());
  1124. TERN_(E4_HAS_STEALTHCHOP, tmc_stealth_enabled.E4 = stepperE4.get_stored_stealthChop());
  1125. TERN_(E5_HAS_STEALTHCHOP, tmc_stealth_enabled.E5 = stepperE5.get_stored_stealthChop());
  1126. TERN_(E6_HAS_STEALTHCHOP, tmc_stealth_enabled.E6 = stepperE6.get_stored_stealthChop());
  1127. TERN_(E7_HAS_STEALTHCHOP, tmc_stealth_enabled.E7 = stepperE7.get_stored_stealthChop());
  1128. EEPROM_WRITE(tmc_stealth_enabled);
  1129. }
  1130. //
  1131. // Linear Advance
  1132. //
  1133. {
  1134. _FIELD_TEST(planner_extruder_advance_K);
  1135. #if ENABLED(LIN_ADVANCE)
  1136. EEPROM_WRITE(planner.extruder_advance_K);
  1137. #else
  1138. dummyf = 0;
  1139. for (uint8_t q = _MAX(EXTRUDERS, 1); q--;) EEPROM_WRITE(dummyf);
  1140. #endif
  1141. }
  1142. //
  1143. // Motor Current PWM
  1144. //
  1145. {
  1146. _FIELD_TEST(motor_current_setting);
  1147. #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM
  1148. EEPROM_WRITE(stepper.motor_current_setting);
  1149. #else
  1150. const uint32_t no_current[MOTOR_CURRENT_COUNT] = { 0 };
  1151. EEPROM_WRITE(no_current);
  1152. #endif
  1153. }
  1154. //
  1155. // CNC Coordinate Systems
  1156. //
  1157. _FIELD_TEST(coordinate_system);
  1158. #if DISABLED(CNC_COORDINATE_SYSTEMS)
  1159. const xyz_pos_t coordinate_system[MAX_COORDINATE_SYSTEMS] = { { 0 } };
  1160. #endif
  1161. EEPROM_WRITE(TERN(CNC_COORDINATE_SYSTEMS, gcode.coordinate_system, coordinate_system));
  1162. //
  1163. // Skew correction factors
  1164. //
  1165. _FIELD_TEST(planner_skew_factor);
  1166. EEPROM_WRITE(planner.skew_factor);
  1167. //
  1168. // Advanced Pause filament load & unload lengths
  1169. //
  1170. #if HAS_EXTRUDERS
  1171. {
  1172. #if DISABLED(ADVANCED_PAUSE_FEATURE)
  1173. const fil_change_settings_t fc_settings[EXTRUDERS] = { 0, 0 };
  1174. #endif
  1175. _FIELD_TEST(fc_settings);
  1176. EEPROM_WRITE(fc_settings);
  1177. }
  1178. #endif
  1179. //
  1180. // Multiple Extruders
  1181. //
  1182. #if HAS_MULTI_EXTRUDER
  1183. _FIELD_TEST(toolchange_settings);
  1184. EEPROM_WRITE(toolchange_settings);
  1185. #endif
  1186. //
  1187. // Backlash Compensation
  1188. //
  1189. {
  1190. #if ENABLED(BACKLASH_GCODE)
  1191. const xyz_float_t &backlash_distance_mm = backlash.distance_mm;
  1192. const uint8_t &backlash_correction = backlash.correction;
  1193. #else
  1194. const xyz_float_t backlash_distance_mm{0};
  1195. const uint8_t backlash_correction = 0;
  1196. #endif
  1197. #if ENABLED(BACKLASH_GCODE) && defined(BACKLASH_SMOOTHING_MM)
  1198. const float &backlash_smoothing_mm = backlash.smoothing_mm;
  1199. #else
  1200. const float backlash_smoothing_mm = 3;
  1201. #endif
  1202. _FIELD_TEST(backlash_distance_mm);
  1203. EEPROM_WRITE(backlash_distance_mm);
  1204. EEPROM_WRITE(backlash_correction);
  1205. EEPROM_WRITE(backlash_smoothing_mm);
  1206. }
  1207. //
  1208. // Extensible UI User Data
  1209. //
  1210. #if ENABLED(EXTENSIBLE_UI)
  1211. {
  1212. char extui_data[ExtUI::eeprom_data_size] = { 0 };
  1213. ExtUI::onStoreSettings(extui_data);
  1214. _FIELD_TEST(extui_data);
  1215. EEPROM_WRITE(extui_data);
  1216. }
  1217. #endif
  1218. //
  1219. // Creality DWIN User Data
  1220. //
  1221. #if ENABLED(DWIN_CREALITY_LCD_ENHANCED)
  1222. {
  1223. char dwin_data[eeprom_data_size] = { 0 };
  1224. DWIN_StoreSettings(dwin_data);
  1225. _FIELD_TEST(dwin_data);
  1226. EEPROM_WRITE(dwin_data);
  1227. }
  1228. #elif ENABLED(DWIN_CREALITY_LCD_JYERSUI)
  1229. {
  1230. char dwin_settings[CrealityDWIN.eeprom_data_size] = { 0 };
  1231. CrealityDWIN.Save_Settings(dwin_settings);
  1232. _FIELD_TEST(dwin_settings);
  1233. EEPROM_WRITE(dwin_settings);
  1234. }
  1235. #endif
  1236. //
  1237. // Case Light Brightness
  1238. //
  1239. #if CASELIGHT_USES_BRIGHTNESS
  1240. EEPROM_WRITE(caselight.brightness);
  1241. #endif
  1242. //
  1243. // Password feature
  1244. //
  1245. #if ENABLED(PASSWORD_FEATURE)
  1246. EEPROM_WRITE(password.is_set);
  1247. EEPROM_WRITE(password.value);
  1248. #endif
  1249. //
  1250. // TOUCH_SCREEN_CALIBRATION
  1251. //
  1252. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  1253. EEPROM_WRITE(touch_calibration.calibration);
  1254. #endif
  1255. //
  1256. // Ethernet network info
  1257. //
  1258. #if HAS_ETHERNET
  1259. {
  1260. _FIELD_TEST(ethernet_hardware_enabled);
  1261. const bool ethernet_hardware_enabled = ethernet.hardware_enabled;
  1262. const uint32_t ethernet_ip = ethernet.ip,
  1263. ethernet_dns = ethernet.myDns,
  1264. ethernet_gateway = ethernet.gateway,
  1265. ethernet_subnet = ethernet.subnet;
  1266. EEPROM_WRITE(ethernet_hardware_enabled);
  1267. EEPROM_WRITE(ethernet_ip);
  1268. EEPROM_WRITE(ethernet_dns);
  1269. EEPROM_WRITE(ethernet_gateway);
  1270. EEPROM_WRITE(ethernet_subnet);
  1271. }
  1272. #endif
  1273. //
  1274. // Buzzer enable/disable
  1275. //
  1276. #if ENABLED(SOUND_MENU_ITEM)
  1277. EEPROM_WRITE(ui.buzzer_enabled);
  1278. #endif
  1279. //
  1280. // Fan tachometer check
  1281. //
  1282. #if HAS_FANCHECK
  1283. EEPROM_WRITE(fan_check.enabled);
  1284. #endif
  1285. //
  1286. // MKS UI controller
  1287. //
  1288. #if ENABLED(DGUS_LCD_UI_MKS)
  1289. EEPROM_WRITE(mks_language_index);
  1290. EEPROM_WRITE(mks_corner_offsets);
  1291. EEPROM_WRITE(mks_park_pos);
  1292. EEPROM_WRITE(mks_min_extrusion_temp);
  1293. #endif
  1294. //
  1295. // Selected LCD language
  1296. //
  1297. #if HAS_MULTI_LANGUAGE
  1298. EEPROM_WRITE(ui.language);
  1299. #endif
  1300. //
  1301. // Report final CRC and Data Size
  1302. //
  1303. if (!eeprom_error) {
  1304. const uint16_t eeprom_size = eeprom_index - (EEPROM_OFFSET),
  1305. final_crc = working_crc;
  1306. // Write the EEPROM header
  1307. eeprom_index = EEPROM_OFFSET;
  1308. EEPROM_WRITE(version);
  1309. #if ENABLED(EEPROM_INIT_NOW)
  1310. EEPROM_WRITE(build_hash);
  1311. #endif
  1312. EEPROM_WRITE(final_crc);
  1313. // Report storage size
  1314. DEBUG_ECHO_MSG("Settings Stored (", eeprom_size, " bytes; crc ", (uint32_t)final_crc, ")");
  1315. eeprom_error |= size_error(eeprom_size);
  1316. }
  1317. EEPROM_FINISH();
  1318. //
  1319. // UBL Mesh
  1320. //
  1321. #if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
  1322. if (ubl.storage_slot >= 0)
  1323. store_mesh(ubl.storage_slot);
  1324. #endif
  1325. if (!eeprom_error) LCD_MESSAGE(MSG_SETTINGS_STORED);
  1326. TERN_(EXTENSIBLE_UI, ExtUI::onConfigurationStoreWritten(!eeprom_error));
  1327. return !eeprom_error;
  1328. }
  1329. /**
  1330. * M501 - Retrieve Configuration
  1331. */
  1332. bool MarlinSettings::_load() {
  1333. if (!EEPROM_START(EEPROM_OFFSET)) return false;
  1334. char stored_ver[4];
  1335. EEPROM_READ_ALWAYS(stored_ver);
  1336. // Version has to match or defaults are used
  1337. if (strncmp(version, stored_ver, 3) != 0) {
  1338. if (stored_ver[3] != '\0') {
  1339. stored_ver[0] = '?';
  1340. stored_ver[1] = '\0';
  1341. }
  1342. DEBUG_ECHO_MSG("EEPROM version mismatch (EEPROM=", stored_ver, " Marlin=" EEPROM_VERSION ")");
  1343. TERN_(DWIN_CREALITY_LCD_ENHANCED, LCD_MESSAGE(MSG_ERR_EEPROM_VERSION));
  1344. IF_DISABLED(EEPROM_AUTO_INIT, ui.eeprom_alert_version());
  1345. eeprom_error = true;
  1346. }
  1347. else {
  1348. // Optionally reset on the first boot after flashing
  1349. #if ENABLED(EEPROM_INIT_NOW)
  1350. uint32_t stored_hash;
  1351. EEPROM_READ_ALWAYS(stored_hash);
  1352. if (stored_hash != build_hash) { EEPROM_FINISH(); return true; }
  1353. #endif
  1354. uint16_t stored_crc;
  1355. EEPROM_READ_ALWAYS(stored_crc);
  1356. float dummyf = 0;
  1357. working_crc = 0; // Init to 0. Accumulated by EEPROM_READ
  1358. _FIELD_TEST(e_factors);
  1359. // Number of e_factors may change
  1360. uint8_t e_factors;
  1361. EEPROM_READ_ALWAYS(e_factors);
  1362. //
  1363. // Planner Motion
  1364. //
  1365. {
  1366. // Get only the number of E stepper parameters previously stored
  1367. // Any steppers added later are set to their defaults
  1368. uint32_t tmp1[LINEAR_AXES + e_factors];
  1369. float tmp2[LINEAR_AXES + e_factors];
  1370. feedRate_t tmp3[LINEAR_AXES + e_factors];
  1371. EEPROM_READ((uint8_t *)tmp1, sizeof(tmp1)); // max_acceleration_mm_per_s2
  1372. EEPROM_READ(planner.settings.min_segment_time_us);
  1373. EEPROM_READ((uint8_t *)tmp2, sizeof(tmp2)); // axis_steps_per_mm
  1374. EEPROM_READ((uint8_t *)tmp3, sizeof(tmp3)); // max_feedrate_mm_s
  1375. if (!validating) LOOP_DISTINCT_AXES(i) {
  1376. const bool in = (i < e_factors + LINEAR_AXES);
  1377. planner.settings.max_acceleration_mm_per_s2[i] = in ? tmp1[i] : pgm_read_dword(&_DMA[ALIM(i, _DMA)]);
  1378. planner.settings.axis_steps_per_mm[i] = in ? tmp2[i] : pgm_read_float(&_DASU[ALIM(i, _DASU)]);
  1379. planner.settings.max_feedrate_mm_s[i] = in ? tmp3[i] : pgm_read_float(&_DMF[ALIM(i, _DMF)]);
  1380. }
  1381. EEPROM_READ(planner.settings.acceleration);
  1382. EEPROM_READ(planner.settings.retract_acceleration);
  1383. EEPROM_READ(planner.settings.travel_acceleration);
  1384. EEPROM_READ(planner.settings.min_feedrate_mm_s);
  1385. EEPROM_READ(planner.settings.min_travel_feedrate_mm_s);
  1386. #if HAS_CLASSIC_JERK
  1387. EEPROM_READ(planner.max_jerk);
  1388. #if HAS_LINEAR_E_JERK
  1389. EEPROM_READ(dummyf);
  1390. #endif
  1391. #else
  1392. for (uint8_t q = LOGICAL_AXES; q--;) EEPROM_READ(dummyf);
  1393. #endif
  1394. EEPROM_READ(TERN(CLASSIC_JERK, dummyf, planner.junction_deviation_mm));
  1395. }
  1396. //
  1397. // Home Offset (M206 / M665)
  1398. //
  1399. {
  1400. _FIELD_TEST(home_offset);
  1401. #if HAS_SCARA_OFFSET
  1402. EEPROM_READ(scara_home_offset);
  1403. #else
  1404. #if !HAS_HOME_OFFSET
  1405. xyz_pos_t home_offset;
  1406. #endif
  1407. EEPROM_READ(home_offset);
  1408. #endif
  1409. }
  1410. //
  1411. // Hotend Offsets, if any
  1412. //
  1413. {
  1414. #if HAS_HOTEND_OFFSET
  1415. // Skip hotend 0 which must be 0
  1416. LOOP_S_L_N(e, 1, HOTENDS)
  1417. EEPROM_READ(hotend_offset[e]);
  1418. #endif
  1419. }
  1420. //
  1421. // Filament Runout Sensor
  1422. //
  1423. {
  1424. int8_t runout_sensor_enabled;
  1425. _FIELD_TEST(runout_sensor_enabled);
  1426. EEPROM_READ(runout_sensor_enabled);
  1427. #if HAS_FILAMENT_SENSOR
  1428. runout.enabled = runout_sensor_enabled < 0 ? FIL_RUNOUT_ENABLED_DEFAULT : runout_sensor_enabled;
  1429. #endif
  1430. TERN_(HAS_FILAMENT_SENSOR, if (runout.enabled) runout.reset());
  1431. float runout_distance_mm;
  1432. EEPROM_READ(runout_distance_mm);
  1433. #if HAS_FILAMENT_RUNOUT_DISTANCE
  1434. if (!validating) runout.set_runout_distance(runout_distance_mm);
  1435. #endif
  1436. }
  1437. //
  1438. // Global Leveling
  1439. //
  1440. EEPROM_READ(TERN(ENABLE_LEVELING_FADE_HEIGHT, new_z_fade_height, dummyf));
  1441. //
  1442. // Mesh (Manual) Bed Leveling
  1443. //
  1444. {
  1445. uint8_t mesh_num_x, mesh_num_y;
  1446. EEPROM_READ(dummyf);
  1447. EEPROM_READ_ALWAYS(mesh_num_x);
  1448. EEPROM_READ_ALWAYS(mesh_num_y);
  1449. #if ENABLED(MESH_BED_LEVELING)
  1450. if (!validating) mbl.z_offset = dummyf;
  1451. if (mesh_num_x == (GRID_MAX_POINTS_X) && mesh_num_y == (GRID_MAX_POINTS_Y)) {
  1452. // EEPROM data fits the current mesh
  1453. EEPROM_READ(mbl.z_values);
  1454. }
  1455. else {
  1456. // EEPROM data is stale
  1457. if (!validating) mbl.reset();
  1458. for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummyf);
  1459. }
  1460. #else
  1461. // MBL is disabled - skip the stored data
  1462. for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummyf);
  1463. #endif // MESH_BED_LEVELING
  1464. }
  1465. //
  1466. // Probe Z Offset
  1467. //
  1468. {
  1469. _FIELD_TEST(probe_offset);
  1470. #if HAS_BED_PROBE
  1471. const xyz_pos_t &zpo = probe.offset;
  1472. #else
  1473. xyz_pos_t zpo;
  1474. #endif
  1475. EEPROM_READ(zpo);
  1476. }
  1477. //
  1478. // Planar Bed Leveling matrix
  1479. //
  1480. {
  1481. #if ABL_PLANAR
  1482. EEPROM_READ(planner.bed_level_matrix);
  1483. #else
  1484. for (uint8_t q = 9; q--;) EEPROM_READ(dummyf);
  1485. #endif
  1486. }
  1487. //
  1488. // Bilinear Auto Bed Leveling
  1489. //
  1490. {
  1491. uint8_t grid_max_x, grid_max_y;
  1492. EEPROM_READ_ALWAYS(grid_max_x); // 1 byte
  1493. EEPROM_READ_ALWAYS(grid_max_y); // 1 byte
  1494. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  1495. if (grid_max_x == (GRID_MAX_POINTS_X) && grid_max_y == (GRID_MAX_POINTS_Y)) {
  1496. if (!validating) set_bed_leveling_enabled(false);
  1497. EEPROM_READ(bilinear_grid_spacing); // 2 ints
  1498. EEPROM_READ(bilinear_start); // 2 ints
  1499. EEPROM_READ(z_values); // 9 to 256 floats
  1500. #if ENABLED(X_AXIS_TWIST_COMPENSATION)
  1501. EEPROM_READ(xatc);
  1502. #endif
  1503. }
  1504. else // EEPROM data is stale
  1505. #endif // AUTO_BED_LEVELING_BILINEAR
  1506. {
  1507. // Skip past disabled (or stale) Bilinear Grid data
  1508. xy_pos_t bgs, bs;
  1509. EEPROM_READ(bgs);
  1510. EEPROM_READ(bs);
  1511. for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_READ(dummyf);
  1512. }
  1513. }
  1514. //
  1515. // Unified Bed Leveling active state
  1516. //
  1517. {
  1518. _FIELD_TEST(planner_leveling_active);
  1519. #if ENABLED(AUTO_BED_LEVELING_UBL)
  1520. const bool &planner_leveling_active = planner.leveling_active;
  1521. const int8_t &ubl_storage_slot = ubl.storage_slot;
  1522. #else
  1523. bool planner_leveling_active;
  1524. int8_t ubl_storage_slot;
  1525. #endif
  1526. EEPROM_READ(planner_leveling_active);
  1527. EEPROM_READ(ubl_storage_slot);
  1528. }
  1529. //
  1530. // SERVO_ANGLES
  1531. //
  1532. {
  1533. _FIELD_TEST(servo_angles);
  1534. #if ENABLED(EDITABLE_SERVO_ANGLES)
  1535. uint16_t (&servo_angles_arr)[EEPROM_NUM_SERVOS][2] = servo_angles;
  1536. #else
  1537. uint16_t servo_angles_arr[EEPROM_NUM_SERVOS][2];
  1538. #endif
  1539. EEPROM_READ(servo_angles_arr);
  1540. }
  1541. //
  1542. // Thermal first layer compensation values
  1543. //
  1544. #if HAS_PTC
  1545. #if ENABLED(PTC_PROBE)
  1546. EEPROM_READ(ptc.z_offsets_probe);
  1547. #endif
  1548. # if ENABLED(PTC_BED)
  1549. EEPROM_READ(ptc.z_offsets_bed);
  1550. #endif
  1551. #if ENABLED(PTC_HOTEND)
  1552. EEPROM_READ(ptc.z_offsets_hotend);
  1553. #endif
  1554. ptc.reset_index();
  1555. #else
  1556. // No placeholder data for this feature
  1557. #endif
  1558. //
  1559. // BLTOUCH
  1560. //
  1561. {
  1562. _FIELD_TEST(bltouch_last_written_mode);
  1563. #if ENABLED(BLTOUCH)
  1564. const bool &bltouch_last_written_mode = bltouch.last_written_mode;
  1565. #else
  1566. bool bltouch_last_written_mode;
  1567. #endif
  1568. EEPROM_READ(bltouch_last_written_mode);
  1569. }
  1570. //
  1571. // Kinematic Segments-per-second
  1572. //
  1573. #if IS_KINEMATIC
  1574. {
  1575. EEPROM_READ(segments_per_second);
  1576. #if ENABLED(DELTA)
  1577. _FIELD_TEST(delta_height);
  1578. EEPROM_READ(delta_height); // 1 float
  1579. EEPROM_READ(delta_endstop_adj); // 3 floats
  1580. EEPROM_READ(delta_radius); // 1 float
  1581. EEPROM_READ(delta_diagonal_rod); // 1 float
  1582. EEPROM_READ(delta_tower_angle_trim); // 3 floats
  1583. EEPROM_READ(delta_diagonal_rod_trim); // 3 floats
  1584. #endif
  1585. }
  1586. #endif
  1587. //
  1588. // Extra Endstops offsets
  1589. //
  1590. #if HAS_EXTRA_ENDSTOPS
  1591. {
  1592. _FIELD_TEST(x2_endstop_adj);
  1593. EEPROM_READ(TERN(X_DUAL_ENDSTOPS, endstops.x2_endstop_adj, dummyf)); // 1 float
  1594. EEPROM_READ(TERN(Y_DUAL_ENDSTOPS, endstops.y2_endstop_adj, dummyf)); // 1 float
  1595. EEPROM_READ(TERN(Z_MULTI_ENDSTOPS, endstops.z2_endstop_adj, dummyf)); // 1 float
  1596. #if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 3
  1597. EEPROM_READ(endstops.z3_endstop_adj); // 1 float
  1598. #else
  1599. EEPROM_READ(dummyf);
  1600. #endif
  1601. #if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 4
  1602. EEPROM_READ(endstops.z4_endstop_adj); // 1 float
  1603. #else
  1604. EEPROM_READ(dummyf);
  1605. #endif
  1606. }
  1607. #endif
  1608. #if ENABLED(Z_STEPPER_AUTO_ALIGN)
  1609. EEPROM_READ(z_stepper_align.xy);
  1610. #if ENABLED(Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS)
  1611. EEPROM_READ(z_stepper_align.stepper_xy);
  1612. #endif
  1613. #endif
  1614. //
  1615. // LCD Preheat settings
  1616. //
  1617. #if HAS_PREHEAT
  1618. _FIELD_TEST(ui_material_preset);
  1619. EEPROM_READ(ui.material_preset);
  1620. #endif
  1621. //
  1622. // Hotend PID
  1623. //
  1624. {
  1625. HOTEND_LOOP() {
  1626. PIDCF_t pidcf;
  1627. EEPROM_READ(pidcf);
  1628. #if ENABLED(PIDTEMP)
  1629. if (!validating && !isnan(pidcf.Kp)) {
  1630. // Scale PID values since EEPROM values are unscaled
  1631. PID_PARAM(Kp, e) = pidcf.Kp;
  1632. PID_PARAM(Ki, e) = scalePID_i(pidcf.Ki);
  1633. PID_PARAM(Kd, e) = scalePID_d(pidcf.Kd);
  1634. TERN_(PID_EXTRUSION_SCALING, PID_PARAM(Kc, e) = pidcf.Kc);
  1635. TERN_(PID_FAN_SCALING, PID_PARAM(Kf, e) = pidcf.Kf);
  1636. }
  1637. #endif
  1638. }
  1639. }
  1640. //
  1641. // PID Extrusion Scaling
  1642. //
  1643. {
  1644. _FIELD_TEST(lpq_len);
  1645. #if ENABLED(PID_EXTRUSION_SCALING)
  1646. const int16_t &lpq_len = thermalManager.lpq_len;
  1647. #else
  1648. int16_t lpq_len;
  1649. #endif
  1650. EEPROM_READ(lpq_len);
  1651. }
  1652. //
  1653. // Heated Bed PID
  1654. //
  1655. {
  1656. PID_t pid;
  1657. EEPROM_READ(pid);
  1658. #if ENABLED(PIDTEMPBED)
  1659. if (!validating && !isnan(pid.Kp)) {
  1660. // Scale PID values since EEPROM values are unscaled
  1661. thermalManager.temp_bed.pid.Kp = pid.Kp;
  1662. thermalManager.temp_bed.pid.Ki = scalePID_i(pid.Ki);
  1663. thermalManager.temp_bed.pid.Kd = scalePID_d(pid.Kd);
  1664. }
  1665. #endif
  1666. }
  1667. //
  1668. // Heated Chamber PID
  1669. //
  1670. {
  1671. PID_t pid;
  1672. EEPROM_READ(pid);
  1673. #if ENABLED(PIDTEMPCHAMBER)
  1674. if (!validating && !isnan(pid.Kp)) {
  1675. // Scale PID values since EEPROM values are unscaled
  1676. thermalManager.temp_chamber.pid.Kp = pid.Kp;
  1677. thermalManager.temp_chamber.pid.Ki = scalePID_i(pid.Ki);
  1678. thermalManager.temp_chamber.pid.Kd = scalePID_d(pid.Kd);
  1679. }
  1680. #endif
  1681. }
  1682. //
  1683. // User-defined Thermistors
  1684. //
  1685. #if HAS_USER_THERMISTORS
  1686. {
  1687. _FIELD_TEST(user_thermistor);
  1688. EEPROM_READ(thermalManager.user_thermistor);
  1689. }
  1690. #endif
  1691. //
  1692. // Power monitor
  1693. //
  1694. {
  1695. #if HAS_POWER_MONITOR
  1696. uint8_t &power_monitor_flags = power_monitor.flags;
  1697. #else
  1698. uint8_t power_monitor_flags;
  1699. #endif
  1700. _FIELD_TEST(power_monitor_flags);
  1701. EEPROM_READ(power_monitor_flags);
  1702. }
  1703. //
  1704. // LCD Contrast
  1705. //
  1706. {
  1707. _FIELD_TEST(lcd_contrast);
  1708. uint8_t lcd_contrast;
  1709. EEPROM_READ(lcd_contrast);
  1710. if (!validating) {
  1711. TERN_(HAS_LCD_CONTRAST, ui.set_contrast(lcd_contrast));
  1712. }
  1713. }
  1714. //
  1715. // LCD Brightness
  1716. //
  1717. {
  1718. _FIELD_TEST(lcd_brightness);
  1719. uint8_t lcd_brightness;
  1720. EEPROM_READ(lcd_brightness);
  1721. TERN_(HAS_LCD_BRIGHTNESS, if (!validating) ui.set_brightness(lcd_brightness));
  1722. }
  1723. //
  1724. // Controller Fan
  1725. //
  1726. {
  1727. _FIELD_TEST(controllerFan_settings);
  1728. #if ENABLED(CONTROLLER_FAN_EDITABLE)
  1729. const controllerFan_settings_t &cfs = controllerFan.settings;
  1730. #else
  1731. controllerFan_settings_t cfs = { 0 };
  1732. #endif
  1733. EEPROM_READ(cfs);
  1734. }
  1735. //
  1736. // Power-Loss Recovery
  1737. //
  1738. {
  1739. _FIELD_TEST(recovery_enabled);
  1740. #if ENABLED(POWER_LOSS_RECOVERY)
  1741. const bool &recovery_enabled = recovery.enabled;
  1742. #else
  1743. bool recovery_enabled;
  1744. #endif
  1745. EEPROM_READ(recovery_enabled);
  1746. }
  1747. //
  1748. // Firmware Retraction
  1749. //
  1750. {
  1751. _FIELD_TEST(fwretract_settings);
  1752. #if ENABLED(FWRETRACT)
  1753. EEPROM_READ(fwretract.settings);
  1754. #else
  1755. fwretract_settings_t fwretract_settings;
  1756. EEPROM_READ(fwretract_settings);
  1757. #endif
  1758. #if BOTH(FWRETRACT, FWRETRACT_AUTORETRACT)
  1759. EEPROM_READ(fwretract.autoretract_enabled);
  1760. #else
  1761. bool autoretract_enabled;
  1762. EEPROM_READ(autoretract_enabled);
  1763. #endif
  1764. }
  1765. //
  1766. // Volumetric & Filament Size
  1767. //
  1768. {
  1769. struct {
  1770. bool volumetric_enabled;
  1771. float filament_size[EXTRUDERS];
  1772. float volumetric_extruder_limit[EXTRUDERS];
  1773. } storage;
  1774. _FIELD_TEST(parser_volumetric_enabled);
  1775. EEPROM_READ(storage);
  1776. #if DISABLED(NO_VOLUMETRICS)
  1777. if (!validating) {
  1778. parser.volumetric_enabled = storage.volumetric_enabled;
  1779. COPY(planner.filament_size, storage.filament_size);
  1780. #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
  1781. COPY(planner.volumetric_extruder_limit, storage.volumetric_extruder_limit);
  1782. #endif
  1783. }
  1784. #endif
  1785. }
  1786. //
  1787. // TMC Stepper Settings
  1788. //
  1789. if (!validating) reset_stepper_drivers();
  1790. // TMC Stepper Current
  1791. {
  1792. _FIELD_TEST(tmc_stepper_current);
  1793. tmc_stepper_current_t currents;
  1794. EEPROM_READ(currents);
  1795. #if HAS_TRINAMIC_CONFIG
  1796. #define SET_CURR(Q) stepper##Q.rms_current(currents.Q ? currents.Q : Q##_CURRENT)
  1797. if (!validating) {
  1798. #if AXIS_IS_TMC(X)
  1799. SET_CURR(X);
  1800. #endif
  1801. #if AXIS_IS_TMC(Y)
  1802. SET_CURR(Y);
  1803. #endif
  1804. #if AXIS_IS_TMC(Z)
  1805. SET_CURR(Z);
  1806. #endif
  1807. #if AXIS_IS_TMC(X2)
  1808. SET_CURR(X2);
  1809. #endif
  1810. #if AXIS_IS_TMC(Y2)
  1811. SET_CURR(Y2);
  1812. #endif
  1813. #if AXIS_IS_TMC(Z2)
  1814. SET_CURR(Z2);
  1815. #endif
  1816. #if AXIS_IS_TMC(Z3)
  1817. SET_CURR(Z3);
  1818. #endif
  1819. #if AXIS_IS_TMC(Z4)
  1820. SET_CURR(Z4);
  1821. #endif
  1822. #if AXIS_IS_TMC(I)
  1823. SET_CURR(I);
  1824. #endif
  1825. #if AXIS_IS_TMC(J)
  1826. SET_CURR(J);
  1827. #endif
  1828. #if AXIS_IS_TMC(K)
  1829. SET_CURR(K);
  1830. #endif
  1831. #if AXIS_IS_TMC(E0)
  1832. SET_CURR(E0);
  1833. #endif
  1834. #if AXIS_IS_TMC(E1)
  1835. SET_CURR(E1);
  1836. #endif
  1837. #if AXIS_IS_TMC(E2)
  1838. SET_CURR(E2);
  1839. #endif
  1840. #if AXIS_IS_TMC(E3)
  1841. SET_CURR(E3);
  1842. #endif
  1843. #if AXIS_IS_TMC(E4)
  1844. SET_CURR(E4);
  1845. #endif
  1846. #if AXIS_IS_TMC(E5)
  1847. SET_CURR(E5);
  1848. #endif
  1849. #if AXIS_IS_TMC(E6)
  1850. SET_CURR(E6);
  1851. #endif
  1852. #if AXIS_IS_TMC(E7)
  1853. SET_CURR(E7);
  1854. #endif
  1855. }
  1856. #endif
  1857. }
  1858. // TMC Hybrid Threshold
  1859. {
  1860. tmc_hybrid_threshold_t tmc_hybrid_threshold;
  1861. _FIELD_TEST(tmc_hybrid_threshold);
  1862. EEPROM_READ(tmc_hybrid_threshold);
  1863. #if ENABLED(HYBRID_THRESHOLD)
  1864. if (!validating) {
  1865. TERN_(X_HAS_STEALTHCHOP, stepperX.set_pwm_thrs(tmc_hybrid_threshold.X));
  1866. TERN_(Y_HAS_STEALTHCHOP, stepperY.set_pwm_thrs(tmc_hybrid_threshold.Y));
  1867. TERN_(Z_HAS_STEALTHCHOP, stepperZ.set_pwm_thrs(tmc_hybrid_threshold.Z));
  1868. TERN_(X2_HAS_STEALTHCHOP, stepperX2.set_pwm_thrs(tmc_hybrid_threshold.X2));
  1869. TERN_(Y2_HAS_STEALTHCHOP, stepperY2.set_pwm_thrs(tmc_hybrid_threshold.Y2));
  1870. TERN_(Z2_HAS_STEALTHCHOP, stepperZ2.set_pwm_thrs(tmc_hybrid_threshold.Z2));
  1871. TERN_(Z3_HAS_STEALTHCHOP, stepperZ3.set_pwm_thrs(tmc_hybrid_threshold.Z3));
  1872. TERN_(Z4_HAS_STEALTHCHOP, stepperZ4.set_pwm_thrs(tmc_hybrid_threshold.Z4));
  1873. TERN_(I_HAS_STEALTHCHOP, stepperI.set_pwm_thrs(tmc_hybrid_threshold.I));
  1874. TERN_(J_HAS_STEALTHCHOP, stepperJ.set_pwm_thrs(tmc_hybrid_threshold.J));
  1875. TERN_(K_HAS_STEALTHCHOP, stepperK.set_pwm_thrs(tmc_hybrid_threshold.K));
  1876. TERN_(E0_HAS_STEALTHCHOP, stepperE0.set_pwm_thrs(tmc_hybrid_threshold.E0));
  1877. TERN_(E1_HAS_STEALTHCHOP, stepperE1.set_pwm_thrs(tmc_hybrid_threshold.E1));
  1878. TERN_(E2_HAS_STEALTHCHOP, stepperE2.set_pwm_thrs(tmc_hybrid_threshold.E2));
  1879. TERN_(E3_HAS_STEALTHCHOP, stepperE3.set_pwm_thrs(tmc_hybrid_threshold.E3));
  1880. TERN_(E4_HAS_STEALTHCHOP, stepperE4.set_pwm_thrs(tmc_hybrid_threshold.E4));
  1881. TERN_(E5_HAS_STEALTHCHOP, stepperE5.set_pwm_thrs(tmc_hybrid_threshold.E5));
  1882. TERN_(E6_HAS_STEALTHCHOP, stepperE6.set_pwm_thrs(tmc_hybrid_threshold.E6));
  1883. TERN_(E7_HAS_STEALTHCHOP, stepperE7.set_pwm_thrs(tmc_hybrid_threshold.E7));
  1884. }
  1885. #endif
  1886. }
  1887. //
  1888. // TMC StallGuard threshold.
  1889. //
  1890. {
  1891. tmc_sgt_t tmc_sgt;
  1892. _FIELD_TEST(tmc_sgt);
  1893. EEPROM_READ(tmc_sgt);
  1894. #if USE_SENSORLESS
  1895. if (!validating) {
  1896. LINEAR_AXIS_CODE(
  1897. TERN_(X_SENSORLESS, stepperX.homing_threshold(tmc_sgt.X)),
  1898. TERN_(Y_SENSORLESS, stepperY.homing_threshold(tmc_sgt.Y)),
  1899. TERN_(Z_SENSORLESS, stepperZ.homing_threshold(tmc_sgt.Z)),
  1900. TERN_(I_SENSORLESS, stepperI.homing_threshold(tmc_sgt.I)),
  1901. TERN_(J_SENSORLESS, stepperJ.homing_threshold(tmc_sgt.J)),
  1902. TERN_(K_SENSORLESS, stepperK.homing_threshold(tmc_sgt.K))
  1903. );
  1904. TERN_(X2_SENSORLESS, stepperX2.homing_threshold(tmc_sgt.X2));
  1905. TERN_(Y2_SENSORLESS, stepperY2.homing_threshold(tmc_sgt.Y2));
  1906. TERN_(Z2_SENSORLESS, stepperZ2.homing_threshold(tmc_sgt.Z2));
  1907. TERN_(Z3_SENSORLESS, stepperZ3.homing_threshold(tmc_sgt.Z3));
  1908. TERN_(Z4_SENSORLESS, stepperZ4.homing_threshold(tmc_sgt.Z4));
  1909. }
  1910. #endif
  1911. }
  1912. // TMC stepping mode
  1913. {
  1914. _FIELD_TEST(tmc_stealth_enabled);
  1915. tmc_stealth_enabled_t tmc_stealth_enabled;
  1916. EEPROM_READ(tmc_stealth_enabled);
  1917. #if HAS_TRINAMIC_CONFIG
  1918. #define SET_STEPPING_MODE(ST) stepper##ST.stored.stealthChop_enabled = tmc_stealth_enabled.ST; stepper##ST.refresh_stepping_mode();
  1919. if (!validating) {
  1920. TERN_(X_HAS_STEALTHCHOP, SET_STEPPING_MODE(X));
  1921. TERN_(Y_HAS_STEALTHCHOP, SET_STEPPING_MODE(Y));
  1922. TERN_(Z_HAS_STEALTHCHOP, SET_STEPPING_MODE(Z));
  1923. TERN_(I_HAS_STEALTHCHOP, SET_STEPPING_MODE(I));
  1924. TERN_(J_HAS_STEALTHCHOP, SET_STEPPING_MODE(J));
  1925. TERN_(K_HAS_STEALTHCHOP, SET_STEPPING_MODE(K));
  1926. TERN_(X2_HAS_STEALTHCHOP, SET_STEPPING_MODE(X2));
  1927. TERN_(Y2_HAS_STEALTHCHOP, SET_STEPPING_MODE(Y2));
  1928. TERN_(Z2_HAS_STEALTHCHOP, SET_STEPPING_MODE(Z2));
  1929. TERN_(Z3_HAS_STEALTHCHOP, SET_STEPPING_MODE(Z3));
  1930. TERN_(Z4_HAS_STEALTHCHOP, SET_STEPPING_MODE(Z4));
  1931. TERN_(E0_HAS_STEALTHCHOP, SET_STEPPING_MODE(E0));
  1932. TERN_(E1_HAS_STEALTHCHOP, SET_STEPPING_MODE(E1));
  1933. TERN_(E2_HAS_STEALTHCHOP, SET_STEPPING_MODE(E2));
  1934. TERN_(E3_HAS_STEALTHCHOP, SET_STEPPING_MODE(E3));
  1935. TERN_(E4_HAS_STEALTHCHOP, SET_STEPPING_MODE(E4));
  1936. TERN_(E5_HAS_STEALTHCHOP, SET_STEPPING_MODE(E5));
  1937. TERN_(E6_HAS_STEALTHCHOP, SET_STEPPING_MODE(E6));
  1938. TERN_(E7_HAS_STEALTHCHOP, SET_STEPPING_MODE(E7));
  1939. }
  1940. #endif
  1941. }
  1942. //
  1943. // Linear Advance
  1944. //
  1945. {
  1946. float extruder_advance_K[_MAX(EXTRUDERS, 1)];
  1947. _FIELD_TEST(planner_extruder_advance_K);
  1948. EEPROM_READ(extruder_advance_K);
  1949. #if ENABLED(LIN_ADVANCE)
  1950. if (!validating)
  1951. COPY(planner.extruder_advance_K, extruder_advance_K);
  1952. #endif
  1953. }
  1954. //
  1955. // Motor Current PWM
  1956. //
  1957. {
  1958. _FIELD_TEST(motor_current_setting);
  1959. uint32_t motor_current_setting[MOTOR_CURRENT_COUNT]
  1960. #if HAS_MOTOR_CURRENT_SPI
  1961. = DIGIPOT_MOTOR_CURRENT
  1962. #endif
  1963. ;
  1964. #if HAS_MOTOR_CURRENT_SPI
  1965. DEBUG_ECHO_MSG("DIGIPOTS Loading");
  1966. #endif
  1967. EEPROM_READ(motor_current_setting);
  1968. #if HAS_MOTOR_CURRENT_SPI
  1969. DEBUG_ECHO_MSG("DIGIPOTS Loaded");
  1970. #endif
  1971. #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM
  1972. if (!validating)
  1973. COPY(stepper.motor_current_setting, motor_current_setting);
  1974. #endif
  1975. }
  1976. //
  1977. // CNC Coordinate System
  1978. //
  1979. {
  1980. _FIELD_TEST(coordinate_system);
  1981. #if ENABLED(CNC_COORDINATE_SYSTEMS)
  1982. if (!validating) (void)gcode.select_coordinate_system(-1); // Go back to machine space
  1983. EEPROM_READ(gcode.coordinate_system);
  1984. #else
  1985. xyz_pos_t coordinate_system[MAX_COORDINATE_SYSTEMS];
  1986. EEPROM_READ(coordinate_system);
  1987. #endif
  1988. }
  1989. //
  1990. // Skew correction factors
  1991. //
  1992. {
  1993. skew_factor_t skew_factor;
  1994. _FIELD_TEST(planner_skew_factor);
  1995. EEPROM_READ(skew_factor);
  1996. #if ENABLED(SKEW_CORRECTION_GCODE)
  1997. if (!validating) {
  1998. planner.skew_factor.xy = skew_factor.xy;
  1999. #if ENABLED(SKEW_CORRECTION_FOR_Z)
  2000. planner.skew_factor.xz = skew_factor.xz;
  2001. planner.skew_factor.yz = skew_factor.yz;
  2002. #endif
  2003. }
  2004. #endif
  2005. }
  2006. //
  2007. // Advanced Pause filament load & unload lengths
  2008. //
  2009. #if HAS_EXTRUDERS
  2010. {
  2011. #if DISABLED(ADVANCED_PAUSE_FEATURE)
  2012. fil_change_settings_t fc_settings[EXTRUDERS];
  2013. #endif
  2014. _FIELD_TEST(fc_settings);
  2015. EEPROM_READ(fc_settings);
  2016. }
  2017. #endif
  2018. //
  2019. // Tool-change settings
  2020. //
  2021. #if HAS_MULTI_EXTRUDER
  2022. _FIELD_TEST(toolchange_settings);
  2023. EEPROM_READ(toolchange_settings);
  2024. #endif
  2025. //
  2026. // Backlash Compensation
  2027. //
  2028. {
  2029. #if ENABLED(BACKLASH_GCODE)
  2030. const xyz_float_t &backlash_distance_mm = backlash.distance_mm;
  2031. const uint8_t &backlash_correction = backlash.correction;
  2032. #else
  2033. xyz_float_t backlash_distance_mm;
  2034. uint8_t backlash_correction;
  2035. #endif
  2036. #if ENABLED(BACKLASH_GCODE) && defined(BACKLASH_SMOOTHING_MM)
  2037. const float &backlash_smoothing_mm = backlash.smoothing_mm;
  2038. #else
  2039. float backlash_smoothing_mm;
  2040. #endif
  2041. _FIELD_TEST(backlash_distance_mm);
  2042. EEPROM_READ(backlash_distance_mm);
  2043. EEPROM_READ(backlash_correction);
  2044. EEPROM_READ(backlash_smoothing_mm);
  2045. }
  2046. //
  2047. // Extensible UI User Data
  2048. //
  2049. #if ENABLED(EXTENSIBLE_UI)
  2050. { // This is a significant hardware change; don't reserve EEPROM space when not present
  2051. const char extui_data[ExtUI::eeprom_data_size] = { 0 };
  2052. _FIELD_TEST(extui_data);
  2053. EEPROM_READ(extui_data);
  2054. if (!validating) ExtUI::onLoadSettings(extui_data);
  2055. }
  2056. #endif
  2057. //
  2058. // Creality DWIN User Data
  2059. //
  2060. #if ENABLED(DWIN_CREALITY_LCD_ENHANCED)
  2061. {
  2062. const char dwin_data[eeprom_data_size] = { 0 };
  2063. _FIELD_TEST(dwin_data);
  2064. EEPROM_READ(dwin_data);
  2065. if (!validating) DWIN_LoadSettings(dwin_data);
  2066. }
  2067. #elif ENABLED(DWIN_CREALITY_LCD_JYERSUI)
  2068. {
  2069. const char dwin_settings[CrealityDWIN.eeprom_data_size] = { 0 };
  2070. _FIELD_TEST(dwin_settings);
  2071. EEPROM_READ(dwin_settings);
  2072. if (!validating) CrealityDWIN.Load_Settings(dwin_settings);
  2073. }
  2074. #endif
  2075. //
  2076. // Case Light Brightness
  2077. //
  2078. #if CASELIGHT_USES_BRIGHTNESS
  2079. _FIELD_TEST(caselight_brightness);
  2080. EEPROM_READ(caselight.brightness);
  2081. #endif
  2082. //
  2083. // Password feature
  2084. //
  2085. #if ENABLED(PASSWORD_FEATURE)
  2086. _FIELD_TEST(password_is_set);
  2087. EEPROM_READ(password.is_set);
  2088. EEPROM_READ(password.value);
  2089. #endif
  2090. //
  2091. // TOUCH_SCREEN_CALIBRATION
  2092. //
  2093. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  2094. _FIELD_TEST(touch_calibration_data);
  2095. EEPROM_READ(touch_calibration.calibration);
  2096. #endif
  2097. //
  2098. // Ethernet network info
  2099. //
  2100. #if HAS_ETHERNET
  2101. _FIELD_TEST(ethernet_hardware_enabled);
  2102. uint32_t ethernet_ip, ethernet_dns, ethernet_gateway, ethernet_subnet;
  2103. EEPROM_READ(ethernet.hardware_enabled);
  2104. EEPROM_READ(ethernet_ip); ethernet.ip = ethernet_ip;
  2105. EEPROM_READ(ethernet_dns); ethernet.myDns = ethernet_dns;
  2106. EEPROM_READ(ethernet_gateway); ethernet.gateway = ethernet_gateway;
  2107. EEPROM_READ(ethernet_subnet); ethernet.subnet = ethernet_subnet;
  2108. #endif
  2109. //
  2110. // Buzzer enable/disable
  2111. //
  2112. #if ENABLED(SOUND_MENU_ITEM)
  2113. _FIELD_TEST(buzzer_enabled);
  2114. EEPROM_READ(ui.buzzer_enabled);
  2115. #endif
  2116. //
  2117. // Fan tachometer check
  2118. //
  2119. #if HAS_FANCHECK
  2120. _FIELD_TEST(fan_check_enabled);
  2121. EEPROM_READ(fan_check.enabled);
  2122. #endif
  2123. //
  2124. // MKS UI controller
  2125. //
  2126. #if ENABLED(DGUS_LCD_UI_MKS)
  2127. _FIELD_TEST(mks_language_index);
  2128. EEPROM_READ(mks_language_index);
  2129. EEPROM_READ(mks_corner_offsets);
  2130. EEPROM_READ(mks_park_pos);
  2131. EEPROM_READ(mks_min_extrusion_temp);
  2132. #endif
  2133. //
  2134. // Selected LCD language
  2135. //
  2136. #if HAS_MULTI_LANGUAGE
  2137. {
  2138. uint8_t ui_language;
  2139. EEPROM_READ(ui_language);
  2140. if (ui_language >= NUM_LANGUAGES) ui_language = 0;
  2141. ui.set_language(ui_language);
  2142. }
  2143. #endif
  2144. //
  2145. // Validate Final Size and CRC
  2146. //
  2147. eeprom_error = size_error(eeprom_index - (EEPROM_OFFSET));
  2148. if (eeprom_error) {
  2149. DEBUG_ECHO_MSG("Index: ", eeprom_index - (EEPROM_OFFSET), " Size: ", datasize());
  2150. IF_DISABLED(EEPROM_AUTO_INIT, ui.eeprom_alert_index());
  2151. }
  2152. else if (working_crc != stored_crc) {
  2153. eeprom_error = true;
  2154. DEBUG_ERROR_MSG("EEPROM CRC mismatch - (stored) ", stored_crc, " != ", working_crc, " (calculated)!");
  2155. TERN_(DWIN_CREALITY_LCD_ENHANCED, LCD_MESSAGE(MSG_ERR_EEPROM_CRC));
  2156. IF_DISABLED(EEPROM_AUTO_INIT, ui.eeprom_alert_crc());
  2157. }
  2158. else if (!validating) {
  2159. DEBUG_ECHO_START();
  2160. DEBUG_ECHO(version);
  2161. DEBUG_ECHOLNPGM(" stored settings retrieved (", eeprom_index - (EEPROM_OFFSET), " bytes; crc ", (uint32_t)working_crc, ")");
  2162. }
  2163. if (!validating && !eeprom_error) postprocess();
  2164. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2165. if (!validating) {
  2166. ubl.report_state();
  2167. if (!ubl.sanity_check()) {
  2168. #if BOTH(EEPROM_CHITCHAT, DEBUG_LEVELING_FEATURE)
  2169. ubl.echo_name();
  2170. DEBUG_ECHOLNPGM(" initialized.\n");
  2171. #endif
  2172. }
  2173. else {
  2174. eeprom_error = true;
  2175. #if BOTH(EEPROM_CHITCHAT, DEBUG_LEVELING_FEATURE)
  2176. DEBUG_ECHOPGM("?Can't enable ");
  2177. ubl.echo_name();
  2178. DEBUG_ECHOLNPGM(".");
  2179. #endif
  2180. ubl.reset();
  2181. }
  2182. if (ubl.storage_slot >= 0) {
  2183. load_mesh(ubl.storage_slot);
  2184. DEBUG_ECHOLNPGM("Mesh ", ubl.storage_slot, " loaded from storage.");
  2185. }
  2186. else {
  2187. ubl.reset();
  2188. DEBUG_ECHOLNPGM("UBL reset");
  2189. }
  2190. }
  2191. #endif
  2192. }
  2193. #if ENABLED(EEPROM_CHITCHAT) && DISABLED(DISABLE_M503)
  2194. // Report the EEPROM settings
  2195. if (!validating && TERN1(EEPROM_BOOT_SILENT, IsRunning())) report();
  2196. #endif
  2197. EEPROM_FINISH();
  2198. return !eeprom_error;
  2199. }
  2200. #ifdef ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE
  2201. extern bool restoreEEPROM();
  2202. #endif
  2203. bool MarlinSettings::validate() {
  2204. validating = true;
  2205. #ifdef ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE
  2206. bool success = _load();
  2207. if (!success && restoreEEPROM()) {
  2208. SERIAL_ECHOLNPGM("Recovered backup EEPROM settings from SPI Flash");
  2209. success = _load();
  2210. }
  2211. #else
  2212. const bool success = _load();
  2213. #endif
  2214. validating = false;
  2215. return success;
  2216. }
  2217. bool MarlinSettings::load() {
  2218. if (validate()) {
  2219. const bool success = _load();
  2220. TERN_(EXTENSIBLE_UI, ExtUI::onConfigurationStoreRead(success));
  2221. return success;
  2222. }
  2223. reset();
  2224. #if EITHER(EEPROM_AUTO_INIT, EEPROM_INIT_NOW)
  2225. (void)save();
  2226. SERIAL_ECHO_MSG("EEPROM Initialized");
  2227. #endif
  2228. return false;
  2229. }
  2230. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2231. inline void ubl_invalid_slot(const int s) {
  2232. DEBUG_ECHOLNPGM("?Invalid slot.\n", s, " mesh slots available.");
  2233. UNUSED(s);
  2234. }
  2235. // 128 (+1 because of the change to capacity rather than last valid address)
  2236. // is a placeholder for the size of the MAT; the MAT will always
  2237. // live at the very end of the eeprom
  2238. const uint16_t MarlinSettings::meshes_end = persistentStore.capacity() - 129;
  2239. uint16_t MarlinSettings::meshes_start_index() {
  2240. // Pad the end of configuration data so it can float up
  2241. // or down a little bit without disrupting the mesh data
  2242. return (datasize() + EEPROM_OFFSET + 32) & 0xFFF8;
  2243. }
  2244. #define MESH_STORE_SIZE sizeof(TERN(OPTIMIZED_MESH_STORAGE, mesh_store_t, ubl.z_values))
  2245. uint16_t MarlinSettings::calc_num_meshes() {
  2246. return (meshes_end - meshes_start_index()) / MESH_STORE_SIZE;
  2247. }
  2248. int MarlinSettings::mesh_slot_offset(const int8_t slot) {
  2249. return meshes_end - (slot + 1) * MESH_STORE_SIZE;
  2250. }
  2251. void MarlinSettings::store_mesh(const int8_t slot) {
  2252. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2253. const int16_t a = calc_num_meshes();
  2254. if (!WITHIN(slot, 0, a - 1)) {
  2255. ubl_invalid_slot(a);
  2256. DEBUG_ECHOLNPGM("E2END=", persistentStore.capacity() - 1, " meshes_end=", meshes_end, " slot=", slot);
  2257. DEBUG_EOL();
  2258. return;
  2259. }
  2260. int pos = mesh_slot_offset(slot);
  2261. uint16_t crc = 0;
  2262. #if ENABLED(OPTIMIZED_MESH_STORAGE)
  2263. int16_t z_mesh_store[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
  2264. ubl.set_store_from_mesh(ubl.z_values, z_mesh_store);
  2265. uint8_t * const src = (uint8_t*)&z_mesh_store;
  2266. #else
  2267. uint8_t * const src = (uint8_t*)&ubl.z_values;
  2268. #endif
  2269. // Write crc to MAT along with other data, or just tack on to the beginning or end
  2270. persistentStore.access_start();
  2271. const bool status = persistentStore.write_data(pos, src, MESH_STORE_SIZE, &crc);
  2272. persistentStore.access_finish();
  2273. if (status) SERIAL_ECHOLNPGM("?Unable to save mesh data.");
  2274. else DEBUG_ECHOLNPGM("Mesh saved in slot ", slot);
  2275. #else
  2276. // Other mesh types
  2277. #endif
  2278. }
  2279. void MarlinSettings::load_mesh(const int8_t slot, void * const into/*=nullptr*/) {
  2280. #if ENABLED(AUTO_BED_LEVELING_UBL)
  2281. const int16_t a = settings.calc_num_meshes();
  2282. if (!WITHIN(slot, 0, a - 1)) {
  2283. ubl_invalid_slot(a);
  2284. return;
  2285. }
  2286. int pos = mesh_slot_offset(slot);
  2287. uint16_t crc = 0;
  2288. #if ENABLED(OPTIMIZED_MESH_STORAGE)
  2289. int16_t z_mesh_store[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
  2290. uint8_t * const dest = (uint8_t*)&z_mesh_store;
  2291. #else
  2292. uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&ubl.z_values;
  2293. #endif
  2294. persistentStore.access_start();
  2295. const uint16_t status = persistentStore.read_data(pos, dest, MESH_STORE_SIZE, &crc);
  2296. persistentStore.access_finish();
  2297. #if ENABLED(OPTIMIZED_MESH_STORAGE)
  2298. if (into) {
  2299. float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
  2300. ubl.set_mesh_from_store(z_mesh_store, z_values);
  2301. memcpy(into, z_values, sizeof(z_values));
  2302. }
  2303. else
  2304. ubl.set_mesh_from_store(z_mesh_store, ubl.z_values);
  2305. #endif
  2306. if (status) SERIAL_ECHOLNPGM("?Unable to load mesh data.");
  2307. else DEBUG_ECHOLNPGM("Mesh loaded from slot ", slot);
  2308. EEPROM_FINISH();
  2309. #else
  2310. // Other mesh types
  2311. #endif
  2312. }
  2313. //void MarlinSettings::delete_mesh() { return; }
  2314. //void MarlinSettings::defrag_meshes() { return; }
  2315. #endif // AUTO_BED_LEVELING_UBL
  2316. #else // !EEPROM_SETTINGS
  2317. bool MarlinSettings::save() {
  2318. DEBUG_ERROR_MSG("EEPROM disabled");
  2319. return false;
  2320. }
  2321. #endif // !EEPROM_SETTINGS
  2322. /**
  2323. * M502 - Reset Configuration
  2324. */
  2325. void MarlinSettings::reset() {
  2326. LOOP_DISTINCT_AXES(i) {
  2327. planner.settings.max_acceleration_mm_per_s2[i] = pgm_read_dword(&_DMA[ALIM(i, _DMA)]);
  2328. planner.settings.axis_steps_per_mm[i] = pgm_read_float(&_DASU[ALIM(i, _DASU)]);
  2329. planner.settings.max_feedrate_mm_s[i] = pgm_read_float(&_DMF[ALIM(i, _DMF)]);
  2330. }
  2331. planner.settings.min_segment_time_us = DEFAULT_MINSEGMENTTIME;
  2332. planner.settings.acceleration = DEFAULT_ACCELERATION;
  2333. planner.settings.retract_acceleration = DEFAULT_RETRACT_ACCELERATION;
  2334. planner.settings.travel_acceleration = DEFAULT_TRAVEL_ACCELERATION;
  2335. planner.settings.min_feedrate_mm_s = feedRate_t(DEFAULT_MINIMUMFEEDRATE);
  2336. planner.settings.min_travel_feedrate_mm_s = feedRate_t(DEFAULT_MINTRAVELFEEDRATE);
  2337. #if HAS_CLASSIC_JERK
  2338. #ifndef DEFAULT_XJERK
  2339. #define DEFAULT_XJERK 0
  2340. #endif
  2341. #if HAS_Y_AXIS && !defined(DEFAULT_YJERK)
  2342. #define DEFAULT_YJERK 0
  2343. #endif
  2344. #if HAS_Z_AXIS && !defined(DEFAULT_ZJERK)
  2345. #define DEFAULT_ZJERK 0
  2346. #endif
  2347. #if LINEAR_AXES >= 4 && !defined(DEFAULT_IJERK)
  2348. #define DEFAULT_IJERK 0
  2349. #endif
  2350. #if LINEAR_AXES >= 5 && !defined(DEFAULT_JJERK)
  2351. #define DEFAULT_JJERK 0
  2352. #endif
  2353. #if LINEAR_AXES >= 6 && !defined(DEFAULT_KJERK)
  2354. #define DEFAULT_KJERK 0
  2355. #endif
  2356. planner.max_jerk.set(
  2357. LINEAR_AXIS_LIST(DEFAULT_XJERK, DEFAULT_YJERK, DEFAULT_ZJERK, DEFAULT_IJERK, DEFAULT_JJERK, DEFAULT_KJERK)
  2358. );
  2359. TERN_(HAS_CLASSIC_E_JERK, planner.max_jerk.e = DEFAULT_EJERK);
  2360. #endif
  2361. TERN_(HAS_JUNCTION_DEVIATION, planner.junction_deviation_mm = float(JUNCTION_DEVIATION_MM));
  2362. #if HAS_SCARA_OFFSET
  2363. scara_home_offset.reset();
  2364. #elif HAS_HOME_OFFSET
  2365. home_offset.reset();
  2366. #endif
  2367. TERN_(HAS_HOTEND_OFFSET, reset_hotend_offsets());
  2368. //
  2369. // Filament Runout Sensor
  2370. //
  2371. #if HAS_FILAMENT_SENSOR
  2372. runout.enabled = FIL_RUNOUT_ENABLED_DEFAULT;
  2373. runout.reset();
  2374. TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, runout.set_runout_distance(FILAMENT_RUNOUT_DISTANCE_MM));
  2375. #endif
  2376. //
  2377. // Tool-change Settings
  2378. //
  2379. #if HAS_MULTI_EXTRUDER
  2380. #if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
  2381. toolchange_settings.swap_length = TOOLCHANGE_FS_LENGTH;
  2382. toolchange_settings.extra_resume = TOOLCHANGE_FS_EXTRA_RESUME_LENGTH;
  2383. toolchange_settings.retract_speed = TOOLCHANGE_FS_RETRACT_SPEED;
  2384. toolchange_settings.unretract_speed = TOOLCHANGE_FS_UNRETRACT_SPEED;
  2385. toolchange_settings.extra_prime = TOOLCHANGE_FS_EXTRA_PRIME;
  2386. toolchange_settings.prime_speed = TOOLCHANGE_FS_PRIME_SPEED;
  2387. toolchange_settings.fan_speed = TOOLCHANGE_FS_FAN_SPEED;
  2388. toolchange_settings.fan_time = TOOLCHANGE_FS_FAN_TIME;
  2389. #endif
  2390. #if ENABLED(TOOLCHANGE_FS_PRIME_FIRST_USED)
  2391. enable_first_prime = false;
  2392. #endif
  2393. #if ENABLED(TOOLCHANGE_PARK)
  2394. constexpr xyz_pos_t tpxy = TOOLCHANGE_PARK_XY;
  2395. toolchange_settings.enable_park = true;
  2396. toolchange_settings.change_point = tpxy;
  2397. #endif
  2398. toolchange_settings.z_raise = TOOLCHANGE_ZRAISE;
  2399. #if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
  2400. migration = migration_defaults;
  2401. #endif
  2402. #endif
  2403. #if ENABLED(BACKLASH_GCODE)
  2404. backlash.correction = (BACKLASH_CORRECTION) * 255;
  2405. constexpr xyz_float_t tmp = BACKLASH_DISTANCE_MM;
  2406. backlash.distance_mm = tmp;
  2407. #ifdef BACKLASH_SMOOTHING_MM
  2408. backlash.smoothing_mm = BACKLASH_SMOOTHING_MM;
  2409. #endif
  2410. #endif
  2411. TERN_(EXTENSIBLE_UI, ExtUI::onFactoryReset());
  2412. TERN_(DWIN_CREALITY_LCD_ENHANCED, DWIN_SetDataDefaults());
  2413. TERN_(DWIN_CREALITY_LCD_JYERSUI, CrealityDWIN.Reset_Settings());
  2414. //
  2415. // Case Light Brightness
  2416. //
  2417. TERN_(CASELIGHT_USES_BRIGHTNESS, caselight.brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS);
  2418. //
  2419. // TOUCH_SCREEN_CALIBRATION
  2420. //
  2421. TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset());
  2422. //
  2423. // Buzzer enable/disable
  2424. //
  2425. TERN_(SOUND_MENU_ITEM, ui.buzzer_enabled = true);
  2426. //
  2427. // Magnetic Parking Extruder
  2428. //
  2429. TERN_(MAGNETIC_PARKING_EXTRUDER, mpe_settings_init());
  2430. //
  2431. // Global Leveling
  2432. //
  2433. TERN_(ENABLE_LEVELING_FADE_HEIGHT, new_z_fade_height = (DEFAULT_LEVELING_FADE_HEIGHT));
  2434. TERN_(HAS_LEVELING, reset_bed_level());
  2435. #if HAS_BED_PROBE
  2436. constexpr float dpo[] = NOZZLE_TO_PROBE_OFFSET;
  2437. static_assert(COUNT(dpo) == LINEAR_AXES, "NOZZLE_TO_PROBE_OFFSET must contain offsets for each linear axis X, Y, Z....");
  2438. #if HAS_PROBE_XY_OFFSET
  2439. LOOP_LINEAR_AXES(a) probe.offset[a] = dpo[a];
  2440. #else
  2441. probe.offset.set(LINEAR_AXIS_LIST(0, 0, dpo[Z_AXIS], 0, 0, 0));
  2442. #endif
  2443. #endif
  2444. //
  2445. // Z Stepper Auto-alignment points
  2446. //
  2447. TERN_(Z_STEPPER_AUTO_ALIGN, z_stepper_align.reset_to_default());
  2448. //
  2449. // Servo Angles
  2450. //
  2451. TERN_(EDITABLE_SERVO_ANGLES, COPY(servo_angles, base_servo_angles)); // When not editable only one copy of servo angles exists
  2452. //
  2453. // Probe Temperature Compensation
  2454. //
  2455. TERN_(HAS_PTC, ptc.reset());
  2456. //
  2457. // BLTOUCH
  2458. //
  2459. //#if ENABLED(BLTOUCH)
  2460. // bltouch.last_written_mode;
  2461. //#endif
  2462. //
  2463. // Kinematic settings
  2464. //
  2465. #if IS_KINEMATIC
  2466. segments_per_second = (
  2467. TERN_(DELTA, DELTA_SEGMENTS_PER_SECOND)
  2468. TERN_(IS_SCARA, SCARA_SEGMENTS_PER_SECOND)
  2469. TERN_(POLARGRAPH, POLAR_SEGMENTS_PER_SECOND)
  2470. );
  2471. #if ENABLED(DELTA)
  2472. const abc_float_t adj = DELTA_ENDSTOP_ADJ, dta = DELTA_TOWER_ANGLE_TRIM, ddr = DELTA_DIAGONAL_ROD_TRIM_TOWER;
  2473. delta_height = DELTA_HEIGHT;
  2474. delta_endstop_adj = adj;
  2475. delta_radius = DELTA_RADIUS;
  2476. delta_diagonal_rod = DELTA_DIAGONAL_ROD;
  2477. delta_tower_angle_trim = dta;
  2478. delta_diagonal_rod_trim = ddr;
  2479. #endif
  2480. #endif
  2481. //
  2482. // Endstop Adjustments
  2483. //
  2484. #if ENABLED(X_DUAL_ENDSTOPS)
  2485. #ifndef X2_ENDSTOP_ADJUSTMENT
  2486. #define X2_ENDSTOP_ADJUSTMENT 0
  2487. #endif
  2488. endstops.x2_endstop_adj = X2_ENDSTOP_ADJUSTMENT;
  2489. #endif
  2490. #if ENABLED(Y_DUAL_ENDSTOPS)
  2491. #ifndef Y2_ENDSTOP_ADJUSTMENT
  2492. #define Y2_ENDSTOP_ADJUSTMENT 0
  2493. #endif
  2494. endstops.y2_endstop_adj = Y2_ENDSTOP_ADJUSTMENT;
  2495. #endif
  2496. #if ENABLED(Z_MULTI_ENDSTOPS)
  2497. #ifndef Z2_ENDSTOP_ADJUSTMENT
  2498. #define Z2_ENDSTOP_ADJUSTMENT 0
  2499. #endif
  2500. endstops.z2_endstop_adj = Z2_ENDSTOP_ADJUSTMENT;
  2501. #if NUM_Z_STEPPER_DRIVERS >= 3
  2502. #ifndef Z3_ENDSTOP_ADJUSTMENT
  2503. #define Z3_ENDSTOP_ADJUSTMENT 0
  2504. #endif
  2505. endstops.z3_endstop_adj = Z3_ENDSTOP_ADJUSTMENT;
  2506. #endif
  2507. #if NUM_Z_STEPPER_DRIVERS >= 4
  2508. #ifndef Z4_ENDSTOP_ADJUSTMENT
  2509. #define Z4_ENDSTOP_ADJUSTMENT 0
  2510. #endif
  2511. endstops.z4_endstop_adj = Z4_ENDSTOP_ADJUSTMENT;
  2512. #endif
  2513. #endif
  2514. //
  2515. // Preheat parameters
  2516. //
  2517. #if HAS_PREHEAT
  2518. #define _PITEM(N,T) PREHEAT_##N##_##T,
  2519. #if HAS_HOTEND
  2520. constexpr uint16_t hpre[] = { REPEAT2_S(1, INCREMENT(PREHEAT_COUNT), _PITEM, TEMP_HOTEND) };
  2521. #endif
  2522. #if HAS_HEATED_BED
  2523. constexpr uint16_t bpre[] = { REPEAT2_S(1, INCREMENT(PREHEAT_COUNT), _PITEM, TEMP_BED) };
  2524. #endif
  2525. #if HAS_FAN
  2526. constexpr uint8_t fpre[] = { REPEAT2_S(1, INCREMENT(PREHEAT_COUNT), _PITEM, FAN_SPEED) };
  2527. #endif
  2528. LOOP_L_N(i, PREHEAT_COUNT) {
  2529. TERN_(HAS_HOTEND, ui.material_preset[i].hotend_temp = hpre[i]);
  2530. TERN_(HAS_HEATED_BED, ui.material_preset[i].bed_temp = bpre[i]);
  2531. TERN_(HAS_FAN, ui.material_preset[i].fan_speed = fpre[i]);
  2532. }
  2533. #endif
  2534. //
  2535. // Hotend PID
  2536. //
  2537. #if ENABLED(PIDTEMP)
  2538. #if ENABLED(PID_PARAMS_PER_HOTEND)
  2539. constexpr float defKp[] =
  2540. #ifdef DEFAULT_Kp_LIST
  2541. DEFAULT_Kp_LIST
  2542. #else
  2543. ARRAY_BY_HOTENDS1(DEFAULT_Kp)
  2544. #endif
  2545. , defKi[] =
  2546. #ifdef DEFAULT_Ki_LIST
  2547. DEFAULT_Ki_LIST
  2548. #else
  2549. ARRAY_BY_HOTENDS1(DEFAULT_Ki)
  2550. #endif
  2551. , defKd[] =
  2552. #ifdef DEFAULT_Kd_LIST
  2553. DEFAULT_Kd_LIST
  2554. #else
  2555. ARRAY_BY_HOTENDS1(DEFAULT_Kd)
  2556. #endif
  2557. ;
  2558. static_assert(WITHIN(COUNT(defKp), 1, HOTENDS), "DEFAULT_Kp_LIST must have between 1 and HOTENDS items.");
  2559. static_assert(WITHIN(COUNT(defKi), 1, HOTENDS), "DEFAULT_Ki_LIST must have between 1 and HOTENDS items.");
  2560. static_assert(WITHIN(COUNT(defKd), 1, HOTENDS), "DEFAULT_Kd_LIST must have between 1 and HOTENDS items.");
  2561. #if ENABLED(PID_EXTRUSION_SCALING)
  2562. constexpr float defKc[] =
  2563. #ifdef DEFAULT_Kc_LIST
  2564. DEFAULT_Kc_LIST
  2565. #else
  2566. ARRAY_BY_HOTENDS1(DEFAULT_Kc)
  2567. #endif
  2568. ;
  2569. static_assert(WITHIN(COUNT(defKc), 1, HOTENDS), "DEFAULT_Kc_LIST must have between 1 and HOTENDS items.");
  2570. #endif
  2571. #if ENABLED(PID_FAN_SCALING)
  2572. constexpr float defKf[] =
  2573. #ifdef DEFAULT_Kf_LIST
  2574. DEFAULT_Kf_LIST
  2575. #else
  2576. ARRAY_BY_HOTENDS1(DEFAULT_Kf)
  2577. #endif
  2578. ;
  2579. static_assert(WITHIN(COUNT(defKf), 1, HOTENDS), "DEFAULT_Kf_LIST must have between 1 and HOTENDS items.");
  2580. #endif
  2581. #define PID_DEFAULT(N,E) def##N[E]
  2582. #else
  2583. #define PID_DEFAULT(N,E) DEFAULT_##N
  2584. #endif
  2585. HOTEND_LOOP() {
  2586. PID_PARAM(Kp, e) = float(PID_DEFAULT(Kp, ALIM(e, defKp)));
  2587. PID_PARAM(Ki, e) = scalePID_i(PID_DEFAULT(Ki, ALIM(e, defKi)));
  2588. PID_PARAM(Kd, e) = scalePID_d(PID_DEFAULT(Kd, ALIM(e, defKd)));
  2589. TERN_(PID_EXTRUSION_SCALING, PID_PARAM(Kc, e) = float(PID_DEFAULT(Kc, ALIM(e, defKc))));
  2590. TERN_(PID_FAN_SCALING, PID_PARAM(Kf, e) = float(PID_DEFAULT(Kf, ALIM(e, defKf))));
  2591. }
  2592. #endif
  2593. //
  2594. // PID Extrusion Scaling
  2595. //
  2596. TERN_(PID_EXTRUSION_SCALING, thermalManager.lpq_len = 20); // Default last-position-queue size
  2597. //
  2598. // Heated Bed PID
  2599. //
  2600. #if ENABLED(PIDTEMPBED)
  2601. thermalManager.temp_bed.pid.Kp = DEFAULT_bedKp;
  2602. thermalManager.temp_bed.pid.Ki = scalePID_i(DEFAULT_bedKi);
  2603. thermalManager.temp_bed.pid.Kd = scalePID_d(DEFAULT_bedKd);
  2604. #endif
  2605. //
  2606. // Heated Chamber PID
  2607. //
  2608. #if ENABLED(PIDTEMPCHAMBER)
  2609. thermalManager.temp_chamber.pid.Kp = DEFAULT_chamberKp;
  2610. thermalManager.temp_chamber.pid.Ki = scalePID_i(DEFAULT_chamberKi);
  2611. thermalManager.temp_chamber.pid.Kd = scalePID_d(DEFAULT_chamberKd);
  2612. #endif
  2613. //
  2614. // User-Defined Thermistors
  2615. //
  2616. TERN_(HAS_USER_THERMISTORS, thermalManager.reset_user_thermistors());
  2617. //
  2618. // Power Monitor
  2619. //
  2620. TERN_(POWER_MONITOR, power_monitor.reset());
  2621. //
  2622. // LCD Contrast
  2623. //
  2624. TERN_(HAS_LCD_CONTRAST, ui.set_contrast(DEFAULT_LCD_CONTRAST));
  2625. //
  2626. // LCD Brightness
  2627. //
  2628. TERN_(HAS_LCD_BRIGHTNESS, ui.set_brightness(DEFAULT_LCD_BRIGHTNESS));
  2629. //
  2630. // Controller Fan
  2631. //
  2632. TERN_(USE_CONTROLLER_FAN, controllerFan.reset());
  2633. //
  2634. // Power-Loss Recovery
  2635. //
  2636. TERN_(POWER_LOSS_RECOVERY, recovery.enable(ENABLED(PLR_ENABLED_DEFAULT)));
  2637. //
  2638. // Firmware Retraction
  2639. //
  2640. TERN_(FWRETRACT, fwretract.reset());
  2641. //
  2642. // Volumetric & Filament Size
  2643. //
  2644. #if DISABLED(NO_VOLUMETRICS)
  2645. parser.volumetric_enabled = ENABLED(VOLUMETRIC_DEFAULT_ON);
  2646. LOOP_L_N(q, COUNT(planner.filament_size))
  2647. planner.filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA;
  2648. #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
  2649. LOOP_L_N(q, COUNT(planner.volumetric_extruder_limit))
  2650. planner.volumetric_extruder_limit[q] = DEFAULT_VOLUMETRIC_EXTRUDER_LIMIT;
  2651. #endif
  2652. #endif
  2653. endstops.enable_globally(ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT));
  2654. reset_stepper_drivers();
  2655. //
  2656. // Linear Advance
  2657. //
  2658. #if ENABLED(LIN_ADVANCE)
  2659. LOOP_L_N(i, EXTRUDERS) {
  2660. planner.extruder_advance_K[i] = LIN_ADVANCE_K;
  2661. TERN_(EXTRA_LIN_ADVANCE_K, other_extruder_advance_K[i] = LIN_ADVANCE_K);
  2662. }
  2663. #endif
  2664. //
  2665. // Motor Current PWM
  2666. //
  2667. #if HAS_MOTOR_CURRENT_PWM
  2668. constexpr uint32_t tmp_motor_current_setting[MOTOR_CURRENT_COUNT] = PWM_MOTOR_CURRENT;
  2669. LOOP_L_N(q, MOTOR_CURRENT_COUNT)
  2670. stepper.set_digipot_current(q, (stepper.motor_current_setting[q] = tmp_motor_current_setting[q]));
  2671. #endif
  2672. //
  2673. // DIGIPOTS
  2674. //
  2675. #if HAS_MOTOR_CURRENT_SPI
  2676. static constexpr uint32_t tmp_motor_current_setting[] = DIGIPOT_MOTOR_CURRENT;
  2677. DEBUG_ECHOLNPGM("Writing Digipot");
  2678. LOOP_L_N(q, COUNT(tmp_motor_current_setting))
  2679. stepper.set_digipot_current(q, tmp_motor_current_setting[q]);
  2680. DEBUG_ECHOLNPGM("Digipot Written");
  2681. #endif
  2682. //
  2683. // CNC Coordinate System
  2684. //
  2685. TERN_(CNC_COORDINATE_SYSTEMS, (void)gcode.select_coordinate_system(-1)); // Go back to machine space
  2686. //
  2687. // Skew Correction
  2688. //
  2689. #if ENABLED(SKEW_CORRECTION_GCODE)
  2690. planner.skew_factor.xy = XY_SKEW_FACTOR;
  2691. #if ENABLED(SKEW_CORRECTION_FOR_Z)
  2692. planner.skew_factor.xz = XZ_SKEW_FACTOR;
  2693. planner.skew_factor.yz = YZ_SKEW_FACTOR;
  2694. #endif
  2695. #endif
  2696. //
  2697. // Advanced Pause filament load & unload lengths
  2698. //
  2699. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  2700. LOOP_L_N(e, EXTRUDERS) {
  2701. fc_settings[e].unload_length = FILAMENT_CHANGE_UNLOAD_LENGTH;
  2702. fc_settings[e].load_length = FILAMENT_CHANGE_FAST_LOAD_LENGTH;
  2703. }
  2704. #endif
  2705. #if ENABLED(PASSWORD_FEATURE)
  2706. #ifdef PASSWORD_DEFAULT_VALUE
  2707. password.is_set = true;
  2708. password.value = PASSWORD_DEFAULT_VALUE;
  2709. #else
  2710. password.is_set = false;
  2711. #endif
  2712. #endif
  2713. //
  2714. // Fan tachometer check
  2715. //
  2716. TERN_(HAS_FANCHECK, fan_check.enabled = true);
  2717. //
  2718. // MKS UI controller
  2719. //
  2720. TERN_(DGUS_LCD_UI_MKS, MKS_reset_settings());
  2721. postprocess();
  2722. DEBUG_ECHO_MSG("Hardcoded Default Settings Loaded");
  2723. }
  2724. #if DISABLED(DISABLE_M503)
  2725. #define CONFIG_ECHO_START() gcode.report_echo_start(forReplay)
  2726. #define CONFIG_ECHO_MSG(V...) do{ CONFIG_ECHO_START(); SERIAL_ECHOLNPGM(V); }while(0)
  2727. #define CONFIG_ECHO_MSG_P(V...) do{ CONFIG_ECHO_START(); SERIAL_ECHOLNPGM_P(V); }while(0)
  2728. #define CONFIG_ECHO_HEADING(STR) gcode.report_heading(forReplay, F(STR))
  2729. void M92_report(const bool echo=true, const int8_t e=-1);
  2730. /**
  2731. * M503 - Report current settings in RAM
  2732. *
  2733. * Unless specifically disabled, M503 is available even without EEPROM
  2734. */
  2735. void MarlinSettings::report(const bool forReplay) {
  2736. //
  2737. // Announce current units, in case inches are being displayed
  2738. //
  2739. CONFIG_ECHO_HEADING("Linear Units");
  2740. #if ENABLED(INCH_MODE_SUPPORT)
  2741. SERIAL_ECHO_MSG(" G2", AS_DIGIT(parser.linear_unit_factor == 1.0), " ;");
  2742. #else
  2743. SERIAL_ECHO_MSG(" G21 ;");
  2744. #endif
  2745. gcode.say_units();
  2746. //
  2747. // M149 Temperature units
  2748. //
  2749. #if ENABLED(TEMPERATURE_UNITS_SUPPORT)
  2750. gcode.M149_report(forReplay);
  2751. #else
  2752. CONFIG_ECHO_HEADING(STR_TEMPERATURE_UNITS);
  2753. CONFIG_ECHO_MSG(" M149 C ; Units in Celsius");
  2754. #endif
  2755. //
  2756. // M200 Volumetric Extrusion
  2757. //
  2758. IF_DISABLED(NO_VOLUMETRICS, gcode.M200_report(forReplay));
  2759. //
  2760. // M92 Steps per Unit
  2761. //
  2762. gcode.M92_report(forReplay);
  2763. //
  2764. // M203 Maximum feedrates (units/s)
  2765. //
  2766. gcode.M203_report(forReplay);
  2767. //
  2768. // M201 Maximum Acceleration (units/s2)
  2769. //
  2770. gcode.M201_report(forReplay);
  2771. //
  2772. // M204 Acceleration (units/s2)
  2773. //
  2774. gcode.M204_report(forReplay);
  2775. //
  2776. // M205 "Advanced" Settings
  2777. //
  2778. gcode.M205_report(forReplay);
  2779. //
  2780. // M206 Home Offset
  2781. //
  2782. TERN_(HAS_M206_COMMAND, gcode.M206_report(forReplay));
  2783. //
  2784. // M218 Hotend offsets
  2785. //
  2786. TERN_(HAS_HOTEND_OFFSET, gcode.M218_report(forReplay));
  2787. //
  2788. // Bed Leveling
  2789. //
  2790. #if HAS_LEVELING
  2791. gcode.M420_report(forReplay);
  2792. #if ENABLED(MESH_BED_LEVELING)
  2793. if (leveling_is_valid()) {
  2794. LOOP_L_N(py, GRID_MAX_POINTS_Y) {
  2795. LOOP_L_N(px, GRID_MAX_POINTS_X) {
  2796. CONFIG_ECHO_START();
  2797. SERIAL_ECHOPGM(" G29 S3 I", px, " J", py);
  2798. SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(mbl.z_values[px][py]), 5);
  2799. }
  2800. }
  2801. CONFIG_ECHO_START();
  2802. SERIAL_ECHOLNPAIR_F(" G29 S4 Z", LINEAR_UNIT(mbl.z_offset), 5);
  2803. }
  2804. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  2805. if (!forReplay) {
  2806. SERIAL_EOL();
  2807. ubl.report_state();
  2808. SERIAL_ECHO_MSG("Active Mesh Slot ", ubl.storage_slot);
  2809. SERIAL_ECHO_MSG("EEPROM can hold ", calc_num_meshes(), " meshes.\n");
  2810. }
  2811. //ubl.report_current_mesh(); // This is too verbose for large meshes. A better (more terse)
  2812. // solution needs to be found.
  2813. #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
  2814. if (leveling_is_valid()) {
  2815. LOOP_L_N(py, GRID_MAX_POINTS_Y) {
  2816. LOOP_L_N(px, GRID_MAX_POINTS_X) {
  2817. CONFIG_ECHO_START();
  2818. SERIAL_ECHOPGM(" G29 W I", px, " J", py);
  2819. SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(z_values[px][py]), 5);
  2820. }
  2821. }
  2822. }
  2823. // TODO: Create G-code for settings
  2824. //#if ENABLED(X_AXIS_TWIST_COMPENSATION)
  2825. // CONFIG_ECHO_START();
  2826. // xatc.print_points();
  2827. //#endif
  2828. #endif
  2829. #endif // HAS_LEVELING
  2830. //
  2831. // Editable Servo Angles
  2832. //
  2833. TERN_(EDITABLE_SERVO_ANGLES, gcode.M281_report(forReplay));
  2834. //
  2835. // Kinematic Settings
  2836. //
  2837. TERN_(IS_KINEMATIC, gcode.M665_report(forReplay));
  2838. //
  2839. // M666 Endstops Adjustment
  2840. //
  2841. #if EITHER(DELTA, HAS_EXTRA_ENDSTOPS)
  2842. gcode.M666_report(forReplay);
  2843. #endif
  2844. //
  2845. // Z Auto-Align
  2846. //
  2847. TERN_(Z_STEPPER_AUTO_ALIGN, gcode.M422_report(forReplay));
  2848. //
  2849. // LCD Preheat Settings
  2850. //
  2851. #if HAS_PREHEAT
  2852. gcode.M145_report(forReplay);
  2853. #endif
  2854. //
  2855. // PID
  2856. //
  2857. TERN_(PIDTEMP, gcode.M301_report(forReplay));
  2858. TERN_(PIDTEMPBED, gcode.M304_report(forReplay));
  2859. TERN_(PIDTEMPCHAMBER, gcode.M309_report(forReplay));
  2860. #if HAS_USER_THERMISTORS
  2861. LOOP_L_N(i, USER_THERMISTORS)
  2862. thermalManager.M305_report(i, forReplay);
  2863. #endif
  2864. //
  2865. // LCD Contrast
  2866. //
  2867. TERN_(HAS_LCD_CONTRAST, gcode.M250_report(forReplay));
  2868. //
  2869. // LCD Brightness
  2870. //
  2871. TERN_(HAS_LCD_BRIGHTNESS, gcode.M256_report(forReplay));
  2872. //
  2873. // Controller Fan
  2874. //
  2875. TERN_(CONTROLLER_FAN_EDITABLE, gcode.M710_report(forReplay));
  2876. //
  2877. // Power-Loss Recovery
  2878. //
  2879. TERN_(POWER_LOSS_RECOVERY, gcode.M413_report(forReplay));
  2880. //
  2881. // Firmware Retraction
  2882. //
  2883. #if ENABLED(FWRETRACT)
  2884. gcode.M207_report(forReplay);
  2885. gcode.M208_report(forReplay);
  2886. TERN_(FWRETRACT_AUTORETRACT, gcode.M209_report(forReplay));
  2887. #endif
  2888. //
  2889. // Probe Offset
  2890. //
  2891. TERN_(HAS_BED_PROBE, gcode.M851_report(forReplay));
  2892. //
  2893. // Bed Skew Correction
  2894. //
  2895. TERN_(SKEW_CORRECTION_GCODE, gcode.M852_report(forReplay));
  2896. #if HAS_TRINAMIC_CONFIG
  2897. //
  2898. // TMC Stepper driver current
  2899. //
  2900. gcode.M906_report(forReplay);
  2901. //
  2902. // TMC Hybrid Threshold
  2903. //
  2904. TERN_(HYBRID_THRESHOLD, gcode.M913_report(forReplay));
  2905. //
  2906. // TMC Sensorless homing thresholds
  2907. //
  2908. TERN_(USE_SENSORLESS, gcode.M914_report(forReplay));
  2909. #endif
  2910. //
  2911. // TMC stepping mode
  2912. //
  2913. TERN_(HAS_STEALTHCHOP, gcode.M569_report(forReplay));
  2914. //
  2915. // Linear Advance
  2916. //
  2917. TERN_(LIN_ADVANCE, gcode.M900_report(forReplay));
  2918. //
  2919. // Motor Current (SPI or PWM)
  2920. //
  2921. #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM
  2922. gcode.M907_report(forReplay);
  2923. #endif
  2924. //
  2925. // Advanced Pause filament load & unload lengths
  2926. //
  2927. TERN_(ADVANCED_PAUSE_FEATURE, gcode.M603_report(forReplay));
  2928. //
  2929. // Tool-changing Parameters
  2930. //
  2931. E_TERN_(gcode.M217_report(forReplay));
  2932. //
  2933. // Backlash Compensation
  2934. //
  2935. TERN_(BACKLASH_GCODE, gcode.M425_report(forReplay));
  2936. //
  2937. // Filament Runout Sensor
  2938. //
  2939. TERN_(HAS_FILAMENT_SENSOR, gcode.M412_report(forReplay));
  2940. #if HAS_ETHERNET
  2941. CONFIG_ECHO_HEADING("Ethernet");
  2942. if (!forReplay) ETH0_report();
  2943. CONFIG_ECHO_START(); SERIAL_ECHO_SP(2); MAC_report();
  2944. CONFIG_ECHO_START(); SERIAL_ECHO_SP(2); gcode.M552_report();
  2945. CONFIG_ECHO_START(); SERIAL_ECHO_SP(2); gcode.M553_report();
  2946. CONFIG_ECHO_START(); SERIAL_ECHO_SP(2); gcode.M554_report();
  2947. #endif
  2948. TERN_(HAS_MULTI_LANGUAGE, gcode.M414_report(forReplay));
  2949. }
  2950. #endif // !DISABLE_M503
  2951. #pragma pack(pop)