Skip to content

Commit 7fbd665

Browse files
committed
[zero] Bring more customization to SPI class
1 parent a780f1f commit 7fbd665

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

libraries/SPI/SPI.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,20 @@
2828

2929
const SPISettings DEFAULT_SPI_SETTINGS = SPISettings();
3030

31-
SPIClass::SPIClass(SERCOM *p_sercom, uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI)
31+
SPIClass::SPIClass(SERCOM *p_sercom, uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI, SercomSpiTXPad PadTx, SercomRXPad PadRx)
3232
{
3333
initialized = false;
3434
assert(p_sercom != NULL);
3535
_p_sercom = p_sercom;
3636

37+
// pins
3738
_uc_pinMiso = uc_pinMISO;
3839
_uc_pinSCK = uc_pinSCK;
3940
_uc_pinMosi = uc_pinMOSI;
41+
42+
// SERCOM pads
43+
_padTx=PadTx;
44+
_padRx=PadRx;
4045
}
4146

4247
void SPIClass::begin()
@@ -65,7 +70,7 @@ void SPIClass::config(SPISettings settings)
6570
{
6671
_p_sercom->disableSPI();
6772

68-
_p_sercom->initSPI(SPI_PAD_2_SCK_3, SERCOM_RX_PAD_0, SPI_CHAR_SIZE_8_BITS, settings.bitOrder);
73+
_p_sercom->initSPI(_padTx, _padRx, SPI_CHAR_SIZE_8_BITS, settings.bitOrder);
6974
_p_sercom->initSPIClock(settings.dataMode, settings.clockFreq);
7075

7176
_p_sercom->enableSPI();
@@ -197,4 +202,8 @@ void SPIClass::detachInterrupt() {
197202
// Should be disableInterrupt()
198203
}
199204

200-
SPIClass SPI( &sercom4, PIN_SPI_MISO, PIN_SPI_SCK, PIN_SPI_MOSI );
205+
#if SPI_INTERFACES_COUNT > 0
206+
207+
SPIClass SPI( &PERIPH_SPI, PIN_SPI_MISO, PIN_SPI_SCK, PIN_SPI_MOSI, PAD_SPI_TX, PAD_SPI_RX );
208+
209+
#endif // SPI_INTERFACES_COUNT > 0

libraries/SPI/SPI.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ class SPISettings {
9191

9292
class SPIClass {
9393
public:
94-
SPIClass(SERCOM *p_sercom, uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI);
94+
SPIClass(SERCOM *p_sercom, uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI, SercomSpiTXPad, SercomRXPad);
95+
9596

9697
byte transfer(uint8_t data);
9798
inline void transfer(void *buf, size_t count);
@@ -120,6 +121,10 @@ class SPIClass {
120121
uint8_t _uc_pinMiso;
121122
uint8_t _uc_pinMosi;
122123
uint8_t _uc_pinSCK;
124+
125+
SercomSpiTXPad _padTx;
126+
SercomRXPad _padRx;
127+
123128
bool initialized;
124129
uint8_t interruptMode;
125130
char interruptSave;

0 commit comments

Comments
 (0)