feat(dmx): implement DMX initialization and sending functionality

This commit is contained in:
RaffaelW 2026-03-15 19:51:59 +01:00
parent a2d51540b7
commit 5370e48d07
6 changed files with 91 additions and 2 deletions

View file

@ -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)

View file

@ -1,9 +1,15 @@
#pragma once #pragma once
#include "esp_dmx.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void init_dmx(dmx_port_t port, int pin_tx, int pin_rx);
void send_dmx(dmx_port_t port);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -0,0 +1,43 @@
#define LOG_TAG "DMX"
#include <stdint.h>
#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);
}

37
include/README Normal file
View file

@ -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

View file

@ -1,3 +1,3 @@
idf_component_register(SRCS "dmx-interface.c" idf_component_register(SRCS "dmx-interface.c"
INCLUDE_DIRS "." INCLUDE_DIRS "."
REQUIRES web_server) REQUIRES web_server dmx)

View file

@ -1,5 +1,6 @@
#include <stdio.h> #include <stdio.h>
#include "dmx.h"
#include "esp_err.h" #include "esp_err.h"
#include "esp_log.h" #include "esp_log.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
@ -28,6 +29,8 @@ void app_main(void) {
ESP_LOGI(TAG, "Web server started successfully"); ESP_LOGI(TAG, "Web server started successfully");
ESP_LOGI(TAG, "Open http://192.168.4.1 in your browser"); ESP_LOGI(TAG, "Open http://192.168.4.1 in your browser");
init_dmx(DMX_NUM_1, 21, 33);
// Keep the app running // Keep the app running
while (1) { while (1) {
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));