Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] 🔧 Revamp AUTO_FAN configuration #27214

Draft
wants to merge 19 commits into
base: bugfix-2.1.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -675,22 +675,22 @@
* Extruder auto fans automatically turn on when their extruders'
* temperatures go above EXTRUDER_AUTO_FAN_TEMPERATURE.
*
* Your board's pins file specifies the recommended pins. Override those here
* Your board's pins file may specify recommended pins. Override those here
* or set to -1 to disable completely.
*
* Multiple extruders can be assigned to the same pin in which case
* the fan will turn on when any selected extruder is above the threshold.
*/
#define E0_AUTO_FAN_PIN -1
#define E1_AUTO_FAN_PIN -1
#define E2_AUTO_FAN_PIN -1
#define E3_AUTO_FAN_PIN -1
#define E4_AUTO_FAN_PIN -1
#define E5_AUTO_FAN_PIN -1
#define E6_AUTO_FAN_PIN -1
#define E7_AUTO_FAN_PIN -1
#define CHAMBER_AUTO_FAN_PIN -1
#define COOLER_AUTO_FAN_PIN -1
//#define E0_AUTO_FAN_PIN -1
//#define E1_AUTO_FAN_PIN -1
//#define E2_AUTO_FAN_PIN -1
//#define E3_AUTO_FAN_PIN -1
//#define E4_AUTO_FAN_PIN -1
//#define E5_AUTO_FAN_PIN -1
//#define E6_AUTO_FAN_PIN -1
//#define E7_AUTO_FAN_PIN -1
//#define CHAMBER_AUTO_FAN_PIN -1
//#define COOLER_AUTO_FAN_PIN -1

#define EXTRUDER_AUTO_FAN_TEMPERATURE 50
#define EXTRUDER_AUTO_FAN_SPEED 255 // 255 == full speed
Expand Down
32 changes: 32 additions & 0 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2648,6 +2648,38 @@
#define MAX_FANS 12 // Max supported fans
#endif

// *_AUTO_FAN_PIN hack
#ifndef E0_AUTO_FAN_PIN
#define E0_AUTO_FAN_PIN -1
#endif
#ifndef E1_AUTO_FAN_PIN
#define E1_AUTO_FAN_PIN -1
#endif
#ifndef E2_AUTO_FAN_PIN
#define E2_AUTO_FAN_PIN -1
#endif
#ifndef E3_AUTO_FAN_PIN
#define E3_AUTO_FAN_PIN -1
#endif
#ifndef E4_AUTO_FAN_PIN
#define E4_AUTO_FAN_PIN -1
#endif
#ifndef E5_AUTO_FAN_PIN
#define E5_AUTO_FAN_PIN -1
#endif
#ifndef E6_AUTO_FAN_PIN
#define E6_AUTO_FAN_PIN -1
#endif
#ifndef E7_AUTO_FAN_PIN
#define E7_AUTO_FAN_PIN -1
#endif
#ifndef CHAMBER_AUTO_FAN_PIN
#define CHAMBER_AUTO_FAN_PIN -1
#endif
#ifndef COOLER_AUTO_FAN_PIN
#define COOLER_AUTO_FAN_PIN -1
#endif

#define _IS_E_AUTO(N,F) (PIN_EXISTS(E##N##_AUTO_FAN) && E##N##_AUTO_FAN_PIN == FAN##F##_PIN)
#define _HAS_FAN(F) (F < MAX_FANS && PIN_EXISTS(FAN##F) \
&& !(HAS_CONTROLLER_FAN && CONTROLLER_FAN_PIN == FAN##F##_PIN) \
Expand Down
9 changes: 7 additions & 2 deletions Marlin/src/pins/esp32/pins_MKS_TINYBEE.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,13 @@
#define FAN1_PIN 148 // FAN2
#define HEATER_BED_PIN 144 // H-BED

//#define CONTROLLER_FAN_PIN 148 // FAN2
//#define E0_AUTO_FAN_PIN 148 // FAN2
#ifndef E0_AUTO_FAN_PIN
#define E0_AUTO_FAN_PIN FAN1_PIN // FAN2
Copy link
Member

@thinkyhead thinkyhead Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been conscientiously defining more pins using the pin number rather than references to other defined pins, especially those that have an optional function w/r/t Marlin. This is in consideration of the possibility of some configuration variant that includes #undef FAN1_PIN (because why define a pin that's not needed?) or which redefines FAN1_PIN — either of which would then break the definition of E0_AUTO_FAN_PIN. Although in most cases fan pins do correspond well to the pins marked for fans on the board, that is not strictly the way fan pins must be defined.

Copy link
Member Author

@thisiskeithb thisiskeithb Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using FAN1_PIN for E0_AUTO_FAN_PIN, FAN2_PIN for E1_AUTO_FAN_PIN, etc. is a common configuration and has been around since as long as I have been using Marlin (since at least 2017), so it would be really tough to see that go away.

Copy link
Member

@thinkyhead thinkyhead Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defining pins in reference to other pins is fine when they are known to be unaltered and works best in the case of a configuration file. But pins files are only meant to define the best defaults for any board, while also leaving open the potential for overrides and reordering. Tying the default of one pin to the value of another, which might be modified, is bound to cause confusion, so I am inclined to avoid this inside of pins files going forward. A common internal default used only within a pins file is another matter, as individual pins files are free to define "private" pin names according to their AUX number, silkscreen name, etc.

#endif

#ifndef CONTROLLER_FAN_PIN
#define CONTROLLER_FAN_PIN FAN1_PIN // FAN2
#endif

//
// ADC Reference Voltage
Expand Down
6 changes: 1 addition & 5 deletions Marlin/src/pins/esp32/pins_MM_JOKER.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,7 @@
#define FAN0_PIN 143

#ifndef E0_AUTO_FAN_PIN
#define E0_AUTO_FAN_PIN 142 // Enabled in Configuration_adv.h
#endif

#ifndef CONTROLLER_FAN_PIN
//#define CONTROLLER_FAN_PIN -1
#define E0_AUTO_FAN_PIN 142
#endif

#if ENABLED(JOKER_PLUS_2)
Expand Down
16 changes: 12 additions & 4 deletions Marlin/src/pins/esp32/pins_MRR_ESPE.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,20 @@
//
#define HEATER_0_PIN 145 // 2
#define FAN0_PIN 146 // 15
#define FAN1_PIN 149
#define HEATER_BED_PIN 144 // 4

#define CONTROLLER_FAN_PIN 147
//#define E0_AUTO_FAN_PIN 148 // need to update Configuration_adv.h @section extruder
//#define E1_AUTO_FAN_PIN 149 // need to update Configuration_adv.h @section extruder
#define FAN1_PIN 149
#ifndef CONTROLLER_FAN_PIN
#define CONTROLLER_FAN_PIN 147
#endif

#ifndef E0_AUTO_FAN_PIN
#define E0_AUTO_FAN_PIN 148
#endif

#ifndef E1_AUTO_FAN_PIN
#define E1_AUTO_FAN_PIN FAN1_PIN
#endif

//
// MicroSD card
Expand Down
5 changes: 4 additions & 1 deletion Marlin/src/pins/gd32f1/pins_TRIGORILLA_V006.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@
#define FAN0_PIN PA0 // FAN
#define FAN1_PIN PA14 // Connected to +24V
#define FAN2_PIN -1 // PB1, auto fan for E0
#define CONTROLLER_FAN_PIN FAN1_PIN

#ifndef CONTROLLER_FAN_PIN
#define CONTROLLER_FAN_PIN FAN1_PIN
#endif

//
// Misc
Expand Down
5 changes: 4 additions & 1 deletion Marlin/src/pins/lpc1768/pins_GMARSH_X6_REV1.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@
#define HEATER_BED_PIN P1_19 // Not a PWM pin, software PWM required
#define HEATER_0_PIN P3_26 // PWM1[3]
#define FAN0_PIN P3_25 // Part cooling fan - connected to PWM1[2]
#define E0_AUTO_FAN_PIN P0_27 // Extruder cooling fan

#ifndef E0_AUTO_FAN_PIN
#define E0_AUTO_FAN_PIN P0_27 // Extruder cooling fan
#endif

//
// Misc. Functions
Expand Down
3 changes: 1 addition & 2 deletions Marlin/src/pins/lpc1769/pins_TH3D_EZBOARD.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@
//
// Auto fans
//
#define AUTO_FAN_PIN P1_22 // FET 3
#ifndef E0_AUTO_FAN_PIN
#define E0_AUTO_FAN_PIN AUTO_FAN_PIN
#define E0_AUTO_FAN_PIN P1_22 // FET 3
#endif

//
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/pins/mega/pins_SILVER_GATE.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
#define E0_AUTO_FAN_PIN 3
#endif

#define CONTROLLER_FAN_PIN 2
#ifndef CONTROLLER_FAN_PIN
#define CONTROLLER_FAN_PIN 2
#endif

#define TEMP_0_PIN 7 // Analog Input

Expand Down
5 changes: 4 additions & 1 deletion Marlin/src/pins/ramps/pins_AZTEEG_X3_PRO.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
#define HEATER_7_PIN 11

#ifndef CONTROLLER_FAN_PIN
#define CONTROLLER_FAN_PIN 4 // Pin used for the fan to cool motherboard (-1 to disable)
#define CONTROLLER_FAN_PIN 4
#endif

//
Expand All @@ -137,6 +137,9 @@
#ifndef E3_AUTO_FAN_PIN
#define E3_AUTO_FAN_PIN AUTO_FAN_PIN
#endif
#ifndef E4_AUTO_FAN_PIN
#define E4_AUTO_FAN_PIN AUTO_FAN_PIN
#endif

//
// LCD / Controller
Expand Down
5 changes: 4 additions & 1 deletion Marlin/src/pins/ramps/pins_K8800.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@
//
#define HEATER_0_PIN 10
#define FAN0_PIN 8
#define CONTROLLER_FAN_PIN 9

#ifndef CONTROLLER_FAN_PIN
#define CONTROLLER_FAN_PIN 9
#endif

//
// Misc. Functions
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/pins/ramps/pins_TRIGORILLA_13.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#define FAN2_PIN 9

#ifndef E0_AUTO_FAN_PIN
#define E0_AUTO_FAN_PIN 9
#define E0_AUTO_FAN_PIN FAN2_PIN
#endif

#include "pins_RAMPS_13.h" // ... RAMPS
4 changes: 3 additions & 1 deletion Marlin/src/pins/ramps/pins_TRIGORILLA_14.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@
#define Z_MIN_PROBE_PIN 2 // X+
#endif

#define CONTROLLER_FAN_PIN FAN1_PIN
#ifndef CONTROLLER_FAN_PIN
#define CONTROLLER_FAN_PIN FAN1_PIN
#endif

#if ENABLED(POWER_LOSS_RECOVERY)
#define OUTAGETEST_PIN 79
Expand Down
5 changes: 4 additions & 1 deletion Marlin/src/pins/ramps/pins_VORON.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
//
#define MOSFET_C_PIN 11
#define FAN0_PIN 5 // Using the pin for the controller fan since controller fan is always on.
#define CONTROLLER_FAN_PIN 8

#ifndef CONTROLLER_FAN_PIN
#define CONTROLLER_FAN_PIN 8
#endif

//
// Auto fans
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/pins/sam/pins_RURAMPS4D_11.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@
#define FAN0_PIN 9
#endif
#define FAN1_PIN 8
#define CONTROLLER_FAN_PIN -1

//
// Temperature Sensors
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/pins/sam/pins_RURAMPS4D_13.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@

#define FAN0_PIN 9
#define FAN1_PIN 8
#define CONTROLLER_FAN_PIN -1

//
// Temperature Sensors
Expand Down
49 changes: 24 additions & 25 deletions Marlin/src/pins/sensitive_pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -685,31 +685,6 @@
// Heaters, Fans, Temp Sensors
//

#ifndef E0_AUTO_FAN_PIN
#define E0_AUTO_FAN_PIN -1
#endif
#ifndef E1_AUTO_FAN_PIN
#define E1_AUTO_FAN_PIN -1
#endif
#ifndef E2_AUTO_FAN_PIN
#define E2_AUTO_FAN_PIN -1
#endif
#ifndef E3_AUTO_FAN_PIN
#define E3_AUTO_FAN_PIN -1
#endif
#ifndef E4_AUTO_FAN_PIN
#define E4_AUTO_FAN_PIN -1
#endif
#ifndef E5_AUTO_FAN_PIN
#define E5_AUTO_FAN_PIN -1
#endif
#ifndef E6_AUTO_FAN_PIN
#define E6_AUTO_FAN_PIN -1
#endif
#ifndef E7_AUTO_FAN_PIN
#define E7_AUTO_FAN_PIN -1
#endif

#define _H0_PINS
#define _H1_PINS
#define _H2_PINS
Expand All @@ -722,27 +697,51 @@
#define DIO_PIN(P) TERN(TARGET_LPC1768, P, analogInputToDigitalPin(P))

#if HAS_HOTEND
#ifndef E0_AUTO_FAN_PIN
#define E0_AUTO_FAN_PIN -1
#endif
#undef _H0_PINS
#define _H0_PINS HEATER_0_PIN, E0_AUTO_FAN_PIN, DIO_PIN(TEMP_0_PIN),
#if HAS_MULTI_HOTEND
#ifndef E1_AUTO_FAN_PIN
#define E1_AUTO_FAN_PIN -1
#endif
#undef _H1_PINS
#define _H1_PINS HEATER_1_PIN, E1_AUTO_FAN_PIN, DIO_PIN(TEMP_1_PIN),
#if HOTENDS > 2
#ifndef E2_AUTO_FAN_PIN
#define E3_AUTO_FAN_PIN -1
#endif
#undef _H2_PINS
#define _H2_PINS HEATER_2_PIN, E2_AUTO_FAN_PIN, DIO_PIN(TEMP_2_PIN),
#if HOTENDS > 3
#ifndef E3_AUTO_FAN_PIN
#define E3_AUTO_FAN_PIN -1
#endif
#undef _H3_PINS
#define _H3_PINS HEATER_3_PIN, E3_AUTO_FAN_PIN, DIO_PIN(TEMP_3_PIN),
#if HOTENDS > 4
#ifndef E4_AUTO_FAN_PIN
#define E4_AUTO_FAN_PIN -1
#endif
#undef _H4_PINS
#define _H4_PINS HEATER_4_PIN, E4_AUTO_FAN_PIN, DIO_PIN(TEMP_4_PIN),
#if HOTENDS > 5
#ifndef E5_AUTO_FAN_PIN
#define E5_AUTO_FAN_PIN -1
#endif
#undef _H5_PINS
#define _H5_PINS HEATER_5_PIN, E5_AUTO_FAN_PIN, DIO_PIN(TEMP_5_PIN),
#if HOTENDS > 6
#ifndef E6_AUTO_FAN_PIN
#define E6_AUTO_FAN_PIN -1
#endif
#undef _H6_PINS
#define _H6_PINS HEATER_6_PIN, E6_AUTO_FAN_PIN, DIO_PIN(TEMP_6_PIN),
#if HOTENDS > 7
#ifndef E7_AUTO_FAN_PIN
#define E7_AUTO_FAN_PIN -1
#endif
#undef _H7_PINS
#define _H7_PINS HEATER_7_PIN, E7_AUTO_FAN_PIN, DIO_PIN(TEMP_7_PIN),
#endif // HOTENDS > 7
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/pins/stm32f0/pins_MALYAN_M300.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@
#define HEATER_0_PIN PA1 // HOTEND0 MOSFET
#define HEATER_BED_PIN PA5 // BED MOSFET

#define AUTO_FAN_PIN PA8
#ifndef E0_AUTO_FAN_PIN
#define E0_AUTO_FAN_PIN PA8
#endif
4 changes: 3 additions & 1 deletion Marlin/src/pins/stm32f1/pins_BTT_SKR_CR6.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@
#define FAN0_PIN PC6 // FAN
#define FAN_SOFT_PWM_REQUIRED

#define CONTROLLER_FAN_PIN PC7
#ifndef CONTROLLER_FAN_PIN
#define CONTROLLER_FAN_PIN PC7
#endif

//
// LCD / Controller
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/pins/stm32f1/pins_CHITU3D_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@
//
// Fans
//
#define CONTROLLER_FAN_PIN PD6 // BOARD FAN
#ifndef CONTROLLER_FAN_PIN
#define CONTROLLER_FAN_PIN PD6 // BOARD FAN
#endif
#define FAN0_PIN PG13 // FAN
#define FAN2_PIN PG14

Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@
//
// Fans
//
#define CONTROLLER_FAN_PIN PD6 // FAN
#ifndef CONTROLLER_FAN_PIN
#define CONTROLLER_FAN_PIN PD6 // FAN
#endif
#define FAN0_PIN PG13 // FAN
#define FAN1_PIN PG14 // FAN

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/pins/stm32f4/pins_CREALITY_F401.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@
#define HEATER_BED_PIN PA7 // BED_HEAT_1 FET

#define FAN0_PIN PA0 // Part cooling fan FET
//#define FAN1_PIN PE11 // Extruder fan FET
#define FAN1_PIN PC0 // Extruder fan FET
//#define FAN2_PIN PE1 // Controller fan FET

#ifndef E0_AUTO_FAN_PIN
#define E0_AUTO_FAN_PIN PA1 // FAN1_PIN
#define E0_AUTO_FAN_PIN FAN1_PIN
#endif

//
Expand Down
Loading