Browse Source

stepper.cpp macros rework

delete some tabs
Wurstnase 9 years ago
parent
commit
79a44a9de3
1 changed files with 71 additions and 50 deletions
  1. 71
    50
      Marlin/stepper.cpp

+ 71
- 50
Marlin/stepper.cpp View File

46
 
46
 
47
 // Variables used by The Stepper Driver Interrupt
47
 // Variables used by The Stepper Driver Interrupt
48
 static unsigned char out_bits;        // The next stepping-bits to be output
48
 static unsigned char out_bits;        // The next stepping-bits to be output
49
-static unsigned int cleaning_buffer_counter;  
49
+static unsigned int cleaning_buffer_counter;
50
 
50
 
51
 #ifdef Z_DUAL_ENDSTOPS
51
 #ifdef Z_DUAL_ENDSTOPS
52
   static bool performing_homing = false, 
52
   static bool performing_homing = false, 
285
     }
285
     }
286
     #ifdef Z_PROBE_ENDSTOP
286
     #ifdef Z_PROBE_ENDSTOP
287
     if (endstop_z_probe_hit) {
287
     if (endstop_z_probe_hit) {
288
-    	SERIAL_ECHOPAIR(" Z_PROBE:", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
289
-    	LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "ZP");
288
+      SERIAL_ECHOPAIR(" Z_PROBE:", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
289
+      LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "ZP");
290
     }
290
     }
291
     #endif
291
     #endif
292
     SERIAL_EOL;
292
     SERIAL_EOL;
411
     OCR1A = 200;
411
     OCR1A = 200;
412
     return;
412
     return;
413
   }
413
   }
414
-  
414
+
415
   // If there is no current block, attempt to pop one from the buffer
415
   // If there is no current block, attempt to pop one from the buffer
416
   if (!current_block) {
416
   if (!current_block) {
417
     // Anything in the buffer?
417
     // Anything in the buffer?
463
       count_direction[Y_AXIS] = 1;
463
       count_direction[Y_AXIS] = 1;
464
     }
464
     }
465
 
465
 
466
+    #define _ENDSTOP(axis, minmax) axis ##_## minmax ##_endstop
467
+    #define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
468
+    #define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
469
+    #define _OLD_ENDSTOP(axis, minmax) old_## axis ##_## minmax ##_endstop
470
+    #define _AXIS(AXIS) AXIS ##_AXIS
471
+    #define _ENDSTOP_HIT(axis) endstop_## axis ##_hit
472
+
466
     #define UPDATE_ENDSTOP(axis,AXIS,minmax,MINMAX) \
473
     #define UPDATE_ENDSTOP(axis,AXIS,minmax,MINMAX) \
467
-      bool axis ##_## minmax ##_endstop = (READ(AXIS ##_## MINMAX ##_PIN) != AXIS ##_## MINMAX ##_ENDSTOP_INVERTING); \
468
-      if (axis ##_## minmax ##_endstop && old_## axis ##_## minmax ##_endstop && (current_block->steps[AXIS ##_AXIS] > 0)) { \
469
-        endstops_trigsteps[AXIS ##_AXIS] = count_position[AXIS ##_AXIS]; \
470
-        endstop_## axis ##_hit = true; \
474
+      bool _ENDSTOP(axis, minmax) = (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)); \
475
+      if (_ENDSTOP(axis, minmax) && _OLD_ENDSTOP(axis, minmax) && (current_block->steps[_AXIS(AXIS)] > 0)) { \
476
+        endstops_trigsteps[_AXIS(AXIS)] = count_position[_AXIS(AXIS)]; \
477
+        _ENDSTOP_HIT(axis) = true; \
471
         step_events_completed = current_block->step_event_count; \
478
         step_events_completed = current_block->step_event_count; \
472
       } \
479
       } \
473
-      old_## axis ##_## minmax ##_endstop = axis ##_## minmax ##_endstop;
480
+      _OLD_ENDSTOP(axis, minmax) = _ENDSTOP(axis, minmax);
481
+
474
 
482
 
475
     // Check X and Y endstops
483
     // Check X and Y endstops
476
     if (check_endstops) {
484
     if (check_endstops) {
486
             #ifdef DUAL_X_CARRIAGE
494
             #ifdef DUAL_X_CARRIAGE
487
               // with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
495
               // with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
488
               if ((current_block->active_extruder == 0 && X_HOME_DIR == -1) || (current_block->active_extruder != 0 && X2_HOME_DIR == -1))
496
               if ((current_block->active_extruder == 0 && X_HOME_DIR == -1) || (current_block->active_extruder != 0 && X2_HOME_DIR == -1))
489
-            #endif          
497
+            #endif
490
               {
498
               {
491
                 #if HAS_X_MIN
499
                 #if HAS_X_MIN
492
                   UPDATE_ENDSTOP(x, X, min, MIN);
500
                   UPDATE_ENDSTOP(x, X, min, MIN);
572
           z_probe_endstop=(READ(Z_PROBE_PIN) != Z_PROBE_ENDSTOP_INVERTING);
580
           z_probe_endstop=(READ(Z_PROBE_PIN) != Z_PROBE_ENDSTOP_INVERTING);
573
           if(z_probe_endstop && old_z_probe_endstop)
581
           if(z_probe_endstop && old_z_probe_endstop)
574
           {
582
           {
575
-        	  endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
576
-        	  endstop_z_probe_hit=true;
583
+            endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
584
+            endstop_z_probe_hit=true;
577
 
585
 
578
-//        	  if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
586
+//            if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
579
           }
587
           }
580
           old_z_probe_endstop = z_probe_endstop;
588
           old_z_probe_endstop = z_probe_endstop;
581
         #endif
589
         #endif
582
-        
590
+
583
       } // check_endstops
591
       } // check_endstops
584
 
592
 
585
     }
593
     }
625
           #endif // !Z_DUAL_ENDSTOPS
633
           #endif // !Z_DUAL_ENDSTOPS
626
 
634
 
627
         #endif // Z_MAX_PIN
635
         #endif // Z_MAX_PIN
628
-        
636
+
629
         #ifdef Z_PROBE_ENDSTOP
637
         #ifdef Z_PROBE_ENDSTOP
630
           UPDATE_ENDSTOP(z, Z, probe, PROBE);
638
           UPDATE_ENDSTOP(z, Z, probe, PROBE);
631
           z_probe_endstop=(READ(Z_PROBE_PIN) != Z_PROBE_ENDSTOP_INVERTING);
639
           z_probe_endstop=(READ(Z_PROBE_PIN) != Z_PROBE_ENDSTOP_INVERTING);
632
           if(z_probe_endstop && old_z_probe_endstop)
640
           if(z_probe_endstop && old_z_probe_endstop)
633
           {
641
           {
634
-        	  endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
635
-        	  endstop_z_probe_hit=true;
636
-//        	  if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
642
+            endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
643
+            endstop_z_probe_hit=true;
644
+//            if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
637
           }
645
           }
638
           old_z_probe_endstop = z_probe_endstop;
646
           old_z_probe_endstop = z_probe_endstop;
639
         #endif
647
         #endif
667
         }
675
         }
668
       #endif //ADVANCE
676
       #endif //ADVANCE
669
 
677
 
678
+      #define _COUNTER(axis) counter_## axis
679
+      #define _WRITE_STEP(AXIS, HIGHLOW) AXIS ##_STEP_WRITE(HIGHLOW)
680
+      #define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
681
+      #define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
682
+
670
       #ifdef CONFIG_STEPPERS_TOSHIBA
683
       #ifdef CONFIG_STEPPERS_TOSHIBA
671
         /**
684
         /**
672
          * The Toshiba stepper controller require much longer pulses.
685
          * The Toshiba stepper controller require much longer pulses.
675
          * lag to allow it work with without needing NOPs
688
          * lag to allow it work with without needing NOPs
676
          */
689
          */
677
         #define STEP_ADD(axis, AXIS) \
690
         #define STEP_ADD(axis, AXIS) \
678
-         counter_## axis += current_block->steps[AXIS ##_AXIS]; \
679
-         if (counter_## axis > 0) { AXIS ##_STEP_WRITE(HIGH); }
691
+         _COUNTER(axis) += current_block->steps[_AXIS(AXIS)]; \
692
+         if (_COUNTER(axis) > 0) { _WRITE_STEP(AXIS, HIGH); }
680
         STEP_ADD(x,X);
693
         STEP_ADD(x,X);
681
         STEP_ADD(y,Y);
694
         STEP_ADD(y,Y);
682
         STEP_ADD(z,Z);
695
         STEP_ADD(z,Z);
685
         #endif
698
         #endif
686
 
699
 
687
         #define STEP_IF_COUNTER(axis, AXIS) \
700
         #define STEP_IF_COUNTER(axis, AXIS) \
688
-          if (counter_## axis > 0) { \
689
-            counter_## axis -= current_block->step_event_count; \
690
-            count_position[AXIS ##_AXIS] += count_direction[AXIS ##_AXIS]; \
691
-            AXIS ##_STEP_WRITE(LOW); \
701
+          if (_COUNTER(axis) > 0) { \
702
+            _COUNTER(axis) -= current_block->step_event_count; \
703
+            count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
704
+            _WRITE_STEP(AXIS, LOW); \
692
           }
705
           }
693
 
706
 
694
         STEP_IF_COUNTER(x, X);
707
         STEP_IF_COUNTER(x, X);
701
       #else // !CONFIG_STEPPERS_TOSHIBA
714
       #else // !CONFIG_STEPPERS_TOSHIBA
702
 
715
 
703
         #define APPLY_MOVEMENT(axis, AXIS) \
716
         #define APPLY_MOVEMENT(axis, AXIS) \
704
-          counter_## axis += current_block->steps[AXIS ##_AXIS]; \
705
-          if (counter_## axis > 0) { \
706
-            AXIS ##_APPLY_STEP(!INVERT_## AXIS ##_STEP_PIN,0); \
707
-            counter_## axis -= current_block->step_event_count; \
708
-            count_position[AXIS ##_AXIS] += count_direction[AXIS ##_AXIS]; \
709
-            AXIS ##_APPLY_STEP(INVERT_## AXIS ##_STEP_PIN,0); \
717
+          _COUNTER(axis) += current_block->steps[_AXIS(AXIS)]; \
718
+          if (_COUNTER(axis) > 0) { \
719
+            _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS),0); \
720
+            _COUNTER(axis) -= current_block->step_event_count; \
721
+            count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
722
+            _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
710
           }
723
           }
711
 
724
 
712
         APPLY_MOVEMENT(x, X);
725
         APPLY_MOVEMENT(x, X);
874
   #ifdef HAVE_L6470DRIVER
887
   #ifdef HAVE_L6470DRIVER
875
     L6470_init();
888
     L6470_init();
876
   #endif
889
   #endif
877
-  
890
+
878
   // Initialize Dir Pins
891
   // Initialize Dir Pins
879
   #if HAS_X_DIR
892
   #if HAS_X_DIR
880
     X_DIR_INIT;
893
     X_DIR_INIT;
920
   #if HAS_Y_ENABLE
933
   #if HAS_Y_ENABLE
921
     Y_ENABLE_INIT;
934
     Y_ENABLE_INIT;
922
     if (!Y_ENABLE_ON) Y_ENABLE_WRITE(HIGH);
935
     if (!Y_ENABLE_ON) Y_ENABLE_WRITE(HIGH);
923
-	
924
-	#if defined(Y_DUAL_STEPPER_DRIVERS) && HAS_Y2_ENABLE
925
-	  Y2_ENABLE_INIT;
926
-	  if (!Y_ENABLE_ON) Y2_ENABLE_WRITE(HIGH);
927
-	#endif
936
+
937
+  #if defined(Y_DUAL_STEPPER_DRIVERS) && HAS_Y2_ENABLE
938
+    Y2_ENABLE_INIT;
939
+    if (!Y_ENABLE_ON) Y2_ENABLE_WRITE(HIGH);
940
+  #endif
928
   #endif
941
   #endif
929
   #if HAS_Z_ENABLE
942
   #if HAS_Z_ENABLE
930
     Z_ENABLE_INIT;
943
     Z_ENABLE_INIT;
1001
     #ifdef ENDSTOPPULLUP_ZMAX
1014
     #ifdef ENDSTOPPULLUP_ZMAX
1002
       WRITE(Z2_MAX_PIN,HIGH);
1015
       WRITE(Z2_MAX_PIN,HIGH);
1003
     #endif
1016
     #endif
1004
-  #endif  
1005
-  
1017
+  #endif
1018
+
1006
 #if (defined(Z_PROBE_PIN) && Z_PROBE_PIN >= 0) && defined(Z_PROBE_ENDSTOP) // Check for Z_PROBE_ENDSTOP so we don't pull a pin high unless it's to be used.
1019
 #if (defined(Z_PROBE_PIN) && Z_PROBE_PIN >= 0) && defined(Z_PROBE_ENDSTOP) // Check for Z_PROBE_ENDSTOP so we don't pull a pin high unless it's to be used.
1007
   SET_INPUT(Z_PROBE_PIN);
1020
   SET_INPUT(Z_PROBE_PIN);
1008
   #ifdef ENDSTOPPULLUP_ZPROBE
1021
   #ifdef ENDSTOPPULLUP_ZPROBE
1010
   #endif
1023
   #endif
1011
 #endif
1024
 #endif
1012
 
1025
 
1026
+  #define _STEP_INIT(AXIS) AXIS ##_STEP_INIT
1027
+  #define _DISABLE(axis) disable_## axis()
1028
+
1013
   #define AXIS_INIT(axis, AXIS, PIN) \
1029
   #define AXIS_INIT(axis, AXIS, PIN) \
1014
-    AXIS ##_STEP_INIT; \
1015
-    AXIS ##_STEP_WRITE(INVERT_## PIN ##_STEP_PIN); \
1016
-    disable_## axis()
1030
+    _STEP_INIT(AXIS); \
1031
+    _WRITE_STEP(AXIS, _INVERT_STEP_PIN(PIN)); \
1032
+    _DISABLE(axis)
1017
 
1033
 
1018
   #define E_AXIS_INIT(NUM) AXIS_INIT(e## NUM, E## NUM, E)
1034
   #define E_AXIS_INIT(NUM) AXIS_INIT(e## NUM, E## NUM, E)
1019
 
1035
 
1146
   // No other ISR should ever interrupt this!
1162
   // No other ISR should ever interrupt this!
1147
   void babystep(const uint8_t axis, const bool direction) {
1163
   void babystep(const uint8_t axis, const bool direction) {
1148
 
1164
 
1165
+    #define _ENABLE(axis) enable_## axis()
1166
+    #define _READ_DIR(AXIS) AXIS ##_DIR_READ
1167
+    #define _INVERT_DIR(AXIS) INVERT_## AXIS ##_DIR
1168
+    #define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true)
1169
+
1149
     #define BABYSTEP_AXIS(axis, AXIS, INVERT) { \
1170
     #define BABYSTEP_AXIS(axis, AXIS, INVERT) { \
1150
-        enable_## axis(); \
1151
-        uint8_t old_pin = AXIS ##_DIR_READ; \
1152
-        AXIS ##_APPLY_DIR(INVERT_## AXIS ##_DIR^direction^INVERT, true); \
1153
-        AXIS ##_APPLY_STEP(!INVERT_## AXIS ##_STEP_PIN, true); \
1171
+        _ENABLE(axis); \
1172
+        uint8_t old_pin = _READ_DIR(AXIS); \
1173
+        _APPLY_DIR(AXIS, _INVERT_DIR(AXIS)^direction^INVERT); \
1174
+        _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), true); \
1154
         delayMicroseconds(2); \
1175
         delayMicroseconds(2); \
1155
-        AXIS ##_APPLY_STEP(INVERT_## AXIS ##_STEP_PIN, true); \
1156
-        AXIS ##_APPLY_DIR(old_pin, true); \
1176
+        _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), true); \
1177
+        _APPLY_DIR(AXIS, old_pin); \
1157
       }
1178
       }
1158
 
1179
 
1159
     switch(axis) {
1180
     switch(axis) {
1165
       case Y_AXIS:
1186
       case Y_AXIS:
1166
         BABYSTEP_AXIS(y, Y, false);
1187
         BABYSTEP_AXIS(y, Y, false);
1167
         break;
1188
         break;
1168
-     
1189
+ 
1169
       case Z_AXIS: {
1190
       case Z_AXIS: {
1170
 
1191
 
1171
         #ifndef DELTA
1192
         #ifndef DELTA
1202
         #endif
1223
         #endif
1203
 
1224
 
1204
       } break;
1225
       } break;
1205
-     
1226
+ 
1206
       default: break;
1227
       default: break;
1207
     }
1228
     }
1208
   }
1229
   }
1266
 
1287
 
1267
   #if HAS_MICROSTEPS
1288
   #if HAS_MICROSTEPS
1268
     pinMode(X_MS1_PIN,OUTPUT);
1289
     pinMode(X_MS1_PIN,OUTPUT);
1269
-    pinMode(X_MS2_PIN,OUTPUT);  
1290
+    pinMode(X_MS2_PIN,OUTPUT);
1270
     pinMode(Y_MS1_PIN,OUTPUT);
1291
     pinMode(Y_MS1_PIN,OUTPUT);
1271
     pinMode(Y_MS2_PIN,OUTPUT);
1292
     pinMode(Y_MS2_PIN,OUTPUT);
1272
     pinMode(Z_MS1_PIN,OUTPUT);
1293
     pinMode(Z_MS1_PIN,OUTPUT);

Loading…
Cancel
Save