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.
InterruptIn.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy 00005 * of this software and associated documentation files (the "Software"), to deal 00006 * in the Software without restriction, including without limitation the rights 00007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 * copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in 00012 * all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00020 * SOFTWARE. 00021 */ 00022 #ifndef MBED_INTERRUPTIN_H 00023 #define MBED_INTERRUPTIN_H 00024 00025 #include "platform.h" 00026 00027 #if DEVICE_INTERRUPTIN 00028 00029 #include "gpio_api.h" 00030 #include "gpio_irq_api.h" 00031 00032 #include "FunctionPointer.h" 00033 00034 namespace mbed { 00035 00036 /** A digital interrupt input, used to call a function on a rising or falling edge 00037 * 00038 * Example: 00039 * @code 00040 * // Flash an LED while waiting for events 00041 * 00042 * #include "mbed.h" 00043 * 00044 * InterruptIn event(p16); 00045 * DigitalOut led(LED1); 00046 * 00047 * void trigger() { 00048 * printf("triggered!\n"); 00049 * } 00050 * 00051 * int main() { 00052 * event.rise(&trigger); 00053 * while(1) { 00054 * led = !led; 00055 * wait(0.25); 00056 * } 00057 * } 00058 * @endcode 00059 */ 00060 class InterruptIn { 00061 00062 public: 00063 00064 /** Create an InterruptIn connected to the specified pin 00065 * 00066 * @param pin InterruptIn pin to connect to 00067 * @param name (optional) A string to identify the object 00068 */ 00069 InterruptIn(PinName pin); 00070 virtual ~InterruptIn(); 00071 00072 int read(); 00073 #ifdef MBED_OPERATORS 00074 operator int(); 00075 00076 #endif 00077 00078 /** Attach a function to call when a rising edge occurs on the input 00079 * 00080 * @param fptr A pointer to a void function, or 0 to set as none 00081 */ 00082 void rise(void (*fptr)(void)); 00083 00084 /** Attach a member function to call when a rising edge occurs on the input 00085 * 00086 * @param tptr pointer to the object to call the member function on 00087 * @param mptr pointer to the member function to be called 00088 */ 00089 template<typename T> 00090 void rise(T* tptr, void (T::*mptr)(void)) { 00091 _rise.attach(tptr, mptr); 00092 gpio_irq_set(&gpio_irq, IRQ_RISE, 1); 00093 } 00094 00095 /** Attach a function to call when a falling edge occurs on the input 00096 * 00097 * @param fptr A pointer to a void function, or 0 to set as none 00098 */ 00099 void fall(void (*fptr)(void)); 00100 00101 /** Attach a member function to call when a falling edge occurs on the input 00102 * 00103 * @param tptr pointer to the object to call the member function on 00104 * @param mptr pointer to the member function to be called 00105 */ 00106 template<typename T> 00107 void fall(T* tptr, void (T::*mptr)(void)) { 00108 _fall.attach(tptr, mptr); 00109 gpio_irq_set(&gpio_irq, IRQ_FALL, 1); 00110 } 00111 00112 /** Set the input pin mode 00113 * 00114 * @param mode PullUp, PullDown, PullNone 00115 */ 00116 void mode(PinMode pull); 00117 00118 static void _irq_handler(uint32_t id, gpio_irq_event event); 00119 00120 protected: 00121 gpio_t gpio; 00122 gpio_irq_t gpio_irq; 00123 00124 FunctionPointer _rise; 00125 FunctionPointer _fall; 00126 }; 00127 00128 } // namespace mbed 00129 00130 #endif 00131 00132 #endif 00133
Generated on Wed Jul 13 2022 02:59:11 by
