@ -36,7 +36,19 @@
# include <SPI.h>
# include <SPI.h>
enum StealthIndex : uint8_t { STEALTH_AXIS_XY , STEALTH_AXIS_Z , STEALTH_AXIS_E } ;
enum StealthIndex : uint8_t { STEALTH_AXIS_XY , STEALTH_AXIS_Z , STEALTH_AXIS_E } ;
# define _TMC_INIT(ST, STEALTH_INDEX) tmc_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, stealthchop_by_axis[STEALTH_INDEX])
# define _TMC_INIT_1(ST, STEALTH_INDEX) tmc_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS)
# define _TMC_INIT_2(ST, STEALTH_INDEX) tmc_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, stealthchop_by_axis[STEALTH_INDEX], ST##_HYBRID_THRESHOLD)
# define _TMC_INIT_3(ST, STEALTH_INDEX) tmc_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, stealthchop_by_axis[STEALTH_INDEX], ST##_HYBRID_THRESHOLD, ST##_COOLSTEP_SPEED_THRESHOLD, ST##_COOLSTEP_LOWER_LOAD_THRESHOLD, ST##_COOLSTEP_UPPER_LOAD_THRESHOLD, ST##_COOLSTEP_SEUP, ST##_COOLSTEP_SEDN, ST##_COOLSTEP_SEIMIN)
# define _TMC_INIT_TMC2660(ST, STEALTH_INDEX) _TMC_INIT_1(ST, STEALTH_INDEX)
# define _TMC_INIT_TMC2160(ST, STEALTH_INDEX) _TMC_INIT_2(ST, STEALTH_INDEX)
# define _TMC_INIT_TMC2208(ST, STEALTH_INDEX) _TMC_INIT_2(ST, STEALTH_INDEX)
# define _TMC_INIT_TMC5130(ST, STEALTH_INDEX) _TMC_INIT_3(ST, STEALTH_INDEX)
# define _TMC_INIT_TMC5160(ST, STEALTH_INDEX) _TMC_INIT_3(ST, STEALTH_INDEX)
# define _TMC_INIT_TMC2130(ST, STEALTH_INDEX) _TMC_INIT_3(ST, STEALTH_INDEX)
# define _TMC_INIT_TMC2209(ST, STEALTH_INDEX) _TMC_INIT_3(ST, STEALTH_INDEX)
# define __TMC_INIT(DRV, ST, STEALTH_INDEX) _TMC_INIT_##DRV(ST, STEALTH_INDEX)
# define _TMC_INIT(DRV, ST, STEALTH_INDEX) __TMC_INIT(DRV, ST, STEALTH_INDEX)
# define TMC_INIT(ST, STEALTH_INDEX) _TMC_INIT(ST##_DRIVER_TYPE, ST, STEALTH_INDEX)
// IC = TMC model number
// IC = TMC model number
// ST = Stepper object letter
// ST = Stepper object letter
@ -122,7 +134,19 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
# if HAS_DRIVER(TMC2130)
# if HAS_DRIVER(TMC2130)
template < char AXIS_LETTER , char DRIVER_ID , AxisEnum AXIS_ID >
template < char AXIS_LETTER , char DRIVER_ID , AxisEnum AXIS_ID >
void tmc_init ( TMCMarlin < TMC2130Stepper , AXIS_LETTER , DRIVER_ID , AXIS_ID > & st , const uint16_t mA , const uint16_t microsteps , const uint32_t thrs , const bool stealth ) {
void tmc_init (
TMCMarlin < TMC2130Stepper , AXIS_LETTER , DRIVER_ID , AXIS_ID > & st ,
const uint16_t mA ,
const uint16_t microsteps ,
const bool stealth ,
const uint32_t hyb_thrs ,
const uint32_t cool_thrs ,
const uint8_t cool_semin ,
const uint8_t cool_semax ,
const uint8_t cool_seup ,
const uint8_t cool_sedn ,
const bool cool_seimin
) {
st . begin ( ) ;
st . begin ( ) ;
CHOPCONF_t chopconf { 0 } ;
CHOPCONF_t chopconf { 0 } ;
@ -152,18 +176,33 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
st . PWMCONF ( pwmconf . sr ) ;
st . PWMCONF ( pwmconf . sr ) ;
# if ENABLED(HYBRID_THRESHOLD)
# if ENABLED(HYBRID_THRESHOLD)
st . set_pwm_thrs ( thrs) ;
st . set_pwm_thrs ( hyb_ thrs) ;
# else
# else
UNUSED ( thrs) ;
UNUSED ( hyb_ thrs) ;
# endif
# endif
st . set_cool_thrs ( cool_thrs ) ; // (mm/s)
COOLCONF_t coolconf { 0 } ;
coolconf . semin = cool_semin ;
coolconf . semax = cool_semax ;
coolconf . seup = cool_seup ;
coolconf . sedn = cool_sedn ;
coolconf . seimin = cool_seimin ;
st . COOLCONF ( coolconf . sr ) ;
st . GSTAT ( ) ; // Clear GSTAT
st . GSTAT ( ) ; // Clear GSTAT
}
}
# endif // TMC2130
# endif // TMC2130
# if HAS_DRIVER(TMC2160)
# if HAS_DRIVER(TMC2160)
template < char AXIS_LETTER , char DRIVER_ID , AxisEnum AXIS_ID >
template < char AXIS_LETTER , char DRIVER_ID , AxisEnum AXIS_ID >
void tmc_init ( TMCMarlin < TMC2160Stepper , AXIS_LETTER , DRIVER_ID , AXIS_ID > & st , const uint16_t mA , const uint16_t microsteps , const uint32_t thrs , const bool stealth ) {
void tmc_init (
TMCMarlin < TMC2160Stepper , AXIS_LETTER , DRIVER_ID , AXIS_ID > & st ,
const uint16_t mA ,
const uint16_t microsteps ,
const bool stealth ,
const uint32_t hyb_thrs
) {
st . begin ( ) ;
st . begin ( ) ;
CHOPCONF_t chopconf { 0 } ;
CHOPCONF_t chopconf { 0 } ;
@ -196,9 +235,9 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
st . PWMCONF ( pwmconf . sr ) ;
st . PWMCONF ( pwmconf . sr ) ;
# if ENABLED(HYBRID_THRESHOLD)
# if ENABLED(HYBRID_THRESHOLD)
st . set_pwm_thrs ( thrs) ;
st . set_pwm_thrs ( hyb_ thrs) ;
# else
# else
UNUSED ( thrs) ;
UNUSED ( hyb_ thrs) ;
# endif
# endif
st . GSTAT ( ) ; // Clear GSTAT
st . GSTAT ( ) ; // Clear GSTAT
@ -440,7 +479,13 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
# if HAS_DRIVER(TMC2208)
# if HAS_DRIVER(TMC2208)
template < char AXIS_LETTER , char DRIVER_ID , AxisEnum AXIS_ID >
template < char AXIS_LETTER , char DRIVER_ID , AxisEnum AXIS_ID >
void tmc_init ( TMCMarlin < TMC2208Stepper , AXIS_LETTER , DRIVER_ID , AXIS_ID > & st , const uint16_t mA , const uint16_t microsteps , const uint32_t thrs , const bool stealth ) {
void tmc_init (
TMCMarlin < TMC2208Stepper , AXIS_LETTER , DRIVER_ID , AXIS_ID > & st ,
const uint16_t mA ,
const uint16_t microsteps ,
const bool stealth ,
const uint32_t hyb_thrs
) {
TMC2208_n : : GCONF_t gconf { 0 } ;
TMC2208_n : : GCONF_t gconf { 0 } ;
gconf . pdn_disable = true ; // Use UART
gconf . pdn_disable = true ; // Use UART
gconf . mstep_reg_select = true ; // Select microsteps with UART
gconf . mstep_reg_select = true ; // Select microsteps with UART
@ -476,9 +521,9 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
st . PWMCONF ( pwmconf . sr ) ;
st . PWMCONF ( pwmconf . sr ) ;
# if ENABLED(HYBRID_THRESHOLD)
# if ENABLED(HYBRID_THRESHOLD)
st . set_pwm_thrs ( thrs) ;
st . set_pwm_thrs ( hyb_ thrs) ;
# else
# else
UNUSED ( thrs) ;
UNUSED ( hyb_ thrs) ;
# endif
# endif
st . GSTAT ( 0b111 ) ; // Clear
st . GSTAT ( 0b111 ) ; // Clear
@ -488,7 +533,19 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
# if HAS_DRIVER(TMC2209)
# if HAS_DRIVER(TMC2209)
template < char AXIS_LETTER , char DRIVER_ID , AxisEnum AXIS_ID >
template < char AXIS_LETTER , char DRIVER_ID , AxisEnum AXIS_ID >
void tmc_init ( TMCMarlin < TMC2209Stepper , AXIS_LETTER , DRIVER_ID , AXIS_ID > & st , const uint16_t mA , const uint16_t microsteps , const uint32_t thrs , const bool stealth ) {
void tmc_init (
TMCMarlin < TMC2209Stepper , AXIS_LETTER , DRIVER_ID , AXIS_ID > & st ,
const uint16_t mA ,
const uint16_t microsteps ,
const bool stealth ,
const uint32_t hyb_thrs ,
const uint32_t cool_thrs ,
const uint8_t cool_semin ,
const uint8_t cool_semax ,
const uint8_t cool_seup ,
const uint8_t cool_sedn ,
const bool cool_seimin
) {
TMC2208_n : : GCONF_t gconf { 0 } ;
TMC2208_n : : GCONF_t gconf { 0 } ;
gconf . pdn_disable = true ; // Use UART
gconf . pdn_disable = true ; // Use UART
gconf . mstep_reg_select = true ; // Select microsteps with UART
gconf . mstep_reg_select = true ; // Select microsteps with UART
@ -524,11 +581,20 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
st . PWMCONF ( pwmconf . sr ) ;
st . PWMCONF ( pwmconf . sr ) ;
# if ENABLED(HYBRID_THRESHOLD)
# if ENABLED(HYBRID_THRESHOLD)
st . set_pwm_thrs ( thrs) ;
st . set_pwm_thrs ( hyb_ thrs) ;
# else
# else
UNUSED ( thrs) ;
UNUSED ( hyb_ thrs) ;
# endif
# endif
st . set_cool_thrs ( cool_thrs ) ; // (mm/s)
COOLCONF_t coolconf { 0 } ;
coolconf . semin = cool_semin ;
coolconf . semax = cool_semax ;
coolconf . seup = cool_seup ;
coolconf . sedn = cool_sedn ;
coolconf . seimin = cool_seimin ;
st . COOLCONF ( coolconf . sr ) ;
st . GSTAT ( 0b111 ) ; // Clear
st . GSTAT ( 0b111 ) ; // Clear
delay ( 200 ) ;
delay ( 200 ) ;
}
}
@ -536,7 +602,11 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
# if HAS_DRIVER(TMC2660)
# if HAS_DRIVER(TMC2660)
template < char AXIS_LETTER , char DRIVER_ID , AxisEnum AXIS_ID >
template < char AXIS_LETTER , char DRIVER_ID , AxisEnum AXIS_ID >
void tmc_init ( TMCMarlin < TMC2660Stepper , AXIS_LETTER , DRIVER_ID , AXIS_ID > & st , const uint16_t mA , const uint16_t microsteps , const uint32_t , const bool ) {
void tmc_init (
TMCMarlin < TMC2660Stepper , AXIS_LETTER , DRIVER_ID , AXIS_ID > & st ,
const uint16_t mA ,
const uint16_t microsteps
) {
st . begin ( ) ;
st . begin ( ) ;
TMC2660_n : : CHOPCONF_t chopconf { 0 } ;
TMC2660_n : : CHOPCONF_t chopconf { 0 } ;
@ -563,7 +633,19 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
# if HAS_DRIVER(TMC5130)
# if HAS_DRIVER(TMC5130)
template < char AXIS_LETTER , char DRIVER_ID , AxisEnum AXIS_ID >
template < char AXIS_LETTER , char DRIVER_ID , AxisEnum AXIS_ID >
void tmc_init ( TMCMarlin < TMC5130Stepper , AXIS_LETTER , DRIVER_ID , AXIS_ID > & st , const uint16_t mA , const uint16_t microsteps , const uint32_t thrs , const bool stealth ) {
void tmc_init (
TMCMarlin < TMC5130Stepper , AXIS_LETTER , DRIVER_ID , AXIS_ID > & st ,
const uint16_t mA ,
const uint16_t microsteps ,
const bool stealth ,
const uint32_t hyb_thrs ,
const uint32_t cool_thrs ,
const uint8_t cool_semin ,
const uint8_t cool_semax ,
const uint8_t cool_seup ,
const uint8_t cool_sedn ,
const bool cool_seimin
) {
st . begin ( ) ;
st . begin ( ) ;
CHOPCONF_t chopconf { 0 } ;
CHOPCONF_t chopconf { 0 } ;
@ -593,18 +675,39 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
st . PWMCONF ( pwmconf . sr ) ;
st . PWMCONF ( pwmconf . sr ) ;
# if ENABLED(HYBRID_THRESHOLD)
# if ENABLED(HYBRID_THRESHOLD)
st . set_pwm_thrs ( thrs) ;
st . set_pwm_thrs ( hyb_ thrs) ;
# else
# else
UNUSED ( thrs) ;
UNUSED ( hyb_ thrs) ;
# endif
# endif
st . set_cool_thrs ( cool_thrs ) ; // (mm/s)
COOLCONF_t coolconf { 0 } ;
coolconf . semin = cool_semin ;
coolconf . semax = cool_semax ;
coolconf . seup = cool_seup ;
coolconf . sedn = cool_sedn ;
coolconf . seimin = cool_seimin ;
st . COOLCONF ( coolconf . sr ) ;
st . GSTAT ( ) ; // Clear GSTAT
st . GSTAT ( ) ; // Clear GSTAT
}
}
# endif // TMC5130
# endif // TMC5130
# if HAS_DRIVER(TMC5160)
# if HAS_DRIVER(TMC5160)
template < char AXIS_LETTER , char DRIVER_ID , AxisEnum AXIS_ID >
template < char AXIS_LETTER , char DRIVER_ID , AxisEnum AXIS_ID >
void tmc_init ( TMCMarlin < TMC5160Stepper , AXIS_LETTER , DRIVER_ID , AXIS_ID > & st , const uint16_t mA , const uint16_t microsteps , const uint32_t thrs , const bool stealth ) {
void tmc_init (
TMCMarlin < TMC5160Stepper , AXIS_LETTER , DRIVER_ID , AXIS_ID > & st ,
const uint16_t mA ,
const uint16_t microsteps ,
const bool stealth ,
const uint32_t hyb_thrs ,
const uint32_t cool_thrs ,
const uint8_t cool_semin ,
const uint8_t cool_semax ,
const uint8_t cool_seup ,
const uint8_t cool_sedn ,
const bool cool_seimin
) {
st . begin ( ) ;
st . begin ( ) ;
CHOPCONF_t chopconf { 0 } ;
CHOPCONF_t chopconf { 0 } ;
@ -637,10 +740,20 @@ enum StealthIndex : uint8_t { STEALTH_AXIS_XY, STEALTH_AXIS_Z, STEALTH_AXIS_E };
st . PWMCONF ( pwmconf . sr ) ;
st . PWMCONF ( pwmconf . sr ) ;
# if ENABLED(HYBRID_THRESHOLD)
# if ENABLED(HYBRID_THRESHOLD)
st . set_pwm_thrs ( thrs) ;
st . set_pwm_thrs ( hyb_ thrs) ;
# else
# else
UNUSED ( thrs) ;
UNUSED ( hyb_ thrs) ;
# endif
# endif
st . set_cool_thrs ( cool_thrs ) ; // (mm/s)
COOLCONF_t coolconf { 0 } ;
coolconf . semin = cool_semin ;
coolconf . semax = cool_semax ;
coolconf . seup = cool_seup ;
coolconf . sedn = cool_sedn ;
coolconf . seimin = cool_seimin ;
st . COOLCONF ( coolconf . sr ) ;
st . GSTAT ( ) ; // Clear GSTAT
st . GSTAT ( ) ; // Clear GSTAT
}
}
# endif // TMC5160
# endif // TMC5160
@ -718,52 +831,52 @@ void reset_trinamic_drivers() {
} ;
} ;
# if AXIS_IS_TMC(X)
# if AXIS_IS_TMC(X)
_ TMC_INIT( X , STEALTH_AXIS_XY ) ;
TMC_INIT( X , STEALTH_AXIS_XY ) ;
# endif
# endif
# if AXIS_IS_TMC(X2)
# if AXIS_IS_TMC(X2)
_ TMC_INIT( X2 , STEALTH_AXIS_XY ) ;
TMC_INIT( X2 , STEALTH_AXIS_XY ) ;
# endif
# endif
# if AXIS_IS_TMC(Y)
# if AXIS_IS_TMC(Y)
_ TMC_INIT( Y , STEALTH_AXIS_XY ) ;
TMC_INIT( Y , STEALTH_AXIS_XY ) ;
# endif
# endif
# if AXIS_IS_TMC(Y2)
# if AXIS_IS_TMC(Y2)
_ TMC_INIT( Y2 , STEALTH_AXIS_XY ) ;
TMC_INIT( Y2 , STEALTH_AXIS_XY ) ;
# endif
# endif
# if AXIS_IS_TMC(Z)
# if AXIS_IS_TMC(Z)
_ TMC_INIT( Z , STEALTH_AXIS_Z ) ;
TMC_INIT( Z , STEALTH_AXIS_Z ) ;
# endif
# endif
# if AXIS_IS_TMC(Z2)
# if AXIS_IS_TMC(Z2)
_ TMC_INIT( Z2 , STEALTH_AXIS_Z ) ;
TMC_INIT( Z2 , STEALTH_AXIS_Z ) ;
# endif
# endif
# if AXIS_IS_TMC(Z3)
# if AXIS_IS_TMC(Z3)
_ TMC_INIT( Z3 , STEALTH_AXIS_Z ) ;
TMC_INIT( Z3 , STEALTH_AXIS_Z ) ;
# endif
# endif
# if AXIS_IS_TMC(Z4)
# if AXIS_IS_TMC(Z4)
_ TMC_INIT( Z4 , STEALTH_AXIS_Z ) ;
TMC_INIT( Z4 , STEALTH_AXIS_Z ) ;
# endif
# endif
# if AXIS_IS_TMC(E0)
# if AXIS_IS_TMC(E0)
_ TMC_INIT( E0 , STEALTH_AXIS_E ) ;
TMC_INIT( E0 , STEALTH_AXIS_E ) ;
# endif
# endif
# if AXIS_IS_TMC(E1)
# if AXIS_IS_TMC(E1)
_ TMC_INIT( E1 , STEALTH_AXIS_E ) ;
TMC_INIT( E1 , STEALTH_AXIS_E ) ;
# endif
# endif
# if AXIS_IS_TMC(E2)
# if AXIS_IS_TMC(E2)
_ TMC_INIT( E2 , STEALTH_AXIS_E ) ;
TMC_INIT( E2 , STEALTH_AXIS_E ) ;
# endif
# endif
# if AXIS_IS_TMC(E3)
# if AXIS_IS_TMC(E3)
_ TMC_INIT( E3 , STEALTH_AXIS_E ) ;
TMC_INIT( E3 , STEALTH_AXIS_E ) ;
# endif
# endif
# if AXIS_IS_TMC(E4)
# if AXIS_IS_TMC(E4)
_ TMC_INIT( E4 , STEALTH_AXIS_E ) ;
TMC_INIT( E4 , STEALTH_AXIS_E ) ;
# endif
# endif
# if AXIS_IS_TMC(E5)
# if AXIS_IS_TMC(E5)
_ TMC_INIT( E5 , STEALTH_AXIS_E ) ;
TMC_INIT( E5 , STEALTH_AXIS_E ) ;
# endif
# endif
# if AXIS_IS_TMC(E6)
# if AXIS_IS_TMC(E6)
_ TMC_INIT( E6 , STEALTH_AXIS_E ) ;
TMC_INIT( E6 , STEALTH_AXIS_E ) ;
# endif
# endif
# if AXIS_IS_TMC(E7)
# if AXIS_IS_TMC(E7)
_ TMC_INIT( E7 , STEALTH_AXIS_E ) ;
TMC_INIT( E7 , STEALTH_AXIS_E ) ;
# endif
# endif
# if USE_SENSORLESS
# if USE_SENSORLESS