Переглянути джерело

Merge pull request #4404 from thinkyhead/rc_better_stepper_indirection

Arrange stepper_indirection by axis
Scott Lahteine 8 роки тому
джерело
коміт
54f4f80077
2 змінених файлів з 267 додано та 436 видалено
  1. 1
    0
      Marlin/stepper_indirection.cpp
  2. 266
    436
      Marlin/stepper_indirection.h

+ 1
- 0
Marlin/stepper_indirection.cpp Переглянути файл

@@ -42,6 +42,7 @@
42 42
 */
43 43
 
44 44
 #include "stepper_indirection.h"
45
+
45 46
 #include "Configuration.h"
46 47
 
47 48
 #if ENABLED(HAVE_TMCDRIVER)

+ 266
- 436
Marlin/stepper_indirection.h Переглянути файл

@@ -44,144 +44,311 @@
44 44
 #ifndef STEPPER_INDIRECTION_H
45 45
 #define STEPPER_INDIRECTION_H
46 46
 
47
-#include "macros.h"
47
+#include "Configuration.h"
48 48
 
49
-// X motor
49
+// TMC26X drivers have STEP/DIR on normal pins, but ENABLE via SPI
50
+#if ENABLED(HAVE_TMCDRIVER)
51
+  #include <SPI.h>
52
+  #include <TMC26XStepper.h>
53
+  void tmc_init();
54
+#endif
55
+
56
+// L6470 has STEP on normal pins, but DIR/ENABLE via SPI
57
+#if ENABLED(HAVE_L6470DRIVER)
58
+  #include <SPI.h>
59
+  #include <L6470.h>
60
+  void L6470_init();
61
+#endif
62
+
63
+// X Stepper
64
+#if ENABLED(HAVE_L6470DRIVER) && ENABLED(X_IS_L6470)
65
+  extern L6470 stepperX;
66
+  #define X_ENABLE_INIT NOOP
67
+  #define X_ENABLE_WRITE(STATE) do{if(STATE) stepperX.Step_Clock(stepperX.getStatus() & STATUS_HIZ); else stepperX.softFree();}while(0)
68
+  #define X_ENABLE_READ (stepperX.getStatus() & STATUS_HIZ)
69
+  #define X_DIR_INIT NOOP
70
+  #define X_DIR_WRITE(STATE) stepperX.Step_Clock(STATE)
71
+  #define X_DIR_READ (stepperX.getStatus() & STATUS_DIR)
72
+#else
73
+  #if ENABLED(HAVE_TMCDRIVER) && ENABLED(X_IS_TMC)
74
+    extern TMC26XStepper stepperX;
75
+    #define X_ENABLE_INIT NOOP
76
+    #define X_ENABLE_WRITE(STATE) stepperX.setEnabled(STATE)
77
+    #define X_ENABLE_READ stepperX.isEnabled()
78
+  #else
79
+    #define X_ENABLE_INIT SET_OUTPUT(X_ENABLE_PIN)
80
+    #define X_ENABLE_WRITE(STATE) WRITE(X_ENABLE_PIN,STATE)
81
+    #define X_ENABLE_READ READ(X_ENABLE_PIN)
82
+  #endif
83
+  #define X_DIR_INIT SET_OUTPUT(X_DIR_PIN)
84
+  #define X_DIR_WRITE(STATE) WRITE(X_DIR_PIN,STATE)
85
+  #define X_DIR_READ READ(X_DIR_PIN)
86
+#endif
50 87
 #define X_STEP_INIT SET_OUTPUT(X_STEP_PIN)
51 88
 #define X_STEP_WRITE(STATE) WRITE(X_STEP_PIN,STATE)
52 89
 #define X_STEP_READ READ(X_STEP_PIN)
53 90
 
54
-#define X_DIR_INIT SET_OUTPUT(X_DIR_PIN)
55
-#define X_DIR_WRITE(STATE) WRITE(X_DIR_PIN,STATE)
56
-#define X_DIR_READ READ(X_DIR_PIN)
91
+// Y Stepper
92
+#if ENABLED(HAVE_L6470DRIVER) && ENABLED(Y_IS_L6470)
93
+  extern L6470 stepperY;
94
+  #define Y_ENABLE_INIT NOOP
95
+  #define Y_ENABLE_WRITE(STATE) do{if(STATE) stepperY.Step_Clock(stepperY.getStatus() & STATUS_HIZ); else stepperY.softFree();}while(0)
96
+  #define Y_ENABLE_READ (stepperY.getStatus() & STATUS_HIZ)
97
+  #define Y_DIR_INIT NOOP
98
+  #define Y_DIR_WRITE(STATE) stepperY.Step_Clock(STATE)
99
+  #define Y_DIR_READ (stepperY.getStatus() & STATUS_DIR)
100
+#else
101
+  #if ENABLED(HAVE_TMCDRIVER) && ENABLED(Y_IS_TMC)
102
+    extern TMC26XStepper stepperY;
103
+    #define Y_ENABLE_INIT NOOP
104
+    #define Y_ENABLE_WRITE(STATE) stepperY.setEnabled(STATE)
105
+    #define Y_ENABLE_READ stepperY.isEnabled()
106
+  #else
107
+    #define Y_ENABLE_INIT SET_OUTPUT(Y_ENABLE_PIN)
108
+    #define Y_ENABLE_WRITE(STATE) WRITE(Y_ENABLE_PIN,STATE)
109
+    #define Y_ENABLE_READ READ(Y_ENABLE_PIN)
110
+  #endif
111
+  #define Y_DIR_INIT SET_OUTPUT(Y_DIR_PIN)
112
+  #define Y_DIR_WRITE(STATE) WRITE(Y_DIR_PIN,STATE)
113
+  #define Y_DIR_READ READ(Y_DIR_PIN)
114
+#endif
115
+#define Y_STEP_INIT SET_OUTPUT(Y_STEP_PIN)
116
+#define Y_STEP_WRITE(STATE) WRITE(Y_STEP_PIN,STATE)
117
+#define Y_STEP_READ READ(Y_STEP_PIN)
57 118
 
58
-#define X_ENABLE_INIT SET_OUTPUT(X_ENABLE_PIN)
59
-#define X_ENABLE_WRITE(STATE) WRITE(X_ENABLE_PIN,STATE)
60
-#define X_ENABLE_READ READ(X_ENABLE_PIN)
119
+// Z Stepper
120
+#if ENABLED(HAVE_L6470DRIVER) && ENABLED(Z_IS_L6470)
121
+  extern L6470 stepperZ;
122
+  #define Z_ENABLE_INIT NOOP
123
+  #define Z_ENABLE_WRITE(STATE) do{if(STATE) stepperZ.Step_Clock(stepperZ.getStatus() & STATUS_HIZ); else stepperZ.softFree();}while(0)
124
+  #define Z_ENABLE_READ (stepperZ.getStatus() & STATUS_HIZ)
125
+  #define Z_DIR_INIT NOOP
126
+  #define Z_DIR_WRITE(STATE) stepperZ.Step_Clock(STATE)
127
+  #define Z_DIR_READ (stepperZ.getStatus() & STATUS_DIR)
128
+#else
129
+  #if ENABLED(HAVE_TMCDRIVER) && ENABLED(Z_IS_TMC)
130
+    extern TMC26XStepper stepperZ;
131
+    #define Z_ENABLE_INIT NOOP
132
+    #define Z_ENABLE_WRITE(STATE) stepperZ.setEnabled(STATE)
133
+    #define Z_ENABLE_READ stepperZ.isEnabled()
134
+  #else
135
+    #define Z_ENABLE_INIT SET_OUTPUT(Z_ENABLE_PIN)
136
+    #define Z_ENABLE_WRITE(STATE) WRITE(Z_ENABLE_PIN,STATE)
137
+    #define Z_ENABLE_READ READ(Z_ENABLE_PIN)
138
+  #endif
139
+  #define Z_DIR_INIT SET_OUTPUT(Z_DIR_PIN)
140
+  #define Z_DIR_WRITE(STATE) WRITE(Z_DIR_PIN,STATE)
141
+  #define Z_DIR_READ READ(Z_DIR_PIN)
142
+#endif
143
+#define Z_STEP_INIT SET_OUTPUT(Z_STEP_PIN)
144
+#define Z_STEP_WRITE(STATE) WRITE(Z_STEP_PIN,STATE)
145
+#define Z_STEP_READ READ(Z_STEP_PIN)
61 146
 
62
-// X2 motor
147
+// X2 Stepper
63 148
 #if HAS_X2_ENABLE
149
+  #if ENABLED(HAVE_L6470DRIVER) && ENABLED(X2_IS_L6470)
150
+    extern L6470 stepperX2;
151
+    #define X2_ENABLE_INIT NOOP
152
+    #define X2_ENABLE_WRITE(STATE) do{if(STATE) stepperX2.Step_Clock(stepperX2.getStatus() & STATUS_HIZ); else stepperX2.softFree();}while(0)
153
+    #define X2_ENABLE_READ (stepperX2.getStatus() & STATUS_HIZ)
154
+    #define X2_DIR_INIT NOOP
155
+    #define X2_DIR_WRITE(STATE) stepperX2.Step_Clock(STATE)
156
+    #define X2_DIR_READ (stepperX2.getStatus() & STATUS_DIR)
157
+  #else
158
+    #if ENABLED(HAVE_TMCDRIVER) && ENABLED(X2_IS_TMC)
159
+      extern TMC26XStepper stepperX2;
160
+      #define X2_ENABLE_INIT NOOP
161
+      #define X2_ENABLE_WRITE(STATE) stepperX2.setEnabled(STATE)
162
+      #define X2_ENABLE_READ stepperX2.isEnabled()
163
+    #else
164
+      #define X2_ENABLE_INIT SET_OUTPUT(X2_ENABLE_PIN)
165
+      #define X2_ENABLE_WRITE(STATE) WRITE(X2_ENABLE_PIN,STATE)
166
+      #define X2_ENABLE_READ READ(X2_ENABLE_PIN)
167
+    #endif
168
+    #define X2_DIR_INIT SET_OUTPUT(X2_DIR_PIN)
169
+    #define X2_DIR_WRITE(STATE) WRITE(X2_DIR_PIN,STATE)
170
+    #define X2_DIR_READ READ(X2_DIR_PIN)
171
+  #endif
64 172
   #define X2_STEP_INIT SET_OUTPUT(X2_STEP_PIN)
65 173
   #define X2_STEP_WRITE(STATE) WRITE(X2_STEP_PIN,STATE)
66 174
   #define X2_STEP_READ READ(X2_STEP_PIN)
67
-
68
-  #define X2_DIR_INIT SET_OUTPUT(X2_DIR_PIN)
69
-  #define X2_DIR_WRITE(STATE) WRITE(X2_DIR_PIN,STATE)
70
-  #define X2_DIR_READ READ(X_DIR_PIN)
71
-
72
-  #define X2_ENABLE_INIT SET_OUTPUT(X2_ENABLE_PIN)
73
-  #define X2_ENABLE_WRITE(STATE) WRITE(X2_ENABLE_PIN,STATE)
74
-  #define X2_ENABLE_READ READ(X_ENABLE_PIN)
75 175
 #endif
76 176
 
77
-// Y motor
78
-#define Y_STEP_INIT SET_OUTPUT(Y_STEP_PIN)
79
-#define Y_STEP_WRITE(STATE) WRITE(Y_STEP_PIN,STATE)
80
-#define Y_STEP_READ READ(Y_STEP_PIN)
81
-
82
-#define Y_DIR_INIT SET_OUTPUT(Y_DIR_PIN)
83
-#define Y_DIR_WRITE(STATE) WRITE(Y_DIR_PIN,STATE)
84
-#define Y_DIR_READ READ(Y_DIR_PIN)
85
-
86
-#define Y_ENABLE_INIT SET_OUTPUT(Y_ENABLE_PIN)
87
-#define Y_ENABLE_WRITE(STATE) WRITE(Y_ENABLE_PIN,STATE)
88
-#define Y_ENABLE_READ READ(Y_ENABLE_PIN)
89
-
90
-// Y2 motor
177
+// Y2 Stepper
91 178
 #if HAS_Y2_ENABLE
179
+  #if ENABLED(HAVE_L6470DRIVER) && ENABLED(Y2_IS_L6470)
180
+    extern L6470 stepperY2;
181
+    #define Y2_ENABLE_INIT NOOP
182
+    #define Y2_ENABLE_WRITE(STATE) do{if(STATE) stepperY2.Step_Clock(stepperY2.getStatus() & STATUS_HIZ); else stepperY2.softFree();}while(0)
183
+    #define Y2_ENABLE_READ (stepperY2.getStatus() & STATUS_HIZ)
184
+    #define Y2_DIR_INIT NOOP
185
+    #define Y2_DIR_WRITE(STATE) stepperY2.Step_Clock(STATE)
186
+    #define Y2_DIR_READ (stepperY2.getStatus() & STATUS_DIR)
187
+  #else
188
+    #if ENABLED(HAVE_TMCDRIVER) && ENABLED(Y2_IS_TMC)
189
+      extern TMC26XStepper stepperY2;
190
+      #define Y2_ENABLE_INIT NOOP
191
+      #define Y2_ENABLE_WRITE(STATE) stepperY2.setEnabled(STATE)
192
+      #define Y2_ENABLE_READ stepperY2.isEnabled()
193
+    #else
194
+      #define Y2_ENABLE_INIT SET_OUTPUT(Y2_ENABLE_PIN)
195
+      #define Y2_ENABLE_WRITE(STATE) WRITE(Y2_ENABLE_PIN,STATE)
196
+      #define Y2_ENABLE_READ READ(Y2_ENABLE_PIN)
197
+    #endif
198
+    #define Y2_DIR_INIT SET_OUTPUT(Y2_DIR_PIN)
199
+    #define Y2_DIR_WRITE(STATE) WRITE(Y2_DIR_PIN,STATE)
200
+    #define Y2_DIR_READ READ(Y2_DIR_PIN)
201
+  #endif
92 202
   #define Y2_STEP_INIT SET_OUTPUT(Y2_STEP_PIN)
93 203
   #define Y2_STEP_WRITE(STATE) WRITE(Y2_STEP_PIN,STATE)
94 204
   #define Y2_STEP_READ READ(Y2_STEP_PIN)
205
+#endif
95 206
 
96
-  #define Y2_DIR_INIT SET_OUTPUT(Y2_DIR_PIN)
97
-  #define Y2_DIR_WRITE(STATE) WRITE(Y2_DIR_PIN,STATE)
98
-  #define Y2_DIR_READ READ(Y2_DIR_PIN)
99
-
100
-  #define Y2_ENABLE_INIT SET_OUTPUT(Y2_ENABLE_PIN)
101
-  #define Y2_ENABLE_WRITE(STATE) WRITE(Y2_ENABLE_PIN,STATE)
102
-  #define Y2_ENABLE_READ READ(Y2_ENABLE_PIN)
103
-#endif // Y_DUAL_STEPPER_DRIVERS
104
-
105
-// Z motor
106
-#define Z_STEP_INIT SET_OUTPUT(Z_STEP_PIN)
107
-#define Z_STEP_WRITE(STATE) WRITE(Z_STEP_PIN,STATE)
108
-#define Z_STEP_READ READ(Z_STEP_PIN)
109
-
110
-#define Z_DIR_INIT SET_OUTPUT(Z_DIR_PIN)
111
-#define Z_DIR_WRITE(STATE) WRITE(Z_DIR_PIN,STATE)
112
-#define Z_DIR_READ READ(Z_DIR_PIN)
113
-
114
-#define Z_ENABLE_INIT SET_OUTPUT(Z_ENABLE_PIN)
115
-#define Z_ENABLE_WRITE(STATE) WRITE(Z_ENABLE_PIN,STATE)
116
-#define Z_ENABLE_READ READ(Z_ENABLE_PIN)
117
-
118
-// Z2 motor
207
+// Z2 Stepper
119 208
 #if HAS_Z2_ENABLE
209
+  #if ENABLED(HAVE_L6470DRIVER) && ENABLED(Z2_IS_L6470)
210
+    extern L6470 stepperZ2;
211
+    #define Z2_ENABLE_INIT NOOP
212
+    #define Z2_ENABLE_WRITE(STATE) do{if(STATE) stepperZ2.Step_Clock(stepperZ2.getStatus() & STATUS_HIZ); else stepperZ2.softFree();}while(0)
213
+    #define Z2_ENABLE_READ (stepperZ2.getStatus() & STATUS_HIZ)
214
+    #define Z2_DIR_INIT NOOP
215
+    #define Z2_DIR_WRITE(STATE) stepperZ2.Step_Clock(STATE)
216
+    #define Z2_DIR_READ (stepperZ2.getStatus() & STATUS_DIR)
217
+  #else
218
+    #if ENABLED(HAVE_TMCDRIVER) && ENABLED(Z2_IS_TMC)
219
+      extern TMC26XStepper stepperZ2;
220
+      #define Z2_ENABLE_INIT NOOP
221
+      #define Z2_ENABLE_WRITE(STATE) stepperZ2.setEnabled(STATE)
222
+      #define Z2_ENABLE_READ stepperZ2.isEnabled()
223
+    #else
224
+      #define Z2_ENABLE_INIT SET_OUTPUT(Z2_ENABLE_PIN)
225
+      #define Z2_ENABLE_WRITE(STATE) WRITE(Z2_ENABLE_PIN,STATE)
226
+      #define Z2_ENABLE_READ READ(Z2_ENABLE_PIN)
227
+    #endif
228
+    #define Z2_DIR_INIT SET_OUTPUT(Z2_DIR_PIN)
229
+    #define Z2_DIR_WRITE(STATE) WRITE(Z2_DIR_PIN,STATE)
230
+    #define Z2_DIR_READ READ(Z2_DIR_PIN)
231
+  #endif
120 232
   #define Z2_STEP_INIT SET_OUTPUT(Z2_STEP_PIN)
121 233
   #define Z2_STEP_WRITE(STATE) WRITE(Z2_STEP_PIN,STATE)
122 234
   #define Z2_STEP_READ READ(Z2_STEP_PIN)
235
+#endif
123 236
 
124
-  #define Z2_DIR_INIT SET_OUTPUT(Z2_DIR_PIN)
125
-  #define Z2_DIR_WRITE(STATE) WRITE(Z2_DIR_PIN,STATE)
126
-  #define Z2_DIR_READ READ(Z2_DIR_PIN)
127
-
128
-  #define Z2_ENABLE_INIT SET_OUTPUT(Z2_ENABLE_PIN)
129
-  #define Z2_ENABLE_WRITE(STATE) WRITE(Z2_ENABLE_PIN,STATE)
130
-  #define Z2_ENABLE_READ READ(Z2_ENABLE_PIN)
131
-#endif // Z_DUAL_STEPPER_DRIVERS
132
-
133
-// E0 motor
237
+// E0 Stepper
238
+#if ENABLED(HAVE_L6470DRIVER) && ENABLED(E0_IS_L6470)
239
+  extern L6470 stepperE0;
240
+  #define E0_ENABLE_INIT NOOP
241
+  #define E0_ENABLE_WRITE(STATE) do{if(STATE) stepperE0.Step_Clock(stepperE0.getStatus() & STATUS_HIZ); else stepperE0.softFree();}while(0)
242
+  #define E0_ENABLE_READ (stepperE0.getStatus() & STATUS_HIZ)
243
+  #define E0_DIR_INIT NOOP
244
+  #define E0_DIR_WRITE(STATE) stepperE0.Step_Clock(STATE)
245
+  #define E0_DIR_READ (stepperE0.getStatus() & STATUS_DIR)
246
+#else
247
+  #if ENABLED(HAVE_TMCDRIVER) && ENABLED(E0_IS_TMC)
248
+    extern TMC26XStepper stepperE0;
249
+    #define E0_ENABLE_INIT NOOP
250
+    #define E0_ENABLE_WRITE(STATE) stepperE0.setEnabled(STATE)
251
+    #define E0_ENABLE_READ stepperE0.isEnabled()
252
+  #else
253
+    #define E0_ENABLE_INIT SET_OUTPUT(E0_ENABLE_PIN)
254
+    #define E0_ENABLE_WRITE(STATE) WRITE(E0_ENABLE_PIN,STATE)
255
+    #define E0_ENABLE_READ READ(E0_ENABLE_PIN)
256
+  #endif
257
+  #define E0_DIR_INIT SET_OUTPUT(E0_DIR_PIN)
258
+  #define E0_DIR_WRITE(STATE) WRITE(E0_DIR_PIN,STATE)
259
+  #define E0_DIR_READ READ(E0_DIR_PIN)
260
+#endif
134 261
 #define E0_STEP_INIT SET_OUTPUT(E0_STEP_PIN)
135 262
 #define E0_STEP_WRITE(STATE) WRITE(E0_STEP_PIN,STATE)
136 263
 #define E0_STEP_READ READ(E0_STEP_PIN)
137 264
 
138
-#define E0_DIR_INIT SET_OUTPUT(E0_DIR_PIN)
139
-#define E0_DIR_WRITE(STATE) WRITE(E0_DIR_PIN,STATE)
140
-#define E0_DIR_READ READ(E0_DIR_PIN)
141
-
142
-#define E0_ENABLE_INIT SET_OUTPUT(E0_ENABLE_PIN)
143
-#define E0_ENABLE_WRITE(STATE) WRITE(E0_ENABLE_PIN,STATE)
144
-#define E0_ENABLE_READ READ(E0_ENABLE_PIN)
145
-
146
-// E1 motor
265
+// E1 Stepper
266
+#if ENABLED(HAVE_L6470DRIVER) && ENABLED(E1_IS_L6470)
267
+  extern L6470 stepperE1;
268
+  #define E1_ENABLE_INIT NOOP
269
+  #define E1_ENABLE_WRITE(STATE) do{if(STATE) stepperE1.Step_Clock(stepperE1.getStatus() & STATUS_HIZ); else stepperE1.softFree();}while(0)
270
+  #define E1_ENABLE_READ (stepperE1.getStatus() & STATUS_HIZ)
271
+  #define E1_DIR_INIT NOOP
272
+  #define E1_DIR_WRITE(STATE) stepperE1.Step_Clock(STATE)
273
+  #define E1_DIR_READ (stepperE1.getStatus() & STATUS_DIR)
274
+#else
275
+  #if ENABLED(HAVE_TMCDRIVER) && ENABLED(E1_IS_TMC)
276
+    extern TMC26XStepper stepperE1;
277
+    #define E1_ENABLE_INIT NOOP
278
+    #define E1_ENABLE_WRITE(STATE) stepperE1.setEnabled(STATE)
279
+    #define E1_ENABLE_READ stepperE1.isEnabled()
280
+  #else
281
+    #define E1_ENABLE_INIT SET_OUTPUT(E1_ENABLE_PIN)
282
+    #define E1_ENABLE_WRITE(STATE) WRITE(E1_ENABLE_PIN,STATE)
283
+    #define E1_ENABLE_READ READ(E1_ENABLE_PIN)
284
+  #endif
285
+  #define E1_DIR_INIT SET_OUTPUT(E1_DIR_PIN)
286
+  #define E1_DIR_WRITE(STATE) WRITE(E1_DIR_PIN,STATE)
287
+  #define E1_DIR_READ READ(E1_DIR_PIN)
288
+#endif
147 289
 #define E1_STEP_INIT SET_OUTPUT(E1_STEP_PIN)
148 290
 #define E1_STEP_WRITE(STATE) WRITE(E1_STEP_PIN,STATE)
149 291
 #define E1_STEP_READ READ(E1_STEP_PIN)
150 292
 
151
-#define E1_DIR_INIT SET_OUTPUT(E1_DIR_PIN)
152
-#define E1_DIR_WRITE(STATE) WRITE(E1_DIR_PIN,STATE)
153
-#define E1_DIR_READ READ(E1_DIR_PIN)
154
-
155
-#define E1_ENABLE_INIT SET_OUTPUT(E1_ENABLE_PIN)
156
-#define E1_ENABLE_WRITE(STATE) WRITE(E1_ENABLE_PIN,STATE)
157
-#define E1_ENABLE_READ READ(E1_ENABLE_PIN)
158
-
159
-// E2 motor
293
+// E2 Stepper
294
+#if ENABLED(HAVE_L6470DRIVER) && ENABLED(E2_IS_L6470)
295
+  extern L6470 stepperE2;
296
+  #define E2_ENABLE_INIT NOOP
297
+  #define E2_ENABLE_WRITE(STATE) do{if(STATE) stepperE2.Step_Clock(stepperE2.getStatus() & STATUS_HIZ); else stepperE2.softFree();}while(0)
298
+  #define E2_ENABLE_READ (stepperE2.getStatus() & STATUS_HIZ)
299
+  #define E2_DIR_INIT NOOP
300
+  #define E2_DIR_WRITE(STATE) stepperE2.Step_Clock(STATE)
301
+  #define E2_DIR_READ (stepperE2.getStatus() & STATUS_DIR)
302
+#else
303
+  #if ENABLED(HAVE_TMCDRIVER) && ENABLED(E2_IS_TMC)
304
+    extern TMC26XStepper stepperE2;
305
+    #define E2_ENABLE_INIT NOOP
306
+    #define E2_ENABLE_WRITE(STATE) stepperE2.setEnabled(STATE)
307
+    #define E2_ENABLE_READ stepperE2.isEnabled()
308
+  #else
309
+    #define E2_ENABLE_INIT SET_OUTPUT(E2_ENABLE_PIN)
310
+    #define E2_ENABLE_WRITE(STATE) WRITE(E2_ENABLE_PIN,STATE)
311
+    #define E2_ENABLE_READ READ(E2_ENABLE_PIN)
312
+  #endif
313
+  #define E2_DIR_INIT SET_OUTPUT(E2_DIR_PIN)
314
+  #define E2_DIR_WRITE(STATE) WRITE(E2_DIR_PIN,STATE)
315
+  #define E2_DIR_READ READ(E2_DIR_PIN)
316
+#endif
160 317
 #define E2_STEP_INIT SET_OUTPUT(E2_STEP_PIN)
161 318
 #define E2_STEP_WRITE(STATE) WRITE(E2_STEP_PIN,STATE)
162 319
 #define E2_STEP_READ READ(E2_STEP_PIN)
163 320
 
164
-#define E2_DIR_INIT SET_OUTPUT(E2_DIR_PIN)
165
-#define E2_DIR_WRITE(STATE) WRITE(E2_DIR_PIN,STATE)
166
-#define E2_DIR_READ READ(E2_DIR_PIN)
167
-
168
-#define E2_ENABLE_INIT SET_OUTPUT(E2_ENABLE_PIN)
169
-#define E2_ENABLE_WRITE(STATE) WRITE(E2_ENABLE_PIN,STATE)
170
-#define E2_ENABLE_READ READ(E2_ENABLE_PIN)
171
-
172
-// E3 motor
321
+// E3 Stepper
322
+#if ENABLED(HAVE_L6470DRIVER) && ENABLED(E3_IS_L6470)
323
+  extern L6470 stepperE3;
324
+  #define E3_ENABLE_INIT NOOP
325
+  #define E3_ENABLE_WRITE(STATE) do{if(STATE) stepperE3.Step_Clock(stepperE3.getStatus() & STATUS_HIZ); else stepperE3.softFree();}while(0)
326
+  #define E3_ENABLE_READ (stepperE3.getStatus() & STATUS_HIZ)
327
+  #define E3_DIR_INIT NOOP
328
+  #define E3_DIR_WRITE(STATE) stepperE3.Step_Clock(STATE)
329
+  #define E3_DIR_READ (stepperE3.getStatus() & STATUS_DIR)
330
+#else
331
+  #if ENABLED(HAVE_TMCDRIVER) && ENABLED(E3_IS_TMC)
332
+    extern TMC26XStepper stepperE3;
333
+    #define E3_ENABLE_INIT NOOP
334
+    #define E3_ENABLE_WRITE(STATE) stepperE3.setEnabled(STATE)
335
+    #define E3_ENABLE_READ stepperE3.isEnabled()
336
+  #else
337
+    #define E3_ENABLE_INIT SET_OUTPUT(E3_ENABLE_PIN)
338
+    #define E3_ENABLE_WRITE(STATE) WRITE(E3_ENABLE_PIN,STATE)
339
+    #define E3_ENABLE_READ READ(E3_ENABLE_PIN)
340
+  #endif
341
+  #define E3_DIR_INIT SET_OUTPUT(E3_DIR_PIN)
342
+  #define E3_DIR_WRITE(STATE) WRITE(E3_DIR_PIN,STATE)
343
+  #define E3_DIR_READ READ(E3_DIR_PIN)
344
+#endif
173 345
 #define E3_STEP_INIT SET_OUTPUT(E3_STEP_PIN)
174 346
 #define E3_STEP_WRITE(STATE) WRITE(E3_STEP_PIN,STATE)
175 347
 #define E3_STEP_READ READ(E3_STEP_PIN)
176 348
 
177
-#define E3_DIR_INIT SET_OUTPUT(E3_DIR_PIN)
178
-#define E3_DIR_WRITE(STATE) WRITE(E3_DIR_PIN,STATE)
179
-#define E3_DIR_READ READ(E3_DIR_PIN)
180
-
181
-#define E3_ENABLE_INIT SET_OUTPUT(E3_ENABLE_PIN)
182
-#define E3_ENABLE_WRITE(STATE) WRITE(E3_ENABLE_PIN,STATE)
183
-#define E3_ENABLE_READ READ(E3_ENABLE_PIN)
184
-
349
+/**
350
+ * Extruder indirection for the single E axis
351
+ */
185 352
 #if ENABLED(SWITCHING_EXTRUDER)
186 353
   #define E_STEP_WRITE(v) E0_STEP_WRITE(v)
187 354
   #define NORM_E_DIR() E0_DIR_WRITE(current_block->active_extruder ?  INVERT_E0_DIR : !INVERT_E0_DIR)
@@ -225,341 +392,4 @@
225 392
   #define REV_E_DIR() E0_DIR_WRITE(INVERT_E0_DIR)
226 393
 #endif
227 394
 
228
-//////////////////////////////////
229
-// Pin redefines for TMC drivers.
230
-// TMC26X drivers have step and dir on normal pins, but everything else via SPI
231
-//////////////////////////////////
232
-#if ENABLED(HAVE_TMCDRIVER)
233
-  #include <SPI.h>
234
-  #include <TMC26XStepper.h>
235
-
236
-  void tmc_init();
237
-  #if ENABLED(X_IS_TMC)
238
-    extern TMC26XStepper stepperX;
239
-    #undef X_ENABLE_INIT
240
-    #define X_ENABLE_INIT ((void)0)
241
-
242
-    #undef X_ENABLE_WRITE
243
-    #define X_ENABLE_WRITE(STATE) stepperX.setEnabled(STATE)
244
-
245
-    #undef X_ENABLE_READ
246
-    #define X_ENABLE_READ stepperX.isEnabled()
247
-
248
-  #endif
249
-  #if ENABLED(X2_IS_TMC)
250
-    extern TMC26XStepper stepperX2;
251
-    #undef X2_ENABLE_INIT
252
-    #define X2_ENABLE_INIT ((void)0)
253
-
254
-    #undef X2_ENABLE_WRITE
255
-    #define X2_ENABLE_WRITE(STATE) stepperX2.setEnabled(STATE)
256
-
257
-    #undef X2_ENABLE_READ
258
-    #define X2_ENABLE_READ stepperX2.isEnabled()
259
-  #endif
260
-  #if ENABLED(Y_IS_TMC)
261
-    extern TMC26XStepper stepperY;
262
-    #undef Y_ENABLE_INIT
263
-    #define Y_ENABLE_INIT ((void)0)
264
-
265
-    #undef Y_ENABLE_WRITE
266
-    #define Y_ENABLE_WRITE(STATE) stepperY.setEnabled(STATE)
267
-
268
-    #undef Y_ENABLE_READ
269
-    #define Y_ENABLE_READ stepperY.isEnabled()
270
-  #endif
271
-  #if ENABLED(Y2_IS_TMC)
272
-    extern TMC26XStepper stepperY2;
273
-    #undef Y2_ENABLE_INIT
274
-    #define Y2_ENABLE_INIT ((void)0)
275
-
276
-    #undef Y2_ENABLE_WRITE
277
-    #define Y2_ENABLE_WRITE(STATE) stepperY2.setEnabled(STATE)
278
-
279
-    #undef Y2_ENABLE_READ
280
-    #define Y2_ENABLE_READ stepperY2.isEnabled()
281
-  #endif
282
-  #if ENABLED(Z_IS_TMC)
283
-    extern TMC26XStepper stepperZ;
284
-    #undef Z_ENABLE_INIT
285
-    #define Z_ENABLE_INIT ((void)0)
286
-
287
-    #undef Z_ENABLE_WRITE
288
-    #define Z_ENABLE_WRITE(STATE) stepperZ.setEnabled(STATE)
289
-
290
-    #undef Z_ENABLE_READ
291
-    #define Z_ENABLE_READ stepperZ.isEnabled()
292
-  #endif
293
-  #if ENABLED(Z2_IS_TMC)
294
-    extern TMC26XStepper stepperZ2;
295
-    #undef Z2_ENABLE_INIT
296
-    #define Z2_ENABLE_INIT ((void)0)
297
-
298
-    #undef Z2_ENABLE_WRITE
299
-    #define Z2_ENABLE_WRITE(STATE) stepperZ2.setEnabled(STATE)
300
-
301
-    #undef Z2_ENABLE_READ
302
-    #define Z2_ENABLE_READ stepperZ2.isEnabled()
303
-  #endif
304
-  #if ENABLED(E0_IS_TMC)
305
-    extern TMC26XStepper stepperE0;
306
-    #undef E0_ENABLE_INIT
307
-    #define E0_ENABLE_INIT ((void)0)
308
-
309
-    #undef E0_ENABLE_WRITE
310
-    #define E0_ENABLE_WRITE(STATE) stepperE0.setEnabled(STATE)
311
-
312
-    #undef E0_ENABLE_READ
313
-    #define E0_ENABLE_READ stepperE0.isEnabled()
314
-  #endif
315
-  #if ENABLED(E1_IS_TMC)
316
-    extern TMC26XStepper stepperE1;
317
-    #undef E1_ENABLE_INIT
318
-    #define E1_ENABLE_INIT ((void)0)
319
-
320
-    #undef E1_ENABLE_WRITE
321
-    #define E1_ENABLE_WRITE(STATE) stepperE1.setEnabled(STATE)
322
-
323
-    #undef E1_ENABLE_READ
324
-    #define E1_ENABLE_READ stepperE1.isEnabled()
325
-  #endif
326
-  #if ENABLED(E2_IS_TMC)
327
-    extern TMC26XStepper stepperE2;
328
-    #undef E2_ENABLE_INIT
329
-    #define E2_ENABLE_INIT ((void)0)
330
-
331
-    #undef E2_ENABLE_WRITE
332
-    #define E2_ENABLE_WRITE(STATE) stepperE2.setEnabled(STATE)
333
-
334
-    #undef E2_ENABLE_READ
335
-    #define E2_ENABLE_READ stepperE2.isEnabled()
336
-  #endif
337
-  #if ENABLED(E3_IS_TMC)
338
-    extern TMC26XStepper stepperE3;
339
-    #undef E3_ENABLE_INIT
340
-    #define E3_ENABLE_INIT ((void)0)
341
-
342
-    #undef E3_ENABLE_WRITE
343
-    #define E3_ENABLE_WRITE(STATE) stepperE3.setEnabled(STATE)
344
-
345
-    #undef E3_ENABLE_READ
346
-    #define E3_ENABLE_READ stepperE3.isEnabled()
347
-  #endif
348
-
349
-#endif  // HAVE_TMCDRIVER
350
-
351
-//////////////////////////////////
352
-// Pin redefines for L6470 drivers.
353
-// L640 drivers have step on normal pins, but dir and everything else via SPI
354
-//////////////////////////////////
355
-#if ENABLED(HAVE_L6470DRIVER)
356
-
357
-  #include <SPI.h>
358
-  #include <L6470.h>
359
-
360
-  void L6470_init();
361
-  #if ENABLED(X_IS_L6470)
362
-    extern L6470 stepperX;
363
-    #undef X_ENABLE_INIT
364
-    #define X_ENABLE_INIT ((void)0)
365
-
366
-    #undef X_ENABLE_WRITE
367
-    #define X_ENABLE_WRITE(STATE) {if(STATE) stepperX.Step_Clock(stepperX.getStatus() & STATUS_HIZ); else stepperX.softFree();}
368
-
369
-    #undef X_ENABLE_READ
370
-    #define X_ENABLE_READ (stepperX.getStatus() & STATUS_HIZ)
371
-
372
-    #undef X_DIR_INIT
373
-    #define X_DIR_INIT ((void)0)
374
-
375
-    #undef X_DIR_WRITE
376
-    #define X_DIR_WRITE(STATE) stepperX.Step_Clock(STATE)
377
-
378
-    #undef X_DIR_READ
379
-    #define X_DIR_READ (stepperX.getStatus() & STATUS_DIR)
380
-
381
-  #endif
382
-  #if ENABLED(X2_IS_L6470)
383
-    extern L6470 stepperX2;
384
-    #undef X2_ENABLE_INIT
385
-    #define X2_ENABLE_INIT ((void)0)
386
-
387
-    #undef X2_ENABLE_WRITE
388
-    #define X2_ENABLE_WRITE(STATE) (if(STATE) stepperX2.Step_Clock(stepperX2.getStatus() & STATUS_HIZ); else stepperX2.softFree();)
389
-
390
-    #undef X2_ENABLE_READ
391
-    #define X2_ENABLE_READ (stepperX2.getStatus() & STATUS_HIZ)
392
-
393
-    #undef X2_DIR_INIT
394
-    #define X2_DIR_INIT ((void)0)
395
-
396
-    #undef X2_DIR_WRITE
397
-    #define X2_DIR_WRITE(STATE) stepperX2.Step_Clock(STATE)
398
-
399
-    #undef X2_DIR_READ
400
-    #define X2_DIR_READ (stepperX2.getStatus() & STATUS_DIR)
401
-  #endif
402
-  #if ENABLED(Y_IS_L6470)
403
-    extern L6470 stepperY;
404
-    #undef Y_ENABLE_INIT
405
-    #define Y_ENABLE_INIT ((void)0)
406
-
407
-    #undef Y_ENABLE_WRITE
408
-    #define Y_ENABLE_WRITE(STATE) (if(STATE) stepperY.Step_Clock(stepperY.getStatus() & STATUS_HIZ); else stepperY.softFree();)
409
-
410
-    #undef Y_ENABLE_READ
411
-    #define Y_ENABLE_READ (stepperY.getStatus() & STATUS_HIZ)
412
-
413
-    #undef Y_DIR_INIT
414
-    #define Y_DIR_INIT ((void)0)
415
-
416
-    #undef Y_DIR_WRITE
417
-    #define Y_DIR_WRITE(STATE) stepperY.Step_Clock(STATE)
418
-
419
-    #undef Y_DIR_READ
420
-    #define Y_DIR_READ (stepperY.getStatus() & STATUS_DIR)
421
-  #endif
422
-  #if ENABLED(Y2_IS_L6470)
423
-    extern L6470 stepperY2;
424
-    #undef Y2_ENABLE_INIT
425
-    #define Y2_ENABLE_INIT ((void)0)
426
-
427
-    #undef Y2_ENABLE_WRITE
428
-    #define Y2_ENABLE_WRITE(STATE) (if(STATE) stepperY2.Step_Clock(stepperY2.getStatus() & STATUS_HIZ); else stepperY2.softFree();)
429
-
430
-    #undef Y2_ENABLE_READ
431
-    #define Y2_ENABLE_READ (stepperY2.getStatus() & STATUS_HIZ)
432
-
433
-    #undef Y2_DIR_INIT
434
-    #define Y2_DIR_INIT ((void)0)
435
-
436
-    #undef Y2_DIR_WRITE
437
-    #define Y2_DIR_WRITE(STATE) stepperY2.Step_Clock(STATE)
438
-
439
-    #undef Y2_DIR_READ
440
-    #define Y2_DIR_READ (stepperY2.getStatus() & STATUS_DIR)
441
-  #endif
442
-  #if ENABLED(Z_IS_L6470)
443
-    extern L6470 stepperZ;
444
-    #undef Z_ENABLE_INIT
445
-    #define Z_ENABLE_INIT ((void)0)
446
-
447
-    #undef Z_ENABLE_WRITE
448
-    #define Z_ENABLE_WRITE(STATE) (if(STATE) stepperZ.Step_Clock(stepperZ.getStatus() & STATUS_HIZ); else stepperZ.softFree();)
449
-
450
-    #undef Z_ENABLE_READ
451
-    #define Z_ENABLE_READ (stepperZ.getStatus() & STATUS_HIZ)
452
-
453
-    #undef Z_DIR_INIT
454
-    #define Z_DIR_INIT ((void)0)
455
-
456
-    #undef Z_DIR_WRITE
457
-    #define Z_DIR_WRITE(STATE) stepperZ.Step_Clock(STATE)
458
-
459
-    #undef Y_DIR_READ
460
-    #define Y_DIR_READ (stepperZ.getStatus() & STATUS_DIR)
461
-  #endif
462
-  #if ENABLED(Z2_IS_L6470)
463
-    extern L6470 stepperZ2;
464
-    #undef Z2_ENABLE_INIT
465
-    #define Z2_ENABLE_INIT ((void)0)
466
-
467
-    #undef Z2_ENABLE_WRITE
468
-    #define Z2_ENABLE_WRITE(STATE) (if(STATE) stepperZ2.Step_Clock(stepperZ2.getStatus() & STATUS_HIZ); else stepperZ2.softFree();)
469
-
470
-    #undef Z2_ENABLE_READ
471
-    #define Z2_ENABLE_READ (stepperZ2.getStatus() & STATUS_HIZ)
472
-
473
-    #undef Z2_DIR_INIT
474
-    #define Z2_DIR_INIT ((void)0)
475
-
476
-    #undef Z2_DIR_WRITE
477
-    #define Z2_DIR_WRITE(STATE) stepperZ2.Step_Clock(STATE)
478
-
479
-    #undef Y2_DIR_READ
480
-    #define Y2_DIR_READ (stepperZ2.getStatus() & STATUS_DIR)
481
-  #endif
482
-  #if ENABLED(E0_IS_L6470)
483
-    extern L6470 stepperE0;
484
-    #undef E0_ENABLE_INIT
485
-    #define E0_ENABLE_INIT ((void)0)
486
-
487
-    #undef E0_ENABLE_WRITE
488
-    #define E0_ENABLE_WRITE(STATE) (if(STATE) stepperE0.Step_Clock(stepperE0.getStatus() & STATUS_HIZ); else stepperE0.softFree();)
489
-
490
-    #undef E0_ENABLE_READ
491
-    #define E0_ENABLE_READ (stepperE0.getStatus() & STATUS_HIZ)
492
-
493
-    #undef E0_DIR_INIT
494
-    #define E0_DIR_INIT ((void)0)
495
-
496
-    #undef E0_DIR_WRITE
497
-    #define E0_DIR_WRITE(STATE) stepperE0.Step_Clock(STATE)
498
-
499
-    #undef E0_DIR_READ
500
-    #define E0_DIR_READ (stepperE0.getStatus() & STATUS_DIR)
501
-  #endif
502
-  #if ENABLED(E1_IS_L6470)
503
-    extern L6470 stepperE1;
504
-    #undef E1_ENABLE_INIT
505
-    #define E1_ENABLE_INIT ((void)0)
506
-
507
-    #undef E1_ENABLE_WRITE
508
-    #define E1_ENABLE_WRITE(STATE) (if(STATE) stepperE1.Step_Clock(stepperE1.getStatus() & STATUS_HIZ); else stepperE1.softFree();)
509
-
510
-    #undef E1_ENABLE_READ
511
-    #define E1_ENABLE_READ (stepperE1.getStatus() & STATUS_HIZ)
512
-
513
-    #undef E1_DIR_INIT
514
-    #define E1_DIR_INIT ((void)0)
515
-
516
-    #undef E1_DIR_WRITE
517
-    #define E1_DIR_WRITE(STATE) stepperE1.Step_Clock(STATE)
518
-
519
-    #undef E1_DIR_READ
520
-    #define E1_DIR_READ (stepperE1.getStatus() & STATUS_DIR)
521
-  #endif
522
-  #if ENABLED(E2_IS_L6470)
523
-    extern L6470 stepperE2;
524
-    #undef E2_ENABLE_INIT
525
-    #define E2_ENABLE_INIT ((void)0)
526
-
527
-    #undef E2_ENABLE_WRITE
528
-    #define E2_ENABLE_WRITE(STATE) (if(STATE) stepperE2.Step_Clock(stepperE2.getStatus() & STATUS_HIZ); else stepperE2.softFree();)
529
-
530
-    #undef E2_ENABLE_READ
531
-    #define E2_ENABLE_READ (stepperE2.getStatus() & STATUS_HIZ)
532
-
533
-    #undef E2_DIR_INIT
534
-    #define E2_DIR_INIT ((void)0)
535
-
536
-    #undef E2_DIR_WRITE
537
-    #define E2_DIR_WRITE(STATE) stepperE2.Step_Clock(STATE)
538
-
539
-    #undef E2_DIR_READ
540
-    #define E2_DIR_READ (stepperE2.getStatus() & STATUS_DIR)
541
-  #endif
542
-  #if ENABLED(E3_IS_L6470)
543
-    extern L6470 stepperE3;
544
-    #undef E3_ENABLE_INIT
545
-    #define E3_ENABLE_INIT ((void)0)
546
-
547
-    #undef E3_ENABLE_WRITE
548
-    #define E3_ENABLE_WRITE(STATE) (if(STATE) stepperE3.Step_Clock(stepperE3.getStatus() & STATUS_HIZ); else stepperE3.softFree();)
549
-
550
-    #undef E3_ENABLE_READ
551
-    #define E3_ENABLE_READ (stepperE3.getStatus() & STATUS_HIZ)
552
-
553
-    #undef E3_DIR_INIT
554
-    #define E3_DIR_INIT ((void)0)
555
-
556
-    #undef E3_DIR_WRITE
557
-    #define E3_DIR_WRITE(STATE) stepperE3.Step_Clock(STATE)
558
-
559
-    #undef E3_DIR_READ
560
-    #define E3_DIR_READ (stepperE3.getStatus() & STATUS_DIR)
561
-  #endif
562
-
563
-#endif  //HAVE_L6470DRIVER
564
-
565 395
 #endif // STEPPER_INDIRECTION_H

Завантаження…
Відмінити
Зберегти