Add compile-tested support for ESP32-IDF, some fixes from code review,
update README
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# esphome-dmx512
|
||||
|
||||
This is a DMX512 custom component for ESPHome that allows Arduino-based devices to control DMX devices via UART (this requires an RS485 module, see below). ESP32 with the IDF-framework is currently not supported.
|
||||
This is a DMX512 custom component for ESPHome that allows Arduino-based devices to control DMX devices via UART (this requires an RS485 module, see below).
|
||||
|
||||
## Implementation
|
||||
|
||||
@@ -65,11 +65,9 @@ _Tip:_ Usage of `gamma_correct: 0` in the lights configuration is likely require
|
||||
|
||||
## Wiring
|
||||
|
||||
You can use an RS485-TTL adapter module to connect your ESP device with the DMX bus. Attention: The below module is actually a 5V module, but it seems to work fine even if powered from 3.3V. However, there is no guarantee the MAX485 works at 3.3V. To be on the safe side, Use the MAX3485 instead (which is the equivalent for 3.3V). NEVER power the module by 5V, the ESP is not designed for 5V logic!
|
||||
You can use an RS485-TTL adapter module to connect your ESP device with the DMX bus. Attention: Some modules are actually 5V modules, but seem to work fine even if powered from 3.3V. However, there is no guarantee the MAX485 works at 3.3V. To be on the safe side, Use the MAX3485 instead (which is the equivalent for 3.3V). NEVER power the module by 5V, the ESP is not designed for 5V logic!
|
||||
|
||||

|
||||
|
||||
For this adapter, use the wiring below:
|
||||
For [this adapter](https://community.home-assistant.io/t/modbus-with-max-485-ttl-to-rs-485-converter-module/176540), use the wiring below:
|
||||
|
||||
```
|
||||
MAX485-M VCC -> ESP +3.3V
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome import pins, automation
|
||||
from esphome import pins
|
||||
from esphome.components import uart
|
||||
from esphome.const import CONF_ID, CONF_TX_PIN
|
||||
from esphome.core import CORE, coroutine
|
||||
from esphome.const import CONF_ID, CONF_TX_PIN, CONF_ENABLE_PIN, CONF_UPDATE_INTERVAL
|
||||
from esphome.core import CORE
|
||||
|
||||
DEPENDENCIES = ['uart']
|
||||
MULTI_CONF = True
|
||||
@@ -11,15 +11,14 @@ MULTI_CONF = True
|
||||
dmx512_ns = cg.esphome_ns.namespace('dmx512')
|
||||
DMX512ESP32 = dmx512_ns.class_('DMX512ESP32', cg.Component)
|
||||
DMX512ESP8266 = dmx512_ns.class_('DMX512ESP8266', cg.Component)
|
||||
DMX512ESP32IDF = dmx512_ns.class_('DMX512ESP32IDF', cg.Component)
|
||||
|
||||
CONF_DMX512_ID = 'dmx512_id'
|
||||
CONF_ENABLE_PIN = 'enable_pin'
|
||||
CONF_UART_NUM = 'uart_num'
|
||||
CONF_PERIODIC_UPDATE = 'periodic_update'
|
||||
CONF_FORCE_FULL_FRAMES = 'force_full_frames'
|
||||
CONF_CUSTOM_BREAK_LEN = 'custom_break_len'
|
||||
CONF_CUSTOM_MAB_LEN = 'custom_mab_len'
|
||||
CONF_UPDATE_INTERVAL = 'update_interval'
|
||||
|
||||
UART_MAX = 2
|
||||
|
||||
@@ -32,6 +31,8 @@ def _declare_type(value):
|
||||
if CORE.is_esp32:
|
||||
if CORE.using_arduino:
|
||||
return cv.declare_id(DMX512ESP32)(value)
|
||||
elif CORE.using_esp_idf:
|
||||
return cv.declare_id(DMX512ESP32IDF)(value)
|
||||
elif CORE.is_esp8266:
|
||||
return cv.declare_id(DMX512ESP8266)(value)
|
||||
raise NotImplementedError
|
||||
@@ -43,7 +44,7 @@ CONFIG_SCHEMA = cv.Schema({
|
||||
cv.Optional(CONF_UART_NUM, default=1): cv.int_range(min=0, max=UART_MAX),
|
||||
cv.Optional(CONF_PERIODIC_UPDATE, default=True): cv.boolean,
|
||||
cv.Optional(CONF_FORCE_FULL_FRAMES, default=False): cv.boolean,
|
||||
cv.Optional(CONF_CUSTOM_MAB_LEN, default=12): cv.int_range(min=12,max=1000),
|
||||
cv.Optional(CONF_CUSTOM_MAB_LEN, default=12): cv.int_range(min=12, max=1000),
|
||||
cv.Optional(CONF_CUSTOM_BREAK_LEN, default=92): cv.int_range(min=92, max=1000),
|
||||
cv.Optional(CONF_UPDATE_INTERVAL, default=500): cv.int_range(),
|
||||
}).extend(cv.COMPONENT_SCHEMA).extend(uart.UART_DEVICE_SCHEMA)
|
||||
|
||||
21
components/dmx512/dmx512esp32idf.cpp
Normal file
21
components/dmx512/dmx512esp32idf.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifdef USE_ESP_IDF
|
||||
|
||||
#include "dmx512esp32idf.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include <driver/uart.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace dmx512 {
|
||||
|
||||
static const char *TAG = "dmx512";
|
||||
|
||||
void DMX512ESP32IDF::sendBreak() {
|
||||
uart_set_line_inverse(this->uart_idx_, UART_SIGNAL_TXD_INV);
|
||||
delayMicroseconds(this->break_len_);
|
||||
uart_set_line_inverse(this->uart_idx_, UART_SIGNAL_INV_DISABLE);
|
||||
delayMicroseconds(this->mab_len_);
|
||||
}
|
||||
|
||||
} // namespace dmx512
|
||||
} // namespace esphome
|
||||
#endif // USE_ESP_IDF
|
||||
24
components/dmx512/dmx512esp32idf.h
Normal file
24
components/dmx512/dmx512esp32idf.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef USE_ESP_IDF
|
||||
|
||||
#include "dmx512.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace dmx512 {
|
||||
|
||||
class DMX512ESP32IDF : public DMX512 {
|
||||
public:
|
||||
DMX512ESP32IDF() = default;
|
||||
|
||||
void sendBreak() override;
|
||||
|
||||
void set_uart_num(int num) override {
|
||||
this->uart_idx_ = num;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dmx512
|
||||
} // namespace esphome
|
||||
|
||||
#endif // USE_ESP_IDF
|
||||
@@ -22,6 +22,8 @@ def _declare_type(value):
|
||||
if CORE.is_esp32:
|
||||
if CORE.using_arduino:
|
||||
return cv.use_id(dmx512.DMX512ESP32)(value)
|
||||
elif CORE.using_esp_idf:
|
||||
return cv.use_id(dmx512.DMX512ESP32IDF)(value)
|
||||
elif CORE.is_esp8266:
|
||||
return cv.use_id(dmx512.DMX512ESP8266)(value)
|
||||
raise NotImplementedError
|
||||
|
||||
Reference in New Issue
Block a user