44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
// Project includes
|
|
#include "types.hpp"
|
|
|
|
// SDK Includes
|
|
#include "led_strip.h"
|
|
|
|
// Could be a config but its the GPIO on my ESP32-S3-ETH
|
|
#define LED_GPIO GPIO_NUM_21
|
|
|
|
enum class led_status : uint8 { Connecting, Ready, Failed };
|
|
|
|
internal led_strip_handle_t led_strip;
|
|
|
|
internal void setup_led(void) {
|
|
/* LED strip initialization with the GPIO and pixels number*/
|
|
led_strip_config_t strip_config = {};
|
|
strip_config.strip_gpio_num = LED_GPIO;
|
|
strip_config.max_leds = 1; // at least one LED on board
|
|
|
|
led_strip_rmt_config_t rmt_config = {};
|
|
rmt_config.resolution_hz = 10 * 1000 * 1000; // 10MHz
|
|
rmt_config.flags.with_dma = false;
|
|
ESP_ERROR_CHECK(
|
|
led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));
|
|
|
|
led_strip_clear(led_strip);
|
|
}
|
|
|
|
internal void destroy_led(void) { led_strip_clear(led_strip); }
|
|
|
|
internal void set_led_status(led_status status) {
|
|
switch (status) {
|
|
case led_status::Connecting:
|
|
led_strip_set_pixel(led_strip, 0, 255, 255, 0);
|
|
break;
|
|
case led_status::Ready:
|
|
led_strip_set_pixel(led_strip, 0, 0, 255, 0);
|
|
break;
|
|
case led_status::Failed:
|
|
led_strip_set_pixel(led_strip, 0, 255, 0, 0);
|
|
break;
|
|
}
|
|
led_strip_refresh(led_strip);
|
|
} |