33 lines
543 B
C++
33 lines
543 B
C++
#pragma once
|
|
|
|
#include <avr/io.h>
|
|
|
|
|
|
|
|
#define SPI_PORT PORTB
|
|
#define SPI_DDR DDRB
|
|
#define SPI_SCK PB7
|
|
#define SPI_MOSI PB5
|
|
#define SPI_CS PB4
|
|
|
|
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
|
|
|
|
|
|
class SPI {
|
|
public:
|
|
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);}
|
|
};
|
|
|
|
extern SPI s; |