Add TMC2209 support (#14249)
This commit is contained in:
@@ -92,7 +92,7 @@ class TMCStorage {
|
||||
uint8_t hybrid_thrs = 0;
|
||||
#endif
|
||||
#if USE_SENSORLESS
|
||||
int8_t homing_thrs = 0;
|
||||
int16_t homing_thrs = 0;
|
||||
#endif
|
||||
} stored;
|
||||
};
|
||||
@@ -100,10 +100,10 @@ class TMCStorage {
|
||||
template<class TMC, char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
|
||||
class TMCMarlin : public TMC, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
|
||||
public:
|
||||
TMCMarlin(uint16_t cs_pin, float RS) :
|
||||
TMCMarlin(const uint16_t cs_pin, const float RS) :
|
||||
TMC(cs_pin, RS)
|
||||
{}
|
||||
TMCMarlin(uint16_t CS, float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK) :
|
||||
TMCMarlin(const uint16_t CS, const float RS, const uint16_t pinMOSI, const uint16_t pinMISO, const uint16_t pinSCK) :
|
||||
TMC(CS, RS, pinMOSI, pinMISO, pinSCK)
|
||||
{}
|
||||
inline uint16_t rms_current() { return TMC::rms_current(); }
|
||||
@@ -111,7 +111,7 @@ class TMCMarlin : public TMC, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
|
||||
this->val_mA = mA;
|
||||
TMC::rms_current(mA);
|
||||
}
|
||||
inline void rms_current(uint16_t mA, float mult) {
|
||||
inline void rms_current(const uint16_t mA, const float mult) {
|
||||
this->val_mA = mA;
|
||||
TMC::rms_current(mA, mult);
|
||||
}
|
||||
@@ -132,8 +132,9 @@ class TMCMarlin : public TMC, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
|
||||
}
|
||||
#endif
|
||||
#if USE_SENSORLESS
|
||||
inline int8_t sgt() { return TMC::sgt(); }
|
||||
void sgt(const int8_t sgt_val) {
|
||||
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);
|
||||
TMC::sgt(sgt_val);
|
||||
#if HAS_LCD_MENU
|
||||
this->stored.homing_thrs = sgt_val;
|
||||
@@ -148,25 +149,28 @@ class TMCMarlin : public TMC, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
|
||||
inline void refresh_hybrid_thrs() { set_pwm_thrs(this->stored.hybrid_thrs); }
|
||||
#endif
|
||||
#if USE_SENSORLESS
|
||||
inline void refresh_homing_thrs() { sgt(this->stored.homing_thrs); }
|
||||
inline void refresh_homing_thrs() { homing_threshold(this->stored.homing_thrs); }
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static constexpr int8_t sgt_min = -64,
|
||||
sgt_max = 63;
|
||||
};
|
||||
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> {
|
||||
public:
|
||||
TMCMarlin(Stream * SerialPort, float RS, bool has_rx=true) :
|
||||
TMC2208Stepper(SerialPort, RS, has_rx=true)
|
||||
TMCMarlin(Stream * SerialPort, const float RS, const uint8_t) :
|
||||
TMC2208Stepper(SerialPort, RS, /*has_rx=*/true)
|
||||
{}
|
||||
TMCMarlin(uint16_t RX, uint16_t TX, float RS, bool has_rx=true) :
|
||||
TMC2208Stepper(RX, TX, RS, has_rx=true)
|
||||
TMCMarlin(const uint16_t RX, const uint16_t TX, const float RS, const uint8_t, const bool has_rx=true) :
|
||||
TMC2208Stepper(RX, TX, RS, has_rx)
|
||||
{}
|
||||
uint16_t rms_current() { return TMC2208Stepper::rms_current(); }
|
||||
inline void rms_current(uint16_t mA) {
|
||||
inline void rms_current(const uint16_t mA) {
|
||||
this->val_mA = mA;
|
||||
TMC2208Stepper::rms_current(mA);
|
||||
}
|
||||
inline void rms_current(uint16_t mA, float mult) {
|
||||
inline void rms_current(const uint16_t mA, const float mult) {
|
||||
this->val_mA = mA;
|
||||
TMC2208Stepper::rms_current(mA, mult);
|
||||
}
|
||||
@@ -195,24 +199,87 @@ class TMCMarlin<TMC2208Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC220
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
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)
|
||||
{}
|
||||
TMCMarlin(const uint16_t RX, const uint16_t TX, const float RS, const uint8_t addr, const bool) :
|
||||
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);
|
||||
}
|
||||
|
||||
#if HAS_STEALTHCHOP
|
||||
inline void refresh_stepping_mode() { en_spreadCycle(!this->stored.stealthChop_enabled); }
|
||||
inline bool get_stealthChop_status() { return !this->en_spreadCycle(); }
|
||||
#endif
|
||||
#if ENABLED(HYBRID_THRESHOLD)
|
||||
uint32_t get_pwm_thrs() {
|
||||
return _tmc_thrs(this->microsteps(), this->TPWMTHRS(), planner.settings.axis_steps_per_mm[AXIS_ID]);
|
||||
}
|
||||
void set_pwm_thrs(const uint32_t thrs) {
|
||||
TMC2209Stepper::TPWMTHRS(_tmc_thrs(this->microsteps(), thrs, planner.settings.axis_steps_per_mm[AXIS_ID]));
|
||||
#if HAS_LCD_MENU
|
||||
this->stored.hybrid_thrs = thrs;
|
||||
#endif
|
||||
}
|
||||
#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);
|
||||
#if HAS_LCD_MENU
|
||||
this->stored.homing_thrs = sgt_val;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAS_LCD_MENU
|
||||
inline void refresh_stepper_current() { rms_current(this->val_mA); }
|
||||
|
||||
#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;
|
||||
};
|
||||
|
||||
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> {
|
||||
public:
|
||||
TMCMarlin(uint16_t cs_pin, float RS) :
|
||||
TMCMarlin(const uint16_t cs_pin, const float RS) :
|
||||
TMC2660Stepper(cs_pin, RS)
|
||||
{}
|
||||
TMCMarlin(uint16_t CS, float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK) :
|
||||
TMCMarlin(const uint16_t CS, const float RS, const uint16_t pinMOSI, const uint16_t pinMISO, const uint16_t pinSCK) :
|
||||
TMC2660Stepper(CS, RS, pinMOSI, pinMISO, pinSCK)
|
||||
{}
|
||||
inline uint16_t rms_current() { return TMC2660Stepper::rms_current(); }
|
||||
inline void rms_current(uint16_t mA) {
|
||||
inline void rms_current(const uint16_t mA) {
|
||||
this->val_mA = mA;
|
||||
TMC2660Stepper::rms_current(mA);
|
||||
}
|
||||
|
||||
#if USE_SENSORLESS
|
||||
inline int8_t sgt() { return TMC2660Stepper::sgt(); }
|
||||
void sgt(const int8_t sgt_val) {
|
||||
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);
|
||||
TMC2660Stepper::sgt(sgt_val);
|
||||
#if HAS_LCD_MENU
|
||||
this->stored.homing_thrs = sgt_val;
|
||||
@@ -224,9 +291,12 @@ class TMCMarlin<TMC2660Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC266
|
||||
inline void refresh_stepper_current() { rms_current(this->val_mA); }
|
||||
|
||||
#if USE_SENSORLESS
|
||||
inline void refresh_homing_thrs() { sgt(this->stored.homing_thrs); }
|
||||
inline void refresh_homing_thrs() { homing_threshold(this->stored.homing_thrs); }
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static constexpr int8_t sgt_min = -64,
|
||||
sgt_max = 63;
|
||||
};
|
||||
|
||||
template<typename TMC>
|
||||
@@ -262,7 +332,7 @@ void tmc_print_current(TMC &st) {
|
||||
void tmc_print_sgt(TMC &st) {
|
||||
st.printLabel();
|
||||
SERIAL_ECHOPGM(" homing sensitivity: ");
|
||||
SERIAL_PRINTLN(st.sgt(), DEC);
|
||||
SERIAL_PRINTLN(st.homing_threshold(), DEC);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -293,6 +363,9 @@ void test_tmc_connection(const bool test_x, const bool test_y, const bool test_z
|
||||
bool tmc_enable_stallguard(TMC2130Stepper &st);
|
||||
void tmc_disable_stallguard(TMC2130Stepper &st, const bool restore_stealth);
|
||||
|
||||
bool tmc_enable_stallguard(TMC2209Stepper &st);
|
||||
void tmc_disable_stallguard(TMC2209Stepper &st, const bool restore_stealth);
|
||||
|
||||
bool tmc_enable_stallguard(TMC2660Stepper);
|
||||
void tmc_disable_stallguard(TMC2660Stepper, const bool);
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user