add addressable led on led API including green/red + make rmt properly shared accross services

This commit is contained in:
philippe44
2023-09-01 21:22:42 -07:00
parent e09837158c
commit c7e4d9711c
7 changed files with 197 additions and 113 deletions

View File

@@ -21,6 +21,7 @@
#include <math.h>
#include "esp_log.h"
#include "globdefs.h"
#include "led_strip.h"
#include "platform_config.h"
#include "led_vu.h"
@@ -28,7 +29,6 @@
static const char *TAG = "led_vu";
#define LED_VU_STACK_SIZE (3*1024)
#define LED_VU_RMT_INTR_NUM 20U
#define LED_VU_PEAK_HOLD 6U
@@ -39,12 +39,6 @@ static const char *TAG = "led_vu";
#define max(a,b) (((a) > (b)) ? (a) : (b))
struct led_strip_t* led_display = NULL;
static EXT_RAM_ATTR struct led_strip_t led_strip_config = {
.rgb_led_type = RGB_LED_TYPE_WS2812,
.rmt_channel = RMT_CHANNEL_1,
.rmt_interrupt_num = LED_VU_RMT_INTR_NUM,
.gpio = -1,
};
static EXT_RAM_ATTR struct {
int gpio;
@@ -96,24 +90,26 @@ void led_vu_init()
strip.vu_odd = strip.length - 1;
// create driver configuration
struct led_strip_t led_strip_config = { .rgb_led_type = RGB_LED_TYPE_WS2812 };
led_strip_config.access_semaphore = xSemaphoreCreateBinary();
led_strip_config.led_strip_length = strip.length;
led_strip_config.led_strip_working = heap_caps_malloc(strip.length * sizeof(struct led_color_t), MALLOC_CAP_8BIT);
led_strip_config.led_strip_showing = heap_caps_malloc(strip.length * sizeof(struct led_color_t), MALLOC_CAP_8BIT);
led_strip_config.gpio = strip.gpio;
led_strip_config.rmt_channel = rmt_system_base_channel++;
// initialize driver
bool led_init_ok = led_strip_init(&led_strip_config);
if (led_init_ok) {
led_display = &led_strip_config;
ESP_LOGI(TAG, "led_vu using gpio:%d length:%d", strip.gpio, strip.length);
ESP_LOGI(TAG, "led_vu using gpio:%d length:%d on channek:%d", strip.gpio, strip.length, led_strip_config.rmt_channel);
} else {
ESP_LOGE(TAG, "led_vu init failed");
goto done;
}
// reserver max memory for remote management systems
rmt_set_mem_block_num(RMT_CHANNEL_1, 7);
rmt_set_mem_block_num(led_strip_config.rmt_channel, 7);
led_vu_clear(led_display);