From d2fcc57ed4a19df5d997f3582359ffa669d2ffc9 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Wed, 12 Aug 2015 13:51:58 +0200 Subject: [PATCH] Introduce #ifdef SPI. It's better to separate this by function than by usage. --- config_wrapper.h | 7 +++++++ cpu-avr.c | 4 ++-- mendel.c | 2 +- simulator/spi_sim.c | 4 ++++ spi.c | 6 +++--- spi.h | 7 ++++--- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/config_wrapper.h b/config_wrapper.h index 6f2b77a..249f51b 100644 --- a/config_wrapper.h +++ b/config_wrapper.h @@ -34,6 +34,13 @@ #undef BAUD #endif +/** + Check wether we need SPI. +*/ +#if (defined SD_CARD_SELECT_PIN || defined TEMP_MAX6675) && ! defined SIMULATOR + #define SPI +#endif + /** ACCELERATION_TEMPORAL doesn't support lookahead, yet. */ diff --git a/cpu-avr.c b/cpu-avr.c index 9d4ff4c..d617d96 100644 --- a/cpu-avr.c +++ b/cpu-avr.c @@ -18,13 +18,13 @@ */ void cpu_init() { #ifdef PRR - #if defined TEMP_MAX6675 || defined SD + #if defined SPI PRR = MASK(PRTWI) | MASK(PRADC); #else PRR = MASK(PRTWI) | MASK(PRADC) | MASK(PRSPI); #endif #elif defined PRR0 - #if defined TEMP_MAX6675 || defined SD + #if defined SPI PRR0 = MASK(PRTWI) | MASK(PRADC); #else PRR0 = MASK(PRTWI) | MASK(PRADC) | MASK(PRSPI); diff --git a/mendel.c b/mendel.c index 93c20cc..9e8966f 100644 --- a/mendel.c +++ b/mendel.c @@ -89,7 +89,7 @@ void init(void) { pinio_init(); #ifndef __ARMEL_NOTYET__ - #if defined TEMP_MAX6675 || defined SD + #if defined SPI spi_init(); #endif #endif /* __ARMEL_NOTYET__ */ diff --git a/simulator/spi_sim.c b/simulator/spi_sim.c index d1f50ef..168f4e4 100644 --- a/simulator/spi_sim.c +++ b/simulator/spi_sim.c @@ -5,5 +5,9 @@ #include "spi.h" #include "arduino.h" +#ifdef SPI + void spi_init() { } + +#endif /* SPI */ diff --git a/spi.c b/spi.c index e072b3c..8ba46f5 100644 --- a/spi.c +++ b/spi.c @@ -13,9 +13,7 @@ */ #include "spi.h" -#include "arduino.h" -#include "pinio.h" - +#ifdef SPI /** Initialise serial subsystem. @@ -44,3 +42,5 @@ void spi_init() { // This sets the whole SPRC register. spi_speed_100_400(); } + +#endif /* SPI */ diff --git a/spi.h b/spi.h index 2f37de0..73c4a57 100644 --- a/spi.h +++ b/spi.h @@ -5,6 +5,8 @@ #include "arduino.h" #include "pinio.h" +#ifdef SPI + // Uncomment this to double SPI frequency from (F_CPU / 4) to (F_CPU / 2). //#define SPI_2X @@ -13,8 +15,6 @@ */ void spi_init(void); -#ifndef SIMULATOR /* Avoid inlining code on simulator. */ - /** SPI device selection. Because out famous WRITE() macro works with constant pins, only, we define @@ -102,5 +102,6 @@ inline uint8_t spi_rw(uint8_t byte) { return SPDR; } -#endif /* SIMULATOR */ +#endif /* SPI */ + #endif /* _SPI_H */