summaryrefslogtreecommitdiffstats
path: root/app/led.c
blob: 92469f46dd436f104b06e53be8c68030da4e1233 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "project.h"


static int led_8 = 0;
static int led_9 = 0;

void
led_init (void)
{
  gpio_set_mode (GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
                 GPIO_CNF_OUTPUT_PUSHPULL, GPIO8);
  gpio_set_mode (GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
                 GPIO_CNF_OUTPUT_PUSHPULL, GPIO9);

  gpio_set (GPIOB, GPIO8);
  gpio_set (GPIOB, GPIO9);
}


void
led_set (uint32_t v)
{
  gpio_clear (GPIOB, v);
  if (v & GPIO8)
    led_8 = 50;
  if (v & GPIO9)
    led_9 = 50;
}

void
led_tick (void)
{
  if (led_8)
    {
      led_8--;
      if (!led_8)
        gpio_set (GPIOB, GPIO8);
    }
  if (led_9)
    {
      led_9--;
      if (!led_9)
        gpio_set (GPIOB, GPIO9);
    }

  if (usb_is_suspended)
    gpio_clear (GPIOB, GPIO8 | GPIO9);
}