Skip to content

Commit

Permalink
Using ITIAT instead of TAIT
Browse files Browse the repository at this point in the history
Since Rust 1.81, the TAIT (Trait In Type Aliases) usage is disallowed.
Trialling ITIAT (Impl Trait In Associated Type)
  • Loading branch information
sammhicks committed Nov 27, 2024
1 parent 4b6be6e commit 55eca9b
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 187 deletions.
3 changes: 3 additions & 0 deletions examples/embassy/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rust-analyzer.check.allTargets": false,
}
10 changes: 5 additions & 5 deletions examples/embassy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ exclude = [

[workspace.dependencies]
cortex-m-rt = "0.7.3"
cyw43 = { version = "0.1.0", features = ["firmware-logs"] }
cyw43-pio = "0.1.0"
embassy-executor = { version = "0.5.0", features = ["arch-cortex-m", "executor-thread", "integrated-timers", "nightly"] }
cyw43 = { version = "0.2.0", features = ["firmware-logs"] }
cyw43-pio = "0.2.0"
embassy-executor = { version = "0.6.3", features = ["arch-cortex-m", "executor-thread", "integrated-timers", "nightly"] }
embassy-futures = "0.1.1"
embassy-net = { version = "0.4.0", features = ["tcp", "proto-ipv4", "medium-ethernet"] }
embassy-rp = { version = "0.1.0", features = ["critical-section-impl", "time-driver"] }
embassy-rp = { version = "0.2.0", features = ["critical-section-impl", "time-driver"] }
embassy-sync = "0.6.0"
embassy-time = "0.3.1"
embassy-usb-logger = "0.2.0"
Expand All @@ -27,4 +27,4 @@ panic-persist = { version = "0.3.0", features = ["utf8"] }
picoserve = { path = "../..", features = ["embassy"] }
portable-atomic = { version = "1.7.0", features = ["critical-section"], default-features = false }
rand = { version = "0.8.5", default-features = false }
static_cell = { version = "2.1.0", features = ["nightly"] }
static_cell = "2.1.0"
77 changes: 44 additions & 33 deletions examples/embassy/hello_world/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
#![feature(impl_trait_in_assoc_type)]

use cyw43_pio::PioSpi;
use embassy_rp::{
gpio::{Level, Output},
peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0},
peripherals::{DMA_CH0, PIO0},
pio::Pio,
};

use embassy_time::Duration;
use panic_persist as _;
use picoserve::routing::get;
use picoserve::{make_static, routing::get, AppBuilder, AppRouter};
use rand::Rng;
use static_cell::make_static;

embassy_rp::bind_interrupts!(struct Irqs {
PIO0_IRQ_0 => embassy_rp::pio::InterruptHandler<embassy_rp::peripherals::PIO0>;
Expand All @@ -28,11 +27,7 @@ async fn logger_task(usb: embassy_rp::peripherals::USB) {

#[embassy_executor::task]
async fn wifi_task(
runner: cyw43::Runner<
'static,
Output<'static, PIN_23>,
PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>,
>,
runner: cyw43::Runner<'static, Output<'static>, PioSpi<'static, PIO0, 0, DMA_CH0>>,
) -> ! {
runner.run().await
}
Expand All @@ -42,15 +37,23 @@ async fn net_task(stack: &'static embassy_net::Stack<cyw43::NetDriver<'static>>)
stack.run().await
}

type AppRouter = impl picoserve::routing::PathRouter;
struct AppProps;

impl AppBuilder for AppProps {
type Router = picoserve::Router<impl picoserve::routing::PathRouter>;

fn build_app(self) -> Self::Router {
picoserve::Router::new().route("/", get(|| async move { "Hello World" }))
}
}

const WEB_TASK_POOL_SIZE: usize = 8;

#[embassy_executor::task(pool_size = WEB_TASK_POOL_SIZE)]
async fn web_task(
id: usize,
stack: &'static embassy_net::Stack<cyw43::NetDriver<'static>>,
app: &'static picoserve::Router<AppRouter>,
app: &'static AppRouter<AppProps>,
config: &'static picoserve::Config<Duration>,
) -> ! {
let port = 80;
Expand Down Expand Up @@ -100,22 +103,31 @@ async fn main(spawner: embassy_executor::Spawner) {
p.DMA_CH0,
);

let state = make_static!(cyw43::State::new());
let state = make_static!(cyw43::State, cyw43::State::new());
let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
spawner.must_spawn(wifi_task(runner));

control.init(clm).await;

let stack = &*make_static!(embassy_net::Stack::new(
net_device,
embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address::new(192, 168, 0, 1), 24),
gateway: None,
dns_servers: Default::default(),
}),
make_static!(embassy_net::StackResources::<WEB_TASK_POOL_SIZE>::new()),
embassy_rp::clocks::RoscRng.gen(),
));
let stack = make_static!(
embassy_net::Stack<cyw43::NetDriver>,
embassy_net::Stack::new(
net_device,
embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
address: embassy_net::Ipv4Cidr::new(
embassy_net::Ipv4Address::new(192, 168, 0, 1),
24
),
gateway: None,
dns_servers: Default::default(),
}),
make_static!(
embassy_net::StackResources<WEB_TASK_POOL_SIZE>,
embassy_net::StackResources::new()
),
embassy_rp::clocks::RoscRng.gen(),
)
);

spawner.must_spawn(net_task(stack));

Expand All @@ -127,18 +139,17 @@ async fn main(spawner: embassy_executor::Spawner) {
)
.await;

fn make_app() -> picoserve::Router<AppRouter> {
picoserve::Router::new().route("/", get(|| async move { "Hello World" }))
}
let app = make_static!(AppRouter<AppProps>, AppProps.build_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)),
})
.keep_connection_alive());
let config = make_static!(
picoserve::Config<Duration>,
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)),
})
.keep_connection_alive()
);

for id in 0..WEB_TASK_POOL_SIZE {
spawner.must_spawn(web_task(id, stack, app, config));
Expand Down
3 changes: 3 additions & 0 deletions examples/embassy/hello_world_defmt/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rust-analyzer.check.allTargets": false,
}
10 changes: 5 additions & 5 deletions examples/embassy/hello_world_defmt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ edition = "2021"

[dependencies]
cortex-m-rt = "0.7.3"
cyw43 = { version = "0.1.0", features = ["firmware-logs"] }
cyw43-pio = "0.1.0"
cyw43 = { version = "0.2.0", features = ["firmware-logs"] }
cyw43-pio = "0.2.0"
defmt-rtt = "0.4.0"
embassy-executor = { version = "0.5.0", features = ["arch-cortex-m", "executor-thread", "integrated-timers", "nightly"] }
embassy-executor = { version = "0.6.3", features = ["arch-cortex-m", "executor-thread", "integrated-timers", "nightly"] }
embassy-futures = "0.1.1"
embassy-net = { version = "0.4.0", features = ["tcp", "proto-ipv4", "medium-ethernet"] }
embassy-rp = { version = "0.1.0", features = ["critical-section-impl", "time-driver"] }
embassy-sync = "0.5.0"
embassy-rp = { version = "0.2.0", features = ["critical-section-impl", "time-driver"] }
embassy-sync = "0.6.1"
embassy-time = { version = "0.3.0", features = ["defmt-timestamp-uptime"] }
embedded-io-async = "0.6.0"
example_secrets = { path = "../example_secrets" }
Expand Down
2 changes: 1 addition & 1 deletion examples/embassy/hello_world_defmt/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
targets = ["thumbv6m-none-eabi"]
channel = "nightly-2024-06-12"
channel = "nightly-2024-11-04"
77 changes: 44 additions & 33 deletions examples/embassy/hello_world_defmt/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
#![feature(impl_trait_in_assoc_type)]

use cyw43_pio::PioSpi;
use embassy_rp::{
gpio::{Level, Output},
peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0},
peripherals::{DMA_CH0, PIO0},
pio::Pio,
};

use defmt_rtt as _;
use embassy_time::Duration;
use panic_probe as _;
use picoserve::routing::get;
use picoserve::{make_static, routing::get, AppBuilder, AppRouter};
use rand::Rng;
use static_cell::make_static;

embassy_rp::bind_interrupts!(struct Irqs {
PIO0_IRQ_0 => embassy_rp::pio::InterruptHandler<embassy_rp::peripherals::PIO0>;
});

#[embassy_executor::task]
async fn wifi_task(
runner: cyw43::Runner<
'static,
Output<'static, PIN_23>,
PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>,
>,
runner: cyw43::Runner<'static, Output<'static>, PioSpi<'static, PIO0, 0, DMA_CH0>>,
) -> ! {
runner.run().await
}
Expand All @@ -36,15 +31,23 @@ async fn net_task(stack: &'static embassy_net::Stack<cyw43::NetDriver<'static>>)
stack.run().await
}

type AppRouter = impl picoserve::routing::PathRouter;
struct AppProps;

impl AppBuilder for AppProps {
type Router = picoserve::Router<impl picoserve::routing::PathRouter>;

fn build_app(self) -> Self::Router {
picoserve::Router::new().route("/", get(|| async move { "Hello World" }))
}
}

const WEB_TASK_POOL_SIZE: usize = 8;

#[embassy_executor::task(pool_size = WEB_TASK_POOL_SIZE)]
async fn web_task(
id: usize,
stack: &'static embassy_net::Stack<cyw43::NetDriver<'static>>,
app: &'static picoserve::Router<AppRouter>,
app: &'static AppRouter<AppProps>,
config: &'static picoserve::Config<Duration>,
) -> ! {
let port = 80;
Expand Down Expand Up @@ -85,22 +88,31 @@ async fn main(spawner: embassy_executor::Spawner) {
p.DMA_CH0,
);

let state = make_static!(cyw43::State::new());
let state = make_static!(cyw43::State, cyw43::State::new());
let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
spawner.must_spawn(wifi_task(runner));

control.init(clm).await;

let stack = &*make_static!(embassy_net::Stack::new(
net_device,
embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address::new(192, 168, 0, 1), 24),
gateway: None,
dns_servers: Default::default(),
}),
make_static!(embassy_net::StackResources::<WEB_TASK_POOL_SIZE>::new()),
embassy_rp::clocks::RoscRng.gen(),
));
let stack = make_static!(
embassy_net::Stack::<cyw43::NetDriver>,
embassy_net::Stack::new(
net_device,
embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
address: embassy_net::Ipv4Cidr::new(
embassy_net::Ipv4Address::new(192, 168, 0, 1),
24
),
gateway: None,
dns_servers: Default::default(),
}),
make_static!(
embassy_net::StackResources::<WEB_TASK_POOL_SIZE>,
embassy_net::StackResources::new()
),
embassy_rp::clocks::RoscRng.gen(),
)
);

spawner.must_spawn(net_task(stack));

Expand All @@ -112,18 +124,17 @@ async fn main(spawner: embassy_executor::Spawner) {
)
.await;

fn make_app() -> picoserve::Router<AppRouter> {
picoserve::Router::new().route("/", get(|| async move { "Hello World" }))
}
let app = make_static!(AppRouter<AppProps>, AppProps.build_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)),
})
.keep_connection_alive());
let config = make_static!(
picoserve::Config::<Duration>,
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)),
})
.keep_connection_alive()
);

for id in 0..WEB_TASK_POOL_SIZE {
spawner.must_spawn(web_task(id, stack, app, config));
Expand Down
2 changes: 1 addition & 1 deletion examples/embassy/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
targets = ["thumbv6m-none-eabi"]
channel = "nightly-2024-06-12"
channel = "nightly-2024-11-04"
Loading

0 comments on commit 55eca9b

Please sign in to comment.