Browse Source

Use a macro for array copies

Scott Lahteine 7 years ago
parent
commit
87b03b16bd
3 changed files with 18 additions and 17 deletions
  1. 15
    15
      Marlin/Marlin_main.cpp
  2. 1
    0
      Marlin/macros.h
  3. 2
    2
      Marlin/planner.cpp

+ 15
- 15
Marlin/Marlin_main.cpp View File

@@ -1567,8 +1567,8 @@ inline void line_to_destination(float fr_mm_s) {
1567 1567
 }
1568 1568
 inline void line_to_destination() { line_to_destination(feedrate_mm_s); }
1569 1569
 
1570
-inline void set_current_to_destination() { memcpy(current_position, destination, sizeof(current_position)); }
1571
-inline void set_destination_to_current() { memcpy(destination, current_position, sizeof(destination)); }
1570
+inline void set_current_to_destination() { COPY(current_position, destination); }
1571
+inline void set_destination_to_current() { COPY(destination, current_position); }
1572 1572
 
1573 1573
 #if IS_KINEMATIC
1574 1574
   /**
@@ -3583,7 +3583,7 @@ inline void gcode_G28() {
3583 3583
         HOMEAXIS(X);
3584 3584
 
3585 3585
         // Consider the active extruder to be parked
3586
-        memcpy(raised_parked_position, current_position, sizeof(raised_parked_position));
3586
+        COPY(raised_parked_position, current_position);
3587 3587
         delayed_move_time = 0;
3588 3588
         active_extruder_parked = true;
3589 3589
 
@@ -4383,7 +4383,7 @@ inline void gcode_G28() {
4383 4383
         #endif
4384 4384
 
4385 4385
         float converted[XYZ];
4386
-        memcpy(converted, current_position, sizeof(converted));
4386
+        COPY(converted, current_position);
4387 4387
 
4388 4388
         planner.abl_enabled = true;
4389 4389
         planner.unapply_leveling(converted); // use conversion machinery
@@ -4405,7 +4405,7 @@ inline void gcode_G28() {
4405 4405
         }
4406 4406
 
4407 4407
         // The rotated XY and corrected Z are now current_position
4408
-        memcpy(current_position, converted, sizeof(converted));
4408
+        COPY(current_position, converted);
4409 4409
 
4410 4410
         #if ENABLED(DEBUG_LEVELING_FEATURE)
4411 4411
           if (DEBUGGING(LEVELING)) DEBUG_POS("G29 corrected XYZ", current_position);
@@ -7965,7 +7965,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
7965 7965
               break;
7966 7966
             case DXC_AUTO_PARK_MODE:
7967 7967
               // record raised toolhead position for use by unpark
7968
-              memcpy(raised_parked_position, current_position, sizeof(raised_parked_position));
7968
+              COPY(raised_parked_position, current_position);
7969 7969
               raised_parked_position[Z_AXIS] += TOOLCHANGE_UNPARK_ZLIFT;
7970 7970
               #if ENABLED(max_software_endstops)
7971 7971
                 NOMORE(raised_parked_position[Z_AXIS], soft_endstop_max[Z_AXIS]);
@@ -9332,7 +9332,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
9332 9332
     planner.unapply_leveling(cartes);
9333 9333
   #endif
9334 9334
   if (axis == ALL_AXES)
9335
-    memcpy(current_position, cartes, sizeof(cartes));
9335
+    COPY(current_position, cartes);
9336 9336
   else
9337 9337
     current_position[axis] = cartes[axis];
9338 9338
 }
@@ -9367,14 +9367,14 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
9367 9367
     // Split at the left/front border of the right/top square
9368 9368
     int8_t gcx = max(cx1, cx2), gcy = max(cy1, cy2);
9369 9369
     if (cx2 != cx1 && TEST(x_splits, gcx)) {
9370
-      memcpy(end, destination, sizeof(end));
9370
+      COPY(end, destination);
9371 9371
       destination[X_AXIS] = LOGICAL_X_POSITION(mbl.get_probe_x(gcx));
9372 9372
       normalized_dist = (destination[X_AXIS] - current_position[X_AXIS]) / (end[X_AXIS] - current_position[X_AXIS]);
9373 9373
       destination[Y_AXIS] = MBL_SEGMENT_END(Y);
9374 9374
       CBI(x_splits, gcx);
9375 9375
     }
9376 9376
     else if (cy2 != cy1 && TEST(y_splits, gcy)) {
9377
-      memcpy(end, destination, sizeof(end));
9377
+      COPY(end, destination);
9378 9378
       destination[Y_AXIS] = LOGICAL_Y_POSITION(mbl.get_probe_y(gcy));
9379 9379
       normalized_dist = (destination[Y_AXIS] - current_position[Y_AXIS]) / (end[Y_AXIS] - current_position[Y_AXIS]);
9380 9380
       destination[X_AXIS] = MBL_SEGMENT_END(X);
@@ -9394,7 +9394,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
9394 9394
     mesh_line_to_destination(fr_mm_s, x_splits, y_splits);
9395 9395
 
9396 9396
     // Restore destination from stack
9397
-    memcpy(destination, end, sizeof(end));
9397
+    COPY(destination, end);
9398 9398
     mesh_line_to_destination(fr_mm_s, x_splits, y_splits);
9399 9399
   }
9400 9400
 
@@ -9430,14 +9430,14 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
9430 9430
     // Split at the left/front border of the right/top square
9431 9431
     int8_t gcx = max(cx1, cx2), gcy = max(cy1, cy2);
9432 9432
     if (cx2 != cx1 && TEST(x_splits, gcx)) {
9433
-      memcpy(end, destination, sizeof(end));
9433
+      COPY(end, destination);
9434 9434
       destination[X_AXIS] = LOGICAL_X_POSITION(bilinear_start[X_AXIS] + ABL_BG_SPACING(X_AXIS) * gcx);
9435 9435
       normalized_dist = (destination[X_AXIS] - current_position[X_AXIS]) / (end[X_AXIS] - current_position[X_AXIS]);
9436 9436
       destination[Y_AXIS] = LINE_SEGMENT_END(Y);
9437 9437
       CBI(x_splits, gcx);
9438 9438
     }
9439 9439
     else if (cy2 != cy1 && TEST(y_splits, gcy)) {
9440
-      memcpy(end, destination, sizeof(end));
9440
+      COPY(end, destination);
9441 9441
       destination[Y_AXIS] = LOGICAL_Y_POSITION(bilinear_start[Y_AXIS] + ABL_BG_SPACING(Y_AXIS) * gcy);
9442 9442
       normalized_dist = (destination[Y_AXIS] - current_position[Y_AXIS]) / (end[Y_AXIS] - current_position[Y_AXIS]);
9443 9443
       destination[X_AXIS] = LINE_SEGMENT_END(X);
@@ -9457,7 +9457,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
9457 9457
     bilinear_line_to_destination(fr_mm_s, x_splits, y_splits);
9458 9458
 
9459 9459
     // Restore destination from stack
9460
-    memcpy(destination, end, sizeof(end));
9460
+    COPY(destination, end);
9461 9461
     bilinear_line_to_destination(fr_mm_s, x_splits, y_splits);
9462 9462
   }
9463 9463
 
@@ -9552,7 +9552,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
9552 9552
 
9553 9553
       // Get the logical current position as starting point
9554 9554
       float logical[XYZE];
9555
-      memcpy(logical, current_position, sizeof(logical));
9555
+      COPY(logical, current_position);
9556 9556
 
9557 9557
       #define DELTA_VAR logical
9558 9558
 
@@ -10527,7 +10527,7 @@ void setup() {
10527 10527
 
10528 10528
   #if DISABLED(NO_WORKSPACE_OFFSETS)
10529 10529
     // Initialize current position based on home_offset
10530
-    memcpy(current_position, home_offset, sizeof(home_offset));
10530
+    COPY(current_position, home_offset);
10531 10531
   #else
10532 10532
     ZERO(current_position);
10533 10533
   #endif

+ 1
- 0
Marlin/macros.h View File

@@ -79,6 +79,7 @@
79 79
 #define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-')
80 80
 #define COUNT(a) (sizeof(a)/sizeof(*a))
81 81
 #define ZERO(a) memset(a,0,sizeof(a))
82
+#define COPY(a,b) memcpy(a,b,min(sizeof(a),sizeof(b)))
82 83
 
83 84
 // Macros for initializing arrays
84 85
 #define ARRAY_6(v1, v2, v3, v4, v5, v6, ...) { v1, v2, v3, v4, v5, v6 }

+ 2
- 2
Marlin/planner.cpp View File

@@ -1298,7 +1298,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1298 1298
   block->flag |= BLOCK_FLAG_RECALCULATE | (block->nominal_speed <= v_allowable ? BLOCK_FLAG_NOMINAL_LENGTH : 0);
1299 1299
 
1300 1300
   // Update previous path unit_vector and nominal speed
1301
-  memcpy(previous_speed, current_speed, sizeof(previous_speed));
1301
+  COPY(previous_speed, current_speed);
1302 1302
   previous_nominal_speed = block->nominal_speed;
1303 1303
   previous_safe_speed = safe_speed;
1304 1304
 
@@ -1360,7 +1360,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1360 1360
   block_buffer_head = next_buffer_head;
1361 1361
 
1362 1362
   // Update the position (only when a move was queued)
1363
-  memcpy(position, target, sizeof(position));
1363
+  COPY(position, target);
1364 1364
   #if ENABLED(LIN_ADVANCE)
1365 1365
     position_float[X_AXIS] = a;
1366 1366
     position_float[Y_AXIS] = b;

Loading…
Cancel
Save