Skip to content

Commit

Permalink
examples/*: drop use of Application trait
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Feb 19, 2024
1 parent 2df03cc commit ad02804
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 140 deletions.
10 changes: 0 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions examples/application/Cargo.toml

This file was deleted.

5 changes: 0 additions & 5 deletions examples/application/README.md

This file was deleted.

4 changes: 0 additions & 4 deletions examples/application/laze.yml

This file was deleted.

28 changes: 0 additions & 28 deletions examples/application/src/main.rs

This file was deleted.

82 changes: 34 additions & 48 deletions examples/embassy-http-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<AppRouter, AppState> {
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<AppRouter, AppState> {
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;
Expand Down
23 changes: 7 additions & 16 deletions examples/embassy-net-tcp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 7 additions & 16 deletions examples/embassy-net-udp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion examples/laze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ defaults:
- riot-rs

subdirs:
- application
- benchmark
- bottles
- core-sizes
Expand Down

0 comments on commit ad02804

Please sign in to comment.