|
@@ -11,59 +11,61 @@
|
11
|
11
|
#ifdef DEBUG
|
12
|
12
|
|
13
|
13
|
// Arduino D3 = PD3
|
14
|
|
-#define SCK_on PORTD |= PD3
|
15
|
|
-#define SCK_off PORTD &= ~(PD3)
|
|
14
|
+#define SCK_on PORTD |= (1 << PD3)
|
|
15
|
+#define SCK_off PORTD &= ~(1 << PD3)
|
16
|
16
|
#define SCK_dir DDRD |= (1 << PD3)
|
17
|
17
|
|
18
|
|
-// Arduino D2 = PD2
|
19
|
|
-#define MO_on PORTD |= PD2
|
20
|
|
-#define MO_off PORTD &= ~(PD2)
|
21
|
|
-#define MO_dir DDRD &= ~(1 << PD2)
|
|
18
|
+// Arduino D7 = PD7
|
|
19
|
+#define MO_on PORTD |= (1 << PD7)
|
|
20
|
+#define MO_off PORTD &= ~(1 << PD7)
|
|
21
|
+#define MO_dir DDRD |= (1 << PD7)
|
22
|
22
|
|
23
|
23
|
// Arduino D8 = PB0
|
24
|
|
-#define CS_on PORTB |= PB0
|
25
|
|
-#define CS_off PORTB &= ~(PB0)
|
|
24
|
+#define CS_on PORTB |= (1 << PB0)
|
|
25
|
+#define CS_off PORTB &= ~(1 << PB0)
|
26
|
26
|
#define CS_dir DDRB |= (1 << PB0)
|
27
|
27
|
|
28
|
|
-// Arduino D7 = PD7
|
29
|
|
-#define MI_1 (PIND & PD7) == PD7
|
30
|
|
-#define MI_0 (PIND & PD7) != PD7
|
31
|
|
-#define MI_dir DDRD |= (1 << PD7)
|
|
28
|
+// Arduino D2 = PD2
|
|
29
|
+#define MI_1 (PIND & (1 << PD2)) != 0
|
|
30
|
+#define MI_0 (PIND & (1 << PD2)) == 0
|
|
31
|
+#define MI_dir DDRD &= ~(1 << PD2); PORTD |= (1 << PD2)
|
32
|
32
|
|
33
|
33
|
// Arduino D9 = PB1
|
34
|
|
-#define GDO_1 (PINB & PB1) == PB1
|
35
|
|
-#define GDO_0 (PINB & PB1) != PB1
|
36
|
|
-#define GDO_dir DDRB &= ~(1 << PB1)
|
|
34
|
+#define GDO_1 (PINB & (1 << PB1)) != 0
|
|
35
|
+#define GDO_0 (PINB & (1 << PB1)) == 0
|
|
36
|
+#define GDO_dir DDRB &= ~(1 << PB1); PORTB |= (1 << PB1)
|
37
|
37
|
|
38
|
38
|
#else
|
39
|
39
|
|
40
|
|
-#define SCK_on PORTB |= PB4
|
41
|
|
-#define SCK_off PORTB &= ~(PB4)
|
|
40
|
+#define SCK_on PORTB |= (1 << PB4)
|
|
41
|
+#define SCK_off PORTB &= ~(1 << PB4)
|
42
|
42
|
#define SCK_dir DDRB |= (1 << PB4)
|
43
|
43
|
|
44
|
|
-#define MO_on PORTB |= PB3
|
45
|
|
-#define MO_off PORTB &= ~(PB3)
|
46
|
|
-#define MO_dir DDRB &= ~(1 << PB3)
|
|
44
|
+#define MO_on PORTB |= (1 << PB2)
|
|
45
|
+#define MO_off PORTB &= ~(1 << PB2)
|
|
46
|
+#define MO_dir DDRB |= (1 << PB2)
|
47
|
47
|
|
48
|
|
-#define CS_on PORTB |= PB1
|
49
|
|
-#define CS_off PORTB &= ~(PB1)
|
|
48
|
+#define CS_on PORTB |= (1 << PB1)
|
|
49
|
+#define CS_off PORTB &= ~(1 << PB1)
|
50
|
50
|
#define CS_dir DDRB |= (1 << PB1)
|
51
|
51
|
|
52
|
|
-#define MI_1 (PINB & PB2) == PB2
|
53
|
|
-#define MI_0 (PINB & PB2) != PB2
|
54
|
|
-#define MI_dir DDRB |= (1 << PB2)
|
|
52
|
+#define MI_1 (PINB & (1 << PB3)) != 0
|
|
53
|
+#define MI_0 (PINB & (1 << PB3)) == 0
|
|
54
|
+#define MI_dir DDRB &= ~(1 << PB3); PORTB |= (1 << PB3)
|
55
|
55
|
|
56
|
|
-#define GDO_1 (PINB & PB0) == PB0
|
57
|
|
-#define GDO_0 (PINB & PB0) != PB0
|
58
|
|
-#define GDO_dir DDRB &= ~(1 << PB0)
|
|
56
|
+#define GDO_1 (PINB & (1 << PB0)) != 0
|
|
57
|
+#define GDO_0 (PINB & (1 << PB0)) == 0
|
|
58
|
+#define GDO_dir DDRB &= ~(1 << PB0); PORTB |= (1 << PB0)
|
59
|
59
|
|
60
|
60
|
#endif
|
61
|
61
|
|
62
|
62
|
#define NOP() __asm__ __volatile__("nop")
|
63
|
63
|
|
64
|
64
|
void spiInit(void);
|
65
|
|
-void spiWrite(uint8_t command);
|
66
|
|
-uint8_t spiRead(void);
|
|
65
|
+uint8_t spiReadWrite(uint8_t command);
|
|
66
|
+
|
|
67
|
+#define spiWrite(x) spiReadWrite(x)
|
|
68
|
+#define spiRead() spiReadWrite(0)
|
67
|
69
|
|
68
|
70
|
#endif
|
69
|
71
|
|