My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

stepper_indirection.h 19KB

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