From 82f0b3f02b85f085825b6c34989f19c6f23766eb Mon Sep 17 00:00:00 2001 From: Peter Siegmund Date: Sat, 17 May 2025 22:05:39 +0200 Subject: [PATCH] starting with led configuration Signed-off-by: Peter Siegmund --- components/led_matrix/include/led_matrix.h | 4 +- components/led_matrix/led_matrix.c | 63 ++++++++++++++----- .../remote_control/include/remote_control.h | 4 +- components/remote_control/remote_control.c | 17 ++++- main/Kconfig.projbuild | 13 ++++ main/main.c | 7 ++- 6 files changed, 86 insertions(+), 22 deletions(-) create mode 100644 main/Kconfig.projbuild diff --git a/components/led_matrix/include/led_matrix.h b/components/led_matrix/include/led_matrix.h index abe0efc..a544425 100644 --- a/components/led_matrix/include/led_matrix.h +++ b/components/led_matrix/include/led_matrix.h @@ -1,3 +1,5 @@ #pragma once -void init_led(void); +#include + +void led_matrix_init(void *args); diff --git a/components/led_matrix/led_matrix.c b/components/led_matrix/led_matrix.c index 5a4d57c..8b99cd2 100644 --- a/components/led_matrix/led_matrix.c +++ b/components/led_matrix/led_matrix.c @@ -1,15 +1,34 @@ -#include #include "led_matrix.h" +#include "freertos/FreeRTOS.h" #include "led_strip.h" +#include "esp_log.h" +#include "sdkconfig.h" -#define LED_STRIP_RMT_RES_HZ (10 * 1000 * 1000) - -led_strip_handle_t led_strip_init(uint8_t gpio_pin, uint32_t width, uint32_t height) +typedef struct { + uint8_t red; + uint8_t green; + uint8_t blue; +} led_data_t; + +typedef struct +{ + led_strip_handle_t led_strip; + led_data_t *data; + uint32_t size; +} led_matrix_t; + +led_matrix_t led_matrix; + +static void led_strip_init(uint8_t gpio_pin, uint32_t size) +{ + led_matrix.size = size; + led_matrix.data = (led_data_t *)malloc(sizeof(led_data_t) * size); + led_strip_config_t strip_config = { .strip_gpio_num = gpio_pin, - .max_leds = width * height, + .max_leds = size, .led_model = LED_MODEL_WS2812, .color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_RGB, .flags = { @@ -18,22 +37,34 @@ led_strip_handle_t led_strip_init(uint8_t gpio_pin, uint32_t width, uint32_t hei led_strip_rmt_config_t rmt_config = { .clk_src = RMT_CLK_SRC_DEFAULT, - .resolution_hz = LED_STRIP_RMT_RES_HZ, - .mem_block_symbols = 64, + .resolution_hz = 0, + .mem_block_symbols = 0, .flags = { .with_dma = true, }}; - led_strip_handle_t led_strip; - ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip)); - return led_strip; + ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_matrix.led_strip)); } -void init_led(void) +void led_matrix_init(void *args) { - led_strip_handle_t led = led_strip_init(14, 8, 8); - // led_strip_set_pixel(led, 0, 255, 0, 0); - // led_strip_set_pixel(led, 1, 0, 255, 0); - // led_strip_set_pixel(led, 2, 0, 0, 255); - led_strip_refresh(led); + ESP_LOGI(pcTaskGetName(NULL), "Calling led_matrix_init()"); + + led_strip_init(CONFIG_WLED_DIN_PIN, CONFIG_WLED_LED_COUNT); + int value = 0; + for (int i = 0; i < led_matrix.size; i++) + { + led_strip_set_pixel(led_matrix.led_strip, i, value, 0, 0); + } + led_strip_refresh(led_matrix.led_strip); + + while (true) + { + vTaskDelay(pdMS_TO_TICKS(100)); + } + + free(led_matrix.data); + + ESP_LOGI(pcTaskGetName(NULL), "Exiting led_matrix_init()"); + vTaskDelete(NULL); } diff --git a/components/remote_control/include/remote_control.h b/components/remote_control/include/remote_control.h index f6f3a61..a6b5eb6 100644 --- a/components/remote_control/include/remote_control.h +++ b/components/remote_control/include/remote_control.h @@ -1 +1,3 @@ -void func(void); +#pragma once + +void ble_init(void *args); diff --git a/components/remote_control/remote_control.c b/components/remote_control/remote_control.c index 1e6d1b5..469b3bd 100644 --- a/components/remote_control/remote_control.c +++ b/components/remote_control/remote_control.c @@ -1,7 +1,18 @@ -#include #include "remote_control.h" -void func(void) -{ +#include "esp_log.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +void ble_init(void *args) +{ + ESP_LOGI(pcTaskGetName(NULL), "Calling ble_init()"); + + while (1) + { + vTaskDelay(pdMS_TO_TICKS(100)); + } + + ESP_LOGI(pcTaskGetName(NULL), "Exiting ble_init()"); + vTaskDelete(NULL); } diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild new file mode 100644 index 0000000..f004a7a --- /dev/null +++ b/main/Kconfig.projbuild @@ -0,0 +1,13 @@ +menu "Miniatur Town" + config WLED_DIN_PIN + int "WLED Data In Pin" + default 14 + help + The number of the WLED data in pin. + + config WLED_LED_COUNT + int "WLED LED counter" + default 64 + help + The number of the WLED LEDs. +endmenu diff --git a/main/main.c b/main/main.c index ca664b3..ba81b39 100644 --- a/main/main.c +++ b/main/main.c @@ -1,6 +1,11 @@ #include "led_matrix.h" +#include "remote_control.h" + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" void app_main(void) { - init_led(); + xTaskCreatePinnedToCore(led_matrix_init, "led_matrix", configMINIMAL_STACK_SIZE * 2, NULL, 5, NULL, 1); + xTaskCreatePinnedToCore(ble_init, "remote_control", configMINIMAL_STACK_SIZE * 2, NULL, 5, NULL, 1); }