diff --git a/Cargo.lock b/Cargo.lock index 666aa43f6..d56e169bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,16 +11,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "application" -version = "0.1.0" -dependencies = [ - "embassy-executor", - "embassy-time", - "riot-rs", - "riot-rs-boards", -] - [[package]] name = "arrayvec" version = "0.7.4" diff --git a/examples/application/Cargo.toml b/examples/application/Cargo.toml deleted file mode 100644 index eb67bde58..000000000 --- a/examples/application/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "application" -version = "0.1.0" -authors.workspace = true -edition.workspace = true -publish = false - -[dependencies] -riot-rs = { path = "../../src/riot-rs" } -riot-rs-boards = { path = "../../src/riot-rs-boards" } -embassy-executor = { workspace = true, default-features = false } -embassy-time = { workspace = true, default-features = false } diff --git a/examples/application/README.md b/examples/application/README.md deleted file mode 100644 index 3f48b44f1..000000000 --- a/examples/application/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# application - -## About - -This folder contains a minimal `Application` example. diff --git a/examples/application/laze.yml b/examples/application/laze.yml deleted file mode 100644 index 7b93f3c0c..000000000 --- a/examples/application/laze.yml +++ /dev/null @@ -1,4 +0,0 @@ -apps: - - name: application - selects: - - ?release diff --git a/examples/application/src/main.rs b/examples/application/src/main.rs deleted file mode 100644 index 3ed23b8bf..000000000 --- a/examples/application/src/main.rs +++ /dev/null @@ -1,28 +0,0 @@ -#![no_main] -#![no_std] -#![feature(type_alias_impl_trait)] -#![feature(used_with_arg)] - -use riot_rs::embassy::{arch, Application, ApplicationInitError}; - -use riot_rs::rt::debug::println; - -struct MyApplication { - state: u32, // some state -} - -impl Application for MyApplication { - fn initialize( - _peripherals: &mut arch::OptionalPeripherals, - ) -> Result<&dyn Application, ApplicationInitError> { - println!("MyApplication::initialize()"); - Ok(&Self { state: 0 }) - } - - fn start(&self, _spawner: embassy_executor::Spawner) { - println!("MyApplication::start()"); - // ... - } -} - -riot_rs::embassy::riot_initialize!(MyApplication); diff --git a/examples/embassy-http-server/src/main.rs b/examples/embassy-http-server/src/main.rs index 4b240a68b..994b7c9a5 100644 --- a/examples/embassy-http-server/src/main.rs +++ b/examples/embassy-http-server/src/main.rs @@ -8,7 +8,7 @@ mod routes; use riot_rs as _; -use riot_rs::embassy::{arch::OptionalPeripherals, network, Application, ApplicationInitError}; +use riot_rs::embassy::network; use riot_rs::rt::debug::println; use embassy_net::tcp::TcpSocket; @@ -85,63 +85,49 @@ async fn web_task( } } -struct WebServer { +// TODO: macro up this up +use riot_rs::embassy::{arch::OptionalPeripherals, Spawner}; +#[riot_rs::embassy::distributed_slice(riot_rs::embassy::EMBASSY_TASKS)] +#[linkme(crate = riot_rs::embassy::linkme)] +fn web_server_init(spawner: &Spawner, peripherals: &mut OptionalPeripherals) { #[cfg(feature = "button-readings")] - button_inputs: ButtonInputs, -} - -impl Application for WebServer { - fn initialize( - peripherals: &mut OptionalPeripherals, - ) -> Result<&dyn Application, ApplicationInitError> { - #[cfg(feature = "button-readings")] - let button_inputs = { - let buttons = pins::Buttons::take_from(peripherals)?; - - let buttons = Buttons { - button1: Input::new(buttons.btn1.degrade(), Pull::Up), - button2: Input::new(buttons.btn2.degrade(), Pull::Up), - button3: Input::new(buttons.btn3.degrade(), Pull::Up), - button4: Input::new(buttons.btn4.degrade(), Pull::Up), - }; - - ButtonInputs(make_static!(Mutex::new(buttons))) + let button_inputs = { + let buttons = pins::Buttons::take_from(peripherals).unwrap(); + + let buttons = Buttons { + button1: Input::new(buttons.btn1.degrade(), Pull::Up), + button2: Input::new(buttons.btn2.degrade(), Pull::Up), + button3: Input::new(buttons.btn3.degrade(), Pull::Up), + button4: Input::new(buttons.btn4.degrade(), Pull::Up), }; - Ok(make_static!(Self { - #[cfg(feature = "button-readings")] - button_inputs, - })) - } + ButtonInputs(make_static!(Mutex::new(buttons))) + }; - 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")] - let router = router.route("/buttons", get(routes::buttons)); - router - } + fn make_app() -> picoserve::Router { + let router = picoserve::Router::new().route("/", get(routes::index)); + #[cfg(feature = "button-readings")] + let router = router.route("/buttons", get(routes::buttons)); + router + } - let app = make_static!(make_app()); + let app = make_static!(make_app()); - let config = make_static!(picoserve::Config::new(picoserve::Timeouts { - start_read_request: Some(Duration::from_secs(5)), - read_request: Some(Duration::from_secs(1)), - write: Some(Duration::from_secs(1)), - })); + let config = make_static!(picoserve::Config::new(picoserve::Timeouts { + start_read_request: Some(Duration::from_secs(5)), + read_request: Some(Duration::from_secs(1)), + write: Some(Duration::from_secs(1)), + })); - for id in 0..WEB_TASK_POOL_SIZE { - let app_state = AppState { - #[cfg(feature = "button-readings")] - buttons: self.button_inputs, - }; - spawner.spawn(web_task(id, app, config, app_state)).unwrap(); - } + for id in 0..WEB_TASK_POOL_SIZE { + let app_state = AppState { + #[cfg(feature = "button-readings")] + buttons: button_inputs, + }; + spawner.spawn(web_task(id, app, config, app_state)).unwrap(); } } -riot_rs::embassy::riot_initialize!(WebServer); - #[no_mangle] fn riot_rs_network_config() -> embassy_net::Config { use embassy_net::Ipv4Address; diff --git a/examples/embassy-net-tcp/src/main.rs b/examples/embassy-net-tcp/src/main.rs index 683b6c795..49533b90a 100644 --- a/examples/embassy-net-tcp/src/main.rs +++ b/examples/embassy-net-tcp/src/main.rs @@ -3,8 +3,7 @@ #![feature(type_alias_impl_trait)] #![feature(used_with_arg)] -use riot_rs::embassy::{arch, network, Application, ApplicationInitError}; - +use riot_rs::embassy::network; use riot_rs::rt::debug::println; use embedded_io_async::Write; @@ -56,22 +55,14 @@ async fn tcp_echo() { } } -struct TcpEcho {} - -impl Application for TcpEcho { - fn initialize( - _peripherals: &mut arch::OptionalPeripherals, - ) -> Result<&dyn Application, ApplicationInitError> { - Ok(&Self {}) - } - - fn start(&self, spawner: embassy_executor::Spawner) { - spawner.spawn(tcp_echo()).unwrap(); - } +// TODO: macro up this +use riot_rs::embassy::{arch::OptionalPeripherals, Spawner}; +#[riot_rs::embassy::distributed_slice(riot_rs::embassy::EMBASSY_TASKS)] +#[linkme(crate = riot_rs::embassy::linkme)] +fn __init_tcp_echo(spawner: &Spawner, _peripherals: &mut OptionalPeripherals) { + spawner.spawn(tcp_echo()).unwrap(); } -riot_rs::embassy::riot_initialize!(TcpEcho); - #[no_mangle] fn riot_rs_network_config() -> embassy_net::Config { use embassy_net::Ipv4Address; diff --git a/examples/embassy-net-udp/src/main.rs b/examples/embassy-net-udp/src/main.rs index e14638f79..1c213ae89 100644 --- a/examples/embassy-net-udp/src/main.rs +++ b/examples/embassy-net-udp/src/main.rs @@ -3,8 +3,7 @@ #![feature(type_alias_impl_trait)] #![feature(used_with_arg)] -use riot_rs::embassy::{arch, network, Application, ApplicationInitError}; - +use riot_rs::embassy::network; use riot_rs::rt::debug::println; #[embassy_executor::task] @@ -61,22 +60,14 @@ async fn udp_echo() { } } -struct UdpEcho {} - -impl Application for UdpEcho { - fn initialize( - _peripherals: &mut arch::OptionalPeripherals, - ) -> Result<&dyn Application, ApplicationInitError> { - Ok(&Self {}) - } - - fn start(&self, spawner: embassy_executor::Spawner) { - spawner.spawn(udp_echo()).unwrap(); - } +// TODO: macro up this +use riot_rs::embassy::{arch::OptionalPeripherals, Spawner}; +#[riot_rs::embassy::distributed_slice(riot_rs::embassy::EMBASSY_TASKS)] +#[linkme(crate = riot_rs::embassy::linkme)] +fn __init_udp_echo(spawner: &Spawner, _peripherals: &mut OptionalPeripherals) { + spawner.spawn(udp_echo()).unwrap(); } -riot_rs::embassy::riot_initialize!(UdpEcho); - #[no_mangle] fn riot_rs_network_config() -> embassy_net::Config { use embassy_net::Ipv4Address; diff --git a/examples/laze.yml b/examples/laze.yml index a7a53c748..dd66ac1cb 100644 --- a/examples/laze.yml +++ b/examples/laze.yml @@ -4,7 +4,6 @@ defaults: - riot-rs subdirs: - - application - benchmark - bottles - core-sizes