Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: target-freescale
InterruptIn.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef MBED_INTERRUPTIN_H 00017 #define MBED_INTERRUPTIN_H 00018 00019 #include "platform.h" 00020 00021 #if DEVICE_INTERRUPTIN 00022 00023 #include "gpio_api.h" 00024 #include "gpio_irq_api.h" 00025 #include "FunctionPointer.h" 00026 00027 namespace mbed { 00028 00029 /** A digital interrupt input, used to call a function on a rising or falling edge 00030 * 00031 * Example: 00032 * @code 00033 * // Flash an LED while waiting for events 00034 * 00035 * #include "mbed.h" 00036 * 00037 * InterruptIn event(p16); 00038 * DigitalOut led(LED1); 00039 * 00040 * void trigger() { 00041 * printf("triggered!\n"); 00042 * } 00043 * 00044 * int main() { 00045 * event.rise(&trigger); 00046 * while(1) { 00047 * led = !led; 00048 * wait(0.25); 00049 * } 00050 * } 00051 * @endcode 00052 */ 00053 class InterruptIn { 00054 00055 public: 00056 00057 /** Create an InterruptIn connected to the specified pin 00058 * 00059 * @param pin InterruptIn pin to connect to 00060 * @param name (optional) A string to identify the object 00061 */ 00062 InterruptIn(PinName pin); 00063 virtual ~InterruptIn(); 00064 00065 int read(); 00066 #ifdef MBED_OPERATORS 00067 operator int(); 00068 00069 #endif 00070 00071 /** Attach a function to call when a rising edge occurs on the input 00072 * 00073 * @param fptr A pointer to a void function, or 0 to set as none 00074 */ 00075 void rise(FuncPtr<void()> fptr); 00076 00077 /** Attach a member function to call when a rising edge occurs on the input 00078 * 00079 * @param tptr pointer to the object to call the member function on 00080 * @param mptr pointer to the member function to be called 00081 */ 00082 template<typename T, typename M> 00083 void rise(T *tptr, M *mptr) { 00084 rise(FuncPtr<void()>(tptr, mptr)); 00085 } 00086 00087 /** Attach a function to call when a falling edge occurs on the input 00088 * 00089 * @param fptr A pointer to a void function, or 0 to set as none 00090 */ 00091 void fall(FuncPtr<void()> fptr); 00092 00093 /** Attach a member function to call when a falling edge occurs on the input 00094 * 00095 * @param tptr pointer to the object to call the member function on 00096 * @param mptr pointer to the member function to be called 00097 */ 00098 template<typename T, typename M> 00099 void fall(T *tptr, M *mptr) { 00100 fall(FuncPtr<void()>(tptr, mptr)); 00101 } 00102 00103 /** Set the input pin mode 00104 * 00105 * @param mode PullUp, PullDown, PullNone 00106 */ 00107 void mode(PinMode pull); 00108 00109 /** Enable IRQ. This method depends on hw implementation, might enable one 00110 * port interrupts. For further information, check gpio_irq_enable(). 00111 */ 00112 void enable_irq(); 00113 00114 /** Disable IRQ. This method depends on hw implementation, might disable one 00115 * port interrupts. For further information, check gpio_irq_disable(). 00116 */ 00117 void disable_irq(); 00118 00119 static void _irq_handler(uint32_t id, gpio_irq_event event); 00120 00121 protected: 00122 gpio_t gpio; 00123 gpio_irq_t gpio_irq; 00124 00125 FuncPtr<void()> _rise; 00126 FuncPtr<void()> _fall; 00127 }; 00128 00129 } // namespace mbed 00130 00131 #endif 00132 00133 #endif 00134
Generated on Sat Aug 6 2022 08:19:56 by
1.7.2