добавила флаг состояния прерываний, чтобы не включать их, если кто-то выключил их в setup()
This commit is contained in:
parent
b4f4baaa81
commit
002762bf80
@ -6,6 +6,9 @@
|
|||||||
#include "WInterrupts.h"
|
#include "WInterrupts.h"
|
||||||
#include "wiring_LL.h"
|
#include "wiring_LL.h"
|
||||||
|
|
||||||
|
// interrupts are enabled by default after setup()
|
||||||
|
static bool intIsEnabled = true;
|
||||||
|
|
||||||
typedef void (*voidFuncPtr)(void);
|
typedef void (*voidFuncPtr)(void);
|
||||||
|
|
||||||
// empty irq handler
|
// empty irq handler
|
||||||
@ -18,14 +21,20 @@ static void nothing(void)
|
|||||||
void interrupts(void)
|
void interrupts(void)
|
||||||
{
|
{
|
||||||
GLOBAL_IRQ_ENABLE();
|
GLOBAL_IRQ_ENABLE();
|
||||||
|
intIsEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// disable global interrupts
|
// disable global interrupts
|
||||||
void noInterrupts(void)
|
void noInterrupts(void)
|
||||||
{
|
{
|
||||||
GLOBAL_IRQ_DISABLE();
|
GLOBAL_IRQ_DISABLE();
|
||||||
|
intIsEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isInterruptsEnabled(void)
|
||||||
|
{
|
||||||
|
return intIsEnabled;
|
||||||
|
}
|
||||||
// we can provide no more than 8 interrupts on gpio at the same time
|
// we can provide no more than 8 interrupts on gpio at the same time
|
||||||
static volatile voidFuncPtr intFunc[EXTERNAL_INTERRUPTS_QTY] =
|
static volatile voidFuncPtr intFunc[EXTERNAL_INTERRUPTS_QTY] =
|
||||||
{
|
{
|
||||||
|
|||||||
@ -6,10 +6,12 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "stdbool.h"
|
||||||
|
|
||||||
// enable/disable interrupts
|
// enable/disable interrupts
|
||||||
void interrupts(void);
|
void interrupts(void);
|
||||||
void noInterrupts(void);
|
void noInterrupts(void);
|
||||||
|
bool isInterruptsEnabled(void);
|
||||||
|
|
||||||
// attach/detach interrupt to pin
|
// attach/detach interrupt to pin
|
||||||
void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode);
|
void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode);
|
||||||
|
|||||||
@ -25,8 +25,8 @@ extern "C" void SystemInit(void)
|
|||||||
// called after setup()
|
// called after setup()
|
||||||
void post_init(void)
|
void post_init(void)
|
||||||
{
|
{
|
||||||
// enable global interrupts by default
|
if(isInterruptsEnabled()) // if user has called noInterrupts() in setup(), this value is false
|
||||||
interrupts();
|
interrupts(); // enable global interrupts
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------- other --------------------- //
|
// --------------------- other --------------------- //
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user