From 74b0460e284ae53e2c35a031441ef88df822425d Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Sat, 17 Feb 2024 14:40:43 +0100 Subject: [PATCH 1/2] riot-rs-embassy: drop InitializationArgs --- src/riot-rs-embassy/src/lib.rs | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/src/riot-rs-embassy/src/lib.rs b/src/riot-rs-embassy/src/lib.rs index 3412912e9..f5805a73e 100644 --- a/src/riot-rs-embassy/src/lib.rs +++ b/src/riot-rs-embassy/src/lib.rs @@ -23,16 +23,15 @@ mod network; #[cfg(feature = "wifi_cyw43")] mod wifi; +#[cfg(feature = "net")] use core::cell::OnceCell; // re-exports pub use linkme::{self, distributed_slice}; pub use static_cell::make_static; -use embassy_executor::Spawner; -use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, mutex::Mutex}; - use crate::define_peripherals::DefinePeripheralsError; +use embassy_executor::Spawner; #[cfg(feature = "usb")] use usb::ethernet::NetworkDevice; @@ -46,17 +45,8 @@ pub use network::NetworkStack; #[cfg(feature = "threading")] pub mod blocker; -pub type Task = fn( - &mut arch::OptionalPeripherals, - InitializationArgs, -) -> Result<&dyn Application, ApplicationInitError>; - -// Allows us to pass extra initialization arguments in the future -#[derive(Copy, Clone)] -#[non_exhaustive] -pub struct InitializationArgs { - pub peripherals: &'static Mutex, -} +pub type Task = + fn(&mut arch::OptionalPeripherals) -> Result<&dyn Application, ApplicationInitError>; #[derive(Copy, Clone)] pub struct Drivers { @@ -202,13 +192,9 @@ async fn init_task(mut peripherals: arch::OptionalPeripherals) { wifi::cyw43::join(control).await; }; - let init_args = InitializationArgs { - peripherals: make_static!(Mutex::new(peripherals)), - }; - for task in EMBASSY_TASKS { // TODO: should all tasks be initialized before starting the first one? - match task(&mut *init_args.peripherals.lock().await, init_args) { + match task(&mut peripherals) { Ok(initialized_application) => initialized_application.start(spawner, drivers), Err(err) => panic!("Error while initializing an application: {err:?}"), } @@ -232,7 +218,6 @@ pub trait Application { /// The [`assign_resources!`] macro can be leveraged to extract the required peripherals. fn initialize( peripherals: &mut arch::OptionalPeripherals, - init_args: InitializationArgs, ) -> Result<&dyn Application, ApplicationInitError> where Self: Sized; @@ -271,9 +256,8 @@ macro_rules! riot_initialize { #[linkme(crate = $crate::linkme)] fn __init_application( peripherals: &mut $crate::arch::OptionalPeripherals, - init_args: $crate::InitializationArgs, ) -> Result<&dyn $crate::Application, $crate::ApplicationInitError> { - <$prog_type as Application>::initialize(peripherals, init_args) + <$prog_type as Application>::initialize(peripherals) } }; } From 6777e06b46ed7a0328e3d693c458b400e2192c12 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Sat, 17 Feb 2024 14:41:08 +0100 Subject: [PATCH 2/2] examples/*: drop use of InitializationArgs --- examples/application/src/main.rs | 3 +-- examples/embassy-http-server/src/main.rs | 4 +--- examples/embassy-net-tcp/src/main.rs | 3 +-- examples/embassy-net-udp/src/main.rs | 3 +-- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/examples/application/src/main.rs b/examples/application/src/main.rs index f5e3bfcee..b5c97313e 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, InitializationArgs}; +use riot_rs::embassy::{arch, Application, ApplicationInitError, Drivers}; use riot_rs::rt::debug::println; @@ -14,7 +14,6 @@ struct MyApplication { impl Application for MyApplication { fn initialize( _peripherals: &mut arch::OptionalPeripherals, - _init_args: InitializationArgs, ) -> Result<&dyn Application, ApplicationInitError> { println!("MyApplication::initialize()"); Ok(&Self { state: 0 }) diff --git a/examples/embassy-http-server/src/main.rs b/examples/embassy-http-server/src/main.rs index aa53bd713..ca510caca 100644 --- a/examples/embassy-http-server/src/main.rs +++ b/examples/embassy-http-server/src/main.rs @@ -9,8 +9,7 @@ mod routes; use riot_rs as _; use riot_rs::embassy::{ - arch::OptionalPeripherals, Application, ApplicationInitError, Drivers, InitializationArgs, - NetworkStack, + arch::OptionalPeripherals, Application, ApplicationInitError, Drivers, NetworkStack, }; use riot_rs::rt::debug::println; @@ -95,7 +94,6 @@ struct WebServer { impl Application for WebServer { fn initialize( peripherals: &mut OptionalPeripherals, - _init_args: InitializationArgs, ) -> Result<&dyn Application, ApplicationInitError> { #[cfg(feature = "button-readings")] let button_inputs = { diff --git a/examples/embassy-net-tcp/src/main.rs b/examples/embassy-net-tcp/src/main.rs index c768d9272..08da16e13 100644 --- a/examples/embassy-net-tcp/src/main.rs +++ b/examples/embassy-net-tcp/src/main.rs @@ -3,7 +3,7 @@ #![feature(type_alias_impl_trait)] #![feature(used_with_arg)] -use riot_rs::embassy::{arch, Application, ApplicationInitError, Drivers, InitializationArgs}; +use riot_rs::embassy::{arch, Application, ApplicationInitError, Drivers}; use riot_rs::rt::debug::println; @@ -61,7 +61,6 @@ struct TcpEcho {} impl Application for TcpEcho { fn initialize( _peripherals: &mut arch::OptionalPeripherals, - _init_args: InitializationArgs, ) -> Result<&dyn Application, ApplicationInitError> { Ok(&Self {}) } diff --git a/examples/embassy-net-udp/src/main.rs b/examples/embassy-net-udp/src/main.rs index 3a0e6443a..f8d33f9f8 100644 --- a/examples/embassy-net-udp/src/main.rs +++ b/examples/embassy-net-udp/src/main.rs @@ -3,7 +3,7 @@ #![feature(type_alias_impl_trait)] #![feature(used_with_arg)] -use riot_rs::embassy::{arch, Application, ApplicationInitError, Drivers, InitializationArgs}; +use riot_rs::embassy::{arch, Application, ApplicationInitError, Drivers}; use riot_rs::rt::debug::println; @@ -66,7 +66,6 @@ struct UdpEcho {} impl Application for UdpEcho { fn initialize( _peripherals: &mut arch::OptionalPeripherals, - _init_args: InitializationArgs, ) -> Result<&dyn Application, ApplicationInitError> { Ok(&Self {}) }