Browse Source

🐛 More explicit allocation of solenoids

In reference to #22887
Scott Lahteine 2 years ago
parent
commit
f8968ed13c

+ 0
- 1
Marlin/Configuration.h View File

@@ -260,7 +260,6 @@
260 260
 
261 261
   #define PARKING_EXTRUDER_PARKING_X { -78, 184 }     // X positions for parking the extruders
262 262
   #define PARKING_EXTRUDER_GRAB_DISTANCE 1            // (mm) Distance to move beyond the parking point to grab the extruder
263
-  //#define MANUAL_SOLENOID_CONTROL                   // Manual control of docking solenoids with M380 S / M381
264 263
 
265 264
   #if ENABLED(PARKING_EXTRUDER)
266 265
 

+ 5
- 35
Marlin/src/feature/solenoid.cpp View File

@@ -34,28 +34,12 @@
34 34
   #include "../module/tool_change.h"
35 35
 #endif
36 36
 
37
-#define HAS_SOLENOID(N) (HAS_SOLENOID_##N && (ENABLED(MANUAL_SOLENOID_CONTROL) || N < EXTRUDERS))
38
-
39 37
 // Used primarily with MANUAL_SOLENOID_CONTROL
40 38
 static void set_solenoid(const uint8_t num, const bool active) {
41 39
   const uint8_t value = active ? PE_MAGNET_ON_STATE : !PE_MAGNET_ON_STATE;
40
+  #define _SOL_CASE(N) case N: TERN_(HAS_SOLENOID_##N, OUT_WRITE(SOL##N##_PIN, value)); break;
42 41
   switch (num) {
43
-    case 0: OUT_WRITE(SOL0_PIN, value); break;
44
-    #if HAS_SOLENOID(1)
45
-      case 1: OUT_WRITE(SOL1_PIN, value); break;
46
-    #endif
47
-    #if HAS_SOLENOID(2)
48
-      case 2: OUT_WRITE(SOL2_PIN, value); break;
49
-    #endif
50
-    #if HAS_SOLENOID(3)
51
-      case 3: OUT_WRITE(SOL3_PIN, value); break;
52
-    #endif
53
-    #if HAS_SOLENOID(4)
54
-      case 4: OUT_WRITE(SOL4_PIN, value); break;
55
-    #endif
56
-    #if HAS_SOLENOID(5)
57
-      case 5: OUT_WRITE(SOL5_PIN, value); break;
58
-    #endif
42
+    REPEAT(8, _SOL_CASE)
59 43
     default: SERIAL_ECHO_MSG(STR_INVALID_SOLENOID); break;
60 44
   }
61 45
 
@@ -67,25 +51,11 @@ static void set_solenoid(const uint8_t num, const bool active) {
67 51
 
68 52
 void enable_solenoid(const uint8_t num) { set_solenoid(num, true); }
69 53
 void disable_solenoid(const uint8_t num) { set_solenoid(num, false); }
70
-void enable_solenoid_on_active_extruder() { enable_solenoid(active_extruder); }
54
+void enable_solenoid_on_active_extruder() {  }
71 55
 
72 56
 void disable_all_solenoids() {
73
-  disable_solenoid(0);
74
-  #if HAS_SOLENOID(1)
75
-    disable_solenoid(1);
76
-  #endif
77
-  #if HAS_SOLENOID(2)
78
-    disable_solenoid(2);
79
-  #endif
80
-  #if HAS_SOLENOID(3)
81
-    disable_solenoid(3);
82
-  #endif
83
-  #if HAS_SOLENOID(4)
84
-    disable_solenoid(4);
85
-  #endif
86
-  #if HAS_SOLENOID(5)
87
-    disable_solenoid(5);
88
-  #endif
57
+  #define _SOL_DISABLE(N) TERN_(HAS_SOLENOID_##N, disable_solenoid(N));
58
+  REPEAT(8, _SOL_DISABLE)
89 59
 }
90 60
 
91 61
 #endif // EXT_SOLENOID || MANUAL_SOLENOID_CONTROL

+ 35
- 24
Marlin/src/inc/Conditionals_post.h View File

@@ -1635,9 +1635,6 @@
1635 1635
   #if PIN_EXISTS(E0_MS1)
1636 1636
     #define HAS_E0_MS_PINS 1
1637 1637
   #endif
1638
-  #if PIN_EXISTS(SOL0)
1639
-    #define HAS_SOLENOID_0 1
1640
-  #endif
1641 1638
 
1642 1639
   #if E_STEPPERS > 1
1643 1640
     #if PIN_EXISTS(E1_ENABLE) || AXIS_IS_L64XX(E1) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E1))
@@ -1652,9 +1649,6 @@
1652 1649
     #if PIN_EXISTS(E1_MS1)
1653 1650
       #define HAS_E1_MS_PINS 1
1654 1651
     #endif
1655
-    #if PIN_EXISTS(SOL1)
1656
-      #define HAS_SOLENOID_1 1
1657
-    #endif
1658 1652
   #endif
1659 1653
 
1660 1654
   #if E_STEPPERS > 2
@@ -1670,9 +1664,6 @@
1670 1664
     #if PIN_EXISTS(E2_MS1)
1671 1665
       #define HAS_E2_MS_PINS 1
1672 1666
     #endif
1673
-    #if PIN_EXISTS(SOL2)
1674
-      #define HAS_SOLENOID_2 1
1675
-    #endif
1676 1667
   #endif
1677 1668
 
1678 1669
   #if E_STEPPERS > 3
@@ -1688,9 +1679,6 @@
1688 1679
     #if PIN_EXISTS(E3_MS1)
1689 1680
       #define HAS_E3_MS_PINS 1
1690 1681
     #endif
1691
-    #if PIN_EXISTS(SOL3)
1692
-      #define HAS_SOLENOID_3 1
1693
-    #endif
1694 1682
   #endif
1695 1683
 
1696 1684
   #if E_STEPPERS > 4
@@ -1706,9 +1694,6 @@
1706 1694
     #if PIN_EXISTS(E4_MS1)
1707 1695
       #define HAS_E4_MS_PINS 1
1708 1696
     #endif
1709
-    #if PIN_EXISTS(SOL4)
1710
-      #define HAS_SOLENOID_4 1
1711
-    #endif
1712 1697
   #endif
1713 1698
 
1714 1699
   #if E_STEPPERS > 5
@@ -1724,9 +1709,6 @@
1724 1709
     #if PIN_EXISTS(E5_MS1)
1725 1710
       #define HAS_E5_MS_PINS 1
1726 1711
     #endif
1727
-    #if PIN_EXISTS(SOL5)
1728
-      #define HAS_SOLENOID_5 1
1729
-    #endif
1730 1712
   #endif
1731 1713
 
1732 1714
   #if E_STEPPERS > 6
@@ -1742,9 +1724,6 @@
1742 1724
     #if PIN_EXISTS(E6_MS1)
1743 1725
       #define HAS_E6_MS_PINS 1
1744 1726
     #endif
1745
-    #if PIN_EXISTS(SOL6)
1746
-      #define HAS_SOLENOID_6 1
1747
-    #endif
1748 1727
   #endif
1749 1728
 
1750 1729
   #if E_STEPPERS > 7
@@ -1760,9 +1739,6 @@
1760 1739
     #if PIN_EXISTS(E7_MS1)
1761 1740
       #define HAS_E7_MS_PINS 1
1762 1741
     #endif
1763
-    #if PIN_EXISTS(SOL7)
1764
-      #define HAS_SOLENOID_7 1
1765
-    #endif
1766 1742
   #endif
1767 1743
 
1768 1744
   #if !defined(DISABLE_INACTIVE_E) && ENABLED(DISABLE_E)
@@ -1772,6 +1748,41 @@
1772 1748
   #undef DISABLE_INACTIVE_E
1773 1749
 #endif // HAS_EXTRUDERS
1774 1750
 
1751
+/**
1752
+ * Set solenoid flags if any features use solenoids
1753
+ *   - EXT_SOLENOID (M380, M381) to enable/disable the extruder solenoid
1754
+ *   - MANUAL_SOLENOID_CONTROL (M380, M381) to enable/disable solenoids by index
1755
+ *   - PARKING_EXTRUDER uses SOL0_PIN and SOL1_PIN
1756
+ *   - SOLENOID_PROBE uses SOL1_PIN
1757
+ *   - Z_PROBE_SLED uses SOL1_PIN, when defined (unless EXT_SOLENOID is enabled)
1758
+ */
1759
+#if ANY(EXT_SOLENOID, MANUAL_SOLENOID_CONTROL, PARKING_EXTRUDER, SOLENOID_PROBE, Z_PROBE_SLED)
1760
+  #if PIN_EXISTS(SOL0) && (EITHER(MANUAL_SOLENOID_CONTROL, PARKING_EXTRUDER) || BOTH(EXT_SOLENOID, HAS_EXTRUDERS))
1761
+    #define HAS_SOLENOID_0 1
1762
+  #endif
1763
+  #if PIN_EXISTS(SOL1) && (ANY(MANUAL_SOLENOID_CONTROL, PARKING_EXTRUDER, SOLENOID_PROBE, Z_PROBE_SLED) || TERN0(EXT_SOLENOID, E_STEPPERS > 1))
1764
+    #define HAS_SOLENOID_1 1
1765
+  #endif
1766
+  #if PIN_EXISTS(SOL2) && (ENABLED(MANUAL_SOLENOID_CONTROL) || TERN0(EXT_SOLENOID, E_STEPPERS > 2))
1767
+    #define HAS_SOLENOID_2 2
1768
+  #endif
1769
+  #if PIN_EXISTS(SOL3) && (ENABLED(MANUAL_SOLENOID_CONTROL) || TERN0(EXT_SOLENOID, E_STEPPERS > 3))
1770
+    #define HAS_SOLENOID_3 3
1771
+  #endif
1772
+  #if PIN_EXISTS(SOL4) && (ENABLED(MANUAL_SOLENOID_CONTROL) || TERN0(EXT_SOLENOID, E_STEPPERS > 4))
1773
+    #define HAS_SOLENOID_4 4
1774
+  #endif
1775
+  #if PIN_EXISTS(SOL5) && (ENABLED(MANUAL_SOLENOID_CONTROL) || TERN0(EXT_SOLENOID, E_STEPPERS > 5))
1776
+    #define HAS_SOLENOID_5 5
1777
+  #endif
1778
+  #if PIN_EXISTS(SOL6) && (ENABLED(MANUAL_SOLENOID_CONTROL) || TERN0(EXT_SOLENOID, E_STEPPERS > 6))
1779
+    #define HAS_SOLENOID_6 6
1780
+  #endif
1781
+  #if PIN_EXISTS(SOL7) && (ENABLED(MANUAL_SOLENOID_CONTROL) || TERN0(EXT_SOLENOID, E_STEPPERS > 7))
1782
+    #define HAS_SOLENOID_7 7
1783
+  #endif
1784
+#endif
1785
+
1775 1786
 //
1776 1787
 // Trinamic Stepper Drivers
1777 1788
 //

+ 1
- 1
Marlin/src/inc/SanityCheck.h View File

@@ -1241,7 +1241,7 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
1241 1241
 /**
1242 1242
  * (Magnetic) Parking Extruder requirements
1243 1243
  */
1244
-#if ANY(PARKING_EXTRUDER, MAGNETIC_PARKING_EXTRUDER)
1244
+#if EITHER(PARKING_EXTRUDER, MAGNETIC_PARKING_EXTRUDER)
1245 1245
   #if ENABLED(EXT_SOLENOID)
1246 1246
     #error "(MAGNETIC_)PARKING_EXTRUDER and EXT_SOLENOID are incompatible. (Pins are used twice.)"
1247 1247
   #elif EXTRUDERS != 2

Loading…
Cancel
Save