Parcourir la source

Reduce STEP_PULSE_CYCLES code slightly

Scott Lahteine il y a 7 ans
Parent
révision
d1e6b0e21a
1 fichiers modifiés avec 18 ajouts et 29 suppressions
  1. 18
    29
      Marlin/stepper.cpp

+ 18
- 29
Marlin/stepper.cpp Voir le fichier

@@ -535,8 +535,7 @@ void Stepper::isr() {
535 535
 
536 536
     // If a minimum pulse time was specified get the CPU clock
537 537
     #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_CODE
538
-      static uint32_t pulse_start;
539
-      pulse_start = TCNT0;
538
+      uint32_t pulse_start = TCNT0;
540 539
     #endif
541 540
 
542 541
     #if HAS_X_STEP
@@ -802,8 +801,7 @@ void Stepper::isr() {
802 801
     for (uint8_t i = 0; i < step_loops; i++) {
803 802
 
804 803
       #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_E
805
-        static uint32_t pulse_start;
806
-        pulse_start = TCNT0;
804
+        uint32_t pulse_start = TCNT0;
807 805
       #endif
808 806
 
809 807
       START_E_PULSE(0);
@@ -1232,55 +1230,53 @@ void Stepper::report_positions() {
1232 1230
 #if ENABLED(BABYSTEPPING)
1233 1231
 
1234 1232
   #define CYCLES_EATEN_BY_BABYSTEP 60
1233
+
1235 1234
   #define _ENABLE(axis) enable_## axis()
1236 1235
   #define _READ_DIR(AXIS) AXIS ##_DIR_READ
1237 1236
   #define _INVERT_DIR(AXIS) INVERT_## AXIS ##_DIR
1238 1237
   #define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true)
1239 1238
 
1239
+  #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1240
+    #define _SAVE_START (pulse_start = TCNT0)
1241
+    #define _PULSE_WAIT while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_BABYSTEP) { /* nada */ }
1242
+  #else
1243
+    #define _SAVE_START NOOP
1244
+    #define _PULSE_WAIT NOOP
1245
+  #endif
1246
+
1240 1247
   #define START_BABYSTEP_AXIS(AXIS, INVERT) { \
1248
+      old_dir = _READ_DIR(AXIS); \
1249
+      _SAVE_START; \
1241 1250
       _APPLY_DIR(AXIS, _INVERT_DIR(AXIS)^direction^INVERT); \
1242 1251
       _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), true); \
1243 1252
     }
1244 1253
 
1245 1254
   #define STOP_BABYSTEP_AXIS(AXIS) { \
1255
+      _PULSE_WAIT; \
1246 1256
       _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), true); \
1247
-      _APPLY_DIR(AXIS, old_pin); \
1257
+      _APPLY_DIR(AXIS, old_dir); \
1248 1258
     }
1249 1259
 
1250 1260
   // MUST ONLY BE CALLED BY AN ISR,
1251 1261
   // No other ISR should ever interrupt this!
1252 1262
   void Stepper::babystep(const AxisEnum axis, const bool direction) {
1253 1263
     cli();
1254
-    static uint8_t old_pin;
1264
+    uint8_t old_dir;
1255 1265
     #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1256
-      static uint32_t pulse_start;
1266
+      uint32_t pulse_start;
1257 1267
     #endif
1258 1268
     
1259 1269
     switch (axis) {
1260 1270
 
1261 1271
       case X_AXIS:
1262 1272
         _ENABLE(x);
1263
-        old_pin = _READ_DIR(X);
1264
-        #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1265
-          pulse_start = TCNT0;
1266
-        #endif 
1267 1273
         START_BABYSTEP_AXIS(X, false);
1268
-        #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1269
-          while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_BABYSTEP) { /* nada */ }
1270
-        #endif
1271 1274
         STOP_BABYSTEP_AXIS(X);
1272 1275
         break;
1273 1276
 
1274 1277
       case Y_AXIS:
1275 1278
         _ENABLE(y);
1276
-        old_pin = _READ_DIR(Y);
1277
-        #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1278
-          pulse_start = TCNT0;
1279
-        #endif
1280 1279
         START_BABYSTEP_AXIS(Y, false);
1281
-        #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1282
-          while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_BABYSTEP) { /* nada */ }
1283
-        #endif
1284 1280
         STOP_BABYSTEP_AXIS(Y);
1285 1281
         break;
1286 1282
 
@@ -1289,14 +1285,7 @@ void Stepper::report_positions() {
1289 1285
         #if DISABLED(DELTA)
1290 1286
 
1291 1287
           _ENABLE(z);
1292
-          old_pin = _READ_DIR(Z);
1293
-          #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1294
-            pulse_start = TCNT0;
1295
-          #endif
1296 1288
           START_BABYSTEP_AXIS(Z, BABYSTEP_INVERT_Z);
1297
-          #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1298
-            while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_BABYSTEP) { /* nada */ }
1299
-          #endif
1300 1289
           STOP_BABYSTEP_AXIS(Z);
1301 1290
 
1302 1291
         #else // DELTA
@@ -1340,7 +1329,7 @@ void Stepper::report_positions() {
1340 1329
     sei();
1341 1330
   }
1342 1331
 
1343
-#endif //BABYSTEPPING
1332
+#endif // BABYSTEPPING
1344 1333
 
1345 1334
 /**
1346 1335
  * Software-controlled Stepper Motor Current

Chargement…
Annuler
Enregistrer