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.
Diff: debug_led.cpp
- Revision:
- 12:a8ab6e018422
- Parent:
- 0:e36b454cc2e6
- Child:
- 18:472b66aeb1f5
--- a/debug_led.cpp Thu May 09 21:24:31 2019 +0000
+++ b/debug_led.cpp Mon May 13 08:39:42 2019 +0000
@@ -6,34 +6,33 @@
init(mode);
}
-
// init function
//------------------------------------------------------------------------------------------------------------------
void Debug_led::init(char mode[11]) {
end_breakpoint = false;
number_of_breakpoints = 0;
if (strcmp(mode, "BUTTON_VDD") == 0 || strcmp(mode, "BUTTON_VCC") == 0){ //debug button is connected to VDD
- button.mode(PullDown);
- button_mode = 0;
- button.rise(callback(this, &Debug_led::end_break));
- }else{
- button.mode(PullUp); // debug button is connected to GND
- button_mode = 1;
- button.fall(callback(this, &Debug_led::end_break));
+ button.mode(PullDown); // set internal pull-down for button connected to VCC
+ button_mode = 0; // pull-down->0, pull-up->1
+ button.rise(callback(this, &Debug_led::end_break));// set IRQ function for rising edge of pin button
+ }else{ // debug button is connected to GND
+ button.mode(PullUp); // set internal pull-up for button connected to VCC
+ button_mode = 1;// pull-down->0, pull-up->1
+ button.fall(callback(this, &Debug_led::end_break)); // set IRQ function for falling edge of pin button
}
}
// perform one breakpoint
//------------------------------------------------------------------------------------------------------------------
void Debug_led::breakpoint(int number) {
- number_of_breakpoints++;
- while(button != button_mode){
+ number_of_breakpoints++; //increment number of breakpoints
+ while(button != button_mode){ //wait until is released in case that button was pushed at the begining of breakpoint
wait(0.1);
}
- wait(0.1);
+ wait(0.1); //debounce time
end_breakpoint = false;
- button.enable_irq();
- while (!end_breakpoint){
+ button.enable_irq(); //enable interrupt for button
+ while (!end_breakpoint){ // LED is periodically flashing until the button is pushed
if (number > 0){ // the number was inserted
flash_n_times(150,number);
}else{ // number was not inserted
@@ -47,20 +46,20 @@
//------------------------------------------------------------------------------------------------------------------
void Debug_led::flash_n_times(int wait_time_ms, int n) {
led = 0;
- wait_ms(4*wait_time_ms);
+ wait_ms(4*wait_time_ms);// wait for visibility of periodical flashing
for(int i = 0; i < n; i++){
led = 1;
wait_ms(wait_time_ms);
led = 0;
wait_ms(wait_time_ms);
}
- wait_ms(3*wait_time_ms);
+ wait_ms(3*wait_time_ms);// wait for visibility of periodical flashing
}
-// flash n times with breakpoint led
+// IRQ function after pushing the button
//------------------------------------------------------------------------------------------------------------------
void Debug_led::end_break() {
- button.disable_irq();
+ button.disable_irq(); //disable interrupt until the next breakpoint
end_breakpoint = true;
}