mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	
							
								
								
									
										48
									
								
								esphome/components/adc/adc_sensor_libretiny.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								esphome/components/adc/adc_sensor_libretiny.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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") | ||||
|   | ||||
| @@ -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)) | ||||
| ) | ||||
|  | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| #include "sgp30.h" | ||||
| #include <cinttypes> | ||||
| #include "esphome/core/application.h" | ||||
| #include "esphome/core/hal.h" | ||||
| #include "esphome/core/log.h" | ||||
| #include "esphome/core/application.h" | ||||
| #include <cinttypes> | ||||
|  | ||||
| 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_(); | ||||
|   | ||||
| @@ -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" | ||||
|   | ||||
| @@ -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. | ||||
|   | ||||
							
								
								
									
										4
									
								
								tests/components/adc/test.bk72xx-ard.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								tests/components/adc/test.bk72xx-ard.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| sensor: | ||||
|   - platform: adc | ||||
|     pin: P23 | ||||
|     name: Basic ADC Test | ||||
		Reference in New Issue
	
	Block a user