Contiki 2.5
stepper-steps.h
1 #include <AT91SAM7S64.h>
2 
3 #ifndef MAX
4 #define MIN(a,b) (((a) > (b)) ? (b) : (a))
5 #endif
6 
7 /* Pins for stepper 0 */
8 #define STEPPER0_I00 AT91C_PIO_PA17
9 #define STEPPER0_I01 AT91C_PIO_PA18
10 #define STEPPER0_PHASE0 AT91C_PIO_PA19
11 
12 #define STEPPER0_I10 AT91C_PIO_PA21
13 #define STEPPER0_I11 AT91C_PIO_PA22
14 #define STEPPER0_PHASE1 AT91C_PIO_PA23
15 
16 /* Pins for stepper 1 */
17 #define STEPPER1_I00 AT91C_PIO_PA24
18 #define STEPPER1_I01 AT91C_PIO_PA25
19 #define STEPPER1_PHASE0 AT91C_PIO_PA26
20 
21 #define STEPPER1_I10 AT91C_PIO_PA27
22 #define STEPPER1_I11 AT91C_PIO_PA28
23 #define STEPPER1_PHASE1 AT91C_PIO_PA29
24 
25 /* Common pins */
26 #define STEPPER_INHIBIT AT91C_PIO_PA7
27 
28 
29 #define STEPPER_IOMASK(s) (STEPPER##s##_I00 | STEPPER##s##_I01 | STEPPER##s##_PHASE0 \
30  | STEPPER##s##_I10 | STEPPER##s##_I11 | STEPPER##s##_PHASE1)
31 #define STEPPER_PHASE(s,p,l) ((((l) < 2) ? (STEPPER##s##_I##p##1) : 0) | (((l) & 1) ? 0 : (STEPPER##s##_I##p##0)))
32 
33 #define STEPPER_STEP(s, l0, l1) (\
34 ((l0 >= 0) ? STEPPER_PHASE(s,0, l0):(STEPPER_PHASE(s,0, -(l0))|STEPPER##s##_PHASE0)) | \
35 ((l1 >= 0) ? STEPPER_PHASE(s,1, l1):(STEPPER_PHASE(s,1,-(l1))|STEPPER##s##_PHASE1)))
36 
37 
38 #define FULL_STEP_BOTH(s,l) {\
39  STEPPER_STEP(s,(l),(l)), \
40  STEPPER_STEP(s,(l),-(l)), \
41  STEPPER_STEP(s,-(l),-(l)), \
42  STEPPER_STEP(s,-(l),(l))}
43 
44 
45 #define FULL_STEP_SINGLE(s,l) {\
46  STEPPER_STEP(s,0,(l)), \
47  STEPPER_STEP(s,(l),0), \
48  STEPPER_STEP(s,0,-(l)), \
49  STEPPER_STEP(s,-(l),0)}
50 
51 #define HALF_STEP(s,l) {\
52  STEPPER_STEP(s,0,(l)), \
53  STEPPER_STEP(s,(l),(l)), \
54  STEPPER_STEP(s,(l),0), \
55  STEPPER_STEP(s,(l),-(l)), \
56  STEPPER_STEP(s,0,-(l)), \
57  STEPPER_STEP(s,-(l),-(l)), \
58  STEPPER_STEP(s,-(l),0), \
59  STEPPER_STEP(s,-(l),(l))}
60 
61 
62 #define MINI_STEP(s,l) {\
63  STEPPER_STEP(s,0,(l)), \
64  STEPPER_STEP(s,1,MIN((l),2)), \
65  STEPPER_STEP(s,MIN((l),2),1), \
66  STEPPER_STEP(s,(l),0), \
67  STEPPER_STEP(s,MIN((l),2),-1), \
68  STEPPER_STEP(s,1,-MIN((l),2)), \
69  STEPPER_STEP(s,0,-(l)), \
70  STEPPER_STEP(s,-1,-MIN((l),2)), \
71  STEPPER_STEP(s,-MIN((l),2),-1), \
72  STEPPER_STEP(s,-(l),0), \
73  STEPPER_STEP(s,-MIN((l),2),1), \
74  STEPPER_STEP(s,-1,MIN((l),2))}
75 
76 #define MICRO_STEP(s,l) {\
77  STEPPER_STEP(s,0,(l)), \
78  STEPPER_STEP(s,1,(l)), \
79  STEPPER_STEP(s,MIN((l),2),(l)), \
80  STEPPER_STEP(s,(l),(l)), \
81  STEPPER_STEP(s,(l),MIN((l),2)), \
82  STEPPER_STEP(s,(l),1), \
83  STEPPER_STEP(s,(l),0), \
84  STEPPER_STEP(s,(l),-1), \
85  STEPPER_STEP(s,(l),-MIN((l),2)), \
86  STEPPER_STEP(s,(l),-(l)), \
87  STEPPER_STEP(s,MIN((l),2),-(l)), \
88  STEPPER_STEP(s,1,-(l)), \
89  STEPPER_STEP(s,0,-(l)), \
90  STEPPER_STEP(s,-1,-(l)), \
91  STEPPER_STEP(s,-MIN((l),2),-(l)), \
92  STEPPER_STEP(s,-(l),-(l)), \
93  STEPPER_STEP(s,-(l),-MIN((l),2)), \
94  STEPPER_STEP(s,-(l),-1), \
95  STEPPER_STEP(s,-(l),0), \
96  STEPPER_STEP(s,-(l),1), \
97  STEPPER_STEP(s,-(l),MIN((l),2)), \
98  STEPPER_STEP(s,-(l),(l)), \
99  STEPPER_STEP(s,-MIN((l),2),(l)), \
100  STEPPER_STEP(s,-1,(l))}
101 
102 #define STEPPER_ENABLE() (*AT91C_PIOA_SODR = STEPPER_INHIBIT)
103 #define STEPPER_DISABLE() (*AT91C_PIOA_CODR = STEPPER_INHIBIT)