first commit
[clinton/Smoothieware.git] / gcc4mbed / external / mbed / InterruptIn.h
1 /* mbed Microcontroller Library - InterruptIn
2 * Copyright (c) 2006-2009 ARM Limited. All rights reserved.
3 * sford
4 */
5
6 #ifndef MBED_INTERRUPTIN_H
7 #define MBED_INTERRUPTIN_H
8
9 #include "platform.h"
10 #include "PinNames.h"
11 #include "PeripheralNames.h"
12 #include "Base.h"
13 #include "FunctionPointer.h"
14
15 namespace mbed {
16
17 /* Class: InterruptIn
18 * A digital interrupt input, used to call a function on a rising or falling edge
19 *
20 * Example:
21 * > // Flash an LED while waiting for events
22 * >
23 * > #include "mbed.h"
24 * >
25 * > InterruptIn event(p16);
26 * > DigitalOut led(LED1);
27 * >
28 * > void trigger() {
29 * > printf("triggered!\n");
30 * > }
31 * >
32 * > int main() {
33 * > event.rise(&trigger);
34 * > while(1) {
35 * > led = !led;
36 * > wait(0.25);
37 * > }
38 * > }
39 */
40 class InterruptIn : public Base {
41
42 public:
43
44 /* Constructor: InterruptIn
45 * Create an InterruptIn connected to the specified pin
46 *
47 * Variables:
48 * pin - InterruptIn pin to connect to
49 * name - (optional) A string to identify the object
50 */
51 InterruptIn(PinName pin, const char *name = NULL);
52
53 int read();
54 #ifdef MBED_OPERATORS
55 operator int();
56
57 #endif
58
59 /* Function: rise
60 * Attach a function to call when a rising edge occurs on the input
61 *
62 * Variables:
63 * fptr - A pointer to a void function, or 0 to set as none
64 */
65 void rise(void (*fptr)(void));
66
67 /* Function: rise
68 * Attach a member function to call when a rising edge occurs on the input
69 *
70 * Variables:
71 * tptr - pointer to the object to call the member function on
72 * mptr - pointer to the member function to be called
73 */
74 template<typename T>
75 void rise(T* tptr, void (T::*mptr)(void)) {
76 _rise.attach(tptr, mptr);
77 setup_interrupt(1, 1);
78 }
79
80 /* Function: fall
81 * Attach a function to call when a falling edge occurs on the input
82 *
83 * Variables:
84 * fptr - A pointer to a void function, or 0 to set as none
85 */
86 void fall(void (*fptr)(void));
87
88 /* Function: fall
89 * Attach a member function to call when a falling edge occurs on the input
90 *
91 * Variables:
92 * tptr - pointer to the object to call the member function on
93 * mptr - pointer to the member function to be called
94 */
95 template<typename T>
96 void fall(T* tptr, void (T::*mptr)(void)) {
97 _fall.attach(tptr, mptr);
98 setup_interrupt(0, 1);
99 }
100
101 /* Function: mode
102 * Set the input pin mode
103 *
104 * Variables:
105 * mode - PullUp, PullDown, PullNone
106 */
107 void mode(PinMode pull);
108
109
110 static void _irq();
111 static InterruptIn *_irq_objects[48];
112
113 protected:
114
115 PinName _pin;
116 FunctionPointer _rise;
117 FunctionPointer _fall;
118
119 void setup_interrupt(int rising, int enable);
120
121 };
122
123 } // namespace mbed
124
125 #endif