Struct stm32_i2s_v12x::transfer::I2sTransfer
source · 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>
impl<I, MS, DIR, STD, FMT> I2sTransfer<I, MS, DIR, STD, FMT>
Constructors and Destructors
sourcepub fn new(
i2s_peripheral: I,
config: I2sTransferConfig<MS, DIR, STD, FMT>
) -> Self
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§impl<I, MS, DIR, STD, FMT> I2sTransfer<I, MS, DIR, STD, FMT>where
I: I2sPeripheral,
(STD, FMT): FrameFormat,
impl<I, MS, DIR, STD, FMT> I2sTransfer<I, MS, DIR, STD, FMT>where
I: I2sPeripheral,
(STD, FMT): FrameFormat,
source§impl<I, DIR, STD, FMT> I2sTransfer<I, Slave, DIR, STD, FMT>where
I: I2sPeripheral,
(STD, FMT): FrameFormat,
impl<I, DIR, STD, FMT> I2sTransfer<I, Slave, DIR, STD, FMT>where
I: I2sPeripheral,
(STD, FMT): FrameFormat,
source§impl<I, DIR, STD, FMT> I2sTransfer<I, Master, DIR, STD, FMT>where
I: I2sPeripheral,
(STD, FMT): FrameFormat,
impl<I, DIR, STD, FMT> I2sTransfer<I, Master, DIR, STD, FMT>where
I: I2sPeripheral,
(STD, FMT): FrameFormat,
source§impl<I, DIR, STD, FMT> I2sTransfer<I, Master, DIR, STD, FMT>where
I: I2sPeripheral,
(STD, FMT): FrameFormat,
impl<I, DIR, STD, FMT> I2sTransfer<I, Master, DIR, STD, FMT>where
I: I2sPeripheral,
(STD, FMT): FrameFormat,
pub fn sample_rate(&self) -> u32
source§impl<I, STD, FMT> I2sTransfer<I, Master, Transmit, STD, FMT>where
I: I2sPeripheral,
(STD, FMT): FrameFormat,
impl<I, STD, FMT> I2sTransfer<I, Master, Transmit, STD, FMT>where
I: I2sPeripheral,
(STD, FMT): FrameFormat,
Master Transmit
sourcepub fn write_iter<ITER, T>(&mut self, samples: ITER)where
T: ToRawFrame<STD, FMT>,
ITER: IntoIterator<Item = T>,
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.
sourcepub fn write<T: ToRawFrame<STD, FMT>>(
&mut self,
frame: T
) -> Result<(), Infallible>
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>
impl<I, STD, FMT> I2sTransfer<I, Slave, Transmit, STD, FMT>
Slave Transmit
sourcepub fn write_iter<ITER, T>(&mut self, frames: ITER)where
T: ToRawFrame<STD, FMT>,
ITER: IntoIterator<Item = T>,
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.
sourcepub fn write<T: ToRawFrame<STD, FMT>>(
&mut self,
frame: T
) -> Result<(), Infallible>
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,
impl<I, STD, FMT> I2sTransfer<I, Master, Receive, STD, FMT>where
I: I2sPeripheral,
(STD, FMT): FrameFormat,
Master Receive
sourcepub fn read_while<F, T>(&mut self, predicate: F) -> Result<(), I2sTransferError>
pub fn read_while<F, T>(&mut self, predicate: F) -> Result<(), I2sTransferError>
Read samples while predicate return true
.
The given closure must not block, otherwise communication problems may occur.
sourcepub fn read<T: FromRawFrame<STD, FMT>>(&mut self) -> Result<T, I2sTransferError>
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>
impl<I, STD, FMT> I2sTransfer<I, Slave, Receive, STD, FMT>
sourcepub fn read_while<F, T>(&mut self, predicate: F)
pub fn read_while<F, T>(&mut self, predicate: F)
Read samples while predicate returns true
.
The given closure must not block, otherwise communication problems may occur.
sourcepub fn read<T: FromRawFrame<STD, FMT>>(&mut self) -> Result<T, Infallible>
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