pub struct I2sTransfer<I, MS, DIR, STD, FMT>
where I: I2sPeripheral, (STD, FMT): FrameFormat,
{ /* private fields */ }
Expand description

Abstraction allowing sending and receiving of I2S data while erasing hardware details.

This type is meant to implement the upcoming embeded-hal I2S trait.

§Implementation notes

I2sTransfer in slave mode never fails when an error is detected. Instead, it tries to recover although some data may corrupted. This choice has been made because:

  • corrupted data can’t produce invalid audio values and therefore can’t cause undefined behavior,
  • audio quality is equally degraded by missing or corrupted data,
  • it’s easier to use.

I2sTransfer in master receive mode fails when an overrun occurs. This is because I2sTransfer resets clocks to recover and some parts of the peripheral need to be reset during this process.

I2sTransfer in master transmit never fails because the hardware can’t detect errors in this mode.

Implementations§

source§

impl<I, MS, DIR, STD, FMT> I2sTransfer<I, MS, DIR, STD, FMT>
where I: I2sPeripheral, STD: I2sStandard, FMT: DataFormat, (STD, FMT): FrameFormat,

Constructors and Destructors

source

pub fn new( i2s_peripheral: I, config: I2sTransferConfig<MS, DIR, STD, FMT> ) -> Self

Instantiate and configure an i2s driver around an I2sPeripheral.

§Panics

This method panics if an exact frequency is required by the config and that frequency cannot be set.

source

pub fn release(self) -> I

Destroy the transfer, release the owned i2s device, and reset its configuration.

source§

impl<I, MS, DIR, STD, FMT> I2sTransfer<I, MS, DIR, STD, FMT>
where I: I2sPeripheral, (STD, FMT): FrameFormat,

source

pub fn begin(&mut self)

Activate the I2s interface.

source§

impl<I, DIR, STD, FMT> I2sTransfer<I, Slave, DIR, STD, FMT>
where I: I2sPeripheral, (STD, FMT): FrameFormat,

source

pub fn end(&mut self)

Deactivate the I2s interface and reset internal state

source§

impl<I, DIR, STD, FMT> I2sTransfer<I, Master, DIR, STD, FMT>
where I: I2sPeripheral, (STD, FMT): FrameFormat,

source

pub fn end(&mut self)

Deactivate the I2s interface and reset internal state

source§

impl<I, DIR, STD, FMT> I2sTransfer<I, Master, DIR, STD, FMT>
where I: I2sPeripheral, (STD, FMT): FrameFormat,

source

pub fn sample_rate(&self) -> u32

source§

impl<I, STD, FMT> I2sTransfer<I, Master, Transmit, STD, FMT>
where I: I2sPeripheral, (STD, FMT): FrameFormat,

Master Transmit

source

pub fn write_iter<ITER, T>(&mut self, samples: ITER)
where T: ToRawFrame<STD, FMT>, ITER: IntoIterator<Item = T>,

Transmit (blocking) data from an iterator.

source

pub fn write<T: ToRawFrame<STD, FMT>>( &mut self, frame: T ) -> Result<(), Infallible>

Write one audio frame and activate the I2s interface if disabled.

To fully transmit the frame, this function need to be continuously called until the next frame can be written.

source§

impl<I, STD, FMT> I2sTransfer<I, Slave, Transmit, STD, FMT>
where I: I2sPeripheral, STD: I2sStandard, (STD, FMT): FrameFormat,

Slave Transmit

source

pub fn write_iter<ITER, T>(&mut self, frames: ITER)
where T: ToRawFrame<STD, FMT>, ITER: IntoIterator<Item = T>,

Transmit (blocking) data from an iterator.

source

pub fn write<T: ToRawFrame<STD, FMT>>( &mut self, frame: T ) -> Result<(), Infallible>

Write one audio frame and activate the I2s interface if disabled.

To fully transmit the frame, this function need to be continuously called until the next frame can be written.

source§

impl<I, STD, FMT> I2sTransfer<I, Master, Receive, STD, FMT>
where I: I2sPeripheral, (STD, FMT): FrameFormat,

Master Receive

source

pub fn read_while<F, T>(&mut self, predicate: F) -> Result<(), I2sTransferError>
where T: FromRawFrame<STD, FMT>, F: FnMut(T) -> bool,

Read samples while predicate return true.

The given closure must not block, otherwise communication problems may occur.

source

pub fn read<T: FromRawFrame<STD, FMT>>(&mut self) -> Result<T, I2sTransferError>

Read one audio frame and activate the I2s interface if disabled.

To get the audio frame, this function needs to be continuously called until the frame is returned

source§

impl<I, STD, FMT> I2sTransfer<I, Slave, Receive, STD, FMT>
where I: I2sPeripheral, STD: I2sStandard, (STD, FMT): FrameFormat,

source

pub fn read_while<F, T>(&mut self, predicate: F)
where T: FromRawFrame<STD, FMT>, F: FnMut(T) -> bool,

Read samples while predicate returns true.

The given closure must not block, otherwise communication problems may occur.

source

pub fn read<T: FromRawFrame<STD, FMT>>(&mut self) -> Result<T, Infallible>

Read one audio frame and activate the I2s interface if disabled.

To get the audio frame, this function need to be continuously called until the frame is returned

Auto Trait Implementations§

§

impl<I, MS, DIR, STD, FMT> !Freeze for I2sTransfer<I, MS, DIR, STD, FMT>

§

impl<I, MS, DIR, STD, FMT> !RefUnwindSafe for I2sTransfer<I, MS, DIR, STD, FMT>

§

impl<I, MS, DIR, STD, FMT> Send for I2sTransfer<I, MS, DIR, STD, FMT>
where DIR: Send, FMT: Send, I: Send, MS: Send, STD: Send,

§

impl<I, MS, DIR, STD, FMT> Sync for I2sTransfer<I, MS, DIR, STD, FMT>
where DIR: Sync, FMT: Sync, I: Sync, MS: Sync, STD: Sync,

§

impl<I, MS, DIR, STD, FMT> !Unpin for I2sTransfer<I, MS, DIR, STD, FMT>

§

impl<I, MS, DIR, STD, FMT> !UnwindSafe for I2sTransfer<I, MS, DIR, STD, FMT>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.