InterruptMask library allows masking/unmasking GPIO interrupts (attached to either the rise or falling edges). It also allows clearing pending interrupts which may come handy before unmasking them.

Committer:
nleoni
Date:
Tue Feb 18 15:41:47 2014 +0000
Revision:
2:0e3b2bc65131
Parent:
0:9db76e6c71ce
Child:
3:7b8a744ac27a
Added Improved Comments and example code within the library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nleoni 0:9db76e6c71ce 1 #include "InterruptMask.h"
nleoni 0:9db76e6c71ce 2
nleoni 2:0e3b2bc65131 3 //default constructor required, should not be use will yield error
nleoni 0:9db76e6c71ce 4 InterruptMask::InterruptMask(void){
nleoni 2:0e3b2bc65131 5 exit(1);
nleoni 0:9db76e6c71ce 6 };
nleoni 2:0e3b2bc65131 7
nleoni 2:0e3b2bc65131 8 //Constructor to be used, initialize with any valid mbed pin (p5 thru p30 except pins 19-20)
nleoni 2:0e3b2bc65131 9 //you will need one InterruptMask for every pin you want ot have control over. The constructor
nleoni 2:0e3b2bc65131 10 //will only accept a valid pin, otherwise it will cause the prgram to exit with an error.
nleoni 0:9db76e6c71ce 11 InterruptMask::InterruptMask(int somePin){
nleoni 0:9db76e6c71ce 12 switch(somePin){
nleoni 0:9db76e6c71ce 13 case p5:
nleoni 0:9db76e6c71ce 14 case p6:
nleoni 0:9db76e6c71ce 15 case p7:
nleoni 0:9db76e6c71ce 16 case p8:
nleoni 0:9db76e6c71ce 17 case p9:
nleoni 0:9db76e6c71ce 18 case p10:
nleoni 0:9db76e6c71ce 19 case p11:
nleoni 0:9db76e6c71ce 20 case p12:
nleoni 0:9db76e6c71ce 21 case p13:
nleoni 0:9db76e6c71ce 22 case p14:
nleoni 0:9db76e6c71ce 23 case p15:
nleoni 0:9db76e6c71ce 24 case p16:
nleoni 0:9db76e6c71ce 25 case p17:
nleoni 0:9db76e6c71ce 26 case p18:
nleoni 0:9db76e6c71ce 27 //These pins are in Port 0 of the LPC1768, so the proper register is selected below
nleoni 0:9db76e6c71ce 28 IOIntEnF = &(LPC_GPIOINT->IO0IntEnF);
nleoni 0:9db76e6c71ce 29 IOIntEnR = &(LPC_GPIOINT->IO0IntEnR);
nleoni 0:9db76e6c71ce 30 IOIntClr = &(LPC_GPIOINT->IO0IntClr);
nleoni 0:9db76e6c71ce 31 this->mPin=somePin; //assign pin to internal member variable
nleoni 0:9db76e6c71ce 32 mask=~(1<<( (this->mPin)-P0_0));
nleoni 0:9db76e6c71ce 33 unmask=~mask;
nleoni 0:9db76e6c71ce 34 break;
nleoni 0:9db76e6c71ce 35 case p21:
nleoni 0:9db76e6c71ce 36 case p22:
nleoni 0:9db76e6c71ce 37 case p23:
nleoni 0:9db76e6c71ce 38 case p24:
nleoni 0:9db76e6c71ce 39 case p25:
nleoni 0:9db76e6c71ce 40 case p26:
nleoni 0:9db76e6c71ce 41 case p27:
nleoni 0:9db76e6c71ce 42 case p28:
nleoni 0:9db76e6c71ce 43 case p29:
nleoni 0:9db76e6c71ce 44 case p30:
nleoni 0:9db76e6c71ce 45 //These pins are in Port 0 of the LPC1768, so the proper register is selected below
nleoni 0:9db76e6c71ce 46 IOIntEnF = &(LPC_GPIOINT->IO2IntEnF);
nleoni 0:9db76e6c71ce 47 IOIntEnR = &(LPC_GPIOINT->IO2IntEnR);
nleoni 0:9db76e6c71ce 48 IOIntClr = &(LPC_GPIOINT->IO2IntClr);
nleoni 0:9db76e6c71ce 49 this->mPin=somePin; //assign pin to internal member variable
nleoni 0:9db76e6c71ce 50 mask=~(1<<( (this->mPin)-P2_0));
nleoni 0:9db76e6c71ce 51 unmask=~mask;
nleoni 0:9db76e6c71ce 52 break;
nleoni 0:9db76e6c71ce 53 default:
nleoni 0:9db76e6c71ce 54 exit(1);
nleoni 0:9db76e6c71ce 55 }
nleoni 0:9db76e6c71ce 56 }
nleoni 0:9db76e6c71ce 57
nleoni 2:0e3b2bc65131 58
nleoni 2:0e3b2bc65131 59 //This method will mask (disable) any rising edge interrupts of the specified pin
nleoni 0:9db76e6c71ce 60 void InterruptMask::maskIntR(void){
nleoni 0:9db76e6c71ce 61 (*(this->IOIntEnR)) &= this->mask;
nleoni 0:9db76e6c71ce 62 }
nleoni 0:9db76e6c71ce 63
nleoni 2:0e3b2bc65131 64 //This method will mask (disable) any faling edge interrupts of the specified pin
nleoni 0:9db76e6c71ce 65 void InterruptMask::maskIntF(void){
nleoni 0:9db76e6c71ce 66 (*(this->IOIntEnF)) &= this->mask;
nleoni 0:9db76e6c71ce 67 }
nleoni 0:9db76e6c71ce 68
nleoni 2:0e3b2bc65131 69 //This method will unmask (enable) any rising edge interrupts of the specified pin
nleoni 0:9db76e6c71ce 70 void InterruptMask::unMaskIntR(void){
nleoni 0:9db76e6c71ce 71 (*(this->IOIntEnR)) |= this->unmask;
nleoni 0:9db76e6c71ce 72 }
nleoni 0:9db76e6c71ce 73
nleoni 2:0e3b2bc65131 74 //This method will unmask (enable) any falling edge interrupts of the specified pin
nleoni 0:9db76e6c71ce 75 void InterruptMask::unMaskIntF(void){
nleoni 0:9db76e6c71ce 76 (*(this->IOIntEnF)) |= this->unmask;
nleoni 0:9db76e6c71ce 77 }
nleoni 0:9db76e6c71ce 78
nleoni 2:0e3b2bc65131 79 //This method will clear any pending interrupts of the specified pin
nleoni 0:9db76e6c71ce 80 void InterruptMask::ClrInt(void){
nleoni 0:9db76e6c71ce 81 (*(this->IOIntClr)) |= this->unmask;
nleoni 0:9db76e6c71ce 82 }
nleoni 0:9db76e6c71ce 83