Intial commit

This commit is contained in:
2020-12-11 10:17:19 +13:00
parent 9024442baa
commit 1c89ad2ea0
16 changed files with 900 additions and 0 deletions

31
src/spi.h Normal file
View File

@@ -0,0 +1,31 @@
#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