Introduce #ifdef SPI.

It's better to separate this by function than by usage.
This commit is contained in:
Markus Hitter 2015-08-12 13:51:58 +02:00
parent 274f6c954b
commit d2fcc57ed4
6 changed files with 21 additions and 9 deletions

View File

@ -34,6 +34,13 @@
#undef BAUD #undef BAUD
#endif #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. ACCELERATION_TEMPORAL doesn't support lookahead, yet.
*/ */

View File

@ -18,13 +18,13 @@
*/ */
void cpu_init() { void cpu_init() {
#ifdef PRR #ifdef PRR
#if defined TEMP_MAX6675 || defined SD #if defined SPI
PRR = MASK(PRTWI) | MASK(PRADC); PRR = MASK(PRTWI) | MASK(PRADC);
#else #else
PRR = MASK(PRTWI) | MASK(PRADC) | MASK(PRSPI); PRR = MASK(PRTWI) | MASK(PRADC) | MASK(PRSPI);
#endif #endif
#elif defined PRR0 #elif defined PRR0
#if defined TEMP_MAX6675 || defined SD #if defined SPI
PRR0 = MASK(PRTWI) | MASK(PRADC); PRR0 = MASK(PRTWI) | MASK(PRADC);
#else #else
PRR0 = MASK(PRTWI) | MASK(PRADC) | MASK(PRSPI); PRR0 = MASK(PRTWI) | MASK(PRADC) | MASK(PRSPI);

View File

@ -89,7 +89,7 @@ void init(void) {
pinio_init(); pinio_init();
#ifndef __ARMEL_NOTYET__ #ifndef __ARMEL_NOTYET__
#if defined TEMP_MAX6675 || defined SD #if defined SPI
spi_init(); spi_init();
#endif #endif
#endif /* __ARMEL_NOTYET__ */ #endif /* __ARMEL_NOTYET__ */

View File

@ -5,5 +5,9 @@
#include "spi.h" #include "spi.h"
#include "arduino.h" #include "arduino.h"
#ifdef SPI
void spi_init() { void spi_init() {
} }
#endif /* SPI */

6
spi.c
View File

@ -13,9 +13,7 @@
*/ */
#include "spi.h" #include "spi.h"
#include "arduino.h" #ifdef SPI
#include "pinio.h"
/** Initialise serial subsystem. /** Initialise serial subsystem.
@ -44,3 +42,5 @@ void spi_init() {
// This sets the whole SPRC register. // This sets the whole SPRC register.
spi_speed_100_400(); spi_speed_100_400();
} }
#endif /* SPI */

7
spi.h
View File

@ -5,6 +5,8 @@
#include "arduino.h" #include "arduino.h"
#include "pinio.h" #include "pinio.h"
#ifdef SPI
// Uncomment this to double SPI frequency from (F_CPU / 4) to (F_CPU / 2). // Uncomment this to double SPI frequency from (F_CPU / 4) to (F_CPU / 2).
//#define SPI_2X //#define SPI_2X
@ -13,8 +15,6 @@
*/ */
void spi_init(void); void spi_init(void);
#ifndef SIMULATOR /* Avoid inlining code on simulator. */
/** SPI device selection. /** SPI device selection.
Because out famous WRITE() macro works with constant pins, only, we define 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; return SPDR;
} }
#endif /* SIMULATOR */ #endif /* SPI */
#endif /* _SPI_H */ #endif /* _SPI_H */