diff --git a/src/main.rs b/src/main.rs index 679599a..697667b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,10 @@ +use std::sync::{Arc, Mutex}; use std::thread; use std::time::Duration; use esp_idf_svc::eth::{BlockingEth, EspEth, EthDriver, SpiEthChipset}; use esp_idf_svc::eventloop::EspSystemEventLoop; +use esp_idf_svc::hal::gpio::{Output, PinDriver}; use esp_idf_svc::hal::peripherals::Peripherals; use esp_idf_svc::hal::prelude::*; use esp_idf_svc::hal::spi::{config::DriverConfig, Dma, SpiDriver}; @@ -19,11 +21,14 @@ fn main() -> anyhow::Result<()> { let sysloop = EspSystemEventLoop::take()?; let pins = peripherals.pins; + // LED on IO17 + let led = Arc::new(Mutex::new(PinDriver::output(pins.gpio17)?)); + let spi_driver = SpiDriver::new( peripherals.spi2, pins.gpio13, // SCLK - pins.gpio11, // MOSI (sdo) - Some(pins.gpio12), // MISO (sdi) + pins.gpio11, // MOSI + Some(pins.gpio12), // MISO &DriverConfig { dma: Dma::Auto(4096), ..Default::default() @@ -32,13 +37,13 @@ fn main() -> anyhow::Result<()> { let eth_driver = EthDriver::new_spi( spi_driver, - pins.gpio10, // INT - Some(pins.gpio14), // CS - Some(pins.gpio9), // RST + pins.gpio10, // INT + Some(pins.gpio14), // CS + Some(pins.gpio9), // RST SpiEthChipset::W5500, 20.MHz().into(), - Some(&[0x02, 0x00, 0x00, 0x12, 0x34, 0x56]), // locally-administered MAC - None, // phy addr — default + Some(&[0x02, 0x00, 0x00, 0x12, 0x34, 0x56]), + None, sysloop.clone(), )?; @@ -54,12 +59,33 @@ fn main() -> anyhow::Result<()> { info!("Got IP: {:?}", ip_info); let mut server = EspHttpServer::new(&HttpServerConfig::default())?; + server.fn_handler("/", Method::Get, |req| { - let html = "