From 455a92ab4de709f59292079c3283c36e01e02742 Mon Sep 17 00:00:00 2001 From: TheJoKlLa Date: Mon, 17 Jul 2023 01:05:41 +0200 Subject: [PATCH] Added: LED Timing Test --- firmware/.vscode/c_cpp_properties.json | 2 +- firmware/.vscode/settings.json | 8 ++- firmware/dependencies.lock | 4 +- firmware/main/Kconfig.projbuild | 2 +- firmware/main/LED_Segments.h | 2 +- firmware/main/main.c | 90 ++++++++++++++++++++++---- 6 files changed, 91 insertions(+), 17 deletions(-) diff --git a/firmware/.vscode/c_cpp_properties.json b/firmware/.vscode/c_cpp_properties.json index 3713a36..95acf9a 100644 --- a/firmware/.vscode/c_cpp_properties.json +++ b/firmware/.vscode/c_cpp_properties.json @@ -2,7 +2,7 @@ "configurations": [ { "name": "ESP-IDF", - "compilerPath": "", + "compilerPath": "c:\\Users\\thejo\\Espressif\\tools\\tools\\xtensa-esp32s2-elf\\esp-12.2.0_20230208\\xtensa-esp32s2-elf\\bin\\xtensa-esp32s2-elf-gcc.exe", "includePath": [ "${config:idf.espIdfPath}/components/**", "${config:idf.espIdfPathWin}/components/**", diff --git a/firmware/.vscode/settings.json b/firmware/.vscode/settings.json index 0bb915a..8679820 100644 --- a/firmware/.vscode/settings.json +++ b/firmware/.vscode/settings.json @@ -1,3 +1,9 @@ { - "C_Cpp.intelliSenseEngine": "default" + "C_Cpp.intelliSenseEngine": "default", + "idf.adapterTargetName": "esp32s2", + "idf.openOcdConfigs": [ + "board/esp32s2-bridge.cfg" + ], + "idf.portWin": "COM1", + "idf.flashType": "DFU" } diff --git a/firmware/dependencies.lock b/firmware/dependencies.lock index cf56dfe..d392d7f 100644 --- a/firmware/dependencies.lock +++ b/firmware/dependencies.lock @@ -9,7 +9,7 @@ dependencies: component_hash: null source: type: idf - version: 5.0.1 + version: 5.1.0 manifest_hash: 866a017870fcec1240064adf450d5b56fe14dc761ed21f016308418230712755 -target: esp32 +target: esp32s2 version: 1.0.0 diff --git a/firmware/main/Kconfig.projbuild b/firmware/main/Kconfig.projbuild index 334708e..4284909 100644 --- a/firmware/main/Kconfig.projbuild +++ b/firmware/main/Kconfig.projbuild @@ -104,7 +104,7 @@ menu "FabLight Configuration" config LED_LIMIT int "Brightness limt" - default 0xAA + default 170 #0xAA help Brightness limit to prevent overheating of enclosure diff --git a/firmware/main/LED_Segments.h b/firmware/main/LED_Segments.h index 2b0d11d..fa42d32 100644 --- a/firmware/main/LED_Segments.h +++ b/firmware/main/LED_Segments.h @@ -19,7 +19,7 @@ typedef struct LED_Segments uint8_t segment_id; uint8_t color; enum LED_Effect effect; -} LED_Segment; +} LED_Segments; #endif \ No newline at end of file diff --git a/firmware/main/main.c b/firmware/main/main.c index 772023f..c2d414e 100644 --- a/firmware/main/main.c +++ b/firmware/main/main.c @@ -23,22 +23,90 @@ LED_Segments segments[CONFIG_LED_SEGMENT_COUNT]; esp_mqtt_client_handle_t mqtt_client; led_strip_handle_t led_internal; -led_strip_handle_t led_segments; +led_strip_handle_t led_segments[6]; -// LED Task -void vTaskLED( void * pvParameters ) +led_strip_config_t segments_led_configs[6]; +led_strip_rmt_config_t rmt_config; + +void init_led_strip() { - for( ;; ) - { - // Task code goes here. - } + led_strip_config_t strip_config = + { + .strip_gpio_num = 0, + .max_leds = CONFIG_LED_SEGMENT_COUNT * CONFIG_LED_SEGMENT_SIZE, + .led_pixel_format = LED_PIXEL_FORMAT_GRB, + .led_model = LED_MODEL_WS2812, + .flags.invert_out = false, + }; + + strip_config.strip_gpio_num = CONFIG_PIN_SEGMENT_DATA_0; + segments_led_configs[0] = strip_config; + + strip_config.strip_gpio_num = CONFIG_PIN_SEGMENT_DATA_1; + segments_led_configs[1] = strip_config; + + strip_config.strip_gpio_num = CONFIG_PIN_SEGMENT_DATA_2; + segments_led_configs[2] = strip_config; + + strip_config.strip_gpio_num = CONFIG_PIN_SEGMENT_DATA_3; + segments_led_configs[3] = strip_config; + + strip_config.strip_gpio_num = CONFIG_PIN_SEGMENT_DATA_4; + segments_led_configs[4] = strip_config; + + strip_config.strip_gpio_num = CONFIG_PIN_SEGMENT_DATA_5; + segments_led_configs[5] = strip_config; + + led_strip_rmt_config_t rmt = + { + .clk_src = RMT_CLK_SRC_DEFAULT, + .resolution_hz = LED_STRIP_RMT_RES_HZ, + .flags.with_dma = true, + }; + rmt_config = rmt; + + + strip_config.strip_gpio_num = CONFIG_PIN_INTERNAL_LED; + led_strip_new_rmt_device(&strip_config, &rmt_config, &led_internal); } -void app_main(void) +// LED Task +void vTaskLEDUpdate( void * pvParameters ) { - TaskHandle_t xHandle_LED = NULL; - xTaskCreate( vTaskLED, "LED", 200, NULL, tskIDLE_PRIORITY, &xHandle_LED ); + while(1) + { + ESP_ERROR_CHECK(led_strip_new_rmt_device(&segments_led_configs[0], &rmt_config, &led_segments[0])); + ESP_ERROR_CHECK(led_strip_new_rmt_device(&segments_led_configs[1], &rmt_config, &led_segments[1])); + ESP_ERROR_CHECK(led_strip_new_rmt_device(&segments_led_configs[2], &rmt_config, &led_segments[2])); - + ESP_ERROR_CHECK(led_strip_set_pixel(led_segments[0], 0 , 0xFF, 0xFF, 0xFF)); + ESP_ERROR_CHECK(led_strip_set_pixel(led_segments[1], 0 , 0xFF, 0xFF, 0xFF)); + ESP_ERROR_CHECK(led_strip_set_pixel(led_segments[2], 0 , 0xFF, 0xFF, 0xFF)); + ESP_ERROR_CHECK(led_strip_del(led_segments[0])); + ESP_ERROR_CHECK(led_strip_del(led_segments[1])); + ESP_ERROR_CHECK(led_strip_del(led_segments[2])); + + ESP_ERROR_CHECK(led_strip_new_rmt_device(&segments_led_configs[3], &rmt_config, &led_segments[3])); + ESP_ERROR_CHECK(led_strip_new_rmt_device(&segments_led_configs[4], &rmt_config, &led_segments[4])); + ESP_ERROR_CHECK(led_strip_new_rmt_device(&segments_led_configs[5], &rmt_config, &led_segments[5])); + + ESP_ERROR_CHECK(led_strip_set_pixel(led_segments[3], 0 , 0xFF, 0xFF, 0xFF)); + ESP_ERROR_CHECK(led_strip_set_pixel(led_segments[4], 0 , 0xFF, 0xFF, 0xFF)); + ESP_ERROR_CHECK(led_strip_set_pixel(led_segments[5], 0 , 0xFF, 0xFF, 0xFF)); + + ESP_ERROR_CHECK(led_strip_del(led_segments[3])); + ESP_ERROR_CHECK(led_strip_del(led_segments[4])); + ESP_ERROR_CHECK(led_strip_del(led_segments[5])); + + vTaskDelay(pdMS_TO_TICKS(100)); + } +} + +void app_main(void) +{ + init_led_strip(); + + TaskHandle_t xHandle_LEDUpdate = NULL; + xTaskCreate( vTaskLEDUpdate, "LED", 200, NULL, tskIDLE_PRIORITY, &xHandle_LEDUpdate ); } \ No newline at end of file