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

cleanup: drop Drivers #85

Merged
merged 2 commits into from
Feb 19, 2024
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
4 changes: 2 additions & 2 deletions examples/application/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()");
// ...
}
Expand Down
6 changes: 2 additions & 4 deletions examples/embassy-http-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<AppRouter, AppState> {
let router = picoserve::Router::new().route("/", get(routes::index));
#[cfg(feature = "button-readings")]
Expand Down
8 changes: 4 additions & 4 deletions examples/embassy-net-tcp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/embassy-net-udp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
}
}

Expand Down
16 changes: 2 additions & 14 deletions src/riot-rs-embassy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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:?}"),
}
}
Expand Down Expand Up @@ -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.
Expand Down
Loading