From 902f816645824ccbbb36ca2ab471365256c3b5f3 Mon Sep 17 00:00:00 2001 From: Alexey Matveev Date: Mon, 6 Sep 2021 17:04:27 +0300 Subject: [PATCH 01/29] laser code refactor (FSM) --- Marlin/src/feature/spindle_laser.cpp | 156 ++++++++++++++++++++------- Marlin/src/feature/spindle_laser.h | 53 ++++++--- Marlin/src/gcode/control/M3-M5.cpp | 2 +- Marlin/src/module/stepper.cpp | 16 +-- 4 files changed, 162 insertions(+), 65 deletions(-) diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index 539fafeb3498..00b9150e5261 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -52,9 +52,9 @@ cutter_power_t SpindleLaser::menuPower, // Power s #endif #define SPINDLE_LASER_PWM_OFF TERN(SPINDLE_LASER_PWM_INVERT, 255, 0) -// -// Init the cutter to a safe OFF state -// +/** + * Init the cutter to a safe OFF state + */ void SpindleLaser::init() { #if ENABLED(SPINDLE_SERVO) MOVE_SERVO(SPINDLE_SERVO_NR, SPINDLE_SERVO_MIN); @@ -86,8 +86,10 @@ void SpindleLaser::init() { #if ENABLED(SPINDLE_LASER_PWM) /** * Set the cutter PWM directly to the given ocr value + * + * @param ocr Power value */ - void SpindleLaser::_set_ocr(const uint8_t ocr) { + void SpindleLaser::ocr_set(const uint8_t ocr) { #if NEEDS_HARDWARE_PWM && SPINDLE_LASER_FREQUENCY set_pwm_frequency(pin_t(SPINDLE_LASER_PWM_PIN), TERN(MARLIN_DEV_MODE, frequency, SPINDLE_LASER_FREQUENCY)); set_pwm_duty(pin_t(SPINDLE_LASER_PWM_PIN), ocr ^ SPINDLE_LASER_PWM_OFF); @@ -96,57 +98,131 @@ void SpindleLaser::init() { #endif } - void SpindleLaser::set_ocr(const uint8_t ocr) { - WRITE(SPINDLE_LASER_ENA_PIN, SPINDLE_LASER_ACTIVE_STATE); // Cutter ON - _set_ocr(ocr); - } - void SpindleLaser::ocr_off() { - WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ACTIVE_STATE); // Cutter OFF - _set_ocr(0); + ocr_set(0); } -#endif -// -// Set cutter ON/OFF state (and PWM) to the given cutter power value -// -void SpindleLaser::apply_power(const uint8_t opwr) { - static uint8_t last_power_applied = 0; - if (opwr == last_power_applied) return; - last_power_applied = opwr; - power = opwr; +#endif // SPINDLE_LASER_PWM + +// Set state for pin laser/spindle +// :param - enable True - on; False - off +void SpindleLaser::pin_set(const bool enable) { + WRITE(SPINDLE_LASER_ENA_PIN, enable ? SPINDLE_LASER_ACTIVE_STATE : !SPINDLE_LASER_ACTIVE_STATE); +} + +/** + * Detection event + * + * @param opwr Power value + */ +SPINDLE_LASER_EVENT SpindleLaser::get_event(const uint8_t opwr) { + SPINDLE_LASER_EVENT event; + + // Conditions #if ENABLED(SPINDLE_LASER_PWM) if (cutter.unitPower == 0 && CUTTER_UNIT_IS(RPM)) { - ocr_off(); - isReady = false; - } - else if (ENABLED(CUTTER_POWER_RELATIVE) || enabled()) { - set_ocr(power); - isReady = true; - } - else { - ocr_off(); - isReady = false; + if (power == 0) { + return SPINDLE_LASER_EVENT::OFF; + } else { + return SPINDLE_LASER_EVENT::TO_OFF; + } } - #elif ENABLED(SPINDLE_SERVO) - MOVE_SERVO(SPINDLE_SERVO_NR, power); - #else - WRITE(SPINDLE_LASER_ENA_PIN, enabled() ? SPINDLE_LASER_ACTIVE_STATE : !SPINDLE_LASER_ACTIVE_STATE); - isReady = true; #endif + + if ((power + opwr) == 0) { + event = SPINDLE_LASER_EVENT::OFF; + } else if ((power > 0) && (opwr > 0)){ + event = SPINDLE_LASER_EVENT::ON; + } else if (opwr == 0) { + event = SPINDLE_LASER_EVENT::TO_OFF; + } else { + event = SPINDLE_LASER_EVENT::TO_ON; + } + + return event; +} + +/** + * Apply power for laser/spindle + * + * Apply cutter power value for PWM, Servo, and on/off pin. + * + * @param opwr Power value. Range 0 to MAX. When 0 disable laser/spindel. + */ +void SpindleLaser::apply_power(const uint8_t opwr) { + static uint8_t last_power_applied = 0; + + switch (get_event(opwr)) { + case SPINDLE_LASER_EVENT::ON: + if (opwr == last_power_applied) break; + last_power_applied = opwr; + power = opwr; + + #if ENABLED(SPINDLE_LASER_PWM) + ocr_set(power); + isReady = true; + #endif + #if ENABLED(SPINDLE_SERVO) + MOVE_SERVO(SPINDLE_SERVO_NR, power); + #endif + #if DISABLED(SPINDLE_SERVO) + pin_set(true); + isReady = true; + #endif + + break; + case SPINDLE_LASER_EVENT::TO_ON: + last_power_applied = opwr; + power = opwr; + + #if ENABLED(SPINDLE_LASER_PWM) + ocr_set(power); + isReady = true; + #endif + #if ENABLED(SPINDLE_SERVO) + MOVE_SERVO(SPINDLE_SERVO_NR, power); + #endif + #if DISABLED(SPINDLE_SERVO) + pin_set(true); + isReady = true; + #endif + + power_delay(true); + break; + case SPINDLE_LASER_EVENT::OFF: + break; + case SPINDLE_LASER_EVENT::TO_OFF: + last_power_applied = opwr; + power = opwr; + + #if ENABLED(SPINDLE_LASER_PWM) + ocr_set(0); + isReady = false; + #endif + #if ENABLED(SPINDLE_SERVO) + MOVE_SERVO(SPINDLE_SERVO_NR, power); + #endif + #if DISABLED(SPINDLE_SERVO) + pin_set(false); + isReady = false; + #endif + + power_delay(false); + break; + } } #if ENABLED(SPINDLE_CHANGE_DIR) - // - // Set the spindle direction and apply immediately - // Stop on direction change if SPINDLE_STOP_ON_DIR_CHANGE is enabled - // + /** + * Set the spindle direction and apply immediately + * Stop on direction change if SPINDLE_STOP_ON_DIR_CHANGE is enabled + */ void SpindleLaser::set_reverse(const bool reverse) { const bool dir_state = (reverse == SPINDLE_INVERT_DIR); // Forward (M3) HIGH when not inverted if (TERN0(SPINDLE_STOP_ON_DIR_CHANGE, enabled()) && READ(SPINDLE_DIR_PIN) != dir_state) disable(); WRITE(SPINDLE_DIR_PIN, dir_state); } -#endif +#endif // SPINDLE_CHANGE_DIR #if ENABLED(AIR_EVACUATION) diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index da228cf8a706..cdfab27ed1f7 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -45,6 +45,10 @@ #define SPEED_POWER_INTERCEPT 0 #endif +// States - power == 0 off, power > 0 on +// TO - transit state (TO_ON - from any to on) +enum SPINDLE_LASER_EVENT {ON, OFF, TO_ON, TO_OFF}; + // #define _MAP(N,S1,S2,D1,D2) ((N)*_MAX((D2)-(D1),0)/_MAX((S2)-(S1),1)+(D1)) class SpindleLaser { @@ -109,6 +113,7 @@ class SpindleLaser { unitPower; // Power as displayed status in PWM, Percentage or RPM static void init(); + static SPINDLE_LASER_EVENT get_event(const uint8_t opwr); #if ENABLED(MARLIN_DEV_MODE) static inline void refresh_frequency() { set_pwm_frequency(pin_t(SPINDLE_LASER_PWM_PIN), frequency); } @@ -119,22 +124,20 @@ class SpindleLaser { static inline bool enabled() { return enabled(power); } static void apply_power(const uint8_t inpow); - + // Alias + FORCE_INLINE static void set_power(const uint8_t upwr) { apply_power(upwr); } FORCE_INLINE static void refresh() { apply_power(power); } - FORCE_INLINE static void set_power(const uint8_t upwr) { power = upwr; refresh(); } #if ENABLED(SPINDLE_LASER_PWM) - - private: - - static void _set_ocr(const uint8_t ocr); - public: - static void set_ocr(const uint8_t ocr); - static inline void set_ocr_power(const uint8_t ocr) { power = ocr; set_ocr(ocr); } + static inline void ocr_set_power(const uint8_t ocr) { apply_power(ocr); } + static void ocr_set(const uint8_t ocr); static void ocr_off(); - // Used to update output for power->OCR translation + + /** + * Used to update output for power->OCR translation + */ static inline uint8_t upower_to_ocr(const cutter_power_t upwr) { return ( #if CUTTER_UNIT_IS(PWM255) @@ -147,7 +150,9 @@ class SpindleLaser { ); } - // Correct power to configured range + /** + * Correct power to configured range + */ static inline cutter_power_t power_to_range(const cutter_power_t pwr) { return power_to_range(pwr, ( #if CUTTER_UNIT_IS(PWM255) @@ -161,6 +166,7 @@ class SpindleLaser { #endif )); } + static inline cutter_power_t power_to_range(const cutter_power_t pwr, const uint8_t pwrUnit) { if (pwr <= 0) return 0; cutter_power_t upwr; @@ -190,14 +196,31 @@ class SpindleLaser { } return upwr; } - #endif // SPINDLE_LASER_PWM + static void pin_set(const bool enable); + + /** + * Enable/Disabel spindle/laser + * @param enable True - enable; False - disable + */ static inline void set_enabled(const bool enable) { - set_power(enable ? TERN(SPINDLE_LASER_PWM, (power ?: (unitPower ? upower_to_ocr(cpwr_to_upwr(SPEED_POWER_STARTUP)) : 0)), 255) : 0); + uint8_t value = 0; + if (enable) { + value = TERN(SPINDLE_LASER_PWM, (power ?: (unitPower ? upower_to_ocr(cpwr_to_upwr(SPEED_POWER_STARTUP)) : 0)), 255); + } + apply_power(value); + } + + static inline void disable() { + isReady = false; set_enabled(false); } - // Wait for spindle to spin up or spin down + /** + * Wait for spindle to spin up or spin down + * + * @param on True - state to on; False - state to off. + */ static inline void power_delay(const bool on) { #if DISABLED(LASER_POWER_INLINE) safe_delay(on ? SPINDLE_LASER_POWERUP_DELAY : SPINDLE_LASER_POWERDOWN_DELAY); @@ -230,8 +253,6 @@ class SpindleLaser { } #endif - static inline void disable() { isReady = false; set_enabled(false); } - #if HAS_LCD_MENU static inline void enable_with_dir(const bool reverse) { isReady = true; diff --git a/Marlin/src/gcode/control/M3-M5.cpp b/Marlin/src/gcode/control/M3-M5.cpp index 711bb7e5e4a7..ff5ab5086e3b 100644 --- a/Marlin/src/gcode/control/M3-M5.cpp +++ b/Marlin/src/gcode/control/M3-M5.cpp @@ -108,7 +108,7 @@ void GcodeSuite::M3_M4(const bool is_M4) { #if ENABLED(SPINDLE_LASER_PWM) if (parser.seenval('O')) { cutter.unitPower = cutter.power_to_range(parser.value_byte(), 0); - cutter.set_ocr_power(cutter.unitPower); // The OCR is a value from 0 to 255 (uint8_t) + cutter.ocr_set_power(cutter.unitPower); // The OCR is a value from 0 to 255 (uint8_t) } else cutter.set_power(cutter.upower_to_ocr(get_s_power())); diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 50d8ad426072..f9245336f368 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -1914,7 +1914,7 @@ uint32_t Stepper::block_phase_isr() { laser_trap.acc_step_count += current_block->laser.entry_per; if (laser_trap.cur_power < current_block->laser.power) laser_trap.cur_power++; } - cutter.set_ocr_power(laser_trap.cur_power); + cutter.ocr_set_power(laser_trap.cur_power); } } #else @@ -1923,7 +1923,7 @@ uint32_t Stepper::block_phase_isr() { else { laser_trap.till_update = LASER_POWER_INLINE_TRAPEZOID_CONT_PER; laser_trap.cur_power = (current_block->laser.power * acc_step_rate) / current_block->nominal_rate; - cutter.set_ocr_power(laser_trap.cur_power); // Cycle efficiency is irrelevant it the last line was many cycles + cutter.ocr_set_power(laser_trap.cur_power); // Cycle efficiency is irrelevant it the last line was many cycles } #endif } @@ -1991,7 +1991,7 @@ uint32_t Stepper::block_phase_isr() { laser_trap.acc_step_count += current_block->laser.exit_per; if (laser_trap.cur_power > current_block->laser.power_exit) laser_trap.cur_power--; } - cutter.set_ocr_power(laser_trap.cur_power); + cutter.ocr_set_power(laser_trap.cur_power); } } #else @@ -2000,7 +2000,7 @@ uint32_t Stepper::block_phase_isr() { else { laser_trap.till_update = LASER_POWER_INLINE_TRAPEZOID_CONT_PER; laser_trap.cur_power = (current_block->laser.power * step_rate) / current_block->nominal_rate; - cutter.set_ocr_power(laser_trap.cur_power); // Cycle efficiency isn't relevant when the last line was many cycles + cutter.ocr_set_power(laser_trap.cur_power); // Cycle efficiency isn't relevant when the last line was many cycles } #endif } @@ -2028,7 +2028,7 @@ uint32_t Stepper::block_phase_isr() { if (laser_trap.enabled) { if (!laser_trap.cruise_set) { laser_trap.cur_power = current_block->laser.power; - cutter.set_ocr_power(laser_trap.cur_power); + cutter.ocr_set_power(laser_trap.cur_power); laser_trap.cruise_set = true; } #if ENABLED(LASER_POWER_INLINE_TRAPEZOID_CONT) @@ -2249,14 +2249,14 @@ uint32_t Stepper::block_phase_isr() { #endif // Always have PWM in this case if (stat.isPlanned) { // Planner controls the laser - cutter.set_ocr_power( + cutter.ocr_set_power( stat.isEnabled ? laser_trap.cur_power : 0 // ON with power or OFF ); } #else if (stat.isPlanned) { // Planner controls the laser #if ENABLED(SPINDLE_LASER_PWM) - cutter.set_ocr_power( + cutter.ocr_set_power( stat.isEnabled ? current_block->laser.power : 0 // ON with power or OFF ); #else @@ -2304,7 +2304,7 @@ uint32_t Stepper::block_phase_isr() { const power_status_t stat = planner.laser_inline.status; if (stat.isPlanned) { // Planner controls the laser #if ENABLED(SPINDLE_LASER_PWM) - cutter.set_ocr_power( + cutter.ocr_set_power( stat.isEnabled ? planner.laser_inline.power : 0 // ON with power or OFF ); #else From 5e50c6f16283eada1ad6b2cb6f053654597cced0 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 6 Sep 2021 14:40:02 -0500 Subject: [PATCH 02/29] cleanup --- Marlin/src/feature/spindle_laser.cpp | 109 +++++++++++---------------- Marlin/src/feature/spindle_laser.h | 24 +++--- 2 files changed, 53 insertions(+), 80 deletions(-) diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index 00b9150e5261..e97f8720ab5d 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -86,7 +86,7 @@ void SpindleLaser::init() { #if ENABLED(SPINDLE_LASER_PWM) /** * Set the cutter PWM directly to the given ocr value - * + * * @param ocr Power value */ void SpindleLaser::ocr_set(const uint8_t ocr) { @@ -98,113 +98,96 @@ void SpindleLaser::init() { #endif } - void SpindleLaser::ocr_off() { - ocr_set(0); - } + void SpindleLaser::ocr_off() { ocr_set(0); } -#endif // SPINDLE_LASER_PWM +#endif // SPINDLE_LASER_PWM -// Set state for pin laser/spindle -// :param - enable True - on; False - off -void SpindleLaser::pin_set(const bool enable) { +/** + * Set state for pin laser/spindle + * @param enable true = on; false = off + */ +void SpindleLaser::ena_pin_set(const bool enable) { WRITE(SPINDLE_LASER_ENA_PIN, enable ? SPINDLE_LASER_ACTIVE_STATE : !SPINDLE_LASER_ACTIVE_STATE); } /** * Detection event - * + * * @param opwr Power value */ -SPINDLE_LASER_EVENT SpindleLaser::get_event(const uint8_t opwr) { - SPINDLE_LASER_EVENT event; - - // Conditions - #if ENABLED(SPINDLE_LASER_PWM) - if (cutter.unitPower == 0 && CUTTER_UNIT_IS(RPM)) { - if (power == 0) { - return SPINDLE_LASER_EVENT::OFF; - } else { - return SPINDLE_LASER_EVENT::TO_OFF; - } - } +SpindleLaserEvent SpindleLaser::get_event(const uint8_t opwr) { + #if ENABLED(SPINDLE_LASER_PWM) && CUTTER_UNIT_IS(RPM) + if (cutter.unitPower == 0) + return power ? SpindleLaserEvent::TO_OFF : SpindleLaserEvent::OFF; #endif - if ((power + opwr) == 0) { - event = SPINDLE_LASER_EVENT::OFF; - } else if ((power > 0) && (opwr > 0)){ - event = SPINDLE_LASER_EVENT::ON; - } else if (opwr == 0) { - event = SPINDLE_LASER_EVENT::TO_OFF; - } else { - event = SPINDLE_LASER_EVENT::TO_ON; - } - - return event; + if (opwr == 0) + return power ? SpindleLaserEvent::TO_OFF : SpindleLaserEvent::OFF; + else + return power ? SpindleLaserEvent::ON : SpindleLaserEvent::TO_ON; } /** * Apply power for laser/spindle - * + * * Apply cutter power value for PWM, Servo, and on/off pin. - * + * * @param opwr Power value. Range 0 to MAX. When 0 disable laser/spindel. */ void SpindleLaser::apply_power(const uint8_t opwr) { static uint8_t last_power_applied = 0; switch (get_event(opwr)) { - case SPINDLE_LASER_EVENT::ON: + case SpindleLaserEvent::ON: if (opwr == last_power_applied) break; - last_power_applied = opwr; - power = opwr; + last_power_applied = power = opwr; #if ENABLED(SPINDLE_LASER_PWM) ocr_set(power); isReady = true; #endif + #if ENABLED(SPINDLE_SERVO) MOVE_SERVO(SPINDLE_SERVO_NR, power); - #endif - #if DISABLED(SPINDLE_SERVO) - pin_set(true); + #else + ena_pin_set(true); isReady = true; #endif - break; - case SPINDLE_LASER_EVENT::TO_ON: - last_power_applied = opwr; - power = opwr; + + case SpindleLaserEvent::TO_ON: + last_power_applied = power = opwr; #if ENABLED(SPINDLE_LASER_PWM) ocr_set(power); isReady = true; #endif + #if ENABLED(SPINDLE_SERVO) MOVE_SERVO(SPINDLE_SERVO_NR, power); - #endif - #if DISABLED(SPINDLE_SERVO) - pin_set(true); + #else + ena_pin_set(true); isReady = true; #endif power_delay(true); break; - case SPINDLE_LASER_EVENT::OFF: - break; - case SPINDLE_LASER_EVENT::TO_OFF: - last_power_applied = opwr; - power = opwr; + + case SpindleLaserEvent::OFF: break; + + case SpindleLaserEvent::TO_OFF: + last_power_applied = power = opwr; #if ENABLED(SPINDLE_LASER_PWM) - ocr_set(0); isReady = false; + ocr_set(0); #endif + #if ENABLED(SPINDLE_SERVO) MOVE_SERVO(SPINDLE_SERVO_NR, power); - #endif - #if DISABLED(SPINDLE_SERVO) - pin_set(false); + #else isReady = false; + ena_pin_set(false); #endif power_delay(false); @@ -222,28 +205,20 @@ void SpindleLaser::apply_power(const uint8_t opwr) { if (TERN0(SPINDLE_STOP_ON_DIR_CHANGE, enabled()) && READ(SPINDLE_DIR_PIN) != dir_state) disable(); WRITE(SPINDLE_DIR_PIN, dir_state); } -#endif // SPINDLE_CHANGE_DIR +#endif #if ENABLED(AIR_EVACUATION) - // Enable / disable Cutter Vacuum or Laser Blower motor void SpindleLaser::air_evac_enable() { WRITE(AIR_EVACUATION_PIN, AIR_EVACUATION_ACTIVE); } // Turn ON - void SpindleLaser::air_evac_disable() { WRITE(AIR_EVACUATION_PIN, !AIR_EVACUATION_ACTIVE); } // Turn OFF - void SpindleLaser::air_evac_toggle() { TOGGLE(AIR_EVACUATION_PIN); } // Toggle state - -#endif // AIR_EVACUATION +#endif #if ENABLED(AIR_ASSIST) - // Enable / disable air assist void SpindleLaser::air_assist_enable() { WRITE(AIR_ASSIST_PIN, AIR_ASSIST_PIN); } // Turn ON - void SpindleLaser::air_assist_disable() { WRITE(AIR_ASSIST_PIN, !AIR_ASSIST_PIN); } // Turn OFF - void SpindleLaser::air_assist_toggle() { TOGGLE(AIR_ASSIST_PIN); } // Toggle state - -#endif // AIR_ASSIST +#endif #endif // HAS_CUTTER diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index cdfab27ed1f7..65878a27cdbf 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -46,8 +46,8 @@ #endif // States - power == 0 off, power > 0 on -// TO - transit state (TO_ON - from any to on) -enum SPINDLE_LASER_EVENT {ON, OFF, TO_ON, TO_OFF}; +// TO - transition state (TO_ON - from any to on) +enum SpindleLaserEvent : uint8_t { ON, OFF, TO_ON, TO_OFF }; // #define _MAP(N,S1,S2,D1,D2) ((N)*_MAX((D2)-(D1),0)/_MAX((S2)-(S1),1)+(D1)) @@ -113,7 +113,7 @@ class SpindleLaser { unitPower; // Power as displayed status in PWM, Percentage or RPM static void init(); - static SPINDLE_LASER_EVENT get_event(const uint8_t opwr); + static SpindleLaserEvent get_event(const uint8_t opwr); #if ENABLED(MARLIN_DEV_MODE) static inline void refresh_frequency() { set_pwm_frequency(pin_t(SPINDLE_LASER_PWM_PIN), frequency); } @@ -124,6 +124,7 @@ class SpindleLaser { static inline bool enabled() { return enabled(power); } static void apply_power(const uint8_t inpow); + // Alias FORCE_INLINE static void set_power(const uint8_t upwr) { apply_power(upwr); } FORCE_INLINE static void refresh() { apply_power(power); } @@ -198,27 +199,24 @@ class SpindleLaser { } #endif // SPINDLE_LASER_PWM - static void pin_set(const bool enable); + static void ena_pin_set(const bool enable); /** - * Enable/Disabel spindle/laser - * @param enable True - enable; False - disable + * Enable/Disable spindle/laser + * @param enable true = enable; false = disable */ static inline void set_enabled(const bool enable) { uint8_t value = 0; - if (enable) { + if (enable) value = TERN(SPINDLE_LASER_PWM, (power ?: (unitPower ? upower_to_ocr(cpwr_to_upwr(SPEED_POWER_STARTUP)) : 0)), 255); - } apply_power(value); } - static inline void disable() { - isReady = false; set_enabled(false); - } + static inline void disable() { isReady = false; set_enabled(false); } /** * Wait for spindle to spin up or spin down - * + * * @param on True - state to on; False - state to off. */ static inline void power_delay(const bool on) { @@ -346,7 +344,7 @@ class SpindleLaser { planner.laser_inline.power = ocrpwr; } #endif - #endif // LASER_POWER_INLINE + #endif // LASER_POWER_INLINE static inline void kill() { TERN_(LASER_POWER_INLINE, inline_disable()); From 6f7e2c380c48a6ee0b6a3a126d393032063e9b59 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 6 Sep 2021 15:08:18 -0500 Subject: [PATCH 03/29] expand set_enabled --- Marlin/src/feature/spindle_laser.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index 65878a27cdbf..917c924d5381 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -207,8 +207,16 @@ class SpindleLaser { */ static inline void set_enabled(const bool enable) { uint8_t value = 0; - if (enable) - value = TERN(SPINDLE_LASER_PWM, (power ?: (unitPower ? upower_to_ocr(cpwr_to_upwr(SPEED_POWER_STARTUP)) : 0)), 255); + if (enable) { + #if ENABLED(SPINDLE_LASER_PWM) + if (power) + value = power; + else if (unitPower) + value = upower_to_ocr(cpwr_to_upwr(SPEED_POWER_STARTUP)); + #else + value = 255; + #endif + } apply_power(value); } From a410565f9f3ac2740e18c232d7f679a17369766c Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 6 Sep 2021 15:15:39 -0500 Subject: [PATCH 04/29] use _CUTTER_POWER macros --- Marlin/src/feature/spindle_laser.h | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index 917c924d5381..0643f593cb35 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -137,16 +137,16 @@ class SpindleLaser { static void ocr_off(); /** - * Used to update output for power->OCR translation + * Update output for power->OCR translation */ static inline uint8_t upower_to_ocr(const cutter_power_t upwr) { - return ( + return uint8_t( #if CUTTER_UNIT_IS(PWM255) - uint8_t(upwr) + upwr #elif CUTTER_UNIT_IS(PERCENT) pct_to_ocr(upwr) #else - uint8_t(pct_to_ocr(cpwr_to_pct(upwr))) + pct_to_ocr(cpwr_to_pct(upwr)) #endif ); } @@ -155,38 +155,28 @@ class SpindleLaser { * Correct power to configured range */ static inline cutter_power_t power_to_range(const cutter_power_t pwr) { - return power_to_range(pwr, ( - #if CUTTER_UNIT_IS(PWM255) - 0 - #elif CUTTER_UNIT_IS(PERCENT) - 1 - #elif CUTTER_UNIT_IS(RPM) - 2 - #else - #error "CUTTER_UNIT_IS(unknown)" - #endif - )); + return power_to_range(pwr, _CUTTER_POWER(CUTTER_POWER_UNIT)); } static inline cutter_power_t power_to_range(const cutter_power_t pwr, const uint8_t pwrUnit) { if (pwr <= 0) return 0; cutter_power_t upwr; switch (pwrUnit) { - case 0: // PWM + case _CUTTER_POWER_PWM255: upwr = cutter_power_t( (pwr < pct_to_ocr(min_pct)) ? pct_to_ocr(min_pct) // Use minimum if set below : (pwr > pct_to_ocr(max_pct)) ? pct_to_ocr(max_pct) // Use maximum if set above : pwr ); break; - case 1: // PERCENT + case _CUTTER_POWER_PERCENT: upwr = cutter_power_t( (pwr < min_pct) ? min_pct // Use minimum if set below : (pwr > max_pct) ? max_pct // Use maximum if set above : pwr // PCT ); break; - case 2: // RPM + case _CUTTER_POWER_RPM: upwr = cutter_power_t( (pwr < SPEED_POWER_MIN) ? SPEED_POWER_MIN // Use minimum if set below : (pwr > SPEED_POWER_MAX) ? SPEED_POWER_MAX // Use maximum if set above From 05b1f38d84cdda08c5ba7e74397309f15b2e6351 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 6 Sep 2021 15:43:30 -0500 Subject: [PATCH 05/29] apply_power => set_power --- Marlin/src/feature/spindle_laser.cpp | 8 +++----- Marlin/src/feature/spindle_laser.h | 10 ++++------ Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp | 2 +- Marlin/src/module/stepper.cpp | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index de4d9646c7a2..dfc34771b601 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -103,7 +103,7 @@ void SpindleLaser::init() { #endif // SPINDLE_LASER_PWM /** - * Set state for pin laser/spindle + * Set state for pin spindle/laser * @param enable true = on; false = off */ void SpindleLaser::ena_pin_set(const bool enable) { @@ -128,13 +128,11 @@ SpindleLaserEvent SpindleLaser::get_event(const uint8_t opwr) { } /** - * Apply power for laser/spindle - * - * Apply cutter power value for PWM, Servo, and on/off pin. + * Set cutter power value for PWM, Servo, and on/off pin. * * @param opwr Power value. Range 0 to MAX. When 0 disable spindle/laser. */ -void SpindleLaser::apply_power(const uint8_t opwr) { +void SpindleLaser::set_power(const uint8_t opwr) { static uint8_t last_power_applied = 0; switch (get_event(opwr)) { diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index a1d080196484..4b885002fd6f 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -123,16 +123,14 @@ class SpindleLaser { static inline bool enabled(const cutter_power_t opwr) { return opwr > 0; } static inline bool enabled() { return enabled(power); } - static void apply_power(const uint8_t inpow); + static void set_power(const uint8_t inpow); - // Alias - FORCE_INLINE static void set_power(const uint8_t upwr) { apply_power(upwr); } - FORCE_INLINE static void refresh() { apply_power(power); } + FORCE_INLINE static void refresh() { set_power(power); } #if ENABLED(SPINDLE_LASER_PWM) public: - static inline void ocr_set_power(const uint8_t ocr) { apply_power(ocr); } + static inline void ocr_set_power(const uint8_t ocr) { set_power(ocr); } static void ocr_set(const uint8_t ocr); static void ocr_off(); @@ -207,7 +205,7 @@ class SpindleLaser { value = 255; #endif } - apply_power(value); + set_power(value); } static inline void disable() { isReady = false; set_enabled(false); } diff --git a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp index 712e76e86f21..3dfd68c58d34 100644 --- a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp +++ b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp @@ -863,7 +863,7 @@ void MarlinUI::draw_status_screen() { #endif // - // Line 6..8 Temperatures, FAN for printer or Cooler, Flowmetter, Ampermeter, Cutter for laser/spindle + // Line 6..8 Temperatures, FAN for printer or Cooler, Flowmetter, Ampermeter, Cutter for spindle/laser // #if HAS_HOTEND diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index f9245336f368..30b1e10fe463 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -2070,7 +2070,7 @@ uint32_t Stepper::block_phase_isr() { // For non-inline cutter, grossly apply power #if ENABLED(LASER_FEATURE) && DISABLED(LASER_POWER_INLINE) - cutter.apply_power(current_block->cutter_power); + cutter.set_power(current_block->cutter_power); #endif TERN_(POWER_LOSS_RECOVERY, recovery.info.sdpos = current_block->sdpos); From c259045f449a5d47f5e5661bee2bb8bce0f93379 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 6 Sep 2021 20:02:34 -0500 Subject: [PATCH 06/29] All set_power is OCR --- Marlin/src/feature/spindle_laser.cpp | 30 +++++++++++------------- Marlin/src/feature/spindle_laser.h | 35 +++++++++++++--------------- Marlin/src/gcode/control/M3-M5.cpp | 8 +++---- Marlin/src/module/planner.cpp | 2 +- Marlin/src/module/planner.h | 2 +- Marlin/src/module/stepper.cpp | 2 +- 6 files changed, 37 insertions(+), 42 deletions(-) diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index dfc34771b601..746cb70c368d 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -39,7 +39,7 @@ #endif SpindleLaser cutter; -uint8_t SpindleLaser::power; +uint8_t SpindleLaser::ocr_power; #if ENABLED(LASER_FEATURE) cutter_test_pulse_t SpindleLaser::testPulse = 50; // Test fire Pulse time ms value. #endif @@ -98,8 +98,6 @@ void SpindleLaser::init() { #endif } - void SpindleLaser::ocr_off() { ocr_set(0); } - #endif // SPINDLE_LASER_PWM /** @@ -118,35 +116,35 @@ void SpindleLaser::ena_pin_set(const bool enable) { SpindleLaserEvent SpindleLaser::get_event(const uint8_t opwr) { #if ENABLED(SPINDLE_LASER_PWM) && CUTTER_UNIT_IS(RPM) if (cutter.unitPower == 0) - return power ? SpindleLaserEvent::TO_OFF : SpindleLaserEvent::OFF; + return ocr_power ? SpindleLaserEvent::TO_OFF : SpindleLaserEvent::OFF; #endif if (opwr == 0) - return power ? SpindleLaserEvent::TO_OFF : SpindleLaserEvent::OFF; + return ocr_power ? SpindleLaserEvent::TO_OFF : SpindleLaserEvent::OFF; else - return power ? SpindleLaserEvent::ON : SpindleLaserEvent::TO_ON; + return ocr_power ? SpindleLaserEvent::ON : SpindleLaserEvent::TO_ON; } /** - * Set cutter power value for PWM, Servo, and on/off pin. + * Set cutter ocr_power value for PWM, Servo, and on/off pin. * * @param opwr Power value. Range 0 to MAX. When 0 disable spindle/laser. */ -void SpindleLaser::set_power(const uint8_t opwr) { +void SpindleLaser::ocr_set_power(const uint8_t opwr) { static uint8_t last_power_applied = 0; switch (get_event(opwr)) { case SpindleLaserEvent::ON: if (opwr == last_power_applied) break; - last_power_applied = power = opwr; + last_power_applied = ocr_power = opwr; #if ENABLED(SPINDLE_LASER_PWM) - ocr_set(power); + ocr_set(ocr_power); isReady = true; #endif #if ENABLED(SPINDLE_SERVO) - MOVE_SERVO(SPINDLE_SERVO_NR, power); + MOVE_SERVO(SPINDLE_SERVO_NR, ocr_power); #else ena_pin_set(true); isReady = true; @@ -154,15 +152,15 @@ void SpindleLaser::set_power(const uint8_t opwr) { break; case SpindleLaserEvent::TO_ON: - last_power_applied = power = opwr; + last_power_applied = ocr_power = opwr; #if ENABLED(SPINDLE_LASER_PWM) - ocr_set(power); + ocr_set(ocr_power); isReady = true; #endif #if ENABLED(SPINDLE_SERVO) - MOVE_SERVO(SPINDLE_SERVO_NR, power); + MOVE_SERVO(SPINDLE_SERVO_NR, ocr_power); #else ena_pin_set(true); isReady = true; @@ -174,7 +172,7 @@ void SpindleLaser::set_power(const uint8_t opwr) { case SpindleLaserEvent::OFF: break; case SpindleLaserEvent::TO_OFF: - last_power_applied = power = opwr; + last_power_applied = ocr_power = opwr; #if ENABLED(SPINDLE_LASER_PWM) isReady = false; @@ -182,7 +180,7 @@ void SpindleLaser::set_power(const uint8_t opwr) { #endif #if ENABLED(SPINDLE_SERVO) - MOVE_SERVO(SPINDLE_SERVO_NR, power); + MOVE_SERVO(SPINDLE_SERVO_NR, ocr_power); #else isReady = false; ena_pin_set(false); diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index 4b885002fd6f..8b1349ab3eee 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -103,7 +103,7 @@ class SpindleLaser { #endif static bool isReady; // Ready to apply power setting from the UI to OCR - static uint8_t power; + static uint8_t ocr_power; #if ENABLED(MARLIN_DEV_MODE) static cutter_frequency_t frequency; // Set PWM frequency; range: 2K-50K @@ -121,21 +121,19 @@ class SpindleLaser { // Modifying this function should update everywhere static inline bool enabled(const cutter_power_t opwr) { return opwr > 0; } - static inline bool enabled() { return enabled(power); } + static inline bool enabled() { return enabled(ocr_power); } - static void set_power(const uint8_t inpow); + static void ocr_set_power(const uint8_t opwr); - FORCE_INLINE static void refresh() { set_power(power); } + FORCE_INLINE static void refresh() { ocr_set_power(ocr_power); } #if ENABLED(SPINDLE_LASER_PWM) public: - static inline void ocr_set_power(const uint8_t ocr) { set_power(ocr); } static void ocr_set(const uint8_t ocr); - static void ocr_off(); /** - * Update output for power->OCR translation + * Update output for upower->OCR translation */ static inline uint8_t upower_to_ocr(const cutter_power_t upwr) { return uint8_t( @@ -194,18 +192,18 @@ class SpindleLaser { * @param enable true = enable; false = disable */ static inline void set_enabled(const bool enable) { - uint8_t value = 0; + uint8_t opwr = 0; if (enable) { #if ENABLED(SPINDLE_LASER_PWM) - if (power) - value = power; + if (ocr_power) + opwr = ocr_power; else if (unitPower) - value = upower_to_ocr(cpwr_to_upwr(SPEED_POWER_STARTUP)); + opwr = upower_to_ocr(cpwr_to_upwr(SPEED_POWER_STARTUP)); #else - value = 255; + opwr = 255; #endif } - set_power(value); + ocr_set_power(opwr); } static inline void disable() { isReady = false; set_enabled(false); } @@ -252,7 +250,7 @@ class SpindleLaser { isReady = true; const uint8_t ocr = TERN(SPINDLE_LASER_PWM, upower_to_ocr(menuPower), 255); if (menuPower) - power = ocr; + ocr_power = ocr; else menuPower = cpwr_to_upwr(SPEED_POWER_STARTUP); unitPower = menuPower; @@ -265,7 +263,7 @@ class SpindleLaser { #if ENABLED(SPINDLE_LASER_PWM) static inline void update_from_mpower() { - if (isReady) power = upower_to_ocr(menuPower); + if (isReady) ocr_power = upower_to_ocr(menuPower); unitPower = menuPower; } #endif @@ -334,10 +332,9 @@ class SpindleLaser { static inline void inline_direction(const bool) { /* never */ } #if ENABLED(SPINDLE_LASER_PWM) - static inline void inline_ocr_power(const uint8_t ocrpwr) { - isReady = ocrpwr > 0; - planner.laser_inline.status.isEnabled = ocrpwr > 0; - planner.laser_inline.power = ocrpwr; + static inline void inline_ocr_power(const uint8_t opwr) { + planner.laser_inline.status.isEnabled = isReady = opwr > 0; + planner.laser_inline.power = opwr; } #endif #endif // LASER_POWER_INLINE diff --git a/Marlin/src/gcode/control/M3-M5.cpp b/Marlin/src/gcode/control/M3-M5.cpp index ff5ab5086e3b..c186a99e00f2 100644 --- a/Marlin/src/gcode/control/M3-M5.cpp +++ b/Marlin/src/gcode/control/M3-M5.cpp @@ -79,7 +79,7 @@ void GcodeSuite::M3_M4(const bool is_M4) { } else cutter.unitPower = cutter.cpwr_to_upwr(SPEED_POWER_STARTUP); - return cutter.unitPower; + return cutter.upower_to_ocr(cutter.unitPower); }; #if ENABLED(LASER_POWER_INLINE) @@ -92,7 +92,7 @@ void GcodeSuite::M3_M4(const bool is_M4) { cutter.inline_ocr_power(cutter.unitPower); // The OCR is a value from 0 to 255 (uint8_t) } else - cutter.inline_power(cutter.upower_to_ocr(get_s_power())); + cutter.inline_power(get_s_power()); #else cutter.set_inline_enabled(true); #endif @@ -111,9 +111,9 @@ void GcodeSuite::M3_M4(const bool is_M4) { cutter.ocr_set_power(cutter.unitPower); // The OCR is a value from 0 to 255 (uint8_t) } else - cutter.set_power(cutter.upower_to_ocr(get_s_power())); + cutter.ocr_set_power(get_s_power()); #elif ENABLED(SPINDLE_SERVO) - cutter.set_power(get_s_power()); + cutter.ocr_set_power(get_s_power()); #else cutter.set_enabled(true); #endif diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 04d32f9c1805..639d56f57d3a 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -2133,7 +2133,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move, TERN_(MIXING_EXTRUDER, mixer.populate_block(block->b_color)); - TERN_(HAS_CUTTER, block->cutter_power = cutter.power); + TERN_(HAS_CUTTER, block->cutter_ocr_power = cutter.ocr_power); #if HAS_FAN FANS_LOOP(i) block->fan_speed[i] = thermalManager.fan_speed[i]; diff --git a/Marlin/src/module/planner.h b/Marlin/src/module/planner.h index 5e3922c8979c..f36d887f7ead 100644 --- a/Marlin/src/module/planner.h +++ b/Marlin/src/module/planner.h @@ -221,7 +221,7 @@ typedef struct block_t { #endif #if HAS_CUTTER - cutter_power_t cutter_power; // Power level for Spindle, Laser, etc. + cutter_power_t cutter_ocr_power; // Power level for Spindle, Laser, etc. #endif #if HAS_FAN diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 30b1e10fe463..c003f8a00fa9 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -2070,7 +2070,7 @@ uint32_t Stepper::block_phase_isr() { // For non-inline cutter, grossly apply power #if ENABLED(LASER_FEATURE) && DISABLED(LASER_POWER_INLINE) - cutter.set_power(current_block->cutter_power); + cutter.ocr_set_power(current_block->cutter_ocr_power); #endif TERN_(POWER_LOSS_RECOVERY, recovery.info.sdpos = current_block->sdpos); From 22014e625e42fb99af18b97e8dc70bdac9da18df Mon Sep 17 00:00:00 2001 From: Alexey Matveev Date: Thu, 9 Sep 2021 11:01:12 +0300 Subject: [PATCH 07/29] Add state for direction spindle --- Marlin/src/feature/spindle_laser.cpp | 128 +++++++++++++++++---------- Marlin/src/feature/spindle_laser.h | 27 ++++-- 2 files changed, 97 insertions(+), 58 deletions(-) diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index 746cb70c368d..557024dee76a 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -39,7 +39,8 @@ #endif SpindleLaser cutter; -uint8_t SpindleLaser::ocr_power; +uint8_t SpindleLaser::ocr_power = 0; // Startup disable +uint8_t SpindleLaser::dir = SPINDLE_DIR_CW; // Startup clockwise #if ENABLED(LASER_FEATURE) cutter_test_pulse_t SpindleLaser::testPulse = 50; // Test fire Pulse time ms value. #endif @@ -62,6 +63,7 @@ void SpindleLaser::init() { OUT_WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ACTIVE_STATE); // Init spindle to off #endif #if ENABLED(SPINDLE_CHANGE_DIR) + // dir_set() OUT_WRITE(SPINDLE_DIR_PIN, SPINDLE_INVERT_DIR ? 255 : 0); // Init rotation to clockwise (M3) #endif #if ENABLED(SPINDLE_LASER_PWM) @@ -108,12 +110,26 @@ void SpindleLaser::ena_pin_set(const bool enable) { WRITE(SPINDLE_LASER_ENA_PIN, enable ? SPINDLE_LASER_ACTIVE_STATE : !SPINDLE_LASER_ACTIVE_STATE); } +/** + * Set direction pin for spindel + */ +void SpindleLaser::dir_pin_set(){ + uint8_t dir_state; + // Forward (M3) HIGH when not inverted + if (SPINDLE_INVERT_DIR) + dir_state = (dir == SPINDLE_DIR_CW) ? LOW : HIGH; + else + dir_state = (dir == SPINDLE_DIR_CW) ? HIGH : LOW; + WRITE(SPINDLE_DIR_PIN, dir_state); +} + /** * Detection event * - * @param opwr Power value + * @param opwr New power value + * @param odir New direction spindel */ -SpindleLaserEvent SpindleLaser::get_event(const uint8_t opwr) { +SpindleLaserEvent SpindleLaser::get_event(const uint8_t opwr, const uint8_t odir) { #if ENABLED(SPINDLE_LASER_PWM) && CUTTER_UNIT_IS(RPM) if (cutter.unitPower == 0) return ocr_power ? SpindleLaserEvent::TO_OFF : SpindleLaserEvent::OFF; @@ -121,72 +137,84 @@ SpindleLaserEvent SpindleLaser::get_event(const uint8_t opwr) { if (opwr == 0) return ocr_power ? SpindleLaserEvent::TO_OFF : SpindleLaserEvent::OFF; - else - return ocr_power ? SpindleLaserEvent::ON : SpindleLaserEvent::TO_ON; + if (ocr_power == 0) + return odir == SPINDLE_DIR_CW ? SpindleLaserEvent::TO_ON_CW : SpindleLaserEvent::TO_ON_CCW; + if (odir != dir) + return SpindleLaserEvent::TO_ON_ON; + return dir == SPINDLE_DIR_CW ? SpindleLaserEvent::ON_CW : SpindleLaserEvent::ON_CCW; +} + +/** + * Change hardware state + * set isReady is hack - his state and ena_pin_on is equal + */ +void SpindleLaser::_change_hw(const bool ena_pin_on) { + #if ENABLED(SPINDLE_LASER_PWM) + ocr_set(ocr_power); + isReady = ena_pin_on; + #endif + + #if ENABLED(SPINDLE_SERVO) + MOVE_SERVO(SPINDLE_SERVO_NR, ocr_power); + #else + ena_pin_set(true); + isReady = ena_pin_on; + #endif } /** * Set cutter ocr_power value for PWM, Servo, and on/off pin. * * @param opwr Power value. Range 0 to MAX. When 0 disable spindle/laser. + * @param odir Direction spindel */ -void SpindleLaser::ocr_set_power(const uint8_t opwr) { +void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir) { static uint8_t last_power_applied = 0; + uint8_t dir_value = TERN(SPINDLE_CHANGE_DIR, odir, SPINDLE_DIR_CW); - switch (get_event(opwr)) { - case SpindleLaserEvent::ON: + switch (get_event(opwr, dir_value)) { + case SpindleLaserEvent::ON_CW: + case SpindleLaserEvent::ON_CCW: if (opwr == last_power_applied) break; last_power_applied = ocr_power = opwr; - - #if ENABLED(SPINDLE_LASER_PWM) - ocr_set(ocr_power); - isReady = true; - #endif - - #if ENABLED(SPINDLE_SERVO) - MOVE_SERVO(SPINDLE_SERVO_NR, ocr_power); - #else - ena_pin_set(true); - isReady = true; - #endif + _change_hw(true); break; - case SpindleLaserEvent::TO_ON: + case SpindleLaserEvent::TO_ON_CCW: + case SpindleLaserEvent::TO_ON_CW: last_power_applied = ocr_power = opwr; - - #if ENABLED(SPINDLE_LASER_PWM) - ocr_set(ocr_power); - isReady = true; - #endif - - #if ENABLED(SPINDLE_SERVO) - MOVE_SERVO(SPINDLE_SERVO_NR, ocr_power); - #else - ena_pin_set(true); - isReady = true; - #endif - + dir = dir_value; + dir_pin_set(); + _change_hw(true); power_delay(true); break; - case SpindleLaserEvent::OFF: break; + case SpindleLaserEvent::OFF: + dir = dir_value; + dir_pin_set(); + break; case SpindleLaserEvent::TO_OFF: last_power_applied = ocr_power = opwr; + dir = dir_value; + dir_pin_set(); + _change_hw(false); + power_delay(false); + break; - #if ENABLED(SPINDLE_LASER_PWM) - isReady = false; - ocr_set(0); - #endif - - #if ENABLED(SPINDLE_SERVO) - MOVE_SERVO(SPINDLE_SERVO_NR, ocr_power); + case SpindleLaserEvent::TO_ON_ON: + last_power_applied = ocr_power = opwr; + dir = dir_value; + + #if ENABLED(SPINDLE_CHANGE_DIR_STOP) + _change_hw(false); + power_delay(false); + dir_pin_set(); + _change_hw(true); + power_delay(true); #else - isReady = false; - ena_pin_set(false); + dir_pin_set(); #endif - - power_delay(false); break; } } @@ -197,9 +225,11 @@ void SpindleLaser::ocr_set_power(const uint8_t opwr) { * Stop on direction change if SPINDLE_STOP_ON_DIR_CHANGE is enabled */ void SpindleLaser::set_reverse(const bool reverse) { - const bool dir_state = (reverse == SPINDLE_INVERT_DIR); // Forward (M3) HIGH when not inverted - if (TERN0(SPINDLE_STOP_ON_DIR_CHANGE, enabled()) && READ(SPINDLE_DIR_PIN) != dir_state) disable(); - WRITE(SPINDLE_DIR_PIN, dir_state); + // depricate and need delete + ocr_set_power(ocr_power, SPINDLE_DIR_CCW) + // const bool dir_state = (reverse == SPINDLE_INVERT_DIR); // Forward (M3) HIGH when not inverted + // if (TERN0(SPINDLE_STOP_ON_DIR_CHANGE, enabled()) && READ(SPINDLE_DIR_PIN) != dir_state) disable(); + // WRITE(SPINDLE_DIR_PIN, dir_state); } #endif diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index 8b1349ab3eee..0a921310ba13 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -45,9 +45,18 @@ #define SPEED_POWER_INTERCEPT 0 #endif +#define SPINDLE_DIR_CW 0 +#define SPINDLE_DIR_CCW 1 + // States - power == 0 off, power > 0 on // TO - transition state (TO_ON - from any to on) -enum SpindleLaserEvent : uint8_t { ON, OFF, TO_ON, TO_OFF }; +enum SpindleLaserEvent : uint8_t { + ON_CW, ON_CCW, OFF, + TO_ON_CW, TO_ON_CCW, + TO_OFF, + TO_ON_ON +}; + // #define _MAP(N,S1,S2,D1,D2) ((N)*_MAX((D2)-(D1),0)/_MAX((S2)-(S1),1)+(D1)) @@ -104,6 +113,7 @@ class SpindleLaser { static bool isReady; // Ready to apply power setting from the UI to OCR static uint8_t ocr_power; + static uint8_t dir; // Direction spindel #if ENABLED(MARLIN_DEV_MODE) static cutter_frequency_t frequency; // Set PWM frequency; range: 2K-50K @@ -112,9 +122,6 @@ class SpindleLaser { static cutter_power_t menuPower, // Power as set via LCD menu in PWM, Percentage or RPM unitPower; // Power as displayed status in PWM, Percentage or RPM - static void init(); - static SpindleLaserEvent get_event(const uint8_t opwr); - #if ENABLED(MARLIN_DEV_MODE) static inline void refresh_frequency() { set_pwm_frequency(pin_t(SPINDLE_LASER_PWM_PIN), frequency); } #endif @@ -123,13 +130,17 @@ class SpindleLaser { static inline bool enabled(const cutter_power_t opwr) { return opwr > 0; } static inline bool enabled() { return enabled(ocr_power); } - static void ocr_set_power(const uint8_t opwr); + static void dir_pin_set(); + static void ena_pin_set(const bool enable); + static void _change_hw(const bool ena_pin_on); + static SpindleLaserEvent get_event(const uint8_t opwr, const uint8_t dir); + + static void init(); + static void ocr_set_power(const uint8_t opwr, const uint8_t odir=SPINDLE_DIR_CW); FORCE_INLINE static void refresh() { ocr_set_power(ocr_power); } #if ENABLED(SPINDLE_LASER_PWM) - public: - static void ocr_set(const uint8_t ocr); /** @@ -185,8 +196,6 @@ class SpindleLaser { } #endif // SPINDLE_LASER_PWM - static void ena_pin_set(const bool enable); - /** * Enable/Disable spindle/laser * @param enable true = enable; false = disable From b7106b6e81f6a8ceac94b7932338c8e2a20c3667 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 9 Sep 2021 05:49:14 -0500 Subject: [PATCH 08/29] Fix spelling, SPINDLE_CHANGE_DIR --- Marlin/src/feature/spindle_laser.cpp | 28 +++++++++++++--------------- Marlin/src/feature/spindle_laser.h | 9 +++++++-- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index 557024dee76a..e0412230f246 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -63,7 +63,7 @@ void SpindleLaser::init() { OUT_WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ACTIVE_STATE); // Init spindle to off #endif #if ENABLED(SPINDLE_CHANGE_DIR) - // dir_set() + //dir_set() OUT_WRITE(SPINDLE_DIR_PIN, SPINDLE_INVERT_DIR ? 255 : 0); // Init rotation to clockwise (M3) #endif #if ENABLED(SPINDLE_LASER_PWM) @@ -110,24 +110,22 @@ void SpindleLaser::ena_pin_set(const bool enable) { WRITE(SPINDLE_LASER_ENA_PIN, enable ? SPINDLE_LASER_ACTIVE_STATE : !SPINDLE_LASER_ACTIVE_STATE); } -/** - * Set direction pin for spindel - */ -void SpindleLaser::dir_pin_set(){ - uint8_t dir_state; - // Forward (M3) HIGH when not inverted - if (SPINDLE_INVERT_DIR) - dir_state = (dir == SPINDLE_DIR_CW) ? LOW : HIGH; - else - dir_state = (dir == SPINDLE_DIR_CW) ? HIGH : LOW; - WRITE(SPINDLE_DIR_PIN, dir_state); -} +#if ENABLED(SPINDLE_CHANGE_DIR) + /** + * Set direction pin for spindle + */ + void SpindleLaser::dir_pin_set() { + // Forward (M3) HIGH when not inverted + const uint8_t dir_state = (dir == TERN(SPINDLE_INVERT_DIR, SPINDLE_DIR_CCW, SPINDLE_DIR_CW)) ? HIGH : LOW; + WRITE(SPINDLE_DIR_PIN, dir_state); + } +#endif /** * Detection event * * @param opwr New power value - * @param odir New direction spindel + * @param odir New direction spindle */ SpindleLaserEvent SpindleLaser::get_event(const uint8_t opwr, const uint8_t odir) { #if ENABLED(SPINDLE_LASER_PWM) && CUTTER_UNIT_IS(RPM) @@ -166,7 +164,7 @@ void SpindleLaser::_change_hw(const bool ena_pin_on) { * Set cutter ocr_power value for PWM, Servo, and on/off pin. * * @param opwr Power value. Range 0 to MAX. When 0 disable spindle/laser. - * @param odir Direction spindel + * @param odir Direction spindle */ void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir) { static uint8_t last_power_applied = 0; diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index 0a921310ba13..5cfd6872e5b4 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -113,7 +113,7 @@ class SpindleLaser { static bool isReady; // Ready to apply power setting from the UI to OCR static uint8_t ocr_power; - static uint8_t dir; // Direction spindel + static uint8_t dir; // Direction spindle #if ENABLED(MARLIN_DEV_MODE) static cutter_frequency_t frequency; // Set PWM frequency; range: 2K-50K @@ -130,7 +130,12 @@ class SpindleLaser { static inline bool enabled(const cutter_power_t opwr) { return opwr > 0; } static inline bool enabled() { return enabled(ocr_power); } - static void dir_pin_set(); + #if ENABLED(SPINDLE_CHANGE_DIR) + static void dir_pin_set(); + #else + static inline void dir_pin_set() {} + #endif + static void ena_pin_set(const bool enable); static void _change_hw(const bool ena_pin_on); static SpindleLaserEvent get_event(const uint8_t opwr, const uint8_t dir); From 3a040c844a80178e32ee34c5802c8a41f9907033 Mon Sep 17 00:00:00 2001 From: Alexey Matveev Date: Thu, 9 Sep 2021 19:38:50 +0300 Subject: [PATCH 09/29] Remove last_power_applied --- Marlin/src/feature/spindle_laser.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index e0412230f246..c795be01b1f8 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -167,20 +167,19 @@ void SpindleLaser::_change_hw(const bool ena_pin_on) { * @param odir Direction spindle */ void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir) { - static uint8_t last_power_applied = 0; uint8_t dir_value = TERN(SPINDLE_CHANGE_DIR, odir, SPINDLE_DIR_CW); switch (get_event(opwr, dir_value)) { case SpindleLaserEvent::ON_CW: case SpindleLaserEvent::ON_CCW: - if (opwr == last_power_applied) break; - last_power_applied = ocr_power = opwr; + if (opwr == ocr_power) break; + ocr_power = opwr; _change_hw(true); break; case SpindleLaserEvent::TO_ON_CCW: case SpindleLaserEvent::TO_ON_CW: - last_power_applied = ocr_power = opwr; + ocr_power = opwr; dir = dir_value; dir_pin_set(); _change_hw(true); @@ -193,7 +192,7 @@ void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir) { break; case SpindleLaserEvent::TO_OFF: - last_power_applied = ocr_power = opwr; + ocr_power = opwr; dir = dir_value; dir_pin_set(); _change_hw(false); @@ -201,7 +200,7 @@ void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir) { break; case SpindleLaserEvent::TO_ON_ON: - last_power_applied = ocr_power = opwr; + ocr_power = opwr; dir = dir_value; #if ENABLED(SPINDLE_CHANGE_DIR_STOP) From fe2f3290ee113c2eb2ab34f13618d1c23087599d Mon Sep 17 00:00:00 2001 From: Alexey Matveev Date: Fri, 10 Sep 2021 14:30:58 +0300 Subject: [PATCH 10/29] Add separate pin control for PWM --- Marlin/Configuration_adv.h | 7 +++ Marlin/src/feature/spindle_laser.cpp | 64 +++++++++++++++++++--------- Marlin/src/feature/spindle_laser.h | 23 ++++++---- 3 files changed, 67 insertions(+), 27 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 6857c4063bba..15390cb2cf3e 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -3329,6 +3329,13 @@ #define SPINDLE_LASER_FREQUENCY 2500 // (Hz) Spindle/laser frequency (only on supported HALs: AVR and LPC) + /** + * Control ENA_PIN in mode PWM. + * If defined ENA_PIN can be disabled throught M5 only. + * If it isn't defined when call M3 S0 ENA_PIN will be disable. + */ + #define SPINDLE_LASER_PWN_SEPARATE_PIN + //#define AIR_EVACUATION // Cutter Vacuum / Laser Blower motor control with G-codes M10-M11 #if ENABLED(AIR_EVACUATION) #define AIR_EVACUATION_ACTIVE LOW // Set to "HIGH" if the on/off function is active HIGH diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index c795be01b1f8..2ab676e0e53b 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -41,6 +41,7 @@ SpindleLaser cutter; uint8_t SpindleLaser::ocr_power = 0; // Startup disable uint8_t SpindleLaser::dir = SPINDLE_DIR_CW; // Startup clockwise +SpindleLaserEvent SpindleLaser::state = SpindleLaserEvent::OFF; // Startup OFF #if ENABLED(LASER_FEATURE) cutter_test_pulse_t SpindleLaser::testPulse = 50; // Test fire Pulse time ms value. #endif @@ -124,22 +125,25 @@ void SpindleLaser::ena_pin_set(const bool enable) { /** * Detection event * - * @param opwr New power value - * @param odir New direction spindle + * @param opwr New power value + * @param odir New direction spindle + * @param oena_pin_on New ena_pin state */ -SpindleLaserEvent SpindleLaser::get_event(const uint8_t opwr, const uint8_t odir) { +SpindleLaserEvent SpindleLaser::get_event(const uint8_t opwr, const uint8_t odir, const bool oena_pin_on) { #if ENABLED(SPINDLE_LASER_PWM) && CUTTER_UNIT_IS(RPM) if (cutter.unitPower == 0) - return ocr_power ? SpindleLaserEvent::TO_OFF : SpindleLaserEvent::OFF; + return state == SpindleLaserEvent::OFF ? SpindleLaserEvent::OFF : SpindleLaserEvent::TO_OFF; #endif - if (opwr == 0) - return ocr_power ? SpindleLaserEvent::TO_OFF : SpindleLaserEvent::OFF; - if (ocr_power == 0) + if ((opwr == 0) && (!oena_pin_on)) + return state == SpindleLaserEvent::OFF ? SpindleLaserEvent::OFF : SpindleLaserEvent::TO_OFF; + if (state == SpindleLaserEvent::OFF) return odir == SPINDLE_DIR_CW ? SpindleLaserEvent::TO_ON_CW : SpindleLaserEvent::TO_ON_CCW; if (odir != dir) - return SpindleLaserEvent::TO_ON_ON; - return dir == SPINDLE_DIR_CW ? SpindleLaserEvent::ON_CW : SpindleLaserEvent::ON_CCW; + return odir == SPINDLE_DIR_CW ? SpindleLaserEvent::TO_ON_ON_CW : SpindleLaserEvent::TO_ON_ON_CCW; + // We don't change state + // return dir == SPINDLE_DIR_CW ? SpindleLaserEvent::ON_CW : SpindleLaserEvent::ON_CCW; + return state; } /** @@ -155,7 +159,7 @@ void SpindleLaser::_change_hw(const bool ena_pin_on) { #if ENABLED(SPINDLE_SERVO) MOVE_SERVO(SPINDLE_SERVO_NR, ocr_power); #else - ena_pin_set(true); + ena_pin_set(ena_pin_on); isReady = ena_pin_on; #endif } @@ -163,18 +167,34 @@ void SpindleLaser::_change_hw(const bool ena_pin_on) { /** * Set cutter ocr_power value for PWM, Servo, and on/off pin. * - * @param opwr Power value. Range 0 to MAX. When 0 disable spindle/laser. - * @param odir Direction spindle + * @param opwr Power value. Range 0 to MAX. When 0 disable spindle/laser. + * @param odir Direction spindle (default SPINDLE_DIR_CW) + * @param ena_pin_on Enable/disable ENA_PIN. Work only in separate mode PWM. + * If separate mode is disable - ENA_PIN is managed through opwr value + * if true - enable pin; false - disable pin (default true) */ -void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir) { +void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir, const bool ena_pin_on) { + SpindleLaserEvent event; uint8_t dir_value = TERN(SPINDLE_CHANGE_DIR, odir, SPINDLE_DIR_CW); - switch (get_event(opwr, dir_value)) { + #if ENABLED(SPINDLE_CHANGE_DIR_STOP) + uint8_t ocr_power_tmp; // For save ocr_power (uint16_t) + #endif + + #if BOTH(SPINDLE_LASER_PWM, SPINDLE_LASER_PWN_SEPARATE_PIN) + bool ena_pin_on_value = ena_pin_on; + #else + bool ena_pin_on_value = opwr > 0 ? true : false; + #endif + + event = get_event(opwr, dir_value, ena_pin_on_value); + + switch (event) { case SpindleLaserEvent::ON_CW: case SpindleLaserEvent::ON_CCW: if (opwr == ocr_power) break; ocr_power = opwr; - _change_hw(true); + _change_hw(ena_pin_on_value); break; case SpindleLaserEvent::TO_ON_CCW: @@ -182,13 +202,12 @@ void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir) { ocr_power = opwr; dir = dir_value; dir_pin_set(); - _change_hw(true); + _change_hw(ena_pin_on_value); power_delay(true); break; case SpindleLaserEvent::OFF: dir = dir_value; - dir_pin_set(); break; case SpindleLaserEvent::TO_OFF: @@ -199,21 +218,28 @@ void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir) { power_delay(false); break; - case SpindleLaserEvent::TO_ON_ON: + case SpindleLaserEvent::TO_ON_ON_CW: + case SpindleLaserEvent::TO_ON_ON_CCW: ocr_power = opwr; dir = dir_value; #if ENABLED(SPINDLE_CHANGE_DIR_STOP) + //Stop + ocr_power_tmp = ocr_power; + ocr_power = 0; _change_hw(false); power_delay(false); + //Start + ocr_power = ocr_power_tmp; dir_pin_set(); - _change_hw(true); + _change_hw(ena_pin_on_value); power_delay(true); #else dir_pin_set(); #endif break; } + state = static_cast(event & 0b01111); } #if ENABLED(SPINDLE_CHANGE_DIR) diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index 5cfd6872e5b4..98b62595bfcd 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -51,10 +51,14 @@ // States - power == 0 off, power > 0 on // TO - transition state (TO_ON - from any to on) enum SpindleLaserEvent : uint8_t { - ON_CW, ON_CCW, OFF, - TO_ON_CW, TO_ON_CCW, - TO_OFF, - TO_ON_ON + ON_CW = 1, // 0000 0001 event, state + ON_CCW = 2, // 0000 0010 event, state + OFF = 4, // 0000 0100 event, state + TO_ON_CW = 17, // 0001 0001 event + TO_ON_CCW = 34, // 0010 0010 event + TO_OFF = 52, // 0011 0100 event + TO_ON_ON_CW = 65, // 0100 0001 event + TO_ON_ON_CCW = 82 // 0101 0010 event }; @@ -114,6 +118,7 @@ class SpindleLaser { static bool isReady; // Ready to apply power setting from the UI to OCR static uint8_t ocr_power; static uint8_t dir; // Direction spindle + static SpindleLaserEvent state; // Current state #if ENABLED(MARLIN_DEV_MODE) static cutter_frequency_t frequency; // Set PWM frequency; range: 2K-50K @@ -138,12 +143,13 @@ class SpindleLaser { static void ena_pin_set(const bool enable); static void _change_hw(const bool ena_pin_on); - static SpindleLaserEvent get_event(const uint8_t opwr, const uint8_t dir); + static SpindleLaserEvent get_event(const uint8_t opwr, const uint8_t odir, const bool oena_pin_on); static void init(); - static void ocr_set_power(const uint8_t opwr, const uint8_t odir=SPINDLE_DIR_CW); + static void ocr_set_power(const uint8_t opwr, const uint8_t odir=SPINDLE_DIR_CW, const bool ena_pin_on = true); - FORCE_INLINE static void refresh() { ocr_set_power(ocr_power); } + FORCE_INLINE static void refresh() {} + // { ocr_set_power(ocr_power); } #if ENABLED(SPINDLE_LASER_PWM) static void ocr_set(const uint8_t ocr); @@ -217,7 +223,8 @@ class SpindleLaser { opwr = 255; #endif } - ocr_set_power(opwr); + // ??? + ocr_set_power(opwr, dir, enable); } static inline void disable() { isReady = false; set_enabled(false); } From a77c0100740a7325a259f7c32e083d0de4037717 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 10 Sep 2021 14:27:00 -0500 Subject: [PATCH 11/29] Fix speling --- Marlin/Configuration_adv.h | 4 ++-- Marlin/src/feature/spindle_laser.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 15390cb2cf3e..4e3bff416721 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -3329,12 +3329,12 @@ #define SPINDLE_LASER_FREQUENCY 2500 // (Hz) Spindle/laser frequency (only on supported HALs: AVR and LPC) - /** + /** * Control ENA_PIN in mode PWM. * If defined ENA_PIN can be disabled throught M5 only. * If it isn't defined when call M3 S0 ENA_PIN will be disable. */ - #define SPINDLE_LASER_PWN_SEPARATE_PIN + #define SPINDLE_LASER_PWM_SEPARATE_PIN //#define AIR_EVACUATION // Cutter Vacuum / Laser Blower motor control with G-codes M10-M11 #if ENABLED(AIR_EVACUATION) diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index 2ab676e0e53b..858e56004280 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -181,7 +181,7 @@ void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir, const b uint8_t ocr_power_tmp; // For save ocr_power (uint16_t) #endif - #if BOTH(SPINDLE_LASER_PWM, SPINDLE_LASER_PWN_SEPARATE_PIN) + #if BOTH(SPINDLE_LASER_PWM, SPINDLE_LASER_PWM_SEPARATE_PIN) bool ena_pin_on_value = ena_pin_on; #else bool ena_pin_on_value = opwr > 0 ? true : false; @@ -248,8 +248,8 @@ void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir, const b * Stop on direction change if SPINDLE_STOP_ON_DIR_CHANGE is enabled */ void SpindleLaser::set_reverse(const bool reverse) { - // depricate and need delete - ocr_set_power(ocr_power, SPINDLE_DIR_CCW) + // deprecate and need delete + ocr_set_power(ocr_power, SPINDLE_DIR_CCW); // const bool dir_state = (reverse == SPINDLE_INVERT_DIR); // Forward (M3) HIGH when not inverted // if (TERN0(SPINDLE_STOP_ON_DIR_CHANGE, enabled()) && READ(SPINDLE_DIR_PIN) != dir_state) disable(); // WRITE(SPINDLE_DIR_PIN, dir_state); From d54108e11f5bd676fd0b5a06c1f1a771d9cbca86 Mon Sep 17 00:00:00 2001 From: Alexey Matveev Date: Fri, 10 Sep 2021 23:25:08 +0300 Subject: [PATCH 12/29] Delete 'cutter.unitPower == 0' into get_event --- Marlin/Configuration_adv.h | 2 +- Marlin/src/feature/spindle_laser.cpp | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 4e3bff416721..9565442926c3 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -3334,7 +3334,7 @@ * If defined ENA_PIN can be disabled throught M5 only. * If it isn't defined when call M3 S0 ENA_PIN will be disable. */ - #define SPINDLE_LASER_PWM_SEPARATE_PIN + //#define SPINDLE_LASER_PWM_SEPARATE_PIN //#define AIR_EVACUATION // Cutter Vacuum / Laser Blower motor control with G-codes M10-M11 #if ENABLED(AIR_EVACUATION) diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index 858e56004280..8a727b54bd1d 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -130,11 +130,6 @@ void SpindleLaser::ena_pin_set(const bool enable) { * @param oena_pin_on New ena_pin state */ SpindleLaserEvent SpindleLaser::get_event(const uint8_t opwr, const uint8_t odir, const bool oena_pin_on) { - #if ENABLED(SPINDLE_LASER_PWM) && CUTTER_UNIT_IS(RPM) - if (cutter.unitPower == 0) - return state == SpindleLaserEvent::OFF ? SpindleLaserEvent::OFF : SpindleLaserEvent::TO_OFF; - #endif - if ((opwr == 0) && (!oena_pin_on)) return state == SpindleLaserEvent::OFF ? SpindleLaserEvent::OFF : SpindleLaserEvent::TO_OFF; if (state == SpindleLaserEvent::OFF) From 69dbf96fc416d1ccca3bc1328f32787e55be225f Mon Sep 17 00:00:00 2001 From: Alexey Matveev Date: Sat, 11 Sep 2021 20:34:23 +0300 Subject: [PATCH 13/29] Change enable. Move inner variable and method in private. Added DIR_CURRENT variable to make it more convenient to call the method set_ocr_power --- Marlin/src/feature/spindle_laser.cpp | 11 ++++++-- Marlin/src/feature/spindle_laser.h | 40 +++++++++++++++++----------- Marlin/src/module/planner.cpp | 2 +- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index 8a727b54bd1d..10d3551264bc 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -163,14 +163,16 @@ void SpindleLaser::_change_hw(const bool ena_pin_on) { * Set cutter ocr_power value for PWM, Servo, and on/off pin. * * @param opwr Power value. Range 0 to MAX. When 0 disable spindle/laser. - * @param odir Direction spindle (default SPINDLE_DIR_CW) + * @param odir Direction spindle (default SPINDLE_DIR_CURRENT) * @param ena_pin_on Enable/disable ENA_PIN. Work only in separate mode PWM. * If separate mode is disable - ENA_PIN is managed through opwr value * if true - enable pin; false - disable pin (default true) */ void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir, const bool ena_pin_on) { SpindleLaserEvent event; - uint8_t dir_value = TERN(SPINDLE_CHANGE_DIR, odir, SPINDLE_DIR_CW); + uint8_t dir_value = TERN( + SPINDLE_CHANGE_DIR, (odir == SPINDLE_DIR_CURRENT) ? dir : odir, SPINDLE_DIR_CW + ); #if ENABLED(SPINDLE_CHANGE_DIR_STOP) uint8_t ocr_power_tmp; // For save ocr_power (uint16_t) @@ -237,6 +239,11 @@ void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir, const b state = static_cast(event & 0b01111); } +/** + * Return value ocr_power + */ +uint8_t SpindleLaser::get_ocr_power(){ return ocr_power; } + #if ENABLED(SPINDLE_CHANGE_DIR) /** * Set the spindle direction and apply immediately diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index 98b62595bfcd..758f72277da8 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -45,11 +45,11 @@ #define SPEED_POWER_INTERCEPT 0 #endif -#define SPINDLE_DIR_CW 0 -#define SPINDLE_DIR_CCW 1 +#define SPINDLE_DIR_CURRENT 0 // Don't change current value +#define SPINDLE_DIR_CW 1 +#define SPINDLE_DIR_CCW 2 -// States - power == 0 off, power > 0 on -// TO - transition state (TO_ON - from any to on) +// TO - transition event (example: TO_ - from any to ) enum SpindleLaserEvent : uint8_t { ON_CW = 1, // 0000 0001 event, state ON_CCW = 2, // 0000 0010 event, state @@ -65,6 +65,11 @@ enum SpindleLaserEvent : uint8_t { // #define _MAP(N,S1,S2,D1,D2) ((N)*_MAX((D2)-(D1),0)/_MAX((S2)-(S1),1)+(D1)) class SpindleLaser { +private: + static uint8_t dir; // Direction spindle + static uint8_t ocr_power; // Value for PWM out + static SpindleLaserEvent state; // Current state + public: static constexpr float min_pct = TERN(CUTTER_POWER_RELATIVE, 0, TERN(SPINDLE_FEATURE, round(100.0f * (SPEED_POWER_MIN) / (SPEED_POWER_MAX)), SPEED_POWER_MIN)), @@ -116,9 +121,6 @@ class SpindleLaser { #endif static bool isReady; // Ready to apply power setting from the UI to OCR - static uint8_t ocr_power; - static uint8_t dir; // Direction spindle - static SpindleLaserEvent state; // Current state #if ENABLED(MARLIN_DEV_MODE) static cutter_frequency_t frequency; // Set PWM frequency; range: 2K-50K @@ -131,9 +133,10 @@ class SpindleLaser { static inline void refresh_frequency() { set_pwm_frequency(pin_t(SPINDLE_LASER_PWM_PIN), frequency); } #endif - // Modifying this function should update everywhere - static inline bool enabled(const cutter_power_t opwr) { return opwr > 0; } - static inline bool enabled() { return enabled(ocr_power); } +private: + static void ena_pin_set(const bool enable); + static void _change_hw(const bool ena_pin_on); + static SpindleLaserEvent get_event(const uint8_t opwr, const uint8_t odir, const bool oena_pin_on); #if ENABLED(SPINDLE_CHANGE_DIR) static void dir_pin_set(); @@ -141,19 +144,24 @@ class SpindleLaser { static inline void dir_pin_set() {} #endif - static void ena_pin_set(const bool enable); - static void _change_hw(const bool ena_pin_on); - static SpindleLaserEvent get_event(const uint8_t opwr, const uint8_t odir, const bool oena_pin_on); + #if ENABLED(SPINDLE_LASER_PWM) + static void ocr_set(const uint8_t ocr); + #endif +public: static void init(); - static void ocr_set_power(const uint8_t opwr, const uint8_t odir=SPINDLE_DIR_CW, const bool ena_pin_on = true); + static void ocr_set_power(const uint8_t opwr, const uint8_t odir=SPINDLE_DIR_CURRENT, const bool ena_pin_on = true); + static uint8_t get_ocr_power(); + + /** + * Return state laser/spindle; true if enable. + */ + static inline bool enabled() { return !(state == SpindleLaserEvent::OFF); } FORCE_INLINE static void refresh() {} // { ocr_set_power(ocr_power); } #if ENABLED(SPINDLE_LASER_PWM) - static void ocr_set(const uint8_t ocr); - /** * Update output for upower->OCR translation */ diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 3ea7d39b9de8..513c9f8d5b33 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -2133,7 +2133,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move, TERN_(MIXING_EXTRUDER, mixer.populate_block(block->b_color)); - TERN_(HAS_CUTTER, block->cutter_ocr_power = cutter.ocr_power); + TERN_(HAS_CUTTER, block->cutter_ocr_power = cutter.get_ocr_power()); #if HAS_FAN FANS_LOOP(i) block->fan_speed[i] = thermalManager.fan_speed[i]; From e8439f4dc43c04b248b1673161528fd5a7f88099 Mon Sep 17 00:00:00 2001 From: Alexey Matveev Date: Sun, 12 Sep 2021 11:48:49 +0300 Subject: [PATCH 14/29] Updated M3/M4 for work with new api interface --- Marlin/src/feature/spindle_laser.cpp | 9 +++------ Marlin/src/feature/spindle_laser.h | 5 +++-- Marlin/src/gcode/control/M3-M5.cpp | 9 +++++---- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index 10d3551264bc..c7b70fead9f5 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -247,14 +247,11 @@ uint8_t SpindleLaser::get_ocr_power(){ return ocr_power; } #if ENABLED(SPINDLE_CHANGE_DIR) /** * Set the spindle direction and apply immediately - * Stop on direction change if SPINDLE_STOP_ON_DIR_CHANGE is enabled + * ! deprecate and need delete + * @param reverse If True is SPINDLE_DIR_CCW, false is SPINDLE_DIR_CW */ void SpindleLaser::set_reverse(const bool reverse) { - // deprecate and need delete - ocr_set_power(ocr_power, SPINDLE_DIR_CCW); - // const bool dir_state = (reverse == SPINDLE_INVERT_DIR); // Forward (M3) HIGH when not inverted - // if (TERN0(SPINDLE_STOP_ON_DIR_CHANGE, enabled()) && READ(SPINDLE_DIR_PIN) != dir_state) disable(); - // WRITE(SPINDLE_DIR_PIN, dir_state); + ocr_set_power(ocr_power, reverse ? SPINDLE_DIR_CCW : SPINDLE_DIR_CW); } #endif diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index 758f72277da8..d0b14fabd628 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -218,8 +218,9 @@ class SpindleLaser { /** * Enable/Disable spindle/laser * @param enable true = enable; false = disable + * @param odir Direction spindle (default SPINDLE_DIR_CURRENT) */ - static inline void set_enabled(const bool enable) { + static inline void set_enabled(const bool enable, uint8_t odir = SPINDLE_DIR_CURRENT) { uint8_t opwr = 0; if (enable) { #if ENABLED(SPINDLE_LASER_PWM) @@ -232,7 +233,7 @@ class SpindleLaser { #endif } // ??? - ocr_set_power(opwr, dir, enable); + ocr_set_power(opwr, odir, enable); } static inline void disable() { isReady = false; set_enabled(false); } diff --git a/Marlin/src/gcode/control/M3-M5.cpp b/Marlin/src/gcode/control/M3-M5.cpp index c186a99e00f2..9d9e8c5133e4 100644 --- a/Marlin/src/gcode/control/M3-M5.cpp +++ b/Marlin/src/gcode/control/M3-M5.cpp @@ -103,19 +103,20 @@ void GcodeSuite::M3_M4(const bool is_M4) { #endif planner.synchronize(); // Wait for previous movement commands (G0/G0/G2/G3) to complete before changing power - cutter.set_reverse(is_M4); + + uint8_t dir_value = is_M4 ? SPINDLE_DIR_CCW : SPINDLE_DIR_CW; #if ENABLED(SPINDLE_LASER_PWM) if (parser.seenval('O')) { cutter.unitPower = cutter.power_to_range(parser.value_byte(), 0); - cutter.ocr_set_power(cutter.unitPower); // The OCR is a value from 0 to 255 (uint8_t) + cutter.ocr_set_power(cutter.unitPower, dir_value); // The OCR is a value from 0 to 255 (uint8_t) } else - cutter.ocr_set_power(get_s_power()); + cutter.ocr_set_power(get_s_power(), dir_value); #elif ENABLED(SPINDLE_SERVO) cutter.ocr_set_power(get_s_power()); #else - cutter.set_enabled(true); + cutter.set_enabled(true, dir_value); #endif cutter.menuPower = cutter.unitPower; } From a68d2c778b4ee31505dac1e6d1fa87405dfc609b Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 12 Sep 2021 15:02:49 -0500 Subject: [PATCH 15/29] Init Spindle DIR as HIGH / LOW --- Marlin/src/feature/spindle_laser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index c7b70fead9f5..2f97a7307bea 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -64,8 +64,8 @@ void SpindleLaser::init() { OUT_WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ACTIVE_STATE); // Init spindle to off #endif #if ENABLED(SPINDLE_CHANGE_DIR) - //dir_set() - OUT_WRITE(SPINDLE_DIR_PIN, SPINDLE_INVERT_DIR ? 255 : 0); // Init rotation to clockwise (M3) + SET_OUTPUT(SPINDLE_DIR_PIN); + dir_pin_set(); #endif #if ENABLED(SPINDLE_LASER_PWM) SET_PWM(SPINDLE_LASER_PWM_PIN); From 83c292941847dcadbbdba8e53c339746f1444b21 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 12 Sep 2021 15:56:26 -0500 Subject: [PATCH 16/29] Simplify cutter state, etc. --- Marlin/Configuration_adv.h | 6 +- Marlin/src/feature/spindle_laser.cpp | 131 +++++++++++++-------------- Marlin/src/feature/spindle_laser.h | 34 +++---- 3 files changed, 81 insertions(+), 90 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 9565442926c3..821834b05a5c 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -3330,9 +3330,9 @@ #define SPINDLE_LASER_FREQUENCY 2500 // (Hz) Spindle/laser frequency (only on supported HALs: AVR and LPC) /** - * Control ENA_PIN in mode PWM. - * If defined ENA_PIN can be disabled throught M5 only. - * If it isn't defined when call M3 S0 ENA_PIN will be disable. + * Control ENA_PIN in PWM mode. + * If defined the ENA_PIN is disabled only by 'M5'. + * If not defined 'M3 S0' disables the ENA_PIN. */ //#define SPINDLE_LASER_PWM_SEPARATE_PIN diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index 2f97a7307bea..9c4e60c3420e 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -39,18 +39,18 @@ #endif SpindleLaser cutter; -uint8_t SpindleLaser::ocr_power = 0; // Startup disable -uint8_t SpindleLaser::dir = SPINDLE_DIR_CW; // Startup clockwise -SpindleLaserEvent SpindleLaser::state = SpindleLaserEvent::OFF; // Startup OFF +uint8_t SpindleLaser::ocr_power = 0; // Startup disable +uint8_t SpindleLaser::spindle_dir = SPINDLE_DIR_CW; // Startup clockwise +CutterState SpindleLaser::state = STAY_OFF; // Startup OFF #if ENABLED(LASER_FEATURE) - cutter_test_pulse_t SpindleLaser::testPulse = 50; // Test fire Pulse time ms value. + cutter_test_pulse_t SpindleLaser::testPulse = 50; // Test fire Pulse time ms value. #endif -bool SpindleLaser::isReady; // Ready to apply power setting from the UI to OCR -cutter_power_t SpindleLaser::menuPower, // Power set via LCD menu in PWM, PERCENT, or RPM - SpindleLaser::unitPower; // LCD status power in PWM, PERCENT, or RPM +bool SpindleLaser::isReady; // Ready to apply power setting from the UI to OCR +cutter_power_t SpindleLaser::menuPower, // Power set via LCD menu in PWM, PERCENT, or RPM + SpindleLaser::unitPower; // LCD status power in PWM, PERCENT, or RPM #if ENABLED(MARLIN_DEV_MODE) - cutter_frequency_t SpindleLaser::frequency; // PWM frequency setting; range: 2K - 50K + cutter_frequency_t SpindleLaser::frequency; // PWM frequency setting; range: 2K - 50K #endif #define SPINDLE_LASER_PWM_OFF TERN(SPINDLE_LASER_PWM_INVERT, 255, 0) @@ -117,45 +117,44 @@ void SpindleLaser::ena_pin_set(const bool enable) { */ void SpindleLaser::dir_pin_set() { // Forward (M3) HIGH when not inverted - const uint8_t dir_state = (dir == TERN(SPINDLE_INVERT_DIR, SPINDLE_DIR_CCW, SPINDLE_DIR_CW)) ? HIGH : LOW; + const uint8_t dir_state = (spindle_dir == TERN(SPINDLE_INVERT_DIR, SPINDLE_DIR_CCW, SPINDLE_DIR_CW)) ? HIGH : LOW; WRITE(SPINDLE_DIR_PIN, dir_state); } #endif /** - * Detection event + * Get a change event based on current and new state * * @param opwr New power value * @param odir New direction spindle * @param oena_pin_on New ena_pin state */ -SpindleLaserEvent SpindleLaser::get_event(const uint8_t opwr, const uint8_t odir, const bool oena_pin_on) { - if ((opwr == 0) && (!oena_pin_on)) - return state == SpindleLaserEvent::OFF ? SpindleLaserEvent::OFF : SpindleLaserEvent::TO_OFF; - if (state == SpindleLaserEvent::OFF) - return odir == SPINDLE_DIR_CW ? SpindleLaserEvent::TO_ON_CW : SpindleLaserEvent::TO_ON_CCW; - if (odir != dir) - return odir == SPINDLE_DIR_CW ? SpindleLaserEvent::TO_ON_ON_CW : SpindleLaserEvent::TO_ON_ON_CCW; - // We don't change state - // return dir == SPINDLE_DIR_CW ? SpindleLaserEvent::ON_CW : SpindleLaserEvent::ON_CCW; +CutterState SpindleLaser::get_event(const uint8_t opwr, const uint8_t odir, const bool oena_pin_on) { + // Setting PWM and ENA both off + if (opwr == 0 && !oena_pin_on) + return state == CutterState::STAY_OFF ? CutterState::STAY_OFF : CutterState::TURN_OFF; + + // Setting PWM or ENA while OFF + if (state == CutterState::STAY_OFF) + return CutterState::TURN_ON; + + // Changing direction while already ON + if (odir != spindle_dir) + return CutterState::STAY_ON_REV; + return state; } /** * Change hardware state - * set isReady is hack - his state and ena_pin_on is equal */ void SpindleLaser::_change_hw(const bool ena_pin_on) { - #if ENABLED(SPINDLE_LASER_PWM) - ocr_set(ocr_power); - isReady = ena_pin_on; - #endif + TERN_(SPINDLE_LASER_PWM, ocr_set(ocr_power)); - #if ENABLED(SPINDLE_SERVO) - MOVE_SERVO(SPINDLE_SERVO_NR, ocr_power); - #else - ena_pin_set(ena_pin_on); - isReady = ena_pin_on; + TERN(SPINDLE_SERVO, MOVE_SERVO(SPINDLE_SERVO_NR, ocr_power), ena_pin_set(ena_pin_on)); + + #if ENABLED(SPINDLE_LASER_PWM) || DISABLED(SPINDLE_SERVO) + isReady = ena_pin_on; // This is a hack. isReady state and ena_pin_on are equivalent. #endif } @@ -168,75 +167,73 @@ void SpindleLaser::_change_hw(const bool ena_pin_on) { * If separate mode is disable - ENA_PIN is managed through opwr value * if true - enable pin; false - disable pin (default true) */ -void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir, const bool ena_pin_on) { - SpindleLaserEvent event; - uint8_t dir_value = TERN( - SPINDLE_CHANGE_DIR, (odir == SPINDLE_DIR_CURRENT) ? dir : odir, SPINDLE_DIR_CW - ); - - #if ENABLED(SPINDLE_CHANGE_DIR_STOP) - uint8_t ocr_power_tmp; // For save ocr_power (uint16_t) - #endif +void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir/*=SPINDLE_DIR_CURRENT*/, const bool ena_pin_on/*=true*/) { + const uint8_t dir_value = TERN(SPINDLE_CHANGE_DIR, (odir == SPINDLE_DIR_CURRENT) ? spindle_dir : odir, SPINDLE_DIR_CW); - #if BOTH(SPINDLE_LASER_PWM, SPINDLE_LASER_PWM_SEPARATE_PIN) - bool ena_pin_on_value = ena_pin_on; - #else - bool ena_pin_on_value = opwr > 0 ? true : false; - #endif - - event = get_event(opwr, dir_value, ena_pin_on_value); + const bool ena_pin_on_value = ( + #if BOTH(SPINDLE_LASER_PWM, SPINDLE_LASER_PWM_SEPARATE_PIN) + ena_pin_on + #else + opwr > 0 + #endif + ); - switch (event) { - case SpindleLaserEvent::ON_CW: - case SpindleLaserEvent::ON_CCW: - if (opwr == ocr_power) break; - ocr_power = opwr; - _change_hw(ena_pin_on_value); + switch (get_event(opwr, dir_value, ena_pin_on_value)) { + // Already ON and staying ON + case CutterState::STAY_ON: + state = STAY_ON; // Probably already the current state + if (opwr != ocr_power) { + ocr_power = opwr; + _change_hw(ena_pin_on_value); + } break; - case SpindleLaserEvent::TO_ON_CCW: - case SpindleLaserEvent::TO_ON_CW: + case CutterState::TURN_ON: + state = STAY_ON; ocr_power = opwr; - dir = dir_value; + spindle_dir = dir_value; dir_pin_set(); _change_hw(ena_pin_on_value); power_delay(true); break; - case SpindleLaserEvent::OFF: - dir = dir_value; + case CutterState::STAY_OFF: + state = STAY_OFF; // Probably already the current state + spindle_dir = dir_value; break; - case SpindleLaserEvent::TO_OFF: + case CutterState::TURN_OFF: + state = STAY_OFF; ocr_power = opwr; - dir = dir_value; + spindle_dir = dir_value; dir_pin_set(); _change_hw(false); power_delay(false); break; - case SpindleLaserEvent::TO_ON_ON_CW: - case SpindleLaserEvent::TO_ON_ON_CCW: + case CutterState::STAY_ON_REV: { + state = STAY_ON; ocr_power = opwr; - dir = dir_value; + spindle_dir = dir_value; #if ENABLED(SPINDLE_CHANGE_DIR_STOP) - //Stop - ocr_power_tmp = ocr_power; + // Stop Spindle and wait + const uint8_t curr_power = ocr_power; ocr_power = 0; _change_hw(false); power_delay(false); - //Start - ocr_power = ocr_power_tmp; + // Start spindle and wait + ocr_power = curr_power; dir_pin_set(); _change_hw(ena_pin_on_value); power_delay(true); #else dir_pin_set(); #endif - break; + } break; } - state = static_cast(event & 0b01111); + + UNUSED(ena_pin_on); } /** diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index d0b14fabd628..fea129764469 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -49,26 +49,22 @@ #define SPINDLE_DIR_CW 1 #define SPINDLE_DIR_CCW 2 -// TO - transition event (example: TO_ - from any to ) -enum SpindleLaserEvent : uint8_t { - ON_CW = 1, // 0000 0001 event, state - ON_CCW = 2, // 0000 0010 event, state - OFF = 4, // 0000 0100 event, state - TO_ON_CW = 17, // 0001 0001 event - TO_ON_CCW = 34, // 0010 0010 event - TO_OFF = 52, // 0011 0100 event - TO_ON_ON_CW = 65, // 0100 0001 event - TO_ON_ON_CCW = 82 // 0101 0010 event +// Current ON/OFF state and transitions for get_event +enum CutterState : uint8_t { + STAY_OFF = 0, + STAY_ON, + STAY_ON_REV, + TURN_ON, + TURN_OFF }; - // #define _MAP(N,S1,S2,D1,D2) ((N)*_MAX((D2)-(D1),0)/_MAX((S2)-(S1),1)+(D1)) class SpindleLaser { private: - static uint8_t dir; // Direction spindle - static uint8_t ocr_power; // Value for PWM out - static SpindleLaserEvent state; // Current state + static uint8_t spindle_dir; // Spindle direction + static uint8_t ocr_power; // Value for PWM out + static CutterState state; // Current state public: static constexpr float @@ -136,7 +132,7 @@ class SpindleLaser { private: static void ena_pin_set(const bool enable); static void _change_hw(const bool ena_pin_on); - static SpindleLaserEvent get_event(const uint8_t opwr, const uint8_t odir, const bool oena_pin_on); + static CutterState get_event(const uint8_t opwr, const uint8_t odir, const bool oena_pin_on); #if ENABLED(SPINDLE_CHANGE_DIR) static void dir_pin_set(); @@ -150,16 +146,15 @@ class SpindleLaser { public: static void init(); - static void ocr_set_power(const uint8_t opwr, const uint8_t odir=SPINDLE_DIR_CURRENT, const bool ena_pin_on = true); + static void ocr_set_power(const uint8_t opwr, const uint8_t odir=SPINDLE_DIR_CURRENT, const bool ena_pin_on=true); static uint8_t get_ocr_power(); /** * Return state laser/spindle; true if enable. */ - static inline bool enabled() { return !(state == SpindleLaserEvent::OFF); } + static inline bool enabled() { return state != CutterState::STAY_OFF; } FORCE_INLINE static void refresh() {} - // { ocr_set_power(ocr_power); } #if ENABLED(SPINDLE_LASER_PWM) /** @@ -220,7 +215,7 @@ class SpindleLaser { * @param enable true = enable; false = disable * @param odir Direction spindle (default SPINDLE_DIR_CURRENT) */ - static inline void set_enabled(const bool enable, uint8_t odir = SPINDLE_DIR_CURRENT) { + static inline void set_enabled(const bool enable, uint8_t odir=SPINDLE_DIR_CURRENT) { uint8_t opwr = 0; if (enable) { #if ENABLED(SPINDLE_LASER_PWM) @@ -232,7 +227,6 @@ class SpindleLaser { opwr = 255; #endif } - // ??? ocr_set_power(opwr, odir, enable); } From 0f2da0919dac3c4afbd5323f0a94717f025a29b1 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 12 Sep 2021 16:15:53 -0500 Subject: [PATCH 17/29] Fix some cutter pins --- Marlin/src/inc/Conditionals_post.h | 4 ++-- Marlin/src/pins/mega/pins_HJC2560C_REV2.h | 4 ++-- Marlin/src/pins/ramps/pins_TT_OSCAR.h | 24 +++++++++++------------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 61a9ea2c9a8e..e14d712767a9 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -673,7 +673,7 @@ #endif // Software SPI - enable if MISO/SCK are defined. - #if PIN_EXISTS(TEMP_0_MISO) && PIN_EXISTS(TEMP_0_SCK) && DISABLED(TEMP_SENSOR_0_FORCE_HW_SPI) + #if PINS_EXIST(TEMP_0_MISO, TEMP_0_SCK) && DISABLED(TEMP_SENSOR_0_FORCE_HW_SPI) #if TEMP_SENSOR_0_IS_MAX31865 && !PIN_EXISTS(TEMP_0_MOSI) #error "TEMP_SENSOR_0 MAX31865 requires TEMP_0_MOSI_PIN defined for Software SPI. To use Hardware SPI instead, undefine MISO/SCK or enable TEMP_SENSOR_0_FORCE_HW_SPI." #else @@ -742,7 +742,7 @@ #endif // Software SPI - enable if MISO/SCK are defined. - #if PIN_EXISTS(TEMP_1_MISO) && PIN_EXISTS(TEMP_1_SCK) && DISABLED(TEMP_SENSOR_1_FORCE_HW_SPI) + #if PINS_EXIST(TEMP_1_MISO, TEMP_1_SCK) && DISABLED(TEMP_SENSOR_1_FORCE_HW_SPI) #if TEMP_SENSOR_1_IS_MAX31865 && !PIN_EXISTS(TEMP_1_MOSI) #error "TEMP_SENSOR_1 MAX31865 requires TEMP_1_MOSI_PIN defined for Software SPI. To use Hardware SPI instead, undefine MISO/SCK or enable TEMP_SENSOR_1_FORCE_HW_SPI." #else diff --git a/Marlin/src/pins/mega/pins_HJC2560C_REV2.h b/Marlin/src/pins/mega/pins_HJC2560C_REV2.h index 27ec9988918d..73d4bac47273 100644 --- a/Marlin/src/pins/mega/pins_HJC2560C_REV2.h +++ b/Marlin/src/pins/mega/pins_HJC2560C_REV2.h @@ -112,9 +112,9 @@ // // M3/M4/M5 - Spindle/Laser Control // -#if ENABLED(SPINDLE_LASER_ENABLE) +#if HAS_CUTTER #define SPINDLE_DIR_PIN 16 - #define SPINDLE_LASER_ENABLE_PIN 17 // Pin should have a pullup! + #define SPINDLE_LASER_ENA_PIN 17 // Pin should have a pullup! #define SPINDLE_LASER_PWM_PIN 9 // Hardware PWM #endif diff --git a/Marlin/src/pins/ramps/pins_TT_OSCAR.h b/Marlin/src/pins/ramps/pins_TT_OSCAR.h index a43f10fc93cd..8604eb3cf8e9 100644 --- a/Marlin/src/pins/ramps/pins_TT_OSCAR.h +++ b/Marlin/src/pins/ramps/pins_TT_OSCAR.h @@ -224,28 +224,28 @@ #endif // -// Case Light +// M3/M4/M5 - Spindle/Laser Control // -#if ENABLED(CASE_LIGHT_ENABLE) && !PIN_EXISTS(CASE_LIGHT) && !defined(SPINDLE_LASER_ENABLE_PIN) +#if HAS_CUTTER && !PIN_EXISTS(SPINDLE_LASER_ENA) #if !NUM_SERVOS // Prefer the servo connector - #define CASE_LIGHT_PIN 6 // Hardware PWM + #define SPINDLE_LASER_ENA_PIN 4 // Pullup or pulldown! + #define SPINDLE_LASER_PWM_PIN 6 // Hardware PWM + #define SPINDLE_DIR_PIN 5 #elif HAS_FREE_AUX2_PINS // Try to use AUX 2 - #define CASE_LIGHT_PIN 44 // Hardware PWM + #define SPINDLE_LASER_ENA_PIN 40 // Pullup or pulldown! + #define SPINDLE_LASER_PWM_PIN 44 // Hardware PWM + #define SPINDLE_DIR_PIN 65 #endif #endif // -// M3/M4/M5 - Spindle/Laser Control +// Case Light // -#if ENABLED(SPINDLE_LASER_ENABLE) && !PIN_EXISTS(SPINDLE_LASER_ENABLE) +#if ENABLED(CASE_LIGHT_ENABLE) && !ANY_PIN(CASE_LIGHT, SPINDLE_LASER_ENA) #if !NUM_SERVOS // Prefer the servo connector - #define SPINDLE_LASER_ENABLE_PIN 4 // Pullup or pulldown! - #define SPINDLE_LASER_PWM_PIN 6 // Hardware PWM - #define SPINDLE_DIR_PIN 5 + #define CASE_LIGHT_PIN 6 // Hardware PWM #elif HAS_FREE_AUX2_PINS // Try to use AUX 2 - #define SPINDLE_LASER_ENABLE_PIN 40 // Pullup or pulldown! - #define SPINDLE_LASER_PWM_PIN 44 // Hardware PWM - #define SPINDLE_DIR_PIN 65 + #define CASE_LIGHT_PIN 44 // Hardware PWM #endif #endif From f4ec18bfa74377c9414aca096c7d536e3f129b90 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 12 Sep 2021 16:35:43 -0500 Subject: [PATCH 18/29] Remove confusing option, add conditional --- Marlin/Configuration_adv.h | 7 ------- Marlin/src/feature/spindle_laser.cpp | 8 +------- Marlin/src/inc/Conditionals_adv.h | 3 +++ 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 821834b05a5c..6857c4063bba 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -3329,13 +3329,6 @@ #define SPINDLE_LASER_FREQUENCY 2500 // (Hz) Spindle/laser frequency (only on supported HALs: AVR and LPC) - /** - * Control ENA_PIN in PWM mode. - * If defined the ENA_PIN is disabled only by 'M5'. - * If not defined 'M3 S0' disables the ENA_PIN. - */ - //#define SPINDLE_LASER_PWM_SEPARATE_PIN - //#define AIR_EVACUATION // Cutter Vacuum / Laser Blower motor control with G-codes M10-M11 #if ENABLED(AIR_EVACUATION) #define AIR_EVACUATION_ACTIVE LOW // Set to "HIGH" if the on/off function is active HIGH diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index 9c4e60c3420e..0cb624fc2204 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -170,13 +170,7 @@ void SpindleLaser::_change_hw(const bool ena_pin_on) { void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir/*=SPINDLE_DIR_CURRENT*/, const bool ena_pin_on/*=true*/) { const uint8_t dir_value = TERN(SPINDLE_CHANGE_DIR, (odir == SPINDLE_DIR_CURRENT) ? spindle_dir : odir, SPINDLE_DIR_CW); - const bool ena_pin_on_value = ( - #if BOTH(SPINDLE_LASER_PWM, SPINDLE_LASER_PWM_SEPARATE_PIN) - ena_pin_on - #else - opwr > 0 - #endif - ); + const bool ena_pin_on_value = TERN(HAS_CUTTER_PWM_AND_ENA, ena_pin_on, opwr > 0); switch (get_event(opwr, dir_value, ena_pin_on_value)) { // Already ON and staying ON diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index 9fae92affecd..8cc3fdf3c24c 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -655,6 +655,9 @@ #define _CUTTER_POWER_RPM 3 #define _CUTTER_POWER(V) _CAT(_CUTTER_POWER_, V) #define CUTTER_UNIT_IS(V) (_CUTTER_POWER(CUTTER_POWER_UNIT) == _CUTTER_POWER(V)) + #if ENABLED(SPINDLE_LASER_PWM) && PINS_EXIST(SPINDLE_LASER_ENA, SPINDLE_LASER_PWM) + #define HAS_CUTTER_PWM_AND_ENA 1 + #endif #endif // Add features that need hardware PWM here From b988e7e53b468b250725562f3d77a9fe327dca1c Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 13 Sep 2021 16:12:41 -0500 Subject: [PATCH 19/29] SPINDLE_LASER_PWM => SPINDLE_LASER_USE_PWM --- Marlin/Configuration_adv.h | 30 ++++++++++++--------- Marlin/src/HAL/AVR/inc/SanityCheck.h | 4 +-- Marlin/src/HAL/LINUX/inc/SanityCheck.h | 2 +- Marlin/src/HAL/LPC1768/inc/SanityCheck.h | 2 +- Marlin/src/HAL/NATIVE_SIM/inc/SanityCheck.h | 2 +- Marlin/src/HAL/STM32/inc/SanityCheck.h | 2 +- Marlin/src/feature/spindle_laser.cpp | 10 +++---- Marlin/src/feature/spindle_laser.h | 18 ++++++------- Marlin/src/gcode/control/M3-M5.cpp | 6 ++--- Marlin/src/gcode/gcode.cpp | 2 +- Marlin/src/inc/Conditionals_adv.h | 4 +-- Marlin/src/inc/SanityCheck.h | 18 +++++++------ Marlin/src/lcd/menu/menu_spindle_laser.cpp | 2 +- Marlin/src/module/stepper.cpp | 4 +-- Marlin/src/pins/pinsDebug_list.h | 2 +- 15 files changed, 58 insertions(+), 50 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 6857c4063bba..f525aef30422 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -3323,11 +3323,13 @@ //#define SPINDLE_FEATURE //#define LASER_FEATURE #if EITHER(SPINDLE_FEATURE, LASER_FEATURE) - #define SPINDLE_LASER_ACTIVE_STATE LOW // Set to "HIGH" 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 false // Set to "true" if the speed/power goes up when you want it to go slower + #define SPINDLE_LASER_ACTIVE_STATE LOW // Set to "HIGH" if SPINDLE_LASER_ENA_PIN is active HIGH - #define SPINDLE_LASER_FREQUENCY 2500 // (Hz) Spindle/laser frequency (only on supported HALs: AVR and LPC) + #define SPINDLE_LASER_USE_PWM // Enable if your controller supports setting the speed/power + #if ENABLED(SPINDLE_LASER_USE_PWM) + #define SPINDLE_LASER_PWM_INVERT false // Set to "true" if the speed/power goes up when you want it to go slower + #define SPINDLE_LASER_FREQUENCY 2500 // (Hz) Spindle/laser frequency (only on supported HALs: AVR and LPC) + #endif //#define AIR_EVACUATION // Cutter Vacuum / Laser Blower motor control with G-codes M10-M11 #if ENABLED(AIR_EVACUATION) @@ -3383,17 +3385,21 @@ * Speed/Power = (PWMDC / 255 * 100 - SPEED_POWER_INTERCEPT) / SPEED_POWER_SLOPE * PWMDC = (spdpwr - SPEED_POWER_MIN) / (SPEED_POWER_MAX - SPEED_POWER_MIN) / SPEED_POWER_SLOPE */ - #define SPEED_POWER_INTERCEPT 0 // (%) 0-100 i.e., Minimum power percentage - #define SPEED_POWER_MIN 5000 // (RPM) - #define SPEED_POWER_MAX 30000 // (RPM) SuperPID router controller 0 - 30,000 RPM - #define SPEED_POWER_STARTUP 25000 // (RPM) M3/M4 speed/power default (with no arguments) + #if ENABLED(SPINDLE_LASER_USE_PWM) + #define SPEED_POWER_INTERCEPT 0 // (%) 0-100 i.e., Minimum power percentage + #define SPEED_POWER_MIN 5000 // (RPM) + #define SPEED_POWER_MAX 30000 // (RPM) SuperPID router controller 0 - 30,000 RPM + #define SPEED_POWER_STARTUP 25000 // (RPM) M3/M4 speed/power default (with no arguments) + #endif #else - #define SPEED_POWER_INTERCEPT 0 // (%) 0-100 i.e., Minimum power percentage - #define SPEED_POWER_MIN 0 // (%) 0-100 - #define SPEED_POWER_MAX 100 // (%) 0-100 - #define SPEED_POWER_STARTUP 80 // (%) M3/M4 speed/power default (with no arguments) + #if ENABLED(SPINDLE_LASER_USE_PWM) + #define SPEED_POWER_INTERCEPT 0 // (%) 0-100 i.e., Minimum power percentage + #define SPEED_POWER_MIN 0 // (%) 0-100 + #define SPEED_POWER_MAX 100 // (%) 0-100 + #define SPEED_POWER_STARTUP 80 // (%) M3/M4 speed/power default (with no arguments) + #endif // Define the minimum and maximum test pulse time values for a laser test fire function #define LASER_TEST_PULSE_MIN 1 // Used with Laser Control Menu diff --git a/Marlin/src/HAL/AVR/inc/SanityCheck.h b/Marlin/src/HAL/AVR/inc/SanityCheck.h index 51ba247953b4..79809b8f618d 100644 --- a/Marlin/src/HAL/AVR/inc/SanityCheck.h +++ b/Marlin/src/HAL/AVR/inc/SanityCheck.h @@ -35,7 +35,7 @@ /** * Sanity checks for Spindle / Laser PWM */ -#if ENABLED(SPINDLE_LASER_PWM) +#if ENABLED(SPINDLE_LASER_USE_PWM) #include "../ServoTimers.h" // Needed to check timer availability (_useTimer3) #if SPINDLE_LASER_PWM_PIN == 4 || WITHIN(SPINDLE_LASER_PWM_PIN, 11, 13) #error "Counter/Timer for SPINDLE_LASER_PWM_PIN is used by a system interrupt." @@ -43,7 +43,7 @@ #error "Counter/Timer for SPINDLE_LASER_PWM_PIN is used by the servo system." #endif #elif defined(SPINDLE_LASER_FREQUENCY) - #error "SPINDLE_LASER_FREQUENCY requires SPINDLE_LASER_PWM." + #error "SPINDLE_LASER_FREQUENCY requires SPINDLE_LASER_USE_PWM." #endif /** diff --git a/Marlin/src/HAL/LINUX/inc/SanityCheck.h b/Marlin/src/HAL/LINUX/inc/SanityCheck.h index 45bb2662ace5..36d3190a3e08 100644 --- a/Marlin/src/HAL/LINUX/inc/SanityCheck.h +++ b/Marlin/src/HAL/LINUX/inc/SanityCheck.h @@ -26,7 +26,7 @@ */ // Emulating RAMPS -#if ENABLED(SPINDLE_LASER_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11) +#if ENABLED(SPINDLE_LASER_USE_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11) #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector" #endif diff --git a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h index 23d797b2ab76..3ea054589ec3 100644 --- a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h +++ b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h @@ -67,7 +67,7 @@ static_assert(!(NUM_SERVOS && ENABLED(FAST_PWM_FAN)), "BLTOUCH and Servos are in * Test LPC176x-specific configuration values for errors at compile-time. */ -//#if ENABLED(SPINDLE_LASER_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11) +//#if ENABLED(SPINDLE_LASER_USE_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11) // #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector" //#endif diff --git a/Marlin/src/HAL/NATIVE_SIM/inc/SanityCheck.h b/Marlin/src/HAL/NATIVE_SIM/inc/SanityCheck.h index 104af9af5b20..2d7bef23a36d 100644 --- a/Marlin/src/HAL/NATIVE_SIM/inc/SanityCheck.h +++ b/Marlin/src/HAL/NATIVE_SIM/inc/SanityCheck.h @@ -26,7 +26,7 @@ */ // Emulating RAMPS -#if ENABLED(SPINDLE_LASER_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11) +#if ENABLED(SPINDLE_LASER_USE_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11) #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector" #endif diff --git a/Marlin/src/HAL/STM32/inc/SanityCheck.h b/Marlin/src/HAL/STM32/inc/SanityCheck.h index 12ff2abec7ac..0f1a2acaa41c 100644 --- a/Marlin/src/HAL/STM32/inc/SanityCheck.h +++ b/Marlin/src/HAL/STM32/inc/SanityCheck.h @@ -24,7 +24,7 @@ /** * Test STM32-specific configuration values for errors at compile-time. */ -//#if ENABLED(SPINDLE_LASER_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11) +//#if ENABLED(SPINDLE_LASER_USE_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11) // #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector" //#endif diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index 0cb624fc2204..3fba4bc66dc4 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -67,7 +67,7 @@ void SpindleLaser::init() { SET_OUTPUT(SPINDLE_DIR_PIN); dir_pin_set(); #endif - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) SET_PWM(SPINDLE_LASER_PWM_PIN); analogWrite(pin_t(SPINDLE_LASER_PWM_PIN), SPINDLE_LASER_PWM_OFF); // Set to lowest speed #endif @@ -86,7 +86,7 @@ void SpindleLaser::init() { #endif } -#if ENABLED(SPINDLE_LASER_PWM) +#if ENABLED(SPINDLE_LASER_USE_PWM) /** * Set the cutter PWM directly to the given ocr value * @@ -101,7 +101,7 @@ void SpindleLaser::init() { #endif } -#endif // SPINDLE_LASER_PWM +#endif // SPINDLE_LASER_USE_PWM /** * Set state for pin spindle/laser @@ -149,11 +149,11 @@ CutterState SpindleLaser::get_event(const uint8_t opwr, const uint8_t odir, cons * Change hardware state */ void SpindleLaser::_change_hw(const bool ena_pin_on) { - TERN_(SPINDLE_LASER_PWM, ocr_set(ocr_power)); + TERN_(SPINDLE_LASER_USE_PWM, ocr_set(ocr_power)); TERN(SPINDLE_SERVO, MOVE_SERVO(SPINDLE_SERVO_NR, ocr_power), ena_pin_set(ena_pin_on)); - #if ENABLED(SPINDLE_LASER_PWM) || DISABLED(SPINDLE_SERVO) + #if ENABLED(SPINDLE_LASER_USE_PWM) || DISABLED(SPINDLE_SERVO) isReady = ena_pin_on; // This is a hack. isReady state and ena_pin_on are equivalent. #endif } diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index fea129764469..d99af1b7e4b5 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -140,7 +140,7 @@ class SpindleLaser { static inline void dir_pin_set() {} #endif - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) static void ocr_set(const uint8_t ocr); #endif @@ -156,7 +156,7 @@ class SpindleLaser { FORCE_INLINE static void refresh() {} - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) /** * Update output for upower->OCR translation */ @@ -208,7 +208,7 @@ class SpindleLaser { } return upwr; } - #endif // SPINDLE_LASER_PWM + #endif // SPINDLE_LASER_USE_PWM /** * Enable/Disable spindle/laser @@ -218,7 +218,7 @@ class SpindleLaser { static inline void set_enabled(const bool enable, uint8_t odir=SPINDLE_DIR_CURRENT) { uint8_t opwr = 0; if (enable) { - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) if (ocr_power) opwr = ocr_power; else if (unitPower) @@ -272,7 +272,7 @@ class SpindleLaser { #if HAS_LCD_MENU static inline void enable_with_dir(const bool reverse) { isReady = true; - const uint8_t ocr = TERN(SPINDLE_LASER_PWM, upower_to_ocr(menuPower), 255); + const uint8_t ocr = TERN(SPINDLE_LASER_USE_PWM, upower_to_ocr(menuPower), 255); if (menuPower) ocr_power = ocr; else @@ -285,7 +285,7 @@ class SpindleLaser { FORCE_INLINE static void enable_reverse() { enable_with_dir(true); } FORCE_INLINE static void enable_same_dir() { enable_with_dir(is_reverse()); } - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) static inline void update_from_mpower() { if (isReady) ocr_power = upower_to_ocr(menuPower); unitPower = menuPower; @@ -331,14 +331,14 @@ class SpindleLaser { isReady = false; unitPower = menuPower = 0; planner.laser_inline.status.isPlanned = false; - TERN(SPINDLE_LASER_PWM, inline_ocr_power, inline_power)(0); + TERN(SPINDLE_LASER_USE_PWM, inline_ocr_power, inline_power)(0); } } // Set the power for subsequent movement blocks static void inline_power(const cutter_power_t upwr) { unitPower = menuPower = upwr; - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) #if ENABLED(SPEED_POWER_RELATIVE) && !CUTTER_UNIT_IS(RPM) // relative mode does not turn laser off at 0, except for RPM planner.laser_inline.status.isEnabled = true; planner.laser_inline.power = upower_to_ocr(upwr); @@ -355,7 +355,7 @@ class SpindleLaser { static inline void inline_direction(const bool) { /* never */ } - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) static inline void inline_ocr_power(const uint8_t opwr) { planner.laser_inline.status.isEnabled = isReady = opwr > 0; planner.laser_inline.power = opwr; diff --git a/Marlin/src/gcode/control/M3-M5.cpp b/Marlin/src/gcode/control/M3-M5.cpp index 9d9e8c5133e4..e13eb87a5664 100644 --- a/Marlin/src/gcode/control/M3-M5.cpp +++ b/Marlin/src/gcode/control/M3-M5.cpp @@ -72,7 +72,7 @@ void GcodeSuite::M3_M4(const bool is_M4) { #if ENABLED(SPINDLE_SERVO) cutter.unitPower = spwr; #else - cutter.unitPower = TERN(SPINDLE_LASER_PWM, + cutter.unitPower = TERN(SPINDLE_LASER_USE_PWM, cutter.power_to_range(cutter_power_t(round(spwr))), spwr > 0 ? 255 : 0); #endif @@ -86,7 +86,7 @@ void GcodeSuite::M3_M4(const bool is_M4) { if (parser.seen('I') == DISABLED(LASER_POWER_INLINE_INVERT)) { // Laser power in inline mode cutter.inline_direction(is_M4); // Should always be unused - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) if (parser.seen('O')) { cutter.unitPower = cutter.power_to_range(parser.value_byte(), 0); cutter.inline_ocr_power(cutter.unitPower); // The OCR is a value from 0 to 255 (uint8_t) @@ -106,7 +106,7 @@ void GcodeSuite::M3_M4(const bool is_M4) { uint8_t dir_value = is_M4 ? SPINDLE_DIR_CCW : SPINDLE_DIR_CW; - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) if (parser.seenval('O')) { cutter.unitPower = cutter.power_to_range(parser.value_byte(), 0); cutter.ocr_set_power(cutter.unitPower, dir_value); // The OCR is a value from 0 to 255 (uint8_t) diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 477d43ed6392..e3b90b65b301 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -215,7 +215,7 @@ void GcodeSuite::get_destination_from_command() { // Set the laser power in the planner to configure this move if (parser.seen('S')) { const float spwr = parser.value_float(); - cutter.inline_power(TERN(SPINDLE_LASER_PWM, cutter.power_to_range(cutter_power_t(round(spwr))), spwr > 0 ? 255 : 0)); + cutter.inline_power(TERN(SPINDLE_LASER_USE_PWM, cutter.power_to_range(cutter_power_t(round(spwr))), spwr > 0 ? 255 : 0)); } else if (ENABLED(LASER_MOVE_G0_OFF) && parser.codenum == 0) // G0 cutter.set_inline_enabled(false); diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index 8cc3fdf3c24c..66b259410dc2 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -655,13 +655,13 @@ #define _CUTTER_POWER_RPM 3 #define _CUTTER_POWER(V) _CAT(_CUTTER_POWER_, V) #define CUTTER_UNIT_IS(V) (_CUTTER_POWER(CUTTER_POWER_UNIT) == _CUTTER_POWER(V)) - #if ENABLED(SPINDLE_LASER_PWM) && PINS_EXIST(SPINDLE_LASER_ENA, SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) && PINS_EXIST(SPINDLE_LASER_ENA, SPINDLE_LASER_PWM) #define HAS_CUTTER_PWM_AND_ENA 1 #endif #endif // Add features that need hardware PWM here -#if ANY(FAST_PWM_FAN, SPINDLE_LASER_PWM) +#if ANY(FAST_PWM_FAN, SPINDLE_LASER_USE_PWM) #define NEEDS_HARDWARE_PWM 1 #endif diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 3c00d84142e7..ed583b458993 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -593,6 +593,8 @@ #error "ARC_SUPPORT no longer uses ARC_SEGMENTS_PER_R." #elif ENABLED(ARC_SUPPORT) && (!defined(MIN_ARC_SEGMENT_MM) || !defined(MAX_ARC_SEGMENT_MM)) #error "ARC_SUPPORT now requires MIN_ARC_SEGMENT_MM and MAX_ARC_SEGMENT_MM." +#elif defined(SPINDLE_LASER_PWM) + #error "SPINDLE_LASER_PWM (true) is now set with SPINDLE_LASER_USE_PWM (enabled)." #endif #if MOTHERBOARD == BOARD_DUE3DOM_MINI && PIN_EXISTS(TEMP_2) && DISABLED(TEMP_SENSOR_BOARD) @@ -3554,8 +3556,8 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2) #error "LASER_MOVE_G0_OFF requires LASER_MOVE_POWER." #endif #if ENABLED(LASER_POWER_INLINE_TRAPEZOID) - #if DISABLED(SPINDLE_LASER_PWM) - #error "LASER_POWER_INLINE_TRAPEZOID requires SPINDLE_LASER_PWM to function." + #if DISABLED(SPINDLE_LASER_USE_PWM) + #error "LASER_POWER_INLINE_TRAPEZOID requires SPINDLE_LASER_USE_PWM to function." #elif ENABLED(S_CURVE_ACCELERATION) //#ifndef LASER_POWER_INLINE_S_CURVE_ACCELERATION_WARN // #define LASER_POWER_INLINE_S_CURVE_ACCELERATION_WARN @@ -3587,21 +3589,21 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2) #error "(SPINDLE|LASER)_FEATURE requires SPINDLE_LASER_ENA_PIN or SPINDLE_SERVO to control the power." #elif ENABLED(SPINDLE_CHANGE_DIR) && !PIN_EXISTS(SPINDLE_DIR) #error "SPINDLE_DIR_PIN is required for SPINDLE_CHANGE_DIR." - #elif ENABLED(SPINDLE_LASER_PWM) + #elif ENABLED(SPINDLE_LASER_USE_PWM) #if !defined(SPINDLE_LASER_PWM_PIN) || SPINDLE_LASER_PWM_PIN < 0 - #error "SPINDLE_LASER_PWM_PIN is required for SPINDLE_LASER_PWM." + #error "SPINDLE_LASER_PWM_PIN is required for SPINDLE_LASER_USE_PWM." #elif !_TEST_PWM(SPINDLE_LASER_PWM_PIN) #error "SPINDLE_LASER_PWM_PIN not assigned to a PWM pin." #elif !defined(SPINDLE_LASER_PWM_INVERT) #error "SPINDLE_LASER_PWM_INVERT is required for (SPINDLE|LASER)_FEATURE." #elif !(defined(SPEED_POWER_INTERCEPT) && defined(SPEED_POWER_MIN) && defined(SPEED_POWER_MAX) && defined(SPEED_POWER_STARTUP)) - #error "SPINDLE_LASER_PWM equation constant(s) missing." + #error "SPINDLE_LASER_USE_PWM equation constant(s) missing." #elif _PIN_CONFLICT(X_MIN) - #error "SPINDLE_LASER_PWM pin conflicts with X_MIN_PIN." + #error "SPINDLE_LASER_USE_PWM pin conflicts with X_MIN_PIN." #elif _PIN_CONFLICT(X_MAX) - #error "SPINDLE_LASER_PWM pin conflicts with X_MAX_PIN." + #error "SPINDLE_LASER_USE_PWM pin conflicts with X_MAX_PIN." #elif _PIN_CONFLICT(Z_STEP) - #error "SPINDLE_LASER_PWM pin conflicts with Z_STEP_PIN." + #error "SPINDLE_LASER_USE_PWM pin conflicts with Z_STEP_PIN." #elif _PIN_CONFLICT(CASE_LIGHT) #error "SPINDLE_LASER_PWM_PIN conflicts with CASE_LIGHT_PIN." #elif _PIN_CONFLICT(E0_AUTO_FAN) diff --git a/Marlin/src/lcd/menu/menu_spindle_laser.cpp b/Marlin/src/lcd/menu/menu_spindle_laser.cpp index a28c614c91ae..26f555ad620d 100644 --- a/Marlin/src/lcd/menu/menu_spindle_laser.cpp +++ b/Marlin/src/lcd/menu/menu_spindle_laser.cpp @@ -41,7 +41,7 @@ START_MENU(); BACK_ITEM(MSG_MAIN); - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) // Change the cutter's "current power" value without turning the cutter on or off // Power is displayed and set in units and range according to CUTTER_POWER_UNIT EDIT_ITEM_FAST(CUTTER_MENU_POWER_TYPE, MSG_CUTTER(POWER), &cutter.menuPower, diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 561b884f9794..9953ecf6dbf5 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -2255,7 +2255,7 @@ uint32_t Stepper::block_phase_isr() { } #else if (stat.isPlanned) { // Planner controls the laser - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) cutter.ocr_set_power( stat.isEnabled ? current_block->laser.power : 0 // ON with power or OFF ); @@ -2303,7 +2303,7 @@ uint32_t Stepper::block_phase_isr() { // This should mean ending file with 'M5 I' will stop the laser; thus the inline flag isn't needed const power_status_t stat = planner.laser_inline.status; if (stat.isPlanned) { // Planner controls the laser - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) cutter.ocr_set_power( stat.isEnabled ? planner.laser_inline.power : 0 // ON with power or OFF ); diff --git a/Marlin/src/pins/pinsDebug_list.h b/Marlin/src/pins/pinsDebug_list.h index 501ae921c217..e12835bd5194 100644 --- a/Marlin/src/pins/pinsDebug_list.h +++ b/Marlin/src/pins/pinsDebug_list.h @@ -996,7 +996,7 @@ #if PIN_EXISTS(SPINDLE_LASER_ENA) REPORT_NAME_DIGITAL(__LINE__, SPINDLE_LASER_ENA_PIN) #endif -#if PIN_EXISTS(SPINDLE_LASER_PWM) +#if PIN_EXISTS(SPINDLE_LASER_USE_PWM) REPORT_NAME_DIGITAL(__LINE__, SPINDLE_LASER_PWM_PIN) #endif #if PIN_EXISTS(SR_CLK) From 1a9c0f1f7e3c68306be96ca66322b7106efff6cd Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 13 Sep 2021 16:28:12 -0500 Subject: [PATCH 20/29] SPINDLE_LASER_PWM => SPINDLE_LASER_USE_PWM --- Marlin/Configuration_adv.h | 30 ++++++++++++--------- Marlin/src/HAL/AVR/inc/SanityCheck.h | 4 +-- Marlin/src/HAL/LINUX/inc/SanityCheck.h | 2 +- Marlin/src/HAL/LPC1768/inc/SanityCheck.h | 2 +- Marlin/src/HAL/NATIVE_SIM/inc/SanityCheck.h | 2 +- Marlin/src/HAL/STM32/inc/SanityCheck.h | 2 +- Marlin/src/feature/spindle_laser.cpp | 8 +++--- Marlin/src/feature/spindle_laser.h | 16 +++++------ Marlin/src/gcode/control/M3-M5.cpp | 6 ++--- Marlin/src/gcode/gcode.cpp | 2 +- Marlin/src/inc/Conditionals_adv.h | 2 +- Marlin/src/inc/SanityCheck.h | 18 +++++++------ Marlin/src/lcd/menu/menu_spindle_laser.cpp | 2 +- Marlin/src/module/stepper.cpp | 4 +-- Marlin/src/module/stepper.h | 6 ++--- 15 files changed, 57 insertions(+), 49 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 6857c4063bba..f525aef30422 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -3323,11 +3323,13 @@ //#define SPINDLE_FEATURE //#define LASER_FEATURE #if EITHER(SPINDLE_FEATURE, LASER_FEATURE) - #define SPINDLE_LASER_ACTIVE_STATE LOW // Set to "HIGH" 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 false // Set to "true" if the speed/power goes up when you want it to go slower + #define SPINDLE_LASER_ACTIVE_STATE LOW // Set to "HIGH" if SPINDLE_LASER_ENA_PIN is active HIGH - #define SPINDLE_LASER_FREQUENCY 2500 // (Hz) Spindle/laser frequency (only on supported HALs: AVR and LPC) + #define SPINDLE_LASER_USE_PWM // Enable if your controller supports setting the speed/power + #if ENABLED(SPINDLE_LASER_USE_PWM) + #define SPINDLE_LASER_PWM_INVERT false // Set to "true" if the speed/power goes up when you want it to go slower + #define SPINDLE_LASER_FREQUENCY 2500 // (Hz) Spindle/laser frequency (only on supported HALs: AVR and LPC) + #endif //#define AIR_EVACUATION // Cutter Vacuum / Laser Blower motor control with G-codes M10-M11 #if ENABLED(AIR_EVACUATION) @@ -3383,17 +3385,21 @@ * Speed/Power = (PWMDC / 255 * 100 - SPEED_POWER_INTERCEPT) / SPEED_POWER_SLOPE * PWMDC = (spdpwr - SPEED_POWER_MIN) / (SPEED_POWER_MAX - SPEED_POWER_MIN) / SPEED_POWER_SLOPE */ - #define SPEED_POWER_INTERCEPT 0 // (%) 0-100 i.e., Minimum power percentage - #define SPEED_POWER_MIN 5000 // (RPM) - #define SPEED_POWER_MAX 30000 // (RPM) SuperPID router controller 0 - 30,000 RPM - #define SPEED_POWER_STARTUP 25000 // (RPM) M3/M4 speed/power default (with no arguments) + #if ENABLED(SPINDLE_LASER_USE_PWM) + #define SPEED_POWER_INTERCEPT 0 // (%) 0-100 i.e., Minimum power percentage + #define SPEED_POWER_MIN 5000 // (RPM) + #define SPEED_POWER_MAX 30000 // (RPM) SuperPID router controller 0 - 30,000 RPM + #define SPEED_POWER_STARTUP 25000 // (RPM) M3/M4 speed/power default (with no arguments) + #endif #else - #define SPEED_POWER_INTERCEPT 0 // (%) 0-100 i.e., Minimum power percentage - #define SPEED_POWER_MIN 0 // (%) 0-100 - #define SPEED_POWER_MAX 100 // (%) 0-100 - #define SPEED_POWER_STARTUP 80 // (%) M3/M4 speed/power default (with no arguments) + #if ENABLED(SPINDLE_LASER_USE_PWM) + #define SPEED_POWER_INTERCEPT 0 // (%) 0-100 i.e., Minimum power percentage + #define SPEED_POWER_MIN 0 // (%) 0-100 + #define SPEED_POWER_MAX 100 // (%) 0-100 + #define SPEED_POWER_STARTUP 80 // (%) M3/M4 speed/power default (with no arguments) + #endif // Define the minimum and maximum test pulse time values for a laser test fire function #define LASER_TEST_PULSE_MIN 1 // Used with Laser Control Menu diff --git a/Marlin/src/HAL/AVR/inc/SanityCheck.h b/Marlin/src/HAL/AVR/inc/SanityCheck.h index 51ba247953b4..79809b8f618d 100644 --- a/Marlin/src/HAL/AVR/inc/SanityCheck.h +++ b/Marlin/src/HAL/AVR/inc/SanityCheck.h @@ -35,7 +35,7 @@ /** * Sanity checks for Spindle / Laser PWM */ -#if ENABLED(SPINDLE_LASER_PWM) +#if ENABLED(SPINDLE_LASER_USE_PWM) #include "../ServoTimers.h" // Needed to check timer availability (_useTimer3) #if SPINDLE_LASER_PWM_PIN == 4 || WITHIN(SPINDLE_LASER_PWM_PIN, 11, 13) #error "Counter/Timer for SPINDLE_LASER_PWM_PIN is used by a system interrupt." @@ -43,7 +43,7 @@ #error "Counter/Timer for SPINDLE_LASER_PWM_PIN is used by the servo system." #endif #elif defined(SPINDLE_LASER_FREQUENCY) - #error "SPINDLE_LASER_FREQUENCY requires SPINDLE_LASER_PWM." + #error "SPINDLE_LASER_FREQUENCY requires SPINDLE_LASER_USE_PWM." #endif /** diff --git a/Marlin/src/HAL/LINUX/inc/SanityCheck.h b/Marlin/src/HAL/LINUX/inc/SanityCheck.h index 45bb2662ace5..36d3190a3e08 100644 --- a/Marlin/src/HAL/LINUX/inc/SanityCheck.h +++ b/Marlin/src/HAL/LINUX/inc/SanityCheck.h @@ -26,7 +26,7 @@ */ // Emulating RAMPS -#if ENABLED(SPINDLE_LASER_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11) +#if ENABLED(SPINDLE_LASER_USE_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11) #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector" #endif diff --git a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h index 23d797b2ab76..3ea054589ec3 100644 --- a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h +++ b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h @@ -67,7 +67,7 @@ static_assert(!(NUM_SERVOS && ENABLED(FAST_PWM_FAN)), "BLTOUCH and Servos are in * Test LPC176x-specific configuration values for errors at compile-time. */ -//#if ENABLED(SPINDLE_LASER_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11) +//#if ENABLED(SPINDLE_LASER_USE_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11) // #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector" //#endif diff --git a/Marlin/src/HAL/NATIVE_SIM/inc/SanityCheck.h b/Marlin/src/HAL/NATIVE_SIM/inc/SanityCheck.h index 104af9af5b20..2d7bef23a36d 100644 --- a/Marlin/src/HAL/NATIVE_SIM/inc/SanityCheck.h +++ b/Marlin/src/HAL/NATIVE_SIM/inc/SanityCheck.h @@ -26,7 +26,7 @@ */ // Emulating RAMPS -#if ENABLED(SPINDLE_LASER_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11) +#if ENABLED(SPINDLE_LASER_USE_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11) #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector" #endif diff --git a/Marlin/src/HAL/STM32/inc/SanityCheck.h b/Marlin/src/HAL/STM32/inc/SanityCheck.h index 12ff2abec7ac..0f1a2acaa41c 100644 --- a/Marlin/src/HAL/STM32/inc/SanityCheck.h +++ b/Marlin/src/HAL/STM32/inc/SanityCheck.h @@ -24,7 +24,7 @@ /** * Test STM32-specific configuration values for errors at compile-time. */ -//#if ENABLED(SPINDLE_LASER_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11) +//#if ENABLED(SPINDLE_LASER_USE_PWM) && !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11) // #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector" //#endif diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index 68a84e1aba7c..ea6fc4990e95 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -64,7 +64,7 @@ void SpindleLaser::init() { #if ENABLED(SPINDLE_CHANGE_DIR) OUT_WRITE(SPINDLE_DIR_PIN, SPINDLE_INVERT_DIR ? 255 : 0); // Init rotation to clockwise (M3) #endif - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) SET_PWM(SPINDLE_LASER_PWM_PIN); analogWrite(pin_t(SPINDLE_LASER_PWM_PIN), SPINDLE_LASER_PWM_OFF); // Set to lowest speed #endif @@ -83,7 +83,7 @@ void SpindleLaser::init() { #endif } -#if ENABLED(SPINDLE_LASER_PWM) +#if ENABLED(SPINDLE_LASER_USE_PWM) /** * Set the cutter PWM directly to the given ocr value * @@ -107,7 +107,7 @@ void SpindleLaser::init() { WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ACTIVE_STATE); // Cutter OFF _set_ocr(0); } -#endif // SPINDLE_LASER_PWM +#endif // SPINDLE_LASER_USE_PWM /** * Apply power for laser/spindle @@ -121,7 +121,7 @@ void SpindleLaser::apply_power(const uint8_t opwr) { if (opwr == last_power_applied) return; last_power_applied = opwr; power = opwr; - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) if (cutter.unitPower == 0 && CUTTER_UNIT_IS(RPM)) { ocr_off(); isReady = false; diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index 9a2d05c79d16..ba82c4d7319a 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -123,7 +123,7 @@ class SpindleLaser { FORCE_INLINE static void refresh() { apply_power(power); } FORCE_INLINE static void set_power(const uint8_t upwr) { power = upwr; refresh(); } - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) private: @@ -186,7 +186,7 @@ class SpindleLaser { } return upwr; } - #endif // SPINDLE_LASER_PWM + #endif // SPINDLE_LASER_USE_PWM /** * Enable/Disable spindle/laser @@ -195,7 +195,7 @@ class SpindleLaser { static inline void set_enabled(const bool enable) { uint8_t value = 0; if (enable) { - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) if (power) value = power; else if (unitPower) @@ -249,7 +249,7 @@ class SpindleLaser { #if HAS_LCD_MENU static inline void enable_with_dir(const bool reverse) { isReady = true; - const uint8_t ocr = TERN(SPINDLE_LASER_PWM, upower_to_ocr(menuPower), 255); + const uint8_t ocr = TERN(SPINDLE_LASER_USE_PWM, upower_to_ocr(menuPower), 255); if (menuPower) power = ocr; else @@ -262,7 +262,7 @@ class SpindleLaser { FORCE_INLINE static void enable_reverse() { enable_with_dir(true); } FORCE_INLINE static void enable_same_dir() { enable_with_dir(is_reverse()); } - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) static inline void update_from_mpower() { if (isReady) power = upower_to_ocr(menuPower); unitPower = menuPower; @@ -308,14 +308,14 @@ class SpindleLaser { isReady = false; unitPower = menuPower = 0; planner.laser_inline.status.isPlanned = false; - TERN(SPINDLE_LASER_PWM, inline_ocr_power, inline_power)(0); + TERN(SPINDLE_LASER_USE_PWM, inline_ocr_power, inline_power)(0); } } // Set the power for subsequent movement blocks static void inline_power(const cutter_power_t upwr) { unitPower = menuPower = upwr; - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) #if ENABLED(SPEED_POWER_RELATIVE) && !CUTTER_UNIT_IS(RPM) // relative mode does not turn laser off at 0, except for RPM planner.laser_inline.status.isEnabled = true; planner.laser_inline.power = upower_to_ocr(upwr); @@ -332,7 +332,7 @@ class SpindleLaser { static inline void inline_direction(const bool) { /* never */ } - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) static inline void inline_ocr_power(const uint8_t ocrpwr) { isReady = ocrpwr > 0; planner.laser_inline.status.isEnabled = ocrpwr > 0; diff --git a/Marlin/src/gcode/control/M3-M5.cpp b/Marlin/src/gcode/control/M3-M5.cpp index ff5ab5086e3b..ecae8b06c69f 100644 --- a/Marlin/src/gcode/control/M3-M5.cpp +++ b/Marlin/src/gcode/control/M3-M5.cpp @@ -72,7 +72,7 @@ void GcodeSuite::M3_M4(const bool is_M4) { #if ENABLED(SPINDLE_SERVO) cutter.unitPower = spwr; #else - cutter.unitPower = TERN(SPINDLE_LASER_PWM, + cutter.unitPower = TERN(SPINDLE_LASER_USE_PWM, cutter.power_to_range(cutter_power_t(round(spwr))), spwr > 0 ? 255 : 0); #endif @@ -86,7 +86,7 @@ void GcodeSuite::M3_M4(const bool is_M4) { if (parser.seen('I') == DISABLED(LASER_POWER_INLINE_INVERT)) { // Laser power in inline mode cutter.inline_direction(is_M4); // Should always be unused - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) if (parser.seen('O')) { cutter.unitPower = cutter.power_to_range(parser.value_byte(), 0); cutter.inline_ocr_power(cutter.unitPower); // The OCR is a value from 0 to 255 (uint8_t) @@ -105,7 +105,7 @@ void GcodeSuite::M3_M4(const bool is_M4) { planner.synchronize(); // Wait for previous movement commands (G0/G0/G2/G3) to complete before changing power cutter.set_reverse(is_M4); - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) if (parser.seenval('O')) { cutter.unitPower = cutter.power_to_range(parser.value_byte(), 0); cutter.ocr_set_power(cutter.unitPower); // The OCR is a value from 0 to 255 (uint8_t) diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 477d43ed6392..e3b90b65b301 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -215,7 +215,7 @@ void GcodeSuite::get_destination_from_command() { // Set the laser power in the planner to configure this move if (parser.seen('S')) { const float spwr = parser.value_float(); - cutter.inline_power(TERN(SPINDLE_LASER_PWM, cutter.power_to_range(cutter_power_t(round(spwr))), spwr > 0 ? 255 : 0)); + cutter.inline_power(TERN(SPINDLE_LASER_USE_PWM, cutter.power_to_range(cutter_power_t(round(spwr))), spwr > 0 ? 255 : 0)); } else if (ENABLED(LASER_MOVE_G0_OFF) && parser.codenum == 0) // G0 cutter.set_inline_enabled(false); diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index 9fae92affecd..94332c926886 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -658,7 +658,7 @@ #endif // Add features that need hardware PWM here -#if ANY(FAST_PWM_FAN, SPINDLE_LASER_PWM) +#if ANY(FAST_PWM_FAN, SPINDLE_LASER_USE_PWM) #define NEEDS_HARDWARE_PWM 1 #endif diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 5e627ff79c38..ab8b252ba6cd 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -593,6 +593,8 @@ #error "ARC_SUPPORT no longer uses ARC_SEGMENTS_PER_R." #elif ENABLED(ARC_SUPPORT) && (!defined(MIN_ARC_SEGMENT_MM) || !defined(MAX_ARC_SEGMENT_MM)) #error "ARC_SUPPORT now requires MIN_ARC_SEGMENT_MM and MAX_ARC_SEGMENT_MM." +#elif defined(SPINDLE_LASER_PWM) + #error "SPINDLE_LASER_PWM (true) is now set with SPINDLE_LASER_USE_PWM (enabled)." #endif #if MOTHERBOARD == BOARD_DUE3DOM_MINI && PIN_EXISTS(TEMP_2) && DISABLED(TEMP_SENSOR_BOARD) @@ -3558,8 +3560,8 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2) #error "LASER_MOVE_G0_OFF requires LASER_MOVE_POWER." #endif #if ENABLED(LASER_POWER_INLINE_TRAPEZOID) - #if DISABLED(SPINDLE_LASER_PWM) - #error "LASER_POWER_INLINE_TRAPEZOID requires SPINDLE_LASER_PWM to function." + #if DISABLED(SPINDLE_LASER_USE_PWM) + #error "LASER_POWER_INLINE_TRAPEZOID requires SPINDLE_LASER_USE_PWM to function." #elif ENABLED(S_CURVE_ACCELERATION) //#ifndef LASER_POWER_INLINE_S_CURVE_ACCELERATION_WARN // #define LASER_POWER_INLINE_S_CURVE_ACCELERATION_WARN @@ -3591,21 +3593,21 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2) #error "(SPINDLE|LASER)_FEATURE requires SPINDLE_LASER_ENA_PIN or SPINDLE_SERVO to control the power." #elif ENABLED(SPINDLE_CHANGE_DIR) && !PIN_EXISTS(SPINDLE_DIR) #error "SPINDLE_DIR_PIN is required for SPINDLE_CHANGE_DIR." - #elif ENABLED(SPINDLE_LASER_PWM) + #elif ENABLED(SPINDLE_LASER_USE_PWM) #if !defined(SPINDLE_LASER_PWM_PIN) || SPINDLE_LASER_PWM_PIN < 0 - #error "SPINDLE_LASER_PWM_PIN is required for SPINDLE_LASER_PWM." + #error "SPINDLE_LASER_PWM_PIN is required for SPINDLE_LASER_USE_PWM." #elif !_TEST_PWM(SPINDLE_LASER_PWM_PIN) #error "SPINDLE_LASER_PWM_PIN not assigned to a PWM pin." #elif !defined(SPINDLE_LASER_PWM_INVERT) #error "SPINDLE_LASER_PWM_INVERT is required for (SPINDLE|LASER)_FEATURE." #elif !(defined(SPEED_POWER_INTERCEPT) && defined(SPEED_POWER_MIN) && defined(SPEED_POWER_MAX) && defined(SPEED_POWER_STARTUP)) - #error "SPINDLE_LASER_PWM equation constant(s) missing." + #error "SPINDLE_LASER_USE_PWM equation constant(s) missing." #elif _PIN_CONFLICT(X_MIN) - #error "SPINDLE_LASER_PWM pin conflicts with X_MIN_PIN." + #error "SPINDLE_LASER_USE_PWM pin conflicts with X_MIN_PIN." #elif _PIN_CONFLICT(X_MAX) - #error "SPINDLE_LASER_PWM pin conflicts with X_MAX_PIN." + #error "SPINDLE_LASER_USE_PWM pin conflicts with X_MAX_PIN." #elif _PIN_CONFLICT(Z_STEP) - #error "SPINDLE_LASER_PWM pin conflicts with Z_STEP_PIN." + #error "SPINDLE_LASER_USE_PWM pin conflicts with Z_STEP_PIN." #elif _PIN_CONFLICT(CASE_LIGHT) #error "SPINDLE_LASER_PWM_PIN conflicts with CASE_LIGHT_PIN." #elif _PIN_CONFLICT(E0_AUTO_FAN) diff --git a/Marlin/src/lcd/menu/menu_spindle_laser.cpp b/Marlin/src/lcd/menu/menu_spindle_laser.cpp index a28c614c91ae..26f555ad620d 100644 --- a/Marlin/src/lcd/menu/menu_spindle_laser.cpp +++ b/Marlin/src/lcd/menu/menu_spindle_laser.cpp @@ -41,7 +41,7 @@ START_MENU(); BACK_ITEM(MSG_MAIN); - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) // Change the cutter's "current power" value without turning the cutter on or off // Power is displayed and set in units and range according to CUTTER_POWER_UNIT EDIT_ITEM_FAST(CUTTER_MENU_POWER_TYPE, MSG_CUTTER(POWER), &cutter.menuPower, diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index aea5f88c06a8..83aa15063b8a 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -2255,7 +2255,7 @@ uint32_t Stepper::block_phase_isr() { } #else if (stat.isPlanned) { // Planner controls the laser - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) cutter.ocr_set_power( stat.isEnabled ? current_block->laser.power : 0 // ON with power or OFF ); @@ -2303,7 +2303,7 @@ uint32_t Stepper::block_phase_isr() { // This should mean ending file with 'M5 I' will stop the laser; thus the inline flag isn't needed const power_status_t stat = planner.laser_inline.status; if (stat.isPlanned) { // Planner controls the laser - #if ENABLED(SPINDLE_LASER_PWM) + #if ENABLED(SPINDLE_LASER_USE_PWM) cutter.ocr_set_power( stat.isEnabled ? planner.laser_inline.power : 0 // ON with power or OFF ); diff --git a/Marlin/src/module/stepper.h b/Marlin/src/module/stepper.h index 236ba5ee9847..d2f42b63fc11 100644 --- a/Marlin/src/module/stepper.h +++ b/Marlin/src/module/stepper.h @@ -372,11 +372,11 @@ class Stepper { uint8_t cur_power; // Current laser power bool cruise_set; // Power set up for cruising? - #if DISABLED(LASER_POWER_INLINE_TRAPEZOID_CONT) + #if ENABLED(LASER_POWER_INLINE_TRAPEZOID_CONT) + uint16_t till_update; // Countdown to the next update + #else uint32_t last_step_count, // Step count from the last update acc_step_count; // Bresenham counter for laser accel/decel - #else - uint16_t till_update; // Countdown to the next update #endif } stepper_laser_t; From a504fd7bcf62d0e0104a3325838f1dffe72bb3ae Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 13 Sep 2021 16:48:57 -0500 Subject: [PATCH 21/29] merge followup --- Marlin/src/pins/pinsDebug_list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/pins/pinsDebug_list.h b/Marlin/src/pins/pinsDebug_list.h index e12835bd5194..501ae921c217 100644 --- a/Marlin/src/pins/pinsDebug_list.h +++ b/Marlin/src/pins/pinsDebug_list.h @@ -996,7 +996,7 @@ #if PIN_EXISTS(SPINDLE_LASER_ENA) REPORT_NAME_DIGITAL(__LINE__, SPINDLE_LASER_ENA_PIN) #endif -#if PIN_EXISTS(SPINDLE_LASER_USE_PWM) +#if PIN_EXISTS(SPINDLE_LASER_PWM) REPORT_NAME_DIGITAL(__LINE__, SPINDLE_LASER_PWM_PIN) #endif #if PIN_EXISTS(SR_CLK) From f66135d9fe955e6887842f572dd912e842b27c5d Mon Sep 17 00:00:00 2001 From: Alexey Matveev Date: Tue, 14 Sep 2021 16:17:32 +0300 Subject: [PATCH 22/29] PWM value setting only when laser is on --- Marlin/src/module/stepper.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 9953ecf6dbf5..cbc95ca849b1 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -2070,7 +2070,8 @@ uint32_t Stepper::block_phase_isr() { // For non-inline cutter, grossly apply power #if ENABLED(LASER_FEATURE) && DISABLED(LASER_POWER_INLINE) - cutter.ocr_set_power(current_block->cutter_ocr_power); + if (cutter.enabled()) + cutter.ocr_set_power(current_block->cutter_ocr_power); #endif TERN_(POWER_LOSS_RECOVERY, recovery.info.sdpos = current_block->sdpos); From 352c94a42d25a6be317271757dc5c436b1a483ec Mon Sep 17 00:00:00 2001 From: Alexey Matveev Date: Tue, 14 Sep 2021 23:11:10 +0300 Subject: [PATCH 23/29] Test added BigTreeTech SKR Pro | Laser (one ENA PIN) --- buildroot/tests/BIGTREE_SKR_PRO | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/buildroot/tests/BIGTREE_SKR_PRO b/buildroot/tests/BIGTREE_SKR_PRO index 2503b28544ad..d8ff872c9b15 100755 --- a/buildroot/tests/BIGTREE_SKR_PRO +++ b/buildroot/tests/BIGTREE_SKR_PRO @@ -31,3 +31,15 @@ exec_test $1 $2 "BigTreeTech SKR Pro | Laser (Percent) | Cooling | LCD" "$3" # clean up restore_configs + +# +# Test Laser features [When use only one ENA PIN] +# + +opt_enable LASER_FEATURE +opt_disable SPINDLE_LASER_USE_PWM + +exec_test $1 $2 "BigTreeTech SKR Pro | Laser (one ENA PIN)" "$3" + +# clean up +restore_configs From daf81d3a227014672a53c382177ff4bc18b5e721 Mon Sep 17 00:00:00 2001 From: Alexey Matveev Date: Tue, 14 Sep 2021 23:18:21 +0300 Subject: [PATCH 24/29] miss --- buildroot/tests/BIGTREE_SKR_PRO | 2 ++ 1 file changed, 2 insertions(+) diff --git a/buildroot/tests/BIGTREE_SKR_PRO b/buildroot/tests/BIGTREE_SKR_PRO index d8ff872c9b15..2c371b047c37 100755 --- a/buildroot/tests/BIGTREE_SKR_PRO +++ b/buildroot/tests/BIGTREE_SKR_PRO @@ -36,6 +36,8 @@ restore_configs # Test Laser features [When use only one ENA PIN] # +opt_set MOTHERBOARD BOARD_BTT_SKR_PRO_V1_1 SERIAL_PORT 1 + opt_enable LASER_FEATURE opt_disable SPINDLE_LASER_USE_PWM From 2c163ed44ccfa0f2a94d1ed4c5de7a6c156daf12 Mon Sep 17 00:00:00 2001 From: Alexey Matveev Date: Tue, 14 Sep 2021 23:33:14 +0300 Subject: [PATCH 25/29] miss --- buildroot/tests/BIGTREE_SKR_PRO | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildroot/tests/BIGTREE_SKR_PRO b/buildroot/tests/BIGTREE_SKR_PRO index 2c371b047c37..1ee22ae2b702 100755 --- a/buildroot/tests/BIGTREE_SKR_PRO +++ b/buildroot/tests/BIGTREE_SKR_PRO @@ -37,7 +37,7 @@ restore_configs # opt_set MOTHERBOARD BOARD_BTT_SKR_PRO_V1_1 SERIAL_PORT 1 - +opt_set SPINDLE_LASER_ENA_PIN opt_enable LASER_FEATURE opt_disable SPINDLE_LASER_USE_PWM From 090987860b214de1f941b1d28497592ed883c60c Mon Sep 17 00:00:00 2001 From: Alexey Matveev Date: Tue, 14 Sep 2021 23:57:09 +0300 Subject: [PATCH 26/29] reset --- buildroot/tests/BIGTREE_SKR_PRO | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/buildroot/tests/BIGTREE_SKR_PRO b/buildroot/tests/BIGTREE_SKR_PRO index 1ee22ae2b702..2503b28544ad 100755 --- a/buildroot/tests/BIGTREE_SKR_PRO +++ b/buildroot/tests/BIGTREE_SKR_PRO @@ -31,17 +31,3 @@ exec_test $1 $2 "BigTreeTech SKR Pro | Laser (Percent) | Cooling | LCD" "$3" # clean up restore_configs - -# -# Test Laser features [When use only one ENA PIN] -# - -opt_set MOTHERBOARD BOARD_BTT_SKR_PRO_V1_1 SERIAL_PORT 1 -opt_set SPINDLE_LASER_ENA_PIN -opt_enable LASER_FEATURE -opt_disable SPINDLE_LASER_USE_PWM - -exec_test $1 $2 "BigTreeTech SKR Pro | Laser (one ENA PIN)" "$3" - -# clean up -restore_configs From 78811872e2dc57a7433a4c317b1c8cb8ad009a48 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 15 Sep 2021 20:07:51 -0500 Subject: [PATCH 27/29] Use enum for spindle direction --- Marlin/src/feature/spindle_laser.cpp | 50 ++++++++++++++-------------- Marlin/src/feature/spindle_laser.h | 20 +++++------ Marlin/src/gcode/control/M3-M5.cpp | 4 +-- 3 files changed, 36 insertions(+), 38 deletions(-) diff --git a/Marlin/src/feature/spindle_laser.cpp b/Marlin/src/feature/spindle_laser.cpp index 3fba4bc66dc4..113d1e10d639 100644 --- a/Marlin/src/feature/spindle_laser.cpp +++ b/Marlin/src/feature/spindle_laser.cpp @@ -39,18 +39,18 @@ #endif SpindleLaser cutter; -uint8_t SpindleLaser::ocr_power = 0; // Startup disable -uint8_t SpindleLaser::spindle_dir = SPINDLE_DIR_CW; // Startup clockwise -CutterState SpindleLaser::state = STAY_OFF; // Startup OFF +uint8_t SpindleLaser::ocr_power = 0; // Startup disable +SpindleDir SpindleLaser::spindle_dir = SpindleDirCW; // Startup clockwise +CutterState SpindleLaser::state = STAY_OFF; // Startup OFF #if ENABLED(LASER_FEATURE) - cutter_test_pulse_t SpindleLaser::testPulse = 50; // Test fire Pulse time ms value. + cutter_test_pulse_t SpindleLaser::testPulse = 50; // Test fire Pulse time ms value. #endif -bool SpindleLaser::isReady; // Ready to apply power setting from the UI to OCR -cutter_power_t SpindleLaser::menuPower, // Power set via LCD menu in PWM, PERCENT, or RPM - SpindleLaser::unitPower; // LCD status power in PWM, PERCENT, or RPM +bool SpindleLaser::isReady; // Ready to apply power setting from the UI to OCR +cutter_power_t SpindleLaser::menuPower, // Power set via LCD menu in PWM, PERCENT, or RPM + SpindleLaser::unitPower; // LCD status power in PWM, PERCENT, or RPM #if ENABLED(MARLIN_DEV_MODE) - cutter_frequency_t SpindleLaser::frequency; // PWM frequency setting; range: 2K - 50K + cutter_frequency_t SpindleLaser::frequency; // PWM frequency setting; range: 2K - 50K #endif #define SPINDLE_LASER_PWM_OFF TERN(SPINDLE_LASER_PWM_INVERT, 255, 0) @@ -117,7 +117,7 @@ void SpindleLaser::ena_pin_set(const bool enable) { */ void SpindleLaser::dir_pin_set() { // Forward (M3) HIGH when not inverted - const uint8_t dir_state = (spindle_dir == TERN(SPINDLE_INVERT_DIR, SPINDLE_DIR_CCW, SPINDLE_DIR_CW)) ? HIGH : LOW; + const uint8_t dir_state = (spindle_dir == TERN(SPINDLE_INVERT_DIR, SpindleDirCCW, SpindleDirCW)) ? HIGH : LOW; WRITE(SPINDLE_DIR_PIN, dir_state); } #endif @@ -129,18 +129,18 @@ void SpindleLaser::ena_pin_set(const bool enable) { * @param odir New direction spindle * @param oena_pin_on New ena_pin state */ -CutterState SpindleLaser::get_event(const uint8_t opwr, const uint8_t odir, const bool oena_pin_on) { +CutterState SpindleLaser::get_event(const uint8_t opwr, const SpindleDir odir, const bool oena_pin_on) { // Setting PWM and ENA both off if (opwr == 0 && !oena_pin_on) - return state == CutterState::STAY_OFF ? CutterState::STAY_OFF : CutterState::TURN_OFF; + return state == STAY_OFF ? STAY_OFF : TURN_OFF; // Setting PWM or ENA while OFF - if (state == CutterState::STAY_OFF) - return CutterState::TURN_ON; + if (state == STAY_OFF) + return TURN_ON; // Changing direction while already ON if (odir != spindle_dir) - return CutterState::STAY_ON_REV; + return STAY_ON_REV; return state; } @@ -162,19 +162,19 @@ void SpindleLaser::_change_hw(const bool ena_pin_on) { * Set cutter ocr_power value for PWM, Servo, and on/off pin. * * @param opwr Power value. Range 0 to MAX. When 0 disable spindle/laser. - * @param odir Direction spindle (default SPINDLE_DIR_CURRENT) + * @param odir Direction spindle (default SpindleDirSame) * @param ena_pin_on Enable/disable ENA_PIN. Work only in separate mode PWM. * If separate mode is disable - ENA_PIN is managed through opwr value * if true - enable pin; false - disable pin (default true) */ -void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir/*=SPINDLE_DIR_CURRENT*/, const bool ena_pin_on/*=true*/) { - const uint8_t dir_value = TERN(SPINDLE_CHANGE_DIR, (odir == SPINDLE_DIR_CURRENT) ? spindle_dir : odir, SPINDLE_DIR_CW); +void SpindleLaser::ocr_set_power(const uint8_t opwr, const SpindleDir odir/*=SpindleDirSame*/, const bool ena_pin_on/*=true*/) { + const SpindleDir dir_value = TERN(SPINDLE_CHANGE_DIR, (odir == SpindleDirSame) ? spindle_dir : odir, SpindleDirCW); const bool ena_pin_on_value = TERN(HAS_CUTTER_PWM_AND_ENA, ena_pin_on, opwr > 0); switch (get_event(opwr, dir_value, ena_pin_on_value)) { // Already ON and staying ON - case CutterState::STAY_ON: + case STAY_ON: state = STAY_ON; // Probably already the current state if (opwr != ocr_power) { ocr_power = opwr; @@ -182,7 +182,7 @@ void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir/*=SPINDL } break; - case CutterState::TURN_ON: + case TURN_ON: state = STAY_ON; ocr_power = opwr; spindle_dir = dir_value; @@ -191,12 +191,12 @@ void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir/*=SPINDL power_delay(true); break; - case CutterState::STAY_OFF: - state = STAY_OFF; // Probably already the current state + case STAY_OFF: + state = STAY_OFF; // Probably already the current state spindle_dir = dir_value; break; - case CutterState::TURN_OFF: + case TURN_OFF: state = STAY_OFF; ocr_power = opwr; spindle_dir = dir_value; @@ -205,7 +205,7 @@ void SpindleLaser::ocr_set_power(const uint8_t opwr, const uint8_t odir/*=SPINDL power_delay(false); break; - case CutterState::STAY_ON_REV: { + case STAY_ON_REV: { state = STAY_ON; ocr_power = opwr; spindle_dir = dir_value; @@ -239,10 +239,10 @@ uint8_t SpindleLaser::get_ocr_power(){ return ocr_power; } /** * Set the spindle direction and apply immediately * ! deprecate and need delete - * @param reverse If True is SPINDLE_DIR_CCW, false is SPINDLE_DIR_CW + * @param reverse If True is SpindleDirCCW, false is SpindleDirCW */ void SpindleLaser::set_reverse(const bool reverse) { - ocr_set_power(ocr_power, reverse ? SPINDLE_DIR_CCW : SPINDLE_DIR_CW); + ocr_set_power(ocr_power, reverse ? SpindleDirCCW : SpindleDirCW); } #endif diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index d99af1b7e4b5..e0d7a94abd94 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -45,13 +45,11 @@ #define SPEED_POWER_INTERCEPT 0 #endif -#define SPINDLE_DIR_CURRENT 0 // Don't change current value -#define SPINDLE_DIR_CW 1 -#define SPINDLE_DIR_CCW 2 +enum SpindleDir : uint8_t { SpindleDirSame, SpindleDirCW, SpindleDirCCW }; // Current ON/OFF state and transitions for get_event enum CutterState : uint8_t { - STAY_OFF = 0, + STAY_OFF, STAY_ON, STAY_ON_REV, TURN_ON, @@ -62,7 +60,7 @@ enum CutterState : uint8_t { class SpindleLaser { private: - static uint8_t spindle_dir; // Spindle direction + static SpindleDir spindle_dir; // Spindle direction static uint8_t ocr_power; // Value for PWM out static CutterState state; // Current state @@ -132,7 +130,7 @@ class SpindleLaser { private: static void ena_pin_set(const bool enable); static void _change_hw(const bool ena_pin_on); - static CutterState get_event(const uint8_t opwr, const uint8_t odir, const bool oena_pin_on); + static CutterState get_event(const uint8_t opwr, const SpindleDir odir, const bool oena_pin_on); #if ENABLED(SPINDLE_CHANGE_DIR) static void dir_pin_set(); @@ -146,7 +144,7 @@ class SpindleLaser { public: static void init(); - static void ocr_set_power(const uint8_t opwr, const uint8_t odir=SPINDLE_DIR_CURRENT, const bool ena_pin_on=true); + static void ocr_set_power(const uint8_t opwr, const SpindleDir odir=SpindleDirSame, const bool ena_pin_on=true); static uint8_t get_ocr_power(); /** @@ -213,9 +211,9 @@ class SpindleLaser { /** * Enable/Disable spindle/laser * @param enable true = enable; false = disable - * @param odir Direction spindle (default SPINDLE_DIR_CURRENT) + * @param odir Direction spindle (default SpindleDirSame) */ - static inline void set_enabled(const bool enable, uint8_t odir=SPINDLE_DIR_CURRENT) { + static inline void set_enabled(const bool enable, SpindleDir odir=SpindleDirSame) { uint8_t opwr = 0; if (enable) { #if ENABLED(SPINDLE_LASER_USE_PWM) @@ -281,8 +279,8 @@ class SpindleLaser { set_reverse(reverse); set_enabled(true); } - FORCE_INLINE static void enable_forward() { enable_with_dir(false); } - FORCE_INLINE static void enable_reverse() { enable_with_dir(true); } + FORCE_INLINE static void enable_forward() { enable_with_dir(false); } + FORCE_INLINE static void enable_reverse() { enable_with_dir(true); } FORCE_INLINE static void enable_same_dir() { enable_with_dir(is_reverse()); } #if ENABLED(SPINDLE_LASER_USE_PWM) diff --git a/Marlin/src/gcode/control/M3-M5.cpp b/Marlin/src/gcode/control/M3-M5.cpp index e13eb87a5664..290674b4fdef 100644 --- a/Marlin/src/gcode/control/M3-M5.cpp +++ b/Marlin/src/gcode/control/M3-M5.cpp @@ -103,8 +103,8 @@ void GcodeSuite::M3_M4(const bool is_M4) { #endif planner.synchronize(); // Wait for previous movement commands (G0/G0/G2/G3) to complete before changing power - - uint8_t dir_value = is_M4 ? SPINDLE_DIR_CCW : SPINDLE_DIR_CW; + + const SpindleDir dir_value = is_M4 ? SpindleDirCCW : SpindleDirCW; #if ENABLED(SPINDLE_LASER_USE_PWM) if (parser.seenval('O')) { From 69c7c2ddd904d73e7b627a5347f20677cda3f176 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 15 Sep 2021 21:08:02 -0500 Subject: [PATCH 28/29] Separate spindle test --- buildroot/tests/mega1280 | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/buildroot/tests/mega1280 b/buildroot/tests/mega1280 index d8cefbaf8145..42728f8e7ca5 100755 --- a/buildroot/tests/mega1280 +++ b/buildroot/tests/mega1280 @@ -13,19 +13,34 @@ set -e #exec_test $1 $2 "Default Configuration" "$3" # -# Test MESH_BED_LEVELING feature, with LCD +# Test MESH_BED_LEVELING, Closed-loop, Power Monitor, Ultimaker LCD # restore_configs opt_set LCD_LANGUAGE an \ POWER_MONITOR_CURRENT_PIN 14 POWER_MONITOR_VOLTAGE_PIN 15 \ CLOSED_LOOP_ENABLE_PIN 44 CLOSED_LOOP_MOVE_COMPLETE_PIN 45 -opt_enable SPINDLE_FEATURE ULTIMAKERCONTROLLER LCD_BED_LEVELING \ +opt_enable ULTIMAKERCONTROLLER \ EEPROM_SETTINGS EEPROM_BOOT_SILENT EEPROM_AUTO_INIT \ SENSORLESS_BACKOFF_MM HOMING_BACKOFF_POST_MM HOME_Y_BEFORE_X CODEPENDENT_XY_HOMING \ - MESH_BED_LEVELING ENABLE_LEVELING_FADE_HEIGHT MESH_G28_REST_ORIGIN \ - G26_MESH_VALIDATION MESH_EDIT_MENU GCODE_QUOTED_STRINGS \ + MESH_BED_LEVELING ENABLE_LEVELING_FADE_HEIGHT MESH_G28_REST_ORIGIN LCD_BED_LEVELING MESH_EDIT_MENU \ + G26_MESH_VALIDATION GCODE_QUOTED_STRINGS \ EXTERNAL_CLOSED_LOOP_CONTROLLER POWER_MONITOR_CURRENT POWER_MONITOR_VOLTAGE -exec_test $1 $2 "Spindle, MESH_BED_LEVELING, closed loop, Power Monitor, and LCD" "$3" +exec_test $1 $2 "MESH_BED_LEVELING, Closed-loop, Power Monitor, Ultimaker LCD" "$3" + +# +# Test SPINDLE_FEATURE with zero extruders +# +restore_configs +opt_set MOTHERBOARD BOARD_RIGIDBOARD EXTRUDERS 0 LCD_LANGUAGE hu \ + AXIS_RELATIVE_MODES '{ true, true, true }' \ + DEFAULT_AXIS_STEPS_PER_UNIT '{ 80, 80, 400 }' \ + DEFAULT_MAX_FEEDRATE '{ 300, 300, 5 }' \ + DEFAULT_MAX_ACCELERATION '{ 3000, 3000, 100 }' \ + MANUAL_FEEDRATE '{ 50*60, 50*60, 4*60 }' +opt_enable SPINDLE_FEATURE SPINDLE_CHANGE_DIR RIGIDBOT_PANEL EEPROM_SETTINGS \ + HOMING_BACKOFF_POST_MM HOME_Y_BEFORE_X HOME_Y_BEFORE_X +opt_disable EEPROM_BOOT_SILENT EEPROM_AUTO_INIT FASTER_GCODE_PARSER +exec_test $1 $2 "Spindle, Zero Extruders, Rigidbot Panel" "$3" # # Test DUAL_X_CARRIAGE From fc3b34959f0d63b57c4b05c118bcf7e6c737d5ad Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 24 Apr 2022 13:39:51 -0500 Subject: [PATCH 29/29] Drop inline hints --- Marlin/src/feature/spindle_laser.h | 46 +++++++++++++++--------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index e0d7a94abd94..5728007d6172 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -69,12 +69,12 @@ class SpindleLaser { min_pct = TERN(CUTTER_POWER_RELATIVE, 0, TERN(SPINDLE_FEATURE, round(100.0f * (SPEED_POWER_MIN) / (SPEED_POWER_MAX)), SPEED_POWER_MIN)), max_pct = TERN(SPINDLE_FEATURE, 100, SPEED_POWER_MAX); - static const inline uint8_t pct_to_ocr(const_float_t pct) { return uint8_t(PCT_TO_PWM(pct)); } + static constexpr uint8_t pct_to_ocr(const_float_t pct) { return uint8_t(PCT_TO_PWM(pct)); } // cpower = configured values (e.g., SPEED_POWER_MAX) // Convert configured power range to a percentage - static const inline uint8_t cpwr_to_pct(const cutter_cpower_t cpwr) { + static const uint8_t cpwr_to_pct(const cutter_cpower_t cpwr) { constexpr cutter_cpower_t power_floor = TERN(CUTTER_POWER_RELATIVE, SPEED_POWER_MIN, 0), power_range = SPEED_POWER_MAX - power_floor; return cpwr ? round(100.0f * (cpwr - power_floor) / power_range) : 0; @@ -82,7 +82,7 @@ class SpindleLaser { // Convert a cpower (e.g., SPEED_POWER_STARTUP) to unit power (upwr, upower), // which can be PWM, Percent, Servo angle, or RPM (rel/abs). - static const inline cutter_power_t cpwr_to_upwr(const cutter_cpower_t cpwr) { // STARTUP power to Unit power + static const cutter_power_t cpwr_to_upwr(const cutter_cpower_t cpwr) { // STARTUP power to Unit power const cutter_power_t upwr = ( #if ENABLED(SPINDLE_FEATURE) // Spindle configured values are in RPM @@ -124,7 +124,7 @@ class SpindleLaser { unitPower; // Power as displayed status in PWM, Percentage or RPM #if ENABLED(MARLIN_DEV_MODE) - static inline void refresh_frequency() { set_pwm_frequency(pin_t(SPINDLE_LASER_PWM_PIN), frequency); } + static void refresh_frequency() { set_pwm_frequency(pin_t(SPINDLE_LASER_PWM_PIN), frequency); } #endif private: @@ -135,7 +135,7 @@ class SpindleLaser { #if ENABLED(SPINDLE_CHANGE_DIR) static void dir_pin_set(); #else - static inline void dir_pin_set() {} + static void dir_pin_set() {} #endif #if ENABLED(SPINDLE_LASER_USE_PWM) @@ -150,7 +150,7 @@ class SpindleLaser { /** * Return state laser/spindle; true if enable. */ - static inline bool enabled() { return state != CutterState::STAY_OFF; } + static bool enabled() { return state != CutterState::STAY_OFF; } FORCE_INLINE static void refresh() {} @@ -158,7 +158,7 @@ class SpindleLaser { /** * Update output for upower->OCR translation */ - static inline uint8_t upower_to_ocr(const cutter_power_t upwr) { + static uint8_t upower_to_ocr(const cutter_power_t upwr) { return uint8_t( #if CUTTER_UNIT_IS(PWM255) upwr @@ -173,11 +173,11 @@ class SpindleLaser { /** * Correct power to configured range */ - static inline cutter_power_t power_to_range(const cutter_power_t pwr) { + static cutter_power_t power_to_range(const cutter_power_t pwr) { return power_to_range(pwr, _CUTTER_POWER(CUTTER_POWER_UNIT)); } - static inline cutter_power_t power_to_range(const cutter_power_t pwr, const uint8_t pwrUnit) { + static cutter_power_t power_to_range(const cutter_power_t pwr, const uint8_t pwrUnit) { if (pwr <= 0) return 0; cutter_power_t upwr; switch (pwrUnit) { @@ -213,7 +213,7 @@ class SpindleLaser { * @param enable true = enable; false = disable * @param odir Direction spindle (default SpindleDirSame) */ - static inline void set_enabled(const bool enable, SpindleDir odir=SpindleDirSame) { + static void set_enabled(const bool enable, SpindleDir odir=SpindleDirSame) { uint8_t opwr = 0; if (enable) { #if ENABLED(SPINDLE_LASER_USE_PWM) @@ -228,14 +228,14 @@ class SpindleLaser { ocr_set_power(opwr, odir, enable); } - static inline void disable() { isReady = false; set_enabled(false); } + static void disable() { isReady = false; set_enabled(false); } /** * Wait for spindle to spin up or spin down * * @param on true = state to on; false = state to off. */ - static inline void power_delay(const bool on) { + static void power_delay(const bool on) { #if DISABLED(LASER_POWER_INLINE) safe_delay(on ? SPINDLE_LASER_POWERUP_DELAY : SPINDLE_LASER_POWERDOWN_DELAY); #endif @@ -245,7 +245,7 @@ class SpindleLaser { static void set_reverse(const bool reverse); static bool is_reverse() { return READ(SPINDLE_DIR_PIN) == SPINDLE_INVERT_DIR; } #else - static inline void set_reverse(const bool) {} + static void set_reverse(const bool) {} static bool is_reverse() { return false; } #endif @@ -253,7 +253,7 @@ class SpindleLaser { static void air_evac_enable(); // Turn On Cutter Vacuum or Laser Blower motor static void air_evac_disable(); // Turn Off Cutter Vacuum or Laser Blower motor static void air_evac_toggle(); // Toggle Cutter Vacuum or Laser Blower motor - static inline bool air_evac_state() { // Get current state + static bool air_evac_state() { // Get current state return (READ(AIR_EVACUATION_PIN) == AIR_EVACUATION_ACTIVE); } #endif @@ -262,13 +262,13 @@ class SpindleLaser { static void air_assist_enable(); // Turn on air assist static void air_assist_disable(); // Turn off air assist static void air_assist_toggle(); // Toggle air assist - static inline bool air_assist_state() { // Get current state + static bool air_assist_state() { // Get current state return (READ(AIR_ASSIST_PIN) == AIR_ASSIST_ACTIVE); } #endif #if HAS_LCD_MENU - static inline void enable_with_dir(const bool reverse) { + static void enable_with_dir(const bool reverse) { isReady = true; const uint8_t ocr = TERN(SPINDLE_LASER_USE_PWM, upower_to_ocr(menuPower), 255); if (menuPower) @@ -284,7 +284,7 @@ class SpindleLaser { FORCE_INLINE static void enable_same_dir() { enable_with_dir(is_reverse()); } #if ENABLED(SPINDLE_LASER_USE_PWM) - static inline void update_from_mpower() { + static void update_from_mpower() { if (isReady) ocr_power = upower_to_ocr(menuPower); unitPower = menuPower; } @@ -296,7 +296,7 @@ class SpindleLaser { * Also fires with any PWM power that was previous set * If not set defaults to 80% power */ - static inline void test_fire_pulse() { + static void test_fire_pulse() { TERN_(USE_BEEPER, buzzer.tone(30, 3000)); enable_forward(); // Turn Laser on (Spindle speak but same funct) delay(testPulse); // Delay for time set by user in pulse ms menu screen. @@ -313,7 +313,7 @@ class SpindleLaser { */ // Force disengage planner power control - static inline void inline_disable() { + static void inline_disable() { isReady = false; unitPower = 0; planner.laser_inline.status.isPlanned = false; @@ -322,7 +322,7 @@ class SpindleLaser { } // Inline modes of all other functions; all enable planner inline power control - static inline void set_inline_enabled(const bool enable) { + static void set_inline_enabled(const bool enable) { if (enable) inline_power(255); else { @@ -351,17 +351,17 @@ class SpindleLaser { #endif } - static inline void inline_direction(const bool) { /* never */ } + static void inline_direction(const bool) { /* never */ } #if ENABLED(SPINDLE_LASER_USE_PWM) - static inline void inline_ocr_power(const uint8_t opwr) { + static void inline_ocr_power(const uint8_t opwr) { planner.laser_inline.status.isEnabled = isReady = opwr > 0; planner.laser_inline.power = opwr; } #endif #endif // LASER_POWER_INLINE - static inline void kill() { + static void kill() { TERN_(LASER_POWER_INLINE, inline_disable()); disable(); }