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
 
260
 
261
   #define PARKING_EXTRUDER_PARKING_X { -78, 184 }     // X positions for parking the extruders
261
   #define PARKING_EXTRUDER_PARKING_X { -78, 184 }     // X positions for parking the extruders
262
   #define PARKING_EXTRUDER_GRAB_DISTANCE 1            // (mm) Distance to move beyond the parking point to grab the extruder
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
   #if ENABLED(PARKING_EXTRUDER)
264
   #if ENABLED(PARKING_EXTRUDER)
266
 
265
 

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

34
   #include "../module/tool_change.h"
34
   #include "../module/tool_change.h"
35
 #endif
35
 #endif
36
 
36
 
37
-#define HAS_SOLENOID(N) (HAS_SOLENOID_##N && (ENABLED(MANUAL_SOLENOID_CONTROL) || N < EXTRUDERS))
38
-
39
 // Used primarily with MANUAL_SOLENOID_CONTROL
37
 // Used primarily with MANUAL_SOLENOID_CONTROL
40
 static void set_solenoid(const uint8_t num, const bool active) {
38
 static void set_solenoid(const uint8_t num, const bool active) {
41
   const uint8_t value = active ? PE_MAGNET_ON_STATE : !PE_MAGNET_ON_STATE;
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
   switch (num) {
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
     default: SERIAL_ECHO_MSG(STR_INVALID_SOLENOID); break;
43
     default: SERIAL_ECHO_MSG(STR_INVALID_SOLENOID); break;
60
   }
44
   }
61
 
45
 
67
 
51
 
68
 void enable_solenoid(const uint8_t num) { set_solenoid(num, true); }
52
 void enable_solenoid(const uint8_t num) { set_solenoid(num, true); }
69
 void disable_solenoid(const uint8_t num) { set_solenoid(num, false); }
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
 void disable_all_solenoids() {
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
 #endif // EXT_SOLENOID || MANUAL_SOLENOID_CONTROL
61
 #endif // EXT_SOLENOID || MANUAL_SOLENOID_CONTROL

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

1635
   #if PIN_EXISTS(E0_MS1)
1635
   #if PIN_EXISTS(E0_MS1)
1636
     #define HAS_E0_MS_PINS 1
1636
     #define HAS_E0_MS_PINS 1
1637
   #endif
1637
   #endif
1638
-  #if PIN_EXISTS(SOL0)
1639
-    #define HAS_SOLENOID_0 1
1640
-  #endif
1641
 
1638
 
1642
   #if E_STEPPERS > 1
1639
   #if E_STEPPERS > 1
1643
     #if PIN_EXISTS(E1_ENABLE) || AXIS_IS_L64XX(E1) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E1))
1640
     #if PIN_EXISTS(E1_ENABLE) || AXIS_IS_L64XX(E1) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E1))
1652
     #if PIN_EXISTS(E1_MS1)
1649
     #if PIN_EXISTS(E1_MS1)
1653
       #define HAS_E1_MS_PINS 1
1650
       #define HAS_E1_MS_PINS 1
1654
     #endif
1651
     #endif
1655
-    #if PIN_EXISTS(SOL1)
1656
-      #define HAS_SOLENOID_1 1
1657
-    #endif
1658
   #endif
1652
   #endif
1659
 
1653
 
1660
   #if E_STEPPERS > 2
1654
   #if E_STEPPERS > 2
1670
     #if PIN_EXISTS(E2_MS1)
1664
     #if PIN_EXISTS(E2_MS1)
1671
       #define HAS_E2_MS_PINS 1
1665
       #define HAS_E2_MS_PINS 1
1672
     #endif
1666
     #endif
1673
-    #if PIN_EXISTS(SOL2)
1674
-      #define HAS_SOLENOID_2 1
1675
-    #endif
1676
   #endif
1667
   #endif
1677
 
1668
 
1678
   #if E_STEPPERS > 3
1669
   #if E_STEPPERS > 3
1688
     #if PIN_EXISTS(E3_MS1)
1679
     #if PIN_EXISTS(E3_MS1)
1689
       #define HAS_E3_MS_PINS 1
1680
       #define HAS_E3_MS_PINS 1
1690
     #endif
1681
     #endif
1691
-    #if PIN_EXISTS(SOL3)
1692
-      #define HAS_SOLENOID_3 1
1693
-    #endif
1694
   #endif
1682
   #endif
1695
 
1683
 
1696
   #if E_STEPPERS > 4
1684
   #if E_STEPPERS > 4
1706
     #if PIN_EXISTS(E4_MS1)
1694
     #if PIN_EXISTS(E4_MS1)
1707
       #define HAS_E4_MS_PINS 1
1695
       #define HAS_E4_MS_PINS 1
1708
     #endif
1696
     #endif
1709
-    #if PIN_EXISTS(SOL4)
1710
-      #define HAS_SOLENOID_4 1
1711
-    #endif
1712
   #endif
1697
   #endif
1713
 
1698
 
1714
   #if E_STEPPERS > 5
1699
   #if E_STEPPERS > 5
1724
     #if PIN_EXISTS(E5_MS1)
1709
     #if PIN_EXISTS(E5_MS1)
1725
       #define HAS_E5_MS_PINS 1
1710
       #define HAS_E5_MS_PINS 1
1726
     #endif
1711
     #endif
1727
-    #if PIN_EXISTS(SOL5)
1728
-      #define HAS_SOLENOID_5 1
1729
-    #endif
1730
   #endif
1712
   #endif
1731
 
1713
 
1732
   #if E_STEPPERS > 6
1714
   #if E_STEPPERS > 6
1742
     #if PIN_EXISTS(E6_MS1)
1724
     #if PIN_EXISTS(E6_MS1)
1743
       #define HAS_E6_MS_PINS 1
1725
       #define HAS_E6_MS_PINS 1
1744
     #endif
1726
     #endif
1745
-    #if PIN_EXISTS(SOL6)
1746
-      #define HAS_SOLENOID_6 1
1747
-    #endif
1748
   #endif
1727
   #endif
1749
 
1728
 
1750
   #if E_STEPPERS > 7
1729
   #if E_STEPPERS > 7
1760
     #if PIN_EXISTS(E7_MS1)
1739
     #if PIN_EXISTS(E7_MS1)
1761
       #define HAS_E7_MS_PINS 1
1740
       #define HAS_E7_MS_PINS 1
1762
     #endif
1741
     #endif
1763
-    #if PIN_EXISTS(SOL7)
1764
-      #define HAS_SOLENOID_7 1
1765
-    #endif
1766
   #endif
1742
   #endif
1767
 
1743
 
1768
   #if !defined(DISABLE_INACTIVE_E) && ENABLED(DISABLE_E)
1744
   #if !defined(DISABLE_INACTIVE_E) && ENABLED(DISABLE_E)
1772
   #undef DISABLE_INACTIVE_E
1748
   #undef DISABLE_INACTIVE_E
1773
 #endif // HAS_EXTRUDERS
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
 // Trinamic Stepper Drivers
1787
 // Trinamic Stepper Drivers
1777
 //
1788
 //

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

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

Loading…
Cancel
Save