mirror of
https://github.com/esphome/esphome.git
synced 2025-03-13 14:18:14 +00:00
[esp32_rmt] Set pull-up and open-drain modes based on pin schema (#8178)
Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
This commit is contained in:
parent
4eb551864d
commit
7e626b04f2
@ -2,6 +2,7 @@
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#ifdef USE_ESP32
|
||||
#include <driver/gpio.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace remote_receiver {
|
||||
@ -62,6 +63,11 @@ void RemoteReceiverComponent::setup() {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
if (this->pin_->get_flags() & gpio::FLAG_PULLUP) {
|
||||
gpio_pullup_en(gpio_num_t(this->pin_->get_pin()));
|
||||
} else {
|
||||
gpio_pullup_dis(gpio_num_t(this->pin_->get_pin()));
|
||||
}
|
||||
error = rmt_enable(this->channel_);
|
||||
if (error != ESP_OK) {
|
||||
this->error_code_ = error;
|
||||
|
@ -8,6 +8,8 @@ from esphome.const import (
|
||||
CONF_CLOCK_RESOLUTION,
|
||||
CONF_ID,
|
||||
CONF_INVERTED,
|
||||
CONF_MODE,
|
||||
CONF_OPEN_DRAIN,
|
||||
CONF_PIN,
|
||||
CONF_RMT_CHANNEL,
|
||||
CONF_RMT_SYMBOLS,
|
||||
@ -20,7 +22,6 @@ AUTO_LOAD = ["remote_base"]
|
||||
CONF_EOT_LEVEL = "eot_level"
|
||||
CONF_ON_TRANSMIT = "on_transmit"
|
||||
CONF_ON_COMPLETE = "on_complete"
|
||||
CONF_ONE_WIRE = "one_wire"
|
||||
|
||||
remote_transmitter_ns = cg.esphome_ns.namespace("remote_transmitter")
|
||||
RemoteTransmitterComponent = remote_transmitter_ns.class_(
|
||||
@ -44,7 +45,6 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
cv.only_on_esp32, cv.only_with_arduino, cv.int_range(min=1, max=255)
|
||||
),
|
||||
cv.Optional(CONF_EOT_LEVEL): cv.All(cv.only_with_esp_idf, cv.boolean),
|
||||
cv.Optional(CONF_ONE_WIRE): cv.All(cv.only_with_esp_idf, cv.boolean),
|
||||
cv.Optional(CONF_USE_DMA): cv.All(cv.only_with_esp_idf, cv.boolean),
|
||||
cv.SplitDefault(
|
||||
CONF_RMT_SYMBOLS,
|
||||
@ -74,14 +74,15 @@ async def to_code(config):
|
||||
cg.add(var.set_clock_resolution(config[CONF_CLOCK_RESOLUTION]))
|
||||
if CONF_USE_DMA in config:
|
||||
cg.add(var.set_with_dma(config[CONF_USE_DMA]))
|
||||
if CONF_ONE_WIRE in config:
|
||||
cg.add(var.set_one_wire(config[CONF_ONE_WIRE]))
|
||||
if CONF_EOT_LEVEL in config:
|
||||
cg.add(var.set_eot_level(config[CONF_EOT_LEVEL]))
|
||||
elif CONF_ONE_WIRE in config and config[CONF_ONE_WIRE]:
|
||||
cg.add(var.set_eot_level(True))
|
||||
elif CONF_INVERTED in config[CONF_PIN] and config[CONF_PIN][CONF_INVERTED]:
|
||||
cg.add(var.set_eot_level(True))
|
||||
else:
|
||||
cg.add(
|
||||
var.set_eot_level(
|
||||
config[CONF_PIN][CONF_MODE][CONF_OPEN_DRAIN]
|
||||
or config[CONF_PIN][CONF_INVERTED]
|
||||
)
|
||||
)
|
||||
else:
|
||||
if (rmt_channel := config.get(CONF_RMT_CHANNEL, None)) is not None:
|
||||
var = cg.new_Pvariable(config[CONF_ID], pin, rmt_channel)
|
||||
|
@ -40,7 +40,6 @@ class RemoteTransmitterComponent : public remote_base::RemoteTransmitterBase,
|
||||
|
||||
#if defined(USE_ESP32) && ESP_IDF_VERSION_MAJOR >= 5
|
||||
void set_with_dma(bool with_dma) { this->with_dma_ = with_dma; }
|
||||
void set_one_wire(bool one_wire) { this->one_wire_ = one_wire; }
|
||||
void set_eot_level(bool eot_level) { this->eot_level_ = eot_level; }
|
||||
void digital_write(bool value);
|
||||
#endif
|
||||
@ -69,7 +68,6 @@ class RemoteTransmitterComponent : public remote_base::RemoteTransmitterBase,
|
||||
#if ESP_IDF_VERSION_MAJOR >= 5
|
||||
std::vector<rmt_symbol_word_t> rmt_temp_;
|
||||
bool with_dma_{false};
|
||||
bool one_wire_{false};
|
||||
bool eot_level_{false};
|
||||
rmt_channel_handle_t channel_{NULL};
|
||||
rmt_encoder_handle_t encoder_{NULL};
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "esphome/core/application.h"
|
||||
|
||||
#ifdef USE_ESP32
|
||||
#include <driver/gpio.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace remote_transmitter {
|
||||
@ -18,7 +19,6 @@ void RemoteTransmitterComponent::setup() {
|
||||
void RemoteTransmitterComponent::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "Remote Transmitter:");
|
||||
#if ESP_IDF_VERSION_MAJOR >= 5
|
||||
ESP_LOGCONFIG(TAG, " One wire: %s", this->one_wire_ ? "true" : "false");
|
||||
ESP_LOGCONFIG(TAG, " Clock resolution: %" PRIu32 " hz", this->clock_resolution_);
|
||||
ESP_LOGCONFIG(TAG, " RMT symbols: %" PRIu32, this->rmt_symbols_);
|
||||
#else
|
||||
@ -68,6 +68,7 @@ void RemoteTransmitterComponent::configure_rmt_() {
|
||||
esp_err_t error;
|
||||
|
||||
if (!this->initialized_) {
|
||||
bool open_drain = (this->pin_->get_flags() & gpio::FLAG_OPEN_DRAIN) != 0;
|
||||
rmt_tx_channel_config_t channel;
|
||||
memset(&channel, 0, sizeof(channel));
|
||||
channel.clk_src = RMT_CLK_SRC_DEFAULT;
|
||||
@ -75,8 +76,8 @@ void RemoteTransmitterComponent::configure_rmt_() {
|
||||
channel.gpio_num = gpio_num_t(this->pin_->get_pin());
|
||||
channel.mem_block_symbols = this->rmt_symbols_;
|
||||
channel.trans_queue_depth = 1;
|
||||
channel.flags.io_loop_back = this->one_wire_;
|
||||
channel.flags.io_od_mode = this->one_wire_;
|
||||
channel.flags.io_loop_back = open_drain;
|
||||
channel.flags.io_od_mode = open_drain;
|
||||
channel.flags.invert_out = 0;
|
||||
channel.flags.with_dma = this->with_dma_;
|
||||
channel.intr_priority = 0;
|
||||
@ -91,6 +92,11 @@ void RemoteTransmitterComponent::configure_rmt_() {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
if (this->pin_->get_flags() & gpio::FLAG_PULLUP) {
|
||||
gpio_pullup_en(gpio_num_t(this->pin_->get_pin()));
|
||||
} else {
|
||||
gpio_pullup_dis(gpio_num_t(this->pin_->get_pin()));
|
||||
}
|
||||
|
||||
rmt_copy_encoder_config_t encoder;
|
||||
memset(&encoder, 0, sizeof(encoder));
|
||||
@ -109,7 +115,7 @@ void RemoteTransmitterComponent::configure_rmt_() {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
this->digital_write(this->one_wire_ || this->inverted_);
|
||||
this->digital_write(open_drain || this->inverted_);
|
||||
this->initialized_ = true;
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@ remote_transmitter:
|
||||
pin: ${pin}
|
||||
carrier_duty_percent: 50%
|
||||
clock_resolution: ${clock_resolution}
|
||||
one_wire: ${one_wire}
|
||||
rmt_symbols: ${rmt_symbols}
|
||||
use_dma: ${use_dma}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
substitutions:
|
||||
pin: GPIO2
|
||||
clock_resolution: "2000000"
|
||||
one_wire: "true"
|
||||
rmt_symbols: "64"
|
||||
use_dma: "true"
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
substitutions:
|
||||
pin: GPIO2
|
||||
clock_resolution: "2000000"
|
||||
one_wire: "true"
|
||||
rmt_symbols: "64"
|
||||
use_dma: "true"
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
substitutions:
|
||||
pin: GPIO38
|
||||
clock_resolution: "2000000"
|
||||
one_wire: "true"
|
||||
rmt_symbols: "64"
|
||||
use_dma: "true"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user