Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instant Freeze/Resume Function #17462

Merged
merged 10 commits into from
May 14, 2021
10 changes: 10 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3781,6 +3781,16 @@
#define GANTRY_CALIBRATION_COMMANDS_POST "G28" // G28 highly recommended to ensure an accurate position
#endif

/**
* Instant freeze / unfreeze functionality
* Specified pin has pullup and connecting to ground will instantly pause motion.
* Potentially useful for emergency stop that allows being resumed.
*/
//#define FREEZE_FEATURE
#if ENABLED(FREEZE_FEATURE)
//#define FREEZE_PIN 41 // Override the default (KILL) pin here
#endif

/**
* MAX7219 Debug Matrix
*
Expand Down
8 changes: 8 additions & 0 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,10 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) {
}
#endif

#if HAS_FREEZE_PIN
Stepper::frozen = !READ(FREEZE_PIN);
#endif

#if HAS_HOME
// Handle a standalone HOME button
constexpr millis_t HOME_DEBOUNCE_DELAY = 1000UL;
Expand Down Expand Up @@ -1089,6 +1093,10 @@ void setup() {
#endif
#endif

#if HAS_FREEZE_PIN
SET_INPUT_PULLUP(FREEZE_PIN);
#endif

#if HAS_SUICIDE
SETUP_LOG("SUICIDE_PIN");
OUT_WRITE(SUICIDE_PIN, !SUICIDE_PIN_INVERTING);
Expand Down
16 changes: 13 additions & 3 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2318,12 +2318,22 @@
#endif

// User Interface
#if PIN_EXISTS(HOME)
#define HAS_HOME 1
#if ENABLED(FREEZE_FEATURE)
#if !PIN_EXISTS(FREEZE) && PIN_EXISTS(KILL)
#define FREEZE_PIN KILL_PIN
#endif
#if PIN_EXISTS(FREEZE)
#define HAS_FREEZE_PIN 1
#endif
#else
#undef FREEZE_PIN
#endif
#if PIN_EXISTS(KILL)
#if PIN_EXISTS(KILL) && TERN1(FREEZE_FEATURE, KILL_PIN != FREEZE_PIN)
#define HAS_KILL 1
#endif
#if PIN_EXISTS(HOME)
#define HAS_HOME 1
#endif
#if PIN_EXISTS(SUICIDE)
#define HAS_SUICIDE 1
#endif
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -3307,3 +3307,7 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2)

// Misc. Cleanup
#undef _TEST_PWM

#if ENABLED(FREEZE_FEATURE) && !PIN_EXISTS(FREEZE)
#error "FREEZE_FEATURE requires a FREEZE_PIN to be defined."
#endif
7 changes: 7 additions & 0 deletions Marlin/src/module/stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ bool Stepper::abort_current_block;
uint32_t Stepper::acceleration_time, Stepper::deceleration_time;
uint8_t Stepper::steps_per_isr;

#if HAS_FREEZE_PIN
bool Stepper::frozen; // = false
#endif

IF_DISABLED(ADAPTIVE_STEP_SMOOTHING, constexpr) uint8_t Stepper::oversampling_factor;

xyze_long_t Stepper::delta_error{0};
Expand Down Expand Up @@ -1531,6 +1535,9 @@ void Stepper::pulse_phase_isr() {
// If there is no current block, do nothing
if (!current_block) return;

// Skipping step processing causes motion to freeze
if (TERN0(HAS_FREEZE_PIN, frozen)) return;

// Count of pending loops and events for this iteration
const uint32_t pending_events = step_event_count - step_events_completed;
uint8_t events_to_do = _MIN(pending_events, steps_per_isr);
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/module/stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ class Stepper {
static constexpr uint8_t last_moved_extruder = 0;
#endif

#if HAS_FREEZE_PIN
static bool frozen; // Set this flag to instantly freeze motion
#endif

private:

static block_t* current_block; // A pointer to the block currently being traced
Expand Down
5 changes: 4 additions & 1 deletion Marlin/src/pins/pinsDebug_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,12 @@
#if PIN_EXISTS(I2C_SDA)
REPORT_NAME_DIGITAL(__LINE__, I2C_SDA_PIN)
#endif
#if PIN_EXISTS(KILL)
#if HAS_KILL
REPORT_NAME_DIGITAL(__LINE__, KILL_PIN)
#endif
#if HAS_FREEZE_PIN
REPORT_NAME_DIGITAL(__LINE__, FREEZE_PIN)
#endif
#if PIN_EXISTS(LCD_BACKLIGHT)
REPORT_NAME_DIGITAL(__LINE__, LCD_BACKLIGHT_PIN)
#endif
Expand Down
2 changes: 1 addition & 1 deletion buildroot/tests/mega2560
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ opt_set MOTHERBOARD BOARD_AZTEEG_X3_PRO LCD_LANGUAGE fr \
opt_enable AUTO_BED_LEVELING_UBL RESTORE_LEVELING_AFTER_G28 DEBUG_LEVELING_FEATURE G26_MESH_VALIDATION ENABLE_LEVELING_FADE_HEIGHT SKEW_CORRECTION \
REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER LIGHTWEIGHT_UI STATUS_MESSAGE_SCROLLING SHOW_CUSTOM_BOOTSCREEN BOOT_MARLIN_LOGO_SMALL \
SDSUPPORT SDCARD_SORT_ALPHA USB_FLASH_DRIVE_SUPPORT AUTO_REPORT_SD_STATUS SCROLL_LONG_FILENAMES CANCEL_OBJECTS SOUND_MENU_ITEM \
EEPROM_SETTINGS EEPROM_CHITCHAT GCODE_MACROS CUSTOM_MENU_MAIN \
EEPROM_SETTINGS EEPROM_CHITCHAT GCODE_MACROS CUSTOM_MENU_MAIN FREEZE_FEATURE \
MULTI_NOZZLE_DUPLICATION CLASSIC_JERK LIN_ADVANCE EXTRA_LIN_ADVANCE_K QUICK_HOME \
LCD_SET_PROGRESS_MANUALLY PRINT_PROGRESS_SHOW_DECIMALS SHOW_REMAINING_TIME \
BABYSTEPPING BABYSTEP_XY NANODLP_Z_SYNC I2C_POSITION_ENCODERS M114_DETAIL
Expand Down