From 5370e48d07a80c858dfb7341df91a05f85707b2e Mon Sep 17 00:00:00 2001 From: RaffaelW <146560011+RaffaelW@users.noreply.github.com> Date: Sun, 15 Mar 2026 19:51:59 +0100 Subject: [PATCH 1/3] feat(dmx): implement DMX initialization and sending functionality --- components/dmx/CMakeLists.txt | 2 +- components/dmx/include/dmx.h | 6 +++++ components/dmx/src/dmx.c | 43 +++++++++++++++++++++++++++++++++++ include/README | 37 ++++++++++++++++++++++++++++++ main/CMakeLists.txt | 2 +- main/dmx-interface.c | 3 +++ 6 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 include/README diff --git a/components/dmx/CMakeLists.txt b/components/dmx/CMakeLists.txt index 7b3abdc..a483df2 100644 --- a/components/dmx/CMakeLists.txt +++ b/components/dmx/CMakeLists.txt @@ -1 +1 @@ -idf_component_register(SRCS "src/dmx.c" INCLUDE_DIRS "include") +idf_component_register(SRCS "src/dmx.c" INCLUDE_DIRS "include" REQUIRES logger esp_dmx) diff --git a/components/dmx/include/dmx.h b/components/dmx/include/dmx.h index cd74574..5e8c371 100644 --- a/components/dmx/include/dmx.h +++ b/components/dmx/include/dmx.h @@ -1,9 +1,15 @@ #pragma once +#include "esp_dmx.h" + #ifdef __cplusplus extern "C" { #endif +void init_dmx(dmx_port_t port, int pin_tx, int pin_rx); + +void send_dmx(dmx_port_t port); + #ifdef __cplusplus } #endif diff --git a/components/dmx/src/dmx.c b/components/dmx/src/dmx.c index e69de29..ad39152 100644 --- a/components/dmx/src/dmx.c +++ b/components/dmx/src/dmx.c @@ -0,0 +1,43 @@ +#define LOG_TAG "DMX" + +#include + +#include "dmx.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "logger.h" + +static void dmx_sender_task(void *pv_parameters) { + dmx_port_t port = (dmx_port_t)(intptr_t)pv_parameters; + TickType_t last_wake_time = xTaskGetTickCount(); + + while (1) { + send_dmx(port); + vTaskDelayUntil(&last_wake_time, pdMS_TO_TICKS(1000)); + } +} + +void init_dmx(dmx_port_t port, int pin_tx, int pin_rx) { + LOGI("Initializing DMX port %d on pin %d (TX) and %d (RX)", port, pin_tx, + pin_rx); + + dmx_config_t config = DMX_CONFIG_DEFAULT; + dmx_personality_t personalities[] = {}; + dmx_driver_install(port, &config, personalities, 0); + + dmx_set_pin(port, pin_tx, pin_rx, DMX_PIN_NO_CHANGE); // RTS pin is not used + + BaseType_t task_created = xTaskCreate(dmx_sender_task, "dmx_sender", 2048, + (void *)(intptr_t)port, 5, NULL); + if (task_created != pdPASS) { + LOGE("Failed to create DMX sender task for port %d", port); + } +} + +void send_dmx(dmx_port_t port) { + LOGD("Sending DMX data on port %d", port); + + uint8_t dmx_data[DMX_PACKET_SIZE] = {DMX_SC, 0, 0, 0, 255, 100, 0, 100, 0}; + dmx_write(port, dmx_data, DMX_PACKET_SIZE); + dmx_send(port); +} \ No newline at end of file diff --git a/include/README b/include/README new file mode 100644 index 0000000..49819c0 --- /dev/null +++ b/include/README @@ -0,0 +1,37 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the convention is to give header files names that end with `.h'. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 836026c..1a454b6 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,3 +1,3 @@ idf_component_register(SRCS "dmx-interface.c" INCLUDE_DIRS "." - REQUIRES web_server) + REQUIRES web_server dmx) diff --git a/main/dmx-interface.c b/main/dmx-interface.c index 4ed7ccd..ac0ec96 100644 --- a/main/dmx-interface.c +++ b/main/dmx-interface.c @@ -1,5 +1,6 @@ #include +#include "dmx.h" #include "esp_err.h" #include "esp_log.h" #include "freertos/FreeRTOS.h" @@ -28,6 +29,8 @@ void app_main(void) { ESP_LOGI(TAG, "Web server started successfully"); ESP_LOGI(TAG, "Open http://192.168.4.1 in your browser"); + init_dmx(DMX_NUM_1, 21, 33); + // Keep the app running while (1) { vTaskDelay(pdMS_TO_TICKS(1000)); From c669e28cdf532d7b6275d27c791da8a713d1b66e Mon Sep 17 00:00:00 2001 From: RaffaelW <146560011+RaffaelW@users.noreply.github.com> Date: Sun, 15 Mar 2026 20:40:46 +0100 Subject: [PATCH 2/3] fix(dmx): add newline at end of dmx.c --- components/dmx/src/dmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/dmx/src/dmx.c b/components/dmx/src/dmx.c index ad39152..7e4096d 100644 --- a/components/dmx/src/dmx.c +++ b/components/dmx/src/dmx.c @@ -40,4 +40,4 @@ void send_dmx(dmx_port_t port) { uint8_t dmx_data[DMX_PACKET_SIZE] = {DMX_SC, 0, 0, 0, 255, 100, 0, 100, 0}; dmx_write(port, dmx_data, DMX_PACKET_SIZE); dmx_send(port); -} \ No newline at end of file +} From 226370a077f62efe5316be4b3b2cb756feecf504 Mon Sep 17 00:00:00 2001 From: HendrikRauh <114620133+HendrikRauh@users.noreply.github.com> Date: Fri, 20 Mar 2026 22:55:55 +0100 Subject: [PATCH 3/3] refactor: format CMakeLists.txt for better readability and add documentation comments in dmx.h --- components/dmx/CMakeLists.txt | 9 ++++++++- components/dmx/include/dmx.h | 10 ++++++++++ components/dmx/src/dmx.c | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/components/dmx/CMakeLists.txt b/components/dmx/CMakeLists.txt index a483df2..18becaa 100644 --- a/components/dmx/CMakeLists.txt +++ b/components/dmx/CMakeLists.txt @@ -1 +1,8 @@ -idf_component_register(SRCS "src/dmx.c" INCLUDE_DIRS "include" REQUIRES logger esp_dmx) +idf_component_register( + SRCS + "src/dmx.c" + INCLUDE_DIRS + "include" + REQUIRES + logger + esp_dmx) diff --git a/components/dmx/include/dmx.h b/components/dmx/include/dmx.h index 5e8c371..dac038d 100644 --- a/components/dmx/include/dmx.h +++ b/components/dmx/include/dmx.h @@ -6,8 +6,18 @@ extern "C" { #endif +/** + * @brief Initialize the DMX interface. + * @param port The DMX port to initialize. + * @param pin_tx The pin for TX of the RS485. + * @param pin_rx The pin for RX of the RS485. + */ void init_dmx(dmx_port_t port, int pin_tx, int pin_rx); +/** + * @brief Send some test DMX data on the specified port. + * @param port The DMX port to send data on. + */ void send_dmx(dmx_port_t port); #ifdef __cplusplus diff --git a/components/dmx/src/dmx.c b/components/dmx/src/dmx.c index 7e4096d..3dd1c12 100644 --- a/components/dmx/src/dmx.c +++ b/components/dmx/src/dmx.c @@ -1,4 +1,4 @@ -#define LOG_TAG "DMX" +#define LOG_TAG "DMX" ///< "DMX" log tag for this file #include