Skip to content

Commit 05c5e46

Browse files
committed
Initial
1 parent e346f20 commit 05c5e46

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

cores/esp32/FunctionalInterrupt.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* FunctionalInterrupt.cpp
3+
*
4+
* Created on: 8 jul. 2018
5+
* Author: Herman
6+
*/
7+
8+
#include "FunctionalInterrupt.h"
9+
#include "Arduino.h"
10+
11+
typedef void (*voidFuncPtr)(void);
12+
typedef void (*voidFuncPtrArg)(void*);
13+
14+
extern "C"
15+
{
16+
extern void __attachInterruptArg(uint8_t pin, voidFuncPtrArg userFunc, void * arg, int intr_type);
17+
}
18+
19+
void interruptFunctional(void* arg)
20+
{
21+
InterruptArgStructure* localArg = (InterruptArgStructure*)arg;
22+
if (localArg->interruptFunction)
23+
{
24+
localArg->interruptFunction();
25+
}
26+
}
27+
28+
void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode)
29+
{
30+
// use the local interrupt routine which takes the ArgStructure as argument
31+
__attachInterruptArg (pin, (voidFuncPtrArg)interruptFunctional, new InterruptArgStructure{intRoutine}, mode);
32+
}
33+
34+
extern "C"
35+
{
36+
void cleanupFunctional(void* arg)
37+
{
38+
delete (InterruptArgStructure*)arg;
39+
}
40+
}
41+
42+
43+
44+

cores/esp32/FunctionalInterrupt.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* FunctionalInterrupt.h
3+
*
4+
* Created on: 8 jul. 2018
5+
* Author: Herman
6+
*/
7+
8+
#ifndef CORE_CORE_FUNCTIONALINTERRUPT_H_
9+
#define CORE_CORE_FUNCTIONALINTERRUPT_H_
10+
11+
#include <functional>
12+
13+
struct InterruptArgStructure {
14+
std::function<void(void)> interruptFunction;
15+
};
16+
17+
void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode);
18+
19+
20+
#endif /* CORE_CORE_FUNCTIONALINTERRUPT_H_ */

0 commit comments

Comments
 (0)