|
@@ -76,6 +76,13 @@ volatile long endstops_trigsteps[3] = { 0 };
|
76
|
76
|
volatile long endstops_stepsTotal, endstops_stepsDone;
|
77
|
77
|
static volatile char endstop_hit_bits = 0; // use X_MIN, Y_MIN, Z_MIN and Z_PROBE as BIT value
|
78
|
78
|
|
|
79
|
+#ifndef Z_DUAL_ENDSTOPS
|
|
80
|
+ static byte
|
|
81
|
+#else
|
|
82
|
+ static uint16_t
|
|
83
|
+#endif
|
|
84
|
+ old_endstop_bits = 0; // use X_MIN, X_MAX... Z_MAX, Z_PROBE, Z2_MIN, Z2_MAX
|
|
85
|
+
|
79
|
86
|
#ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
|
80
|
87
|
bool abort_on_endstop_hit = false;
|
81
|
88
|
#endif
|
|
@@ -84,31 +91,6 @@ static volatile char endstop_hit_bits = 0; // use X_MIN, Y_MIN, Z_MIN and Z_PROB
|
84
|
91
|
int motor_current_setting[3] = DEFAULT_PWM_MOTOR_CURRENT;
|
85
|
92
|
#endif
|
86
|
93
|
|
87
|
|
-#if HAS_X_MIN
|
88
|
|
- static bool old_x_min_endstop = false;
|
89
|
|
-#endif
|
90
|
|
-#if HAS_X_MAX
|
91
|
|
- static bool old_x_max_endstop = false;
|
92
|
|
-#endif
|
93
|
|
-#if HAS_Y_MIN
|
94
|
|
- static bool old_y_min_endstop = false;
|
95
|
|
-#endif
|
96
|
|
-#if HAS_Y_MAX
|
97
|
|
- static bool old_y_max_endstop = false;
|
98
|
|
-#endif
|
99
|
|
-
|
100
|
|
-static bool old_z_min_endstop = false;
|
101
|
|
-static bool old_z_max_endstop = false;
|
102
|
|
-
|
103
|
|
-#ifdef Z_DUAL_ENDSTOPS
|
104
|
|
- static bool old_z2_min_endstop = false;
|
105
|
|
- static bool old_z2_max_endstop = false;
|
106
|
|
-#endif
|
107
|
|
-
|
108
|
|
-#ifdef Z_PROBE_ENDSTOP // No need to check for valid pin, SanityCheck.h already does this.
|
109
|
|
- static bool old_z_probe_endstop = false;
|
110
|
|
-#endif
|
111
|
|
-
|
112
|
94
|
static bool check_endstops = true;
|
113
|
95
|
|
114
|
96
|
volatile long count_position[NUM_AXIS] = { 0 };
|
|
@@ -155,11 +137,11 @@ volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
|
155
|
137
|
#define Z_APPLY_STEP(v,Q) \
|
156
|
138
|
if (performing_homing) { \
|
157
|
139
|
if (Z_HOME_DIR > 0) {\
|
158
|
|
- if (!(old_z_max_endstop && (count_direction[Z_AXIS] > 0)) && !locked_z_motor) Z_STEP_WRITE(v); \
|
159
|
|
- if (!(old_z2_max_endstop && (count_direction[Z_AXIS] > 0)) && !locked_z2_motor) Z2_STEP_WRITE(v); \
|
|
140
|
+ if (!(TEST(old_endstop_bits, Z_MAX) && (count_direction[Z_AXIS] > 0)) && !locked_z_motor) Z_STEP_WRITE(v); \
|
|
141
|
+ if (!(TEST(old_endstop_bits, Z2_MAX) && (count_direction[Z_AXIS] > 0)) && !locked_z2_motor) Z2_STEP_WRITE(v); \
|
160
|
142
|
} else {\
|
161
|
|
- if (!(old_z_min_endstop && (count_direction[Z_AXIS] < 0)) && !locked_z_motor) Z_STEP_WRITE(v); \
|
162
|
|
- if (!(old_z2_min_endstop && (count_direction[Z_AXIS] < 0)) && !locked_z2_motor) Z2_STEP_WRITE(v); \
|
|
143
|
+ if (!(TEST(old_endstop_bits, Z_MIN) && (count_direction[Z_AXIS] < 0)) && !locked_z_motor) Z_STEP_WRITE(v); \
|
|
144
|
+ if (!(TEST(old_endstop_bits, Z2_MIN) && (count_direction[Z_AXIS] < 0)) && !locked_z2_motor) Z2_STEP_WRITE(v); \
|
163
|
145
|
} \
|
164
|
146
|
} else { \
|
165
|
147
|
Z_STEP_WRITE(v); \
|
|
@@ -266,7 +248,7 @@ void endstops_hit_on_purpose() {
|
266
|
248
|
}
|
267
|
249
|
|
268
|
250
|
void checkHitEndstops() {
|
269
|
|
- if (endstop_hit_bits) { // #ifdef || endstop_z_probe_hit to save space if needed.
|
|
251
|
+ if (endstop_hit_bits) {
|
270
|
252
|
SERIAL_ECHO_START;
|
271
|
253
|
SERIAL_ECHOPGM(MSG_ENDSTOPS_HIT);
|
272
|
254
|
if (endstop_hit_bits & BIT(X_MIN)) {
|
|
@@ -447,7 +429,7 @@ FORCE_INLINE void trapezoid_generator_reset() {
|
447
|
429
|
// It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
|
448
|
430
|
ISR(TIMER1_COMPA_vect) {
|
449
|
431
|
|
450
|
|
- if(cleaning_buffer_counter)
|
|
432
|
+ if (cleaning_buffer_counter)
|
451
|
433
|
{
|
452
|
434
|
current_block = NULL;
|
453
|
435
|
plan_discard_current_block();
|
|
@@ -492,22 +474,33 @@ ISR(TIMER1_COMPA_vect) {
|
492
|
474
|
// Check endstops
|
493
|
475
|
if (check_endstops) {
|
494
|
476
|
|
495
|
|
- #define _ENDSTOP(axis, minmax) axis ##_## minmax ##_endstop
|
|
477
|
+ #ifdef Z_DUAL_ENDSTOPS
|
|
478
|
+ uint16_t
|
|
479
|
+ #else
|
|
480
|
+ byte
|
|
481
|
+ #endif
|
|
482
|
+ current_endstop_bits;
|
|
483
|
+
|
496
|
484
|
#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
|
497
|
485
|
#define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
|
498
|
|
- #define _OLD_ENDSTOP(axis, minmax) old_## axis ##_## minmax ##_endstop
|
499
|
486
|
#define _AXIS(AXIS) AXIS ##_AXIS
|
500
|
|
- #define _HIT_BIT(AXIS) AXIS ##_MIN
|
501
|
|
- #define _ENDSTOP_HIT(AXIS) endstop_hit_bits |= BIT(_HIT_BIT(AXIS))
|
502
|
|
-
|
503
|
|
- #define UPDATE_ENDSTOP(axis,AXIS,minmax,MINMAX) \
|
504
|
|
- bool _ENDSTOP(axis, minmax) = (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)); \
|
505
|
|
- if (_ENDSTOP(axis, minmax) && _OLD_ENDSTOP(axis, minmax) && (current_block->steps[_AXIS(AXIS)] > 0)) { \
|
|
487
|
+ #define _ENDSTOP_HIT(AXIS) endstop_hit_bits |= BIT(_ENDSTOP(AXIS, MIN))
|
|
488
|
+ #define _ENDSTOP(AXIS, MINMAX) AXIS ##_## MINMAX
|
|
489
|
+
|
|
490
|
+ // SET_ENDSTOP_BIT: set the current endstop bits for an endstop to its status
|
|
491
|
+ #define SET_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT(current_endstop_bits, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
|
|
492
|
+ // COPY_BIT: copy the value of COPY_BIT to BIT in bits
|
|
493
|
+ #define COPY_BIT(bits, COPY_BIT, BIT) SET_BIT(bits, BIT, TEST(bits, COPY_BIT))
|
|
494
|
+ // TEST_ENDSTOP: test the old and the current status of an endstop
|
|
495
|
+ #define TEST_ENDSTOP(ENDSTOP) (TEST(current_endstop_bits, ENDSTOP) && TEST(old_endstop_bits, ENDSTOP))
|
|
496
|
+
|
|
497
|
+ #define UPDATE_ENDSTOP(AXIS,MINMAX) \
|
|
498
|
+ SET_ENDSTOP_BIT(AXIS, MINMAX); \
|
|
499
|
+ if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX)) && (current_block->steps[_AXIS(AXIS)] > 0)) { \
|
506
|
500
|
endstops_trigsteps[_AXIS(AXIS)] = count_position[_AXIS(AXIS)]; \
|
507
|
501
|
_ENDSTOP_HIT(AXIS); \
|
508
|
502
|
step_events_completed = current_block->step_event_count; \
|
509
|
|
- } \
|
510
|
|
- _OLD_ENDSTOP(axis, minmax) = _ENDSTOP(axis, minmax);
|
|
503
|
+ }
|
511
|
504
|
|
512
|
505
|
#ifdef COREXY
|
513
|
506
|
// Head direction in -X axis for CoreXY bots.
|
|
@@ -524,7 +517,7 @@ ISR(TIMER1_COMPA_vect) {
|
524
|
517
|
#endif
|
525
|
518
|
{
|
526
|
519
|
#if HAS_X_MIN
|
527
|
|
- UPDATE_ENDSTOP(x, X, min, MIN);
|
|
520
|
+ UPDATE_ENDSTOP(X, MIN);
|
528
|
521
|
#endif
|
529
|
522
|
}
|
530
|
523
|
}
|
|
@@ -535,7 +528,7 @@ ISR(TIMER1_COMPA_vect) {
|
535
|
528
|
#endif
|
536
|
529
|
{
|
537
|
530
|
#if HAS_X_MAX
|
538
|
|
- UPDATE_ENDSTOP(x, X, max, MAX);
|
|
531
|
+ UPDATE_ENDSTOP(X, MAX);
|
539
|
532
|
#endif
|
540
|
533
|
}
|
541
|
534
|
}
|
|
@@ -550,12 +543,12 @@ ISR(TIMER1_COMPA_vect) {
|
550
|
543
|
#endif
|
551
|
544
|
{ // -direction
|
552
|
545
|
#if HAS_Y_MIN
|
553
|
|
- UPDATE_ENDSTOP(y, Y, min, MIN);
|
|
546
|
+ UPDATE_ENDSTOP(Y, MIN);
|
554
|
547
|
#endif
|
555
|
548
|
}
|
556
|
549
|
else { // +direction
|
557
|
550
|
#if HAS_Y_MAX
|
558
|
|
- UPDATE_ENDSTOP(y, Y, max, MAX);
|
|
551
|
+ UPDATE_ENDSTOP(Y, MAX);
|
559
|
552
|
#endif
|
560
|
553
|
}
|
561
|
554
|
#ifdef COREXY
|
|
@@ -565,45 +558,36 @@ ISR(TIMER1_COMPA_vect) {
|
565
|
558
|
#if HAS_Z_MIN
|
566
|
559
|
|
567
|
560
|
#ifdef Z_DUAL_ENDSTOPS
|
|
561
|
+ SET_ENDSTOP_BIT(Z, MIN);
|
|
562
|
+ #if HAS_Z2_MIN
|
|
563
|
+ SET_ENDSTOP_BIT(Z2, MIN);
|
|
564
|
+ #else
|
|
565
|
+ COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN)
|
|
566
|
+ #endif
|
|
567
|
+
|
|
568
|
+ byte z_test = TEST_ENDSTOP(Z_MIN) << 0 + TEST_ENDSTOP(Z2_MIN) << 1; // bit 0 for Z, bit 1 for Z2
|
568
|
569
|
|
569
|
|
- bool z_min_endstop = READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING,
|
570
|
|
- z2_min_endstop =
|
571
|
|
- #if HAS_Z2_MIN
|
572
|
|
- READ(Z2_MIN_PIN) != Z2_MIN_ENDSTOP_INVERTING
|
573
|
|
- #else
|
574
|
|
- z_min_endstop
|
575
|
|
- #endif
|
576
|
|
- ;
|
577
|
|
-
|
578
|
|
- bool z_min_both = z_min_endstop && old_z_min_endstop,
|
579
|
|
- z2_min_both = z2_min_endstop && old_z2_min_endstop;
|
580
|
|
- if ((z_min_both || z2_min_both) && current_block->steps[Z_AXIS] > 0) {
|
|
570
|
+ if (z_test && current_block->steps[Z_AXIS] > 0) { // z_test = Z_MIN || Z2_MIN
|
581
|
571
|
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
582
|
572
|
endstop_hit_bits |= BIT(Z_MIN);
|
583
|
|
- if (!performing_homing || (performing_homing && z_min_both && z2_min_both)) //if not performing home or if both endstops were trigged during homing...
|
584
|
|
- step_events_completed = current_block->step_event_count;
|
|
573
|
+ if (!performing_homing || (performing_homing && !((~z_test) & 0x3))) //if not performing home or if both endstops were trigged during homing...
|
|
574
|
+ step_events_completed = current_block->step_event_count; //!((~z_test) & 0x3) = Z_MIN && Z2_MIN
|
585
|
575
|
}
|
586
|
|
- old_z_min_endstop = z_min_endstop;
|
587
|
|
- old_z2_min_endstop = z2_min_endstop;
|
588
|
|
-
|
589
|
576
|
#else // !Z_DUAL_ENDSTOPS
|
590
|
577
|
|
591
|
|
- UPDATE_ENDSTOP(z, Z, min, MIN);
|
592
|
|
-
|
|
578
|
+ UPDATE_ENDSTOP(Z, MIN);
|
593
|
579
|
#endif // !Z_DUAL_ENDSTOPS
|
594
|
|
-
|
595
|
580
|
#endif // Z_MIN_PIN
|
596
|
581
|
|
597
|
582
|
#ifdef Z_PROBE_ENDSTOP
|
598
|
|
- UPDATE_ENDSTOP(z, Z, probe, PROBE);
|
599
|
|
- z_probe_endstop=(READ(Z_PROBE_PIN) != Z_PROBE_ENDSTOP_INVERTING);
|
600
|
|
- if(z_probe_endstop && old_z_probe_endstop)
|
|
583
|
+ UPDATE_ENDSTOP(Z, PROBE);
|
|
584
|
+ SET_ENDSTOP_BIT(Z, PROBE);
|
|
585
|
+
|
|
586
|
+ if (TEST_ENDSTOP(Z_PROBE))
|
601
|
587
|
{
|
602
|
588
|
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
603
|
589
|
endstop_hit_bits |= BIT(Z_PROBE);
|
604
|
|
- // if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
|
605
|
590
|
}
|
606
|
|
- old_z_probe_endstop = z_probe_endstop;
|
607
|
591
|
#endif
|
608
|
592
|
}
|
609
|
593
|
else { // z +direction
|
|
@@ -611,55 +595,43 @@ ISR(TIMER1_COMPA_vect) {
|
611
|
595
|
|
612
|
596
|
#ifdef Z_DUAL_ENDSTOPS
|
613
|
597
|
|
614
|
|
- bool z_max_endstop = READ(Z_MAX_PIN) != Z_MAX_ENDSTOP_INVERTING,
|
615
|
|
- z2_max_endstop =
|
616
|
|
- #if HAS_Z2_MAX
|
617
|
|
- READ(Z2_MAX_PIN) != Z2_MAX_ENDSTOP_INVERTING
|
618
|
|
- #else
|
619
|
|
- z_max_endstop
|
620
|
|
- #endif
|
621
|
|
- ;
|
622
|
|
-
|
623
|
|
- bool z_max_both = z_max_endstop && old_z_max_endstop,
|
624
|
|
- z2_max_both = z2_max_endstop && old_z2_max_endstop;
|
625
|
|
- if ((z_max_both || z2_max_both) && current_block->steps[Z_AXIS] > 0) {
|
626
|
|
- endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
627
|
|
- endstop_hit_bits |= BIT(Z_MIN);
|
|
598
|
+ SET_ENDSTOP_BIT(Z, MAX);
|
|
599
|
+ #if HAS_Z2_MAX
|
|
600
|
+ SET_ENDSTOP_BIT(Z2, MAX);
|
|
601
|
+ #else
|
|
602
|
+ COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX)
|
|
603
|
+ #endif
|
628
|
604
|
|
629
|
|
- // if (z_max_both) SERIAL_ECHOLN("z_max_endstop = true");
|
630
|
|
- // if (z2_max_both) SERIAL_ECHOLN("z2_max_endstop = true");
|
|
605
|
+ byte z_test = TEST_ENDSTOP(Z_MAX) << 0 + TEST_ENDSTOP(Z2_MAX) << 1; // bit 0 for Z, bit 1 for Z2
|
631
|
606
|
|
632
|
|
- if (!performing_homing || (performing_homing && z_max_both && z2_max_both)) //if not performing home or if both endstops were trigged during homing...
|
633
|
|
- step_events_completed = current_block->step_event_count;
|
|
607
|
+ if (z_test && current_block->steps[Z_AXIS] > 0) { // t_test = Z_MAX || Z2_MAX
|
|
608
|
+ endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
|
609
|
+ endstop_hit_bits |= BIT(Z_MIN);
|
|
610
|
+ if (!performing_homing || (performing_homing && !((~z_test) & 0x3))) //if not performing home or if both endstops were trigged during homing...
|
|
611
|
+ step_events_completed = current_block->step_event_count; //!((~z_test) & 0x3) = Z_MAX && Z2_MAX
|
634
|
612
|
}
|
635
|
|
- old_z_max_endstop = z_max_endstop;
|
636
|
|
- old_z2_max_endstop = z2_max_endstop;
|
637
|
613
|
|
638
|
614
|
#else // !Z_DUAL_ENDSTOPS
|
639
|
615
|
|
640
|
|
- UPDATE_ENDSTOP(z, Z, max, MAX);
|
|
616
|
+ UPDATE_ENDSTOP(Z, MAX);
|
641
|
617
|
|
642
|
618
|
#endif // !Z_DUAL_ENDSTOPS
|
643
|
|
-
|
644
|
619
|
#endif // Z_MAX_PIN
|
645
|
620
|
|
646
|
621
|
#ifdef Z_PROBE_ENDSTOP
|
647
|
|
- UPDATE_ENDSTOP(z, Z, probe, PROBE);
|
648
|
|
- z_probe_endstop=(READ(Z_PROBE_PIN) != Z_PROBE_ENDSTOP_INVERTING);
|
649
|
|
- if(z_probe_endstop && old_z_probe_endstop)
|
|
622
|
+ UPDATE_ENDSTOP(Z, PROBE);
|
|
623
|
+ SET_ENDSTOP_BIT(Z, PROBE);
|
|
624
|
+ if (TEST_ENDSTOP(Z_PROBE))
|
650
|
625
|
{
|
651
|
626
|
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
652
|
627
|
endstop_hit_bits |= BIT(Z_PROBE);
|
653
|
|
-// if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
|
654
|
628
|
}
|
655
|
|
- old_z_probe_endstop = z_probe_endstop;
|
656
|
629
|
#endif
|
657
|
630
|
}
|
658
|
|
-
|
|
631
|
+ old_endstop_bits = current_endstop_bits;
|
659
|
632
|
}
|
660
|
633
|
|
661
|
634
|
|
662
|
|
-
|
663
|
635
|
// Take multiple steps per interrupt (For high speed moves)
|
664
|
636
|
for (int8_t i = 0; i < step_loops; i++) {
|
665
|
637
|
#ifndef AT90USB
|