#ifndef __SPI_H
#define __SPI_H

#include "spi_proto.h"

#include "spi_config.h"


// copied/adapted from usbdrv.h
#define SPI_CONCAT(a, b)            a ## b

#define SPI_OUTPORT(name)           SPI_CONCAT(PORT, name)
#define SPI_INPORT(name)            SPI_CONCAT(PIN, name)
#define SPI_DDRPORT(name)           SPI_CONCAT(DDR, name)

#define SPI_SSOUT SPI_OUTPORT(SPI_SS_PORT)
#define SPI_SSIN SPI_INPORT(SPI_SS_PORT)
#define SPI_SSDDR SPI_DDRPORT(SPI_SS_PORT)

void spi_init();
void spi_mst_start_packet();
void spi_mst_end_packet();
void spi_mst_write(uint8_t len, uint8_t *data);
void spi_mst_read(uint8_t len, uint8_t *data);
void spi_mst_write_read(uint8_t len, uint8_t *data);
void spi_sla_handle_packet();


#endif
