ESP-IDF support and generic target platforms (#2303)

* Socket refactor and SSL

* esp-idf temp

* Fixes

* Echo component and noise

* Add noise API transport support

* Updates

* ESP-IDF

* Complete

* Fixes

* Fixes

* Versions update

* New i2c APIs

* Complete i2c refactor

* SPI migration

* Revert ESP Preferences migration, too complex for now

* OTA support

* Remove echo again

* Remove ssl again

* GPIOFlags updates

* Rename esphal and ICACHE_RAM_ATTR

* Make ESP32 arduino compilable again

* Fix GPIO flags

* Complete pin registry refactor and fixes

* Fixes to make test1 compile

* Remove sdkconfig file

* Ignore sdkconfig file

* Fixes in reviewing

* Make test2 compile

* Make test4 compile

* Make test5 compile

* Run clang-format

* Fix lint errors

* Use esp-idf APIs instead of btStart

* Another round of fixes

* Start implementing ESP8266

* Make test3 compile

* Guard esp8266 code

* Lint

* Reformat

* Fixes

* Fixes v2

* more fixes

* ESP-IDF tidy target

* Convert ARDUINO_ARCH_ESPxx

* Update WiFiSignalSensor

* Update time ifdefs

* OTA needs millis from hal

* RestartSwitch needs delay from hal

* ESP-IDF Uart

* Fix OTA blank password

* Allow setting sdkconfig

* Fix idf partitions and allow setting sdkconfig from yaml

* Re-add read/write compat APIs and fix esp8266 uart

* Fix esp8266 store log strings in flash

* Fix ESP32 arduino preferences not initialized

* Update ifdefs

* Change how sdkconfig change is detected

* Add checks to ci-custom and fix them

* Run clang-format

* Add esp-idf clang-tidy target and fix errors

* Fixes from clang-tidy idf round 2

* Fixes from compiling tests with esp-idf

* Run clang-format

* Switch test5.yaml to esp-idf

* Implement ESP8266 Preferences

* Lint

* Re-do PIO package version selection a bit

* Fix arduinoespressif32 package version

* Fix unit tests

* Lint

* Lint fixes

* Fix readv/writev not defined

* Fix graphing component

* Re-add all old options from core/config.py

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Otto Winter
2021-09-20 11:47:51 +02:00
committed by GitHub
parent 1e8e471dec
commit ac0d921413
583 changed files with 9008 additions and 5420 deletions
+5 -1
View File
@@ -46,7 +46,7 @@ jobs:
name: Run script/clang-format name: Run script/clang-format
- id: clang-tidy - id: clang-tidy
name: Run script/clang-tidy for ESP8266 name: Run script/clang-tidy for ESP8266
options: --environment esp8266-tidy --grep ARDUINO_ARCH_ESP8266 options: --environment esp8266-tidy --grep USE_ESP8266
pio_cache_key: tidyesp8266 pio_cache_key: tidyesp8266
- id: clang-tidy - id: clang-tidy
name: Run script/clang-tidy for ESP32 1/4 name: Run script/clang-tidy for ESP32 1/4
@@ -64,6 +64,10 @@ jobs:
name: Run script/clang-tidy for ESP32 4/4 name: Run script/clang-tidy for ESP32 4/4
options: --environment esp32-tidy --split-num 4 --split-at 4 options: --environment esp32-tidy --split-num 4 --split-at 4
pio_cache_key: tidyesp32 pio_cache_key: tidyesp32
- id: clang-tidy
name: Run script/clang-tidy for ESP32 esp-idf
options: --environment esp32-idf-tidy --grep USE_ESP_IDF
pio_cache_key: tidyesp32-idf
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
+2
View File
@@ -124,3 +124,5 @@ tests/.esphome/
/.temp-clang-tidy.cpp /.temp-clang-tidy.cpp
/.temp/ /.temp/
.pio/ .pio/
sdkconfig.*
+3
View File
@@ -44,9 +44,11 @@ esphome/components/dfplayer/* @glmnet
esphome/components/dht/* @OttoWinter esphome/components/dht/* @OttoWinter
esphome/components/ds1307/* @badbadc0ffee esphome/components/ds1307/* @badbadc0ffee
esphome/components/dsmr/* @glmnet @zuidwijk esphome/components/dsmr/* @glmnet @zuidwijk
esphome/components/esp32/* @esphome/core
esphome/components/esp32_ble/* @jesserockz esphome/components/esp32_ble/* @jesserockz
esphome/components/esp32_ble_server/* @jesserockz esphome/components/esp32_ble_server/* @jesserockz
esphome/components/esp32_improv/* @jesserockz esphome/components/esp32_improv/* @jesserockz
esphome/components/esp8266/* @esphome/core
esphome/components/exposure_notifications/* @OttoWinter esphome/components/exposure_notifications/* @OttoWinter
esphome/components/ezo/* @ssieb esphome/components/ezo/* @ssieb
esphome/components/fastled_base/* @OttoWinter esphome/components/fastled_base/* @OttoWinter
@@ -81,6 +83,7 @@ esphome/components/mcp23x17_base/* @jesserockz
esphome/components/mcp23xxx_base/* @jesserockz esphome/components/mcp23xxx_base/* @jesserockz
esphome/components/mcp2515/* @danielschramm @mvturnho esphome/components/mcp2515/* @danielschramm @mvturnho
esphome/components/mcp9808/* @k7hpn esphome/components/mcp9808/* @k7hpn
esphome/components/mdns/* @esphome/core
esphome/components/midea/* @dudanov esphome/components/midea/* @dudanov
esphome/components/mitsubishi/* @RubyBailey esphome/components/mitsubishi/* @RubyBailey
esphome/components/network/* @esphome/core esphome/components/network/* @esphome/core
+1 -1
View File
@@ -245,7 +245,7 @@ def upload_program(config, args, host):
ota_conf = config[CONF_OTA] ota_conf = config[CONF_OTA]
remote_port = ota_conf[CONF_PORT] remote_port = ota_conf[CONF_PORT]
password = ota_conf[CONF_PASSWORD] password = ota_conf.get(CONF_PASSWORD, "")
return espota2.run_ota(host, remote_port, password, CORE.firmware_bin) return espota2.run_ota(host, remote_port, password, CORE.firmware_bin)
+3
View File
@@ -30,6 +30,7 @@ from esphome.cpp_generator import ( # noqa
add_library, add_library,
add_build_flag, add_build_flag,
add_define, add_define,
add_platformio_option,
get_variable, get_variable,
get_variable_with_full_id, get_variable_with_full_id,
process_lambda, process_lambda,
@@ -78,4 +79,6 @@ from esphome.cpp_types import ( # noqa
JsonObjectConstRef, JsonObjectConstRef,
Controller, Controller,
GPIOPin, GPIOPin,
InternalGPIOPin,
gpio_Flags,
) )
+1 -1
View File
@@ -1,7 +1,7 @@
#pragma once #pragma once
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/core/esphal.h" #include "esphome/core/hal.h"
#include "esphome/components/stepper/stepper.h" #include "esphome/components/stepper/stepper.h"
namespace esphome { namespace esphome {
+28 -19
View File
@@ -1,10 +1,16 @@
#ifdef USE_ARDUINO
#include "ac_dimmer.h" #include "ac_dimmer.h"
#include "esphome/core/helpers.h" #include "esphome/core/helpers.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include <cmath>
#ifdef ARDUINO_ARCH_ESP8266 #ifdef USE_ESP8266
#include <core_esp8266_waveform.h> #include <core_esp8266_waveform.h>
#endif #endif
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
#include <esp32-hal-timer.h>
#endif
namespace esphome { namespace esphome {
namespace ac_dimmer { namespace ac_dimmer {
@@ -25,7 +31,7 @@ static const uint32_t GATE_ENABLE_TIME = 50;
/// Function called from timer interrupt /// Function called from timer interrupt
/// Input is current time in microseconds (micros()) /// Input is current time in microseconds (micros())
/// Returns when next "event" is expected in µs, or 0 if no such event known. /// Returns when next "event" is expected in µs, or 0 if no such event known.
uint32_t ICACHE_RAM_ATTR HOT AcDimmerDataStore::timer_intr(uint32_t now) { uint32_t IRAM_ATTR HOT AcDimmerDataStore::timer_intr(uint32_t now) {
// If no ZC signal received yet. // If no ZC signal received yet.
if (this->crossed_zero_at == 0) if (this->crossed_zero_at == 0)
return 0; return 0;
@@ -37,13 +43,13 @@ uint32_t ICACHE_RAM_ATTR HOT AcDimmerDataStore::timer_intr(uint32_t now) {
if (this->enable_time_us != 0 && time_since_zc >= this->enable_time_us) { if (this->enable_time_us != 0 && time_since_zc >= this->enable_time_us) {
this->enable_time_us = 0; this->enable_time_us = 0;
this->gate_pin->digital_write(true); this->gate_pin.digital_write(true);
// Prevent too short pulses // Prevent too short pulses
this->disable_time_us = max(this->disable_time_us, time_since_zc + GATE_ENABLE_TIME); this->disable_time_us = std::max(this->disable_time_us, time_since_zc + GATE_ENABLE_TIME);
} }
if (this->disable_time_us != 0 && time_since_zc >= this->disable_time_us) { if (this->disable_time_us != 0 && time_since_zc >= this->disable_time_us) {
this->disable_time_us = 0; this->disable_time_us = 0;
this->gate_pin->digital_write(false); this->gate_pin.digital_write(false);
} }
if (time_since_zc < this->enable_time_us) if (time_since_zc < this->enable_time_us)
@@ -63,7 +69,7 @@ uint32_t ICACHE_RAM_ATTR HOT AcDimmerDataStore::timer_intr(uint32_t now) {
} }
/// Run timer interrupt code and return in how many µs the next event is expected /// Run timer interrupt code and return in how many µs the next event is expected
uint32_t ICACHE_RAM_ATTR HOT timer_interrupt() { uint32_t IRAM_ATTR HOT timer_interrupt() {
// run at least with 1kHz // run at least with 1kHz
uint32_t min_dt_us = 1000; uint32_t min_dt_us = 1000;
uint32_t now = micros(); uint32_t now = micros();
@@ -80,7 +86,7 @@ uint32_t ICACHE_RAM_ATTR HOT timer_interrupt() {
} }
/// GPIO interrupt routine, called when ZC pin triggers /// GPIO interrupt routine, called when ZC pin triggers
void ICACHE_RAM_ATTR HOT AcDimmerDataStore::gpio_intr() { void IRAM_ATTR HOT AcDimmerDataStore::gpio_intr() {
uint32_t prev_crossed = this->crossed_zero_at; uint32_t prev_crossed = this->crossed_zero_at;
// 50Hz mains frequency should give a half cycle of 10ms a 60Hz will give 8.33ms // 50Hz mains frequency should give a half cycle of 10ms a 60Hz will give 8.33ms
@@ -97,7 +103,7 @@ void ICACHE_RAM_ATTR HOT AcDimmerDataStore::gpio_intr() {
if (this->value == 65535) { if (this->value == 65535) {
// fully on, enable output immediately // fully on, enable output immediately
this->gate_pin->digital_write(true); this->gate_pin.digital_write(true);
} else if (this->init_cycle) { } else if (this->init_cycle) {
// send a full cycle // send a full cycle
this->init_cycle = false; this->init_cycle = false;
@@ -105,29 +111,29 @@ void ICACHE_RAM_ATTR HOT AcDimmerDataStore::gpio_intr() {
this->disable_time_us = cycle_time_us; this->disable_time_us = cycle_time_us;
} else if (this->value == 0) { } else if (this->value == 0) {
// fully off, disable output immediately // fully off, disable output immediately
this->gate_pin->digital_write(false); this->gate_pin.digital_write(false);
} else { } else {
if (this->method == DIM_METHOD_TRAILING) { if (this->method == DIM_METHOD_TRAILING) {
this->enable_time_us = 1; // cannot be 0 this->enable_time_us = 1; // cannot be 0
this->disable_time_us = max((uint32_t) 10, this->value * this->cycle_time_us / 65535); this->disable_time_us = std::max((uint32_t) 10, this->value * this->cycle_time_us / 65535);
} else { } else {
// calculate time until enable in µs: (1.0-value)*cycle_time, but with integer arithmetic // calculate time until enable in µs: (1.0-value)*cycle_time, but with integer arithmetic
// also take into account min_power // also take into account min_power
auto min_us = this->cycle_time_us * this->min_power / 1000; auto min_us = this->cycle_time_us * this->min_power / 1000;
this->enable_time_us = max((uint32_t) 1, ((65535 - this->value) * (this->cycle_time_us - min_us)) / 65535); this->enable_time_us = std::max((uint32_t) 1, ((65535 - this->value) * (this->cycle_time_us - min_us)) / 65535);
if (this->method == DIM_METHOD_LEADING_PULSE) { if (this->method == DIM_METHOD_LEADING_PULSE) {
// Minimum pulse time should be enough for the triac to trigger when it is close to the ZC zone // Minimum pulse time should be enough for the triac to trigger when it is close to the ZC zone
// this is for brightness near 99% // this is for brightness near 99%
this->disable_time_us = max(this->enable_time_us + GATE_ENABLE_TIME, (uint32_t) cycle_time_us / 10); this->disable_time_us = std::max(this->enable_time_us + GATE_ENABLE_TIME, (uint32_t) cycle_time_us / 10);
} else { } else {
this->gate_pin->digital_write(false); this->gate_pin.digital_write(false);
this->disable_time_us = this->cycle_time_us; this->disable_time_us = this->cycle_time_us;
} }
} }
} }
} }
void ICACHE_RAM_ATTR HOT AcDimmerDataStore::s_gpio_intr(AcDimmerDataStore *store) { void IRAM_ATTR HOT AcDimmerDataStore::s_gpio_intr(AcDimmerDataStore *store) {
// Attaching pin interrupts on the same pin will override the previous interrupt // Attaching pin interrupts on the same pin will override the previous interrupt
// However, the user expects that multiple dimmers sharing the same ZC pin will work. // However, the user expects that multiple dimmers sharing the same ZC pin will work.
// We solve this in a bit of a hacky way: On each pin interrupt, we check all dimmers // We solve this in a bit of a hacky way: On each pin interrupt, we check all dimmers
@@ -141,11 +147,11 @@ void ICACHE_RAM_ATTR HOT AcDimmerDataStore::s_gpio_intr(AcDimmerDataStore *store
} }
} }
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
// ESP32 implementation, uses basically the same code but needs to wrap // ESP32 implementation, uses basically the same code but needs to wrap
// timer_interrupt() function to auto-reschedule // timer_interrupt() function to auto-reschedule
static hw_timer_t *dimmer_timer = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) static hw_timer_t *dimmer_timer = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
void ICACHE_RAM_ATTR HOT AcDimmerDataStore::s_timer_intr() { timer_interrupt(); } void IRAM_ATTR HOT AcDimmerDataStore::s_timer_intr() { timer_interrupt(); }
#endif #endif
void AcDimmer::setup() { void AcDimmer::setup() {
@@ -174,15 +180,16 @@ void AcDimmer::setup() {
if (setup_zero_cross_pin) { if (setup_zero_cross_pin) {
this->zero_cross_pin_->setup(); this->zero_cross_pin_->setup();
this->store_.zero_cross_pin = this->zero_cross_pin_->to_isr(); this->store_.zero_cross_pin = this->zero_cross_pin_->to_isr();
this->zero_cross_pin_->attach_interrupt(&AcDimmerDataStore::s_gpio_intr, &this->store_, FALLING); this->zero_cross_pin_->attach_interrupt(&AcDimmerDataStore::s_gpio_intr, &this->store_,
gpio::INTERRUPT_FALLING_EDGE);
} }
#ifdef ARDUINO_ARCH_ESP8266 #ifdef USE_ESP8266
// Uses ESP8266 waveform (soft PWM) class // Uses ESP8266 waveform (soft PWM) class
// PWM and AcDimmer can even run at the same time this way // PWM and AcDimmer can even run at the same time this way
setTimer1Callback(&timer_interrupt); setTimer1Callback(&timer_interrupt);
#endif #endif
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
// 80 Divider -> 1 count=1µs // 80 Divider -> 1 count=1µs
dimmer_timer = timerBegin(0, 80, true); dimmer_timer = timerBegin(0, 80, true);
timerAttachInterrupt(dimmer_timer, &AcDimmerDataStore::s_timer_intr, true); timerAttachInterrupt(dimmer_timer, &AcDimmerDataStore::s_timer_intr, true);
@@ -218,3 +225,5 @@ void AcDimmer::dump_config() {
} // namespace ac_dimmer } // namespace ac_dimmer
} // namespace esphome } // namespace esphome
#endif // USE_ARDUINO
+12 -8
View File
@@ -1,7 +1,9 @@
#pragma once #pragma once
#ifdef USE_ARDUINO
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/core/esphal.h" #include "esphome/core/hal.h"
#include "esphome/components/output/float_output.h" #include "esphome/components/output/float_output.h"
namespace esphome { namespace esphome {
@@ -11,11 +13,11 @@ enum DimMethod { DIM_METHOD_LEADING_PULSE = 0, DIM_METHOD_LEADING, DIM_METHOD_TR
struct AcDimmerDataStore { struct AcDimmerDataStore {
/// Zero-cross pin /// Zero-cross pin
ISRInternalGPIOPin *zero_cross_pin; ISRInternalGPIOPin zero_cross_pin;
/// Zero-cross pin number - used to share ZC pin across multiple dimmers /// Zero-cross pin number - used to share ZC pin across multiple dimmers
uint8_t zero_cross_pin_number; uint8_t zero_cross_pin_number;
/// Output pin to write to /// Output pin to write to
ISRInternalGPIOPin *gate_pin; ISRInternalGPIOPin gate_pin;
/// Value of the dimmer - 0 to 65535. /// Value of the dimmer - 0 to 65535.
uint16_t value; uint16_t value;
/// Minimum power for activation /// Minimum power for activation
@@ -37,7 +39,7 @@ struct AcDimmerDataStore {
void gpio_intr(); void gpio_intr();
static void s_gpio_intr(AcDimmerDataStore *store); static void s_gpio_intr(AcDimmerDataStore *store);
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
static void s_timer_intr(); static void s_timer_intr();
#endif #endif
}; };
@@ -47,16 +49,16 @@ class AcDimmer : public output::FloatOutput, public Component {
void setup() override; void setup() override;
void dump_config() override; void dump_config() override;
void set_gate_pin(GPIOPin *gate_pin) { gate_pin_ = gate_pin; } void set_gate_pin(InternalGPIOPin *gate_pin) { gate_pin_ = gate_pin; }
void set_zero_cross_pin(GPIOPin *zero_cross_pin) { zero_cross_pin_ = zero_cross_pin; } void set_zero_cross_pin(InternalGPIOPin *zero_cross_pin) { zero_cross_pin_ = zero_cross_pin; }
void set_init_with_half_cycle(bool init_with_half_cycle) { init_with_half_cycle_ = init_with_half_cycle; } void set_init_with_half_cycle(bool init_with_half_cycle) { init_with_half_cycle_ = init_with_half_cycle; }
void set_method(DimMethod method) { method_ = method; } void set_method(DimMethod method) { method_ = method; }
protected: protected:
void write_state(float state) override; void write_state(float state) override;
GPIOPin *gate_pin_; InternalGPIOPin *gate_pin_;
GPIOPin *zero_cross_pin_; InternalGPIOPin *zero_cross_pin_;
AcDimmerDataStore store_; AcDimmerDataStore store_;
bool init_with_half_cycle_; bool init_with_half_cycle_;
DimMethod method_; DimMethod method_;
@@ -64,3 +66,5 @@ class AcDimmer : public output::FloatOutput, public Component {
} // namespace ac_dimmer } // namespace ac_dimmer
} // namespace esphome } // namespace esphome
#endif // USE_ARDUINO
+14 -11
View File
@@ -19,17 +19,20 @@ DIM_METHODS = {
CONF_GATE_PIN = "gate_pin" CONF_GATE_PIN = "gate_pin"
CONF_ZERO_CROSS_PIN = "zero_cross_pin" CONF_ZERO_CROSS_PIN = "zero_cross_pin"
CONF_INIT_WITH_HALF_CYCLE = "init_with_half_cycle" CONF_INIT_WITH_HALF_CYCLE = "init_with_half_cycle"
CONFIG_SCHEMA = output.FLOAT_OUTPUT_SCHEMA.extend( CONFIG_SCHEMA = cv.All(
{ output.FLOAT_OUTPUT_SCHEMA.extend(
cv.Required(CONF_ID): cv.declare_id(AcDimmer), {
cv.Required(CONF_GATE_PIN): pins.internal_gpio_output_pin_schema, cv.Required(CONF_ID): cv.declare_id(AcDimmer),
cv.Required(CONF_ZERO_CROSS_PIN): pins.internal_gpio_input_pin_schema, cv.Required(CONF_GATE_PIN): pins.internal_gpio_output_pin_schema,
cv.Optional(CONF_INIT_WITH_HALF_CYCLE, default=True): cv.boolean, cv.Required(CONF_ZERO_CROSS_PIN): pins.internal_gpio_input_pin_schema,
cv.Optional(CONF_METHOD, default="leading pulse"): cv.enum( cv.Optional(CONF_INIT_WITH_HALF_CYCLE, default=True): cv.boolean,
DIM_METHODS, upper=True, space="_" cv.Optional(CONF_METHOD, default="leading pulse"): cv.enum(
), DIM_METHODS, upper=True, space="_"
} ),
).extend(cv.COMPONENT_SCHEMA) }
).extend(cv.COMPONENT_SCHEMA),
cv.only_with_arduino,
)
async def to_code(config): async def to_code(config):
+15 -14
View File
@@ -2,6 +2,7 @@
#include "esphome/core/log.h" #include "esphome/core/log.h"
#ifdef USE_ADC_SENSOR_VCC #ifdef USE_ADC_SENSOR_VCC
#include <Esp.h>
ADC_MODE(ADC_VCC) ADC_MODE(ADC_VCC)
#endif #endif
@@ -10,7 +11,7 @@ namespace adc {
static const char *const TAG = "adc"; static const char *const TAG = "adc";
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
void ADCSensor::set_attenuation(adc_atten_t attenuation) { this->attenuation_ = attenuation; } void ADCSensor::set_attenuation(adc_atten_t attenuation) { this->attenuation_ = attenuation; }
inline adc1_channel_t gpio_to_adc1(uint8_t pin) { inline adc1_channel_t gpio_to_adc1(uint8_t pin) {
@@ -57,28 +58,28 @@ inline adc1_channel_t gpio_to_adc1(uint8_t pin) {
void ADCSensor::setup() { void ADCSensor::setup() {
ESP_LOGCONFIG(TAG, "Setting up ADC '%s'...", this->get_name().c_str()); ESP_LOGCONFIG(TAG, "Setting up ADC '%s'...", this->get_name().c_str());
#ifndef USE_ADC_SENSOR_VCC #ifndef USE_ADC_SENSOR_VCC
GPIOPin(this->pin_, INPUT).setup(); pin_->setup();
#endif #endif
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
adc1_config_channel_atten(gpio_to_adc1(pin_), attenuation_); adc1_config_channel_atten(gpio_to_adc1(pin_->get_pin()), attenuation_);
adc1_config_width(ADC_WIDTH_BIT_12); adc1_config_width(ADC_WIDTH_BIT_12);
#if !CONFIG_IDF_TARGET_ESP32C3 && !CONFIG_IDF_TARGET_ESP32H2 #if !CONFIG_IDF_TARGET_ESP32C3 && !CONFIG_IDF_TARGET_ESP32H2
adc_gpio_init(ADC_UNIT_1, (adc_channel_t) gpio_to_adc1(pin_)); adc_gpio_init(ADC_UNIT_1, (adc_channel_t) gpio_to_adc1(pin_->get_pin()));
#endif #endif
#endif #endif
} }
void ADCSensor::dump_config() { void ADCSensor::dump_config() {
LOG_SENSOR("", "ADC Sensor", this); LOG_SENSOR("", "ADC Sensor", this);
#ifdef ARDUINO_ARCH_ESP8266 #ifdef USE_ESP8266
#ifdef USE_ADC_SENSOR_VCC #ifdef USE_ADC_SENSOR_VCC
ESP_LOGCONFIG(TAG, " Pin: VCC"); ESP_LOGCONFIG(TAG, " Pin: VCC");
#else #else
ESP_LOGCONFIG(TAG, " Pin: %u", this->pin_); LOG_PIN(" Pin: ", pin_);
#endif #endif
#endif #endif
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
ESP_LOGCONFIG(TAG, " Pin: %u", this->pin_); LOG_PIN(" Pin: ", pin_);
switch (this->attenuation_) { switch (this->attenuation_) {
case ADC_ATTEN_DB_0: case ADC_ATTEN_DB_0:
ESP_LOGCONFIG(TAG, " Attenuation: 0db (max 1.1V)"); ESP_LOGCONFIG(TAG, " Attenuation: 0db (max 1.1V)");
@@ -105,8 +106,8 @@ void ADCSensor::update() {
this->publish_state(value_v); this->publish_state(value_v);
} }
float ADCSensor::sample() { float ADCSensor::sample() {
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
int raw = adc1_get_raw(gpio_to_adc1(pin_)); int raw = adc1_get_raw(gpio_to_adc1(pin_->get_pin()));
float value_v = raw / 4095.0f; float value_v = raw / 4095.0f;
#if CONFIG_IDF_TARGET_ESP32 #if CONFIG_IDF_TARGET_ESP32
switch (this->attenuation_) { switch (this->attenuation_) {
@@ -146,15 +147,15 @@ float ADCSensor::sample() {
return value_v; return value_v;
#endif #endif
#ifdef ARDUINO_ARCH_ESP8266 #ifdef USE_ESP8266
#ifdef USE_ADC_SENSOR_VCC #ifdef USE_ADC_SENSOR_VCC
return ESP.getVcc() / 1024.0f; // NOLINT(readability-static-accessed-through-instance) return ESP.getVcc() / 1024.0f; // NOLINT(readability-static-accessed-through-instance)
#else #else
return analogRead(this->pin_) / 1024.0f; // NOLINT return analogRead(this->pin_->get_pin()) / 1024.0f; // NOLINT
#endif #endif
#endif #endif
} }
#ifdef ARDUINO_ARCH_ESP8266 #ifdef USE_ESP8266
std::string ADCSensor::unique_id() { return get_mac_address() + "-adc"; } std::string ADCSensor::unique_id() { return get_mac_address() + "-adc"; }
#endif #endif
+7 -7
View File
@@ -1,12 +1,12 @@
#pragma once #pragma once
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/core/esphal.h" #include "esphome/core/hal.h"
#include "esphome/core/defines.h" #include "esphome/core/defines.h"
#include "esphome/components/sensor/sensor.h" #include "esphome/components/sensor/sensor.h"
#include "esphome/components/voltage_sampler/voltage_sampler.h" #include "esphome/components/voltage_sampler/voltage_sampler.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
#include "driver/adc.h" #include "driver/adc.h"
#endif #endif
@@ -15,7 +15,7 @@ namespace adc {
class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage_sampler::VoltageSampler { class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage_sampler::VoltageSampler {
public: public:
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
/// Set the attenuation for this pin. Only available on the ESP32. /// Set the attenuation for this pin. Only available on the ESP32.
void set_attenuation(adc_atten_t attenuation); void set_attenuation(adc_atten_t attenuation);
#endif #endif
@@ -27,17 +27,17 @@ class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage
void dump_config() override; void dump_config() override;
/// `HARDWARE_LATE` setup priority. /// `HARDWARE_LATE` setup priority.
float get_setup_priority() const override; float get_setup_priority() const override;
void set_pin(uint8_t pin) { this->pin_ = pin; } void set_pin(InternalGPIOPin *pin) { this->pin_ = pin; }
float sample() override; float sample() override;
#ifdef ARDUINO_ARCH_ESP8266 #ifdef USE_ESP8266
std::string unique_id() override; std::string unique_id() override;
#endif #endif
protected: protected:
uint8_t pin_; InternalGPIOPin *pin_;
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
adc_atten_t attenuation_{ADC_ATTEN_DB_0}; adc_atten_t attenuation_{ADC_ATTEN_DB_0};
#endif #endif
}; };
+32 -5
View File
@@ -5,11 +5,13 @@ from esphome.components import sensor, voltage_sampler
from esphome.const import ( from esphome.const import (
CONF_ATTENUATION, CONF_ATTENUATION,
CONF_ID, CONF_ID,
CONF_INPUT,
CONF_PIN, CONF_PIN,
DEVICE_CLASS_VOLTAGE, DEVICE_CLASS_VOLTAGE,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_VOLT, UNIT_VOLT,
) )
from esphome.core import CORE
AUTO_LOAD = ["voltage_sampler"] AUTO_LOAD = ["voltage_sampler"]
@@ -23,10 +25,34 @@ ATTENUATION_MODES = {
def validate_adc_pin(value): def validate_adc_pin(value):
vcc = str(value).upper() if str(value).upper() == "VCC":
if vcc == "VCC": return cv.only_on_esp8266("VCC")
return cv.only_on_esp8266(vcc)
return pins.analog_pin(value) if CORE.is_esp32:
from esphome.components.esp32 import is_esp32c3
value = pins.internal_gpio_input_pin_number(value)
if is_esp32c3():
if not (0 <= value <= 4): # ADC1
raise cv.Invalid("ESP32-C3: Only pins 0 though 4 support ADC.")
if not (32 <= value <= 39): # ADC1
raise cv.Invalid("ESP32: Only pins 32 though 39 support ADC.")
elif CORE.is_esp8266:
from esphome.components.esp8266.gpio import CONF_ANALOG
value = pins.internal_gpio_pin_number({CONF_ANALOG: True, CONF_INPUT: True})(
value
)
if value != 17: # A0
raise cv.Invalid("ESP8266: Only pin A0 (GPIO17) supports ADC.")
return pins.gpio_pin_schema(
{CONF_ANALOG: True, CONF_INPUT: True}, internal=True
)(value)
else:
raise NotImplementedError
return pins.internal_gpio_input_pin_schema(value)
adc_ns = cg.esphome_ns.namespace("adc") adc_ns = cg.esphome_ns.namespace("adc")
@@ -62,7 +88,8 @@ async def to_code(config):
if config[CONF_PIN] == "VCC": if config[CONF_PIN] == "VCC":
cg.add_define("USE_ADC_SENSOR_VCC") cg.add_define("USE_ADC_SENSOR_VCC")
else: else:
cg.add(var.set_pin(config[CONF_PIN])) pin = await cg.gpio_pin_expression(config[CONF_PIN])
cg.add(var.set_pin(pin))
if CONF_ATTENUATION in config: if CONF_ATTENUATION in config:
cg.add(var.set_attenuation(config[CONF_ATTENUATION])) cg.add(var.set_attenuation(config[CONF_ATTENUATION]))
+16 -17
View File
@@ -8,9 +8,7 @@ static const char *const TAG = "ade7953";
void ADE7953::dump_config() { void ADE7953::dump_config() {
ESP_LOGCONFIG(TAG, "ADE7953:"); ESP_LOGCONFIG(TAG, "ADE7953:");
if (this->has_irq_) { LOG_PIN(" IRQ Pin: ", irq_pin_);
ESP_LOGCONFIG(TAG, " IRQ Pin: GPIO%u", this->irq_pin_number_);
}
LOG_I2C_DEVICE(this); LOG_I2C_DEVICE(this);
LOG_UPDATE_INTERVAL(this); LOG_UPDATE_INTERVAL(this);
LOG_SENSOR(" ", "Voltage Sensor", this->voltage_sensor_); LOG_SENSOR(" ", "Voltage Sensor", this->voltage_sensor_);
@@ -20,27 +18,28 @@ void ADE7953::dump_config() {
LOG_SENSOR(" ", "Active Power B Sensor", this->active_power_b_sensor_); LOG_SENSOR(" ", "Active Power B Sensor", this->active_power_b_sensor_);
} }
#define ADE_PUBLISH_(name, factor) \ #define ADE_PUBLISH_(name, val, factor) \
if ((name) && this->name##_sensor_) { \ if (err == i2c::ERROR_OK && this->name##_sensor_) { \
float value = *(name) / (factor); \ float value = (val) / (factor); \
this->name##_sensor_->publish_state(value); \ this->name##_sensor_->publish_state(value); \
} }
#define ADE_PUBLISH(name, factor) ADE_PUBLISH_(name, factor) #define ADE_PUBLISH(name, val, factor) ADE_PUBLISH_(name, val, factor)
void ADE7953::update() { void ADE7953::update() {
if (!this->is_setup_) if (!this->is_setup_)
return; return;
auto active_power_a = this->ade_read_<int32_t>(0x0312); uint32_t val;
ADE_PUBLISH(active_power_a, 154.0f); i2c::ErrorCode err = ade_read_32_(0x0312, &val);
auto active_power_b = this->ade_read_<int32_t>(0x0313); ADE_PUBLISH(active_power_a, (int32_t) val, 154.0f);
ADE_PUBLISH(active_power_b, 154.0f); err = ade_read_32_(0x0313, &val);
auto current_a = this->ade_read_<uint32_t>(0x031A); ADE_PUBLISH(active_power_b, (int32_t) val, 154.0f);
ADE_PUBLISH(current_a, 100000.0f); err = ade_read_32_(0x031A, &val);
auto current_b = this->ade_read_<uint32_t>(0x031B); ADE_PUBLISH(current_a, (uint32_t) val, 100000.0f);
ADE_PUBLISH(current_b, 100000.0f); err = ade_read_32_(0x031B, &val);
auto voltage = this->ade_read_<uint32_t>(0x031C); ADE_PUBLISH(current_b, (uint32_t) val, 100000.0f);
ADE_PUBLISH(voltage, 26000.0f); err = ade_read_32_(0x031C, &val);
ADE_PUBLISH(voltage, (uint32_t) val, 26000.0f);
// auto apparent_power_a = this->ade_read_<int32_t>(0x0310); // auto apparent_power_a = this->ade_read_<int32_t>(0x0310);
// auto apparent_power_b = this->ade_read_<int32_t>(0x0311); // auto apparent_power_b = this->ade_read_<int32_t>(0x0311);
+45 -30
View File
@@ -1,7 +1,7 @@
#pragma once #pragma once
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/core/esphal.h" #include "esphome/core/hal.h"
#include "esphome/components/i2c/i2c.h" #include "esphome/components/i2c/i2c.h"
#include "esphome/components/sensor/sensor.h" #include "esphome/components/sensor/sensor.h"
@@ -10,10 +10,7 @@ namespace ade7953 {
class ADE7953 : public i2c::I2CDevice, public PollingComponent { class ADE7953 : public i2c::I2CDevice, public PollingComponent {
public: public:
void set_irq_pin(uint8_t irq_pin) { void set_irq_pin(InternalGPIOPin *irq_pin) { irq_pin_ = irq_pin; }
has_irq_ = true;
irq_pin_number_ = irq_pin;
}
void set_voltage_sensor(sensor::Sensor *voltage_sensor) { voltage_sensor_ = voltage_sensor; } void set_voltage_sensor(sensor::Sensor *voltage_sensor) { voltage_sensor_ = voltage_sensor; }
void set_current_a_sensor(sensor::Sensor *current_a_sensor) { current_a_sensor_ = current_a_sensor; } void set_current_a_sensor(sensor::Sensor *current_a_sensor) { current_a_sensor_ = current_a_sensor; }
void set_current_b_sensor(sensor::Sensor *current_b_sensor) { current_b_sensor_ = current_b_sensor; } void set_current_b_sensor(sensor::Sensor *current_b_sensor) { current_b_sensor_ = current_b_sensor; }
@@ -25,15 +22,13 @@ class ADE7953 : public i2c::I2CDevice, public PollingComponent {
} }
void setup() override { void setup() override {
if (this->has_irq_) { if (this->irq_pin_ != nullptr) {
auto pin = GPIOPin(this->irq_pin_number_, INPUT);
this->irq_pin_ = &pin;
this->irq_pin_->setup(); this->irq_pin_->setup();
} }
this->set_timeout(100, [this]() { this->set_timeout(100, [this]() {
this->ade_write_<uint8_t>(0x0010, 0x04); this->ade_write_8_(0x0010, 0x04);
this->ade_write_<uint8_t>(0x00FE, 0xAD); this->ade_write_8_(0x00FE, 0xAD);
this->ade_write_<uint16_t>(0x0120, 0x0030); this->ade_write_16_(0x0120, 0x0030);
this->is_setup_ = true; this->is_setup_ = true;
}); });
} }
@@ -43,31 +38,51 @@ class ADE7953 : public i2c::I2CDevice, public PollingComponent {
void update() override; void update() override;
protected: protected:
template<typename T> bool ade_write_(uint16_t reg, T value) { i2c::ErrorCode ade_write_8_(uint16_t reg, uint8_t value) {
std::vector<uint8_t> data; std::vector<uint8_t> data;
data.push_back(reg >> 8); data.push_back(reg >> 8);
data.push_back(reg >> 0); data.push_back(reg >> 0);
for (int i = sizeof(T) - 1; i >= 0; i--) data.push_back(value);
data.push_back(value >> (i * 8)); return write(data.data(), data.size());
return this->write_bytes_raw(data);
} }
template<typename T> optional<T> ade_read_(uint16_t reg) { i2c::ErrorCode ade_write_16_(uint16_t reg, uint16_t value) {
uint8_t hi = reg >> 8; std::vector<uint8_t> data;
uint8_t lo = reg >> 0; data.push_back(reg >> 8);
if (!this->write_bytes_raw({hi, lo})) data.push_back(reg >> 0);
return {}; data.push_back(value >> 8);
auto ret = this->read_bytes_raw<sizeof(T)>(); data.push_back(value >> 0);
if (!ret.has_value()) return write(data.data(), data.size());
return {}; }
T result = 0; i2c::ErrorCode ade_write_32_(uint16_t reg, uint32_t value) {
for (int i = 0, j = sizeof(T) - 1; i < sizeof(T); i++, j--) std::vector<uint8_t> data;
result |= T((*ret)[i]) << (j * 8); data.push_back(reg >> 8);
return result; data.push_back(reg >> 0);
data.push_back(value >> 24);
data.push_back(value >> 16);
data.push_back(value >> 8);
data.push_back(value >> 0);
return write(data.data(), data.size());
}
i2c::ErrorCode ade_read_32_(uint16_t reg, uint32_t *value) {
uint8_t reg_data[2];
reg_data[0] = reg >> 8;
reg_data[1] = reg >> 0;
i2c::ErrorCode err = write(reg_data, 2);
if (err != i2c::ERROR_OK)
return err;
uint8_t recv[4];
err = read(recv, 4);
if (err != i2c::ERROR_OK)
return err;
*value = 0;
*value |= ((uint32_t) recv[0]) << 24;
*value |= ((uint32_t) recv[1]) << 24;
*value |= ((uint32_t) recv[2]) << 24;
*value |= ((uint32_t) recv[3]) << 24;
return i2c::ERROR_OK;
} }
bool has_irq_ = false; InternalGPIOPin *irq_pin_ = nullptr;
uint8_t irq_pin_number_;
GPIOPin *irq_pin_{nullptr};
bool is_setup_{false}; bool is_setup_{false};
sensor::Sensor *voltage_sensor_{nullptr}; sensor::Sensor *voltage_sensor_{nullptr};
sensor::Sensor *current_a_sensor_{nullptr}; sensor::Sensor *current_a_sensor_{nullptr};
+3 -2
View File
@@ -29,7 +29,7 @@ CONFIG_SCHEMA = (
cv.Schema( cv.Schema(
{ {
cv.GenerateID(): cv.declare_id(ADE7953), cv.GenerateID(): cv.declare_id(ADE7953),
cv.Optional(CONF_IRQ_PIN): pins.input_pin, cv.Optional(CONF_IRQ_PIN): pins.internal_gpio_input_pin_schema,
cv.Optional(CONF_VOLTAGE): sensor.sensor_schema( cv.Optional(CONF_VOLTAGE): sensor.sensor_schema(
unit_of_measurement=UNIT_VOLT, unit_of_measurement=UNIT_VOLT,
accuracy_decimals=1, accuracy_decimals=1,
@@ -73,7 +73,8 @@ async def to_code(config):
await i2c.register_i2c_device(var, config) await i2c.register_i2c_device(var, config)
if CONF_IRQ_PIN in config: if CONF_IRQ_PIN in config:
cg.add(var.set_irq_pin(config[CONF_IRQ_PIN])) irq_pin = await cg.gpio_pin_expression(config[CONF_IRQ_PIN])
cg.add(var.set_irq_pin(irq_pin))
for key in [ for key in [
CONF_VOLTAGE, CONF_VOLTAGE,
+2 -1
View File
@@ -1,5 +1,6 @@
#include "ads1115.h" #include "ads1115.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/hal.h"
namespace esphome { namespace esphome {
namespace ads1115 { namespace ads1115 {
@@ -159,7 +160,7 @@ float ADS1115Component::request_measurement(ADS1115Sensor *sensor) {
float ADS1115Sensor::sample() { return this->parent_->request_measurement(this); } float ADS1115Sensor::sample() { return this->parent_->request_measurement(this); }
void ADS1115Sensor::update() { void ADS1115Sensor::update() {
float v = this->parent_->request_measurement(this); float v = this->parent_->request_measurement(this);
if (!isnan(v)) { if (!std::isnan(v)) {
ESP_LOGD(TAG, "'%s': Got Voltage=%fV", this->get_name().c_str(), v); ESP_LOGD(TAG, "'%s': Got Voltage=%fV", this->get_name().c_str(), v);
this->publish_state(v); this->publish_state(v);
} }
+34 -10
View File
@@ -14,6 +14,7 @@
#include "aht10.h" #include "aht10.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/hal.h"
namespace esphome { namespace esphome {
namespace aht10 { namespace aht10 {
@@ -33,8 +34,19 @@ void AHT10Component::setup() {
this->mark_failed(); this->mark_failed();
return; return;
} }
uint8_t data; uint8_t data = 0;
if (!this->read_byte(0, &data, AHT10_DEFAULT_DELAY)) { if (this->write(&data, 1) != i2c::ERROR_OK) {
ESP_LOGD(TAG, "Communication with AHT10 failed!");
this->mark_failed();
return;
}
delay(AHT10_DEFAULT_DELAY);
if (this->read(&data, 1) != i2c::ERROR_OK) {
ESP_LOGD(TAG, "Communication with AHT10 failed!");
this->mark_failed();
return;
}
if (this->read(&data, 1) != i2c::ERROR_OK) {
ESP_LOGD(TAG, "Communication with AHT10 failed!"); ESP_LOGD(TAG, "Communication with AHT10 failed!");
this->mark_failed(); this->mark_failed();
return; return;
@@ -55,15 +67,26 @@ void AHT10Component::update() {
return; return;
} }
uint8_t data[6]; uint8_t data[6];
uint8_t delay = AHT10_DEFAULT_DELAY; uint8_t delay_ms = AHT10_DEFAULT_DELAY;
if (this->humidity_sensor_ != nullptr) if (this->humidity_sensor_ != nullptr)
delay = AHT10_HUMIDITY_DELAY; delay_ms = AHT10_HUMIDITY_DELAY;
bool success = false;
for (int i = 0; i < AHT10_ATTEMPTS; ++i) { for (int i = 0; i < AHT10_ATTEMPTS; ++i) {
ESP_LOGVV(TAG, "Attempt %u at %6ld", i, millis()); ESP_LOGVV(TAG, "Attempt %d at %6u", i, millis());
delay_microseconds_accurate(4); delay_microseconds_accurate(4);
if (!this->read_bytes(0, data, 6, delay)) {
uint8_t reg = 0;
if (this->write(&reg, 1) != i2c::ERROR_OK) {
ESP_LOGD(TAG, "Communication with AHT10 failed, waiting..."); ESP_LOGD(TAG, "Communication with AHT10 failed, waiting...");
} else if ((data[0] & 0x80) == 0x80) { // Bit[7] = 0b1, device is busy continue;
}
delay(delay_ms);
if (this->read(data, 6) != i2c::ERROR_OK) {
ESP_LOGD(TAG, "Communication with AHT10 failed, waiting...");
continue;
}
if ((data[0] & 0x80) == 0x80) { // Bit[7] = 0b1, device is busy
ESP_LOGD(TAG, "AHT10 is busy, waiting..."); ESP_LOGD(TAG, "AHT10 is busy, waiting...");
} else if (data[1] == 0x0 && data[2] == 0x0 && (data[3] >> 4) == 0x0) { } else if (data[1] == 0x0 && data[2] == 0x0 && (data[3] >> 4) == 0x0) {
// Unrealistic humidity (0x0) // Unrealistic humidity (0x0)
@@ -80,11 +103,12 @@ void AHT10Component::update() {
} }
} else { } else {
// data is valid, we can break the loop // data is valid, we can break the loop
ESP_LOGVV(TAG, "Answer at %6ld", millis()); ESP_LOGVV(TAG, "Answer at %6u", millis());
success = true;
break; break;
} }
} }
if ((data[0] & 0x80) == 0x80) { if (!success || (data[0] & 0x80) == 0x80) {
ESP_LOGE(TAG, "Measurements reading timed-out!"); ESP_LOGE(TAG, "Measurements reading timed-out!");
this->status_set_warning(); this->status_set_warning();
return; return;
@@ -105,7 +129,7 @@ void AHT10Component::update() {
this->temperature_sensor_->publish_state(temperature); this->temperature_sensor_->publish_state(temperature);
} }
if (this->humidity_sensor_ != nullptr) { if (this->humidity_sensor_ != nullptr) {
if (isnan(humidity)) if (std::isnan(humidity))
ESP_LOGW(TAG, "Invalid humidity! Sensor reported 0%% Hum"); ESP_LOGW(TAG, "Invalid humidity! Sensor reported 0%% Hum");
this->humidity_sensor_->publish_state(humidity); this->humidity_sensor_->publish_state(humidity);
} }
@@ -1,7 +1,7 @@
#include "airthings_listener.h" #include "airthings_listener.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
namespace esphome { namespace esphome {
namespace airthings_ble { namespace airthings_ble {
@@ -1,10 +1,9 @@
#pragma once #pragma once
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h" #include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
#include <BLEDevice.h>
namespace esphome { namespace esphome {
namespace airthings_ble { namespace airthings_ble {
@@ -1,6 +1,6 @@
#include "airthings_wave_plus.h" #include "airthings_wave_plus.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32_FRAMEWORK_ARDUINO
namespace esphome { namespace esphome {
namespace airthings_wave_plus { namespace airthings_wave_plus {
@@ -141,4 +141,4 @@ void AirthingsWavePlus::setup() {}
} // namespace airthings_wave_plus } // namespace airthings_wave_plus
} // namespace esphome } // namespace esphome
#endif // ARDUINO_ARCH_ESP32 #endif // USE_ESP32_FRAMEWORK_ARDUINO
@@ -1,6 +1,6 @@
#pragma once #pragma once
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32_FRAMEWORK_ARDUINO
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
@@ -72,4 +72,4 @@ class AirthingsWavePlus : public PollingComponent, public ble_client::BLEClientN
} // namespace airthings_wave_plus } // namespace airthings_wave_plus
} // namespace esphome } // namespace esphome
#endif // ARDUINO_ARCH_ESP32 #endif // USE_ESP32_FRAMEWORK_ARDUINO
@@ -34,7 +34,7 @@ AirthingsWavePlus = airthings_wave_plus_ns.class_(
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = cv.All(
cv.Schema( cv.Schema(
{ {
cv.GenerateID(): cv.declare_id(AirthingsWavePlus), cv.GenerateID(): cv.declare_id(AirthingsWavePlus),
@@ -83,7 +83,9 @@ CONFIG_SCHEMA = (
} }
) )
.extend(cv.polling_component_schema("5mins")) .extend(cv.polling_component_schema("5mins"))
.extend(ble_client.BLE_CLIENT_SCHEMA) .extend(ble_client.BLE_CLIENT_SCHEMA),
# Until BLEUUID reference removed
cv.only_with_arduino,
) )
+2 -1
View File
@@ -5,6 +5,7 @@
#include "am2320.h" #include "am2320.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/hal.h"
namespace esphome { namespace esphome {
namespace am2320 { namespace am2320 {
@@ -77,7 +78,7 @@ bool AM2320Component::read_bytes_(uint8_t a_register, uint8_t *data, uint8_t len
if (conversion > 0) if (conversion > 0)
delay(conversion); delay(conversion);
return this->parent_->raw_receive(this->address_, data, len); return this->read(data, len) == i2c::ERROR_OK;
} }
bool AM2320Component::read_data_(uint8_t *data) { bool AM2320Component::read_data_(uint8_t *data) {
+2 -1
View File
@@ -1,7 +1,8 @@
#include "am43.h" #include "am43.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/hal.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
namespace esphome { namespace esphome {
namespace am43 { namespace am43 {
+1 -1
View File
@@ -6,7 +6,7 @@
#include "esphome/components/sensor/sensor.h" #include "esphome/components/sensor/sensor.h"
#include "esphome/components/am43/am43_base.h" #include "esphome/components/am43/am43_base.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
#include <esp_gattc_api.h> #include <esp_gattc_api.h>
+1 -1
View File
@@ -1,7 +1,7 @@
#include "am43_cover.h" #include "am43_cover.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
namespace esphome { namespace esphome {
namespace am43 { namespace am43 {
+1 -1
View File
@@ -6,7 +6,7 @@
#include "esphome/components/cover/cover.h" #include "esphome/components/cover/cover.h"
#include "esphome/components/am43/am43_base.h" #include "esphome/components/am43/am43_base.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
#include <esp_gattc_api.h> #include <esp_gattc_api.h>
+1 -1
View File
@@ -1,7 +1,7 @@
#include "anova.h" #include "anova.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
namespace esphome { namespace esphome {
namespace anova { namespace anova {
+1 -1
View File
@@ -6,7 +6,7 @@
#include "esphome/components/climate/climate.h" #include "esphome/components/climate/climate.h"
#include "anova_base.h" #include "anova_base.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
#include <esp_gattc_api.h> #include <esp_gattc_api.h>
+1
View File
@@ -1,5 +1,6 @@
#include "apds9960.h" #include "apds9960.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/hal.h"
namespace esphome { namespace esphome {
namespace apds9960 { namespace apds9960 {
+3 -2
View File
@@ -1,7 +1,8 @@
#include "api_connection.h" #include "api_connection.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/util.h" #include "esphome/components/network/util.h"
#include "esphome/core/version.h" #include "esphome/core/version.h"
#include "esphome/core/hal.h"
#include <cerrno> #include <cerrno>
#ifdef USE_DEEP_SLEEP #ifdef USE_DEEP_SLEEP
@@ -48,7 +49,7 @@ void APIConnection::loop() {
if (this->remove_) if (this->remove_)
return; return;
if (!network_is_connected()) { if (!network::is_connected()) {
// when network is disconnected force disconnect immediately // when network is disconnected force disconnect immediately
// don't wait for timeout // don't wait for timeout
this->on_fatal_error(); this->on_fatal_error();
@@ -3,6 +3,7 @@
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/helpers.h" #include "esphome/core/helpers.h"
#include "proto.h" #include "proto.h"
#include <cstring>
namespace esphome { namespace esphome {
namespace api { namespace api {
+1
View File
@@ -2,6 +2,7 @@
// See scripts/api_protobuf/api_protobuf.py // See scripts/api_protobuf/api_protobuf.py
#include "api_pb2.h" #include "api_pb2.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include <cstdio>
namespace esphome { namespace esphome {
namespace api { namespace api {
+3 -1
View File
@@ -5,6 +5,8 @@
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/util.h" #include "esphome/core/util.h"
#include "esphome/core/version.h" #include "esphome/core/version.h"
#include "esphome/core/hal.h"
#include "esphome/components/network/util.h"
#include <cerrno> #include <cerrno>
#ifdef USE_LOGGER #ifdef USE_LOGGER
@@ -130,7 +132,7 @@ void APIServer::loop() {
} }
void APIServer::dump_config() { void APIServer::dump_config() {
ESP_LOGCONFIG(TAG, "API Server:"); ESP_LOGCONFIG(TAG, "API Server:");
ESP_LOGCONFIG(TAG, " Address: %s:%u", network_get_address().c_str(), this->port_); ESP_LOGCONFIG(TAG, " Address: %s:%u", network::get_use_address().c_str(), this->port_);
} }
bool APIServer::uses_password() const { return !this->password_.empty(); } bool APIServer::uses_password() const { return !this->password_.empty(); }
bool APIServer::check_password(const std::string &password) const { bool APIServer::check_password(const std::string &password) const {
+1
View File
@@ -246,6 +246,7 @@ class ProtoWriteBuffer {
class ProtoMessage { class ProtoMessage {
public: public:
virtual ~ProtoMessage() = default;
virtual void encode(ProtoWriteBuffer buffer) const = 0; virtual void encode(ProtoWriteBuffer buffer) const = 0;
void decode(const uint8_t *buffer, size_t length); void decode(const uint8_t *buffer, size_t length);
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
+1 -1
View File
@@ -1,7 +1,7 @@
#pragma once #pragma once
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/core/esphal.h" #include "esphome/core/hal.h"
#include "esphome/components/sensor/sensor.h" #include "esphome/components/sensor/sensor.h"
#include "esphome/components/binary_sensor/binary_sensor.h" #include "esphome/components/binary_sensor/binary_sensor.h"
+6 -2
View File
@@ -25,8 +25,12 @@ void I2CAS3935Component::write_register(uint8_t reg, uint8_t mask, uint8_t bits,
uint8_t I2CAS3935Component::read_register(uint8_t reg) { uint8_t I2CAS3935Component::read_register(uint8_t reg) {
uint8_t value; uint8_t value;
if (!this->read_byte(reg, &value, 2)) { if (write(&reg, 1) != i2c::ERROR_OK) {
ESP_LOGW(TAG, "Read failed!"); ESP_LOGW(TAG, "Writing register failed!");
return 0;
}
if (read(&value, 1) != i2c::ERROR_OK) {
ESP_LOGW(TAG, "Reading register failed!");
return 0; return 0;
} }
return value; return value;
+6
View File
@@ -1,9 +1,15 @@
# Dummy integration to allow relying on AsyncTCP # Dummy integration to allow relying on AsyncTCP
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.core import CORE, coroutine_with_priority from esphome.core import CORE, coroutine_with_priority
CODEOWNERS = ["@OttoWinter"] CODEOWNERS = ["@OttoWinter"]
CONFIG_SCHEMA = cv.All(
cv.Schema({}),
cv.only_with_arduino,
)
@coroutine_with_priority(200.0) @coroutine_with_priority(200.0)
async def to_code(config): async def to_code(config):
@@ -1,7 +1,7 @@
#include "atc_mithermometer.h" #include "atc_mithermometer.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
namespace esphome { namespace esphome {
namespace atc_mithermometer { namespace atc_mithermometer {
@@ -4,7 +4,7 @@
#include "esphome/components/sensor/sensor.h" #include "esphome/components/sensor/sensor.h"
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h" #include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
namespace esphome { namespace esphome {
namespace atc_mithermometer { namespace atc_mithermometer {
+2 -2
View File
@@ -1,7 +1,7 @@
#include "b_parasite.h" #include "b_parasite.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
namespace esphome { namespace esphome {
namespace b_parasite { namespace b_parasite {
@@ -79,4 +79,4 @@ bool BParasite::parse_device(const esp32_ble_tracker::ESPBTDevice &device) {
} // namespace b_parasite } // namespace b_parasite
} // namespace esphome } // namespace esphome
#endif // ARDUINO_ARCH_ESP32 #endif // USE_ESP32
+2 -2
View File
@@ -4,7 +4,7 @@
#include "esphome/components/sensor/sensor.h" #include "esphome/components/sensor/sensor.h"
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h" #include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
namespace esphome { namespace esphome {
namespace b_parasite { namespace b_parasite {
@@ -37,4 +37,4 @@ class BParasite : public Component, public esp32_ble_tracker::ESPBTDeviceListene
} // namespace b_parasite } // namespace b_parasite
} // namespace esphome } // namespace esphome
#endif // ARDUINO_ARCH_ESP32 #endif // USE_ESP32
@@ -69,7 +69,8 @@ void BangBangClimate::compute_state_() {
this->switch_to_action_(climate::CLIMATE_ACTION_OFF); this->switch_to_action_(climate::CLIMATE_ACTION_OFF);
return; return;
} }
if (isnan(this->current_temperature) || isnan(this->target_temperature_low) || isnan(this->target_temperature_high)) { if (std::isnan(this->current_temperature) || std::isnan(this->target_temperature_low) ||
std::isnan(this->target_temperature_high)) {
// if any control parameters are nan, go to OFF action (not IDLE!) // if any control parameters are nan, go to OFF action (not IDLE!)
this->switch_to_action_(climate::CLIMATE_ACTION_OFF); this->switch_to_action_(climate::CLIMATE_ACTION_OFF);
return; return;
+2 -1
View File
@@ -71,10 +71,11 @@ void BH1750Sensor::update() {
float BH1750Sensor::get_setup_priority() const { return setup_priority::DATA; } float BH1750Sensor::get_setup_priority() const { return setup_priority::DATA; }
void BH1750Sensor::read_data_() { void BH1750Sensor::read_data_() {
uint16_t raw_value; uint16_t raw_value;
if (!this->parent_->raw_receive_16(this->address_, &raw_value, 1)) { if (!this->read(reinterpret_cast<uint8_t *>(&raw_value), 2)) {
this->status_set_warning(); this->status_set_warning();
return; return;
} }
raw_value = i2c::i2ctohs(raw_value);
float lx = float(raw_value) / 1.2f; float lx = float(raw_value) / 1.2f;
lx *= 69.0f / this->measurement_duration_; lx *= 69.0f / this->measurement_duration_;
@@ -4,6 +4,7 @@
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/core/automation.h" #include "esphome/core/automation.h"
#include "esphome/core/hal.h"
#include "esphome/components/binary_sensor/binary_sensor.h" #include "esphome/components/binary_sensor/binary_sensor.h"
namespace esphome { namespace esphome {
+1 -1
View File
@@ -3,7 +3,7 @@
#include "esphome/core/automation.h" #include "esphome/core/automation.h"
#include "esphome/components/ble_client/ble_client.h" #include "esphome/components/ble_client/ble_client.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
namespace esphome { namespace esphome {
namespace ble_client { namespace ble_client {
+1 -1
View File
@@ -4,7 +4,7 @@
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h" #include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
#include "ble_client.h" #include "ble_client.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
namespace esphome { namespace esphome {
namespace ble_client { namespace ble_client {
+1 -1
View File
@@ -4,7 +4,7 @@
#include "esphome/core/helpers.h" #include "esphome/core/helpers.h"
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h" #include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
#include <string> #include <string>
#include <array> #include <array>
@@ -3,7 +3,7 @@
#include "esphome/core/automation.h" #include "esphome/core/automation.h"
#include "esphome/components/ble_client/sensor/ble_sensor.h" #include "esphome/components/ble_client/sensor/ble_sensor.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
namespace esphome { namespace esphome {
namespace ble_client { namespace ble_client {
@@ -4,7 +4,7 @@
#include "esphome/core/helpers.h" #include "esphome/core/helpers.h"
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h" #include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
#ifdef ARDUINO_ARCH_ESP32 #ifdef USE_ESP32
namespace esphome { namespace esphome {
namespace ble_client { namespace ble_client {

Some files were not shown because too many files have changed in this diff Show More