Reduce all stepper_indirection init code with macros

master
Scott Lahteine 8 years ago
parent 4e4f37b6c2
commit 644fac5d34

@ -45,12 +45,14 @@
#include "MarlinConfig.h" #include "MarlinConfig.h"
//
// TMC26X Driver objects and inits
//
#if ENABLED(HAVE_TMCDRIVER) #if ENABLED(HAVE_TMCDRIVER)
#include <SPI.h> #include <SPI.h>
#include <TMC26XStepper.h> #include <TMC26XStepper.h>
#endif
// Stepper objects of TMC steppers used
#if ENABLED(X_IS_TMC) #if ENABLED(X_IS_TMC)
TMC26XStepper stepperX(200, X_ENABLE_PIN, X_STEP_PIN, X_DIR_PIN, X_MAX_CURRENT, X_SENSE_RESISTOR); TMC26XStepper stepperX(200, X_ENABLE_PIN, X_STEP_PIN, X_DIR_PIN, X_MAX_CURRENT, X_SENSE_RESISTOR);
#endif #endif
@ -82,51 +84,49 @@
TMC26XStepper stepperE3(200, E3_ENABLE_PIN, E3_STEP_PIN, E3_DIR_PIN, E3_MAX_CURRENT, E3_SENSE_RESISTOR); TMC26XStepper stepperE3(200, E3_ENABLE_PIN, E3_STEP_PIN, E3_DIR_PIN, E3_MAX_CURRENT, E3_SENSE_RESISTOR);
#endif #endif
#if ENABLED(HAVE_TMCDRIVER) #define _TMC_INIT(A) do{ \
stepper##A.setMicrosteps(A##_MICROSTEPS);
stepper##A.start();
} while(0)
void tmc_init() { void tmc_init() {
#if ENABLED(X_IS_TMC) #if ENABLED(X_IS_TMC)
stepperX.setMicrosteps(X_MICROSTEPS); _TMC_INIT(X);
stepperX.start();
#endif #endif
#if ENABLED(X2_IS_TMC) #if ENABLED(X2_IS_TMC)
stepperX2.setMicrosteps(X2_MICROSTEPS); _TMC_INIT(X2);
stepperX2.start();
#endif #endif
#if ENABLED(Y_IS_TMC) #if ENABLED(Y_IS_TMC)
stepperY.setMicrosteps(Y_MICROSTEPS); _TMC_INIT(Y);
stepperY.start();
#endif #endif
#if ENABLED(Y2_IS_TMC) #if ENABLED(Y2_IS_TMC)
stepperY2.setMicrosteps(Y2_MICROSTEPS); _TMC_INIT(Y2);
stepperY2.start();
#endif #endif
#if ENABLED(Z_IS_TMC) #if ENABLED(Z_IS_TMC)
stepperZ.setMicrosteps(Z_MICROSTEPS); _TMC_INIT(Z);
stepperZ.start();
#endif #endif
#if ENABLED(Z2_IS_TMC) #if ENABLED(Z2_IS_TMC)
stepperZ2.setMicrosteps(Z2_MICROSTEPS); _TMC_INIT(Z2);
stepperZ2.start();
#endif #endif
#if ENABLED(E0_IS_TMC) #if ENABLED(E0_IS_TMC)
stepperE0.setMicrosteps(E0_MICROSTEPS); _TMC_INIT(E0);
stepperE0.start();
#endif #endif
#if ENABLED(E1_IS_TMC) #if ENABLED(E1_IS_TMC)
stepperE1.setMicrosteps(E1_MICROSTEPS); _TMC_INIT(E1);
stepperE1.start();
#endif #endif
#if ENABLED(E2_IS_TMC) #if ENABLED(E2_IS_TMC)
stepperE2.setMicrosteps(E2_MICROSTEPS); _TMC_INIT(E2);
stepperE2.start();
#endif #endif
#if ENABLED(E3_IS_TMC) #if ENABLED(E3_IS_TMC)
stepperE3.setMicrosteps(E3_MICROSTEPS); _TMC_INIT(E3);
stepperE3.start();
#endif #endif
} }
#endif
#endif // HAVE_TMCDRIVER
//
// TMC2130 Driver objects and inits
//
#if ENABLED(HAVE_TMC2130DRIVER) #if ENABLED(HAVE_TMC2130DRIVER)
#include <SPI.h> #include <SPI.h>
@ -549,12 +549,13 @@ void tmc_init() {
#endif // HAVE_TMC2130DRIVER #endif // HAVE_TMC2130DRIVER
//
// L6470 Driver objects and inits // L6470 Driver objects and inits
//
#if ENABLED(HAVE_L6470DRIVER) #if ENABLED(HAVE_L6470DRIVER)
#include <SPI.h> #include <SPI.h>
#include <L6470.h> #include <L6470.h>
#endif
// L6470 Stepper objects // L6470 Stepper objects
#if ENABLED(X_IS_L6470) #if ENABLED(X_IS_L6470)
@ -588,80 +589,46 @@ void tmc_init() {
L6470 stepperE3(E3_ENABLE_PIN); L6470 stepperE3(E3_ENABLE_PIN);
#endif #endif
#define _L6470_INIT(A) do{ \
stepper##A.init(A##_K_VAL); \
stepper##A.softFree(); \
stepper##A.setMicroSteps(A##_MICROSTEPS); \
stepper##A.setOverCurrent(A##_OVERCURRENT); \
stepper##A.setStallCurrent(A##_STALLCURRENT); \
} while(0)
// init routine
#if ENABLED(HAVE_L6470DRIVER)
void L6470_init() { void L6470_init() {
#if ENABLED(X_IS_L6470) #if ENABLED(X_IS_L6470)
stepperX.init(X_K_VAL); _L6470_INIT(X);
stepperX.softFree();
stepperX.setMicroSteps(X_MICROSTEPS);
stepperX.setOverCurrent(X_OVERCURRENT); //set overcurrent protection
stepperX.setStallCurrent(X_STALLCURRENT);
#endif #endif
#if ENABLED(X2_IS_L6470) #if ENABLED(X2_IS_L6470)
stepperX2.init(X2_K_VAL); _L6470_INIT(X2);
stepperX2.softFree();
stepperX2.setMicroSteps(X2_MICROSTEPS);
stepperX2.setOverCurrent(X2_OVERCURRENT); //set overcurrent protection
stepperX2.setStallCurrent(X2_STALLCURRENT);
#endif #endif
#if ENABLED(Y_IS_L6470) #if ENABLED(Y_IS_L6470)
stepperY.init(Y_K_VAL); _L6470_INIT(Y);
stepperY.softFree();
stepperY.setMicroSteps(Y_MICROSTEPS);
stepperY.setOverCurrent(Y_OVERCURRENT); //set overcurrent protection
stepperY.setStallCurrent(Y_STALLCURRENT);
#endif #endif
#if ENABLED(Y2_IS_L6470) #if ENABLED(Y2_IS_L6470)
stepperY2.init(Y2_K_VAL); _L6470_INIT(Y2);
stepperY2.softFree();
stepperY2.setMicroSteps(Y2_MICROSTEPS);
stepperY2.setOverCurrent(Y2_OVERCURRENT); //set overcurrent protection
stepperY2.setStallCurrent(Y2_STALLCURRENT);
#endif #endif
#if ENABLED(Z_IS_L6470) #if ENABLED(Z_IS_L6470)
stepperZ.init(Z_K_VAL); _L6470_INIT(Z);
stepperZ.softFree();
stepperZ.setMicroSteps(Z_MICROSTEPS);
stepperZ.setOverCurrent(Z_OVERCURRENT); //set overcurrent protection
stepperZ.setStallCurrent(Z_STALLCURRENT);
#endif #endif
#if ENABLED(Z2_IS_L6470) #if ENABLED(Z2_IS_L6470)
stepperZ2.init(Z2_K_VAL); _L6470_INIT(Z2);
stepperZ2.softFree();
stepperZ2.setMicroSteps(Z2_MICROSTEPS);
stepperZ2.setOverCurrent(Z2_OVERCURRENT); //set overcurrent protection
stepperZ2.setStallCurrent(Z2_STALLCURRENT);
#endif #endif
#if ENABLED(E0_IS_L6470) #if ENABLED(E0_IS_L6470)
stepperE0.init(E0_K_VAL); _L6470_INIT(E0);
stepperE0.softFree();
stepperE0.setMicroSteps(E0_MICROSTEPS);
stepperE0.setOverCurrent(E0_OVERCURRENT); //set overcurrent protection
stepperE0.setStallCurrent(E0_STALLCURRENT);
#endif #endif
#if ENABLED(E1_IS_L6470) #if ENABLED(E1_IS_L6470)
stepperE1.init(E1_K_VAL); _L6470_INIT(E1);
stepperE1.softFree();
stepperE1.setMicroSteps(E1_MICROSTEPS);
stepperE1.setOverCurrent(E1_OVERCURRENT); //set overcurrent protection
stepperE1.setStallCurrent(E1_STALLCURRENT);
#endif #endif
#if ENABLED(E2_IS_L6470) #if ENABLED(E2_IS_L6470)
stepperE2.init(E2_K_VAL); _L6470_INIT(E2);
stepperE2.softFree();
stepperE2.setMicroSteps(E2_MICROSTEPS);
stepperE2.setOverCurrent(E2_OVERCURRENT); //set overcurrent protection
stepperE2.setStallCurrent(E2_STALLCURRENT);
#endif #endif
#if ENABLED(E3_IS_L6470) #if ENABLED(E3_IS_L6470)
stepperE3.init(E3_K_VAL); _L6470_INIT(E3);
stepperE3.softFree();
stepperE3.setMicroSteps(E3_MICROSTEPS);
stepperE3.setOverCurrent(E3_OVERCURRENT); //set overcurrent protection
stepperE3.setStallCurrent(E3_STALLCURRENT);
#endif #endif
} }
#endif
#endif // HAVE_L6470DRIVER

Loading…
Cancel
Save