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

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