embassy-stm32

Crates

git

Versions

stm32l4p5vg

Flavors

embassy_stm32::sai

Struct Sai

Source
pub struct Sai<'d, T: Instance, W: Word> { /* private fields */ }
Expand description

SAI sub-block driver.

Implementations§

Source§

impl<'d, T: Instance, W: Word> Sai<'d, T, W>

Source

pub fn new_asynchronous_with_mclk<S: SubBlockInstance>( peri: SubBlock<'d, T, S>, sck: impl Peripheral<P = impl SckPin<T, S>> + 'd, sd: impl Peripheral<P = impl SdPin<T, S>> + 'd, fs: impl Peripheral<P = impl FsPin<T, S>> + 'd, mclk: impl Peripheral<P = impl MclkPin<T, S>> + 'd, dma: impl Peripheral<P = impl Channel + Dma<T, S>> + 'd, dma_buf: &'d mut [W], config: Config, ) -> Self

Create a new SAI driver in asynchronous mode with MCLK.

You can obtain the SubBlock with split_subblocks.

Source

pub fn new_asynchronous<S: SubBlockInstance>( peri: SubBlock<'d, T, S>, sck: impl Peripheral<P = impl SckPin<T, S>> + 'd, sd: impl Peripheral<P = impl SdPin<T, S>> + 'd, fs: impl Peripheral<P = impl FsPin<T, S>> + 'd, dma: impl Peripheral<P = impl Channel + Dma<T, S>> + 'd, dma_buf: &'d mut [W], config: Config, ) -> Self

Create a new SAI driver in asynchronous mode without MCLK.

You can obtain the SubBlock with split_subblocks.

Source

pub fn new_synchronous<S: SubBlockInstance>( peri: SubBlock<'d, T, S>, sd: impl Peripheral<P = impl SdPin<T, S>> + 'd, dma: impl Peripheral<P = impl Channel + Dma<T, S>> + 'd, dma_buf: &'d mut [W], config: Config, ) -> Self

Create a new SAI driver in synchronous mode.

You can obtain the SubBlock with split_subblocks.

Source

pub fn start(&mut self) -> Result<(), Error>

Start the SAI driver.

Only receivers can be started. Transmitters are started on the first writing operation.

Source

pub fn reset()

Reset SAI operation.

Source

pub fn set_mute(&mut self, value: bool)

Enable or disable mute.

Source

pub fn is_muted(&self) -> Result<bool, Error>

Determine the mute state of the receiver.

Clears the mute state flag in the status register.

Source

pub async fn wait_write_error(&mut self) -> Result<(), Error>

Wait until any SAI write error occurs.

One useful application for this is stopping playback as soon as the SAI experiences an overrun of the ring buffer. Then, instead of letting the SAI peripheral play the last written buffer over and over again, SAI can be muted or dropped instead.

Source

pub async fn write(&mut self, data: &[W]) -> Result<(), Error>

Write data to the SAI ringbuffer.

The first write starts the DMA after filling the ring buffer with the provided data. This ensures that the DMA does not run before data is available in the ring buffer.

This appends the data to the buffer and returns immediately. The data will be transmitted in the background.

If there’s no space in the buffer, this waits until there is.

Source

pub async fn read(&mut self, data: &mut [W]) -> Result<(), Error>

Read data from the SAI ringbuffer.

SAI is always receiving data in the background. This function pops already-received data from the buffer.

If there’s less than data.len() data in the buffer, this waits until there is.

Trait Implementations§

Source§

impl<'d, T: Instance, W: Word> Drop for Sai<'d, T, W>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'d, T, W> Freeze for Sai<'d, T, W>
where T: Freeze,

§

impl<'d, T, W> RefUnwindSafe for Sai<'d, T, W>

§

impl<'d, T, W> Send for Sai<'d, T, W>
where T: Send, W: Send,

§

impl<'d, T, W> Sync for Sai<'d, T, W>
where T: Sync, W: Sync,

§

impl<'d, T, W> Unpin for Sai<'d, T, W>
where T: Unpin,

§

impl<'d, T, W> !UnwindSafe for Sai<'d, T, W>

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>,

Source§

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>,

Source§

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.