22
22
23
23
#include " gpio_api.h"
24
24
#include " gpio_irq_api.h"
25
-
26
25
#include " FunctionPointer.h"
27
- #include " CallChain.h"
28
26
29
27
namespace mbed {
30
28
@@ -73,167 +71,37 @@ class InterruptIn {
73
71
/* * Attach a function to call when a rising edge occurs on the input
74
72
*
75
73
* @param fptr A pointer to a void function, or 0 to set as none
76
- *
77
- * @returns
78
- * The function object created for 'fptr'
79
- */
80
- pFunctionPointer_t rise (void (*fptr)(void ));
81
-
82
- /* * Add a function to be called when a rising edge occurs at the end of the call chain
83
- *
84
- * @param fptr the function to add
85
- *
86
- * @returns
87
- * The function object created for 'fptr'
88
74
*/
89
- pFunctionPointer_t rise_add (void (*fptr)(void )) {
90
- return rise_add_common (fptr);
91
- }
92
-
93
- /* * Add a function to be called when a rising edge occurs at the beginning of the call chain
94
- *
95
- * @param fptr the function to add
96
- *
97
- * @returns
98
- * The function object created for 'fptr'
99
- */
100
- pFunctionPointer_t rise_add_front (void (*fptr)(void )) {
101
- return rise_add_common (fptr, true );
102
- }
75
+ void rise (void (*fptr)(void ));
103
76
104
77
/* * Attach a member function to call when a rising edge occurs on the input
105
78
*
106
79
* @param tptr pointer to the object to call the member function on
107
80
* @param mptr pointer to the member function to be called
108
- *
109
- * @returns
110
- * The function object created for 'tptr' and 'mptr'
111
81
*/
112
82
template <typename T>
113
- pFunctionPointer_t rise (T* tptr, void (T::*mptr)(void )) {
114
- _rise.clear ();
115
- pFunctionPointer_t pf = _rise.add (tptr, mptr);
83
+ void rise (T* tptr, void (T::*mptr)(void )) {
84
+ _rise.attach (tptr, mptr);
116
85
gpio_irq_set (&gpio_irq, IRQ_RISE, 1 );
117
- return pf;
118
86
}
119
87
120
- /* * Add a function to be called when a rising edge occurs at the end of the call chain
121
- *
122
- * @param tptr pointer to the object to call the member function on
123
- * @param mptr pointer to the member function to be called
124
- *
125
- * @returns
126
- * The function object created for 'tptr' and 'mptr'
127
- */
128
- template <typename T>
129
- pFunctionPointer_t rise_add (T* tptr, void (T::*mptr)(void )) {
130
- return rise_add_common (tptr, mptr);
131
- }
132
-
133
- /* * Add a function to be called when a rising edge occurs at the beginning of the call chain
134
- *
135
- * @param tptr pointer to the object to call the member function on
136
- * @param mptr pointer to the member function to be called
137
- *
138
- * @returns
139
- * The function object created for 'tptr' and 'mptr'
140
- */
141
- template <typename T>
142
- pFunctionPointer_t rise_add_front (T* tptr, void (T::*mptr)(void )) {
143
- return rise_add_common (tptr, mptr, true );
144
- }
145
-
146
- /* * Remove a function from the list of functions to be called when a rising edge occurs
147
- *
148
- * @param pf the function object to remove
149
- *
150
- * @returns
151
- * true if the function was found and removed, false otherwise
152
- */
153
- bool rise_remove (pFunctionPointer_t pf);
154
-
155
88
/* * Attach a function to call when a falling edge occurs on the input
156
89
*
157
90
* @param fptr A pointer to a void function, or 0 to set as none
158
- *
159
- * @returns
160
- * The function object created for 'fptr'
161
91
*/
162
- pFunctionPointer_t fall (void (*fptr)(void ));
163
-
164
- /* * Add a function to be called when a falling edge occurs at the end of the call chain
165
- *
166
- * @param fptr the function to add
167
- *
168
- * @returns
169
- * The function object created for 'fptr'
170
- */
171
- pFunctionPointer_t fall_add (void (*fptr)(void )) {
172
- return fall_add_common (fptr);
173
- }
174
-
175
- /* * Add a function to be called when a falling edge occurs at the beginning of the call chain
176
- *
177
- * @param fptr the function to add
178
- *
179
- * @returns
180
- * The function object created for 'fptr'
181
- */
182
- pFunctionPointer_t fall_add_front (void (*fptr)(void )) {
183
- return fall_add_common (fptr, true );
184
- }
92
+ void fall (void (*fptr)(void ));
185
93
186
94
/* * Attach a member function to call when a falling edge occurs on the input
187
95
*
188
96
* @param tptr pointer to the object to call the member function on
189
97
* @param mptr pointer to the member function to be called
190
- *
191
- * @returns
192
- * The function object created for 'tptr' and 'mptr'
193
98
*/
194
99
template <typename T>
195
- pFunctionPointer_t fall (T* tptr, void (T::*mptr)(void )) {
196
- _fall.clear ();
197
- pFunctionPointer_t pf = _fall.add (tptr, mptr);
100
+ void fall (T* tptr, void (T::*mptr)(void )) {
101
+ _fall.attach (tptr, mptr);
198
102
gpio_irq_set (&gpio_irq, IRQ_FALL, 1 );
199
- return pf;
200
- }
201
-
202
- /* * Add a function to be called when a falling edge occurs at the end of the call chain
203
- *
204
- * @param tptr pointer to the object to call the member function on
205
- * @param mptr pointer to the member function to be called
206
- *
207
- * @returns
208
- * The function object created for 'tptr' and 'mptr'
209
- */
210
- template <typename T>
211
- pFunctionPointer_t fall_add (T* tptr, void (T::*mptr)(void )) {
212
- return fall_add_common (tptr, mptr);
213
- }
214
-
215
- /* * Add a function to be called when a falling edge occurs at the beginning of the call chain
216
- *
217
- * @param tptr pointer to the object to call the member function on
218
- * @param mptr pointer to the member function to be called
219
- *
220
- * @returns
221
- * The function object created for 'tptr' and 'mptr'
222
- */
223
- template <typename T>
224
- pFunctionPointer_t fall_add_front (T* tptr, void (T::*mptr)(void )) {
225
- return fall_add_common (tptr, mptr, true );
226
103
}
227
104
228
- /* * Remove a function from the list of functions to be called when a falling edge occurs
229
- *
230
- * @param pf the function object to remove
231
- *
232
- * @returns
233
- * true if the function was found and removed, false otherwise
234
- */
235
- bool fall_remove (pFunctionPointer_t pf);
236
-
237
105
/* * Set the input pin mode
238
106
*
239
107
* @param mode PullUp, PullDown, PullNone
@@ -251,27 +119,11 @@ class InterruptIn {
251
119
static void _irq_handler (uint32_t id, gpio_irq_event event);
252
120
253
121
protected:
254
- pFunctionPointer_t rise_add_common (void (*fptr)(void ), bool front=false);
255
- pFunctionPointer_t fall_add_common (void (*fptr)(void ), bool front=false);
256
-
257
- template <typename T>
258
- pFunctionPointer_t rise_add_common (T* tptr, void (T::*mptr)(void ), bool front=false) {
259
- pFunctionPointer_t pf = front ? _rise.add_front (tptr, mptr) : _rise.add (tptr, mptr);
260
- gpio_irq_set (&gpio_irq, IRQ_RISE, 1 );
261
- return pf;
262
- }
263
- template <typename T>
264
- pFunctionPointer_t fall_add_common (T* tptr, void (T::*mptr)(void ), bool front=false) {
265
- pFunctionPointer_t pf = front ? _fall.add_front (tptr, mptr) : _fall.add (tptr, mptr);
266
- gpio_irq_set (&gpio_irq, IRQ_FALL, 1 );
267
- return pf;
268
- }
269
-
270
122
gpio_t gpio;
271
123
gpio_irq_t gpio_irq;
272
124
273
- CallChain _rise;
274
- CallChain _fall;
125
+ FunctionPointer _rise;
126
+ FunctionPointer _fall;
275
127
};
276
128
277
129
} // namespace mbed
0 commit comments