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
Revision 0:d726461bd0af, committed 2014-07-26
- Comitter:
- Sissors
- Date:
- Sat Jul 26 15:02:43 2014 +0000
- Child:
- 1:128f3fe79240
- Commit message:
- v1.0
Changed in this revision
WakeInterruptIn.cpp | Show annotated file Show diff for this revision Revisions of this file |
WakeInterruptIn.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WakeInterruptIn.cpp Sat Jul 26 15:02:43 2014 +0000 @@ -0,0 +1,56 @@ +#include "WakeInterruptIn.h" + +WakeInterruptIn* WakeInterruptIn::objects[NUM_CHANNEL] = {0}; + +WakeInterruptIn::WakeInterruptIn(PinName pin) : DigitalIn(pin) +{ + if (pin < P1_0) + channel = (pin >> PIN_SHIFT) & 0xF; + else if (pin == P1_0) + channel = 12; + else + error("Pin is not valid for WakeInterruptIn"); + + objects[channel] = this; + switch (channel) { + case 0: + NVIC_SetVector((IRQn_Type)channel, (uint32_t)handler0); + break; + case 1: + NVIC_SetVector((IRQn_Type)channel, (uint32_t)handler1); + break; + case 2: + NVIC_SetVector((IRQn_Type)channel, (uint32_t)handler2); + break; + case 3: + NVIC_SetVector((IRQn_Type)channel, (uint32_t)handler3); + break; + case 4: + NVIC_SetVector((IRQn_Type)channel, (uint32_t)handler4); + break; + case 5: + NVIC_SetVector((IRQn_Type)channel, (uint32_t)handler5); + break; + case 6: + NVIC_SetVector((IRQn_Type)channel, (uint32_t)handler6); + break; + case 7: + NVIC_SetVector((IRQn_Type)channel, (uint32_t)handler7); + break; + case 8: + NVIC_SetVector((IRQn_Type)channel, (uint32_t)handler8); + break; + case 9: + NVIC_SetVector((IRQn_Type)channel, (uint32_t)handler9); + break; + case 10: + NVIC_SetVector((IRQn_Type)channel, (uint32_t)handler10); + break; + case 11: + NVIC_SetVector((IRQn_Type)channel, (uint32_t)handler11); + break; + case 12: + NVIC_SetVector((IRQn_Type)channel, (uint32_t)handler12); + break; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WakeInterruptIn.h Sat Jul 26 15:02:43 2014 +0000 @@ -0,0 +1,116 @@ +/* +Most mbed targets can be woken up from deepsleep by regular InterruptIn. +On the LPC1114 this has to be done by different interrupts. This +simple library helps with that +*/ + +#include "mbed.h" +#define NUM_CHANNEL 13 + +/** Class to wake LPC1114 from deepsleep +* +* Use like regular InterruptIn, it works not only +* to wake up from sleep but also just like InterruptIn. +* Only you can NOT attach both rising and falling edge interrupts. +*/ +class WakeInterruptIn : DigitalIn { + public: + + /** Constructor + * + * Pins which are allowed are all pins from Port 0 and P1_0 + * + * @param pin Pin to use as WakeInterruptIn pin + */ + WakeInterruptIn(PinName pin); + + ~WakeInterruptIn() { + disable(); + objects[channel] = NULL; + } + + /* Attach rising edge interrupt + * + * Attaching a member function can be done the regular way too + * + * @argument fptr Pointer to function to call, NULL to disable interrupt + */ + void rise(void (*fptr)(void)) { + fpointer.attach(fptr); + LPC_SYSCON->STARTAPRP0 |= (1 << channel); + if (fptr == NULL) + disable(); + else + enable(); + } + template<typename T> + void rise(T* tptr, void (T::*mptr)(void)) { + fpointer.attach(tptr, mptr); + LPC_SYSCON->STARTAPRP0 |= (1 << channel); + if (fptr == NULL) + disable(); + else + enable(); + } + + /* Attach falling edge interrupt + * + * Attaching a member function can be done the regular way too + * + * @argument fptr Pointer to function to call, NULL to disable interrupt + */ + void fall(void (*fptr)(void)) { + fpointer.attach(fptr); + LPC_SYSCON->STARTAPRP0 &= ~(1 << channel); + if (fptr == NULL) + disable(); + else + enable(); + } + template<typename T> + void fall(T* tptr, void (T::*mptr)(void)) { + fpointer.attach(tptr, mptr); + LPC_SYSCON->STARTAPRP0 &= ~(1 << channel); + if (fptr == NULL) + disable(); + else + enable(); + } + + + + private: + uint8_t channel; + FunctionPointer fpointer; + + void enable(void) { + LPC_SYSCON->STARTERP0 |= (1 << channel); + NVIC_EnableIRQ((IRQn_Type)channel); + } + + void disable(void) { + LPC_SYSCON->STARTERP0 &= ~(1 << channel); + NVIC_DisableIRQ((IRQn_Type)channel); + } + + void handle( void ) { + LPC_SYSCON->STARTRSRP0CLR = 1 << channel; + fpointer.call(); + } + + static WakeInterruptIn* objects[NUM_CHANNEL]; + static void handler0(void) { objects[0]->handle(); } + static void handler1(void) { objects[1]->handle(); } + static void handler2(void) { objects[2]->handle(); } + static void handler3(void) { objects[3]->handle(); } + static void handler4(void) { objects[4]->handle(); } + static void handler5(void) { objects[5]->handle(); } + static void handler6(void) { objects[6]->handle(); } + static void handler7(void) { objects[7]->handle(); } + static void handler8(void) { objects[8]->handle(); } + static void handler9(void) { objects[9]->handle(); } + static void handler10(void) { objects[10]->handle(); } + static void handler11(void) { objects[11]->handle(); } + static void handler12(void) { objects[12]->handle(); } + +}; \ No newline at end of file