supports interrup handling within mbed rtos, using rtos compatible threads and timer threads

Fork of DebounceInt by napoleon leoni

Files at this revision

API Documentation at this revision

Comitter:
nleoni
Date:
Wed Feb 26 00:17:35 2014 +0000
Parent:
1:519b4ce3b082
Commit message:
Currently Debounce feature is turned off, it was found that somehow the RTOS timer used to re-enable the interrupts is not yet operating

Changed in this revision

DebounceInt.cpp Show diff for this revision Revisions of this file
DebounceInt.h Show diff for this revision Revisions of this file
DebounceIntRTOS.cpp Show annotated file Show diff for this revision Revisions of this file
DebounceIntRTOS.h Show annotated file Show diff for this revision Revisions of this file
--- a/DebounceInt.cpp	Tue Feb 25 19:55:04 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,86 +0,0 @@
-/* DebounceInt Library */
-/* This class enables debouncing a GPIO interrupt from a specific MBED pin            */
-/* It does so by using the InterruptMask library to temporarily mask the interrupt    */
-/* from the specified pin for a user specified delay specified in us. After the delay */
-/* time has passed the interrupt is unmasked (reenabled) and any pending interrupts   */
-/* also cleared. The library gives you the flexibiity to debounce on either the       */
-/* rising or falling edge interrupts.                                                 */
-// Usage:
-// Declare a DebounceInt object with a valid mbed pin (p5-p30 except p19 and p20) as 
-// an argument. Within your interrupt service routine call the appropriate debounce
-// method debouncePinRise or debouncePinFall. 
-// Requires the InterruptMask library available at: https://mbed.org/users/nleoni/code/InterruptMask/
-
-#include "DebounceInt.h"
-
-//Default constructor, required but not to be used, will yield error and exit.
-    DebounceInt::DebounceInt(){
-        exit(1);
-    }
-    
-//Constructor with PinName, delay will remain default value
-    DebounceInt::DebounceInt(PinName pin){
-    // Inputs:
-    // PinName pin: Expected Proper Mbed Pin (e.g. p12), program will exit otherwise
-        this->pinIntMask = new InterruptMask(pin);
-        this->debounceCallBackRise = new RtosTimer(&DebounceInt::wrapperDebouncePinRise, osTimerOnce, this);
-        this->debounceCallBackFall = new RtosTimer(&DebounceInt::wrapperDebouncePinFall, osTimerOnce, this);
-        this->setDelay(_DEBOUNCEINTDELAYDEFAULT);
-    }
-    
-    
-//Constructor with PinName and specified delay in micro-seconds
-    DebounceInt::DebounceInt(PinName pin,unsigned int delay_ms){
-    // Inputs:
-    // PinName pin: Expected Proper Mbed Pin (e.g. p12), program will exit otherwise
-    // unsigned int delay: Expected positive delay, will force delay to be larger
-    // than minimum delay _MINDBOUNCEDELAY
-        this->pinIntMask = new InterruptMask(pin);        
-        this->setDelay(delay_ms);
-    }
-
-//method to modify delay for debounce in us
-    void DebounceInt::setDelay(unsigned int delay_ms){
-    // Inputs:
-    // unsigned int delay: Expected positive delay, will force delay to be larger
-    // than minimum delay _MINDBOUNCEDELAY
-        if(delay_ms>(_MINDBOUNCEDELAY) ){
-            this->delay=delay_ms;
-        } else { 
-            this->delay=_MINDBOUNCEDELAY;
-        }
-    } 
-
-//method to be called within Interrupt Service Routine to debounce GPIO pin on rising edge
-    void DebounceInt::debouncePinRise(void){
-        this->pinIntMask->maskIntR();
-        this->debounceCallBackRise->start(this->delay);
-    }
-    
-    void DebounceInt::wrapperDebouncePinRise(void const *ptr2Object){
-        DebounceInt* instance = (DebounceInt*) ptr2Object;    
-        instance->debounceCallbackPinRise();
-    }
-
-    void DebounceInt::wrapperDebouncePinFall(void const *ptr2Object){
-        DebounceInt* instance = (DebounceInt*) ptr2Object;    
-        instance->debounceCallbackPinFall();
-    }
-
-//internal callback used to re-enable (unmask) interrupts on rising edge
-    void DebounceInt::debounceCallbackPinRise(void){
-        this->pinIntMask->ClrInt();
-        this->pinIntMask->unMaskIntR();
-    }
-
-//method to be called within Interrupt Service Routine to debounce GPIO pin on falling edge
-    void DebounceInt::debouncePinFall(void){
-        this->pinIntMask->maskIntF();
-        this->debounceCallBackFall->start(this->delay);
-    }
-    
-//internal callback used to re-enable (unmask) interrupts on falling edge
-    void DebounceInt::debounceCallbackPinFall(void){
-        this->pinIntMask->ClrInt();
-        this->pinIntMask->unMaskIntF();
-    }
\ No newline at end of file
--- a/DebounceInt.h	Tue Feb 25 19:55:04 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/* DebounceInt Library */
-/* This class enables debouncing a GPIO interrupt from a specific MBED pin            */
-/* It does so by using the InterruptMask library to temporarily mask the interrupt    */
-/* from the specified pin for a user specified delay specified in us. After the delay */
-/* time has passed the interrupt is unmasked (reenabled) and any pending interrupts   */
-/* also cleared. The library gives you the flexibiity to debounce on either the       */
-/* rising or falling edge interrupts.                                                 */
-// Usage:
-// Declare a DebounceInt object with a valid mbed pin (p5-p30 except p19 and p20) as 
-// an argument. Within your interrupt service routine call the appropriate debounce
-// method debouncePinRise or debouncePinFall. 
-// Requires the InterruptMask library available at: https://mbed.org/users/nleoni/code/InterruptMask/
-
-//
-// Example Code: toggles LED1 on falling edge interrupt
-//#include "mbed.h"
-//#include "DebounceInt.h"
-//DigitalOut myled(LED1);
-//InterruptIn upPressed(p15);
-//DebounceInt *upPressedDebounce; //debounce object to be used within interrupt for joystick up
-//                                //note that pointer is defined here to have global variable
-//                                //but constructor call must be within the main function.
-//int main() {
-//  upPressedDebounce = new DebounceInt(p15,50000); //create DebounceInt object for p15 interrupt
-//                                                  //with a 50000 us delay (interrupt disabled to avoid bounce)                                    
-//  upPressed.fall(ISRup);            //attach joystick up click on falling edge, that is when
-//                                    //user releases the joystick the action will happen
-//  while(1){
-//  }
-//}
-//void ISRup(void){
-//    upPressedDebounce->debouncePinFall(); //call debounce method on pin fall, will disable interrupt for 
-//                                          //specified delay
-//    myled=!myled;
-//}
-
-
-#include "mbed.h"
-#include "rtos.h"
-#include "InterruptMask.h"
-
-#ifndef DEBOUNCEINT
-#define DEBOUNCEINT
-#define _DEBOUNCEINTDELAYDEFAULT 50 //milli-seconds, this number would be about 50 ms
-#define _MINDBOUNCEDELAY 0.1
-class DebounceInt{
-public://members
-private://members
-    InterruptMask* pinIntMask; //Internal InterruptMask object
-    unsigned int delay; //this is the debounce delay, during which the interrupt in question is masked
-    RtosTimer *debounceCallBackRise,*debounceCallBackFall;
-
-public://methods
-    DebounceInt();     //Default constructor, required but not to be used, will yield error and exit.
-    DebounceInt(PinName pin);//Constructor with PinName, delay will remain default value
-    DebounceInt(PinName pin,unsigned int delay_us);//Constructor with PinName and specified delay in micro-seconds
-    void setDelay(unsigned int); //method to modify delay for debounce in us
-    void debouncePinRise(void);  //method to be called within Interrupt Service Routine to debounce GPIO pin on rising edge
-    void debouncePinFall(void);  //method to be called within Interrupt Service Routine to debounce GPIO pin on falling edge
-    
-private://methods
-    void debounceCallbackPinRise(void); //internal callback used to re-enable (unmask) interrupts on rising edge
-    void debounceCallbackPinFall(void); //internal callback used to re-enable (unmask) interrupts on falling edge
-    static void wrapperDebouncePinRise(void const *ptr2Object);
-    static void wrapperDebouncePinFall(void const *ptr2Object);
-    
-};
-
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DebounceIntRTOS.cpp	Wed Feb 26 00:17:35 2014 +0000
@@ -0,0 +1,92 @@
+/* DebounceInt Library */
+/* This class enables debouncing a GPIO interrupt from a specific MBED pin            */
+/* It does so by using the InterruptMask library to temporarily mask the interrupt    */
+/* from the specified pin for a user specified delay specified in us. After the delay */
+/* time has passed the interrupt is unmasked (reenabled) and any pending interrupts   */
+/* also cleared. The library gives you the flexibiity to debounce on either the       */
+/* rising or falling edge interrupts.                                                 */
+// Usage:
+// Declare a DebounceInt object with a valid mbed pin (p5-p30 except p19 and p20) as 
+// an argument. Within your interrupt service routine call the appropriate debounce
+// method debouncePinRise or debouncePinFall. 
+// Requires the InterruptMask library available at: https://mbed.org/users/nleoni/code/InterruptMask/
+
+#include "DebounceIntRTOS.h"
+
+//Default constructor, required but not to be used, will yield error and exit.
+    DebounceInt::DebounceInt(){
+        exit(1);
+    }
+    
+//Constructor with PinName, delay will remain default value
+    DebounceInt::DebounceInt(PinName pin){
+    // Inputs:
+    // PinName pin: Expected Proper Mbed Pin (e.g. p12), program will exit otherwise
+        this->pinIntMask = new InterruptMask(pin);
+        this->debounceCallBackRise = new RtosTimer(&DebounceInt::wrapperDebouncePinRise, osTimerPeriodic, this);
+        this->debounceCallBackFall = new RtosTimer(&DebounceInt::wrapperDebouncePinFall, osTimerPeriodic, this);
+        this->setDelay(_DEBOUNCEINTDELAYDEFAULT);
+    }
+    
+    
+//Constructor with PinName and specified delay in micro-seconds
+    DebounceInt::DebounceInt(PinName pin,unsigned int delay_ms){
+    // Inputs:
+    // PinName pin: Expected Proper Mbed Pin (e.g. p12), program will exit otherwise
+    // unsigned int delay: Expected positive delay, will force delay to be larger
+    // than minimum delay _MINDBOUNCEDELAY
+        this->pinIntMask = new InterruptMask(pin);        
+        this->debounceCallBackRise = new RtosTimer(&DebounceInt::wrapperDebouncePinRise, osTimerPeriodic, this);
+        this->debounceCallBackFall = new RtosTimer(&DebounceInt::wrapperDebouncePinFall, osTimerPeriodic, this);
+        this->setDelay(delay_ms);
+    }
+
+//method to modify delay for debounce in us
+    void DebounceInt::setDelay(unsigned int delay_ms){
+    // Inputs:
+    // unsigned int delay: Expected positive delay, will force delay to be larger
+    // than minimum delay _MINDBOUNCEDELAY
+        if(delay_ms>(_MINDBOUNCEDELAY) ){
+            this->delay=delay_ms;
+        } else { 
+            this->delay=_MINDBOUNCEDELAY;
+        }
+    } 
+
+//method to be called within Interrupt Service Routine to debounce GPIO pin on rising edge
+    void DebounceInt::debouncePinRise(void){
+        //this->pinIntMask->maskIntR();
+        this->debounceCallBackRise->start(this->delay);
+    }
+    
+    void DebounceInt::wrapperDebouncePinRise(void const *ptr2Object){
+        DebounceInt* instance = (DebounceInt*) ptr2Object;    
+        instance->debounceCallbackPinRise();
+    }
+
+    void DebounceInt::wrapperDebouncePinFall(void const *ptr2Object){
+        DebounceInt* instance = (DebounceInt*) ptr2Object;    
+        instance->debounceCallbackPinFall();
+    }
+
+//internal callback used to re-enable (unmask) interrupts on rising edge
+    void DebounceInt::debounceCallbackPinRise(void){
+        this->pinIntMask->ClrInt();
+        this->pinIntMask->unMaskIntR();
+        this->debounceCallBackRise->stop();
+
+    }
+
+//method to be called within Interrupt Service Routine to debounce GPIO pin on falling edge
+    void DebounceInt::debouncePinFall(void){
+        //this->pinIntMask->maskIntF();
+        this->debounceCallBackFall->start(this->delay);
+    }
+    
+//internal callback used to re-enable (unmask) interrupts on falling edge
+    void DebounceInt::debounceCallbackPinFall(void){
+        this->pinIntMask->ClrInt();
+        this->pinIntMask->unMaskIntF();
+        this->debounceCallBackFall->stop();
+
+    }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DebounceIntRTOS.h	Wed Feb 26 00:17:35 2014 +0000
@@ -0,0 +1,69 @@
+/* DebounceInt Library */
+/* This class enables debouncing a GPIO interrupt from a specific MBED pin            */
+/* It does so by using the InterruptMask library to temporarily mask the interrupt    */
+/* from the specified pin for a user specified delay specified in us. After the delay */
+/* time has passed the interrupt is unmasked (reenabled) and any pending interrupts   */
+/* also cleared. The library gives you the flexibiity to debounce on either the       */
+/* rising or falling edge interrupts.                                                 */
+// Usage:
+// Declare a DebounceInt object with a valid mbed pin (p5-p30 except p19 and p20) as 
+// an argument. Within your interrupt service routine call the appropriate debounce
+// method debouncePinRise or debouncePinFall. 
+// Requires the InterruptMask library available at: https://mbed.org/users/nleoni/code/InterruptMask/
+
+//
+// Example Code: toggles LED1 on falling edge interrupt
+//#include "mbed.h"
+//#include "DebounceInt.h"
+//DigitalOut myled(LED1);
+//InterruptIn upPressed(p15);
+//DebounceInt *upPressedDebounce; //debounce object to be used within interrupt for joystick up
+//                                //note that pointer is defined here to have global variable
+//                                //but constructor call must be within the main function.
+//int main() {
+//  upPressedDebounce = new DebounceInt(p15,50000); //create DebounceInt object for p15 interrupt
+//                                                  //with a 50000 us delay (interrupt disabled to avoid bounce)                                    
+//  upPressed.fall(ISRup);            //attach joystick up click on falling edge, that is when
+//                                    //user releases the joystick the action will happen
+//  while(1){
+//  }
+//}
+//void ISRup(void){
+//    upPressedDebounce->debouncePinFall(); //call debounce method on pin fall, will disable interrupt for 
+//                                          //specified delay
+//    myled=!myled;
+//}
+
+
+#include "mbed.h"
+#include "rtos.h"
+#include "InterruptMask.h"
+
+#ifndef DEBOUNCEINT
+#define DEBOUNCEINT
+#define _DEBOUNCEINTDELAYDEFAULT 50 //milli-seconds, this number would be about 50 ms
+#define _MINDBOUNCEDELAY 0.1
+class DebounceInt{
+public://members
+private://members
+    InterruptMask* pinIntMask; //Internal InterruptMask object
+    unsigned int delay; //this is the debounce delay, during which the interrupt in question is masked
+    RtosTimer *debounceCallBackRise,*debounceCallBackFall;
+
+public://methods
+    DebounceInt();     //Default constructor, required but not to be used, will yield error and exit.
+    DebounceInt(PinName pin);//Constructor with PinName, delay will remain default value
+    DebounceInt(PinName pin,unsigned int delay_us);//Constructor with PinName and specified delay in micro-seconds
+    void setDelay(unsigned int); //method to modify delay for debounce in us
+    void debouncePinRise(void);  //method to be called within Interrupt Service Routine to debounce GPIO pin on rising edge
+    void debouncePinFall(void);  //method to be called within Interrupt Service Routine to debounce GPIO pin on falling edge
+    
+private://methods
+    void debounceCallbackPinRise(void); //internal callback used to re-enable (unmask) interrupts on rising edge
+    void debounceCallbackPinFall(void); //internal callback used to re-enable (unmask) interrupts on falling edge
+    static void wrapperDebouncePinRise(void const *ptr2Object);
+    static void wrapperDebouncePinFall(void const *ptr2Object);
+    
+};
+
+#endif