Soundharrajan
Fork of mbed by
Embed:
(wiki syntax)
Show/hide line numbers
InterruptIn.h
00001 /* mbed Microcontroller Library - InterruptIn 00002 * Copyright (c) 2006-2011 ARM Limited. All rights reserved. 00003 */ 00004 00005 #ifndef MBED_INTERRUPTIN_H 00006 #define MBED_INTERRUPTIN_H 00007 00008 #include "device.h" 00009 00010 #if DEVICE_INTERRUPTIN 00011 00012 #include "platform.h" 00013 #include "PinNames.h" 00014 #include "PeripheralNames.h" 00015 #include "Base.h" 00016 #include "FunctionPointer.h" 00017 00018 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) 00019 #define CHANNEL_NUM 48 00020 #elif defined(TARGET_LPC11U24) 00021 #define CHANNEL_NUM 8 00022 #endif 00023 00024 namespace mbed { 00025 00026 /* Class: InterruptIn 00027 * A digital interrupt input, used to call a function on a rising or falling edge 00028 * 00029 * Example: 00030 * > // Flash an LED while waiting for events 00031 * > 00032 * > #include "mbed.h" 00033 * > 00034 * > InterruptIn event(p16); 00035 * > DigitalOut led(LED1); 00036 * > 00037 * > void trigger() { 00038 * > printf("triggered!\n"); 00039 * > } 00040 * > 00041 * > int main() { 00042 * > event.rise(&trigger); 00043 * > while(1) { 00044 * > led = !led; 00045 * > wait(0.25); 00046 * > } 00047 * > } 00048 */ 00049 class InterruptIn : public Base { 00050 00051 public: 00052 00053 /* Constructor: InterruptIn 00054 * Create an InterruptIn connected to the specified pin 00055 * 00056 * Variables: 00057 * pin - InterruptIn pin to connect to 00058 * name - (optional) A string to identify the object 00059 */ 00060 InterruptIn(PinName pin, const char *name = NULL); 00061 #if defined(TARGET_LPC11U24) 00062 virtual ~InterruptIn(); 00063 #endif 00064 00065 int read(); 00066 #ifdef MBED_OPERATORS 00067 operator int(); 00068 00069 #endif 00070 00071 /* Function: rise 00072 * Attach a function to call when a rising edge occurs on the input 00073 * 00074 * Variables: 00075 * fptr - A pointer to a void function, or 0 to set as none 00076 */ 00077 void rise(void (*fptr)(void)); 00078 00079 /* Function: rise 00080 * Attach a member function to call when a rising edge occurs on the input 00081 * 00082 * Variables: 00083 * tptr - pointer to the object to call the member function on 00084 * mptr - pointer to the member function to be called 00085 */ 00086 template<typename T> 00087 void rise(T* tptr, void (T::*mptr)(void)) { 00088 _rise.attach(tptr, mptr); 00089 setup_interrupt(1, 1); 00090 } 00091 00092 /* Function: fall 00093 * Attach a function to call when a falling edge occurs on the input 00094 * 00095 * Variables: 00096 * fptr - A pointer to a void function, or 0 to set as none 00097 */ 00098 void fall(void (*fptr)(void)); 00099 00100 /* Function: fall 00101 * Attach a member function to call when a falling edge occurs on the input 00102 * 00103 * Variables: 00104 * tptr - pointer to the object to call the member function on 00105 * mptr - pointer to the member function to be called 00106 */ 00107 template<typename T> 00108 void fall(T* tptr, void (T::*mptr)(void)) { 00109 _fall.attach(tptr, mptr); 00110 setup_interrupt(0, 1); 00111 } 00112 00113 /* Function: mode 00114 * Set the input pin mode 00115 * 00116 * Variables: 00117 * mode - PullUp, PullDown, PullNone 00118 */ 00119 void mode(PinMode pull); 00120 00121 static InterruptIn *_irq_objects[CHANNEL_NUM]; 00122 00123 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) 00124 static void _irq(); 00125 #elif defined(TARGET_LPC11U24) 00126 static void handle_interrupt_in(unsigned int channel); 00127 static void _irq0(); static void _irq1(); 00128 static void _irq2(); static void _irq3(); 00129 static void _irq4(); static void _irq5(); 00130 static void _irq6(); static void _irq7(); 00131 #endif 00132 00133 protected: 00134 PinName _pin; 00135 #if defined(TARGET_LPC11U24) 00136 Channel _channel; 00137 #endif 00138 FunctionPointer _rise; 00139 FunctionPointer _fall; 00140 00141 void setup_interrupt(int rising, int enable); 00142 00143 }; 00144 00145 } // namespace mbed 00146 00147 #endif 00148 00149 #endif
Generated on Tue Jul 12 2022 21:25:21 by 1.7.2