blk_box_tc/main/drivers/leds.cpp

46 lines
1.0 KiB
C++

#include "leds.h"
#include "led_strip.h"
#include <esp_log.h>
static const char* TAG = "leds";
static led_strip_handle_t leds;
void init_leds() {
ESP_LOGI(TAG, "Initializing LEDs...");
led_strip_config_t strip_config = {
.strip_gpio_num = NEOPIXEL_PIN,
.max_leds = LED_COUNT,
.led_pixel_format = LED_PIXEL_FORMAT_GRB,
.led_model = LED_MODEL_WS2812
};
led_strip_rmt_config_t rmt_config = {
.clk_src = RMT_CLK_SRC_DEFAULT,
.resolution_hz = LED_STRIP_RMT_RES_HZ,
};
rmt_config.flags.with_dma = false;
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &leds));
ESP_LOGI(TAG, "LEDs initialized!");
}
void led_set(uint32_t led, uint8_t r, uint8_t g, uint8_t b) {
led_strip_set_pixel(leds, led, r, g, b);
}
void led_set(uint32_t led, uint32_t color) {
led_set(led, (color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF);
}
void leds_flush() {
led_strip_refresh(leds);
}
void leds_clear()
{
led_strip_clear(leds);
}