добавила флаг состояния прерываний, чтобы не включать их, если кто-то выключил их в setup()
This commit is contained in:
parent
b4f4baaa81
commit
002762bf80
@ -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] =
|
||||
{
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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 --------------------- //
|
||||
|
||||
Loading…
Reference in New Issue
Block a user