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@1:128f3fe79240, 2014-07-28 (annotated)
- Committer:
- Sissors
- Date:
- Mon Jul 28 06:14:48 2014 +0000
- Revision:
- 1:128f3fe79240
- Parent:
- 0:d726461bd0af
Added include guards + only include it on correct targets (allows for re-using it in other libraries)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sissors | 0:d726461bd0af | 1 | /* |
Sissors | 0:d726461bd0af | 2 | Most mbed targets can be woken up from deepsleep by regular InterruptIn. |
Sissors | 0:d726461bd0af | 3 | On the LPC1114 this has to be done by different interrupts. This |
Sissors | 0:d726461bd0af | 4 | simple library helps with that |
Sissors | 0:d726461bd0af | 5 | */ |
Sissors | 0:d726461bd0af | 6 | |
Sissors | 1:128f3fe79240 | 7 | //Only include it for correct target. This allows me to re-use it in WakeUp lib |
Sissors | 1:128f3fe79240 | 8 | #ifdef TARGET_LPC11XX_11CXX |
Sissors | 1:128f3fe79240 | 9 | |
Sissors | 1:128f3fe79240 | 10 | #ifndef WAKEINTERRUPTIN_H |
Sissors | 1:128f3fe79240 | 11 | #define WAKEINTERRUPTIN_H |
Sissors | 1:128f3fe79240 | 12 | |
Sissors | 0:d726461bd0af | 13 | #include "mbed.h" |
Sissors | 0:d726461bd0af | 14 | #define NUM_CHANNEL 13 |
Sissors | 0:d726461bd0af | 15 | |
Sissors | 0:d726461bd0af | 16 | /** Class to wake LPC1114 from deepsleep |
Sissors | 0:d726461bd0af | 17 | * |
Sissors | 0:d726461bd0af | 18 | * Use like regular InterruptIn, it works not only |
Sissors | 0:d726461bd0af | 19 | * to wake up from sleep but also just like InterruptIn. |
Sissors | 0:d726461bd0af | 20 | * Only you can NOT attach both rising and falling edge interrupts. |
Sissors | 0:d726461bd0af | 21 | */ |
Sissors | 0:d726461bd0af | 22 | class WakeInterruptIn : DigitalIn { |
Sissors | 0:d726461bd0af | 23 | public: |
Sissors | 0:d726461bd0af | 24 | |
Sissors | 0:d726461bd0af | 25 | /** Constructor |
Sissors | 0:d726461bd0af | 26 | * |
Sissors | 0:d726461bd0af | 27 | * Pins which are allowed are all pins from Port 0 and P1_0 |
Sissors | 0:d726461bd0af | 28 | * |
Sissors | 0:d726461bd0af | 29 | * @param pin Pin to use as WakeInterruptIn pin |
Sissors | 0:d726461bd0af | 30 | */ |
Sissors | 0:d726461bd0af | 31 | WakeInterruptIn(PinName pin); |
Sissors | 0:d726461bd0af | 32 | |
Sissors | 0:d726461bd0af | 33 | ~WakeInterruptIn() { |
Sissors | 0:d726461bd0af | 34 | disable(); |
Sissors | 0:d726461bd0af | 35 | objects[channel] = NULL; |
Sissors | 0:d726461bd0af | 36 | } |
Sissors | 0:d726461bd0af | 37 | |
Sissors | 0:d726461bd0af | 38 | /* Attach rising edge interrupt |
Sissors | 0:d726461bd0af | 39 | * |
Sissors | 0:d726461bd0af | 40 | * Attaching a member function can be done the regular way too |
Sissors | 0:d726461bd0af | 41 | * |
Sissors | 0:d726461bd0af | 42 | * @argument fptr Pointer to function to call, NULL to disable interrupt |
Sissors | 0:d726461bd0af | 43 | */ |
Sissors | 0:d726461bd0af | 44 | void rise(void (*fptr)(void)) { |
Sissors | 0:d726461bd0af | 45 | fpointer.attach(fptr); |
Sissors | 0:d726461bd0af | 46 | LPC_SYSCON->STARTAPRP0 |= (1 << channel); |
Sissors | 0:d726461bd0af | 47 | if (fptr == NULL) |
Sissors | 0:d726461bd0af | 48 | disable(); |
Sissors | 0:d726461bd0af | 49 | else |
Sissors | 0:d726461bd0af | 50 | enable(); |
Sissors | 0:d726461bd0af | 51 | } |
Sissors | 0:d726461bd0af | 52 | template<typename T> |
Sissors | 0:d726461bd0af | 53 | void rise(T* tptr, void (T::*mptr)(void)) { |
Sissors | 0:d726461bd0af | 54 | fpointer.attach(tptr, mptr); |
Sissors | 0:d726461bd0af | 55 | LPC_SYSCON->STARTAPRP0 |= (1 << channel); |
Sissors | 0:d726461bd0af | 56 | if (fptr == NULL) |
Sissors | 0:d726461bd0af | 57 | disable(); |
Sissors | 0:d726461bd0af | 58 | else |
Sissors | 0:d726461bd0af | 59 | enable(); |
Sissors | 0:d726461bd0af | 60 | } |
Sissors | 0:d726461bd0af | 61 | |
Sissors | 0:d726461bd0af | 62 | /* Attach falling edge interrupt |
Sissors | 0:d726461bd0af | 63 | * |
Sissors | 0:d726461bd0af | 64 | * Attaching a member function can be done the regular way too |
Sissors | 0:d726461bd0af | 65 | * |
Sissors | 0:d726461bd0af | 66 | * @argument fptr Pointer to function to call, NULL to disable interrupt |
Sissors | 0:d726461bd0af | 67 | */ |
Sissors | 0:d726461bd0af | 68 | void fall(void (*fptr)(void)) { |
Sissors | 0:d726461bd0af | 69 | fpointer.attach(fptr); |
Sissors | 0:d726461bd0af | 70 | LPC_SYSCON->STARTAPRP0 &= ~(1 << channel); |
Sissors | 0:d726461bd0af | 71 | if (fptr == NULL) |
Sissors | 0:d726461bd0af | 72 | disable(); |
Sissors | 0:d726461bd0af | 73 | else |
Sissors | 0:d726461bd0af | 74 | enable(); |
Sissors | 0:d726461bd0af | 75 | } |
Sissors | 0:d726461bd0af | 76 | template<typename T> |
Sissors | 0:d726461bd0af | 77 | void fall(T* tptr, void (T::*mptr)(void)) { |
Sissors | 0:d726461bd0af | 78 | fpointer.attach(tptr, mptr); |
Sissors | 0:d726461bd0af | 79 | LPC_SYSCON->STARTAPRP0 &= ~(1 << channel); |
Sissors | 0:d726461bd0af | 80 | if (fptr == NULL) |
Sissors | 0:d726461bd0af | 81 | disable(); |
Sissors | 0:d726461bd0af | 82 | else |
Sissors | 0:d726461bd0af | 83 | enable(); |
Sissors | 0:d726461bd0af | 84 | } |
Sissors | 0:d726461bd0af | 85 | |
Sissors | 0:d726461bd0af | 86 | |
Sissors | 0:d726461bd0af | 87 | |
Sissors | 0:d726461bd0af | 88 | private: |
Sissors | 0:d726461bd0af | 89 | uint8_t channel; |
Sissors | 0:d726461bd0af | 90 | FunctionPointer fpointer; |
Sissors | 0:d726461bd0af | 91 | |
Sissors | 0:d726461bd0af | 92 | void enable(void) { |
Sissors | 1:128f3fe79240 | 93 | LPC_SYSCON->STARTRSRP0CLR = 1 << channel; |
Sissors | 0:d726461bd0af | 94 | LPC_SYSCON->STARTERP0 |= (1 << channel); |
Sissors | 0:d726461bd0af | 95 | NVIC_EnableIRQ((IRQn_Type)channel); |
Sissors | 0:d726461bd0af | 96 | } |
Sissors | 0:d726461bd0af | 97 | |
Sissors | 0:d726461bd0af | 98 | void disable(void) { |
Sissors | 0:d726461bd0af | 99 | LPC_SYSCON->STARTERP0 &= ~(1 << channel); |
Sissors | 0:d726461bd0af | 100 | NVIC_DisableIRQ((IRQn_Type)channel); |
Sissors | 0:d726461bd0af | 101 | } |
Sissors | 0:d726461bd0af | 102 | |
Sissors | 0:d726461bd0af | 103 | void handle( void ) { |
Sissors | 0:d726461bd0af | 104 | LPC_SYSCON->STARTRSRP0CLR = 1 << channel; |
Sissors | 0:d726461bd0af | 105 | fpointer.call(); |
Sissors | 0:d726461bd0af | 106 | } |
Sissors | 0:d726461bd0af | 107 | |
Sissors | 0:d726461bd0af | 108 | static WakeInterruptIn* objects[NUM_CHANNEL]; |
Sissors | 0:d726461bd0af | 109 | static void handler0(void) { objects[0]->handle(); } |
Sissors | 0:d726461bd0af | 110 | static void handler1(void) { objects[1]->handle(); } |
Sissors | 0:d726461bd0af | 111 | static void handler2(void) { objects[2]->handle(); } |
Sissors | 0:d726461bd0af | 112 | static void handler3(void) { objects[3]->handle(); } |
Sissors | 0:d726461bd0af | 113 | static void handler4(void) { objects[4]->handle(); } |
Sissors | 0:d726461bd0af | 114 | static void handler5(void) { objects[5]->handle(); } |
Sissors | 0:d726461bd0af | 115 | static void handler6(void) { objects[6]->handle(); } |
Sissors | 0:d726461bd0af | 116 | static void handler7(void) { objects[7]->handle(); } |
Sissors | 0:d726461bd0af | 117 | static void handler8(void) { objects[8]->handle(); } |
Sissors | 0:d726461bd0af | 118 | static void handler9(void) { objects[9]->handle(); } |
Sissors | 0:d726461bd0af | 119 | static void handler10(void) { objects[10]->handle(); } |
Sissors | 0:d726461bd0af | 120 | static void handler11(void) { objects[11]->handle(); } |
Sissors | 0:d726461bd0af | 121 | static void handler12(void) { objects[12]->handle(); } |
Sissors | 0:d726461bd0af | 122 | |
Sissors | 1:128f3fe79240 | 123 | }; |
Sissors | 1:128f3fe79240 | 124 | #endif |
Sissors | 1:128f3fe79240 | 125 | #endif |