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.
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
26 void spi_setup(uint8_t config
);
27 #define SPI_MSBFIRST 0
28 #define SPI_LSBFIRST _BV(DORD)
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
);