diff options
| -rw-r--r-- | examples/rp/src/bin/button.rs | 5 | ||||
| -rw-r--r-- | examples/rp/src/bin/wifi_blinky.rs | 59 |
2 files changed, 63 insertions, 1 deletions
diff --git a/examples/rp/src/bin/button.rs b/examples/rp/src/bin/button.rs index c5422c616..0d246c093 100644 --- a/examples/rp/src/bin/button.rs +++ b/examples/rp/src/bin/button.rs | |||
| @@ -9,9 +9,12 @@ use {defmt_rtt as _, panic_probe as _}; | |||
| 9 | #[embassy_executor::main] | 9 | #[embassy_executor::main] |
| 10 | async fn main(_spawner: Spawner) { | 10 | async fn main(_spawner: Spawner) { |
| 11 | let p = embassy_rp::init(Default::default()); | 11 | let p = embassy_rp::init(Default::default()); |
| 12 | let button = Input::new(p.PIN_28, Pull::Up); | ||
| 13 | let mut led = Output::new(p.PIN_25, Level::Low); | 12 | let mut led = Output::new(p.PIN_25, Level::Low); |
| 14 | 13 | ||
| 14 | // Use PIN_28, Pin34 on J0 for RP Pico, as a input. | ||
| 15 | // You need to add your own button. | ||
| 16 | let button = Input::new(p.PIN_28, Pull::Up); | ||
| 17 | |||
| 15 | loop { | 18 | loop { |
| 16 | if button.is_high() { | 19 | if button.is_high() { |
| 17 | led.set_high(); | 20 | led.set_high(); |
diff --git a/examples/rp/src/bin/wifi_blinky.rs b/examples/rp/src/bin/wifi_blinky.rs new file mode 100644 index 000000000..be965807b --- /dev/null +++ b/examples/rp/src/bin/wifi_blinky.rs | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use cyw43_pio::PioSpi; | ||
| 6 | use defmt::*; | ||
| 7 | use embassy_executor::Spawner; | ||
| 8 | use embassy_rp::gpio::{Level, Output}; | ||
| 9 | use embassy_rp::peripherals::{DMA_CH0, PIN_23, PIN_25, PIO0}; | ||
| 10 | use embassy_rp::pio::Pio; | ||
| 11 | use embassy_time::{Duration, Timer}; | ||
| 12 | use static_cell::make_static; | ||
| 13 | use {defmt_rtt as _, panic_probe as _}; | ||
| 14 | |||
| 15 | #[embassy_executor::task] | ||
| 16 | async fn wifi_task( | ||
| 17 | runner: cyw43::Runner<'static, Output<'static, PIN_23>, PioSpi<'static, PIN_25, PIO0, 0, DMA_CH0>>, | ||
| 18 | ) -> ! { | ||
| 19 | runner.run().await | ||
| 20 | } | ||
| 21 | |||
| 22 | #[embassy_executor::main] | ||
| 23 | async fn main(spawner: Spawner) { | ||
| 24 | let p = embassy_rp::init(Default::default()); | ||
| 25 | let fw = include_bytes!("../../../../cyw43-firmware/43439A0.bin"); | ||
| 26 | let clm = include_bytes!("../../../../cyw43-firmware/43439A0_clm.bin"); | ||
| 27 | |||
| 28 | // To make flashing faster for development, you may want to flash the firmwares independently | ||
| 29 | // at hardcoded addresses, instead of baking them into the program with `include_bytes!`: | ||
| 30 | // probe-rs-cli download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000 | ||
| 31 | // probe-rs-cli download 43439A0_clm.bin --format bin --chip RP2040 --base-address 0x10140000 | ||
| 32 | //let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) }; | ||
| 33 | //let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) }; | ||
| 34 | |||
| 35 | let pwr = Output::new(p.PIN_23, Level::Low); | ||
| 36 | let cs = Output::new(p.PIN_25, Level::High); | ||
| 37 | let mut pio = Pio::new(p.PIO0); | ||
| 38 | let spi = PioSpi::new(&mut pio.common, pio.sm0, pio.irq0, cs, p.PIN_24, p.PIN_29, p.DMA_CH0); | ||
| 39 | |||
| 40 | let state = make_static!(cyw43::State::new()); | ||
| 41 | let (_net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; | ||
| 42 | unwrap!(spawner.spawn(wifi_task(runner))); | ||
| 43 | |||
| 44 | control.init(clm).await; | ||
| 45 | control | ||
| 46 | .set_power_management(cyw43::PowerManagementMode::PowerSave) | ||
| 47 | .await; | ||
| 48 | |||
| 49 | let delay = Duration::from_secs(1); | ||
| 50 | loop { | ||
| 51 | info!("led on!"); | ||
| 52 | control.gpio_set(0, true).await; | ||
| 53 | Timer::after(delay).await; | ||
| 54 | |||
| 55 | info!("led off!"); | ||
| 56 | control.gpio_set(0, false).await; | ||
| 57 | Timer::after(delay).await; | ||
| 58 | } | ||
| 59 | } | ||
