Files
microchip-application-bmd38…/led.c
T

75 lines
1.5 KiB
C

#include "nrf_gpio.h"
#include "nrf_log.h"
#include "nrf_spim.h"
#include "FreeRTOS.h"
#include "semphr.h"
#include "task.h"
#include "elite_pin_ctrl.h"
#include "led.h"
#define DISP_LED_COLOR 0
#define LED_COUNT 12
typedef struct
{
uint8_t brightness : 5;
uint8_t preamble : 3;
struct led_color color;
} led_t;
led_t led[LED_COUNT];
const led_t led_default = {
.brightness = 0b00000,
.preamble = 0b111,
.color = {
.B = 0,
.G = 0,
.R = 0},
};
static void led_write(uint8_t *pucData, uint32_t ulSize)
{
spi1_write(pucData, ulSize);
}
void led_set(uint32_t idx, struct led_color color, uint8_t brightness)
{
uint32_t start_frame = 0x00000000;
led_write((void *)&start_frame, sizeof(start_frame));
led[idx].color = color;
led[idx].brightness = brightness;
for (int i = 0; i < LED_COUNT; i++)
{
led_write((void *)&led[i], sizeof(led[i]));
}
uint32_t end_frame = 0xFFFFFFFF;
led_write((void *)&end_frame, sizeof(end_frame));
}
void led_off(void)
{
NRF_LOG_INFO("LED_NONE");
uint32_t start_frame = 0x00000000;
led_write((void *)&start_frame, sizeof(start_frame));
for (int i = 0; i < LED_COUNT; i++)
{
led[i] = led_default;
led_write((void *)&led[i], sizeof(led[i]));
}
uint32_t end_frame = 0xFFFFFFFF;
led_write((void *)&end_frame, sizeof(end_frame));
}
void led_init(void)
{
// turn off
led_off();
}