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

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