Struct esp_idf_svc::hal::i2s::I2sDriverRef

source ·
pub struct I2sDriverRef<'d, Dir>(/* private fields */);
Expand description

Reference for I2S driver

Methods from Deref<Target = I2sDriver<'d, Dir>>§

source

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

Borrow the I2S driver by a reference

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

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

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> Deref for I2sDriverRef<'d, Dir>

§

type Target = I2sDriver<'d, Dir>

The resulting type after dereferencing.
source§

fn deref(&self) -> &<I2sDriverRef<'d, Dir> as Deref>::Target

Dereferences the value.
source§

impl<'d, Dir> DerefMut for I2sDriverRef<'d, Dir>

source§

fn deref_mut(&mut self) -> &mut <I2sDriverRef<'d, Dir> as Deref>::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

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

§

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

§

impl<'d, Dir> !Send for I2sDriverRef<'d, Dir>

§

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

§

impl<'d, Dir> Unpin for I2sDriverRef<'d, Dir>

§

impl<'d, Dir> UnwindSafe for I2sDriverRef<'d, Dir>
where Dir: RefUnwindSafe,

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.