Skip to content

Add SPI.notUsingInterrupt(...) #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions libraries/SPI/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ void SPIClass::usingInterrupt(int interruptNumber)
interrupts();
}

void SPIClass::notUsingInterrupt(int interruptNumber)
{
if ((interruptNumber == NOT_AN_INTERRUPT) || (interruptNumber == EXTERNAL_INT_NMI))
return;

if (interruptMode & SPI_IMODE_GLOBAL)
return; // can't go back, as there is no reference count

uint8_t irestore = interruptsStatus();
noInterrupts();

interruptMask &= ~(1 << interruptNumber);

if (interruptMask == 0)
interruptMode = SPI_IMODE_NONE;

if (irestore)
interrupts();
}

void SPIClass::beginTransaction(SPISettings settings)
{
if (interruptMode != SPI_IMODE_NONE)
Expand Down
4 changes: 4 additions & 0 deletions libraries/SPI/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// - SPISetting(clock, bitOrder, dataMode)
#define SPI_HAS_TRANSACTION 1

// SPI_HAS_NOTUSINGINTERRUPT means that SPI has notUsingInterrupt() method
#define SPI_HAS_NOTUSINGINTERRUPT 1

#define SPI_MODE0 0x02
#define SPI_MODE1 0x00
#define SPI_MODE2 0x03
Expand Down Expand Up @@ -100,6 +103,7 @@ class SPIClass {

// Transaction Functions
void usingInterrupt(int interruptNumber);
void notUsingInterrupt(int interruptNumber);
void beginTransaction(SPISettings settings);
void endTransaction(void);

Expand Down