Skip to content

Commit

Permalink
⚡️ Handle shared enable pins
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Sep 23, 2021
1 parent 35ad3b0 commit 402d136
Show file tree
Hide file tree
Showing 26 changed files with 517 additions and 246 deletions.
80 changes: 17 additions & 63 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@
#endif
#endif

#if ENABLED(EXTENSIBLE_UI)
#include "lcd/extui/ui_api.h"
#endif

#if HAS_ETHERNET
#include "feature/ethernet.h"
#endif
Expand Down Expand Up @@ -312,48 +308,6 @@ bool pin_is_protected(const pin_t pin) {

#pragma GCC diagnostic pop

void enable_e_steppers() {
#define _ENA_E(N) ENABLE_AXIS_E##N();
REPEAT(E_STEPPERS, _ENA_E)
}

void enable_all_steppers() {
TERN_(AUTO_POWER_CONTROL, powerManager.power_on());
ENABLE_AXIS_X();
ENABLE_AXIS_Y();
ENABLE_AXIS_Z();
ENABLE_AXIS_I(); // Marlin 6-axis support by DerAndere (https://github.com/DerAndere1/Marlin/wiki)
ENABLE_AXIS_J();
ENABLE_AXIS_K();
enable_e_steppers();

TERN_(EXTENSIBLE_UI, ExtUI::onSteppersEnabled());
}

void disable_e_steppers() {
#define _DIS_E(N) DISABLE_AXIS_E##N();
REPEAT(E_STEPPERS, _DIS_E)
}

void disable_e_stepper(const uint8_t e) {
#define _CASE_DIS_E(N) case N: DISABLE_AXIS_E##N(); break;
switch (e) {
REPEAT(E_STEPPERS, _CASE_DIS_E)
}
}

void disable_all_steppers() {
DISABLE_AXIS_X();
DISABLE_AXIS_Y();
DISABLE_AXIS_Z();
DISABLE_AXIS_I();
DISABLE_AXIS_J();
DISABLE_AXIS_K();
disable_e_steppers();

TERN_(EXTENSIBLE_UI, ExtUI::onSteppersDisabled());
}

/**
* A Print Job exists when the timer is running or SD is printing
*/
Expand Down Expand Up @@ -464,13 +418,13 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
already_shutdown_steppers = true; // L6470 SPI will consume 99% of free time without this

// Individual axes will be disabled if configured
if (ENABLED(DISABLE_INACTIVE_X)) DISABLE_AXIS_X();
if (ENABLED(DISABLE_INACTIVE_Y)) DISABLE_AXIS_Y();
if (ENABLED(DISABLE_INACTIVE_Z)) DISABLE_AXIS_Z();
if (ENABLED(DISABLE_INACTIVE_I)) DISABLE_AXIS_I();
if (ENABLED(DISABLE_INACTIVE_J)) DISABLE_AXIS_J();
if (ENABLED(DISABLE_INACTIVE_K)) DISABLE_AXIS_K();
if (ENABLED(DISABLE_INACTIVE_E)) disable_e_steppers();
TERN_(DISABLE_INACTIVE_X, stepper.disable_axis(X_AXIS));
TERN_(DISABLE_INACTIVE_Y, stepper.disable_axis(Y_AXIS));
TERN_(DISABLE_INACTIVE_Z, stepper.disable_axis(Z_AXIS));
TERN_(DISABLE_INACTIVE_I, stepper.disable_axis(I_AXIS));
TERN_(DISABLE_INACTIVE_J, stepper.disable_axis(J_AXIS));
TERN_(DISABLE_INACTIVE_K, stepper.disable_axis(K_AXIS));
TERN_(DISABLE_INACTIVE_E, stepper.disable_e_steppers());

TERN_(AUTO_BED_LEVELING_UBL, ubl.steppers_were_disabled());
}
Expand Down Expand Up @@ -689,13 +643,13 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
#if ENABLED(SWITCHING_EXTRUDER)
bool oldstatus;
switch (active_extruder) {
default: oldstatus = E0_ENABLE_READ(); ENABLE_AXIS_E0(); break;
default: oldstatus = stepper.AXIS_IS_ENABLED(E_AXIS, 0); stepper.ENABLE_EXTRUDER(0); break;
#if E_STEPPERS > 1
case 2: case 3: oldstatus = E1_ENABLE_READ(); ENABLE_AXIS_E1(); break;
case 2: case 3: oldstatus = stepper.AXIS_IS_ENABLED(E_AXIS, 1); stepper.ENABLE_EXTRUDER(1); break;
#if E_STEPPERS > 2
case 4: case 5: oldstatus = E2_ENABLE_READ(); ENABLE_AXIS_E2(); break;
case 4: case 5: oldstatus = stepper.AXIS_IS_ENABLED(E_AXIS, 2); stepper.ENABLE_EXTRUDER(2); break;
#if E_STEPPERS > 3
case 6: case 7: oldstatus = E3_ENABLE_READ(); ENABLE_AXIS_E3(); break;
case 6: case 7: oldstatus = stepper.AXIS_IS_ENABLED(E_AXIS, 3); stepper.ENABLE_EXTRUDER(3); break;
#endif // E_STEPPERS > 3
#endif // E_STEPPERS > 2
#endif // E_STEPPERS > 1
Expand All @@ -704,7 +658,7 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
bool oldstatus;
switch (active_extruder) {
default:
#define _CASE_EN(N) case N: oldstatus = E##N##_ENABLE_READ(); ENABLE_AXIS_E##N(); break;
#define _CASE_EN(N) case N: oldstatus = stepper.AXIS_IS_ENABLED(E_AXIS, N); stepper.ENABLE_EXTRUDER(N); break;
REPEAT(E_STEPPERS, _CASE_EN);
}
#endif
Expand All @@ -718,17 +672,17 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {

#if ENABLED(SWITCHING_EXTRUDER)
switch (active_extruder) {
default: oldstatus = E0_ENABLE_WRITE(oldstatus); break;
default: if (oldstatus) stepper.ENABLE_EXTRUDER(0); else stepper.DISABLE_EXTRUDER(0); break;
#if E_STEPPERS > 1
case 2: case 3: oldstatus = E1_ENABLE_WRITE(oldstatus); break;
case 2: case 3: if (oldstatus) stepper.ENABLE_EXTRUDER(1); else stepper.DISABLE_EXTRUDER(1); break;
#if E_STEPPERS > 2
case 4: case 5: oldstatus = E2_ENABLE_WRITE(oldstatus); break;
case 4: case 5: if (oldstatus) stepper.ENABLE_EXTRUDER(2); else stepper.DISABLE_EXTRUDER(2); break;
#endif // E_STEPPERS > 2
#endif // E_STEPPERS > 1
}
#else // !SWITCHING_EXTRUDER
switch (active_extruder) {
#define _CASE_RESTORE(N) case N: E##N##_ENABLE_WRITE(oldstatus); break;
#define _CASE_RESTORE(N) case N: if (oldstatus) stepper.ENABLE_EXTRUDER(N); else stepper.DISABLE_EXTRUDER(N); break;
REPEAT(E_STEPPERS, _CASE_RESTORE);
}
#endif // !SWITCHING_EXTRUDER
Expand Down Expand Up @@ -940,7 +894,7 @@ void minkill(const bool steppers_off/*=false*/) {
TERN_(HAS_CUTTER, cutter.kill()); // Reiterate cutter shutdown

// Power off all steppers (for M112) or just the E steppers
steppers_off ? disable_all_steppers() : disable_e_steppers();
steppers_off ? stepper.disable_all_steppers() : stepper.disable_e_steppers();

TERN_(PSU_CONTROL, powerManager.power_off());

Expand Down
9 changes: 0 additions & 9 deletions Marlin/src/MarlinCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ inline void idle_no_sleep() { idle(true); }
extern bool G38_did_trigger; // Flag from the ISR to indicate the endstop changed
#endif

/**
* The axis order in all axis related arrays is X, Y, Z, E
*/
void enable_e_steppers();
void enable_all_steppers();
void disable_e_stepper(const uint8_t e);
void disable_e_steppers();
void disable_all_steppers();

void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
void minkill(const bool steppers_off=false);

Expand Down
27 changes: 3 additions & 24 deletions Marlin/src/feature/controllerfan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#if ENABLED(USE_CONTROLLER_FAN)

#include "controllerfan.h"
#include "../module/stepper/indirection.h"
#include "../module/stepper.h"
#include "../module/temperature.h"

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

#define MOTOR_IS_ON(A,B) (A##_ENABLE_READ() == bool(B##_ENABLE_ON))
#define _OR_ENABLED_E(N) || MOTOR_IS_ON(E##N,E)

const bool motor_on = (
( DISABLED(CONTROLLER_FAN_IGNORE_Z) &&
( MOTOR_IS_ON(Z,Z)
|| TERN0(HAS_Z2_ENABLE, MOTOR_IS_ON(Z2,Z))
|| TERN0(HAS_Z3_ENABLE, MOTOR_IS_ON(Z3,Z))
|| TERN0(HAS_Z4_ENABLE, MOTOR_IS_ON(Z4,Z))
)
) || (
DISABLED(CONTROLLER_FAN_USE_Z_ONLY) &&
( MOTOR_IS_ON(X,X) || MOTOR_IS_ON(Y,Y)
|| TERN0(HAS_X2_ENABLE, MOTOR_IS_ON(X2,X))
|| TERN0(HAS_Y2_ENABLE, MOTOR_IS_ON(Y2,Y))
#if E_STEPPERS
REPEAT(E_STEPPERS, _OR_ENABLED_E)
#endif
)
)
);

// If any triggers for the controller fan are true...
// - At least one stepper driver is enabled
// - The heated bed is enabled
// - TEMP_SENSOR_BOARD is reporting >= CONTROLLER_FAN_MIN_BOARD_TEMP
if ( motor_on
const ena_mask_t axis_mask = TERN(CONTROLLER_FAN_USE_Z_ONLY, _BV(Z_AXIS), ~TERN0(CONTROLLER_FAN_IGNORE_Z, _BV(Z_AXIS)));
if ( (stepper.axis_enabled.bits & axis_mask)
|| TERN0(HAS_HEATED_BED, thermalManager.temp_bed.soft_pwm_amount > 0)
|| TERN0(HAS_CONTROLLER_FAN_MIN_BOARD_TEMP, thermalManager.wholeDegBoard() >= CONTROLLER_FAN_MIN_BOARD_TEMP)
) lastMotorOn = ms; //... set time to NOW so the fan will turn on
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/fwretract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void FWRetract::reset() {

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

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/fwretract.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class FWRetract {
#endif
}

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

static void M207_report();
static void M207();
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/feature/mmu/mmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "../MarlinCore.h"
#include "../module/planner.h"
#include "../module/stepper.h"

void mmu_init() {
SET_OUTPUT(E_MUX0_PIN);
Expand All @@ -35,7 +36,7 @@ void mmu_init() {

void select_multiplexed_stepper(const uint8_t e) {
planner.synchronize();
disable_e_steppers();
stepper.disable_e_steppers();
WRITE(E_MUX0_PIN, TEST(e, 0) ? HIGH : LOW);
WRITE(E_MUX1_PIN, TEST(e, 1) ? HIGH : LOW);
WRITE(E_MUX2_PIN, TEST(e, 2) ? HIGH : LOW);
Expand Down
36 changes: 18 additions & 18 deletions Marlin/src/feature/mmu/mmu2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ MMU2 mmu2;
#include "../../libs/nozzle.h"
#include "../../module/temperature.h"
#include "../../module/planner.h"
#include "../../module/stepper/indirection.h"
#include "../../module/stepper.h"
#include "../../MarlinCore.h"

#if ENABLED(HOST_PROMPT_SUPPORT)
Expand Down Expand Up @@ -486,7 +486,7 @@ static void mmu2_not_responding() {

if (index != extruder) {

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

command(MMU_CMD_T0 + index);
Expand All @@ -495,7 +495,7 @@ static void mmu2_not_responding() {
if (load_to_gears()) {
extruder = index; // filament change is finished
active_extruder = 0;
ENABLE_AXIS_E0();
stepper.enable_extruder();
SERIAL_ECHO_MSG(STR_ACTIVE_EXTRUDER, extruder);
}
ui.reset_status();
Expand Down Expand Up @@ -531,13 +531,13 @@ static void mmu2_not_responding() {
#if ENABLED(MMU2_MENUS)
planner.synchronize();
const uint8_t index = mmu2_choose_filament();
DISABLE_AXIS_E0();
stepper.disable_extruder();
command(MMU_CMD_T0 + index);
manage_response(true, true);

if (load_to_gears()) {
mmu_loop();
ENABLE_AXIS_E0();
stepper.enable_extruder();
extruder = index;
active_extruder = 0;
}
Expand Down Expand Up @@ -566,7 +566,7 @@ static void mmu2_not_responding() {
set_runout_valid(false);

if (index != extruder) {
DISABLE_AXIS_E0();
stepper.disable_extruder();
if (FILAMENT_PRESENT()) {
DEBUG_ECHOLNPGM("Unloading\n");
mmu_loading_flag = false;
Expand All @@ -582,7 +582,7 @@ static void mmu2_not_responding() {
extruder = index;
active_extruder = 0;

ENABLE_AXIS_E0();
stepper.enable_extruder();
SERIAL_ECHO_MSG(STR_ACTIVE_EXTRUDER, extruder);

ui.reset_status();
Expand Down Expand Up @@ -620,14 +620,14 @@ static void mmu2_not_responding() {
#if ENABLED(MMU2_MENUS)
planner.synchronize();
uint8_t index = mmu2_choose_filament();
DISABLE_AXIS_E0();
stepper.disable_extruder();
command(MMU_CMD_T0 + index);
manage_response(true, true);
mmu_continue_loading();
command(MMU_CMD_C0);
mmu_loop();

ENABLE_AXIS_E0();
stepper.enable_extruder();
extruder = index;
active_extruder = 0;
#else
Expand Down Expand Up @@ -670,14 +670,14 @@ static void mmu2_not_responding() {
set_runout_valid(false);

if (index != extruder) {
DISABLE_AXIS_E0();
stepper.disable_extruder();
ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(index + 1));
command(MMU_CMD_T0 + index);
manage_response(true, true);
command(MMU_CMD_C0);
extruder = index; //filament change is finished
active_extruder = 0;
ENABLE_AXIS_E0();
stepper.enable_extruder();
SERIAL_ECHO_MSG(STR_ACTIVE_EXTRUDER, extruder);
ui.reset_status();
}
Expand Down Expand Up @@ -714,13 +714,13 @@ static void mmu2_not_responding() {
#if ENABLED(MMU2_MENUS)
planner.synchronize();
uint8_t index = mmu2_choose_filament();
DISABLE_AXIS_E0();
stepper.disable_extruder();
command(MMU_CMD_T0 + index);
manage_response(true, true);
command(MMU_CMD_C0);
mmu_loop();

ENABLE_AXIS_E0();
stepper.enable_extruder();
extruder = index;
active_extruder = 0;
#else
Expand Down Expand Up @@ -912,7 +912,7 @@ bool MMU2::load_filament_to_nozzle(const uint8_t index) {
return false;
}

DISABLE_AXIS_E0();
stepper.disable_extruder();
command(MMU_CMD_T0 + index);
manage_response(true, true);

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

LCD_MESSAGEPGM(MSG_MMU2_EJECTING_FILAMENT);

ENABLE_AXIS_E0();
stepper.enable_extruder();
current_position.e -= MMU2_FILAMENTCHANGE_EJECT_FEED;
line_to_current_position(MMM_TO_MMS(2500));
planner.synchronize();
Expand Down Expand Up @@ -979,7 +979,7 @@ bool MMU2::eject_filament(const uint8_t index, const bool recover) {

BUZZ(200, 404);

DISABLE_AXIS_E0();
stepper.disable_extruder();

return true;
}
Expand Down Expand Up @@ -1016,7 +1016,7 @@ bool MMU2::unload() {
void MMU2::execute_extruder_sequence(const E_Step * sequence, int steps) {

planner.synchronize();
ENABLE_AXIS_E0();
stepper.enable_extruder();

const E_Step* step = sequence;

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

DISABLE_AXIS_E0();
stepper.disable_extruder();
}

#endif // HAS_PRUSA_MMU2
Loading

0 comments on commit 402d136

Please sign in to comment.