Struct esp_idf_svc::hal::i2s::I2sDriver

source ·
pub struct I2sDriver<'d, Dir> { /* private fields */ }
Expand description

Inter-IC Sound (I2S) driver.

Implementations§

source§

impl<'d> I2sDriver<'d, I2sTx>

source

pub fn new_pdm_tx<I2S>( _i2s: impl Peripheral<P = I2S> + 'd, tx_cfg: &PdmTxConfig, clk: impl Peripheral<P = impl OutputPin> + 'd, dout: impl Peripheral<P = impl OutputPin> + 'd, dout2: Option<impl Peripheral<P = impl OutputPin> + 'd>, ) -> Result<I2sDriver<'d, I2sTx>, EspError>
where I2S: I2s,

Create a new pulse density modulation (PDM) mode driver for the given I2S peripheral with only the transmit channel open.

source§

impl<'d> I2sDriver<'d, I2sBiDir>

source

pub fn new_std_bidir<I2S>( i2s: impl Peripheral<P = I2S> + 'd, config: &StdConfig, bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd, din: impl Peripheral<P = impl InputPin> + 'd, dout: impl Peripheral<P = impl OutputPin> + 'd, mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>, ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd, ) -> Result<I2sDriver<'d, I2sBiDir>, EspError>
where I2S: I2s,

Create a new standard mode driver for the given I2S peripheral with both the receive and transmit channels open.

source§

impl<'d> I2sDriver<'d, I2sRx>

source

pub fn new_std_rx<I2S>( i2s: impl Peripheral<P = I2S> + 'd, config: &StdConfig, bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd, din: impl Peripheral<P = impl InputPin> + 'd, mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>, ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd, ) -> Result<I2sDriver<'d, I2sRx>, EspError>
where I2S: I2s,

Create a new standard mode driver for the given I2S peripheral with only the receive channel open.

source§

impl<'d> I2sDriver<'d, I2sTx>

source

pub fn new_std_tx<I2S>( i2s: impl Peripheral<P = I2S> + 'd, config: &StdConfig, bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd, dout: impl Peripheral<P = impl OutputPin> + 'd, mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>, ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd, ) -> Result<I2sDriver<'d, I2sTx>, EspError>
where I2S: I2s,

Create a new standard mode driver for the given I2S peripheral with only the transmit channel open.

source§

impl<'d> I2sDriver<'d, I2sBiDir>

source

pub fn new_tdm_bidir<I2S>( i2s: impl Peripheral<P = I2S> + 'd, config: &TdmConfig, bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd, din: impl Peripheral<P = impl InputPin> + 'd, dout: impl Peripheral<P = impl OutputPin> + 'd, mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>, ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd, ) -> Result<I2sDriver<'d, I2sBiDir>, EspError>
where I2S: I2s,

Create a new TDM mode driver for the given I2S peripheral with both the receive and transmit channels open.

source§

impl<'d> I2sDriver<'d, I2sRx>

source

pub fn new_tdm_rx<I2S>( i2s: impl Peripheral<P = I2S> + 'd, config: &TdmConfig, bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd, din: impl Peripheral<P = impl InputPin> + 'd, mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>, ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd, ) -> Result<I2sDriver<'d, I2sRx>, EspError>
where I2S: I2s,

Create a new TDM mode driver for the given I2S peripheral with only the receive channel open.

source§

impl<'d> I2sDriver<'d, I2sTx>

source

pub fn new_tdm_tx<I2S>( i2s: impl Peripheral<P = I2S> + 'd, config: &TdmConfig, bclk: impl Peripheral<P = impl InputPin + OutputPin> + 'd, dout: impl Peripheral<P = impl OutputPin> + 'd, mclk: Option<impl Peripheral<P = impl InputPin + OutputPin> + 'd>, ws: impl Peripheral<P = impl InputPin + OutputPin> + 'd, ) -> Result<I2sDriver<'d, I2sTx>, EspError>
where I2S: I2s,

Create a new TDM mode driver for the given I2S peripheral with only the transmit channel open.

source§

impl<'d, Dir> I2sDriver<'d, Dir>

source

pub fn as_ref(&mut self) -> I2sDriverRef<'_, Dir>

Borrow the I2S driver by a reference

source§

impl<'d, Dir> I2sDriver<'d, Dir>
where Dir: I2sRxSupported,

Functions for receive channels.

source

pub fn rx_enable(&mut self) -> Result<(), EspError>

Enable the I2S receive channel.

§Note

This can only be called when the channel is in the READY state: initialized but not yet started from a driver constructor, or disabled from the RUNNING state via [rx_enable()][I2sRxChannel::rx_disable]. The channel will enter the RUNNING state if it is enabled successfully.

Enabling the channel will start I2S communications on the hardware. BCLK and WS signals will be generated if this is a controller. MCLK will be generated once initialization is finished.

§Errors

This will return an EspError with ESP_ERR_INVALID_STATE if the channel is not in the READY state.

source

pub fn rx_disable(&mut self) -> Result<(), EspError>

Disable the I2S receive channel.

§Note

This can only be called when the channel is in the RUNNING state: the channel has been previously enabled via a call to [rx_enable()][I2sRxChannel::rx_enable]. The channel will enter the READY state if it is disabled successfully.

Disabling the channel will stop I2S communications on the hardware. BCLK and WS signals will stop being generated if this is a controller. MCLK will continue to be generated.

§Errors

This will return an EspError with ESP_ERR_INVALID_STATE if the channel is not in the RUNNING state.

source

pub async fn read_async(&mut self, buffer: &mut [u8]) -> Result<usize, EspError>

Read data from the channel asynchronously.

This may be called only when the channel is in the RUNNING state.

§Returns

This returns the number of bytes read, or an EspError if an error occurred.

source

pub fn read( &mut self, buffer: &mut [u8], timeout: u32, ) -> Result<usize, EspError>

Read data from the channel.

This may be called only when the channel is in the RUNNING state.

§Returns

This returns the number of bytes read, or an EspError if an error occurred.

source

pub async fn read_uninit_async( &mut self, buffer: &mut [MaybeUninit<u8>], ) -> Result<usize, EspError>

Read data from the channel into an uninitalized buffer asynchronously.

This may be called only when the channel is in the RUNNING state.

§Returns

This returns the number of bytes read, or an EspError if an error occurred.

§Safety

Upon a successful return with Ok(n_read), buffer[..n_read] will be initialized.

source

pub fn read_uninit( &mut self, buffer: &mut [MaybeUninit<u8>], timeout: u32, ) -> Result<usize, EspError>

Read data from the channel into an uninitalized buffer.

This may be called only when the channel is in the RUNNING state.

§Returns

This returns the number of bytes read, or an EspError if an error occurred.

§Safety

Upon a successful return with Ok(n_read), buffer[..n_read] will be initialized.

source§

impl<'d, Dir> I2sDriver<'d, Dir>
where Dir: I2sTxSupported,

Functions for transmit channels.

source

pub fn tx_enable(&mut self) -> Result<(), EspError>

Enable the I2S transmit channel.

§Note

This can only be called when the channel is in the READY state: initialized but not yet started from a driver constructor, or disabled from the RUNNING state via [tx_disable()][I2sTxChannel::tx_disable]. The channel will enter the RUNNING state if it is enabled successfully.

Enabling the channel will start I2S communications on the hardware. BCLK and WS signals will be generated if this is a controller. MCLK will be generated once initialization is finished.

§Errors

This will return an EspError with ESP_ERR_INVALID_STATE if the channel is not in the READY state.

source

pub fn tx_disable(&mut self) -> Result<(), EspError>

Disable the I2S transmit channel.

§Note

This can only be called when the channel is in the RUNNING state: the channel has been previously enabled via a call to [tx_enable()][I2sTxChannel::tx_enable]. The channel will enter the READY state if it is disabled successfully.

Disabling the channel will stop I2S communications on the hardware. BCLK and WS signals will stop being generated if this is a controller. MCLK will continue to be generated.

§Errors

This will return an EspError with ESP_ERR_INVALID_STATE if the channel is not in the RUNNING state.

source

pub fn preload_data(&mut self, data: &[u8]) -> Result<usize, EspError>

Preload data into the transmit channel DMA buffer.

This may be called only when the channel is in the READY state: initialized but not yet started.

This is used to preload data into the DMA buffer so that valid data can be transmitted immediately after the channel is enabled via [tx_enable()][I2sTxChannel::tx_enable]. If this function is not called before enabling the channel, empty data will be transmitted.

This function can be called multiple times before enabling the channel. Additional calls will concatenate the data to the end of the buffer until the buffer is full.

§Returns

This returns the number of bytes that have been loaded into the buffer. If this is less than the length of the data provided, the buffer is full and no more data can be loaded.

source

pub async fn write_async(&mut self, data: &[u8]) -> Result<usize, EspError>

Write data to the channel asynchronously.

This may be called only when the channel is in the RUNNING state.

§Returns

This returns the number of bytes sent. This may be less than the length of the data provided.

source

pub async fn write_all_async(&mut self, data: &[u8]) -> Result<(), EspError>

Write all data to the channel asynchronously.

This may be called only when the channel is in the RUNNING state.

source

pub fn write(&mut self, data: &[u8], timeout: u32) -> Result<usize, EspError>

Write data to the channel.

This may be called only when the channel is in the RUNNING state.

§Returns

This returns the number of bytes sent. This may be less than the length of the data provided.

source

pub fn write_all(&mut self, data: &[u8], timeout: u32) -> Result<(), EspError>

Write all data to the channel.

This may be called only when the channel is in the RUNNING state.

source§

impl<'d> I2sDriver<'d, I2sBiDir>

source

pub fn split(&mut self) -> (I2sDriverRef<'_, I2sRx>, I2sDriverRef<'_, I2sTx>)

Split the bidirectional I2S driver into two parts (Rx, Tx)

§Safety

It is safe to use the two parts separately

  • esp-idf guarantees thread safety
  • esp-idf-hal guarantees asynchronous safety

Trait Implementations§

source§

impl<'d, Dir> Drop for I2sDriver<'d, Dir>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'d, Dir> ErrorType for I2sDriver<'d, Dir>

§

type Error = EspIOError

Error type of all the IO operations on this type.
source§

impl<'d, Dir> I2sPort for I2sDriver<'d, Dir>

source§

fn port(&self) -> u32

Returns the I2S port number of this driver.
source§

impl<'d, Dir> Read for I2sDriver<'d, Dir>
where Dir: I2sRxSupported,

source§

fn read( &mut self, buf: &mut [u8], ) -> Result<usize, <I2sDriver<'d, Dir> as ErrorType>::Error>

Read some bytes from this source into the specified buffer, returning how many bytes were read. Read more
source§

fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>

Read the exact number of bytes required to fill buf. Read more
source§

impl<'d, Dir> Read for I2sDriver<'d, Dir>
where Dir: I2sRxSupported,

source§

async fn read( &mut self, buf: &mut [u8], ) -> Result<usize, <I2sDriver<'d, Dir> as ErrorType>::Error>

Read some bytes from this source into the specified buffer, returning how many bytes were read. Read more
source§

async fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>

Read the exact number of bytes required to fill buf. Read more
source§

impl<'d, Dir> Write for I2sDriver<'d, Dir>
where Dir: I2sTxSupported,

source§

fn write( &mut self, buf: &[u8], ) -> Result<usize, <I2sDriver<'d, Dir> as ErrorType>::Error>

Write a buffer into this writer, returning how many bytes were written. Read more
source§

fn flush(&mut self) -> Result<(), <I2sDriver<'d, Dir> as ErrorType>::Error>

Flush this output stream, blocking until all intermediately buffered contents reach their destination.
source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error>

Write an entire buffer into this writer. Read more
source§

fn write_fmt( &mut self, fmt: Arguments<'_>, ) -> Result<(), WriteFmtError<Self::Error>>

Write a formatted string into this writer, returning any error encountered. Read more
source§

impl<'d, Dir> Write for I2sDriver<'d, Dir>
where Dir: I2sTxSupported,

source§

async fn write( &mut self, buf: &[u8], ) -> Result<usize, <I2sDriver<'d, Dir> as ErrorType>::Error>

Write a buffer into this writer, returning how many bytes were written. Read more
source§

async fn flush( &mut self, ) -> Result<(), <I2sDriver<'d, Dir> as ErrorType>::Error>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
source§

async fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error>

Write an entire buffer into this writer. Read more
source§

impl<'d, Dir> Send for I2sDriver<'d, Dir>

Auto Trait Implementations§

§

impl<'d, Dir> Freeze for I2sDriver<'d, Dir>

§

impl<'d, Dir> RefUnwindSafe for I2sDriver<'d, Dir>
where Dir: RefUnwindSafe,

§

impl<'d, Dir> !Sync for I2sDriver<'d, Dir>

§

impl<'d, Dir> Unpin for I2sDriver<'d, Dir>
where Dir: Unpin,

§

impl<'d, Dir> UnwindSafe for I2sDriver<'d, Dir>
where Dir: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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.
§

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

Performs the conversion.