mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-06 04:48:27 +02:00
🏗 Merge C++ into python codebase (#504)
## Description: Move esphome-core codebase into esphome (and a bunch of other refactors). See https://github.com/esphome/feature-requests/issues/97 Yes this is a shit ton of work and no there's no way to automate it :( But it will be worth it 👍 Progress: - Core support (file copy etc): 80% - Base Abstractions (light, switch): ~50% - Integrations: ~10% - Working? Yes, (but only with ported components). Other refactors: - Moves all codegen related stuff into a single class: `esphome.codegen` (imported as `cg`) - Rework coroutine syntax - Move from `component/platform.py` to `domain/component.py` structure as with HA - Move all defaults out of C++ and into config validation. - Remove `make_...` helpers from Application class. Reason: Merge conflicts with every single new integration. - Pointer Variables are stored globally instead of locally in setup(). Reason: stack size limit. Future work: - Rework const.py - Move all `CONF_...` into a conf class (usage `conf.UPDATE_INTERVAL` vs `CONF_UPDATE_INTERVAL`). Reason: Less convoluted import block - Enable loading from `custom_components` folder. **Related issue (if applicable):** https://github.com/esphome/feature-requests/issues/97 **Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here> ## Checklist: - [ ] The code change is tested and works locally. - [ ] Tests have been added to verify that the new code works (under `tests/` folder). If user exposed functionality or configuration variables are added/changed: - [ ] Documentation added/updated in [esphomedocs](https://github.com/OttoWinter/esphomedocs).
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/esphal.h"
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
|
||||
#include "esp_eth.h"
|
||||
#include <esp_wifi.h>
|
||||
#include <WiFiType.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace ethernet {
|
||||
|
||||
enum EthernetType {
|
||||
ETHERNET_TYPE_LAN8720 = 0,
|
||||
ETHERNET_TYPE_TLK110,
|
||||
};
|
||||
|
||||
struct ManualIP {
|
||||
IPAddress static_ip;
|
||||
IPAddress gateway;
|
||||
IPAddress subnet;
|
||||
IPAddress dns1; ///< The first DNS server. 0.0.0.0 for default.
|
||||
IPAddress dns2; ///< The second DNS server. 0.0.0.0 for default.
|
||||
};
|
||||
|
||||
class EthernetComponent : public Component {
|
||||
public:
|
||||
EthernetComponent();
|
||||
void setup() override;
|
||||
void loop() override;
|
||||
void dump_config() override;
|
||||
float get_setup_priority() const override;
|
||||
bool can_proceed() override;
|
||||
bool is_connected();
|
||||
|
||||
void set_phy_addr(uint8_t phy_addr);
|
||||
void set_power_pin(GPIOPin *power_pin);
|
||||
void set_mdc_pin(uint8_t mdc_pin);
|
||||
void set_mdio_pin(uint8_t mdio_pin);
|
||||
void set_type(EthernetType type);
|
||||
void set_clk_mode(eth_clock_mode_t clk_mode);
|
||||
void set_manual_ip(ManualIP manual_ip);
|
||||
|
||||
IPAddress get_ip_address();
|
||||
std::string get_use_address() const;
|
||||
void set_use_address(const std::string &use_address);
|
||||
|
||||
protected:
|
||||
void on_wifi_event_(system_event_id_t event, system_event_info_t info);
|
||||
void start_connect_();
|
||||
void dump_connect_params_();
|
||||
|
||||
static void eth_phy_config_gpio_();
|
||||
static void eth_phy_power_enable_(bool enable);
|
||||
|
||||
std::string use_address_;
|
||||
uint8_t phy_addr_{0};
|
||||
GPIOPin *power_pin_{nullptr};
|
||||
uint8_t mdc_pin_{23};
|
||||
uint8_t mdio_pin_{18};
|
||||
EthernetType type_{ETHERNET_TYPE_LAN8720};
|
||||
eth_clock_mode_t clk_mode_{ETH_CLOCK_GPIO0_IN};
|
||||
optional<ManualIP> manual_ip_{};
|
||||
|
||||
bool initialized_{false};
|
||||
bool connected_{false};
|
||||
bool last_connected_{false};
|
||||
uint32_t connect_begin_;
|
||||
eth_config_t eth_config;
|
||||
eth_phy_power_enable_func orig_power_enable_fun_;
|
||||
};
|
||||
|
||||
extern EthernetComponent *global_eth_component;
|
||||
|
||||
} // namespace ethernet
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user