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
 
32
 
33
 #include "../lcd/ultralcd.h"
33
 #include "../lcd/ultralcd.h"
34
 #include "../gcode/queue.h"
34
 #include "../gcode/queue.h"
35
+#include "../module/motion.h"
35
 #include "../module/planner.h"
36
 #include "../module/planner.h"
36
 #include "../module/printcounter.h"
37
 #include "../module/printcounter.h"
37
 #include "../module/temperature.h"
38
 #include "../module/temperature.h"
43
 JobRecoveryPhase job_recovery_phase = JOB_RECOVERY_IDLE;
44
 JobRecoveryPhase job_recovery_phase = JOB_RECOVERY_IDLE;
44
 uint8_t job_recovery_commands_count; //=0
45
 uint8_t job_recovery_commands_count; //=0
45
 char job_recovery_commands[BUFSIZE + APPEND_CMD_COUNT][MAX_CMD_SIZE];
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
 #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
50
 #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
50
   void debug_print_job_recovery(const bool recovery) {
51
   void debug_print_job_recovery(const bool recovery) {

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

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

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

87
  */
87
  */
88
 float destination[XYZE] = { 0 };
88
 float destination[XYZE] = { 0 };
89
 
89
 
90
-
91
 // The active extruder (tool). Set with T<extruder> command.
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
 // Extruder offsets
95
 // Extruder offsets
95
 #if HAS_HOTEND_OFFSET
96
 #if HAS_HOTEND_OFFSET

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

76
 extern int16_t feedrate_percentage;
76
 extern int16_t feedrate_percentage;
77
 #define MMS_SCALED(MM_S) ((MM_S)*feedrate_percentage*0.01f)
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
 #if HAS_HOTEND_OFFSET
86
 #if HAS_HOTEND_OFFSET
82
   extern float hotend_offset[XYZ][HOTENDS];
87
   extern float hotend_offset[XYZ][HOTENDS];

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

1759
     block->e_to_p_pressure = baricuda_e_to_p_pressure;
1759
     block->e_to_p_pressure = baricuda_e_to_p_pressure;
1760
   #endif
1760
   #endif
1761
 
1761
 
1762
-  block->active_extruder = extruder;
1762
+  #if EXTRUDERS > 1
1763
+    block->active_extruder = extruder;
1764
+  #endif
1763
 
1765
 
1764
   #if ENABLED(AUTO_POWER_CONTROL)
1766
   #if ENABLED(AUTO_POWER_CONTROL)
1765
     if (block->steps[X_AXIS] || block->steps[Y_AXIS] || block->steps[Z_AXIS])
1767
     if (block->steps[X_AXIS] || block->steps[Y_AXIS] || block->steps[Z_AXIS])

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

101
   };
101
   };
102
   uint32_t step_event_count;                // The number of step events required to complete this block
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
   #if ENABLED(MIXING_EXTRUDER)
108
   #if ENABLED(MIXING_EXTRUDER)
107
     uint32_t mix_steps[MIXING_STEPPERS];    // Scaled steps[E_AXIS] for the mixing steppers
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
 
124
 
125
 bool Stepper::abort_current_block;
125
 bool Stepper::abort_current_block;
126
 
126
 
127
-#if DISABLED(MIXING_EXTRUDER)
127
+#if DISABLED(MIXING_EXTRUDER) && EXTRUDERS > 1
128
   uint8_t Stepper::last_moved_extruder = 0xFF;
128
   uint8_t Stepper::last_moved_extruder = 0xFF;
129
 #endif
129
 #endif
130
 
130
 
159
   int32_t Stepper::delta_error_m[MIXING_STEPPERS];
159
   int32_t Stepper::delta_error_m[MIXING_STEPPERS];
160
   uint32_t Stepper::advance_dividend_m[MIXING_STEPPERS],
160
   uint32_t Stepper::advance_dividend_m[MIXING_STEPPERS],
161
            Stepper::advance_divisor_m;
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
 #endif
164
 #endif
165
 
165
 
166
 #if ENABLED(S_CURVE_ACCELERATION)
166
 #if ENABLED(S_CURVE_ACCELERATION)
1702
           advance_dividend_m[i] = current_block->mix_steps[i] << 1;
1702
           advance_dividend_m[i] = current_block->mix_steps[i] << 1;
1703
         }
1703
         }
1704
         advance_divisor_m = e_steps << 1;
1704
         advance_divisor_m = e_steps << 1;
1705
-      #else
1705
+      #elif EXTRUDERS > 1
1706
         active_extruder = current_block->active_extruder;
1706
         active_extruder = current_block->active_extruder;
1707
       #endif
1707
       #endif
1708
 
1708
 
1729
         #endif
1729
         #endif
1730
       ) {
1730
       ) {
1731
         last_direction_bits = current_block->direction_bits;
1731
         last_direction_bits = current_block->direction_bits;
1732
-        #if DISABLED(MIXING_EXTRUDER)
1732
+        #if DISABLED(MIXING_EXTRUDER) && EXTRUDERS > 1
1733
           last_moved_extruder = active_extruder;
1733
           last_moved_extruder = active_extruder;
1734
         #endif
1734
         #endif
1735
         set_directions();
1735
         set_directions();

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

254
 
254
 
255
     static bool abort_current_block;        // Signals to the stepper that current block should be aborted
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
     #endif
262
     #endif
260
 
263
 
261
     #if ENABLED(X_DUAL_ENDSTOPS)
264
     #if ENABLED(X_DUAL_ENDSTOPS)
293
                       advance_divisor_m;
296
                       advance_divisor_m;
294
       #define MIXING_STEPPERS_LOOP(VAR) \
297
       #define MIXING_STEPPERS_LOOP(VAR) \
295
         for (uint8_t VAR = 0; VAR < MIXING_STEPPERS; VAR++)
298
         for (uint8_t VAR = 0; VAR < MIXING_STEPPERS; VAR++)
299
+    #elif EXTRUDERS > 1
300
+      static uint8_t active_extruder;
296
     #else
301
     #else
297
-      static int8_t active_extruder;      // Active extruder
302
+      static constexpr uint8_t active_extruder = 0;
298
     #endif
303
     #endif
299
 
304
 
300
     #if ENABLED(S_CURVE_ACCELERATION)
305
     #if ENABLED(S_CURVE_ACCELERATION)
385
     // The extruder associated to the last movement
390
     // The extruder associated to the last movement
386
     FORCE_INLINE static uint8_t movement_extruder() {
391
     FORCE_INLINE static uint8_t movement_extruder() {
387
       return
392
       return
388
-        #if ENABLED(MIXING_EXTRUDER)
393
+        #if ENABLED(MIXING_EXTRUDER) || EXTRUDERS < 2
389
           0
394
           0
390
         #else
395
         #else
391
           last_moved_extruder
396
           last_moved_extruder

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

158
       #if ENABLED(DEBUG_LEVELING_FEATURE)
158
       #if ENABLED(DEBUG_LEVELING_FEATURE)
159
         if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(4) Move to position near new extruder");
159
         if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(4) Move to position near new extruder");
160
       #endif
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
       #if ENABLED(DEBUG_LEVELING_FEATURE)
163
       #if ENABLED(DEBUG_LEVELING_FEATURE)
164
         if (DEBUGGING(LEVELING)) DEBUG_POS("Move away from parked extruder", current_position);
164
         if (DEBUGGING(LEVELING)) DEBUG_POS("Move away from parked extruder", current_position);
177
       pe_activate_magnet(tmp_extruder);
177
       pe_activate_magnet(tmp_extruder);
178
 
178
 
179
       // STEP 6
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
       planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
181
       planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
182
       current_position[X_AXIS] = grabpos;
182
       current_position[X_AXIS] = grabpos;
183
       #if ENABLED(DEBUG_LEVELING_FEATURE)
183
       #if ENABLED(DEBUG_LEVELING_FEATURE)
393
       #define CUR_Z current_position[Z_AXIS]
393
       #define CUR_Z current_position[Z_AXIS]
394
       #define CUR_E current_position[E_AXIS]
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
       planner.synchronize();
400
       planner.synchronize();
401
     }
401
     }
607
         select_multiplexed_stepper(tmp_extruder);
607
         select_multiplexed_stepper(tmp_extruder);
608
       #endif
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
     #endif // HOTENDS <= 1
615
     #endif // HOTENDS <= 1
614
 
616
 
627
     #endif
629
     #endif
628
 
630
 
629
     SERIAL_ECHO_START();
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
   #endif // !MIXING_EXTRUDER || MIXING_VIRTUAL_TOOLS <= 1
634
   #endif // !MIXING_EXTRUDER || MIXING_VIRTUAL_TOOLS <= 1
633
 }
635
 }

Loading…
Cancel
Save