Skip to content

Commit e9c5c84

Browse files
authored
refine xor flip to ensure we only flip once per millisecond (#479)
1 parent 6afbc9b commit e9c5c84

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ll/status_led.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#include "status_led.h"
22

3+
#include <stdbool.h>
4+
35
// LED on GPIO A15
46

57
static GPIO_InitTypeDef GPIO_IS;
68
static LED_SPEED fast_blink;
9+
static bool do_flip = false;
710

811
void status_led_init(void){
912
// activate peripheral clock
@@ -21,9 +24,12 @@ void status_led_init(void){
2124
// call this at a regular interval (designed for 1ms interval)
2225
uint32_t next_flip = 0;
2326
void status_led_tick(uint32_t time_now){
24-
if(time_now > next_flip){
25-
status_led_xor();
27+
if(time_now > next_flip // time to animate timer
28+
|| (do_flip && fast_blink)){ // xor event & USB connected
29+
// status_led_xor();
30+
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_15);
2631
next_flip = time_now + (fast_blink ? 2000 : 500);
32+
do_flip = false;
2733
}
2834
}
2935

@@ -36,5 +42,6 @@ void status_led_set(uint8_t is_on){
3642
}
3743

3844
void status_led_xor(void){
39-
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_15);
45+
// HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_15);
46+
do_flip = true;
4047
}

0 commit comments

Comments
 (0)