aboutsummaryrefslogtreecommitdiff
path: root/examples/rp/src/bin/wifi_scan.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-05-30 23:22:34 +0200
committerDario Nieuwenhuis <[email protected]>2023-05-30 23:26:29 +0200
commit3f35a8876ee65d030e32ab2444bc0abb29d88382 (patch)
tree2b456e04f83b22cad28632034680e0227292a7f8 /examples/rp/src/bin/wifi_scan.rs
parentb3bbe5eb2d0f7ec6c8cae6e0486cb46a433fe11a (diff)
cyw43: adapt build to main embassy repo.
Diffstat (limited to 'examples/rp/src/bin/wifi_scan.rs')
-rw-r--r--examples/rp/src/bin/wifi_scan.rs75
1 files changed, 75 insertions, 0 deletions
diff --git a/examples/rp/src/bin/wifi_scan.rs b/examples/rp/src/bin/wifi_scan.rs
new file mode 100644
index 000000000..aa5e5a399
--- /dev/null
+++ b/examples/rp/src/bin/wifi_scan.rs
@@ -0,0 +1,75 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4#![feature(async_fn_in_trait)]
5#![allow(incomplete_features)]
6
7use core::str;
8
9use cyw43_pio::PioSpi;
10use defmt::*;
11use embassy_executor::Spawner;
12use embassy_net::Stack;
13use embassy_rp::gpio::{Level, Output};
14use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0};
15use embassy_rp::pio::Pio;
16use static_cell::StaticCell;
17use {defmt_rtt as _, panic_probe as _};
18
19macro_rules! singleton {
20 ($val:expr) => {{
21 type T = impl Sized;
22 static STATIC_CELL: StaticCell<T> = StaticCell::new();
23 STATIC_CELL.init_with(move || $val)
24 }};
25}
26
27#[embassy_executor::task]
28async fn wifi_task(
29 runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>,
30) -> ! {
31 runner.run().await
32}
33
34#[embassy_executor::task]
35async fn net_task(stack: &'static Stack<cyw43::NetDriver<'static>>) -> ! {
36 stack.run().await
37}
38
39#[embassy_executor::main]
40async fn main(spawner: Spawner) {
41 info!("Hello World!");
42
43 let p = embassy_rp::init(Default::default());
44
45 let fw = include_bytes!("../../../../cyw43-firmware/43439A0.bin");
46 let clm = include_bytes!("../../../../cyw43-firmware/43439A0_clm.bin");
47
48 // To make flashing faster for development, you may want to flash the firmwares independently
49 // at hardcoded addresses, instead of baking them into the program with `include_bytes!`:
50 // probe-rs-cli download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000
51 // probe-rs-cli download 43439A0_clm.bin --format bin --chip RP2040 --base-address 0x10140000
52 //let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) };
53 //let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) };
54
55 let pwr = Output::new(p.PIN_23, Level::Low);
56 let cs = Output::new(p.PIN_25, Level::High);
57 let mut pio = Pio::new(p.PIO0);
58 let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0);
59
60 let state = singleton!(cyw43::State::new());
61 let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
62 unwrap!(spawner.spawn(wifi_task(runner)));
63
64 control.init(clm).await;
65 control
66 .set_power_management(cyw43::PowerManagementMode::PowerSave)
67 .await;
68
69 let mut scanner = control.scan().await;
70 while let Some(bss) = scanner.next().await {
71 if let Ok(ssid_str) = str::from_utf8(&bss.ssid) {
72 info!("scanned {} == {:x}", ssid_str, bss.bssid);
73 }
74 }
75}