Prusa MINI Firmware overview
indirection.h
Go to the documentation of this file.
1 /**
2  * Marlin 3D Printer Firmware
3  * Copyright (c) 2019 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 #pragma once
23 
24 /**
25  * stepper/indirection.h
26  *
27  * Stepper motor driver indirection to allow some stepper functions to
28  * be done via SPI/I2c instead of direct pin manipulation.
29  *
30  * Copyright (c) 2015 Dominik Wenger
31  */
32 
33 #include "../../inc/MarlinConfig.h"
34 
35 #if HAS_DRIVER(L6470)
36  #include "L6470.h"
37 #endif
38 
39 #if HAS_DRIVER(TMC26X)
40  #include "TMC26X.h"
41 #endif
42 
43 #if HAS_TRINAMIC
44  #include "trinamic.h"
45 #endif
46 
47 void restore_stepper_drivers(); // Called by PSU_ON
48 void reset_stepper_drivers(); // Called by settings.load / settings.reset
49 
50 // X Stepper
51 #ifndef X_ENABLE_INIT
52  #define X_ENABLE_INIT SET_OUTPUT(X_ENABLE_PIN)
53  #define X_ENABLE_WRITE(STATE) WRITE(X_ENABLE_PIN,STATE)
54  #define X_ENABLE_READ() READ(X_ENABLE_PIN)
55 #endif
56 #ifndef X_DIR_INIT
57  #define X_DIR_INIT SET_OUTPUT(X_DIR_PIN)
58  #define X_DIR_WRITE(STATE) WRITE(X_DIR_PIN,STATE)
59  #define X_DIR_READ() READ(X_DIR_PIN)
60 #endif
61 #define X_STEP_INIT SET_OUTPUT(X_STEP_PIN)
62 #ifndef X_STEP_WRITE
63  #define X_STEP_WRITE(STATE) WRITE(X_STEP_PIN,STATE)
64 #endif
65 #define X_STEP_READ READ(X_STEP_PIN)
66 
67 // Y Stepper
68 #ifndef Y_ENABLE_INIT
69  #define Y_ENABLE_INIT SET_OUTPUT(Y_ENABLE_PIN)
70  #define Y_ENABLE_WRITE(STATE) WRITE(Y_ENABLE_PIN,STATE)
71  #define Y_ENABLE_READ() READ(Y_ENABLE_PIN)
72 #endif
73 #ifndef Y_DIR_INIT
74  #define Y_DIR_INIT SET_OUTPUT(Y_DIR_PIN)
75  #define Y_DIR_WRITE(STATE) WRITE(Y_DIR_PIN,STATE)
76  #define Y_DIR_READ() READ(Y_DIR_PIN)
77 #endif
78 #define Y_STEP_INIT SET_OUTPUT(Y_STEP_PIN)
79 #ifndef Y_STEP_WRITE
80  #define Y_STEP_WRITE(STATE) WRITE(Y_STEP_PIN,STATE)
81 #endif
82 #define Y_STEP_READ READ(Y_STEP_PIN)
83 
84 // Z Stepper
85 #ifndef Z_ENABLE_INIT
86  #define Z_ENABLE_INIT SET_OUTPUT(Z_ENABLE_PIN)
87  #define Z_ENABLE_WRITE(STATE) WRITE(Z_ENABLE_PIN,STATE)
88  #define Z_ENABLE_READ() READ(Z_ENABLE_PIN)
89 #endif
90 #ifndef Z_DIR_INIT
91  #define Z_DIR_INIT SET_OUTPUT(Z_DIR_PIN)
92  #define Z_DIR_WRITE(STATE) WRITE(Z_DIR_PIN,STATE)
93  #define Z_DIR_READ() READ(Z_DIR_PIN)
94 #endif
95 #define Z_STEP_INIT SET_OUTPUT(Z_STEP_PIN)
96 #ifndef Z_STEP_WRITE
97  #define Z_STEP_WRITE(STATE) WRITE(Z_STEP_PIN,STATE)
98 #endif
99 #define Z_STEP_READ READ(Z_STEP_PIN)
100 
101 // X2 Stepper
102 #if HAS_X2_ENABLE
103  #ifndef X2_ENABLE_INIT
104  #define X2_ENABLE_INIT SET_OUTPUT(X2_ENABLE_PIN)
105  #define X2_ENABLE_WRITE(STATE) WRITE(X2_ENABLE_PIN,STATE)
106  #define X2_ENABLE_READ() READ(X2_ENABLE_PIN)
107  #endif
108  #ifndef X2_DIR_INIT
109  #define X2_DIR_INIT SET_OUTPUT(X2_DIR_PIN)
110  #define X2_DIR_WRITE(STATE) WRITE(X2_DIR_PIN,STATE)
111  #define X2_DIR_READ() READ(X2_DIR_PIN)
112  #endif
113  #define X2_STEP_INIT SET_OUTPUT(X2_STEP_PIN)
114  #ifndef X2_STEP_WRITE
115  #define X2_STEP_WRITE(STATE) WRITE(X2_STEP_PIN,STATE)
116  #endif
117  #define X2_STEP_READ READ(X2_STEP_PIN)
118 #endif
119 
120 // Y2 Stepper
121 #if HAS_Y2_ENABLE
122  #ifndef Y2_ENABLE_INIT
123  #define Y2_ENABLE_INIT SET_OUTPUT(Y2_ENABLE_PIN)
124  #define Y2_ENABLE_WRITE(STATE) WRITE(Y2_ENABLE_PIN,STATE)
125  #define Y2_ENABLE_READ() READ(Y2_ENABLE_PIN)
126  #endif
127  #ifndef Y2_DIR_INIT
128  #define Y2_DIR_INIT SET_OUTPUT(Y2_DIR_PIN)
129  #define Y2_DIR_WRITE(STATE) WRITE(Y2_DIR_PIN,STATE)
130  #define Y2_DIR_READ() READ(Y2_DIR_PIN)
131  #endif
132  #define Y2_STEP_INIT SET_OUTPUT(Y2_STEP_PIN)
133  #ifndef Y2_STEP_WRITE
134  #define Y2_STEP_WRITE(STATE) WRITE(Y2_STEP_PIN,STATE)
135  #endif
136  #define Y2_STEP_READ READ(Y2_STEP_PIN)
137 #else
138  #define Y2_DIR_WRITE(STATE) NOOP
139 #endif
140 
141 // Z2 Stepper
142 #if HAS_Z2_ENABLE
143  #ifndef Z2_ENABLE_INIT
144  #define Z2_ENABLE_INIT SET_OUTPUT(Z2_ENABLE_PIN)
145  #define Z2_ENABLE_WRITE(STATE) WRITE(Z2_ENABLE_PIN,STATE)
146  #define Z2_ENABLE_READ() READ(Z2_ENABLE_PIN)
147  #endif
148  #ifndef Z2_DIR_INIT
149  #define Z2_DIR_INIT SET_OUTPUT(Z2_DIR_PIN)
150  #define Z2_DIR_WRITE(STATE) WRITE(Z2_DIR_PIN,STATE)
151  #define Z2_DIR_READ() READ(Z2_DIR_PIN)
152  #endif
153  #define Z2_STEP_INIT SET_OUTPUT(Z2_STEP_PIN)
154  #ifndef Z2_STEP_WRITE
155  #define Z2_STEP_WRITE(STATE) WRITE(Z2_STEP_PIN,STATE)
156  #endif
157  #define Z2_STEP_READ READ(Z2_STEP_PIN)
158 #else
159  #define Z2_DIR_WRITE(STATE) NOOP
160 #endif
161 
162 // Z3 Stepper
163 #if HAS_Z3_ENABLE
164  #ifndef Z3_ENABLE_INIT
165  #define Z3_ENABLE_INIT SET_OUTPUT(Z3_ENABLE_PIN)
166  #define Z3_ENABLE_WRITE(STATE) WRITE(Z3_ENABLE_PIN,STATE)
167  #define Z3_ENABLE_READ() READ(Z3_ENABLE_PIN)
168  #endif
169  #ifndef Z3_DIR_INIT
170  #define Z3_DIR_INIT SET_OUTPUT(Z3_DIR_PIN)
171  #define Z3_DIR_WRITE(STATE) WRITE(Z3_DIR_PIN,STATE)
172  #define Z3_DIR_READ() READ(Z3_DIR_PIN)
173  #endif
174  #define Z3_STEP_INIT SET_OUTPUT(Z3_STEP_PIN)
175  #ifndef Z3_STEP_WRITE
176  #define Z3_STEP_WRITE(STATE) WRITE(Z3_STEP_PIN,STATE)
177  #endif
178  #define Z3_STEP_READ READ(Z3_STEP_PIN)
179 #else
180  #define Z3_DIR_WRITE(STATE) NOOP
181 #endif
182 
183 // E0 Stepper
184 #ifndef E0_ENABLE_INIT
185  #define E0_ENABLE_INIT SET_OUTPUT(E0_ENABLE_PIN)
186  #define E0_ENABLE_WRITE(STATE) WRITE(E0_ENABLE_PIN,STATE)
187  #define E0_ENABLE_READ() READ(E0_ENABLE_PIN)
188 #endif
189 #ifndef E0_DIR_INIT
190  #define E0_DIR_INIT SET_OUTPUT(E0_DIR_PIN)
191  #define E0_DIR_WRITE(STATE) WRITE(E0_DIR_PIN,STATE)
192  #define E0_DIR_READ() READ(E0_DIR_PIN)
193 #endif
194 #define E0_STEP_INIT SET_OUTPUT(E0_STEP_PIN)
195 #ifndef E0_STEP_WRITE
196  #define E0_STEP_WRITE(STATE) WRITE(E0_STEP_PIN,STATE)
197 #endif
198 #define E0_STEP_READ READ(E0_STEP_PIN)
199 
200 // E1 Stepper
201 #ifndef E1_ENABLE_INIT
202  #define E1_ENABLE_INIT SET_OUTPUT(E1_ENABLE_PIN)
203  #define E1_ENABLE_WRITE(STATE) WRITE(E1_ENABLE_PIN,STATE)
204  #define E1_ENABLE_READ() READ(E1_ENABLE_PIN)
205 #endif
206 #ifndef E1_DIR_INIT
207  #define E1_DIR_INIT SET_OUTPUT(E1_DIR_PIN)
208  #define E1_DIR_WRITE(STATE) WRITE(E1_DIR_PIN,STATE)
209  #define E1_DIR_READ() READ(E1_DIR_PIN)
210 #endif
211 #define E1_STEP_INIT SET_OUTPUT(E1_STEP_PIN)
212 #ifndef E1_STEP_WRITE
213  #define E1_STEP_WRITE(STATE) WRITE(E1_STEP_PIN,STATE)
214 #endif
215 #define E1_STEP_READ READ(E1_STEP_PIN)
216 
217 // E2 Stepper
218 #ifndef E2_ENABLE_INIT
219  #define E2_ENABLE_INIT SET_OUTPUT(E2_ENABLE_PIN)
220  #define E2_ENABLE_WRITE(STATE) WRITE(E2_ENABLE_PIN,STATE)
221  #define E2_ENABLE_READ() READ(E2_ENABLE_PIN)
222 #endif
223 #ifndef E2_DIR_INIT
224  #define E2_DIR_INIT SET_OUTPUT(E2_DIR_PIN)
225  #define E2_DIR_WRITE(STATE) WRITE(E2_DIR_PIN,STATE)
226  #define E2_DIR_READ() READ(E2_DIR_PIN)
227 #endif
228 #define E2_STEP_INIT SET_OUTPUT(E2_STEP_PIN)
229 #ifndef E2_STEP_WRITE
230  #define E2_STEP_WRITE(STATE) WRITE(E2_STEP_PIN,STATE)
231 #endif
232 #define E2_STEP_READ READ(E2_STEP_PIN)
233 
234 // E3 Stepper
235 #ifndef E3_ENABLE_INIT
236  #define E3_ENABLE_INIT SET_OUTPUT(E3_ENABLE_PIN)
237  #define E3_ENABLE_WRITE(STATE) WRITE(E3_ENABLE_PIN,STATE)
238  #define E3_ENABLE_READ() READ(E3_ENABLE_PIN)
239 #endif
240 #ifndef E3_DIR_INIT
241  #define E3_DIR_INIT SET_OUTPUT(E3_DIR_PIN)
242  #define E3_DIR_WRITE(STATE) WRITE(E3_DIR_PIN,STATE)
243  #define E3_DIR_READ() READ(E3_DIR_PIN)
244 #endif
245 #define E3_STEP_INIT SET_OUTPUT(E3_STEP_PIN)
246 #ifndef E3_STEP_WRITE
247  #define E3_STEP_WRITE(STATE) WRITE(E3_STEP_PIN,STATE)
248 #endif
249 #define E3_STEP_READ READ(E3_STEP_PIN)
250 
251 // E4 Stepper
252 #ifndef E4_ENABLE_INIT
253  #define E4_ENABLE_INIT SET_OUTPUT(E4_ENABLE_PIN)
254  #define E4_ENABLE_WRITE(STATE) WRITE(E4_ENABLE_PIN,STATE)
255  #define E4_ENABLE_READ() READ(E4_ENABLE_PIN)
256 #endif
257 #ifndef E4_DIR_INIT
258  #define E4_DIR_INIT SET_OUTPUT(E4_DIR_PIN)
259  #define E4_DIR_WRITE(STATE) WRITE(E4_DIR_PIN,STATE)
260  #define E4_DIR_READ() READ(E4_DIR_PIN)
261 #endif
262 #define E4_STEP_INIT SET_OUTPUT(E4_STEP_PIN)
263 #ifndef E4_STEP_WRITE
264  #define E4_STEP_WRITE(STATE) WRITE(E4_STEP_PIN,STATE)
265 #endif
266 #define E4_STEP_READ READ(E4_STEP_PIN)
267 
268 // E5 Stepper
269 #ifndef E5_ENABLE_INIT
270  #define E5_ENABLE_INIT SET_OUTPUT(E5_ENABLE_PIN)
271  #define E5_ENABLE_WRITE(STATE) WRITE(E5_ENABLE_PIN,STATE)
272  #define E5_ENABLE_READ() READ(E5_ENABLE_PIN)
273 #endif
274 #ifndef E5_DIR_INIT
275  #define E5_DIR_INIT SET_OUTPUT(E5_DIR_PIN)
276  #define E5_DIR_WRITE(STATE) WRITE(E5_DIR_PIN,STATE)
277  #define E5_DIR_READ() READ(E5_DIR_PIN)
278 #endif
279 #define E5_STEP_INIT SET_OUTPUT(E5_STEP_PIN)
280 #ifndef E5_STEP_WRITE
281  #define E5_STEP_WRITE(STATE) WRITE(E5_STEP_PIN,STATE)
282 #endif
283 #define E5_STEP_READ READ(E5_STEP_PIN)
284 
285 /**
286  * Extruder indirection for the single E axis
287  */
288 #if ENABLED(SWITCHING_EXTRUDER) // One stepper driver per two extruders, reversed on odd index
289  #if EXTRUDERS > 5
290  #define E_STEP_WRITE(E,V) do{ if (E < 2) { E0_STEP_WRITE(V); } else if (E < 4) { E1_STEP_WRITE(V); } else { E2_STEP_WRITE(V); } }while(0)
291  #define NORM_E_DIR(E) do{ switch (E) { 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); case 5: E2_DIR_WRITE( INVERT_E2_DIR); } }while(0)
292  #define REV_E_DIR(E) do{ switch (E) { 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); case 5: E2_DIR_WRITE(!INVERT_E2_DIR); } }while(0)
293  #elif EXTRUDERS > 4
294  #define E_STEP_WRITE(E,V) do{ if (E < 2) { E0_STEP_WRITE(V); } else if (E < 4) { E1_STEP_WRITE(V); } else { E2_STEP_WRITE(V); } }while(0)
295  #define NORM_E_DIR(E) do{ switch (E) { 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); } }while(0)
296  #define REV_E_DIR(E) do{ switch (E) { 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); } }while(0)
297  #elif EXTRUDERS > 3
298  #define E_STEP_WRITE(E,V) do{ if (E < 2) { E0_STEP_WRITE(V); } else { E1_STEP_WRITE(V); } }while(0)
299  #define NORM_E_DIR(E) do{ switch (E) { 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); } }while(0)
300  #define REV_E_DIR(E) do{ switch (E) { 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); } }while(0)
301  #elif EXTRUDERS > 2
302  #define E_STEP_WRITE(E,V) do{ if (E < 2) { E0_STEP_WRITE(V); } else { E1_STEP_WRITE(V); } }while(0)
303  #define NORM_E_DIR(E) do{ switch (E) { 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); } }while(0)
304  #define REV_E_DIR(E) do{ switch (E) { 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); } }while(0)
305  #else
306  #define E_STEP_WRITE(E,V) E0_STEP_WRITE(V)
307  #define NORM_E_DIR(E) do{ E0_DIR_WRITE(E ? INVERT_E0_DIR : !INVERT_E0_DIR); }while(0)
308  #define REV_E_DIR(E) do{ E0_DIR_WRITE(E ? !INVERT_E0_DIR : INVERT_E0_DIR); }while(0)
309  #endif
310 #elif ENABLED(PRUSA_MMU2)
311  #define E_STEP_WRITE(E,V) E0_STEP_WRITE(V)
312  #define NORM_E_DIR(E) E0_DIR_WRITE(!INVERT_E0_DIR)
313  #define REV_E_DIR(E) E0_DIR_WRITE( INVERT_E0_DIR)
314 
315 #elif ENABLED(MK2_MULTIPLEXER) // One multiplexed stepper driver, reversed on odd index
316  #define E_STEP_WRITE(E,V) E0_STEP_WRITE(V)
317  #define NORM_E_DIR(E) do{ E0_DIR_WRITE(TEST(E, 0) ? !INVERT_E0_DIR: INVERT_E0_DIR); }while(0)
318  #define REV_E_DIR(E) do{ E0_DIR_WRITE(TEST(E, 0) ? INVERT_E0_DIR: !INVERT_E0_DIR); }while(0)
319 
320 #elif E_STEPPERS > 1
321 
322  #if E_STEPPERS > 5
323  #define _E_STEP_WRITE(E,V) do{ switch (E) { 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); case 5: E5_STEP_WRITE(V); } }while(0)
324  #define _NORM_E_DIR(E) do{ switch (E) { 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); case 5: E5_DIR_WRITE(!INVERT_E5_DIR); } }while(0)
325  #define _REV_E_DIR(E) do{ switch (E) { 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); case 5: E5_DIR_WRITE( INVERT_E5_DIR); } }while(0)
326  #elif E_STEPPERS > 4
327  #define _E_STEP_WRITE(E,V) do{ switch (E) { 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); } }while(0)
328  #define _NORM_E_DIR(E) do{ switch (E) { 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); } }while(0)
329  #define _REV_E_DIR(E) do{ switch (E) { 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); } }while(0)
330  #elif E_STEPPERS > 3
331  #define _E_STEP_WRITE(E,V) do{ switch (E) { 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); } }while(0)
332  #define _NORM_E_DIR(E) do{ switch (E) { 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); } }while(0)
333  #define _REV_E_DIR(E) do{ switch (E) { 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); } }while(0)
334  #elif E_STEPPERS > 2
335  #define _E_STEP_WRITE(E,V) do{ switch (E) { case 0: E0_STEP_WRITE(V); break; case 1: E1_STEP_WRITE(V); break; case 2: E2_STEP_WRITE(V); } }while(0)
336  #define _NORM_E_DIR(E) do{ switch (E) { 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); } }while(0)
337  #define _REV_E_DIR(E) do{ switch (E) { 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); } }while(0)
338  #else
339  #define _E_STEP_WRITE(E,V) do{ if (E == 0) { E0_STEP_WRITE(V); } else { E1_STEP_WRITE(V); } }while(0)
340  #define _NORM_E_DIR(E) do{ if (E == 0) { E0_DIR_WRITE(!INVERT_E0_DIR); } else { E1_DIR_WRITE(!INVERT_E1_DIR); } }while(0)
341  #define _REV_E_DIR(E) do{ if (E == 0) { E0_DIR_WRITE( INVERT_E0_DIR); } else { E1_DIR_WRITE( INVERT_E1_DIR); } }while(0)
342  #endif
343 
344  #if HAS_DUPLICATION_MODE
345 
346  #if ENABLED(MULTI_NOZZLE_DUPLICATION)
347  #define _DUPE(N,T,V) do{ if (TEST(duplication_e_mask, N)) E##N##_##T##_WRITE(V); }while(0)
348  #else
349  #define _DUPE(N,T,V) E##N##_##T##_WRITE(V)
350  #endif
351 
352  #define NDIR(N) _DUPE(N,DIR,!INVERT_E##N##_DIR)
353  #define RDIR(N) _DUPE(N,DIR, INVERT_E##N##_DIR)
354 
355  #define E_STEP_WRITE(E,V) do{ if (extruder_duplication_enabled) { DUPE(STEP,V); } else _E_STEP_WRITE(E,V); }while(0)
356 
357  #if E_STEPPERS > 2
358  #if E_STEPPERS > 5
359  #define DUPE(T,V) do{ _DUPE(0,T,V); _DUPE(1,T,V); _DUPE(2,T,V); _DUPE(3,T,V); _DUPE(4,T,V); _DUPE(5,T,V); }while(0)
360  #define NORM_E_DIR(E) do{ if (extruder_duplication_enabled) { NDIR(0); NDIR(1); NDIR(2); NDIR(3); NDIR(4); NDIR(5); } else _NORM_E_DIR(E); }while(0)
361  #define REV_E_DIR(E) do{ if (extruder_duplication_enabled) { RDIR(0); RDIR(1); RDIR(2); RDIR(3); RDIR(4); RDIR(5); } else _REV_E_DIR(E); }while(0)
362  #elif E_STEPPERS > 4
363  #define DUPE(T,V) do{ _DUPE(0,T,V); _DUPE(1,T,V); _DUPE(2,T,V); _DUPE(3,T,V); _DUPE(4,T,V); }while(0)
364  #define NORM_E_DIR(E) do{ if (extruder_duplication_enabled) { NDIR(0); NDIR(1); NDIR(2); NDIR(3); NDIR(4); } else _NORM_E_DIR(E); }while(0)
365  #define REV_E_DIR(E) do{ if (extruder_duplication_enabled) { RDIR(0); RDIR(1); RDIR(2); RDIR(3); RDIR(4); } else _REV_E_DIR(E); }while(0)
366  #elif E_STEPPERS > 3
367  #define DUPE(T,V) do{ _DUPE(0,T,V); _DUPE(1,T,V); _DUPE(2,T,V); _DUPE(3,T,V); }while(0)
368  #define NORM_E_DIR(E) do{ if (extruder_duplication_enabled) { NDIR(0); NDIR(1); NDIR(2); NDIR(3); } else _NORM_E_DIR(E); }while(0)
369  #define REV_E_DIR(E) do{ if (extruder_duplication_enabled) { RDIR(0); RDIR(1); RDIR(2); RDIR(3); } else _REV_E_DIR(E); }while(0)
370  #else
371  #define DUPE(T,V) do{ _DUPE(0,T,V); _DUPE(1,T,V); _DUPE(2,T,V); }while(0)
372  #define NORM_E_DIR(E) do{ if (extruder_duplication_enabled) { NDIR(0); NDIR(1); NDIR(2); } else _NORM_E_DIR(E); }while(0)
373  #define REV_E_DIR(E) do{ if (extruder_duplication_enabled) { RDIR(0); RDIR(1); RDIR(2); } else _REV_E_DIR(E); }while(0)
374  #endif
375  #else
376  #define DUPE(T,V) do{ _DUPE(0,T,V); _DUPE(1,T,V); }while(0)
377  #define NORM_E_DIR(E) do{ if (extruder_duplication_enabled) { NDIR(0); NDIR(1); } else _NORM_E_DIR(E); }while(0)
378  #define REV_E_DIR(E) do{ if (extruder_duplication_enabled) { RDIR(0); RDIR(1); } else _REV_E_DIR(E); }while(0)
379  #endif
380 
381  #else
382 
383  #define E_STEP_WRITE(E,V) _E_STEP_WRITE(E,V)
384  #define NORM_E_DIR(E) _NORM_E_DIR(E)
385  #define REV_E_DIR(E) _REV_E_DIR(E)
386 
387  #endif
388 
389 #elif E_STEPPERS
390  #define E_STEP_WRITE(E,V) E0_STEP_WRITE(V)
391  #define NORM_E_DIR(E) E0_DIR_WRITE(!INVERT_E0_DIR)
392  #define REV_E_DIR(E) E0_DIR_WRITE( INVERT_E0_DIR)
393 
394 #else
395  #define E_STEP_WRITE(E,V) NOOP
396  #define NORM_E_DIR(E) NOOP
397  #define REV_E_DIR(E) NOOP
398 
399 #endif
L6470.h
reset_stepper_drivers
void reset_stepper_drivers()
Definition: indirection.cpp:41
TMC26X.h
indirection.h
L6470_Marlin::init_to_defaults
static void init_to_defaults()
L6470
L6470_Marlin L6470
tmc26x_init_to_defaults
void tmc26x_init_to_defaults()
reset_stepper_drivers
void reset_stepper_drivers()
Definition: indirection.cpp:41
restore_trinamic_drivers
void restore_trinamic_drivers()
restore_stepper_drivers
void restore_stepper_drivers()
Definition: indirection.cpp:35
restore_stepper_drivers
void restore_stepper_drivers()
Definition: indirection.cpp:35
reset_trinamic_drivers
void reset_trinamic_drivers()