-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLed.c
85 lines (76 loc) · 1.74 KB
/
Led.c
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "Main.h"
#include "Port.h"
#include "Led.h"
void LED_Init(tLED led, tLED_State state)
{
/* Add your code here! */
/* Configure led pins as output */
switch (led)
{
case LED_1:
GPIO_InitPortPin(LED_1_PORT_dir, LED_1_PIN, GPIO_OUT);
break;
case LED_2:
GPIO_InitPortPin(LED_2_PORT_dir, LED_2_PIN, GPIO_OUT);
break;
default:
/* Should not come here */
break;
}
/* Set led state */
LED_SetState(led, state);
/* End of your code */
}
void LED_Toggle(tLED led)
{
/* Add your code here! */
/* Toggle led */
if (LED_GetState(led) == LED_ON)
{
LED_SetState(led, LED_OFF);
} else
{
LED_SetState(led, LED_ON);
}
/* Delay to show toggling effect */
// Delay_MS(LED_DELAY_MS);
/* End of your code */
}
void LED_SetState(tLED led, tLED_State state)
{
/* Add your code here! */
/* Set led state */
switch (led)
{
case LED_1:
GPIO_WritePortPin(LED1_PORT, LED_1_PIN, state);
break;
case LED_2:
GPIO_WritePortPin(LED2_PORT, LED_2_PIN, state);
break;
default:
/* Should not come here */
break;
}
/* End of your code */
}
tLED_State LED_GetState(tLED led)
{
tLED_State ret = LED_OFF;
/* Add your code here! */
/* Set led state */
switch (led)
{
case LED_1:
ret = GPIO_ReadPortPin(LED1_PORT, LED_1_PIN);
break;
case LED_2:
ret = GPIO_ReadPortPin(LED2_PORT, LED_2_PIN);
break;
default:
/* Should not come here */
break;
}
/* End of your code */
return ret;
}