From f7dade8c2c83257df8cc0e32d84334e400161aaf Mon Sep 17 00:00:00 2001 From: Giuliano Zaro <3684609+GMagician@users.noreply.github.com> Date: Thu, 20 Aug 2020 03:11:20 +0200 Subject: [PATCH] Configurable number of M106 fans (#18883) --- Marlin/Configuration.h | 4 ++++ Marlin/src/inc/Conditionals_post.h | 22 +++++++++++++++++++--- Marlin/src/inc/SanityCheck.h | 7 +++++++ Marlin/src/module/temperature.cpp | 2 +- Marlin/src/pins/sam/pins_CNCONTROLS_15D.h | 2 +- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 24d7c46a68..986b9efb65 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -2275,6 +2275,10 @@ // @section extras +// Set number of user-controlled fans. Disable to use all board-defined fans. +// :[1,2,3,4,5,6,7,8] +//#define NUM_M106_FANS 1 + // Increase the FAN PWM frequency. Removes the PWM noise but increases heating in the FET/Arduino //#define FAST_PWM_FAN diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 29ab2cfc29..5d7322753f 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -1876,12 +1876,28 @@ #undef AUTO_POWER_CHAMBER_FAN #endif -// Other fans +// Print Cooling fans (limit) +#ifdef NUM_M106_FANS + #define MAX_FANS NUM_M106_FANS +#else + #define MAX_FANS 8 // Max supported fans +#endif + +#define _NOT_E_AUTO(N,F) (E##N##_AUTO_FAN_PIN != FAN##F##_PIN) +#define _HAS_FAN(F) (PIN_EXISTS(FAN##F) \ + && CONTROLLER_FAN_PIN != FAN##F##_PIN \ + && _NOT_E_AUTO(0,F) \ + && _NOT_E_AUTO(1,F) \ + && _NOT_E_AUTO(2,F) \ + && _NOT_E_AUTO(3,F) \ + && _NOT_E_AUTO(4,F) \ + && _NOT_E_AUTO(5,F) \ + && _NOT_E_AUTO(6,F) \ + && _NOT_E_AUTO(7,F) \ + && F < MAX_FANS) #if PIN_EXISTS(FAN) #define HAS_FAN0 1 #endif -#define _NOT_E_AUTO(N,F) (E##N##_AUTO_FAN_PIN != FAN##F##_PIN) -#define _HAS_FAN(F) (PIN_EXISTS(FAN##F) && CONTROLLER_FAN_PIN != FAN##F##_PIN && _NOT_E_AUTO(0,F) && _NOT_E_AUTO(1,F) && _NOT_E_AUTO(2,F) && _NOT_E_AUTO(3,F) && _NOT_E_AUTO(4,F) && _NOT_E_AUTO(5,F) && _NOT_E_AUTO(6,F) && _NOT_E_AUTO(7,F)) #if _HAS_FAN(1) #define HAS_FAN1 1 #endif diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 6fcd867981..d31a826778 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -1106,6 +1106,13 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS #error "FANMUX0_PIN and FANMUX1_PIN must be set before FANMUX2_PIN can be set." #endif +/** + * Limited user-controlled fans + */ +#if NUM_M106_FANS > FAN_COUNT + #error "The selected board doesn't support enough user-controlled fans. Reduce NUM_M106_FANS." +#endif + /** * Limited number of servos */ diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index a217fc9ab8..1208e4e995 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -195,7 +195,7 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY, #endif #if ENABLED(ADAPTIVE_FAN_SLOWING) - uint8_t Temperature::fan_speed_scaler[FAN_COUNT] = ARRAY_N(FAN_COUNT, 128, 128, 128, 128, 128, 128); + uint8_t Temperature::fan_speed_scaler[FAN_COUNT] = ARRAY_N(FAN_COUNT, 128, 128, 128, 128, 128, 128, 128, 128); #endif /** diff --git a/Marlin/src/pins/sam/pins_CNCONTROLS_15D.h b/Marlin/src/pins/sam/pins_CNCONTROLS_15D.h index b977ad1aba..a2094bee4d 100644 --- a/Marlin/src/pins/sam/pins_CNCONTROLS_15D.h +++ b/Marlin/src/pins/sam/pins_CNCONTROLS_15D.h @@ -92,7 +92,7 @@ // // Fans // -//#define FAN0_PIN 8 +//#define FAN_PIN 8 // // Auto fans