-
Notifications
You must be signed in to change notification settings - Fork 12
/
led_rgb.c
executable file
·45 lines (44 loc) · 1.07 KB
/
led_rgb.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
#include "led_rgb.h"
#include "ch.h"
#include "hal.h"
#include "hw_conf.h"
#if defined(INFINITY_V4_0) || defined(INFINITY_V3_0)
#include "ws2812b.h"
#else
static PWMConfig pwmcfg = {
512000,
256,
NULL,
{
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_ACTIVE_LOW, NULL},
{PWM_OUTPUT_ACTIVE_LOW, NULL},
{PWM_OUTPUT_ACTIVE_LOW, NULL}
},
0,
0
};
#endif
void led_rgb_init(void)
{
#if defined(INFINITY_V4_0) || defined(INFINITY_V3_0)
ws2812b_init();
#else
pwmStart(&LED_PWM_DEV, &pwmcfg);
pwmEnableChannel(&LED_PWM_DEV, LED_R_CHANNEL, 0);
pwmEnableChannel(&LED_PWM_DEV, LED_G_CHANNEL, 0);
pwmEnableChannel(&LED_PWM_DEV, LED_B_CHANNEL, 0);
#endif
}
void led_rgb_set(uint32_t color)
{
#if defined(INFINITY_V4_0) || defined(INFINITY_V3_0)
ws2812b_set_all(color);
#else
pwmEnableChannel(&LED_PWM_DEV, LED_B_CHANNEL, color & 0xFF);
color = color >> 8;
pwmEnableChannel(&LED_PWM_DEV, LED_G_CHANNEL, color & 0xFF);
color = color >> 8;
pwmEnableChannel(&LED_PWM_DEV, LED_R_CHANNEL, color & 0xFF);
#endif
}