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

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