From c1ec6a4f2596ae4417703b307e49b4c8563eba62 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Sat, 17 Feb 2024 15:37:08 +0100 Subject: [PATCH 1/2] riot-rs-embassy: drop `struct Drivers` --- src/riot-rs-embassy/src/lib.rs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/riot-rs-embassy/src/lib.rs b/src/riot-rs-embassy/src/lib.rs index e734a4e26..af5e52713 100644 --- a/src/riot-rs-embassy/src/lib.rs +++ b/src/riot-rs-embassy/src/lib.rs @@ -49,12 +49,6 @@ pub mod sendcell; pub type Task = fn(&mut arch::OptionalPeripherals) -> Result<&dyn Application, ApplicationInitError>; -#[derive(Copy, Clone)] -pub struct Drivers { - #[cfg(feature = "net")] - pub stack: &'static OnceCell<&'static NetworkStack>, -} - pub static EXECUTOR: arch::Executor = arch::Executor::new(); #[distributed_slice] @@ -74,11 +68,6 @@ pub(crate) fn init() { async fn init_task(mut peripherals: arch::OptionalPeripherals) { riot_rs_rt::debug::println!("riot-rs-embassy::init_task()"); - let drivers = Drivers { - #[cfg(feature = "net")] - stack: make_static!(OnceCell::new()), - }; - #[cfg(all(context = "nrf52", feature = "usb"))] { // nrf52840 @@ -201,7 +190,7 @@ async fn init_task(mut peripherals: arch::OptionalPeripherals) { for task in EMBASSY_TASKS { // TODO: should all tasks be initialized before starting the first one? match task(&mut peripherals) { - Ok(initialized_application) => initialized_application.start(spawner, drivers), + Ok(initialized_application) => initialized_application.start(spawner), Err(err) => panic!("Error while initializing an application: {err:?}"), } } @@ -233,8 +222,7 @@ pub trait Application { /// /// This function must not block but may spawn [Embassy tasks](embassy_executor::task) using /// the provided [`Spawner`](embassy_executor::Spawner). - /// In addition, it is provided with the drivers initialized by the system. - fn start(&self, spawner: embassy_executor::Spawner, drivers: Drivers); + fn start(&self, spawner: embassy_executor::Spawner); } /// Represents errors that can happen during application initialization. From dddf0f300b1b055ac4e3a0726a9b38a558a8c51e Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 19 Feb 2024 15:46:32 +0100 Subject: [PATCH 2/2] examples/*: drop use of `Drivers` --- examples/application/src/main.rs | 4 ++-- examples/embassy-http-server/src/main.rs | 6 ++---- examples/embassy-net-tcp/src/main.rs | 8 ++++---- examples/embassy-net-udp/src/main.rs | 8 ++++---- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/examples/application/src/main.rs b/examples/application/src/main.rs index b5c97313e..3ed23b8bf 100644 --- a/examples/application/src/main.rs +++ b/examples/application/src/main.rs @@ -3,7 +3,7 @@ #![feature(type_alias_impl_trait)] #![feature(used_with_arg)] -use riot_rs::embassy::{arch, Application, ApplicationInitError, Drivers}; +use riot_rs::embassy::{arch, Application, ApplicationInitError}; use riot_rs::rt::debug::println; @@ -19,7 +19,7 @@ impl Application for MyApplication { Ok(&Self { state: 0 }) } - fn start(&self, _spawner: embassy_executor::Spawner, _drivers: Drivers) { + fn start(&self, _spawner: embassy_executor::Spawner) { println!("MyApplication::start()"); // ... } diff --git a/examples/embassy-http-server/src/main.rs b/examples/embassy-http-server/src/main.rs index 7a951b2e8..4b240a68b 100644 --- a/examples/embassy-http-server/src/main.rs +++ b/examples/embassy-http-server/src/main.rs @@ -8,9 +8,7 @@ mod routes; use riot_rs as _; -use riot_rs::embassy::{ - arch::OptionalPeripherals, network, Application, ApplicationInitError, Drivers, -}; +use riot_rs::embassy::{arch::OptionalPeripherals, network, Application, ApplicationInitError}; use riot_rs::rt::debug::println; use embassy_net::tcp::TcpSocket; @@ -116,7 +114,7 @@ impl Application for WebServer { })) } - fn start(&self, spawner: embassy_executor::Spawner, _drivers: Drivers) { + fn start(&self, spawner: embassy_executor::Spawner) { fn make_app() -> picoserve::Router { let router = picoserve::Router::new().route("/", get(routes::index)); #[cfg(feature = "button-readings")] diff --git a/examples/embassy-net-tcp/src/main.rs b/examples/embassy-net-tcp/src/main.rs index 2749382c2..683b6c795 100644 --- a/examples/embassy-net-tcp/src/main.rs +++ b/examples/embassy-net-tcp/src/main.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] #![feature(used_with_arg)] -use riot_rs::embassy::{arch, network, Application, ApplicationInitError, Drivers}; +use riot_rs::embassy::{arch, network, Application, ApplicationInitError}; use riot_rs::rt::debug::println; use embedded_io_async::Write; #[embassy_executor::task] -async fn tcp_echo(_drivers: Drivers) { +async fn tcp_echo() { use embassy_net::tcp::TcpSocket; let stack = network::network_stack().await.unwrap(); @@ -65,8 +65,8 @@ impl Application for TcpEcho { Ok(&Self {}) } - fn start(&self, spawner: embassy_executor::Spawner, drivers: Drivers) { - spawner.spawn(tcp_echo(drivers)).unwrap(); + fn start(&self, spawner: embassy_executor::Spawner) { + spawner.spawn(tcp_echo()).unwrap(); } } diff --git a/examples/embassy-net-udp/src/main.rs b/examples/embassy-net-udp/src/main.rs index 2089570d3..e14638f79 100644 --- a/examples/embassy-net-udp/src/main.rs +++ b/examples/embassy-net-udp/src/main.rs @@ -3,12 +3,12 @@ #![feature(type_alias_impl_trait)] #![feature(used_with_arg)] -use riot_rs::embassy::{arch, network, Application, ApplicationInitError, Drivers}; +use riot_rs::embassy::{arch, network, Application, ApplicationInitError}; use riot_rs::rt::debug::println; #[embassy_executor::task] -async fn udp_echo(_drivers: Drivers) { +async fn udp_echo() { use embassy_net::udp::{PacketMetadata, UdpSocket}; let stack = network::network_stack().await.unwrap(); @@ -70,8 +70,8 @@ impl Application for UdpEcho { Ok(&Self {}) } - fn start(&self, spawner: embassy_executor::Spawner, drivers: Drivers) { - spawner.spawn(udp_echo(drivers)).unwrap(); + fn start(&self, spawner: embassy_executor::Spawner) { + spawner.spawn(udp_echo()).unwrap(); } }