This commit is contained in:
Andreas Böhler
2022-01-16 02:14:34 +01:00
parent 506e7526bc
commit 3b82f4d7cf
4 changed files with 98 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
#include "dmx512esp32.h"
#include "esphome/core/log.h"
namespace esphome {
namespace dmx512 {
static const char *TAG = "dmx512";
void DMX512ESP32::sendBreak() {
pinMatrixOutDetach(this->tx_pin_, false, false);
pinMode(this->tx_pin_, OUTPUT);
digitalWrite(this->tx_pin_, LOW);
delayMicroseconds(this->break_len_);
digitalWrite(this->tx_pin_, HIGH);
delayMicroseconds(this->mab_len_);
pinMatrixOutAttach(this->tx_pin_, this->uart_idx_, false, false);
}
} // namespace dmx512
} // namespace esphome
#endif // USE_ESP32_FRAMEWORK_ARDUINO

View File

@@ -0,0 +1,31 @@
#pragma once
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
#include "dmx512.h"
#include "esp32-hal-matrix.h"
namespace esphome {
namespace dmx512 {
class DMX512ESP32 : public DMX512 {
public:
DMX512ESP32() = default;
void sendBreak() override;
void set_uart_num(int num) override {
if(num == 0) {
this->uart_idx_ = U0TXD_OUT_IDX;
} else if(num == 1) {
this->uart_idx_ = U1TXD_OUT_IDX;
} else if(num == 2) {
this->uart_idx_ = U2TXD_OUT_IDX;
}
}
};
} // namespace dmx512
} // namespace esphome
#endif // USE_ESP32_FRAMEWORK_ARDUINO

View File

@@ -0,0 +1,21 @@
#ifdef USE_ESP8266
#include "dmx512esp8266.h"
#include "esphome/core/log.h"
#include "uart_register.h"
namespace esphome {
namespace dmx512 {
static const char *TAG = "dmx512";
void DMX512ESP8266::sendBreak() {
SET_PERI_REG_MASK(UART_CONF0(this->uart_idx_), UART_TXD_BRK);
delayMicroseconds(this->break_len_);
CLEAR_PERI_REG_MASK(UART_CONF0(this->uart_idx_), UART_TXD_BRK);
delayMicroseconds(this->mab_len_);
}
} // namespace dmx512
} // namespace esphome
#endif // USE_ESP8266

View File

@@ -0,0 +1,23 @@
#pragma once
#ifdef USE_ESP8266
#include "dmx512.h"
namespace esphome {
namespace dmx512 {
class DMX512ESP8266 : public DMX512 {
public:
DMX512ESP8266() = default;
void sendBreak() override;
void set_uart_num(int num) override {
this->uart_idx_ = num;
}
};
} // namespace dmx512
} // namespace esphome
#endif // USE_ESP8266