Browse Source

Add a struct defining EEPROM storage

Scott Lahteine 7 years ago
parent
commit
b91ca168fb
2 changed files with 195 additions and 168 deletions
  1. 1
    1
      Marlin/src/gcode/gcode.h
  2. 194
    167
      Marlin/src/module/configuration_store.cpp

+ 1
- 1
Marlin/src/gcode/gcode.h View File

271
     static WorkspacePlane workspace_plane;
271
     static WorkspacePlane workspace_plane;
272
   #endif
272
   #endif
273
 
273
 
274
+  #define MAX_COORDINATE_SYSTEMS 9
274
   #if ENABLED(CNC_COORDINATE_SYSTEMS)
275
   #if ENABLED(CNC_COORDINATE_SYSTEMS)
275
-    #define MAX_COORDINATE_SYSTEMS 9
276
     static int8_t active_coordinate_system;
276
     static int8_t active_coordinate_system;
277
     static float coordinate_system[MAX_COORDINATE_SYSTEMS][XYZ];
277
     static float coordinate_system[MAX_COORDINATE_SYSTEMS][XYZ];
278
     static bool select_coordinate_system(const int8_t _new);
278
     static bool select_coordinate_system(const int8_t _new);

+ 194
- 167
Marlin/src/module/configuration_store.cpp View File

36
  *
36
  *
37
  */
37
  */
38
 
38
 
39
+// Change EEPROM version if the structure changes
39
 #define EEPROM_VERSION "V48"
40
 #define EEPROM_VERSION "V48"
40
-
41
-// Change EEPROM version if these are changed:
42
 #define EEPROM_OFFSET 100
41
 #define EEPROM_OFFSET 100
43
 
42
 
44
-/**
45
- * V48 EEPROM Layout:
46
- *
47
- *  100  Version                                    (char x4)
48
- *  104  EEPROM CRC16                               (uint16_t)
49
- *
50
- *  106            E_STEPPERS                       (uint8_t)
51
- *  107  M92 XYZE  planner.axis_steps_per_mm        (float x4 ... x8) + 64
52
- *  123  M203 XYZE planner.max_feedrate_mm_s        (float x4 ... x8) + 64
53
- *  139  M201 XYZE planner.max_acceleration_mm_per_s2 (uint32_t x4 ... x8) + 64
54
- *  155  M204 P    planner.acceleration             (float)
55
- *  159  M204 R    planner.retract_acceleration     (float)
56
- *  163  M204 T    planner.travel_acceleration      (float)
57
- *  167  M205 S    planner.min_feedrate_mm_s        (float)
58
- *  171  M205 T    planner.min_travel_feedrate_mm_s (float)
59
- *  175  M205 B    planner.min_segment_time_us      (ulong)
60
- *  179  M205 X    planner.max_jerk[X_AXIS]         (float)
61
- *  183  M205 Y    planner.max_jerk[Y_AXIS]         (float)
62
- *  187  M205 Z    planner.max_jerk[Z_AXIS]         (float)
63
- *  191  M205 E    planner.max_jerk[E_AXIS]         (float)
64
- *  195  M206 XYZ  home_offset                      (float x3)
65
- *  207  M218 XYZ  hotend_offset                    (float x3 per additional hotend) +16
66
- *
67
- * Global Leveling:                                 4 bytes
68
- *  219            z_fade_height                    (float)
69
- *
70
- * MESH_BED_LEVELING:                               43 bytes
71
- *  223  M420 S    planner.leveling_active          (bool)
72
- *  224            mbl.z_offset                     (float)
73
- *  228            GRID_MAX_POINTS_X                (uint8_t)
74
- *  229            GRID_MAX_POINTS_Y                (uint8_t)
75
- *  230 G29 S3 XYZ z_values[][]                     (float x9, up to float x81) +288
76
- *
77
- * HAS_BED_PROBE:                                   4 bytes
78
- *  266  M851      zprobe_zoffset                   (float)
79
- *
80
- * ABL_PLANAR:                                      36 bytes
81
- *  270            planner.bed_level_matrix         (matrix_3x3 = float x9)
82
- *
83
- * AUTO_BED_LEVELING_BILINEAR:                      46 bytes
84
- *  306            GRID_MAX_POINTS_X                (uint8_t)
85
- *  307            GRID_MAX_POINTS_Y                (uint8_t)
86
- *  308            bilinear_grid_spacing            (int x2)
87
- *  312  G29 L F   bilinear_start                   (int x2)
88
- *  316            z_values[][]                     (float x9, up to float x256) +988
89
- *
90
- * AUTO_BED_LEVELING_UBL:                           2 bytes
91
- *  352  G29 A     planner.leveling_active          (bool)
92
- *  353  G29 S     ubl.storage_slot                 (int8_t)
93
- *
94
- * DELTA:                                           44 bytes
95
- *  354  M666 H    delta_height                     (float)
96
- *  358  M666 XYZ  delta_endstop_adj                (float x3)
97
- *  370  M665 R    delta_radius                     (float)
98
- *  374  M665 L    delta_diagonal_rod               (float)
99
- *  378  M665 S    delta_segments_per_second        (float)
100
- *  382  M665 B    delta_calibration_radius         (float)
101
- *  386  M665 X    delta_tower_angle_trim[A]        (float)
102
- *  390  M665 Y    delta_tower_angle_trim[B]        (float)
103
- *  394  M665 Z    delta_tower_angle_trim[C]        (float)
104
- *
105
- * [XYZ]_DUAL_ENDSTOPS:                             12 bytes
106
- *  354  M666 X    x_endstop_adj                    (float)
107
- *  358  M666 Y    y_endstop_adj                    (float)
108
- *  362  M666 Z    z_endstop_adj                    (float)
109
- *
110
- * ULTIPANEL:                                       6 bytes
111
- *  398  M145 S0 H lcd_preheat_hotend_temp          (int x2)
112
- *  402  M145 S0 B lcd_preheat_bed_temp             (int x2)
113
- *  406  M145 S0 F lcd_preheat_fan_speed            (int x2)
114
- *
115
- * PIDTEMP:                                         82 bytes
116
- *  410  M301 E0 PIDC  Kp[0], Ki[0], Kd[0], Kc[0]   (float x4)
117
- *  426  M301 E1 PIDC  Kp[1], Ki[1], Kd[1], Kc[1]   (float x4)
118
- *  442  M301 E2 PIDC  Kp[2], Ki[2], Kd[2], Kc[2]   (float x4)
119
- *  458  M301 E3 PIDC  Kp[3], Ki[3], Kd[3], Kc[3]   (float x4)
120
- *  474  M301 E4 PIDC  Kp[3], Ki[3], Kd[3], Kc[3]   (float x4)
121
- *  490  M301 L        lpq_len                      (int)
122
- *
123
- * PIDTEMPBED:                                      12 bytes
124
- *  492  M304 PID  bedKp, .bedKi, .bedKd            (float x3)
125
- *
126
- * DOGLCD:                                          2 bytes
127
- *  504  M250 C    lcd_contrast                     (uint16_t)
128
- *
129
- * FWRETRACT:                                       33 bytes
130
- *  506  M209 S    autoretract_enabled              (bool)
131
- *  507  M207 S    retract_length                   (float)
132
- *  511  M207 F    retract_feedrate_mm_s            (float)
133
- *  515  M207 Z    retract_zlift                    (float)
134
- *  519  M208 S    retract_recover_length           (float)
135
- *  523  M208 F    retract_recover_feedrate_mm_s    (float)
136
- *  527  M207 W    swap_retract_length              (float)
137
- *  531  M208 W    swap_retract_recover_length      (float)
138
- *  535  M208 R    swap_retract_recover_feedrate_mm_s (float)
139
- *
140
- * Volumetric Extrusion:                            21 bytes
141
- *  539  M200 D    parser.volumetric_enabled        (bool)
142
- *  540  M200 T D  planner.filament_size            (float x5) (T0..4)
143
- *
144
- * HAS_TRINAMIC:                                    22 bytes
145
- *  560  M906 X    Stepper X current                (uint16_t)
146
- *  562  M906 Y    Stepper Y current                (uint16_t)
147
- *  564  M906 Z    Stepper Z current                (uint16_t)
148
- *  566  M906 X2   Stepper X2 current               (uint16_t)
149
- *  568  M906 Y2   Stepper Y2 current               (uint16_t)
150
- *  570  M906 Z2   Stepper Z2 current               (uint16_t)
151
- *  572  M906 E0   Stepper E0 current               (uint16_t)
152
- *  574  M906 E1   Stepper E1 current               (uint16_t)
153
- *  576  M906 E2   Stepper E2 current               (uint16_t)
154
- *  578  M906 E3   Stepper E3 current               (uint16_t)
155
- *  580  M906 E4   Stepper E4 current               (uint16_t)
156
- *
157
- * SENSORLESS_HOMING:                               4 bytes
158
- *  582  M914 X    Stepper X and X2 threshold       (int16_t)
159
- *  584  M914 Y    Stepper Y and Y2 threshold       (int16_t)
160
- *
161
- * LIN_ADVANCE:                                     8 bytes
162
- *  586  M900 K    extruder_advance_k               (float)
163
- *  590  M900 WHD  advance_ed_ratio                 (float)
164
- *
165
- * HAS_MOTOR_CURRENT_PWM:
166
- *  594  M907 X    Stepper XY current               (uint32_t)
167
- *  598  M907 Z    Stepper Z current                (uint32_t)
168
- *  602  M907 E    Stepper E current                (uint32_t)
169
- *
170
- * CNC_COORDINATE_SYSTEMS:                          108 bytes
171
- *  606  G54-G59.3 coordinate_system                (float x 27)
172
- *
173
- * SKEW_CORRECTION:                                 12 bytes
174
- *  714  M852 I    planner.xy_skew_factor           (float)
175
- *  718  M852 J    planner.xz_skew_factor           (float)
176
- *  722  M852 K    planner.yz_skew_factor           (float)
177
- *
178
- * ADVANCED_PAUSE_FEATURE:                          40 bytes
179
- *  726  M603 T U  filament_change_unload_length    (float x 5) (T0..4)
180
- *  746  M603 T L  filament_change_load_length      (float x 5) (T0..4)
181
- *
182
- *  766                                   Minimum end-point
183
- * 2295 (766 + 208 + 36 + 9 + 288 + 988)  Maximum end-point
184
- *
185
- * ========================================================================
186
- * meshes_begin (between max and min end-point, directly above)
187
- * -- MESHES --
188
- * meshes_end
189
- * -- MAT (Mesh Allocation Table) --                128 bytes (placeholder size)
190
- * mat_end = E2END (0xFFF)
191
- *
192
- */
193
 #include "configuration_store.h"
43
 #include "configuration_store.h"
194
-
195
-MarlinSettings settings;
196
-
197
 #include "endstops.h"
44
 #include "endstops.h"
198
 #include "planner.h"
45
 #include "planner.h"
199
 #include "stepper.h"
46
 #include "stepper.h"
200
 #include "temperature.h"
47
 #include "temperature.h"
201
 #include "../lcd/ultralcd.h"
48
 #include "../lcd/ultralcd.h"
202
 #include "../core/language.h"
49
 #include "../core/language.h"
50
+#include "../libs/vector_3.h"
51
+#include "../gcode/gcode.h"
203
 #include "../Marlin.h"
52
 #include "../Marlin.h"
204
 
53
 
205
-#include "../gcode/parser.h"
206
-
207
 #if HAS_LEVELING
54
 #if HAS_LEVELING
208
   #include "../feature/bedlevel/bedlevel.h"
55
   #include "../feature/bedlevel/bedlevel.h"
209
 #endif
56
 #endif
220
   #include "../feature/fwretract.h"
67
   #include "../feature/fwretract.h"
221
 #endif
68
 #endif
222
 
69
 
223
-#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
224
-  float new_z_fade_height;
225
-#endif
70
+typedef struct PID { float Kp, Ki, Kd; } PID;
71
+typedef struct PIDC { float Kp, Ki, Kd, Kc; } PIDC;
72
+
73
+/**
74
+ * Current EEPROM Layout
75
+ *
76
+ * Keep this data structure up to date so
77
+ * EEPROM size is known at compile time!
78
+ */
79
+typedef struct SettingsDataStruct {
80
+  char      version[4];                                 // Vnn\0
81
+  uint16_t  crc;                                        // Data Checksum
82
+
83
+  //
84
+  // DISTINCT_E_FACTORS
85
+  //
86
+  uint8_t   esteppers;                                  // XYZE_N - XYZ
87
+
88
+  float     planner_axis_steps_per_mm[XYZE_N],          // M92 XYZE   planner.axis_steps_per_mm[XYZE_N]
89
+            planner_max_feedrate_mm_s[XYZE_N];          // M203 XYZE  planner.max_feedrate_mm_s[XYZE_N]
90
+  uint32_t  planner_max_acceleration_mm_per_s2[XYZE_N]; // M201 XYZE  planner.max_acceleration_mm_per_s2[XYZE_N]
91
+  float     planner_acceleration,                       // M204 P     planner.acceleration
92
+            planner_retract_acceleration,               // M204 R     planner.retract_acceleration
93
+            planner_travel_acceleration,                // M204 T     planner.travel_acceleration
94
+            planner_min_feedrate_mm_s,                  // M205 S     planner.min_feedrate_mm_s
95
+            planner_min_travel_feedrate_mm_s;           // M205 T     planner.min_travel_feedrate_mm_s
96
+  uint32_t  planner_min_segment_time_us;                // M205 B     planner.min_segment_time_us
97
+  float     planner_max_jerk[XYZE];                     // M205 XYZE  planner.max_jerk[XYZE]
98
+
99
+  float home_offset[XYZ];                               // M206 XYZ
100
+
101
+  #if HOTENDS > 1
102
+    float hotend_offset[XYZ][HOTENDS - 1];              // M218 XYZ
103
+  #endif
104
+
105
+  //
106
+  // ENABLE_LEVELING_FADE_HEIGHT
107
+  //
108
+  float planner_z_fade_height;                          // M420 Zn  planner.z_fade_height
109
+
110
+  //
111
+  // MESH_BED_LEVELING
112
+  //
113
+  bool mbl_has_mesh;                                    // mbl.has_mesh
114
+  float mbl_z_offset;                                   // mbl.z_offset
115
+  uint8_t mesh_num_x, mesh_num_y;                       // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y
116
+  #if ENABLED(MESH_BED_LEVELING)
117
+    float mbl_z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y]; // mbl.z_values
118
+  #else
119
+    float mbl_z_values[3][3];
120
+  #endif
121
+
122
+  //
123
+  // HAS_BED_PROBE
124
+  //
125
+  float zprobe_zoffset;                                 // M851 Z
126
+
127
+  //
128
+  // ABL_PLANAR
129
+  //
130
+  matrix_3x3 planner_bed_level_matrix;                  // planner.bed_level_matrix
131
+
132
+  //
133
+  // AUTO_BED_LEVELING_BILINEAR
134
+  //
135
+  uint8_t grid_max_x, grid_max_y;                       // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y
136
+  int bilinear_grid_spacing[2],
137
+      bilinear_start[2];                                // G29 L F
138
+  #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
139
+    float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y]; // G29
140
+  #else
141
+    float z_values[3][3];
142
+  #endif
143
+
144
+  //
145
+  // AUTO_BED_LEVELING_UBL
146
+  //
147
+  bool planner_leveling_active;                         // M420 S  planner.leveling_active
148
+  int8_t ubl_storage_slot;                              // ubl.storage_slot
149
+
150
+  //
151
+  // DELTA / [XYZ]_DUAL_ENDSTOPS
152
+  //
153
+  #if ENABLED(DELTA)
154
+    float delta_height,                                 // M666 H
155
+          delta_endstop_adj[ABC],                       // M666 XYZ
156
+          delta_radius,                                 // M665 R
157
+          delta_diagonal_rod,                           // M665 L
158
+          delta_segments_per_second,                    // M665 S
159
+          delta_calibration_radius,                     // M665 B
160
+          delta_tower_angle_trim[ABC];                  // M665 XYZ
161
+  #elif ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
162
+    float x_endstop_adj,                                // M666 X
163
+          y_endstop_adj,                                // M666 Y
164
+          z_endstop_adj;                                // M666 Z
165
+    float xyz_dual_reserved[8];
166
+  #else
167
+    float xyz_dual_placeholder[11];
168
+  #endif
169
+
170
+  //
171
+  // ULTIPANEL
172
+  //
173
+  int lcd_preheat_hotend_temp[2],                       // M145 S0 H
174
+      lcd_preheat_bed_temp[2],                          // M145 S0 B
175
+      lcd_preheat_fan_speed[2];                         // M145 S0 F
176
+
177
+  //
178
+  // PIDTEMP
179
+  //
180
+  PIDC hotendPID[MAX_EXTRUDERS];                        // M301 En PIDC / M303 En U
181
+
182
+  int lpq_len;                                          // M301 L
183
+
184
+  //
185
+  // PIDTEMPBED
186
+  //
187
+  PID bedPID;                                           // M304 PID / M303 E-1 U
188
+
189
+  //
190
+  // HAS_LCD_CONTRAST
191
+  //
192
+  uint16_t lcd_contrast;                                // M250 C
193
+
194
+  //
195
+  // FWRETRACT
196
+  //
197
+  bool autoretract_enabled;                             // M209 S
198
+  float retract_length,                                 // M207 S
199
+        retract_feedrate_mm_s,                          // M207 F
200
+        retract_zlift,                                  // M207 Z
201
+        retract_recover_length,                         // M208 S
202
+        retract_recover_feedrate_mm_s,                  // M208 F
203
+        swap_retract_length,                            // M207 W
204
+        swap_retract_recover_length,                    // M208 W
205
+        swap_retract_recover_feedrate_mm_s;             // M208 R
206
+
207
+  //
208
+  // !NO_VOLUMETRIC
209
+  //
210
+  bool parser_volumetric_enabled;                       // M200 D  parser.volumetric_enabled
211
+  float planner_filament_size[MAX_EXTRUDERS];           // M200 T D  planner.filament_size[]
212
+
213
+  //
214
+  // HAS_TRINAMIC
215
+  //
216
+  uint16_t tmc_stepper_current[11];                     // M906 X Y Z X2 Y2 Z2 E0 E1 E2 E3 E4
217
+  int16_t tmc_sgt[2];                                   // M914 X Y
218
+
219
+  //
220
+  // LIN_ADVANCE
221
+  //
222
+  float planner_extruder_advance_k,                     // M900 K    planner.extruder_advance_k
223
+        planner_advance_ed_ratio;                       // M900 WHD  planner.advance_ed_ratio
224
+
225
+  //
226
+  // HAS_MOTOR_CURRENT_PWM
227
+  //
228
+  uint32_t motor_current_setting[XYZ];                  // M907 X Z E
229
+
230
+  //
231
+  // CNC_COORDINATE_SYSTEMS
232
+  //
233
+  float coordinate_system[MAX_COORDINATE_SYSTEMS][XYZ]; // G54-G59.3
234
+
235
+  //
236
+  // SKEW_CORRECTION
237
+  //
238
+  float planner_xy_skew_factor,                         // M852 I  planner.xy_skew_factor
239
+        planner_xz_skew_factor,                         // M852 J  planner.xz_skew_factor
240
+        planner_yz_skew_factor;                         // M852 K  planner.yz_skew_factor
241
+
242
+  //
243
+  // ADVANCED_PAUSE_FEATURE
244
+  //
245
+  float filament_change_unload_length[MAX_EXTRUDERS],   // M603 T U
246
+        filament_change_load_length[MAX_EXTRUDERS];     // M603 T L
247
+
248
+} SettingsData;
249
+
250
+MarlinSettings settings;
226
 
251
 
227
 /**
252
 /**
228
  * Post-process after Retrieve or Reset
253
  * Post-process after Retrieve or Reset
229
  */
254
  */
255
+
256
+#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
257
+  float new_z_fade_height;
258
+#endif
259
+
230
 void MarlinSettings::postprocess() {
260
 void MarlinSettings::postprocess() {
231
   const float oldpos[] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] };
261
   const float oldpos[] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] };
232
 
262
 
686
       EEPROM_WRITE(coordinate_system); // 27 floats
716
       EEPROM_WRITE(coordinate_system); // 27 floats
687
     #else
717
     #else
688
       dummy = 0.0f;
718
       dummy = 0.0f;
689
-      for (uint8_t q = 27; q--;) EEPROM_WRITE(dummy);
719
+      for (uint8_t q = MAX_COORDINATE_SYSTEMS * XYZ; q--;) EEPROM_WRITE(dummy);
690
     #endif
720
     #endif
691
 
721
 
692
     //
722
     //
723
     // Validate CRC
753
     // Validate CRC
724
     //
754
     //
725
     if (!eeprom_error) {
755
     if (!eeprom_error) {
726
-      #if ENABLED(EEPROM_CHITCHAT)
727
-        const int eeprom_size = eeprom_index;
728
-      #endif
729
-
730
-      const uint16_t final_crc = working_crc;
756
+      const uint16_t eeprom_size = eeprom_index - (EEPROM_OFFSET),
757
+                     final_crc = working_crc;
731
 
758
 
732
       // Write the EEPROM header
759
       // Write the EEPROM header
733
       eeprom_index = EEPROM_OFFSET;
760
       eeprom_index = EEPROM_OFFSET;
738
       // Report storage size
765
       // Report storage size
739
       #if ENABLED(EEPROM_CHITCHAT)
766
       #if ENABLED(EEPROM_CHITCHAT)
740
         SERIAL_ECHO_START();
767
         SERIAL_ECHO_START();
741
-        SERIAL_ECHOPAIR("Settings Stored (", eeprom_size - (EEPROM_OFFSET));
768
+        SERIAL_ECHOPAIR("Settings Stored (", eeprom_size);
742
         SERIAL_ECHOPAIR(" bytes; crc ", (uint32_t)final_crc);
769
         SERIAL_ECHOPAIR(" bytes; crc ", (uint32_t)final_crc);
743
         SERIAL_ECHOLNPGM(")");
770
         SERIAL_ECHOLNPGM(")");
744
       #endif
771
       #endif
1196
         if (!validating) (void)gcode.select_coordinate_system(-1); // Go back to machine space
1223
         if (!validating) (void)gcode.select_coordinate_system(-1); // Go back to machine space
1197
         EEPROM_READ(gcode.coordinate_system);                  // 27 floats
1224
         EEPROM_READ(gcode.coordinate_system);                  // 27 floats
1198
       #else
1225
       #else
1199
-        for (uint8_t q = 27; q--;) EEPROM_READ(dummy);
1226
+        for (uint8_t q = MAX_COORDINATE_SYSTEMS * XYZ; q--;) EEPROM_READ(dummy);
1200
       #endif
1227
       #endif
1201
 
1228
 
1202
       //
1229
       //

Loading…
Cancel
Save