Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of DebounceInt by
DebounceInt2.h
00001 /* DebounceInt2 Library */ 00002 /* This class enables debouncing a GPIO interrupt from a specific MBED pin */ 00003 /* It does so by using the InterruptMask library to temporarily mask the interrupt */ 00004 /* from the specified pin for a user specified delay specified in us. After the delay */ 00005 /* time has passed the interrupt is unmasked (reenabled) and any pending interrupts */ 00006 /* also cleared. The library gives you the flexibiity to debounce on either the */ 00007 /* rising or falling edge interrupts. */ 00008 // Deprecated Usage: 00009 // Declare a DebounceInt2 object with a valid mbed pin (p5-p30 except p19 and p20) as 00010 // an argument. Within your interrupt service routine call the appropriate debounce 00011 // method debouncePinRise or debouncePinFall. 00012 // Requires the InterruptMask library available at: https://mbed.org/users/nleoni/code/InterruptMask/ 00013 00014 // 00015 // Example Code: toggles LED1 on falling edge interrupt 00016 //#include "mbed.h" 00017 //#include "DebounceInt2.h" 00018 //DigitalOut myled(LED1); 00019 //InterruptIn upPressed(p15); 00020 //DebounceInt2 *upPressedDebounce; //debounce object to be used within interrupt for joystick up 00021 // //note that pointer is defined here to have global variable 00022 // //but constructor call must be within the main function. 00023 //int main() { 00024 // upPressedDebounce = new DebounceInt2(p15,50000); //create DebounceInt2 object for p15 interrupt 00025 // //with a 50000 us delay (interrupt disabled to avoid bounce) 00026 // upPressed.fall(ISRup); //attach joystick up click on falling edge, that is when 00027 // //user releases the joystick the action will happen 00028 // while(1){ 00029 // } 00030 //} 00031 //void ISRup(void){ 00032 // upPressedDebounce->debouncePinFall(); //call debounce method on pin fall, will disable interrupt for 00033 // //specified delay 00034 // myled=!myled; 00035 //} 00036 00037 00038 #include "mbed.h" 00039 #include "InterruptMask.h" 00040 00041 #ifndef DebounceInt2Exclude 00042 #define DebounceInt2Exclude 00043 #define _DEBOUNCEINTDELAYDEFAULT 50000 //useconds, this number would be about 50 ms 00044 #define _MINDBOUNCEDELAY 50 00045 00046 //typedef void (*t_fhandler)(void); 00047 00048 class DebounceInt2 00049 { 00050 public://members 00051 private://members 00052 InterruptMask* pinIntMask; //Internal InterruptMask object 00053 unsigned int delay; //this is the debounce delay, during which the interrupt in question is masked 00054 Timeout debounceCallBack; 00055 InterruptIn* intRise; 00056 InterruptIn* intFall; 00057 bool riseAttached,fallAttached; 00058 FunctionPointer *riseHandler,*fallHandler; 00059 PinName pin; 00060 00061 public://methods 00062 DebounceInt2(); //Default constructor, required but not to be used, will yield error and exit. 00063 DebounceInt2(PinName pin);//Constructor with PinName, delay will remain default value 00064 DebounceInt2(PinName pin,unsigned int delay_us);//Constructor with PinName and specified delay in micro-seconds 00065 void setDelay(unsigned int); //method to modify delay for debounce in us 00066 void rise(FunctionPointer); //attach interrupt handler for interrupt on rising edge 00067 template<typename T> 00068 void rise(T* tptr, void (T::*mptr)(void)); 00069 void disableRise(void); //rise interrupt handler for rising edge 00070 void enableRise(void); //unmask rise interrupt handler for rising edge 00071 void fall(FunctionPointer); //attach interrupt handler for interrupt on falling edge 00072 template<typename T> 00073 void fall(T* tptr, void (T::*mptr)(void)); 00074 void disableFall(void); //mask fall interrupt handler for rising edge 00075 void enableFall(void); //unmask fall interrupt handler for rising edge 00076 00077 private://methods 00078 void debouncePinRise(void); //method to be called within Interrupt Service Routine to debounce GPIO pin on rising edge 00079 void debouncePinFall(void); //method to be called within Interrupt Service Routine to debounce GPIO pin on falling edge 00080 void debounceCallbackPinRise(void); //internal callback used to re-enable (unmask) interrupts on rising edge 00081 void debounceCallbackPinFall(void); //internal callback used to re-enable (unmask) interrupts on falling edge 00082 00083 }; 00084 00085 #endif
Generated on Tue Jul 19 2022 00:41:45 by
1.7.2
