mirror of
https://github.com/esphome/esphome.git
synced 2025-02-15 01:18:16 +00:00
* 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>
99 lines
2.3 KiB
C++
99 lines
2.3 KiB
C++
#pragma once
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
namespace esphome {
|
|
|
|
#define LOG_PIN(prefix, pin) \
|
|
if ((pin) != nullptr) { \
|
|
ESP_LOGCONFIG(TAG, prefix "%s", pin->dump_summary().c_str()); \
|
|
}
|
|
|
|
// put GPIO flags in a namepsace to not pollute esphome namespace
|
|
namespace gpio {
|
|
|
|
enum Flags : uint8_t {
|
|
// Can't name these just INPUT because of Arduino defines :(
|
|
FLAG_NONE = 0x00,
|
|
FLAG_INPUT = 0x01,
|
|
FLAG_OUTPUT = 0x02,
|
|
FLAG_OPEN_DRAIN = 0x04,
|
|
FLAG_PULLUP = 0x08,
|
|
FLAG_PULLDOWN = 0x10,
|
|
};
|
|
|
|
class FlagsHelper {
|
|
public:
|
|
constexpr FlagsHelper(Flags val) : val_(val) {}
|
|
constexpr operator Flags() const { return val_; }
|
|
|
|
protected:
|
|
Flags val_;
|
|
};
|
|
constexpr FlagsHelper operator&(Flags lhs, Flags rhs) {
|
|
return static_cast<Flags>(static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs));
|
|
}
|
|
constexpr FlagsHelper operator|(Flags lhs, Flags rhs) {
|
|
return static_cast<Flags>(static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
|
|
}
|
|
|
|
enum InterruptType : uint8_t {
|
|
INTERRUPT_RISING_EDGE = 1,
|
|
INTERRUPT_FALLING_EDGE = 2,
|
|
INTERRUPT_ANY_EDGE = 3,
|
|
INTERRUPT_LOW_LEVEL = 4,
|
|
INTERRUPT_HIGH_LEVEL = 5,
|
|
};
|
|
|
|
} // namespace gpio
|
|
|
|
class GPIOPin {
|
|
public:
|
|
virtual void setup() = 0;
|
|
|
|
virtual void pin_mode(gpio::Flags flags) = 0;
|
|
|
|
virtual bool digital_read() = 0;
|
|
|
|
virtual void digital_write(bool value) = 0;
|
|
|
|
virtual std::string dump_summary() const = 0;
|
|
|
|
virtual bool is_internal() { return false; }
|
|
};
|
|
|
|
/// Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
|
|
class ISRInternalGPIOPin {
|
|
public:
|
|
ISRInternalGPIOPin() = default;
|
|
ISRInternalGPIOPin(void *arg) : arg_(arg) {}
|
|
bool digital_read();
|
|
void digital_write(bool value);
|
|
void clear_interrupt();
|
|
|
|
protected:
|
|
void *arg_ = nullptr;
|
|
};
|
|
|
|
class InternalGPIOPin : public GPIOPin {
|
|
public:
|
|
template<typename T> void attach_interrupt(void (*func)(T *), T *arg, gpio::InterruptType type) const {
|
|
this->attach_interrupt_(reinterpret_cast<void (*)(void *)>(func), arg, type);
|
|
}
|
|
|
|
virtual void detach_interrupt() const = 0;
|
|
|
|
virtual ISRInternalGPIOPin to_isr() const = 0;
|
|
|
|
virtual uint8_t get_pin() const = 0;
|
|
|
|
bool is_internal() override { return true; }
|
|
|
|
virtual bool is_inverted() const = 0;
|
|
|
|
protected:
|
|
virtual void attach_interrupt_(void (*func)(void *), void *arg, gpio::InterruptType type) const = 0;
|
|
};
|
|
|
|
} // namespace esphome
|