1 /* mbed Microcontroller Library - InterruptIn
2 * Copyright (c) 2006-2009 ARM Limited. All rights reserved.
6 #ifndef MBED_INTERRUPTIN_H
7 #define MBED_INTERRUPTIN_H
11 #include "PeripheralNames.h"
13 #include "FunctionPointer.h"
18 * A digital interrupt input, used to call a function on a rising or falling edge
21 * > // Flash an LED while waiting for events
25 * > InterruptIn event(p16);
26 * > DigitalOut led(LED1);
29 * > printf("triggered!\n");
33 * > event.rise(&trigger);
40 class InterruptIn
: public Base
{
44 /* Constructor: InterruptIn
45 * Create an InterruptIn connected to the specified pin
48 * pin - InterruptIn pin to connect to
49 * name - (optional) A string to identify the object
51 InterruptIn(PinName pin
, const char *name
= NULL
);
60 * Attach a function to call when a rising edge occurs on the input
63 * fptr - A pointer to a void function, or 0 to set as none
65 void rise(void (*fptr
)(void));
68 * Attach a member function to call when a rising edge occurs on the input
71 * tptr - pointer to the object to call the member function on
72 * mptr - pointer to the member function to be called
75 void rise(T
* tptr
, void (T::*mptr
)(void)) {
76 _rise
.attach(tptr
, mptr
);
77 setup_interrupt(1, 1);
81 * Attach a function to call when a falling edge occurs on the input
84 * fptr - A pointer to a void function, or 0 to set as none
86 void fall(void (*fptr
)(void));
89 * Attach a member function to call when a falling edge occurs on the input
92 * tptr - pointer to the object to call the member function on
93 * mptr - pointer to the member function to be called
96 void fall(T
* tptr
, void (T::*mptr
)(void)) {
97 _fall
.attach(tptr
, mptr
);
98 setup_interrupt(0, 1);
102 * Set the input pin mode
105 * mode - PullUp, PullDown, PullNone
107 void mode(PinMode pull
);
111 static InterruptIn
*_irq_objects
[48];
116 FunctionPointer _rise
;
117 FunctionPointer _fall
;
119 void setup_interrupt(int rising
, int enable
);