Removed an unnecessary sleep from r0ketbeam. Added support for 7 segment
[cerebrum.git] / spi.h
blob7deb5fd392efc399c3130c01449c78f6fec05bcf
1 /*
2 Copyright (C) 2012 jaseg <s@jaseg.de>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 3 as published by the Free Software Foundation.
7 */
9 #ifndef __SPI_H__
10 #define __SPI_H__
12 #include <avr/io.h>
14 #define SPI_MOSI_PORT PORTB
15 #define SPI_MOSI_DDR DDRB
16 #define SPI_MOSI_PIN 2
18 #define SPI_SCK_PORT PORTB
19 #define SPI_SCK_DDR DDRB
20 #define SPI_SCK_PIN 1
22 void spi_begin(void);
24 void spi_end(void);
26 void spi_setup(uint8_t config);
27 #define SPI_MSBFIRST 0
28 #define SPI_LSBFIRST _BV(DORD)
29 #define SPI_MODE0 0
30 #define SPI_MODE1 _BV(CPHA)
31 #define SPI_MODE2 _BV(CPOL)
32 #define SPI_MODE3 (_BV(CPHA) | _BV(CPOL))
33 //To avoid passing more than 1 byte to the setup function, the SPI2X bit is mapped onto the SPE bit here
34 #define SPI_CLOCK_DIV2 _BV(SPE)
35 #define SPI_CLOCK_DIV4 0
36 #define SPI_CLOCK_DIV8 (_BV(SPE) | _BV(SPR0))
37 #define SPI_CLOCK_DIV16 _BV(SPR0)
38 #define SPI_CLOCK_DIV32 (_BV(SPE) | _BV(SPR1))
39 #define SPI_CLOCK_DIV64 _BV(SPR1)
40 #define SPI_CLOCK_DIV128 (_BV(SPR1) | _BV(SPR0))
42 uint8_t spi_transfer(uint8_t data);
44 #endif//__SPI_H__