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/platform.h" 00020 00021 #if defined (DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY) 00022 00023 #include "hal/gpio_api.h" 00024 #include "hal/gpio_irq_api.h" 00025 #include "platform/Callback.h" 00026 #include "platform/mbed_critical.h" 00027 #include "platform/mbed_toolchain.h" 00028 #include "platform/NonCopyable.h" 00029 00030 namespace mbed { 00031 /** \addtogroup drivers */ 00032 00033 /** A digital interrupt input, used to call a function on a rising or falling edge 00034 * 00035 * @note Synchronization level: Interrupt safe 00036 * 00037 * Example: 00038 * @code 00039 * // Flash an LED while waiting for events 00040 * 00041 * #include "mbed.h" 00042 * 00043 * InterruptIn event(p16); 00044 * DigitalOut led(LED1); 00045 * 00046 * void trigger() { 00047 * printf("triggered!\n"); 00048 * } 00049 * 00050 * int main() { 00051 * // register trigger() to be called upon the rising edge of event 00052 * event.rise(&trigger); 00053 * while(1) { 00054 * led = !led; 00055 * wait(0.25); 00056 * } 00057 * } 00058 * @endcode 00059 * @ingroup drivers 00060 */ 00061 class InterruptIn : private NonCopyable<InterruptIn> { 00062 00063 public: 00064 00065 /** Create an InterruptIn connected to the specified pin 00066 * 00067 * @param pin InterruptIn pin to connect to 00068 */ 00069 InterruptIn(PinName pin); 00070 00071 /** Create an InterruptIn connected to the specified pin, 00072 * and the pin configured to the specified mode. 00073 * 00074 * @param pin InterruptIn pin to connect to 00075 * @param mode Desired Pin mode configuration. 00076 * (Valid values could be PullNone, PullDown, PullUp and PullDefault. 00077 * See PinNames.h for your target for definitions) 00078 * 00079 */ 00080 InterruptIn(PinName pin, PinMode mode); 00081 00082 virtual ~InterruptIn(); 00083 00084 /** Read the input, represented as 0 or 1 (int) 00085 * 00086 * @returns 00087 * An integer representing the state of the input pin, 00088 * 0 for logical 0, 1 for logical 1 00089 */ 00090 int read(); 00091 00092 /** An operator shorthand for read() 00093 */ 00094 operator int(); 00095 00096 00097 /** Attach a function to call when a rising edge occurs on the input 00098 * 00099 * @param func A pointer to a void function, or 0 to set as none 00100 */ 00101 void rise(Callback<void()> func); 00102 00103 /** Attach a member function to call when a rising edge occurs on the input 00104 * 00105 * @param obj pointer to the object to call the member function on 00106 * @param method pointer to the member function to be called 00107 * @deprecated 00108 * The rise function does not support cv-qualifiers. Replaced by 00109 * rise(callback(obj, method)). 00110 */ 00111 template<typename T, typename M> 00112 MBED_DEPRECATED_SINCE("mbed-os-5.1", 00113 "The rise function does not support cv-qualifiers. Replaced by " 00114 "rise(callback(obj, method)).") 00115 void rise(T *obj, M method) 00116 { 00117 core_util_critical_section_enter(); 00118 rise(callback(obj, method)); 00119 core_util_critical_section_exit(); 00120 } 00121 00122 /** Attach a function to call when a falling edge occurs on the input 00123 * 00124 * @param func A pointer to a void function, or 0 to set as none 00125 */ 00126 void fall(Callback<void()> func); 00127 00128 /** Attach a member function to call when a falling edge occurs on the input 00129 * 00130 * @param obj pointer to the object to call the member function on 00131 * @param method pointer to the member function to be called 00132 * @deprecated 00133 * The rise function does not support cv-qualifiers. Replaced by 00134 * rise(callback(obj, method)). 00135 */ 00136 template<typename T, typename M> 00137 MBED_DEPRECATED_SINCE("mbed-os-5.1", 00138 "The fall function does not support cv-qualifiers. Replaced by " 00139 "fall(callback(obj, method)).") 00140 void fall(T *obj, M method) 00141 { 00142 core_util_critical_section_enter(); 00143 fall(callback(obj, method)); 00144 core_util_critical_section_exit(); 00145 } 00146 00147 /** Set the input pin mode 00148 * 00149 * @param pull PullUp, PullDown, PullNone, PullDefault 00150 * See PinNames.h for your target for definitions) 00151 */ 00152 void mode(PinMode pull); 00153 00154 /** Enable IRQ. This method depends on hardware implementation, might enable one 00155 * port interrupts. For further information, check gpio_irq_enable(). 00156 */ 00157 void enable_irq(); 00158 00159 /** Disable IRQ. This method depends on hardware implementation, might disable one 00160 * port interrupts. For further information, check gpio_irq_disable(). 00161 */ 00162 void disable_irq(); 00163 00164 static void _irq_handler(uint32_t id, gpio_irq_event event); 00165 #if !defined(DOXYGEN_ONLY) 00166 protected: 00167 gpio_t gpio; 00168 gpio_irq_t gpio_irq; 00169 00170 Callback<void()> _rise; 00171 Callback<void()> _fall; 00172 00173 void irq_init(PinName pin); 00174 #endif 00175 }; 00176 00177 } // namespace mbed 00178 00179 #endif 00180 00181 #endif
Generated on Tue Jul 12 2022 20:52:44 by
1.7.2