Skip to content

Commit 4568471

Browse files
committed
Made multiple SPI instances fully configurable from variant
1 parent 90e234f commit 4568471

File tree

2 files changed

+46
-18
lines changed

2 files changed

+46
-18
lines changed

libraries/SPI/SPI.cpp

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -219,22 +219,35 @@ void SPIClass::detachInterrupt() {
219219
}
220220

221221
#if SPI_INTERFACES_COUNT > 0
222+
/* In case new variant doesn't define these macros,
223+
* we put here the ones for Arduino Zero.
224+
*
225+
* These values should be different on some variants!
226+
*
227+
* The SPI PAD values can be found in cores/arduino/SERCOM.h:
228+
* - SercomSpiTXPad
229+
* - SercomRXPad
230+
*/
231+
#ifndef PERIPH_SPI
232+
#define PERIPH_SPI sercom4
233+
#define PAD_SPI_TX SPI_PAD_2_SCK_3
234+
#define PAD_SPI_RX SERCOM_RX_PAD_0
235+
#endif // PERIPH_SPI
236+
SPIClass SPI (&PERIPH_SPI, PIN_SPI_MISO, PIN_SPI_SCK, PIN_SPI_MOSI, PAD_SPI_TX, PAD_SPI_RX);
237+
#endif
238+
#if SPI_INTERFACES_COUNT > 1
239+
SPIClass SPI1(&PERIPH_SPI1, PIN_SPI1_MISO, PIN_SPI1_SCK, PIN_SPI1_MOSI, PAD_SPI1_TX, PAD_SPI1_RX);
240+
#endif
241+
#if SPI_INTERFACES_COUNT > 2
242+
SPIClass SPI2(&PERIPH_SPI2, PIN_SPI2_MISO, PIN_SPI2_SCK, PIN_SPI2_MOSI, PAD_SPI2_TX, PAD_SPI2_RX);
243+
#endif
244+
#if SPI_INTERFACES_COUNT > 3
245+
SPIClass SPI3(&PERIPH_SPI3, PIN_SPI3_MISO, PIN_SPI3_SCK, PIN_SPI3_MOSI, PAD_SPI3_TX, PAD_SPI3_RX);
246+
#endif
247+
#if SPI_INTERFACES_COUNT > 4
248+
SPIClass SPI4(&PERIPH_SPI4, PIN_SPI4_MISO, PIN_SPI4_SCK, PIN_SPI4_MOSI, PAD_SPI4_TX, PAD_SPI4_RX);
249+
#endif
250+
#if SPI_INTERFACES_COUNT > 5
251+
SPIClass SPI5(&PERIPH_SPI5, PIN_SPI5_MISO, PIN_SPI5_SCK, PIN_SPI5_MOSI, PAD_SPI5_TX, PAD_SPI5_RX);
252+
#endif
222253

223-
/* In case new variant doesn't define these macros,
224-
* we put here the ones for Arduino Zero.
225-
*
226-
* These values should be different on some variants!
227-
*
228-
* The SPI PAD values can be found in cores/arduino/SERCOM.h:
229-
* - SercomSpiTXPad
230-
* - SercomRXPad
231-
*/
232-
#ifndef PERIPH_SPI
233-
#define PERIPH_SPI sercom4
234-
#define PAD_SPI_TX SPI_PAD_2_SCK_3
235-
#define PAD_SPI_RX SERCOM_RX_PAD_0
236-
#endif // PERIPH_SPI
237-
238-
SPIClass SPI( &PERIPH_SPI, PIN_SPI_MISO, PIN_SPI_SCK, PIN_SPI_MOSI, PAD_SPI_TX, PAD_SPI_RX );
239-
240-
#endif // SPI_INTERFACES_COUNT > 0

libraries/SPI/SPI.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,21 @@ void SPIClass::transfer(void *buf, size_t count)
143143
#if SPI_INTERFACES_COUNT > 0
144144
extern SPIClass SPI;
145145
#endif
146+
#if SPI_INTERFACES_COUNT > 1
147+
extern SPIClass SPI1;
148+
#endif
149+
#if SPI_INTERFACES_COUNT > 2
150+
extern SPIClass SPI2;
151+
#endif
152+
#if SPI_INTERFACES_COUNT > 3
153+
extern SPIClass SPI3;
154+
#endif
155+
#if SPI_INTERFACES_COUNT > 4
156+
extern SPIClass SPI4;
157+
#endif
158+
#if SPI_INTERFACES_COUNT > 5
159+
extern SPIClass SPI5;
160+
#endif
146161

147162
// For compatibility with sketches designed for AVR @ 16 MHz
148163
// New programs should use SPI.beginTransaction to set the SPI clock

0 commit comments

Comments
 (0)