78 lines
1.7 KiB
C
78 lines
1.7 KiB
C
#include "nrf_gpio.h"
|
|
#include "nrf_log.h"
|
|
#include "nrf_spim.h"
|
|
|
|
#include "apa102_2020.h"
|
|
|
|
#include "FreeRTOS.h"
|
|
#include "task.h"
|
|
|
|
#if (DEF_APA102_2020_ENABLED)
|
|
|
|
#define DISP_LED_COLOR 0
|
|
|
|
typedef struct
|
|
{
|
|
uint8_t brightness : 5;
|
|
uint8_t preamble : 3;
|
|
struct led_color color;
|
|
} led_t;
|
|
|
|
static led_t *p_led = NULL;
|
|
static uint32_t led_count = 0;
|
|
|
|
const led_t led_default = {
|
|
.brightness = 0b00000,
|
|
.preamble = 0b111,
|
|
.color = {
|
|
.B = 0,
|
|
.G = 0,
|
|
.R = 0},
|
|
};
|
|
|
|
static void apa102_led_write(uint8_t *pucData, uint32_t ulSize)
|
|
{
|
|
spi1_write(pucData, ulSize);
|
|
}
|
|
|
|
int32_t apa102_led_set(uint32_t idx, struct led_color color, uint8_t brightness)
|
|
{
|
|
uint32_t start_frame = 0x00000000;
|
|
uint32_t end_frame = 0xFFFFFFFF;
|
|
p_led[idx].color = color;
|
|
p_led[idx].brightness = brightness;
|
|
|
|
apa102_led_write((void *)&start_frame, sizeof(start_frame));
|
|
apa102_led_write((void *)p_led, led_count * sizeof(*p_led));
|
|
apa102_led_write((void *)&end_frame, sizeof(end_frame));
|
|
|
|
return 0;
|
|
}
|
|
|
|
int32_t apa102_init(uint32_t cnt)
|
|
{
|
|
uint32_t start_frame = 0x00000000;
|
|
uint32_t end_frame = 0xFFFFFFFF;
|
|
|
|
led_count = cnt;
|
|
p_led = pvPortMalloc(led_count * sizeof(*p_led));
|
|
|
|
for (int i = 0; i < led_count; i++)
|
|
{
|
|
p_led[i] = led_default;
|
|
}
|
|
|
|
apa102_led_write((void *)&start_frame, sizeof(start_frame));
|
|
apa102_led_write((void *)p_led, led_count * sizeof(*p_led));
|
|
apa102_led_write((void *)&end_frame, sizeof(end_frame));
|
|
|
|
return 0;
|
|
}
|
|
|
|
const led_drv_if_t apa102_drv = {
|
|
.init = apa102_init,
|
|
.set = apa102_led_set,
|
|
};
|
|
|
|
#endif /* ! DEF_APA102_2020_ENABLED */
|