My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

stepper_indirection.h 18KB

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