b15f/firmware/spi.h

49 lines
818 B
C
Raw Normal View History

2019-03-25 12:00:22 +00:00
#ifndef SPI_H
#define SPI_H
2019-03-22 14:51:52 +00:00
#include <util/delay.h>
2019-03-26 07:44:30 +00:00
#include <avr/io.h>
2019-03-25 12:00:22 +00:00
#include <stdint.h>
2019-03-25 08:57:38 +00:00
2019-03-26 07:44:30 +00:00
#define SLSL PB4
#define MOSI PB5
#define MISO PB6
#define SCLK PB7
2019-03-22 14:51:52 +00:00
2019-03-26 07:44:30 +00:00
#define DMUX1 PD2
#define DMUX2 PD3
#define DMUX3 PD4
2019-03-25 12:00:22 +00:00
enum SPIADR {
2019-04-03 09:38:15 +00:00
AA0 = 0,
AA1 = 1,
BEBA0 = 2,
BEBA1 = 3,
EXT = 4,
2019-03-25 14:02:24 +00:00
SWITCH = 5,
2019-04-03 09:38:15 +00:00
NONE = 7,
2019-03-25 12:00:22 +00:00
};
class SPI
{
public:
2019-03-25 08:57:38 +00:00
SPI(void);
2019-04-03 06:40:14 +00:00
void init(void) const volatile;
2019-04-03 09:38:15 +00:00
void handleTransfer() volatile;
void transfer(uint8_t adr) volatile;
void addByte(uint8_t b) volatile;
void wait(void) volatile;
constexpr static uint8_t BUFFER_SIZE = 8;
volatile uint8_t buffer[BUFFER_SIZE];
2019-03-22 14:51:52 +00:00
2019-04-03 09:38:15 +00:00
private:
void setAdr(uint8_t) const volatile;
volatile uint8_t index = 0;
volatile uint8_t length = 0;
volatile bool active = false;
2019-03-22 14:51:52 +00:00
};
2019-03-25 12:00:22 +00:00
#endif // SPI_H