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
DebounceIntRTOS.h
00001 /* DebounceInt 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 // Usage: 00009 // Declare a DebounceInt 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 "DebounceInt.h" 00018 //DigitalOut myled(LED1); 00019 //InterruptIn upPressed(p15); 00020 //DebounceInt *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 DebounceInt(p15,50000); //create DebounceInt 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 "rtos.h" 00040 #include "InterruptMask.h" 00041 00042 #ifndef DEBOUNCEINT 00043 #define DEBOUNCEINT 00044 #define _DEBOUNCEINTDELAYDEFAULT 50 //milli-seconds, this number would be about 50 ms 00045 #define _MINDBOUNCEDELAY 0.1 00046 class DebounceInt{ 00047 public://members 00048 private://members 00049 InterruptMask* pinIntMask; //Internal InterruptMask object 00050 unsigned int delay; //this is the debounce delay, during which the interrupt in question is masked 00051 RtosTimer *debounceCallBackRise,*debounceCallBackFall; 00052 00053 public://methods 00054 DebounceInt(); //Default constructor, required but not to be used, will yield error and exit. 00055 DebounceInt(PinName pin);//Constructor with PinName, delay will remain default value 00056 DebounceInt(PinName pin,unsigned int delay_us);//Constructor with PinName and specified delay in micro-seconds 00057 void setDelay(unsigned int); //method to modify delay for debounce in us 00058 void debouncePinRise(void); //method to be called within Interrupt Service Routine to debounce GPIO pin on rising edge 00059 void debouncePinFall(void); //method to be called within Interrupt Service Routine to debounce GPIO pin on falling edge 00060 00061 private://methods 00062 void debounceCallbackPinRise(void); //internal callback used to re-enable (unmask) interrupts on rising edge 00063 void debounceCallbackPinFall(void); //internal callback used to re-enable (unmask) interrupts on falling edge 00064 static void wrapperDebouncePinRise(void const *ptr2Object); 00065 static void wrapperDebouncePinFall(void const *ptr2Object); 00066 00067 }; 00068 00069 #endif
Generated on Sat Jul 16 2022 02:32:15 by
1.7.2
