2017-12-15 22:03:14 +01:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 15:00:57 +01:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-12-15 22:03:14 +01:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-12-15 22:03:14 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-07-23 05:20:14 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-12-15 22:03:14 +01:00
|
|
|
*
|
|
|
|
*/
|
2018-11-04 09:25:55 +01:00
|
|
|
#pragma once
|
2017-12-15 22:03:14 +01:00
|
|
|
|
2018-10-03 09:48:49 +02:00
|
|
|
#include "../inc/MarlinConfig.h"
|
2020-10-17 02:36:25 +02:00
|
|
|
#include "../lcd/marlinui.h"
|
2019-05-26 01:22:12 +02:00
|
|
|
|
2020-03-02 19:03:43 +01:00
|
|
|
#if HAS_TRINAMIC_CONFIG
|
2019-05-26 01:22:12 +02:00
|
|
|
|
|
|
|
#include <TMCStepper.h>
|
|
|
|
#include "../module/planner.h"
|
2018-03-13 08:01:41 +01:00
|
|
|
|
2018-12-18 19:42:14 +01:00
|
|
|
#define CHOPPER_DEFAULT_12V { 3, -1, 1 }
|
|
|
|
#define CHOPPER_DEFAULT_19V { 4, 1, 1 }
|
|
|
|
#define CHOPPER_DEFAULT_24V { 4, 2, 1 }
|
|
|
|
#define CHOPPER_DEFAULT_36V { 5, 2, 4 }
|
2019-03-22 19:03:36 +01:00
|
|
|
#define CHOPPER_PRUSAMK3_24V { 3, -2, 6 }
|
2018-12-18 19:42:14 +01:00
|
|
|
#define CHOPPER_MARLIN_119 { 5, 2, 3 }
|
2020-07-19 01:54:44 +02:00
|
|
|
#define CHOPPER_09STEP_24V { 3, -1, 5 }
|
2018-12-18 19:42:14 +01:00
|
|
|
|
2019-02-20 09:22:42 +01:00
|
|
|
#if ENABLED(MONITOR_DRIVER_STATUS) && !defined(MONITOR_DRIVER_STATUS_INTERVAL_MS)
|
2020-10-09 23:50:17 +02:00
|
|
|
#define MONITOR_DRIVER_STATUS_INTERVAL_MS 500U
|
2019-02-20 09:22:42 +01:00
|
|
|
#endif
|
|
|
|
|
2019-05-26 01:22:12 +02:00
|
|
|
constexpr uint16_t _tmc_thrs(const uint16_t msteps, const uint32_t thrs, const uint32_t spmm) {
|
2019-01-17 20:17:16 +01:00
|
|
|
return 12650000UL * msteps / (256 * thrs * spmm);
|
|
|
|
}
|
|
|
|
|
2018-10-03 09:48:49 +02:00
|
|
|
template<char AXIS_LETTER, char DRIVER_ID>
|
|
|
|
class TMCStorage {
|
|
|
|
protected:
|
|
|
|
// Only a child class has access to constructor => Don't create on its own! "Poor man's abstract class"
|
|
|
|
TMCStorage() {}
|
|
|
|
|
2019-01-17 20:17:16 +01:00
|
|
|
public:
|
2018-10-03 09:48:49 +02:00
|
|
|
uint16_t val_mA = 0;
|
|
|
|
|
|
|
|
#if ENABLED(MONITOR_DRIVER_STATUS)
|
2018-12-07 22:34:21 +01:00
|
|
|
uint8_t otpw_count = 0,
|
|
|
|
error_count = 0;
|
2018-10-03 09:48:49 +02:00
|
|
|
bool flag_otpw = false;
|
2019-01-17 20:17:16 +01:00
|
|
|
inline bool getOTPW() { return flag_otpw; }
|
|
|
|
inline void clear_otpw() { flag_otpw = 0; }
|
2018-10-03 09:48:49 +02:00
|
|
|
#endif
|
|
|
|
|
2019-01-17 20:17:16 +01:00
|
|
|
inline uint16_t getMilliamps() { return val_mA; }
|
2017-12-15 22:03:14 +01:00
|
|
|
|
2019-01-17 20:17:16 +01:00
|
|
|
inline void printLabel() {
|
2018-10-03 09:48:49 +02:00
|
|
|
SERIAL_CHAR(AXIS_LETTER);
|
|
|
|
if (DRIVER_ID > '0') SERIAL_CHAR(DRIVER_ID);
|
|
|
|
}
|
2019-01-17 20:17:16 +01:00
|
|
|
|
|
|
|
struct {
|
2021-05-24 04:33:22 +02:00
|
|
|
OPTCODE(HAS_STEALTHCHOP, bool stealthChop_enabled = false)
|
|
|
|
OPTCODE(HYBRID_THRESHOLD, uint8_t hybrid_thrs = 0)
|
|
|
|
OPTCODE(USE_SENSORLESS, int16_t homing_thrs = 0)
|
2019-01-17 20:17:16 +01:00
|
|
|
} stored;
|
2018-10-03 09:48:49 +02:00
|
|
|
};
|
|
|
|
|
2019-05-26 01:22:12 +02:00
|
|
|
template<class TMC, char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
|
2018-10-03 09:48:49 +02:00
|
|
|
class TMCMarlin : public TMC, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
|
|
|
|
public:
|
2019-06-20 22:47:50 +02:00
|
|
|
TMCMarlin(const uint16_t cs_pin, const float RS) :
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC(cs_pin, RS)
|
|
|
|
{}
|
2019-09-29 12:47:20 +02:00
|
|
|
TMCMarlin(const uint16_t cs_pin, const float RS, const uint8_t axis_chain_index) :
|
|
|
|
TMC(cs_pin, RS, axis_chain_index)
|
|
|
|
{}
|
2019-06-20 22:47:50 +02:00
|
|
|
TMCMarlin(const uint16_t CS, const float RS, const uint16_t pinMOSI, const uint16_t pinMISO, const uint16_t pinSCK) :
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC(CS, RS, pinMOSI, pinMISO, pinSCK)
|
|
|
|
{}
|
2019-09-29 12:47:20 +02:00
|
|
|
TMCMarlin(const uint16_t CS, const float RS, const uint16_t pinMOSI, const uint16_t pinMISO, const uint16_t pinSCK, const uint8_t axis_chain_index) :
|
|
|
|
TMC(CS, RS, pinMOSI, pinMISO, pinSCK, axis_chain_index)
|
|
|
|
{}
|
2019-01-17 20:17:16 +01:00
|
|
|
inline uint16_t rms_current() { return TMC::rms_current(); }
|
|
|
|
inline void rms_current(uint16_t mA) {
|
2018-10-03 09:48:49 +02:00
|
|
|
this->val_mA = mA;
|
|
|
|
TMC::rms_current(mA);
|
|
|
|
}
|
2019-06-20 22:47:50 +02:00
|
|
|
inline void rms_current(const uint16_t mA, const float mult) {
|
2018-10-03 09:48:49 +02:00
|
|
|
this->val_mA = mA;
|
|
|
|
TMC::rms_current(mA, mult);
|
|
|
|
}
|
2020-04-20 15:08:00 +02:00
|
|
|
inline uint16_t get_microstep_counter() { return TMC::MSCNT(); }
|
2020-04-28 11:31:59 +02:00
|
|
|
|
2019-01-21 06:54:57 +01:00
|
|
|
#if HAS_STEALTHCHOP
|
2020-10-24 06:37:45 +02:00
|
|
|
inline bool get_stealthChop() { return this->en_pwm_mode(); }
|
|
|
|
inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; }
|
|
|
|
inline void refresh_stepping_mode() { this->en_pwm_mode(this->stored.stealthChop_enabled); }
|
|
|
|
inline void set_stealthChop(const bool stch) { this->stored.stealthChop_enabled = stch; refresh_stepping_mode(); }
|
|
|
|
inline bool toggle_stepping_mode() { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); }
|
2019-01-17 20:17:16 +01:00
|
|
|
#endif
|
2020-02-09 04:01:57 +01:00
|
|
|
|
2019-05-26 01:22:12 +02:00
|
|
|
#if ENABLED(HYBRID_THRESHOLD)
|
|
|
|
uint32_t get_pwm_thrs() {
|
|
|
|
return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
|
|
|
|
}
|
2021-04-17 09:03:16 +02:00
|
|
|
void set_pwm_thrs(const uint32_t thrs) {
|
|
|
|
TMC::TPWMTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID]));
|
|
|
|
TERN_(HAS_LCD_MENU, this->stored.hybrid_thrs = thrs);
|
|
|
|
}
|
2019-05-26 01:22:12 +02:00
|
|
|
#endif
|
2020-02-09 04:01:57 +01:00
|
|
|
|
2019-05-26 01:22:12 +02:00
|
|
|
#if USE_SENSORLESS
|
2019-06-20 22:47:50 +02:00
|
|
|
inline int16_t homing_threshold() { return TMC::sgt(); }
|
|
|
|
void homing_threshold(int16_t sgt_val) {
|
|
|
|
sgt_val = (int16_t)constrain(sgt_val, sgt_min, sgt_max);
|
2019-05-26 01:22:12 +02:00
|
|
|
TMC::sgt(sgt_val);
|
2020-04-22 23:35:03 +02:00
|
|
|
TERN_(HAS_LCD_MENU, this->stored.homing_thrs = sgt_val);
|
2019-01-17 20:17:16 +01:00
|
|
|
}
|
2019-08-05 05:22:58 +02:00
|
|
|
#if ENABLED(SPI_ENDSTOPS)
|
|
|
|
bool test_stall_status();
|
|
|
|
#endif
|
2019-05-26 01:22:12 +02:00
|
|
|
#endif
|
2019-01-17 20:17:16 +01:00
|
|
|
|
2019-05-26 01:22:12 +02:00
|
|
|
#if HAS_LCD_MENU
|
2019-01-17 20:17:16 +01:00
|
|
|
inline void refresh_stepper_current() { rms_current(this->val_mA); }
|
|
|
|
|
|
|
|
#if ENABLED(HYBRID_THRESHOLD)
|
2019-05-26 01:22:12 +02:00
|
|
|
inline void refresh_hybrid_thrs() { set_pwm_thrs(this->stored.hybrid_thrs); }
|
2019-01-17 20:17:16 +01:00
|
|
|
#endif
|
2019-05-26 01:22:12 +02:00
|
|
|
#if USE_SENSORLESS
|
2019-06-20 22:47:50 +02:00
|
|
|
inline void refresh_homing_thrs() { homing_threshold(this->stored.homing_thrs); }
|
2019-01-17 20:17:16 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2019-06-20 22:47:50 +02:00
|
|
|
|
|
|
|
static constexpr int8_t sgt_min = -64,
|
|
|
|
sgt_max = 63;
|
2018-10-03 09:48:49 +02:00
|
|
|
};
|
2020-02-09 04:01:57 +01:00
|
|
|
|
2019-05-26 01:22:12 +02:00
|
|
|
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
|
|
|
|
class TMCMarlin<TMC2208Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC2208Stepper, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
|
2018-10-03 09:48:49 +02:00
|
|
|
public:
|
2019-06-20 22:47:50 +02:00
|
|
|
TMCMarlin(Stream * SerialPort, const float RS, const uint8_t) :
|
2019-11-06 23:57:48 +01:00
|
|
|
TMC2208Stepper(SerialPort, RS)
|
2018-10-03 09:48:49 +02:00
|
|
|
{}
|
2020-05-25 22:48:33 +02:00
|
|
|
TMCMarlin(Stream * SerialPort, const float RS, uint8_t addr, const uint16_t mul_pin1, const uint16_t mul_pin2) :
|
|
|
|
TMC2208Stepper(SerialPort, RS, addr, mul_pin1, mul_pin2)
|
|
|
|
{}
|
2020-06-22 05:10:29 +02:00
|
|
|
TMCMarlin(const uint16_t RX, const uint16_t TX, const float RS, const uint8_t) :
|
|
|
|
TMC2208Stepper(RX, TX, RS)
|
2018-10-03 09:48:49 +02:00
|
|
|
{}
|
2020-05-25 22:48:33 +02:00
|
|
|
|
2018-10-03 09:48:49 +02:00
|
|
|
uint16_t rms_current() { return TMC2208Stepper::rms_current(); }
|
2019-06-20 22:47:50 +02:00
|
|
|
inline void rms_current(const uint16_t mA) {
|
2018-10-03 09:48:49 +02:00
|
|
|
this->val_mA = mA;
|
|
|
|
TMC2208Stepper::rms_current(mA);
|
|
|
|
}
|
2019-06-20 22:47:50 +02:00
|
|
|
inline void rms_current(const uint16_t mA, const float mult) {
|
2018-10-03 09:48:49 +02:00
|
|
|
this->val_mA = mA;
|
|
|
|
TMC2208Stepper::rms_current(mA, mult);
|
|
|
|
}
|
2020-04-20 15:08:00 +02:00
|
|
|
inline uint16_t get_microstep_counter() { return TMC2208Stepper::MSCNT(); }
|
2019-01-17 20:17:16 +01:00
|
|
|
|
2019-01-21 06:54:57 +01:00
|
|
|
#if HAS_STEALTHCHOP
|
2020-10-24 06:37:45 +02:00
|
|
|
inline bool get_stealthChop() { return !this->en_spreadCycle(); }
|
|
|
|
inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; }
|
|
|
|
inline void refresh_stepping_mode() { this->en_spreadCycle(!this->stored.stealthChop_enabled); }
|
|
|
|
inline void set_stealthChop(const bool stch) { this->stored.stealthChop_enabled = stch; refresh_stepping_mode(); }
|
|
|
|
inline bool toggle_stepping_mode() { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); }
|
2019-01-17 20:17:16 +01:00
|
|
|
#endif
|
2020-02-09 04:01:57 +01:00
|
|
|
|
2019-05-26 01:22:12 +02:00
|
|
|
#if ENABLED(HYBRID_THRESHOLD)
|
|
|
|
uint32_t get_pwm_thrs() {
|
|
|
|
return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
|
|
|
|
}
|
2021-04-17 09:03:16 +02:00
|
|
|
void set_pwm_thrs(const uint32_t thrs) {
|
|
|
|
TMC2208Stepper::TPWMTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID]));
|
|
|
|
TERN_(HAS_LCD_MENU, this->stored.hybrid_thrs = thrs);
|
|
|
|
}
|
2019-05-26 01:22:12 +02:00
|
|
|
#endif
|
2019-01-17 20:17:16 +01:00
|
|
|
|
2019-05-26 01:22:12 +02:00
|
|
|
#if HAS_LCD_MENU
|
2019-01-17 20:17:16 +01:00
|
|
|
inline void refresh_stepper_current() { rms_current(this->val_mA); }
|
2021-04-17 09:03:16 +02:00
|
|
|
|
2019-01-17 20:17:16 +01:00
|
|
|
#if ENABLED(HYBRID_THRESHOLD)
|
2019-05-26 01:22:12 +02:00
|
|
|
inline void refresh_hybrid_thrs() { set_pwm_thrs(this->stored.hybrid_thrs); }
|
2019-01-17 20:17:16 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-06-19 18:55:49 +02:00
|
|
|
};
|
2019-06-20 22:47:50 +02:00
|
|
|
|
|
|
|
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
|
|
|
|
class TMCMarlin<TMC2209Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC2209Stepper, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
|
|
|
|
public:
|
|
|
|
TMCMarlin(Stream * SerialPort, const float RS, const uint8_t addr) :
|
|
|
|
TMC2209Stepper(SerialPort, RS, addr)
|
|
|
|
{}
|
2020-06-22 21:25:46 +02:00
|
|
|
TMCMarlin(const uint16_t RX, const uint16_t TX, const float RS, const uint8_t addr) :
|
2019-06-20 22:47:50 +02:00
|
|
|
TMC2209Stepper(RX, TX, RS, addr)
|
|
|
|
{}
|
|
|
|
uint8_t get_address() { return slave_address; }
|
|
|
|
uint16_t rms_current() { return TMC2209Stepper::rms_current(); }
|
|
|
|
inline void rms_current(const uint16_t mA) {
|
|
|
|
this->val_mA = mA;
|
|
|
|
TMC2209Stepper::rms_current(mA);
|
|
|
|
}
|
|
|
|
inline void rms_current(const uint16_t mA, const float mult) {
|
|
|
|
this->val_mA = mA;
|
|
|
|
TMC2209Stepper::rms_current(mA, mult);
|
|
|
|
}
|
2020-04-20 15:08:00 +02:00
|
|
|
inline uint16_t get_microstep_counter() { return TMC2209Stepper::MSCNT(); }
|
2019-06-20 22:47:50 +02:00
|
|
|
|
|
|
|
#if HAS_STEALTHCHOP
|
2020-10-24 06:37:45 +02:00
|
|
|
inline bool get_stealthChop() { return !this->en_spreadCycle(); }
|
|
|
|
inline bool get_stored_stealthChop() { return this->stored.stealthChop_enabled; }
|
|
|
|
inline void refresh_stepping_mode() { this->en_spreadCycle(!this->stored.stealthChop_enabled); }
|
|
|
|
inline void set_stealthChop(const bool stch) { this->stored.stealthChop_enabled = stch; refresh_stepping_mode(); }
|
|
|
|
inline bool toggle_stepping_mode() { set_stealthChop(!this->stored.stealthChop_enabled); return get_stealthChop(); }
|
2019-06-20 22:47:50 +02:00
|
|
|
#endif
|
2020-02-09 04:01:57 +01:00
|
|
|
|
2019-06-20 22:47:50 +02:00
|
|
|
#if ENABLED(HYBRID_THRESHOLD)
|
|
|
|
uint32_t get_pwm_thrs() {
|
|
|
|
return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
|
|
|
|
}
|
2021-04-17 09:03:16 +02:00
|
|
|
void set_pwm_thrs(const uint32_t thrs) {
|
|
|
|
TMC2209Stepper::TPWMTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID]));
|
|
|
|
TERN_(HAS_LCD_MENU, this->stored.hybrid_thrs = thrs);
|
|
|
|
}
|
2019-06-20 22:47:50 +02:00
|
|
|
#endif
|
|
|
|
#if USE_SENSORLESS
|
|
|
|
inline int16_t homing_threshold() { return TMC2209Stepper::SGTHRS(); }
|
|
|
|
void homing_threshold(int16_t sgt_val) {
|
|
|
|
sgt_val = (int16_t)constrain(sgt_val, sgt_min, sgt_max);
|
|
|
|
TMC2209Stepper::SGTHRS(sgt_val);
|
2020-04-22 23:35:03 +02:00
|
|
|
TERN_(HAS_LCD_MENU, this->stored.homing_thrs = sgt_val);
|
2019-06-20 22:47:50 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_LCD_MENU
|
|
|
|
inline void refresh_stepper_current() { rms_current(this->val_mA); }
|
2020-02-10 04:22:26 +01:00
|
|
|
|
2019-06-20 22:47:50 +02:00
|
|
|
#if ENABLED(HYBRID_THRESHOLD)
|
|
|
|
inline void refresh_hybrid_thrs() { set_pwm_thrs(this->stored.hybrid_thrs); }
|
|
|
|
#endif
|
|
|
|
#if USE_SENSORLESS
|
|
|
|
inline void refresh_homing_thrs() { homing_threshold(this->stored.homing_thrs); }
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static constexpr uint8_t sgt_min = 0,
|
|
|
|
sgt_max = 255;
|
|
|
|
};
|
|
|
|
|
2019-05-26 01:22:12 +02:00
|
|
|
template<char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
|
|
|
|
class TMCMarlin<TMC2660Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC2660Stepper, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
|
2019-01-17 20:17:16 +01:00
|
|
|
public:
|
2019-09-29 12:47:20 +02:00
|
|
|
TMCMarlin(const uint16_t cs_pin, const float RS, const uint8_t) :
|
2019-01-17 20:17:16 +01:00
|
|
|
TMC2660Stepper(cs_pin, RS)
|
|
|
|
{}
|
2019-09-29 12:47:20 +02:00
|
|
|
TMCMarlin(const uint16_t CS, const float RS, const uint16_t pinMOSI, const uint16_t pinMISO, const uint16_t pinSCK, const uint8_t) :
|
2019-01-17 20:17:16 +01:00
|
|
|
TMC2660Stepper(CS, RS, pinMOSI, pinMISO, pinSCK)
|
|
|
|
{}
|
|
|
|
inline uint16_t rms_current() { return TMC2660Stepper::rms_current(); }
|
2019-06-20 22:47:50 +02:00
|
|
|
inline void rms_current(const uint16_t mA) {
|
2019-01-17 20:17:16 +01:00
|
|
|
this->val_mA = mA;
|
|
|
|
TMC2660Stepper::rms_current(mA);
|
|
|
|
}
|
2020-04-20 15:08:00 +02:00
|
|
|
inline uint16_t get_microstep_counter() { return TMC2660Stepper::mstep(); }
|
2017-12-15 22:03:14 +01:00
|
|
|
|
2019-05-26 01:22:12 +02:00
|
|
|
#if USE_SENSORLESS
|
2019-06-20 22:47:50 +02:00
|
|
|
inline int16_t homing_threshold() { return TMC2660Stepper::sgt(); }
|
|
|
|
void homing_threshold(int16_t sgt_val) {
|
|
|
|
sgt_val = (int16_t)constrain(sgt_val, sgt_min, sgt_max);
|
2019-05-26 01:22:12 +02:00
|
|
|
TMC2660Stepper::sgt(sgt_val);
|
2020-04-22 23:35:03 +02:00
|
|
|
TERN_(HAS_LCD_MENU, this->stored.homing_thrs = sgt_val);
|
2019-01-17 20:17:16 +01:00
|
|
|
}
|
2019-05-26 01:22:12 +02:00
|
|
|
#endif
|
2019-01-17 20:17:16 +01:00
|
|
|
|
2019-05-26 01:22:12 +02:00
|
|
|
#if HAS_LCD_MENU
|
2019-01-17 20:17:16 +01:00
|
|
|
inline void refresh_stepper_current() { rms_current(this->val_mA); }
|
|
|
|
|
2019-05-26 01:22:12 +02:00
|
|
|
#if USE_SENSORLESS
|
2019-06-20 22:47:50 +02:00
|
|
|
inline void refresh_homing_thrs() { homing_threshold(this->stored.homing_thrs); }
|
2019-01-17 20:17:16 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2019-06-20 22:47:50 +02:00
|
|
|
|
|
|
|
static constexpr int8_t sgt_min = -64,
|
|
|
|
sgt_max = 63;
|
2019-01-17 20:17:16 +01:00
|
|
|
};
|
2018-01-10 02:14:07 +01:00
|
|
|
|
2017-12-15 22:03:14 +01:00
|
|
|
template<typename TMC>
|
2019-05-26 01:22:12 +02:00
|
|
|
void tmc_print_current(TMC &st) {
|
2018-10-03 09:48:49 +02:00
|
|
|
st.printLabel();
|
2021-09-09 11:57:05 +02:00
|
|
|
SERIAL_ECHOLNPGM(" driver current: ", st.getMilliamps());
|
2017-12-29 20:38:08 +01:00
|
|
|
}
|
2019-01-17 20:17:16 +01:00
|
|
|
|
2018-10-03 09:48:49 +02:00
|
|
|
#if ENABLED(MONITOR_DRIVER_STATUS)
|
|
|
|
template<typename TMC>
|
|
|
|
void tmc_report_otpw(TMC &st) {
|
|
|
|
st.printLabel();
|
|
|
|
SERIAL_ECHOPGM(" temperature prewarn triggered: ");
|
2019-04-06 03:02:46 +02:00
|
|
|
serialprint_truefalse(st.getOTPW());
|
2018-10-03 09:48:49 +02:00
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
template<typename TMC>
|
|
|
|
void tmc_clear_otpw(TMC &st) {
|
|
|
|
st.clear_otpw();
|
|
|
|
st.printLabel();
|
|
|
|
SERIAL_ECHOLNPGM(" prewarn flag cleared");
|
|
|
|
}
|
|
|
|
#endif
|
2019-05-26 01:22:12 +02:00
|
|
|
#if ENABLED(HYBRID_THRESHOLD)
|
|
|
|
template<typename TMC>
|
|
|
|
void tmc_print_pwmthrs(TMC &st) {
|
|
|
|
st.printLabel();
|
2021-09-09 11:57:05 +02:00
|
|
|
SERIAL_ECHOLNPGM(" stealthChop max speed: ", st.get_pwm_thrs());
|
2019-05-26 01:22:12 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if USE_SENSORLESS
|
|
|
|
template<typename TMC>
|
|
|
|
void tmc_print_sgt(TMC &st) {
|
|
|
|
st.printLabel();
|
|
|
|
SERIAL_ECHOPGM(" homing sensitivity: ");
|
2021-08-09 04:25:17 +02:00
|
|
|
SERIAL_PRINTLN(st.homing_threshold(), PrintBase::Dec);
|
2019-05-26 01:22:12 +02:00
|
|
|
}
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
|
2019-11-30 13:59:44 +01:00
|
|
|
void monitor_tmc_drivers();
|
2021-06-05 09:18:47 +02:00
|
|
|
void test_tmc_connection(LOGICAL_AXIS_DECL(const bool, true));
|
2017-12-15 22:03:14 +01:00
|
|
|
|
2018-01-10 02:14:07 +01:00
|
|
|
#if ENABLED(TMC_DEBUG)
|
2018-10-07 00:18:10 +02:00
|
|
|
#if ENABLED(MONITOR_DRIVER_STATUS)
|
2019-02-20 09:22:42 +01:00
|
|
|
void tmc_set_report_interval(const uint16_t update_interval);
|
2018-10-07 00:18:10 +02:00
|
|
|
#endif
|
2021-06-05 09:18:47 +02:00
|
|
|
void tmc_report_all(LOGICAL_AXIS_DECL(const bool, true));
|
|
|
|
void tmc_get_registers(LOGICAL_AXIS_ARGS(const bool));
|
2018-01-10 02:14:07 +01:00
|
|
|
#endif
|
|
|
|
|
2017-12-15 22:03:14 +01:00
|
|
|
/**
|
2019-07-24 08:52:36 +02:00
|
|
|
* TMC2130-specific sensorless homing using stallGuard2.
|
2017-12-15 22:03:14 +01:00
|
|
|
* stallGuard2 only works when in spreadCycle mode.
|
2019-07-24 08:52:36 +02:00
|
|
|
* spreadCycle and stealthChop are mutually-exclusive.
|
2017-12-15 22:03:14 +01:00
|
|
|
*
|
|
|
|
* Defined here because of limitations with templates and headers.
|
|
|
|
*/
|
2018-09-09 21:59:12 +02:00
|
|
|
#if USE_SENSORLESS
|
2019-08-05 05:22:58 +02:00
|
|
|
|
2018-12-07 22:34:21 +01:00
|
|
|
// Track enabled status of stealthChop and only re-enable where applicable
|
2021-06-05 09:18:47 +02:00
|
|
|
struct sensorless_t { bool LINEAR_AXIS_ARGS(), x2, y2, z2, z3, z4; };
|
2018-12-07 22:34:21 +01:00
|
|
|
|
2019-08-05 05:22:58 +02:00
|
|
|
#if ENABLED(IMPROVE_HOMING_RELIABILITY)
|
|
|
|
extern millis_t sg_guard_period;
|
|
|
|
constexpr uint16_t default_sg_guard_duration = 400;
|
|
|
|
#endif
|
|
|
|
|
2018-12-07 22:34:21 +01:00
|
|
|
bool tmc_enable_stallguard(TMC2130Stepper &st);
|
|
|
|
void tmc_disable_stallguard(TMC2130Stepper &st, const bool restore_stealth);
|
|
|
|
|
2019-06-20 22:47:50 +02:00
|
|
|
bool tmc_enable_stallguard(TMC2209Stepper &st);
|
|
|
|
void tmc_disable_stallguard(TMC2209Stepper &st, const bool restore_stealth);
|
|
|
|
|
2018-12-07 22:34:21 +01:00
|
|
|
bool tmc_enable_stallguard(TMC2660Stepper);
|
|
|
|
void tmc_disable_stallguard(TMC2660Stepper, const bool);
|
2019-08-05 05:22:58 +02:00
|
|
|
|
|
|
|
#if ENABLED(SPI_ENDSTOPS)
|
|
|
|
|
|
|
|
template<class TMC, char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
|
|
|
|
bool TMCMarlin<TMC, AXIS_LETTER, DRIVER_ID, AXIS_ID>::test_stall_status() {
|
|
|
|
this->switchCSpin(LOW);
|
|
|
|
|
2019-10-15 18:34:45 +02:00
|
|
|
// read stallGuard flag from TMC library, will handle HW and SW SPI
|
|
|
|
TMC2130_n::DRV_STATUS_t drv_status{0};
|
|
|
|
drv_status.sr = this->DRV_STATUS();
|
|
|
|
|
2019-08-05 05:22:58 +02:00
|
|
|
this->switchCSpin(HIGH);
|
|
|
|
|
2019-10-15 18:34:45 +02:00
|
|
|
return drv_status.stallGuard;
|
2019-08-05 05:22:58 +02:00
|
|
|
}
|
|
|
|
#endif // SPI_ENDSTOPS
|
|
|
|
|
|
|
|
#endif // USE_SENSORLESS
|
2017-12-15 22:03:14 +01:00
|
|
|
|
2020-02-09 04:01:57 +01:00
|
|
|
#if HAS_TMC_SPI
|
2018-02-10 21:08:53 +01:00
|
|
|
void tmc_init_cs_pins();
|
|
|
|
#endif
|
2019-05-26 01:22:12 +02:00
|
|
|
|
2020-03-02 19:03:43 +01:00
|
|
|
#endif // HAS_TRINAMIC_CONFIG
|