Browse Source

Simplified pin definitions

Thomas Buck 8 years ago
parent
commit
fc041c00ea
2 changed files with 35 additions and 33 deletions
  1. 29
    19
      include/spi.h
  2. 6
    14
      src/spi.c

+ 29
- 19
include/spi.h View File

10
 
10
 
11
 #ifdef DEBUG
11
 #ifdef DEBUG
12
 
12
 
13
-// Arduino D2
14
-#define SCK_on PORTD |= PD2
15
-#define SCK_off PORTD &= ~(PD2)
16
-
17
-// Arduino D4
18
-#define MO_on PORTD |= PD4
19
-#define MO_off PORTD &= ~(PD4)
20
-
21
-// Arduino D7
22
-#define CS_on PORTD |= PD7
23
-#define CS_off PORTD &= ~(PD7)
24
-
25
-// Arduino D8
26
-#define MI_1 (PINB & PB0) == PB0
27
-#define MI_0 (PINB & PB0) != PB0
28
-
29
-// Arduino D12
30
-#define GDO_1 (PINB & PB4) == PB4
31
-#define GDO_0 (PINB & PB4) != PB4
13
+// Arduino D3 = PD3
14
+#define SCK_on PORTD |= PD3
15
+#define SCK_off PORTD &= ~(PD3)
16
+#define SCK_dir DDRD |= (1 << PD3)
17
+
18
+// Arduino D2 = PD2
19
+#define MO_on PORTD |= PD2
20
+#define MO_off PORTD &= ~(PD2)
21
+#define MO_dir DDRD &= ~(1 << PD2)
22
+
23
+// Arduino D8 = PB0
24
+#define CS_on PORTB |= PB0
25
+#define CS_off PORTB &= ~(PB0)
26
+#define CS_dir DDRB |= (1 << PB0)
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)
32
+
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)
32
 
37
 
33
 #else
38
 #else
34
 
39
 
35
 #define SCK_on PORTB |= PB4
40
 #define SCK_on PORTB |= PB4
36
 #define SCK_off PORTB &= ~(PB4)
41
 #define SCK_off PORTB &= ~(PB4)
42
+#define SCK_dir DDRB |= (1 << PB4)
37
 
43
 
38
 #define MO_on PORTB |= PB3
44
 #define MO_on PORTB |= PB3
39
 #define MO_off PORTB &= ~(PB3)
45
 #define MO_off PORTB &= ~(PB3)
46
+#define MO_dir DDRB &= ~(1 << PB3)
40
 
47
 
41
 #define CS_on PORTB |= PB1
48
 #define CS_on PORTB |= PB1
42
 #define CS_off PORTB &= ~(PB1)
49
 #define CS_off PORTB &= ~(PB1)
50
+#define CS_dir DDRB |= (1 << PB1)
43
 
51
 
44
 #define MI_1 (PINB & PB2) == PB2
52
 #define MI_1 (PINB & PB2) == PB2
45
 #define MI_0 (PINB & PB2) != PB2
53
 #define MI_0 (PINB & PB2) != PB2
54
+#define MI_dir DDRB |= (1 << PB2)
46
 
55
 
47
 #define GDO_1 (PINB & PB0) == PB0
56
 #define GDO_1 (PINB & PB0) == PB0
48
 #define GDO_0 (PINB & PB0) != PB0
57
 #define GDO_0 (PINB & PB0) != PB0
58
+#define GDO_dir DDRB &= ~(1 << PB0)
49
 
59
 
50
 #endif
60
 #endif
51
 
61
 

+ 6
- 14
src/spi.c View File

5
 #include "spi.h"
5
 #include "spi.h"
6
 
6
 
7
 void spiInit(void) {
7
 void spiInit(void) {
8
-#ifdef DEBUG
9
-    DDRB |= (1 << PB0);  // SI output
10
-    DDRD &= ~(1 << PD4); // SO input
11
-    DDRD |= (1 << PD2);  // SCLK output
12
-    DDRD |= (1 << PD7);  // CS output
13
-    DDRB &= ~(1 << PB4); // GDO0 input
14
-#else
15
-    DDRB |= (1 << PB2);  // SI output
16
-    DDRB &= ~(1 << PB3); // SO input
17
-    DDRB |= (1 << PB4);  // SCLK output
18
-    DDRB |= (1 << PB1);  // CS output
19
-    DDRB &= ~(1 << PB0); // GDO0 input
20
-#endif
8
+    MI_dir;
9
+    MO_dir;
10
+    SCK_dir;
11
+    CS_dir;
12
+    GDO_dir;
21
 
13
 
22
     SCK_off;
14
     SCK_off;
23
     MO_off;
15
     MO_off;
25
 }
17
 }
26
 
18
 
27
 void spiWrite(uint8_t command) {
19
 void spiWrite(uint8_t command) {
28
-    SCK_off; //SCK start low
20
+    SCK_off;
29
     MO_off;
21
     MO_off;
30
 
22
 
31
     uint8_t n = 8;
23
     uint8_t n = 8;

Loading…
Cancel
Save