Add compile-tested support for ESP32-IDF, some fixes from code review,

update README
This commit is contained in:
Andreas Böhler
2022-02-22 19:13:07 +01:00
parent ad4504dc68
commit ed1eb69094
5 changed files with 58 additions and 12 deletions

View File

@@ -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)
@@ -53,7 +54,7 @@ async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await uart.register_uart_device(var, config)
if CONF_ENABLE_PIN in config:
enable = await cg.gpio_pin_expression(config[CONF_ENABLE_PIN])
cg.add(var.set_enable_pin(enable))

View 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

View 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

View File

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