Firmware/Marlin/stepper_indirection.h

519 lines
25 KiB
C
Raw Normal View History

/**
2016-03-24 19:01:20 +01:00
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
2018-03-07 12:45:06 +01:00
* stepper_indirection.h - stepper motor driver indirection macros
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef STEPPER_INDIRECTION_H
#define STEPPER_INDIRECTION_H
#include "MarlinConfig.h"
2016-07-25 03:54:24 +02:00
// TMC26X drivers have STEP/DIR on normal pins, but ENABLE via SPI
#if ENABLED(HAVE_TMC26X)
2016-07-25 03:54:24 +02:00
#include <SPI.h>
#include <TMC26XStepper.h>
void tmc26x_init_to_defaults();
2016-07-25 03:54:24 +02:00
#endif
#if ENABLED(HAVE_TMC2130)
#include <TMC2130Stepper.h>
void tmc2130_init_to_defaults();
2016-09-14 08:48:47 +02:00
#endif
2017-12-15 22:02:39 +01:00
#if ENABLED(HAVE_TMC2208)
#include <TMC2208Stepper.h>
void tmc2208_serial_begin();
void tmc2208_init_to_defaults();
2017-12-15 22:02:39 +01:00
#endif
2016-07-25 03:54:24 +02:00
// L6470 has STEP on normal pins, but DIR/ENABLE via SPI
#if ENABLED(HAVE_L6470DRIVER)
#include <SPI.h>
#include <L6470.h>
void L6470_init_to_defaults();
2016-07-25 03:54:24 +02:00
#endif
void restore_stepper_drivers(); // Called by PSU_ON
void reset_stepper_drivers(); // Called by settings.load / settings.reset
2016-07-25 03:54:24 +02:00
// X Stepper
#if ENABLED(X_IS_L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperX;
#define X_ENABLE_INIT NOOP
#define X_ENABLE_WRITE(STATE) do{ if (STATE) stepperX.Step_Clock(stepperX.getStatus() & STATUS_HIZ); else stepperX.softFree(); }while(0)
2016-07-25 03:54:24 +02:00
#define X_ENABLE_READ (stepperX.getStatus() & STATUS_HIZ)
#define X_DIR_INIT NOOP
#define X_DIR_WRITE(STATE) stepperX.Step_Clock(STATE)
#define X_DIR_READ (stepperX.getStatus() & STATUS_DIR)
#else
#if ENABLED(X_IS_TMC26X)
2016-07-25 03:54:24 +02:00
extern TMC26XStepper stepperX;
#define X_ENABLE_INIT NOOP
#define X_ENABLE_WRITE(STATE) stepperX.setEnabled(STATE)
#define X_ENABLE_READ stepperX.isEnabled()
#else
#if ENABLED(X_IS_TMC2130)
extern TMC2130Stepper stepperX;
#elif ENABLED(X_IS_TMC2208)
2017-12-15 22:02:39 +01:00
extern TMC2208Stepper stepperX;
2016-09-14 08:48:47 +02:00
#endif
2016-07-25 03:54:24 +02:00
#define X_ENABLE_INIT SET_OUTPUT(X_ENABLE_PIN)
#define X_ENABLE_WRITE(STATE) WRITE(X_ENABLE_PIN,STATE)
#define X_ENABLE_READ READ(X_ENABLE_PIN)
#endif
#define X_DIR_INIT SET_OUTPUT(X_DIR_PIN)
#define X_DIR_WRITE(STATE) WRITE(X_DIR_PIN,STATE)
#define X_DIR_READ READ(X_DIR_PIN)
#endif
#define X_STEP_INIT SET_OUTPUT(X_STEP_PIN)
#define X_STEP_WRITE(STATE) WRITE(X_STEP_PIN,STATE)
#define X_STEP_READ READ(X_STEP_PIN)
2016-07-25 03:54:24 +02:00
// Y Stepper
#if ENABLED(Y_IS_L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperY;
#define Y_ENABLE_INIT NOOP
#define Y_ENABLE_WRITE(STATE) do{ if (STATE) stepperY.Step_Clock(stepperY.getStatus() & STATUS_HIZ); else stepperY.softFree(); }while(0)
2016-07-25 03:54:24 +02:00
#define Y_ENABLE_READ (stepperY.getStatus() & STATUS_HIZ)
#define Y_DIR_INIT NOOP
#define Y_DIR_WRITE(STATE) stepperY.Step_Clock(STATE)
#define Y_DIR_READ (stepperY.getStatus() & STATUS_DIR)
#else
#if ENABLED(Y_IS_TMC26X)
2016-07-25 03:54:24 +02:00
extern TMC26XStepper stepperY;
#define Y_ENABLE_INIT NOOP
#define Y_ENABLE_WRITE(STATE) stepperY.setEnabled(STATE)
#define Y_ENABLE_READ stepperY.isEnabled()
#else
#if ENABLED(Y_IS_TMC2130)
extern TMC2130Stepper stepperY;
#elif ENABLED(Y_IS_TMC2208)
2017-12-15 22:02:39 +01:00
extern TMC2208Stepper stepperY;
2016-09-14 08:48:47 +02:00
#endif
2016-07-25 03:54:24 +02:00
#define Y_ENABLE_INIT SET_OUTPUT(Y_ENABLE_PIN)
#define Y_ENABLE_WRITE(STATE) WRITE(Y_ENABLE_PIN,STATE)
#define Y_ENABLE_READ READ(Y_ENABLE_PIN)
#endif
#define Y_DIR_INIT SET_OUTPUT(Y_DIR_PIN)
#define Y_DIR_WRITE(STATE) WRITE(Y_DIR_PIN,STATE)
#define Y_DIR_READ READ(Y_DIR_PIN)
#endif
#define Y_STEP_INIT SET_OUTPUT(Y_STEP_PIN)
#define Y_STEP_WRITE(STATE) WRITE(Y_STEP_PIN,STATE)
#define Y_STEP_READ READ(Y_STEP_PIN)
2016-07-25 03:54:24 +02:00
// Z Stepper
#if ENABLED(Z_IS_L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperZ;
#define Z_ENABLE_INIT NOOP
#define Z_ENABLE_WRITE(STATE) do{ if (STATE) stepperZ.Step_Clock(stepperZ.getStatus() & STATUS_HIZ); else stepperZ.softFree(); }while(0)
2016-07-25 03:54:24 +02:00
#define Z_ENABLE_READ (stepperZ.getStatus() & STATUS_HIZ)
#define Z_DIR_INIT NOOP
#define Z_DIR_WRITE(STATE) stepperZ.Step_Clock(STATE)
#define Z_DIR_READ (stepperZ.getStatus() & STATUS_DIR)
#else
#if ENABLED(Z_IS_TMC26X)
2016-07-25 03:54:24 +02:00
extern TMC26XStepper stepperZ;
#define Z_ENABLE_INIT NOOP
#define Z_ENABLE_WRITE(STATE) stepperZ.setEnabled(STATE)
#define Z_ENABLE_READ stepperZ.isEnabled()
#else
#if ENABLED(Z_IS_TMC2130)
extern TMC2130Stepper stepperZ;
#elif ENABLED(Z_IS_TMC2208)
2017-12-15 22:02:39 +01:00
extern TMC2208Stepper stepperZ;
2016-09-14 08:48:47 +02:00
#endif
2016-07-25 03:54:24 +02:00
#define Z_ENABLE_INIT SET_OUTPUT(Z_ENABLE_PIN)
#define Z_ENABLE_WRITE(STATE) WRITE(Z_ENABLE_PIN,STATE)
#define Z_ENABLE_READ READ(Z_ENABLE_PIN)
#endif
#define Z_DIR_INIT SET_OUTPUT(Z_DIR_PIN)
#define Z_DIR_WRITE(STATE) WRITE(Z_DIR_PIN,STATE)
#define Z_DIR_READ READ(Z_DIR_PIN)
#endif
#define Z_STEP_INIT SET_OUTPUT(Z_STEP_PIN)
#define Z_STEP_WRITE(STATE) WRITE(Z_STEP_PIN,STATE)
#define Z_STEP_READ READ(Z_STEP_PIN)
2016-07-25 03:54:24 +02:00
// X2 Stepper
2016-07-11 19:19:07 +02:00
#if HAS_X2_ENABLE
#if ENABLED(X2_IS_L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperX2;
#define X2_ENABLE_INIT NOOP
#define X2_ENABLE_WRITE(STATE) do{ if (STATE) stepperX2.Step_Clock(stepperX2.getStatus() & STATUS_HIZ); else stepperX2.softFree(); }while(0)
2016-07-25 03:54:24 +02:00
#define X2_ENABLE_READ (stepperX2.getStatus() & STATUS_HIZ)
#define X2_DIR_INIT NOOP
#define X2_DIR_WRITE(STATE) stepperX2.Step_Clock(STATE)
#define X2_DIR_READ (stepperX2.getStatus() & STATUS_DIR)
#else
#if ENABLED(X2_IS_TMC26X)
2016-07-25 03:54:24 +02:00
extern TMC26XStepper stepperX2;
#define X2_ENABLE_INIT NOOP
#define X2_ENABLE_WRITE(STATE) stepperX2.setEnabled(STATE)
#define X2_ENABLE_READ stepperX2.isEnabled()
#else
#if ENABLED(X2_IS_TMC2130)
extern TMC2130Stepper stepperX2;
#elif ENABLED(X2_IS_TMC2208)
2017-12-15 22:02:39 +01:00
extern TMC2208Stepper stepperX2;
2016-09-14 08:48:47 +02:00
#endif
2016-07-25 03:54:24 +02:00
#define X2_ENABLE_INIT SET_OUTPUT(X2_ENABLE_PIN)
#define X2_ENABLE_WRITE(STATE) WRITE(X2_ENABLE_PIN,STATE)
#define X2_ENABLE_READ READ(X2_ENABLE_PIN)
#endif
#define X2_DIR_INIT SET_OUTPUT(X2_DIR_PIN)
#define X2_DIR_WRITE(STATE) WRITE(X2_DIR_PIN,STATE)
#define X2_DIR_READ READ(X2_DIR_PIN)
#endif
2016-05-17 23:56:49 +02:00
#define X2_STEP_INIT SET_OUTPUT(X2_STEP_PIN)
#define X2_STEP_WRITE(STATE) WRITE(X2_STEP_PIN,STATE)
#define X2_STEP_READ READ(X2_STEP_PIN)
2016-07-20 19:24:33 +02:00
#endif
2016-07-25 03:54:24 +02:00
// Y2 Stepper
2016-07-11 19:19:07 +02:00
#if HAS_Y2_ENABLE
#if ENABLED(Y2_IS_L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperY2;
#define Y2_ENABLE_INIT NOOP
#define Y2_ENABLE_WRITE(STATE) do{ if (STATE) stepperY2.Step_Clock(stepperY2.getStatus() & STATUS_HIZ); else stepperY2.softFree(); }while(0)
2016-07-25 03:54:24 +02:00
#define Y2_ENABLE_READ (stepperY2.getStatus() & STATUS_HIZ)
#define Y2_DIR_INIT NOOP
#define Y2_DIR_WRITE(STATE) stepperY2.Step_Clock(STATE)
#define Y2_DIR_READ (stepperY2.getStatus() & STATUS_DIR)
#else
#if ENABLED(Y2_IS_TMC26X)
2016-07-25 03:54:24 +02:00
extern TMC26XStepper stepperY2;
#define Y2_ENABLE_INIT NOOP
#define Y2_ENABLE_WRITE(STATE) stepperY2.setEnabled(STATE)
#define Y2_ENABLE_READ stepperY2.isEnabled()
#else
#if ENABLED(Y2_IS_TMC2130)
extern TMC2130Stepper stepperY2;
#elif ENABLED(Y2_IS_TMC2208)
2017-12-15 22:02:39 +01:00
extern TMC2208Stepper stepperY2;
2016-09-14 08:48:47 +02:00
#endif
2016-07-25 03:54:24 +02:00
#define Y2_ENABLE_INIT SET_OUTPUT(Y2_ENABLE_PIN)
#define Y2_ENABLE_WRITE(STATE) WRITE(Y2_ENABLE_PIN,STATE)
#define Y2_ENABLE_READ READ(Y2_ENABLE_PIN)
#endif
#define Y2_DIR_INIT SET_OUTPUT(Y2_DIR_PIN)
#define Y2_DIR_WRITE(STATE) WRITE(Y2_DIR_PIN,STATE)
#define Y2_DIR_READ READ(Y2_DIR_PIN)
#endif
2016-05-17 23:56:49 +02:00
#define Y2_STEP_INIT SET_OUTPUT(Y2_STEP_PIN)
#define Y2_STEP_WRITE(STATE) WRITE(Y2_STEP_PIN,STATE)
#define Y2_STEP_READ READ(Y2_STEP_PIN)
2016-07-25 03:54:24 +02:00
#endif
2016-07-25 03:54:24 +02:00
// Z2 Stepper
2016-07-11 19:19:07 +02:00
#if HAS_Z2_ENABLE
#if ENABLED(Z2_IS_L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperZ2;
#define Z2_ENABLE_INIT NOOP
#define Z2_ENABLE_WRITE(STATE) do{ if (STATE) stepperZ2.Step_Clock(stepperZ2.getStatus() & STATUS_HIZ); else stepperZ2.softFree(); }while(0)
2016-07-25 03:54:24 +02:00
#define Z2_ENABLE_READ (stepperZ2.getStatus() & STATUS_HIZ)
#define Z2_DIR_INIT NOOP
#define Z2_DIR_WRITE(STATE) stepperZ2.Step_Clock(STATE)
#define Z2_DIR_READ (stepperZ2.getStatus() & STATUS_DIR)
#else
#if ENABLED(Z2_IS_TMC26X)
2016-07-25 03:54:24 +02:00
extern TMC26XStepper stepperZ2;
#define Z2_ENABLE_INIT NOOP
#define Z2_ENABLE_WRITE(STATE) stepperZ2.setEnabled(STATE)
#define Z2_ENABLE_READ stepperZ2.isEnabled()
#else
#if ENABLED(Z2_IS_TMC2130)
extern TMC2130Stepper stepperZ2;
#elif ENABLED(Z2_IS_TMC2208)
2017-12-15 22:02:39 +01:00
extern TMC2208Stepper stepperZ2;
2016-09-14 08:48:47 +02:00
#endif
2016-07-25 03:54:24 +02:00
#define Z2_ENABLE_INIT SET_OUTPUT(Z2_ENABLE_PIN)
#define Z2_ENABLE_WRITE(STATE) WRITE(Z2_ENABLE_PIN,STATE)
#define Z2_ENABLE_READ READ(Z2_ENABLE_PIN)
#endif
#define Z2_DIR_INIT SET_OUTPUT(Z2_DIR_PIN)
#define Z2_DIR_WRITE(STATE) WRITE(Z2_DIR_PIN,STATE)
#define Z2_DIR_READ READ(Z2_DIR_PIN)
#endif
2016-05-17 23:56:49 +02:00
#define Z2_STEP_INIT SET_OUTPUT(Z2_STEP_PIN)
#define Z2_STEP_WRITE(STATE) WRITE(Z2_STEP_PIN,STATE)
#define Z2_STEP_READ READ(Z2_STEP_PIN)
2016-07-25 03:54:24 +02:00
#endif
2016-05-17 23:56:49 +02:00
2016-07-25 03:54:24 +02:00
// E0 Stepper
#if ENABLED(E0_IS_L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperE0;
#define E0_ENABLE_INIT NOOP
#define E0_ENABLE_WRITE(STATE) do{ if (STATE) stepperE0.Step_Clock(stepperE0.getStatus() & STATUS_HIZ); else stepperE0.softFree(); }while(0)
2016-07-25 03:54:24 +02:00
#define E0_ENABLE_READ (stepperE0.getStatus() & STATUS_HIZ)
#define E0_DIR_INIT NOOP
#define E0_DIR_WRITE(STATE) stepperE0.Step_Clock(STATE)
#define E0_DIR_READ (stepperE0.getStatus() & STATUS_DIR)
#else
#if ENABLED(E0_IS_TMC26X)
2016-07-25 03:54:24 +02:00
extern TMC26XStepper stepperE0;
#define E0_ENABLE_INIT NOOP
#define E0_ENABLE_WRITE(STATE) stepperE0.setEnabled(STATE)
#define E0_ENABLE_READ stepperE0.isEnabled()
#else
#if ENABLED(E0_IS_TMC2130)
extern TMC2130Stepper stepperE0;
#elif ENABLED(E0_IS_TMC2208)
2017-12-15 22:02:39 +01:00
extern TMC2208Stepper stepperE0;
2016-09-14 08:48:47 +02:00
#endif
2016-07-25 03:54:24 +02:00
#define E0_ENABLE_INIT SET_OUTPUT(E0_ENABLE_PIN)
#define E0_ENABLE_WRITE(STATE) WRITE(E0_ENABLE_PIN,STATE)
#define E0_ENABLE_READ READ(E0_ENABLE_PIN)
#endif
#define E0_DIR_INIT SET_OUTPUT(E0_DIR_PIN)
#define E0_DIR_WRITE(STATE) WRITE(E0_DIR_PIN,STATE)
#define E0_DIR_READ READ(E0_DIR_PIN)
#endif
#define E0_STEP_INIT SET_OUTPUT(E0_STEP_PIN)
#define E0_STEP_WRITE(STATE) WRITE(E0_STEP_PIN,STATE)
#define E0_STEP_READ READ(E0_STEP_PIN)
2016-07-25 03:54:24 +02:00
// E1 Stepper
#if ENABLED(E1_IS_L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperE1;
#define E1_ENABLE_INIT NOOP
#define E1_ENABLE_WRITE(STATE) do{ if (STATE) stepperE1.Step_Clock(stepperE1.getStatus() & STATUS_HIZ); else stepperE1.softFree(); }while(0)
2016-07-25 03:54:24 +02:00
#define E1_ENABLE_READ (stepperE1.getStatus() & STATUS_HIZ)
#define E1_DIR_INIT NOOP
#define E1_DIR_WRITE(STATE) stepperE1.Step_Clock(STATE)
#define E1_DIR_READ (stepperE1.getStatus() & STATUS_DIR)
#else
#if ENABLED(E1_IS_TMC26X)
2016-07-25 03:54:24 +02:00
extern TMC26XStepper stepperE1;
#define E1_ENABLE_INIT NOOP
#define E1_ENABLE_WRITE(STATE) stepperE1.setEnabled(STATE)
#define E1_ENABLE_READ stepperE1.isEnabled()
#else
#if ENABLED(E1_IS_TMC2130)
extern TMC2130Stepper stepperE1;
#elif ENABLED(E1_IS_TMC2208)
2017-12-15 22:02:39 +01:00
extern TMC2208Stepper stepperE1;
2016-09-14 08:48:47 +02:00
#endif
2016-07-25 03:54:24 +02:00
#define E1_ENABLE_INIT SET_OUTPUT(E1_ENABLE_PIN)
#define E1_ENABLE_WRITE(STATE) WRITE(E1_ENABLE_PIN,STATE)
#define E1_ENABLE_READ READ(E1_ENABLE_PIN)
#endif
#define E1_DIR_INIT SET_OUTPUT(E1_DIR_PIN)
#define E1_DIR_WRITE(STATE) WRITE(E1_DIR_PIN,STATE)
#define E1_DIR_READ READ(E1_DIR_PIN)
#endif
#define E1_STEP_INIT SET_OUTPUT(E1_STEP_PIN)
#define E1_STEP_WRITE(STATE) WRITE(E1_STEP_PIN,STATE)
#define E1_STEP_READ READ(E1_STEP_PIN)
2016-07-25 03:54:24 +02:00
// E2 Stepper
#if ENABLED(E2_IS_L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperE2;
#define E2_ENABLE_INIT NOOP
#define E2_ENABLE_WRITE(STATE) do{ if (STATE) stepperE2.Step_Clock(stepperE2.getStatus() & STATUS_HIZ); else stepperE2.softFree(); }while(0)
2016-07-25 03:54:24 +02:00
#define E2_ENABLE_READ (stepperE2.getStatus() & STATUS_HIZ)
#define E2_DIR_INIT NOOP
#define E2_DIR_WRITE(STATE) stepperE2.Step_Clock(STATE)
#define E2_DIR_READ (stepperE2.getStatus() & STATUS_DIR)
#else
#if ENABLED(E2_IS_TMC26X)
2016-07-25 03:54:24 +02:00
extern TMC26XStepper stepperE2;
#define E2_ENABLE_INIT NOOP
#define E2_ENABLE_WRITE(STATE) stepperE2.setEnabled(STATE)
#define E2_ENABLE_READ stepperE2.isEnabled()
#else
#if ENABLED(E2_IS_TMC2130)
extern TMC2130Stepper stepperE2;
#elif ENABLED(E2_IS_TMC2208)
2017-12-15 22:02:39 +01:00
extern TMC2208Stepper stepperE2;
2016-09-14 08:48:47 +02:00
#endif
2016-07-25 03:54:24 +02:00
#define E2_ENABLE_INIT SET_OUTPUT(E2_ENABLE_PIN)
#define E2_ENABLE_WRITE(STATE) WRITE(E2_ENABLE_PIN,STATE)
#define E2_ENABLE_READ READ(E2_ENABLE_PIN)
#endif
#define E2_DIR_INIT SET_OUTPUT(E2_DIR_PIN)
#define E2_DIR_WRITE(STATE) WRITE(E2_DIR_PIN,STATE)
#define E2_DIR_READ READ(E2_DIR_PIN)
#endif
#define E2_STEP_INIT SET_OUTPUT(E2_STEP_PIN)
#define E2_STEP_WRITE(STATE) WRITE(E2_STEP_PIN,STATE)
#define E2_STEP_READ READ(E2_STEP_PIN)
2016-07-25 03:54:24 +02:00
// E3 Stepper
#if ENABLED(E3_IS_L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperE3;
#define E3_ENABLE_INIT NOOP
#define E3_ENABLE_WRITE(STATE) do{ if (STATE) stepperE3.Step_Clock(stepperE3.getStatus() & STATUS_HIZ); else stepperE3.softFree(); }while(0)
2016-07-25 03:54:24 +02:00
#define E3_ENABLE_READ (stepperE3.getStatus() & STATUS_HIZ)
#define E3_DIR_INIT NOOP
#define E3_DIR_WRITE(STATE) stepperE3.Step_Clock(STATE)
#define E3_DIR_READ (stepperE3.getStatus() & STATUS_DIR)
#else
#if ENABLED(E3_IS_TMC26X)
2016-07-25 03:54:24 +02:00
extern TMC26XStepper stepperE3;
#define E3_ENABLE_INIT NOOP
#define E3_ENABLE_WRITE(STATE) stepperE3.setEnabled(STATE)
#define E3_ENABLE_READ stepperE3.isEnabled()
#else
#if ENABLED(E3_IS_TMC2130)
extern TMC2130Stepper stepperE3;
#elif ENABLED(E3_IS_TMC2208)
2017-12-15 22:02:39 +01:00
extern TMC2208Stepper stepperE3;
2016-09-14 08:48:47 +02:00
#endif
2016-07-25 03:54:24 +02:00
#define E3_ENABLE_INIT SET_OUTPUT(E3_ENABLE_PIN)
#define E3_ENABLE_WRITE(STATE) WRITE(E3_ENABLE_PIN,STATE)
#define E3_ENABLE_READ READ(E3_ENABLE_PIN)
#endif
#define E3_DIR_INIT SET_OUTPUT(E3_DIR_PIN)
#define E3_DIR_WRITE(STATE) WRITE(E3_DIR_PIN,STATE)
#define E3_DIR_READ READ(E3_DIR_PIN)
#endif
#define E3_STEP_INIT SET_OUTPUT(E3_STEP_PIN)
#define E3_STEP_WRITE(STATE) WRITE(E3_STEP_PIN,STATE)
#define E3_STEP_READ READ(E3_STEP_PIN)
2017-04-09 10:23:05 +02:00
// E4 Stepper
#if ENABLED(E4_IS_L6470)
2017-04-09 10:23:05 +02:00
extern L6470 stepperE4;
#define E4_ENABLE_INIT NOOP
#define E4_ENABLE_WRITE(STATE) do{ if (STATE) stepperE4.Step_Clock(stepperE4.getStatus() & STATUS_HIZ); else stepperE4.softFree(); }while(0)
#define E4_ENABLE_READ (stepperE4.getStatus() & STATUS_HIZ)
#define E4_DIR_INIT NOOP
#define E4_DIR_WRITE(STATE) stepperE4.Step_Clock(STATE)
#define E4_DIR_READ (stepperE4.getStatus() & STATUS_DIR)
#else
#if ENABLED(E4_IS_TMC26X)
2017-04-09 10:23:05 +02:00
extern TMC26XStepper stepperE4;
#define E4_ENABLE_INIT NOOP
#define E4_ENABLE_WRITE(STATE) stepperE4.setEnabled(STATE)
#define E4_ENABLE_READ stepperE4.isEnabled()
#else
#if ENABLED(E4_IS_TMC2130)
2017-04-09 10:23:05 +02:00
extern TMC2130Stepper stepperE4;
#elif ENABLED(E4_IS_TMC2208)
2017-12-15 22:02:39 +01:00
extern TMC2208Stepper stepperE4;
2017-04-09 10:23:05 +02:00
#endif
#define E4_ENABLE_INIT SET_OUTPUT(E4_ENABLE_PIN)
#define E4_ENABLE_WRITE(STATE) WRITE(E4_ENABLE_PIN,STATE)
#define E4_ENABLE_READ READ(E4_ENABLE_PIN)
#endif
#define E4_DIR_INIT SET_OUTPUT(E4_DIR_PIN)
#define E4_DIR_WRITE(STATE) WRITE(E4_DIR_PIN,STATE)
#define E4_DIR_READ READ(E4_DIR_PIN)
#endif
#define E4_STEP_INIT SET_OUTPUT(E4_STEP_PIN)
#define E4_STEP_WRITE(STATE) WRITE(E4_STEP_PIN,STATE)
#define E4_STEP_READ READ(E4_STEP_PIN)
2016-07-25 03:54:24 +02:00
/**
* Extruder indirection for the single E axis
*/
#if ENABLED(SWITCHING_EXTRUDER)
2018-05-22 07:24:52 +02:00
#if EXTRUDERS > 4
2018-03-11 02:57:14 +01:00
#define E_STEP_WRITE(v) do{ if (current_block->active_extruder < 2) { E0_STEP_WRITE(v); } else if (current_block->active_extruder < 4) { E1_STEP_WRITE(v); } else { E2_STEP_WRITE(v); } }while(0)
2018-05-22 07:24:52 +02:00
#define NORM_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 1: E0_DIR_WRITE( INVERT_E0_DIR); break; case 2: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 3: E1_DIR_WRITE( INVERT_E1_DIR); break; case 4: E2_DIR_WRITE(!INVERT_E2_DIR); } }while(0)
#define REV_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE( INVERT_E0_DIR); break; case 1: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 2: E1_DIR_WRITE( INVERT_E1_DIR); break; case 3: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 4: E2_DIR_WRITE( INVERT_E2_DIR); } }while(0)
#elif EXTRUDERS > 3
#define E_STEP_WRITE(v) do{ if (current_block->active_extruder < 2) { E0_STEP_WRITE(v); } else { E1_STEP_WRITE(v); } }while(0)
#define NORM_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 1: E0_DIR_WRITE( INVERT_E0_DIR); break; case 2: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 3: E1_DIR_WRITE( INVERT_E1_DIR); } }while(0)
#define REV_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE( INVERT_E0_DIR); break; case 1: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 2: E1_DIR_WRITE( INVERT_E1_DIR); break; case 3: E1_DIR_WRITE(!INVERT_E1_DIR); } }while(0)
2017-06-19 23:54:37 +02:00
#elif EXTRUDERS > 2
2018-05-22 07:24:52 +02:00
#define E_STEP_WRITE(v) do{ if (current_block->active_extruder < 2) { E0_STEP_WRITE(v); } else { E1_STEP_WRITE(v); } }while(0)
#define NORM_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 1: E0_DIR_WRITE( INVERT_E0_DIR); break; case 2: E1_DIR_WRITE(!INVERT_E1_DIR); } }while(0)
#define REV_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE( INVERT_E0_DIR); break; case 1: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 2: E1_DIR_WRITE( INVERT_E1_DIR); } }while(0)
#else
#define E_STEP_WRITE(v) E0_STEP_WRITE(v)
#define NORM_E_DIR() do{ E0_DIR_WRITE(current_block->active_extruder ? INVERT_E0_DIR : !INVERT_E0_DIR); }while(0)
#define REV_E_DIR() do{ E0_DIR_WRITE(current_block->active_extruder ? !INVERT_E0_DIR : INVERT_E0_DIR); }while(0)
2017-06-19 23:54:37 +02:00
#endif
#elif ENABLED(MK2_MULTIPLEXER) // Even-numbered steppers are reversed
#define E_STEP_WRITE(v) E0_STEP_WRITE(v)
#define NORM_E_DIR() do{ E0_DIR_WRITE(TEST(current_block->active_extruder, 0) ? !INVERT_E0_DIR: INVERT_E0_DIR); }while(0)
2018-05-22 07:24:52 +02:00
#define REV_E_DIR() do{ E0_DIR_WRITE(TEST(current_block->active_extruder, 0) ? INVERT_E0_DIR: !INVERT_E0_DIR); }while(0)
#elif EXTRUDERS > 4
2018-03-07 12:45:06 +01:00
#define E_STEP_WRITE(v) do{ switch (current_block->active_extruder) { case 0: E0_STEP_WRITE(v); break; case 1: E1_STEP_WRITE(v); break; case 2: E2_STEP_WRITE(v); break; case 3: E3_STEP_WRITE(v); break; case 4: E4_STEP_WRITE(v); } }while(0)
#define NORM_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 1: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 2: E2_DIR_WRITE(!INVERT_E2_DIR); break; case 3: E3_DIR_WRITE(!INVERT_E3_DIR); break; case 4: E4_DIR_WRITE(!INVERT_E4_DIR); } }while(0)
2018-05-22 07:24:52 +02:00
#define REV_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE( INVERT_E0_DIR); break; case 1: E1_DIR_WRITE( INVERT_E1_DIR); break; case 2: E2_DIR_WRITE( INVERT_E2_DIR); break; case 3: E3_DIR_WRITE( INVERT_E3_DIR); break; case 4: E4_DIR_WRITE( INVERT_E4_DIR); } }while(0)
#elif EXTRUDERS > 3
2018-03-07 12:45:06 +01:00
#define E_STEP_WRITE(v) do{ switch (current_block->active_extruder) { case 0: E0_STEP_WRITE(v); break; case 1: E1_STEP_WRITE(v); break; case 2: E2_STEP_WRITE(v); break; case 3: E3_STEP_WRITE(v); } }while(0)
#define NORM_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 1: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 2: E2_DIR_WRITE(!INVERT_E2_DIR); break; case 3: E3_DIR_WRITE(!INVERT_E3_DIR); } }while(0)
2018-05-22 07:24:52 +02:00
#define REV_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE( INVERT_E0_DIR); break; case 1: E1_DIR_WRITE( INVERT_E1_DIR); break; case 2: E2_DIR_WRITE( INVERT_E2_DIR); break; case 3: E3_DIR_WRITE( INVERT_E3_DIR); } }while(0)
#elif EXTRUDERS > 2
2018-03-07 12:45:06 +01:00
#define E_STEP_WRITE(v) do{ switch (current_block->active_extruder) { case 0: E0_STEP_WRITE(v); break; case 1: E1_STEP_WRITE(v); break; case 2: E2_STEP_WRITE(v); } }while(0)
#define NORM_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 1: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 2: E2_DIR_WRITE(!INVERT_E2_DIR); } }while(0)
2018-05-22 07:24:52 +02:00
#define REV_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE( INVERT_E0_DIR); break; case 1: E1_DIR_WRITE( INVERT_E1_DIR); break; case 2: E2_DIR_WRITE( INVERT_E2_DIR); } }while(0)
#elif EXTRUDERS > 1
#if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
2018-03-07 12:45:06 +01:00
#define E_STEP_WRITE(v) do{ if (extruder_duplication_enabled) { E0_STEP_WRITE(v); E1_STEP_WRITE(v); } else if (current_block->active_extruder == 0) { E0_STEP_WRITE(v); } else { E1_STEP_WRITE(v); } }while(0)
#define NORM_E_DIR() do{ if (extruder_duplication_enabled) { E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); } else if (current_block->active_extruder == 0) { E0_DIR_WRITE(!INVERT_E0_DIR); } else { E1_DIR_WRITE(!INVERT_E1_DIR); } }while(0)
2018-05-22 07:24:52 +02:00
#define REV_E_DIR() do{ if (extruder_duplication_enabled) { E0_DIR_WRITE( INVERT_E0_DIR); E1_DIR_WRITE( INVERT_E1_DIR); } else if (current_block->active_extruder == 0) { E0_DIR_WRITE( INVERT_E0_DIR); } else { E1_DIR_WRITE( INVERT_E1_DIR); } }while(0)
#else
2018-03-07 12:45:06 +01:00
#define E_STEP_WRITE(v) do{ if (current_block->active_extruder == 0) { E0_STEP_WRITE(v); } else { E1_STEP_WRITE(v); } }while(0)
#define NORM_E_DIR() do{ if (current_block->active_extruder == 0) { E0_DIR_WRITE(!INVERT_E0_DIR); } else { E1_DIR_WRITE(!INVERT_E1_DIR); } }while(0)
2018-05-22 07:24:52 +02:00
#define REV_E_DIR() do{ if (current_block->active_extruder == 0) { E0_DIR_WRITE( INVERT_E0_DIR); } else { E1_DIR_WRITE( INVERT_E1_DIR); } }while(0)
#endif
#elif ENABLED(MIXING_EXTRUDER)
#define E_STEP_WRITE(v) NOOP /* not used for mixing extruders! */
#if MIXING_STEPPERS > 4
2018-03-07 12:45:06 +01:00
#define En_STEP_WRITE(n,v) do{ switch (n) { case 0: E0_STEP_WRITE(v); break; case 1: E1_STEP_WRITE(v); break; case 2: E2_STEP_WRITE(v); break; case 3: E3_STEP_WRITE(v); break; case 4: E4_STEP_WRITE(v); } }while(0)
#define NORM_E_DIR() do{ E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); E2_DIR_WRITE(!INVERT_E2_DIR); E3_DIR_WRITE(!INVERT_E3_DIR); E4_DIR_WRITE(!INVERT_E4_DIR); }while(0)
#define REV_E_DIR() do{ E0_DIR_WRITE( INVERT_E0_DIR); E1_DIR_WRITE( INVERT_E1_DIR); E2_DIR_WRITE( INVERT_E2_DIR); E3_DIR_WRITE( INVERT_E3_DIR); E4_DIR_WRITE( INVERT_E4_DIR); }while(0)
#elif MIXING_STEPPERS > 3
2018-03-07 12:45:06 +01:00
#define En_STEP_WRITE(n,v) do{ switch (n) { case 0: E0_STEP_WRITE(v); break; case 1: E1_STEP_WRITE(v); break; case 2: E2_STEP_WRITE(v); break; case 3: E3_STEP_WRITE(v); } }while(0)
#define NORM_E_DIR() do{ E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); E2_DIR_WRITE(!INVERT_E2_DIR); E3_DIR_WRITE(!INVERT_E3_DIR); }while(0)
#define REV_E_DIR() do{ E0_DIR_WRITE( INVERT_E0_DIR); E1_DIR_WRITE( INVERT_E1_DIR); E2_DIR_WRITE( INVERT_E2_DIR); E3_DIR_WRITE( INVERT_E3_DIR); }while(0)
#elif MIXING_STEPPERS > 2
2018-03-07 12:45:06 +01:00
#define En_STEP_WRITE(n,v) do{ switch (n) { case 0: E0_STEP_WRITE(v); break; case 1: E1_STEP_WRITE(v); break; case 2: E2_STEP_WRITE(v); } }while(0)
#define NORM_E_DIR() do{ E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); E2_DIR_WRITE(!INVERT_E2_DIR); }while(0)
#define REV_E_DIR() do{ E0_DIR_WRITE( INVERT_E0_DIR); E1_DIR_WRITE( INVERT_E1_DIR); E2_DIR_WRITE( INVERT_E2_DIR); }while(0)
#else
2018-03-07 12:45:06 +01:00
#define En_STEP_WRITE(n,v) do{ switch (n) { case 0: E0_STEP_WRITE(v); break; case 1: E1_STEP_WRITE(v); } }while(0)
#define NORM_E_DIR() do{ E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); }while(0)
#define REV_E_DIR() do{ E0_DIR_WRITE( INVERT_E0_DIR); E1_DIR_WRITE( INVERT_E1_DIR); }while(0)
#endif
#else
#define E_STEP_WRITE(v) E0_STEP_WRITE(v)
#define NORM_E_DIR() E0_DIR_WRITE(!INVERT_E0_DIR)
2018-05-22 07:24:52 +02:00
#define REV_E_DIR() E0_DIR_WRITE( INVERT_E0_DIR)
#endif
2016-03-24 19:01:20 +01:00
#endif // STEPPER_INDIRECTION_H