SensESP 3.3.0
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
ethernet_provisioner.h
Go to the documentation of this file.
1#ifndef SENSESP_NET_ETHERNET_PROVISIONER_H_
2#define SENSESP_NET_ETHERNET_PROVISIONER_H_
3
4// Native RMII Ethernet support.
5//
6// Currently only ESP32-P4 ships an Arduino-ESP32 ETH.h implementation
7// that SensESP can drive without writing a custom EMAC bring-up, so the
8// entire EthernetProvisioner class is guarded behind CONFIG_IDF_TARGET_ESP32P4.
9// On any other target, including this header compiles to nothing and
10// `EthernetConfig` / `EthernetProvisioner` are simply not declared —
11// so a user sketch that tries to call
12// `builder.set_ethernet(EthernetConfig::…())` on a classic ESP32 will
13// get a clear compile error at the use site ("'EthernetConfig' was
14// not declared in this scope") rather than a silent runtime failure.
15//
16// When future ESP32 variants grow a usable Arduino-ESP32 ETH driver,
17// the guard can be widened accordingly.
18
19#include <Arduino.h>
20
21#if defined(CONFIG_IDF_TARGET_ESP32P4)
22
23#include <ETH.h>
24
26#include "sensesp_base_app.h"
27
28namespace sensesp {
29
30class EthernetProvisioner;
31
44struct EthernetConfig {
47 using ProvisionerType = EthernetProvisioner;
48
49 eth_phy_type_t phy_type = ETH_PHY_IP101;
50 int32_t phy_addr = 1;
51 int mdc_pin = 31;
52 int mdio_pin = 52;
53 int power_pin = 51; // PHY reset pin
54 eth_clock_mode_t clock_mode = EMAC_CLK_EXT_IN;
55
61 static EthernetConfig waveshare_esp32p4_poe() {
62 EthernetConfig cfg;
63 cfg.phy_type = ETH_PHY_IP101;
64 cfg.phy_addr = 1;
65 cfg.mdc_pin = 31;
66 cfg.mdio_pin = 52;
67 cfg.power_pin = 51;
68 cfg.clock_mode = EMAC_CLK_EXT_IN;
69 return cfg;
70 }
71};
72
85class EthernetProvisioner : public NetworkProvisioner {
86 public:
87 explicit EthernetProvisioner(const EthernetConfig& config);
88 ~EthernetProvisioner() override;
89
90 // -- NetworkProvisioner --
91 IPAddress local_ip() const override;
92 IPAddress gateway_ip() const override;
93 String mac_address() const override;
94 bool is_connected() const override;
95
96 // -- Ethernet-specific --
98 int link_speed_mbps() const;
99
101 bool is_full_duplex() const;
102
103 private:
104 EthernetConfig config_;
105};
106
107} // namespace sensesp
108
109#endif // CONFIG_IDF_TARGET_ESP32P4
110
111#endif // SENSESP_NET_ETHERNET_PROVISIONER_H_
Transport-agnostic network provisioner interface.