32 lines
612 B
C
32 lines
612 B
C
|
#pragma once
|
||
|
|
||
|
#include <avr/io.h>
|
||
|
|
||
|
|
||
|
#if defined __AVR_ATmega328P__
|
||
|
#define SPI_DDR DDRB
|
||
|
#define SPI_PORT PORTB
|
||
|
#define SPI_SCK PB5
|
||
|
#define SPI_MISO PB4
|
||
|
#define SPI_MOSI PB3
|
||
|
#define SPI_CS PB2
|
||
|
#elif defined __AVR_ATmega32__ || defined __AVR_ATmega16__
|
||
|
#define SPI_PORT PORTB
|
||
|
#define SPI_DDR DDRB
|
||
|
#define SPI_SCK PB7
|
||
|
#define SPI_MOSI PB5
|
||
|
#define SPI_CS PB4
|
||
|
#endif
|
||
|
|
||
|
namespace spi
|
||
|
{
|
||
|
void init();
|
||
|
uint8_t transfer(uint8_t data);
|
||
|
|
||
|
inline void cs_low() {SPI_PORT &= ~(1<<SPI_CS);}
|
||
|
|
||
|
inline void cs_high() {SPI_PORT |= (1<<SPI_CS);}
|
||
|
} // namespace spi
|
||
|
|
||
|
|