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.
Fork of mbed-src by
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(void (*fptr)(void)); 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> 00083 void rise(T* tptr, void (T::*mptr)(void)) { 00084 _rise.attach(tptr, mptr); 00085 gpio_irq_set(&gpio_irq, IRQ_RISE, 1); 00086 } 00087 00088 /** Attach a function to call when a falling edge occurs on the input 00089 * 00090 * @param fptr A pointer to a void function, or 0 to set as none 00091 */ 00092 void fall(void (*fptr)(void)); 00093 00094 /** Attach a member function to call when a falling edge occurs on the input 00095 * 00096 * @param tptr pointer to the object to call the member function on 00097 * @param mptr pointer to the member function to be called 00098 */ 00099 template<typename T> 00100 void fall(T* tptr, void (T::*mptr)(void)) { 00101 _fall.attach(tptr, mptr); 00102 gpio_irq_set(&gpio_irq, IRQ_FALL, 1); 00103 } 00104 00105 /** Set the input pin mode 00106 * 00107 * @param mode PullUp, PullDown, PullNone 00108 */ 00109 void mode(PinMode pull); 00110 00111 /** Enable IRQ. This method depends on hw implementation, might enable one 00112 * port interrupts. For further information, check gpio_irq_enable(). 00113 */ 00114 void enable_irq(); 00115 00116 /** Disable IRQ. This method depends on hw implementation, might disable one 00117 * port interrupts. For further information, check gpio_irq_disable(). 00118 */ 00119 void disable_irq(); 00120 00121 static void _irq_handler(uint32_t id, gpio_irq_event event); 00122 00123 protected: 00124 gpio_t gpio; 00125 gpio_irq_t gpio_irq; 00126 00127 FunctionPointer _rise; 00128 FunctionPointer _fall; 00129 }; 00130 00131 } // namespace mbed 00132 00133 #endif 00134 00135 #endif
Generated on Tue Jul 12 2022 21:21:33 by
