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 104KB

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