diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-10-21 21:03:51 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-10-21 21:03:51 +0000 |
| commit | ce1cba761c2942b7faa27f4098487c6468784729 (patch) | |
| tree | fbce880d165f6e660253bbefa40ac637e1362029 /examples | |
| parent | 495ca6108ce6febb06ae5438834935541be5a04f (diff) | |
| parent | a4afab46403aacd7bb555cadaefad7f216fb9931 (diff) | |
Merge #855
855: PDM microphone support for nrf r=Dirbaio a=pbert519
PDM microphones have a long startup phase, therefore the driver samples continuously and only switches the target buffer if the user requests sampling.
Co-authored-by: pbert <[email protected]>
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf/src/bin/pdm.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/examples/nrf/src/bin/pdm.rs b/examples/nrf/src/bin/pdm.rs new file mode 100644 index 000000000..7388580fb --- /dev/null +++ b/examples/nrf/src/bin/pdm.rs | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::info; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_nrf::interrupt; | ||
| 8 | use embassy_nrf::pdm::{Config, Pdm}; | ||
| 9 | use embassy_time::{Duration, Timer}; | ||
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 11 | |||
| 12 | #[embassy_executor::main] | ||
| 13 | async fn main(_p: Spawner) { | ||
| 14 | let p = embassy_nrf::init(Default::default()); | ||
| 15 | let config = Config::default(); | ||
| 16 | let mut pdm = Pdm::new(p.PDM, interrupt::take!(PDM), p.P0_01, p.P0_00, config); | ||
| 17 | |||
| 18 | loop { | ||
| 19 | pdm.start().await; | ||
| 20 | |||
| 21 | // wait some time till the microphon settled | ||
| 22 | Timer::after(Duration::from_millis(1000)).await; | ||
| 23 | |||
| 24 | const SAMPLES: usize = 2048; | ||
| 25 | let mut buf = [0i16; SAMPLES]; | ||
| 26 | pdm.sample(&mut buf).await.unwrap(); | ||
| 27 | |||
| 28 | info!("samples: {:?}", &buf); | ||
| 29 | |||
| 30 | pdm.stop().await; | ||
| 31 | Timer::after(Duration::from_millis(100)).await; | ||
| 32 | } | ||
| 33 | } | ||
