|
@@ -39,6 +39,46 @@
|
39
|
39
|
// Clock speed factor
|
40
|
40
|
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000UL) // 16 or 20
|
41
|
41
|
|
|
42
|
+// Highly granular delays for step pulses, etc.
|
|
43
|
+#define DELAY_0_NOP NOOP
|
|
44
|
+#define DELAY_1_NOP __asm__("nop\n\t")
|
|
45
|
+#define DELAY_2_NOP DELAY_1_NOP; DELAY_1_NOP
|
|
46
|
+#define DELAY_3_NOP DELAY_1_NOP; DELAY_2_NOP
|
|
47
|
+#define DELAY_4_NOP DELAY_1_NOP; DELAY_3_NOP
|
|
48
|
+#define DELAY_5_NOP DELAY_1_NOP; DELAY_4_NOP
|
|
49
|
+
|
|
50
|
+#define DELAY_NOPS(X) \
|
|
51
|
+ switch (X) { \
|
|
52
|
+ case 20: DELAY_1_NOP; case 19: DELAY_1_NOP; \
|
|
53
|
+ case 18: DELAY_1_NOP; case 17: DELAY_1_NOP; \
|
|
54
|
+ case 16: DELAY_1_NOP; case 15: DELAY_1_NOP; \
|
|
55
|
+ case 14: DELAY_1_NOP; case 13: DELAY_1_NOP; \
|
|
56
|
+ case 12: DELAY_1_NOP; case 11: DELAY_1_NOP; \
|
|
57
|
+ case 10: DELAY_1_NOP; case 9: DELAY_1_NOP; \
|
|
58
|
+ case 8: DELAY_1_NOP; case 7: DELAY_1_NOP; \
|
|
59
|
+ case 6: DELAY_1_NOP; case 5: DELAY_1_NOP; \
|
|
60
|
+ case 4: DELAY_1_NOP; case 3: DELAY_1_NOP; \
|
|
61
|
+ case 2: DELAY_1_NOP; case 1: DELAY_1_NOP; \
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+#define DELAY_10_NOP DELAY_5_NOP; DELAY_5_NOP
|
|
65
|
+#define DELAY_20_NOP DELAY_10_NOP; DELAY_10_NOP
|
|
66
|
+
|
|
67
|
+#if CYCLES_PER_MICROSECOND == 16
|
|
68
|
+ #define DELAY_1US DELAY_10_NOP; DELAY_5_NOP; DELAY_1_NOP
|
|
69
|
+#else
|
|
70
|
+ #define DELAY_1US DELAY_20_NOP
|
|
71
|
+#endif
|
|
72
|
+#define DELAY_2US DELAY_1US; DELAY_1US
|
|
73
|
+#define DELAY_3US DELAY_1US; DELAY_2US
|
|
74
|
+#define DELAY_4US DELAY_1US; DELAY_3US
|
|
75
|
+#define DELAY_5US DELAY_1US; DELAY_4US
|
|
76
|
+#define DELAY_6US DELAY_1US; DELAY_5US
|
|
77
|
+#define DELAY_7US DELAY_1US; DELAY_6US
|
|
78
|
+#define DELAY_8US DELAY_1US; DELAY_7US
|
|
79
|
+#define DELAY_9US DELAY_1US; DELAY_8US
|
|
80
|
+#define DELAY_10US DELAY_1US; DELAY_9US
|
|
81
|
+
|
42
|
82
|
// Remove compiler warning on an unused variable
|
43
|
83
|
#define UNUSED(x) (void) (x)
|
44
|
84
|
|