Browse Source

X_DUAL_STEPPER_DRIVERS implementation

Scott Lahteine 8 years ago
parent
commit
4b4a582c4f
4 changed files with 70 additions and 63 deletions
  1. 34
    38
      Marlin/Marlin.h
  2. 19
    12
      Marlin/pins.h
  3. 14
    10
      Marlin/stepper.cpp
  4. 3
    3
      Marlin/stepper_indirection.h

+ 34
- 38
Marlin/Marlin.h View File

@@ -134,73 +134,69 @@ void manage_inactivity(bool ignore_stepper_queue = false);
134 134
   extern bool extruder_duplication_enabled;
135 135
 #endif
136 136
 
137
-#if ENABLED(DUAL_X_CARRIAGE) && HAS_X_ENABLE && HAS_X2_ENABLE
138
-  #define  enable_x() do { X_ENABLE_WRITE( X_ENABLE_ON); X2_ENABLE_WRITE( X_ENABLE_ON); } while (0)
139
-  #define disable_x() do { X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; } while (0)
137
+#if HAS_X2_ENABLE
138
+  #define  enable_x() do{ X_ENABLE_WRITE( X_ENABLE_ON); X2_ENABLE_WRITE( X_ENABLE_ON); }while(0)
139
+  #define disable_x() do{ X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
140 140
 #elif HAS_X_ENABLE
141 141
   #define  enable_x() X_ENABLE_WRITE( X_ENABLE_ON)
142
-  #define disable_x() { X_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }
142
+  #define disable_x() do{ X_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
143 143
 #else
144
-  #define enable_x() ;
145
-  #define disable_x() ;
144
+  #define  enable_x() NOOP
145
+  #define disable_x() NOOP
146 146
 #endif
147 147
 
148
-#if HAS_Y_ENABLE
149
-  #if ENABLED(Y_DUAL_STEPPER_DRIVERS)
150
-    #define  enable_y() { Y_ENABLE_WRITE( Y_ENABLE_ON); Y2_ENABLE_WRITE(Y_ENABLE_ON); }
151
-    #define disable_y() { Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }
152
-  #else
153
-    #define  enable_y() Y_ENABLE_WRITE( Y_ENABLE_ON)
154
-    #define disable_y() { Y_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }
155
-  #endif
148
+#if HAS_Y2_ENABLE
149
+  #define  enable_y() do{ Y_ENABLE_WRITE( Y_ENABLE_ON); Y2_ENABLE_WRITE(Y_ENABLE_ON); }while(0)
150
+  #define disable_y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
151
+#elif HAS_Y_ENABLE
152
+  #define  enable_y() Y_ENABLE_WRITE( Y_ENABLE_ON)
153
+  #define disable_y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
156 154
 #else
157
-  #define enable_y() ;
158
-  #define disable_y() ;
155
+  #define  enable_y() NOOP
156
+  #define disable_y() NOOP
159 157
 #endif
160 158
 
161
-#if HAS_Z_ENABLE
162
-  #if ENABLED(Z_DUAL_STEPPER_DRIVERS)
163
-    #define  enable_z() { Z_ENABLE_WRITE( Z_ENABLE_ON); Z2_ENABLE_WRITE(Z_ENABLE_ON); }
164
-    #define disable_z() { Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
165
-  #else
166
-    #define  enable_z() Z_ENABLE_WRITE( Z_ENABLE_ON)
167
-    #define disable_z() { Z_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }
168
-  #endif
159
+#if HAS_Z2_ENABLE
160
+  #define  enable_z() do{ Z_ENABLE_WRITE( Z_ENABLE_ON); Z2_ENABLE_WRITE(Z_ENABLE_ON); }while(0)
161
+  #define disable_z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
162
+#elif HAS_Z_ENABLE
163
+  #define  enable_z() Z_ENABLE_WRITE( Z_ENABLE_ON)
164
+  #define disable_z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
169 165
 #else
170
-  #define enable_z() ;
171
-  #define disable_z() ;
166
+  #define  enable_z() NOOP
167
+  #define disable_z() NOOP
172 168
 #endif
173 169
 
174 170
 #if HAS_E0_ENABLE
175
-  #define enable_e0()  E0_ENABLE_WRITE( E_ENABLE_ON)
171
+  #define  enable_e0() E0_ENABLE_WRITE( E_ENABLE_ON)
176 172
   #define disable_e0() E0_ENABLE_WRITE(!E_ENABLE_ON)
177 173
 #else
178
-  #define enable_e0()  /* nothing */
179
-  #define disable_e0() /* nothing */
174
+  #define  enable_e0() NOOP
175
+  #define disable_e0() NOOP
180 176
 #endif
181 177
 
182 178
 #if (EXTRUDERS > 1) && HAS_E1_ENABLE
183
-  #define enable_e1()  E1_ENABLE_WRITE( E_ENABLE_ON)
179
+  #define  enable_e1() E1_ENABLE_WRITE( E_ENABLE_ON)
184 180
   #define disable_e1() E1_ENABLE_WRITE(!E_ENABLE_ON)
185 181
 #else
186
-  #define enable_e1()  /* nothing */
187
-  #define disable_e1() /* nothing */
182
+  #define  enable_e1() NOOP
183
+  #define disable_e1() NOOP
188 184
 #endif
189 185
 
190 186
 #if (EXTRUDERS > 2) && HAS_E2_ENABLE
191
-  #define enable_e2()  E2_ENABLE_WRITE( E_ENABLE_ON)
187
+  #define  enable_e2() E2_ENABLE_WRITE( E_ENABLE_ON)
192 188
   #define disable_e2() E2_ENABLE_WRITE(!E_ENABLE_ON)
193 189
 #else
194
-  #define enable_e2()  /* nothing */
195
-  #define disable_e2() /* nothing */
190
+  #define  enable_e2() NOOP
191
+  #define disable_e2() NOOP
196 192
 #endif
197 193
 
198 194
 #if (EXTRUDERS > 3) && HAS_E3_ENABLE
199
-  #define enable_e3()  E3_ENABLE_WRITE( E_ENABLE_ON)
195
+  #define  enable_e3() E3_ENABLE_WRITE( E_ENABLE_ON)
200 196
   #define disable_e3() E3_ENABLE_WRITE(!E_ENABLE_ON)
201 197
 #else
202
-  #define enable_e3()  /* nothing */
203
-  #define disable_e3() /* nothing */
198
+  #define  enable_e3() NOOP
199
+  #define disable_e3() NOOP
204 200
 #endif
205 201
 
206 202
 /**

+ 19
- 12
Marlin/pins.h View File

@@ -369,8 +369,8 @@
369 369
 #define __EPIN(p,q) E##p##_##q##_PIN
370 370
 #define _EPIN(p,q) __EPIN(p,q)
371 371
 
372
-#if ENABLED(DUAL_X_CARRIAGE)
373
-  // The X2 axis, if any, should be the next open extruder port
372
+// The X2 axis, if any, should be the next open extruder port
373
+#if ENABLED(DUAL_X_CARRIAGE) || ENABLED(X_DUAL_STEPPER_DRIVERS)
374 374
   #ifndef X2_STEP_PIN
375 375
     #define X2_STEP_PIN   _EPIN(EXTRUDERS, STEP)
376 376
     #define X2_DIR_PIN    _EPIN(EXTRUDERS, DIR)
@@ -378,25 +378,32 @@
378 378
   #endif
379 379
   #undef _X2_PINS
380 380
   #define _X2_PINS X2_STEP_PIN, X2_DIR_PIN, X2_ENABLE_PIN,
381
-  #define Y2_Z2_E_INDEX INCREMENT(EXTRUDERS)
381
+  #define Y2_E_INDEX INCREMENT(EXTRUDERS)
382 382
 #else
383
-  #define Y2_Z2_E_INDEX EXTRUDERS
383
+  #define Y2_E_INDEX EXTRUDERS
384 384
 #endif
385 385
 
386 386
 // The Y2 axis, if any, should be the next open extruder port
387
-#if ENABLED(Y_DUAL_STEPPER_DRIVERS) && !defined(Y2_STEP_PIN)
388
-  #define Y2_STEP_PIN   _EPIN(Y2_Z2_E_INDEX, STEP)
389
-  #define Y2_DIR_PIN    _EPIN(Y2_Z2_E_INDEX, DIR)
390
-  #define Y2_ENABLE_PIN _EPIN(Y2_Z2_E_INDEX, ENABLE)
387
+#if ENABLED(Y_DUAL_STEPPER_DRIVERS)
388
+  #ifndef Y2_STEP_PIN
389
+    #define Y2_STEP_PIN   _EPIN(Y2_E_INDEX, STEP)
390
+    #define Y2_DIR_PIN    _EPIN(Y2_E_INDEX, DIR)
391
+    #define Y2_ENABLE_PIN _EPIN(Y2_E_INDEX, ENABLE)
392
+  #endif
391 393
   #undef _Y2_PINS
392 394
   #define _Y2_PINS Y2_STEP_PIN, Y2_DIR_PIN, Y2_ENABLE_PIN,
395
+  #define Z2_E_INDEX INCREMENT(Y2_E_INDEX)
396
+#else
397
+  #define Z2_E_INDEX Y2_E_INDEX
393 398
 #endif
394 399
 
395 400
 // The Z2 axis, if any, should be the next open extruder port
396
-#if ENABLED(Z_DUAL_STEPPER_DRIVERS) && !defined(Z2_STEP_PIN)
397
-  #define Z2_STEP_PIN   _EPIN(Y2_Z2_E_INDEX, STEP)
398
-  #define Z2_DIR_PIN    _EPIN(Y2_Z2_E_INDEX, DIR)
399
-  #define Z2_ENABLE_PIN _EPIN(Y2_Z2_E_INDEX, ENABLE)
401
+#if ENABLED(Z_DUAL_STEPPER_DRIVERS)
402
+  #ifndef Z2_STEP_PIN
403
+    #define Z2_STEP_PIN   _EPIN(Z2_E_INDEX, STEP)
404
+    #define Z2_DIR_PIN    _EPIN(Z2_E_INDEX, DIR)
405
+    #define Z2_ENABLE_PIN _EPIN(Z2_E_INDEX, ENABLE)
406
+  #endif
400 407
   #undef _Z2_PINS
401 408
   #define _Z2_PINS Z2_STEP_PIN, Z2_DIR_PIN, Z2_ENABLE_PIN,
402 409
 #endif

+ 14
- 10
Marlin/stepper.cpp View File

@@ -120,7 +120,10 @@ unsigned short Stepper::OCR1A_nominal;
120 120
 
121 121
 volatile long Stepper::endstops_trigsteps[3];
122 122
 
123
-#if ENABLED(DUAL_X_CARRIAGE)
123
+#if ENABLED(X_DUAL_STEPPER_DRIVERS)
124
+  #define X_APPLY_DIR(v,Q) do{ X_DIR_WRITE(v); X2_DIR_WRITE((v) != INVERT_X2_VS_X_DIR); }while(0)
125
+  #define X_APPLY_STEP(v,Q) do{ X_STEP_WRITE(v); X2_STEP_WRITE(v); }while(0)
126
+#elif ENABLED(DUAL_X_CARRIAGE)
124 127
   #define X_APPLY_DIR(v,ALWAYS) \
125 128
     if (extruder_duplication_enabled || ALWAYS) { \
126 129
       X_DIR_WRITE(v); \
@@ -143,15 +146,15 @@ volatile long Stepper::endstops_trigsteps[3];
143 146
 #endif
144 147
 
145 148
 #if ENABLED(Y_DUAL_STEPPER_DRIVERS)
146
-  #define Y_APPLY_DIR(v,Q) { Y_DIR_WRITE(v); Y2_DIR_WRITE((v) != INVERT_Y2_VS_Y_DIR); }
147
-  #define Y_APPLY_STEP(v,Q) { Y_STEP_WRITE(v); Y2_STEP_WRITE(v); }
149
+  #define Y_APPLY_DIR(v,Q) do{ Y_DIR_WRITE(v); Y2_DIR_WRITE((v) != INVERT_Y2_VS_Y_DIR); }while(0)
150
+  #define Y_APPLY_STEP(v,Q) do{ Y_STEP_WRITE(v); Y2_STEP_WRITE(v); }while(0)
148 151
 #else
149 152
   #define Y_APPLY_DIR(v,Q) Y_DIR_WRITE(v)
150 153
   #define Y_APPLY_STEP(v,Q) Y_STEP_WRITE(v)
151 154
 #endif
152 155
 
153 156
 #if ENABLED(Z_DUAL_STEPPER_DRIVERS)
154
-  #define Z_APPLY_DIR(v,Q) { Z_DIR_WRITE(v); Z2_DIR_WRITE(v); }
157
+  #define Z_APPLY_DIR(v,Q) do{ Z_DIR_WRITE(v); Z2_DIR_WRITE(v); }while(0)
155 158
   #if ENABLED(Z_DUAL_ENDSTOPS)
156 159
     #define Z_APPLY_STEP(v,Q) \
157 160
     if (performing_homing) { \
@@ -169,7 +172,7 @@ volatile long Stepper::endstops_trigsteps[3];
169 172
       Z2_STEP_WRITE(v); \
170 173
     }
171 174
   #else
172
-    #define Z_APPLY_STEP(v,Q) { Z_STEP_WRITE(v); Z2_STEP_WRITE(v); }
175
+    #define Z_APPLY_STEP(v,Q) do{ Z_STEP_WRITE(v); Z2_STEP_WRITE(v); }while(0)
173 176
   #endif
174 177
 #else
175 178
   #define Z_APPLY_DIR(v,Q) Z_DIR_WRITE(v)
@@ -669,14 +672,15 @@ void Stepper::init() {
669 672
 
670 673
   // Initialize Step Pins
671 674
   #if HAS_X_STEP
672
-    AXIS_INIT(x, X, X);
673
-    #if ENABLED(DUAL_X_CARRIAGE) && HAS_X2_STEP
674
-      AXIS_INIT(x, X2, X);
675
+    #if ENABLED(X_DUAL_STEPPER_DRIVERS) || ENABLED(DUAL_X_CARRIAGE)
676
+      X2_STEP_INIT;
677
+      X2_STEP_WRITE(INVERT_X_STEP_PIN);
675 678
     #endif
679
+    AXIS_INIT(x, X, X);
676 680
   #endif
677 681
 
678 682
   #if HAS_Y_STEP
679
-    #if ENABLED(Y_DUAL_STEPPER_DRIVERS) && HAS_Y2_STEP
683
+    #if ENABLED(Y_DUAL_STEPPER_DRIVERS)
680 684
       Y2_STEP_INIT;
681 685
       Y2_STEP_WRITE(INVERT_Y_STEP_PIN);
682 686
     #endif
@@ -684,7 +688,7 @@ void Stepper::init() {
684 688
   #endif
685 689
 
686 690
   #if HAS_Z_STEP
687
-    #if ENABLED(Z_DUAL_STEPPER_DRIVERS) && HAS_Z2_STEP
691
+    #if ENABLED(Z_DUAL_STEPPER_DRIVERS)
688 692
       Z2_STEP_INIT;
689 693
       Z2_STEP_WRITE(INVERT_Z_STEP_PIN);
690 694
     #endif

+ 3
- 3
Marlin/stepper_indirection.h View File

@@ -60,7 +60,7 @@
60 60
 #define X_ENABLE_READ READ(X_ENABLE_PIN)
61 61
 
62 62
 // X2 motor
63
-#if ENABLED(DUAL_X_CARRIAGE)
63
+#if HAS_X2_ENABLE
64 64
   #define X2_STEP_INIT SET_OUTPUT(X2_STEP_PIN)
65 65
   #define X2_STEP_WRITE(STATE) WRITE(X2_STEP_PIN,STATE)
66 66
   #define X2_STEP_READ READ(X2_STEP_PIN)
@@ -88,7 +88,7 @@
88 88
 #define Y_ENABLE_READ READ(Y_ENABLE_PIN)
89 89
 
90 90
 // Y2 motor
91
-#if ENABLED(Y_DUAL_STEPPER_DRIVERS)
91
+#if HAS_Y2_ENABLE
92 92
   #define Y2_STEP_INIT SET_OUTPUT(Y2_STEP_PIN)
93 93
   #define Y2_STEP_WRITE(STATE) WRITE(Y2_STEP_PIN,STATE)
94 94
   #define Y2_STEP_READ READ(Y2_STEP_PIN)
@@ -116,7 +116,7 @@
116 116
 #define Z_ENABLE_READ READ(Z_ENABLE_PIN)
117 117
 
118 118
 // Z2 motor
119
-#if ENABLED(Z_DUAL_STEPPER_DRIVERS)
119
+#if HAS_Z2_ENABLE
120 120
   #define Z2_STEP_INIT SET_OUTPUT(Z2_STEP_PIN)
121 121
   #define Z2_STEP_WRITE(STATE) WRITE(Z2_STEP_PIN,STATE)
122 122
   #define Z2_STEP_READ READ(Z2_STEP_PIN)

Loading…
Cancel
Save