From 401d8ce02e0638f96d66b9ac1f0b43219b2d20d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sat, 14 Mar 2015 11:37:43 +0100 Subject: SPI implemented !NOT TESTED! SPI for spi hardware implemented, but newer tested yet! --- spi.h | 21 +++++++++++++++++++++ src/avr5/spi.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 spi.h create mode 100644 src/avr5/spi.c diff --git a/spi.h b/spi.h new file mode 100644 index 0000000..acee3b5 --- /dev/null +++ b/spi.h @@ -0,0 +1,21 @@ +#include +#include + +#include "mcu/mcu.h" + +#ifndef _IOE_SPI_H_ +#define _IOE_SPI_H_ + +inline void ioe_spi_init(void); +inline int ioe_spi_ready(void); +inline void ioe_spi_join(void); +#ifdef IOE_SPI_MASTER +inline int8_t ioe_spi_transfer(int8_t data); +#else /* IOE_SPI_MASTER */ +inline void ioe_spi_expose(int8_t data); +#endif /* IOE_SPI_MASTER */ + +// Following function must be user defined +inline void ioe_spi_retrieve(int8_t); + +#endif /* _IOE_SPI_H_ */ diff --git a/src/avr5/spi.c b/src/avr5/spi.c new file mode 100644 index 0000000..bc026ef --- /dev/null +++ b/src/avr5/spi.c @@ -0,0 +1,47 @@ +#include "../../spi.h" + +#if __AVR_ARCH__ == 5 + +inline void ioe_spi_join(void) { + // TODO +} + +#ifdef IOE_SPI_MASTER +inline void ioe_spi_init(void) { + // Set MOSI and SCK output, all other input + DDR_SPI = _BV(DD_MOSI) | _BV(DD_SCLK); + // Enable interrupt + SPCR |= _BV(SPIE); + // Enable SPI master and set clock rate fck/16 + SPCR = _BV(SPE) | _BV(MSTR) | _BV(SPR0); +} + +inline int ioe_spi_ready(void) { + // TODO +} + +inline void ioe_spi_transfer(int8_t data) { + SPDR = data; +} + +#else /* IOE_SPI_MASTER */ +inline void ioe_spi_init(void) { + // Set MISO as output, all other input + DDR_SPI = _BV(DD_MISO); + // Enable interrupt + SPCR |= _BV(SPIE); + // Enable SPI + SPCR = _BV(SPE); +} + +inline void ioe_spi_expose(int8_t data) { + SPDR = data; +} + +#endif /* IOE_SPI_MASTER */ + +SIGNAL(SPI_STC_vect) { + ioe_spi_retrieve(SPDR); +} + +#endif /* __AVR_ARCH__ == 5 */ -- cgit v1.2.3