79 lines
1.7 KiB
C
79 lines
1.7 KiB
C
#include "status_led.h"
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
#include "board_pins.h"
|
|
#include "led_strip.h"
|
|
#include "led_strip_rmt.h"
|
|
|
|
#define RGB_LED_COUNT 1
|
|
#define RGB_LED_BRIGHTNESS 32
|
|
|
|
static led_strip_handle_t s_strip;
|
|
|
|
esp_err_t status_led_init(void)
|
|
{
|
|
const led_strip_config_t strip_config = {
|
|
.strip_gpio_num = BOARD_RGB_LED_GPIO,
|
|
.max_leds = RGB_LED_COUNT,
|
|
.led_model = LED_MODEL_WS2812,
|
|
.color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRB,
|
|
.flags = {
|
|
.invert_out = false,
|
|
},
|
|
};
|
|
|
|
const led_strip_rmt_config_t rmt_config = {
|
|
.clk_src = RMT_CLK_SRC_DEFAULT,
|
|
.resolution_hz = 10 * 1000 * 1000,
|
|
.mem_block_symbols = 0,
|
|
.flags = {
|
|
.with_dma = false,
|
|
},
|
|
};
|
|
|
|
esp_err_t err = led_strip_new_rmt_device(&strip_config, &rmt_config, &s_strip);
|
|
if (err != ESP_OK) {
|
|
return err;
|
|
}
|
|
|
|
return status_led_set(STATUS_LED_IDLE);
|
|
}
|
|
|
|
esp_err_t status_led_set(status_led_state_t state)
|
|
{
|
|
uint8_t red = 0;
|
|
uint8_t green = 0;
|
|
uint8_t blue = 0;
|
|
|
|
if (s_strip == NULL) {
|
|
return ESP_ERR_INVALID_STATE;
|
|
}
|
|
|
|
switch (state) {
|
|
case STATUS_LED_IDLE:
|
|
blue = RGB_LED_BRIGHTNESS;
|
|
break;
|
|
case STATUS_LED_RUNNING:
|
|
red = RGB_LED_BRIGHTNESS;
|
|
green = RGB_LED_BRIGHTNESS / 2;
|
|
break;
|
|
case STATUS_LED_PASS:
|
|
green = RGB_LED_BRIGHTNESS;
|
|
break;
|
|
case STATUS_LED_FAIL:
|
|
red = RGB_LED_BRIGHTNESS;
|
|
break;
|
|
default:
|
|
return ESP_ERR_INVALID_ARG;
|
|
}
|
|
|
|
esp_err_t err = led_strip_set_pixel(s_strip, 0, red, green, blue);
|
|
if (err != ESP_OK) {
|
|
return err;
|
|
}
|
|
|
|
return led_strip_refresh(s_strip);
|
|
}
|