From 002762bf80e389a87e1eec86eac7fa4a35536dd2 Mon Sep 17 00:00:00 2001 From: KLASSENTS Date: Fri, 31 Jan 2025 11:54:11 +0700 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=20=D1=84=D0=BB=D0=B0=D0=B3=20=D1=81=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=BE=D1=8F=D0=BD=D0=B8=D1=8F=20=D0=BF=D1=80=D0=B5=D1=80=D1=8B?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B9,=20=D1=87=D1=82=D0=BE=D0=B1?= =?UTF-8?q?=D1=8B=20=D0=BD=D0=B5=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B8=D1=85,=20=D0=B5=D1=81=D0=BB=D0=B8=20?= =?UTF-8?q?=D0=BA=D1=82=D0=BE-=D1=82=D0=BE=20=D0=B2=D1=8B=D0=BA=D0=BB?= =?UTF-8?q?=D1=8E=D1=87=D0=B8=D0=BB=20=D0=B8=D1=85=20=D0=B2=20setup()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cores/arduino/WInterrupts.c | 9 +++++++++ cores/arduino/WInterrupts.h | 2 ++ cores/arduino/board.cpp | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) 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 --------------------- //