spiport.h 1.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/*
 * spiport.h
 *
 * Created: 2/7/2018 10:51:52 AM
 *  Author: Jake
 */ 


#ifndef SPIPORT_H_
#define SPIPORT_H_

#include "sam.h"

// TODO: cleaning settings / init values for prettiness, ease of use on variable devices

typedef struct{
	Sercom *com;
	PortGroup *port;
	
	uint32_t miso_pin;
	uint32_t miso_bm;
	uint32_t mosi_pin;
	uint32_t mosi_bm;
	uint32_t sck_pin;
	uint32_t sck_bm;
	uint32_t csn_pin;
	uint32_t csn_bm;
	
	uint32_t apbx;
	uint32_t peripheral;
	uint32_t baud;
}spiport_t;

spiport_t spi_new(Sercom *com, PortGroup *port, uint32_t miso_pin, uint32_t mosi_pin, uint32_t sck_pin, uint32_t csn_pin, uint32_t apbx, uint32_t peripheral);

void spi_init(spiport_t *spi, uint32_t gclknum, uint32_t gclkidcore, uint8_t baud, uint8_t dipo, uint8_t dopo, uint8_t csnhardware, uint8_t cpha, uint8_t cpol, uint8_t lsbfirst); // bits: 0: 8, 1: 32

void spi_txchar_polled(spiport_t *spi, uint8_t data);
void spi_txchars_polled(spiport_t *spi, uint8_t *data, uint8_t length);
Jake Read's avatar
Jake Read committed
40 41
void spi_txrxchar_polled(spiport_t *spi, uint8_t data, uint8_t *rxdata); // not implemented, use
void spi_txrxchars_polled(spiport_t *spi, uint8_t *data_tx, uint8_t length, uint8_t *data_rx);
42 43

#endif /* SPIPORT_H_ */