Skip to content

Commit 231fb54

Browse files
committed
SPI pins are defined in newer version of Arduino
See: arduino/Arduino#4814
1 parent 238c269 commit 231fb54

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

usbhost.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,19 @@ template< typename SPI_CLK, typename SPI_MOSI, typename SPI_MISO, typename SPI_S
8585
};
8686

8787
/* SPI pin definitions. see avrpins.h */
88-
#if defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
88+
#if defined(PIN_SPI_SCK) && defined(PIN_SPI_MOSI) && defined(PIN_SPI_MISO) && defined(PIN_SPI_SS)
89+
// Use pin defines: https://github.com/arduino/Arduino/pull/4814
90+
// Based on: https://www.mikeash.com/pyblog/friday-qa-2015-03-20-preprocessor-abuse-and-optional-parentheses.html
91+
#define NOTHING_EXTRACT
92+
#define EXTRACT(...) EXTRACT __VA_ARGS__
93+
#define PASTE(x, ...) x ## __VA_ARGS__
94+
#define EVALUATING_PASTE(x, ...) PASTE(x, __VA_ARGS__)
95+
#define UNPAREN(x) EVALUATING_PASTE(NOTHING_, EXTRACT x)
96+
#define APPEND_PIN(pin) P ## pin // Appends the pin to 'P', e.g. 1 becomes P1
97+
#define MAKE_PIN(x) EVALUATING_PASTE(APPEND_, PIN(UNPAREN(x)))
98+
typedef SPi< MAKE_PIN(PIN_SPI_SCK), MAKE_PIN(PIN_SPI_MOSI), MAKE_PIN(PIN_SPI_MISO), MAKE_PIN(PIN_SPI_SS) > spi;
99+
#undef MAKE_PIN
100+
#elif defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
89101
typedef SPi< Pb1, Pb2, Pb3, Pb0 > spi;
90102
#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
91103
typedef SPi< Pb5, Pb3, Pb4, Pb2 > spi;

0 commit comments

Comments
 (0)