2
2
#include " Schedule.h"
3
3
#include " Arduino.h"
4
4
5
- #if defined(ESP8266)
6
-
7
- // Duplicate typedefs from core_esp8266_wiring_digital.cpp
8
- // Keep in sync
9
- typedef void (*voidFuncPtr)(void );
10
- typedef void (*voidFuncPtrArg)(void *);
11
-
12
- typedef struct {
13
- uint8_t mode;
14
- voidFuncPtr fn;
15
- void * arg;
16
- } interrupt_handler_t ;
17
-
18
- // Helper functions for Functional interrupt routines
19
- extern " C" interrupt_handler_t * __getInterruptHandler (uint8_t pin);
20
-
21
- #elif defined(ESP32)
22
-
23
- // Duplicate typedefs from esp32-hal-gpio.c
24
- // Keep in sync
25
- typedef void (*voidFuncPtr)(void );
26
- typedef void (*voidFuncPtrArg)(void *);
27
- typedef struct {
28
- voidFuncPtr fn;
29
- void * arg;
30
- } InterruptHandle_t;
31
-
32
- // Helper functions for Functional interrupt routines
33
- extern " C" InterruptHandle_t* __getInterruptHandler (uint8_t pin);
34
-
35
- #endif
36
-
37
5
void ICACHE_RAM_ATTR interruptFunctional (void * arg)
38
6
{
39
7
ArgStructure* localArg = static_cast <ArgStructure*>(arg);
@@ -44,32 +12,30 @@ void ICACHE_RAM_ATTR interruptFunctional(void* arg)
44
12
}
45
13
if (localArg->functionInfo ->reqScheduledFunction )
46
14
{
47
- schedule_function (std::bind (localArg->functionInfo ->reqScheduledFunction ,InterruptInfo (*(localArg->interruptInfo ))));
15
+ schedule_function (
16
+ [reqScheduledFunction = localArg->functionInfo ->reqScheduledFunction ,
17
+ interruptInfo = *localArg->interruptInfo ]() { reqScheduledFunction (interruptInfo); });
48
18
}
49
19
if (localArg->functionInfo ->reqFunction )
50
20
{
51
21
localArg->functionInfo ->reqFunction ();
52
22
}
53
23
}
54
24
55
- void cleanupFunctional (void * arg)
56
- {
57
- ArgStructure* localArg = static_cast <ArgStructure*>(arg);
58
- delete localArg;
59
- }
25
+ void cleanupFunctional (void * arg)
26
+ {
27
+ ArgStructure* localArg = static_cast <ArgStructure*>(arg);
28
+ delete localArg;
29
+ }
60
30
61
31
void attachInterrupt (uint8_t pin, std::function<void (void )> intRoutine, int mode)
62
32
{
63
33
// use the local interrupt routine which takes the ArgStructure as argument
64
34
65
- #if defined(ESP8266)
66
- interrupt_handler_t * handler = __getInterruptHandler (pin);
67
- #elif defined(ESP32)
68
- InterruptHandle_t* handler = __getInterruptHandler (pin);
69
- #endif
70
- if (handler->arg )
35
+ void * localArg = detachInterruptArg (pin);
36
+ if (localArg)
71
37
{
72
- cleanupFunctional (handler-> arg );
38
+ cleanupFunctional (localArg );
73
39
}
74
40
75
41
FunctionInfo* fi = new FunctionInfo;
@@ -78,19 +44,15 @@ void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode
78
44
ArgStructure* as = new ArgStructure;
79
45
as->functionInfo = fi;
80
46
81
- :: attachInterruptArg (pin, static_cast <voidFuncPtrArg>( interruptFunctional) , as, mode);
47
+ attachInterruptArg (pin, interruptFunctional, as, mode);
82
48
}
83
49
84
50
void attachScheduledInterrupt (uint8_t pin, std::function<void (InterruptInfo)> scheduledIntRoutine, int mode)
85
51
{
86
- #if defined(ESP8266)
87
- interrupt_handler_t * handler = __getInterruptHandler (pin);
88
- #elif defined(ESP32)
89
- InterruptHandle_t* handler = __getInterruptHandler (pin);
90
- #endif
91
- if (handler->arg )
52
+ void * localArg = detachInterruptArg (pin);
53
+ if (localArg)
92
54
{
93
- cleanupFunctional (handler-> arg );
55
+ cleanupFunctional (localArg );
94
56
}
95
57
96
58
InterruptInfo* ii = new InterruptInfo (pin);
@@ -102,20 +64,14 @@ void attachScheduledInterrupt(uint8_t pin, std::function<void(InterruptInfo)> sc
102
64
as->interruptInfo = ii;
103
65
as->functionInfo = fi;
104
66
105
- :: attachInterruptArg (pin, static_cast <voidFuncPtrArg>( interruptFunctional) , as, mode);
67
+ attachInterruptArg (pin, interruptFunctional, as, mode);
106
68
}
107
69
108
70
void detachFunctionalInterrupt (uint8_t pin)
109
71
{
110
- #if defined(ESP8266)
111
- interrupt_handler_t * handler = __getInterruptHandler (pin);
112
- #elif defined(ESP32)
113
- InterruptHandle_t* handler = __getInterruptHandler (pin);
114
- #endif
115
- if (handler->arg )
72
+ void * localArg = detachInterruptArg (pin);
73
+ if (localArg)
116
74
{
117
- cleanupFunctional (handler-> arg );
75
+ cleanupFunctional (localArg );
118
76
}
119
- ::detachInterrupt (pin);
120
77
}
121
-
0 commit comments