Class similar to InterruptIn which allows the LPC1114 to wake from deepsleep. (For other targets you can use InterruptIn).
Dependents: WakeUp WakeUp WakeUp WakeUp ... more
WakeInterruptIn.h
00001 /* 00002 Most mbed targets can be woken up from deepsleep by regular InterruptIn. 00003 On the LPC1114 this has to be done by different interrupts. This 00004 simple library helps with that 00005 */ 00006 00007 //Only include it for correct target. This allows me to re-use it in WakeUp lib 00008 #ifdef TARGET_LPC11XX_11CXX 00009 00010 #ifndef WAKEINTERRUPTIN_H 00011 #define WAKEINTERRUPTIN_H 00012 00013 #include "mbed.h" 00014 #define NUM_CHANNEL 13 00015 00016 /** Class to wake LPC1114 from deepsleep 00017 * 00018 * Use like regular InterruptIn, it works not only 00019 * to wake up from sleep but also just like InterruptIn. 00020 * Only you can NOT attach both rising and falling edge interrupts. 00021 */ 00022 class WakeInterruptIn : DigitalIn { 00023 public: 00024 00025 /** Constructor 00026 * 00027 * Pins which are allowed are all pins from Port 0 and P1_0 00028 * 00029 * @param pin Pin to use as WakeInterruptIn pin 00030 */ 00031 WakeInterruptIn(PinName pin); 00032 00033 ~WakeInterruptIn() { 00034 disable(); 00035 objects[channel] = NULL; 00036 } 00037 00038 /* Attach rising edge interrupt 00039 * 00040 * Attaching a member function can be done the regular way too 00041 * 00042 * @argument fptr Pointer to function to call, NULL to disable interrupt 00043 */ 00044 void rise(void (*fptr)(void)) { 00045 fpointer.attach(fptr); 00046 LPC_SYSCON->STARTAPRP0 |= (1 << channel); 00047 if (fptr == NULL) 00048 disable(); 00049 else 00050 enable(); 00051 } 00052 template<typename T> 00053 void rise(T* tptr, void (T::*mptr)(void)) { 00054 fpointer.attach(tptr, mptr); 00055 LPC_SYSCON->STARTAPRP0 |= (1 << channel); 00056 if (fptr == NULL) 00057 disable(); 00058 else 00059 enable(); 00060 } 00061 00062 /* Attach falling edge interrupt 00063 * 00064 * Attaching a member function can be done the regular way too 00065 * 00066 * @argument fptr Pointer to function to call, NULL to disable interrupt 00067 */ 00068 void fall(void (*fptr)(void)) { 00069 fpointer.attach(fptr); 00070 LPC_SYSCON->STARTAPRP0 &= ~(1 << channel); 00071 if (fptr == NULL) 00072 disable(); 00073 else 00074 enable(); 00075 } 00076 template<typename T> 00077 void fall(T* tptr, void (T::*mptr)(void)) { 00078 fpointer.attach(tptr, mptr); 00079 LPC_SYSCON->STARTAPRP0 &= ~(1 << channel); 00080 if (fptr == NULL) 00081 disable(); 00082 else 00083 enable(); 00084 } 00085 00086 00087 00088 private: 00089 uint8_t channel; 00090 FunctionPointer fpointer; 00091 00092 void enable(void) { 00093 LPC_SYSCON->STARTRSRP0CLR = 1 << channel; 00094 LPC_SYSCON->STARTERP0 |= (1 << channel); 00095 NVIC_EnableIRQ((IRQn_Type)channel); 00096 } 00097 00098 void disable(void) { 00099 LPC_SYSCON->STARTERP0 &= ~(1 << channel); 00100 NVIC_DisableIRQ((IRQn_Type)channel); 00101 } 00102 00103 void handle( void ) { 00104 LPC_SYSCON->STARTRSRP0CLR = 1 << channel; 00105 fpointer.call(); 00106 } 00107 00108 static WakeInterruptIn* objects[NUM_CHANNEL]; 00109 static void handler0(void) { objects[0]->handle(); } 00110 static void handler1(void) { objects[1]->handle(); } 00111 static void handler2(void) { objects[2]->handle(); } 00112 static void handler3(void) { objects[3]->handle(); } 00113 static void handler4(void) { objects[4]->handle(); } 00114 static void handler5(void) { objects[5]->handle(); } 00115 static void handler6(void) { objects[6]->handle(); } 00116 static void handler7(void) { objects[7]->handle(); } 00117 static void handler8(void) { objects[8]->handle(); } 00118 static void handler9(void) { objects[9]->handle(); } 00119 static void handler10(void) { objects[10]->handle(); } 00120 static void handler11(void) { objects[11]->handle(); } 00121 static void handler12(void) { objects[12]->handle(); } 00122 00123 }; 00124 #endif 00125 #endif
Generated on Sun Jul 17 2022 03:02:06 by 1.7.2