mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-25 15:18:29 +02:00
ac0d921413
* 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>
97 lines
3.4 KiB
C++
97 lines
3.4 KiB
C++
#pragma once
|
|
|
|
#ifdef USE_ESP32_FRAMEWORK_ESP_IDF
|
|
#include "esphome/core/hal.h"
|
|
#include <driver/gpio.h>
|
|
|
|
namespace esphome {
|
|
namespace esp32 {
|
|
|
|
class IDFInternalGPIOPin : public InternalGPIOPin {
|
|
public:
|
|
void set_pin(gpio_num_t pin) { pin_ = pin; }
|
|
void set_inverted(bool inverted) { inverted_ = inverted; }
|
|
void set_drive_strength(gpio_drive_cap_t drive_strength) { drive_strength_ = drive_strength; }
|
|
void set_flags(gpio::Flags flags) { flags_ = flags; }
|
|
|
|
void setup() override {
|
|
pin_mode(flags_);
|
|
gpio_set_drive_capability(pin_, drive_strength_);
|
|
}
|
|
void pin_mode(gpio::Flags flags) override {
|
|
gpio_config_t conf{};
|
|
conf.pin_bit_mask = 1 << static_cast<uint32_t>(pin_);
|
|
conf.mode = flags_to_mode_(flags);
|
|
conf.pull_up_en = flags & gpio::FLAG_PULLUP ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE;
|
|
conf.pull_down_en = flags & gpio::FLAG_PULLDOWN ? GPIO_PULLDOWN_ENABLE : GPIO_PULLDOWN_DISABLE;
|
|
conf.intr_type = GPIO_INTR_DISABLE;
|
|
gpio_config(&conf);
|
|
}
|
|
bool digital_read() override { return bool(gpio_get_level(pin_)) != inverted_; }
|
|
void digital_write(bool value) override { gpio_set_level(pin_, value != inverted_ ? 1 : 0); }
|
|
std::string dump_summary() const override;
|
|
void detach_interrupt() const override { gpio_intr_disable(pin_); }
|
|
ISRInternalGPIOPin to_isr() const override;
|
|
uint8_t get_pin() const override { return (uint8_t) pin_; }
|
|
bool is_inverted() const override { return inverted_; }
|
|
|
|
protected:
|
|
static gpio_mode_t flags_to_mode_(gpio::Flags flags) {
|
|
flags = (gpio::Flags)(flags & ~(gpio::FLAG_PULLUP | gpio::FLAG_PULLDOWN));
|
|
if (flags == gpio::FLAG_NONE) {
|
|
return GPIO_MODE_DISABLE;
|
|
} else if (flags == gpio::FLAG_INPUT) {
|
|
return GPIO_MODE_INPUT;
|
|
} else if (flags == gpio::FLAG_OUTPUT) {
|
|
return GPIO_MODE_OUTPUT;
|
|
} else if (flags == (gpio::FLAG_OUTPUT | gpio::FLAG_OPEN_DRAIN)) {
|
|
return GPIO_MODE_OUTPUT_OD;
|
|
} else if (flags == (gpio::FLAG_INPUT | gpio::FLAG_OUTPUT | gpio::FLAG_OPEN_DRAIN)) {
|
|
return GPIO_MODE_INPUT_OUTPUT_OD;
|
|
} else if (flags == (gpio::FLAG_INPUT | gpio::FLAG_OUTPUT)) {
|
|
return GPIO_MODE_INPUT_OUTPUT;
|
|
} else {
|
|
// unsupported
|
|
return GPIO_MODE_DISABLE;
|
|
}
|
|
}
|
|
void attach_interrupt_(void (*func)(void *), void *arg, gpio::InterruptType type) const override {
|
|
gpio_int_type_t idf_type = GPIO_INTR_ANYEDGE;
|
|
switch (type) {
|
|
case gpio::INTERRUPT_RISING_EDGE:
|
|
idf_type = inverted_ ? GPIO_INTR_NEGEDGE : GPIO_INTR_POSEDGE;
|
|
break;
|
|
case gpio::INTERRUPT_FALLING_EDGE:
|
|
idf_type = inverted_ ? GPIO_INTR_POSEDGE : GPIO_INTR_NEGEDGE;
|
|
break;
|
|
case gpio::INTERRUPT_ANY_EDGE:
|
|
idf_type = GPIO_INTR_ANYEDGE;
|
|
break;
|
|
case gpio::INTERRUPT_LOW_LEVEL:
|
|
idf_type = inverted_ ? GPIO_INTR_HIGH_LEVEL : GPIO_INTR_LOW_LEVEL;
|
|
break;
|
|
case gpio::INTERRUPT_HIGH_LEVEL:
|
|
idf_type = inverted_ ? GPIO_INTR_LOW_LEVEL : GPIO_INTR_HIGH_LEVEL;
|
|
break;
|
|
}
|
|
gpio_set_intr_type(pin_, idf_type);
|
|
gpio_intr_enable(pin_);
|
|
if (!isr_service_installed_) {
|
|
gpio_install_isr_service(ESP_INTR_FLAG_LEVEL5);
|
|
isr_service_installed_ = true;
|
|
}
|
|
gpio_isr_handler_add(pin_, func, arg);
|
|
}
|
|
|
|
gpio_num_t pin_;
|
|
bool inverted_;
|
|
gpio_drive_cap_t drive_strength_;
|
|
gpio::Flags flags_;
|
|
static bool isr_service_installed_;
|
|
};
|
|
|
|
} // namespace esp32
|
|
} // namespace esphome
|
|
|
|
#endif // USE_ESP32_FRAMEWORK_ESP_IDF
|