mirror of
https://github.com/esphome/esphome.git
synced 2026-09-17 18:18:43 +00:00
[remote_receiver] [remote_transmitter] Keep the RMT setup error message as a pointer to the literal (#19210)
This commit is contained in:
@@ -83,14 +83,14 @@ class RemoteReceiverComponent final : public remote_base::RemoteReceiverBase,
|
||||
protected:
|
||||
#if defined(USE_ESP32) && SOC_RMT_SUPPORTED
|
||||
void decode_rmt_(rmt_symbol_word_t *item, size_t item_count);
|
||||
// log the failed RMT call and mark the component failed
|
||||
void fail_(esp_err_t error, const LogString *reason);
|
||||
rmt_channel_handle_t channel_{NULL};
|
||||
uint32_t filter_symbols_{0};
|
||||
uint32_t receive_symbols_{0};
|
||||
bool with_dma_{false};
|
||||
uint32_t carrier_frequency_{0};
|
||||
uint8_t carrier_duty_percent_{100};
|
||||
esp_err_t error_code_{ESP_OK};
|
||||
std::string error_string_;
|
||||
#endif
|
||||
|
||||
#if defined(USE_ESP8266) || defined(USE_LIBRETINY) || defined(USE_RP2) || defined(USE_ESP32)
|
||||
|
||||
@@ -43,6 +43,11 @@ static bool IRAM_ATTR HOT rmt_callback(rmt_channel_handle_t channel, const rmt_r
|
||||
return task_woken != pdFALSE;
|
||||
}
|
||||
|
||||
void RemoteReceiverComponent::fail_(esp_err_t error, const LogString *reason) {
|
||||
ESP_LOGE(TAG, "RMT driver failed: %s", esp_err_to_name(error));
|
||||
this->mark_failed(reason);
|
||||
}
|
||||
|
||||
void RemoteReceiverComponent::setup() {
|
||||
rmt_rx_channel_config_t channel;
|
||||
memset(&channel, 0, sizeof(channel));
|
||||
@@ -55,13 +60,8 @@ void RemoteReceiverComponent::setup() {
|
||||
channel.flags.with_dma = this->with_dma_;
|
||||
esp_err_t error = rmt_new_rx_channel(&channel, &this->channel_);
|
||||
if (error != ESP_OK) {
|
||||
this->error_code_ = error;
|
||||
if (error == ESP_ERR_NOT_FOUND) {
|
||||
this->error_string_ = "out of RMT symbol memory";
|
||||
} else {
|
||||
this->error_string_ = "in rmt_new_rx_channel";
|
||||
}
|
||||
this->mark_failed();
|
||||
this->fail_(error,
|
||||
error == ESP_ERR_NOT_FOUND ? LOG_STR("out of RMT symbol memory") : LOG_STR("in rmt_new_rx_channel"));
|
||||
return;
|
||||
}
|
||||
if (this->pin_->get_flags() & gpio::FLAG_PULLUP) {
|
||||
@@ -71,9 +71,7 @@ void RemoteReceiverComponent::setup() {
|
||||
}
|
||||
error = rmt_enable(this->channel_);
|
||||
if (error != ESP_OK) {
|
||||
this->error_code_ = error;
|
||||
this->error_string_ = "in rmt_enable";
|
||||
this->mark_failed();
|
||||
this->fail_(error, LOG_STR("in rmt_enable"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -85,9 +83,7 @@ void RemoteReceiverComponent::setup() {
|
||||
carrier.flags.polarity_active_low = this->pin_->is_inverted();
|
||||
error = rmt_apply_carrier(this->channel_, &carrier);
|
||||
if (error != ESP_OK) {
|
||||
this->error_code_ = error;
|
||||
this->error_string_ = "in rmt_apply_carrier";
|
||||
this->mark_failed();
|
||||
this->fail_(error, LOG_STR("in rmt_apply_carrier"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -97,9 +93,7 @@ void RemoteReceiverComponent::setup() {
|
||||
callbacks.on_recv_done = rmt_callback;
|
||||
error = rmt_rx_register_event_callbacks(this->channel_, &callbacks, &this->store_);
|
||||
if (error != ESP_OK) {
|
||||
this->error_code_ = error;
|
||||
this->error_string_ = "in rmt_rx_register_event_callbacks";
|
||||
this->mark_failed();
|
||||
this->fail_(error, LOG_STR("in rmt_rx_register_event_callbacks"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -122,9 +116,7 @@ void RemoteReceiverComponent::setup() {
|
||||
error = rmt_receive(this->channel_, (uint8_t *) this->store_.buffer + event_size, this->store_.receive_size,
|
||||
&this->store_.config);
|
||||
if (error != ESP_OK) {
|
||||
this->error_code_ = error;
|
||||
this->error_string_ = "in rmt_receive";
|
||||
this->mark_failed();
|
||||
this->fail_(error, LOG_STR("in rmt_receive"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -148,18 +140,11 @@ void RemoteReceiverComponent::dump_config() {
|
||||
(this->tolerance_mode_ == remote_base::TOLERANCE_MODE_TIME) ? LOG_STR_LITERAL(" us") : LOG_STR_LITERAL("%"),
|
||||
this->carrier_frequency_, this->carrier_duty_percent_, this->filter_us_, this->idle_us_);
|
||||
LOG_PIN(" Pin: ", this->pin_);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Configuring RMT driver failed: %s (%s)", esp_err_to_name(this->error_code_),
|
||||
this->error_string_.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteReceiverComponent::loop() {
|
||||
if (this->store_.error != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Receive error");
|
||||
this->error_code_ = this->store_.error;
|
||||
this->error_string_ = "in rmt_callback";
|
||||
this->mark_failed();
|
||||
this->fail_(this->store_.error, LOG_STR("in rmt_callback"));
|
||||
}
|
||||
if (this->store_.overflow) {
|
||||
ESP_LOGW(TAG, "Buffer overflow");
|
||||
|
||||
@@ -141,6 +141,8 @@ class RemoteTransmitterComponent final : public remote_base::RemoteTransmitterBa
|
||||
#endif
|
||||
|
||||
#if defined(USE_ESP32) && SOC_RMT_SUPPORTED
|
||||
// log the failed RMT call and mark the component failed
|
||||
void fail_(esp_err_t error, const LogString *reason);
|
||||
void configure_rmt_();
|
||||
void wait_for_rmt_();
|
||||
|
||||
@@ -156,8 +158,6 @@ class RemoteTransmitterComponent final : public remote_base::RemoteTransmitterBa
|
||||
bool eot_level_{false};
|
||||
rmt_channel_handle_t channel_{NULL};
|
||||
rmt_encoder_handle_t encoder_{NULL};
|
||||
esp_err_t error_code_{ESP_OK};
|
||||
std::string error_string_;
|
||||
bool inverted_{false};
|
||||
bool non_blocking_{false};
|
||||
#endif
|
||||
|
||||
@@ -51,6 +51,11 @@ static size_t IRAM_ATTR HOT encoder_callback(const void *data, size_t size, size
|
||||
}
|
||||
#endif
|
||||
|
||||
void RemoteTransmitterComponent::fail_(esp_err_t error, const LogString *reason) {
|
||||
ESP_LOGE(TAG, "RMT driver failed: %s", esp_err_to_name(error));
|
||||
this->mark_failed(reason);
|
||||
}
|
||||
|
||||
void RemoteTransmitterComponent::setup() {
|
||||
this->inverted_ = this->pin_->is_inverted();
|
||||
this->configure_rmt_();
|
||||
@@ -67,11 +72,6 @@ void RemoteTransmitterComponent::dump_config() {
|
||||
if (this->current_carrier_frequency_ != 0 && this->carrier_duty_percent_ != 100) {
|
||||
ESP_LOGCONFIG(TAG, " Carrier Duty: %u%%", this->carrier_duty_percent_);
|
||||
}
|
||||
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Configuring RMT driver failed: %s (%s)", esp_err_to_name(this->error_code_),
|
||||
this->error_string_.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteTransmitterComponent::digital_write(bool value) {
|
||||
@@ -129,13 +129,8 @@ void RemoteTransmitterComponent::configure_rmt_() {
|
||||
#endif
|
||||
error = rmt_new_tx_channel(&channel, &this->channel_);
|
||||
if (error != ESP_OK) {
|
||||
this->error_code_ = error;
|
||||
if (error == ESP_ERR_NOT_FOUND) {
|
||||
this->error_string_ = "out of RMT symbol memory";
|
||||
} else {
|
||||
this->error_string_ = "in rmt_new_tx_channel";
|
||||
}
|
||||
this->mark_failed();
|
||||
this->fail_(error,
|
||||
error == ESP_ERR_NOT_FOUND ? LOG_STR("out of RMT symbol memory") : LOG_STR("in rmt_new_tx_channel"));
|
||||
return;
|
||||
}
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
|
||||
@@ -159,9 +154,7 @@ void RemoteTransmitterComponent::configure_rmt_() {
|
||||
encoder.min_chunk_size = 1;
|
||||
error = rmt_new_simple_encoder(&encoder, &this->encoder_);
|
||||
if (error != ESP_OK) {
|
||||
this->error_code_ = error;
|
||||
this->error_string_ = "in rmt_new_simple_encoder";
|
||||
this->mark_failed();
|
||||
this->fail_(error, LOG_STR("in rmt_new_simple_encoder"));
|
||||
return;
|
||||
}
|
||||
#else
|
||||
@@ -169,18 +162,14 @@ void RemoteTransmitterComponent::configure_rmt_() {
|
||||
memset(&encoder, 0, sizeof(encoder));
|
||||
error = rmt_new_copy_encoder(&encoder, &this->encoder_);
|
||||
if (error != ESP_OK) {
|
||||
this->error_code_ = error;
|
||||
this->error_string_ = "in rmt_new_copy_encoder";
|
||||
this->mark_failed();
|
||||
this->fail_(error, LOG_STR("in rmt_new_copy_encoder"));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
error = rmt_enable(this->channel_);
|
||||
if (error != ESP_OK) {
|
||||
this->error_code_ = error;
|
||||
this->error_string_ = "in rmt_enable";
|
||||
this->mark_failed();
|
||||
this->fail_(error, LOG_STR("in rmt_enable"));
|
||||
return;
|
||||
}
|
||||
this->digital_write(open_drain || this->inverted_);
|
||||
@@ -199,9 +188,7 @@ void RemoteTransmitterComponent::configure_rmt_() {
|
||||
error = rmt_apply_carrier(this->channel_, &carrier);
|
||||
}
|
||||
if (error != ESP_OK) {
|
||||
this->error_code_ = error;
|
||||
this->error_string_ = "in rmt_apply_carrier";
|
||||
this->mark_failed();
|
||||
this->fail_(error, LOG_STR("in rmt_apply_carrier"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user