1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef MBED_INTERRUPTIN_H
17 #define MBED_INTERRUPTIN_H
21 #if DEVICE_INTERRUPTIN
24 #include "gpio_irq_api.h"
25 #include "FunctionPointer.h"
29 /** A digital interrupt input, used to call a function on a rising or falling edge
33 * // Flash an LED while waiting for events
37 * InterruptIn event(p16);
38 * DigitalOut led(LED1);
41 * printf("triggered!\n");
45 * event.rise(&trigger);
57 /** Create an InterruptIn connected to the specified pin
59 * @param pin InterruptIn pin to connect to
60 * @param name (optional) A string to identify the object
62 InterruptIn(PinName pin);
63 virtual ~InterruptIn();
71 /** Attach a function to call when a rising edge occurs on the input
73 * @param fptr A pointer to a void function, or 0 to set as none
75 void rise(void (*fptr)(void));
77 /** Attach a member function to call when a rising edge occurs on the input
79 * @param tptr pointer to the object to call the member function on
80 * @param mptr pointer to the member function to be called
83 void rise(T* tptr, void (T::*mptr)(void)) {
84 _rise.attach(tptr, mptr);
85 gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
88 /** Attach a function to call when a falling edge occurs on the input
90 * @param fptr A pointer to a void function, or 0 to set as none
92 void fall(void (*fptr)(void));
94 /** Attach a member function to call when a falling edge occurs on the input
96 * @param tptr pointer to the object to call the member function on
97 * @param mptr pointer to the member function to be called
100 void fall(T* tptr, void (T::*mptr)(void)) {
101 _fall.attach(tptr, mptr);
102 gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
105 /** Set the input pin mode
107 * @param mode PullUp, PullDown, PullNone
109 void mode(PinMode pull);
111 /** Enable IRQ. This method depends on hw implementation, might enable one
112 * port interrupts. For further information, check gpio_irq_enable().
116 /** Disable IRQ. This method depends on hw implementation, might disable one
117 * port interrupts. For further information, check gpio_irq_disable().
121 static void _irq_handler(uint32_t id, gpio_irq_event event);
127 FunctionPointer _rise;
128 FunctionPointer _fall;