Change requset type parameter back to uint8_t (fix type cast), support USB indicator pulse

This commit is contained in:
Nathan Conrad
2019-09-14 18:07:12 -04:00
parent 6e00886ffb
commit 64bfec79b2
5 changed files with 68 additions and 22 deletions

View File

@@ -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
}
}