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

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