From ba63d266d823170fbd19761f97ca6539418795ed Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Wed, 11 Dec 2024 23:37:22 -0500 Subject: [PATCH 1/8] [const] Add RMT CONF variables to const.py (#7953) Co-authored-by: Jonathan Swoboda --- esphome/components/remote_receiver/__init__.py | 13 ++++++------- esphome/const.py | 4 ++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/esphome/components/remote_receiver/__init__.py b/esphome/components/remote_receiver/__init__.py index e5085bb33c..d3f61977c6 100644 --- a/esphome/components/remote_receiver/__init__.py +++ b/esphome/components/remote_receiver/__init__.py @@ -1,24 +1,23 @@ -import esphome.codegen as cg -import esphome.config_validation as cv from esphome import pins -from esphome.components import remote_base, esp32_rmt +import esphome.codegen as cg +from esphome.components import esp32_rmt, remote_base +import esphome.config_validation as cv from esphome.const import ( CONF_BUFFER_SIZE, + CONF_CLOCK_DIVIDER, CONF_DUMP, CONF_FILTER, CONF_ID, CONF_IDLE, + CONF_MEMORY_BLOCKS, CONF_PIN, + CONF_RMT_CHANNEL, CONF_TOLERANCE, CONF_TYPE, - CONF_MEMORY_BLOCKS, - CONF_RMT_CHANNEL, CONF_VALUE, ) from esphome.core import CORE, TimePeriod -CONF_CLOCK_DIVIDER = "clock_divider" - AUTO_LOAD = ["remote_base"] remote_receiver_ns = cg.esphome_ns.namespace("remote_receiver") remote_base_ns = cg.esphome_ns.namespace("remote_base") diff --git a/esphome/const.py b/esphome/const.py index 08cc907fdf..0f41dc1aec 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -131,7 +131,9 @@ CONF_CLIENT_CERTIFICATE = "client_certificate" CONF_CLIENT_CERTIFICATE_KEY = "client_certificate_key" CONF_CLIENT_ID = "client_id" CONF_CLK_PIN = "clk_pin" +CONF_CLOCK_DIVIDER = "clock_divider" CONF_CLOCK_PIN = "clock_pin" +CONF_CLOCK_RESOLUTION = "clock_resolution" CONF_CLOSE_ACTION = "close_action" CONF_CLOSE_DURATION = "close_duration" CONF_CLOSE_ENDSTOP = "close_endstop" @@ -739,6 +741,7 @@ CONF_RGB_ORDER = "rgb_order" CONF_RGBW = "rgbw" CONF_RISING_EDGE = "rising_edge" CONF_RMT_CHANNEL = "rmt_channel" +CONF_RMT_SYMBOLS = "rmt_symbols" CONF_ROTATION = "rotation" CONF_ROW = "row" CONF_RS_PIN = "rs_pin" @@ -918,6 +921,7 @@ CONF_UPDATE_ON_BOOT = "update_on_boot" CONF_URL = "url" CONF_USE_ABBREVIATIONS = "use_abbreviations" CONF_USE_ADDRESS = "use_address" +CONF_USE_DMA = "use_dma" CONF_USE_FAHRENHEIT = "use_fahrenheit" CONF_USERNAME = "username" CONF_UUID = "uuid" From 42bc960a36b32c5bdda326bf3eca80733ae38a6d Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Thu, 12 Dec 2024 22:37:51 +1300 Subject: [PATCH 2/8] [sgp30] Set default update interval to 60s (#7952) --- esphome/components/sgp30/sensor.py | 19 +++++++++---------- esphome/components/sgp30/sgp30.cpp | 8 ++------ 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/esphome/components/sgp30/sensor.py b/esphome/components/sgp30/sensor.py index 13e859cc09..8c92f55ef7 100644 --- a/esphome/components/sgp30/sensor.py +++ b/esphome/components/sgp30/sensor.py @@ -1,23 +1,22 @@ import esphome.codegen as cg +from esphome.components import i2c, sensirion_common, sensor import esphome.config_validation as cv -from esphome.components import i2c, sensor, sensirion_common - from esphome.const import ( - CONF_COMPENSATION, - CONF_ID, CONF_BASELINE, + CONF_COMPENSATION, CONF_ECO2, + CONF_ID, CONF_STORE_BASELINE, CONF_TEMPERATURE_SOURCE, CONF_TVOC, - ICON_RADIATOR, DEVICE_CLASS_CARBON_DIOXIDE, DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS_PARTS, - STATE_CLASS_MEASUREMENT, - UNIT_PARTS_PER_MILLION, - UNIT_PARTS_PER_BILLION, - ICON_MOLECULE_CO2, ENTITY_CATEGORY_DIAGNOSTIC, + ICON_MOLECULE_CO2, + ICON_RADIATOR, + STATE_CLASS_MEASUREMENT, + UNIT_PARTS_PER_BILLION, + UNIT_PARTS_PER_MILLION, ) DEPENDENCIES = ["i2c"] @@ -77,7 +76,7 @@ CONFIG_SCHEMA = ( ), } ) - .extend(cv.polling_component_schema("1s")) + .extend(cv.polling_component_schema("60s")) .extend(i2c.i2c_device_schema(0x58)) ) diff --git a/esphome/components/sgp30/sgp30.cpp b/esphome/components/sgp30/sgp30.cpp index 261604b992..77e9ef9820 100644 --- a/esphome/components/sgp30/sgp30.cpp +++ b/esphome/components/sgp30/sgp30.cpp @@ -1,8 +1,8 @@ #include "sgp30.h" +#include +#include "esphome/core/application.h" #include "esphome/core/hal.h" #include "esphome/core/log.h" -#include "esphome/core/application.h" -#include namespace esphome { namespace sgp30 { @@ -295,10 +295,6 @@ void SGP30Component::update() { if (this->tvoc_sensor_ != nullptr) this->tvoc_sensor_->publish_state(tvoc); - if (this->get_update_interval() != 1000) { - ESP_LOGW(TAG, "Update interval for SGP30 sensor must be set to 1s for optimized readout"); - } - this->status_clear_warning(); this->send_env_data_(); this->read_iaq_baseline_(); From c187cb547cd2c7a1223d399ea4c99aec1d386c73 Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:45:10 -0500 Subject: [PATCH 3/8] [core] Move delay_microseconds_safe to iram (#7957) Co-authored-by: Jonathan Swoboda --- esphome/core/helpers.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/esphome/core/helpers.cpp b/esphome/core/helpers.cpp index 4e8caeae99..b11615204e 100644 --- a/esphome/core/helpers.cpp +++ b/esphome/core/helpers.cpp @@ -767,7 +767,8 @@ bool mac_address_is_valid(const uint8_t *mac) { return !(is_all_zeros || is_all_ones); } -void delay_microseconds_safe(uint32_t us) { // avoids CPU locks that could trigger WDT or affect WiFi/BT stability +void IRAM_ATTR HOT delay_microseconds_safe(uint32_t us) { + // avoids CPU locks that could trigger WDT or affect WiFi/BT stability uint32_t start = micros(); const uint32_t lag = 5000; // microseconds, specifies the maximum time for a CPU busy-loop. From 88742e03995145e572e0feed57c3c22a7ce196fc Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Fri, 13 Dec 2024 22:16:11 +0100 Subject: [PATCH 4/8] [rotary_encoder] Fix volatile increment/decrement deprecation warnings (#7958) --- esphome/components/rotary_encoder/rotary_encoder.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/esphome/components/rotary_encoder/rotary_encoder.cpp b/esphome/components/rotary_encoder/rotary_encoder.cpp index e9a0eac3f5..f8e5357a6e 100644 --- a/esphome/components/rotary_encoder/rotary_encoder.cpp +++ b/esphome/components/rotary_encoder/rotary_encoder.cpp @@ -93,13 +93,17 @@ void IRAM_ATTR HOT RotaryEncoderSensorStore::gpio_intr(RotaryEncoderSensorStore int8_t rotation_dir = 0; uint16_t new_state = STATE_LOOKUP_TABLE[input_state]; if ((new_state & arg->resolution & STATE_HAS_INCREMENTED) != 0) { - if (arg->counter < arg->max_value) - arg->counter++; + if (arg->counter < arg->max_value) { + auto x = arg->counter + 1; + arg->counter = x; + } rotation_dir = 1; } if ((new_state & arg->resolution & STATE_HAS_DECREMENTED) != 0) { - if (arg->counter > arg->min_value) - arg->counter--; + if (arg->counter > arg->min_value) { + auto x = arg->counter - 1; + arg->counter = x; + } rotation_dir = -1; } From ce7ff15c8ad9f3dd3ba4110428ffc42ae0f901dd Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Fri, 13 Dec 2024 22:21:54 +0100 Subject: [PATCH 5/8] [pulse_counter] Fix volatile increment/decrement deprecation warnings (#7954) --- .../pulse_counter/pulse_counter_sensor.cpp | 23 +++++++++++-------- .../pulse_counter/pulse_counter_sensor.h | 8 +++---- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/esphome/components/pulse_counter/pulse_counter_sensor.cpp b/esphome/components/pulse_counter/pulse_counter_sensor.cpp index bd3e4fcbef..2bc80c352c 100644 --- a/esphome/components/pulse_counter/pulse_counter_sensor.cpp +++ b/esphome/components/pulse_counter/pulse_counter_sensor.cpp @@ -13,9 +13,9 @@ PulseCounterStorageBase *get_storage(bool hw_pcnt) { return (hw_pcnt ? (PulseCounterStorageBase *) (new HwPulseCounterStorage) : (PulseCounterStorageBase *) (new BasicPulseCounterStorage)); } -#else +#else // HAS_PCNT PulseCounterStorageBase *get_storage(bool) { return new BasicPulseCounterStorage; } -#endif +#endif // HAS_PCNT void IRAM_ATTR BasicPulseCounterStorage::gpio_intr(BasicPulseCounterStorage *arg) { const uint32_t now = micros(); @@ -28,14 +28,17 @@ void IRAM_ATTR BasicPulseCounterStorage::gpio_intr(BasicPulseCounterStorage *arg switch (mode) { case PULSE_COUNTER_DISABLE: break; - case PULSE_COUNTER_INCREMENT: - arg->counter++; - break; - case PULSE_COUNTER_DECREMENT: - arg->counter--; - break; + case PULSE_COUNTER_INCREMENT: { + auto x = arg->counter + 1; + arg->counter = x; + } break; + case PULSE_COUNTER_DECREMENT: { + auto x = arg->counter - 1; + arg->counter = x; + } break; } } + bool BasicPulseCounterStorage::pulse_counter_setup(InternalGPIOPin *pin) { this->pin = pin; this->pin->setup(); @@ -43,6 +46,7 @@ bool BasicPulseCounterStorage::pulse_counter_setup(InternalGPIOPin *pin) { this->pin->attach_interrupt(BasicPulseCounterStorage::gpio_intr, this, gpio::INTERRUPT_ANY_EDGE); return true; } + pulse_counter_t BasicPulseCounterStorage::read_raw_value() { pulse_counter_t counter = this->counter; pulse_counter_t ret = counter - this->last_value; @@ -141,6 +145,7 @@ bool HwPulseCounterStorage::pulse_counter_setup(InternalGPIOPin *pin) { } return true; } + pulse_counter_t HwPulseCounterStorage::read_raw_value() { pulse_counter_t counter; pcnt_get_counter_value(this->pcnt_unit, &counter); @@ -148,7 +153,7 @@ pulse_counter_t HwPulseCounterStorage::read_raw_value() { this->last_value = counter; return ret; } -#endif +#endif // HAS_PCNT void PulseCounterSensor::setup() { ESP_LOGCONFIG(TAG, "Setting up pulse counter '%s'...", this->name_.c_str()); diff --git a/esphome/components/pulse_counter/pulse_counter_sensor.h b/esphome/components/pulse_counter/pulse_counter_sensor.h index fc3d8711d1..cea9fa7bf9 100644 --- a/esphome/components/pulse_counter/pulse_counter_sensor.h +++ b/esphome/components/pulse_counter/pulse_counter_sensor.h @@ -9,7 +9,7 @@ #if defined(USE_ESP32) && !defined(USE_ESP32_VARIANT_ESP32C3) #include #define HAS_PCNT -#endif +#endif // defined(USE_ESP32) && !defined(USE_ESP32_VARIANT_ESP32C3) namespace esphome { namespace pulse_counter { @@ -22,9 +22,9 @@ enum PulseCounterCountMode { #ifdef HAS_PCNT using pulse_counter_t = int16_t; -#else +#else // HAS_PCNT using pulse_counter_t = int32_t; -#endif +#endif // HAS_PCNT struct PulseCounterStorageBase { virtual bool pulse_counter_setup(InternalGPIOPin *pin) = 0; @@ -57,7 +57,7 @@ struct HwPulseCounterStorage : public PulseCounterStorageBase { pcnt_unit_t pcnt_unit; pcnt_channel_t pcnt_channel; }; -#endif +#endif // HAS_PCNT PulseCounterStorageBase *get_storage(bool hw_pcnt = false); From 7f2ca800c1312f8b864f17949ab35339a55ac4f6 Mon Sep 17 00:00:00 2001 From: Kevin Ahrendt Date: Sat, 14 Dec 2024 00:17:58 -0500 Subject: [PATCH 6/8] [i2s_audio] Bugfix: Correctly set ring buffer size (#7959) --- esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp index d2a582c2cc..46f1b00d05 100644 --- a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +++ b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp @@ -247,7 +247,7 @@ void I2SAudioSpeaker::speaker_task(void *params) { // Ensure ring buffer is at least as large as the total size of the DMA buffers const size_t ring_buffer_size = - std::min((uint32_t) dma_buffers_size, this_speaker->buffer_duration_ms_ * bytes_per_ms); + std::max((uint32_t) dma_buffers_size, this_speaker->buffer_duration_ms_ * bytes_per_ms); if (this_speaker->send_esp_err_to_event_group_(this_speaker->allocate_buffers_(dma_buffers_size, ring_buffer_size))) { // Failed to allocate buffers From 5877c57a3572138de2873262a0204759a2704149 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Sat, 14 Dec 2024 19:55:04 +0100 Subject: [PATCH 7/8] [adc] Restore missing LIBRETINY code in a separated file (#7955) --- .../components/adc/adc_sensor_libretiny.cpp | 48 +++++++++++++++++++ tests/components/adc/test.bk72xx-ard.yaml | 4 ++ 2 files changed, 52 insertions(+) create mode 100644 esphome/components/adc/adc_sensor_libretiny.cpp create mode 100644 tests/components/adc/test.bk72xx-ard.yaml diff --git a/esphome/components/adc/adc_sensor_libretiny.cpp b/esphome/components/adc/adc_sensor_libretiny.cpp new file mode 100644 index 0000000000..cd04477b3f --- /dev/null +++ b/esphome/components/adc/adc_sensor_libretiny.cpp @@ -0,0 +1,48 @@ +#ifdef USE_LIBRETINY + +#include "adc_sensor.h" +#include "esphome/core/log.h" + +namespace esphome { +namespace adc { + +static const char *const TAG = "adc.libretiny"; + +void ADCSensor::setup() { + ESP_LOGCONFIG(TAG, "Setting up ADC '%s'...", this->get_name().c_str()); +#ifndef USE_ADC_SENSOR_VCC + this->pin_->setup(); +#endif // !USE_ADC_SENSOR_VCC +} + +void ADCSensor::dump_config() { + LOG_SENSOR("", "ADC Sensor", this); +#ifdef USE_ADC_SENSOR_VCC + ESP_LOGCONFIG(TAG, " Pin: VCC"); +#else // USE_ADC_SENSOR_VCC + LOG_PIN(" Pin: ", this->pin_); +#endif // USE_ADC_SENSOR_VCC + ESP_LOGCONFIG(TAG, " Samples: %i", this->sample_count_); + LOG_UPDATE_INTERVAL(this); +} + +float ADCSensor::sample() { + uint32_t raw = 0; + if (this->output_raw_) { + for (uint8_t sample = 0; sample < this->sample_count_; sample++) { + raw += analogRead(this->pin_->get_pin()); // NOLINT + } + raw = (raw + (this->sample_count_ >> 1)) / this->sample_count_; // NOLINT(clang-analyzer-core.DivideZero) + return raw; + } + for (uint8_t sample = 0; sample < this->sample_count_; sample++) { + raw += analogReadVoltage(this->pin_->get_pin()); // NOLINT + } + raw = (raw + (this->sample_count_ >> 1)) / this->sample_count_; // NOLINT(clang-analyzer-core.DivideZero) + return raw / 1000.0f; +} + +} // namespace adc +} // namespace esphome + +#endif // USE_LIBRETINY diff --git a/tests/components/adc/test.bk72xx-ard.yaml b/tests/components/adc/test.bk72xx-ard.yaml new file mode 100644 index 0000000000..491d0af3b9 --- /dev/null +++ b/tests/components/adc/test.bk72xx-ard.yaml @@ -0,0 +1,4 @@ +sensor: + - platform: adc + pin: P23 + name: Basic ADC Test From df4224e779a2173ca63e75ea7ed8f294e540a2f1 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Sun, 15 Dec 2024 19:30:47 +0100 Subject: [PATCH 8/8] [nextion] Publishes `is_connected()` (#7961) --- esphome/components/nextion/nextion.cpp | 2 +- esphome/components/nextion/nextion.h | 21 +++++++++++++++++++-- tests/components/nextion/common.yaml | 2 ++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/esphome/components/nextion/nextion.cpp b/esphome/components/nextion/nextion.cpp index 50a5834347..0b3ded07ae 100644 --- a/esphome/components/nextion/nextion.cpp +++ b/esphome/components/nextion/nextion.cpp @@ -40,7 +40,7 @@ bool Nextion::send_command_(const std::string &command) { } bool Nextion::check_connect_() { - if (this->get_is_connected_()) + if (this->is_connected_) return true; // Check if the handshake should be skipped for the Nextion connection diff --git a/esphome/components/nextion/nextion.h b/esphome/components/nextion/nextion.h index f539c79718..800bdaaa74 100644 --- a/esphome/components/nextion/nextion.h +++ b/esphome/components/nextion/nextion.h @@ -1217,6 +1217,25 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe */ bool is_updating() override; + /** + * @brief Check if the Nextion display is successfully connected. + * + * This method returns whether a successful connection has been established with + * the Nextion display. A connection is considered established when: + * + * - The initial handshake with the display is completed successfully, or + * - The handshake is skipped via skip_connection_handshake_ flag + * + * The connection status is particularly useful when: + * - Troubleshooting communication issues + * - Ensuring the display is ready before sending commands + * - Implementing connection-dependent behaviors + * + * @return true if the Nextion display is connected and ready to receive commands + * @return false if the display is not yet connected or connection was lost + */ + bool is_connected() { return this->is_connected_; } + protected: std::deque nextion_queue_; std::deque waveform_queue_; @@ -1315,8 +1334,6 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe #endif // USE_NEXTION_TFT_UPLOAD - bool get_is_connected_() { return this->is_connected_; } - bool check_connect_(); std::vector touch_; diff --git a/tests/components/nextion/common.yaml b/tests/components/nextion/common.yaml index e84cd08422..73fc8484c0 100644 --- a/tests/components/nextion/common.yaml +++ b/tests/components/nextion/common.yaml @@ -1,5 +1,7 @@ esphome: on_boot: + - lambda: 'ESP_LOGD("display","is_connected(): %s", YESNO(id(main_lcd).is_connected()));' + # Binary sensor publish action tests - binary_sensor.nextion.publish: id: r0_sensor