|
28 | 28 | #include "../inc/MarlinConfig.h"
|
29 | 29 | #include <stdint.h>
|
30 | 30 |
|
| 31 | +#define __ES_ITEM(N) N, |
| 32 | +#define _ES_ITEM(K,N) TERN_(K,DEFER4(__ES_ITEM)(N)) |
| 33 | + |
31 | 34 | enum EndstopEnum : char {
|
32 |
| - X_MIN, Y_MIN, Z_MIN, Z_MIN_PROBE, |
33 |
| - X_MAX, Y_MAX, Z_MAX, |
34 |
| - X2_MIN, X2_MAX, |
35 |
| - Y2_MIN, Y2_MAX, |
36 |
| - Z2_MIN, Z2_MAX, |
37 |
| - Z3_MIN, Z3_MAX, |
38 |
| - Z4_MIN, Z4_MAX |
| 35 | + _ES_ITEM(HAS_X_MIN, X_MIN) |
| 36 | + _ES_ITEM(HAS_X_MAX, X_MAX) |
| 37 | + _ES_ITEM(HAS_Y_MIN, Y_MIN) |
| 38 | + _ES_ITEM(HAS_Y_MAX, Y_MAX) |
| 39 | + _ES_ITEM(HAS_Z_MIN, Z_MIN) |
| 40 | + _ES_ITEM(HAS_Z_MAX, Z_MAX) |
| 41 | + #if ENABLED(X_DUAL_ENDSTOPS) |
| 42 | + _ES_ITEM(HAS_X_MIN, X2_MIN) |
| 43 | + _ES_ITEM(HAS_X_MAX, X2_MAX) |
| 44 | + #endif |
| 45 | + #if ENABLED(Y_DUAL_ENDSTOPS) |
| 46 | + _ES_ITEM(HAS_Y_MIN, Y2_MIN) |
| 47 | + _ES_ITEM(HAS_Y_MAX, Y2_MAX) |
| 48 | + #endif |
| 49 | + #if ENABLED(Z_MULTI_ENDSTOPS) |
| 50 | + _ES_ITEM(HAS_Z_MIN, Z2_MIN) |
| 51 | + _ES_ITEM(HAS_Z_MAX, Z2_MAX) |
| 52 | + #if NUM_Z_STEPPER_DRIVERS >= 3 |
| 53 | + _ES_ITEM(HAS_Z_MIN, Z3_MIN) |
| 54 | + _ES_ITEM(HAS_Z_MAX, Z3_MAX) |
| 55 | + #endif |
| 56 | + #if NUM_Z_STEPPER_DRIVERS >= 4 |
| 57 | + _ES_ITEM(HAS_Z_MIN, Z4_MIN) |
| 58 | + _ES_ITEM(HAS_Z_MAX, Z4_MAX) |
| 59 | + #endif |
| 60 | + #endif |
| 61 | + _ES_ITEM(HAS_Z_MIN_PROBE_PIN, Z_MIN_PROBE) |
| 62 | + NUM_ENDSTOP_STATES |
39 | 63 | };
|
40 | 64 |
|
41 | 65 | #define X_ENDSTOP (x_home_dir(active_extruder) < 0 ? X_MIN : X_MAX)
|
42 | 66 | #define Y_ENDSTOP (Y_HOME_DIR < 0 ? Y_MIN : Y_MAX)
|
43 | 67 | #define Z_ENDSTOP (Z_HOME_DIR < 0 ? TERN(HOMING_Z_WITH_PROBE, Z_MIN, Z_MIN_PROBE) : Z_MAX)
|
44 | 68 |
|
| 69 | +#undef __ES_ITEM |
| 70 | +#undef _ES_ITEM |
| 71 | + |
45 | 72 | class Endstops {
|
46 | 73 | public:
|
47 |
| - #if HAS_EXTRA_ENDSTOPS |
48 |
| - typedef uint16_t esbits_t; |
49 |
| - #if ENABLED(X_DUAL_ENDSTOPS) |
50 |
| - static float x2_endstop_adj; |
51 |
| - #endif |
52 |
| - #if ENABLED(Y_DUAL_ENDSTOPS) |
53 |
| - static float y2_endstop_adj; |
54 |
| - #endif |
55 |
| - #if ENABLED(Z_MULTI_ENDSTOPS) |
56 |
| - static float z2_endstop_adj; |
57 |
| - #endif |
58 |
| - #if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 3 |
59 |
| - static float z3_endstop_adj; |
60 |
| - #endif |
61 |
| - #if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 4 |
62 |
| - static float z4_endstop_adj; |
63 |
| - #endif |
64 |
| - #else |
65 |
| - typedef uint8_t esbits_t; |
| 74 | + |
| 75 | + typedef IF<(NUM_ENDSTOP_STATES > 8), uint16_t, uint8_t>::type endstop_mask_t; |
| 76 | + |
| 77 | + #if ENABLED(X_DUAL_ENDSTOPS) |
| 78 | + static float x2_endstop_adj; |
| 79 | + #endif |
| 80 | + #if ENABLED(Y_DUAL_ENDSTOPS) |
| 81 | + static float y2_endstop_adj; |
| 82 | + #endif |
| 83 | + #if ENABLED(Z_MULTI_ENDSTOPS) |
| 84 | + static float z2_endstop_adj; |
| 85 | + #endif |
| 86 | + #if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 3 |
| 87 | + static float z3_endstop_adj; |
| 88 | + #endif |
| 89 | + #if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 4 |
| 90 | + static float z4_endstop_adj; |
66 | 91 | #endif
|
67 | 92 |
|
68 | 93 | private:
|
69 | 94 | static bool enabled, enabled_globally;
|
70 |
| - static esbits_t live_state; |
71 |
| - static volatile uint8_t hit_state; // Use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT index |
| 95 | + static endstop_mask_t live_state; |
| 96 | + static volatile endstop_mask_t hit_state; // Use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT index |
72 | 97 |
|
73 | 98 | #if ENDSTOP_NOISE_THRESHOLD
|
74 |
| - static esbits_t validated_live_state; |
| 99 | + static endstop_mask_t validated_live_state; |
75 | 100 | static uint8_t endstop_poll_count; // Countdown from threshold for polling
|
76 | 101 | #endif
|
77 | 102 |
|
@@ -107,12 +132,12 @@ class Endstops {
|
107 | 132 | /**
|
108 | 133 | * Get Endstop hit state.
|
109 | 134 | */
|
110 |
| - FORCE_INLINE static uint8_t trigger_state() { return hit_state; } |
| 135 | + FORCE_INLINE static endstop_mask_t trigger_state() { return hit_state; } |
111 | 136 |
|
112 | 137 | /**
|
113 | 138 | * Get current endstops state
|
114 | 139 | */
|
115 |
| - FORCE_INLINE static esbits_t state() { |
| 140 | + FORCE_INLINE static endstop_mask_t state() { |
116 | 141 | return
|
117 | 142 | #if ENDSTOP_NOISE_THRESHOLD
|
118 | 143 | validated_live_state
|
|
0 commit comments