Skip to content

Commit

Permalink
🩹 Relocate Fan conditionals, sanity-checks (MarlinFirmware#25731)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <[email protected]>
  • Loading branch information
sjasonsmith and thinkyhead authored Apr 23, 2023
1 parent 95cfc98 commit ce85b98
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 49 deletions.
11 changes: 0 additions & 11 deletions Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1233,17 +1233,6 @@
#define CANNOT_EMBED_CONFIGURATION defined(__AVR__)
#endif

// Fan Kickstart
#if FAN_KICKSTART_TIME && !defined(FAN_KICKSTART_POWER)
#define FAN_KICKSTART_POWER 180
#endif

#if FAN_MIN_PWM == 0 && FAN_MAX_PWM == 255
#define CALC_FAN_SPEED(f) (f ?: FAN_OFF_PWM)
#else
#define CALC_FAN_SPEED(f) (f ? map(f, 1, 255, FAN_MIN_PWM, FAN_MAX_PWM) : FAN_OFF_PWM)
#endif

// Input shaping
#if EITHER(INPUT_SHAPING_X, INPUT_SHAPING_Y)
#define HAS_ZV_SHAPING 1
Expand Down
60 changes: 30 additions & 30 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2719,37 +2719,8 @@
#define HAS_FAN 1
#endif

/**
* Part Cooling fan multipliexer
*/
#if PIN_EXISTS(FANMUX0)
#define HAS_FANMUX 1
#endif

/**
* MIN/MAX fan PWM scaling
*/
#ifndef FAN_OFF_PWM
#define FAN_OFF_PWM 0
#endif
#ifndef FAN_MIN_PWM
#if FAN_OFF_PWM > 0
#define FAN_MIN_PWM (FAN_OFF_PWM + 1)
#else
#define FAN_MIN_PWM 0
#endif
#endif
#ifndef FAN_MAX_PWM
#define FAN_MAX_PWM 255
#endif
#if FAN_MIN_PWM < 0 || FAN_MIN_PWM > 255
#error "FAN_MIN_PWM must be a value from 0 to 255."
#elif FAN_MAX_PWM < 0 || FAN_MAX_PWM > 255
#error "FAN_MAX_PWM must be a value from 0 to 255."
#elif FAN_MIN_PWM > FAN_MAX_PWM
#error "FAN_MIN_PWM must be less than or equal to FAN_MAX_PWM."
#elif FAN_OFF_PWM > FAN_MIN_PWM
#error "FAN_OFF_PWM must be less than or equal to FAN_MIN_PWM."
#define HAS_FANMUX 1 // Part Cooling fan multipliexer
#endif

/**
Expand All @@ -2773,6 +2744,35 @@
#endif
#endif

/**
* MIN/MAX fan PWM scaling
*/
#if EITHER(HAS_FAN, USE_CONTROLLER_FAN)
#ifndef FAN_OFF_PWM
#define FAN_OFF_PWM 0
#endif
#ifndef FAN_MIN_PWM
#if FAN_OFF_PWM > 0
#define FAN_MIN_PWM (FAN_OFF_PWM + 1)
#else
#define FAN_MIN_PWM 0
#endif
#endif
#ifndef FAN_MAX_PWM
#define FAN_MAX_PWM 255
#endif
#if FAN_MIN_PWM == 0 && FAN_MAX_PWM == 255
#define CALC_FAN_SPEED(f) (f ?: FAN_OFF_PWM)
#else
#define CALC_FAN_SPEED(f) (f ? map(f, 1, 255, FAN_MIN_PWM, FAN_MAX_PWM) : FAN_OFF_PWM)
#endif
#endif

// Fan Kickstart
#if FAN_KICKSTART_TIME && !defined(FAN_KICKSTART_POWER)
#define FAN_KICKSTART_POWER 180
#endif

// Servos
#if PIN_EXISTS(SERVO0) && NUM_SERVOS > 0
#define HAS_SERVO_0 1
Expand Down
31 changes: 23 additions & 8 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -1560,11 +1560,11 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
/**
* Part-Cooling Fan Multiplexer requirements
*/
#if PIN_EXISTS(FANMUX1)
#if !HAS_FANMUX
#error "FANMUX0_PIN must be set before FANMUX1_PIN can be set."
#endif
#elif PIN_EXISTS(FANMUX2)
#if HAS_FANMUX && !HAS_FAN0
#error "FAN0_PIN must be defined to use Fan Multiplexing."
#elif PIN_EXISTS(FANMUX1) && !PIN_EXISTS(FANMUX0)
#error "FANMUX0_PIN must be set before FANMUX1_PIN can be set."
#elif PIN_EXISTS(FANMUX2) && !PINS_EXIST(FANMUX0, FANMUX1)
#error "FANMUX0_PIN and FANMUX1_PIN must be set before FANMUX2_PIN can be set."
#endif

Expand Down Expand Up @@ -1608,7 +1608,7 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
#endif

#if ENABLED(MPC_INCLUDE_FAN)
#if FAN_COUNT < 1
#if !HAS_FAN
#error "MPC_INCLUDE_FAN requires at least one fan."
#endif
#if FAN_COUNT < HOTENDS
Expand All @@ -1627,8 +1627,8 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
#error "To use BED_LIMIT_SWITCHING you must disable PIDTEMPBED."
#endif

// Fan Kickstart
#if FAN_KICKSTART_TIME && defined(FAN_KICKSTART_POWER) && !WITHIN(FAN_KICKSTART_POWER, 64, 255)
// Fan Kickstart power
#if FAN_KICKSTART_TIME && !WITHIN(FAN_KICKSTART_POWER, 64, 255)
#error "FAN_KICKSTART_POWER must be an integer from 64 to 255."
#endif

Expand Down Expand Up @@ -2454,6 +2454,21 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
#endif
#endif

/**
* Make sure FAN_*_PWM values are sensible
*/
#if EITHER(HAS_FAN, USE_CONTROLLER_FAN)
#if !WITHIN(FAN_MIN_PWM, 0, 255)
#error "FAN_MIN_PWM must be a value from 0 to 255."
#elif !WITHIN(FAN_MAX_PWM, 0, 255)
#error "FAN_MAX_PWM must be a value from 0 to 255."
#elif FAN_MIN_PWM > FAN_MAX_PWM
#error "FAN_MIN_PWM must be less than or equal to FAN_MAX_PWM."
#elif FAN_OFF_PWM > FAN_MIN_PWM
#error "FAN_OFF_PWM must be less than or equal to FAN_MIN_PWM."
#endif
#endif

#ifdef REDUNDANT_PART_COOLING_FAN
#if FAN_COUNT < 2
#error "REDUNDANT_PART_COOLING_FAN requires a board with at least two PWM fans."
Expand Down

0 comments on commit ce85b98

Please sign in to comment.