Skip to content

Commit 872da13

Browse files
committed
[avr] Added SPI.notUsingInterrupt() (Andrew Kroll)
1 parent 6f71582 commit 872da13

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

hardware/arduino/avr/libraries/SPI/SPI.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,44 @@ void SPIClass::usingInterrupt(uint8_t interruptNumber)
141141
SREG = sreg;
142142
}
143143

144+
void SPIClass::notUsingInterrupt(uint8_t interruptNumber)
145+
{
146+
uint8_t mask = 0;
147+
uint8_t sreg = SREG;
148+
noInterrupts(); // Protect from a scheduler and prevent transactionBegin
149+
switch (interruptNumber) {
150+
#ifdef SPI_INT0_MASK
151+
case 0: mask = SPI_INT0_MASK; break;
152+
#endif
153+
#ifdef SPI_INT1_MASK
154+
case 1: mask = SPI_INT1_MASK; break;
155+
#endif
156+
#ifdef SPI_INT2_MASK
157+
case 2: mask = SPI_INT2_MASK; break;
158+
#endif
159+
#ifdef SPI_INT3_MASK
160+
case 3: mask = SPI_INT3_MASK; break;
161+
#endif
162+
#ifdef SPI_INT4_MASK
163+
case 4: mask = SPI_INT4_MASK; break;
164+
#endif
165+
#ifdef SPI_INT5_MASK
166+
case 5: mask = SPI_INT5_MASK; break;
167+
#endif
168+
#ifdef SPI_INT6_MASK
169+
case 6: mask = SPI_INT6_MASK; break;
170+
#endif
171+
#ifdef SPI_INT7_MASK
172+
case 7: mask = SPI_INT7_MASK; break;
173+
#endif
174+
default:
175+
if (interruptMask) {
176+
modeFlags.interruptMode = 1;
177+
} else {
178+
modeFlags.interruptMode = 0;
179+
}
180+
break;
181+
}
182+
interruptMask &= ~mask;
183+
SREG = sreg;
184+
}

hardware/arduino/avr/libraries/SPI/SPI.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
// usingInterrupt(), and SPISetting(clock, bitOrder, dataMode)
2121
#define SPI_HAS_TRANSACTION 1
2222

23+
// SPI_HAS_NOTUSINGINTERRUPT means that SPI has notUsingInterrup() method
24+
#define SPI_HAS_NOTUSINGINTERRUPT 1
25+
2326
// SPI_ATOMIC_VERSION means that SPI has atomicity fixes and what version.
2427
// This way when there is a bug fix you can check this define to alert users
2528
// of your code if it uses better version of this library.
@@ -169,6 +172,8 @@ class SPIClass {
169172
// with attachInterrupt. If SPI is used from a different interrupt
170173
// (eg, a timer), interruptNumber should be 255.
171174
static void usingInterrupt(uint8_t interruptNumber);
175+
// And this does the opposite.
176+
static void notUsingInterrupt(uint8_t interruptNumber);
172177

173178
// Before using SPI.transfer() or asserting chip select pins,
174179
// this function is used to gain exclusive access to the SPI bus

0 commit comments

Comments
 (0)