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>>§
sourcepub fn as_ref(&mut self) -> I2sDriverRef<'_, Dir>
pub fn as_ref(&mut self) -> I2sDriverRef<'_, Dir>
Borrow the I2S driver by a reference
sourcepub fn rx_enable(&mut self) -> Result<(), EspError>
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.
sourcepub fn rx_disable(&mut self) -> Result<(), EspError>
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.
sourcepub async fn read_async(&mut self, buffer: &mut [u8]) -> Result<usize, EspError>
pub async fn read_async(&mut self, buffer: &mut [u8]) -> Result<usize, EspError>
sourcepub async fn read_uninit_async(
&mut self,
buffer: &mut [MaybeUninit<u8>],
) -> Result<usize, EspError>
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.
sourcepub fn read_uninit(
&mut self,
buffer: &mut [MaybeUninit<u8>],
timeout: u32,
) -> Result<usize, EspError>
pub fn read_uninit( &mut self, buffer: &mut [MaybeUninit<u8>], timeout: u32, ) -> Result<usize, EspError>
sourcepub fn tx_enable(&mut self) -> Result<(), EspError>
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.
sourcepub fn tx_disable(&mut self) -> Result<(), EspError>
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.
sourcepub fn preload_data(&mut self, data: &[u8]) -> Result<usize, EspError>
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.
sourcepub async fn write_async(&mut self, data: &[u8]) -> Result<usize, EspError>
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.
sourcepub async fn write_all_async(&mut self, data: &[u8]) -> Result<(), EspError>
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.
sourcepub fn write(&mut self, data: &[u8], timeout: u32) -> Result<usize, EspError>
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.
sourcepub fn write_all(&mut self, data: &[u8], timeout: u32) -> Result<(), EspError>
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.
sourcepub fn split(&mut self) -> (I2sDriverRef<'_, I2sRx>, I2sDriverRef<'_, I2sTx>)
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