File tree 2 files changed +52
-0
lines changed
2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -151,3 +151,45 @@ void SPIClass::usingInterrupt(uint8_t interruptNumber)
151
151
interrupts ();
152
152
}
153
153
154
+ void SPIClass::notUsingInterrupt (uint8_t interruptNumber)
155
+ {
156
+ // Once in mode 2 we can't go back to 0 without a proper reference count
157
+ if (interruptMode == 2 )
158
+ return ;
159
+ uint8_t mask = 0 ;
160
+ uint8_t sreg = SREG;
161
+ noInterrupts (); // Protect from a scheduler and prevent transactionBegin
162
+ switch (interruptNumber) {
163
+ #ifdef SPI_INT0_MASK
164
+ case 0 : mask = SPI_INT0_MASK; break ;
165
+ #endif
166
+ #ifdef SPI_INT1_MASK
167
+ case 1 : mask = SPI_INT1_MASK; break ;
168
+ #endif
169
+ #ifdef SPI_INT2_MASK
170
+ case 2 : mask = SPI_INT2_MASK; break ;
171
+ #endif
172
+ #ifdef SPI_INT3_MASK
173
+ case 3 : mask = SPI_INT3_MASK; break ;
174
+ #endif
175
+ #ifdef SPI_INT4_MASK
176
+ case 4 : mask = SPI_INT4_MASK; break ;
177
+ #endif
178
+ #ifdef SPI_INT5_MASK
179
+ case 5 : mask = SPI_INT5_MASK; break ;
180
+ #endif
181
+ #ifdef SPI_INT6_MASK
182
+ case 6 : mask = SPI_INT6_MASK; break ;
183
+ #endif
184
+ #ifdef SPI_INT7_MASK
185
+ case 7 : mask = SPI_INT7_MASK; break ;
186
+ #endif
187
+ default :
188
+ break ;
189
+ // this case can't be reached
190
+ }
191
+ interruptMask &= ~mask;
192
+ if (!interruptMask)
193
+ interruptMode = 0 ;
194
+ SREG = sreg;
195
+ }
Original file line number Diff line number Diff line change 20
20
// usingInterrupt(), and SPISetting(clock, bitOrder, dataMode)
21
21
#define SPI_HAS_TRANSACTION 1
22
22
23
+ // SPI_HAS_NOTUSINGINTERRUPT means that SPI has notUsingInterrupt() method
24
+ #define SPI_HAS_NOTUSINGINTERRUPT 1
25
+
23
26
// Uncomment this line to add detection of mismatched begin/end transactions.
24
27
// A mismatch occurs if other libraries fail to use SPI.endTransaction() for
25
28
// each SPI.beginTransaction(). Connect an LED to this pin. The LED will turn
@@ -154,6 +157,13 @@ class SPIClass {
154
157
// with attachInterrupt. If SPI is used from a different interrupt
155
158
// (eg, a timer), interruptNumber should be 255.
156
159
static void usingInterrupt (uint8_t interruptNumber);
160
+ // And this does the opposite.
161
+ static void notUsingInterrupt (uint8_t interruptNumber);
162
+ // Note: the usingInterrupt and notUsingInterrupt functions should
163
+ // not to be called from ISR context or inside a transaction.
164
+ // For details see:
165
+ // https://github.com/arduino/Arduino/pull/2381
166
+ // https://github.com/arduino/Arduino/pull/2449
157
167
158
168
// Before using SPI.transfer() or asserting chip select pins,
159
169
// this function is used to gain exclusive access to the SPI bus
You can’t perform that action at this time.
0 commit comments