Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/bugfix-2.0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
marciot committed Apr 3, 2020
2 parents 8bca254 + df8b7df commit 4dc3501
Show file tree
Hide file tree
Showing 50 changed files with 1,059 additions and 474 deletions.
122 changes: 107 additions & 15 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2662,31 +2662,123 @@
#define SPINDLE_LASER_ACTIVE_HIGH false // Set to "true" if the on/off function is active HIGH
#define SPINDLE_LASER_PWM true // Set to "true" if your controller supports setting the speed/power
#define SPINDLE_LASER_PWM_INVERT true // Set to "true" if the speed/power goes up when you want it to go slower
#define SPINDLE_LASER_POWERUP_DELAY 5000 // (ms) Delay to allow the spindle/laser to come up to speed/power
#define SPINDLE_LASER_POWERDOWN_DELAY 5000 // (ms) Delay to allow the spindle to stop

#define SPINDLE_LASER_FREQUENCY 2500 // (Hz) Spindle/laser frequency (only on supported HALs: AVR and LPC)

/**
* Speed / Power can be set ('M3 S') and displayed in terms of:
* - PWM (S0 - S255)
* - PERCENT (S0 - S100)
* - RPM (S0 - S50000) Best for use with a spindle
*/
#define CUTTER_POWER_DISPLAY PWM

/**
* Relative mode uses relative range (SPEED_POWER_MIN to SPEED_POWER_MAX) instead of normal range (0 to SPEED_POWER_MAX)
* Best use with SuperPID router controller where for example S0 = 5,000 RPM and S255 = 30,000 RPM
*/
//#define CUTTER_POWER_RELATIVE // Set speed proportional to [SPEED_POWER_MIN...SPEED_POWER_MAX] instead of directly

#if ENABLED(SPINDLE_FEATURE)
//#define SPINDLE_CHANGE_DIR // Enable if your spindle controller can change spindle direction
#define SPINDLE_CHANGE_DIR_STOP // Enable if the spindle should stop before changing spin direction
#define SPINDLE_INVERT_DIR false // Set to "true" if the spin direction is reversed

#define SPINDLE_LASER_POWERUP_DELAY 5000 // (ms) Delay to allow the spindle/laser to come up to speed/power
#define SPINDLE_LASER_POWERDOWN_DELAY 5000 // (ms) Delay to allow the spindle to stop

/**
* The M3 & M4 commands use the following equation to convert PWM duty cycle to speed/power
* M3/M4 uses the following equation to convert speed/power to PWM duty cycle
* Power = ((DC / 255 * 100) - SPEED_POWER_INTERCEPT)) * (1 / SPEED_POWER_SLOPE)
* where PWM DC varies from 0 to 255
*
* SPEED/POWER = PWM duty cycle * SPEED_POWER_SLOPE + SPEED_POWER_INTERCEPT
* where PWM duty cycle varies from 0 to 255
*
* set the following for your controller (ALL MUST BE SET)
* Set these required parameters for your controller
*/
#define SPEED_POWER_SLOPE 118.4
#define SPEED_POWER_INTERCEPT 0
#define SPEED_POWER_MIN 5000
#define SPEED_POWER_MAX 30000 // SuperPID router controller 0 - 30,000 RPM
#define SPEED_POWER_SLOPE 118.4 // SPEED_POWER_SLOPE = SPEED_POWER_MAX / 255
#define SPEED_POWER_INTERCEPT 0
#define SPEED_POWER_MIN 5000
#define SPEED_POWER_MAX 30000 // SuperPID router controller 0 - 30,000 RPM
#define SPEED_POWER_STARTUP 25000 // The default value for speed power when M3 is called without arguments

#else
#define SPEED_POWER_SLOPE 0.3922
#define SPEED_POWER_INTERCEPT 0
#define SPEED_POWER_MIN 10
#define SPEED_POWER_MAX 100 // 0-100%

#define SPEED_POWER_SLOPE 0.3922 // SPEED_POWER_SLOPE = SPEED_POWER_MAX / 255
#define SPEED_POWER_INTERCEPT 0
#define SPEED_POWER_MIN 0
#define SPEED_POWER_MAX 100 // 0-100%
#define SPEED_POWER_STARTUP 80 // The default value for speed power when M3 is called without arguments

/**
* Enable inline laser power to be handled in the planner / stepper routines.
* Inline power is specified by the I (inline) flag in an M3 command (e.g., M3 S20 I)
* or by the 'S' parameter in G0/G1/G2/G3 moves (see LASER_MOVE_POWER).
*
* This allows the laser to keep in perfect sync with the planner and removes
* the powerup/down delay since lasers require negligible time.
*/
#define LASER_POWER_INLINE

#if ENABLED(LASER_POWER_INLINE)
/**
* Scale the laser's power in proportion to the movement rate.
*
* - Sets the entry power proportional to the entry speed over the nominal speed.
* - Ramps the power up every N steps to approximate the speed trapezoid.
* - Due to the limited power resolution this is only approximate.
*/
#define LASER_POWER_INLINE_TRAPEZOID
/**
* Continuously calculate the current power (nominal_power * current_rate / nominal_rate).
* Required for accurate power with non-trapezoidal acceleration (e.g., S_CURVE_ACCELERATION).
* This is a costly calculation so this option is discouraged on 8-bit AVR boards.
*
* LASER_POWER_INLINE_TRAPEZOID_CONT_PER defines how many step cycles there are between power updates. If your
* board isn't able to generate steps fast enough (and you are using LASER_POWER_INLINE_TRAPEZOID_CONT), increase this.
* Note that when this is zero it means it occurs every cycle; 1 means a delay wait one cycle then run, etc.
*/
//#define LASER_POWER_INLINE_TRAPEZOID_CONT
/**
* Stepper iterations between power updates. Increase this value if the board
* can't keep up with the processing demands of LASER_POWER_INLINE_TRAPEZOID_CONT.
* Disable (or set to 0) to recalculate power on every stepper iteration.
*/
//#define LASER_POWER_INLINE_TRAPEZOID_CONT_PER 10
/**
* Include laser power in G0/G1/G2/G3/G5 commands with the 'S' parameter
*/
//#define LASER_MOVE_POWER

#if ENABLED(LASER_MOVE_POWER)
// Turn off the laser on G0 moves with no power parameter.
// If a power parameter is provided, use that instead.
//#define LASER_MOVE_G0_OFF
#endif

/**
* Inline flag inverted
*
* WARNING: M5 will NOT turn off the laser unless another move
* is done (so G-code files must end with 'M5 I').
*/
//#define LASER_POWER_INLINE_INVERT

/**
* Continuously apply inline power. ('M3 S3' == 'G1 S3' == 'M3 S3 I')
*
* The laser might do some weird things, so only enable this
* feature if you understand the implications.
*/
//#define LASER_POWER_INLINE_CONTINUOUS

#else

#define SPINDLE_LASER_POWERUP_DELAY 50 // (ms) Delay to allow the spindle/laser to come up to speed/power
#define SPINDLE_LASER_POWERDOWN_DELAY 50 // (ms) Delay to allow the spindle to stop

#endif
#endif
#endif

Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/HAL/AVR/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ inline void HAL_adc_init() {
// AVR compatibility
#define strtof strtod

#define HAL_CAN_SET_PWM_FREQ // This HAL supports PWM Frequency adjustment

/**
* set_pwm_frequency
* Sets the frequency of the timer corresponding to the provided pin
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/AVR/fast_pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include "../../inc/MarlinConfigPre.h"

#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_PWM
#if NEEDS_HARDWARE_PWM // Specific meta-flag for features that mandate PWM

#include "HAL.h"

Expand Down Expand Up @@ -278,5 +278,5 @@ void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255
}
}

#endif // FAST_PWM_FAN || SPINDLE_LASER_PWM
#endif // NEEDS_HARDWARE_PWM
#endif // __AVR__
6 changes: 3 additions & 3 deletions Marlin/src/HAL/ESP32/eeprom_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

#include "../../inc/MarlinConfig.h"

#if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION)
#if USE_WIRED_EEPROM

#include "../shared/eeprom_api.h"
#include "EEPROM.h"
#include <EEPROM.h>

#define EEPROM_SIZE 4096

Expand Down Expand Up @@ -59,5 +59,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t

size_t PersistentStore::capacity() { return EEPROM_SIZE; }

#endif // EEPROM_SETTINGS
#endif // USE_WIRED_EEPROM
#endif // ARDUINO_ARCH_ESP32
6 changes: 3 additions & 3 deletions Marlin/src/HAL/ESP32/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
#pragma once

// If no real EEPROM, Flash emulation, or SRAM emulation is available fall back to SD emulation
#if ENABLED(EEPROM_SETTINGS) && NONE(USE_WIRED_EEPROM, FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION)
#define SDCARD_EEPROM_EMULATION
#undef USE_WIRED_EEPROM
#if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION)
#define USE_WIRED_EEPROM 1
#endif
2 changes: 2 additions & 0 deletions Marlin/src/HAL/LPC1768/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ void HAL_idletask();
#define PLATFORM_M997_SUPPORT
void flashFirmware(const int16_t);

#define HAL_CAN_SET_PWM_FREQ // This HAL supports PWM Frequency adjustment

/**
* set_pwm_frequency
* Set the frequency of the timer corresponding to the provided pin
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/LPC1768/fast_pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include "../../inc/MarlinConfigPre.h"

#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_PWM
#if NEEDS_HARDWARE_PWM // Specific meta-flag for features that mandate PWM

#include <pwm.h>

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/SAMD51/QSPIFlash.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#pragma once

#include "Adafruit_SPIFlashBase.h"
#include <Adafruit_SPIFlashBase.h>

// This class extends Adafruit_SPIFlashBase by adding caching support.
//
Expand Down
60 changes: 37 additions & 23 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,8 @@ bool wait_for_heatup = true;
KEEPALIVE_STATE(PAUSED_FOR_USER);
wait_for_user = true;
if (ms) ms += millis(); // expire time
while (wait_for_user && !(ms && ELAPSED(millis(), ms))) {
idle(
#if ENABLED(ADVANCED_PAUSE_FEATURE)
no_sleep
#endif
);
}
while (wait_for_user && !(ms && ELAPSED(millis(), ms)))
idle(TERN_(ADVANCED_PAUSE_FEATURE, no_sleep));
wait_for_user = false;
}

Expand Down Expand Up @@ -425,7 +420,11 @@ void startOrResumeJob() {
#if DISABLED(SD_ABORT_NO_COOLDOWN)
thermalManager.disable_all_heaters();
#endif
thermalManager.zero_fan_speeds();
#if !HAS_CUTTER
thermalManager.zero_fan_speeds();
#else
cutter.kill(); // Full cutter shutdown including ISR control
#endif
wait_for_heatup = false;
#if ENABLED(POWER_LOSS_RECOVERY)
recovery.purge();
Expand Down Expand Up @@ -647,52 +646,54 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) {
/**
* Standard idle routine keeps the machine alive
*/
void idle(
#if ENABLED(ADVANCED_PAUSE_FEATURE)
bool no_stepper_sleep/*=false*/
#endif
) {
void idle(TERN_(ADVANCED_PAUSE_FEATURE, bool no_stepper_sleep/*=false*/)) {
// Handle Power-Loss Recovery
#if ENABLED(POWER_LOSS_RECOVERY) && PIN_EXISTS(POWER_LOSS)
recovery.outage();
#endif

// Run StallGuard endstop checks
#if ENABLED(SPI_ENDSTOPS)
if (endstops.tmc_spi_homing.any
#if ENABLED(IMPROVE_HOMING_RELIABILITY)
&& ELAPSED(millis(), sg_guard_period)
#endif
) {
for (uint8_t i = 4; i--;) // Read SGT 4 times per idle loop
&& TERN1(IMPROVE_HOMING_RELIABILITY, ELAPSED(millis(), sg_guard_period))
) LOOP_L_N(i, 4) // Read SGT 4 times per idle loop
if (endstops.tmc_spi_homing_check()) break;
}
#endif

// Max7219 heartbeat, animation, etc.
#if ENABLED(MAX7219_DEBUG)
max7219.idle_tasks();
#endif

// Read Buttons and Update the LCD
ui.update();

// Announce Host Keepalive state (if any)
#if ENABLED(HOST_KEEPALIVE_FEATURE)
gcode.host_keepalive();
#endif

// Core Marlin activities
manage_inactivity(
#if ENABLED(ADVANCED_PAUSE_FEATURE)
no_stepper_sleep
#endif
);

// Manage heaters (and Watchdog)
thermalManager.manage_heater();

// Update the Print Job Timer state
#if ENABLED(PRINTCOUNTER)
print_job_timer.tick();
#endif

// Update the Beeper queue
#if USE_BEEPER
buzzer.tick();
#endif

// Run i2c Position Encoders
#if ENABLED(I2C_POSITION_ENCODERS)
static millis_t i2cpem_next_update_ms;
if (planner.has_blocks_queued()) {
Expand All @@ -704,10 +705,12 @@ void idle(
}
#endif

// Run HAL idle tasks
#ifdef HAL_IDLETASK
HAL_idletask();
#endif

// Auto-report Temperatures / SD Status
#if HAS_AUTO_REPORTING
if (!gcode.autoreport_paused) {
#if ENABLED(AUTO_REPORT_TEMPERATURES)
Expand All @@ -719,14 +722,17 @@ void idle(
}
#endif

// Handle USB Flash Drive insert / remove
#if ENABLED(USB_FLASH_DRIVE_SUPPORT)
Sd2Card::idle();
#endif

// Update the Prusa MMU2
#if ENABLED(PRUSA_MMU2)
mmu2.mmu_loop();
#endif

// Handle Joystick jogging
#if ENABLED(POLL_JOG)
joystick.inject_jog_moves();
#endif
Expand All @@ -739,6 +745,10 @@ void idle(
void kill(PGM_P const lcd_error/*=nullptr*/, PGM_P const lcd_component/*=nullptr*/, const bool steppers_off/*=false*/) {
thermalManager.disable_all_heaters();

#if HAS_CUTTER
cutter.kill(); // Full cutter shutdown including ISR control
#endif

SERIAL_ERROR_MSG(STR_ERR_KILLED);

#if HAS_DISPLAY
Expand Down Expand Up @@ -768,6 +778,10 @@ void minkill(const bool steppers_off/*=false*/) {
// Reiterate heaters off
thermalManager.disable_all_heaters();

#if HAS_CUTTER
cutter.kill(); // Reiterate cutter shutdown
#endif

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

Expand All @@ -787,14 +801,14 @@ void minkill(const bool steppers_off/*=false*/) {
// Wait for kill to be pressed
while (READ(KILL_PIN)) watchdog_refresh();

void (*resetFunc)() = 0; // Declare resetFunc() at address 0
void (*resetFunc)() = 0; // Declare resetFunc() at address 0
resetFunc(); // Jump to address 0

#else // !HAS_KILL
#else

for (;;) watchdog_refresh(); // Wait for reset
for (;;) watchdog_refresh(); // Wait for reset

#endif // !HAS_KILL
#endif
}

/**
Expand Down
Loading

0 comments on commit 4dc3501

Please sign in to comment.