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/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 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/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_(); diff --git a/esphome/const.py b/esphome/const.py index 4d8d550fd1..64b3f83b83 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -1,6 +1,6 @@ """Constants used by esphome.""" -__version__ = "2024.12.0b1" +__version__ = "2024.12.0b2" ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_" VALID_SUBSTITUTIONS_CHARACTERS = ( @@ -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" 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. 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