From 64bfec79b2d1d75b5c06be2dc2fff83ee385a720 Mon Sep 17 00:00:00 2001 From: Nathan Conrad Date: Sat, 14 Sep 2019 18:07:12 -0400 Subject: Change requset type parameter back to uint8_t (fix type cast), support USB indicator pulse --- examples/device/usbtmc/src/main.c | 47 +++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 9 deletions(-) (limited to 'examples/device/usbtmc/src/main.c') diff --git a/examples/device/usbtmc/src/main.c b/examples/device/usbtmc/src/main.c index 0293261ad..8bc2a8398 100644 --- a/examples/device/usbtmc/src/main.c +++ b/examples/device/usbtmc/src/main.c @@ -36,12 +36,12 @@ /* Blink pattern * - 250 ms : device not mounted - * - 1000 ms : device mounted + * - 0 ms : device mounted * - 2500 ms : device is suspended */ enum { BLINK_NOT_MOUNTED = 250, - BLINK_MOUNTED = 1000, + BLINK_MOUNTED = 0, BLINK_SUSPENDED = 2500, }; @@ -97,17 +97,46 @@ void tud_resume_cb(void) } //--------------------------------------------------------------------+ -// BLINKING TASK +// BLINKING TASK + Indicator pulse //--------------------------------------------------------------------+ + + +volatile uint8_t doPulse = false; +// called from USB context +void led_indicator_pulse(void) { + doPulse = true; +} + void led_blinking_task(void) { static uint32_t start_ms = 0; static bool led_state = false; + if(blink_interval_ms == BLINK_MOUNTED) // Mounted + { + if(doPulse) + { + led_state = true; + board_led_write(true); + start_ms = board_millis(); + doPulse = false; + } + else if (led_state == true) + { + if ( board_millis() - start_ms < 750) //Spec says blink must be between 500 and 1000 ms. + { + return; // not enough time + } + led_state = false; + board_led_write(false); + } + } + else + { + // Blink every interval ms + if ( board_millis() - start_ms < blink_interval_ms) return; // not enough time + start_ms += blink_interval_ms; - // Blink every interval ms - if ( board_millis() - start_ms < blink_interval_ms) return; // not enough time - start_ms += blink_interval_ms; - - board_led_write(led_state); - led_state = 1 - led_state; // toggle + board_led_write(led_state); + led_state = 1 - led_state; // toggle + } } -- cgit v1.3.1