From b331742ea3ce7e8bfc211dfc1300dca1cb2706b1 Mon Sep 17 00:00:00 2001 From: Samuel Hicks Date: Fri, 6 Dec 2024 19:27:40 +0000 Subject: [PATCH] Updated to embassy-net 0.5 --- Cargo.toml | 2 +- examples/embassy/Cargo.toml | 2 +- examples/embassy/hello_world/src/main.rs | 36 ++++++++----------- examples/embassy/hello_world_defmt/Cargo.toml | 2 +- .../embassy/hello_world_defmt/src/main.rs | 36 ++++++++----------- examples/embassy/set_pico_w_led/src/main.rs | 36 ++++++++----------- examples/embassy/web_sockets/src/main.rs | 36 ++++++++----------- src/lib.rs | 4 +-- 8 files changed, 65 insertions(+), 89 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9f6d252..ef298ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ categories = ["asynchronous", "network-programming", "web-programming::http-serv const-sha1 = { version = "0.3.0", default-features = false } data-encoding = { version = "2.4.0", default-features = false } defmt = { version = "0.3.6", optional = true } -embassy-net = { version = "0.4.0", optional = true, features = ["tcp", "proto-ipv4", "medium-ethernet"] } +embassy-net = { version = "0.5.0", optional = true, features = ["tcp", "proto-ipv4", "medium-ethernet"] } embassy-time = { version = "0.3.0", optional = true } embedded-io-async = "0.6.0" futures-util = { version = "0.3.28", default-features = false } diff --git a/examples/embassy/Cargo.toml b/examples/embassy/Cargo.toml index e0ec24b..2017e6d 100644 --- a/examples/embassy/Cargo.toml +++ b/examples/embassy/Cargo.toml @@ -16,7 +16,7 @@ cyw43 = { version = "0.2.0", features = ["firmware-logs"] } cyw43-pio = "0.2.0" embassy-executor = { version = "0.6.3", features = ["arch-cortex-m", "executor-thread", "integrated-timers", "nightly"] } embassy-futures = "0.1.1" -embassy-net = { version = "0.4.0", features = ["tcp", "proto-ipv4", "medium-ethernet"] } +embassy-net = { version = "0.5.0", features = ["tcp", "proto-ipv4", "medium-ethernet"] } embassy-rp = { version = "0.2.0", features = ["critical-section-impl", "time-driver"] } embassy-sync = "0.6.0" embassy-time = "0.3.1" diff --git a/examples/embassy/hello_world/src/main.rs b/examples/embassy/hello_world/src/main.rs index c60a17b..ef7fb6f 100644 --- a/examples/embassy/hello_world/src/main.rs +++ b/examples/embassy/hello_world/src/main.rs @@ -33,7 +33,7 @@ async fn wifi_task( } #[embassy_executor::task] -async fn net_task(stack: &'static embassy_net::Stack>) -> ! { +async fn net_task(mut stack: embassy_net::Runner<'static, cyw43::NetDriver<'static>>) -> ! { stack.run().await } @@ -52,7 +52,7 @@ const WEB_TASK_POOL_SIZE: usize = 8; #[embassy_executor::task(pool_size = WEB_TASK_POOL_SIZE)] async fn web_task( id: usize, - stack: &'static embassy_net::Stack>, + stack: embassy_net::Stack<'static>, app: &'static AppRouter, config: &'static picoserve::Config, ) -> ! { @@ -109,27 +109,21 @@ async fn main(spawner: embassy_executor::Spawner) { control.init(clm).await; - let stack = make_static!( - embassy_net::Stack, - embassy_net::Stack::new( - net_device, - embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { - address: embassy_net::Ipv4Cidr::new( - embassy_net::Ipv4Address::new(192, 168, 0, 1), - 24 - ), - gateway: None, - dns_servers: Default::default(), - }), - make_static!( - embassy_net::StackResources, - embassy_net::StackResources::new() - ), - embassy_rp::clocks::RoscRng.gen(), - ) + let (stack, runner) = embassy_net::new( + net_device, + embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { + address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address::new(192, 168, 0, 1), 24), + gateway: None, + dns_servers: Default::default(), + }), + make_static!( + embassy_net::StackResources, + embassy_net::StackResources::new() + ), + embassy_rp::clocks::RoscRng.gen(), ); - spawner.must_spawn(net_task(stack)); + spawner.must_spawn(net_task(runner)); control .start_ap_wpa2( diff --git a/examples/embassy/hello_world_defmt/Cargo.toml b/examples/embassy/hello_world_defmt/Cargo.toml index 24d972b..0d9464f 100644 --- a/examples/embassy/hello_world_defmt/Cargo.toml +++ b/examples/embassy/hello_world_defmt/Cargo.toml @@ -12,7 +12,7 @@ cyw43-pio = "0.2.0" defmt-rtt = "0.4.0" embassy-executor = { version = "0.6.3", features = ["arch-cortex-m", "executor-thread", "integrated-timers", "nightly"] } embassy-futures = "0.1.1" -embassy-net = { version = "0.4.0", features = ["tcp", "proto-ipv4", "medium-ethernet"] } +embassy-net = { version = "0.5.0", features = ["tcp", "proto-ipv4", "medium-ethernet"] } embassy-rp = { version = "0.2.0", features = ["critical-section-impl", "time-driver"] } embassy-sync = "0.6.1" embassy-time = { version = "0.3.0", features = ["defmt-timestamp-uptime"] } diff --git a/examples/embassy/hello_world_defmt/src/main.rs b/examples/embassy/hello_world_defmt/src/main.rs index de8eed3..22f7174 100644 --- a/examples/embassy/hello_world_defmt/src/main.rs +++ b/examples/embassy/hello_world_defmt/src/main.rs @@ -27,7 +27,7 @@ async fn wifi_task( } #[embassy_executor::task] -async fn net_task(stack: &'static embassy_net::Stack>) -> ! { +async fn net_task(mut stack: embassy_net::Runner<'static, cyw43::NetDriver<'static>>) -> ! { stack.run().await } @@ -46,7 +46,7 @@ const WEB_TASK_POOL_SIZE: usize = 8; #[embassy_executor::task(pool_size = WEB_TASK_POOL_SIZE)] async fn web_task( id: usize, - stack: &'static embassy_net::Stack>, + stack: embassy_net::Stack<'static>, app: &'static AppRouter, config: &'static picoserve::Config, ) -> ! { @@ -94,27 +94,21 @@ async fn main(spawner: embassy_executor::Spawner) { control.init(clm).await; - let stack = make_static!( - embassy_net::Stack::, - embassy_net::Stack::new( - net_device, - embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { - address: embassy_net::Ipv4Cidr::new( - embassy_net::Ipv4Address::new(192, 168, 0, 1), - 24 - ), - gateway: None, - dns_servers: Default::default(), - }), - make_static!( - embassy_net::StackResources::, - embassy_net::StackResources::new() - ), - embassy_rp::clocks::RoscRng.gen(), - ) + let (stack, runner) = embassy_net::new( + net_device, + embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { + address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address::new(192, 168, 0, 1), 24), + gateway: None, + dns_servers: Default::default(), + }), + make_static!( + embassy_net::StackResources::, + embassy_net::StackResources::new() + ), + embassy_rp::clocks::RoscRng.gen(), ); - spawner.must_spawn(net_task(stack)); + spawner.must_spawn(net_task(runner)); control .start_ap_wpa2( diff --git a/examples/embassy/set_pico_w_led/src/main.rs b/examples/embassy/set_pico_w_led/src/main.rs index 4786cdc..6d70e32 100644 --- a/examples/embassy/set_pico_w_led/src/main.rs +++ b/examples/embassy/set_pico_w_led/src/main.rs @@ -41,7 +41,7 @@ async fn wifi_task( } #[embassy_executor::task] -async fn net_task(stack: &'static embassy_net::Stack>) -> ! { +async fn net_task(mut stack: embassy_net::Runner<'static, cyw43::NetDriver<'static>>) -> ! { stack.run().await } @@ -98,7 +98,7 @@ const WEB_TASK_POOL_SIZE: usize = 8; #[embassy_executor::task(pool_size = WEB_TASK_POOL_SIZE)] async fn web_task( id: usize, - stack: &'static embassy_net::Stack>, + stack: embassy_net::Stack<'static>, app: &'static AppRouter, config: &'static picoserve::Config, state: AppState, @@ -157,27 +157,21 @@ async fn main(spawner: embassy_executor::Spawner) { control.init(clm).await; - let stack = make_static!( - embassy_net::Stack::, - embassy_net::Stack::new( - net_device, - embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { - address: embassy_net::Ipv4Cidr::new( - embassy_net::Ipv4Address::new(192, 168, 0, 1), - 24 - ), - gateway: None, - dns_servers: Default::default(), - }), - make_static!( - embassy_net::StackResources::, - embassy_net::StackResources::new() - ), - embassy_rp::clocks::RoscRng.gen(), - ) + let (stack, runner) = embassy_net::new( + net_device, + embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { + address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address::new(192, 168, 0, 1), 24), + gateway: None, + dns_servers: Default::default(), + }), + make_static!( + embassy_net::StackResources::, + embassy_net::StackResources::new() + ), + embassy_rp::clocks::RoscRng.gen(), ); - spawner.must_spawn(net_task(stack)); + spawner.must_spawn(net_task(runner)); control .start_ap_wpa2( diff --git a/examples/embassy/web_sockets/src/main.rs b/examples/embassy/web_sockets/src/main.rs index ce38e65..f548a0e 100644 --- a/examples/embassy/web_sockets/src/main.rs +++ b/examples/embassy/web_sockets/src/main.rs @@ -37,7 +37,7 @@ async fn wifi_task( } #[embassy_executor::task] -async fn net_task(stack: &'static embassy_net::Stack>) -> ! { +async fn net_task(mut stack: embassy_net::Runner<'static, cyw43::NetDriver<'static>>) -> ! { stack.run().await } @@ -76,7 +76,7 @@ const WEB_TASK_POOL_SIZE: usize = 8; #[embassy_executor::task(pool_size = WEB_TASK_POOL_SIZE)] async fn web_task( id: usize, - stack: &'static embassy_net::Stack>, + stack: embassy_net::Stack<'static>, app: &'static AppRouter, config: &'static picoserve::Config, ) -> ! { @@ -176,27 +176,21 @@ async fn main(spawner: embassy_executor::Spawner) { control.init(clm).await; - let stack = make_static!( - embassy_net::Stack::, - embassy_net::Stack::new( - net_device, - embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { - address: embassy_net::Ipv4Cidr::new( - embassy_net::Ipv4Address::new(192, 168, 0, 1), - 24 - ), - gateway: None, - dns_servers: Default::default(), - }), - make_static!( - embassy_net::StackResources::, - embassy_net::StackResources::new() - ), - embassy_rp::clocks::RoscRng.gen(), - ) + let (stack, runner) = embassy_net::new( + net_device, + embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { + address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address::new(192, 168, 0, 1), 24), + gateway: None, + dns_servers: Default::default(), + }), + make_static!( + embassy_net::StackResources::, + embassy_net::StackResources::new() + ), + embassy_rp::clocks::RoscRng.gen(), ); - spawner.must_spawn(net_task(stack)); + spawner.must_spawn(net_task(runner)); control .start_ap_wpa2( diff --git a/src/lib.rs b/src/lib.rs index 938b43c..7f445f9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -340,7 +340,7 @@ pub async fn listen_and_serve>( task_id: impl LogDisplay, app: &Router, config: &Config, - stack: &embassy_net::Stack, + stack: embassy_net::Stack<'_>, port: u16, tcp_rx_buffer: &mut [u8], tcp_tx_buffer: &mut [u8], @@ -367,7 +367,7 @@ pub async fn listen_and_serve_with_state>( task_id: impl LogDisplay, app: &Router, config: &Config, - stack: &embassy_net::Stack, + stack: embassy_net::Stack<'_>, port: u16, tcp_rx_buffer: &mut [u8], tcp_tx_buffer: &mut [u8],