embassy/examples/rpi-pico-w/src/main.rs

49 lines
1.2 KiB
Rust
Raw Normal View History

2022-07-10 19:45:26 +02:00
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait, concat_bytes)]
use core::slice;
use defmt::{assert, assert_eq, panic, *};
use embassy::executor::Spawner;
2022-07-11 00:25:35 +02:00
use embassy::util::Forever;
2022-07-10 19:45:26 +02:00
use embassy_rp::gpio::{Flex, Level, Output, Pin};
2022-07-11 00:25:35 +02:00
use embassy_rp::peripherals::{PIN_23, PIN_24, PIN_25, PIN_29};
2022-07-10 19:45:26 +02:00
use embassy_rp::Peripherals;
use {defmt_rtt as _, panic_probe as _};
macro_rules! forever {
($val:expr) => {{
type T = impl Sized;
static FOREVER: Forever<T> = Forever::new();
FOREVER.put_with(move || $val)
}};
}
2022-07-11 00:25:35 +02:00
#[embassy::task]
async fn wifi_task(runner: cyw43::Runner<'static, PIN_23, PIN_25, PIN_29, PIN_24>) -> ! {
runner.run().await
}
2022-07-10 19:45:26 +02:00
#[embassy::main]
2022-07-11 00:25:35 +02:00
async fn main(spawner: Spawner, p: Peripherals) {
2022-07-10 19:45:26 +02:00
info!("Hello World!");
let (pwr, cs, clk, dio) = (p.PIN_23, p.PIN_25, p.PIN_29, p.PIN_24);
//let (pwr, cs, clk, dio) = (p.PIN_23, p.PIN_0, p.PIN_1, p.PIN_2);
2022-07-11 00:25:35 +02:00
let state = forever!(cyw43::State::new());
let (mut control, runner) = cyw43::new(
state,
2022-07-10 19:45:26 +02:00
Output::new(pwr, Level::Low),
Output::new(cs, Level::High),
Output::new(clk, Level::Low),
Flex::new(dio),
2022-07-11 00:25:35 +02:00
)
.await;
2022-07-10 19:45:26 +02:00
2022-07-11 00:25:35 +02:00
spawner.spawn(wifi_task(runner)).unwrap();
2022-07-10 19:45:26 +02:00
2022-07-11 00:25:35 +02:00
control.init().await;
2022-07-10 19:45:26 +02:00
}