🎨 Apply _TERN where possible

This commit is contained in:
Scott Lahteine 2022-03-22 19:17:12 -05:00 committed by Scott Lahteine
parent 10a0c9a9b3
commit ced0ad8e09
5 changed files with 57 additions and 158 deletions

View File

@ -82,15 +82,13 @@
#if ENABLED(SENSORLESS_HOMING) #if ENABLED(SENSORLESS_HOMING)
sensorless_t stealth_states { sensorless_t stealth_states {
LINEAR_AXIS_LIST(tmc_enable_stallguard(stepperX), tmc_enable_stallguard(stepperY), false, false, false, false) LINEAR_AXIS_LIST(
, false TERN0(X_SENSORLESS, tmc_enable_stallguard(stepperX)),
#if AXIS_HAS_STALLGUARD(X2) TERN0(Y_SENSORLESS, tmc_enable_stallguard(stepperY)),
|| tmc_enable_stallguard(stepperX2) false, false, false, false
#endif )
, false , TERN0(X2_SENSORLESS, tmc_enable_stallguard(stepperX2))
#if AXIS_HAS_STALLGUARD(Y2) , TERN0(Y2_SENSORLESS, tmc_enable_stallguard(stepperY2))
|| tmc_enable_stallguard(stepperY2)
#endif
}; };
#endif #endif
@ -101,14 +99,10 @@
current_position.set(0.0, 0.0); current_position.set(0.0, 0.0);
#if ENABLED(SENSORLESS_HOMING) && DISABLED(ENDSTOPS_ALWAYS_ON_DEFAULT) #if ENABLED(SENSORLESS_HOMING) && DISABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
tmc_disable_stallguard(stepperX, stealth_states.x); TERN_(X_SENSORLESS, tmc_disable_stallguard(stepperX, stealth_states.x));
tmc_disable_stallguard(stepperY, stealth_states.y); TERN_(X2_SENSORLESS, tmc_disable_stallguard(stepperX2, stealth_states.x2));
#if AXIS_HAS_STALLGUARD(X2) TERN_(Y_SENSORLESS, tmc_disable_stallguard(stepperY, stealth_states.y));
tmc_disable_stallguard(stepperX2, stealth_states.x2); TERN_(Y2_SENSORLESS, tmc_disable_stallguard(stepperY2, stealth_states.y2));
#endif
#if AXIS_HAS_STALLGUARD(Y2)
tmc_disable_stallguard(stepperY2, stealth_states.y2);
#endif
#endif #endif
} }

View File

@ -457,92 +457,48 @@
switch (i) { switch (i) {
#if X_SENSORLESS #if X_SENSORLESS
case X_AXIS: case X_AXIS:
#if AXIS_HAS_STALLGUARD(X) if (index < 2) stepperX.homing_threshold(value);
if (index < 2) stepperX.homing_threshold(value); TERN_(X2_SENSORLESS, if (!(index & 1)) stepperX2.homing_threshold(value));
#endif
#if AXIS_HAS_STALLGUARD(X2)
if (!(index & 1)) stepperX2.homing_threshold(value);
#endif
break; break;
#endif #endif
#if Y_SENSORLESS #if Y_SENSORLESS
case Y_AXIS: case Y_AXIS:
#if AXIS_HAS_STALLGUARD(Y) if (index < 2) stepperY.homing_threshold(value);
if (index < 2) stepperY.homing_threshold(value); TERN_(Y2_SENSORLESS, if (!(index & 1)) stepperY2.homing_threshold(value));
#endif
#if AXIS_HAS_STALLGUARD(Y2)
if (!(index & 1)) stepperY2.homing_threshold(value);
#endif
break; break;
#endif #endif
#if Z_SENSORLESS #if Z_SENSORLESS
case Z_AXIS: case Z_AXIS:
#if AXIS_HAS_STALLGUARD(Z) if (index < 2) stepperZ.homing_threshold(value);
if (index < 2) stepperZ.homing_threshold(value); TERN_(Z2_SENSORLESS, if (index == 0 || index == 2) stepperZ2.homing_threshold(value));
#endif TERN_(Z3_SENSORLESS, if (index == 0 || index == 3) stepperZ3.homing_threshold(value));
#if AXIS_HAS_STALLGUARD(Z2) TERN_(Z4_SENSORLESS, if (index == 0 || index == 4) stepperZ4.homing_threshold(value));
if (index == 0 || index == 2) stepperZ2.homing_threshold(value);
#endif
#if AXIS_HAS_STALLGUARD(Z3)
if (index == 0 || index == 3) stepperZ3.homing_threshold(value);
#endif
#if AXIS_HAS_STALLGUARD(Z4)
if (index == 0 || index == 4) stepperZ4.homing_threshold(value);
#endif
break; break;
#endif #endif
#if I_SENSORLESS && AXIS_HAS_STALLGUARD(I) #if I_SENSORLESS
case I_AXIS: stepperI.homing_threshold(value); break; case I_AXIS: stepperI.homing_threshold(value); break;
#endif #endif
#if J_SENSORLESS && AXIS_HAS_STALLGUARD(J) #if J_SENSORLESS
case J_AXIS: stepperJ.homing_threshold(value); break; case J_AXIS: stepperJ.homing_threshold(value); break;
#endif #endif
#if K_SENSORLESS && AXIS_HAS_STALLGUARD(K) #if K_SENSORLESS
case K_AXIS: stepperK.homing_threshold(value); break; case K_AXIS: stepperK.homing_threshold(value); break;
#endif #endif
} }
} }
if (report) { if (report) {
#if X_SENSORLESS TERN_(X_SENSORLESS, tmc_print_sgt(stepperX));
#if AXIS_HAS_STALLGUARD(X) TERN_(X2_SENSORLESS, tmc_print_sgt(stepperX2));
tmc_print_sgt(stepperX); TERN_(Y_SENSORLESS, tmc_print_sgt(stepperY));
#endif TERN_(Y2_SENSORLESS, tmc_print_sgt(stepperY2));
#if AXIS_HAS_STALLGUARD(X2) TERN_(Z_SENSORLESS, tmc_print_sgt(stepperZ));
tmc_print_sgt(stepperX2); TERN_(Z2_SENSORLESS, tmc_print_sgt(stepperZ2));
#endif TERN_(Z3_SENSORLESS, tmc_print_sgt(stepperZ3));
#endif TERN_(Z4_SENSORLESS, tmc_print_sgt(stepperZ4));
#if Y_SENSORLESS TERN_(I_SENSORLESS, tmc_print_sgt(stepperI));
#if AXIS_HAS_STALLGUARD(Y) TERN_(J_SENSORLESS, tmc_print_sgt(stepperJ));
tmc_print_sgt(stepperY); TERN_(K_SENSORLESS, tmc_print_sgt(stepperK));
#endif
#if AXIS_HAS_STALLGUARD(Y2)
tmc_print_sgt(stepperY2);
#endif
#endif
#if Z_SENSORLESS
#if AXIS_HAS_STALLGUARD(Z)
tmc_print_sgt(stepperZ);
#endif
#if AXIS_HAS_STALLGUARD(Z2)
tmc_print_sgt(stepperZ2);
#endif
#if AXIS_HAS_STALLGUARD(Z3)
tmc_print_sgt(stepperZ3);
#endif
#if AXIS_HAS_STALLGUARD(Z4)
tmc_print_sgt(stepperZ4);
#endif
#endif
#if I_SENSORLESS && AXIS_HAS_STALLGUARD(I)
tmc_print_sgt(stepperI);
#endif
#if J_SENSORLESS && AXIS_HAS_STALLGUARD(J)
tmc_print_sgt(stepperJ);
#endif
#if K_SENSORLESS && AXIS_HAS_STALLGUARD(K)
tmc_print_sgt(stepperK);
#endif
} }
} }

View File

@ -1655,9 +1655,9 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
* Require pin options and pins to be defined * Require pin options and pins to be defined
*/ */
#if ENABLED(SENSORLESS_PROBING) #if ENABLED(SENSORLESS_PROBING)
#if ENABLED(DELTA) && !(AXIS_HAS_STALLGUARD(X) && AXIS_HAS_STALLGUARD(Y) && AXIS_HAS_STALLGUARD(Z)) #if ENABLED(DELTA) && !(X_SENSORLESS && Y_SENSORLESS && Z_SENSORLESS)
#error "SENSORLESS_PROBING requires TMC2130/2160/2209/5130/5160 drivers on X, Y, and Z." #error "SENSORLESS_PROBING requires TMC2130/2160/2209/5130/5160 drivers on X, Y, and Z."
#elif !AXIS_HAS_STALLGUARD(Z) #elif !Z_SENSORLESS
#error "SENSORLESS_PROBING requires a TMC2130/2160/2209/5130/5160 driver on Z." #error "SENSORLESS_PROBING requires a TMC2130/2160/2209/5130/5160 driver on Z."
#endif #endif
#elif ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) #elif ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)

View File

@ -1359,9 +1359,7 @@ void prepare_line_to_destination() {
#if X_SENSORLESS #if X_SENSORLESS
case X_AXIS: case X_AXIS:
stealth_states.x = tmc_enable_stallguard(stepperX); stealth_states.x = tmc_enable_stallguard(stepperX);
#if AXIS_HAS_STALLGUARD(X2) TERN_(X2_SENSORLESS, stealth_states.x2 = tmc_enable_stallguard(stepperX2));
stealth_states.x2 = tmc_enable_stallguard(stepperX2);
#endif
#if ANY(CORE_IS_XY, MARKFORGED_XY, MARKFORGED_YX) && Y_SENSORLESS #if ANY(CORE_IS_XY, MARKFORGED_XY, MARKFORGED_YX) && Y_SENSORLESS
stealth_states.y = tmc_enable_stallguard(stepperY); stealth_states.y = tmc_enable_stallguard(stepperY);
#elif CORE_IS_XZ && Z_SENSORLESS #elif CORE_IS_XZ && Z_SENSORLESS
@ -1372,9 +1370,7 @@ void prepare_line_to_destination() {
#if Y_SENSORLESS #if Y_SENSORLESS
case Y_AXIS: case Y_AXIS:
stealth_states.y = tmc_enable_stallguard(stepperY); stealth_states.y = tmc_enable_stallguard(stepperY);
#if AXIS_HAS_STALLGUARD(Y2) TERN_(Y2_SENSORLESS, stealth_states.y2 = tmc_enable_stallguard(stepperY2));
stealth_states.y2 = tmc_enable_stallguard(stepperY2);
#endif
#if ANY(CORE_IS_XY, MARKFORGED_XY, MARKFORGED_YX) && X_SENSORLESS #if ANY(CORE_IS_XY, MARKFORGED_XY, MARKFORGED_YX) && X_SENSORLESS
stealth_states.x = tmc_enable_stallguard(stepperX); stealth_states.x = tmc_enable_stallguard(stepperX);
#elif CORE_IS_YZ && Z_SENSORLESS #elif CORE_IS_YZ && Z_SENSORLESS
@ -1385,15 +1381,9 @@ void prepare_line_to_destination() {
#if Z_SENSORLESS #if Z_SENSORLESS
case Z_AXIS: case Z_AXIS:
stealth_states.z = tmc_enable_stallguard(stepperZ); stealth_states.z = tmc_enable_stallguard(stepperZ);
#if AXIS_HAS_STALLGUARD(Z2) TERN_(Z2_SENSORLESS, stealth_states.z2 = tmc_enable_stallguard(stepperZ2));
stealth_states.z2 = tmc_enable_stallguard(stepperZ2); TERN_(Z3_SENSORLESS, stealth_states.z3 = tmc_enable_stallguard(stepperZ3));
#endif TERN_(Z4_SENSORLESS, stealth_states.z4 = tmc_enable_stallguard(stepperZ4));
#if AXIS_HAS_STALLGUARD(Z3)
stealth_states.z3 = tmc_enable_stallguard(stepperZ3);
#endif
#if AXIS_HAS_STALLGUARD(Z4)
stealth_states.z4 = tmc_enable_stallguard(stepperZ4);
#endif
#if CORE_IS_XZ && X_SENSORLESS #if CORE_IS_XZ && X_SENSORLESS
stealth_states.x = tmc_enable_stallguard(stepperX); stealth_states.x = tmc_enable_stallguard(stepperX);
#elif CORE_IS_YZ && Y_SENSORLESS #elif CORE_IS_YZ && Y_SENSORLESS
@ -1445,9 +1435,7 @@ void prepare_line_to_destination() {
#if X_SENSORLESS #if X_SENSORLESS
case X_AXIS: case X_AXIS:
tmc_disable_stallguard(stepperX, enable_stealth.x); tmc_disable_stallguard(stepperX, enable_stealth.x);
#if AXIS_HAS_STALLGUARD(X2) TERN_(X2_SENSORLESS, tmc_disable_stallguard(stepperX2, enable_stealth.x2));
tmc_disable_stallguard(stepperX2, enable_stealth.x2);
#endif
#if ANY(CORE_IS_XY, MARKFORGED_XY, MARKFORGED_YX) && Y_SENSORLESS #if ANY(CORE_IS_XY, MARKFORGED_XY, MARKFORGED_YX) && Y_SENSORLESS
tmc_disable_stallguard(stepperY, enable_stealth.y); tmc_disable_stallguard(stepperY, enable_stealth.y);
#elif CORE_IS_XZ && Z_SENSORLESS #elif CORE_IS_XZ && Z_SENSORLESS
@ -1458,9 +1446,7 @@ void prepare_line_to_destination() {
#if Y_SENSORLESS #if Y_SENSORLESS
case Y_AXIS: case Y_AXIS:
tmc_disable_stallguard(stepperY, enable_stealth.y); tmc_disable_stallguard(stepperY, enable_stealth.y);
#if AXIS_HAS_STALLGUARD(Y2) TERN_(Y2_SENSORLESS, tmc_disable_stallguard(stepperY2, enable_stealth.y2));
tmc_disable_stallguard(stepperY2, enable_stealth.y2);
#endif
#if ANY(CORE_IS_XY, MARKFORGED_XY, MARKFORGED_YX) && X_SENSORLESS #if ANY(CORE_IS_XY, MARKFORGED_XY, MARKFORGED_YX) && X_SENSORLESS
tmc_disable_stallguard(stepperX, enable_stealth.x); tmc_disable_stallguard(stepperX, enable_stealth.x);
#elif CORE_IS_YZ && Z_SENSORLESS #elif CORE_IS_YZ && Z_SENSORLESS
@ -1471,15 +1457,9 @@ void prepare_line_to_destination() {
#if Z_SENSORLESS #if Z_SENSORLESS
case Z_AXIS: case Z_AXIS:
tmc_disable_stallguard(stepperZ, enable_stealth.z); tmc_disable_stallguard(stepperZ, enable_stealth.z);
#if AXIS_HAS_STALLGUARD(Z2) TERN_(Z2_SENSORLESS, tmc_disable_stallguard(stepperZ2, enable_stealth.z2));
tmc_disable_stallguard(stepperZ2, enable_stealth.z2); TERN_(Z3_SENSORLESS, tmc_disable_stallguard(stepperZ3, enable_stealth.z3));
#endif TERN_(Z4_SENSORLESS, tmc_disable_stallguard(stepperZ4, enable_stealth.z4));
#if AXIS_HAS_STALLGUARD(Z3)
tmc_disable_stallguard(stepperZ3, enable_stealth.z3);
#endif
#if AXIS_HAS_STALLGUARD(Z4)
tmc_disable_stallguard(stepperZ4, enable_stealth.z4);
#endif
#if CORE_IS_XZ && X_SENSORLESS #if CORE_IS_XZ && X_SENSORLESS
tmc_disable_stallguard(stepperX, enable_stealth.x); tmc_disable_stallguard(stepperX, enable_stealth.x);
#elif CORE_IS_YZ && Y_SENSORLESS #elif CORE_IS_YZ && Y_SENSORLESS

View File

@ -906,49 +906,18 @@ void reset_trinamic_drivers() {
#endif #endif
#if USE_SENSORLESS #if USE_SENSORLESS
#if X_SENSORLESS TERN_(X_SENSORLESS, stepperX.homing_threshold(X_STALL_SENSITIVITY));
stepperX.homing_threshold(X_STALL_SENSITIVITY); TERN_(X2_SENSORLESS, stepperX2.homing_threshold(CAT(TERN(X2_SENSORLESS, X2, X), _STALL_SENSITIVITY)));
#if AXIS_HAS_STALLGUARD(X2) TERN_(Y_SENSORLESS, stepperY.homing_threshold(Y_STALL_SENSITIVITY));
stepperX2.homing_threshold(CAT(TERN(X2_SENSORLESS, X2, X), _STALL_SENSITIVITY)); TERN_(Y2_SENSORLESS, stepperY2.homing_threshold(CAT(TERN(Y2_SENSORLESS, Y2, Y), _STALL_SENSITIVITY)));
#endif TERN_(Z_SENSORLESS, stepperZ.homing_threshold(Z_STALL_SENSITIVITY));
#endif TERN_(Z2_SENSORLESS, stepperZ2.homing_threshold(CAT(TERN(Z2_SENSORLESS, Z2, Z), _STALL_SENSITIVITY)));
#if Y_SENSORLESS TERN_(Z3_SENSORLESS, stepperZ3.homing_threshold(CAT(TERN(Z3_SENSORLESS, Z3, Z), _STALL_SENSITIVITY)));
stepperY.homing_threshold(Y_STALL_SENSITIVITY); TERN_(Z4_SENSORLESS, stepperZ4.homing_threshold(CAT(TERN(Z4_SENSORLESS, Z4, Z), _STALL_SENSITIVITY)));
#if AXIS_HAS_STALLGUARD(Y2) TERN_(I_SENSORLESS, stepperI.homing_threshold(I_STALL_SENSITIVITY));
stepperY2.homing_threshold(CAT(TERN(Y2_SENSORLESS, Y2, Y), _STALL_SENSITIVITY)); TERN_(J_SENSORLESS, stepperJ.homing_threshold(J_STALL_SENSITIVITY));
#endif TERN_(K_SENSORLESS, stepperK.homing_threshold(K_STALL_SENSITIVITY));
#endif #endif
#if Z_SENSORLESS
stepperZ.homing_threshold(Z_STALL_SENSITIVITY);
#if AXIS_HAS_STALLGUARD(Z2)
stepperZ2.homing_threshold(CAT(TERN(Z2_SENSORLESS, Z2, Z), _STALL_SENSITIVITY));
#endif
#if AXIS_HAS_STALLGUARD(Z3)
stepperZ3.homing_threshold(CAT(TERN(Z3_SENSORLESS, Z3, Z), _STALL_SENSITIVITY));
#endif
#if AXIS_HAS_STALLGUARD(Z4)
stepperZ4.homing_threshold(CAT(TERN(Z4_SENSORLESS, Z4, Z), _STALL_SENSITIVITY));
#endif
#endif
#if I_SENSORLESS
stepperI.homing_threshold(I_STALL_SENSITIVITY);
#if AXIS_HAS_STALLGUARD(I)
stepperI.homing_threshold(CAT(TERN(I_SENSORLESS, I, I), _STALL_SENSITIVITY));
#endif
#endif
#if J_SENSORLESS
stepperJ.homing_threshold(J_STALL_SENSITIVITY);
#if AXIS_HAS_STALLGUARD(J)
stepperJ.homing_threshold(CAT(TERN(J_SENSORLESS, J, J), _STALL_SENSITIVITY));
#endif
#endif
#if K_SENSORLESS
stepperK.homing_threshold(K_STALL_SENSITIVITY);
#if AXIS_HAS_STALLGUARD(K)
stepperK.homing_threshold(CAT(TERN(K_SENSORLESS, K, K), _STALL_SENSITIVITY));
#endif
#endif
#endif // USE SENSORLESS
#ifdef TMC_ADV #ifdef TMC_ADV
TMC_ADV() TMC_ADV()