-
Notifications
You must be signed in to change notification settings - Fork 196
/
Copy patheth.rs
70 lines (55 loc) · 1.81 KB
/
eth.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! This example demonstrates how to configure an RMII based Ethernet adapter
//!
//! To use it, you need an RMII-capable Espressif MCU, like the original ESP32 chip
#[cfg(esp32)]
use esp_idf_svc::{
eth::{BlockingEth, EspEth, EthDriver},
eventloop::EspSystemEventLoop,
hal::{gpio, prelude::Peripherals},
log::EspLogger,
};
#[cfg(esp32)]
use log::info;
#[cfg(esp32)]
fn main() -> anyhow::Result<()> {
esp_idf_svc::sys::link_patches();
EspLogger::initialize_default();
let peripherals = Peripherals::take()?;
let pins = peripherals.pins;
let sys_loop = EspSystemEventLoop::take()?;
// Make sure to configure ethernet in sdkconfig and adjust the parameters below for your hardware
let eth_driver = EthDriver::new_rmii(
peripherals.mac,
pins.gpio25,
pins.gpio26,
pins.gpio27,
pins.gpio23,
pins.gpio22,
pins.gpio21,
pins.gpio19,
pins.gpio18,
esp_idf_svc::eth::RmiiClockConfig::<gpio::Gpio0, gpio::Gpio16, gpio::Gpio17>::OutputInvertedGpio17(
pins.gpio17,
),
Some(pins.gpio5),
// Replace with IP101 if you have that variant, or with some of the others in the `RmiiEthChipset`` enum
esp_idf_svc::eth::RmiiEthChipset::LAN87XX,
Some(0),
sys_loop.clone(),
)?;
let eth = EspEth::wrap(eth_driver)?;
info!("Eth created");
let mut eth = BlockingEth::wrap(eth, sys_loop.clone())?;
info!("Starting eth...");
eth.start()?;
info!("Waiting for DHCP lease...");
eth.wait_netif_up()?;
let ip_info = eth.eth().netif().get_ip_info()?;
info!("Eth DHCP info: {:?}", ip_info);
Ok(())
}
#[cfg(not(esp32))]
fn main() {
use esp_idf_svc::{self as _};
panic!("This example is configured for esp32, please adjust pins to your module");
}