Ver código fonte

Reduce STEP_PULSE_CYCLES code slightly

Scott Lahteine 8 anos atrás
pai
commit
d1e6b0e21a
1 arquivos alterados com 18 adições e 29 exclusões
  1. 18
    29
      Marlin/stepper.cpp

+ 18
- 29
Marlin/stepper.cpp Ver arquivo

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

Carregando…
Cancelar
Salvar