equal
deleted
inserted
replaced
|
1 #ifndef QMSK_SPI_H |
|
2 #define QMSK_SPI_H |
|
3 |
|
4 #include "stdlib.h" |
|
5 #include "port.h" |
|
6 |
|
7 static ioport_t *const SPI_DDR = &DDRB; |
|
8 static ioport_t *const SPI_PORT = &PORTB; |
|
9 |
|
10 static const byte SPI_SCK = PORTB5; |
|
11 static const byte SPI_MISO = PORTB4; |
|
12 static const byte SPI_MOSI = PORTB3; |
|
13 static const byte SPI_SS = PORTB2; |
|
14 |
|
15 enum spi_dord { |
|
16 SPI_DORD_MSB = 0b0, |
|
17 |
|
18 SPI_DORD = SPI_DORD_MSB |
|
19 }; |
|
20 |
|
21 enum spi_cpol { |
|
22 SPI_CPOL_0 = 0b0, |
|
23 SPI_CPOL_1 = 0b1, |
|
24 |
|
25 SPI_CPOL = SPI_CPOL_1 // mode 3 |
|
26 }; |
|
27 |
|
28 enum spi_cpha { |
|
29 SPI_CPHA_0 = 0b0, |
|
30 SPI_CPHA_1 = 0b1, |
|
31 |
|
32 SPI_CPHA = SPI_CPHA_1 // mode 3 |
|
33 }; |
|
34 |
|
35 enum spi_clock { |
|
36 SPI_CLOCK_4 = 0b000, |
|
37 SPI_CLOCK_16 = 0b001, |
|
38 SPI_CLOCK_64 = 0b010, |
|
39 SPI_CLOCK_128 = 0b011, |
|
40 |
|
41 SPI_CLOCK = SPI_CLOCK_16 |
|
42 }; |
|
43 |
|
44 #define SPI_COUNT 2 |
|
45 |
|
46 /* |
|
47 * Initialize in SPI master mode. |
|
48 */ |
|
49 void spi_init (); |
|
50 |
|
51 /* |
|
52 * Write out value, and return read value. |
|
53 */ |
|
54 byte spi_readwrite (byte value); |
|
55 |
|
56 /* |
|
57 * Perform an SPI bus update. |
|
58 */ |
|
59 void spi_update (); |
|
60 |
|
61 void spi_set (byte index, byte value); |
|
62 |
|
63 byte spi_get (byte index); |
|
64 |
|
65 #endif |