My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

stepper_indirection.h 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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.h - stepper motor driver indirection macros
  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. #ifndef STEPPER_INDIRECTION_H
  39. #define STEPPER_INDIRECTION_H
  40. #include "MarlinConfig.h"
  41. // TMC26X drivers have STEP/DIR on normal pins, but ENABLE via SPI
  42. #if ENABLED(HAVE_TMCDRIVER)
  43. #include <SPI.h>
  44. #include <TMC26XStepper.h>
  45. void tmc_init();
  46. #endif
  47. #if ENABLED(HAVE_TMC2130)
  48. #include <TMC2130Stepper.h>
  49. void tmc2130_init();
  50. #endif
  51. // L6470 has STEP on normal pins, but DIR/ENABLE via SPI
  52. #if ENABLED(HAVE_L6470DRIVER)
  53. #include <SPI.h>
  54. #include <L6470.h>
  55. void L6470_init();
  56. #endif
  57. // X Stepper
  58. #if ENABLED(HAVE_L6470DRIVER) && ENABLED(X_IS_L6470)
  59. extern L6470 stepperX;
  60. #define X_ENABLE_INIT NOOP
  61. #define X_ENABLE_WRITE(STATE) do{if(STATE) stepperX.Step_Clock(stepperX.getStatus() & STATUS_HIZ); else stepperX.softFree();}while(0)
  62. #define X_ENABLE_READ (stepperX.getStatus() & STATUS_HIZ)
  63. #define X_DIR_INIT NOOP
  64. #define X_DIR_WRITE(STATE) stepperX.Step_Clock(STATE)
  65. #define X_DIR_READ (stepperX.getStatus() & STATUS_DIR)
  66. #else
  67. #if ENABLED(HAVE_TMCDRIVER) && ENABLED(X_IS_TMC)
  68. extern TMC26XStepper stepperX;
  69. #define X_ENABLE_INIT NOOP
  70. #define X_ENABLE_WRITE(STATE) stepperX.setEnabled(STATE)
  71. #define X_ENABLE_READ stepperX.isEnabled()
  72. #else
  73. #if ENABLED(HAVE_TMC2130) && ENABLED(X_IS_TMC2130)
  74. extern TMC2130Stepper stepperX;
  75. #endif
  76. #define X_ENABLE_INIT SET_OUTPUT(X_ENABLE_PIN)
  77. #define X_ENABLE_WRITE(STATE) WRITE(X_ENABLE_PIN,STATE)
  78. #define X_ENABLE_READ READ(X_ENABLE_PIN)
  79. #endif
  80. #define X_DIR_INIT SET_OUTPUT(X_DIR_PIN)
  81. #define X_DIR_WRITE(STATE) WRITE(X_DIR_PIN,STATE)
  82. #define X_DIR_READ READ(X_DIR_PIN)
  83. #endif
  84. #define X_STEP_INIT SET_OUTPUT(X_STEP_PIN)
  85. #define X_STEP_WRITE(STATE) WRITE(X_STEP_PIN,STATE)
  86. #define X_STEP_READ READ(X_STEP_PIN)
  87. // Y Stepper
  88. #if ENABLED(HAVE_L6470DRIVER) && ENABLED(Y_IS_L6470)
  89. extern L6470 stepperY;
  90. #define Y_ENABLE_INIT NOOP
  91. #define Y_ENABLE_WRITE(STATE) do{if(STATE) stepperY.Step_Clock(stepperY.getStatus() & STATUS_HIZ); else stepperY.softFree();}while(0)
  92. #define Y_ENABLE_READ (stepperY.getStatus() & STATUS_HIZ)
  93. #define Y_DIR_INIT NOOP
  94. #define Y_DIR_WRITE(STATE) stepperY.Step_Clock(STATE)
  95. #define Y_DIR_READ (stepperY.getStatus() & STATUS_DIR)
  96. #else
  97. #if ENABLED(HAVE_TMCDRIVER) && ENABLED(Y_IS_TMC)
  98. extern TMC26XStepper stepperY;
  99. #define Y_ENABLE_INIT NOOP
  100. #define Y_ENABLE_WRITE(STATE) stepperY.setEnabled(STATE)
  101. #define Y_ENABLE_READ stepperY.isEnabled()
  102. #else
  103. #if ENABLED(HAVE_TMC2130) && ENABLED(Y_IS_TMC2130)
  104. extern TMC2130Stepper stepperY;
  105. #endif
  106. #define Y_ENABLE_INIT SET_OUTPUT(Y_ENABLE_PIN)
  107. #define Y_ENABLE_WRITE(STATE) WRITE(Y_ENABLE_PIN,STATE)
  108. #define Y_ENABLE_READ READ(Y_ENABLE_PIN)
  109. #endif
  110. #define Y_DIR_INIT SET_OUTPUT(Y_DIR_PIN)
  111. #define Y_DIR_WRITE(STATE) WRITE(Y_DIR_PIN,STATE)
  112. #define Y_DIR_READ READ(Y_DIR_PIN)
  113. #endif
  114. #define Y_STEP_INIT SET_OUTPUT(Y_STEP_PIN)
  115. #define Y_STEP_WRITE(STATE) WRITE(Y_STEP_PIN,STATE)
  116. #define Y_STEP_READ READ(Y_STEP_PIN)
  117. // Z Stepper
  118. #if ENABLED(HAVE_L6470DRIVER) && ENABLED(Z_IS_L6470)
  119. extern L6470 stepperZ;
  120. #define Z_ENABLE_INIT NOOP
  121. #define Z_ENABLE_WRITE(STATE) do{if(STATE) stepperZ.Step_Clock(stepperZ.getStatus() & STATUS_HIZ); else stepperZ.softFree();}while(0)
  122. #define Z_ENABLE_READ (stepperZ.getStatus() & STATUS_HIZ)
  123. #define Z_DIR_INIT NOOP
  124. #define Z_DIR_WRITE(STATE) stepperZ.Step_Clock(STATE)
  125. #define Z_DIR_READ (stepperZ.getStatus() & STATUS_DIR)
  126. #else
  127. #if ENABLED(HAVE_TMCDRIVER) && ENABLED(Z_IS_TMC)
  128. extern TMC26XStepper stepperZ;
  129. #define Z_ENABLE_INIT NOOP
  130. #define Z_ENABLE_WRITE(STATE) stepperZ.setEnabled(STATE)
  131. #define Z_ENABLE_READ stepperZ.isEnabled()
  132. #else
  133. #if ENABLED(HAVE_TMC2130) && ENABLED(Z_IS_TMC2130)
  134. extern TMC2130Stepper stepperZ;
  135. #endif
  136. #define Z_ENABLE_INIT SET_OUTPUT(Z_ENABLE_PIN)
  137. #define Z_ENABLE_WRITE(STATE) WRITE(Z_ENABLE_PIN,STATE)
  138. #define Z_ENABLE_READ READ(Z_ENABLE_PIN)
  139. #endif
  140. #define Z_DIR_INIT SET_OUTPUT(Z_DIR_PIN)
  141. #define Z_DIR_WRITE(STATE) WRITE(Z_DIR_PIN,STATE)
  142. #define Z_DIR_READ READ(Z_DIR_PIN)
  143. #endif
  144. #define Z_STEP_INIT SET_OUTPUT(Z_STEP_PIN)
  145. #define Z_STEP_WRITE(STATE) WRITE(Z_STEP_PIN,STATE)
  146. #define Z_STEP_READ READ(Z_STEP_PIN)
  147. // X2 Stepper
  148. #if HAS_X2_ENABLE
  149. #if ENABLED(HAVE_L6470DRIVER) && ENABLED(X2_IS_L6470)
  150. extern L6470 stepperX2;
  151. #define X2_ENABLE_INIT NOOP
  152. #define X2_ENABLE_WRITE(STATE) do{if(STATE) stepperX2.Step_Clock(stepperX2.getStatus() & STATUS_HIZ); else stepperX2.softFree();}while(0)
  153. #define X2_ENABLE_READ (stepperX2.getStatus() & STATUS_HIZ)
  154. #define X2_DIR_INIT NOOP
  155. #define X2_DIR_WRITE(STATE) stepperX2.Step_Clock(STATE)
  156. #define X2_DIR_READ (stepperX2.getStatus() & STATUS_DIR)
  157. #else
  158. #if ENABLED(HAVE_TMCDRIVER) && ENABLED(X2_IS_TMC)
  159. extern TMC26XStepper stepperX2;
  160. #define X2_ENABLE_INIT NOOP
  161. #define X2_ENABLE_WRITE(STATE) stepperX2.setEnabled(STATE)
  162. #define X2_ENABLE_READ stepperX2.isEnabled()
  163. #else
  164. #if ENABLED(HAVE_TMC2130) && ENABLED(X2_IS_TMC2130)
  165. extern TMC2130Stepper stepperX2;
  166. #endif
  167. #define X2_ENABLE_INIT SET_OUTPUT(X2_ENABLE_PIN)
  168. #define X2_ENABLE_WRITE(STATE) WRITE(X2_ENABLE_PIN,STATE)
  169. #define X2_ENABLE_READ READ(X2_ENABLE_PIN)
  170. #endif
  171. #define X2_DIR_INIT SET_OUTPUT(X2_DIR_PIN)
  172. #define X2_DIR_WRITE(STATE) WRITE(X2_DIR_PIN,STATE)
  173. #define X2_DIR_READ READ(X2_DIR_PIN)
  174. #endif
  175. #define X2_STEP_INIT SET_OUTPUT(X2_STEP_PIN)
  176. #define X2_STEP_WRITE(STATE) WRITE(X2_STEP_PIN,STATE)
  177. #define X2_STEP_READ READ(X2_STEP_PIN)
  178. #endif
  179. // Y2 Stepper
  180. #if HAS_Y2_ENABLE
  181. #if ENABLED(HAVE_L6470DRIVER) && ENABLED(Y2_IS_L6470)
  182. extern L6470 stepperY2;
  183. #define Y2_ENABLE_INIT NOOP
  184. #define Y2_ENABLE_WRITE(STATE) do{if(STATE) stepperY2.Step_Clock(stepperY2.getStatus() & STATUS_HIZ); else stepperY2.softFree();}while(0)
  185. #define Y2_ENABLE_READ (stepperY2.getStatus() & STATUS_HIZ)
  186. #define Y2_DIR_INIT NOOP
  187. #define Y2_DIR_WRITE(STATE) stepperY2.Step_Clock(STATE)
  188. #define Y2_DIR_READ (stepperY2.getStatus() & STATUS_DIR)
  189. #else
  190. #if ENABLED(HAVE_TMCDRIVER) && ENABLED(Y2_IS_TMC)
  191. extern TMC26XStepper stepperY2;
  192. #define Y2_ENABLE_INIT NOOP
  193. #define Y2_ENABLE_WRITE(STATE) stepperY2.setEnabled(STATE)
  194. #define Y2_ENABLE_READ stepperY2.isEnabled()
  195. #else
  196. #if ENABLED(HAVE_TMC2130) && ENABLED(Y2_IS_TMC2130)
  197. extern TMC2130Stepper stepperY2;
  198. #endif
  199. #define Y2_ENABLE_INIT SET_OUTPUT(Y2_ENABLE_PIN)
  200. #define Y2_ENABLE_WRITE(STATE) WRITE(Y2_ENABLE_PIN,STATE)
  201. #define Y2_ENABLE_READ READ(Y2_ENABLE_PIN)
  202. #endif
  203. #define Y2_DIR_INIT SET_OUTPUT(Y2_DIR_PIN)
  204. #define Y2_DIR_WRITE(STATE) WRITE(Y2_DIR_PIN,STATE)
  205. #define Y2_DIR_READ READ(Y2_DIR_PIN)
  206. #endif
  207. #define Y2_STEP_INIT SET_OUTPUT(Y2_STEP_PIN)
  208. #define Y2_STEP_WRITE(STATE) WRITE(Y2_STEP_PIN,STATE)
  209. #define Y2_STEP_READ READ(Y2_STEP_PIN)
  210. #endif
  211. // Z2 Stepper
  212. #if HAS_Z2_ENABLE
  213. #if ENABLED(HAVE_L6470DRIVER) && ENABLED(Z2_IS_L6470)
  214. extern L6470 stepperZ2;
  215. #define Z2_ENABLE_INIT NOOP
  216. #define Z2_ENABLE_WRITE(STATE) do{if(STATE) stepperZ2.Step_Clock(stepperZ2.getStatus() & STATUS_HIZ); else stepperZ2.softFree();}while(0)
  217. #define Z2_ENABLE_READ (stepperZ2.getStatus() & STATUS_HIZ)
  218. #define Z2_DIR_INIT NOOP
  219. #define Z2_DIR_WRITE(STATE) stepperZ2.Step_Clock(STATE)
  220. #define Z2_DIR_READ (stepperZ2.getStatus() & STATUS_DIR)
  221. #else
  222. #if ENABLED(HAVE_TMCDRIVER) && ENABLED(Z2_IS_TMC)
  223. extern TMC26XStepper stepperZ2;
  224. #define Z2_ENABLE_INIT NOOP
  225. #define Z2_ENABLE_WRITE(STATE) stepperZ2.setEnabled(STATE)
  226. #define Z2_ENABLE_READ stepperZ2.isEnabled()
  227. #else
  228. #if ENABLED(HAVE_TMC2130) && ENABLED(Z2_IS_TMC2130)
  229. extern TMC2130Stepper stepperZ2;
  230. #endif
  231. #define Z2_ENABLE_INIT SET_OUTPUT(Z2_ENABLE_PIN)
  232. #define Z2_ENABLE_WRITE(STATE) WRITE(Z2_ENABLE_PIN,STATE)
  233. #define Z2_ENABLE_READ READ(Z2_ENABLE_PIN)
  234. #endif
  235. #define Z2_DIR_INIT SET_OUTPUT(Z2_DIR_PIN)
  236. #define Z2_DIR_WRITE(STATE) WRITE(Z2_DIR_PIN,STATE)
  237. #define Z2_DIR_READ READ(Z2_DIR_PIN)
  238. #endif
  239. #define Z2_STEP_INIT SET_OUTPUT(Z2_STEP_PIN)
  240. #define Z2_STEP_WRITE(STATE) WRITE(Z2_STEP_PIN,STATE)
  241. #define Z2_STEP_READ READ(Z2_STEP_PIN)
  242. #endif
  243. // E0 Stepper
  244. #if ENABLED(HAVE_L6470DRIVER) && ENABLED(E0_IS_L6470)
  245. extern L6470 stepperE0;
  246. #define E0_ENABLE_INIT NOOP
  247. #define E0_ENABLE_WRITE(STATE) do{if(STATE) stepperE0.Step_Clock(stepperE0.getStatus() & STATUS_HIZ); else stepperE0.softFree();}while(0)
  248. #define E0_ENABLE_READ (stepperE0.getStatus() & STATUS_HIZ)
  249. #define E0_DIR_INIT NOOP
  250. #define E0_DIR_WRITE(STATE) stepperE0.Step_Clock(STATE)
  251. #define E0_DIR_READ (stepperE0.getStatus() & STATUS_DIR)
  252. #else
  253. #if ENABLED(HAVE_TMCDRIVER) && ENABLED(E0_IS_TMC)
  254. extern TMC26XStepper stepperE0;
  255. #define E0_ENABLE_INIT NOOP
  256. #define E0_ENABLE_WRITE(STATE) stepperE0.setEnabled(STATE)
  257. #define E0_ENABLE_READ stepperE0.isEnabled()
  258. #else
  259. #if ENABLED(HAVE_TMC2130) && ENABLED(E0_IS_TMC2130)
  260. extern TMC2130Stepper stepperE0;
  261. #endif
  262. #define E0_ENABLE_INIT SET_OUTPUT(E0_ENABLE_PIN)
  263. #define E0_ENABLE_WRITE(STATE) WRITE(E0_ENABLE_PIN,STATE)
  264. #define E0_ENABLE_READ READ(E0_ENABLE_PIN)
  265. #endif
  266. #define E0_DIR_INIT SET_OUTPUT(E0_DIR_PIN)
  267. #define E0_DIR_WRITE(STATE) WRITE(E0_DIR_PIN,STATE)
  268. #define E0_DIR_READ READ(E0_DIR_PIN)
  269. #endif
  270. #define E0_STEP_INIT SET_OUTPUT(E0_STEP_PIN)
  271. #define E0_STEP_WRITE(STATE) WRITE(E0_STEP_PIN,STATE)
  272. #define E0_STEP_READ READ(E0_STEP_PIN)
  273. // E1 Stepper
  274. #if ENABLED(HAVE_L6470DRIVER) && ENABLED(E1_IS_L6470)
  275. extern L6470 stepperE1;
  276. #define E1_ENABLE_INIT NOOP
  277. #define E1_ENABLE_WRITE(STATE) do{if(STATE) stepperE1.Step_Clock(stepperE1.getStatus() & STATUS_HIZ); else stepperE1.softFree();}while(0)
  278. #define E1_ENABLE_READ (stepperE1.getStatus() & STATUS_HIZ)
  279. #define E1_DIR_INIT NOOP
  280. #define E1_DIR_WRITE(STATE) stepperE1.Step_Clock(STATE)
  281. #define E1_DIR_READ (stepperE1.getStatus() & STATUS_DIR)
  282. #else
  283. #if ENABLED(HAVE_TMCDRIVER) && ENABLED(E1_IS_TMC)
  284. extern TMC26XStepper stepperE1;
  285. #define E1_ENABLE_INIT NOOP
  286. #define E1_ENABLE_WRITE(STATE) stepperE1.setEnabled(STATE)
  287. #define E1_ENABLE_READ stepperE1.isEnabled()
  288. #else
  289. #if ENABLED(HAVE_TMC2130) && ENABLED(E1_IS_TMC2130)
  290. extern TMC2130Stepper stepperE1;
  291. #endif
  292. #define E1_ENABLE_INIT SET_OUTPUT(E1_ENABLE_PIN)
  293. #define E1_ENABLE_WRITE(STATE) WRITE(E1_ENABLE_PIN,STATE)
  294. #define E1_ENABLE_READ READ(E1_ENABLE_PIN)
  295. #endif
  296. #define E1_DIR_INIT SET_OUTPUT(E1_DIR_PIN)
  297. #define E1_DIR_WRITE(STATE) WRITE(E1_DIR_PIN,STATE)
  298. #define E1_DIR_READ READ(E1_DIR_PIN)
  299. #endif
  300. #define E1_STEP_INIT SET_OUTPUT(E1_STEP_PIN)
  301. #define E1_STEP_WRITE(STATE) WRITE(E1_STEP_PIN,STATE)
  302. #define E1_STEP_READ READ(E1_STEP_PIN)
  303. // E2 Stepper
  304. #if ENABLED(HAVE_L6470DRIVER) && ENABLED(E2_IS_L6470)
  305. extern L6470 stepperE2;
  306. #define E2_ENABLE_INIT NOOP
  307. #define E2_ENABLE_WRITE(STATE) do{if(STATE) stepperE2.Step_Clock(stepperE2.getStatus() & STATUS_HIZ); else stepperE2.softFree();}while(0)
  308. #define E2_ENABLE_READ (stepperE2.getStatus() & STATUS_HIZ)
  309. #define E2_DIR_INIT NOOP
  310. #define E2_DIR_WRITE(STATE) stepperE2.Step_Clock(STATE)
  311. #define E2_DIR_READ (stepperE2.getStatus() & STATUS_DIR)
  312. #else
  313. #if ENABLED(HAVE_TMCDRIVER) && ENABLED(E2_IS_TMC)
  314. extern TMC26XStepper stepperE2;
  315. #define E2_ENABLE_INIT NOOP
  316. #define E2_ENABLE_WRITE(STATE) stepperE2.setEnabled(STATE)
  317. #define E2_ENABLE_READ stepperE2.isEnabled()
  318. #else
  319. #if ENABLED(HAVE_TMC2130) && ENABLED(E2_IS_TMC2130)
  320. extern TMC2130Stepper stepperE2;
  321. #endif
  322. #define E2_ENABLE_INIT SET_OUTPUT(E2_ENABLE_PIN)
  323. #define E2_ENABLE_WRITE(STATE) WRITE(E2_ENABLE_PIN,STATE)
  324. #define E2_ENABLE_READ READ(E2_ENABLE_PIN)
  325. #endif
  326. #define E2_DIR_INIT SET_OUTPUT(E2_DIR_PIN)
  327. #define E2_DIR_WRITE(STATE) WRITE(E2_DIR_PIN,STATE)
  328. #define E2_DIR_READ READ(E2_DIR_PIN)
  329. #endif
  330. #define E2_STEP_INIT SET_OUTPUT(E2_STEP_PIN)
  331. #define E2_STEP_WRITE(STATE) WRITE(E2_STEP_PIN,STATE)
  332. #define E2_STEP_READ READ(E2_STEP_PIN)
  333. // E3 Stepper
  334. #if ENABLED(HAVE_L6470DRIVER) && ENABLED(E3_IS_L6470)
  335. extern L6470 stepperE3;
  336. #define E3_ENABLE_INIT NOOP
  337. #define E3_ENABLE_WRITE(STATE) do{if(STATE) stepperE3.Step_Clock(stepperE3.getStatus() & STATUS_HIZ); else stepperE3.softFree();}while(0)
  338. #define E3_ENABLE_READ (stepperE3.getStatus() & STATUS_HIZ)
  339. #define E3_DIR_INIT NOOP
  340. #define E3_DIR_WRITE(STATE) stepperE3.Step_Clock(STATE)
  341. #define E3_DIR_READ (stepperE3.getStatus() & STATUS_DIR)
  342. #else
  343. #if ENABLED(HAVE_TMCDRIVER) && ENABLED(E3_IS_TMC)
  344. extern TMC26XStepper stepperE3;
  345. #define E3_ENABLE_INIT NOOP
  346. #define E3_ENABLE_WRITE(STATE) stepperE3.setEnabled(STATE)
  347. #define E3_ENABLE_READ stepperE3.isEnabled()
  348. #else
  349. #if ENABLED(HAVE_TMC2130) && ENABLED(E3_IS_TMC2130)
  350. extern TMC2130Stepper stepperE3;
  351. #endif
  352. #define E3_ENABLE_INIT SET_OUTPUT(E3_ENABLE_PIN)
  353. #define E3_ENABLE_WRITE(STATE) WRITE(E3_ENABLE_PIN,STATE)
  354. #define E3_ENABLE_READ READ(E3_ENABLE_PIN)
  355. #endif
  356. #define E3_DIR_INIT SET_OUTPUT(E3_DIR_PIN)
  357. #define E3_DIR_WRITE(STATE) WRITE(E3_DIR_PIN,STATE)
  358. #define E3_DIR_READ READ(E3_DIR_PIN)
  359. #endif
  360. #define E3_STEP_INIT SET_OUTPUT(E3_STEP_PIN)
  361. #define E3_STEP_WRITE(STATE) WRITE(E3_STEP_PIN,STATE)
  362. #define E3_STEP_READ READ(E3_STEP_PIN)
  363. // E4 Stepper
  364. #if ENABLED(HAVE_L6470DRIVER) && ENABLED(E4_IS_L6470)
  365. extern L6470 stepperE4;
  366. #define E4_ENABLE_INIT NOOP
  367. #define E4_ENABLE_WRITE(STATE) do{ if (STATE) stepperE4.Step_Clock(stepperE4.getStatus() & STATUS_HIZ); else stepperE4.softFree(); }while(0)
  368. #define E4_ENABLE_READ (stepperE4.getStatus() & STATUS_HIZ)
  369. #define E4_DIR_INIT NOOP
  370. #define E4_DIR_WRITE(STATE) stepperE4.Step_Clock(STATE)
  371. #define E4_DIR_READ (stepperE4.getStatus() & STATUS_DIR)
  372. #else
  373. #if ENABLED(HAVE_TMCDRIVER) && ENABLED(E4_IS_TMC)
  374. extern TMC26XStepper stepperE4;
  375. #define E4_ENABLE_INIT NOOP
  376. #define E4_ENABLE_WRITE(STATE) stepperE4.setEnabled(STATE)
  377. #define E4_ENABLE_READ stepperE4.isEnabled()
  378. #else
  379. #if ENABLED(HAVE_TMC2130) && ENABLED(E4_IS_TMC2130)
  380. extern TMC2130Stepper stepperE4;
  381. #endif
  382. #define E4_ENABLE_INIT SET_OUTPUT(E4_ENABLE_PIN)
  383. #define E4_ENABLE_WRITE(STATE) WRITE(E4_ENABLE_PIN,STATE)
  384. #define E4_ENABLE_READ READ(E4_ENABLE_PIN)
  385. #endif
  386. #define E4_DIR_INIT SET_OUTPUT(E4_DIR_PIN)
  387. #define E4_DIR_WRITE(STATE) WRITE(E4_DIR_PIN,STATE)
  388. #define E4_DIR_READ READ(E4_DIR_PIN)
  389. #endif
  390. #define E4_STEP_INIT SET_OUTPUT(E4_STEP_PIN)
  391. #define E4_STEP_WRITE(STATE) WRITE(E4_STEP_PIN,STATE)
  392. #define E4_STEP_READ READ(E4_STEP_PIN)
  393. /**
  394. * Extruder indirection for the single E axis
  395. */
  396. #if ENABLED(SWITCHING_EXTRUDER)
  397. #if EXTRUDERS == 2
  398. #define E_STEP_WRITE(v) E0_STEP_WRITE(v)
  399. #define NORM_E_DIR() E0_DIR_WRITE(current_block->active_extruder ? INVERT_E0_DIR : !INVERT_E0_DIR)
  400. #define REV_E_DIR() E0_DIR_WRITE(current_block->active_extruder ? !INVERT_E0_DIR : INVERT_E0_DIR)
  401. #elif EXTRUDERS > 4
  402. #define E_STEP_WRITE(v) { if (current_block->active_extruder < 2) E0_STEP_WRITE(v); else if (current_block->active_extruder < 4) E1_STEP_WRITE(v); else E2_STEP_WRITE(v); }
  403. #define NORM_E_DIR() { switch (current_block->active_extruder) { 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); } }
  404. #define REV_E_DIR() { switch (current_block->active_extruder) { 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); } }
  405. #elif EXTRUDERS > 2
  406. #define E_STEP_WRITE(v) { if (current_block->active_extruder < 2) E0_STEP_WRITE(v); else if (current_block->active_extruder < 4) E1_STEP_WRITE(v); else E1_STEP_WRITE(v); }
  407. #define NORM_E_DIR() { switch (current_block->active_extruder) { 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); } }
  408. #define REV_E_DIR() { switch (current_block->active_extruder) { 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); } }
  409. #endif
  410. #elif ENABLED(MK2_MULTIPLEXER) // Even-numbered steppers are reversed
  411. #define E_STEP_WRITE(v) E0_STEP_WRITE(v)
  412. #define NORM_E_DIR() E0_DIR_WRITE(TEST(current_block->active_extruder, 0) ? !INVERT_E0_DIR: INVERT_E0_DIR)
  413. #define REV_E_DIR() E0_DIR_WRITE(TEST(current_block->active_extruder, 0) ? INVERT_E0_DIR: !INVERT_E0_DIR)
  414. #elif EXTRUDERS > 4
  415. #define E_STEP_WRITE(v) { switch (current_block->active_extruder) { 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); } }
  416. #define NORM_E_DIR() { switch (current_block->active_extruder) { 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); } }
  417. #define REV_E_DIR() { switch (current_block->active_extruder) { 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); } }
  418. #elif EXTRUDERS > 3
  419. #define E_STEP_WRITE(v) { switch (current_block->active_extruder) { 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); } }
  420. #define NORM_E_DIR() { switch (current_block->active_extruder) { 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); } }
  421. #define REV_E_DIR() { switch (current_block->active_extruder) { 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); } }
  422. #elif EXTRUDERS > 2
  423. #define E_STEP_WRITE(v) { switch (current_block->active_extruder) { case 0: E0_STEP_WRITE(v); break; case 1: E1_STEP_WRITE(v); break; case 2: E2_STEP_WRITE(v); } }
  424. #define NORM_E_DIR() { switch (current_block->active_extruder) { 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); } }
  425. #define REV_E_DIR() { switch (current_block->active_extruder) { 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); } }
  426. #elif EXTRUDERS > 1
  427. #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
  428. #define E_STEP_WRITE(v) { if (extruder_duplication_enabled) { E0_STEP_WRITE(v); E1_STEP_WRITE(v); } else if (current_block->active_extruder == 0) { E0_STEP_WRITE(v); } else { E1_STEP_WRITE(v); } }
  429. #define NORM_E_DIR() { if (extruder_duplication_enabled) { E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); } else if (current_block->active_extruder == 0) { E0_DIR_WRITE(!INVERT_E0_DIR); } else { E1_DIR_WRITE(!INVERT_E1_DIR); } }
  430. #define REV_E_DIR() { if (extruder_duplication_enabled) { E0_DIR_WRITE(INVERT_E0_DIR); E1_DIR_WRITE(INVERT_E1_DIR); } else if (current_block->active_extruder == 0) { E0_DIR_WRITE(INVERT_E0_DIR); } else { E1_DIR_WRITE(INVERT_E1_DIR); } }
  431. #else
  432. #define E_STEP_WRITE(v) { if (current_block->active_extruder == 0) { E0_STEP_WRITE(v); } else { E1_STEP_WRITE(v); } }
  433. #define NORM_E_DIR() { if (current_block->active_extruder == 0) { E0_DIR_WRITE(!INVERT_E0_DIR); } else { E1_DIR_WRITE(!INVERT_E1_DIR); } }
  434. #define REV_E_DIR() { if (current_block->active_extruder == 0) { E0_DIR_WRITE(INVERT_E0_DIR); } else { E1_DIR_WRITE(INVERT_E1_DIR); } }
  435. #endif
  436. #elif ENABLED(MIXING_EXTRUDER)
  437. #define E_STEP_WRITE(v) NOOP /* not used for mixing extruders! */
  438. #if MIXING_STEPPERS > 4
  439. #define En_STEP_WRITE(n,v) { switch (n) { 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); } }
  440. #define NORM_E_DIR() { E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); E2_DIR_WRITE(!INVERT_E2_DIR); E3_DIR_WRITE(!INVERT_E3_DIR); E4_DIR_WRITE(!INVERT_E4_DIR); }
  441. #define REV_E_DIR() { E0_DIR_WRITE( INVERT_E0_DIR); E1_DIR_WRITE( INVERT_E1_DIR); E2_DIR_WRITE( INVERT_E2_DIR); E3_DIR_WRITE( INVERT_E3_DIR); E4_DIR_WRITE( INVERT_E4_DIR); }
  442. #elif MIXING_STEPPERS > 3
  443. #define En_STEP_WRITE(n,v) { switch (n) { 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); } }
  444. #define NORM_E_DIR() { E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); E2_DIR_WRITE(!INVERT_E2_DIR); E3_DIR_WRITE(!INVERT_E3_DIR); }
  445. #define REV_E_DIR() { E0_DIR_WRITE( INVERT_E0_DIR); E1_DIR_WRITE( INVERT_E1_DIR); E2_DIR_WRITE( INVERT_E2_DIR); E3_DIR_WRITE( INVERT_E3_DIR); }
  446. #elif MIXING_STEPPERS > 2
  447. #define En_STEP_WRITE(n,v) { switch (n) { case 0: E0_STEP_WRITE(v); break; case 1: E1_STEP_WRITE(v); break; case 2: E2_STEP_WRITE(v); } }
  448. #define NORM_E_DIR() { E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); E2_DIR_WRITE(!INVERT_E2_DIR); }
  449. #define REV_E_DIR() { E0_DIR_WRITE( INVERT_E0_DIR); E1_DIR_WRITE( INVERT_E1_DIR); E2_DIR_WRITE( INVERT_E2_DIR); }
  450. #else
  451. #define En_STEP_WRITE(n,v) { switch (n) { case 0: E0_STEP_WRITE(v); break; case 1: E1_STEP_WRITE(v); } }
  452. #define NORM_E_DIR() { E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); }
  453. #define REV_E_DIR() { E0_DIR_WRITE( INVERT_E0_DIR); E1_DIR_WRITE( INVERT_E1_DIR); }
  454. #endif
  455. #else
  456. #define E_STEP_WRITE(v) E0_STEP_WRITE(v)
  457. #define NORM_E_DIR() E0_DIR_WRITE(!INVERT_E0_DIR)
  458. #define REV_E_DIR() E0_DIR_WRITE(INVERT_E0_DIR)
  459. #endif
  460. #endif // STEPPER_INDIRECTION_H