Skip to content

Commit

Permalink
refine xor flip to ensure we only flip once per millisecond (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
trentgill authored Mar 1, 2023
1 parent 6afbc9b commit e9c5c84
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ll/status_led.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "status_led.h"

#include <stdbool.h>

// LED on GPIO A15

static GPIO_InitTypeDef GPIO_IS;
static LED_SPEED fast_blink;
static bool do_flip = false;

void status_led_init(void){
// activate peripheral clock
Expand All @@ -21,9 +24,12 @@ void status_led_init(void){
// call this at a regular interval (designed for 1ms interval)
uint32_t next_flip = 0;
void status_led_tick(uint32_t time_now){
if(time_now > next_flip){
status_led_xor();
if(time_now > next_flip // time to animate timer
|| (do_flip && fast_blink)){ // xor event & USB connected
// status_led_xor();
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_15);
next_flip = time_now + (fast_blink ? 2000 : 500);
do_flip = false;
}
}

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

void status_led_xor(void){
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_15);
// HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_15);
do_flip = true;
}

0 comments on commit e9c5c84

Please sign in to comment.