Browse Source

Save some PROGMEM with constexpr (#11798)

When possible, make `active_extruder` a `constexpr` to save some PROGMEM.
Scott Lahteine 6 years ago
parent
commit
d882717d98
No account linked to committer's email address

+ 3
- 2
Marlin/src/feature/power_loss_recovery.cpp View File

@@ -32,6 +32,7 @@
32 32
 
33 33
 #include "../lcd/ultralcd.h"
34 34
 #include "../gcode/queue.h"
35
+#include "../module/motion.h"
35 36
 #include "../module/planner.h"
36 37
 #include "../module/printcounter.h"
37 38
 #include "../module/temperature.h"
@@ -43,8 +44,8 @@ job_recovery_info_t job_recovery_info;
43 44
 JobRecoveryPhase job_recovery_phase = JOB_RECOVERY_IDLE;
44 45
 uint8_t job_recovery_commands_count; //=0
45 46
 char job_recovery_commands[BUFSIZE + APPEND_CMD_COUNT][MAX_CMD_SIZE];
46
-// Extern
47
-extern uint8_t active_extruder, commands_in_queue, cmd_queue_index_r;
47
+
48
+extern uint8_t commands_in_queue, cmd_queue_index_r;
48 49
 
49 50
 #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
50 51
   void debug_print_job_recovery(const bool recovery) {

+ 1
- 1
Marlin/src/lcd/ultralcd.h View File

@@ -43,6 +43,7 @@
43 43
 
44 44
   #if ENABLED(ADVANCED_PAUSE_FEATURE)
45 45
     #include "../feature/pause.h"
46
+    #include "../module/motion.h" // for active_extruder
46 47
   #endif
47 48
 
48 49
   bool lcd_hasstatus();
@@ -116,7 +117,6 @@
116 117
     void lcd_completion_feedback(const bool good=true);
117 118
 
118 119
     #if ENABLED(ADVANCED_PAUSE_FEATURE)
119
-      extern uint8_t active_extruder;
120 120
       void lcd_advanced_pause_show_message(const AdvancedPauseMessage message,
121 121
                                            const AdvancedPauseMode mode=ADVANCED_PAUSE_MODE_PAUSE_PRINT,
122 122
                                            const uint8_t extruder=active_extruder);

+ 3
- 2
Marlin/src/module/motion.cpp View File

@@ -87,9 +87,10 @@ float current_position[XYZE] = { 0 };
87 87
  */
88 88
 float destination[XYZE] = { 0 };
89 89
 
90
-
91 90
 // The active extruder (tool). Set with T<extruder> command.
92
-uint8_t active_extruder; // = 0;
91
+#if EXTRUDERS > 1
92
+  uint8_t active_extruder; // = 0
93
+#endif
93 94
 
94 95
 // Extruder offsets
95 96
 #if HAS_HOTEND_OFFSET

+ 6
- 1
Marlin/src/module/motion.h View File

@@ -76,7 +76,12 @@ extern float feedrate_mm_s;
76 76
 extern int16_t feedrate_percentage;
77 77
 #define MMS_SCALED(MM_S) ((MM_S)*feedrate_percentage*0.01f)
78 78
 
79
-extern uint8_t active_extruder;
79
+// The active extruder (tool). Set with T<extruder> command.
80
+#if EXTRUDERS > 1
81
+  extern uint8_t active_extruder;
82
+#else
83
+  constexpr uint8_t active_extruder = 0;
84
+#endif
80 85
 
81 86
 #if HAS_HOTEND_OFFSET
82 87
   extern float hotend_offset[XYZ][HOTENDS];

+ 3
- 1
Marlin/src/module/planner.cpp View File

@@ -1759,7 +1759,9 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
1759 1759
     block->e_to_p_pressure = baricuda_e_to_p_pressure;
1760 1760
   #endif
1761 1761
 
1762
-  block->active_extruder = extruder;
1762
+  #if EXTRUDERS > 1
1763
+    block->active_extruder = extruder;
1764
+  #endif
1763 1765
 
1764 1766
   #if ENABLED(AUTO_POWER_CONTROL)
1765 1767
     if (block->steps[X_AXIS] || block->steps[Y_AXIS] || block->steps[Z_AXIS])

+ 3
- 1
Marlin/src/module/planner.h View File

@@ -101,7 +101,9 @@ typedef struct {
101 101
   };
102 102
   uint32_t step_event_count;                // The number of step events required to complete this block
103 103
 
104
-  uint8_t active_extruder;                  // The extruder to move (if E move)
104
+  #if EXTRUDERS > 1
105
+    uint8_t active_extruder;                // The extruder to move (if E move)
106
+  #endif
105 107
 
106 108
   #if ENABLED(MIXING_EXTRUDER)
107 109
     uint32_t mix_steps[MIXING_STEPPERS];    // Scaled steps[E_AXIS] for the mixing steppers

+ 5
- 5
Marlin/src/module/stepper.cpp View File

@@ -124,7 +124,7 @@ uint8_t Stepper::last_direction_bits = 0,
124 124
 
125 125
 bool Stepper::abort_current_block;
126 126
 
127
-#if DISABLED(MIXING_EXTRUDER)
127
+#if DISABLED(MIXING_EXTRUDER) && EXTRUDERS > 1
128 128
   uint8_t Stepper::last_moved_extruder = 0xFF;
129 129
 #endif
130 130
 
@@ -159,8 +159,8 @@ uint32_t Stepper::advance_dividend[XYZE] = { 0 },
159 159
   int32_t Stepper::delta_error_m[MIXING_STEPPERS];
160 160
   uint32_t Stepper::advance_dividend_m[MIXING_STEPPERS],
161 161
            Stepper::advance_divisor_m;
162
-#else
163
-  int8_t Stepper::active_extruder;           // Active extruder
162
+#elif EXTRUDERS > 1
163
+  uint8_t Stepper::active_extruder;          // Active extruder
164 164
 #endif
165 165
 
166 166
 #if ENABLED(S_CURVE_ACCELERATION)
@@ -1702,7 +1702,7 @@ uint32_t Stepper::stepper_block_phase_isr() {
1702 1702
           advance_dividend_m[i] = current_block->mix_steps[i] << 1;
1703 1703
         }
1704 1704
         advance_divisor_m = e_steps << 1;
1705
-      #else
1705
+      #elif EXTRUDERS > 1
1706 1706
         active_extruder = current_block->active_extruder;
1707 1707
       #endif
1708 1708
 
@@ -1729,7 +1729,7 @@ uint32_t Stepper::stepper_block_phase_isr() {
1729 1729
         #endif
1730 1730
       ) {
1731 1731
         last_direction_bits = current_block->direction_bits;
1732
-        #if DISABLED(MIXING_EXTRUDER)
1732
+        #if DISABLED(MIXING_EXTRUDER) && EXTRUDERS > 1
1733 1733
           last_moved_extruder = active_extruder;
1734 1734
         #endif
1735 1735
         set_directions();

+ 9
- 4
Marlin/src/module/stepper.h View File

@@ -254,8 +254,11 @@ class Stepper {
254 254
 
255 255
     static bool abort_current_block;        // Signals to the stepper that current block should be aborted
256 256
 
257
-    #if DISABLED(MIXING_EXTRUDER)
258
-      static uint8_t last_moved_extruder;   // Last-moved extruder, as set when the last movement was fetched from planner
257
+    // Last-moved extruder, as set when the last movement was fetched from planner
258
+    #if EXTRUDERS < 2
259
+      static constexpr uint8_t last_moved_extruder = 0;
260
+    #elif DISABLED(MIXING_EXTRUDER)
261
+      static uint8_t last_moved_extruder;
259 262
     #endif
260 263
 
261 264
     #if ENABLED(X_DUAL_ENDSTOPS)
@@ -293,8 +296,10 @@ class Stepper {
293 296
                       advance_divisor_m;
294 297
       #define MIXING_STEPPERS_LOOP(VAR) \
295 298
         for (uint8_t VAR = 0; VAR < MIXING_STEPPERS; VAR++)
299
+    #elif EXTRUDERS > 1
300
+      static uint8_t active_extruder;
296 301
     #else
297
-      static int8_t active_extruder;      // Active extruder
302
+      static constexpr uint8_t active_extruder = 0;
298 303
     #endif
299 304
 
300 305
     #if ENABLED(S_CURVE_ACCELERATION)
@@ -385,7 +390,7 @@ class Stepper {
385 390
     // The extruder associated to the last movement
386 391
     FORCE_INLINE static uint8_t movement_extruder() {
387 392
       return
388
-        #if ENABLED(MIXING_EXTRUDER)
393
+        #if ENABLED(MIXING_EXTRUDER) || EXTRUDERS < 2
389 394
           0
390 395
         #else
391 396
           last_moved_extruder

+ 10
- 8
Marlin/src/module/tool_change.cpp View File

@@ -158,7 +158,7 @@
158 158
       #if ENABLED(DEBUG_LEVELING_FEATURE)
159 159
         if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(4) Move to position near new extruder");
160 160
       #endif
161
-      current_position[X_AXIS] += (active_extruder == 0 ? 10 : -10); // move 10mm away from parked extruder
161
+      current_position[X_AXIS] += active_extruder ? -10 : 10; // move 10mm away from parked extruder
162 162
 
163 163
       #if ENABLED(DEBUG_LEVELING_FEATURE)
164 164
         if (DEBUGGING(LEVELING)) DEBUG_POS("Move away from parked extruder", current_position);
@@ -177,7 +177,7 @@
177 177
       pe_activate_magnet(tmp_extruder);
178 178
 
179 179
       // STEP 6
180
-      current_position[X_AXIS] = grabpos + (tmp_extruder == 0 ? (+10) : (-10));
180
+      current_position[X_AXIS] = grabpos + (tmp_extruder ? -10 : 10);
181 181
       planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
182 182
       current_position[X_AXIS] = grabpos;
183 183
       #if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -393,9 +393,9 @@ inline void invalid_extruder_error(const uint8_t e) {
393 393
       #define CUR_Z current_position[Z_AXIS]
394 394
       #define CUR_E current_position[E_AXIS]
395 395
 
396
-      planner.buffer_line( CUR_X, CUR_Y, raised_z, CUR_E, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
397
-      planner.buffer_line( xhome, CUR_Y, raised_z, CUR_E, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
398
-      planner.buffer_line( xhome, CUR_Y, CUR_Z,    CUR_E, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
396
+      planner.buffer_line(CUR_X, CUR_Y, raised_z, CUR_E, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
397
+      planner.buffer_line(xhome, CUR_Y, raised_z, CUR_E, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
398
+      planner.buffer_line(xhome, CUR_Y, CUR_Z,    CUR_E, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
399 399
 
400 400
       planner.synchronize();
401 401
     }
@@ -607,8 +607,10 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
607 607
         select_multiplexed_stepper(tmp_extruder);
608 608
       #endif
609 609
 
610
-      // Set the new active extruder
611
-      active_extruder = tmp_extruder;
610
+      #if EXTRUDERS > 1
611
+        // Set the new active extruder
612
+        active_extruder = tmp_extruder;
613
+      #endif
612 614
 
613 615
     #endif // HOTENDS <= 1
614 616
 
@@ -627,7 +629,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
627 629
     #endif
628 630
 
629 631
     SERIAL_ECHO_START();
630
-    SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, (int)active_extruder);
632
+    SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, int(active_extruder));
631 633
 
632 634
   #endif // !MIXING_EXTRUDER || MIXING_VIRTUAL_TOOLS <= 1
633 635
 }

Loading…
Cancel
Save