Skip to content

Commit

Permalink
heater inverting as switch
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Mar 28, 2023
1 parent d60eb85 commit 4c79287
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 67 deletions.
65 changes: 11 additions & 54 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2799,54 +2799,24 @@
#define HAS_MICROSTEPS 1
#endif

/**
* Heater signal inversion defaults
*/

#if HAS_HEATER_0 && !defined(HEATER_0_INVERTING)
#define HEATER_0_INVERTING false
#endif
#if HAS_HEATER_1 && !defined(HEATER_1_INVERTING)
#define HEATER_1_INVERTING false
#endif
#if HAS_HEATER_2 && !defined(HEATER_2_INVERTING)
#define HEATER_2_INVERTING false
#endif
#if HAS_HEATER_3 && !defined(HEATER_3_INVERTING)
#define HEATER_3_INVERTING false
#endif
#if HAS_HEATER_4 && !defined(HEATER_4_INVERTING)
#define HEATER_4_INVERTING false
#endif
#if HAS_HEATER_5 && !defined(HEATER_5_INVERTING)
#define HEATER_5_INVERTING false
#endif
#if HAS_HEATER_6 && !defined(HEATER_6_INVERTING)
#define HEATER_6_INVERTING false
#endif
#if HAS_HEATER_7 && !defined(HEATER_7_INVERTING)
#define HEATER_7_INVERTING false
#endif

/**
* Helper Macros for heaters and extruder fan
*/

#define WRITE_HEATER_0P(v) WRITE(HEATER_0_PIN, (v) ^ HEATER_0_INVERTING)
#define WRITE_HEATER_0P(v) WRITE(HEATER_0_PIN, (v) ^ ENABLED(HEATER_0_INVERTING))
#if EITHER(HAS_MULTI_HOTEND, HEATERS_PARALLEL)
#define WRITE_HEATER_1(v) WRITE(HEATER_1_PIN, (v) ^ HEATER_1_INVERTING)
#define WRITE_HEATER_1(v) WRITE(HEATER_1_PIN, (v) ^ ENABLED(HEATER_1_INVERTING))
#if HOTENDS > 2
#define WRITE_HEATER_2(v) WRITE(HEATER_2_PIN, (v) ^ HEATER_2_INVERTING)
#define WRITE_HEATER_2(v) WRITE(HEATER_2_PIN, (v) ^ ENABLED(HEATER_2_INVERTING))
#if HOTENDS > 3
#define WRITE_HEATER_3(v) WRITE(HEATER_3_PIN, (v) ^ HEATER_3_INVERTING)
#define WRITE_HEATER_3(v) WRITE(HEATER_3_PIN, (v) ^ ENABLED(HEATER_3_INVERTING))
#if HOTENDS > 4
#define WRITE_HEATER_4(v) WRITE(HEATER_4_PIN, (v) ^ HEATER_4_INVERTING)
#define WRITE_HEATER_4(v) WRITE(HEATER_4_PIN, (v) ^ ENABLED(HEATER_4_INVERTING))
#if HOTENDS > 5
#define WRITE_HEATER_5(v) WRITE(HEATER_5_PIN, (v) ^ HEATER_5_INVERTING)
#define WRITE_HEATER_5(v) WRITE(HEATER_5_PIN, (v) ^ ENABLED(HEATER_5_INVERTING))
#if HOTENDS > 6
#define WRITE_HEATER_6(v) WRITE(HEATER_6_PIN, (v) ^ HEATER_6_INVERTING)
#define WRITE_HEATER_6(v) WRITE(HEATER_6_PIN, (v) ^ ENABLED(HEATER_6_INVERTING))
#if HOTENDS > 7
#define WRITE_HEATER_7(v) WRITE(HEATER_7_PIN, (v) ^ HEATER_7_INVERTING)
#define WRITE_HEATER_7(v) WRITE(HEATER_7_PIN, (v) ^ ENABLED(HEATER_7_INVERTING))
#endif // HOTENDS > 7
#endif // HOTENDS > 6
#endif // HOTENDS > 5
Expand All @@ -2860,10 +2830,6 @@
#define WRITE_HEATER_0(v) WRITE_HEATER_0P(v)
#endif

#ifndef MIN_POWER
#define MIN_POWER 0
#endif

/**
* Heated bed requires settings
*/
Expand All @@ -2874,10 +2840,7 @@
#ifndef MAX_BED_POWER
#define MAX_BED_POWER 255
#endif
#ifndef HEATER_BED_INVERTING
#define HEATER_BED_INVERTING false
#endif
#define WRITE_HEATER_BED(v) WRITE(HEATER_BED_PIN, (v) ^ HEATER_BED_INVERTING)
#define WRITE_HEATER_BED(v) WRITE(HEATER_BED_PIN, (v) ^ ENABLED(HEATER_BED_INVERTING))
#endif

/**
Expand All @@ -2890,10 +2853,7 @@
#ifndef MAX_CHAMBER_POWER
#define MAX_CHAMBER_POWER 255
#endif
#ifndef HEATER_CHAMBER_INVERTING
#define HEATER_CHAMBER_INVERTING false
#endif
#define WRITE_HEATER_CHAMBER(v) WRITE(HEATER_CHAMBER_PIN, (v) ^ HEATER_CHAMBER_INVERTING)
#define WRITE_HEATER_CHAMBER(v) WRITE(HEATER_CHAMBER_PIN, (v) ^ ENABLED(HEATER_CHAMBER_INVERTING))
#endif

/**
Expand All @@ -2903,10 +2863,7 @@
#ifndef MAX_COOLER_POWER
#define MAX_COOLER_POWER 255
#endif
#ifndef COOLER_INVERTING
#define COOLER_INVERTING true
#endif
#define WRITE_HEATER_COOLER(v) WRITE(COOLER_PIN, (v) ^ COOLER_INVERTING)
#define WRITE_HEATER_COOLER(v) WRITE(COOLER_PIN, (v) ^ ENABLED(COOLER_INVERTING))
#endif

#if HAS_HOTEND || HAS_HEATED_BED || HAS_HEATED_CHAMBER || HAS_COOLER
Expand Down
26 changes: 13 additions & 13 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2630,47 +2630,47 @@ void Temperature::init() {

#if HAS_HEATER_0
#ifdef BOARD_OPENDRAIN_MOSFETS
OUT_WRITE_OD(HEATER_0_PIN, HEATER_0_INVERTING);
OUT_WRITE_OD(HEATER_0_PIN, ENABLED(HEATER_0_INVERTING));
#else
OUT_WRITE(HEATER_0_PIN, HEATER_0_INVERTING);
OUT_WRITE(HEATER_0_PIN, ENABLED(HEATER_0_INVERTING));
#endif
#endif
#if HAS_HEATER_1
OUT_WRITE(HEATER_1_PIN, HEATER_1_INVERTING);
OUT_WRITE(HEATER_1_PIN, ENABLED(HEATER_1_INVERTING));
#endif
#if HAS_HEATER_2
OUT_WRITE(HEATER_2_PIN, HEATER_2_INVERTING);
OUT_WRITE(HEATER_2_PIN, ENABLED(HEATER_2_INVERTING));
#endif
#if HAS_HEATER_3
OUT_WRITE(HEATER_3_PIN, HEATER_3_INVERTING);
OUT_WRITE(HEATER_3_PIN, ENABLED(HEATER_3_INVERTING));
#endif
#if HAS_HEATER_4
OUT_WRITE(HEATER_4_PIN, HEATER_4_INVERTING);
OUT_WRITE(HEATER_4_PIN, ENABLED(HEATER_4_INVERTING));
#endif
#if HAS_HEATER_5
OUT_WRITE(HEATER_5_PIN, HEATER_5_INVERTING);
OUT_WRITE(HEATER_5_PIN, ENABLED(HEATER_5_INVERTING));
#endif
#if HAS_HEATER_6
OUT_WRITE(HEATER_6_PIN, HEATER_6_INVERTING);
OUT_WRITE(HEATER_6_PIN, ENABLED(HEATER_6_INVERTING));
#endif
#if HAS_HEATER_7
OUT_WRITE(HEATER_7_PIN, HEATER_7_INVERTING);
OUT_WRITE(HEATER_7_PIN, ENABLED(HEATER_7_INVERTING));
#endif

#if HAS_HEATED_BED
#ifdef BOARD_OPENDRAIN_MOSFETS
OUT_WRITE_OD(HEATER_BED_PIN, HEATER_BED_INVERTING);
OUT_WRITE_OD(HEATER_BED_PIN, ENABLED(HEATER_BED_INVERTING));
#else
OUT_WRITE(HEATER_BED_PIN, HEATER_BED_INVERTING);
OUT_WRITE(HEATER_BED_PIN, ENABLED(HEATER_BED_INVERTING));
#endif
#endif

#if HAS_HEATED_CHAMBER
OUT_WRITE(HEATER_CHAMBER_PIN, HEATER_CHAMBER_INVERTING);
OUT_WRITE(HEATER_CHAMBER_PIN, ENABLED(HEATER_CHAMBER_INVERTING));
#endif

#if HAS_COOLER
OUT_WRITE(COOLER_PIN, COOLER_INVERTING);
OUT_WRITE(COOLER_PIN, ENABLED(COOLER_INVERTING));
#endif

#if HAS_FAN0
Expand Down

0 comments on commit 4c79287

Please sign in to comment.