diff options
| author | Quentin Smith <[email protected]> | 2022-08-21 02:16:26 -0400 |
|---|---|---|
| committer | Quentin Smith <[email protected]> | 2022-08-21 02:16:26 -0400 |
| commit | ed97e61dbecc636c3cc9f67778d4b7eb48cff893 (patch) | |
| tree | 5e7a83a0167f0fd4eee31b4db2b1fb16a7277e5b /embassy-nrf | |
| parent | 029713eca0e6c4a17283891de77c69f27bbf1a54 (diff) | |
PDM clock frequency control
Diffstat (limited to 'embassy-nrf')
| -rw-r--r-- | embassy-nrf/src/pdm.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/embassy-nrf/src/pdm.rs b/embassy-nrf/src/pdm.rs index 6a070e7bc..b58a0e976 100644 --- a/embassy-nrf/src/pdm.rs +++ b/embassy-nrf/src/pdm.rs | |||
| @@ -9,6 +9,8 @@ use embassy_util::waitqueue::AtomicWaker; | |||
| 9 | use futures::future::poll_fn; | 9 | use futures::future::poll_fn; |
| 10 | use pac::{pdm, PDM}; | 10 | use pac::{pdm, PDM}; |
| 11 | use pdm::mode::{EDGE_A, OPERATION_A}; | 11 | use pdm::mode::{EDGE_A, OPERATION_A}; |
| 12 | pub use pdm::pdmclkctrl::FREQ_A as Frequency; | ||
| 13 | pub use pdm::ratio::RATIO_A as Ratio; | ||
| 12 | use fixed::types::I7F1; | 14 | use fixed::types::I7F1; |
| 13 | 15 | ||
| 14 | use crate::interrupt::InterruptExt; | 16 | use crate::interrupt::InterruptExt; |
| @@ -32,8 +34,10 @@ static WAKER: AtomicWaker = AtomicWaker::new(); | |||
| 32 | /// See the `Default` impl for suitable default values. | 34 | /// See the `Default` impl for suitable default values. |
| 33 | #[non_exhaustive] | 35 | #[non_exhaustive] |
| 34 | pub struct Config { | 36 | pub struct Config { |
| 35 | /// Clock | 37 | /// Clock frequency |
| 38 | pub frequency: Frequency, | ||
| 36 | /// Clock ratio | 39 | /// Clock ratio |
| 40 | pub ratio: Ratio, | ||
| 37 | /// Channels | 41 | /// Channels |
| 38 | pub channels: Channels, | 42 | pub channels: Channels, |
| 39 | /// Edge to sample on | 43 | /// Edge to sample on |
| @@ -48,6 +52,8 @@ impl Default for Config { | |||
| 48 | /// Default configuration for single channel sampling. | 52 | /// Default configuration for single channel sampling. |
| 49 | fn default() -> Self { | 53 | fn default() -> Self { |
| 50 | Self { | 54 | Self { |
| 55 | frequency: Frequency::DEFAULT, | ||
| 56 | ratio: Ratio::RATIO80, | ||
| 51 | channels: Channels::Stereo, | 57 | channels: Channels::Stereo, |
| 52 | left_edge: Edge::FallingEdge, | 58 | left_edge: Edge::FallingEdge, |
| 53 | gain_left: I7F1::ZERO, | 59 | gain_left: I7F1::ZERO, |
| @@ -78,11 +84,12 @@ impl<'d> Pdm<'d> { | |||
| 78 | 84 | ||
| 79 | let r = unsafe { &*PDM::ptr() }; | 85 | let r = unsafe { &*PDM::ptr() }; |
| 80 | 86 | ||
| 81 | let Config { channels, left_edge, gain_left, gain_right } = config; | 87 | let Config { frequency, ratio, channels, left_edge, gain_left, gain_right } = config; |
| 82 | 88 | ||
| 83 | // Configure channels | 89 | // Configure channels |
| 84 | r.enable.write(|w| w.enable().enabled()); | 90 | r.enable.write(|w| w.enable().enabled()); |
| 85 | // TODO: Clock control | 91 | r.pdmclkctrl.write(|w| w.freq().variant(frequency)); |
| 92 | r.ratio.write(|w| w.ratio().variant(ratio)); | ||
| 86 | r.mode.write(|w| { | 93 | r.mode.write(|w| { |
| 87 | w.operation().variant(channels.into()); | 94 | w.operation().variant(channels.into()); |
| 88 | w.edge().variant(left_edge.into()); | 95 | w.edge().variant(left_edge.into()); |
