2017-12-15 21:03:14 +00: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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _TMC_UTIL_H_
|
|
|
|
#define _TMC_UTIL_H_
|
|
|
|
|
2018-03-13 07:01:41 +00:00
|
|
|
#include "../inc/MarlinConfigPre.h"
|
2017-12-15 21:03:14 +00:00
|
|
|
|
2018-07-14 11:13:06 +00:00
|
|
|
#if HAS_DRIVER(TMC2130)
|
2018-03-13 07:01:41 +00:00
|
|
|
#include <TMC2130Stepper.h>
|
|
|
|
#endif
|
|
|
|
|
2018-07-14 11:13:06 +00:00
|
|
|
#if HAS_DRIVER(TMC2208)
|
2018-03-13 07:01:41 +00:00
|
|
|
#include <TMC2208Stepper.h>
|
|
|
|
#endif
|
2017-12-15 21:03:14 +00:00
|
|
|
|
2017-12-25 15:05:31 +00:00
|
|
|
extern bool report_tmc_status;
|
2017-12-29 19:38:08 +00:00
|
|
|
|
2018-06-19 16:55:49 +00:00
|
|
|
enum TMC_AxisEnum : char {
|
|
|
|
TMC_X, TMC_Y, TMC_Z
|
|
|
|
#if ENABLED(DUAL_X_CARRIAGE) || ENABLED(X_DUAL_STEPPER_DRIVERS)
|
|
|
|
, TMC_X2
|
|
|
|
#endif
|
|
|
|
#if ENABLED(Y_DUAL_STEPPER_DRIVERS)
|
|
|
|
, TMC_Y2
|
|
|
|
#endif
|
|
|
|
#if ENABLED(Z_DUAL_STEPPER_DRIVERS)
|
|
|
|
, TMC_Z2
|
|
|
|
#endif
|
|
|
|
#if ENABLED(Z_TRIPLE_STEPPER_DRIVERS)
|
|
|
|
, TMC_Z3
|
|
|
|
#endif
|
2018-09-13 06:35:55 +00:00
|
|
|
#if E_STEPPERS
|
|
|
|
, TMC_E0
|
|
|
|
#if E_STEPPERS > 1
|
|
|
|
, TMC_E1
|
|
|
|
#if E_STEPPERS > 2
|
|
|
|
, TMC_E2
|
|
|
|
#if E_STEPPERS > 3
|
|
|
|
, TMC_E3
|
|
|
|
#if E_STEPPERS > 4
|
|
|
|
, TMC_E4
|
|
|
|
#if E_STEPPERS > 5
|
|
|
|
, TMC_E5
|
|
|
|
#endif // E_STEPPERS > 5
|
|
|
|
#endif // E_STEPPERS > 4
|
|
|
|
#endif // E_STEPPERS > 3
|
|
|
|
#endif // E_STEPPERS > 2
|
|
|
|
#endif // E_STEPPERS > 1
|
|
|
|
#endif // E_STEPPERS
|
2018-06-19 16:55:49 +00:00
|
|
|
};
|
2017-12-15 21:03:14 +00:00
|
|
|
|
2018-01-10 01:14:07 +00:00
|
|
|
constexpr uint32_t _tmc_thrs(const uint16_t msteps, const int32_t thrs, const uint32_t spmm) {
|
|
|
|
return 12650000UL * msteps / (256 * thrs * spmm);
|
|
|
|
}
|
|
|
|
|
2018-03-07 04:16:19 +00:00
|
|
|
void _tmc_say_axis(const TMC_AxisEnum axis);
|
|
|
|
void _tmc_say_current(const TMC_AxisEnum axis, const uint16_t curr);
|
|
|
|
void _tmc_say_otpw(const TMC_AxisEnum axis, const bool otpw);
|
|
|
|
void _tmc_say_otpw_cleared(const TMC_AxisEnum axis);
|
|
|
|
void _tmc_say_pwmthrs(const TMC_AxisEnum axis, const uint32_t thrs);
|
|
|
|
void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt);
|
2018-01-10 01:14:07 +00:00
|
|
|
|
2017-12-15 21:03:14 +00:00
|
|
|
template<typename TMC>
|
2018-03-07 04:16:19 +00:00
|
|
|
void tmc_get_current(TMC &st, const TMC_AxisEnum axis) {
|
|
|
|
_tmc_say_current(axis, st.getCurrent());
|
2017-12-29 19:38:08 +00:00
|
|
|
}
|
2017-12-15 21:03:14 +00:00
|
|
|
template<typename TMC>
|
2018-05-10 05:05:15 +00:00
|
|
|
void tmc_set_current(TMC &st, const int mA) {
|
2017-12-29 19:38:08 +00:00
|
|
|
st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
|
|
|
|
}
|
2017-12-15 21:03:14 +00:00
|
|
|
template<typename TMC>
|
2018-03-07 04:16:19 +00:00
|
|
|
void tmc_report_otpw(TMC &st, const TMC_AxisEnum axis) {
|
|
|
|
_tmc_say_otpw(axis, st.getOTPW());
|
2017-12-29 19:38:08 +00:00
|
|
|
}
|
2017-12-15 21:03:14 +00:00
|
|
|
template<typename TMC>
|
2018-03-07 04:16:19 +00:00
|
|
|
void tmc_clear_otpw(TMC &st, const TMC_AxisEnum axis) {
|
2017-12-29 19:38:08 +00:00
|
|
|
st.clear_otpw();
|
2018-03-07 04:16:19 +00:00
|
|
|
_tmc_say_otpw_cleared(axis);
|
2017-12-29 19:38:08 +00:00
|
|
|
}
|
2017-12-15 21:03:14 +00:00
|
|
|
template<typename TMC>
|
2018-03-07 04:16:19 +00:00
|
|
|
void tmc_get_pwmthrs(TMC &st, const TMC_AxisEnum axis, const uint16_t spmm) {
|
|
|
|
_tmc_say_pwmthrs(axis, _tmc_thrs(st.microsteps(), st.TPWMTHRS(), spmm));
|
2017-12-29 19:38:08 +00:00
|
|
|
}
|
2017-12-15 21:03:14 +00:00
|
|
|
template<typename TMC>
|
2018-05-10 05:05:15 +00:00
|
|
|
void tmc_set_pwmthrs(TMC &st, const int32_t thrs, const uint32_t spmm) {
|
2018-01-10 01:14:07 +00:00
|
|
|
st.TPWMTHRS(_tmc_thrs(st.microsteps(), thrs, spmm));
|
2017-12-29 19:38:08 +00:00
|
|
|
}
|
2017-12-15 21:03:14 +00:00
|
|
|
template<typename TMC>
|
2018-03-07 04:16:19 +00:00
|
|
|
void tmc_get_sgt(TMC &st, const TMC_AxisEnum axis) {
|
|
|
|
_tmc_say_sgt(axis, st.sgt());
|
2017-12-29 19:38:08 +00:00
|
|
|
}
|
2017-12-15 21:03:14 +00:00
|
|
|
template<typename TMC>
|
2018-05-10 05:05:15 +00:00
|
|
|
void tmc_set_sgt(TMC &st, const int8_t sgt_val) {
|
2017-12-29 19:38:08 +00:00
|
|
|
st.sgt(sgt_val);
|
|
|
|
}
|
2017-12-15 21:03:14 +00:00
|
|
|
|
|
|
|
void monitor_tmc_driver();
|
|
|
|
|
2018-01-10 01:14:07 +00:00
|
|
|
#if ENABLED(TMC_DEBUG)
|
|
|
|
void tmc_set_report_status(const bool status);
|
|
|
|
void tmc_report_all();
|
|
|
|
#endif
|
|
|
|
|
2017-12-15 21:03:14 +00:00
|
|
|
/**
|
|
|
|
* TMC2130 specific sensorless homing using stallGuard2.
|
|
|
|
* stallGuard2 only works when in spreadCycle mode.
|
|
|
|
* spreadCycle and stealthChop are mutually exclusive.
|
|
|
|
*
|
|
|
|
* Defined here because of limitations with templates and headers.
|
|
|
|
*/
|
|
|
|
#if ENABLED(SENSORLESS_HOMING)
|
2018-04-27 05:51:28 +00:00
|
|
|
void tmc_sensorless_homing(TMC2130Stepper &st, const bool enable=true);
|
2017-12-15 21:03:14 +00:00
|
|
|
#endif
|
|
|
|
|
2018-07-14 11:13:06 +00:00
|
|
|
#if HAS_DRIVER(TMC2130)
|
2018-02-10 20:08:53 +00:00
|
|
|
void tmc_init_cs_pins();
|
|
|
|
#endif
|
|
|
|
|
2017-12-15 21:03:14 +00:00
|
|
|
#endif // _TMC_UTIL_H_
|