From 4e31bb94ef48bc87880affc4a1a23aeec1356491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 9 Apr 2023 13:12:22 +0000 Subject: [PATCH] tmc2130: simplify parsing axis mask There is no need to check if every axis bit with each for-loop iteration. We just need to check if a given axit bit is set. Change in memory: Flash: -6 bytes SRAM: 0 bytes --- Firmware/tmc2130.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index 99bc3f5a4..944a7ae3f 100755 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -272,8 +272,7 @@ void tmc2130_home_enter(uint8_t axes_mask) tmc2130_wait_standstill_xy(1000); for (uint8_t axis = X_AXIS; axis <= Z_AXIS; axis++) //X Y and Z axes { - uint8_t mask = (X_AXIS_MASK << axis); - if (axes_mask & mask) + if (const uint8_t mask = axes_mask & _BV(axis); mask) { tmc2130_sg_homing_axes_mask |= mask; //Configuration to spreadCycle @@ -281,8 +280,7 @@ void tmc2130_home_enter(uint8_t axes_mask) tmc2130_wr(axis, TMC2130_REG_COOLCONF, (((uint32_t)tmc2130_sg_thr_home[axis]) << 16)); tmc2130_wr(axis, TMC2130_REG_TCOOLTHRS, __tcoolthrs(axis)); tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r_home[axis]); - if (mask & (X_AXIS_MASK | Y_AXIS_MASK | Z_AXIS_MASK)) - tmc2130_wr(axis, TMC2130_REG_GCONF, TMC2130_GCONF_SGSENS); //stallguard output DIAG1, DIAG1 = pushpull + tmc2130_wr(axis, TMC2130_REG_GCONF, TMC2130_GCONF_SGSENS); //stallguard output DIAG1, DIAG1 = pushpull } } #endif //TMC2130_SG_HOMING @@ -298,8 +296,7 @@ void tmc2130_home_exit() { for (uint8_t axis = X_AXIS; axis <= Z_AXIS; axis++) //X Y and Z axes { - uint8_t mask = (X_AXIS_MASK << axis); - if (tmc2130_sg_homing_axes_mask & mask & (X_AXIS_MASK | Y_AXIS_MASK | Z_AXIS_MASK)) + if (tmc2130_sg_homing_axes_mask & _BV(axis)) { #ifndef TMC2130_STEALTH_Z if ((tmc2130_mode == TMC2130_MODE_SILENT) && (axis != Z_AXIS))