2016-03-25 07:19:46 +01:00
|
|
|
/**
|
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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-03-25 07:19:46 +01:00
|
|
|
/**
|
2017-03-07 06:00:43 +01:00
|
|
|
* stepper_indirection.cpp
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
2015-02-26 12:57:46 +01:00
|
|
|
|
|
|
|
#include "stepper_indirection.h"
|
2016-07-25 03:54:24 +02:00
|
|
|
|
2017-09-06 13:28:32 +02:00
|
|
|
#include "../inc/MarlinConfig.h"
|
2015-02-26 12:57:46 +01:00
|
|
|
|
2018-09-15 03:00:55 +02:00
|
|
|
#include "../module/stepper.h"
|
|
|
|
|
2016-11-07 21:46:01 +01:00
|
|
|
//
|
|
|
|
// TMC26X Driver objects and inits
|
|
|
|
//
|
2018-07-14 13:13:06 +02:00
|
|
|
#if HAS_DRIVER(TMC26X)
|
2015-07-31 07:28:11 +02:00
|
|
|
#include <SPI.h>
|
2018-01-22 00:13:56 +01:00
|
|
|
|
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
|
2015-02-26 12:57:46 +01:00
|
|
|
|
2018-04-28 19:02:45 +02:00
|
|
|
#define _TMC26X_DEFINE(ST) TMC26XStepper stepper##ST(200, ST##_CS_PIN, ST##_STEP_PIN, ST##_DIR_PIN, ST##_MAX_CURRENT, ST##_SENSE_RESISTOR)
|
2017-03-07 06:00:43 +01:00
|
|
|
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(X, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_DEFINE(X);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(X2, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_DEFINE(X2);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Y, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_DEFINE(Y);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Y2, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_DEFINE(Y2);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_DEFINE(Z);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z2, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_DEFINE(Z2);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-06-19 18:55:49 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z3, TMC26X)
|
|
|
|
_TMC26X_DEFINE(Z3);
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E0, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_DEFINE(E0);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E1, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_DEFINE(E1);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E2, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_DEFINE(E2);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E3, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_DEFINE(E3);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E4, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_DEFINE(E4);
|
2017-04-09 10:23:05 +02:00
|
|
|
#endif
|
2018-09-17 06:57:50 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E5, TMC26X)
|
|
|
|
_TMC26X_DEFINE(E5);
|
|
|
|
#endif
|
2015-02-27 12:43:23 +01:00
|
|
|
|
2018-03-19 01:01:42 +01:00
|
|
|
#define _TMC26X_INIT(A) do{ \
|
2017-03-04 12:17:39 +01:00
|
|
|
stepper##A.setMicrosteps(A##_MICROSTEPS); \
|
|
|
|
stepper##A.start(); \
|
2017-03-07 06:00:43 +01:00
|
|
|
}while(0)
|
2016-11-07 21:46:01 +01:00
|
|
|
|
2018-03-19 01:01:42 +01:00
|
|
|
void tmc26x_init_to_defaults() {
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(X, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_INIT(X);
|
2016-11-07 21:46:01 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(X2, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_INIT(X2);
|
2016-11-07 21:46:01 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Y, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_INIT(Y);
|
2016-11-07 21:46:01 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Y2, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_INIT(Y2);
|
2016-11-07 21:46:01 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_INIT(Z);
|
2016-11-07 21:46:01 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z2, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_INIT(Z2);
|
2016-11-07 21:46:01 +01:00
|
|
|
#endif
|
2018-06-19 18:55:49 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z3, TMC26X)
|
|
|
|
_TMC26X_INIT(Z3);
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E0, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_INIT(E0);
|
2016-11-07 21:46:01 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E1, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_INIT(E1);
|
2016-11-07 21:46:01 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E2, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_INIT(E2);
|
2016-11-07 21:46:01 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E3, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_INIT(E3);
|
2016-11-07 21:46:01 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E4, TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
_TMC26X_INIT(E4);
|
2017-04-09 10:23:05 +02:00
|
|
|
#endif
|
2018-09-17 06:57:50 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E5, TMC26X)
|
|
|
|
_TMC26X_INIT(E5);
|
|
|
|
#endif
|
2016-11-07 21:46:01 +01:00
|
|
|
}
|
2018-07-14 13:13:06 +02:00
|
|
|
#endif // TMC26X
|
2016-11-07 21:46:01 +01:00
|
|
|
|
2018-10-03 09:48:49 +02:00
|
|
|
#if HAS_TRINAMIC
|
|
|
|
#define _TMC_INIT(ST, SPMM) tmc_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, SPMM)
|
|
|
|
#endif
|
|
|
|
|
2016-11-07 21:46:01 +01:00
|
|
|
//
|
|
|
|
// TMC2130 Driver objects and inits
|
|
|
|
//
|
2018-07-14 13:13:06 +02:00
|
|
|
#if HAS_DRIVER(TMC2130)
|
2016-11-07 21:35:14 +01:00
|
|
|
|
2016-09-14 08:48:47 +02:00
|
|
|
#include <SPI.h>
|
2017-12-15 22:03:14 +01:00
|
|
|
#include "planner.h"
|
2017-09-06 13:28:32 +02:00
|
|
|
#include "../core/enum.h"
|
2016-09-14 08:48:47 +02:00
|
|
|
|
2018-02-02 04:49:40 +01:00
|
|
|
#if ENABLED(TMC_USE_SW_SPI)
|
2018-10-03 09:48:49 +02:00
|
|
|
#define _TMC2130_DEFINE(ST, L) TMCMarlin<TMC2130Stepper, L> stepper##ST(ST##_CS_PIN, R_SENSE, TMC_SW_MOSI, TMC_SW_MISO, TMC_SW_SCK)
|
|
|
|
#define TMC2130_DEFINE(ST) _TMC2130_DEFINE(ST, TMC_##ST##_LABEL)
|
2018-02-02 04:49:40 +01:00
|
|
|
#else
|
2018-10-03 09:48:49 +02:00
|
|
|
#define _TMC2130_DEFINE(ST, L) TMCMarlin<TMC2130Stepper, L> stepper##ST(ST##_CS_PIN, R_SENSE)
|
|
|
|
#define TMC2130_DEFINE(ST) _TMC2130_DEFINE(ST, TMC_##ST##_LABEL)
|
2018-02-02 04:49:40 +01:00
|
|
|
#endif
|
2017-03-07 06:00:43 +01:00
|
|
|
// Stepper objects of TMC2130 steppers used
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(X, TMC2130)
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2130_DEFINE(X);
|
2016-11-07 21:35:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(X2, TMC2130)
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2130_DEFINE(X2);
|
2016-11-07 21:35:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Y, TMC2130)
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2130_DEFINE(Y);
|
2016-11-07 21:35:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Y2, TMC2130)
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2130_DEFINE(Y2);
|
2016-11-07 21:35:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z, TMC2130)
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2130_DEFINE(Z);
|
2016-11-07 21:35:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z2, TMC2130)
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2130_DEFINE(Z2);
|
2016-11-07 21:35:14 +01:00
|
|
|
#endif
|
2018-06-19 18:55:49 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z3, TMC2130)
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2130_DEFINE(Z3);
|
2018-06-19 18:55:49 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E0, TMC2130)
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2130_DEFINE(E0);
|
2016-11-07 21:35:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E1, TMC2130)
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2130_DEFINE(E1);
|
2016-11-07 21:35:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E2, TMC2130)
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2130_DEFINE(E2);
|
2016-11-07 21:35:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E3, TMC2130)
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2130_DEFINE(E3);
|
2016-11-07 21:35:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E4, TMC2130)
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2130_DEFINE(E4);
|
2017-04-09 10:23:05 +02:00
|
|
|
#endif
|
2018-09-17 06:57:50 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E5, TMC2130)
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2130_DEFINE(E5);
|
2018-09-17 06:57:50 +02:00
|
|
|
#endif
|
2016-11-07 21:35:14 +01:00
|
|
|
|
2018-10-03 09:48:49 +02:00
|
|
|
template<char AXIS_LETTER, char DRIVER_ID>
|
|
|
|
void tmc_init(TMCMarlin<TMC2130Stepper, AXIS_LETTER, DRIVER_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
|
2018-05-10 07:05:15 +02:00
|
|
|
#if DISABLED(STEALTHCHOP) || DISABLED(HYBRID_THRESHOLD)
|
|
|
|
UNUSED(thrs);
|
|
|
|
UNUSED(spmm);
|
|
|
|
#endif
|
2017-03-07 06:00:43 +01:00
|
|
|
st.begin();
|
2018-10-03 09:48:49 +02:00
|
|
|
|
|
|
|
CHOPCONF_t chopconf{0};
|
|
|
|
chopconf.tbl = 1;
|
|
|
|
chopconf.toff = 3;
|
|
|
|
chopconf.intpol = INTERPOLATE;
|
|
|
|
chopconf.hstrt = 2;
|
|
|
|
chopconf.hend = 5;
|
|
|
|
st.CHOPCONF(chopconf.sr);
|
|
|
|
|
|
|
|
st.rms_current(mA, HOLD_MULTIPLIER);
|
2017-03-07 06:00:43 +01:00
|
|
|
st.microsteps(microsteps);
|
2018-10-03 09:48:49 +02:00
|
|
|
st.iholddelay(10);
|
|
|
|
st.TPOWERDOWN(128); // ~2s until driver lowers to hold current
|
|
|
|
|
2017-03-07 06:00:43 +01:00
|
|
|
#if ENABLED(STEALTHCHOP)
|
2018-10-03 09:48:49 +02:00
|
|
|
st.en_pwm_mode(true);
|
2017-03-07 06:00:43 +01:00
|
|
|
|
2018-10-03 09:48:49 +02:00
|
|
|
PWMCONF_t pwmconf{0};
|
|
|
|
pwmconf.pwm_freq = 0b01; // f_pwm = 2/683 f_clk
|
|
|
|
pwmconf.pwm_autoscale = true;
|
|
|
|
pwmconf.pwm_grad = 5;
|
|
|
|
pwmconf.pwm_ampl = 180;
|
|
|
|
st.PWMCONF(pwmconf.sr);
|
2017-03-07 06:00:43 +01:00
|
|
|
|
2018-10-03 09:48:49 +02:00
|
|
|
#if ENABLED(HYBRID_THRESHOLD)
|
|
|
|
st.TPWMTHRS(12650000UL*microsteps/(256*thrs*spmm));
|
2018-03-19 01:01:42 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-10-03 09:48:49 +02:00
|
|
|
st.GSTAT(); // Clear GSTAT
|
2016-11-07 21:35:14 +01:00
|
|
|
}
|
2018-07-14 13:13:06 +02:00
|
|
|
#endif // TMC2130
|
2016-11-07 21:35:14 +01:00
|
|
|
|
2017-12-15 22:03:14 +01:00
|
|
|
//
|
|
|
|
// TMC2208 Driver objects and inits
|
|
|
|
//
|
2018-07-14 13:13:06 +02:00
|
|
|
#if HAS_DRIVER(TMC2208)
|
2017-12-15 22:03:14 +01:00
|
|
|
#include <HardwareSerial.h>
|
|
|
|
#include "planner.h"
|
|
|
|
|
2018-10-03 09:48:49 +02:00
|
|
|
#define _TMC2208_DEFINE_HARDWARE(ST, L) TMCMarlin<TMC2208Stepper, L> stepper##ST(&ST##_HARDWARE_SERIAL, R_SENSE)
|
|
|
|
#define TMC2208_DEFINE_HARDWARE(ST) _TMC2208_DEFINE_HARDWARE(ST, TMC_##ST##_LABEL)
|
2018-03-24 20:26:11 +01:00
|
|
|
|
2018-10-03 09:48:49 +02:00
|
|
|
#define _TMC2208_DEFINE_SOFTWARE(ST, L) TMCMarlin<TMC2208Stepper, L> stepper##ST(ST##_SERIAL_RX_PIN, ST##_SERIAL_TX_PIN, R_SENSE, ST##_SERIAL_RX_PIN > -1)
|
|
|
|
#define TMC2208_DEFINE_SOFTWARE(ST) _TMC2208_DEFINE_SOFTWARE(ST, TMC_##ST##_LABEL)
|
2017-12-15 22:03:14 +01:00
|
|
|
|
|
|
|
// Stepper objects of TMC2208 steppers used
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(X, TMC2208)
|
2018-01-22 17:24:30 +01:00
|
|
|
#ifdef X_HARDWARE_SERIAL
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_HARDWARE(X);
|
2017-12-15 22:03:14 +01:00
|
|
|
#else
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_SOFTWARE(X);
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(X2, TMC2208)
|
2018-01-22 17:24:30 +01:00
|
|
|
#ifdef X2_HARDWARE_SERIAL
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_HARDWARE(X2);
|
2017-12-15 22:03:14 +01:00
|
|
|
#else
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_SOFTWARE(X2);
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Y, TMC2208)
|
2018-01-22 17:24:30 +01:00
|
|
|
#ifdef Y_HARDWARE_SERIAL
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_HARDWARE(Y);
|
2017-12-15 22:03:14 +01:00
|
|
|
#else
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_SOFTWARE(Y);
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Y2, TMC2208)
|
2018-01-22 17:24:30 +01:00
|
|
|
#ifdef Y2_HARDWARE_SERIAL
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_HARDWARE(Y2);
|
2017-12-15 22:03:14 +01:00
|
|
|
#else
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_SOFTWARE(Y2);
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z, TMC2208)
|
2018-01-22 17:24:30 +01:00
|
|
|
#ifdef Z_HARDWARE_SERIAL
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_HARDWARE(Z);
|
2017-12-15 22:03:14 +01:00
|
|
|
#else
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_SOFTWARE(Z);
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z2, TMC2208)
|
2018-01-22 17:24:30 +01:00
|
|
|
#ifdef Z2_HARDWARE_SERIAL
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_HARDWARE(Z2);
|
2017-12-15 22:03:14 +01:00
|
|
|
#else
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_SOFTWARE(Z2);
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-06-19 18:55:49 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z3, TMC2208)
|
|
|
|
#ifdef Z3_HARDWARE_SERIAL
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_HARDWARE(Z3);
|
2018-06-19 18:55:49 +02:00
|
|
|
#else
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_SOFTWARE(Z3);
|
2018-06-19 18:55:49 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E0, TMC2208)
|
2018-01-22 17:24:30 +01:00
|
|
|
#ifdef E0_HARDWARE_SERIAL
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_HARDWARE(E0);
|
2017-12-15 22:03:14 +01:00
|
|
|
#else
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_SOFTWARE(E0);
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E1, TMC2208)
|
2018-01-22 17:24:30 +01:00
|
|
|
#ifdef E1_HARDWARE_SERIAL
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_HARDWARE(E1);
|
2017-12-15 22:03:14 +01:00
|
|
|
#else
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_SOFTWARE(E1);
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E2, TMC2208)
|
2018-01-22 17:24:30 +01:00
|
|
|
#ifdef E2_HARDWARE_SERIAL
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_HARDWARE(E2);
|
2017-12-15 22:03:14 +01:00
|
|
|
#else
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_SOFTWARE(E2);
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E3, TMC2208)
|
2018-01-22 17:24:30 +01:00
|
|
|
#ifdef E3_HARDWARE_SERIAL
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_HARDWARE(E3);
|
2017-12-15 22:03:14 +01:00
|
|
|
#else
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_SOFTWARE(E3);
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E4, TMC2208)
|
2018-01-22 17:24:30 +01:00
|
|
|
#ifdef E4_HARDWARE_SERIAL
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_HARDWARE(E4);
|
2017-12-15 22:03:14 +01:00
|
|
|
#else
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_SOFTWARE(E4);
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-09-17 06:57:50 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E5, TMC2208)
|
|
|
|
#ifdef E5_HARDWARE_SERIAL
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_HARDWARE(E5);
|
2018-09-17 06:57:50 +02:00
|
|
|
#else
|
2018-10-03 09:48:49 +02:00
|
|
|
TMC2208_DEFINE_SOFTWARE(E5);
|
2018-09-17 06:57:50 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
|
|
|
|
void tmc2208_serial_begin() {
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(X, TMC2208)
|
2018-08-15 01:41:37 +02:00
|
|
|
#ifdef X_HARDWARE_SERIAL
|
|
|
|
X_HARDWARE_SERIAL.begin(115200);
|
|
|
|
#else
|
|
|
|
stepperX.beginSerial(115200);
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(X2, TMC2208)
|
2018-08-15 01:41:37 +02:00
|
|
|
#ifdef X2_HARDWARE_SERIAL
|
|
|
|
X2_HARDWARE_SERIAL.begin(115200);
|
|
|
|
#else
|
|
|
|
stepperX2.beginSerial(115200);
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Y, TMC2208)
|
2018-08-15 01:41:37 +02:00
|
|
|
#ifdef Y_HARDWARE_SERIAL
|
|
|
|
Y_HARDWARE_SERIAL.begin(115200);
|
|
|
|
#else
|
|
|
|
stepperY.beginSerial(115200);
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Y2, TMC2208)
|
2018-08-15 01:41:37 +02:00
|
|
|
#ifdef Y2_HARDWARE_SERIAL
|
|
|
|
Y2_HARDWARE_SERIAL.begin(115200);
|
|
|
|
#else
|
|
|
|
stepperY2.beginSerial(115200);
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z, TMC2208)
|
2018-08-15 01:41:37 +02:00
|
|
|
#ifdef Z_HARDWARE_SERIAL
|
|
|
|
Z_HARDWARE_SERIAL.begin(115200);
|
|
|
|
#else
|
|
|
|
stepperZ.beginSerial(115200);
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z2, TMC2208)
|
2018-08-15 01:41:37 +02:00
|
|
|
#ifdef Z2_HARDWARE_SERIAL
|
|
|
|
Z2_HARDWARE_SERIAL.begin(115200);
|
|
|
|
#else
|
|
|
|
stepperZ2.beginSerial(115200);
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2018-06-19 18:55:49 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z3, TMC2208)
|
|
|
|
#ifdef Z3_HARDWARE_SERIAL
|
|
|
|
Z3_HARDWARE_SERIAL.begin(115200);
|
|
|
|
#else
|
|
|
|
stepperZ3.beginSerial(115200);
|
|
|
|
#endif
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E0, TMC2208)
|
2018-08-15 01:41:37 +02:00
|
|
|
#ifdef E0_HARDWARE_SERIAL
|
|
|
|
E0_HARDWARE_SERIAL.begin(115200);
|
|
|
|
#else
|
|
|
|
stepperE0.beginSerial(115200);
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E1, TMC2208)
|
2018-08-15 01:41:37 +02:00
|
|
|
#ifdef E1_HARDWARE_SERIAL
|
|
|
|
E1_HARDWARE_SERIAL.begin(115200);
|
|
|
|
#else
|
|
|
|
stepperE1.beginSerial(115200);
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E2, TMC2208)
|
2018-08-15 01:41:37 +02:00
|
|
|
#ifdef E2_HARDWARE_SERIAL
|
|
|
|
E2_HARDWARE_SERIAL.begin(115200);
|
|
|
|
#else
|
|
|
|
stepperE2.beginSerial(115200);
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E3, TMC2208)
|
2018-08-15 01:41:37 +02:00
|
|
|
#ifdef E3_HARDWARE_SERIAL
|
|
|
|
E3_HARDWARE_SERIAL.begin(115200);
|
|
|
|
#else
|
|
|
|
stepperE3.beginSerial(115200);
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E4, TMC2208)
|
2018-08-15 01:41:37 +02:00
|
|
|
#ifdef E4_HARDWARE_SERIAL
|
|
|
|
E4_HARDWARE_SERIAL.begin(115200);
|
|
|
|
#else
|
|
|
|
stepperE4.beginSerial(115200);
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2018-09-17 06:57:50 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E5, TMC2208)
|
|
|
|
#ifdef E5_HARDWARE_SERIAL
|
|
|
|
E5_HARDWARE_SERIAL.begin(115200);
|
|
|
|
#else
|
|
|
|
stepperE5.beginSerial(115200);
|
|
|
|
#endif
|
|
|
|
#endif
|
2017-12-15 22:03:14 +01:00
|
|
|
}
|
|
|
|
|
2018-10-03 09:48:49 +02:00
|
|
|
template<char AXIS_LETTER, char DRIVER_ID>
|
|
|
|
void tmc_init(TMCMarlin<TMC2208Stepper, AXIS_LETTER, DRIVER_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
|
|
|
|
#if DISABLED(STEALTHCHOP) || DISABLED(HYBRID_THRESHOLD)
|
|
|
|
UNUSED(thrs);
|
|
|
|
UNUSED(spmm);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
TMC2208_n::GCONF_t gconf{0};
|
|
|
|
gconf.pdn_disable = true; // Use UART
|
|
|
|
gconf.mstep_reg_select = true; // Select microsteps with UART
|
|
|
|
gconf.i_scale_analog = false;
|
|
|
|
|
|
|
|
TMC2208_n::CHOPCONF_t chopconf{0};
|
|
|
|
chopconf.tbl = 0b01; // blank_time = 24
|
|
|
|
chopconf.toff = 5;
|
|
|
|
chopconf.intpol = INTERPOLATE;
|
|
|
|
chopconf.hstrt = 2;
|
|
|
|
chopconf.hend = 5;
|
|
|
|
st.CHOPCONF(chopconf.sr);
|
|
|
|
|
|
|
|
st.rms_current(mA, HOLD_MULTIPLIER);
|
2017-12-15 22:03:14 +01:00
|
|
|
st.microsteps(microsteps);
|
2018-10-03 09:48:49 +02:00
|
|
|
st.iholddelay(10);
|
2017-12-15 22:03:14 +01:00
|
|
|
st.TPOWERDOWN(128); // ~2s until driver lowers to hold current
|
|
|
|
#if ENABLED(STEALTHCHOP)
|
2018-10-03 09:48:49 +02:00
|
|
|
gconf.en_spreadcycle = false;
|
|
|
|
|
|
|
|
TMC2208_n::PWMCONF_t pwmconf{0};
|
|
|
|
pwmconf.pwm_lim = 12;
|
|
|
|
pwmconf.pwm_reg = 8;
|
|
|
|
pwmconf.pwm_autograd = true;
|
|
|
|
pwmconf.pwm_autoscale = true;
|
|
|
|
pwmconf.pwm_freq = 0b01;
|
|
|
|
pwmconf.pwm_grad = 14;
|
|
|
|
pwmconf.pwm_ofs = 36;
|
|
|
|
st.PWMCONF(pwmconf.sr);
|
2017-12-15 22:03:14 +01:00
|
|
|
#if ENABLED(HYBRID_THRESHOLD)
|
|
|
|
st.TPWMTHRS(12650000UL*microsteps/(256*thrs*spmm));
|
|
|
|
#endif
|
|
|
|
#else
|
2018-10-03 09:48:49 +02:00
|
|
|
gconf.en_spreadcycle = true;
|
2017-12-15 22:03:14 +01:00
|
|
|
#endif
|
2018-10-03 09:48:49 +02:00
|
|
|
st.GCONF(gconf.sr);
|
2017-12-15 22:03:14 +01:00
|
|
|
st.GSTAT(0b111); // Clear
|
|
|
|
delay(200);
|
|
|
|
}
|
2018-07-14 13:13:06 +02:00
|
|
|
#endif // TMC2208
|
2017-12-15 22:03:14 +01:00
|
|
|
|
2018-10-07 00:18:10 +02:00
|
|
|
//
|
|
|
|
// TMC2660 Driver objects and inits
|
|
|
|
//
|
|
|
|
#if HAS_DRIVER(TMC2660)
|
|
|
|
|
|
|
|
#include <SPI.h>
|
|
|
|
#include "planner.h"
|
|
|
|
#include "../core/enum.h"
|
|
|
|
|
|
|
|
#if ENABLED(TMC_USE_SW_SPI)
|
|
|
|
#define _TMC2660_DEFINE(ST, L) TMCMarlin<TMC2660Stepper, L> stepper##ST(ST##_CS_PIN, R_SENSE, TMC_SW_MOSI, TMC_SW_MISO, TMC_SW_SCK)
|
|
|
|
#define TMC2660_DEFINE(ST) _TMC2660_DEFINE(ST, TMC_##ST##_LABEL)
|
|
|
|
#else
|
|
|
|
#define _TMC2660_DEFINE(ST, L) TMCMarlin<TMC2660Stepper, L> stepper##ST(ST##_CS_PIN, R_SENSE)
|
|
|
|
#define TMC2660_DEFINE(ST) _TMC2660_DEFINE(ST, TMC_##ST##_LABEL)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Stepper objects of TMC2660 steppers used
|
|
|
|
#if AXIS_DRIVER_TYPE(X, TMC2660)
|
|
|
|
TMC2660_DEFINE(X);
|
|
|
|
#endif
|
|
|
|
#if AXIS_DRIVER_TYPE(X2, TMC2660)
|
|
|
|
TMC2660_DEFINE(X2);
|
|
|
|
#endif
|
|
|
|
#if AXIS_DRIVER_TYPE(Y, TMC2660)
|
|
|
|
TMC2660_DEFINE(Y);
|
|
|
|
#endif
|
|
|
|
#if AXIS_DRIVER_TYPE(Y2, TMC2660)
|
|
|
|
TMC2660_DEFINE(Y2);
|
|
|
|
#endif
|
|
|
|
#if AXIS_DRIVER_TYPE(Z, TMC2660)
|
|
|
|
TMC2660_DEFINE(Z);
|
|
|
|
#endif
|
|
|
|
#if AXIS_DRIVER_TYPE(Z2, TMC2660)
|
|
|
|
TMC2660_DEFINE(Z2);
|
|
|
|
#endif
|
|
|
|
#if AXIS_DRIVER_TYPE(E0, TMC2660)
|
|
|
|
TMC2660_DEFINE(E0);
|
|
|
|
#endif
|
|
|
|
#if AXIS_DRIVER_TYPE(E1, TMC2660)
|
|
|
|
TMC2660_DEFINE(E1);
|
|
|
|
#endif
|
|
|
|
#if AXIS_DRIVER_TYPE(E2, TMC2660)
|
|
|
|
TMC2660_DEFINE(E2);
|
|
|
|
#endif
|
|
|
|
#if AXIS_DRIVER_TYPE(E3, TMC2660)
|
|
|
|
TMC2660_DEFINE(E3);
|
|
|
|
#endif
|
|
|
|
#if AXIS_DRIVER_TYPE(E4, TMC2660)
|
|
|
|
TMC2660_DEFINE(E4);
|
|
|
|
#endif
|
|
|
|
#if AXIS_DRIVER_TYPE(E5, TMC2660)
|
|
|
|
TMC2660_DEFINE(E5);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template<char AXIS_LETTER, char DRIVER_ID>
|
|
|
|
void tmc_init(TMCMarlin<TMC2660Stepper, AXIS_LETTER, DRIVER_ID> &st, const uint16_t mA, const uint16_t microsteps, const uint32_t, const float) {
|
|
|
|
st.begin();
|
|
|
|
st.rms_current(mA);
|
|
|
|
st.microsteps(microsteps);
|
|
|
|
st.blank_time(24);
|
|
|
|
st.toff(5); // Only enables the driver if used with stealthChop
|
|
|
|
st.intpol(INTERPOLATE);
|
|
|
|
//st.hysteresis_start(3);
|
|
|
|
//st.hysteresis_end(2);
|
|
|
|
}
|
|
|
|
#endif // TMC2660
|
|
|
|
|
2018-03-19 01:01:42 +01:00
|
|
|
void restore_stepper_drivers() {
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_IS_TMC(X)
|
2018-03-19 01:01:42 +01:00
|
|
|
stepperX.push();
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_IS_TMC(X2)
|
2018-03-19 01:01:42 +01:00
|
|
|
stepperX2.push();
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_IS_TMC(Y)
|
2018-03-19 01:01:42 +01:00
|
|
|
stepperY.push();
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_IS_TMC(Y2)
|
2018-03-19 01:01:42 +01:00
|
|
|
stepperY2.push();
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_IS_TMC(Z)
|
2018-03-19 01:01:42 +01:00
|
|
|
stepperZ.push();
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_IS_TMC(Z2)
|
2018-03-19 01:01:42 +01:00
|
|
|
stepperZ2.push();
|
|
|
|
#endif
|
2018-06-19 18:55:49 +02:00
|
|
|
#if AXIS_IS_TMC(Z3)
|
|
|
|
stepperZ3.push();
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_IS_TMC(E0)
|
2018-03-19 01:01:42 +01:00
|
|
|
stepperE0.push();
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_IS_TMC(E1)
|
2018-03-19 01:01:42 +01:00
|
|
|
stepperE1.push();
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_IS_TMC(E2)
|
2018-03-19 01:01:42 +01:00
|
|
|
stepperE2.push();
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_IS_TMC(E3)
|
2018-03-19 01:01:42 +01:00
|
|
|
stepperE3.push();
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_IS_TMC(E4)
|
2018-03-19 01:01:42 +01:00
|
|
|
stepperE4.push();
|
|
|
|
#endif
|
2018-09-17 06:57:50 +02:00
|
|
|
#if AXIS_IS_TMC(E5)
|
|
|
|
stepperE5.push();
|
|
|
|
#endif
|
2018-03-19 01:01:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset_stepper_drivers() {
|
2018-07-14 13:13:06 +02:00
|
|
|
#if HAS_DRIVER(TMC26X)
|
2018-03-19 01:01:42 +01:00
|
|
|
tmc26x_init_to_defaults();
|
|
|
|
#endif
|
2018-10-03 09:48:49 +02:00
|
|
|
#if ENABLED(HAVE_L6470DRIVER)
|
|
|
|
L6470_init_to_defaults();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if AXIS_IS_TMC(X)
|
|
|
|
_TMC_INIT(X, planner.axis_steps_per_mm[X_AXIS]);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(X2)
|
|
|
|
_TMC_INIT(X2, planner.axis_steps_per_mm[X_AXIS]);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Y)
|
|
|
|
_TMC_INIT(Y, planner.axis_steps_per_mm[Y_AXIS]);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Y2)
|
|
|
|
_TMC_INIT(Y2, planner.axis_steps_per_mm[Y_AXIS]);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Z)
|
|
|
|
_TMC_INIT(Z, planner.axis_steps_per_mm[Z_AXIS]);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Z2)
|
|
|
|
_TMC_INIT(Z2, planner.axis_steps_per_mm[Z_AXIS]);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(Z3)
|
|
|
|
_TMC_INIT(Z3, planner.axis_steps_per_mm[Z_AXIS]);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E0)
|
|
|
|
_TMC_INIT(E0, planner.axis_steps_per_mm[E_AXIS]);
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E1)
|
|
|
|
{ constexpr uint8_t extruder = 1; _TMC_INIT(E1, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); }
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E2)
|
|
|
|
{ constexpr uint8_t extruder = 2; _TMC_INIT(E2, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); }
|
2018-03-19 01:01:42 +01:00
|
|
|
#endif
|
2018-10-03 09:48:49 +02:00
|
|
|
#if AXIS_IS_TMC(E3)
|
|
|
|
{ constexpr uint8_t extruder = 3; _TMC_INIT(E3, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); }
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E4)
|
|
|
|
{ constexpr uint8_t extruder = 4; _TMC_INIT(E4, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); }
|
|
|
|
#endif
|
|
|
|
#if AXIS_IS_TMC(E5)
|
|
|
|
{ constexpr uint8_t extruder = 5; _TMC_INIT(E5, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); }
|
|
|
|
#endif
|
|
|
|
|
2018-10-07 22:37:44 +02:00
|
|
|
#if USE_SENSORLESS
|
2018-10-03 09:48:49 +02:00
|
|
|
#if X_SENSORLESS
|
|
|
|
#if AXIS_HAS_STALLGUARD(X)
|
|
|
|
stepperX.sgt(X_STALL_SENSITIVITY);
|
|
|
|
#endif
|
|
|
|
#if AXIS_HAS_STALLGUARD(X2)
|
|
|
|
stepperX2.sgt(X_STALL_SENSITIVITY);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if Y_SENSORLESS
|
|
|
|
#if AXIS_HAS_STALLGUARD(Y)
|
|
|
|
stepperY.sgt(Y_STALL_SENSITIVITY);
|
|
|
|
#endif
|
|
|
|
#if AXIS_HAS_STALLGUARD(Y2)
|
|
|
|
stepperY2.sgt(Y_STALL_SENSITIVITY);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if Z_SENSORLESS
|
|
|
|
#if AXIS_HAS_STALLGUARD(Z)
|
|
|
|
stepperZ.sgt(Z_STALL_SENSITIVITY);
|
|
|
|
#endif
|
|
|
|
#if AXIS_HAS_STALLGUARD(Z2)
|
|
|
|
stepperZ2.sgt(Z_STALL_SENSITIVITY);
|
|
|
|
#endif
|
|
|
|
#if AXIS_HAS_STALLGUARD(Z3)
|
|
|
|
stepperZ3.sgt(Z_STALL_SENSITIVITY);
|
|
|
|
#endif
|
|
|
|
#endif
|
2018-03-19 01:01:42 +01:00
|
|
|
#endif
|
2018-10-03 09:48:49 +02:00
|
|
|
|
2018-03-19 01:01:42 +01:00
|
|
|
#ifdef TMC_ADV
|
|
|
|
TMC_ADV()
|
|
|
|
#endif
|
2018-10-03 09:48:49 +02:00
|
|
|
|
2018-09-15 03:00:55 +02:00
|
|
|
stepper.set_directions();
|
2018-03-19 01:01:42 +01:00
|
|
|
}
|
|
|
|
|
2016-11-07 21:46:01 +01:00
|
|
|
//
|
2015-02-27 12:43:23 +01:00
|
|
|
// L6470 Driver objects and inits
|
2016-11-07 21:46:01 +01:00
|
|
|
//
|
2018-07-14 13:13:06 +02:00
|
|
|
#if HAS_DRIVER(L6470)
|
2016-11-07 21:46:01 +01:00
|
|
|
|
2015-10-03 08:08:58 +02:00
|
|
|
#include <SPI.h>
|
|
|
|
#include <L6470.h>
|
2015-02-27 12:43:23 +01:00
|
|
|
|
2017-03-07 06:00:43 +01:00
|
|
|
#define _L6470_DEFINE(ST) L6470 stepper##ST(ST##_ENABLE_PIN)
|
|
|
|
|
2016-11-07 21:46:01 +01:00
|
|
|
// L6470 Stepper objects
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(X, L6470)
|
2017-03-07 06:00:43 +01:00
|
|
|
_L6470_DEFINE(X);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(X2, L6470)
|
2017-03-07 06:00:43 +01:00
|
|
|
_L6470_DEFINE(X2);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Y, L6470)
|
2017-03-07 06:00:43 +01:00
|
|
|
_L6470_DEFINE(Y);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Y2, L6470)
|
2017-03-07 06:00:43 +01:00
|
|
|
_L6470_DEFINE(Y2);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z, L6470)
|
2017-03-07 06:00:43 +01:00
|
|
|
_L6470_DEFINE(Z);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z2, L6470)
|
2017-03-07 06:00:43 +01:00
|
|
|
_L6470_DEFINE(Z2);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-06-19 18:55:49 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z3, L6470)
|
|
|
|
_L6470_DEFINE(Z3);
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E0, L6470)
|
2017-03-07 06:00:43 +01:00
|
|
|
_L6470_DEFINE(E0);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E1, L6470)
|
2017-03-07 06:00:43 +01:00
|
|
|
_L6470_DEFINE(E1);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E2, L6470)
|
2017-03-07 06:00:43 +01:00
|
|
|
_L6470_DEFINE(E2);
|
2015-07-31 07:28:11 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E3, L6470)
|
2017-03-07 06:00:43 +01:00
|
|
|
_L6470_DEFINE(E3);
|
2015-10-03 08:08:58 +02:00
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E4, L6470)
|
2017-04-09 10:23:05 +02:00
|
|
|
_L6470_DEFINE(E4);
|
|
|
|
#endif
|
2018-09-17 06:57:50 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E5, L6470)
|
|
|
|
_L6470_DEFINE(E5);
|
|
|
|
#endif
|
2016-11-07 21:46:01 +01:00
|
|
|
|
|
|
|
#define _L6470_INIT(A) do{ \
|
2017-09-07 10:36:39 +02:00
|
|
|
stepper##A.init(); \
|
2016-11-07 21:46:01 +01:00
|
|
|
stepper##A.softFree(); \
|
|
|
|
stepper##A.setMicroSteps(A##_MICROSTEPS); \
|
|
|
|
stepper##A.setOverCurrent(A##_OVERCURRENT); \
|
|
|
|
stepper##A.setStallCurrent(A##_STALLCURRENT); \
|
2017-06-15 22:17:41 +02:00
|
|
|
}while(0)
|
2016-11-07 21:46:01 +01:00
|
|
|
|
2018-03-19 01:01:42 +01:00
|
|
|
void L6470_init_to_defaults() {
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(X, L6470)
|
2016-11-07 21:46:01 +01:00
|
|
|
_L6470_INIT(X);
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(X2, L6470)
|
2016-11-07 21:46:01 +01:00
|
|
|
_L6470_INIT(X2);
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Y, L6470)
|
2016-11-07 21:46:01 +01:00
|
|
|
_L6470_INIT(Y);
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Y2, L6470)
|
2016-11-07 21:46:01 +01:00
|
|
|
_L6470_INIT(Y2);
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z, L6470)
|
2016-11-07 21:46:01 +01:00
|
|
|
_L6470_INIT(Z);
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z2, L6470)
|
2016-11-07 21:46:01 +01:00
|
|
|
_L6470_INIT(Z2);
|
|
|
|
#endif
|
2018-06-19 18:55:49 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(Z3, L6470)
|
|
|
|
_L6470_INIT(Z3);
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E0, L6470)
|
2016-11-07 21:46:01 +01:00
|
|
|
_L6470_INIT(E0);
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E1, L6470)
|
2016-11-07 21:46:01 +01:00
|
|
|
_L6470_INIT(E1);
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E2, L6470)
|
2016-11-07 21:46:01 +01:00
|
|
|
_L6470_INIT(E2);
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E3, L6470)
|
2016-11-07 21:46:01 +01:00
|
|
|
_L6470_INIT(E3);
|
|
|
|
#endif
|
2018-07-14 13:13:06 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E4, L6470)
|
2017-04-09 10:23:05 +02:00
|
|
|
_L6470_INIT(E4);
|
|
|
|
#endif
|
2018-09-17 06:57:50 +02:00
|
|
|
#if AXIS_DRIVER_TYPE(E5, L6470)
|
|
|
|
_L6470_INIT(E5);
|
|
|
|
#endif
|
2016-11-07 21:46:01 +01:00
|
|
|
}
|
|
|
|
|
2018-07-14 13:13:06 +02:00
|
|
|
#endif // L6470
|