Pārlūkot izejas kodu

Merge pull request #9971 from thinkyhead/bf2_lin_advance_duplication

[2.0.x] Support duplication mode in LIN_ADVANCE
Scott Lahteine 7 gadus atpakaļ
vecāks
revīzija
d7aed2fe4f
Revīzijas autora e-pasta adrese nav piesaistīta nevienam kontam
2 mainītis faili ar 34 papildinājumiem un 28 dzēšanām
  1. 22
    19
      Marlin/src/module/stepper.cpp
  2. 12
    9
      Marlin/src/module/stepper.h

+ 22
- 19
Marlin/src/module/stepper.cpp Parādīt failu

122
            Stepper::final_adv_steps,
122
            Stepper::final_adv_steps,
123
            Stepper::max_adv_steps;
123
            Stepper::max_adv_steps;
124
 
124
 
125
-  int8_t Stepper::e_steps = 0,
126
-         Stepper::LA_active_extruder; // Copy from current executed block. Needed because current_block is set to NULL "too early".
125
+  int8_t Stepper::e_steps = 0;
126
+
127
+  #if E_STEPPERS > 1
128
+    int8_t Stepper::LA_active_extruder; // Copy from current executed block. Needed because current_block is set to NULL "too early".
129
+  #else
130
+    constexpr int8_t Stepper::LA_active_extruder;
131
+  #endif
127
 
132
 
128
   bool Stepper::use_advance_lead;
133
   bool Stepper::use_advance_lead;
129
 
134
 
755
 
760
 
756
   void Stepper::advance_isr() {
761
   void Stepper::advance_isr() {
757
 
762
 
758
-    #if ENABLED(MK2_MULTIPLEXER)
759
-      // Even-numbered steppers are reversed
760
-      #define SET_E_STEP_DIR(INDEX) \
761
-        if (e_steps) E## INDEX ##_DIR_WRITE(e_steps < 0 ? !INVERT_E## INDEX ##_DIR ^ TEST(INDEX, 0) : INVERT_E## INDEX ##_DIR ^ TEST(INDEX, 0))
763
+    #if ENABLED(MK2_MULTIPLEXER) // For SNMM even-numbered steppers are reversed
764
+      #define SET_E_STEP_DIR(INDEX) do{ if (e_steps) E## INDEX ##_DIR_WRITE(e_steps < 0 ? !INVERT_E## INDEX ##_DIR ^ TEST(INDEX, 0) : INVERT_E## INDEX ##_DIR ^ TEST(INDEX, 0)); }while(0)
765
+    #elif ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
766
+      #define SET_E_STEP_DIR(INDEX) do{ if (e_steps) { e_steps < 0 ? REV_E_DIR() : NORM_E_DIR(); } }while(0)
762
     #else
767
     #else
763
-      #define SET_E_STEP_DIR(INDEX) \
764
-        if (e_steps) E## INDEX ##_DIR_WRITE(e_steps < 0 ? INVERT_E## INDEX ##_DIR : !INVERT_E## INDEX ##_DIR)
768
+      #define SET_E_STEP_DIR(INDEX) do{ if (e_steps) E## INDEX ##_DIR_WRITE(e_steps < 0 ? INVERT_E## INDEX ##_DIR : !INVERT_E## INDEX ##_DIR); }while(0)
765
     #endif
769
     #endif
766
 
770
 
767
-    #define START_E_PULSE(INDEX) \
768
-      if (e_steps) E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN)
769
-
770
-    #define STOP_E_PULSE(INDEX) \
771
-      if (e_steps) { \
772
-        e_steps < 0 ? ++e_steps : --e_steps; \
773
-        E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); \
774
-      }
771
+    #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
772
+      #define START_E_PULSE(INDEX) do{ if (e_steps) E_STEP_WRITE(!INVERT_E_STEP_PIN); }while(0)
773
+      #define STOP_E_PULSE(INDEX) do{ if (e_steps) { E_STEP_WRITE(INVERT_E_STEP_PIN); e_steps < 0 ? ++e_steps : --e_steps; } }while(0)
774
+    #else
775
+      #define START_E_PULSE(INDEX) do{ if (e_steps) E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN); }while(0)
776
+      #define STOP_E_PULSE(INDEX) do { if (e_steps) { E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); e_steps < 0 ? ++e_steps : --e_steps; } }while(0)
777
+    #endif
775
 
778
 
776
     if (current_block->use_advance_lead) {
779
     if (current_block->use_advance_lead) {
777
       if (step_events_completed > LA_decelerate_after && current_adv_steps > final_adv_steps) {
780
       if (step_events_completed > LA_decelerate_after && current_adv_steps > final_adv_steps) {
793
     else
796
     else
794
       nextAdvanceISR = ADV_NEVER;
797
       nextAdvanceISR = ADV_NEVER;
795
 
798
 
796
-    switch(LA_active_extruder) {
799
+    switch (LA_active_extruder) {
797
       case 0: SET_E_STEP_DIR(0); break;
800
       case 0: SET_E_STEP_DIR(0); break;
798
       #if EXTRUDERS > 1
801
       #if EXTRUDERS > 1
799
         case 1: SET_E_STEP_DIR(1); break;
802
         case 1: SET_E_STEP_DIR(1); break;
816
         hal_timer_t pulse_start = HAL_timer_get_count(PULSE_TIMER_NUM);
819
         hal_timer_t pulse_start = HAL_timer_get_count(PULSE_TIMER_NUM);
817
       #endif
820
       #endif
818
 
821
 
819
-      switch(LA_active_extruder) {
822
+      switch (LA_active_extruder) {
820
         case 0: START_E_PULSE(0); break;
823
         case 0: START_E_PULSE(0); break;
821
         #if EXTRUDERS > 1
824
         #if EXTRUDERS > 1
822
           case 1: START_E_PULSE(1); break;
825
           case 1: START_E_PULSE(1); break;
840
         DELAY_NOPS(EXTRA_CYCLES_E);
843
         DELAY_NOPS(EXTRA_CYCLES_E);
841
       #endif
844
       #endif
842
 
845
 
843
-      switch(LA_active_extruder) {
846
+      switch (LA_active_extruder) {
844
         case 0: STOP_E_PULSE(0); break;
847
         case 0: STOP_E_PULSE(0); break;
845
         #if EXTRUDERS > 1
848
         #if EXTRUDERS > 1
846
           case 1: STOP_E_PULSE(1); break;
849
           case 1: STOP_E_PULSE(1); break;

+ 12
- 9
Marlin/src/module/stepper.h Parādīt failu

104
       static uint16_t current_adv_steps, final_adv_steps, max_adv_steps; // Copy from current executed block. Needed because current_block is set to NULL "too early".
104
       static uint16_t current_adv_steps, final_adv_steps, max_adv_steps; // Copy from current executed block. Needed because current_block is set to NULL "too early".
105
       #define _NEXT_ISR(T) nextMainISR = T
105
       #define _NEXT_ISR(T) nextMainISR = T
106
       static int8_t e_steps;
106
       static int8_t e_steps;
107
-      static int8_t LA_active_extruder; // Copy from current executed block. Needed because current_block is set to NULL "too early".
108
       static bool use_advance_lead;
107
       static bool use_advance_lead;
108
+      #if E_STEPPERS > 1
109
+        static int8_t LA_active_extruder; // Copy from current executed block. Needed because current_block is set to NULL "too early".
110
+      #else
111
+        constexpr int8_t LA_active_extruder = 0;
112
+      #endif
109
 
113
 
110
     #else // !LIN_ADVANCE
114
     #else // !LIN_ADVANCE
111
 
115
 
352
       static int8_t last_extruder = -1;
356
       static int8_t last_extruder = -1;
353
 
357
 
354
       #if ENABLED(LIN_ADVANCE)
358
       #if ENABLED(LIN_ADVANCE)
355
-        if (current_block->active_extruder != last_extruder) {
356
-          current_adv_steps = 0; // If the now active extruder wasn't in use during the last move, its pressure is most likely gone.
357
-          LA_active_extruder = current_block->active_extruder;
358
-        }
359
+        #if E_STEPPERS > 1
360
+          if (current_block->active_extruder != last_extruder) {
361
+            current_adv_steps = 0; // If the now active extruder wasn't in use during the last move, its pressure is most likely gone.
362
+            LA_active_extruder = current_block->active_extruder;
363
+          }
364
+        #endif
359
 
365
 
360
-        if (current_block->use_advance_lead) {
366
+        if ((use_advance_lead = current_block->use_advance_lead)) {
361
           LA_decelerate_after = current_block->decelerate_after;
367
           LA_decelerate_after = current_block->decelerate_after;
362
           final_adv_steps = current_block->final_adv_steps;
368
           final_adv_steps = current_block->final_adv_steps;
363
           max_adv_steps = current_block->max_adv_steps;
369
           max_adv_steps = current_block->max_adv_steps;
364
-          use_advance_lead = true;
365
         }
370
         }
366
-        else
367
-          use_advance_lead = false;
368
       #endif
371
       #endif
369
 
372
 
370
       if (current_block->direction_bits != last_direction_bits || current_block->active_extruder != last_extruder) {
373
       if (current_block->direction_bits != last_direction_bits || current_block->active_extruder != last_extruder) {

Notiek ielāde…
Atcelt
Saglabāt