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