ReelTwo
RSeries astromech firmware
PinInterruptHandler.h
Go to the documentation of this file.
1
#ifndef PinInterruptHandler_h
2
#define PinInterruptHandler_h
3
4
#include "
ReelTwo.h
"
5
6
class
PinInterruptHandler
7
{
8
public
:
9
void
detachInterrupt
(
unsigned
pin)
10
{
11
unsigned
inum = digitalPinToInterrupt(pin);
12
::detachInterrupt
(inum);
13
handlerToISR(inum) =
nullptr
;
14
}
15
16
bool
attachInterrupt
(
unsigned
pin)
17
{
18
uint8_t inum = digitalPinToInterrupt(pin);
19
// Serial.println("attachInterrupt pin="+String(pin)+" interrupt="+String(inum));
20
handlerToISR(inum) =
this
;
21
switch
(inum) {
22
#define ATTACH_INTTERUPT(num) \
23
case num: \
24
::attachInterrupt(inum, ISR_##num, CHANGE); \
25
break;
26
#ifdef __AVR__
27
ATTACH_INTTERUPT
(0)
28
ATTACH_INTTERUPT
(1)
29
ATTACH_INTTERUPT
(2)
30
ATTACH_INTTERUPT
(3)
31
ATTACH_INTTERUPT
(4)
32
ATTACH_INTTERUPT
(5)
33
ATTACH_INTTERUPT
(6)
34
ATTACH_INTTERUPT
(7)
35
ATTACH_INTTERUPT
(8)
36
ATTACH_INTTERUPT
(9)
37
ATTACH_INTTERUPT
(10)
38
ATTACH_INTTERUPT
(11)
39
ATTACH_INTTERUPT
(12)
40
ATTACH_INTTERUPT
(13)
41
ATTACH_INTTERUPT
(14)
42
ATTACH_INTTERUPT
(15)
43
ATTACH_INTTERUPT
(16)
44
ATTACH_INTTERUPT
(17)
45
ATTACH_INTTERUPT
(18)
46
ATTACH_INTTERUPT
(19)
47
#elif defined(ESP32)
48
ATTACH_INTTERUPT
(0)
49
ATTACH_INTTERUPT
(2)
50
ATTACH_INTTERUPT
(4)
51
ATTACH_INTTERUPT
(5)
52
ATTACH_INTTERUPT
(12)
53
ATTACH_INTTERUPT
(13)
54
ATTACH_INTTERUPT
(14)
55
ATTACH_INTTERUPT
(15)
56
ATTACH_INTTERUPT
(16)
57
ATTACH_INTTERUPT
(17)
58
ATTACH_INTTERUPT
(18)
59
ATTACH_INTTERUPT
(19)
60
ATTACH_INTTERUPT
(21)
61
ATTACH_INTTERUPT
(22)
62
ATTACH_INTTERUPT
(23)
63
ATTACH_INTTERUPT
(25)
64
ATTACH_INTTERUPT
(26)
65
ATTACH_INTTERUPT
(27)
66
ATTACH_INTTERUPT
(32)
67
ATTACH_INTTERUPT
(33)
68
ATTACH_INTTERUPT
(34)
69
ATTACH_INTTERUPT
(35)
70
ATTACH_INTTERUPT
(36)
71
ATTACH_INTTERUPT
(39)
72
#else
73
#error Not supported yet
74
#endif
75
76
#undef ATTACH_INTTERUPT
77
default
:
78
return
false
;
79
}
80
return
true
;
81
}
82
83
protected
:
84
virtual
void
interrupt
() = 0;
85
86
private
:
87
#ifdef ESP32
88
#define MAX_ISR_COUNT 40
89
#else
90
#define MAX_ISR_COUNT 20
91
#endif
92
static
PinInterruptHandler
*& handlerToISR(
int
isr)
93
{
94
static
PinInterruptHandler
* sHandlers[
MAX_ISR_COUNT
+1];
95
return
sHandlers[(isr >= 0 && isr <
MAX_ISR_COUNT
) ? isr+1 : 0];
96
}
97
98
#define DEFINE_ISR_HANDLER(n) \
99
static void ISR_##n() \
100
{ \
101
PinInterruptHandler* handler = handlerToISR(n); \
102
if (handler != nullptr) \
103
handler->interrupt(); \
104
}
105
106
#ifdef __AVR__
107
DEFINE_ISR_HANDLER
(0)
108
DEFINE_ISR_HANDLER
(1)
109
DEFINE_ISR_HANDLER
(2)
110
DEFINE_ISR_HANDLER
(3)
111
DEFINE_ISR_HANDLER
(4)
112
DEFINE_ISR_HANDLER
(5)
113
DEFINE_ISR_HANDLER
(6)
114
DEFINE_ISR_HANDLER
(7)
115
DEFINE_ISR_HANDLER
(8)
116
DEFINE_ISR_HANDLER
(9)
117
DEFINE_ISR_HANDLER
(10)
118
DEFINE_ISR_HANDLER
(11)
119
DEFINE_ISR_HANDLER
(12)
120
DEFINE_ISR_HANDLER
(13)
121
DEFINE_ISR_HANDLER
(14)
122
DEFINE_ISR_HANDLER
(15)
123
DEFINE_ISR_HANDLER
(16)
124
DEFINE_ISR_HANDLER
(17)
125
DEFINE_ISR_HANDLER
(18)
126
DEFINE_ISR_HANDLER
(19)
127
#elif defined(ESP32)
128
DEFINE_ISR_HANDLER
(0)
129
DEFINE_ISR_HANDLER
(2)
130
DEFINE_ISR_HANDLER
(4)
131
DEFINE_ISR_HANDLER
(5)
132
DEFINE_ISR_HANDLER
(12)
133
DEFINE_ISR_HANDLER
(13)
134
DEFINE_ISR_HANDLER
(14)
135
DEFINE_ISR_HANDLER
(15)
136
DEFINE_ISR_HANDLER
(16)
137
DEFINE_ISR_HANDLER
(17)
138
DEFINE_ISR_HANDLER
(18)
139
DEFINE_ISR_HANDLER
(19)
140
DEFINE_ISR_HANDLER
(21)
141
DEFINE_ISR_HANDLER
(22)
142
DEFINE_ISR_HANDLER
(23)
143
DEFINE_ISR_HANDLER
(25)
144
DEFINE_ISR_HANDLER
(26)
145
DEFINE_ISR_HANDLER
(27)
146
DEFINE_ISR_HANDLER
(32)
147
DEFINE_ISR_HANDLER
(33)
148
DEFINE_ISR_HANDLER
(34)
149
DEFINE_ISR_HANDLER
(35)
150
DEFINE_ISR_HANDLER
(36)
151
DEFINE_ISR_HANDLER
(39)
152
#else
153
#error Not supported yet
154
#endif
155
#undef MAX_ISR_COUNT
156
};
157
#endif
ATTACH_INTTERUPT
#define ATTACH_INTTERUPT(num)
ReelTwo.h
PinInterruptHandler::detachInterrupt
void detachInterrupt(unsigned pin)
Definition:
PinInterruptHandler.h:9
MAX_ISR_COUNT
#define MAX_ISR_COUNT
Definition:
PinInterruptHandler.h:90
PinInterruptHandler::attachInterrupt
bool attachInterrupt(unsigned pin)
Definition:
PinInterruptHandler.h:16
PinInterruptHandler
Definition:
PinInterruptHandler.h:6
DEFINE_ISR_HANDLER
#define DEFINE_ISR_HANDLER(n)
Definition:
PinInterruptHandler.h:98
PinInterruptHandler::interrupt
virtual void interrupt()=0
core
PinInterruptHandler.h
Generated by
1.8.17