Browse Source

Apply `const` in Stepper::isr

Scott Lahteine 7 years ago
parent
commit
ac96ae89f9
1 changed files with 17 additions and 23 deletions
  1. 17
    23
      Marlin/stepper.cpp

+ 17
- 23
Marlin/stepper.cpp View File

@@ -366,7 +366,7 @@ void Stepper::isr() {
366 366
     #define SPLIT(L) do { \
367 367
       _SPLIT(L); \
368 368
       if (ENDSTOPS_ENABLED && L > ENDSTOP_NOMINAL_OCR_VAL) { \
369
-        uint16_t remainder = (uint16_t)L % (ENDSTOP_NOMINAL_OCR_VAL); \
369
+        const uint16_t remainder = (uint16_t)L % (ENDSTOP_NOMINAL_OCR_VAL); \
370 370
         ocr_val = (remainder < OCR_VAL_TOLERANCE) ? ENDSTOP_NOMINAL_OCR_VAL + remainder : ENDSTOP_NOMINAL_OCR_VAL; \
371 371
         step_remaining = (uint16_t)L - ocr_val; \
372 372
       } \
@@ -447,8 +447,6 @@ void Stepper::isr() {
447 447
   }
448 448
 
449 449
   // Update endstops state, if enabled
450
-
451
-
452 450
   #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
453 451
     if (e_hit && ENDSTOPS_ENABLED) {
454 452
       endstops.update();
@@ -640,7 +638,7 @@ void Stepper::isr() {
640 638
 
641 639
   #if ENABLED(LIN_ADVANCE)
642 640
     if (current_block->use_advance_lead) {
643
-      int delta_adv_steps = current_estep_rate[TOOL_E_INDEX] - current_adv_steps[TOOL_E_INDEX];
641
+      const int delta_adv_steps = current_estep_rate[TOOL_E_INDEX] - current_adv_steps[TOOL_E_INDEX];
644 642
       current_adv_steps[TOOL_E_INDEX] += delta_adv_steps;
645 643
       #if ENABLED(MIXING_EXTRUDER)
646 644
         // Mixing extruders apply advance lead proportionally
@@ -668,7 +666,7 @@ void Stepper::isr() {
668 666
     NOMORE(acc_step_rate, current_block->nominal_rate);
669 667
 
670 668
     // step_rate to timer interval
671
-    uint16_t timer = calc_timer(acc_step_rate);
669
+    const uint16_t timer = calc_timer(acc_step_rate);
672 670
 
673 671
     SPLIT(timer);  // split step into multiple ISRs if larger than  ENDSTOP_NOMINAL_OCR_VAL
674 672
     _NEXT_ISR(ocr_val);
@@ -691,8 +689,8 @@ void Stepper::isr() {
691 689
       advance += advance_rate * step_loops;
692 690
       //NOLESS(advance, current_block->advance);
693 691
 
694
-      long advance_whole = advance >> 8,
695
-           advance_factor = advance_whole - old_advance;
692
+      const long advance_whole = advance >> 8,
693
+                 advance_factor = advance_whole - old_advance;
696 694
 
697 695
       // Do E steps + advance steps
698 696
       #if ENABLED(MIXING_EXTRUDER)
@@ -724,7 +722,7 @@ void Stepper::isr() {
724 722
       step_rate = current_block->final_rate;
725 723
 
726 724
     // step_rate to timer interval
727
-    uint16_t timer = calc_timer(step_rate);
725
+    const uint16_t timer = calc_timer(step_rate);
728 726
 
729 727
     SPLIT(timer);  // split step into multiple ISRs if larger than  ENDSTOP_NOMINAL_OCR_VAL
730 728
     _NEXT_ISR(ocr_val);
@@ -748,8 +746,8 @@ void Stepper::isr() {
748 746
       NOLESS(advance, final_advance);
749 747
 
750 748
       // Do E steps + advance steps
751
-      long advance_whole = advance >> 8,
752
-           advance_factor = advance_whole - old_advance;
749
+      const long advance_whole = advance >> 8,
750
+                 advance_factor = advance_whole - old_advance;
753 751
 
754 752
       #if ENABLED(MIXING_EXTRUDER)
755 753
         MIXING_STEPPERS_LOOP(j)
@@ -1179,7 +1177,7 @@ void Stepper::set_e_position(const long &e) {
1179 1177
  */
1180 1178
 long Stepper::position(AxisEnum axis) {
1181 1179
   CRITICAL_SECTION_START;
1182
-  long count_pos = count_position[axis];
1180
+  const long count_pos = count_position[axis];
1183 1181
   CRITICAL_SECTION_END;
1184 1182
   return count_pos;
1185 1183
 }
@@ -1246,9 +1244,9 @@ void Stepper::endstop_triggered(AxisEnum axis) {
1246 1244
 
1247 1245
 void Stepper::report_positions() {
1248 1246
   CRITICAL_SECTION_START;
1249
-  long xpos = count_position[X_AXIS],
1250
-       ypos = count_position[Y_AXIS],
1251
-       zpos = count_position[Z_AXIS];
1247
+  const long xpos = count_position[X_AXIS],
1248
+             ypos = count_position[Y_AXIS],
1249
+             zpos = count_position[Z_AXIS];
1252 1250
   CRITICAL_SECTION_END;
1253 1251
 
1254 1252
   #if CORE_IS_XY || CORE_IS_XZ || IS_SCARA
@@ -1290,7 +1288,7 @@ void Stepper::report_positions() {
1290 1288
   #define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true)
1291 1289
 
1292 1290
   #if EXTRA_CYCLES_BABYSTEP > 20
1293
-    #define _SAVE_START (pulse_start = TCNT0)
1291
+    #define _SAVE_START const uint32_t pulse_start = TCNT0
1294 1292
     #define _PULSE_WAIT while (EXTRA_CYCLES_BABYSTEP > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
1295 1293
   #else
1296 1294
     #define _SAVE_START NOOP
@@ -1322,10 +1320,6 @@ void Stepper::report_positions() {
1322 1320
     cli();
1323 1321
     uint8_t old_dir;
1324 1322
 
1325
-    #if EXTRA_CYCLES_BABYSTEP > 20
1326
-      uint32_t pulse_start;
1327
-    #endif
1328
-
1329 1323
     switch (axis) {
1330 1324
 
1331 1325
       #if ENABLED(BABYSTEP_XY)
@@ -1348,15 +1342,15 @@ void Stepper::report_positions() {
1348 1342
 
1349 1343
         #else // DELTA
1350 1344
 
1351
-          bool z_direction = direction ^ BABYSTEP_INVERT_Z;
1345
+          const bool z_direction = direction ^ BABYSTEP_INVERT_Z;
1352 1346
 
1353 1347
           enable_X();
1354 1348
           enable_Y();
1355 1349
           enable_Z();
1356 1350
 
1357
-          uint8_t old_x_dir_pin = X_DIR_READ,
1358
-                  old_y_dir_pin = Y_DIR_READ,
1359
-                  old_z_dir_pin = Z_DIR_READ;
1351
+          const uint8_t old_x_dir_pin = X_DIR_READ,
1352
+                        old_y_dir_pin = Y_DIR_READ,
1353
+                        old_z_dir_pin = Z_DIR_READ;
1360 1354
 
1361 1355
           X_DIR_WRITE(INVERT_X_DIR ^ z_direction);
1362 1356
           Y_DIR_WRITE(INVERT_Y_DIR ^ z_direction);

Loading…
Cancel
Save