-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathled.cpp
68 lines (55 loc) · 1.06 KB
/
led.cpp
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
/*
* author : Shuichi TAKANO
* since : Sat Aug 31 2019 14:34:10
*/
#include "led.h"
#include <fpioa.h>
#include <gpio.h>
namespace
{
enum
{
R,
G,
B,
};
uint8_t gpio_[3];
} // namespace
void initLED(int rPin, int rGPIO,
int gPin, int gGPIO,
int bPin, int bGPIO)
{
gpio_[R] = rGPIO;
gpio_[G] = gGPIO;
gpio_[B] = bGPIO;
fpioa_set_function(rPin, (fpioa_function_t)(FUNC_GPIO0 + rGPIO));
fpioa_set_function(gPin, (fpioa_function_t)(FUNC_GPIO0 + gGPIO));
fpioa_set_function(bPin, (fpioa_function_t)(FUNC_GPIO0 + bGPIO));
for (int i = 0; i < 3; ++i)
{
gpio_set_drive_mode(gpio_[i], GPIO_DM_OUTPUT);
gpio_set_pin(gpio_[i], GPIO_PV_HIGH);
}
}
void setLED(int i, int on)
{
gpio_set_pin(gpio_[i], on ? GPIO_PV_LOW : GPIO_PV_HIGH);
}
void setRedLED(int on)
{
setLED(R, on);
}
void setGreenLED(int on)
{
setLED(G, on);
}
void setBlueLED(int on)
{
setLED(B, on);
}
void setRGBLED(int rgbMask)
{
setLED(R, rgbMask & 1);
setLED(G, rgbMask & 2);
setLED(B, rgbMask & 4);
}