From 7223c9dea8873fa81660ce0490fcf9c19f131306 Mon Sep 17 00:00:00 2001 From: Nico Tonnhofer Date: Sat, 17 Sep 2016 21:23:47 +0200 Subject: [PATCH] ARM: split out spi-avr.c from spi.c --- spi-avr.c | 36 ++++++++++++++++++++++++++++++++++++ spi.c | 35 +++++++---------------------------- 2 files changed, 43 insertions(+), 28 deletions(-) create mode 100644 spi-avr.c diff --git a/spi-avr.c b/spi-avr.c new file mode 100644 index 0000000..4dad025 --- /dev/null +++ b/spi-avr.c @@ -0,0 +1,36 @@ + +/** \file + \brief SPI routines, AVR specific part. +*/ + +#if defined TEACUP_C_INCLUDE && defined __AVR__ + +/** Initialise SPI subsystem. + + Code copied from ATmega164/324/644/1284 data sheet, section 18.2, page 160, + or moved here from mendel.c. +*/ +void spi_init() { + + // Set SCK (clock) and MOSI line to output, ie. set USART in master mode. + SET_OUTPUT(SCK); + SET_OUTPUT(MOSI); + SET_INPUT(MISO); + // SS must be set as output to disconnect it from the SPI subsystem. + // Too bad if something else tries to use this pin as digital input. + // See ATmega164/324/644/1284 data sheet, section 18.3.2, page 162. + // Not written there: this must apparently be done before setting the SPRC + // register, else future R/W-operations may hang. + SET_OUTPUT(SS); + + #ifdef SPI_2X + SPSR = 0x01; + #else + SPSR = 0x00; + #endif + + // This sets the whole SPRC register. + spi_speed_100_400(); +} + +#endif /* defined TEACUP_C_INCLUDE && defined __AVR__ */ diff --git a/spi.c b/spi.c index e1f1fdd..b634b18 100644 --- a/spi.c +++ b/spi.c @@ -1,4 +1,3 @@ - /** \file \brief SPI subsystem @@ -11,36 +10,16 @@ happens before reading and writing, data exchange its self is the same for each device, then. */ + #include "spi.h" #ifdef SPI -/** Initialise SPI subsystem. - - Code copied from ATmega164/324/644/1284 data sheet, section 18.2, page 160, - or moved here from mendel.c. -*/ -void spi_init() { - - // Set SCK (clock) and MOSI line to output, ie. set USART in master mode. - SET_OUTPUT(SCK); - SET_OUTPUT(MOSI); - SET_INPUT(MISO); - // SS must be set as output to disconnect it from the SPI subsystem. - // Too bad if something else tries to use this pin as digital input. - // See ATmega164/324/644/1284 data sheet, section 18.3.2, page 162. - // Not written there: this must apparently be done before setting the SPRC - // register, else future R/W-operations may hang. - SET_OUTPUT(SS); - - #ifdef SPI_2X - SPSR = 0x01; - #else - SPSR = 0x00; - #endif - - // This sets the whole SPRC register. - spi_speed_100_400(); -} +#define TEACUP_C_INCLUDE +#include "spi-avr.c" +// Each ARM needs it's own file +// #include "spi-lpc.c" +// #include "spi-stm32.c" +#undef TEACUP_C_INCLUDE #endif /* SPI */