]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/api/InterruptIn.h
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / api / InterruptIn.h
1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #ifndef MBED_INTERRUPTIN_H
17 #define MBED_INTERRUPTIN_H
18
19 #include "platform.h"
20
21 #if DEVICE_INTERRUPTIN
22
23 #include "gpio_api.h"
24 #include "gpio_irq_api.h"
25 #include "FunctionPointer.h"
26
27 namespace mbed {
28
29 /** A digital interrupt input, used to call a function on a rising or falling edge
30 *
31 * Example:
32 * @code
33 * // Flash an LED while waiting for events
34 *
35 * #include "mbed.h"
36 *
37 * InterruptIn event(p16);
38 * DigitalOut led(LED1);
39 *
40 * void trigger() {
41 * printf("triggered!\n");
42 * }
43 *
44 * int main() {
45 * event.rise(&trigger);
46 * while(1) {
47 * led = !led;
48 * wait(0.25);
49 * }
50 * }
51 * @endcode
52 */
53 class InterruptIn {
54
55 public:
56
57 /** Create an InterruptIn connected to the specified pin
58 *
59 * @param pin InterruptIn pin to connect to
60 * @param name (optional) A string to identify the object
61 */
62 InterruptIn(PinName pin);
63 virtual ~InterruptIn();
64
65 int read();
66 #ifdef MBED_OPERATORS
67 operator int();
68
69 #endif
70
71 /** Attach a function to call when a rising edge occurs on the input
72 *
73 * @param fptr A pointer to a void function, or 0 to set as none
74 */
75 void rise(void (*fptr)(void));
76
77 /** Attach a member function to call when a rising edge occurs on the input
78 *
79 * @param tptr pointer to the object to call the member function on
80 * @param mptr pointer to the member function to be called
81 */
82 template<typename T>
83 void rise(T* tptr, void (T::*mptr)(void)) {
84 _rise.attach(tptr, mptr);
85 gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
86 }
87
88 /** Attach a function to call when a falling edge occurs on the input
89 *
90 * @param fptr A pointer to a void function, or 0 to set as none
91 */
92 void fall(void (*fptr)(void));
93
94 /** Attach a member function to call when a falling edge occurs on the input
95 *
96 * @param tptr pointer to the object to call the member function on
97 * @param mptr pointer to the member function to be called
98 */
99 template<typename T>
100 void fall(T* tptr, void (T::*mptr)(void)) {
101 _fall.attach(tptr, mptr);
102 gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
103 }
104
105 /** Set the input pin mode
106 *
107 * @param mode PullUp, PullDown, PullNone
108 */
109 void mode(PinMode pull);
110
111 /** Enable IRQ. This method depends on hw implementation, might enable one
112 * port interrupts. For further information, check gpio_irq_enable().
113 */
114 void enable_irq();
115
116 /** Disable IRQ. This method depends on hw implementation, might disable one
117 * port interrupts. For further information, check gpio_irq_disable().
118 */
119 void disable_irq();
120
121 static void _irq_handler(uint32_t id, gpio_irq_event event);
122
123 protected:
124 gpio_t gpio;
125 gpio_irq_t gpio_irq;
126
127 FunctionPointer _rise;
128 FunctionPointer _fall;
129 };
130
131 } // namespace mbed
132
133 #endif
134
135 #endif
Imprint / Impressum