Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for ethernet #289

Merged
merged 4 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions examples/eth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#[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().unwrap();
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(
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),
esp_idf_svc::eth::RmiiEthChipset::LAN87XX,
ivmarkov marked this conversation as resolved.
Show resolved Hide resolved
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");
}
1 change: 1 addition & 0 deletions examples/http_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const SSID: &str = env!("WIFI_SSID");
const PASSWORD: &str = env!("WIFI_PASS");

fn main() -> anyhow::Result<()> {
esp_idf_svc::sys::link_patches();
EspLogger::initialize_default();

// Setup Wifi
Expand Down
1 change: 1 addition & 0 deletions examples/nvs_get_set_c_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use esp_idf_svc::nvs::*;
use log::info;

fn main() -> anyhow::Result<()> {
esp_idf_svc::sys::link_patches();
EspLogger::initialize_default();

let nvs_default_partition: EspNvsPartition<NvsDefault> =
Expand Down
1 change: 1 addition & 0 deletions examples/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ A7sKPPcw7+uvTPyLNhBzPvOk
-----END CERTIFICATE-----\0";

fn main() -> anyhow::Result<()> {
esp_idf_svc::sys::link_patches();
EspLogger::initialize_default();

let peripherals = Peripherals::take().unwrap();
Expand Down
1 change: 1 addition & 0 deletions examples/wifi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const SSID: &str = env!("WIFI_SSID");
const PASSWORD: &str = env!("WIFI_PASS");

fn main() -> anyhow::Result<()> {
esp_idf_svc::sys::link_patches();
EspLogger::initialize_default();

let peripherals = Peripherals::take().unwrap();
Expand Down
1 change: 1 addition & 0 deletions examples/wifi_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const SSID: &str = env!("WIFI_SSID");
const PASSWORD: &str = env!("WIFI_PASS");

fn main() -> anyhow::Result<()> {
esp_idf_svc::sys::link_patches();
EspLogger::initialize_default();

let peripherals = Peripherals::take().unwrap();
Expand Down