1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-25 21:23:53 +01:00

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

View File

@@ -82,12 +82,12 @@ static const uint16_t DRAM_ATTR STATE_LOOKUP_TABLE[32] = {
STATE_CW | STATE_S3 // 0x1F: stay here
};
void ICACHE_RAM_ATTR HOT RotaryEncoderSensorStore::gpio_intr(RotaryEncoderSensorStore *arg) {
void IRAM_ATTR HOT RotaryEncoderSensorStore::gpio_intr(RotaryEncoderSensorStore *arg) {
// Forget upper bits and add pin states
uint8_t input_state = arg->state & STATE_LUT_MASK;
if (arg->pin_a->digital_read())
if (arg->pin_a.digital_read())
input_state |= STATE_PIN_A_HIGH;
if (arg->pin_b->digital_read())
if (arg->pin_b.digital_read())
input_state |= STATE_PIN_B_HIGH;
int8_t rotation_dir = 0;
@@ -134,8 +134,8 @@ void RotaryEncoderSensor::setup() {
this->pin_i_->setup();
}
this->pin_a_->attach_interrupt(RotaryEncoderSensorStore::gpio_intr, &this->store_, CHANGE);
this->pin_b_->attach_interrupt(RotaryEncoderSensorStore::gpio_intr, &this->store_, CHANGE);
this->pin_a_->attach_interrupt(RotaryEncoderSensorStore::gpio_intr, &this->store_, gpio::INTERRUPT_ANY_EDGE);
this->pin_b_->attach_interrupt(RotaryEncoderSensorStore::gpio_intr, &this->store_, gpio::INTERRUPT_ANY_EDGE);
}
void RotaryEncoderSensor::dump_config() {
LOG_SENSOR("", "Rotary Encoder", this);
@@ -157,13 +157,14 @@ void RotaryEncoderSensor::dump_config() {
void RotaryEncoderSensor::loop() {
std::array<int8_t, 8> rotation_events;
bool rotation_events_overflow;
ets_intr_lock();
rotation_events = this->store_.rotation_events;
rotation_events_overflow = this->store_.rotation_events_overflow;
{
InterruptLock lock;
rotation_events = this->store_.rotation_events;
rotation_events_overflow = this->store_.rotation_events_overflow;
this->store_.rotation_events.fill(0);
this->store_.rotation_events_overflow = false;
ets_intr_unlock();
this->store_.rotation_events.fill(0);
this->store_.rotation_events_overflow = false;
}
if (rotation_events_overflow) {
ESP_LOGW(TAG, "Captured more rotation events than expected");

View File

@@ -3,7 +3,7 @@
#include <array>
#include "esphome/core/component.h"
#include "esphome/core/esphal.h"
#include "esphome/core/hal.h"
#include "esphome/core/automation.h"
#include "esphome/components/sensor/sensor.h"
@@ -19,8 +19,8 @@ enum RotaryEncoderResolution {
};
struct RotaryEncoderSensorStore {
ISRInternalGPIOPin *pin_a;
ISRInternalGPIOPin *pin_b;
ISRInternalGPIOPin pin_a;
ISRInternalGPIOPin pin_b;
volatile int32_t counter{0};
RotaryEncoderResolution resolution{ROTARY_ENCODER_1_PULSE_PER_CYCLE};
@@ -37,8 +37,8 @@ struct RotaryEncoderSensorStore {
class RotaryEncoderSensor : public sensor::Sensor, public Component {
public:
void set_pin_a(GPIOPin *pin_a) { pin_a_ = pin_a; }
void set_pin_b(GPIOPin *pin_b) { pin_b_ = pin_b; }
void set_pin_a(InternalGPIOPin *pin_a) { pin_a_ = pin_a; }
void set_pin_b(InternalGPIOPin *pin_b) { pin_b_ = pin_b; }
/** Set the resolution of the rotary encoder.
*
@@ -76,8 +76,8 @@ class RotaryEncoderSensor : public sensor::Sensor, public Component {
}
protected:
GPIOPin *pin_a_;
GPIOPin *pin_b_;
InternalGPIOPin *pin_a_;
InternalGPIOPin *pin_b_;
GPIOPin *pin_i_{nullptr}; /// Index pin, if this is not nullptr, the counter will reset to 0 once this pin is HIGH.
RotaryEncoderSensorStore store_{};

View File

@@ -64,12 +64,8 @@ CONFIG_SCHEMA = cv.All(
.extend(
{
cv.GenerateID(): cv.declare_id(RotaryEncoderSensor),
cv.Required(CONF_PIN_A): cv.All(
pins.internal_gpio_input_pin_schema, pins.validate_has_interrupt
),
cv.Required(CONF_PIN_B): cv.All(
pins.internal_gpio_input_pin_schema, pins.validate_has_interrupt
),
cv.Required(CONF_PIN_A): cv.All(pins.internal_gpio_input_pin_schema),
cv.Required(CONF_PIN_B): cv.All(pins.internal_gpio_input_pin_schema),
cv.Optional(CONF_PIN_RESET): pins.internal_gpio_output_pin_schema,
cv.Optional(CONF_RESOLUTION, default=1): cv.enum(RESOLUTIONS, int=True),
cv.Optional(CONF_MIN_VALUE): cv.int_,