This repository has been archived on 2022-01-28. You can view files and clone it, but cannot push or open issues or pull requests.
Marlin-Artillery-M600/Marlin/src/module/stepper_indirection.h

677 lines
30 KiB
C
Raw Normal View History

/**
2016-03-24 19:01:20 +01:00
* Marlin 3D Printer Firmware
2019-02-12 22:06:53 +01:00
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
2016-03-24 19:01:20 +01:00
*
* 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/>.
*
*/
#pragma once
2016-03-24 19:01:20 +01:00
/**
2017-11-18 09:08:03 +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/>.
*/
2017-09-06 13:28:32 +02:00
#include "../inc/MarlinConfig.h"
2016-07-25 03:54:24 +02:00
// TMC26X drivers have STEP/DIR on normal pins, but ENABLE via SPI
#if HAS_DRIVER(TMC26X)
2016-07-25 03:54:24 +02:00
#include <SPI.h>
2018-01-15 09:28:39 +01:00
#ifdef STM32F7
2018-01-11 22:29:08 +01:00
#include "../HAL/HAL_STM32F7/TMC2660.h"
#else
#include <TMC26XStepper.h>
#endif
void tmc26x_init_to_defaults();
2016-07-25 03:54:24 +02:00
#endif
2018-10-03 09:48:49 +02:00
#if HAS_TRINAMIC
#include <TMCStepper.h>
#include "../feature/tmc_util.h"
#if TMCSTEPPER_VERSION < 0x000202
#error "Update TMCStepper library to 0.2.2 or newer."
2018-10-03 09:48:49 +02:00
#endif
2016-09-14 08:48:47 +02:00
2019-01-21 06:47:28 +01:00
#define ____TMC_CLASS(MODEL, A, I) TMCMarlin<TMC##MODEL##Stepper, A, I>
#define ___TMC_CLASS(MODEL, A, I) ____TMC_CLASS(MODEL, A, I)
#define __TMC_CLASS(MODEL, A, I) ___TMC_CLASS(_##MODEL, A, I)
2018-10-03 09:48:49 +02:00
#define _TMC_CLASS(MODEL, L) __TMC_CLASS(MODEL, L)
#define TMC_CLASS(ST) _TMC_CLASS(ST##_DRIVER_TYPE, TMC_##ST##_LABEL)
typedef struct {
uint8_t toff;
int8_t hend;
uint8_t hstrt;
} chopper_timing_t;
static constexpr chopper_timing_t chopper_timing = CHOPPER_TIMING;
2018-10-03 09:48:49 +02:00
#if HAS_DRIVER(TMC2208)
void tmc2208_serial_begin();
#endif
2017-12-15 22:03:14 +01:00
#endif
2016-07-25 03:54:24 +02:00
// L6470 has STEP on normal pins, but DIR/ENABLE via SPI
#if HAS_DRIVER(L6470)
2019-01-24 02:06:54 +01:00
#include "L6470/L6470_Marlin.h"
#define L6470_WRITE_DIR_COMMAND(STATE,Q) do{ L6470_dir_commands[Q] = (STATE ? dSPIN_STEP_CLOCK_REV : dSPIN_STEP_CLOCK_FWD); }while(0)
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
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_X(L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperX;
#define X_ENABLE_INIT NOOP
2019-01-24 02:06:54 +01:00
#define X_ENABLE_WRITE(STATE) NOOP
2016-07-25 03:54:24 +02:00
#define X_ENABLE_READ (stepperX.getStatus() & STATUS_HIZ)
#define X_DIR_INIT NOOP
2019-01-24 02:06:54 +01:00
#define X_DIR_WRITE(STATE) L6470_WRITE_DIR_COMMAND(STATE,X)
2016-07-25 03:54:24 +02:00
#define X_DIR_READ (stepperX.getStatus() & STATUS_DIR)
#else
2018-10-03 09:48:49 +02:00
#if AXIS_IS_TMC(X)
extern TMC_CLASS(X) stepperX;
#endif
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_X(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()
#elif ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(X)
2018-10-07 00:18:10 +02:00
#define X_ENABLE_INIT NOOP
#define X_ENABLE_WRITE(STATE) stepperX.toff((STATE)==X_ENABLE_ON ? chopper_timing.toff : 0)
2018-10-07 00:18:10 +02:00
#define X_ENABLE_READ stepperX.isEnabled()
2016-07-25 03:54:24 +02:00
#else
#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
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_Y(L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperY;
#define Y_ENABLE_INIT NOOP
2019-01-24 02:06:54 +01:00
#define Y_ENABLE_WRITE(STATE) NOOP
2016-07-25 03:54:24 +02:00
#define Y_ENABLE_READ (stepperY.getStatus() & STATUS_HIZ)
#define Y_DIR_INIT NOOP
2019-01-24 02:06:54 +01:00
#define Y_DIR_WRITE(STATE) L6470_WRITE_DIR_COMMAND(STATE,Y)
2016-07-25 03:54:24 +02:00
#define Y_DIR_READ (stepperY.getStatus() & STATUS_DIR)
#else
2018-10-03 09:48:49 +02:00
#if AXIS_IS_TMC(Y)
extern TMC_CLASS(Y) stepperY;
#endif
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_Y(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()
#elif ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(Y)
2018-10-07 00:18:10 +02:00
#define Y_ENABLE_INIT NOOP
#define Y_ENABLE_WRITE(STATE) stepperY.toff((STATE)==Y_ENABLE_ON ? chopper_timing.toff : 0)
2018-10-07 00:18:10 +02:00
#define Y_ENABLE_READ stepperY.isEnabled()
2016-07-25 03:54:24 +02:00
#else
#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
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_Z(L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperZ;
#define Z_ENABLE_INIT NOOP
2019-01-24 02:06:54 +01:00
#define Z_ENABLE_WRITE(STATE) NOOP
2016-07-25 03:54:24 +02:00
#define Z_ENABLE_READ (stepperZ.getStatus() & STATUS_HIZ)
#define Z_DIR_INIT NOOP
2019-01-24 02:06:54 +01:00
#define Z_DIR_WRITE(STATE) L6470_WRITE_DIR_COMMAND(STATE,Z)
2016-07-25 03:54:24 +02:00
#define Z_DIR_READ (stepperZ.getStatus() & STATUS_DIR)
#else
2018-10-03 09:48:49 +02:00
#if AXIS_IS_TMC(Z)
extern TMC_CLASS(Z) stepperZ;
#endif
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_Z(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()
#elif ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(Z)
2018-10-07 00:18:10 +02:00
#define Z_ENABLE_INIT NOOP
#define Z_ENABLE_WRITE(STATE) stepperZ.toff((STATE)==Z_ENABLE_ON ? chopper_timing.toff : 0)
2018-10-07 00:18:10 +02:00
#define Z_ENABLE_READ stepperZ.isEnabled()
2016-07-25 03:54:24 +02:00
#else
#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
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_X2(L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperX2;
#define X2_ENABLE_INIT NOOP
2019-01-24 02:06:54 +01:00
#define X2_ENABLE_WRITE(STATE) NOOP
2016-07-25 03:54:24 +02:00
#define X2_ENABLE_READ (stepperX2.getStatus() & STATUS_HIZ)
#define X2_DIR_INIT NOOP
2019-01-24 02:06:54 +01:00
#define X2_DIR_WRITE(STATE) L6470_WRITE_DIR_COMMAND(STATE,X2)
2016-07-25 03:54:24 +02:00
#define X2_DIR_READ (stepperX2.getStatus() & STATUS_DIR)
#else
2018-10-03 09:48:49 +02:00
#if AXIS_IS_TMC(X2)
extern TMC_CLASS(X2) stepperX2;
#endif
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_X2(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()
#elif ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(X2)
2018-10-07 00:18:10 +02:00
#define X2_ENABLE_INIT NOOP
#define X2_ENABLE_WRITE(STATE) stepperX2.toff((STATE)==X_ENABLE_ON ? chopper_timing.toff : 0)
2018-10-07 00:18:10 +02:00
#define X2_ENABLE_READ stepperX2.isEnabled()
2016-07-25 03:54:24 +02:00
#else
#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
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_Y2(L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperY2;
#define Y2_ENABLE_INIT NOOP
2019-01-24 02:06:54 +01:00
#define Y2_ENABLE_WRITE(STATE) NOOP
2016-07-25 03:54:24 +02:00
#define Y2_ENABLE_READ (stepperY2.getStatus() & STATUS_HIZ)
#define Y2_DIR_INIT NOOP
2019-01-24 02:06:54 +01:00
#define Y2_DIR_WRITE(STATE) L6470_WRITE_DIR_COMMAND(STATE,Y2)
2016-07-25 03:54:24 +02:00
#define Y2_DIR_READ (stepperY2.getStatus() & STATUS_DIR)
#else
2018-10-03 09:48:49 +02:00
#if AXIS_IS_TMC(Y2)
extern TMC_CLASS(Y2) stepperY2;
#endif
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_Y2(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()
#elif ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(Y2)
2018-10-07 00:18:10 +02:00
#define Y2_ENABLE_INIT NOOP
#define Y2_ENABLE_WRITE(STATE) stepperY2.toff((STATE)==Y_ENABLE_ON ? chopper_timing.toff : 0)
2018-10-07 00:18:10 +02:00
#define Y2_ENABLE_READ stepperY2.isEnabled()
2016-07-25 03:54:24 +02:00
#else
#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)
2019-01-24 02:06:54 +01:00
#else
#define Y2_DIR_WRITE(STATE) NOOP
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
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_Z2(L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperZ2;
#define Z2_ENABLE_INIT NOOP
2019-01-24 02:06:54 +01:00
#define Z2_ENABLE_WRITE(STATE) NOOP
2016-07-25 03:54:24 +02:00
#define Z2_ENABLE_READ (stepperZ2.getStatus() & STATUS_HIZ)
#define Z2_DIR_INIT NOOP
2019-01-24 02:06:54 +01:00
#define Z2_DIR_WRITE(STATE) L6470_WRITE_DIR_COMMAND(STATE,Z2)
2016-07-25 03:54:24 +02:00
#define Z2_DIR_READ (stepperZ2.getStatus() & STATUS_DIR)
#else
2018-10-03 09:48:49 +02:00
#if AXIS_IS_TMC(Z2)
extern TMC_CLASS(Z2) stepperZ2;
#endif
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_Z2(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()
#elif ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(Z2)
2018-10-07 00:18:10 +02:00
#define Z2_ENABLE_INIT NOOP
#define Z2_ENABLE_WRITE(STATE) stepperZ2.toff((STATE)==Z_ENABLE_ON ? chopper_timing.toff : 0)
2018-10-07 00:18:10 +02:00
#define Z2_ENABLE_READ stepperZ2.isEnabled()
2016-07-25 03:54:24 +02:00
#else
#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)
2019-01-24 02:06:54 +01:00
#else
#define Z2_DIR_WRITE(STATE) NOOP
2016-07-25 03:54:24 +02:00
#endif
2016-05-17 23:56:49 +02:00
// Z3 Stepper
#if HAS_Z3_ENABLE
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_Z3(L6470)
extern L6470 stepperZ3;
#define Z3_ENABLE_INIT NOOP
2019-01-24 02:06:54 +01:00
#define Z3_ENABLE_WRITE(STATE) NOOP
#define Z3_ENABLE_READ (stepperZ3.getStatus() & STATUS_HIZ)
#define Z3_DIR_INIT NOOP
2019-01-24 02:06:54 +01:00
#define Z3_DIR_WRITE(STATE) L6470_WRITE_DIR_COMMAND(STATE,Z3)
#define Z3_DIR_READ (stepperZ3.getStatus() & STATUS_DIR)
#else
2018-10-03 09:48:49 +02:00
#if AXIS_IS_TMC(Z3)
extern TMC_CLASS(Z3) stepperZ3;
#endif
#if ENABLED(Z3_IS_TMC26X)
extern TMC26XStepper stepperZ3;
#define Z3_ENABLE_INIT NOOP
#define Z3_ENABLE_WRITE(STATE) stepperZ3.setEnabled(STATE)
#define Z3_ENABLE_READ stepperZ3.isEnabled()
#elif ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(Z3)
2018-10-07 00:18:10 +02:00
#define Z3_ENABLE_INIT NOOP
#define Z3_ENABLE_WRITE(STATE) stepperZ3.toff((STATE)==Z_ENABLE_ON ? chopper_timing.toff : 0)
2018-10-07 00:18:10 +02:00
#define Z3_ENABLE_READ stepperZ3.isEnabled()
#else
#define Z3_ENABLE_INIT SET_OUTPUT(Z3_ENABLE_PIN)
#define Z3_ENABLE_WRITE(STATE) WRITE(Z3_ENABLE_PIN,STATE)
#define Z3_ENABLE_READ READ(Z3_ENABLE_PIN)
#endif
#define Z3_DIR_INIT SET_OUTPUT(Z3_DIR_PIN)
#define Z3_DIR_WRITE(STATE) WRITE(Z3_DIR_PIN,STATE)
#define Z3_DIR_READ READ(Z3_DIR_PIN)
#endif
#define Z3_STEP_INIT SET_OUTPUT(Z3_STEP_PIN)
#define Z3_STEP_WRITE(STATE) WRITE(Z3_STEP_PIN,STATE)
#define Z3_STEP_READ READ(Z3_STEP_PIN)
2019-01-24 02:06:54 +01:00
#else
#define Z3_DIR_WRITE(STATE) NOOP
#endif
2016-07-25 03:54:24 +02:00
// E0 Stepper
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_E0(L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperE0;
#define E0_ENABLE_INIT NOOP
2019-01-24 02:06:54 +01:00
#define E0_ENABLE_WRITE(STATE) NOOP
2016-07-25 03:54:24 +02:00
#define E0_ENABLE_READ (stepperE0.getStatus() & STATUS_HIZ)
#define E0_DIR_INIT NOOP
2019-01-24 02:06:54 +01:00
#define E0_DIR_WRITE(STATE) L6470_WRITE_DIR_COMMAND(STATE,E0)
2016-07-25 03:54:24 +02:00
#define E0_DIR_READ (stepperE0.getStatus() & STATUS_DIR)
#else
2018-10-03 09:48:49 +02:00
#if AXIS_IS_TMC(E0)
extern TMC_CLASS(E0) stepperE0;
#endif
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_E0(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()
#elif ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E0)
2018-10-07 00:18:10 +02:00
#define E0_ENABLE_INIT NOOP
#define E0_ENABLE_WRITE(STATE) stepperE0.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
2018-10-07 00:18:10 +02:00
#define E0_ENABLE_READ stepperE0.isEnabled()
2016-07-25 03:54:24 +02:00
#else
#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
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_E1(L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperE1;
#define E1_ENABLE_INIT NOOP
2019-01-24 02:06:54 +01:00
#define E1_ENABLE_WRITE(STATE) NOOP
2016-07-25 03:54:24 +02:00
#define E1_ENABLE_READ (stepperE1.getStatus() & STATUS_HIZ)
#define E1_DIR_INIT NOOP
2019-01-24 02:06:54 +01:00
#define E1_DIR_WRITE(STATE) L6470_WRITE_DIR_COMMAND(STATE,E1)
2016-07-25 03:54:24 +02:00
#define E1_DIR_READ (stepperE1.getStatus() & STATUS_DIR)
#else
2018-10-03 09:48:49 +02:00
#if AXIS_IS_TMC(E1)
extern TMC_CLASS(E1) stepperE1;
#endif
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_E1(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()
#elif ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E1)
2018-10-07 00:18:10 +02:00
#define E1_ENABLE_INIT NOOP
#define E1_ENABLE_WRITE(STATE) stepperE1.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
2018-10-07 00:18:10 +02:00
#define E1_ENABLE_READ stepperE1.isEnabled()
2016-07-25 03:54:24 +02:00
#else
#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
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_E2(L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperE2;
#define E2_ENABLE_INIT NOOP
2019-01-24 02:06:54 +01:00
#define E2_ENABLE_WRITE(STATE) NOOP
2016-07-25 03:54:24 +02:00
#define E2_ENABLE_READ (stepperE2.getStatus() & STATUS_HIZ)
#define E2_DIR_INIT NOOP
2019-01-24 02:06:54 +01:00
#define E2_DIR_WRITE(STATE) L6470_WRITE_DIR_COMMAND(STATE,E2)
2016-07-25 03:54:24 +02:00
#define E2_DIR_READ (stepperE2.getStatus() & STATUS_DIR)
#else
2018-10-03 09:48:49 +02:00
#if AXIS_IS_TMC(E2)
extern TMC_CLASS(E2) stepperE2;
#endif
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_E2(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()
#elif ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E2)
2018-10-07 00:18:10 +02:00
#define E2_ENABLE_INIT NOOP
#define E2_ENABLE_WRITE(STATE) stepperE2.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
2018-10-07 00:18:10 +02:00
#define E2_ENABLE_READ stepperE2.isEnabled()
2016-07-25 03:54:24 +02:00
#else
#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
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_E3(L6470)
2016-07-25 03:54:24 +02:00
extern L6470 stepperE3;
#define E3_ENABLE_INIT NOOP
2019-01-24 02:06:54 +01:00
#define E3_ENABLE_WRITE(STATE) NOOP
2016-07-25 03:54:24 +02:00
#define E3_ENABLE_READ (stepperE3.getStatus() & STATUS_HIZ)
#define E3_DIR_INIT NOOP
2019-01-24 02:06:54 +01:00
#define E3_DIR_WRITE(STATE) L6470_WRITE_DIR_COMMAND(STATE,E3)
2016-07-25 03:54:24 +02:00
#define E3_DIR_READ (stepperE3.getStatus() & STATUS_DIR)
#else
2018-10-03 09:48:49 +02:00
#if AXIS_IS_TMC(E3)
extern TMC_CLASS(E3) stepperE3;
#endif
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_E3(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()
#elif ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E3)
2018-10-07 00:18:10 +02:00
#define E3_ENABLE_INIT NOOP
#define E3_ENABLE_WRITE(STATE) stepperE3.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
2018-10-07 00:18:10 +02:00
#define E3_ENABLE_READ stepperE3.isEnabled()
2016-07-25 03:54:24 +02:00
#else
#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
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_E4(L6470)
2017-04-09 10:23:05 +02:00
extern L6470 stepperE4;
#define E4_ENABLE_INIT NOOP
2019-01-24 02:06:54 +01:00
#define E4_ENABLE_WRITE(STATE) NOOP
2017-04-09 10:23:05 +02:00
#define E4_ENABLE_READ (stepperE4.getStatus() & STATUS_HIZ)
#define E4_DIR_INIT NOOP
2019-01-24 02:06:54 +01:00
#define E4_DIR_WRITE(STATE) L6470_WRITE_DIR_COMMAND(STATE,E4)
2017-04-09 10:23:05 +02:00
#define E4_DIR_READ (stepperE4.getStatus() & STATUS_DIR)
#else
2018-10-03 09:48:49 +02:00
#if AXIS_IS_TMC(E4)
extern TMC_CLASS(E4) stepperE4;
#endif
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_E4(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()
#elif ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E4)
2018-10-07 00:18:10 +02:00
#define E4_ENABLE_INIT NOOP
#define E4_ENABLE_WRITE(STATE) stepperE4.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
2018-10-07 00:18:10 +02:00
#define E4_ENABLE_READ stepperE4.isEnabled()
2017-04-09 10:23:05 +02:00
#else
#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)
// E5 Stepper
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_E5(L6470)
extern L6470 stepperE5;
#define E5_ENABLE_INIT NOOP
2019-01-24 02:06:54 +01:00
#define E5_ENABLE_WRITE(STATE) NOOP
#define E5_ENABLE_READ (stepperE5.getStatus() & STATUS_HIZ)
#define E5_DIR_INIT NOOP
2019-01-24 02:06:54 +01:00
#define E5_DIR_WRITE(STATE) L6470_WRITE_DIR_COMMAND(STATE,E5)
#define E5_DIR_READ (stepperE5.getStatus() & STATUS_DIR)
#else
2018-10-03 09:48:49 +02:00
#if AXIS_IS_TMC(E5)
extern TMC_CLASS(E5) stepperE5;
#endif
2019-01-24 02:06:54 +01:00
#if AXIS_DRIVER_TYPE_E5(TMC26X)
extern TMC26XStepper stepperE5;
#define E5_ENABLE_INIT NOOP
#define E5_ENABLE_WRITE(STATE) stepperE5.setEnabled(STATE)
#define E5_ENABLE_READ stepperE5.isEnabled()
#elif ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E5)
2018-10-07 00:18:10 +02:00
#define E5_ENABLE_INIT NOOP
#define E5_ENABLE_WRITE(STATE) stepperE5.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
2018-10-07 00:18:10 +02:00
#define E5_ENABLE_READ stepperE5.isEnabled()
#else
#define E5_ENABLE_INIT SET_OUTPUT(E5_ENABLE_PIN)
#define E5_ENABLE_WRITE(STATE) WRITE(E5_ENABLE_PIN,STATE)
#define E5_ENABLE_READ READ(E5_ENABLE_PIN)
#endif
#define E5_DIR_INIT SET_OUTPUT(E5_DIR_PIN)
#define E5_DIR_WRITE(STATE) WRITE(E5_DIR_PIN,STATE)
#define E5_DIR_READ READ(E5_DIR_PIN)
#endif
#define E5_STEP_INIT SET_OUTPUT(E5_STEP_PIN)
#define E5_STEP_WRITE(STATE) WRITE(E5_STEP_PIN,STATE)
#define E5_STEP_READ READ(E5_STEP_PIN)
2016-07-25 03:54:24 +02:00
/**
* Extruder indirection for the single E axis
*/
#if ENABLED(SWITCHING_EXTRUDER) // One stepper driver per two extruders, reversed on odd index
#if EXTRUDERS > 5
#define E_STEP_WRITE(E,V) do{ if (E < 2) { E0_STEP_WRITE(V); } else if (E < 4) { E1_STEP_WRITE(V); } else { E2_STEP_WRITE(V); } }while(0)
#define NORM_E_DIR(E) do{ switch (E) { 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); case 5: E2_DIR_WRITE( INVERT_E2_DIR); } }while(0)
#define REV_E_DIR(E) do{ switch (E) { 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); case 5: E2_DIR_WRITE(!INVERT_E2_DIR); } }while(0)
#elif EXTRUDERS > 4
#define E_STEP_WRITE(E,V) do{ if (E < 2) { E0_STEP_WRITE(V); } else if (E < 4) { E1_STEP_WRITE(V); } else { E2_STEP_WRITE(V); } }while(0)
#define NORM_E_DIR(E) do{ switch (E) { 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(E) do{ switch (E) { 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)
2018-05-22 07:18:21 +02:00
#elif EXTRUDERS > 3
#define E_STEP_WRITE(E,V) do{ if (E < 2) { E0_STEP_WRITE(V); } else { E1_STEP_WRITE(V); } }while(0)
#define NORM_E_DIR(E) do{ switch (E) { 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(E) do{ switch (E) { 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
#define E_STEP_WRITE(E,V) do{ if (E < 2) { E0_STEP_WRITE(V); } else { E1_STEP_WRITE(V); } }while(0)
#define NORM_E_DIR(E) do{ switch (E) { 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(E) do{ switch (E) { 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)
2018-05-22 07:18:21 +02:00
#else
#define E_STEP_WRITE(E,V) E0_STEP_WRITE(V)
#define NORM_E_DIR(E) do{ E0_DIR_WRITE(E ? INVERT_E0_DIR : !INVERT_E0_DIR); }while(0)
#define REV_E_DIR(E) do{ E0_DIR_WRITE(E ? !INVERT_E0_DIR : INVERT_E0_DIR); }while(0)
2017-06-19 23:54:37 +02:00
#endif
2019-02-01 02:10:52 +01:00
#elif ENABLED(PRUSA_MMU2)
#define E_STEP_WRITE(E,V) E0_STEP_WRITE(V)
#define NORM_E_DIR(E) E0_DIR_WRITE(!INVERT_E0_DIR)
#define REV_E_DIR(E) E0_DIR_WRITE( INVERT_E0_DIR)
#elif ENABLED(MK2_MULTIPLEXER) // One multiplexed stepper driver, reversed on odd index
#define E_STEP_WRITE(E,V) E0_STEP_WRITE(V)
#define NORM_E_DIR(E) do{ E0_DIR_WRITE(TEST(E, 0) ? !INVERT_E0_DIR: INVERT_E0_DIR); }while(0)
#define REV_E_DIR(E) do{ E0_DIR_WRITE(TEST(E, 0) ? INVERT_E0_DIR: !INVERT_E0_DIR); }while(0)
#elif E_STEPPERS > 1
2018-09-17 08:06:22 +02:00
#if E_STEPPERS > 5
#define _E_STEP_WRITE(E,V) do{ switch (E) { 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); case 5: E5_STEP_WRITE(V); } }while(0)
#define _NORM_E_DIR(E) do{ switch (E) { 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); case 5: E5_DIR_WRITE(!INVERT_E5_DIR); } }while(0)
#define _REV_E_DIR(E) do{ switch (E) { 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); case 5: E5_DIR_WRITE( INVERT_E5_DIR); } }while(0)
#elif E_STEPPERS > 4
#define _E_STEP_WRITE(E,V) do{ switch (E) { 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(E) do{ switch (E) { 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)
#define _REV_E_DIR(E) do{ switch (E) { 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 E_STEPPERS > 3
#define _E_STEP_WRITE(E,V) do{ switch (E) { 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(E) do{ switch (E) { 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)
#define _REV_E_DIR(E) do{ switch (E) { 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 E_STEPPERS > 2
#define _E_STEP_WRITE(E,V) do{ switch (E) { 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(E) do{ switch (E) { 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)
#define _REV_E_DIR(E) do{ switch (E) { 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)
#else
#define _E_STEP_WRITE(E,V) do{ if (E == 0) { E0_STEP_WRITE(V); } else { E1_STEP_WRITE(V); } }while(0)
#define _NORM_E_DIR(E) do{ if (E == 0) { E0_DIR_WRITE(!INVERT_E0_DIR); } else { E1_DIR_WRITE(!INVERT_E1_DIR); } }while(0)
#define _REV_E_DIR(E) do{ if (E == 0) { E0_DIR_WRITE( INVERT_E0_DIR); } else { E1_DIR_WRITE( INVERT_E1_DIR); } }while(0)
#endif
#if HAS_DUPLICATION_MODE
#if ENABLED(MULTI_NOZZLE_DUPLICATION)
#define _DUPE(N,T,V) do{ if (TEST(duplication_e_mask, N)) E##N##_##T##_WRITE(V); }while(0)
#else
#define _DUPE(N,T,V) E##N##_##T##_WRITE(V)
#endif
#define NDIR(N) _DUPE(N,DIR,!INVERT_E##N##_DIR)
#define RDIR(N) _DUPE(N,DIR, INVERT_E##N##_DIR)
#define E_STEP_WRITE(E,V) do{ if (extruder_duplication_enabled) { DUPE(STEP,V); } else _E_STEP_WRITE(E,V); }while(0)
2018-09-17 08:06:22 +02:00
#if E_STEPPERS > 2
#if E_STEPPERS > 5
#define DUPE(T,V) do{ _DUPE(0,T,V); _DUPE(1,T,V); _DUPE(2,T,V); _DUPE(3,T,V); _DUPE(4,T,V); _DUPE(5,T,V); }while(0)
#define NORM_E_DIR(E) do{ if (extruder_duplication_enabled) { NDIR(0); NDIR(1); NDIR(2); NDIR(3); NDIR(4); NDIR(5); } else _NORM_E_DIR(E); }while(0)
#define REV_E_DIR(E) do{ if (extruder_duplication_enabled) { RDIR(0); RDIR(1); RDIR(2); RDIR(3); RDIR(4); RDIR(5); } else _REV_E_DIR(E); }while(0)
#elif E_STEPPERS > 4
#define DUPE(T,V) do{ _DUPE(0,T,V); _DUPE(1,T,V); _DUPE(2,T,V); _DUPE(3,T,V); _DUPE(4,T,V); }while(0)
#define NORM_E_DIR(E) do{ if (extruder_duplication_enabled) { NDIR(0); NDIR(1); NDIR(2); NDIR(3); NDIR(4); } else _NORM_E_DIR(E); }while(0)
#define REV_E_DIR(E) do{ if (extruder_duplication_enabled) { RDIR(0); RDIR(1); RDIR(2); RDIR(3); RDIR(4); } else _REV_E_DIR(E); }while(0)
#elif E_STEPPERS > 3
#define DUPE(T,V) do{ _DUPE(0,T,V); _DUPE(1,T,V); _DUPE(2,T,V); _DUPE(3,T,V); }while(0)
#define NORM_E_DIR(E) do{ if (extruder_duplication_enabled) { NDIR(0); NDIR(1); NDIR(2); NDIR(3); } else _NORM_E_DIR(E); }while(0)
#define REV_E_DIR(E) do{ if (extruder_duplication_enabled) { RDIR(0); RDIR(1); RDIR(2); RDIR(3); } else _REV_E_DIR(E); }while(0)
#else
#define DUPE(T,V) do{ _DUPE(0,T,V); _DUPE(1,T,V); _DUPE(2,T,V); }while(0)
#define NORM_E_DIR(E) do{ if (extruder_duplication_enabled) { NDIR(0); NDIR(1); NDIR(2); } else _NORM_E_DIR(E); }while(0)
#define REV_E_DIR(E) do{ if (extruder_duplication_enabled) { RDIR(0); RDIR(1); RDIR(2); } else _REV_E_DIR(E); }while(0)
#endif
#else
#define DUPE(T,V) do{ _DUPE(0,T,V); _DUPE(1,T,V); } while(0)
#define NORM_E_DIR(E) do{ if (extruder_duplication_enabled) { NDIR(0); NDIR(1); } else _NORM_E_DIR(E); }while(0)
#define REV_E_DIR(E) do{ if (extruder_duplication_enabled) { RDIR(0); RDIR(1); } else _REV_E_DIR(E); }while(0)
#endif
2018-09-17 08:06:22 +02:00
#else
#define E_STEP_WRITE(E,V) _E_STEP_WRITE(E,V)
#define NORM_E_DIR(E) _NORM_E_DIR(E)
#define REV_E_DIR(E) _REV_E_DIR(E)
#endif
#elif E_STEPPERS
#define E_STEP_WRITE(E,V) E0_STEP_WRITE(V)
#define NORM_E_DIR(E) E0_DIR_WRITE(!INVERT_E0_DIR)
#define REV_E_DIR(E) E0_DIR_WRITE( INVERT_E0_DIR)
#else
#define E_STEP_WRITE(E,V) NOOP
#define NORM_E_DIR(E) NOOP
#define REV_E_DIR(E) NOOP
#endif