2022-07-10 20:12:25 +02:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
use defmt::info;
|
|
|
|
use embassy_executor::Spawner;
|
2023-03-05 20:50:45 +01:00
|
|
|
use embassy_nrf::pdm::{self, Config, Pdm};
|
|
|
|
use embassy_nrf::{bind_interrupts, peripherals};
|
2022-07-10 20:12:25 +02:00
|
|
|
use embassy_time::{Duration, Timer};
|
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
|
|
|
|
2023-03-05 20:50:45 +01:00
|
|
|
bind_interrupts!(struct Irqs {
|
|
|
|
PDM => pdm::InterruptHandler<peripherals::PDM>;
|
|
|
|
});
|
|
|
|
|
2022-07-10 20:12:25 +02:00
|
|
|
#[embassy_executor::main]
|
|
|
|
async fn main(_p: Spawner) {
|
|
|
|
let p = embassy_nrf::init(Default::default());
|
|
|
|
let config = Config::default();
|
2023-03-05 20:50:45 +01:00
|
|
|
let mut pdm = Pdm::new(p.PDM, Irqs, p.P0_01, p.P0_00, config);
|
2022-07-10 20:12:25 +02:00
|
|
|
|
|
|
|
loop {
|
|
|
|
pdm.start().await;
|
|
|
|
|
|
|
|
// wait some time till the microphon settled
|
|
|
|
Timer::after(Duration::from_millis(1000)).await;
|
|
|
|
|
|
|
|
const SAMPLES: usize = 2048;
|
|
|
|
let mut buf = [0i16; SAMPLES];
|
|
|
|
pdm.sample(&mut buf).await.unwrap();
|
|
|
|
|
|
|
|
info!("samples: {:?}", &buf);
|
|
|
|
|
|
|
|
pdm.stop().await;
|
|
|
|
Timer::after(Duration::from_millis(100)).await;
|
|
|
|
}
|
|
|
|
}
|