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 * 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 "Callback.h" 00026 #include "critical.h" 00027 00028 namespace mbed { 00029 00030 /** A digital interrupt input, used to call a function on a rising or falling edge 00031 * 00032 * @Note Synchronization level: Interrupt safe 00033 * 00034 * Example: 00035 * @code 00036 * // Flash an LED while waiting for events 00037 * 00038 * #include "mbed.h" 00039 * 00040 * InterruptIn event(p16); 00041 * DigitalOut led(LED1); 00042 * 00043 * void trigger() { 00044 * printf("triggered!\n"); 00045 * } 00046 * 00047 * int main() { 00048 * event.rise(&trigger); 00049 * while(1) { 00050 * led = !led; 00051 * wait(0.25); 00052 * } 00053 * } 00054 * @endcode 00055 */ 00056 class InterruptIn { 00057 00058 public: 00059 00060 /** Create an InterruptIn connected to the specified pin 00061 * 00062 * @param pin InterruptIn pin to connect to 00063 * @param name (optional) A string to identify the object 00064 */ 00065 InterruptIn(PinName pin); 00066 virtual ~InterruptIn(); 00067 00068 /** Read the input, represented as 0 or 1 (int) 00069 * 00070 * @returns 00071 * An integer representing the state of the input pin, 00072 * 0 for logical 0, 1 for logical 1 00073 */ 00074 int read(); 00075 00076 /** An operator shorthand for read() 00077 */ 00078 operator int(); 00079 00080 00081 /** Attach a function to call when a rising edge occurs on the input 00082 * 00083 * @param func A pointer to a void function, or 0 to set as none 00084 */ 00085 void rise(Callback<void()> func); 00086 00087 /** Attach a member function to call when a rising edge occurs on the input 00088 * 00089 * @param obj pointer to the object to call the member function on 00090 * @param method pointer to the member function to be called 00091 */ 00092 template<typename T, typename M> 00093 void rise(T *obj, M method) { 00094 core_util_critical_section_enter(); 00095 rise(Callback<void()>(obj, method)); 00096 core_util_critical_section_exit(); 00097 } 00098 00099 /** Attach a function to call when a falling edge occurs on the input 00100 * 00101 * @param func A pointer to a void function, or 0 to set as none 00102 */ 00103 void fall(Callback<void()> func); 00104 00105 /** Attach a member function to call when a falling edge occurs on the input 00106 * 00107 * @param obj pointer to the object to call the member function on 00108 * @param method pointer to the member function to be called 00109 */ 00110 template<typename T, typename M> 00111 void fall(T *obj, M method) { 00112 core_util_critical_section_enter(); 00113 fall(Callback<void()>(obj, method)); 00114 core_util_critical_section_exit(); 00115 } 00116 00117 /** Set the input pin mode 00118 * 00119 * @param mode PullUp, PullDown, PullNone 00120 */ 00121 void mode(PinMode pull); 00122 00123 /** Enable IRQ. This method depends on hw implementation, might enable one 00124 * port interrupts. For further information, check gpio_irq_enable(). 00125 */ 00126 void enable_irq(); 00127 00128 /** Disable IRQ. This method depends on hw implementation, might disable one 00129 * port interrupts. For further information, check gpio_irq_disable(). 00130 */ 00131 void disable_irq(); 00132 00133 static void _irq_handler(uint32_t id, gpio_irq_event event); 00134 00135 protected: 00136 gpio_t gpio; 00137 gpio_irq_t gpio_irq; 00138 00139 Callback<void()> _rise; 00140 Callback<void()> _fall; 00141 }; 00142 00143 } // namespace mbed 00144 00145 #endif 00146 00147 #endif
Generated on Tue Jul 12 2022 22:19:20 by
