grblHAL core  20260206
motor_pins.h
Go to the documentation of this file.
1 /*
2  motor_pins.h - pin mappings resolver for ganged/squared/ABC axes
3 
4  NOTE: This file is not used by the core, it may be used by drivers to simplify board map files
5 
6  Part of grblHAL
7 
8  Copyright (c) 2021-2026 Terje Io
9 
10  grblHAL is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  grblHAL is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with grblHAL. If not, see <http://www.gnu.org/licenses/>.
22 */
23 
24 #pragma once
25 
26 #ifdef __GNUC__
27 #pragma GCC diagnostic push
28 #pragma GCC diagnostic ignored "-Wexpansion-to-defined"
29 #endif
30 
31 #define CAT(a, b) CAT_(a, b)
32 #define CAT_(a, b) a##b
33 
34 #define MOTOR_IO(n, t) CAT(M, CAT(n, t))
35 
36 #define mn_has_limit(a) \
37  (a == 3 ? defined(M3_LIMIT_PIN) : \
38  (a == 4 ? defined(M4_LIMIT_PIN) : \
39  (a == 5 ? defined(M5_LIMIT_PIN) : \
40  (a == 6 ? defined(M6_LIMIT_PIN) : \
41  (a == 7 ? defined(M7_LIMIT_PIN) : 0)))))
42 
43 #define mn_has_home(a) \
44  (a == 3 ? defined(M3_HOME_PIN) : \
45  (a == 4 ? defined(M4_HOME_PIN) : \
46  (a == 5 ? defined(M5_HOME_PIN) : \
47  (a == 6 ? defined(M6_HOME_PIN) : \
48  (a == 7 ? defined(M7_HOME_PIN) : 0)))))
49 
50 #define mn_has_limit_max(a) \
51  (a == 3 ? defined(M3_LIMIT_PIN_MAX) : \
52  (a == 4 ? defined(M4_LIMIT_PIN_MAX) : \
53  (a == 5 ? defined(M5_LIMIT_PIN_MAX) : \
54  (a == 6 ? defined(M6_LIMIT_PIN_MAX) : \
55  (a == 7 ? defined(M7_LIMIT_PIN_MAX) : 0)))))
56 
57 #define mn_has_fault(a) \
58  (a == 3 ? defined(M3_MOTOR_FAULT_PIN) : \
59  (a == 4 ? defined(M4_MOTOR_FAULT_PIN) : \
60  (a == 5 ? defined(M5_MOTOR_FAULT_PIN) : \
61  (a == 6 ? defined(M6_MOTOR_FAULT_PIN) : \
62  (a == 7 ? defined(M7_MOTOR_FAULT_PIN) : 0)))))
63 
64 #define mn_has_enable(a) \
65  (a == 3 ? defined(M3_ENABLE_PIN) : \
66  (a == 4 ? defined(M4_ENABLE_PIN) : \
67  (a == 5 ? defined(M5_ENABLE_PIN) : \
68  (a == 6 ? defined(M6_ENABLE_PIN) : \
69  (a == 7 ? defined(M7_ENABLE_PIN) : 0)))))
70 
71 #define N_MOTORS (3 + defined(M3_AVAILABLE) + defined(M4_AVAILABLE) + defined(M5_AVAILABLE) + defined(M6_AVAILABLE) + defined(M7_AVAILABLE))
72 
73 #if N_AXIS > 3
74  #if !defined(M3_STEP_BIT)
75  #define M3_STEP_BIT (1<<M3_STEP_PIN)
76  #endif
77  #if !defined(M3_DIRECTION_BIT)
78  #define M3_DIRECTION_BIT (1<<M3_DIRECTION_PIN)
79  #endif
80  #if !defined(M3_ENABLE_BIT)
81  #ifdef M3_ENABLE_PIN
82  #define M3_ENABLE_BIT (1<<M3_ENABLE_PIN)
83  #else
84  #define M3_ENABLE_BIT 0
85  #endif
86  #endif
87  #if !defined(M3_HOME_BIT)
88  #ifdef M3_HOME_PIN
89  #define M3_HOME_BIT (1<<M3_HOME_PIN)
90  #else
91  #define M3_HOME_BIT 0
92  #endif
93  #endif
94  #if !defined(M3_LIMIT_BIT)
95  #ifdef M3_LIMIT_PIN
96  #define M3_LIMIT_BIT (1>>M3_LIMIT_PIN)
97  #else
98  #define M3_LIMIT_BIT 0
99  #endif
100  #endif
101  #if !defined(M3_LIMIT_MAX_BIT)
102  #ifdef M3_LIMIT_MAX_PIN
103  #define M3_LIMIT_MAX_BIT (1<<M3_LIMIT_MAX_PIN)
104  #else
105  #define M3_LIMIT_MAX_BIT 0
106  #endif
107  #endif
108  #if !defined(M3_MOTOR_FAULT_BIT)
109  #ifdef M3_MOTOR_FAULT_PIN
110  #define M3_MOTOR_FAULT_BIT (1<<M3_MOTOR_FAULT_PIN)
111  #else
112  #define M3_MOTOR_FAULT_BIT 0
113  #endif
114  #endif
115 #endif
116 
117 #if N_AXIS > 4
118  #if !defined(M4_STEP_BIT)
119  #define M4_STEP_BIT (1<<M4_STEP_PIN)
120  #endif
121  #if !defined(M4_DIRECTION_BIT)
122  #define M4_DIRECTION_BIT (1<<M4_DIRECTION_PIN)
123  #endif
124  #if !defined(M4_ENABLE_BIT)
125  #ifdef M4_ENABLE_PIN
126  #define M4_ENABLE_BIT (1<<M4_ENABLE_PIN)
127  #else
128  #define M4_ENABLE_BIT 0
129  #endif
130  #endif
131  #if !defined(M4_HOME_BIT)
132  #ifdef M4_HOME_PIN
133  #define M4_HOME_BIT (1<<M4_HOME_PIN)
134  #else
135  #define M4_HOME_BIT 0
136  #endif
137  #endif
138  #if !defined(M4_LIMIT_BIT)
139  #ifdef M4_LIMIT_PIN
140  #define M4_LIMIT_BIT (1>>M4_LIMIT_PIN)
141  #else
142  #define M4_LIMIT_BIT 0
143  #endif
144  #endif
145  #if !defined(M4_LIMIT_MAX_BIT)
146  #ifdef M4_LIMIT_MAX_PIN
147  #define M4_LIMIT_MAX_BIT (1<<M4_LIMIT_MAX_PIN)
148  #else
149  #define M4_LIMIT_MAX_BIT 0
150  #endif
151  #endif
152  #if !defined(M4_MOTOR_FAULT_BIT)
153  #ifdef M4_MOTOR_FAULT_PIN
154  #define M4_MOTOR_FAULT_BIT (1<<M4_MOTOR_FAULT_PIN)
155  #else
156  #define M4_MOTOR_FAULT_BIT 0
157  #endif
158  #endif
159 #endif
160 
161 #if N_AXIS > 5
162  #if !defined(M5_STEP_BIT)
163  #define M5_STEP_BIT (1<<M5_STEP_PIN)
164  #endif
165  #if !defined(M5_DIRECTION_BIT)
166  #define M5_DIRECTION_BIT (1<<M5_DIRECTION_PIN)
167  #endif
168  #if !defined(M5_ENABLE_BIT)
169  #ifdef M5_ENABLE_PIN
170  #define M5_ENABLE_BIT (1<<M5_ENABLE_PIN)
171  #else
172  #define M5_ENABLE_BIT 0
173  #endif
174  #endif
175  #if !defined(M5_HOME_BIT)
176  #ifdef M5_HOME_PIN
177  #define M5_HOME_BIT (1<<M5_HOME_PIN)
178  #else
179  #define M5_HOME_BIT 0
180  #endif
181  #endif
182  #if !defined(M5_LIMIT_BIT)
183  #ifdef M5_LIMIT_PIN
184  #define M5_LIMIT_BIT (1>>M5_LIMIT_PIN)
185  #else
186  #define M5_LIMIT_BIT 0
187  #endif
188  #endif
189  #if !defined(M5_LIMIT_MAX_BIT)
190  #ifdef M5_LIMIT_MAX_PIN
191  #define M5_LIMIT_MAX_BIT (1<<M5_LIMIT_MAX_PIN)
192  #else
193  #define M5_LIMIT_MAX_BIT 0
194  #endif
195  #endif
196  #if !defined(M5_MOTOR_FAULT_BIT)
197  #ifdef M5_MOTOR_FAULT_PIN
198  #define M5_MOTOR_FAULT_BIT (1<<M5_MOTOR_FAULT_PIN)
199  #else
200  #define M5_MOTOR_FAULT_BIT 0
201  #endif
202  #endif
203 #endif
204 
205 #if N_AXIS > 6
206  #if !defined(M6_STEP_BIT)
207  #define M6_STEP_BIT (1<<M6_STEP_PIN)
208  #endif
209  #if !defined(M6_DIRECTION_BIT)
210  #define M6_DIRECTION_BIT (1<<M6_DIRECTION_PIN)
211  #endif
212  #if !defined(M6_ENABLE_BIT)
213  #ifdef M6_ENABLE_PIN
214  #define M6_ENABLE_BIT (1<<M6_ENABLE_PIN)
215  #else
216  #define M6_ENABLE_BIT 0
217  #endif
218  #endif
219  #if !defined(M6_HOME_BIT)
220  #ifdef M6_HOME_PIN
221  #define M6_HOME_BIT (1<<M6_HOME_PIN)
222  #else
223  #define M6_HOME_BIT 0
224  #endif
225  #endif
226  #if !defined(M6_LIMIT_BIT)
227  #ifdef M6_LIMIT_PIN
228  #define M6_LIMIT_BIT (1>>M6_LIMIT_PIN)
229  #else
230  #define M6_LIMIT_BIT 0
231  #endif
232  #endif
233  #if !defined(M6_LIMIT_MAX_BIT)
234  #ifdef M6_LIMIT_MAX_PIN
235  #define M6_LIMIT_MAX_BIT (1<<M6_LIMIT_MAX_PIN)
236  #else
237  #define M6_LIMIT_MAX_BIT 0
238  #endif
239  #endif
240  #if !defined(M6_MOTOR_FAULT_BIT)
241  #ifdef M6_MOTOR_FAULT_PIN
242  #define M6_MOTOR_FAULT_BIT (1<<M6_MOTOR_FAULT_PIN)
243  #else
244  #define M6_MOTOR_FAULT_BIT 0
245  #endif
246  #endif
247 #endif
248 
249 #if N_AXIS > 7
250  #if !defined(M7_STEP_BIT)
251  #define M7_STEP_BIT (1<<M7_STEP_PIN)
252  #endif
253  #if !defined(M7_DIRECTION_BIT)
254  #define M7_DIRECTION_BIT (1<<M7_DIRECTION_PIN)
255  #endif
256  #if !defined(M7_ENABLE_BIT)
257  #ifdef M7_ENABLE_PIN
258  #define M7_ENABLE_BIT (1<<M7_ENABLE_PIN)
259  #else
260  #define M7_ENABLE_BIT 0
261  #endif
262  #endif
263  #if !defined(M7_HOME_BIT)
264  #ifdef M7_HOME_PIN
265  #define M7_HOME_BIT (1<<M7_HOME_PIN)
266  #else
267  #define M7_HOME_BIT 0
268  #endif
269  #endif
270  #if !defined(M7_LIMIT_BIT)
271  #ifdef M7_LIMIT_PIN
272  #define M7_LIMIT_BIT (1>>M7_LIMIT_PIN)
273  #else
274  #define M7_LIMIT_BIT 0
275  #endif
276  #endif
277  #if !defined(M7_LIMIT_MAX_BIT)
278  #ifdef M7_LIMIT_MAX_PIN
279  #define M7_LIMIT_MAX_BIT (1<<M7_LIMIT_MAX_PIN)
280  #else
281  #define M7_LIMIT_MAX_BIT 0
282  #endif
283  #endif
284  #if !defined(M7_MOTOR_FAULT_BIT)
285  #ifdef M7_MOTOR_FAULT_PIN
286  #define M7_MOTOR_FAULT_BIT (1<<M7_MOTOR_FAULT_PIN)
287  #else
288  #define M7_MOTOR_FAULT_BIT 0
289  #endif
290  #endif
291 #endif
292 
293 #if N_GANGED
294 
295 #if N_GANGED > N_ABC_MOTORS
296 #error "Axis configuration is not supported!"
297 #endif
298 
299 #if N_AUTO_SQUARED
300 #define SQUARING_ENABLED
301 #endif
302 
303 #if N_GANGED
304 #define GANGING_ENABLED
305 #endif
306 
307 #if Z_GANGED
308  #if N_MOTORS == 8
309  #define Z2_MOTOR_IDX 7
310  #elif N_MOTORS == 7
311  #define Z2_MOTOR_IDX 6
312  #elif N_MOTORS == 6
313  #define Z2_MOTOR_IDX 5
314  #elif N_MOTORS == 5
315  #define Z2_MOTOR_IDX 4
316  #elif N_MOTORS == 4
317  #define Z2_MOTOR_IDX 3
318  #endif
319 #elif Y_GANGED
320  #if N_MOTORS == 8
321  #define Y2_MOTOR_IDX 7
322  #elif N_MOTORS == 7
323  #define Y2_MOTOR_IDX 6
324  #elif N_MOTORS == 6
325  #define Y2_MOTOR_IDX 5
326  #elif N_MOTORS == 5
327  #define Y2_MOTOR_IDX 4
328  #elif N_MOTORS == 4
329  #define Y2_MOTOR_IDX 3
330  #endif
331 #elif X_GANGED
332  #if N_MOTORS == 8
333  #define X2_MOTOR_IDX 7
334  #elif N_MOTORS == 7
335  #define X2_MOTOR_IDX 6
336  #elif N_MOTORS == 6
337  #define X2_MOTOR_IDX 5
338  #elif N_MOTORS == 5
339  #define X2_MOTOR_IDX 4
340  #elif N_MOTORS == 4
341  #define X2_MOTOR_IDX 3
342  #endif
343 #endif
344 
345 #if Y_GANGED && !defined(Y2_MOTOR_IDX)
346  #if N_MOTORS == 8
347  #define Y2_MOTOR_IDX 6
348  #elif N_MOTORS == 7
349  #define Y2_MOTOR_IDX 5
350  #elif N_MOTORS == 6
351  #define Y2_MOTOR_IDX 4
352  #elif N_MOTORS == 5
353  #define Y2_MOTOR_IDX 3
354  #endif
355 #elif X_GANGED && !defined(X2_MOTOR_IDX)
356  #if N_MOTORS == 8
357  #define X2_MOTOR_IDX 6
358  #elif N_MOTORS == 7
359  #define X2_MOTOR_IDX 5
360  #elif N_MOTORS == 6
361  #define X2_MOTOR_IDX 4
362  #elif N_MOTORS == 5
363  #define X2_MOTOR_IDX 3
364  #endif
365 #endif
366 
367 #if X_GANGED && !defined(X2_MOTOR_IDX)
368  #if N_MOTORS == 8
369  #define X2_MOTOR_IDX 5
370  #elif N_MOTORS == 7
371  #define X2_MOTOR_IDX 4
372  #elif N_MOTORS == 6
373  #define X2_MOTOR_IDX 3
374  #endif
375 #endif
376 
377 #ifdef X2_MOTOR_IDX
378 
379 #define X2_STEP_PORT MOTOR_IO(X2_MOTOR_IDX, _STEP_PORT)
380 #define X2_STEP_PIN MOTOR_IO(X2_MOTOR_IDX, _STEP_PIN)
381 #define X2_STEP_BIT (1<<X2_STEP_PIN)
382 #define X2_DIRECTION_PORT MOTOR_IO(X2_MOTOR_IDX, _DIRECTION_PORT)
383 #define X2_DIRECTION_PIN MOTOR_IO(X2_MOTOR_IDX, _DIRECTION_PIN)
384 #define X2_DIRECTION_BIT (1<<X2_DIRECTION_PIN)
385 #if mn_has_home(X2_MOTOR_IDX)
386  #if X_AUTO_SQUARE
387  #define X2_HOME_PORT MOTOR_IO(X2_MOTOR_IDX, _HOME_PORT)
388  #define X2_HOME_PIN MOTOR_IO(X2_MOTOR_IDX, _HOME_PIN)
389  #define X2_HOME_BIT (1<<X2_HOME_PIN)
390  #endif
391 #elif X_AUTO_SQUARE && defined(X_HOME_PIN)
392  #error "Auto squared Y-axis requires second home pin input"
393 #endif
394 #if mn_has_limit(X2_MOTOR_IDX)
395  #if X_AUTO_SQUARE
396  #define X2_LIMIT_PORT MOTOR_IO(X2_MOTOR_IDX, _LIMIT_PORT)
397  #define X2_LIMIT_PIN MOTOR_IO(X2_MOTOR_IDX, _LIMIT_PIN)
398  #define X2_LIMIT_BIT (1<<X2_LIMIT_PIN)
399  #elif X_GANGED_LIM_MAX && !mn_has_limit_max(X2_MOTOR_IDX)
400  #define X2_LIMIT_MAX_PORT MOTOR_IO(X2_MOTOR_IDX, _LIMIT_MAX_PORT)
401  #define X2_LIMIT_MAX_PIN MOTOR_IO(X2_MOTOR_IDX, _LIMIT_MAX_PIN)
402  #define X2_LIMIT_MAX_BIT (1<<X2_LIMIT_MAX_PIN)
403  #endif
404 #elif X_AUTO_SQUARE
405  #error "Auto squared Y-axis requires second limit pin input"
406 #endif
407 #if mn_has_limit_max(X2_MOTOR_IDX)
408  #define X2_LIMIT_MAX_PORT MOTOR_IO(X2_MOTOR_IDX, _LIMIT_MAX_PORT)
409  #define X2_LIMIT_MAX_PIN MOTOR_IO(X2_MOTOR_IDX, _LIMIT_MAX_PIN)
410  #define X2_LIMIT_MAX_BIT (1<<X2_LIMIT_MAX_PIN)
411 #endif
412 #if mn_has_enable(X2_MOTOR_IDX)
413  #define X2_ENABLE_PORT MOTOR_IO(X2_MOTOR_IDX, _ENABLE_PORT)
414  #define X2_ENABLE_PIN MOTOR_IO(X2_MOTOR_IDX, _ENABLE_PIN)
415  #define X2_ENABLE_BIT (1<<X2_ENABLE_PIN)
416 #endif
417 #if mn_has_fault(X2_MOTOR_IDX)
418  #define X2_MOTOR_FAULT_PORT MOTOR_IO(X2_MOTOR_IDX, _MOTOR_FAULT_PORT)
419  #define X2_MOTOR_FAULT_PIN MOTOR_IO(X2_MOTOR_IDX, _MOTOR_FAULT_PIN)
420  #define X2_MOTOR_FAULT_BIT (1<<X2_MOTOR_FAULT_PIN)
421 #endif
422 
423 #endif // X_GANGED
424 
425 #ifdef Y2_MOTOR_IDX
426 
427 #define Y2_STEP_PORT MOTOR_IO(Y2_MOTOR_IDX, _STEP_PORT)
428 #define Y2_STEP_PIN MOTOR_IO(Y2_MOTOR_IDX, _STEP_PIN)
429 #define Y2_STEP_BIT (1<<Y2_STEP_PIN)
430 #define Y2_DIRECTION_PORT MOTOR_IO(Y2_MOTOR_IDX, _DIRECTION_PORT)
431 #define Y2_DIRECTION_PIN MOTOR_IO(Y2_MOTOR_IDX, _DIRECTION_PIN)
432 #define Y2_DIRECTION_BIT (1<<Y2_DIRECTION_PIN)
433 #if mn_has_home(Y2_MOTOR_IDX)
434  #if Y_AUTO_SQUARE
435  #define Y2_HOME_PORT MOTOR_IO(Y2_MOTOR_IDX, _HOME_PORT)
436  #define Y2_HOME_PIN MOTOR_IO(Y2_MOTOR_IDX, _HOME_PIN)
437  #define Y2_HOME_BIT (1<<Y2_HOME_PIN)
438  #endif
439 #elif Y_AUTO_SQUARE && defined(Y_HOME_PIN)
440  #error "Auto squared Y-axis requires second home pin input"
441 #endif
442 #if mn_has_limit(Y2_MOTOR_IDX)
443  #if Y_AUTO_SQUARE
444  #define Y2_LIMIT_PORT MOTOR_IO(Y2_MOTOR_IDX, _LIMIT_PORT)
445  #define Y2_LIMIT_PIN MOTOR_IO(Y2_MOTOR_IDX, _LIMIT_PIN)
446  #define Y2_LIMIT_BIT (1<<Y2_LIMIT_PIN)
447  #elif Y_GANGED_LIM_MAX && !mn_has_limit_max(Y2_MOTOR_IDX)
448  #define Y2_LIMIT_MAX_PORT MOTOR_IO(Y2_MOTOR_IDX, _LIMIT_MAX_PORT)
449  #define Y2_LIMIT_MAX_PIN MOTOR_IO(Y2_MOTOR_IDX, _LIMIT_MAX_PIN)
450  #define Y2_LIMIT_MAX_BIT (1<<Y2_LIMIT_MAX_PIN)
451  #endif
452 #elif Y_AUTO_SQUARE
453  #error "Auto squared Y-axis requires second limit pin input"
454 #endif
455 #if mn_has_limit_max(Y2_MOTOR_IDX)
456  #define Y2_LIMIT_MAX_PORT MOTOR_IO(Y2_MOTOR_IDX, _LIMIT_MAX_PORT)
457  #define Y2_LIMIT_MAX_PIN MOTOR_IO(Y2_MOTOR_IDX, _LIMIT_MAX_PIN)
458  #define Y2_LIMIT_MAX_BIT (1<<Y2_LIMIT_MAX_PIN)
459 #endif
460 #if mn_has_enable(Y2_MOTOR_IDX)
461  #define Y2_ENABLE_PORT MOTOR_IO(Y2_MOTOR_IDX, _ENABLE_PORT)
462  #define Y2_ENABLE_PIN MOTOR_IO(Y2_MOTOR_IDX, _ENABLE_PIN)
463  #define Y2_ENABLE_BIT (1<<Y2_ENABLE_PIN)
464 #endif
465 #if mn_has_fault(Y2_MOTOR_IDX)
466  #define Y2_MOTOR_FAULT_PORT MOTOR_IO(Y2_MOTOR_IDX, _MOTOR_FAULT_PORT)
467  #define Y2_MOTOR_FAULT_PIN MOTOR_IO(Y2_MOTOR_IDX, _MOTOR_FAULT_PIN)
468  #define Y2_MOTOR_FAULT_BIT (1<<Y2_MOTOR_FAULT_PIN)
469 #endif
470 
471 #endif // Y_GANGED
472 
473 #ifdef Z2_MOTOR_IDX
474 
475 #define Z2_STEP_PORT MOTOR_IO(Z2_MOTOR_IDX, _STEP_PORT)
476 #define Z2_STEP_PIN MOTOR_IO(Z2_MOTOR_IDX, _STEP_PIN)
477 #define Z2_STEP_BIT (1<<<Z2_STEP_PIN)
478 #define Z2_DIRECTION_PORT MOTOR_IO(Z2_MOTOR_IDX, _DIRECTION_PORT)
479 #define Z2_DIRECTION_PIN MOTOR_IO(Z2_MOTOR_IDX, _DIRECTION_PIN)
480 #define Z2_DIRECTION_BIT (1<<Z2_DIRECTION_PIN)
481 #if mn_has_home(Z2_MOTOR_IDX)
482  #if Z_AUTO_SQUARE
483  #define Z2_HOME_PORT MOTOR_IO(Z2_MOTOR_IDX, _HOME_PORT)
484  #define Z2_HOME_PIN MOTOR_IO(Z2_MOTOR_IDX, _HOME_PIN)
485  #define Z2_HOME_BIT (1<<Z2_HOME_PIN)
486  #endif
487 #elif Z_AUTO_SQUARE && defined(Z_HOME_PIN)
488  #error "Auto squared Y-axis requires second home pin input"
489 #endif
490 #if mn_has_limit(Z2_MOTOR_IDX)
491  #if Z_AUTO_SQUARE
492  #define Z2_LIMIT_PORT MOTOR_IO(Z2_MOTOR_IDX, _LIMIT_PORT)
493  #define Z2_LIMIT_PIN MOTOR_IO(Z2_MOTOR_IDX, _LIMIT_PIN)
494  #define Z2_LIMIT_BIT (1<<Z2_LIMIT_PIN)
495  #elif Z_GANGED_LIM_MAX && !mn_has_limit_max(Z2_MOTOR_IDX)
496  #define Z2_LIMIT_MAX_PORT MOTOR_IO(Z2_MOTOR_IDX, _LIMIT_MAX_PORT)
497  #define Z2_LIMIT_MAX_PIN MOTOR_IO(Z2_MOTOR_IDX, _LIMIT_MAX_PIN)
498  #define Z2_LIMIT_MAX_BIT (1<<Z2_LIMIT_MAX_PIN)
499  #endif
500 #elif Z_AUTO_SQUARE
501  #error "Auto squared Y-axis requires second limit pin input"
502 #endif
503 #if mn_has_limit_max(Z2_MOTOR_IDX)
504  #define Z2_LIMIT_MAX_PORT MOTOR_IO(Z2_MOTOR_IDX, _LIMIT_MAX_PORT)
505  #define Z2_LIMIT_MAX_PIN MOTOR_IO(Z2_MOTOR_IDX, _LIMIT_MAX_PIN)
506  #define Z2_LIMIT_MAX_BIT (1<<Z2_LIMIT_MAX_PIN)
507 #endif
508 #if mn_has_enable(Z2_MOTOR_IDX)
509  #define Z2_ENABLE_PORT MOTOR_IO(Z2_MOTOR_IDX, _ENABLE_PORT)
510  #define Z2_ENABLE_PIN MOTOR_IO(Z2_MOTOR_IDX, _ENABLE_PIN)
511  #define Z2_ENABLE_BIT (1<<Z2_ENABLE_PIN)
512 #endif
513 #if mn_has_fault(Z2_MOTOR_IDX)
514  #define Z2_MOTOR_FAULT_PORT MOTOR_IO(Z2_MOTOR_IDX, _MOTOR_FAULT_PORT)
515  #define Z2_MOTOR_FAULT_PIN MOTOR_IO(Z2_MOTOR_IDX, _MOTOR_FAULT_PIN)
516  #define Z2_MOTOR_FAULT_BIT (1<<Z2_MOTOR_FAULT_PIN)
517 #endif
518 
519 #endif // Z_GANGED
520 
521 #endif // N_GANGED
522 
523 #if defined(X2_HOME_PIN) || defined(Y2_HOME_PIN) || defined(Z2_HOME_PIN)
524 #define DUAL_HOME_SWITCHES
525 #ifndef X2_HOME_BIT
526 #define X2_HOME_BIT 0
527 #endif
528 #ifndef Y2_HOME_BIT
529 #define Y2_HOME_BIT 0
530 #endif
531 #ifndef Z2_HOME_BIT
532 #define Z2_HOME_BIT 0
533 #endif
534 #define HOME2_MASK (X2_HOME_BIT|Y2_HOME_BIT|Z2_HOME_BIT)
535 #define HOME2_MASK_SUM (X2_HOME_BIT+Y2_HOME_BIT+Z2_HOME_BIT)
536 #else
537 #define HOME2_MASK 0
538 #define HOME2_MASK_SUM 0
539 #endif
540 
541 #if defined(X2_MOTOR_FAULT_PIN) || defined(Y2_MOTOR_FAULT_PIN) || defined(Z2_MOTOR_FAULT_PIN)
542 #define DUAL_MOTOR_FAULT_SWITCHES
543 #ifndef X2_MOTOR_FAULT_BIT
544 #define X2_MOTOR_FAULT_BIT 0
545 #endif
546 #ifndef Y2_MOTOR_FAULT_BIT
547 #define Y2_MOTOR_FAULT_BIT 0
548 #endif
549 #ifndef Z2_MOTOR_FAULT_BIT
550 #define Z2_MOTOR_FAULT_BIT 0
551 #endif
552 #define MOTOR_FAULT2_MASK (X2_MOTOR_FAULT_BIT|Y2_MOTOR_FAULT_BIT|Z2_MOTOR_FAULT_BIT)
553 #define MOTOR_FAULT2_MASK_SUM (X2_MOTOR_FAULT_BIT+Y2_MOTOR_FAULT_BIT+Z2_MOTOR_FAULT_BIT)
554 #else
555 #define MOTOR_FAULT2_MASK 0
556 #define MOTOR_FAULT2_MASK_SUM 0
557 #endif
558 
559 #if defined(X2_LIMIT_PIN) || defined(Y2_LIMIT_PIN) || defined(Z2_LIMIT_PIN)
560 #define DUAL_LIMIT_SWITCHES
561 #ifndef X2_LIMIT_BIT
562 #define X2_LIMIT_BIT 0
563 #endif
564 #ifndef Y2_LIMIT_BIT
565 #define Y2_LIMIT_BIT 0
566 #endif
567 #ifndef Z2_LIMIT_BIT
568 #define Z2_LIMIT_BIT 0
569 #endif
570 #define LIMIT2_MASK (X2_LIMIT_BIT|Y2_LIMIT_BIT|Z2_LIMIT_BIT)
571 #define LIMIT2_MASK_SUM (X2_LIMIT_BIT+Y2_LIMIT_BIT+Z2_LIMIT_BIT)
572 #else
573 #define LIMIT2_MASK 0
574 #define LIMIT2_MASK_SUM 0
575 #endif
576 
577 #if defined(X_LIMIT_PIN_MAX) || defined(Y_LIMIT_PIN_MAX) || defined(Z_LIMIT_PIN_MAX) || defined(A_LIMIT_PIN_MAX) || defined(B_LIMIT_PIN_MAX) || defined(C_LIMIT_PIN_MAX)
578 #define MAX_LIMIT_SWITCHES
579 #endif
580 
581 #ifdef A_AXIS
582 
583 #if A_AXIS == 3
584 #define A_AXIS_IDX 3
585 #elif A_AXIS == 4
586 #define A_AXIS_IDX 4
587 #elif A_AXIS == 4
588 #define A_AXIS_IDX 5
589 #elif A_AXIS == 4
590 #define A_AXIS_IDX 6
591 #elif A_AXIS == 4
592 #define A_AXIS_IDX 7
593 #endif
594 
595 #if A_AXIS_IDX >= N_MOTORS
596  #error "No pins are available for A axis motor"
597 #endif
598 
599 #define A_STEP_PORT MOTOR_IO(A_AXIS_IDX, _STEP_PORT)
600 #define A_STEP_PIN MOTOR_IO(A_AXIS_IDX, _STEP_PIN)
601 #define A_STEP_BIT (1<<A_STEP_PIN)
602 #define A_DIRECTION_PORT MOTOR_IO(A_AXIS_IDX, _DIRECTION_PORT)
603 #define A_DIRECTION_PIN MOTOR_IO(A_AXIS_IDX, _DIRECTION_PIN)
604 #define A_DIRECTION_BIT (1<<A_DIRECTION_PIN)
605 #if mn_has_home(A_MOTOR_IDX)
606  #define A_HOME_PORT MOTOR_IO(A_AXIS_IDX, _HOME_PORT)
607  #define A_HOME_PIN MOTOR_IO(A_AXIS_IDX, _HOME_PIN)
608  #define A_HOME_BIT (1<<A_HOME_PIN)
609 #endif
610 #if mn_has_limit(A_AXIS_IDX)
611  #define A_LIMIT_PORT MOTOR_IO(A_AXIS_IDX, _LIMIT_PORT)
612  #define A_LIMIT_PIN MOTOR_IO(A_AXIS_IDX, _LIMIT_PIN)
613  #define A_LIMIT_BIT (1<<A_LIMIT_PIN)
614 #endif
615 #if mn_has_limit_max(A_AXIS_IDX)
616  #define A_LIMIT_MAX_PORT MOTOR_IO(A_AXIS_IDX, _LIMIT_MAX_PORT)
617  #define A_LIMIT_MAX_PIN MOTOR_IO(A_AXIS_IDX, _LIMIT_MAX_PIN)
618  #define A_LIMIT_MAX_BIT (1<<A_LIMIT_MAX_PIN)
619 #endif
620 #if mn_has_enable(A_AXIS_IDX)
621  #define A_ENABLE_PORT MOTOR_IO(A_AXIS_IDX, _ENABLE_PORT)
622  #define A_ENABLE_PIN MOTOR_IO(A_AXIS_IDX, _ENABLE_PIN)
623  #define A_ENABLE_BIT (1<<A_ENABLE_PIN)
624 #endif
625 #if mn_has_fault(A_AXIS_IDX)
626  #define A_MOTOR_FAULT_PORT MOTOR_IO(A_AXIS_IDX, _MOTOR_FAULT_PORT)
627  #define A_MOTOR_FAULT_PIN MOTOR_IO(A_AXIS_IDX, _MOTOR_FAULT_PIN)
628  #define A_MOTOR_FAULT_BIT (1<<A_MOTOR_FAULT_PIN)
629 #endif
630 
631 #endif // A_AXIS
632 
633 #ifdef B_AXIS
634 
635 #if B_AXIS == 3
636 #define B_AXIS_IDX 3
637 #elif B_AXIS == 4
638 #define B_AXIS_IDX 4
639 #elif B_AXIS == 5
640 #define B_AXIS_IDX 5
641 #elif B_AXIS == 6
642 #define B_AXIS_IDX 6
643 #elif B_AXIS == 7
644 #define B_AXIS_IDX 7
645 #endif
646 
647 #if B_AXIS_IDX >= N_MOTORS
648  #error "No pins are available for B axis motor"
649 #endif
650 
651 #define B_STEP_PORT MOTOR_IO(B_AXIS_IDX, _STEP_PORT)
652 #define B_STEP_PIN MOTOR_IO(B_AXIS_IDX, _STEP_PIN)
653 #define B_STEP_BIT (1<<B_STEP_PIN)
654 #define B_DIRECTION_PORT MOTOR_IO(B_AXIS_IDX, _DIRECTION_PORT)
655 #define B_DIRECTION_PIN MOTOR_IO(B_AXIS_IDX, _DIRECTION_PIN)
656 #define B_DIRECTION_BIT (1<<B_DIRECTION_PIN)
657 #if mn_has_home(B_MOTOR_IDX)
658  #define B_HOME_PORT MOTOR_IO(B_AXIS_IDX, _HOME_PORT)
659  #define B_HOME_PIN MOTOR_IO(B_AXIS_IDX, _HOME_PIN)
660  #define B_HOME_BIT (1<<B_HOME_PIN)
661 #endif
662 #if mn_has_limit(B_AXIS_IDX)
663  #define B_LIMIT_PORT MOTOR_IO(B_AXIS_IDX, _LIMIT_PORT)
664  #define B_LIMIT_PIN MOTOR_IO(B_AXIS_IDX, _LIMIT_PIN)
665  #define B_LIMIT_BIT (1<<B_LIMIT_PIN)
666 #endif
667 #if mn_has_limit_max(B_AXIS_IDX)
668  #define B_LIMIT_MAX_PORT MOTOR_IO(B_AXIS_IDX, _LIMIT_MAX_PORT)
669  #define B_LIMIT_MAX_PIN MOTOR_IO(B_AXIS_IDX, _LIMIT_MAX_PIN)
670  #define B_LIMIT_MAX_BIT (1<<B_LIMIT_MAX_PIN)
671 #endif
672 #if mn_has_enable(B_AXIS_IDX)
673  #define B_ENABLE_PORT MOTOR_IO(B_AXIS_IDX, _ENABLE_PORT)
674  #define B_ENABLE_PIN MOTOR_IO(B_AXIS_IDX, _ENABLE_PIN)
675  #define B_ENABLE_BIT (1<<B_ENABLE_PIN)
676 #endif
677 #if mn_has_fault(B_AXIS_IDX)
678  #define B_MOTOR_FAULT_PORT MOTOR_IO(B_AXIS_IDX, _MOTOR_FAULT_PORT)
679  #define B_MOTOR_FAULT_PIN MOTOR_IO(B_AXIS_IDX, _MOTOR_FAULT_PIN)
680  #define B_MOTOR_FAULT_BIT (1<<B_MOTOR_FAULT_PIN)
681 #endif
682 
683 #endif //B_AXIS
684 
685 #ifdef C_AXIS
686 
687 #if C_AXIS == 3
688 #define C_AXIS_IDX 3
689 #elif C_AXIS == 4
690 #define C_AXIS_IDX 4
691 #elif C_AXIS == 5
692 #define C_AXIS_IDX 5
693 #elif C_AXIS == 6
694 #define C_AXIS_IDX 6
695 #elif C_AXIS == 7
696 #define C_AXIS_IDX 7
697 #endif
698 
699 #if C_AXIS_IDX >= N_MOTORS
700  #error "No pins are available for C axis motor"
701 #endif
702 
703 #define C_STEP_PORT MOTOR_IO(C_AXIS_IDX, _STEP_PORT)
704 #define C_STEP_PIN MOTOR_IO(C_AXIS_IDX, _STEP_PIN)
705 #define C_STEP_BIT (1<<C_STEP_PIN)
706 #define C_DIRECTION_PORT MOTOR_IO(C_AXIS_IDX, _DIRECTION_PORT)
707 #define C_DIRECTION_PIN MOTOR_IO(C_AXIS_IDX, _DIRECTION_PIN)
708 #define C_DIRECTION_BIT (1<<C_DIRECTION_PIN)
709 #if mn_has_home(C_MOTOR_IDX)
710  #define C_HOME_PORT MOTOR_IO(C_AXIS_IDX, _HOME_PORT)
711  #define C_HOME_PIN MOTOR_IO(C_AXIS_IDX, _HOME_PIN)
712  #define C_HOME_BIT (1<<C_HOME_PIN)
713 #endif
714 #if mn_has_limit(C_AXIS_IDX)
715  #define C_LIMIT_PORT MOTOR_IO(C_AXIS_IDX, _LIMIT_PORT)
716  #define C_LIMIT_PIN MOTOR_IO(C_AXIS_IDX, _LIMIT_PIN)
717  #define C_LIMIT_BIT (1<<C_LIMIT_PIN)
718 #endif
719 #if mn_has_limit_max(C_AXIS_IDX)
720  #define C_LIMIT_MAX_PORT MOTOR_IO(C_AXIS_IDX, _LIMIT_MAX_PORT)
721  #define C_LIMIT_MAX_PIN MOTOR_IO(C_AXIS_IDX, _LIMIT_MAX_PIN)
722  #define C_LIMIT_MAX_BIT (1<<C_LIMIT_MAX_PIN)
723 #endif
724 #if mn_has_enable(C_AXIS_IDX)
725  #define C_ENABLE_PORT MOTOR_IO(C_AXIS_IDX, _ENABLE_PORT)
726  #define C_ENABLE_PIN MOTOR_IO(C_AXIS_IDX, _ENABLE_PIN)
727  #define C_ENABLE_BIT (1<<C_ENABLE_PIN)
728 #endif
729 #if mn_has_fault(C_AXIS_IDX)
730  #define C_MOTOR_FAULT_PORT MOTOR_IO(C_AXIS_IDX, _MOTOR_FAULT_PORT)
731  #define C_MOTOR_FAULT_PIN MOTOR_IO(C_AXIS_IDX, _MOTOR_FAULT_PIN)
732  #define C_MOTOR_FAULT_BIT (1<<C_MOTOR_FAULT_PIN)
733 #endif
734 
735 #endif // C_AXIS
736 
737 #ifdef U_AXIS
738 
739 #if U_AXIS == 3
740 #define U_AXIS_IDX 3
741 #elif U_AXIS == 4
742 #define U_AXIS_IDX 4
743 #elif U_AXIS == 5
744 #define U_AXIS_IDX 5
745 #elif U_AXIS == 6
746 #define U_AXIS_IDX 6
747 #elif U_AXIS == 7
748 #define U_AXIS_IDX 7
749 #endif
750 
751 #if U_AXIS_IDX >= N_MOTORS
752  #error "No pins are available for U axis motor"
753 #endif
754 
755 #define U_STEP_PORT MOTOR_IO(U_AXIS_IDX, _STEP_PORT)
756 #define U_STEP_PIN MOTOR_IO(U_AXIS_IDX, _STEP_PIN)
757 #define U_STEP_BIT (1<<U_STEP_PIN)
758 #define U_DIRECTION_PORT MOTOR_IO(U_AXIS_IDX, _DIRECTION_PORT)
759 #define U_DIRECTION_PIN MOTOR_IO(U_AXIS_IDX, _DIRECTION_PIN)
760 #define U_DIRECTION_BIT (1<<U_DIRECTION_PIN)
761 #if mn_has_home(U_MOTOR_IDX)
762  #define U_HOME_PORT MOTOR_IO(U_AXIS_IDX, _HOME_PORT)
763  #define U_HOME_PIN MOTOR_IO(U_AXIS_IDX, _HOME_PIN)
764  #define U_HOME_BIT (1<<U_HOME_PIN)
765 #endif
766 #if mn_has_limit(U_AXIS_IDX)
767  #define U_LIMIT_PORT MOTOR_IO(U_AXIS_IDX, _LIMIT_PORT)
768  #define U_LIMIT_PIN MOTOR_IO(U_AXIS_IDX, _LIMIT_PIN)
769  #define U_LIMIT_BIT (1<<U_LIMIT_PIN)
770 #endif
771 #if mn_has_limit_max(U_AXIS_IDX)
772  #define U_LIMIT_MAX_PORT MOTOR_IO(U_AXIS_IDX, _LIMIT_MAX_PORT)
773  #define U_LIMIT_MAX_PIN MOTOR_IO(U_AXIS_IDX, _LIMIT_MAX_PIN)
774  #define U_LIMIT_MAX_BIT (1<<U_LIMIT_MAX_PIN)
775 #endif
776 #if mn_has_enable(U_AXIS_IDX)
777  #define U_ENABLE_PORT MOTOR_IO(U_AXIS_IDX, _ENABLE_PORT)
778  #define U_ENABLE_PIN MOTOR_IO(U_AXIS_IDX, _ENABLE_PIN)
779  #define U_ENABLE_BIT (1<<U_ENABLE_PIN)
780 #endif
781 #if mn_has_fault(U_AXIS_IDX)
782  #define U_MOTOR_FAULT_PORT MOTOR_IO(U_AXIS_IDX, _MOTOR_FAULT_PORT)
783  #define U_MOTOR_FAULT_PIN MOTOR_IO(U_AXIS_IDX, _MOTOR_FAULT_PIN)
784  #define U_MOTOR_FAULT_BIT (1<<U_MOTOR_FAULT_PIN)
785 #endif
786 
787 #endif // U_AXIS
788 
789 #ifdef V_AXIS
790 
791 #if V_AXIS == 3
792 #define V_AXIS_IDX 3
793 #elif V_AXIS == 4
794 #define V_AXIS_IDX 4
795 #elif V_AXIS == 5
796 #define V_AXIS_IDX 5
797 #elif V_AXIS == 6
798 #define V_AXIS_IDX 6
799 #elif V_AXIS == 7
800 #define V_AXIS_IDX 7
801 #endif
802 
803 #if V_AXIS_IDX >= N_MOTORS
804  #error "No pins are available for V axis motor"
805 #endif
806 
807 #define V_STEP_PORT MOTOR_IO(V_AXIS_IDX, _STEP_PORT)
808 #define V_STEP_PIN MOTOR_IO(V_AXIS_IDX, _STEP_PIN)
809 #define V_STEP_BIT (1<<V_STEP_PIN)
810 #define V_DIRECTION_PORT MOTOR_IO(V_AXIS_IDX, _DIRECTION_PORT)
811 #define V_DIRECTION_PIN MOTOR_IO(V_AXIS_IDX, _DIRECTION_PIN)
812 #define V_DIRECTION_BIT (1<<V_DIRECTION_PIN)
813 #if mn_has_home(V_MOTOR_IDX)
814  #define V_HOME_PORT MOTOR_IO(V_AXIS_IDX, _HOME_PORT)
815  #define V_HOME_PIN MOTOR_IO(V_AXIS_IDX, _HOME_PIN)
816  #define V_HOME_BIT (1<<V_HOME_PIN)
817 #endif
818 #if mn_has_limit(V_AXIS_IDX)
819  #define V_LIMIT_PORT MOTOR_IO(V_AXIS_IDX, _LIMIT_PORT)
820  #define V_LIMIT_PIN MOTOR_IO(V_AXIS_IDX, _LIMIT_PIN)
821  #define V_LIMIT_BIT (1<<V_LIMIT_PIN)
822 #endif
823 #if mn_has_limit_max(V_AXIS_IDX)
824  #define V_LIMIT_MAX_PORT MOTOR_IO(V_AXIS_IDX, _LIMIT_MAX_PORT)
825  #define V_LIMIT_MAX_PIN MOTOR_IO(V_AXIS_IDX, _LIMIT_MAX_PIN)
826  #define V_LIMIT_MAX_BIT (1<<V_LIMIT_MAX_PIN)
827 #endif
828 #if mn_has_enable(V_AXIS_IDX)
829  #define V_ENABLE_PORT MOTOR_IO(V_AXIS_IDX, _ENABLE_PORT)
830  #define V_ENABLE_PIN MOTOR_IO(V_AXIS_IDX, _ENABLE_PIN)
831  #define V_ENABLE_BIT (1<<V_ENABLE_PIN)
832 #endif
833 #if mn_has_fault(V_AXIS_IDX)
834  #define V_MOTOR_FAULT_PORT MOTOR_IO(V_AXIS_IDX, _MOTOR_FAULT_PORT)
835  #define V_MOTOR_FAULT_PIN MOTOR_IO(V_AXIS_IDX, _MOTOR_FAULT_PIN)
836  #define V_MOTOR_FAULT_BIT (1<<V_MOTOR_FAULT_PIN)
837 #endif
838 
839 #endif // V_AXIS
840 
841 #ifdef W_AXIS
842 
843 #if W_AXIS == 3
844 #define W_AXIS_IDX 3
845 #elif W_AXIS == 4
846 #define W_AXIS_IDX 4
847 #elif W_AXIS == 5
848 #define W_AXIS_IDX 5
849 #elif W_AXIS == 6
850 #define W_AXIS_IDX 6
851 #elif W_AXIS == 7
852 #define W_AXIS_IDX 7
853 #endif
854 
855 #if W_AXIS_IDX >= N_MOTORS
856  #error "No pins are available for W axis motor"
857 #endif
858 
859 #define W_STEP_PORT MOTOR_IO(W_AXIS_IDX, _STEP_PORT)
860 #define W_STEP_PIN MOTOR_IO(W_AXIS_IDX, _STEP_PIN)
861 #define W_STEP_BIT (1<<W_STEP_PIN)
862 #define W_DIRECTION_PORT MOTOR_IO(W_AXIS_IDX, _DIRECTION_PORT)
863 #define W_DIRECTION_PIN MOTOR_IO(W_AXIS_IDX, _DIRECTION_PIN)
864 #define W_DIRECTION_BIT (1<<W_DIRECTION_PIN)
865 #if mn_has_home(W_MOTOR_IDX)
866  #define W_HOME_PORT MOTOR_IO(W_AXIS_IDX, _HOME_PORT)
867  #define W_HOME_PIN MOTOR_IO(W_AXIS_IDX, _HOME_PIN)
868  #define W_HOME_BIT (1<<W_HOME_PIN)
869 #endif
870 #if mn_has_limit(W_AXIS_IDX)
871  #define W_LIMIT_PORT MOTOR_IO(W_AXIS_IDX, _LIMIT_PORT)
872  #define W_LIMIT_PIN MOTOR_IO(W_AXIS_IDX, _LIMIT_PIN)
873  #define W_LIMIT_BIT (1<<W_LIMIT_PIN)
874 #endif
875 #if mn_has_limit_max(W_AXIS_IDX)
876  #define W_LIMIT_MAX_PORT MOTOR_IO(W_AXIS_IDX, _LIMIT_MAX_PORT)
877  #define W_LIMIT_MAX_PIN MOTOR_IO(W_AXIS_IDX, _LIMIT_MAX_PIN)
878  #define W_LIMIT_MAX_BIT (1<<W_LIMIT_MAX_PIN)
879 #endif
880 #if mn_has_enable(W_AXIS_IDX)
881  #define W_ENABLE_PORT MOTOR_IO(W_AXIS_IDX, _ENABLE_PORT)
882  #define W_ENABLE_PIN MOTOR_IO(W_AXIS_IDX, _ENABLE_PIN)
883  #define W_ENABLE_BIT (1<<W_ENABLE_PIN)
884 #endif
885 #if mn_has_fault(W_AXIS_IDX)
886  #define W_MOTOR_FAULT_PORT MOTOR_IO(W_AXIS_IDX, _MOTOR_FAULT_PORT)
887  #define W_MOTOR_FAULT_PIN MOTOR_IO(W_AXIS_IDX, _MOTOR_FAULT_PIN)
888  #define W_MOTOR_FAULT_BIT (1<<W_MOTOR_FAULT_PIN)
889 #endif
890 
891 #endif // W axis
892 
893 #ifdef STEP_PORT
894 #ifndef X_STEP_PORT
895 #define X_STEP_PORT STEP_PORT
896 #endif
897 #ifndef Y_STEP_PORT
898 #define Y_STEP_PORT STEP_PORT
899 #endif
900 #ifndef Z_STEP_PORT
901 #define Z_STEP_PORT STEP_PORT
902 #endif
903 #if defined(A_AXIS) && !defined(A_STEP_PORT)
904 #define A_STEP_PORT STEP_PORT
905 #endif
906 #if defined(B_AXIS) && !defined(B_STEP_PORT)
907 #define B_STEP_PORT STEP_PORT
908 #endif
909 #if defined(C_AXIS) && !defined(C_STEP_PORT)
910 #define C_STEP_PORT STEP_PORT
911 #endif
912 #if defined(U_AXIS) && !defined(U_STEP_PORT)
913 #define U_STEP_PORT STEP_PORT
914 #endif
915 #if defined(V_AXIS) && !defined(V_STEP_PORT)
916 #define V_STEP_PORT STEP_PORT
917 #endif
918 #endif
919 
920 #ifndef X_STEP_BIT
921 #define X_STEP_BIT (1<<X_STEP_PIN)
922 #endif
923 #ifndef Y_STEP_BIT
924 #define Y_STEP_BIT (1<<Y_STEP_PIN)
925 #endif
926 #ifndef Z_STEP_BIT
927 #define Z_STEP_BIT (1<<Z_STEP_PIN)
928 #endif
929 
930 #ifdef DIRECTION_PORT
931 #ifndef X_DIRECTION_PORT
932 #define X_DIRECTION_PORT DIRECTION_PORT
933 #endif
934 #ifndef Y_DIRECTION_PORT
935 #define Y_DIRECTION_PORT DIRECTION_PORT
936 #endif
937 #ifndef Z_DIRECTION_PORT
938 #define Z_DIRECTION_PORT DIRECTION_PORT
939 #endif
940 #if defined(A_AXIS) && !defined(A_DIRECTION_PORT)
941 #define A_DIRECTION_PORT DIRECTION_PORT
942 #endif
943 #if defined(B_AXIS) && !defined(B_DIRECTION_PORT)
944 #define B_DIRECTION_PORT DIRECTION_PORT
945 #endif
946 #if defined(C_AXIS) && !defined(C_DIRECTION_PORT)
947 #define C_DIRECTION_PORT DIRECTION_PORT
948 #endif
949 #if defined(U_AXIS) && !defined(U_DIRECTION_PORT)
950 #define U_DIRECTION_PORT DIRECTION_PORT
951 #endif
952 #if defined(V_AXIS) && !defined(V_DIRECTION_PORT)
953 #define V_DIRECTION_PORT DIRECTION_PORT
954 #endif
955 #endif
956 
957 #ifndef X_DIRECTION_BIT
958 #define X_DIRECTION_BIT (1<<X_DIRECTION_PIN)
959 #endif
960 #ifndef Y_DIRECTION_BIT
961 #define Y_DIRECTION_BIT (1<<Y_DIRECTION_PIN)
962 #endif
963 #ifndef Z_DIRECTION_BIT
964 #define Z_DIRECTION_BIT (1<<Z_DIRECTION_PIN)
965 #endif
966 
967 #ifdef LIMIT_PORT
968 #ifndef X_LIMIT_PORT
969 #define X_LIMIT_PORT LIMIT_PORT
970 #endif
971 #ifndef Y_LIMIT_PORT
972 #define Y_LIMIT_PORT LIMIT_PORT
973 #endif
974 #ifndef Z_LIMIT_PORT
975 #define Z_LIMIT_PORT LIMIT_PORT
976 #endif
977 #endif
978 
979 #ifndef X_HOME_BIT
980 #ifdef X_HOME_PIN
981 #define X_HOME_BIT (1<<X_HOME_PIN)
982 #else
983 #define X_HOME_BIT 0
984 #endif
985 #endif
986 #ifndef Y_HOME_BIT
987 #ifdef Y_HOME_PIN
988 #define Y_HOME_BIT (1<<Y_HOME_PIN)
989 #else
990 #define Y_HOME_BIT 0
991 #endif
992 #endif
993 #ifndef Z_HOME_BIT
994 #ifdef Z_HOME_PIN
995 #define Z_HOME_BIT (1<<Z_HOME_PIN)
996 #else
997 #define Z_HOME_BIT 0
998 #endif
999 #endif
1000 
1001 #ifndef X_MOTOR_FAULT_BIT
1002 #ifdef X_MOTOR_FAULT_PIN
1003 #define X_MOTOR_FAULT_BIT (1<<X_MOTOR_FAULT_PIN)
1004 #else
1005 #define X_MOTOR_FAULT_BIT 0
1006 #endif
1007 #endif
1008 #ifndef Y_MOTOR_FAULT_BIT
1009 #ifdef Y_MOTOR_FAULT_PIN
1010 #define Y_MOTOR_FAULT_BIT (1<<Y_MOTOR_FAULT_PIN)
1011 #else
1012 #define Y_MOTOR_FAULT_BIT 0
1013 #endif
1014 #endif
1015 #ifndef Z_MOTOR_FAULT_BIT
1016 #ifdef Z_MOTOR_FAULT_PIN
1017 #define Z_MOTOR_FAULT_BIT (1<<Z_MOTOR_FAULT_PIN)
1018 #else
1019 #define Z_MOTOR_FAULT_BIT 0
1020 #endif
1021 #endif
1022 
1023 #ifndef X_LIMIT_BIT
1024 #define X_LIMIT_BIT (1<<X_LIMIT_PIN)
1025 #endif
1026 #ifndef Y_LIMIT_BIT
1027 #define Y_LIMIT_BIT (1<<Y_LIMIT_PIN)
1028 #endif
1029 #ifndef Z_LIMIT_BIT
1030 #define Z_LIMIT_BIT (1<<Z_LIMIT_PIN)
1031 #endif
1032 #ifndef X_LIMIT_MAX_BIT
1033 #ifdef X_LIMIT_PIN_MAX
1034 #define X_LIMIT_MAX_BIT (1<<X_LIMIT_PIN_MAX)
1035 #else
1036 #define X_LIMIT_MAX_BIT 0
1037 #endif
1038 #endif
1039 #ifndef Y_LIMIT_MAX_BIT
1040 #ifdef Y_LIMIT_PIN_MAX
1041 #define Y_LIMIT_MAX_BIT (1<<Y_LIMIT_PIN_MAX)
1042 #else
1043 #define Y_LIMIT_MAX_BIT 0
1044 #endif
1045 #endif
1046 #ifndef Z_LIMIT_MAX_BIT
1047 #ifdef Z_LIMIT_PIN_MAX
1048 #define Z_LIMIT_MAX_BIT (1<<Z_LIMIT_PIN_MAX)
1049 #else
1050 #define Z_LIMIT_MAX_BIT 0
1051 #endif
1052 #endif
1053 
1054 #define LIMIT_MAX_MASK_BASE (X_LIMIT_MAX_BIT|Y_LIMIT_MAX_BIT|Z_LIMIT_MAX_BIT)
1055 #define LIMIT_MAX_MASK_BASE_SUM (X_LIMIT_MAX_BIT+Y_LIMIT_MAX_BIT+Z_LIMIT_MAX_BIT)
1056 
1057 #if N_AXIS == 3
1058 #define LIMIT_MAX_MASK LIMIT_MAX_MASK_BASE
1059 #define LIMIT_MAX_MASK_SUM LIMIT_MAX_MASK_BASE_SUM
1060 #elif N_AXIS == 4
1061 #define LIMIT_MAX_MASK (LIMIT_MAX_MASK_BASE|M3_LIMIT_MAX_BIT)
1062 #define LIMIT_MAX_MASK_SUM (LIMIT_MAX_MASK_BASE_SUM+M3_LIMIT_MAX_BIT)
1063 #elif N_AXIS == 5
1064 #define LIMIT_MAX_MASK (LIMIT_MAX_MASK_BASE|M3_LIMIT_MAX_BIT|M4_LIMIT_MAX_BIT)
1065 #define LIMIT_MAX_MASK_SUM (LIMIT_MAX_MASK_BASE_SUM+M3_LIMIT_MAX_BIT+M4_LIMIT_MAX_BIT)
1066 #elif N_AXIS == 6
1067 #define LIMIT_MAX_MASK (LIMIT_MAX_MASK_BASE|M3_LIMIT_MAX_BIT|M4_LIMIT_MAX_BIT|M5_LIMIT_MAX_BIT)
1068 #define LIMIT_MAX_MASK_SUM (LIMIT_MAX_MASK_BASE_SUM+M3_LIMIT_MAX_BIT+M4_LIMIT_MAX_BIT+M5_LIMIT_MAX_BIT)
1069 #elif N_AXIS == 7
1070 #define LIMIT_MAX_MASK (LIMIT_MAX_MASK_BASE|M3_LIMIT_MAX_BIT|M4_LIMIT_MAX_BIT|M5_LIMIT_MAX_BIT|M6_LIMIT_MAX_BIT)
1071 #define LIMIT_MAX_MASK_SUM (LIMIT_MAX_MASK_BASE_SUM+M3_LIMIT_MAX_BIT+M4_LIMIT_MAX_BIT+M5_LIMIT_MAX_BIT+M6_LIMIT_MAX_BIT)
1072 #else
1073 #define LIMIT_MAX_MASK (LIMIT_MAX_MASK_BASE|M3_LIMIT_MAX_BIT|M4_LIMIT_MAX_BIT|M5_LIMIT_MAX_BIT|M6_LIMIT_MAX_BIT|M7_LIMIT_MAX_BIT)
1074 #define LIMIT_MAX_MASK_SUM (LIMIT_MAX_MASK_BASE_SUM+M3_LIMIT_MAX_BIT+M4_LIMIT_MAX_BIT+M5_LIMIT_MAX_BIT+M6_LIMIT_MAX_BIT+M7_LIMIT_MAX_BIT)
1075 #endif
1076 
1077 #if !defined(X_ENABLE_BIT) && defined(X_ENABLE_PIN)
1078 #define X_ENABLE_BIT (1<<X_ENABLE_PIN)
1079 #endif
1080 #if !defined(Y_ENABLE_BIT) && defined(Y_ENABLE_PIN)
1081 #define Y_ENABLE_BIT (1<<Y_ENABLE_PIN)
1082 #endif
1083 #if !defined(Z_ENABLE_BIT) && defined(Z_ENABLE_PIN)
1084 #define Z_ENABLE_BIT (1<<Z_ENABLE_PIN)
1085 #endif
1086 
1087 #ifndef STEP_MASK
1088 #if N_AXIS == 3
1089 #define STEP_MASK (X_STEP_BIT|Y_STEP_BIT|Z_STEP_BIT)
1090 #elif N_AXIS == 4
1091 #define STEP_MASK (X_STEP_BIT|Y_STEP_BIT|Z_STEP_BIT|M3_STEP_BIT)
1092 #elif N_AXIS == 5
1093 #define STEP_MASK (X_STEP_BIT|Y_STEP_BIT|Z_STEP_BIT|M3_STEP_BIT|M4_STEP_BIT)
1094 #elif N_AXIS == 6
1095 #define STEP_MASK (X_STEP_BIT|Y_STEP_BIT|Z_STEP_BIT|M3_STEP_BIT|M4_STEP_BIT|M5_STEP_BIT)
1096 #elif N_AXIS == 7
1097 #define STEP_MASK (X_STEP_BIT|Y_STEP_BIT|Z_STEP_BIT|M3_STEP_BIT|M4_STEP_BIT|M5_STEP_BIT|M6_STEP_BIT)
1098 #else
1099 #define STEP_MASK (X_STEP_BIT|Y_STEP_BIT|Z_STEP_BIT|M3_STEP_BIT|M4_STEP_BIT|M5_STEP_BIT|M6_STEP_BIT|M7_STEP_BIT)
1100 #endif
1101 #endif
1102 
1103 #ifndef DIRECTION_MASK
1104 #if N_AXIS == 3
1105 #define DIRECTION_MASK (X_DIRECTION_BIT|Y_DIRECTION_BIT|Z_DIRECTION_BIT)
1106 #elif N_AXIS == 4
1107 #define DIRECTION_MASK (X_DIRECTION_BIT|Y_DIRECTION_BIT|Z_DIRECTION_BIT|M3_DIRECTION_BIT)
1108 #elif N_AXIS == 5
1109 #define DIRECTION_MASK (X_DIRECTION_BIT|Y_DIRECTION_BIT|Z_DIRECTION_BIT|M3_DIRECTION_BIT|M4_DIRECTION_BIT)
1110 #elif N_AXIS == 6
1111 #define DIRECTION_MASK (X_DIRECTION_BIT|Y_DIRECTION_BIT|Z_DIRECTION_BIT|M3_DIRECTION_BIT|M4_DIRECTION_BIT|M5_DIRECTION_BIT)
1112 #elif N_AXIS == 7
1113 #define DIRECTION_MASK (X_DIRECTION_BIT|Y_DIRECTION_BIT|Z_DIRECTION_BIT|M3_DIRECTION_BIT|M4_DIRECTION_BIT|M5_DIRECTION_BIT|M6_DIRECTION_BIT)
1114 #else
1115 #define DIRECTION_MASK (X_DIRECTION_BIT|Y_DIRECTION_BIT|Z_DIRECTION_BIT|M3_DIRECTION_BIT|M4_DIRECTION_BIT|M5_DIRECTION_BIT|M6_DIRECTION_BIT|M7_DIRECTION_BIT)
1116 #endif
1117 #endif
1118 
1119 #if defined(STEPPERS_ENABLE_PIN) && !defined(STEPPERS_ENABLE_BIT)
1120 #define STEPPERS_ENABLE_BIT (1<<STEPPERS_ENABLE_PIN)
1121 #endif
1122 
1123 #ifndef STEPPERS_ENABLE_MASK
1124 
1125 #ifdef STEPPERS_ENABLE_BIT
1126 #define STEPPERS_ENABLE_MASK STEPPERS_ENABLE_BIT
1127 #else
1128 
1129 #if N_AXIS == 3
1130 #define STEPPERS_ENABLE_MASK (X_ENABLE_BIT|Y_ENABLE_BIT|Z_ENABLE_BIT)
1131 #elif N_AXIS == 4
1132 #define STEPPERS_ENABLE_MASK (X_ENABLE_BIT|Y_ENABLE_BIT|Z_ENABLE_BIT|M3_ENABLE_BIT)
1133 #elif N_AXIS == 5
1134 #define STEPPERS_ENABLE_MASK (X_ENABLE_BIT|Y_ENABLE_BIT|Z_ENABLE_BIT|M3_ENABLE_BIT|M4_ENABLE_BIT)
1135 #elif N_AXIS == 6
1136 #define STEPPERS_ENABLE_MASK (X_ENABLE_BIT|Y_ENABLE_BIT|Z_ENABLE_BIT|M3_ENABLE_BIT|M4_ENABLE_BIT|M5_ENABLE_BIT)
1137 #elif N_AXIS == 7
1138 #define STEPPERS_ENABLE_MASK (X_ENABLE_BIT|Y_ENABLE_BIT|Z_ENABLE_BIT|M3_ENABLE_BIT|M4_ENABLE_BIT|M5_ENABLE_BIT|M6_ENABLE_BIT)
1139 #else
1140 #define STEPPERS_ENABLE_MASK (X_ENABLE_BIT|Y_ENABLE_BIT|Z_ENABLE_BIT|M3_ENABLE_BIT|M4_ENABLE_BIT|M5_ENABLE_BIT|M6_ENABLE_BIT|M7_ENABLE_BIT)
1141 #endif
1142 #endif
1143 
1144 #endif // STEPPERS_ENABLE_MASK
1145 
1146 #ifndef HOME_MASK
1147 
1148 #define HOME_MASK_BASE (X_HOME_BIT|Y_HOME_BIT|Z_HOME_BIT|HOME2_MASK)
1149 #define HOME_MASK_BASE_SUM (X_HOME_BIT+Y_HOME_BIT+Z_HOME_BIT+HOME2_MASK_SUM)
1150 
1151 #if N_AXIS == 3
1152 #define HOME_MASK HOME_MASK_BASE
1153 #define HOME_MASK_SUM HOME_MASK_BASE_SUM
1154 #define HOME_MIN_CAP AXES_BITMASK
1155 #elif N_AXIS == 4
1156 #define HOME_MASK (HOME_MASK_BASE|M3_HOME_BIT)
1157 #define HOME_MASK_SUM (HOME_MASK_BASE_SUM+M3_HOME_BIT)
1158 #elif N_AXIS == 5
1159 #define HOME_MASK (HOME_MASK_BASE|M3_HOME_BIT|M4_HOME_BIT)
1160 #define HOME_MASK_SUM (HOME_MASK_BASE_SUM+M3_HOME_BIT+M4_HOME_BIT)
1161 #elif N_AXIS == 6
1162 #define HOME_MASK (HOME_MASK_BASE|M3_HOME_BIT|M4_HOME_BIT|M5_HOME_BIT)
1163 #define HOME_MASK_SUM (HOME_MASK_BASE_SUM+M3_HOME_BIT+M4_HOME_BIT+M5_HOME_BIT)
1164 #elif N_AXIS == 7
1165 #define HOME_MASK (HOME_MASK_BASE|M3_HOME_BIT|M4_HOME_BIT|M5_HOME_BIT|M6_HOME_BIT)
1166 #define HOME_MASK_SUM (HOME_MASK_BASE_SUM+M3_HOME_BIT+M4_HOME_BIT+M5_HOME_BIT+M6_HOME_BIT)
1167 #else
1168 #define HOME_MASK (HOME_MASK_BASE|M3_HOME_BIT|M4_HOME_BIT|M5_HOME_BIT|M6_HOME_BIT|M7_HOME_BIT)
1169 #define HOME_MASK_SUM (HOME_MASK_BASE_SUM+M3_HOME_BIT+M4_HOME_BIT+M5_HOME_BIT+M6_HOME_BIT+M7_HOME_BIT)
1170 #endif
1171 
1172 #endif // HOME_MASK
1173 
1174 #ifndef LIMIT_MASK
1175 
1176 #ifdef Z_LIMIT_POLL
1177 #define LIMIT_MASK_BASE (X_LIMIT_BIT|Y_LIMIT_BIT|LIMIT2_MASK|LIMIT_MAX_MASK)
1178 #define LIMIT_MASK_BASE_SUM (X_LIMIT_BIT+Y_LIMIT_BIT+LIMIT2_MASK_SUM+LIMIT_MAX_SUM)
1179 #else
1180 #define LIMIT_MASK_BASE (X_LIMIT_BIT|Y_LIMIT_BIT|Z_LIMIT_BIT|LIMIT2_MASK|LIMIT_MAX_MASK)
1181 #define LIMIT_MASK_BASE_SUM (X_LIMIT_BIT+Y_LIMIT_BIT+Z_LIMIT_BIT+LIMIT2_MASK_SUM+LIMIT_MAX_MASK_SUM)
1182 #endif
1183 
1184 #if N_AXIS == 3
1185 #define LIMIT_MASK LIMIT_MASK_BASE
1186 #define LIMIT_MASK_SUM LIMIT_MASK_BASE_SUM
1187 #define LIMIT_MIN_CAP AXES_BITMASK
1188 #elif N_AXIS == 4
1189 #define LIMIT_MASK (LIMIT_MASK_BASE|M3_LIMIT_BIT)
1190 #define LIMIT_MASK_SUM (LIMIT_MASK_BASE_SUM+M3_LIMIT_BIT)
1191 #elif N_AXIS == 5
1192 #define LIMIT_MASK (LIMIT_MASK_BASE|M3_LIMIT_BIT|M4_LIMIT_BIT)
1193 #define LIMIT_MASK_SUM (LIMIT_MASK_BASE_SUM+M3_LIMIT_BIT+M4_LIMIT_BIT)
1194 #elif N_AXIS == 6
1195 #define LIMIT_MASK (LIMIT_MASK_BASE|M3_LIMIT_BIT|M4_LIMIT_BIT|M5_LIMIT_BIT)
1196 #define LIMIT_MASK_SUM (LIMIT_MASK_BASE_SUM+M3_LIMIT_BIT+M4_LIMIT_BIT+M5_LIMIT_BIT)
1197 #elif N_AXIS == 7
1198 #define LIMIT_MASK (LIMIT_MASK_BASE|M3_LIMIT_BIT|M4_LIMIT_BIT|M5_LIMIT_BIT|M6_LIMIT_BIT)
1199 #define LIMIT_MASK_SUM (LIMIT_MASK_BASE_SUM+M3_LIMIT_BIT+M4_LIMIT_BIT+M5_LIMIT_BIT+M6_LIMIT_BIT)
1200 #else
1201 #define LIMIT_MASK (LIMIT_MASK_BASE|M3_LIMIT_BIT|M4_LIMIT_BIT|M5_LIMIT_BIT|M6_LIMIT_BIT|M7_LIMIT_BIT)
1202 #define LIMIT_MASK_SUM (LIMIT_MASK_BASE_SUM+M3_LIMIT_BIT+M4_LIMIT_BIT+M5_LIMIT_BIT+M6_LIMIT_BIT+M7_LIMIT_BIT)
1203 #endif
1204 
1205 #endif // LIMIT_MASK
1206 
1207 #ifndef MOTOR_FAULT_MASK
1208 
1209 #define MOTOR_FAULT_MASK_BASE (X_MOTOR_FAULT_BIT|Y_MOTOR_FAULT_BIT|Z_MOTOR_FAULT_BIT|MOTOR_FAULT2_MASK)
1210 #define MOTOR_FAULT_MASK_BASE_SUM (X_MOTOR_FAULT_BIT+Y_MOTOR_FAULT_BIT+Z_MOTOR_FAULT_BIT+MOTOR_FAULT2_MASK_SUM)
1211 
1212 #if N_AXIS == 3
1213 #define MOTOR_FAULT_MASK MOTOR_FAULT_MASK_BASE
1214 #define MOTOR_FAULT_MASK_SUM MOTOR_FAULT_MASK_BASE_SUM
1215 #define MOTOR_FAULT_MIN_CAP AXES_BITMASK
1216 #elif N_AXIS == 4
1217 #define MOTOR_FAULT_MASK (MOTOR_FAULT_MASK_BASE|A_MOTOR_FAULT_BIT)
1218 #define MOTOR_FAULT_MASK_SUM (MOTOR_FAULT_MASK_BASE_SUM+A_MOTOR_FAULT_BIT)
1219 #elif N_AXIS == 5
1220 #define MOTOR_FAULT_MASK (MOTOR_FAULT_MASK_BASE|M3_MOTOR_FAULT_BIT|M4_MOTOR_FAULT_BIT)
1221 #define MOTOR_FAULT_MASK_SUM (MOTOR_FAULT_MASK_BASE_SUM+M3_MOTOR_FAULT_BIT+M4_MOTOR_FAULT_BIT)
1222 #elif N_AXIS == 6
1223 #define MOTOR_FAULT_MASK (MOTOR_FAULT_MASK_BASE|M3_MOTOR_FAULT_BIT|M4_MOTOR_FAULT_BIT|M5_MOTOR_FAULT_BIT)
1224 #define MOTOR_FAULT_MASK_SUM (MOTOR_FAULT_MASK_BASE_SUM+M3_MOTOR_FAULT_BIT+M4_MOTOR_FAULT_BIT+M5_MOTOR_FAULT_BIT)
1225 #elif N_AXIS == 7
1226 #define MOTOR_FAULT_MASK (MOTOR_FAULT_MASK_BASE|M3_MOTOR_FAULT_BIT|M4_MOTOR_FAULT_BIT|M5_MOTOR_FAULT_BIT|M6_MOTOR_FAULT_BIT)
1227 #define MOTOR_FAULT_MASK_SUM (MOTOR_FAULT_MASK_BASE_SUM+M3_MOTOR_FAULT_BIT+M4_MOTOR_FAULT_BIT+M5_MOTOR_FAULT_BIT+M6_MOTOR_FAULT_BIT)
1228 #else
1229 #define MOTOR_FAULT_MASK (MOTOR_FAULT_MASK_BASE|M3_MOTOR_FAULT_BIT|M4_MOTOR_FAULT_BIT|M5_MOTOR_FAULT_BIT|M6_MOTOR_FAULT_BIT|M7_MOTOR_FAULT_BIT)
1230 #define MOTOR_FAULT_MASK_SUM (MOTOR_FAULT_MASK_BASE_SUM+M3_MOTOR_FAULT_BIT+M4_MOTOR_FAULT_BIT+M5_MOTOR_FAULT_BIT+M6_MOTOR_FAULT_BIT+M7_MOTOR_FAULT_BIT)
1231 #endif
1232 
1233 #endif // MOTOR_FAULT_MASK
1234 
1235 #ifndef N_GANGED
1236 #define N_GANGED 0
1237 #endif
1238 
1239 static void motor_iterator (motor_iterator_callback_ptr callback)
1240 {
1241  motor_map_t motor;
1242 
1243  if(callback) for(motor.id = 0; motor.id < N_AXIS + N_GANGED; motor.id++)
1244  {
1245  if(motor.id < N_AXIS)
1246  motor.axis = motor.id;
1247  else switch (motor.id) {
1248 #ifdef X2_MOTOR_IDX
1249  case X2_MOTOR_IDX:
1250  motor.axis = X_AXIS;
1251  break;
1252 #endif
1253 #ifdef Y2_MOTOR_IDX
1254  case Y2_MOTOR_IDX:
1255  motor.axis = Y_AXIS;
1256  break;
1257 #endif
1258 #ifdef Z2_MOTOR_IDX
1259  case Z2_MOTOR_IDX:
1260  motor.axis = Z_AXIS;
1261  break;
1262 #endif
1263  }
1264  callback(motor);
1265  }
1266 }
1267 
1268 static inline limit_signals_t get_limits_cap (void)
1269 {
1270  limit_signals_t limits = {0};
1271 
1272 #if X_LIMIT_BIT
1273  limits.min.x = On;
1274 #endif
1275 #if Y_LIMIT_BIT
1276  limits.min.y = On;
1277 #endif
1278 #if Z_LIMIT_BIT
1279  limits.min.z = On;
1280 #endif
1281 #ifdef A_LIMIT_BIT
1282  limits.min.a = On;
1283 #endif
1284 #ifdef B_LIMIT_BIT
1285  limits.min.b = On;
1286 #endif
1287 #ifdef C_LIMIT_BIT
1288  limits.min.c = On;
1289 #endif
1290 #ifdef U_LIMIT_BIT
1291  limits.min.u = On;
1292 #endif
1293 #ifdef V_LIMIT_BIT
1294  limits.min.v = On;
1295 #endif
1296 
1297 #ifdef X2_LIMIT_BIT
1298  limits.min2.x = On;
1299 #endif
1300 #ifdef Y2_LIMIT_BIT
1301  limits.min2.y = On;
1302 #endif
1303 #ifdef Z2_LIMIT_BIT
1304  limits.min2.z = On;
1305 #endif
1306 
1307 #if X_LIMIT_MAX_BIT
1308  limits.max.x = On;
1309 #endif
1310 #if Y_LIMIT_MAX_BIT
1311  limits.max.y = On;
1312 #endif
1313 #if Z_LIMIT_MAX_BIT
1314  limits.max.z = On;
1315 #endif
1316 #ifdef A_LIMIT_MAX_BIT
1317  limits.max.a = On;
1318 #endif
1319 #ifdef B_LIMIT_MAX_BIT
1320  limits.max.b = On;
1321 #endif
1322 #ifdef C_LIMIT_MAX_BIT
1323  limits.max.c = On;
1324 #endif
1325 #ifdef U_LIMIT_MAX_BIT
1326  limits.max.u = On;
1327 #endif
1328 #ifdef V_LIMIT_MAX_BIT
1329  limits.max.v = On;
1330 #endif
1331 
1332  return limits;
1333 }
1334 
1335 static inline home_signals_t get_home_cap (void)
1336 {
1337  home_signals_t home = {0};
1338 
1339 #if HOME_MASK
1340 
1341 #if X_HOME_BIT
1342  home.a.x = On;
1343 #endif
1344 #if Y_HOME_BIT
1345  home.a.y = On;
1346 #endif
1347 #if Z_HOME_BIT
1348  home.a.z = On;
1349 #endif
1350 #ifdef A_HOME_BIT
1351  home.a.a = On;
1352 #endif
1353 #ifdef B_HOME_BIT
1354  home.a.b = On;
1355 #endif
1356 #ifdef C_HOME_BIT
1357  home.a.c = On;
1358 #endif
1359 #if U_HOME_BIT
1360  home.a.u = On;
1361 #endif
1362 #ifdef V_HOME_BIT
1363  home.a.v = On;
1364 #endif
1365 
1366 #ifdef X2_HOME_BIT
1367  home.b.x = On;
1368 #endif
1369 #ifdef Y2_HOME_BIT
1370  home.b.y = On;
1371 #endif
1372 #ifdef Z2_HOME_BIT
1373  home.b.z = On;
1374 #endif
1375 
1376 #endif // HOME_MASK
1377 
1378  return home;
1379 }
1380 
1381 static inline home_signals_t get_motor_fault_cap (void)
1382 {
1383  home_signals_t motor_fault = {0};
1384 
1385 #if MOTOR_FAULT_MASK
1386 
1387 #if X_MOTOR_FAULT_BIT
1388  motor_fault.a.x = On;
1389 #endif
1390 #if Y_MOTOR_FAULT_BIT
1391  motor_fault.a.y = On;
1392 #endif
1393 #if Z_MOTOR_FAULT_BIT
1394  motor_fault.a.z = On;
1395 #endif
1396 #ifdef A_MOTOR_FAULT_BIT
1397  motor_fault.a.a = On;
1398 #endif
1399 #ifdef B_MOTOR_FAULT_BIT
1400  motor_fault.a.b = On;
1401 #endif
1402 #ifdef C_MOTOR_FAULT_BIT
1403  motor_fault.a.c = On;
1404 #endif
1405 #ifdef U_MOTOR_FAULT_BIT
1406  motor_fault.a.u = On;
1407 #endif
1408 #ifdef V_MOTOR_FAULT_BIT
1409  motor_fault.a.v = On;
1410 #endif
1411 
1412 #ifdef X2_MOTOR_FAULT_BIT
1413  motor_fault.b.x = On;
1414 #endif
1415 #ifdef Y2_MOTOR_FAULT_BIT
1416  motor_fault.b.y = On;
1417 #endif
1418 #ifdef Z2_MOTOR_FAULT_BIT
1419  motor_fault.b.z = On;
1420 #endif
1421 
1422 #endif // MOTOR_FAULT_MASK
1423 
1424  return motor_fault;
1425 }
1426 
1427 #ifdef __GNUC__
1428 #pragma GCC diagnostic pop
1429 #endif
1430 
1431 /*EOF*/
#define N_AXIS
Defines number of axes supported - minimum 3, maximum 8. If more than 3 axes are configured a complia...
Definition: config.h:42
void(* motor_iterator_callback_ptr)(motor_map_t motor)
Signature of the callback function to receive motor vs. axis mappings.
Definition: hal.h:230
#define N_GANGED
Definition: motor_pins.h:1236
#define X_AXIS
Definition: nuts_bolts.h:71
#define Z_AXIS
Definition: nuts_bolts.h:73
#define On
Definition: nuts_bolts.h:36
#define Y_AXIS
Definition: nuts_bolts.h:72
Home switches struct, consists of two packed axes_signals_t structs.
Definition: nuts_bolts.h:396
axes_signals_t a
Primary home switches status, optional. Limit signals are used for homing if not available.
Definition: nuts_bolts.h:397
axes_signals_t b
Secondary home switch(es) status, required for auto squaring enabled axes if primary switches are ava...
Definition: nuts_bolts.h:398
uint8_t x
Definition: nuts_bolts.h:251
uint8_t y
Definition: nuts_bolts.h:252
uint8_t z
Definition: nuts_bolts.h:274
Limit switches struct, consists of four packed axes_signals_t structs in 32 bits.
Definition: nuts_bolts.h:385
axes_signals_t min
Min limit switches status, required.
Definition: nuts_bolts.h:388
axes_signals_t min2
Secondary min limit switch(es) status, required for auto squaring enabled axes.
Definition: nuts_bolts.h:390
axes_signals_t max
Max limit switches status, optional.
Definition: nuts_bolts.h:389
Motor vs. axis mapping NOTE: id and axis values are equal for primary motors, unequal for secondary (...
Definition: hal.h:219
uint32_t axis
Definition: hal.h:223
uint32_t id
Definition: hal.h:222