diff options
| author | Quentin Smith <[email protected]> | 2023-07-18 17:17:04 -0400 |
|---|---|---|
| committer | Quentin Smith <[email protected]> | 2023-07-18 17:17:04 -0400 |
| commit | 2c01f277c27bc6ca4f3d41ac57aa1ea24868cfc1 (patch) | |
| tree | b5a407f457472fc70dafc3ced5e0744f25443f35 /embassy-nrf | |
| parent | c333d855fca0743de1d58ef14e3c2f6389f73145 (diff) | |
cargo fmt
Diffstat (limited to 'embassy-nrf')
| -rw-r--r-- | embassy-nrf/src/pdm.rs | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/embassy-nrf/src/pdm.rs b/embassy-nrf/src/pdm.rs index f2675bb7a..48668c7f4 100644 --- a/embassy-nrf/src/pdm.rs +++ b/embassy-nrf/src/pdm.rs | |||
| @@ -8,17 +8,17 @@ use core::task::Poll; | |||
| 8 | 8 | ||
| 9 | use embassy_hal_common::drop::OnDrop; | 9 | use embassy_hal_common::drop::OnDrop; |
| 10 | use embassy_hal_common::{into_ref, PeripheralRef}; | 10 | use embassy_hal_common::{into_ref, PeripheralRef}; |
| 11 | use futures::future::poll_fn; | ||
| 12 | use fixed::types::I7F1; | 11 | use fixed::types::I7F1; |
| 12 | use futures::future::poll_fn; | ||
| 13 | 13 | ||
| 14 | use crate::chip::EASY_DMA_SIZE; | 14 | use crate::chip::EASY_DMA_SIZE; |
| 15 | use crate::gpio::sealed::Pin; | 15 | use crate::gpio::sealed::Pin; |
| 16 | use crate::gpio::{AnyPin, Pin as GpioPin}; | 16 | use crate::gpio::{AnyPin, Pin as GpioPin}; |
| 17 | use crate::interrupt::typelevel::Interrupt; | 17 | use crate::interrupt::typelevel::Interrupt; |
| 18 | use crate::{interrupt, Peripheral}; | ||
| 19 | use crate::pac::pdm::mode::{EDGE_A, OPERATION_A}; | 18 | use crate::pac::pdm::mode::{EDGE_A, OPERATION_A}; |
| 20 | pub use crate::pac::pdm::pdmclkctrl::FREQ_A as Frequency; | 19 | pub use crate::pac::pdm::pdmclkctrl::FREQ_A as Frequency; |
| 21 | pub use crate::pac::pdm::ratio::RATIO_A as Ratio; | 20 | pub use crate::pac::pdm::ratio::RATIO_A as Ratio; |
| 21 | use crate::{interrupt, Peripheral}; | ||
| 22 | 22 | ||
| 23 | /// Interrupt handler. | 23 | /// Interrupt handler. |
| 24 | pub struct InterruptHandler<T: Instance> { | 24 | pub struct InterruptHandler<T: Instance> { |
| @@ -133,8 +133,14 @@ impl<'d, T: Instance> Pdm<'d, T> { | |||
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | fn _set_gain(r: &crate::pac::pdm::RegisterBlock, gain_left: I7F1, gain_right: I7F1) { | 135 | fn _set_gain(r: &crate::pac::pdm::RegisterBlock, gain_left: I7F1, gain_right: I7F1) { |
| 136 | let gain_left = gain_left.saturating_add(I7F1::from_bits(40)).saturating_to_num::<u8>().clamp(0, 0x50); | 136 | let gain_left = gain_left |
| 137 | let gain_right = gain_right.saturating_add(I7F1::from_bits(40)).saturating_to_num::<u8>().clamp(0, 0x50); | 137 | .saturating_add(I7F1::from_bits(40)) |
| 138 | .saturating_to_num::<u8>() | ||
| 139 | .clamp(0, 0x50); | ||
| 140 | let gain_right = gain_right | ||
| 141 | .saturating_add(I7F1::from_bits(40)) | ||
| 142 | .saturating_to_num::<u8>() | ||
| 143 | .clamp(0, 0x50); | ||
| 138 | 144 | ||
| 139 | r.gainl.write(|w| unsafe { w.gainl().bits(gain_left) }); | 145 | r.gainl.write(|w| unsafe { w.gainl().bits(gain_left) }); |
| 140 | r.gainr.write(|w| unsafe { w.gainr().bits(gain_right) }); | 146 | r.gainr.write(|w| unsafe { w.gainr().bits(gain_right) }); |
| @@ -258,7 +264,8 @@ impl<'d, T: Instance> Pdm<'d, T> { | |||
| 258 | &mut self, | 264 | &mut self, |
| 259 | bufs: &mut [[i16; N]; 2], | 265 | bufs: &mut [[i16; N]; 2], |
| 260 | mut sampler: S, | 266 | mut sampler: S, |
| 261 | ) -> Result<(), Error> where | 267 | ) -> Result<(), Error> |
| 268 | where | ||
| 262 | S: FnMut(&[i16; N]) -> SamplerState, | 269 | S: FnMut(&[i16; N]) -> SamplerState, |
| 263 | { | 270 | { |
| 264 | let r = T::regs(); | 271 | let r = T::regs(); |
| @@ -267,7 +274,9 @@ impl<'d, T: Instance> Pdm<'d, T> { | |||
| 267 | return Err(Error::AlreadyRunning); | 274 | return Err(Error::AlreadyRunning); |
| 268 | } | 275 | } |
| 269 | 276 | ||
| 270 | r.sample.ptr.write(|w| unsafe { w.sampleptr().bits(bufs[0].as_mut_ptr() as u32) }); | 277 | r.sample |
| 278 | .ptr | ||
| 279 | .write(|w| unsafe { w.sampleptr().bits(bufs[0].as_mut_ptr() as u32) }); | ||
| 271 | r.sample.maxcnt.write(|w| unsafe { w.buffsize().bits(N as _) }); | 280 | r.sample.maxcnt.write(|w| unsafe { w.buffsize().bits(N as _) }); |
| 272 | 281 | ||
| 273 | // Reset and enable the events | 282 | // Reset and enable the events |
| @@ -285,7 +294,7 @@ impl<'d, T: Instance> Pdm<'d, T> { | |||
| 285 | // wouldn't happen anyway. | 294 | // wouldn't happen anyway. |
| 286 | compiler_fence(Ordering::SeqCst); | 295 | compiler_fence(Ordering::SeqCst); |
| 287 | 296 | ||
| 288 | r.tasks_start.write(|w| { w.tasks_start().set_bit() }); | 297 | r.tasks_start.write(|w| w.tasks_start().set_bit()); |
| 289 | 298 | ||
| 290 | let mut current_buffer = 0; | 299 | let mut current_buffer = 0; |
| 291 | 300 | ||
| @@ -309,7 +318,8 @@ impl<'d, T: Instance> Pdm<'d, T> { | |||
| 309 | r.events_end.reset(); | 318 | r.events_end.reset(); |
| 310 | r.intenset.write(|w| w.end().set()); | 319 | r.intenset.write(|w| w.end().set()); |
| 311 | 320 | ||
| 312 | if !done { // Discard the last buffer after the user requested a stop. | 321 | if !done { |
| 322 | // Discard the last buffer after the user requested a stop. | ||
| 313 | if sampler(&bufs[current_buffer]) == SamplerState::Sampled { | 323 | if sampler(&bufs[current_buffer]) == SamplerState::Sampled { |
| 314 | let next_buffer = 1 - current_buffer; | 324 | let next_buffer = 1 - current_buffer; |
| 315 | current_buffer = next_buffer; | 325 | current_buffer = next_buffer; |
