|
@@ -36,12 +36,6 @@
|
36
|
36
|
#include HAL_PATH(../HAL, endstop_interrupts.h)
|
37
|
37
|
#endif
|
38
|
38
|
|
39
|
|
-#if HAS_BED_PROBE
|
40
|
|
- #define ENDSTOPS_ENABLED (enabled || z_probe_enabled)
|
41
|
|
-#else
|
42
|
|
- #define ENDSTOPS_ENABLED enabled
|
43
|
|
-#endif
|
44
|
|
-
|
45
|
39
|
Endstops endstops;
|
46
|
40
|
|
47
|
41
|
// public:
|
|
@@ -50,9 +44,9 @@ bool Endstops::enabled, Endstops::enabled_globally; // Initialized by settings.l
|
50
|
44
|
volatile uint8_t Endstops::hit_state;
|
51
|
45
|
|
52
|
46
|
Endstops::esbits_t Endstops::live_state = 0;
|
|
47
|
+
|
53
|
48
|
#if ENABLED(ENDSTOP_NOISE_FILTER)
|
54
|
|
- Endstops::esbits_t Endstops::old_live_state,
|
55
|
|
- Endstops::validated_live_state;
|
|
49
|
+ Endstops::esbits_t Endstops::validated_live_state;
|
56
|
50
|
uint8_t Endstops::endstop_poll_count;
|
57
|
51
|
#endif
|
58
|
52
|
|
|
@@ -222,9 +216,6 @@ void Endstops::init() {
|
222
|
216
|
|
223
|
217
|
} // Endstops::init
|
224
|
218
|
|
225
|
|
-// Called from ISR. A change was detected. Find out what happened!
|
226
|
|
-void Endstops::check_possible_change() { if (ENDSTOPS_ENABLED) update(); }
|
227
|
|
-
|
228
|
219
|
// Called from ISR: Poll endstop state if required
|
229
|
220
|
void Endstops::poll() {
|
230
|
221
|
|
|
@@ -232,8 +223,10 @@ void Endstops::poll() {
|
232
|
223
|
run_monitor(); // report changes in endstop status
|
233
|
224
|
#endif
|
234
|
225
|
|
235
|
|
- #if DISABLED(ENDSTOP_INTERRUPTS_FEATURE) || ENABLED(ENDSTOP_NOISE_FILTER)
|
236
|
|
- if (ENDSTOPS_ENABLED) update();
|
|
226
|
+ #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) && ENABLED(ENDSTOP_NOISE_FILTER)
|
|
227
|
+ if (endstop_poll_count) update();
|
|
228
|
+ #elif DISABLED(ENDSTOP_INTERRUPTS_FEATURE) || ENABLED(ENDSTOP_NOISE_FILTER)
|
|
229
|
+ update();
|
237
|
230
|
#endif
|
238
|
231
|
}
|
239
|
232
|
|
|
@@ -241,7 +234,7 @@ void Endstops::enable_globally(const bool onoff) {
|
241
|
234
|
enabled_globally = enabled = onoff;
|
242
|
235
|
|
243
|
236
|
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
244
|
|
- if (onoff) update(); // If enabling, update state now
|
|
237
|
+ update();
|
245
|
238
|
#endif
|
246
|
239
|
}
|
247
|
240
|
|
|
@@ -250,7 +243,7 @@ void Endstops::enable(const bool onoff) {
|
250
|
243
|
enabled = onoff;
|
251
|
244
|
|
252
|
245
|
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
253
|
|
- if (onoff) update(); // If enabling, update state now
|
|
246
|
+ update();
|
254
|
247
|
#endif
|
255
|
248
|
}
|
256
|
249
|
|
|
@@ -259,7 +252,7 @@ void Endstops::not_homing() {
|
259
|
252
|
enabled = enabled_globally;
|
260
|
253
|
|
261
|
254
|
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
262
|
|
- if (enabled) update(); // If enabling, update state now
|
|
255
|
+ update();
|
263
|
256
|
#endif
|
264
|
257
|
}
|
265
|
258
|
|
|
@@ -269,7 +262,7 @@ void Endstops::not_homing() {
|
269
|
262
|
z_probe_enabled = onoff;
|
270
|
263
|
|
271
|
264
|
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
272
|
|
- if (enabled) update(); // If enabling, update state now
|
|
265
|
+ update();
|
273
|
266
|
#endif
|
274
|
267
|
}
|
275
|
268
|
#endif
|
|
@@ -396,10 +389,12 @@ void Endstops::M119() {
|
396
|
389
|
// Check endstops - Could be called from ISR!
|
397
|
390
|
void Endstops::update() {
|
398
|
391
|
|
399
|
|
- // UPDATE_ENDSTOP_BIT: set the current endstop bits for an endstop to its status
|
|
392
|
+ #if DISABLED(ENDSTOP_NOISE_FILTER)
|
|
393
|
+ if (!abort_enabled()) return;
|
|
394
|
+ #endif
|
|
395
|
+
|
400
|
396
|
#define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT_TO(live_state, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
|
401
|
|
- // COPY_BIT: copy the value of SRC_BIT to DST_BIT in DST
|
402
|
|
- #define COPY_BIT(DST, SRC_BIT, DST_BIT) SET_BIT_TO(DST, DST_BIT, TEST(DST, SRC_BIT))
|
|
397
|
+ #define COPY_LIVE_STATE(SRC_BIT, DST_BIT) SET_BIT_TO(live_state, DST_BIT, TEST(live_state, SRC_BIT))
|
403
|
398
|
|
404
|
399
|
#if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && !(CORE_IS_XY || CORE_IS_XZ)
|
405
|
400
|
// If G38 command is active check Z_MIN_PROBE for ALL movement
|
|
@@ -444,7 +439,7 @@ void Endstops::update() {
|
444
|
439
|
#if HAS_X2_MIN
|
445
|
440
|
UPDATE_ENDSTOP_BIT(X2, MIN);
|
446
|
441
|
#else
|
447
|
|
- COPY_BIT(live_state, X_MIN, X2_MIN);
|
|
442
|
+ COPY_LIVE_STATE(X_MIN, X2_MIN);
|
448
|
443
|
#endif
|
449
|
444
|
#else
|
450
|
445
|
if (X_MIN_TEST) UPDATE_ENDSTOP_BIT(X, MIN);
|
|
@@ -458,7 +453,7 @@ void Endstops::update() {
|
458
|
453
|
#if HAS_X2_MAX
|
459
|
454
|
UPDATE_ENDSTOP_BIT(X2, MAX);
|
460
|
455
|
#else
|
461
|
|
- COPY_BIT(live_state, X_MAX, X2_MAX);
|
|
456
|
+ COPY_LIVE_STATE(X_MAX, X2_MAX);
|
462
|
457
|
#endif
|
463
|
458
|
#else
|
464
|
459
|
if (X_MAX_TEST) UPDATE_ENDSTOP_BIT(X, MAX);
|
|
@@ -475,7 +470,7 @@ void Endstops::update() {
|
475
|
470
|
#if HAS_Y2_MIN
|
476
|
471
|
UPDATE_ENDSTOP_BIT(Y2, MIN);
|
477
|
472
|
#else
|
478
|
|
- COPY_BIT(live_state, Y_MIN, Y2_MIN);
|
|
473
|
+ COPY_LIVE_STATE(Y_MIN, Y2_MIN);
|
479
|
474
|
#endif
|
480
|
475
|
#else
|
481
|
476
|
UPDATE_ENDSTOP_BIT(Y, MIN);
|
|
@@ -489,7 +484,7 @@ void Endstops::update() {
|
489
|
484
|
#if HAS_Y2_MAX
|
490
|
485
|
UPDATE_ENDSTOP_BIT(Y2, MAX);
|
491
|
486
|
#else
|
492
|
|
- COPY_BIT(live_state, Y_MAX, Y2_MAX);
|
|
487
|
+ COPY_LIVE_STATE(Y_MAX, Y2_MAX);
|
493
|
488
|
#endif
|
494
|
489
|
#else
|
495
|
490
|
UPDATE_ENDSTOP_BIT(Y, MAX);
|
|
@@ -506,7 +501,7 @@ void Endstops::update() {
|
506
|
501
|
#if HAS_Z2_MIN
|
507
|
502
|
UPDATE_ENDSTOP_BIT(Z2, MIN);
|
508
|
503
|
#else
|
509
|
|
- COPY_BIT(live_state, Z_MIN, Z2_MIN);
|
|
504
|
+ COPY_LIVE_STATE(Z_MIN, Z2_MIN);
|
510
|
505
|
#endif
|
511
|
506
|
#elif ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
|
512
|
507
|
if (z_probe_enabled) UPDATE_ENDSTOP_BIT(Z, MIN);
|
|
@@ -528,7 +523,7 @@ void Endstops::update() {
|
528
|
523
|
#if HAS_Z2_MAX
|
529
|
524
|
UPDATE_ENDSTOP_BIT(Z2, MAX);
|
530
|
525
|
#else
|
531
|
|
- COPY_BIT(live_state, Z_MAX, Z2_MAX);
|
|
526
|
+ COPY_LIVE_STATE(Z_MAX, Z2_MAX);
|
532
|
527
|
#endif
|
533
|
528
|
#elif DISABLED(Z_MIN_PROBE_ENDSTOP) || Z_MAX_PIN != Z_MIN_PROBE_PIN
|
534
|
529
|
// If this pin isn't the bed probe it's the Z endstop
|
|
@@ -538,36 +533,31 @@ void Endstops::update() {
|
538
|
533
|
}
|
539
|
534
|
}
|
540
|
535
|
|
541
|
|
- // All endstops were updated.
|
542
|
536
|
#if ENABLED(ENDSTOP_NOISE_FILTER)
|
543
|
|
- if (old_live_state != live_state) { // We detected a change. Reinit the timeout
|
544
|
|
- /**
|
545
|
|
- * Filtering out noise on endstops requires a delayed decision. Let's assume, due to noise,
|
546
|
|
- * that 50% of endstop signal samples are good and 50% are bad (assuming normal distribution
|
547
|
|
- * of random noise). Then the first sample has a 50% chance to be good or bad. The 2nd sample
|
548
|
|
- * also has a 50% chance to be good or bad. The chances of 2 samples both being bad becomes
|
549
|
|
- * 50% of 50%, or 25%. That was the previous implementation of Marlin endstop handling. It
|
550
|
|
- * reduces chances of bad readings in half, at the cost of 1 extra sample period, but chances
|
551
|
|
- * still exist. The only way to reduce them further is to increase the number of samples.
|
552
|
|
- * To reduce the chance to 1% (1/128th) requires 7 samples (adding 7ms of delay).
|
553
|
|
- */
|
|
537
|
+ /**
|
|
538
|
+ * Filtering out noise on endstops requires a delayed decision. Let's assume, due to noise,
|
|
539
|
+ * that 50% of endstop signal samples are good and 50% are bad (assuming normal distribution
|
|
540
|
+ * of random noise). Then the first sample has a 50% chance to be good or bad. The 2nd sample
|
|
541
|
+ * also has a 50% chance to be good or bad. The chances of 2 samples both being bad becomes
|
|
542
|
+ * 50% of 50%, or 25%. That was the previous implementation of Marlin endstop handling. It
|
|
543
|
+ * reduces chances of bad readings in half, at the cost of 1 extra sample period, but chances
|
|
544
|
+ * still exist. The only way to reduce them further is to increase the number of samples.
|
|
545
|
+ * To reduce the chance to 1% (1/128th) requires 7 samples (adding 7ms of delay).
|
|
546
|
+ */
|
|
547
|
+ static esbits_t old_live_state;
|
|
548
|
+ if (old_live_state != live_state) {
|
554
|
549
|
endstop_poll_count = 7;
|
555
|
550
|
old_live_state = live_state;
|
556
|
551
|
}
|
557
|
552
|
else if (endstop_poll_count && !--endstop_poll_count)
|
558
|
553
|
validated_live_state = live_state;
|
559
|
554
|
|
560
|
|
- #else
|
561
|
|
-
|
562
|
|
- // Lets accept the new endstop values as valid - We assume hardware filtering of lines
|
563
|
|
- esbits_t validated_live_state = live_state;
|
|
555
|
+ if (!abort_enabled()) return;
|
564
|
556
|
|
565
|
557
|
#endif
|
566
|
558
|
|
567
|
|
- // Endstop readings are validated in validated_live_state
|
568
|
|
-
|
569
|
559
|
// Test the current status of an endstop
|
570
|
|
- #define TEST_ENDSTOP(ENDSTOP) (TEST(validated_live_state, ENDSTOP))
|
|
560
|
+ #define TEST_ENDSTOP(ENDSTOP) (TEST(state(), ENDSTOP))
|
571
|
561
|
|
572
|
562
|
// Record endstop was hit
|
573
|
563
|
#define _ENDSTOP_HIT(AXIS, MINMAX) SBI(hit_state, _ENDSTOP(AXIS, MINMAX))
|