summaryrefslogtreecommitdiff
path: root/examples/device/usbtmc/src/main.c
diff options
context:
space:
mode:
authorNathan Conrad <[email protected]>2019-09-14 18:07:12 -0400
committerNathan Conrad <[email protected]>2019-09-14 18:11:07 -0400
commit64bfec79b2d1d75b5c06be2dc2fff83ee385a720 (patch)
treed9cf0c0ded83ee06bca0cd8c73e10f754c065ff9 /examples/device/usbtmc/src/main.c
parent6e00886ffbbc552cf91be73d57fe8ad0a4842d0b (diff)
Change requset type parameter back to uint8_t (fix type cast), support USB indicator pulse
Diffstat (limited to 'examples/device/usbtmc/src/main.c')
-rw-r--r--examples/device/usbtmc/src/main.c47
1 files changed, 38 insertions, 9 deletions
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
+ }
}