My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stepper_indirection.cpp 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * stepper_indirection.cpp
  24. *
  25. * Stepper motor driver indirection to allow some stepper functions to
  26. * be done via SPI/I2c instead of direct pin manipulation.
  27. *
  28. * Part of Marlin
  29. *
  30. * Copyright (c) 2015 Dominik Wenger
  31. */
  32. #include "stepper_indirection.h"
  33. #include "../inc/MarlinConfig.h"
  34. //
  35. // TMC26X Driver objects and inits
  36. //
  37. #if ENABLED(HAVE_TMC26X)
  38. #include <SPI.h>
  39. #ifdef STM32F7
  40. #include "../HAL/HAL_STM32F7/TMC2660.h"
  41. #else
  42. #include <TMC26XStepper.h>
  43. #endif
  44. #define _TMC26X_DEFINE(ST) TMC26XStepper stepper##ST(200, ST##_CS_PIN, ST##_STEP_PIN, ST##_DIR_PIN, ST##_MAX_CURRENT, ST##_SENSE_RESISTOR)
  45. #if ENABLED(X_IS_TMC26X)
  46. _TMC26X_DEFINE(X);
  47. #endif
  48. #if ENABLED(X2_IS_TMC26X)
  49. _TMC26X_DEFINE(X2);
  50. #endif
  51. #if ENABLED(Y_IS_TMC26X)
  52. _TMC26X_DEFINE(Y);
  53. #endif
  54. #if ENABLED(Y2_IS_TMC26X)
  55. _TMC26X_DEFINE(Y2);
  56. #endif
  57. #if ENABLED(Z_IS_TMC26X)
  58. _TMC26X_DEFINE(Z);
  59. #endif
  60. #if ENABLED(Z2_IS_TMC26X)
  61. _TMC26X_DEFINE(Z2);
  62. #endif
  63. #if ENABLED(E0_IS_TMC26X)
  64. _TMC26X_DEFINE(E0);
  65. #endif
  66. #if ENABLED(E1_IS_TMC26X)
  67. _TMC26X_DEFINE(E1);
  68. #endif
  69. #if ENABLED(E2_IS_TMC26X)
  70. _TMC26X_DEFINE(E2);
  71. #endif
  72. #if ENABLED(E3_IS_TMC26X)
  73. _TMC26X_DEFINE(E3);
  74. #endif
  75. #if ENABLED(E4_IS_TMC26X)
  76. _TMC26X_DEFINE(E4);
  77. #endif
  78. #define _TMC26X_INIT(A) do{ \
  79. stepper##A.setMicrosteps(A##_MICROSTEPS); \
  80. stepper##A.start(); \
  81. }while(0)
  82. void tmc26x_init_to_defaults() {
  83. #if ENABLED(X_IS_TMC26X)
  84. _TMC26X_INIT(X);
  85. #endif
  86. #if ENABLED(X2_IS_TMC26X)
  87. _TMC26X_INIT(X2);
  88. #endif
  89. #if ENABLED(Y_IS_TMC26X)
  90. _TMC26X_INIT(Y);
  91. #endif
  92. #if ENABLED(Y2_IS_TMC26X)
  93. _TMC26X_INIT(Y2);
  94. #endif
  95. #if ENABLED(Z_IS_TMC26X)
  96. _TMC26X_INIT(Z);
  97. #endif
  98. #if ENABLED(Z2_IS_TMC26X)
  99. _TMC26X_INIT(Z2);
  100. #endif
  101. #if ENABLED(E0_IS_TMC26X)
  102. _TMC26X_INIT(E0);
  103. #endif
  104. #if ENABLED(E1_IS_TMC26X)
  105. _TMC26X_INIT(E1);
  106. #endif
  107. #if ENABLED(E2_IS_TMC26X)
  108. _TMC26X_INIT(E2);
  109. #endif
  110. #if ENABLED(E3_IS_TMC26X)
  111. _TMC26X_INIT(E3);
  112. #endif
  113. #if ENABLED(E4_IS_TMC26X)
  114. _TMC26X_INIT(E4);
  115. #endif
  116. }
  117. #endif // HAVE_TMC26X
  118. //
  119. // TMC2130 Driver objects and inits
  120. //
  121. #if ENABLED(HAVE_TMC2130)
  122. #include <SPI.h>
  123. #include <TMC2130Stepper.h>
  124. #include "planner.h"
  125. #include "../core/enum.h"
  126. #if TMC2130STEPPER_VERSION < 0x020201
  127. #error "Update TMC2130Stepper library to 2.2.1 or newer."
  128. #endif
  129. #if ENABLED(TMC_USE_SW_SPI)
  130. #define _TMC2130_DEFINE(ST) TMC2130Stepper stepper##ST(ST##_ENABLE_PIN, ST##_DIR_PIN, ST##_STEP_PIN, ST##_CS_PIN, TMC_SW_MOSI, TMC_SW_MISO, TMC_SW_SCK)
  131. #else
  132. #define _TMC2130_DEFINE(ST) TMC2130Stepper stepper##ST(ST##_ENABLE_PIN, ST##_DIR_PIN, ST##_STEP_PIN, ST##_CS_PIN)
  133. #endif
  134. // Stepper objects of TMC2130 steppers used
  135. #if ENABLED(X_IS_TMC2130)
  136. _TMC2130_DEFINE(X);
  137. #endif
  138. #if ENABLED(X2_IS_TMC2130)
  139. _TMC2130_DEFINE(X2);
  140. #endif
  141. #if ENABLED(Y_IS_TMC2130)
  142. _TMC2130_DEFINE(Y);
  143. #endif
  144. #if ENABLED(Y2_IS_TMC2130)
  145. _TMC2130_DEFINE(Y2);
  146. #endif
  147. #if ENABLED(Z_IS_TMC2130)
  148. _TMC2130_DEFINE(Z);
  149. #endif
  150. #if ENABLED(Z2_IS_TMC2130)
  151. _TMC2130_DEFINE(Z2);
  152. #endif
  153. #if ENABLED(E0_IS_TMC2130)
  154. _TMC2130_DEFINE(E0);
  155. #endif
  156. #if ENABLED(E1_IS_TMC2130)
  157. _TMC2130_DEFINE(E1);
  158. #endif
  159. #if ENABLED(E2_IS_TMC2130)
  160. _TMC2130_DEFINE(E2);
  161. #endif
  162. #if ENABLED(E3_IS_TMC2130)
  163. _TMC2130_DEFINE(E3);
  164. #endif
  165. #if ENABLED(E4_IS_TMC2130)
  166. _TMC2130_DEFINE(E4);
  167. #endif
  168. // Use internal reference voltage for current calculations. This is the default.
  169. // Following values from Trinamic's spreadsheet with values for a NEMA17 (42BYGHW609)
  170. // https://www.trinamic.com/products/integrated-circuits/details/tmc2130/
  171. void tmc2130_init(TMC2130Stepper &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
  172. #if DISABLED(STEALTHCHOP) || DISABLED(HYBRID_THRESHOLD)
  173. UNUSED(thrs);
  174. UNUSED(spmm);
  175. #endif
  176. st.begin();
  177. st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
  178. st.microsteps(microsteps);
  179. st.blank_time(24);
  180. st.off_time(5); // Only enables the driver if used with stealthChop
  181. st.interpolate(INTERPOLATE);
  182. st.power_down_delay(128); // ~2s until driver lowers to hold current
  183. st.hysteresis_start(3);
  184. st.hysteresis_end(2);
  185. #if ENABLED(STEALTHCHOP)
  186. st.stealth_freq(1); // f_pwm = 2/683 f_clk
  187. st.stealth_autoscale(1);
  188. st.stealth_gradient(5);
  189. st.stealth_amplitude(255);
  190. st.stealthChop(1);
  191. #if ENABLED(HYBRID_THRESHOLD)
  192. st.stealth_max_speed(12650000UL*microsteps/(256*thrs*spmm));
  193. #endif
  194. #elif ENABLED(SENSORLESS_HOMING)
  195. st.coolstep_min_speed(1024UL * 1024UL - 1UL);
  196. #endif
  197. st.GSTAT(); // Clear GSTAT
  198. }
  199. #define _TMC2130_INIT(ST, SPMM) tmc2130_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, SPMM)
  200. void tmc2130_init_to_defaults() {
  201. #if ENABLED(X_IS_TMC2130)
  202. _TMC2130_INIT( X, planner.axis_steps_per_mm[X_AXIS]);
  203. #endif
  204. #if ENABLED(X2_IS_TMC2130)
  205. _TMC2130_INIT(X2, planner.axis_steps_per_mm[X_AXIS]);
  206. #endif
  207. #if ENABLED(Y_IS_TMC2130)
  208. _TMC2130_INIT( Y, planner.axis_steps_per_mm[Y_AXIS]);
  209. #endif
  210. #if ENABLED(Y2_IS_TMC2130)
  211. _TMC2130_INIT(Y2, planner.axis_steps_per_mm[Y_AXIS]);
  212. #endif
  213. #if ENABLED(Z_IS_TMC2130)
  214. _TMC2130_INIT( Z, planner.axis_steps_per_mm[Z_AXIS]);
  215. #endif
  216. #if ENABLED(Z2_IS_TMC2130)
  217. _TMC2130_INIT(Z2, planner.axis_steps_per_mm[Z_AXIS]);
  218. #endif
  219. #if ENABLED(E0_IS_TMC2130)
  220. _TMC2130_INIT(E0, planner.axis_steps_per_mm[E_AXIS]);
  221. #endif
  222. #if ENABLED(E1_IS_TMC2130)
  223. { constexpr int extruder = 1; _TMC2130_INIT(E1, planner.axis_steps_per_mm[E_AXIS_N]); }
  224. #endif
  225. #if ENABLED(E2_IS_TMC2130)
  226. { constexpr int extruder = 2; _TMC2130_INIT(E2, planner.axis_steps_per_mm[E_AXIS_N]); }
  227. #endif
  228. #if ENABLED(E3_IS_TMC2130)
  229. { constexpr int extruder = 3; _TMC2130_INIT(E3, planner.axis_steps_per_mm[E_AXIS_N]); }
  230. #endif
  231. #if ENABLED(E4_IS_TMC2130)
  232. { constexpr int extruder = 4; _TMC2130_INIT(E4, planner.axis_steps_per_mm[E_AXIS_N]); }
  233. #endif
  234. #if ENABLED(SENSORLESS_HOMING)
  235. #define TMC_INIT_SGT(P,Q) stepper##Q.sgt(P##_HOMING_SENSITIVITY);
  236. #ifdef X_HOMING_SENSITIVITY
  237. #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)
  238. stepperX.sgt(X_HOMING_SENSITIVITY);
  239. #endif
  240. #if ENABLED(X2_IS_TMC2130)
  241. stepperX2.sgt(X_HOMING_SENSITIVITY);
  242. #endif
  243. #endif
  244. #ifdef Y_HOMING_SENSITIVITY
  245. #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS)
  246. stepperY.sgt(Y_HOMING_SENSITIVITY);
  247. #endif
  248. #if ENABLED(Y2_IS_TMC2130)
  249. stepperY2.sgt(Y_HOMING_SENSITIVITY);
  250. #endif
  251. #endif
  252. #ifdef Z_HOMING_SENSITIVITY
  253. #if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS)
  254. stepperZ.sgt(Z_HOMING_SENSITIVITY);
  255. #endif
  256. #if ENABLED(Z2_IS_TMC2130)
  257. stepperZ2.sgt(Z_HOMING_SENSITIVITY);
  258. #endif
  259. #endif
  260. #endif
  261. }
  262. #endif // HAVE_TMC2130
  263. //
  264. // TMC2208 Driver objects and inits
  265. //
  266. #if ENABLED(HAVE_TMC2208)
  267. #include <SoftwareSerial.h>
  268. #include <HardwareSerial.h>
  269. #include <TMC2208Stepper.h>
  270. #include "planner.h"
  271. #if TMC2208STEPPER_VERSION < 0x000101
  272. #error "Update TMC2208Stepper library to 0.1.1 or newer."
  273. #endif
  274. #define _TMC2208_DEFINE_HARDWARE(ST) TMC2208Stepper stepper##ST(&ST##_HARDWARE_SERIAL)
  275. #define _TMC2208_DEFINE_SOFTWARE(ST) SoftwareSerial ST##_HARDWARE_SERIAL = SoftwareSerial(ST##_SERIAL_RX_PIN, ST##_SERIAL_TX_PIN); \
  276. TMC2208Stepper stepper##ST(&ST##_HARDWARE_SERIAL, ST##_SERIAL_RX_PIN > -1)
  277. // Stepper objects of TMC2208 steppers used
  278. #if ENABLED(X_IS_TMC2208)
  279. #ifdef X_HARDWARE_SERIAL
  280. _TMC2208_DEFINE_HARDWARE(X);
  281. #else
  282. _TMC2208_DEFINE_SOFTWARE(X);
  283. #endif
  284. #endif
  285. #if ENABLED(X2_IS_TMC2208)
  286. #ifdef X2_HARDWARE_SERIAL
  287. _TMC2208_DEFINE_HARDWARE(X2);
  288. #else
  289. _TMC2208_DEFINE_SOFTWARE(X2);
  290. #endif
  291. #endif
  292. #if ENABLED(Y_IS_TMC2208)
  293. #ifdef Y_HARDWARE_SERIAL
  294. _TMC2208_DEFINE_HARDWARE(Y);
  295. #else
  296. _TMC2208_DEFINE_SOFTWARE(Y);
  297. #endif
  298. #endif
  299. #if ENABLED(Y2_IS_TMC2208)
  300. #ifdef Y2_HARDWARE_SERIAL
  301. _TMC2208_DEFINE_HARDWARE(Y2);
  302. #else
  303. _TMC2208_DEFINE_SOFTWARE(Y2);
  304. #endif
  305. #endif
  306. #if ENABLED(Z_IS_TMC2208)
  307. #ifdef Z_HARDWARE_SERIAL
  308. _TMC2208_DEFINE_HARDWARE(Z);
  309. #else
  310. _TMC2208_DEFINE_SOFTWARE(Z);
  311. #endif
  312. #endif
  313. #if ENABLED(Z2_IS_TMC2208)
  314. #ifdef Z2_HARDWARE_SERIAL
  315. _TMC2208_DEFINE_HARDWARE(Z2);
  316. #else
  317. _TMC2208_DEFINE_SOFTWARE(Z2);
  318. #endif
  319. #endif
  320. #if ENABLED(E0_IS_TMC2208)
  321. #ifdef E0_HARDWARE_SERIAL
  322. _TMC2208_DEFINE_HARDWARE(E0);
  323. #else
  324. _TMC2208_DEFINE_SOFTWARE(E0);
  325. #endif
  326. #endif
  327. #if ENABLED(E1_IS_TMC2208)
  328. #ifdef E1_HARDWARE_SERIAL
  329. _TMC2208_DEFINE_HARDWARE(E1);
  330. #else
  331. _TMC2208_DEFINE_SOFTWARE(E1);
  332. #endif
  333. #endif
  334. #if ENABLED(E2_IS_TMC2208)
  335. #ifdef E2_HARDWARE_SERIAL
  336. _TMC2208_DEFINE_HARDWARE(E2);
  337. #else
  338. _TMC2208_DEFINE_SOFTWARE(E2);
  339. #endif
  340. #endif
  341. #if ENABLED(E3_IS_TMC2208)
  342. #ifdef E3_HARDWARE_SERIAL
  343. _TMC2208_DEFINE_HARDWARE(E3);
  344. #else
  345. _TMC2208_DEFINE_SOFTWARE(E3);
  346. #endif
  347. #endif
  348. #if ENABLED(E4_IS_TMC2208)
  349. #ifdef E4_HARDWARE_SERIAL
  350. _TMC2208_DEFINE_HARDWARE(E4);
  351. #else
  352. _TMC2208_DEFINE_SOFTWARE(E4);
  353. #endif
  354. #endif
  355. void tmc2208_serial_begin() {
  356. #if ENABLED(X_IS_TMC2208)
  357. X_HARDWARE_SERIAL.begin(115200);
  358. #endif
  359. #if ENABLED(X2_IS_TMC2208)
  360. X2_HARDWARE_SERIAL.begin(115200);
  361. #endif
  362. #if ENABLED(Y_IS_TMC2208)
  363. Y_HARDWARE_SERIAL.begin(115200);
  364. #endif
  365. #if ENABLED(Y2_IS_TMC2208)
  366. Y2_HARDWARE_SERIAL.begin(115200);
  367. #endif
  368. #if ENABLED(Z_IS_TMC2208)
  369. Z_HARDWARE_SERIAL.begin(115200);
  370. #endif
  371. #if ENABLED(Z2_IS_TMC2208)
  372. Z2_HARDWARE_SERIAL.begin(115200);
  373. #endif
  374. #if ENABLED(E0_IS_TMC2208)
  375. E0_HARDWARE_SERIAL.begin(115200);
  376. #endif
  377. #if ENABLED(E1_IS_TMC2208)
  378. E1_HARDWARE_SERIAL.begin(115200);
  379. #endif
  380. #if ENABLED(E2_IS_TMC2208)
  381. E2_HARDWARE_SERIAL.begin(115200);
  382. #endif
  383. #if ENABLED(E3_IS_TMC2208)
  384. E3_HARDWARE_SERIAL.begin(115200);
  385. #endif
  386. #if ENABLED(E4_IS_TMC2208)
  387. E4_HARDWARE_SERIAL.begin(115200);
  388. #endif
  389. }
  390. // Use internal reference voltage for current calculations. This is the default.
  391. // Following values from Trinamic's spreadsheet with values for a NEMA17 (42BYGHW609)
  392. void tmc2208_init(TMC2208Stepper &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
  393. st.pdn_disable(true); // Use UART
  394. st.mstep_reg_select(true); // Select microsteps with UART
  395. st.I_scale_analog(false);
  396. st.rms_current(mA, HOLD_MULTIPLIER, R_SENSE);
  397. st.microsteps(microsteps);
  398. st.blank_time(24);
  399. st.toff(5);
  400. st.intpol(INTERPOLATE);
  401. st.TPOWERDOWN(128); // ~2s until driver lowers to hold current
  402. st.hysteresis_start(3);
  403. st.hysteresis_end(2);
  404. #if ENABLED(STEALTHCHOP)
  405. st.pwm_lim(12);
  406. st.pwm_reg(8);
  407. st.pwm_autograd(1);
  408. st.pwm_autoscale(1);
  409. st.pwm_freq(1);
  410. st.pwm_grad(14);
  411. st.pwm_ofs(36);
  412. st.en_spreadCycle(false);
  413. #if ENABLED(HYBRID_THRESHOLD)
  414. st.TPWMTHRS(12650000UL*microsteps/(256*thrs*spmm));
  415. #else
  416. UNUSED(thrs);
  417. UNUSED(spmm);
  418. #endif
  419. #else
  420. st.en_spreadCycle(true);
  421. #endif
  422. st.GSTAT(0b111); // Clear
  423. delay(200);
  424. }
  425. #define _TMC2208_INIT(ST, SPMM) tmc2208_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, SPMM)
  426. void tmc2208_init_to_defaults() {
  427. #if ENABLED(X_IS_TMC2208)
  428. _TMC2208_INIT(X, planner.axis_steps_per_mm[X_AXIS]);
  429. #endif
  430. #if ENABLED(X2_IS_TMC2208)
  431. _TMC2208_INIT(X2, planner.axis_steps_per_mm[X_AXIS]);
  432. #endif
  433. #if ENABLED(Y_IS_TMC2208)
  434. _TMC2208_INIT(Y, planner.axis_steps_per_mm[Y_AXIS]);
  435. #endif
  436. #if ENABLED(Y2_IS_TMC2208)
  437. _TMC2208_INIT(Y2, planner.axis_steps_per_mm[Y_AXIS]);
  438. #endif
  439. #if ENABLED(Z_IS_TMC2208)
  440. _TMC2208_INIT(Z, planner.axis_steps_per_mm[Z_AXIS]);
  441. #endif
  442. #if ENABLED(Z2_IS_TMC2208)
  443. _TMC2208_INIT(Z2, planner.axis_steps_per_mm[Z_AXIS]);
  444. #endif
  445. #if ENABLED(E0_IS_TMC2208)
  446. _TMC2208_INIT(E0, planner.axis_steps_per_mm[E_AXIS]);
  447. #endif
  448. #if ENABLED(E1_IS_TMC2208)
  449. { constexpr int extruder = 1; _TMC2208_INIT(E1, planner.axis_steps_per_mm[E_AXIS_N]); }
  450. #endif
  451. #if ENABLED(E2_IS_TMC2208)
  452. { constexpr int extruder = 2; _TMC2208_INIT(E2, planner.axis_steps_per_mm[E_AXIS_N]); }
  453. #endif
  454. #if ENABLED(E3_IS_TMC2208)
  455. { constexpr int extruder = 3; _TMC2208_INIT(E3, planner.axis_steps_per_mm[E_AXIS_N]); }
  456. #endif
  457. #if ENABLED(E4_IS_TMC2208)
  458. { constexpr int extruder = 4; _TMC2208_INIT(E4, planner.axis_steps_per_mm[E_AXIS_N]); }
  459. #endif
  460. }
  461. #endif // HAVE_TMC2208
  462. void restore_stepper_drivers() {
  463. #if X_IS_TRINAMIC
  464. stepperX.push();
  465. #endif
  466. #if X2_IS_TRINAMIC
  467. stepperX2.push();
  468. #endif
  469. #if Y_IS_TRINAMIC
  470. stepperY.push();
  471. #endif
  472. #if Y2_IS_TRINAMIC
  473. stepperY2.push();
  474. #endif
  475. #if Z_IS_TRINAMIC
  476. stepperZ.push();
  477. #endif
  478. #if Z2_IS_TRINAMIC
  479. stepperZ2.push();
  480. #endif
  481. #if E0_IS_TRINAMIC
  482. stepperE0.push();
  483. #endif
  484. #if E1_IS_TRINAMIC
  485. stepperE1.push();
  486. #endif
  487. #if E2_IS_TRINAMIC
  488. stepperE2.push();
  489. #endif
  490. #if E3_IS_TRINAMIC
  491. stepperE3.push();
  492. #endif
  493. #if E4_IS_TRINAMIC
  494. stepperE4.push();
  495. #endif
  496. }
  497. void reset_stepper_drivers() {
  498. #if ENABLED(HAVE_TMC26X)
  499. tmc26x_init_to_defaults();
  500. #endif
  501. #if ENABLED(HAVE_TMC2130)
  502. delay(100);
  503. tmc2130_init_to_defaults();
  504. #endif
  505. #if ENABLED(HAVE_TMC2208)
  506. delay(100);
  507. tmc2208_init_to_defaults();
  508. #endif
  509. #ifdef TMC_ADV
  510. TMC_ADV()
  511. #endif
  512. #if ENABLED(HAVE_L6470DRIVER)
  513. L6470_init_to_defaults();
  514. #endif
  515. }
  516. //
  517. // L6470 Driver objects and inits
  518. //
  519. #if ENABLED(HAVE_L6470DRIVER)
  520. #include <SPI.h>
  521. #include <L6470.h>
  522. #define _L6470_DEFINE(ST) L6470 stepper##ST(ST##_ENABLE_PIN)
  523. // L6470 Stepper objects
  524. #if ENABLED(X_IS_L6470)
  525. _L6470_DEFINE(X);
  526. #endif
  527. #if ENABLED(X2_IS_L6470)
  528. _L6470_DEFINE(X2);
  529. #endif
  530. #if ENABLED(Y_IS_L6470)
  531. _L6470_DEFINE(Y);
  532. #endif
  533. #if ENABLED(Y2_IS_L6470)
  534. _L6470_DEFINE(Y2);
  535. #endif
  536. #if ENABLED(Z_IS_L6470)
  537. _L6470_DEFINE(Z);
  538. #endif
  539. #if ENABLED(Z2_IS_L6470)
  540. _L6470_DEFINE(Z2);
  541. #endif
  542. #if ENABLED(E0_IS_L6470)
  543. _L6470_DEFINE(E0);
  544. #endif
  545. #if ENABLED(E1_IS_L6470)
  546. _L6470_DEFINE(E1);
  547. #endif
  548. #if ENABLED(E2_IS_L6470)
  549. _L6470_DEFINE(E2);
  550. #endif
  551. #if ENABLED(E3_IS_L6470)
  552. _L6470_DEFINE(E3);
  553. #endif
  554. #if ENABLED(E4_IS_L6470)
  555. _L6470_DEFINE(E4);
  556. #endif
  557. #define _L6470_INIT(A) do{ \
  558. stepper##A.init(); \
  559. stepper##A.softFree(); \
  560. stepper##A.setMicroSteps(A##_MICROSTEPS); \
  561. stepper##A.setOverCurrent(A##_OVERCURRENT); \
  562. stepper##A.setStallCurrent(A##_STALLCURRENT); \
  563. }while(0)
  564. void L6470_init_to_defaults() {
  565. #if ENABLED(X_IS_L6470)
  566. _L6470_INIT(X);
  567. #endif
  568. #if ENABLED(X2_IS_L6470)
  569. _L6470_INIT(X2);
  570. #endif
  571. #if ENABLED(Y_IS_L6470)
  572. _L6470_INIT(Y);
  573. #endif
  574. #if ENABLED(Y2_IS_L6470)
  575. _L6470_INIT(Y2);
  576. #endif
  577. #if ENABLED(Z_IS_L6470)
  578. _L6470_INIT(Z);
  579. #endif
  580. #if ENABLED(Z2_IS_L6470)
  581. _L6470_INIT(Z2);
  582. #endif
  583. #if ENABLED(E0_IS_L6470)
  584. _L6470_INIT(E0);
  585. #endif
  586. #if ENABLED(E1_IS_L6470)
  587. _L6470_INIT(E1);
  588. #endif
  589. #if ENABLED(E2_IS_L6470)
  590. _L6470_INIT(E2);
  591. #endif
  592. #if ENABLED(E3_IS_L6470)
  593. _L6470_INIT(E3);
  594. #endif
  595. #if ENABLED(E4_IS_L6470)
  596. _L6470_INIT(E4);
  597. #endif
  598. }
  599. #endif // HAVE_L6470DRIVER