My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

settings.cpp 104KB

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