From 473d2b888ad642d8129cc44b6ba436882ff704c8 Mon Sep 17 00:00:00 2001 From: Marcio T Date: Mon, 21 Nov 2022 16:25:56 -0700 Subject: [PATCH] Fix FAST_PWM_FAN / TouchUI with NO_MOTION_BEFORE_HOMING (#25005) Fix regressions from #20323, #23463 --- Marlin/src/HAL/AVR/fast_pwm.cpp | 10 +++++----- Marlin/src/lcd/extui/ui_api.cpp | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Marlin/src/HAL/AVR/fast_pwm.cpp b/Marlin/src/HAL/AVR/fast_pwm.cpp index 0a384172c3..e440315e00 100644 --- a/Marlin/src/HAL/AVR/fast_pwm.cpp +++ b/Marlin/src/HAL/AVR/fast_pwm.cpp @@ -146,11 +146,11 @@ void MarlinHAL::set_pwm_frequency(const pin_t pin, const uint16_t f_desired) { LIMIT(res_pc_temp, 1U, maxtop); // Calculate frequencies of test prescaler and resolution values - const uint32_t f_diff = _MAX(f, f_desired) - _MIN(f, f_desired), - f_fast_temp = (F_CPU) / (p * (1 + res_fast_temp)), - f_fast_diff = _MAX(f_fast_temp, f_desired) - _MIN(f_fast_temp, f_desired), - f_pc_temp = (F_CPU) / (2 * p * res_pc_temp), - f_pc_diff = _MAX(f_pc_temp, f_desired) - _MIN(f_pc_temp, f_desired); + const int f_diff = ABS(f - int(f_desired)), + f_fast_temp = (F_CPU) / (p * (1 + res_fast_temp)), + f_fast_diff = ABS(f_fast_temp - int(f_desired)), + f_pc_temp = (F_CPU) / (2 * p * res_pc_temp), + f_pc_diff = ABS(f_pc_temp - int(f_desired)); if (f_fast_diff < f_diff && f_fast_diff <= f_pc_diff) { // FAST values are closest to desired f // Set the Wave Generation Mode to FAST PWM diff --git a/Marlin/src/lcd/extui/ui_api.cpp b/Marlin/src/lcd/extui/ui_api.cpp index 967fb1021d..4422e8115d 100644 --- a/Marlin/src/lcd/extui/ui_api.cpp +++ b/Marlin/src/lcd/extui/ui_api.cpp @@ -375,9 +375,9 @@ namespace ExtUI { bool canMove(const axis_t axis) { switch (axis) { #if IS_KINEMATIC || ENABLED(NO_MOTION_BEFORE_HOMING) - case X: return axis_should_home(X_AXIS); - OPTCODE(HAS_Y_AXIS, case Y: return axis_should_home(Y_AXIS)) - OPTCODE(HAS_Z_AXIS, case Z: return axis_should_home(Z_AXIS)) + case X: return !axis_should_home(X_AXIS); + OPTCODE(HAS_Y_AXIS, case Y: return !axis_should_home(Y_AXIS)) + OPTCODE(HAS_Z_AXIS, case Z: return !axis_should_home(Z_AXIS)) #else case X: case Y: case Z: return true; #endif