добавила флаг состояния прерываний, чтобы не включать их, если кто-то выключил их в setup()

This commit is contained in:
KLASSENTS 2025-01-31 11:54:11 +07:00
parent b4f4baaa81
commit 002762bf80
3 changed files with 13 additions and 2 deletions

View File

@ -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] =
{

View File

@ -6,10 +6,12 @@ extern "C" {
#endif
#include <stdint.h>
#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);

View File

@ -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 --------------------- //