From 5727cb3ed459c1ac468a550f7e5aa7b8046f36b4 Mon Sep 17 00:00:00 2001 From: domonoky Date: Thu, 26 Feb 2015 12:57:46 +0100 Subject: [PATCH] Cleanup TMC Stepper a bit. --- Marlin/stepper.cpp | 78 +----------------------- Marlin/stepper.h | 40 ------------- Marlin/stepper_indirection.cpp | 106 +++++++++++++++++++++++++++++++++ Marlin/stepper_indirection.h | 54 +++++++++++++---- 4 files changed, 151 insertions(+), 127 deletions(-) create mode 100644 Marlin/stepper_indirection.cpp diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index efb546412..0419c4861 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -87,37 +87,7 @@ static bool check_endstops = true; volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0}; volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1}; -// Stepper objects of TMC steppers are used -#ifdef X_IS_TMC - TMC26XStepper stepperX(200,X_ENABLE_PIN,X_STEP_PIN,X_DIR_PIN,X_MAX_CURRENT,X_SENSE_RESISTOR); -#endif -#ifdef X2_IS_TMC - TMC26XStepper stepperX2(200,X2_ENABLE_PIN,X2_STEP_PIN,X2_DIR_PIN,X2_MAX_CURRENT,X2_SENSE_RESISTOR); -#endif -#ifdef Y_IS_TMC - TMC26XStepper stepperY(200,Y_ENABLE_PIN,Y_STEP_PIN,Y_DIR_PIN,Y_MAX_CURRENT,Y_SENSE_RESISTOR); -#endif -#ifdef Y2_IS_TMC - TMC26XStepper stepperY2(200,Y2_ENABLE_PIN,Y2_STEP_PIN,Y2_DIR_PIN,Y2_MAX_CURRENT,Y2_SENSE_RESISTOR); -#endif -#ifdef Z_IS_TMC - TMC26XStepper stepperZ(200,Z_ENABLE_PIN,Z_STEP_PIN,Z_DIR_PIN,Z_MAX_CURRENT,Z_SENSE_RESISTOR); -#endif -#ifdef Z2_IS_TMC - TMC26XStepper stepperZ2(200,Z2_ENABLE_PIN,Z2_STEP_PIN,Z2_DIR_PIN,Z2_MAX_CURRENT,Z2_SENSE_RESISTOR); -#endif -#ifdef E0_IS_TMC - TMC26XStepper stepperE0(200,E0_ENABLE_PIN,E0_STEP_PIN,E0_DIR_PIN,E0_MAX_CURRENT,E0_SENSE_RESISTOR); -#endif -#ifdef E1_IS_TMC - TMC26XStepper stepperE1(200,E1_ENABLE_PIN,E1_STEP_PIN,E1_DIR_PIN,E1_MAX_CURRENT,E1_SENSE_RESISTOR); -#endif -#ifdef E2_IS_TMC - TMC26XStepper stepperE2(200,E2_ENABLE_PIN,E2_STEP_PIN,E2_DIR_PIN,E2_MAX_CURRENT,E2_SENSE_RESISTOR); -#endif -#ifdef E3_IS_TMC - TMC26XStepper stepperE3(200,E3_ENABLE_PIN,E3_STEP_PIN,E3_DIR_PIN,E3_MAX_CURRENT,E3_SENSE_RESISTOR); -#endif + //=========================================================================== //=============================functions ============================ //=========================================================================== @@ -1420,49 +1390,3 @@ void microstep_readings() SERIAL_PROTOCOLLN( digitalRead(E1_MS2_PIN)); #endif } - -#ifdef HAVE_TMCDRIVER -void tmc_init() -{ -#ifdef X_IS_TMC - stepperX.setMicrosteps(X_MICROSTEPS); - stepperX.start(); -#endif -#ifdef X2_IS_TMC - stepperX2.setMicrosteps(X2_MICROSTEPS); - stepperX2.start(); -#endif -#ifdef Y_IS_TMC - stepperY.setMicrosteps(Y_MICROSTEPS); - stepperY.start(); -#endif -#ifdef Y2_IS_TMC - stepperY2.setMicrosteps(Y2_MICROSTEPS); - stepperY2.start(); -#endif -#ifdef Z_IS_TMC - stepperZ.setMicrosteps(Z_MICROSTEPS); - stepperZ.start(); -#endif -#ifdef Z2_IS_TMC - stepperZ2.setMicrosteps(Z2_MICROSTEPS); - stepperZ2.start(); -#endif -#ifdef E0_IS_TMC - stepperE0.setMicrosteps(E0_MICROSTEPS); - stepperE0.start(); -#endif -#ifdef E1_IS_TMC - stepperE1.setMicrosteps(E1_MICROSTEPS); - stepperE1.start(); -#endif -#ifdef E2_IS_TMC - stepperE2.setMicrosteps(E2_MICROSTEPS); - stepperE2.start(); -#endif -#ifdef E3_IS_TMC - stepperE3.setMicrosteps(E3_MICROSTEPS); - stepperE3.start(); -#endif -} -#endif \ No newline at end of file diff --git a/Marlin/stepper.h b/Marlin/stepper.h index 34a88e1cd..2d316225a 100644 --- a/Marlin/stepper.h +++ b/Marlin/stepper.h @@ -24,11 +24,6 @@ #include "planner.h" #include "stepper_indirection.h" -#ifdef HAVE_TMCDRIVER -#include -#include -#endif - #if EXTRUDERS > 3 #define WRITE_E_STEP(v) { if(current_block->active_extruder == 3) { E3_STEP_WRITE(v); } else { if(current_block->active_extruder == 2) { E2_STEP_WRITE(v); } else { if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }}}} #define NORM_E_DIR() { if(current_block->active_extruder == 3) { E3_DIR_WRITE( !INVERT_E3_DIR); } else { if(current_block->active_extruder == 2) { E2_DIR_WRITE(!INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { E1_DIR_WRITE(!INVERT_E1_DIR); } else { E0_DIR_WRITE(!INVERT_E0_DIR); }}}} @@ -106,39 +101,4 @@ void microstep_readings(); void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention #endif -#ifdef HAVE_TMCDRIVER -void tmc_init(); - -#ifdef X_IS_TMC - extern TMC26XStepper stepperX; -#endif -#ifdef X2_IS_TMC - extern TMC26XStepper stepperX2; -#endif -#ifdef Y_IS_TMC - extern TMC26XStepper stepperY; -#endif -#ifdef Y2_IS_TMC - extern TMC26XStepper stepperY2; -#endif -#ifdef Z_IS_TMC - extern TMC26XStepper stepperZ; -#endif -#ifdef Z2_IS_TMC - extern TMC26XStepper stepperZ2; -#endif -#ifdef E0_IS_TMC - extern TMC26XStepper stepperE0; -#endif -#ifdef E1_IS_TMC - extern TMC26XStepper stepperE1; -#endif -#ifdef E2_IS_TMC - extern TMC26XStepper stepperE2; -#endif -#ifdef E3_IS_TMC - extern TMC26XStepper stepperE3; -#endif -#endif - #endif diff --git a/Marlin/stepper_indirection.cpp b/Marlin/stepper_indirection.cpp new file mode 100644 index 000000000..4c722d369 --- /dev/null +++ b/Marlin/stepper_indirection.cpp @@ -0,0 +1,106 @@ +/* + stepper_indirection.c - stepper motor driver indirection + to allow some stepper functions to be done via SPI/I2c instead of direct pin manipulation + Part of Marlin + + Copyright (c) 2015 Dominik Wenger + + Marlin 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. + + Marlin 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 + along with Marlin. If not, see . +*/ + +#include "stepper_indirection.h" +#include "Configuration.h" + +#ifdef HAVE_TMCDRIVER +#include +#include +#endif + +// Stepper objects of TMC steppers used +#ifdef X_IS_TMC + TMC26XStepper stepperX(200,X_ENABLE_PIN,X_STEP_PIN,X_DIR_PIN,X_MAX_CURRENT,X_SENSE_RESISTOR); +#endif +#ifdef X2_IS_TMC + TMC26XStepper stepperX2(200,X2_ENABLE_PIN,X2_STEP_PIN,X2_DIR_PIN,X2_MAX_CURRENT,X2_SENSE_RESISTOR); +#endif +#ifdef Y_IS_TMC + TMC26XStepper stepperY(200,Y_ENABLE_PIN,Y_STEP_PIN,Y_DIR_PIN,Y_MAX_CURRENT,Y_SENSE_RESISTOR); +#endif +#ifdef Y2_IS_TMC + TMC26XStepper stepperY2(200,Y2_ENABLE_PIN,Y2_STEP_PIN,Y2_DIR_PIN,Y2_MAX_CURRENT,Y2_SENSE_RESISTOR); +#endif +#ifdef Z_IS_TMC + TMC26XStepper stepperZ(200,Z_ENABLE_PIN,Z_STEP_PIN,Z_DIR_PIN,Z_MAX_CURRENT,Z_SENSE_RESISTOR); +#endif +#ifdef Z2_IS_TMC + TMC26XStepper stepperZ2(200,Z2_ENABLE_PIN,Z2_STEP_PIN,Z2_DIR_PIN,Z2_MAX_CURRENT,Z2_SENSE_RESISTOR); +#endif +#ifdef E0_IS_TMC + TMC26XStepper stepperE0(200,E0_ENABLE_PIN,E0_STEP_PIN,E0_DIR_PIN,E0_MAX_CURRENT,E0_SENSE_RESISTOR); +#endif +#ifdef E1_IS_TMC + TMC26XStepper stepperE1(200,E1_ENABLE_PIN,E1_STEP_PIN,E1_DIR_PIN,E1_MAX_CURRENT,E1_SENSE_RESISTOR); +#endif +#ifdef E2_IS_TMC + TMC26XStepper stepperE2(200,E2_ENABLE_PIN,E2_STEP_PIN,E2_DIR_PIN,E2_MAX_CURRENT,E2_SENSE_RESISTOR); +#endif +#ifdef E3_IS_TMC + TMC26XStepper stepperE3(200,E3_ENABLE_PIN,E3_STEP_PIN,E3_DIR_PIN,E3_MAX_CURRENT,E3_SENSE_RESISTOR); +#endif + +#ifdef HAVE_TMCDRIVER +void tmc_init() +{ +#ifdef X_IS_TMC + stepperX.setMicrosteps(X_MICROSTEPS); + stepperX.start(); +#endif +#ifdef X2_IS_TMC + stepperX2.setMicrosteps(X2_MICROSTEPS); + stepperX2.start(); +#endif +#ifdef Y_IS_TMC + stepperY.setMicrosteps(Y_MICROSTEPS); + stepperY.start(); +#endif +#ifdef Y2_IS_TMC + stepperY2.setMicrosteps(Y2_MICROSTEPS); + stepperY2.start(); +#endif +#ifdef Z_IS_TMC + stepperZ.setMicrosteps(Z_MICROSTEPS); + stepperZ.start(); +#endif +#ifdef Z2_IS_TMC + stepperZ2.setMicrosteps(Z2_MICROSTEPS); + stepperZ2.start(); +#endif +#ifdef E0_IS_TMC + stepperE0.setMicrosteps(E0_MICROSTEPS); + stepperE0.start(); +#endif +#ifdef E1_IS_TMC + stepperE1.setMicrosteps(E1_MICROSTEPS); + stepperE1.start(); +#endif +#ifdef E2_IS_TMC + stepperE2.setMicrosteps(E2_MICROSTEPS); + stepperE2.start(); +#endif +#ifdef E3_IS_TMC + stepperE3.setMicrosteps(E3_MICROSTEPS); + stepperE3.start(); +#endif +} +#endif \ No newline at end of file diff --git a/Marlin/stepper_indirection.h b/Marlin/stepper_indirection.h index 66790eb5e..6b226b74b 100644 --- a/Marlin/stepper_indirection.h +++ b/Marlin/stepper_indirection.h @@ -157,9 +157,43 @@ // TMC26X drivers have step and dir on normal pins, but everything else via SPI ////////////////////////////////// #ifdef HAVE_TMCDRIVER +#include +#include + +#ifdef X_IS_TMC + extern TMC26XStepper stepperX; +#endif +#ifdef X2_IS_TMC + extern TMC26XStepper stepperX2; +#endif +#ifdef Y_IS_TMC + extern TMC26XStepper stepperY; +#endif +#ifdef Y2_IS_TMC + extern TMC26XStepper stepperY2; +#endif +#ifdef Z_IS_TMC + extern TMC26XStepper stepperZ; +#endif +#ifdef Z2_IS_TMC + extern TMC26XStepper stepperZ2; +#endif +#ifdef E0_IS_TMC + extern TMC26XStepper stepperE0; +#endif +#ifdef E1_IS_TMC + extern TMC26XStepper stepperE1; +#endif +#ifdef E2_IS_TMC + extern TMC26XStepper stepperE2; +#endif +#ifdef E3_IS_TMC + extern TMC26XStepper stepperE3; +#endif + void tmc_init(); #ifdef X_IS_TMC #undef X_ENABLE_INIT - #define X_ENABLE_INIT + #define X_ENABLE_INIT ((void)0) #undef X_ENABLE_WRITE #define X_ENABLE_WRITE(STATE) stepperX.setEnabled(STATE) @@ -169,7 +203,7 @@ #endif #ifdef X2_IS_TMC #undef X2_ENABLE_INIT - #define X2_ENABLE_INIT + #define X2_ENABLE_INIT ((void)0) #undef X2_ENABLE_WRITE #define X2_ENABLE_WRITE(STATE) stepperX2.setEnabled(STATE) @@ -179,7 +213,7 @@ #endif #ifdef Y_IS_TMC #undef Y_ENABLE_INIT - #define Y_ENABLE_INIT + #define Y_ENABLE_INIT ((void)0) #undef Y_ENABLE_WRITE #define Y_ENABLE_WRITE(STATE) stepperY.setEnabled(STATE) @@ -189,7 +223,7 @@ #endif #ifdef Y2_IS_TMC #undef Y2_ENABLE_INIT - #define Y2_ENABLE_INIT + #define Y2_ENABLE_INIT ((void)0) #undef Y2_ENABLE_WRITE #define Y2_ENABLE_WRITE(STATE) stepperY2.setEnabled(STATE) @@ -199,7 +233,7 @@ #endif #ifdef Z_IS_TMC #undef Z_ENABLE_INIT - #define Z_ENABLE_INIT + #define Z_ENABLE_INIT ((void)0) #undef Z_ENABLE_WRITE #define Z_ENABLE_WRITE(STATE) stepperZ.setEnabled(STATE) @@ -209,7 +243,7 @@ #endif #ifdef Z2_IS_TMC #undef Z2_ENABLE_INIT - #define Z2_ENABLE_INIT + #define Z2_ENABLE_INIT ((void)0) #undef Z2_ENABLE_WRITE #define Z2_ENABLE_WRITE(STATE) stepperZ2.setEnabled(STATE) @@ -219,7 +253,7 @@ #endif #ifdef E0_IS_TMC #undef E0_ENABLE_INIT - #define E0_ENABLE_INIT + #define E0_ENABLE_INIT ((void)0) #undef E0_ENABLE_WRITE #define E0_ENABLE_WRITE(STATE) stepperE0.setEnabled(STATE) @@ -229,7 +263,7 @@ #endif #ifdef E1_IS_TMC #undef E1_ENABLE_INIT - #define E1_ENABLE_INIT + #define E1_ENABLE_INIT ((void)0) #undef E1_ENABLE_WRITE #define E1_ENABLE_WRITE(STATE) stepperE1.setEnabled(STATE) @@ -239,7 +273,7 @@ #endif #ifdef E2_IS_TMC #undef E2_ENABLE_INIT - #define E2_ENABLE_INIT + #define E2_ENABLE_INIT ((void)0) #undef E2_ENABLE_WRITE #define E2_ENABLE_WRITE(STATE) stepperE2.setEnabled(STATE) @@ -249,7 +283,7 @@ #endif #ifdef E3_IS_TMC #undef E3_ENABLE_INIT - #define E3_ENABLE_INIT + #define E3_ENABLE_INIT ((void)0) #undef E3_ENABLE_WRITE #define E3_ENABLE_WRITE(STATE) stepperE3.setEnabled(STATE)