Skip to content

Commit 9dca099

Browse files
thinkyheadmh-dm
authored andcommitted
⚡️ Handle shared enable pins (MarlinFirmware#22824)
1 parent 328c568 commit 9dca099

File tree

26 files changed

+517
-246
lines changed

26 files changed

+517
-246
lines changed

Marlin/src/MarlinCore.cpp

Lines changed: 17 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@
8181
#endif
8282
#endif
8383

84-
#if ENABLED(EXTENSIBLE_UI)
85-
#include "lcd/extui/ui_api.h"
86-
#endif
87-
8884
#if HAS_ETHERNET
8985
#include "feature/ethernet.h"
9086
#endif
@@ -312,48 +308,6 @@ bool pin_is_protected(const pin_t pin) {
312308

313309
#pragma GCC diagnostic pop
314310

315-
void enable_e_steppers() {
316-
#define _ENA_E(N) ENABLE_AXIS_E##N();
317-
REPEAT(E_STEPPERS, _ENA_E)
318-
}
319-
320-
void enable_all_steppers() {
321-
TERN_(AUTO_POWER_CONTROL, powerManager.power_on());
322-
ENABLE_AXIS_X();
323-
ENABLE_AXIS_Y();
324-
ENABLE_AXIS_Z();
325-
ENABLE_AXIS_I(); // Marlin 6-axis support by DerAndere (https://github.com/DerAndere1/Marlin/wiki)
326-
ENABLE_AXIS_J();
327-
ENABLE_AXIS_K();
328-
enable_e_steppers();
329-
330-
TERN_(EXTENSIBLE_UI, ExtUI::onSteppersEnabled());
331-
}
332-
333-
void disable_e_steppers() {
334-
#define _DIS_E(N) DISABLE_AXIS_E##N();
335-
REPEAT(E_STEPPERS, _DIS_E)
336-
}
337-
338-
void disable_e_stepper(const uint8_t e) {
339-
#define _CASE_DIS_E(N) case N: DISABLE_AXIS_E##N(); break;
340-
switch (e) {
341-
REPEAT(E_STEPPERS, _CASE_DIS_E)
342-
}
343-
}
344-
345-
void disable_all_steppers() {
346-
DISABLE_AXIS_X();
347-
DISABLE_AXIS_Y();
348-
DISABLE_AXIS_Z();
349-
DISABLE_AXIS_I();
350-
DISABLE_AXIS_J();
351-
DISABLE_AXIS_K();
352-
disable_e_steppers();
353-
354-
TERN_(EXTENSIBLE_UI, ExtUI::onSteppersDisabled());
355-
}
356-
357311
/**
358312
* A Print Job exists when the timer is running or SD is printing
359313
*/
@@ -464,13 +418,13 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
464418
already_shutdown_steppers = true; // L6470 SPI will consume 99% of free time without this
465419

466420
// Individual axes will be disabled if configured
467-
if (ENABLED(DISABLE_INACTIVE_X)) DISABLE_AXIS_X();
468-
if (ENABLED(DISABLE_INACTIVE_Y)) DISABLE_AXIS_Y();
469-
if (ENABLED(DISABLE_INACTIVE_Z)) DISABLE_AXIS_Z();
470-
if (ENABLED(DISABLE_INACTIVE_I)) DISABLE_AXIS_I();
471-
if (ENABLED(DISABLE_INACTIVE_J)) DISABLE_AXIS_J();
472-
if (ENABLED(DISABLE_INACTIVE_K)) DISABLE_AXIS_K();
473-
if (ENABLED(DISABLE_INACTIVE_E)) disable_e_steppers();
421+
TERN_(DISABLE_INACTIVE_X, stepper.disable_axis(X_AXIS));
422+
TERN_(DISABLE_INACTIVE_Y, stepper.disable_axis(Y_AXIS));
423+
TERN_(DISABLE_INACTIVE_Z, stepper.disable_axis(Z_AXIS));
424+
TERN_(DISABLE_INACTIVE_I, stepper.disable_axis(I_AXIS));
425+
TERN_(DISABLE_INACTIVE_J, stepper.disable_axis(J_AXIS));
426+
TERN_(DISABLE_INACTIVE_K, stepper.disable_axis(K_AXIS));
427+
TERN_(DISABLE_INACTIVE_E, stepper.disable_e_steppers());
474428

475429
TERN_(AUTO_BED_LEVELING_UBL, ubl.steppers_were_disabled());
476430
}
@@ -689,13 +643,13 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
689643
#if ENABLED(SWITCHING_EXTRUDER)
690644
bool oldstatus;
691645
switch (active_extruder) {
692-
default: oldstatus = E0_ENABLE_READ(); ENABLE_AXIS_E0(); break;
646+
default: oldstatus = stepper.AXIS_IS_ENABLED(E_AXIS, 0); stepper.ENABLE_EXTRUDER(0); break;
693647
#if E_STEPPERS > 1
694-
case 2: case 3: oldstatus = E1_ENABLE_READ(); ENABLE_AXIS_E1(); break;
648+
case 2: case 3: oldstatus = stepper.AXIS_IS_ENABLED(E_AXIS, 1); stepper.ENABLE_EXTRUDER(1); break;
695649
#if E_STEPPERS > 2
696-
case 4: case 5: oldstatus = E2_ENABLE_READ(); ENABLE_AXIS_E2(); break;
650+
case 4: case 5: oldstatus = stepper.AXIS_IS_ENABLED(E_AXIS, 2); stepper.ENABLE_EXTRUDER(2); break;
697651
#if E_STEPPERS > 3
698-
case 6: case 7: oldstatus = E3_ENABLE_READ(); ENABLE_AXIS_E3(); break;
652+
case 6: case 7: oldstatus = stepper.AXIS_IS_ENABLED(E_AXIS, 3); stepper.ENABLE_EXTRUDER(3); break;
699653
#endif // E_STEPPERS > 3
700654
#endif // E_STEPPERS > 2
701655
#endif // E_STEPPERS > 1
@@ -704,7 +658,7 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
704658
bool oldstatus;
705659
switch (active_extruder) {
706660
default:
707-
#define _CASE_EN(N) case N: oldstatus = E##N##_ENABLE_READ(); ENABLE_AXIS_E##N(); break;
661+
#define _CASE_EN(N) case N: oldstatus = stepper.AXIS_IS_ENABLED(E_AXIS, N); stepper.ENABLE_EXTRUDER(N); break;
708662
REPEAT(E_STEPPERS, _CASE_EN);
709663
}
710664
#endif
@@ -718,17 +672,17 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
718672

719673
#if ENABLED(SWITCHING_EXTRUDER)
720674
switch (active_extruder) {
721-
default: oldstatus = E0_ENABLE_WRITE(oldstatus); break;
675+
default: if (oldstatus) stepper.ENABLE_EXTRUDER(0); else stepper.DISABLE_EXTRUDER(0); break;
722676
#if E_STEPPERS > 1
723-
case 2: case 3: oldstatus = E1_ENABLE_WRITE(oldstatus); break;
677+
case 2: case 3: if (oldstatus) stepper.ENABLE_EXTRUDER(1); else stepper.DISABLE_EXTRUDER(1); break;
724678
#if E_STEPPERS > 2
725-
case 4: case 5: oldstatus = E2_ENABLE_WRITE(oldstatus); break;
679+
case 4: case 5: if (oldstatus) stepper.ENABLE_EXTRUDER(2); else stepper.DISABLE_EXTRUDER(2); break;
726680
#endif // E_STEPPERS > 2
727681
#endif // E_STEPPERS > 1
728682
}
729683
#else // !SWITCHING_EXTRUDER
730684
switch (active_extruder) {
731-
#define _CASE_RESTORE(N) case N: E##N##_ENABLE_WRITE(oldstatus); break;
685+
#define _CASE_RESTORE(N) case N: if (oldstatus) stepper.ENABLE_EXTRUDER(N); else stepper.DISABLE_EXTRUDER(N); break;
732686
REPEAT(E_STEPPERS, _CASE_RESTORE);
733687
}
734688
#endif // !SWITCHING_EXTRUDER
@@ -940,7 +894,7 @@ void minkill(const bool steppers_off/*=false*/) {
940894
TERN_(HAS_CUTTER, cutter.kill()); // Reiterate cutter shutdown
941895

942896
// Power off all steppers (for M112) or just the E steppers
943-
steppers_off ? disable_all_steppers() : disable_e_steppers();
897+
steppers_off ? stepper.disable_all_steppers() : stepper.disable_e_steppers();
944898

945899
TERN_(PSU_CONTROL, powerManager.power_off());
946900

Marlin/src/MarlinCore.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ inline void idle_no_sleep() { idle(true); }
3838
extern bool G38_did_trigger; // Flag from the ISR to indicate the endstop changed
3939
#endif
4040

41-
/**
42-
* The axis order in all axis related arrays is X, Y, Z, E
43-
*/
44-
void enable_e_steppers();
45-
void enable_all_steppers();
46-
void disable_e_stepper(const uint8_t e);
47-
void disable_e_steppers();
48-
void disable_all_steppers();
49-
5041
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
5142
void minkill(const bool steppers_off=false);
5243

Marlin/src/feature/controllerfan.cpp

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#if ENABLED(USE_CONTROLLER_FAN)
2626

2727
#include "controllerfan.h"
28-
#include "../module/stepper/indirection.h"
28+
#include "../module/stepper.h"
2929
#include "../module/temperature.h"
3030

3131
ControllerFan controllerFan;
@@ -54,33 +54,12 @@ void ControllerFan::update() {
5454
if (ELAPSED(ms, nextMotorCheck)) {
5555
nextMotorCheck = ms + 2500UL; // Not a time critical function, so only check every 2.5s
5656

57-
#define MOTOR_IS_ON(A,B) (A##_ENABLE_READ() == bool(B##_ENABLE_ON))
58-
#define _OR_ENABLED_E(N) || MOTOR_IS_ON(E##N,E)
59-
60-
const bool motor_on = (
61-
( DISABLED(CONTROLLER_FAN_IGNORE_Z) &&
62-
( MOTOR_IS_ON(Z,Z)
63-
|| TERN0(HAS_Z2_ENABLE, MOTOR_IS_ON(Z2,Z))
64-
|| TERN0(HAS_Z3_ENABLE, MOTOR_IS_ON(Z3,Z))
65-
|| TERN0(HAS_Z4_ENABLE, MOTOR_IS_ON(Z4,Z))
66-
)
67-
) || (
68-
DISABLED(CONTROLLER_FAN_USE_Z_ONLY) &&
69-
( MOTOR_IS_ON(X,X) || MOTOR_IS_ON(Y,Y)
70-
|| TERN0(HAS_X2_ENABLE, MOTOR_IS_ON(X2,X))
71-
|| TERN0(HAS_Y2_ENABLE, MOTOR_IS_ON(Y2,Y))
72-
#if E_STEPPERS
73-
REPEAT(E_STEPPERS, _OR_ENABLED_E)
74-
#endif
75-
)
76-
)
77-
);
78-
7957
// If any triggers for the controller fan are true...
8058
// - At least one stepper driver is enabled
8159
// - The heated bed is enabled
8260
// - TEMP_SENSOR_BOARD is reporting >= CONTROLLER_FAN_MIN_BOARD_TEMP
83-
if ( motor_on
61+
const ena_mask_t axis_mask = TERN(CONTROLLER_FAN_USE_Z_ONLY, _BV(Z_AXIS), ~TERN0(CONTROLLER_FAN_IGNORE_Z, _BV(Z_AXIS)));
62+
if ( (stepper.axis_enabled.bits & axis_mask)
8463
|| TERN0(HAS_HEATED_BED, thermalManager.temp_bed.soft_pwm_amount > 0)
8564
|| TERN0(HAS_CONTROLLER_FAN_MIN_BOARD_TEMP, thermalManager.wholeDegBoard() >= CONTROLLER_FAN_MIN_BOARD_TEMP)
8665
) lastMotorOn = ms; //... set time to NOW so the fan will turn on

Marlin/src/feature/fwretract.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void FWRetract::reset() {
7575

7676
LOOP_L_N(i, EXTRUDERS) {
7777
retracted[i] = false;
78-
TERN_(HAS_MULTI_EXTRUDER, retracted_swap[i] = false);
78+
E_TERN_(retracted_swap[i] = false);
7979
current_retract[i] = 0.0;
8080
}
8181
}
@@ -91,7 +91,7 @@ void FWRetract::reset() {
9191
* Note: Auto-retract will apply the set Z hop in addition to any Z hop
9292
* included in the G-code. Use M207 Z0 to to prevent double hop.
9393
*/
94-
void FWRetract::retract(const bool retracting OPTARG(HAS_MULTI_EXTRUDER, bool swapping/*=false*/)) {
94+
void FWRetract::retract(const bool retracting E_OPTARG(bool swapping/*=false*/)) {
9595
// Prevent two retracts or recovers in a row
9696
if (retracted[active_extruder] == retracting) return;
9797

Marlin/src/feature/fwretract.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class FWRetract {
7474
#endif
7575
}
7676

77-
static void retract(const bool retracting OPTARG(HAS_MULTI_EXTRUDER, bool swapping = false));
77+
static void retract(const bool retracting E_OPTARG(bool swapping=false));
7878

7979
static void M207_report();
8080
static void M207();

Marlin/src/feature/mmu/mmu.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "../MarlinCore.h"
2828
#include "../module/planner.h"
29+
#include "../module/stepper.h"
2930

3031
void mmu_init() {
3132
SET_OUTPUT(E_MUX0_PIN);
@@ -35,7 +36,7 @@ void mmu_init() {
3536

3637
void select_multiplexed_stepper(const uint8_t e) {
3738
planner.synchronize();
38-
disable_e_steppers();
39+
stepper.disable_e_steppers();
3940
WRITE(E_MUX0_PIN, TEST(e, 0) ? HIGH : LOW);
4041
WRITE(E_MUX1_PIN, TEST(e, 1) ? HIGH : LOW);
4142
WRITE(E_MUX2_PIN, TEST(e, 2) ? HIGH : LOW);

Marlin/src/feature/mmu/mmu2.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ MMU2 mmu2;
3535
#include "../../libs/nozzle.h"
3636
#include "../../module/temperature.h"
3737
#include "../../module/planner.h"
38-
#include "../../module/stepper/indirection.h"
38+
#include "../../module/stepper.h"
3939
#include "../../MarlinCore.h"
4040

4141
#if ENABLED(HOST_PROMPT_SUPPORT)
@@ -486,7 +486,7 @@ static void mmu2_not_responding() {
486486

487487
if (index != extruder) {
488488

489-
DISABLE_AXIS_E0();
489+
stepper.disable_extruder();
490490
ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(index + 1));
491491

492492
command(MMU_CMD_T0 + index);
@@ -495,7 +495,7 @@ static void mmu2_not_responding() {
495495
if (load_to_gears()) {
496496
extruder = index; // filament change is finished
497497
active_extruder = 0;
498-
ENABLE_AXIS_E0();
498+
stepper.enable_extruder();
499499
SERIAL_ECHO_MSG(STR_ACTIVE_EXTRUDER, extruder);
500500
}
501501
ui.reset_status();
@@ -531,13 +531,13 @@ static void mmu2_not_responding() {
531531
#if ENABLED(MMU2_MENUS)
532532
planner.synchronize();
533533
const uint8_t index = mmu2_choose_filament();
534-
DISABLE_AXIS_E0();
534+
stepper.disable_extruder();
535535
command(MMU_CMD_T0 + index);
536536
manage_response(true, true);
537537

538538
if (load_to_gears()) {
539539
mmu_loop();
540-
ENABLE_AXIS_E0();
540+
stepper.enable_extruder();
541541
extruder = index;
542542
active_extruder = 0;
543543
}
@@ -566,7 +566,7 @@ static void mmu2_not_responding() {
566566
set_runout_valid(false);
567567

568568
if (index != extruder) {
569-
DISABLE_AXIS_E0();
569+
stepper.disable_extruder();
570570
if (FILAMENT_PRESENT()) {
571571
DEBUG_ECHOLNPGM("Unloading\n");
572572
mmu_loading_flag = false;
@@ -582,7 +582,7 @@ static void mmu2_not_responding() {
582582
extruder = index;
583583
active_extruder = 0;
584584

585-
ENABLE_AXIS_E0();
585+
stepper.enable_extruder();
586586
SERIAL_ECHO_MSG(STR_ACTIVE_EXTRUDER, extruder);
587587

588588
ui.reset_status();
@@ -620,14 +620,14 @@ static void mmu2_not_responding() {
620620
#if ENABLED(MMU2_MENUS)
621621
planner.synchronize();
622622
uint8_t index = mmu2_choose_filament();
623-
DISABLE_AXIS_E0();
623+
stepper.disable_extruder();
624624
command(MMU_CMD_T0 + index);
625625
manage_response(true, true);
626626
mmu_continue_loading();
627627
command(MMU_CMD_C0);
628628
mmu_loop();
629629

630-
ENABLE_AXIS_E0();
630+
stepper.enable_extruder();
631631
extruder = index;
632632
active_extruder = 0;
633633
#else
@@ -670,14 +670,14 @@ static void mmu2_not_responding() {
670670
set_runout_valid(false);
671671

672672
if (index != extruder) {
673-
DISABLE_AXIS_E0();
673+
stepper.disable_extruder();
674674
ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(index + 1));
675675
command(MMU_CMD_T0 + index);
676676
manage_response(true, true);
677677
command(MMU_CMD_C0);
678678
extruder = index; //filament change is finished
679679
active_extruder = 0;
680-
ENABLE_AXIS_E0();
680+
stepper.enable_extruder();
681681
SERIAL_ECHO_MSG(STR_ACTIVE_EXTRUDER, extruder);
682682
ui.reset_status();
683683
}
@@ -714,13 +714,13 @@ static void mmu2_not_responding() {
714714
#if ENABLED(MMU2_MENUS)
715715
planner.synchronize();
716716
uint8_t index = mmu2_choose_filament();
717-
DISABLE_AXIS_E0();
717+
stepper.disable_extruder();
718718
command(MMU_CMD_T0 + index);
719719
manage_response(true, true);
720720
command(MMU_CMD_C0);
721721
mmu_loop();
722722

723-
ENABLE_AXIS_E0();
723+
stepper.enable_extruder();
724724
extruder = index;
725725
active_extruder = 0;
726726
#else
@@ -912,7 +912,7 @@ bool MMU2::load_filament_to_nozzle(const uint8_t index) {
912912
return false;
913913
}
914914

915-
DISABLE_AXIS_E0();
915+
stepper.disable_extruder();
916916
command(MMU_CMD_T0 + index);
917917
manage_response(true, true);
918918

@@ -950,7 +950,7 @@ bool MMU2::eject_filament(const uint8_t index, const bool recover) {
950950

951951
LCD_MESSAGEPGM(MSG_MMU2_EJECTING_FILAMENT);
952952

953-
ENABLE_AXIS_E0();
953+
stepper.enable_extruder();
954954
current_position.e -= MMU2_FILAMENTCHANGE_EJECT_FEED;
955955
line_to_current_position(MMM_TO_MMS(2500));
956956
planner.synchronize();
@@ -979,7 +979,7 @@ bool MMU2::eject_filament(const uint8_t index, const bool recover) {
979979

980980
BUZZ(200, 404);
981981

982-
DISABLE_AXIS_E0();
982+
stepper.disable_extruder();
983983

984984
return true;
985985
}
@@ -1016,7 +1016,7 @@ bool MMU2::unload() {
10161016
void MMU2::execute_extruder_sequence(const E_Step * sequence, int steps) {
10171017

10181018
planner.synchronize();
1019-
ENABLE_AXIS_E0();
1019+
stepper.enable_extruder();
10201020

10211021
const E_Step* step = sequence;
10221022

@@ -1034,7 +1034,7 @@ void MMU2::execute_extruder_sequence(const E_Step * sequence, int steps) {
10341034
step++;
10351035
}
10361036

1037-
DISABLE_AXIS_E0();
1037+
stepper.disable_extruder();
10381038
}
10391039

10401040
#endif // HAS_PRUSA_MMU2

0 commit comments

Comments
 (0)