-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use bt_hci::controller::ExternalController; | ||
use cyw43_pio::PioSpi; | ||
use defmt::*; | ||
use embassy_executor::Spawner; | ||
use embassy_rp::bind_interrupts; | ||
use embassy_rp::clocks::RoscRng; | ||
use embassy_rp::gpio::{Level, Output}; | ||
use embassy_rp::peripherals::{DMA_CH0, PIO0}; | ||
use embassy_rp::pio::{InterruptHandler, Pio}; | ||
use rand_chacha::ChaCha12Rng; | ||
use rand_core::SeedableRng; | ||
use static_cell::StaticCell; | ||
use trouble_example_apps::ble_bas_central_sec; | ||
use {defmt_rtt as _, embassy_time as _, panic_probe as _}; | ||
|
||
bind_interrupts!(struct Irqs { | ||
PIO0_IRQ_0 => InterruptHandler<PIO0>; | ||
}); | ||
|
||
#[embassy_executor::task] | ||
async fn cyw43_task(runner: cyw43::Runner<'static, Output<'static>, PioSpi<'static, PIO0, 0, DMA_CH0>>) -> ! { | ||
runner.run().await | ||
} | ||
|
||
#[embassy_executor::main] | ||
async fn main(spawner: Spawner) { | ||
let p = embassy_rp::init(Default::default()); | ||
|
||
#[cfg(feature = "skip-cyw43-firmware")] | ||
let (fw, clm, btfw) = (&[], &[], &[]); | ||
|
||
#[cfg(not(feature = "skip-cyw43-firmware"))] | ||
let (fw, clm, btfw) = { | ||
// IMPORTANT | ||
// | ||
// Download and make sure these files from https://github.com/embassy-rs/embassy/tree/main/cyw43-firmware | ||
// are available in `./examples/rp-pico-w`. (should be automatic) | ||
// | ||
// IMPORTANT | ||
let fw = include_bytes!("../../cyw43-firmware/43439A0.bin"); | ||
let clm = include_bytes!("../../cyw43-firmware/43439A0_clm.bin"); | ||
let btfw = include_bytes!("../../cyw43-firmware/43439A0_btfw.bin"); | ||
(fw, clm, btfw) | ||
}; | ||
|
||
let pwr = Output::new(p.PIN_23, Level::Low); | ||
let cs = Output::new(p.PIN_25, Level::High); | ||
let mut pio = Pio::new(p.PIO0, Irqs); | ||
let spi = PioSpi::new( | ||
&mut pio.common, | ||
pio.sm0, | ||
cyw43_pio::DEFAULT_CLOCK_DIVIDER, | ||
pio.irq0, | ||
cs, | ||
p.PIN_24, | ||
p.PIN_29, | ||
p.DMA_CH0, | ||
); | ||
|
||
static STATE: StaticCell<cyw43::State> = StaticCell::new(); | ||
let state = STATE.init(cyw43::State::new()); | ||
let (_net_device, bt_device, mut control, runner) = cyw43::new_with_bluetooth(state, pwr, spi, fw, btfw).await; | ||
unwrap!(spawner.spawn(cyw43_task(runner))); | ||
control.init(clm).await; | ||
|
||
let mut rng = ChaCha12Rng::from_rng(&mut RoscRng).unwrap(); | ||
|
||
let controller: ExternalController<_, 10> = ExternalController::new(bt_device); | ||
|
||
ble_bas_central_sec::run::<_, _, 128>(controller, &mut rng).await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use bt_hci::controller::ExternalController; | ||
use cyw43_pio::PioSpi; | ||
use defmt::*; | ||
use embassy_executor::Spawner; | ||
use embassy_rp::bind_interrupts; | ||
use embassy_rp::clocks::RoscRng; | ||
use embassy_rp::gpio::{Level, Output}; | ||
use embassy_rp::peripherals::{DMA_CH0, PIO0}; | ||
use embassy_rp::pio::{InterruptHandler, Pio}; | ||
use rand_chacha::ChaCha12Rng; | ||
use rand_core::SeedableRng; | ||
use static_cell::StaticCell; | ||
use trouble_example_apps::ble_bas_peripheral_sec; | ||
use {defmt_rtt as _, embassy_time as _, panic_probe as _}; | ||
|
||
bind_interrupts!(struct Irqs { | ||
PIO0_IRQ_0 => InterruptHandler<PIO0>; | ||
}); | ||
|
||
#[embassy_executor::task] | ||
async fn cyw43_task(runner: cyw43::Runner<'static, Output<'static>, PioSpi<'static, PIO0, 0, DMA_CH0>>) -> ! { | ||
runner.run().await | ||
} | ||
|
||
#[embassy_executor::main] | ||
async fn main(spawner: Spawner) { | ||
let p = embassy_rp::init(Default::default()); | ||
|
||
#[cfg(feature = "skip-cyw43-firmware")] | ||
let (fw, clm, btfw) = (&[], &[], &[]); | ||
|
||
#[cfg(not(feature = "skip-cyw43-firmware"))] | ||
let (fw, clm, btfw) = { | ||
// IMPORTANT | ||
// | ||
// Download and make sure these files from https://github.com/embassy-rs/embassy/tree/main/cyw43-firmware | ||
// are available in `./examples/rp-pico-w`. (should be automatic) | ||
// | ||
// IMPORTANT | ||
let fw = include_bytes!("../../cyw43-firmware/43439A0.bin"); | ||
let clm = include_bytes!("../../cyw43-firmware/43439A0_clm.bin"); | ||
let btfw = include_bytes!("../../cyw43-firmware/43439A0_btfw.bin"); | ||
(fw, clm, btfw) | ||
}; | ||
|
||
let pwr = Output::new(p.PIN_23, Level::Low); | ||
let cs = Output::new(p.PIN_25, Level::High); | ||
let mut pio = Pio::new(p.PIO0, Irqs); | ||
let spi = PioSpi::new( | ||
&mut pio.common, | ||
pio.sm0, | ||
cyw43_pio::DEFAULT_CLOCK_DIVIDER, | ||
pio.irq0, | ||
cs, | ||
p.PIN_24, | ||
p.PIN_29, | ||
p.DMA_CH0, | ||
); | ||
|
||
static STATE: StaticCell<cyw43::State> = StaticCell::new(); | ||
let state = STATE.init(cyw43::State::new()); | ||
let (_net_device, bt_device, mut control, runner) = cyw43::new_with_bluetooth(state, pwr, spi, fw, btfw).await; | ||
unwrap!(spawner.spawn(cyw43_task(runner))); | ||
control.init(clm).await; | ||
|
||
let mut rng = ChaCha12Rng::from_rng(&mut RoscRng).unwrap(); | ||
|
||
let controller: ExternalController<_, 10> = ExternalController::new(bt_device); | ||
|
||
ble_bas_peripheral_sec::run::<_, _, 128>(controller, &mut rng).await; | ||
} |