-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEeprom.h
350 lines (336 loc) · 10.7 KB
/
Eeprom.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/*
This file is part of Repetier-Firmware.
Repetier-Firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Repetier-Firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _EEPROM_H
#define _EEPROM_H
// Id to distinguish version changes
#define EEPROM_PROTOCOL_VERSION 6
/** Where to start with our datablock in memory. Can be moved if you
have problems with other modules using the eeprom */
#define EPR_MAGIC_BYTE 0
#define EPR_ACCELERATION_TYPE 1
#define EPR_XAXIS_STEPS_PER_MM 3
#define EPR_YAXIS_STEPS_PER_MM 7
#define EPR_ZAXIS_STEPS_PER_MM 11
#define EPR_X_MAX_FEEDRATE 15
#define EPR_Y_MAX_FEEDRATE 19
#define EPR_Z_MAX_FEEDRATE 23
#define EPR_X_HOMING_FEEDRATE 27
#define EPR_Y_HOMING_FEEDRATE 31
#define EPR_Z_HOMING_FEEDRATE 35
#define EPR_MAX_JERK 39
//#define EPR_OPS_MIN_DISTANCE 43
#define EPR_MAX_ZJERK 47
#define EPR_X_MAX_ACCEL 51
#define EPR_Y_MAX_ACCEL 55
#define EPR_Z_MAX_ACCEL 59
#define EPR_X_MAX_TRAVEL_ACCEL 63
#define EPR_Y_MAX_TRAVEL_ACCEL 67
#define EPR_Z_MAX_TRAVEL_ACCEL 71
#define EPR_BAUDRATE 75
#define EPR_MAX_INACTIVE_TIME 79
#define EPR_STEPPER_INACTIVE_TIME 83
//#define EPR_OPS_RETRACT_DISTANCE 87
//#define EPR_OPS_RETRACT_BACKLASH 91
#define EPR_EXTRUDER_SPEED 95
//#define EPR_OPS_MOVE_AFTER 99
//#define EPR_OPS_MODE 103
#define EPR_INTEGRITY_BYTE 104 // Here the xored sum over eeprom is stored
#define EPR_VERSION 105 // Version id for updates in EEPROM storage
#define EPR_BED_HEAT_MANAGER 106
#define EPR_BED_DRIVE_MAX 107
#define EPR_BED_PID_PGAIN 108
#define EPR_BED_PID_IGAIN 112
#define EPR_BED_PID_DGAIN 116
#define EPR_BED_PID_MAX 120
#define EPR_BED_DRIVE_MIN 124
#define EPR_PRINTING_TIME 125 // Time in seconds printing
#define EPR_PRINTING_DISTANCE 129 // Filament length printed
#define EPR_X_HOME_OFFSET 133
#define EPR_Y_HOME_OFFSET 137
#define EPR_Z_HOME_OFFSET 141
#define EPR_X_LENGTH 145
#define EPR_Y_LENGTH 149
#define EPR_Z_LENGTH 153
#define EPR_BACKLASH_X 157
#define EPR_BACKLASH_Y 161
#define EPR_BACKLASH_Z 165
#define EPR_Z_PROBE_X_OFFSET 800
#define EPR_Z_PROBE_Y_OFFSET 804
#define EPR_Z_PROBE_HEIGHT 808
#define EPR_Z_PROBE_SPEED 812
#define EPR_Z_PROBE_X1 816
#define EPR_Z_PROBE_Y1 820
#define EPR_Z_PROBE_X2 824
#define EPR_Z_PROBE_Y2 828
#define EPR_Z_PROBE_X3 832
#define EPR_Z_PROBE_Y3 836
#define EPR_Z_PROBE_XY_SPEED 840
#define EPR_AUTOLEVEL_MATRIX 844
#define EPR_AUTOLEVEL_ACTIVE 880
#define EPR_DELTA_DIAGONAL_ROD_LENGTH 881
#define EPR_DELTA_HORIZONTAL_RADIUS 885
#define EPR_DELTA_SEGMENTS_PER_SECOND_PRINT 889
#define EPR_DELTA_SEGMENTS_PER_SECOND_MOVE 891
#define EPR_DELTA_TOWERX_OFFSET_STEPS 893
#define EPR_DELTA_TOWERY_OFFSET_STEPS 895
#define EPR_DELTA_TOWERZ_OFFSET_STEPS 897
#define EPR_DELTA_ALPHA_A 901
#define EPR_DELTA_ALPHA_B 905
#define EPR_DELTA_ALPHA_C 909
#define EPR_DELTA_RADIUS_CORR_A 913
#define EPR_DELTA_RADIUS_CORR_B 917
#define EPR_DELTA_RADIUS_CORR_C 921
#define EEPROM_EXTRUDER_OFFSET 200
// bytes per extruder needed, leave some space for future development
#define EEPROM_EXTRUDER_LENGTH 100
// Extruder positions relative to extruder start
#define EPR_EXTRUDER_STEPS_PER_MM 0
#define EPR_EXTRUDER_MAX_FEEDRATE 4
// Feedrate from halted extruder in mm/s
#define EPR_EXTRUDER_MAX_START_FEEDRATE 8
// Acceleration in mm/s^2
#define EPR_EXTRUDER_MAX_ACCELERATION 12
#define EPR_EXTRUDER_HEAT_MANAGER 16
#define EPR_EXTRUDER_DRIVE_MAX 17
#define EPR_EXTRUDER_PID_PGAIN 18
#define EPR_EXTRUDER_PID_IGAIN 22
#define EPR_EXTRUDER_PID_DGAIN 26
#define EPR_EXTRUDER_PID_MAX 30
#define EPR_EXTRUDER_X_OFFSET 31
#define EPR_EXTRUDER_Y_OFFSET 35
#define EPR_EXTRUDER_WATCH_PERIOD 39
#define EPR_EXTRUDER_ADVANCE_K 41
#define EPR_EXTRUDER_DRIVE_MIN 45
#define EPR_EXTRUDER_ADVANCE_L 46
#define EPR_EXTRUDER_WAIT_RETRACT_TEMP 50
#define EPR_EXTRUDER_WAIT_RETRACT_UNITS 52
#define EPR_EXTRUDER_COOLER_SPEED 54
class EEPROM
{
#if EEPROM_MODE!=0
static uint8_t computeChecksum();
static void writeExtruderPrefix(uint pos);
static void writeFloat(uint pos,PGM_P text,uint8_t digits=3);
static void writeLong(uint pos,PGM_P text);
static void writeInt(uint pos,PGM_P text);
static void writeByte(uint pos,PGM_P text);
#endif
public:
static void init();
static void initBaudrate();
static void storeDataIntoEEPROM(uint8_t corrupted=0);
static void readDataFromEEPROM();
static void restoreEEPROMSettingsFromConfiguration();
static void writeSettings();
static void update(GCode *com);
static void updatePrinterUsage();
static inline float zProbeSpeed() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_Z_PROBE_SPEED);
#else
return Z_PROBE_SPEED;
#endif
}
static inline float zProbeXYSpeed() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_Z_PROBE_XY_SPEED);
#else
return Z_PROBE_XY_SPEED;
#endif
}
static inline float zProbeXOffset() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_Z_PROBE_X_OFFSET);
#else
return Z_PROBE_X_OFFSET;
#endif
}
static inline float zProbeYOffset() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_Z_PROBE_Y_OFFSET);
#else
return Z_PROBE_Y_OFFSET;
#endif
}
static inline float zProbeHeight() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_Z_PROBE_HEIGHT);
#else
return Z_PROBE_HEIGHT;
#endif
}
static inline float zProbeX1() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_Z_PROBE_X1);
#else
return Z_PROBE_X1;
#endif
}
static inline float zProbeY1() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_Z_PROBE_Y1);
#else
return Z_PROBE_Y1;
#endif
}
static inline float zProbeX2() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_Z_PROBE_X2);
#else
return Z_PROBE_X2;
#endif
}
static inline float zProbeY2() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_Z_PROBE_Y2);
#else
return Z_PROBE_Y2;
#endif
}
static inline float zProbeX3() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_Z_PROBE_X3);
#else
return Z_PROBE_X3;
#endif
}
static inline float zProbeY3() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_Z_PROBE_Y3);
#else
return Z_PROBE_Y3;
#endif
}
#if NONLINEAR_SYSTEM
static inline int16_t deltaSegmentsPerSecondMove() {
#if EEPROM_MODE!=0
return HAL::eprGetInt16(EPR_DELTA_SEGMENTS_PER_SECOND_MOVE);
#else
return DELTA_SEGMENTS_PER_SECOND_MOVE;
#endif
}
static inline float deltaDiagonalRodLength() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_DELTA_DIAGONAL_ROD_LENGTH);
#else
return DELTA_DIAGONAL_ROD;
#endif
}
static inline int16_t deltaSegmentsPerSecondPrint() {
#if EEPROM_MODE!=0
return HAL::eprGetInt16(EPR_DELTA_SEGMENTS_PER_SECOND_PRINT);
#else
return DELTA_SEGMENTS_PER_SECOND_PRINT;
#endif
}
#endif
#if DRIVE_SYSTEM==3
static inline float deltaHorizontalRadius() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_DELTA_HORIZONTAL_RADIUS);
#else
return DELTA_RADIUS;
#endif
}
static inline int16_t deltaTowerXOffsetSteps() {
#if EEPROM_MODE!=0
return HAL::eprGetInt16(EPR_DELTA_TOWERX_OFFSET_STEPS);
#else
return DELTA_X_ENDSTOP_OFFSET_STEPS;
#endif
}
static inline int16_t deltaTowerYOffsetSteps() {
#if EEPROM_MODE!=0
return HAL::eprGetInt16(EPR_DELTA_TOWERY_OFFSET_STEPS);
#else
return DELTA_Y_ENDSTOP_OFFSET_STEPS;
#endif
}
static inline int16_t deltaTowerZOffsetSteps() {
#if EEPROM_MODE!=0
return HAL::eprGetInt16(EPR_DELTA_TOWERZ_OFFSET_STEPS);
#else
return DELTA_Z_ENDSTOP_OFFSET_STEPS;
#endif
}
static inline void setDeltaTowerXOffsetSteps(int16_t steps) {
#if EEPROM_MODE!=0
HAL::eprSetInt16(EPR_DELTA_TOWERX_OFFSET_STEPS,steps);
uint8_t newcheck = computeChecksum();
if(newcheck!=HAL::eprGetByte(EPR_INTEGRITY_BYTE))
HAL::eprSetByte(EPR_INTEGRITY_BYTE,newcheck);
#endif
}
static inline void setDeltaTowerYOffsetSteps(int16_t steps) {
#if EEPROM_MODE!=0
HAL::eprSetInt16(EPR_DELTA_TOWERY_OFFSET_STEPS,steps);
uint8_t newcheck = computeChecksum();
if(newcheck!=HAL::eprGetByte(EPR_INTEGRITY_BYTE))
HAL::eprSetByte(EPR_INTEGRITY_BYTE,newcheck);
#endif
}
static inline void setDeltaTowerZOffsetSteps(int16_t steps) {
#if EEPROM_MODE!=0
HAL::eprSetInt16(EPR_DELTA_TOWERZ_OFFSET_STEPS,steps);
uint8_t newcheck = computeChecksum();
if(newcheck!=HAL::eprGetByte(EPR_INTEGRITY_BYTE))
HAL::eprSetByte(EPR_INTEGRITY_BYTE,newcheck);
#endif
}
static inline float deltaAlphaA() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_DELTA_ALPHA_A);
#else
return DELTA_ALPHA_A;
#endif
}
static inline float deltaAlphaB() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_DELTA_ALPHA_B);
#else
return DELTA_ALPHA_B;
#endif
}
static inline float deltaAlphaC() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_DELTA_ALPHA_C);
#else
return DELTA_ALPHA_C;
#endif
}
static inline float deltaRadiusCorrectionA() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_DELTA_RADIUS_CORR_A);
#else
return DELTA_RADIUS_CORRECTION_A;
#endif
}
static inline float deltaRadiusCorrectionB() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_DELTA_RADIUS_CORR_B);
#else
return DELTA_RADIUS_CORRECTION_B;
#endif
}
static inline float deltaRadiusCorrectionC() {
#if EEPROM_MODE!=0
return HAL::eprGetFloat(EPR_DELTA_RADIUS_CORR_C);
#else
return DELTA_RADIUS_CORRECTION_C;
#endif
}
#endif
static void initalizeUncached();
};
#endif