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

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