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