My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

stepper_indirection.cpp 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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.c - stepper motor driver indirection
  24. to allow some stepper functions to be done via SPI/I2c instead of direct pin manipulation
  25. Part of Marlin
  26. Copyright (c) 2015 Dominik Wenger
  27. Marlin is free software: you can redistribute it and/or modify
  28. it under the terms of the GNU General Public License as published by
  29. the Free Software Foundation, either version 3 of the License, or
  30. (at your option) any later version.
  31. Marlin is distributed in the hope that it will be useful,
  32. but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34. GNU General Public License for more details.
  35. You should have received a copy of the GNU General Public License
  36. along with Marlin. If not, see <http://www.gnu.org/licenses/>.
  37. */
  38. #include "stepper_indirection.h"
  39. #include "MarlinConfig.h"
  40. //
  41. // TMC26X Driver objects and inits
  42. //
  43. #if ENABLED(HAVE_TMCDRIVER)
  44. #include <SPI.h>
  45. #include <TMC26XStepper.h>
  46. #if ENABLED(X_IS_TMC)
  47. TMC26XStepper stepperX(200, X_ENABLE_PIN, X_STEP_PIN, X_DIR_PIN, X_MAX_CURRENT, X_SENSE_RESISTOR);
  48. #endif
  49. #if ENABLED(X2_IS_TMC)
  50. TMC26XStepper stepperX2(200, X2_ENABLE_PIN, X2_STEP_PIN, X2_DIR_PIN, X2_MAX_CURRENT, X2_SENSE_RESISTOR);
  51. #endif
  52. #if ENABLED(Y_IS_TMC)
  53. TMC26XStepper stepperY(200, Y_ENABLE_PIN, Y_STEP_PIN, Y_DIR_PIN, Y_MAX_CURRENT, Y_SENSE_RESISTOR);
  54. #endif
  55. #if ENABLED(Y2_IS_TMC)
  56. TMC26XStepper stepperY2(200, Y2_ENABLE_PIN, Y2_STEP_PIN, Y2_DIR_PIN, Y2_MAX_CURRENT, Y2_SENSE_RESISTOR);
  57. #endif
  58. #if ENABLED(Z_IS_TMC)
  59. TMC26XStepper stepperZ(200, Z_ENABLE_PIN, Z_STEP_PIN, Z_DIR_PIN, Z_MAX_CURRENT, Z_SENSE_RESISTOR);
  60. #endif
  61. #if ENABLED(Z2_IS_TMC)
  62. TMC26XStepper stepperZ2(200, Z2_ENABLE_PIN, Z2_STEP_PIN, Z2_DIR_PIN, Z2_MAX_CURRENT, Z2_SENSE_RESISTOR);
  63. #endif
  64. #if ENABLED(E0_IS_TMC)
  65. TMC26XStepper stepperE0(200, E0_ENABLE_PIN, E0_STEP_PIN, E0_DIR_PIN, E0_MAX_CURRENT, E0_SENSE_RESISTOR);
  66. #endif
  67. #if ENABLED(E1_IS_TMC)
  68. TMC26XStepper stepperE1(200, E1_ENABLE_PIN, E1_STEP_PIN, E1_DIR_PIN, E1_MAX_CURRENT, E1_SENSE_RESISTOR);
  69. #endif
  70. #if ENABLED(E2_IS_TMC)
  71. TMC26XStepper stepperE2(200, E2_ENABLE_PIN, E2_STEP_PIN, E2_DIR_PIN, E2_MAX_CURRENT, E2_SENSE_RESISTOR);
  72. #endif
  73. #if ENABLED(E3_IS_TMC)
  74. TMC26XStepper stepperE3(200, E3_ENABLE_PIN, E3_STEP_PIN, E3_DIR_PIN, E3_MAX_CURRENT, E3_SENSE_RESISTOR);
  75. #endif
  76. #define _TMC_INIT(A) do{ \
  77. stepper##A.setMicrosteps(A##_MICROSTEPS);
  78. stepper##A.start();
  79. } while(0)
  80. void tmc_init() {
  81. #if ENABLED(X_IS_TMC)
  82. _TMC_INIT(X);
  83. #endif
  84. #if ENABLED(X2_IS_TMC)
  85. _TMC_INIT(X2);
  86. #endif
  87. #if ENABLED(Y_IS_TMC)
  88. _TMC_INIT(Y);
  89. #endif
  90. #if ENABLED(Y2_IS_TMC)
  91. _TMC_INIT(Y2);
  92. #endif
  93. #if ENABLED(Z_IS_TMC)
  94. _TMC_INIT(Z);
  95. #endif
  96. #if ENABLED(Z2_IS_TMC)
  97. _TMC_INIT(Z2);
  98. #endif
  99. #if ENABLED(E0_IS_TMC)
  100. _TMC_INIT(E0);
  101. #endif
  102. #if ENABLED(E1_IS_TMC)
  103. _TMC_INIT(E1);
  104. #endif
  105. #if ENABLED(E2_IS_TMC)
  106. _TMC_INIT(E2);
  107. #endif
  108. #if ENABLED(E3_IS_TMC)
  109. _TMC_INIT(E3);
  110. #endif
  111. }
  112. #endif // HAVE_TMCDRIVER
  113. //
  114. // TMC2130 Driver objects and inits
  115. //
  116. #if ENABLED(HAVE_TMC2130DRIVER)
  117. #include <SPI.h>
  118. #include <Trinamic_TMC2130.h>
  119. #if ENABLED(TMC2130_ADVANCED_CONFIGURATION)
  120. #ifdef GLOBAL_I_SCALE_ANALOG
  121. #define _2130_set_I_scale_analog(A) stepper##A.set_I_scale_analog(GLOBAL_I_SCALE_ANALOG)
  122. #else
  123. #define _2130_set_I_scale_analog(A) NOOP
  124. #endif
  125. #ifdef GLOBAL_INTERNAL_RSENSE
  126. #define _2130_set_internal_Rsense(A) stepper##A.set_internal_Rsense(GLOBAL_INTERNAL_RSENSE)
  127. #else
  128. #define _2130_set_internal_Rsense(A) NOOP
  129. #endif
  130. #ifdef GLOBAL_EN_PWM_MODE
  131. #define _2130_set_en_pwm_mode(A) stepper##A.set_en_pwm_mode(GLOBAL_EN_PWM_MODE)
  132. #else
  133. #define _2130_set_en_pwm_mode(A) NOOP
  134. #endif
  135. #ifdef GLOBAL_ENC_COMMUTATION
  136. #define _2130_set_enc_commutation(A) stepper##A.set_enc_commutation(GLOBAL_ENC_COMMUTATION)
  137. #else
  138. #define _2130_set_enc_commutation(A) NOOP
  139. #endif
  140. #ifdef GLOBAL_SHAFT
  141. #define _2130_set_shaft(A) stepper##A.set_shaft(GLOBAL_SHAFT)
  142. #else
  143. #define _2130_set_shaft(A) NOOP
  144. #endif
  145. #ifdef GLOBAL_DIAG0_ERROR
  146. #define _2130_set_diag0_error(A) stepper##A.set_diag0_error(GLOBAL_DIAG0_ERROR)
  147. #else
  148. #define _2130_set_diag0_error(A) NOOP
  149. #endif
  150. #ifdef GLOBAL_DIAG0_OTPW
  151. #define _2130_set_diag0_otpw(A) stepper##A.set_diag0_otpw(GLOBAL_DIAG0_OTPW)
  152. #else
  153. #define _2130_set_diag0_otpw(A) NOOP
  154. #endif
  155. #ifdef GLOBAL_DIAG0_STALL
  156. #define _2130_set_diag0_stall(A) stepper##A.set_diag0_stall(GLOBAL_DIAG0_STALL)
  157. #else
  158. #define _2130_set_diag0_stall(A) NOOP
  159. #endif
  160. #ifdef GLOBAL_DIAG1_STALL
  161. #define _2130_set_diag1_stall(A) stepper##A.set_diag1_stall(GLOBAL_DIAG1_STALL)
  162. #else
  163. #define _2130_set_diag1_stall(A) NOOP
  164. #endif
  165. #ifdef GLOBAL_DIAG1_INDEX
  166. #define _2130_set_diag1_index(A) stepper##A.set_diag1_index(GLOBAL_DIAG1_INDEX)
  167. #else
  168. #define _2130_set_diag1_index(A) NOOP
  169. #endif
  170. #ifdef GLOBAL_DIAG1_ONSTATE
  171. #define _2130_set_diag1_onstate(A) stepper##A.set_diag1_onstate(GLOBAL_DIAG1_ONSTATE)
  172. #else
  173. #define _2130_set_diag1_onstate(A) NOOP
  174. #endif
  175. #ifdef GLOBAL_DIAG1_ONSTATE
  176. #define _2130_set_diag1_steps_skipped(A) stepper##A.set_diag1_steps_skipped(GLOBAL_DIAG1_ONSTATE)
  177. #else
  178. #define _2130_set_diag1_steps_skipped(A) NOOP
  179. #endif
  180. #ifdef GLOBAL_DIAG0_INT_PUSHPULL
  181. #define _2130_set_diag0_int_pushpull(A) stepper##A.set_diag0_int_pushpull(GLOBAL_DIAG0_INT_PUSHPULL)
  182. #else
  183. #define _2130_set_diag0_int_pushpull(A) NOOP
  184. #endif
  185. #ifdef GLOBAL_DIAG1_INT_PUSHPULL
  186. #define _2130_set_diag1_int_pushpull(A) stepper##A.set_diag1_int_pushpull(GLOBAL_DIAG1_INT_PUSHPULL)
  187. #else
  188. #define _2130_set_diag1_int_pushpull(A) NOOP
  189. #endif
  190. #ifdef GLOBAL_SMALL_HYSTERESIS
  191. #define _2130_set_small_hysteresis(A) stepper##A.set_small_hysteresis(GLOBAL_SMALL_HYSTERESIS)
  192. #else
  193. #define _2130_set_small_hysteresis(A) NOOP
  194. #endif
  195. #ifdef GLOBAL_STOP_ENABLE
  196. #define _2130_set_stop_enable(A) stepper##A.set_stop_enable(GLOBAL_STOP_ENABLE)
  197. #else
  198. #define _2130_set_stop_enable(A) NOOP
  199. #endif
  200. #ifdef GLOBAL_DIRECT_MODE
  201. #define _2130_set_direct_mode(A) stepper##A.set_direct_mode(GLOBAL_DIRECT_MODE)
  202. #else
  203. #define _2130_set_direct_mode(A) NOOP
  204. #endif
  205. #if defined(GLOBAL_IHOLD) && defined(GLOBAL_IRUN) && defined(GLOBAL_IHOLDDELAY)
  206. #define _2130_set_IHOLD_IRUN(A) stepper##A.set_IHOLD_IRUN(GLOBAL_IHOLD, GLOBAL_IRUN, GLOBAL_IHOLDDELAY)
  207. #else
  208. #define _2130_set_IHOLD_IRUN(A) NOOP
  209. #endif
  210. #ifdef GLOBAL_TPOWERDOWN
  211. #define _2130_set_TPOWERDOWN(A) stepper##A.set_TPOWERDOWN(GLOBAL_TPOWERDOWN)
  212. #else
  213. #define _2130_set_TPOWERDOWN(A) NOOP
  214. #endif
  215. #ifdef GLOBAL_TPWMTHRS
  216. #define _2130_set_TPWMTHRS(A) stepper##A.set_TPWMTHRS(GLOBAL_TPWMTHRS)
  217. #else
  218. #define _2130_set_TPWMTHRS(A) NOOP
  219. #endif
  220. #ifdef GLOBAL_TCOOLTHRS
  221. #define _2130_set_TCOOLTHRS(A) stepper##A.set_TCOOLTHRS(GLOBAL_TCOOLTHRS)
  222. #else
  223. #define _2130_set_TCOOLTHRS(A) NOOP
  224. #endif
  225. #ifdef GLOBAL_THIGH
  226. #define _2130_set_THIGH(A) stepper##A.set_THIGH(GLOBAL_THIGH)
  227. #else
  228. #define _2130_set_THIGH(A) NOOP
  229. #endif
  230. #ifdef GLOBAL_XDIRECT
  231. #define _2130_set_XDIRECT(A) stepper##A.set_XDIRECT(GLOBAL_XDIRECT)
  232. #else
  233. #define _2130_set_XDIRECT(A) NOOP
  234. #endif
  235. #ifdef GLOBAL_VDCMIN
  236. #define _2130_set_VDCMIN(A) stepper##A.set_VDCMIN(GLOBAL_VDCMIN)
  237. #else
  238. #define _2130_set_VDCMIN(A) NOOP
  239. #endif
  240. #ifdef GLOBAL_DEDGE
  241. #define _2130_set_dedge(A) stepper##A.set_dedge(GLOBAL_DEDGE)
  242. #else
  243. #define _2130_set_dedge(A) NOOP
  244. #endif
  245. #ifdef GLOBAL_DISS2G
  246. #define _2130_set_diss2g(A) stepper##A.set_diss2g(GLOBAL_DISS2G)
  247. #else
  248. #define _2130_set_diss2g(A) NOOP
  249. #endif
  250. #ifdef GLOBAL_INTPOL
  251. #define _2130_set_intpol(A) stepper##A.set_intpol(GLOBAL_INTPOL)
  252. #else
  253. #define _2130_set_intpol(A) NOOP
  254. #endif
  255. #ifdef GLOBAL_MRES
  256. #define _2130_set_mres(A) stepper##A.set_mres(GLOBAL_MRES)
  257. #else
  258. #define _2130_set_mres(A) NOOP
  259. #endif
  260. #ifdef GLOBAL_SYNC
  261. #define _2130_set_sync(A) stepper##A.set_sync(GLOBAL_SYNC)
  262. #else
  263. #define _2130_set_sync(A) NOOP
  264. #endif
  265. #ifdef GLOBAL_VHIGHCHM
  266. #define _2130_set_vhighchm(A) stepper##A.set_vhighchm(GLOBAL_VHIGHCHM)
  267. #else
  268. #define _2130_set_vhighchm(A) NOOP
  269. #endif
  270. #ifdef GLOBAL_VHIGHFS
  271. #define _2130_set_vhighfs(A) stepper##A.set_vhighfs(GLOBAL_VHIGHFS)
  272. #else
  273. #define _2130_set_vhighfs(A) NOOP
  274. #endif
  275. #ifdef GLOBAL_VSENSE
  276. #define _2130_set_vsense(A) stepper##A.set_vsense(GLOBAL_VSENSE)
  277. #else
  278. #define _2130_set_vsense(A) NOOP
  279. #endif
  280. #ifdef GLOBAL_TBL
  281. #define _2130_set_tbl(A) stepper##A.set_tbl(GLOBAL_TBL)
  282. #else
  283. #define _2130_set_tbl(A) NOOP
  284. #endif
  285. #ifdef GLOBAL_CHM
  286. #define _2130_set_chm(A) stepper##A.set_chm(GLOBAL_CHM)
  287. #else
  288. #define _2130_set_chm(A) NOOP
  289. #endif
  290. #ifdef GLOBAL_RNDTF
  291. #define _2130_set_rndtf(A) stepper##A.set_rndtf(GLOBAL_RNDTF)
  292. #else
  293. #define _2130_set_rndtf(A) NOOP
  294. #endif
  295. #ifdef GLOBAL_DISFDCC
  296. #define _2130_set_disfdcc(A) stepper##A.set_disfdcc(GLOBAL_DISFDCC)
  297. #else
  298. #define _2130_set_disfdcc(A) NOOP
  299. #endif
  300. #ifdef GLOBAL_FD
  301. #define _2130_set_fd(A) stepper##A.set_fd(GLOBAL_FD)
  302. #else
  303. #define _2130_set_fd(A) NOOP
  304. #endif
  305. #ifdef GLOBAL_HEND
  306. #define _2130_set_hend(A) stepper##A.set_hend(GLOBAL_HEND)
  307. #else
  308. #define _2130_set_hend(A) NOOP
  309. #endif
  310. #ifdef GLOBAL_HSTRT
  311. #define _2130_set_hstrt(A) stepper##A.set_hstrt(GLOBAL_HSTRT)
  312. #else
  313. #define _2130_set_hstrt(A) NOOP
  314. #endif
  315. #ifdef GLOBAL_TOFF
  316. #define _2130_set_toff(A) stepper##A.set_toff(GLOBAL_TOFF)
  317. #else
  318. #define _2130_set_toff(A) NOOP
  319. #endif
  320. #ifdef GLOBAL_SFILT
  321. #define _2130_set_sfilt(A) stepper##A.set_sfilt(GLOBAL_SFILT)
  322. #else
  323. #define _2130_set_sfilt(A) NOOP
  324. #endif
  325. #ifdef GLOBAL_SGT
  326. #define _2130_set_sgt(A) stepper##A.set_sgt(GLOBAL_SGT)
  327. #else
  328. #define _2130_set_sgt(A) NOOP
  329. #endif
  330. #ifdef GLOBAL_SEIMIN
  331. #define _2130_set_seimin(A) stepper##A.set_seimin(GLOBAL_SEIMIN)
  332. #else
  333. #define _2130_set_seimin(A) NOOP
  334. #endif
  335. #ifdef GLOBAL_SEDN
  336. #define _2130_set_sedn(A) stepper##A.set_sedn(GLOBAL_SEDN)
  337. #else
  338. #define _2130_set_sedn(A) NOOP
  339. #endif
  340. #ifdef GLOBAL_SEMAX
  341. #define _2130_set_semax(A) stepper##A.set_semax(GLOBAL_SEMAX)
  342. #else
  343. #define _2130_set_semax(A) NOOP
  344. #endif
  345. #ifdef GLOBAL_SEUP
  346. #define _2130_set_seup(A) stepper##A.set_seup(GLOBAL_SEUP)
  347. #else
  348. #define _2130_set_seup(A) NOOP
  349. #endif
  350. #ifdef GLOBAL_SEMIN
  351. #define _2130_set_semin(A) stepper##A.set_semin(GLOBAL_SEMIN)
  352. #else
  353. #define _2130_set_semin(A) NOOP
  354. #endif
  355. #if defined(GLOBAL_DC_TIME) && defined(GLOBAL_DC_SG)
  356. #define _2130_set_DCCTRL(A) stepper##A.set_DCCTRL(GLOBAL_DC_TIME, GLOBAL_DC_SG)
  357. #else
  358. #define _2130_set_DCCTRL(A) NOOP
  359. #endif
  360. #ifdef GLOBAL_FREEWHEEL
  361. #define _2130_set_freewheel(A) stepper##A.set_freewheel(GLOBAL_FREEWHEEL)
  362. #else
  363. #define _2130_set_freewheel(A) NOOP
  364. #endif
  365. #ifdef GLOBAL_PWM_SYMMETRIC
  366. #define _2130_set_pwm_symmetric(A) stepper##A.set_pwm_symmetric(GLOBAL_PWM_SYMMETRIC)
  367. #else
  368. #define _2130_set_pwm_symmetric(A) NOOP
  369. #endif
  370. #ifdef GLOBAL_PWM_AUTOSCALE
  371. #define _2130_set_pwm_autoscale(A) stepper##A.set_pwm_autoscale(GLOBAL_PWM_AUTOSCALE)
  372. #else
  373. #define _2130_set_pwm_autoscale(A) NOOP
  374. #endif
  375. #ifdef GLOBAL_PWM_FREQ
  376. #define _2130_set_pwm_freq(A) stepper##A.set_pwm_freq(GLOBAL_PWM_FREQ)
  377. #else
  378. #define _2130_set_pwm_freq(A) NOOP
  379. #endif
  380. #ifdef GLOBAL_PWM_GRAD
  381. #define _2130_set_PWM_GRAD(A) stepper##A.set_PWM_GRAD(GLOBAL_PWM_GRAD)
  382. #else
  383. #define _2130_set_PWM_GRAD(A) NOOP
  384. #endif
  385. #ifdef GLOBAL_PWM_AMPL
  386. #define _2130_set_PWM_AMPL(A) stepper##A.set_PWM_AMPL(GLOBAL_PWM_AMPL)
  387. #else
  388. #define _2130_set_PWM_AMPL(A) NOOP
  389. #endif
  390. #ifdef GLOBAL_ENCM_CTRL
  391. #define _2130_set_ENCM_CTRL(A) stepper##A.set_ENCM_CTRL(GLOBAL_ENCM_CTRL)
  392. #else
  393. #define _2130_set_ENCM_CTRL(A) NOOP
  394. #endif
  395. #define _TMC2130_INIT(A) do{ \
  396. stepper##A.init(); \
  397. _2130_set_I_scale_analog(A); \
  398. _2130_set_internal_Rsense(A); \
  399. _2130_set_en_pwm_mode(A); \
  400. _2130_set_enc_commutation(A); \
  401. _2130_set_shaft(A); \
  402. _2130_set_diag0_error(A); \
  403. _2130_set_diag0_otpw(A); \
  404. _2130_set_diag0_stall(A); \
  405. _2130_set_diag1_stall(A); \
  406. _2130_set_diag1_index(A); \
  407. _2130_set_diag1_onstate(A); \
  408. _2130_set_diag1_steps_skipped(A); \
  409. _2130_set_diag0_int_pushpull(A); \
  410. _2130_set_diag1_int_pushpull(A); \
  411. _2130_set_small_hysteresis(A); \
  412. _2130_set_stop_enable(A); \
  413. _2130_set_direct_mode(A); \
  414. _2130_set_IHOLD_IRUN(A); \
  415. _2130_set_TPOWERDOWN(A); \
  416. _2130_set_TPWMTHRS(A); \
  417. _2130_set_TCOOLTHRS(A); \
  418. _2130_set_THIGH(A); \
  419. _2130_set_XDIRECT(A); \
  420. _2130_set_VDCMIN(A); \
  421. _2130_set_dedge(A); \
  422. _2130_set_diss2g(A); \
  423. _2130_set_intpol(A); \
  424. _2130_set_mres(A); \
  425. _2130_set_sync(A); \
  426. _2130_set_vhighchm(A); \
  427. _2130_set_vhighfs(A); \
  428. _2130_set_vsense(A); \
  429. _2130_set_tbl(A); \
  430. _2130_set_chm(A); \
  431. _2130_set_rndtf(A); \
  432. _2130_set_disfdcc(A); \
  433. _2130_set_fd(A); \
  434. _2130_set_hend(A); \
  435. _2130_set_hstrt(A); \
  436. _2130_set_toff(A); \
  437. _2130_set_sfilt(A); \
  438. _2130_set_sgt(A); \
  439. _2130_set_seimin(A); \
  440. _2130_set_sedn(A); \
  441. _2130_set_semax(A); \
  442. _2130_set_seup(A); \
  443. _2130_set_semin(A); \
  444. _2130_set_DCCTRL(A); \
  445. _2130_set_freewheel(A); \
  446. _2130_set_pwm_symmetric(A); \
  447. _2130_set_pwm_autoscale(A); \
  448. _2130_set_pwm_freq(A); \
  449. _2130_set_PWM_GRAD(A); \
  450. _2130_set_PWM_AMPL(A); \
  451. _2130_set_ENCM_CTRL(A); \
  452. } while(0)
  453. #else // !TMC2130_ADVANCED_CONFIGURATION
  454. #define _TMC2130_INIT(A) do{ \
  455. stepper##A.init(); \
  456. stepper##A.set_mres(A##_MRES); \
  457. stepper##A.set_IHOLD_IRUN(A##_IHOLD, A##_IRUN, A##_IHOLDDELAY); \
  458. stepper##A.set_I_scale_analog(A##_I_SCALE_ANALOG); \
  459. stepper##A.set_tbl(A##_TBL); \
  460. stepper##A.set_toff(A##_TOFF); \
  461. } while(0)
  462. #endif // TMC2130_ADVANCED_CONFIGURATION
  463. // Stepper objects of TMC2310 steppers used
  464. #if ENABLED(X_IS_TMC2130)
  465. Trinamic_TMC2130 stepperX(X_CS_PIN);
  466. #endif
  467. #if ENABLED(X2_IS_TMC2130)
  468. Trinamic_TMC2130 stepperX2(X2_CS_PIN);
  469. #endif
  470. #if ENABLED(Y_IS_TMC2130)
  471. Trinamic_TMC2130 stepperY(Y_CS_PIN);
  472. #endif
  473. #if ENABLED(Y2_IS_TMC2130)
  474. Trinamic_TMC2130 stepperY2(Y2_CS_PINR);
  475. #endif
  476. #if ENABLED(Z_IS_TMC2130)
  477. Trinamic_TMC2130 stepperZ(Z_CS_PIN);
  478. #endif
  479. #if ENABLED(Z2_IS_TMC2130)
  480. Trinamic_TMC2130 stepperZ2(Z2_CS_PIN);
  481. #endif
  482. #if ENABLED(E0_IS_TMC2130)
  483. Trinamic_TMC2130 stepperE0(E0_CS_PIN);
  484. #endif
  485. #if ENABLED(E1_IS_TMC2130)
  486. Trinamic_TMC2130 stepperE1(E1_CS_PIN);
  487. #endif
  488. #if ENABLED(E2_IS_TMC2130)
  489. Trinamic_TMC2130 stepperE2(E2_CS_PIN);
  490. #endif
  491. #if ENABLED(E3_IS_TMC2130)
  492. Trinamic_TMC2130 stepperE3(E3_CS_PIN);
  493. #endif
  494. void tmc2130_init() {
  495. #if ENABLED(X_IS_TMC2130)
  496. _TMC2130_INIT(X);
  497. #endif
  498. #if ENABLED(X2_IS_TMC2130)
  499. _TMC2130_INIT(X2);
  500. #endif
  501. #if ENABLED(Y_IS_TMC2130)
  502. _TMC2130_INIT(Y);
  503. #endif
  504. #if ENABLED(Y2_IS_TMC2130)
  505. _TMC2130_INIT(Y2);
  506. #endif
  507. #if ENABLED(Z_IS_TMC2130)
  508. _TMC2130_INIT(Z);
  509. #endif
  510. #if ENABLED(Z2_IS_TMC2130)
  511. _TMC2130_INIT(Z2);
  512. #endif
  513. #if ENABLED(E0_IS_TMC2130)
  514. _TMC2130_INIT(E0);
  515. #endif
  516. #if ENABLED(E1_IS_TMC2130)
  517. _TMC2130_INIT(E1);
  518. #endif
  519. #if ENABLED(E2_IS_TMC2130)
  520. _TMC2130_INIT(E2);
  521. #endif
  522. #if ENABLED(E3_IS_TMC2130)
  523. _TMC2130_INIT(E3);
  524. #endif
  525. }
  526. #endif // HAVE_TMC2130DRIVER
  527. //
  528. // L6470 Driver objects and inits
  529. //
  530. #if ENABLED(HAVE_L6470DRIVER)
  531. #include <SPI.h>
  532. #include <L6470.h>
  533. // L6470 Stepper objects
  534. #if ENABLED(X_IS_L6470)
  535. L6470 stepperX(X_ENABLE_PIN);
  536. #endif
  537. #if ENABLED(X2_IS_L6470)
  538. L6470 stepperX2(X2_ENABLE_PIN);
  539. #endif
  540. #if ENABLED(Y_IS_L6470)
  541. L6470 stepperY(Y_ENABLE_PIN);
  542. #endif
  543. #if ENABLED(Y2_IS_L6470)
  544. L6470 stepperY2(Y2_ENABLE_PIN);
  545. #endif
  546. #if ENABLED(Z_IS_L6470)
  547. L6470 stepperZ(Z_ENABLE_PIN);
  548. #endif
  549. #if ENABLED(Z2_IS_L6470)
  550. L6470 stepperZ2(Z2_ENABLE_PIN);
  551. #endif
  552. #if ENABLED(E0_IS_L6470)
  553. L6470 stepperE0(E0_ENABLE_PIN);
  554. #endif
  555. #if ENABLED(E1_IS_L6470)
  556. L6470 stepperE1(E1_ENABLE_PIN);
  557. #endif
  558. #if ENABLED(E2_IS_L6470)
  559. L6470 stepperE2(E2_ENABLE_PIN);
  560. #endif
  561. #if ENABLED(E3_IS_L6470)
  562. L6470 stepperE3(E3_ENABLE_PIN);
  563. #endif
  564. #define _L6470_INIT(A) do{ \
  565. stepper##A.init(A##_K_VAL); \
  566. stepper##A.softFree(); \
  567. stepper##A.setMicroSteps(A##_MICROSTEPS); \
  568. stepper##A.setOverCurrent(A##_OVERCURRENT); \
  569. stepper##A.setStallCurrent(A##_STALLCURRENT); \
  570. } while(0)
  571. void L6470_init() {
  572. #if ENABLED(X_IS_L6470)
  573. _L6470_INIT(X);
  574. #endif
  575. #if ENABLED(X2_IS_L6470)
  576. _L6470_INIT(X2);
  577. #endif
  578. #if ENABLED(Y_IS_L6470)
  579. _L6470_INIT(Y);
  580. #endif
  581. #if ENABLED(Y2_IS_L6470)
  582. _L6470_INIT(Y2);
  583. #endif
  584. #if ENABLED(Z_IS_L6470)
  585. _L6470_INIT(Z);
  586. #endif
  587. #if ENABLED(Z2_IS_L6470)
  588. _L6470_INIT(Z2);
  589. #endif
  590. #if ENABLED(E0_IS_L6470)
  591. _L6470_INIT(E0);
  592. #endif
  593. #if ENABLED(E1_IS_L6470)
  594. _L6470_INIT(E1);
  595. #endif
  596. #if ENABLED(E2_IS_L6470)
  597. _L6470_INIT(E2);
  598. #endif
  599. #if ENABLED(E3_IS_L6470)
  600. _L6470_INIT(E3);
  601. #endif
  602. }
  603. #endif // HAVE_L6470DRIVER