diff --git a/cores/arduino/WInterrupts.c b/cores/arduino/WInterrupts.c index 6b4783f..0f63b22 100644 --- a/cores/arduino/WInterrupts.c +++ b/cores/arduino/WInterrupts.c @@ -6,6 +6,9 @@ #include "WInterrupts.h" #include "wiring_LL.h" +// interrupts are enabled by default after setup() +static bool intIsEnabled = true; + typedef void (*voidFuncPtr)(void); // empty irq handler @@ -18,14 +21,20 @@ static void nothing(void) void interrupts(void) { GLOBAL_IRQ_ENABLE(); + intIsEnabled = true; } // disable global interrupts void noInterrupts(void) { GLOBAL_IRQ_DISABLE(); + intIsEnabled = false; } +bool isInterruptsEnabled(void) +{ + return intIsEnabled; +} // we can provide no more than 8 interrupts on gpio at the same time static volatile voidFuncPtr intFunc[EXTERNAL_INTERRUPTS_QTY] = { diff --git a/cores/arduino/WInterrupts.h b/cores/arduino/WInterrupts.h index 4bab44e..50b3b9b 100644 --- a/cores/arduino/WInterrupts.h +++ b/cores/arduino/WInterrupts.h @@ -6,10 +6,12 @@ extern "C" { #endif #include +#include "stdbool.h" // enable/disable interrupts void interrupts(void); void noInterrupts(void); +bool isInterruptsEnabled(void); // attach/detach interrupt to pin void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode); diff --git a/cores/arduino/board.cpp b/cores/arduino/board.cpp index da0f39b..591676c 100644 --- a/cores/arduino/board.cpp +++ b/cores/arduino/board.cpp @@ -25,8 +25,8 @@ extern "C" void SystemInit(void) // called after setup() void post_init(void) { - // enable global interrupts by default - interrupts(); + if(isInterruptsEnabled()) // if user has called noInterrupts() in setup(), this value is false + interrupts(); // enable global interrupts } // --------------------- other --------------------- //