Skip to content

Commit 694b1d2

Browse files
committed
Make SPI interrupt handlers weak and fix example ambiguity
- Add __attribute__((weak)) to all SPI interrupt handlers (SERCOM4, SPI1, etc) This allows variants to override them when SERCOM is used for other peripherals (e.g., MKR variants use SERCOM4 for Serial2/UART) - Explicitly cast slave addresses to uint8_t in Wire examples to avoid any potential overload resolution issues on different compiler versions
1 parent 12f886b commit 694b1d2

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

libraries/SPI/SPI.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ void SPIClass::detachInterrupt() {
364364
#ifndef SPI_IT_HANDLER
365365
#define SPI_IT_HANDLER SERCOM4_Handler
366366
#endif
367+
void SPI_IT_HANDLER(void) __attribute__ ((weak));
367368
void SPI_IT_HANDLER(void) { SPI.onService(); }
368369

369370
#if defined(__SAMD51__)
@@ -373,6 +374,10 @@ void SPIClass::detachInterrupt() {
373374
#define SPI_IT_HANDLER_2 SERCOM4_2_Handler
374375
#define SPI_IT_HANDLER_3 SERCOM4_3_Handler
375376
#endif
377+
void SPI_IT_HANDLER_0(void) __attribute__ ((weak));
378+
void SPI_IT_HANDLER_1(void) __attribute__ ((weak));
379+
void SPI_IT_HANDLER_2(void) __attribute__ ((weak));
380+
void SPI_IT_HANDLER_3(void) __attribute__ ((weak));
376381
void SPI_IT_HANDLER_0(void) { SPI.onService(); }
377382
void SPI_IT_HANDLER_1(void) { SPI.onService(); }
378383
void SPI_IT_HANDLER_2(void) { SPI.onService(); }
@@ -383,10 +388,15 @@ void SPIClass::detachInterrupt() {
383388
SPIClass SPI1(&PERIPH_SPI1, PIN_SPI1_MISO, PIN_SPI1_SCK, PIN_SPI1_MOSI, PAD_SPI1_TX, PAD_SPI1_RX);
384389

385390
#if defined(SPI1_IT_HANDLER)
391+
void SPI1_IT_HANDLER(void) __attribute__ ((weak));
386392
void SPI1_IT_HANDLER(void) { SPI1.onService(); }
387393
#endif
388394

389395
#if defined(__SAMD51__) && defined(SPI1_IT_HANDLER_0)
396+
void SPI1_IT_HANDLER_0(void) __attribute__ ((weak));
397+
void SPI1_IT_HANDLER_1(void) __attribute__ ((weak));
398+
void SPI1_IT_HANDLER_2(void) __attribute__ ((weak));
399+
void SPI1_IT_HANDLER_3(void) __attribute__ ((weak));
390400
void SPI1_IT_HANDLER_0(void) { SPI1.onService(); }
391401
void SPI1_IT_HANDLER_1(void) { SPI1.onService(); }
392402
void SPI1_IT_HANDLER_2(void) { SPI1.onService(); }

libraries/Wire/examples/slave_receiver/slave_receiver.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
void setup()
1616
{
17-
Wire.begin(4); // join i2c bus with address #4
17+
Wire.begin((uint8_t)4); // join i2c bus with address #4
1818
Wire.onReceive(receiveEvent); // register event
1919
Serial.begin(9600); // start serial for output
2020
}

libraries/Wire/examples/slave_sender/slave_sender.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
void setup()
1616
{
17-
Wire.begin(2); // join i2c bus with address #2
17+
Wire.begin((uint8_t)2); // join i2c bus with address #2
1818
Wire.onRequest(requestEvent); // register event
1919
}
2020

0 commit comments

Comments
 (0)