UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
led.c
Go to the documentation of this file.
1 
11 #include "board.h"
12 #include "../gpio.h"
13 
14 #include "../led.h"
15 
16 /* LED description struct */
17 typedef struct LED {
18  uint8_t gpio;
19  bool state;
20 } LED;
21 
22 /* Array of connected LEDs */
23 static LED LED_leds[2] =
24  { { GPIO_PC2, false } // LED A
25  , { GPIO_PB1, false } // LED B
26  };
27 #define NUMBER_OF_LEDS ( sizeof(LED_leds) / sizeof(LED) )
28 
31 void LED_on(uint8_t led_num)
32 {
33  LED_set(led_num, true);
34 }
35 
36 void LED_off(uint8_t led_num)
37 {
38  LED_set(led_num, false);
39 }
40 
41 void LED_set(uint8_t led_num, bool state)
42 {
43  if(led_num >= NUMBER_OF_LEDS)
44  return;
45  LED *led = &LED_leds[led_num];
46 
47  GPIO_write(led->gpio, state);
48 
49  led->state = state;
50 }
51 
52 void LED_toggle(uint8_t led_num)
53 {
54  if(led_num >= NUMBER_OF_LEDS)
55  return;
56  LED *led = &LED_leds[led_num];
57 
58  GPIO_write(led->gpio, !led->state);
59 
60  led->state = !led->state;
61 }
62 
Definition: led.c:5
void LED_set(uint8_t led_num, bool state)
Definition: led.c:25
void LED_off(uint8_t led_num)
Definition: led.c:20
void LED_on(uint8_t led_num)
Definition: led.c:15
void GPIO_write(uint8_t gpio_num, bool state)
Definition: gpio.c:23