Add a way to enable dma support

This commit is contained in:
Jonathan Swoboda 2024-11-23 21:43:18 -05:00
parent 43a6a5a850
commit 712b2ad21f
6 changed files with 18 additions and 2 deletions

View File

@ -18,6 +18,7 @@ from esphome.const import (
from esphome.core import CORE, TimePeriod
CONF_CLOCK_DIVIDER = "clock_divider"
CONF_WITH_DMA = "with_dma"
AUTO_LOAD = ["remote_base"]
remote_receiver_ns = cg.esphome_ns.namespace("remote_receiver")
@ -105,6 +106,7 @@ CONFIG_SCHEMA = remote_base.validate_triggers(
cv.positive_time_period_microseconds,
cv.Range(max=TimePeriod(microseconds=4294967295)),
),
cv.Optional(CONF_WITH_DMA, default=False): cv.boolean,
cv.Optional(CONF_MEMORY_BLOCKS, default=3): cv.Range(min=1, max=8),
cv.Optional(CONF_RMT_CHANNEL): esp32_rmt.validate_rmt_channel(tx=False),
}
@ -116,6 +118,7 @@ async def to_code(config):
pin = await cg.gpio_pin_expression(config[CONF_PIN])
if CORE.is_esp32:
var = cg.new_Pvariable(config[CONF_ID], pin, config[CONF_MEMORY_BLOCKS])
cg.add(var.set_with_dma(config[CONF_WITH_DMA]))
cg.add(var.set_clock_divider(config[CONF_CLOCK_DIVIDER]))
else:
var = cg.new_Pvariable(config[CONF_ID], pin)

View File

@ -63,6 +63,9 @@ class RemoteReceiverComponent : public remote_base::RemoteReceiverBase,
void loop() override;
float get_setup_priority() const override { return setup_priority::DATA; }
#ifdef USE_ESP32
void set_with_dma(bool with_dma) { this->with_dma_ = with_dma; }
#endif
void set_buffer_size(uint32_t buffer_size) { this->buffer_size_ = buffer_size; }
void set_filter_us(uint32_t filter_us) { this->filter_us_ = filter_us; }
void set_idle_us(uint32_t idle_us) { this->idle_us_ = idle_us; }
@ -73,6 +76,7 @@ class RemoteReceiverComponent : public remote_base::RemoteReceiverBase,
rmt_channel_handle_t channel_{NULL};
esp_err_t error_code_{ESP_OK};
std::string error_string_{""};
bool with_dma_{false};
#endif
RemoteReceiverComponentStore store_;

View File

@ -39,7 +39,7 @@ void RemoteReceiverComponent::setup() {
channel.gpio_num = gpio_num_t(this->pin_->get_pin());
channel.intr_priority = 0;
channel.flags.invert_in = 0;
channel.flags.with_dma = 0;
channel.flags.with_dma = this->with_dma_;
channel.flags.io_loop_back = 0;
esp_err_t error = rmt_new_rx_channel(&channel, &this->channel_);
if (error != ESP_OK) {

View File

@ -3,11 +3,13 @@ import esphome.codegen as cg
from esphome.components import esp32_rmt, remote_base
import esphome.config_validation as cv
from esphome.const import CONF_CARRIER_DUTY_PERCENT, CONF_ID, CONF_PIN, CONF_RMT_CHANNEL
from esphome.core import CORE
AUTO_LOAD = ["remote_base"]
CONF_ON_TRANSMIT = "on_transmit"
CONF_ON_COMPLETE = "on_complete"
CONF_WITH_DMA = "with_dma"
CONF_ONE_WIRE = "one_wire"
remote_transmitter_ns = cg.esphome_ns.namespace("remote_transmitter")
@ -24,6 +26,7 @@ CONFIG_SCHEMA = cv.Schema(
cv.percentage_int, cv.Range(min=1, max=100)
),
cv.Optional(CONF_ONE_WIRE): cv.boolean,
cv.Optional(CONF_WITH_DMA, default=False): cv.boolean,
cv.Optional(CONF_RMT_CHANNEL): esp32_rmt.validate_rmt_channel(tx=True),
cv.Optional(CONF_ON_TRANSMIT): automation.validate_automation(single=True),
cv.Optional(CONF_ON_COMPLETE): automation.validate_automation(single=True),
@ -36,6 +39,8 @@ async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID], pin)
await cg.register_component(var, config)
if CORE.is_esp32:
cg.add(var.set_with_dma(config[CONF_WITH_DMA]))
cg.add(var.set_carrier_duty_percent(config[CONF_CARRIER_DUTY_PERCENT]))
if one_wire_config := config.get(CONF_ONE_WIRE):

View File

@ -34,7 +34,10 @@ class RemoteTransmitterComponent : public remote_base::RemoteTransmitterBase,
void set_carrier_duty_percent(uint8_t carrier_duty_percent) { this->carrier_duty_percent_ = carrier_duty_percent; }
#ifdef USE_ESP32
void set_with_dma(bool with_dma) { this->with_dma_ = with_dma; }
void set_one_wire(bool one_wire) { this->one_wire_ = one_wire; }
#endif
Trigger<> *get_transmit_trigger() const { return this->transmit_trigger_; };
Trigger<> *get_complete_trigger() const { return this->complete_trigger_; };
@ -64,6 +67,7 @@ class RemoteTransmitterComponent : public remote_base::RemoteTransmitterBase,
esp_err_t error_code_{ESP_OK};
std::string error_string_{""};
bool inverted_{false};
bool with_dma_{false};
#endif
uint8_t carrier_duty_percent_;

View File

@ -47,7 +47,7 @@ void RemoteTransmitterComponent::configure_rmt_() {
channel.flags.io_od_mode = 0;
}
channel.flags.invert_out = 0;
channel.flags.with_dma = 0;
channel.flags.with_dma = this->with_dma_;
channel.intr_priority = 0;
esp_err_t error = rmt_new_tx_channel(&channel, &this->channel_);
if (error != ESP_OK) {