Skip to content

Commit

Permalink
[esp32_rmt] IDF 5+ update fixes (esphome#8002)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Swoboda <jonathan.swoboda>
Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
  • Loading branch information
swoboda1337 and kbx81 authored Dec 24, 2024
1 parent 45beea6 commit 387bde6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
8 changes: 4 additions & 4 deletions esphome/components/remote_receiver/remote_receiver_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@ void RemoteReceiverComponent::setup() {
void RemoteReceiverComponent::dump_config() {
ESP_LOGCONFIG(TAG, "Remote Receiver:");
LOG_PIN(" Pin: ", this->pin_);
if (this->pin_->digital_read()) {
ESP_LOGW(TAG, "Remote Receiver Signal starts with a HIGH value. Usually this means you have to "
"invert the signal using 'inverted: True' in the pin schema!");
}
#if ESP_IDF_VERSION_MAJOR >= 5
ESP_LOGCONFIG(TAG, " Clock resolution: %" PRIu32 " hz", this->clock_resolution_);
ESP_LOGCONFIG(TAG, " RMT symbols: %" PRIu32, this->rmt_symbols_);
ESP_LOGCONFIG(TAG, " Filter symbols: %" PRIu32, this->filter_symbols_);
ESP_LOGCONFIG(TAG, " Receive symbols: %" PRIu32, this->receive_symbols_);
#else
if (this->pin_->digital_read()) {
ESP_LOGW(TAG, "Remote Receiver Signal starts with a HIGH value. Usually this means you have to "
"invert the signal using 'inverted: True' in the pin schema!");
}
ESP_LOGCONFIG(TAG, " Channel: %d", this->channel_);
ESP_LOGCONFIG(TAG, " RMT memory blocks: %d", this->mem_block_num_);
ESP_LOGCONFIG(TAG, " Clock divider: %u", this->clock_divider_);
Expand Down
9 changes: 9 additions & 0 deletions esphome/components/remote_transmitter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
CONF_CLOCK_DIVIDER,
CONF_CLOCK_RESOLUTION,
CONF_ID,
CONF_INVERTED,
CONF_PIN,
CONF_RMT_CHANNEL,
CONF_RMT_SYMBOLS,
Expand All @@ -16,6 +17,7 @@

AUTO_LOAD = ["remote_base"]

CONF_EOT_LEVEL = "eot_level"
CONF_ON_TRANSMIT = "on_transmit"
CONF_ON_COMPLETE = "on_complete"
CONF_ONE_WIRE = "one_wire"
Expand All @@ -41,6 +43,7 @@
cv.Optional(CONF_CLOCK_DIVIDER): cv.All(
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(
Expand Down Expand Up @@ -73,6 +76,12 @@ async def to_code(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:
if (rmt_channel := config.get(CONF_RMT_CHANNEL, None)) is not None:
var = cg.new_Pvariable(config[CONF_ID], pin, rmt_channel)
Expand Down
3 changes: 3 additions & 0 deletions esphome/components/remote_transmitter/remote_transmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ 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

Trigger<> *get_transmit_trigger() const { return this->transmit_trigger_; };
Expand Down Expand Up @@ -68,6 +70,7 @@ class RemoteTransmitterComponent : public remote_base::RemoteTransmitterBase,
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};
#else
Expand Down
34 changes: 29 additions & 5 deletions esphome/components/remote_transmitter/remote_transmitter_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ static const char *const TAG = "remote_transmitter";

void RemoteTransmitterComponent::setup() {
ESP_LOGCONFIG(TAG, "Setting up Remote Transmitter...");
this->inverted_ = this->pin_->is_inverted();
this->configure_rmt_();
}

Expand All @@ -37,6 +38,31 @@ void RemoteTransmitterComponent::dump_config() {
}
}

#if ESP_IDF_VERSION_MAJOR >= 5
void RemoteTransmitterComponent::digital_write(bool value) {
rmt_symbol_word_t symbol = {
.duration0 = 1,
.level0 = value,
.duration1 = 0,
.level1 = value,
};
rmt_transmit_config_t config;
memset(&config, 0, sizeof(config));
config.loop_count = 0;
config.flags.eot_level = value;
esp_err_t error = rmt_transmit(this->channel_, this->encoder_, &symbol, sizeof(symbol), &config);
if (error != ESP_OK) {
ESP_LOGW(TAG, "rmt_transmit failed: %s", esp_err_to_name(error));
this->status_set_warning();
}
error = rmt_tx_wait_all_done(this->channel_, -1);
if (error != ESP_OK) {
ESP_LOGW(TAG, "rmt_tx_wait_all_done failed: %s", esp_err_to_name(error));
this->status_set_warning();
}
}
#endif

void RemoteTransmitterComponent::configure_rmt_() {
#if ESP_IDF_VERSION_MAJOR >= 5
esp_err_t error;
Expand Down Expand Up @@ -83,6 +109,7 @@ void RemoteTransmitterComponent::configure_rmt_() {
this->mark_failed();
return;
}
this->digital_write(this->one_wire_ || this->inverted_);
this->initialized_ = true;
}

Expand Down Expand Up @@ -120,13 +147,12 @@ void RemoteTransmitterComponent::configure_rmt_() {
}

c.tx_config.idle_output_en = true;
if (!this->pin_->is_inverted()) {
if (!this->inverted_) {
c.tx_config.carrier_level = RMT_CARRIER_LEVEL_HIGH;
c.tx_config.idle_level = RMT_IDLE_LEVEL_LOW;
} else {
c.tx_config.carrier_level = RMT_CARRIER_LEVEL_LOW;
c.tx_config.idle_level = RMT_IDLE_LEVEL_HIGH;
this->inverted_ = true;
}

esp_err_t error = rmt_config(&c);
Expand Down Expand Up @@ -210,7 +236,7 @@ void RemoteTransmitterComponent::send_internal(uint32_t send_times, uint32_t sen
rmt_transmit_config_t config;
memset(&config, 0, sizeof(config));
config.loop_count = 0;
config.flags.eot_level = this->inverted_;
config.flags.eot_level = this->eot_level_;
esp_err_t error = rmt_transmit(this->channel_, this->encoder_, this->rmt_temp_.data(),
this->rmt_temp_.size() * sizeof(rmt_symbol_word_t), &config);
if (error != ESP_OK) {
Expand All @@ -223,8 +249,6 @@ void RemoteTransmitterComponent::send_internal(uint32_t send_times, uint32_t sen
if (error != ESP_OK) {
ESP_LOGW(TAG, "rmt_tx_wait_all_done failed: %s", esp_err_to_name(error));
this->status_set_warning();
} else {
this->status_clear_warning();
}
if (i + 1 < send_times)
delayMicroseconds(send_wait);
Expand Down

0 comments on commit 387bde6

Please sign in to comment.