From f6a6839a82312f05efbd39acc3bbbd92b990e8a5 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 19 Jan 2020 19:29:30 -0600 Subject: [PATCH] Simplify TMC monitor code --- Marlin/src/feature/tmc_util.cpp | 85 ++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/Marlin/src/feature/tmc_util.cpp b/Marlin/src/feature/tmc_util.cpp index f50371d73..e044044a0 100644 --- a/Marlin/src/feature/tmc_util.cpp +++ b/Marlin/src/feature/tmc_util.cpp @@ -346,64 +346,73 @@ #endif if (need_update_error_counters || need_debug_reporting) { - #if AXIS_IS_TMC(X) - if (monitor_tmc_driver(stepperX, need_update_error_counters, need_debug_reporting)) { - #if AXIS_IS_TMC(X2) - step_current_down(stepperX2); - #endif - } - #endif - #if AXIS_IS_TMC(X2) - if (monitor_tmc_driver(stepperX2, need_update_error_counters, need_debug_reporting)) { + + #if AXIS_IS_TMC(X) || AXIS_IS_TMC(X2) + { + bool result = false; + #if AXIS_IS_TMC(X) + if (monitor_tmc_driver(stepperX, need_update_error_counters, need_debug_reporting)) result = true; + #endif + #if AXIS_IS_TMC(X2) + if (monitor_tmc_driver(stepperX2, need_update_error_counters, need_debug_reporting)) result = true; + #endif + if (result) { #if AXIS_IS_TMC(X) step_current_down(stepperX); #endif - } - #endif - #if AXIS_IS_TMC(Y) - if (monitor_tmc_driver(stepperY, need_update_error_counters, need_debug_reporting)) { - #if AXIS_IS_TMC(Y2) - step_current_down(stepperY2); + #if AXIS_IS_TMC(X2) + step_current_down(stepperX2); #endif } + } #endif - #if AXIS_IS_TMC(Y2) - if (monitor_tmc_driver(stepperY2, need_update_error_counters, need_debug_reporting)) { + + #if AXIS_IS_TMC(Y) || AXIS_IS_TMC(Y2) + { + bool result = false; + #if AXIS_IS_TMC(Y) + if (monitor_tmc_driver(stepperY, need_update_error_counters, need_debug_reporting)) result = true; + #endif + #if AXIS_IS_TMC(Y2) + if (monitor_tmc_driver(stepperY2, need_update_error_counters, need_debug_reporting)) result = true; + #endif + if (result) { #if AXIS_IS_TMC(Y) step_current_down(stepperY); #endif - } - #endif - #if AXIS_IS_TMC(Z) - if (monitor_tmc_driver(stepperZ, need_update_error_counters, need_debug_reporting)) { - #if AXIS_IS_TMC(Z2) - step_current_down(stepperZ2); - #endif - #if AXIS_IS_TMC(Z3) - step_current_down(stepperZ3); - #endif - } - #endif - #if AXIS_IS_TMC(Z2) - if (monitor_tmc_driver(stepperZ2, need_update_error_counters, need_debug_reporting)) { - #if AXIS_IS_TMC(Z) - step_current_down(stepperZ); - #endif - #if AXIS_IS_TMC(Z3) - step_current_down(stepperZ3); + #if AXIS_IS_TMC(Y2) + step_current_down(stepperY2); #endif } + } #endif - #if AXIS_IS_TMC(Z3) - if (monitor_tmc_driver(stepperZ3, need_update_error_counters, need_debug_reporting)) { + + #if AXIS_IS_TMC(Z) || AXIS_IS_TMC(Z2) || AXIS_IS_TMC(Z3) + { + bool result = false; + #if AXIS_IS_TMC(Z) + if (monitor_tmc_driver(stepperZ, need_update_error_counters, need_debug_reporting)) result = true; + #endif + #if AXIS_IS_TMC(Z2) + if (monitor_tmc_driver(stepperZ2, need_update_error_counters, need_debug_reporting)) result = true; + #endif + #if AXIS_IS_TMC(Z3) + if (monitor_tmc_driver(stepperZ3, need_update_error_counters, need_debug_reporting)) result = true; + #endif + if (result) { #if AXIS_IS_TMC(Z) step_current_down(stepperZ); #endif #if AXIS_IS_TMC(Z2) step_current_down(stepperZ2); #endif + #if AXIS_IS_TMC(Z3) + step_current_down(stepperZ3); + #endif } + } #endif + #if AXIS_IS_TMC(E0) (void)monitor_tmc_driver(stepperE0, need_update_error_counters, need_debug_reporting); #endif