Skip to content

Commit 56f1010

Browse files
sjasonsmiththinkyhead
authored andcommitted
🩹 Relocate Fan conditionals, sanity-checks (MarlinFirmware#25731)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
1 parent 83cc9ab commit 56f1010

File tree

3 files changed

+53
-49
lines changed

3 files changed

+53
-49
lines changed

Marlin/src/inc/Conditionals_adv.h

-11
Original file line numberDiff line numberDiff line change
@@ -1233,17 +1233,6 @@
12331233
#define CANNOT_EMBED_CONFIGURATION defined(__AVR__)
12341234
#endif
12351235

1236-
// Fan Kickstart
1237-
#if FAN_KICKSTART_TIME && !defined(FAN_KICKSTART_POWER)
1238-
#define FAN_KICKSTART_POWER 180
1239-
#endif
1240-
1241-
#if FAN_MIN_PWM == 0 && FAN_MAX_PWM == 255
1242-
#define CALC_FAN_SPEED(f) (f ?: FAN_OFF_PWM)
1243-
#else
1244-
#define CALC_FAN_SPEED(f) (f ? map(f, 1, 255, FAN_MIN_PWM, FAN_MAX_PWM) : FAN_OFF_PWM)
1245-
#endif
1246-
12471236
// Input shaping
12481237
#if EITHER(INPUT_SHAPING_X, INPUT_SHAPING_Y)
12491238
#define HAS_ZV_SHAPING 1

Marlin/src/inc/Conditionals_post.h

+30-30
Original file line numberDiff line numberDiff line change
@@ -2722,37 +2722,8 @@
27222722
#define HAS_FAN 1
27232723
#endif
27242724

2725-
/**
2726-
* Part Cooling fan multipliexer
2727-
*/
27282725
#if PIN_EXISTS(FANMUX0)
2729-
#define HAS_FANMUX 1
2730-
#endif
2731-
2732-
/**
2733-
* MIN/MAX fan PWM scaling
2734-
*/
2735-
#ifndef FAN_OFF_PWM
2736-
#define FAN_OFF_PWM 0
2737-
#endif
2738-
#ifndef FAN_MIN_PWM
2739-
#if FAN_OFF_PWM > 0
2740-
#define FAN_MIN_PWM (FAN_OFF_PWM + 1)
2741-
#else
2742-
#define FAN_MIN_PWM 0
2743-
#endif
2744-
#endif
2745-
#ifndef FAN_MAX_PWM
2746-
#define FAN_MAX_PWM 255
2747-
#endif
2748-
#if FAN_MIN_PWM < 0 || FAN_MIN_PWM > 255
2749-
#error "FAN_MIN_PWM must be a value from 0 to 255."
2750-
#elif FAN_MAX_PWM < 0 || FAN_MAX_PWM > 255
2751-
#error "FAN_MAX_PWM must be a value from 0 to 255."
2752-
#elif FAN_MIN_PWM > FAN_MAX_PWM
2753-
#error "FAN_MIN_PWM must be less than or equal to FAN_MAX_PWM."
2754-
#elif FAN_OFF_PWM > FAN_MIN_PWM
2755-
#error "FAN_OFF_PWM must be less than or equal to FAN_MIN_PWM."
2726+
#define HAS_FANMUX 1 // Part Cooling fan multipliexer
27562727
#endif
27572728

27582729
/**
@@ -2776,6 +2747,35 @@
27762747
#endif
27772748
#endif
27782749

2750+
/**
2751+
* MIN/MAX fan PWM scaling
2752+
*/
2753+
#if EITHER(HAS_FAN, USE_CONTROLLER_FAN)
2754+
#ifndef FAN_OFF_PWM
2755+
#define FAN_OFF_PWM 0
2756+
#endif
2757+
#ifndef FAN_MIN_PWM
2758+
#if FAN_OFF_PWM > 0
2759+
#define FAN_MIN_PWM (FAN_OFF_PWM + 1)
2760+
#else
2761+
#define FAN_MIN_PWM 0
2762+
#endif
2763+
#endif
2764+
#ifndef FAN_MAX_PWM
2765+
#define FAN_MAX_PWM 255
2766+
#endif
2767+
#if FAN_MIN_PWM == 0 && FAN_MAX_PWM == 255
2768+
#define CALC_FAN_SPEED(f) (f ?: FAN_OFF_PWM)
2769+
#else
2770+
#define CALC_FAN_SPEED(f) (f ? map(f, 1, 255, FAN_MIN_PWM, FAN_MAX_PWM) : FAN_OFF_PWM)
2771+
#endif
2772+
#endif
2773+
2774+
// Fan Kickstart
2775+
#if FAN_KICKSTART_TIME && !defined(FAN_KICKSTART_POWER)
2776+
#define FAN_KICKSTART_POWER 180
2777+
#endif
2778+
27792779
// Servos
27802780
#if PIN_EXISTS(SERVO0) && NUM_SERVOS > 0
27812781
#define HAS_SERVO_0 1

Marlin/src/inc/SanityCheck.h

+23-8
Original file line numberDiff line numberDiff line change
@@ -1558,11 +1558,11 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
15581558
/**
15591559
* Part-Cooling Fan Multiplexer requirements
15601560
*/
1561-
#if PIN_EXISTS(FANMUX1)
1562-
#if !HAS_FANMUX
1563-
#error "FANMUX0_PIN must be set before FANMUX1_PIN can be set."
1564-
#endif
1565-
#elif PIN_EXISTS(FANMUX2)
1561+
#if HAS_FANMUX && !HAS_FAN0
1562+
#error "FAN0_PIN must be defined to use Fan Multiplexing."
1563+
#elif PIN_EXISTS(FANMUX1) && !PIN_EXISTS(FANMUX0)
1564+
#error "FANMUX0_PIN must be set before FANMUX1_PIN can be set."
1565+
#elif PIN_EXISTS(FANMUX2) && !PINS_EXIST(FANMUX0, FANMUX1)
15661566
#error "FANMUX0_PIN and FANMUX1_PIN must be set before FANMUX2_PIN can be set."
15671567
#endif
15681568

@@ -1606,7 +1606,7 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
16061606
#endif
16071607

16081608
#if ENABLED(MPC_INCLUDE_FAN)
1609-
#if FAN_COUNT < 1
1609+
#if !HAS_FAN
16101610
#error "MPC_INCLUDE_FAN requires at least one fan."
16111611
#endif
16121612
#if FAN_COUNT < HOTENDS
@@ -1625,8 +1625,8 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
16251625
#error "To use BED_LIMIT_SWITCHING you must disable PIDTEMPBED."
16261626
#endif
16271627

1628-
// Fan Kickstart
1629-
#if FAN_KICKSTART_TIME && defined(FAN_KICKSTART_POWER) && !WITHIN(FAN_KICKSTART_POWER, 64, 255)
1628+
// Fan Kickstart power
1629+
#if FAN_KICKSTART_TIME && !WITHIN(FAN_KICKSTART_POWER, 64, 255)
16301630
#error "FAN_KICKSTART_POWER must be an integer from 64 to 255."
16311631
#endif
16321632

@@ -2452,6 +2452,21 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
24522452
#endif
24532453
#endif
24542454

2455+
/**
2456+
* Make sure FAN_*_PWM values are sensible
2457+
*/
2458+
#if EITHER(HAS_FAN, USE_CONTROLLER_FAN)
2459+
#if !WITHIN(FAN_MIN_PWM, 0, 255)
2460+
#error "FAN_MIN_PWM must be a value from 0 to 255."
2461+
#elif !WITHIN(FAN_MAX_PWM, 0, 255)
2462+
#error "FAN_MAX_PWM must be a value from 0 to 255."
2463+
#elif FAN_MIN_PWM > FAN_MAX_PWM
2464+
#error "FAN_MIN_PWM must be less than or equal to FAN_MAX_PWM."
2465+
#elif FAN_OFF_PWM > FAN_MIN_PWM
2466+
#error "FAN_OFF_PWM must be less than or equal to FAN_MIN_PWM."
2467+
#endif
2468+
#endif
2469+
24552470
#ifdef REDUNDANT_PART_COOLING_FAN
24562471
#if FAN_COUNT < 2
24572472
#error "REDUNDANT_PART_COOLING_FAN requires a board with at least two PWM fans."

0 commit comments

Comments
 (0)