aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf
diff options
context:
space:
mode:
authorFrank Plowman <[email protected]>2024-02-16 20:45:58 +0000
committerFrank Plowman <[email protected]>2024-02-16 20:45:58 +0000
commit07987aea4e2706d8a7fa252ba3f6e31d576537ee (patch)
treed001b323d5747a665de816b9d58066fd76fe03ba /embassy-nrf
parentc5f39d5c89240d17b0d7c8ee48fc48757c163bba (diff)
embassy-nrf: Fix various typos and make style more consistent
Diffstat (limited to 'embassy-nrf')
-rw-r--r--embassy-nrf/src/pdm.rs40
1 files changed, 20 insertions, 20 deletions
diff --git a/embassy-nrf/src/pdm.rs b/embassy-nrf/src/pdm.rs
index d03315fb6..dcaeffe0f 100644
--- a/embassy-nrf/src/pdm.rs
+++ b/embassy-nrf/src/pdm.rs
@@ -1,4 +1,4 @@
1//! Pulse Density Modulation (PDM) mirophone driver. 1//! Pulse Density Modulation (PDM) mirophone driver
2 2
3#![macro_use] 3#![macro_use]
4 4
@@ -26,7 +26,7 @@ pub use crate::pac::pdm::pdmclkctrl::FREQ_A as Frequency;
26pub use crate::pac::pdm::ratio::RATIO_A as Ratio; 26pub use crate::pac::pdm::ratio::RATIO_A as Ratio;
27use crate::{interrupt, Peripheral}; 27use crate::{interrupt, Peripheral};
28 28
29/// Interrupt handler. 29/// Interrupt handler
30pub struct InterruptHandler<T: Instance> { 30pub struct InterruptHandler<T: Instance> {
31 _phantom: PhantomData<T>, 31 _phantom: PhantomData<T>,
32} 32}
@@ -56,12 +56,12 @@ pub struct Pdm<'d, T: Instance> {
56 _peri: PeripheralRef<'d, T>, 56 _peri: PeripheralRef<'d, T>,
57} 57}
58 58
59/// PDM error. 59/// PDM error
60#[derive(Debug, Clone, Copy, PartialEq, Eq)] 60#[derive(Debug, Clone, Copy, PartialEq, Eq)]
61#[cfg_attr(feature = "defmt", derive(defmt::Format))] 61#[cfg_attr(feature = "defmt", derive(defmt::Format))]
62#[non_exhaustive] 62#[non_exhaustive]
63pub enum Error { 63pub enum Error {
64 /// Buffer is too long. 64 /// Buffer is too long
65 BufferTooLong, 65 BufferTooLong,
66 /// Buffer is empty 66 /// Buffer is empty
67 BufferZeroLength, 67 BufferZeroLength,
@@ -75,13 +75,13 @@ static DUMMY_BUFFER: [i16; 1] = [0; 1];
75 75
76/// The state of a continuously running sampler. While it reflects 76/// The state of a continuously running sampler. While it reflects
77/// the progress of a sampler, it also signals what should be done 77/// the progress of a sampler, it also signals what should be done
78/// next. For example, if the sampler has stopped then the Pdm implementation 78/// next. For example, if the sampler has stopped then the PDM implementation
79/// can then tear down its infrastructure. 79/// can then tear down its infrastructure
80#[derive(PartialEq)] 80#[derive(PartialEq)]
81pub enum SamplerState { 81pub enum SamplerState {
82 /// The sampler processed the samples and is ready for more. 82 /// The sampler processed the samples and is ready for more
83 Sampled, 83 Sampled,
84 /// The sampler is done processing samples. 84 /// The sampler is done processing samples
85 Stopped, 85 Stopped,
86} 86}
87 87
@@ -162,12 +162,12 @@ impl<'d, T: Instance> Pdm<'d, T> {
162 Self::_set_gain(T::regs(), gain_left, gain_right) 162 Self::_set_gain(T::regs(), gain_left, gain_right)
163 } 163 }
164 164
165 /// Start sampling microphon data into a dummy buffer 165 /// Start sampling microphone data into a dummy buffer.
166 /// Usefull to start the microphon and keep it active between recording samples 166 /// Useful to start the microphone and keep it active between recording samples.
167 pub async fn start(&mut self) { 167 pub async fn start(&mut self) {
168 let r = T::regs(); 168 let r = T::regs();
169 169
170 // start dummy sampling because microphon needs some setup time 170 // start dummy sampling because microphone needs some setup time
171 r.sample 171 r.sample
172 .ptr 172 .ptr
173 .write(|w| unsafe { w.sampleptr().bits(DUMMY_BUFFER.as_ptr() as u32) }); 173 .write(|w| unsafe { w.sampleptr().bits(DUMMY_BUFFER.as_ptr() as u32) });
@@ -178,14 +178,14 @@ impl<'d, T: Instance> Pdm<'d, T> {
178 r.tasks_start.write(|w| unsafe { w.bits(1) }); 178 r.tasks_start.write(|w| unsafe { w.bits(1) });
179 } 179 }
180 180
181 /// Stop sampling microphon data inta a dummy buffer 181 /// Stop sampling microphone data inta a dummy buffer
182 pub async fn stop(&mut self) { 182 pub async fn stop(&mut self) {
183 let r = T::regs(); 183 let r = T::regs();
184 r.tasks_stop.write(|w| unsafe { w.bits(1) }); 184 r.tasks_stop.write(|w| unsafe { w.bits(1) });
185 r.events_started.reset(); 185 r.events_started.reset();
186 } 186 }
187 187
188 /// Sample data into the given buffer. 188 /// Sample data into the given buffer
189 pub async fn sample(&mut self, buffer: &mut [i16]) -> Result<(), Error> { 189 pub async fn sample(&mut self, buffer: &mut [i16]) -> Result<(), Error> {
190 if buffer.len() == 0 { 190 if buffer.len() == 0 {
191 return Err(Error::BufferZeroLength); 191 return Err(Error::BufferZeroLength);
@@ -302,7 +302,7 @@ impl<'d, T: Instance> Pdm<'d, T> {
302 }); 302 });
303 303
304 // Don't reorder the start event before the previous writes. Hopefully self 304 // Don't reorder the start event before the previous writes. Hopefully self
305 // wouldn't happen anyway. 305 // wouldn't happen anyway
306 compiler_fence(Ordering::SeqCst); 306 compiler_fence(Ordering::SeqCst);
307 307
308 r.tasks_start.write(|w| unsafe { w.bits(1) }); 308 r.tasks_start.write(|w| unsafe { w.bits(1) });
@@ -313,11 +313,11 @@ impl<'d, T: Instance> Pdm<'d, T> {
313 313
314 let drop = OnDrop::new(|| { 314 let drop = OnDrop::new(|| {
315 r.tasks_stop.write(|w| unsafe { w.bits(1) }); 315 r.tasks_stop.write(|w| unsafe { w.bits(1) });
316 // N.B. It would be better if this were async, but Drop only support sync code. 316 // N.B. It would be better if this were async, but Drop only support sync code
317 while r.events_stopped.read().bits() != 0 {} 317 while r.events_stopped.read().bits() != 0 {}
318 }); 318 });
319 319
320 // Wait for events and complete when the sampler indicates it has had enough. 320 // Wait for events and complete when the sampler indicates it has had enough
321 poll_fn(|cx| { 321 poll_fn(|cx| {
322 let r = T::regs(); 322 let r = T::regs();
323 323
@@ -330,7 +330,7 @@ impl<'d, T: Instance> Pdm<'d, T> {
330 r.intenset.write(|w| w.end().set()); 330 r.intenset.write(|w| w.end().set());
331 331
332 if !done { 332 if !done {
333 // Discard the last buffer after the user requested a stop. 333 // Discard the last buffer after the user requested a stop
334 if sampler(&bufs[current_buffer]) == SamplerState::Sampled { 334 if sampler(&bufs[current_buffer]) == SamplerState::Sampled {
335 let next_buffer = 1 - current_buffer; 335 let next_buffer = 1 - current_buffer;
336 current_buffer = next_buffer; 336 current_buffer = next_buffer;
@@ -404,7 +404,7 @@ impl Default for Config {
404 } 404 }
405} 405}
406 406
407/// PDM operation mode. 407/// PDM operation mode
408#[derive(PartialEq)] 408#[derive(PartialEq)]
409pub enum OperationMode { 409pub enum OperationMode {
410 /// Mono (1 channel) 410 /// Mono (1 channel)
@@ -475,9 +475,9 @@ pub(crate) mod sealed {
475 } 475 }
476} 476}
477 477
478/// PDM peripheral instance. 478/// PDM peripheral instance
479pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send { 479pub trait Instance: Peripheral<P = Self> + sealed::Instance + 'static + Send {
480 /// Interrupt for this peripheral. 480 /// Interrupt for this peripheral
481 type Interrupt: interrupt::typelevel::Interrupt; 481 type Interrupt: interrupt::typelevel::Interrupt;
482} 482}
483 483